loudmouth/lm-asyncns-resolver.c
author Mikael Berthe <mikael@lilotux.net>
Thu, 05 Nov 2015 21:47:40 +0100
changeset 672 71f60c55efb3
parent 670 88c6aef5ff18
child 690 7ccf2113ec5f
permissions -rw-r--r--
Update release information files Change the maintainers.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
516
4dd3aa6b83e5 Change the tab width to 4 steps in the emacs headers
Mikael Hallendal <micke@imendio.com>
parents: 515
diff changeset
     1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     2
/*
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     3
 * Copyright (C) 2008 Imendio AB
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     4
 *
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     6
 * modify it under the terms of the GNU Lesser General Public License as
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     7
 * published by the Free Software Foundation; either version 2 of the
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     8
 * License, or (at your option) any later version.
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     9
 *
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    13
 * Lesser General Public License for more details.
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    14
 *
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    15
 * You should have received a copy of the GNU Lesser General Public
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    16
 * License along with this program; if not, write to the
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    18
 * Boston, MA 02111-1307, USA.
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    19
 */
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    20
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    21
#include <config.h>
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    22
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    23
#include <string.h>
616
b853d91bc249 Remove internal asyncns
Frank Zschockelt <lm@freakysoft.de>
parents: 614
diff changeset
    24
#ifdef HAVE_ASYNCNS
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    25
#include <asyncns.h>
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    26
#define freeaddrinfo(x) asyncns_freeaddrinfo(x)
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    27
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    28
/* Needed on Mac OS X */
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    29
#if HAVE_ARPA_NAMESER_COMPAT_H
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    30
#include <arpa/nameser_compat.h>
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    31
#endif
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    32
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    33
#include <arpa/nameser.h>
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    34
#include <resolv.h>
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    35
611
1535ce921a7a Replace g_print with g_log in asyncns-resolver:
Frank Zschockelt <lm@freakysoft.de>
parents: 607
diff changeset
    36
#include "lm-debug.h"
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    37
#include "lm-error.h"
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    38
#include "lm-internals.h"
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    39
#include "lm-marshal.h"
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    40
#include "lm-misc.h"
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    41
#include "lm-asyncns-resolver.h"
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    42
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    43
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), LM_TYPE_ASYNCNS_RESOLVER, LmAsyncnsResolverPriv))
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    44
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    45
typedef struct LmAsyncnsResolverPriv LmAsyncnsResolverPriv;
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    46
struct LmAsyncnsResolverPriv {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    47
    GSource     *watch_resolv;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    48
    asyncns_query_t *resolv_query;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    49
    asyncns_t   *asyncns_ctx;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    50
    GIOChannel  *resolv_channel;
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    51
};
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    52
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    53
static void     asyncns_resolver_finalize      (GObject     *object);
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    54
static void     asyncns_resolver_lookup        (LmResolver  *resolver);
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    55
static void     asyncns_resolver_cancel        (LmResolver  *resolver);
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    56
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    57
G_DEFINE_TYPE (LmAsyncnsResolver, lm_asyncns_resolver, LM_TYPE_RESOLVER)
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    58
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    59
static void
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    60
lm_asyncns_resolver_class_init (LmAsyncnsResolverClass *class)
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    61
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    62
    GObjectClass    *object_class = G_OBJECT_CLASS (class);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    63
    LmResolverClass *resolver_class = LM_RESOLVER_CLASS (class);
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    64
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    65
    object_class->finalize = asyncns_resolver_finalize;
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    66
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    67
    resolver_class->lookup = asyncns_resolver_lookup;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    68
    resolver_class->cancel = asyncns_resolver_cancel;
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    69
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    70
    g_type_class_add_private (object_class, sizeof (LmAsyncnsResolverPriv));
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    71
}
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    72
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    73
static void
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    74
lm_asyncns_resolver_init (LmAsyncnsResolver *asyncns_resolver)
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    75
{
624
a94013a4555d Fix some gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
    76
    (void) GET_PRIV (asyncns_resolver);
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    77
}
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    78
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    79
static void
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    80
asyncns_resolver_finalize (GObject *object)
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    81
{
624
a94013a4555d Fix some gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
    82
    (void) GET_PRIV (object);
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    83
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    84
    (G_OBJECT_CLASS (lm_asyncns_resolver_parent_class)->finalize) (object);
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    85
}
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    86
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    87
static void
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    88
asyncns_resolver_cleanup (LmResolver *resolver)
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    89
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    90
    LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    91
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    92
    if (priv->resolv_channel != NULL) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    93
        g_io_channel_unref (priv->resolv_channel);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    94
        priv->resolv_channel = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    95
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 606
diff changeset
    96
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    97
    if (priv->watch_resolv) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    98
        g_source_destroy (priv->watch_resolv);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    99
        priv->watch_resolv = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   100
    }
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   101
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   102
    if (priv->asyncns_ctx) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   103
        asyncns_free (priv->asyncns_ctx);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   104
        priv->asyncns_ctx = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   105
    }
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   106
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   107
    priv->resolv_query = NULL;
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   108
}
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   109
477
09fe238533b9 Put a ref on the resolver while calling the callback.
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   110
static void
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   111
asyncns_resolver_done (LmResolver *resolver)
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   112
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   113
    LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   114
    struct addrinfo       *ans;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   115
    int                err;
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   116
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   117
    err = asyncns_getaddrinfo_done (priv->asyncns_ctx, priv->resolv_query, &ans);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   118
    priv->resolv_query = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   119
    /* Signal that we are done */
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   120
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   121
    g_object_ref (resolver);
477
09fe238533b9 Put a ref on the resolver while calling the callback.
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   122
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   123
    if (err) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   124
        _lm_resolver_set_result (resolver,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 606
diff changeset
   125
                                 LM_RESOLVER_RESULT_FAILED,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   126
                                 NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   127
    } else {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   128
        _lm_resolver_set_result (resolver,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   129
                                 LM_RESOLVER_RESULT_OK,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   130
                                 ans);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   131
    }
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   132
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   133
    asyncns_resolver_cleanup (resolver);
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   134
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   135
    g_object_unref (resolver);
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   136
}
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   137
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   138
typedef gboolean  (* LmAsyncnsResolverCallback) (LmResolver *resolver);
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   139
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   140
static gboolean
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   141
asyncns_resolver_io_cb (GSource      *source,
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   142
                        GIOCondition  condition,
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   143
                        LmResolver   *resolver)
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   144
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   145
    LmAsyncnsResolverPriv     *priv = GET_PRIV (resolver);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   146
    LmAsyncnsResolverCallback  func;
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   147
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   148
    asyncns_wait (priv->asyncns_ctx, FALSE);
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   149
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   150
    if (!asyncns_isdone (priv->asyncns_ctx, priv->resolv_query)) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   151
        return TRUE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   152
    }
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   153
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   154
    func = (LmAsyncnsResolverCallback) asyncns_getuserdata (priv->asyncns_ctx,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   155
                                                            priv->resolv_query);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   156
    return func (resolver);
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   157
}
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   158
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   159
static gboolean
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   160
asyncns_resolver_prep (LmResolver *resolver, GError **error)
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   161
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   162
    LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   163
    GMainContext          *context;
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   164
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   165
    if (priv->asyncns_ctx) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   166
        return TRUE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   167
    }
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   168
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   169
    priv->asyncns_ctx = asyncns_new (1);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   170
    if (priv->asyncns_ctx == NULL) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   171
        g_set_error (error,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 606
diff changeset
   172
                     LM_ERROR,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 606
diff changeset
   173
                     LM_ERROR_CONNECTION_FAILED,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   174
                     "can't initialise libasyncns");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   175
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   176
    }
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   177
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   178
    priv->resolv_channel =
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   179
        g_io_channel_unix_new (asyncns_fd (priv->asyncns_ctx));
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   180
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   181
    g_object_get (resolver, "context", &context, NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 606
diff changeset
   182
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 606
diff changeset
   183
    priv->watch_resolv =
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   184
        lm_misc_add_io_watch (context,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   185
                              priv->resolv_channel,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   186
                              G_IO_IN,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   187
                              (GIOFunc) asyncns_resolver_io_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   188
                              resolver);
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   189
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   190
    return TRUE;
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   191
}
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   192
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   193
static void
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   194
asyncns_resolver_lookup_host (LmResolver *resolver)
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   195
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   196
    LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   197
    gchar               *host;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   198
    struct addrinfo      req;
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   199
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   200
    g_object_get (resolver, "host", &host, NULL);
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   201
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   202
    memset (&req, 0, sizeof(req));
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   203
    req.ai_family   = AF_UNSPEC;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   204
    req.ai_socktype = SOCK_STREAM;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   205
    req.ai_protocol = IPPROTO_TCP;
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   206
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   207
    if (!asyncns_resolver_prep (resolver, NULL)) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 611
diff changeset
   208
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "Signal error\n");
670
88c6aef5ff18 Fix a few memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
   209
        g_free (host);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   210
        return;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   211
    }
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   212
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   213
    priv->resolv_query =
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   214
        asyncns_getaddrinfo (priv->asyncns_ctx,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   215
                             host,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   216
                             NULL,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   217
                             &req);
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   218
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   219
    asyncns_setuserdata (priv->asyncns_ctx,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   220
                         priv->resolv_query,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   221
                         (gpointer) asyncns_resolver_done);
670
88c6aef5ff18 Fix a few memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
   222
88c6aef5ff18 Fix a few memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
   223
    g_free (host);
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   224
}
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   225
477
09fe238533b9 Put a ref on the resolver while calling the callback.
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   226
static void
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   227
asyncns_resolver_srv_done (LmResolver *resolver)
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   228
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   229
    LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   230
    unsigned char         *srv_ans;
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   231
    int                    srv_len;
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   232
    gboolean               result = FALSE;
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   233
611
1535ce921a7a Replace g_print with g_log in asyncns-resolver:
Frank Zschockelt <lm@freakysoft.de>
parents: 607
diff changeset
   234
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "srv_done callback\n");
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   235
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 606
diff changeset
   236
    srv_len = asyncns_res_done (priv->asyncns_ctx,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   237
                                priv->resolv_query, &srv_ans);
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   238
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   239
    priv->resolv_query = NULL;
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   240
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   241
    if (srv_len <= 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   242
        /* FIXME: Report error */
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 611
diff changeset
   243
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 611
diff changeset
   244
               "Failed to read srv request results");
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   245
    } else {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   246
        gchar *new_server;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   247
        guint  new_port;
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   248
611
1535ce921a7a Replace g_print with g_log in asyncns-resolver:
Frank Zschockelt <lm@freakysoft.de>
parents: 607
diff changeset
   249
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
1535ce921a7a Replace g_print with g_log in asyncns-resolver:
Frank Zschockelt <lm@freakysoft.de>
parents: 607
diff changeset
   250
               "trying to parse srv response\n");
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   251
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   252
        result = _lm_resolver_parse_srv_response (srv_ans, srv_len,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   253
                                                  &new_server,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   254
                                                  &new_port);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   255
        if (result == TRUE) {
611
1535ce921a7a Replace g_print with g_log in asyncns-resolver:
Frank Zschockelt <lm@freakysoft.de>
parents: 607
diff changeset
   256
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
1535ce921a7a Replace g_print with g_log in asyncns-resolver:
Frank Zschockelt <lm@freakysoft.de>
parents: 607
diff changeset
   257
                   "worked, new host/post is %s/%d\n",
1535ce921a7a Replace g_print with g_log in asyncns-resolver:
Frank Zschockelt <lm@freakysoft.de>
parents: 607
diff changeset
   258
                   new_server, new_port);
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   259
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   260
            g_object_set (resolver,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   261
                          "host", new_server,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   262
                          "port", new_port,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   263
                          NULL);
620
2e344ed4140b Fix segfault in asyncns resolver
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
   264
            g_free (new_server);
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   265
        }
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   266
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   267
        /* TODO: Check whether srv_ans needs freeing */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   268
    }
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   269
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   270
    asyncns_resolver_cleanup (resolver);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 606
diff changeset
   271
606
14aa64152209 asyncns resolver: fail when the server doesn't have a SRV field.
Frank Zschockelt <lm@freakysoft.de>
parents: 561
diff changeset
   272
    g_object_ref (resolver);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   273
    if (result == TRUE) {
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   274
        _lm_resolver_set_result (LM_RESOLVER (resolver), LM_RESOLVER_RESULT_OK, NULL);
606
14aa64152209 asyncns resolver: fail when the server doesn't have a SRV field.
Frank Zschockelt <lm@freakysoft.de>
parents: 561
diff changeset
   275
    } else {
14aa64152209 asyncns resolver: fail when the server doesn't have a SRV field.
Frank Zschockelt <lm@freakysoft.de>
parents: 561
diff changeset
   276
        _lm_resolver_set_result (LM_RESOLVER (resolver), LM_RESOLVER_RESULT_FAILED, NULL);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   277
    }
606
14aa64152209 asyncns resolver: fail when the server doesn't have a SRV field.
Frank Zschockelt <lm@freakysoft.de>
parents: 561
diff changeset
   278
    g_object_unref (resolver);
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   279
}
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   280
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   281
static void
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   282
asyncns_resolver_lookup_service (LmResolver *resolver)
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   283
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   284
    LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   285
    gchar                 *domain;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   286
    gchar                 *service;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   287
    gchar                 *protocol;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   288
    gchar                 *srv;
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   289
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   290
    g_object_get (resolver,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   291
                  "domain", &domain,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   292
                  "service", &service,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   293
                  "protocol", &protocol,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   294
                  NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 606
diff changeset
   295
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   296
    srv = _lm_resolver_create_srv_string (domain, service, protocol);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 606
diff changeset
   297
611
1535ce921a7a Replace g_print with g_log in asyncns-resolver:
Frank Zschockelt <lm@freakysoft.de>
parents: 607
diff changeset
   298
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
1535ce921a7a Replace g_print with g_log in asyncns-resolver:
Frank Zschockelt <lm@freakysoft.de>
parents: 607
diff changeset
   299
           "ASYNCNS: Looking up service: %s %s %s [%s]\n",
1535ce921a7a Replace g_print with g_log in asyncns-resolver:
Frank Zschockelt <lm@freakysoft.de>
parents: 607
diff changeset
   300
           domain, service, protocol, srv);
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   301
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   302
    if (!asyncns_resolver_prep (resolver, /* Use GError? */ NULL)) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 611
diff changeset
   303
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 611
diff changeset
   304
               "Failed to initiate the asyncns library");
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   305
        /* FIXME: Signal error */
670
88c6aef5ff18 Fix a few memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
   306
        g_free (srv);
88c6aef5ff18 Fix a few memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
   307
        g_free (domain);
88c6aef5ff18 Fix a few memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
   308
        g_free (service);
88c6aef5ff18 Fix a few memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
   309
        g_free (protocol);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   310
        return;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   311
    }
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   312
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   313
    priv->resolv_query =
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   314
        asyncns_res_query (priv->asyncns_ctx, srv, C_IN, T_SRV);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 606
diff changeset
   315
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 606
diff changeset
   316
    asyncns_setuserdata (priv->asyncns_ctx,
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 606
diff changeset
   317
                         priv->resolv_query,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   318
                         (gpointer) asyncns_resolver_srv_done);
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   319
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   320
    g_free (srv);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   321
    g_free (domain);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   322
    g_free (service);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   323
    g_free (protocol);
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   324
}
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   325
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   326
static void
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   327
asyncns_resolver_lookup (LmResolver *resolver)
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   328
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   329
    gint type;
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   330
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   331
    /* Start the DNS querying */
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   332
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   333
    /* Decide if we are going to lookup a srv or host */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   334
    g_object_get (resolver, "type", &type, NULL);
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   335
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   336
    switch (type) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   337
    case LM_RESOLVER_HOST:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   338
        asyncns_resolver_lookup_host (resolver);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   339
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   340
    case LM_RESOLVER_SRV:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   341
        asyncns_resolver_lookup_service (resolver);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   342
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   343
    };
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   344
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   345
    /* End of DNS querying */
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 606
diff changeset
   346
}
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   347
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   348
static void
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   349
asyncns_resolver_cancel (LmResolver *resolver)
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   350
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   351
    LmAsyncnsResolverPriv *priv;
475
001da49d7fd1 Added cancel operation for asyncns resolver
Mikael Hallendal <micke@imendio.com>
parents: 474
diff changeset
   352
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   353
    g_return_if_fail (LM_IS_ASYNCNS_RESOLVER (resolver));
475
001da49d7fd1 Added cancel operation for asyncns resolver
Mikael Hallendal <micke@imendio.com>
parents: 474
diff changeset
   354
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   355
    priv = GET_PRIV (resolver);
475
001da49d7fd1 Added cancel operation for asyncns resolver
Mikael Hallendal <micke@imendio.com>
parents: 474
diff changeset
   356
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   357
    if (priv->asyncns_ctx) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   358
        if (priv->resolv_query) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   359
            asyncns_cancel (priv->asyncns_ctx, priv->resolv_query);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   360
            priv->resolv_query = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   361
        }
475
001da49d7fd1 Added cancel operation for asyncns resolver
Mikael Hallendal <micke@imendio.com>
parents: 474
diff changeset
   362
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   363
        _lm_resolver_set_result (resolver,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   364
                                 LM_RESOLVER_RESULT_CANCELLED,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   365
                                 NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   366
    }
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   367
}
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   368
616
b853d91bc249 Remove internal asyncns
Frank Zschockelt <lm@freakysoft.de>
parents: 614
diff changeset
   369
#endif //HAVE_ASYNCNS