loudmouth/lm-resolver.c
author Mikael Hallendal <micke@imendio.com>
Wed, 22 Oct 2008 14:08:45 +0200
changeset 539 4e387d919a46
parent 518 cdd6a0c5b439
child 547 692c7753f64e
permissions -rw-r--r--
Made type property on LmResolver settable after creation. Currently the type of the resolver is changed after doing the initial SRV lookup so the property can't be creation only.
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"
463
158aebfa7b7c Moved MIN_PORT and MAX_PORT to lm-internals.h and renamed them.
Mikael Hallendal <micke@imendio.com>
parents: 462
diff changeset
    35
#include "lm-internals.h"
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    36
#include "lm-marshal.h"
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    37
#include "lm-resolver.h"
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    38
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    39
#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
    40
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    41
typedef struct LmResolverPriv LmResolverPriv;
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    42
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
    43
    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
    44
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
    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
    46
    gpointer            user_data;
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    47
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
    48
    /* -- 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
    49
    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
    50
    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
    51
    guint               port;
461
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
    52
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
    53
    /* 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
    54
    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
    55
    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
    56
    gchar              *protocol;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
    57
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
    58
    /* 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
    59
    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
    60
    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
    61
    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
    62
};
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
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
    65
static void     resolver_get_property        (GObject           *object,
461
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
    66
                                              guint              param_id,
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
    67
                                              GValue            *value,
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
    68
                                              GParamSpec        *pspec);
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    69
static void     resolver_set_property        (GObject           *object,
461
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
    70
                                              guint              param_id,
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
    71
                                              const GValue      *value,
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
    72
                                              GParamSpec        *pspec);
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    73
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    74
G_DEFINE_TYPE (LmResolver, lm_resolver, G_TYPE_OBJECT)
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    75
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    76
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
    77
    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
    78
    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
    79
    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
    80
    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
    81
    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
    82
    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
    83
    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
    84
    PROP_PROTOCOL
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    85
};
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
static void
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
    88
lm_resolver_class_init (LmResolverClass *class)
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    89
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    90
    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
    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
    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
    93
    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
    94
    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
    95
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
    96
    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
    97
                                     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
    98
                                     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
    99
                                                           "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
                                                           "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
   101
                                                           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
   102
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
   103
    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
   104
                                     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
   105
                                     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
   106
                                                       "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
                                                       "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
   108
                                                       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
   109
                                                       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
   110
                                                       LM_RESOLVER_HOST,
539
4e387d919a46 Made type property on LmResolver settable after creation.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   111
                                                       G_PARAM_READWRITE));
455
d42ef653a60c Added type property to LmResolver
Mikael Hallendal <micke@imendio.com>
parents: 454
diff changeset
   112
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   113
    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
   114
                                     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
   115
                                     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
   116
                                                          "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 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
   118
                                                          NULL,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   119
                                                          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
   120
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   121
    g_object_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
   122
                                     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
   123
                                     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
   124
                                                        "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 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
   126
                                                        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
   127
                                                        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
   128
                                                        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
   129
                                                        G_PARAM_READWRITE));
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   130
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
   131
    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
   132
                                     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
   133
                                     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
   134
                                                          "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 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
   136
                                                          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
   137
                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   138
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
   139
    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
   140
                                     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
   141
                                     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
   142
                                                          "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 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
   144
                                                          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
   145
                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
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
    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
   148
                                     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
   149
                                     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
   150
                                                          "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 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
   152
                                                          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
   153
                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
461
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   154
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
   155
    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
   156
}
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   157
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   158
static void
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   159
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
   160
{
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
   161
    LmResolverPriv *priv;
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   162
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
   163
    priv = GET_PRIV (resolver);
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   164
}
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
static void
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   167
resolver_finalize (GObject *object)
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   168
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   169
    LmResolverPriv *priv;
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
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 = GET_PRIV (object);
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   172
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
   173
    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
   174
    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
   175
    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
   176
    g_free (priv->protocol);
461
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   177
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   178
    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
   179
        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
   180
    }
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
   181
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
   182
    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
   183
        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
   184
    }
476
08d36982e998 First cut of integrating the new resolver in LmOldSocket
Mikael Hallendal <micke@imendio.com>
parents: 474
diff changeset
   185
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
   186
    (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
   187
}
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
static void
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   190
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
   191
                       guint       param_id,
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   192
                       GValue     *value,
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   193
                       GParamSpec *pspec)
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   194
{
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
   195
    LmResolverPriv *priv;
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   196
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
   197
    priv = GET_PRIV (object);
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   198
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
   199
    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
   200
    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
   201
        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
   202
        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
   203
    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
   204
        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
   205
        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
   206
    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
   207
        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
   208
        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
   209
    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
   210
        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
   211
        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
   212
    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
   213
        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
   214
        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
   215
    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
   216
        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
   217
        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
   218
    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
   219
        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
   220
        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
   221
    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
   222
        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
   223
        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
   224
    };
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   225
}
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
static void
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   228
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
   229
                       guint         param_id,
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   230
                       const GValue *value,
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   231
                       GParamSpec   *pspec)
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   232
{
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
    LmResolverPriv *priv;
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
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
    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
   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
    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
   238
    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
   239
        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
   240
            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
   241
        }
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
   242
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
   243
        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
   244
        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
   245
        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
   246
    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
   247
        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
   248
        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
   249
    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
   250
        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
   251
        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
   252
        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
   253
    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
   254
        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
   255
        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
   256
    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
   257
        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
   258
        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
   259
        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
   260
    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
   261
        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
   262
        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
   263
        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
   264
    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
   265
        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
   266
        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
   267
        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
   268
    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
   269
        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
   270
        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
   271
    };
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   272
}
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
LmResolver *
478
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   275
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
   276
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   277
    LmResolver *resolver;
478
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   278
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   279
#if 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
   280
    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
   281
#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
   282
    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
   283
#endif
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   284
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
   285
    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
   286
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
   287
    return resolver;
478
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   288
}
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
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
   291
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
   292
                          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
   293
                          gpointer            user_data)
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   294
{
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
   295
    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
   296
    LmResolverPriv *priv;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   297
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
   298
    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
   299
    g_return_val_if_fail (callback != NULL, NULL);
461
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   300
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
   301
    resolver =  g_object_new (LM_TYPE_ASYNCNS_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
   302
                              "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
   303
                              "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
   304
                              NULL);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
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
    priv = GET_PRIV (resolver);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   307
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
   308
    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
   309
    priv->user_data = user_data;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   310
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
   311
    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
   312
}
18ffac09f030 Changed so that we create a resolver with various arguments depending on type.
Mikael Hallendal <micke@imendio.com>
parents: 453
diff changeset
   313
18ffac09f030 Changed so that we create a resolver with various arguments depending on type.
Mikael Hallendal <micke@imendio.com>
parents: 453
diff changeset
   314
LmResolver *
461
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   315
lm_resolver_new_for_service (const gchar        *domain, 
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   316
                             const gchar        *service,
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   317
                             const gchar        *protocol,
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   318
                             LmResolverCallback  callback,
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   319
                             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
   320
{
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
   321
    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
   322
    LmResolverPriv *priv;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   323
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
   324
    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
   325
    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
   326
    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
   327
    g_return_val_if_fail (callback != NULL, NULL);
461
f7c5f4b5dadd Added protocol for srv lookups
Mikael Hallendal <micke@imendio.com>
parents: 456
diff changeset
   328
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   329
    resolver = g_object_new (LM_TYPE_ASYNCNS_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
   330
                             "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
   331
                             "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
   332
                             "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
   333
                             "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
   334
                             NULL);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   335
        
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   336
    priv = GET_PRIV (resolver);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   337
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
   338
    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
   339
    priv->user_data = user_data;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   340
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
    return resolver;
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   342
}
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   343
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   344
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
   345
lm_resolver_lookup (LmResolver *resolver)
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
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
    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
   348
        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
   349
    }
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   350
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   351
    LM_RESOLVER_GET_CLASS(resolver)->lookup (resolver);
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   352
}
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   353
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   354
void
478
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   355
lm_resolver_lookup_host (LmResolver *resolver, const gchar *host)
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   356
{}
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   357
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   358
void
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   359
lm_resolver_lookup_srv (LmResolver *resolver, const gchar *srv)
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   360
{}
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   361
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   362
void
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   363
lm_resolver_cancel (LmResolver *resolver)
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   364
{
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
   365
    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
   366
        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
   367
    }
453
deebf7d6750b Made LmResolver an object for subclassing instead of an interface
Mikael Hallendal <micke@imendio.com>
parents: 452
diff changeset
   368
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
   369
    LM_RESOLVER_GET_CLASS(resolver)->cancel (resolver);
452
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   370
}
ad59c48027f2 Added LmResolver interface.
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   371
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   372
/* To iterate through the results */ 
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   373
struct addrinfo *
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   374
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
   375
{
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
   376
    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
   377
    struct addrinfo *ret_val;
467
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
    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
   380
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
   381
    priv = GET_PRIV (resolver);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   382
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
   383
    if (!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
   384
        return 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
   385
    }
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   386
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
   387
    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
   388
    priv->current_result = priv->current_result->ai_next;
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
    return ret_val;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   391
}
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   392
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   393
void
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   394
lm_resolver_results_reset (LmResolver *resolver)
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   395
{
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
   396
    LmResolverPriv *priv;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   397
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
   398
    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
   399
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
   400
    priv = GET_PRIV (resolver);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   401
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
   402
    priv->current_result = priv->results;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   403
}
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   404
478
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   405
gchar *
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   406
_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
   407
                                const gchar *service,
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   408
                                const gchar *protocol)
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   409
{
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
   410
    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
   411
    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
   412
    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
   413
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
   414
    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
   415
}
acce45e212a6 Changed lm_resolver_create_srv_string to be internal to LmResolvers
Mikael Hallendal <micke@imendio.com>
parents: 476
diff changeset
   416
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   417
void 
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   418
_lm_resolver_set_result (LmResolver       *resolver,
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   419
                         LmResolverResult  result,
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   420
                         struct addrinfo  *results)
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   421
{
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
   422
    LmResolverPriv *priv;
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   423
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
   424
    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
   425
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
   426
    priv = GET_PRIV (resolver);
467
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   427
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
   428
    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
   429
    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
   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
    g_print ("Calling resolver callback\n");
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->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
   434
}
943afa7cfac5 The blocking dns resolver now works as expected.
Mikael Hallendal <micke@imendio.com>
parents: 464
diff changeset
   435
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   436
gboolean
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   437
_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
   438
                                 int             srv_len, 
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   439
                                 gchar         **out_server, 
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   440
                                 guint          *out_port)
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   441
{
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
   442
    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
   443
    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
   444
    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
   445
    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
   446
    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
   447
    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
   448
    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
   449
    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
   450
    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
   451
    guint                pref_prio = 9999;
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   452
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
   453
    pref_name[0] = 0;
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   454
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
   455
    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
   456
    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
   457
    head = (HEADER *) srv;
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   458
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
   459
    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
   460
    ancount = ntohs (head->ancount);
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   461
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
   462
    /* 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
   463
    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
   464
        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
   465
        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
   466
    }
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   467
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
   468
    /* 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
   469
    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
   470
        /* 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
   471
        uint16_t pref, weight, port;
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
        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
   474
        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
   475
        /* 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
   476
        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
   477
        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
   478
        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
   479
        GETSHORT (port, pos);
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   480
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
   481
        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
   482
        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
   483
            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
   484
            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
   485
            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
   486
        }
cdd6a0c5b439 Went 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
        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
   488
    }
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   489
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
   490
    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
   491
        *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
   492
        *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
   493
        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
   494
    } 
cdd6a0c5b439 Went 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
    return FALSE;
473
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   496
}
2006c0c0a63d More work on the asyncns srv lookup.
Mikael Hallendal <micke@imendio.com>
parents: 472
diff changeset
   497