loudmouth/lm-asyncns-resolver.c
author Mikael Hallendal <micke@imendio.com>
Sat, 25 Oct 2008 20:09:25 +0200
changeset 547 692c7753f64e
parent 518 cdd6a0c5b439
child 561 f659884550a5
permissions -rw-r--r--
Improved the resolvers a bit. LmOldSocket currently creates a new resolver when doing a host lookup after a successful srv lookup.
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>
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    24
#include <asyncns.h>
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    25
#define freeaddrinfo(x) asyncns_freeaddrinfo(x)
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    26
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    27
/* Needed on Mac OS X */
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    28
#if HAVE_ARPA_NAMESER_COMPAT_H
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    29
#include <arpa/nameser_compat.h>
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    30
#endif
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    31
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    32
#include <arpa/nameser.h>
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    33
#include <resolv.h>
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    34
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    35
#include "lm-error.h"
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    36
#include "lm-internals.h"
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    37
#include "lm-marshal.h"
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    38
#include "lm-misc.h"
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    39
#include "lm-asyncns-resolver.h"
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    40
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    41
#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
    42
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    43
typedef struct LmAsyncnsResolverPriv LmAsyncnsResolverPriv;
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    44
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
    45
    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
    46
    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
    47
    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
    48
    GIOChannel  *resolv_channel;
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    49
};
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    50
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    51
static void     asyncns_resolver_finalize      (GObject     *object);
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    52
static void     asyncns_resolver_lookup        (LmResolver  *resolver);
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    53
static void     asyncns_resolver_cancel        (LmResolver  *resolver);
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    54
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    55
G_DEFINE_TYPE (LmAsyncnsResolver, lm_asyncns_resolver, LM_TYPE_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
static void
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    58
lm_asyncns_resolver_class_init (LmAsyncnsResolverClass *class)
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    59
{
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
    60
    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
    61
    LmResolverClass *resolver_class = LM_RESOLVER_CLASS (class);
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    62
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
    63
    object_class->finalize = asyncns_resolver_finalize;
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
    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
    66
    resolver_class->cancel = asyncns_resolver_cancel;
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    67
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
    68
    g_type_class_add_private (object_class, sizeof (LmAsyncnsResolverPriv));
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    69
}
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    70
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    71
static void
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    72
lm_asyncns_resolver_init (LmAsyncnsResolver *asyncns_resolver)
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    73
{
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
    74
    LmAsyncnsResolverPriv *priv;
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    75
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
    76
    priv = 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
{
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
    82
    LmAsyncnsResolverPriv *priv;
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
    priv = GET_PRIV (object);
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    85
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
    86
    (G_OBJECT_CLASS (lm_asyncns_resolver_parent_class)->finalize) (object);
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    87
}
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    88
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    89
static void
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    90
asyncns_resolver_cleanup (LmResolver *resolver)
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
    LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    93
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
    94
    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
    95
        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
    96
        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
    97
    }
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
    98
 
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
    99
    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
   100
        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
   101
        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
   102
    }
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   103
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
   104
    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
   105
        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
   106
        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
   107
    }
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   108
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
   109
    priv->resolv_query = NULL;
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   110
}
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   111
477
09fe238533b9 Put a ref on the resolver while calling the callback.
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   112
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
   113
asyncns_resolver_done (LmResolver *resolver)
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   114
{
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
   115
    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
   116
    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
   117
    int                err;
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   118
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
   119
    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
   120
    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
   121
    /* Signal that we are done */
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
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
    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
   124
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
   125
    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
   126
        _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
   127
                                 LM_RESOLVER_RESULT_FAILED, 
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
                                 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
   129
    } 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
   130
        _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
   131
                                 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
   132
                                 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
   133
    }
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
    asyncns_resolver_cleanup (resolver);
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   136
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
   137
    g_object_unref (resolver);
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   138
}
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   139
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   140
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
   141
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   142
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
   143
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
   144
                        GIOCondition  condition,
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   145
                        LmResolver   *resolver)
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   146
{
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
   147
    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
   148
    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
   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
    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
   151
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
   152
    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
   153
        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
   154
    }
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   155
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
   156
    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
   157
                                                            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
   158
    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
   159
}
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   160
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   161
static gboolean
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   162
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
   163
{
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
   164
    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
   165
    GMainContext          *context;
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   166
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
   167
    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
   168
        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
   169
    }
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   170
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
   171
    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
   172
    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
   173
        g_set_error (error,
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
                     LM_ERROR,                 
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
                     LM_ERROR_CONNECTION_FAILED,   
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
                     "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
   177
        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
   178
    }
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   179
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
   180
    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
   181
        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
   182
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
   183
    g_object_get (resolver, "context", &context, NULL);
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   184
        
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
   185
    g_print ("Setting up io watch\n");
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   186
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
   187
    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
   188
        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
   189
                              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
   190
                              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
   191
                              (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
   192
                              resolver);
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   193
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
   194
    return TRUE;
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   195
}
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   196
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   197
static void
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   198
asyncns_resolver_lookup_host (LmResolver *resolver)
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
    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
   201
    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
   202
    struct addrinfo      req;
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   203
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
   204
    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
   205
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
   206
    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
   207
    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
   208
    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
   209
    req.ai_protocol = IPPROTO_TCP;
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   210
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
   211
    if (!asyncns_resolver_prep (resolver, 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
   212
        g_warning ("Signal error\n");
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
        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
   214
    }
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   215
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
   216
    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
   217
        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
   218
                             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
   219
                             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
   220
                             &req);
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   221
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
   222
    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
   223
                         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
   224
                         (gpointer) asyncns_resolver_done);
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   225
}
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   226
477
09fe238533b9 Put a ref on the resolver while calling the callback.
Mikael Hallendal <micke@imendio.com>
parents: 475
diff changeset
   227
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
   228
asyncns_resolver_srv_done (LmResolver *resolver)
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   229
{
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
   230
    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
   231
    unsigned char         *srv_ans;
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   232
    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
   233
    gboolean               result = FALSE;
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   234
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
   235
    g_print ("srv_done callback\n");
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   236
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
    srv_len = asyncns_res_done (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
   238
                                priv->resolv_query, &srv_ans);
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   239
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
   240
    priv->resolv_query = NULL;
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   241
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
   242
    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
   243
        /* FIXME: Report error */
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
   244
        g_warning ("Failed to read srv request results");
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
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
   249
        g_print ("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
   250
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
   251
        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
   252
                                                  &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
   253
                                                  &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
   254
        if (result == 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
   255
            g_print ("worked, new host/post is %s/%d\n",
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
   256
                     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
   257
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
   258
            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
   259
                          "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
   260
                          "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
   261
                          NULL);
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   262
        }
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   263
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
   264
        g_free (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
   265
        /* 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
   266
    }
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   267
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
   268
    asyncns_resolver_cleanup (resolver);
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 518
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
    if (result == TRUE) {
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   271
        g_object_ref (resolver);
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   272
        _lm_resolver_set_result (LM_RESOLVER (resolver), LM_RESOLVER_RESULT_OK, NULL);
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   273
        g_object_unref (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
   274
    }
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   275
}
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   276
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   277
static void
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   278
asyncns_resolver_lookup_service (LmResolver *resolver)
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   279
{
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
   280
    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
   281
    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
   282
    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
   283
    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
   284
    gchar                 *srv;
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   285
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
   286
    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
   287
                  "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
   288
                  "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
   289
                  "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
   290
                  NULL);
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   291
        
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
   292
    srv = _lm_resolver_create_srv_string (domain, service, protocol);
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   293
        
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   294
    g_print ("ASYNCNS: Looking up service: %s %s %s\n[%s]", domain, service, protocol, srv);
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
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
    if (!asyncns_resolver_prep (resolver, /* Use GError? */ 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
   297
        g_warning ("Failed to initiate the asyncns library");
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
   298
        /* FIXME: Signal error */
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
   299
        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
   300
    }
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
    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
   303
        asyncns_res_query (priv->asyncns_ctx, srv, C_IN, T_SRV);
474
b4eff3e1235c Fixed so that service lookup seems to work with new asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 473
diff changeset
   304
        
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
    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
   306
                         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
   307
                         (gpointer) asyncns_resolver_srv_done);
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   308
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
   309
    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
   310
    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
   311
    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
   312
    g_free (protocol);
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   313
}
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   314
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   315
static void
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   316
asyncns_resolver_lookup (LmResolver *resolver)
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   317
{
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
    gint type;
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
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
    /* Start the DNS querying */
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   321
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
   322
    /* 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
   323
    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
   324
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
   325
    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
   326
    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
   327
        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
   328
        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
   329
    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
   330
        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
   331
        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
   332
    };
471
a7cf42557aef Copied in code from LmOldSocket to LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents: 457
diff changeset
   333
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
   334
    /* End of DNS querying */
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   335
} 
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   336
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   337
static void
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   338
asyncns_resolver_cancel (LmResolver *resolver)
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   339
{
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
   340
    LmAsyncnsResolverPriv *priv;
475
001da49d7fd1 Added cancel operation for asyncns resolver
Mikael Hallendal <micke@imendio.com>
parents: 474
diff changeset
   341
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
   342
    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
   343
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
   344
    priv = GET_PRIV (resolver);
475
001da49d7fd1 Added cancel operation for asyncns resolver
Mikael Hallendal <micke@imendio.com>
parents: 474
diff changeset
   345
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
   346
    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
   347
        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
   348
            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
   349
            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
   350
        }
475
001da49d7fd1 Added cancel operation for asyncns resolver
Mikael Hallendal <micke@imendio.com>
parents: 474
diff changeset
   351
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
   352
        _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
   353
                                 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
   354
                                 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
   355
    }
457
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   356
}
9eeae02afc18 Added LmAsyncnsResolver
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   357