loudmouth/lm-resolver.c
author Jayson Vantuyl <jvantuyl@engineyard.com>
Mon, 23 Feb 2009 23:09:45 -0800
changeset 587 7c793095138e
parent 549 99a387fdb1bb
child 588 d4468955feb1
permissions -rw-r--r--
Fixed Retry Behavior, Fixed Crash on IPv6 Addresses, Log and Exit On No Host
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 -*- */
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     2
/*
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     3
 * Copyright (C) 2008 Imendio AB
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     4
 *
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     6
 * modify it under the terms of the GNU Lesser General Public License as
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     7
 * published by the Free Software Foundation; either version 2 of the
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     8
 * License, or (at your option) any later version.
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     9
 *
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    13
 * Lesser General Public License for more details.
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    14
 *
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    15
 * You should have received a copy of the GNU Lesser General Public
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    16
 * License along with this program; if not, write to the
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    18
 * Boston, MA 02111-1307, USA.
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    19
 */
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    20
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    21
#include <config.h>
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    22
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    23
#include <string.h>
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    24
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    25
/* Needed on Mac OS X */
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    26
#if HAVE_ARPA_NAMESER_COMPAT_H
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    27
#include <arpa/nameser_compat.h>
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    28
#endif
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    29
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    30
#include <arpa/nameser.h>
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    31
#include <resolv.h>
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
    32
472
5aa76e995f0d Renamed the test to test-dns and fixed a bug in the asyncns resolver.
Mikael Hallendal <micke@imendio.com>
parents: 467
diff changeset
    33
#include "lm-asyncns-resolver.h"
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
    34
#include "lm-blocking-resolver.h"
549
99a387fdb1bb Updated asyncns.[ch]
Mikael Hallendal <micke@imendio.com>
parents: 548
diff changeset
    35
#include "lm-debug.h"
463
158aebfa7b7c Moved MIN_PORT and MAX_PORT to lm-internals.h and renamed them.
Mikael Hallendal <micke@imendio.com>
parents: 462
diff changeset
    36
#include "lm-internals.h"
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    37
#include "lm-marshal.h"
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    38
#include "lm-resolver.h"
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    39
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    40
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), LM_TYPE_RESOLVER, LmResolverPriv))
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    41
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    42
typedef struct LmResolverPriv LmResolverPriv;
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    43
struct LmResolverPriv {
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
    44
    GMainContext       *context;
462
11f85004aa32 Added GMainContext to LmResolver and use lm_misc_add_idle to add an idle in it.
Mikael Hallendal <micke@imendio.com>
parents: 461
diff changeset
    45
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
    46
    LmResolverCallback  callback;
cdd6a0c5b439 Went 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
    gpointer            user_data;
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    48
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
    49
    /* -- Properties -- */
cdd6a0c5b439 Went 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
    LmResolverType      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
    51
    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
    52
    guint               port;
461
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
    53
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
    54
    /* For SRV lookups */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    55
    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
    56
    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
    57
    gchar              *protocol;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
    58
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
    59
    /* The 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
    60
    LmResolverResult    result;
cdd6a0c5b439 Went 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
    struct addrinfo    *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
    62
    struct addrinfo    *current_result;
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    63
};
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    64
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    65
static void     resolver_finalize            (GObject           *object);
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    66
static void     resolver_get_property        (GObject           *object,
461
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
    67
                                              guint              param_id,
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
    68
                                              GValue            *value,
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
    69
                                              GParamSpec        *pspec);
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    70
static void     resolver_set_property        (GObject           *object,
461
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
    71
                                              guint              param_id,
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
    72
                                              const GValue      *value,
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
    73
                                              GParamSpec        *pspec);
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    74
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    75
G_DEFINE_TYPE (LmResolver, lm_resolver, G_TYPE_OBJECT)
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    76
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    77
enum {
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
    78
    PROP_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
    79
    PROP_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
    80
    PROP_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
    81
    PROP_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
    82
    PROP_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
    83
    PROP_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
    84
    PROP_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
    85
    PROP_PROTOCOL
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    86
};
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    87
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    88
static void
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    89
lm_resolver_class_init (LmResolverClass *class)
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    90
{
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
    91
    GObjectClass *object_class = G_OBJECT_CLASS (class);
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    92
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
    93
    object_class->finalize     = resolver_finalize;
cdd6a0c5b439 Went 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
    object_class->get_property = resolver_get_property;
cdd6a0c5b439 Went 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
    object_class->set_property = resolver_set_property;
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
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
    g_object_class_install_property (object_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
    98
                                     PROP_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
    99
                                     g_param_spec_pointer ("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
   100
                                                           "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
   101
                                                           "Main context to use",
cdd6a0c5b439 Went 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
                                                           G_PARAM_READWRITE));
462
11f85004aa32 Added GMainContext to LmResolver and use lm_misc_add_idle to add an idle in it.
Mikael Hallendal <micke@imendio.com>
parents: 461
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
    g_object_class_install_property (object_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
   105
                                     PROP_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
   106
                                     g_param_spec_int ("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
   107
                                                       "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
   108
                                                       "Resolver 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
   109
                                                       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
   110
                                                       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
   111
                                                       LM_RESOLVER_HOST,
539
4e387d919a46 Made type property on LmResolver settable after creation.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   112
                                                       G_PARAM_READWRITE));
455
d42ef653a60c Added type property to LmResolver
Mikael Hallendal <micke@imendio.com>
parents: 454
diff changeset
   113
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
   114
    g_object_class_install_property (object_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
   115
                                     PROP_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
   116
                                     g_param_spec_string ("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
   117
                                                          "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
   118
                                                          "Host to 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
   119
                                                          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
   120
                                                          G_PARAM_READWRITE));
463
158aebfa7b7c Moved MIN_PORT and MAX_PORT to lm-internals.h and renamed them.
Mikael Hallendal <micke@imendio.com>
parents: 462
diff changeset
   121
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
   122
    g_object_class_install_property (object_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
   123
                                     PROP_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
   124
                                     g_param_spec_uint ("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
   125
                                                        "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
   126
                                                        "Port number",
cdd6a0c5b439 Went 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
                                                        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
   128
                                                        LM_MAX_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
   129
                                                        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
   130
                                                        G_PARAM_READWRITE));
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   131
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
   132
    g_object_class_install_property (object_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
   133
                                     PROP_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
   134
                                     g_param_spec_string ("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
   135
                                                          "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
   136
                                                          "Domain to 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
   137
                                                          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
   138
                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   139
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
   140
    g_object_class_install_property (object_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
   141
                                     PROP_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
   142
                                     g_param_spec_string ("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
   143
                                                          "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
   144
                                                          "Service to 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
   145
                                                          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
   146
                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
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
    g_object_class_install_property (object_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
   149
                                     PROP_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
   150
                                     g_param_spec_string ("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
   151
                                                          "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
   152
                                                          "Protocol for SRV 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
   153
                                                          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
   154
                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
461
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
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
    g_type_class_add_private (object_class, sizeof (LmResolverPriv));
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   157
}
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   158
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   159
static void
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   160
lm_resolver_init (LmResolver *resolver)
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
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
    LmResolverPriv *priv;
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
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
    priv = GET_PRIV (resolver);
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   165
}
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   166
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   167
static void
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   168
resolver_finalize (GObject *object)
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   169
{
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
   170
    LmResolverPriv *priv;
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   171
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
   172
    priv = GET_PRIV (object);
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   173
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
    g_free (priv->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
   175
    g_free (priv->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
   176
    g_free (priv->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
   177
    g_free (priv->protocol);
461
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   178
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
   179
    if (priv->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
   180
        g_main_context_unref (priv->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
   181
    }
462
11f85004aa32 Added GMainContext to LmResolver and use lm_misc_add_idle to add an idle in it.
Mikael Hallendal <micke@imendio.com>
parents: 461
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
    if (priv->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
   184
        freeaddrinfo (priv->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
   185
    }
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 474
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
    (G_OBJECT_CLASS (lm_resolver_parent_class)->finalize) (object);
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   188
}
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   189
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   190
static void
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   191
resolver_get_property (GObject    *object,
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   192
                       guint       param_id,
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   193
                       GValue     *value,
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   194
                       GParamSpec *pspec)
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
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
    LmResolverPriv *priv;
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   197
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
   198
    priv = GET_PRIV (object);
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
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
    switch (param_id) {
cdd6a0c5b439 Went 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
    case PROP_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
   202
        g_value_set_pointer (value, priv->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
   203
        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
   204
    case PROP_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
   205
        g_value_set_int (value, priv->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
   206
        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
   207
    case PROP_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
   208
        g_value_set_string (value, priv->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
   209
        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
   210
    case PROP_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
   211
        g_value_set_uint (value, priv->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
   212
        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
   213
    case PROP_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
   214
        g_value_set_string (value, priv->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
   215
        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
   216
    case PROP_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
   217
        g_value_set_string (value, priv->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
   218
        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
   219
    case PROP_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
   220
        g_value_set_string (value, priv->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
   221
        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
   222
    default:
cdd6a0c5b439 Went 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
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
cdd6a0c5b439 Went 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
        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
   225
    };
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   226
}
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   227
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   228
static void
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   229
resolver_set_property (GObject      *object,
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   230
                       guint         param_id,
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   231
                       const GValue *value,
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   232
                       GParamSpec   *pspec)
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   233
{
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
   234
    LmResolverPriv *priv;
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   235
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
   236
    priv = GET_PRIV (object);
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   237
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
   238
    switch (param_id) {
cdd6a0c5b439 Went 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
    case PROP_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
   240
        if (priv->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
   241
            g_main_context_unref (priv->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
   242
        }
462
11f85004aa32 Added GMainContext to LmResolver and use lm_misc_add_idle to add an idle in it.
Mikael Hallendal <micke@imendio.com>
parents: 461
diff changeset
   243
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
   244
        priv->context = (GMainContext *) g_value_get_pointer (value);
cdd6a0c5b439 Went 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
        g_main_context_ref (priv->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
   246
        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
   247
    case PROP_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
   248
        priv->type = g_value_get_int (value);
cdd6a0c5b439 Went 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
        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
   250
    case PROP_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
   251
        g_free (priv->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
   252
        priv->host = g_value_dup_string (value);
cdd6a0c5b439 Went 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
        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
   254
    case PROP_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
        priv->port = g_value_get_uint (value);
cdd6a0c5b439 Went 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
        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
   257
    case PROP_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
   258
        g_free (priv->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
   259
        priv->domain = g_value_dup_string (value);
cdd6a0c5b439 Went 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
        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
   261
    case PROP_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
   262
        g_free (priv->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
   263
        priv->service = g_value_dup_string (value);
cdd6a0c5b439 Went 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
        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
   265
    case PROP_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
   266
        g_free (priv->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
   267
        priv->protocol = g_value_dup_string (value);
cdd6a0c5b439 Went 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
        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
   269
    default:
cdd6a0c5b439 Went 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
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   271
        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
   272
    };
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   273
}
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   274
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   275
LmResolver *
478
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   276
lm_resolver_new (GMainContext *context)
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   277
{
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
   278
    LmResolver *resolver;
478
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   279
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 539
diff changeset
   280
#ifdef HAVE_ASYNCNS
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
   281
    resolver = g_object_new (LM_TYPE_ASYNCNS_RESOLVER, NULL);
499
1d61af397e09 Fixed compile error when asyncns is not available [#17]
Jelmer Vernooij <jelmer@samba.org>
parents: 478
diff changeset
   282
#else
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
   283
    resolver = g_object_new (LM_TYPE_BLOCKING_RESOLVER, NULL);
478
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   284
#endif
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
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_set (resolver, "context", context, NULL);
478
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   287
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
   288
    return resolver;
478
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   289
}
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   290
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 539
diff changeset
   291
static GType
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 539
diff changeset
   292
resolver_get_gtype (void)
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 539
diff changeset
   293
{
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 539
diff changeset
   294
#ifdef HAVE_ASYNCNS
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 539
diff changeset
   295
    return LM_TYPE_ASYNCNS_RESOLVER;
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 539
diff changeset
   296
#else
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 539
diff changeset
   297
    return LM_TYPE_BLOCKING_RESOLVER;
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 539
diff changeset
   298
#endif /* HAVE_ASYNCNS */
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 539
diff changeset
   299
}
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 539
diff changeset
   300
478
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   301
LmResolver *
454
18ffac09f030 Changed so that we create a resolver with various arguments depending on type.
Mikael Hallendal <micke@imendio.com>
parents: 453
diff changeset
   302
lm_resolver_new_for_host (const gchar        *host,
18ffac09f030 Changed so that we create a resolver with various arguments depending on type.
Mikael Hallendal <micke@imendio.com>
parents: 453
diff changeset
   303
                          LmResolverCallback  callback,
18ffac09f030 Changed so that we create a resolver with various arguments depending on type.
Mikael Hallendal <micke@imendio.com>
parents: 453
diff changeset
   304
                          gpointer            user_data)
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   305
{
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
   306
    LmResolver     *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
   307
    LmResolverPriv *priv;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
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_return_val_if_fail (host != NULL, 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
   310
    g_return_val_if_fail (callback != NULL, NULL);
461
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   311
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 539
diff changeset
   312
    resolver =  g_object_new (resolver_get_gtype (),
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
                              "type", 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
   314
                              "host", 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
   315
                              NULL);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   316
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
   317
    priv = GET_PRIV (resolver);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   318
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
   319
    priv->callback = callback;
cdd6a0c5b439 Went 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
    priv->user_data = user_data;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
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
    return resolver;
454
18ffac09f030 Changed so that we create a resolver with various arguments depending on type.
Mikael Hallendal <micke@imendio.com>
parents: 453
diff changeset
   323
}
18ffac09f030 Changed so that we create a resolver with various arguments depending on type.
Mikael Hallendal <micke@imendio.com>
parents: 453
diff changeset
   324
18ffac09f030 Changed so that we create a resolver with various arguments depending on type.
Mikael Hallendal <micke@imendio.com>
parents: 453
diff changeset
   325
LmResolver *
461
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   326
lm_resolver_new_for_service (const gchar        *domain, 
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   327
                             const gchar        *service,
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   328
                             const gchar        *protocol,
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   329
                             LmResolverCallback  callback,
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   330
                             gpointer            user_data)
454
18ffac09f030 Changed so that we create a resolver with various arguments depending on type.
Mikael Hallendal <micke@imendio.com>
parents: 453
diff changeset
   331
{
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
   332
    LmResolver     *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
   333
    LmResolverPriv *priv;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   334
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
   335
    g_return_val_if_fail (domain != NULL, 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
   336
    g_return_val_if_fail (service != NULL, 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
   337
    g_return_val_if_fail (protocol != NULL, 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
   338
    g_return_val_if_fail (callback != NULL, NULL);
461
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   339
547
692c7753f64e Improved the resolvers a bit.
Mikael Hallendal <micke@imendio.com>
parents: 539
diff changeset
   340
    resolver = g_object_new (resolver_get_gtype (),
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
   341
                             "type", 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
   342
                             "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
   343
                             "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
   344
                             "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
   345
                             NULL);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   346
        
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
   347
    priv = GET_PRIV (resolver);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   348
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
   349
    priv->callback = callback;
cdd6a0c5b439 Went 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
    priv->user_data = user_data;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
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
    return resolver;
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   353
}
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   354
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   355
void
454
18ffac09f030 Changed so that we create a resolver with various arguments depending on type.
Mikael Hallendal <micke@imendio.com>
parents: 453
diff changeset
   356
lm_resolver_lookup (LmResolver *resolver)
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   357
{
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
   358
    if (!LM_RESOLVER_GET_CLASS(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
   359
        g_assert_not_reached ();
cdd6a0c5b439 Went 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
    }
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   361
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
   362
    LM_RESOLVER_GET_CLASS(resolver)->lookup (resolver);
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   363
}
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   364
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   365
void
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   366
lm_resolver_cancel (LmResolver *resolver)
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   367
{
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
   368
    if (!LM_RESOLVER_GET_CLASS(resolver)->cancel) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   369
        g_assert_not_reached ();
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   370
    }
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   371
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
   372
    LM_RESOLVER_GET_CLASS(resolver)->cancel (resolver);
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   373
}
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   374
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   375
/* To iterate through the results */ 
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   376
struct addrinfo *
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   377
lm_resolver_results_get_next (LmResolver *resolver)
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   378
{
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
   379
    LmResolverPriv  *priv;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   380
    struct addrinfo *ret_val;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   381
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
   382
    g_return_val_if_fail (LM_IS_RESOLVER (resolver), NULL);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   383
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
   384
    priv = GET_PRIV (resolver);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   385
587
7c793095138e Fixed Retry Behavior, Fixed Crash on IPv6 Addresses, Log and Exit On No Host
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 549
diff changeset
   386
skipresult:
7c793095138e Fixed Retry Behavior, Fixed Crash on IPv6 Addresses, Log and Exit On No Host
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 549
diff changeset
   387
    if (!priv->current_result)
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
   388
        return NULL;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   389
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
   390
    ret_val = priv->current_result;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   391
    priv->current_result = priv->current_result->ai_next;
587
7c793095138e Fixed Retry Behavior, Fixed Crash on IPv6 Addresses, Log and Exit On No Host
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 549
diff changeset
   392
    if (ret_val->ai_family != AF_INET) /* FIXME: we only support IPv4 for now */
7c793095138e Fixed Retry Behavior, Fixed Crash on IPv6 Addresses, Log and Exit On No Host
Jayson Vantuyl <jvantuyl@engineyard.com>
parents: 549
diff changeset
   393
        goto skipresult;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   394
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
   395
    return ret_val;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   396
}
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   397
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   398
void
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   399
lm_resolver_results_reset (LmResolver *resolver)
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   400
{
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
   401
    LmResolverPriv *priv;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   402
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
   403
    g_return_if_fail (LM_IS_RESOLVER (resolver));
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   404
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
   405
    priv = GET_PRIV (resolver);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   406
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
   407
    priv->current_result = priv->results;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   408
}
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   409
478
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   410
gchar *
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   411
_lm_resolver_create_srv_string (const gchar *domain, 
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   412
                                const gchar *service,
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   413
                                const gchar *protocol)
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   414
{
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
   415
    g_return_val_if_fail (domain != NULL, 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
   416
    g_return_val_if_fail (service != NULL, 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
   417
    g_return_val_if_fail (protocol != NULL, NULL);
478
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   418
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
   419
    return g_strdup_printf ("_%s._%s.%s", service, protocol, domain);
478
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   420
}
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   421
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   422
void 
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   423
_lm_resolver_set_result (LmResolver       *resolver,
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   424
                         LmResolverResult  result,
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   425
                         struct addrinfo  *results)
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   426
{
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
   427
    LmResolverPriv *priv;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   428
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
   429
    g_return_if_fail (LM_IS_RESOLVER (resolver));
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   430
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
   431
    priv = GET_PRIV (resolver);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   432
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
   433
    priv->result = result;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   434
    priv->results = priv->current_result = results;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   435
548
60c1d6cbde10 Added some verbose debug output
Mikael Hallendal <micke@imendio.com>
parents: 547
diff changeset
   436
    lm_verbose ("Calling resolver callback: %s\n", priv->host);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   437
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
   438
    priv->callback (resolver, result, priv->user_data);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   439
}
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   440
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   441
gboolean
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   442
_lm_resolver_parse_srv_response (unsigned char  *srv, 
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   443
                                 int             srv_len, 
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   444
                                 gchar         **out_server, 
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   445
                                 guint          *out_port)
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   446
{
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
   447
    int                  qdcount;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   448
    int                  ancount;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   449
    int                  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
   450
    const unsigned char *pos;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   451
    unsigned char       *end;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   452
    HEADER              *head;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   453
    char                 name[256];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   454
    char                 pref_name[256];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   455
    guint                pref_port = 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
   456
    guint                pref_prio = 9999;
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   457
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
   458
    pref_name[0] = 0;
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   459
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
   460
    pos = srv + sizeof (HEADER);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   461
    end = srv + 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
   462
    head = (HEADER *) srv;
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   463
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
   464
    qdcount = ntohs (head->qdcount);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   465
    ancount = ntohs (head->ancount);
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   466
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
   467
    /* Ignore the questions */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   468
    while (qdcount-- > 0 && (len = dn_expand (srv, end, pos, name, 255)) >= 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
   469
        g_assert (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
   470
        pos += len + QFIXEDSZ;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   471
    }
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   472
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
   473
    /* Parse the answers */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   474
    while (ancount-- > 0 && (len = dn_expand (srv, end, pos, name, 255)) >= 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
   475
        /* Ignore the initial string */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   476
        uint16_t pref, weight, port;
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   477
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
   478
        g_assert (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
   479
        pos += 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
   480
        /* Ignore type, ttl, class and dlen */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   481
        pos += 10;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   482
        GETSHORT (pref, pos);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   483
        GETSHORT (weight, pos);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   484
        GETSHORT (port, pos);
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   485
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
   486
        len = dn_expand (srv, end, pos, name, 255);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   487
        if (pref < pref_prio) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   488
            pref_prio = pref;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   489
            strcpy (pref_name, name);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   490
            pref_port = 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
   491
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   492
        pos += 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
   493
    }
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   494
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
   495
    if (pref_name[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
   496
        *out_server = g_strdup (pref_name);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   497
        *out_port = pref_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
   498
        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
   499
    } 
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   500
    return FALSE;
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   501
}
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   502