lightmelody

changeset 737:418935456927 objectify

Removing redundant DNS resolvers (functionality provided by GIO)
author Arc Riley <arcriley@gmail.com>
date Wed, 15 Oct 2014 10:44:13 +0000
parents 28da2358458b
children 42e7bc90547b
files examples/test-dns.c src/lightmelody.sym src/lm-asyncns-resolver.c src/lm-asyncns-resolver.h src/lm-blocking-resolver.c src/lm-blocking-resolver.h src/lm-resolver.c src/lm-resolver.h
diffstat 8 files changed, 0 insertions(+), 1406 deletions(-) [+]
line diff
     1.1 --- a/examples/test-dns.c	Wed Oct 15 10:35:23 2014 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,81 +0,0 @@
     1.4 -/*
     1.5 - *  Copyright (C) 2012,2013,2014 Copyleft Games Group
     1.6 - *
     1.7 - *  This program is free software; you can redistribute it and/or modify
     1.8 - *  it under the terms of the GNU Affero General Public License as published
     1.9 - *  by the Free Software Foundation, either version 3 of the License, or
    1.10 - *  (at your option) any later version.
    1.11 - *
    1.12 - *  This program is distributed in the hope that it will be useful,
    1.13 - *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 - *  GNU Affero General Public License for more details.
    1.16 - *
    1.17 - *  You should have received a copy of the GNU Affero General Public License
    1.18 - *  along with this program; if not, see http://www.gnu.org/licenses
    1.19 - *
    1.20 - */
    1.21 -
    1.22 -#include <lightmelody.h>
    1.23 -#include "lm-blocking-resolver.h"
    1.24 -
    1.25 -GMainLoop *main_loop;
    1.26 -
    1.27 -static void
    1.28 -resolver_result_cb (LmResolver       *resolver,
    1.29 -                    LmResolverResult  result,
    1.30 -                    gpointer          user_data)
    1.31 -{
    1.32 -    gchar           *host;
    1.33 -    struct addrinfo *addr;
    1.34 -
    1.35 -    g_object_get (resolver, "host", &host, NULL);
    1.36 -
    1.37 -    if (result != LM_RESOLVER_RESULT_OK) {
    1.38 -        g_print ("Failed to lookup %s\n", host);
    1.39 -        g_free (host);
    1.40 -        return;
    1.41 -    }
    1.42 -
    1.43 -    g_print ("In %s\n", G_STRFUNC);
    1.44 -
    1.45 -    while ((addr = lm_resolver_results_get_next (resolver))) {
    1.46 -        g_print ("Result!\n");
    1.47 -    }
    1.48 -
    1.49 -    g_free (host);
    1.50 -
    1.51 -    g_main_loop_quit (main_loop);
    1.52 -}
    1.53 -
    1.54 -int
    1.55 -main (int argc, char **argv)
    1.56 -{
    1.57 -#if 0
    1.58 -    LmResolver *resolver;
    1.59 -#endif
    1.60 -    LmResolver *srv_resolver;
    1.61 -
    1.62 -    g_type_init ();
    1.63 -#if 0
    1.64 -    resolver = lm_resolver_new_for_host ("kenny.imendio.com",
    1.65 -                                         resolver_result_cb,
    1.66 -                                         NULL);
    1.67 -    lm_resolver_lookup (resolver);
    1.68 -#endif
    1.69 -
    1.70 -    srv_resolver = lm_resolver_new_for_service ("jabber.org",
    1.71 -                                                "xmpp-client", "tcp",
    1.72 -                                                resolver_result_cb,
    1.73 -                                                NULL);
    1.74 -    lm_resolver_lookup (srv_resolver);
    1.75 -
    1.76 -    g_print ("Running main loop\n");
    1.77 -
    1.78 -    main_loop = g_main_loop_new (NULL, FALSE);
    1.79 -    g_main_loop_run (main_loop);
    1.80 -
    1.81 -    g_print ("Finished\n");
    1.82 -
    1.83 -    return 0;
    1.84 -}
     2.1 --- a/src/lightmelody.sym	Wed Oct 15 10:35:23 2014 +0000
     2.2 +++ b/src/lightmelody.sym	Wed Oct 15 10:44:13 2014 +0000
     2.3 @@ -1,4 +1,3 @@
     2.4 -lm_blocking_resolver_get_type
     2.5  lm_connection_authenticate
     2.6  lm_connection_authenticate_and_block
     2.7  lm_connection_cancel_open
     2.8 @@ -78,11 +77,6 @@
     2.9  lm_proxy_set_type
    2.10  lm_proxy_set_username
    2.11  lm_proxy_unref
    2.12 -lm_resolver_lookup
    2.13 -lm_resolver_new_for_host
    2.14 -lm_resolver_new_for_service
    2.15 -lm_resolver_results_get_next
    2.16 -lm_resolver_results_reset
    2.17  lm_ssl_get_fingerprint
    2.18  lm_ssl_get_require_starttls
    2.19  lm_ssl_get_use_starttls
     3.1 --- a/src/lm-asyncns-resolver.c	Wed Oct 15 10:35:23 2014 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,360 +0,0 @@
     3.4 -/*
     3.5 - *  Copyright (C) 2012,2013,2014 Copyleft Games Group
     3.6 - *  Copyright (C) 2008 Imendio AB
     3.7 - *
     3.8 - *  This program is free software; you can redistribute it and/or modify
     3.9 - *  it under the terms of the GNU Affero General Public License as published
    3.10 - *  by the Free Software Foundation, either version 3 of the License, or
    3.11 - *  (at your option) any later version.
    3.12 - *
    3.13 - *  This program is distributed in the hope that it will be useful,
    3.14 - *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.16 - *  GNU Affero General Public License for more details.
    3.17 - *
    3.18 - *  You should have received a copy of the GNU Affero General Public License
    3.19 - *  along with this program; if not, see http://www.gnu.org/licenses
    3.20 - *
    3.21 - */
    3.22 -
    3.23 -#include <config.h>
    3.24 -
    3.25 -#include <string.h>
    3.26 -#ifdef HAVE_ASYNCNS
    3.27 -#include <asyncns.h>
    3.28 -#define freeaddrinfo(x) asyncns_freeaddrinfo(x)
    3.29 -
    3.30 -/* Needed on Mac OS X */
    3.31 -#if HAVE_ARPA_NAMESER_COMPAT_H
    3.32 -#include <arpa/nameser_compat.h>
    3.33 -#endif
    3.34 -
    3.35 -#include <arpa/nameser.h>
    3.36 -#include <resolv.h>
    3.37 -
    3.38 -#include "lm-debug.h"
    3.39 -#include "lm-internals.h"
    3.40 -#include "lm-marshal.h"
    3.41 -#include "lm-misc.h"
    3.42 -#include "lm-asyncns-resolver.h"
    3.43 -
    3.44 -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), LM_TYPE_ASYNCNS_RESOLVER, LmAsyncnsResolverPriv))
    3.45 -
    3.46 -typedef struct LmAsyncnsResolverPriv LmAsyncnsResolverPriv;
    3.47 -struct LmAsyncnsResolverPriv {
    3.48 -    GSource     *watch_resolv;
    3.49 -    asyncns_query_t *resolv_query;
    3.50 -    asyncns_t   *asyncns_ctx;
    3.51 -    GIOChannel  *resolv_channel;
    3.52 -};
    3.53 -
    3.54 -static void     asyncns_resolver_finalize      (GObject     *object);
    3.55 -static void     asyncns_resolver_lookup        (LmResolver  *resolver);
    3.56 -static void     asyncns_resolver_cancel        (LmResolver  *resolver);
    3.57 -
    3.58 -G_DEFINE_TYPE (LmAsyncnsResolver, lm_asyncns_resolver, LM_TYPE_RESOLVER)
    3.59 -
    3.60 -static void
    3.61 -lm_asyncns_resolver_class_init (LmAsyncnsResolverClass *class)
    3.62 -{
    3.63 -    GObjectClass    *object_class = G_OBJECT_CLASS (class);
    3.64 -    LmResolverClass *resolver_class = LM_RESOLVER_CLASS (class);
    3.65 -
    3.66 -    object_class->finalize = asyncns_resolver_finalize;
    3.67 -
    3.68 -    resolver_class->lookup = asyncns_resolver_lookup;
    3.69 -    resolver_class->cancel = asyncns_resolver_cancel;
    3.70 -
    3.71 -    g_type_class_add_private (object_class, sizeof (LmAsyncnsResolverPriv));
    3.72 -}
    3.73 -
    3.74 -static void
    3.75 -lm_asyncns_resolver_init (LmAsyncnsResolver *asyncns_resolver)
    3.76 -{
    3.77 -    (void) GET_PRIV (asyncns_resolver);
    3.78 -}
    3.79 -
    3.80 -static void
    3.81 -asyncns_resolver_finalize (GObject *object)
    3.82 -{
    3.83 -    (void) GET_PRIV (object);
    3.84 -
    3.85 -    (G_OBJECT_CLASS (lm_asyncns_resolver_parent_class)->finalize) (object);
    3.86 -}
    3.87 -
    3.88 -static void
    3.89 -asyncns_resolver_cleanup (LmResolver *resolver)
    3.90 -{
    3.91 -    LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
    3.92 -
    3.93 -    if (priv->resolv_channel != NULL) {
    3.94 -        g_io_channel_unref (priv->resolv_channel);
    3.95 -        priv->resolv_channel = NULL;
    3.96 -    }
    3.97 -
    3.98 -    if (priv->watch_resolv) {
    3.99 -        g_source_destroy (priv->watch_resolv);
   3.100 -        priv->watch_resolv = NULL;
   3.101 -    }
   3.102 -
   3.103 -    if (priv->asyncns_ctx) {
   3.104 -        asyncns_free (priv->asyncns_ctx);
   3.105 -        priv->asyncns_ctx = NULL;
   3.106 -    }
   3.107 -
   3.108 -    priv->resolv_query = NULL;
   3.109 -}
   3.110 -
   3.111 -static void
   3.112 -asyncns_resolver_done (LmResolver *resolver)
   3.113 -{
   3.114 -    LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
   3.115 -    struct addrinfo       *ans;
   3.116 -    int                err;
   3.117 -
   3.118 -    err = asyncns_getaddrinfo_done (priv->asyncns_ctx, priv->resolv_query, &ans);
   3.119 -    priv->resolv_query = NULL;
   3.120 -    /* Signal that we are done */
   3.121 -
   3.122 -    g_object_ref (resolver);
   3.123 -
   3.124 -    if (err) {
   3.125 -        _lm_resolver_set_result (resolver,
   3.126 -                                 LM_RESOLVER_RESULT_FAILED,
   3.127 -                                 NULL);
   3.128 -    } else {
   3.129 -        _lm_resolver_set_result (resolver,
   3.130 -                                 LM_RESOLVER_RESULT_OK,
   3.131 -                                 ans);
   3.132 -    }
   3.133 -
   3.134 -    asyncns_resolver_cleanup (resolver);
   3.135 -
   3.136 -    g_object_unref (resolver);
   3.137 -}
   3.138 -
   3.139 -typedef gboolean  (* LmAsyncnsResolverCallback) (LmResolver *resolver);
   3.140 -
   3.141 -static gboolean
   3.142 -asyncns_resolver_io_cb (GSource      *source,
   3.143 -                        GIOCondition  condition,
   3.144 -                        LmResolver   *resolver)
   3.145 -{
   3.146 -    LmAsyncnsResolverPriv     *priv = GET_PRIV (resolver);
   3.147 -    LmAsyncnsResolverCallback  func;
   3.148 -
   3.149 -    asyncns_wait (priv->asyncns_ctx, FALSE);
   3.150 -
   3.151 -    if (!asyncns_isdone (priv->asyncns_ctx, priv->resolv_query)) {
   3.152 -        return TRUE;
   3.153 -    }
   3.154 -
   3.155 -    func = (LmAsyncnsResolverCallback) asyncns_getuserdata (priv->asyncns_ctx,
   3.156 -                                                            priv->resolv_query);
   3.157 -    return func (resolver);
   3.158 -}
   3.159 -
   3.160 -static gboolean
   3.161 -asyncns_resolver_prep (LmResolver *resolver, GError **error)
   3.162 -{
   3.163 -    LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
   3.164 -    GMainContext          *context;
   3.165 -
   3.166 -    if (priv->asyncns_ctx) {
   3.167 -        return TRUE;
   3.168 -    }
   3.169 -
   3.170 -    priv->asyncns_ctx = asyncns_new (1);
   3.171 -    if (priv->asyncns_ctx == NULL) {
   3.172 -        g_set_error (error,
   3.173 -                     LM_ERROR,
   3.174 -                     LM_ERROR_CONNECTION_FAILED,
   3.175 -                     "can't initialise libasyncns");
   3.176 -        return FALSE;
   3.177 -    }
   3.178 -
   3.179 -    priv->resolv_channel =
   3.180 -        g_io_channel_unix_new (asyncns_fd (priv->asyncns_ctx));
   3.181 -
   3.182 -    g_object_get (resolver, "context", &context, NULL);
   3.183 -
   3.184 -    priv->watch_resolv =
   3.185 -        lm_misc_add_io_watch (context,
   3.186 -                              priv->resolv_channel,
   3.187 -                              G_IO_IN,
   3.188 -                              (GIOFunc) asyncns_resolver_io_cb,
   3.189 -                              resolver);
   3.190 -
   3.191 -    return TRUE;
   3.192 -}
   3.193 -
   3.194 -static void
   3.195 -asyncns_resolver_lookup_host (LmResolver *resolver)
   3.196 -{
   3.197 -    LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
   3.198 -    gchar               *host;
   3.199 -    struct addrinfo      req;
   3.200 -
   3.201 -    g_object_get (resolver, "host", &host, NULL);
   3.202 -
   3.203 -    memset (&req, 0, sizeof(req));
   3.204 -    req.ai_family   = AF_UNSPEC;
   3.205 -    req.ai_socktype = SOCK_STREAM;
   3.206 -    req.ai_protocol = IPPROTO_TCP;
   3.207 -
   3.208 -    if (!asyncns_resolver_prep (resolver, NULL)) {
   3.209 -        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "Signal error\n");
   3.210 -        return;
   3.211 -    }
   3.212 -
   3.213 -    priv->resolv_query =
   3.214 -        asyncns_getaddrinfo (priv->asyncns_ctx,
   3.215 -                             host,
   3.216 -                             NULL,
   3.217 -                             &req);
   3.218 -
   3.219 -    asyncns_setuserdata (priv->asyncns_ctx,
   3.220 -                         priv->resolv_query,
   3.221 -                         (gpointer) asyncns_resolver_done);
   3.222 -}
   3.223 -
   3.224 -static void
   3.225 -asyncns_resolver_srv_done (LmResolver *resolver)
   3.226 -{
   3.227 -    LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
   3.228 -    unsigned char         *srv_ans;
   3.229 -    int                    srv_len;
   3.230 -    gboolean               result = FALSE;
   3.231 -
   3.232 -    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "srv_done callback\n");
   3.233 -
   3.234 -    srv_len = asyncns_res_done (priv->asyncns_ctx,
   3.235 -                                priv->resolv_query, &srv_ans);
   3.236 -
   3.237 -    priv->resolv_query = NULL;
   3.238 -
   3.239 -    if (srv_len <= 0) {
   3.240 -        /* FIXME: Report error */
   3.241 -        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
   3.242 -               "Failed to read srv request results");
   3.243 -    } else {
   3.244 -        gchar *new_server;
   3.245 -        guint  new_port;
   3.246 -
   3.247 -        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
   3.248 -               "trying to parse srv response\n");
   3.249 -
   3.250 -        result = _lm_resolver_parse_srv_response (srv_ans, srv_len,
   3.251 -                                                  &new_server,
   3.252 -                                                  &new_port);
   3.253 -        if (result == TRUE) {
   3.254 -            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
   3.255 -                   "worked, new host/post is %s/%d\n",
   3.256 -                   new_server, new_port);
   3.257 -
   3.258 -            g_object_set (resolver,
   3.259 -                          "host", new_server,
   3.260 -                          "port", new_port,
   3.261 -                          NULL);
   3.262 -            g_free (new_server);
   3.263 -        }
   3.264 -
   3.265 -        /* TODO: Check whether srv_ans needs freeing */
   3.266 -    }
   3.267 -
   3.268 -    asyncns_resolver_cleanup (resolver);
   3.269 -
   3.270 -    g_object_ref (resolver);
   3.271 -    if (result == TRUE) {
   3.272 -        _lm_resolver_set_result (LM_RESOLVER (resolver), LM_RESOLVER_RESULT_OK, NULL);
   3.273 -    } else {
   3.274 -        _lm_resolver_set_result (LM_RESOLVER (resolver), LM_RESOLVER_RESULT_FAILED, NULL);
   3.275 -    }
   3.276 -    g_object_unref (resolver);
   3.277 -}
   3.278 -
   3.279 -static void
   3.280 -asyncns_resolver_lookup_service (LmResolver *resolver)
   3.281 -{
   3.282 -    LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
   3.283 -    gchar                 *domain;
   3.284 -    gchar                 *service;
   3.285 -    gchar                 *protocol;
   3.286 -    gchar                 *srv;
   3.287 -
   3.288 -    g_object_get (resolver,
   3.289 -                  "domain", &domain,
   3.290 -                  "service", &service,
   3.291 -                  "protocol", &protocol,
   3.292 -                  NULL);
   3.293 -
   3.294 -    srv = _lm_resolver_create_srv_string (domain, service, protocol);
   3.295 -
   3.296 -    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
   3.297 -           "ASYNCNS: Looking up service: %s %s %s [%s]\n",
   3.298 -           domain, service, protocol, srv);
   3.299 -
   3.300 -    if (!asyncns_resolver_prep (resolver, /* Use GError? */ NULL)) {
   3.301 -        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
   3.302 -               "Failed to initiate the asyncns library");
   3.303 -        /* FIXME: Signal error */
   3.304 -        return;
   3.305 -    }
   3.306 -
   3.307 -    priv->resolv_query =
   3.308 -        asyncns_res_query (priv->asyncns_ctx, srv, C_IN, T_SRV);
   3.309 -
   3.310 -    asyncns_setuserdata (priv->asyncns_ctx,
   3.311 -                         priv->resolv_query,
   3.312 -                         (gpointer) asyncns_resolver_srv_done);
   3.313 -
   3.314 -    g_free (srv);
   3.315 -    g_free (domain);
   3.316 -    g_free (service);
   3.317 -    g_free (protocol);
   3.318 -}
   3.319 -
   3.320 -static void
   3.321 -asyncns_resolver_lookup (LmResolver *resolver)
   3.322 -{
   3.323 -    gint type;
   3.324 -
   3.325 -    /* Start the DNS querying */
   3.326 -
   3.327 -    /* Decide if we are going to lookup a srv or host */
   3.328 -    g_object_get (resolver, "type", &type, NULL);
   3.329 -
   3.330 -    switch (type) {
   3.331 -    case LM_RESOLVER_HOST:
   3.332 -        asyncns_resolver_lookup_host (resolver);
   3.333 -        break;
   3.334 -    case LM_RESOLVER_SRV:
   3.335 -        asyncns_resolver_lookup_service (resolver);
   3.336 -        break;
   3.337 -    };
   3.338 -
   3.339 -    /* End of DNS querying */
   3.340 -}
   3.341 -
   3.342 -static void
   3.343 -asyncns_resolver_cancel (LmResolver *resolver)
   3.344 -{
   3.345 -    LmAsyncnsResolverPriv *priv;
   3.346 -
   3.347 -    g_return_if_fail (LM_IS_ASYNCNS_RESOLVER (resolver));
   3.348 -
   3.349 -    priv = GET_PRIV (resolver);
   3.350 -
   3.351 -    if (priv->asyncns_ctx) {
   3.352 -        if (priv->resolv_query) {
   3.353 -            asyncns_cancel (priv->asyncns_ctx, priv->resolv_query);
   3.354 -            priv->resolv_query = NULL;
   3.355 -        }
   3.356 -
   3.357 -        _lm_resolver_set_result (resolver,
   3.358 -                                 LM_RESOLVER_RESULT_CANCELLED,
   3.359 -                                 NULL);
   3.360 -    }
   3.361 -}
   3.362 -
   3.363 -#endif //HAVE_ASYNCNS
     4.1 --- a/src/lm-asyncns-resolver.h	Wed Oct 15 10:35:23 2014 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,52 +0,0 @@
     4.4 -/*
     4.5 - *  Copyright (C) 2012,2013,2014 Copyleft Games Group
     4.6 - *  Copyright (C) 2008 Imendio AB
     4.7 - *
     4.8 - *  This program is free software; you can redistribute it and/or modify
     4.9 - *  it under the terms of the GNU Affero General Public License as published
    4.10 - *  by the Free Software Foundation, either version 3 of the License, or
    4.11 - *  (at your option) any later version.
    4.12 - *
    4.13 - *  This program is distributed in the hope that it will be useful,
    4.14 - *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.16 - *  GNU Affero General Public License for more details.
    4.17 - *
    4.18 - *  You should have received a copy of the GNU Affero General Public License
    4.19 - *  along with this program; if not, see http://www.gnu.org/licenses
    4.20 - *
    4.21 - */
    4.22 -
    4.23 -#ifndef __LM_ASYNCNS_RESOLVER_H__
    4.24 -#define __LM_ASYNCNS_RESOLVER_H__
    4.25 -
    4.26 -#include <glib-object.h>
    4.27 -
    4.28 -#include "lm-resolver.h"
    4.29 -
    4.30 -G_BEGIN_DECLS
    4.31 -
    4.32 -#define LM_TYPE_ASYNCNS_RESOLVER            (lm_asyncns_resolver_get_type ())
    4.33 -#define LM_ASYNCNS_RESOLVER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), LM_TYPE_ASYNCNS_RESOLVER, LmAsyncnsResolver))
    4.34 -#define LM_ASYNCNS_RESOLVER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), LM_TYPE_ASYNCNS_RESOLVER, LmAsyncnsResolverClass))
    4.35 -#define LM_IS_ASYNCNS_RESOLVER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LM_TYPE_ASYNCNS_RESOLVER))
    4.36 -#define LM_IS_ASYNCNS_RESOLVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LM_TYPE_ASYNCNS_RESOLVER))
    4.37 -#define LM_ASYNCNS_RESOLVER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), LM_TYPE_ASYNCNS_RESOLVER, LmAsyncnsResolverClass))
    4.38 -
    4.39 -typedef struct LmAsyncnsResolver      LmAsyncnsResolver;
    4.40 -typedef struct LmAsyncnsResolverClass LmAsyncnsResolverClass;
    4.41 -
    4.42 -struct LmAsyncnsResolver {
    4.43 -    LmResolver parent;
    4.44 -};
    4.45 -
    4.46 -struct LmAsyncnsResolverClass {
    4.47 -    LmResolverClass parent_class;
    4.48 -};
    4.49 -
    4.50 -GType   lm_asyncns_resolver_get_type  (void);
    4.51 -
    4.52 -G_END_DECLS
    4.53 -
    4.54 -#endif /* __LM_ASYNCNS_RESOLVER_H__ */
    4.55 -
     5.1 --- a/src/lm-blocking-resolver.c	Wed Oct 15 10:35:23 2014 +0000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,251 +0,0 @@
     5.4 -/*
     5.5 - *  Copyright (C) 2012,2013,2014 Copyleft Games Group
     5.6 - *  Copyright (C) 2008 Imendio AB
     5.7 - *
     5.8 - *  This program is free software; you can redistribute it and/or modify
     5.9 - *  it under the terms of the GNU Affero General Public License as published
    5.10 - *  by the Free Software Foundation, either version 3 of the License, or
    5.11 - *  (at your option) any later version.
    5.12 - *
    5.13 - *  This program is distributed in the hope that it will be useful,
    5.14 - *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.16 - *  GNU Affero General Public License for more details.
    5.17 - *
    5.18 - *  You should have received a copy of the GNU Affero General Public License
    5.19 - *  along with this program; if not, see http://www.gnu.org/licenses
    5.20 - *
    5.21 - */
    5.22 -
    5.23 -#include <config.h>
    5.24 -
    5.25 -#include <string.h>
    5.26 -#include <sys/types.h>
    5.27 -#include <netdb.h>
    5.28 -
    5.29 -/* Needed on Mac OS X */
    5.30 -#if HAVE_ARPA_NAMESER_COMPAT_H
    5.31 -#include <arpa/nameser_compat.h>
    5.32 -#endif
    5.33 -
    5.34 -#include <arpa/nameser.h>
    5.35 -#include <resolv.h>
    5.36 -
    5.37 -#include "android-resolv.h"
    5.38 -
    5.39 -#include "lm-marshal.h"
    5.40 -#include "lm-misc.h"
    5.41 -
    5.42 -#include "lm-blocking-resolver.h"
    5.43 -
    5.44 -#define SRV_LEN 8192
    5.45 -
    5.46 -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), LM_TYPE_BLOCKING_RESOLVER, LmBlockingResolverPriv))
    5.47 -
    5.48 -typedef struct LmBlockingResolverPriv LmBlockingResolverPriv;
    5.49 -struct LmBlockingResolverPriv {
    5.50 -    GSource *idle_source;
    5.51 -};
    5.52 -
    5.53 -static void     blocking_resolver_finalize    (GObject       *object);
    5.54 -static void     blocking_resolver_lookup      (LmResolver    *resolver);
    5.55 -static void     blocking_resolver_cancel      (LmResolver    *resolver);
    5.56 -
    5.57 -G_DEFINE_TYPE (LmBlockingResolver, lm_blocking_resolver, LM_TYPE_RESOLVER)
    5.58 -
    5.59 -static void
    5.60 -lm_blocking_resolver_class_init (LmBlockingResolverClass *class)
    5.61 -{
    5.62 -    GObjectClass    *object_class   = G_OBJECT_CLASS (class);
    5.63 -    LmResolverClass *resolver_class = LM_RESOLVER_CLASS (class);
    5.64 -
    5.65 -    object_class->finalize = blocking_resolver_finalize;
    5.66 -
    5.67 -    resolver_class->lookup = blocking_resolver_lookup;
    5.68 -    resolver_class->cancel = blocking_resolver_cancel;
    5.69 -
    5.70 -    g_type_class_add_private (object_class,
    5.71 -                              sizeof (LmBlockingResolverPriv));
    5.72 -}
    5.73 -
    5.74 -static void
    5.75 -lm_blocking_resolver_init (LmBlockingResolver *blocking_resolver)
    5.76 -{
    5.77 -    (void) GET_PRIV (blocking_resolver);
    5.78 -}
    5.79 -
    5.80 -static void
    5.81 -blocking_resolver_finalize (GObject *object)
    5.82 -{
    5.83 -    (void) GET_PRIV (object);
    5.84 -
    5.85 -    /* Ensure we don't have an idle around */
    5.86 -    blocking_resolver_cancel (LM_RESOLVER (object));
    5.87 -
    5.88 -    (G_OBJECT_CLASS (lm_blocking_resolver_parent_class)->finalize) (object);
    5.89 -}
    5.90 -
    5.91 -static gboolean
    5.92 -blocking_resolver_lookup_host (LmBlockingResolver *resolver)
    5.93 -{
    5.94 -    gchar           *host;
    5.95 -    struct addrinfo  req;
    5.96 -    struct addrinfo *ans;
    5.97 -    int              err;
    5.98 -    gboolean         retval = TRUE;
    5.99 -
   5.100 -    g_object_get (resolver, "host", &host, NULL);
   5.101 -
   5.102 -    /* Lookup */
   5.103 -
   5.104 -    memset (&req, 0, sizeof(req));
   5.105 -    req.ai_family   = PF_UNSPEC;
   5.106 -    req.ai_socktype = SOCK_STREAM;
   5.107 -    req.ai_protocol = IPPROTO_TCP;
   5.108 -
   5.109 -    err = getaddrinfo (host, NULL, &req, &ans);
   5.110 -
   5.111 -    if (err != 0) {
   5.112 -        _lm_resolver_set_result (LM_RESOLVER (resolver), LM_RESOLVER_RESULT_FAILED,
   5.113 -                                 NULL);
   5.114 -
   5.115 -        retval = FALSE;
   5.116 -    }
   5.117 -
   5.118 -    if (ans == NULL) {
   5.119 -        /* Couldn't find any results */
   5.120 -        g_object_ref (resolver);
   5.121 -        _lm_resolver_set_result (LM_RESOLVER (resolver), LM_RESOLVER_RESULT_FAILED,
   5.122 -                                 NULL);
   5.123 -
   5.124 -        g_object_unref (resolver);
   5.125 -        retval = FALSE;
   5.126 -    }
   5.127 -
   5.128 -    /* FIXME: How to set and iterate the results */
   5.129 -    /*priv->results    = ans;
   5.130 -      priv->cur_result = ans; */
   5.131 -
   5.132 -    if (retval) {
   5.133 -        g_object_ref (resolver);
   5.134 -
   5.135 -        _lm_resolver_set_result (LM_RESOLVER (resolver), LM_RESOLVER_RESULT_OK,
   5.136 -                                 ans);
   5.137 -
   5.138 -        g_object_unref (resolver);
   5.139 -    }
   5.140 -
   5.141 -    g_free (host);
   5.142 -
   5.143 -    return retval;
   5.144 -}
   5.145 -
   5.146 -static gboolean
   5.147 -blocking_resolver_lookup_service (LmBlockingResolver *resolver)
   5.148 -{
   5.149 -    gchar *domain;
   5.150 -    gchar *service;
   5.151 -    gchar *protocol;
   5.152 -    gchar *srv;
   5.153 -    gchar *new_server = NULL;
   5.154 -    guint  new_port = 0;
   5.155 -    gboolean  result;
   5.156 -    unsigned char    srv_ans[SRV_LEN];
   5.157 -    int              len;
   5.158 -    gboolean         retval = TRUE;
   5.159 -
   5.160 -    g_object_get (resolver,
   5.161 -                  "domain", &domain,
   5.162 -                  "service", &service,
   5.163 -                  "protocol", &protocol,
   5.164 -                  NULL);
   5.165 -
   5.166 -    srv = _lm_resolver_create_srv_string (domain, service, protocol);
   5.167 -
   5.168 -    res_init ();
   5.169 -
   5.170 -    len = res_query (srv, C_IN, T_SRV, srv_ans, SRV_LEN);
   5.171 -
   5.172 -    result = _lm_resolver_parse_srv_response (srv_ans, len,
   5.173 -                                              &new_server, &new_port);
   5.174 -    if (result == FALSE) {
   5.175 -        retval = FALSE;
   5.176 -    }
   5.177 -
   5.178 -    g_object_set (resolver,
   5.179 -                  "host", new_server,
   5.180 -                  "port", new_port,
   5.181 -                  NULL);
   5.182 -
   5.183 -    g_object_ref (resolver);
   5.184 -    _lm_resolver_set_result (LM_RESOLVER (resolver), LM_RESOLVER_RESULT_OK, NULL);
   5.185 -    g_object_unref (resolver);
   5.186 -
   5.187 -    /* Lookup the new server and the new port */
   5.188 -   /* blocking_resolver_lookup_host (resolver); */
   5.189 -
   5.190 -    g_free (new_server);
   5.191 -    g_free (srv);
   5.192 -    g_free (domain);
   5.193 -    g_free (service);
   5.194 -    g_free (protocol);
   5.195 -
   5.196 -    return retval;
   5.197 -}
   5.198 -
   5.199 -static gboolean
   5.200 -blocking_resolver_idle_lookup (LmBlockingResolver *resolver)
   5.201 -{
   5.202 -    LmBlockingResolverPriv *priv = GET_PRIV (resolver);
   5.203 -    gint                    type;
   5.204 -
   5.205 -    /* Start the DNS querying */
   5.206 -
   5.207 -    /* Decide if we are going to lookup a srv or host */
   5.208 -    g_object_get (resolver, "type", &type, NULL);
   5.209 -
   5.210 -    switch (type) {
   5.211 -    case LM_RESOLVER_HOST:
   5.212 -        blocking_resolver_lookup_host (resolver);
   5.213 -        break;
   5.214 -    case LM_RESOLVER_SRV:
   5.215 -        blocking_resolver_lookup_service (resolver);
   5.216 -        break;
   5.217 -    };
   5.218 -
   5.219 -    /* End of DNS querying */
   5.220 -    priv->idle_source = NULL;
   5.221 -    return FALSE;
   5.222 -}
   5.223 -
   5.224 -static void
   5.225 -blocking_resolver_lookup (LmResolver *resolver)
   5.226 -{
   5.227 -    LmBlockingResolverPriv *priv;
   5.228 -    GMainContext           *context;
   5.229 -
   5.230 -    g_return_if_fail (LM_IS_BLOCKING_RESOLVER (resolver));
   5.231 -
   5.232 -    priv = GET_PRIV (resolver);
   5.233 -
   5.234 -    g_object_get (resolver, "context", &context, NULL);
   5.235 -
   5.236 -    priv->idle_source = lm_misc_add_idle (context,
   5.237 -                                          (GSourceFunc) blocking_resolver_idle_lookup,
   5.238 -                                          resolver);
   5.239 -}
   5.240 -
   5.241 -static void
   5.242 -blocking_resolver_cancel (LmResolver *resolver)
   5.243 -{
   5.244 -    LmBlockingResolverPriv *priv;
   5.245 -
   5.246 -    g_return_if_fail (LM_IS_BLOCKING_RESOLVER (resolver));
   5.247 -
   5.248 -    priv = GET_PRIV (resolver);
   5.249 -
   5.250 -    if (priv->idle_source) {
   5.251 -        g_source_destroy (priv->idle_source);
   5.252 -        priv->idle_source = NULL;
   5.253 -    }
   5.254 -}
     6.1 --- a/src/lm-blocking-resolver.h	Wed Oct 15 10:35:23 2014 +0000
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,52 +0,0 @@
     6.4 -/*
     6.5 - *  Copyright (C) 2012,2013,2014 Copyleft Games Group
     6.6 - *  Copyright (C) 2008 Imendio AB
     6.7 - *
     6.8 - *  This program is free software; you can redistribute it and/or modify
     6.9 - *  it under the terms of the GNU Affero General Public License as published
    6.10 - *  by the Free Software Foundation, either version 3 of the License, or
    6.11 - *  (at your option) any later version.
    6.12 - *
    6.13 - *  This program is distributed in the hope that it will be useful,
    6.14 - *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.16 - *  GNU Affero General Public License for more details.
    6.17 - *
    6.18 - *  You should have received a copy of the GNU Affero General Public License
    6.19 - *  along with this program; if not, see http://www.gnu.org/licenses
    6.20 - *
    6.21 - */
    6.22 -
    6.23 -#ifndef __LM_BLOCKING_RESOLVER_H__
    6.24 -#define __LM_BLOCKING_RESOLVER_H__
    6.25 -
    6.26 -#include <glib-object.h>
    6.27 -
    6.28 -#include "lm-resolver.h"
    6.29 -
    6.30 -G_BEGIN_DECLS
    6.31 -
    6.32 -#define LM_TYPE_BLOCKING_RESOLVER            (lm_blocking_resolver_get_type ())
    6.33 -#define LM_BLOCKING_RESOLVER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), LM_TYPE_BLOCKING_RESOLVER, LmBlockingResolver))
    6.34 -#define LM_BLOCKING_RESOLVER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), LM_TYPE_BLOCKING_RESOLVER, LmBlockingResolverClass))
    6.35 -#define LM_IS_BLOCKING_RESOLVER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LM_TYPE_BLOCKING_RESOLVER))
    6.36 -#define LM_IS_BLOCKING_RESOLVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LM_TYPE_BLOCKING_RESOLVER))
    6.37 -#define LM_BLOCKING_RESOLVER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), LM_TYPE_BLOCKING_RESOLVER, LmBlockingResolverClass))
    6.38 -
    6.39 -typedef struct LmBlockingResolver      LmBlockingResolver;
    6.40 -typedef struct LmBlockingResolverClass LmBlockingResolverClass;
    6.41 -
    6.42 -struct LmBlockingResolver {
    6.43 -    LmResolver parent;
    6.44 -};
    6.45 -
    6.46 -struct LmBlockingResolverClass {
    6.47 -    LmResolverClass parent_class;
    6.48 -};
    6.49 -
    6.50 -GType   lm_blocking_resolver_get_type  (void);
    6.51 -
    6.52 -G_END_DECLS
    6.53 -
    6.54 -#endif /* __LM_BLOCKING_RESOLVER_H__ */
    6.55 -
     7.1 --- a/src/lm-resolver.c	Wed Oct 15 10:35:23 2014 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,507 +0,0 @@
     7.4 -/*
     7.5 - *  Copyright (C) 2012,2013,2014 Copyleft Games Group
     7.6 - *  Copyright (C) 2008 Imendio AB
     7.7 - *
     7.8 - *  This program is free software; you can redistribute it and/or modify
     7.9 - *  it under the terms of the GNU Affero General Public License as published
    7.10 - *  by the Free Software Foundation, either version 3 of the License, or
    7.11 - *  (at your option) any later version.
    7.12 - *
    7.13 - *  This program is distributed in the hope that it will be useful,
    7.14 - *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    7.16 - *  GNU Affero General Public License for more details.
    7.17 - *
    7.18 - *  You should have received a copy of the GNU Affero General Public License
    7.19 - *  along with this program; if not, see http://www.gnu.org/licenses
    7.20 - *
    7.21 - */
    7.22 -
    7.23 -#include <config.h>
    7.24 -
    7.25 -#include <string.h>
    7.26 -
    7.27 -/* Needed on Mac OS X */
    7.28 -#if HAVE_ARPA_NAMESER_COMPAT_H
    7.29 -#include <arpa/nameser_compat.h>
    7.30 -#endif
    7.31 -
    7.32 -#include <arpa/nameser.h>
    7.33 -#include <resolv.h>
    7.34 -
    7.35 -#include "android-resolv.h"
    7.36 -
    7.37 -#include "lm-asyncns-resolver.h"
    7.38 -#include "lm-blocking-resolver.h"
    7.39 -#include "lm-debug.h"
    7.40 -#include "lm-internals.h"
    7.41 -#include "lm-marshal.h"
    7.42 -#include "lm-resolver.h"
    7.43 -
    7.44 -#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), LM_TYPE_RESOLVER, LmResolverPriv))
    7.45 -
    7.46 -typedef struct LmResolverPriv LmResolverPriv;
    7.47 -struct LmResolverPriv {
    7.48 -    GMainContext       *context;
    7.49 -
    7.50 -    LmResolverCallback  callback;
    7.51 -    gpointer            user_data;
    7.52 -
    7.53 -    /* -- Properties -- */
    7.54 -    LmResolverType      type;
    7.55 -    gchar              *host;
    7.56 -    guint               port;
    7.57 -
    7.58 -    /* For SRV lookups */
    7.59 -    gchar              *domain;
    7.60 -    gchar              *service;
    7.61 -    gchar              *protocol;
    7.62 -
    7.63 -    /* The results */
    7.64 -    LmResolverResult    result;
    7.65 -    struct addrinfo    *results;
    7.66 -    struct addrinfo    *current_result;
    7.67 -};
    7.68 -
    7.69 -static void     resolver_finalize            (GObject           *object);
    7.70 -static void     resolver_get_property        (GObject           *object,
    7.71 -                                              guint              param_id,
    7.72 -                                              GValue            *value,
    7.73 -                                              GParamSpec        *pspec);
    7.74 -static void     resolver_set_property        (GObject           *object,
    7.75 -                                              guint              param_id,
    7.76 -                                              const GValue      *value,
    7.77 -                                              GParamSpec        *pspec);
    7.78 -
    7.79 -G_DEFINE_TYPE (LmResolver, lm_resolver, G_TYPE_OBJECT)
    7.80 -
    7.81 -enum {
    7.82 -    PROP_0,
    7.83 -    PROP_CONTEXT,
    7.84 -    PROP_TYPE,
    7.85 -    PROP_HOST,
    7.86 -    PROP_PORT,
    7.87 -    PROP_DOMAIN,
    7.88 -    PROP_SERVICE,
    7.89 -    PROP_PROTOCOL
    7.90 -};
    7.91 -
    7.92 -static void
    7.93 -lm_resolver_class_init (LmResolverClass *class)
    7.94 -{
    7.95 -    GObjectClass *object_class = G_OBJECT_CLASS (class);
    7.96 -
    7.97 -    object_class->finalize     = resolver_finalize;
    7.98 -    object_class->get_property = resolver_get_property;
    7.99 -    object_class->set_property = resolver_set_property;
   7.100 -
   7.101 -    g_object_class_install_property (object_class,
   7.102 -                                     PROP_CONTEXT,
   7.103 -                                     g_param_spec_pointer ("context",
   7.104 -                                                           "Context",
   7.105 -                                                           "Main context to use",
   7.106 -                                                           G_PARAM_READWRITE));
   7.107 -
   7.108 -    g_object_class_install_property (object_class,
   7.109 -                                     PROP_TYPE,
   7.110 -                                     g_param_spec_int ("type",
   7.111 -                                                       "Type",
   7.112 -                                                       "Resolver Type",
   7.113 -                                                       LM_RESOLVER_HOST,
   7.114 -                                                       LM_RESOLVER_SRV,
   7.115 -                                                       LM_RESOLVER_HOST,
   7.116 -                                                       G_PARAM_READWRITE));
   7.117 -
   7.118 -    g_object_class_install_property (object_class,
   7.119 -                                     PROP_HOST,
   7.120 -                                     g_param_spec_string ("host",
   7.121 -                                                          "Host",
   7.122 -                                                          "Host to lookup",
   7.123 -                                                          NULL,
   7.124 -                                                          G_PARAM_READWRITE));
   7.125 -
   7.126 -    g_object_class_install_property (object_class,
   7.127 -                                     PROP_PORT,
   7.128 -                                     g_param_spec_uint ("port",
   7.129 -                                                        "Port",
   7.130 -                                                        "Port number",
   7.131 -                                                        0,
   7.132 -                                                        LM_MAX_PORT,
   7.133 -                                                        0,
   7.134 -                                                        G_PARAM_READWRITE));
   7.135 -
   7.136 -    g_object_class_install_property (object_class,
   7.137 -                                     PROP_DOMAIN,
   7.138 -                                     g_param_spec_string ("domain",
   7.139 -                                                          "Domain",
   7.140 -                                                          "Domain to lookup",
   7.141 -                                                          NULL,
   7.142 -                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
   7.143 -
   7.144 -    g_object_class_install_property (object_class,
   7.145 -                                     PROP_SERVICE,
   7.146 -                                     g_param_spec_string ("service",
   7.147 -                                                          "Service",
   7.148 -                                                          "Service to lookup",
   7.149 -                                                          NULL,
   7.150 -                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
   7.151 -
   7.152 -    g_object_class_install_property (object_class,
   7.153 -                                     PROP_PROTOCOL,
   7.154 -                                     g_param_spec_string ("protocol",
   7.155 -                                                          "Protocol",
   7.156 -                                                          "Protocol for SRV lookup",
   7.157 -                                                          NULL,
   7.158 -                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
   7.159 -
   7.160 -    g_type_class_add_private (object_class, sizeof (LmResolverPriv));
   7.161 -}
   7.162 -
   7.163 -static void
   7.164 -lm_resolver_init (LmResolver *resolver)
   7.165 -{
   7.166 -    (void) GET_PRIV (resolver);
   7.167 -}
   7.168 -
   7.169 -static void
   7.170 -resolver_finalize (GObject *object)
   7.171 -{
   7.172 -    LmResolverPriv *priv;
   7.173 -
   7.174 -    priv = GET_PRIV (object);
   7.175 -
   7.176 -    g_free (priv->host);
   7.177 -    g_free (priv->domain);
   7.178 -    g_free (priv->service);
   7.179 -    g_free (priv->protocol);
   7.180 -
   7.181 -    if (priv->context) {
   7.182 -        g_main_context_unref (priv->context);
   7.183 -    }
   7.184 -
   7.185 -    if (priv->results) {
   7.186 -        freeaddrinfo (priv->results);
   7.187 -    }
   7.188 -
   7.189 -    (G_OBJECT_CLASS (lm_resolver_parent_class)->finalize) (object);
   7.190 -}
   7.191 -
   7.192 -static void
   7.193 -resolver_get_property (GObject    *object,
   7.194 -                       guint       param_id,
   7.195 -                       GValue     *value,
   7.196 -                       GParamSpec *pspec)
   7.197 -{
   7.198 -    LmResolverPriv *priv;
   7.199 -
   7.200 -    priv = GET_PRIV (object);
   7.201 -
   7.202 -    switch (param_id) {
   7.203 -    case PROP_CONTEXT:
   7.204 -        g_value_set_pointer (value, priv->context);
   7.205 -        break;
   7.206 -    case PROP_TYPE:
   7.207 -        g_value_set_int (value, priv->type);
   7.208 -        break;
   7.209 -    case PROP_HOST:
   7.210 -        g_value_set_string (value, priv->host);
   7.211 -        break;
   7.212 -    case PROP_PORT:
   7.213 -        g_value_set_uint (value, priv->port);
   7.214 -        break;
   7.215 -    case PROP_DOMAIN:
   7.216 -        g_value_set_string (value, priv->domain);
   7.217 -        break;
   7.218 -    case PROP_SERVICE:
   7.219 -        g_value_set_string (value, priv->service);
   7.220 -        break;
   7.221 -    case PROP_PROTOCOL:
   7.222 -        g_value_set_string (value, priv->protocol);
   7.223 -        break;
   7.224 -    default:
   7.225 -        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
   7.226 -        break;
   7.227 -    };
   7.228 -}
   7.229 -
   7.230 -static void
   7.231 -resolver_set_property (GObject      *object,
   7.232 -                       guint         param_id,
   7.233 -                       const GValue *value,
   7.234 -                       GParamSpec   *pspec)
   7.235 -{
   7.236 -    LmResolverPriv *priv;
   7.237 -
   7.238 -    priv = GET_PRIV (object);
   7.239 -
   7.240 -    switch (param_id) {
   7.241 -    case PROP_CONTEXT:
   7.242 -        if (priv->context) {
   7.243 -            g_main_context_unref (priv->context);
   7.244 -        }
   7.245 -
   7.246 -        priv->context = (GMainContext *) g_value_get_pointer (value);
   7.247 -        g_main_context_ref (priv->context);
   7.248 -        break;
   7.249 -    case PROP_TYPE:
   7.250 -        priv->type = g_value_get_int (value);
   7.251 -        break;
   7.252 -    case PROP_HOST:
   7.253 -        g_free (priv->host);
   7.254 -        priv->host = g_value_dup_string (value);
   7.255 -        break;
   7.256 -    case PROP_PORT:
   7.257 -        priv->port = g_value_get_uint (value);
   7.258 -        break;
   7.259 -    case PROP_DOMAIN:
   7.260 -        g_free (priv->domain);
   7.261 -        priv->domain = g_value_dup_string (value);
   7.262 -        break;
   7.263 -    case PROP_SERVICE:
   7.264 -        g_free (priv->service);
   7.265 -        priv->service = g_value_dup_string (value);
   7.266 -        break;
   7.267 -    case PROP_PROTOCOL:
   7.268 -        g_free (priv->protocol);
   7.269 -        priv->protocol = g_value_dup_string (value);
   7.270 -        break;
   7.271 -    default:
   7.272 -        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
   7.273 -        break;
   7.274 -    };
   7.275 -}
   7.276 -
   7.277 -LmResolver *
   7.278 -lm_resolver_new (GMainContext *context)
   7.279 -{
   7.280 -    LmResolver *resolver;
   7.281 -
   7.282 -#ifdef HAVE_ASYNCNS
   7.283 -    resolver = g_object_new (LM_TYPE_ASYNCNS_RESOLVER, NULL);
   7.284 -#else
   7.285 -    resolver = g_object_new (LM_TYPE_BLOCKING_RESOLVER, NULL);
   7.286 -#endif
   7.287 -
   7.288 -    g_object_set (resolver, "context", context, NULL);
   7.289 -
   7.290 -    return resolver;
   7.291 -}
   7.292 -
   7.293 -static GType
   7.294 -resolver_get_gtype (void)
   7.295 -{
   7.296 -#ifdef HAVE_ASYNCNS
   7.297 -    return LM_TYPE_ASYNCNS_RESOLVER;
   7.298 -#else
   7.299 -    return LM_TYPE_BLOCKING_RESOLVER;
   7.300 -#endif /* HAVE_ASYNCNS */
   7.301 -}
   7.302 -
   7.303 -LmResolver *
   7.304 -lm_resolver_new_for_host (const gchar        *host,
   7.305 -                          LmResolverCallback  callback,
   7.306 -                          gpointer            user_data)
   7.307 -{
   7.308 -    LmResolver     *resolver;
   7.309 -    LmResolverPriv *priv;
   7.310 -
   7.311 -    g_return_val_if_fail (host != NULL, NULL);
   7.312 -    g_return_val_if_fail (callback != NULL, NULL);
   7.313 -
   7.314 -    resolver =  g_object_new (resolver_get_gtype (),
   7.315 -                              "type", LM_RESOLVER_HOST,
   7.316 -                              "host", host,
   7.317 -                              NULL);
   7.318 -
   7.319 -    priv = GET_PRIV (resolver);
   7.320 -
   7.321 -    priv->callback = callback;
   7.322 -    priv->user_data = user_data;
   7.323 -
   7.324 -    return resolver;
   7.325 -}
   7.326 -
   7.327 -LmResolver *
   7.328 -lm_resolver_new_for_service (const gchar        *domain,
   7.329 -                             const gchar        *service,
   7.330 -                             const gchar        *protocol,
   7.331 -                             LmResolverCallback  callback,
   7.332 -                             gpointer            user_data)
   7.333 -{
   7.334 -    LmResolver     *resolver;
   7.335 -    LmResolverPriv *priv;
   7.336 -
   7.337 -    g_return_val_if_fail (domain != NULL, NULL);
   7.338 -    g_return_val_if_fail (service != NULL, NULL);
   7.339 -    g_return_val_if_fail (protocol != NULL, NULL);
   7.340 -    g_return_val_if_fail (callback != NULL, NULL);
   7.341 -
   7.342 -    resolver = g_object_new (resolver_get_gtype (),
   7.343 -                             "type", LM_RESOLVER_SRV,
   7.344 -                             "domain", domain,
   7.345 -                             "service", service,
   7.346 -                             "protocol", protocol,
   7.347 -                             NULL);
   7.348 -
   7.349 -    priv = GET_PRIV (resolver);
   7.350 -
   7.351 -    priv->callback = callback;
   7.352 -    priv->user_data = user_data;
   7.353 -
   7.354 -    return resolver;
   7.355 -}
   7.356 -
   7.357 -void
   7.358 -lm_resolver_lookup (LmResolver *resolver)
   7.359 -{
   7.360 -    if (!LM_RESOLVER_GET_CLASS(resolver)) {
   7.361 -        g_assert_not_reached ();
   7.362 -    }
   7.363 -
   7.364 -    LM_RESOLVER_GET_CLASS(resolver)->lookup (resolver);
   7.365 -}
   7.366 -
   7.367 -void
   7.368 -lm_resolver_cancel (LmResolver *resolver)
   7.369 -{
   7.370 -    if (!LM_RESOLVER_GET_CLASS(resolver)->cancel) {
   7.371 -        g_assert_not_reached ();
   7.372 -    }
   7.373 -
   7.374 -    LM_RESOLVER_GET_CLASS(resolver)->cancel (resolver);
   7.375 -}
   7.376 -
   7.377 -/* To iterate through the results */
   7.378 -struct addrinfo *
   7.379 -lm_resolver_results_get_next (LmResolver *resolver)
   7.380 -{
   7.381 -    LmResolverPriv  *priv;
   7.382 -    struct addrinfo *ret_val;
   7.383 -
   7.384 -    g_return_val_if_fail (LM_IS_RESOLVER (resolver), NULL);
   7.385 -
   7.386 -    priv = GET_PRIV (resolver);
   7.387 -
   7.388 -skipresult:
   7.389 -    if (!priv->current_result) {
   7.390 -        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
   7.391 -               "no more results from resolver\n");
   7.392 -        return NULL;
   7.393 -    };
   7.394 -
   7.395 -    ret_val = priv->current_result;
   7.396 -    priv->current_result = priv->current_result->ai_next;
   7.397 -    if (ret_val->ai_family != AF_INET) {
   7.398 -        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_VERBOSE,
   7.399 -               "skipping non-IPv4 resolver entry\n");
   7.400 -        goto skipresult;
   7.401 -    };
   7.402 -
   7.403 -    return ret_val;
   7.404 -}
   7.405 -
   7.406 -void
   7.407 -lm_resolver_results_reset (LmResolver *resolver)
   7.408 -{
   7.409 -    LmResolverPriv *priv;
   7.410 -
   7.411 -    g_return_if_fail (LM_IS_RESOLVER (resolver));
   7.412 -
   7.413 -    priv = GET_PRIV (resolver);
   7.414 -
   7.415 -    priv->current_result = priv->results;
   7.416 -}
   7.417 -
   7.418 -gchar *
   7.419 -_lm_resolver_create_srv_string (const gchar *domain,
   7.420 -                                const gchar *service,
   7.421 -                                const gchar *protocol)
   7.422 -{
   7.423 -    g_return_val_if_fail (domain != NULL, NULL);
   7.424 -    g_return_val_if_fail (service != NULL, NULL);
   7.425 -    g_return_val_if_fail (protocol != NULL, NULL);
   7.426 -
   7.427 -    return g_strdup_printf ("_%s._%s.%s", service, protocol, domain);
   7.428 -}
   7.429 -
   7.430 -void
   7.431 -_lm_resolver_set_result (LmResolver       *resolver,
   7.432 -                         LmResolverResult  result,
   7.433 -                         struct addrinfo  *results)
   7.434 -{
   7.435 -    LmResolverPriv *priv;
   7.436 -
   7.437 -    g_return_if_fail (LM_IS_RESOLVER (resolver));
   7.438 -
   7.439 -    priv = GET_PRIV (resolver);
   7.440 -
   7.441 -    priv->result = result;
   7.442 -    priv->results = priv->current_result = results;
   7.443 -
   7.444 -    lm_verbose ("Calling resolver callback: %s\n", priv->host);
   7.445 -
   7.446 -    priv->callback (resolver, result, priv->user_data);
   7.447 -}
   7.448 -
   7.449 -gboolean
   7.450 -_lm_resolver_parse_srv_response (unsigned char  *srv,
   7.451 -                                 int             srv_len,
   7.452 -                                 gchar         **out_server,
   7.453 -                                 guint          *out_port)
   7.454 -{
   7.455 -    int                  qdcount;
   7.456 -    int                  ancount;
   7.457 -    int                  len;
   7.458 -    const unsigned char *pos;
   7.459 -    unsigned char       *end;
   7.460 -    HEADER              *head;
   7.461 -    char                 name[256];
   7.462 -    char                 pref_name[256];
   7.463 -    guint                pref_port = 0;
   7.464 -    guint                pref_prio = 9999;
   7.465 -
   7.466 -    pref_name[0] = 0;
   7.467 -
   7.468 -    pos = srv + sizeof (HEADER);
   7.469 -    end = srv + srv_len;
   7.470 -    head = (HEADER *) srv;
   7.471 -
   7.472 -    qdcount = ntohs (head->qdcount);
   7.473 -    ancount = ntohs (head->ancount);
   7.474 -
   7.475 -    /* Ignore the questions */
   7.476 -    while (qdcount-- > 0 && (len = dn_expand (srv, end, pos, name, 255)) >= 0) {
   7.477 -        g_assert (len >= 0);
   7.478 -        pos += len + QFIXEDSZ;
   7.479 -    }
   7.480 -
   7.481 -    /* Parse the answers */
   7.482 -    while (ancount-- > 0 && (len = dn_expand (srv, end, pos, name, 255)) >= 0) {
   7.483 -        /* Ignore the initial string */
   7.484 -        uint16_t pref, weight, port;
   7.485 -
   7.486 -        g_assert (len >= 0);
   7.487 -        pos += len;
   7.488 -        /* Ignore type, ttl, class and dlen */
   7.489 -        pos += 10;
   7.490 -        GETSHORT (pref, pos);
   7.491 -        GETSHORT (weight, pos);
   7.492 -        GETSHORT (port, pos);
   7.493 -
   7.494 -        len = dn_expand (srv, end, pos, name, 255);
   7.495 -        if (pref < pref_prio) {
   7.496 -            pref_prio = pref;
   7.497 -            strcpy (pref_name, name);
   7.498 -            pref_port = port;
   7.499 -        }
   7.500 -        pos += len;
   7.501 -    }
   7.502 -
   7.503 -    if (pref_name[0]) {
   7.504 -        *out_server = g_strdup (pref_name);
   7.505 -        *out_port = pref_port;
   7.506 -        return TRUE;
   7.507 -    }
   7.508 -    return FALSE;
   7.509 -}
   7.510 -
     8.1 --- a/src/lm-resolver.h	Wed Oct 15 10:35:23 2014 +0000
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,97 +0,0 @@
     8.4 -/*
     8.5 - *  Copyright (C) 2012,2013,2014 Copyleft Games Group
     8.6 - *  Copyright (C) 2008 Imendio AB
     8.7 - *
     8.8 - *  This program is free software; you can redistribute it and/or modify
     8.9 - *  it under the terms of the GNU Affero General Public License as published
    8.10 - *  by the Free Software Foundation, either version 3 of the License, or
    8.11 - *  (at your option) any later version.
    8.12 - *
    8.13 - *  This program is distributed in the hope that it will be useful,
    8.14 - *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.16 - *  GNU Affero General Public License for more details.
    8.17 - *
    8.18 - *  You should have received a copy of the GNU Affero General Public License
    8.19 - *  along with this program; if not, see http://www.gnu.org/licenses
    8.20 - *
    8.21 - */
    8.22 -
    8.23 -#ifndef __LM_RESOLVER_H__
    8.24 -#define __LM_RESOLVER_H__
    8.25 -
    8.26 -#include <glib-object.h>
    8.27 -
    8.28 -G_BEGIN_DECLS
    8.29 -
    8.30 -#define LM_TYPE_RESOLVER            (lm_resolver_get_type ())
    8.31 -#define LM_RESOLVER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), LM_TYPE_RESOLVER, LmResolver))
    8.32 -#define LM_RESOLVER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), LM_TYPE_RESOLVER, LmResolverClass))
    8.33 -#define LM_IS_RESOLVER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LM_TYPE_RESOLVER))
    8.34 -#define LM_IS_RESOLVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LM_TYPE_RESOLVER))
    8.35 -#define LM_RESOLVER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), LM_TYPE_RESOLVER, LmResolverClass))
    8.36 -
    8.37 -typedef struct LmResolver      LmResolver;
    8.38 -typedef struct LmResolverClass LmResolverClass;
    8.39 -
    8.40 -struct LmResolver {
    8.41 -    GObject parent;
    8.42 -};
    8.43 -
    8.44 -struct LmResolverClass {
    8.45 -    GObjectClass parent_class;
    8.46 -
    8.47 -    /* <vtable> */
    8.48 -    void (*lookup)  (LmResolver  *resolver);
    8.49 -    void (*cancel)  (LmResolver  *resolver);
    8.50 -};
    8.51 -
    8.52 -typedef enum {
    8.53 -    LM_RESOLVER_HOST,
    8.54 -    LM_RESOLVER_SRV
    8.55 -} LmResolverType;
    8.56 -
    8.57 -typedef enum {
    8.58 -    LM_RESOLVER_RESULT_OK,
    8.59 -    LM_RESOLVER_RESULT_FAILED,
    8.60 -    LM_RESOLVER_RESULT_CANCELLED
    8.61 -} LmResolverResult;
    8.62 -
    8.63 -typedef void (*LmResolverCallback) (LmResolver       *resolver,
    8.64 -                                    LmResolverResult  result,
    8.65 -                                    gpointer          user_data);
    8.66 -
    8.67 -GType             lm_resolver_get_type          (void);
    8.68 -LmResolver *      lm_resolver_new               (GMainContext       *context);
    8.69 -
    8.70 -LmResolver *      lm_resolver_new_for_host      (const gchar        *host,
    8.71 -                                                 LmResolverCallback  callback,
    8.72 -                                                 gpointer            user_data);
    8.73 -LmResolver *      lm_resolver_new_for_service   (const gchar        *domain,
    8.74 -                                                 const gchar        *service,
    8.75 -                                                 const gchar        *protocol,
    8.76 -                                                 LmResolverCallback  callback,
    8.77 -                                                 gpointer            user_data);
    8.78 -void              lm_resolver_lookup            (LmResolver         *resolver);
    8.79 -void              lm_resolver_cancel            (LmResolver         *resolver);
    8.80 -/* To iterate through the results */
    8.81 -struct addrinfo * lm_resolver_results_get_next  (LmResolver         *resolver);
    8.82 -void              lm_resolver_results_reset     (LmResolver         *resolver);
    8.83 -
    8.84 -/* Only for sub classes */
    8.85 -gchar *           _lm_resolver_create_srv_string (const gchar        *domain,
    8.86 -                                                  const gchar        *service,
    8.87 -                                                  const gchar        *protocol);
    8.88 -
    8.89 -void              _lm_resolver_set_result       (LmResolver         *resolver,
    8.90 -                                                 LmResolverResult    result,
    8.91 -                                                 struct addrinfo    *results);
    8.92 -gboolean        _lm_resolver_parse_srv_response (unsigned char      *srv,
    8.93 -                                                 int                 srv_len,
    8.94 -                                                 gchar            **out_server,
    8.95 -                                                 guint              *out_port);
    8.96 -
    8.97 -G_END_DECLS
    8.98 -
    8.99 -#endif /* __LM_RESOLVER_H__ */
   8.100 -