loudmouth/lm-asyncns-resolver.c
changeset 739 4a32df98ff8c
parent 712 ba47719252ad
child 744 4ebe32453682
equal deleted inserted replaced
738:264fece7ff0d 739:4a32df98ff8c
    36 #include "lm-internals.h"
    36 #include "lm-internals.h"
    37 #include "lm-marshal.h"
    37 #include "lm-marshal.h"
    38 #include "lm-misc.h"
    38 #include "lm-misc.h"
    39 #include "lm-asyncns-resolver.h"
    39 #include "lm-asyncns-resolver.h"
    40 
    40 
    41 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), LM_TYPE_ASYNCNS_RESOLVER, LmAsyncnsResolverPriv))
    41 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), LM_TYPE_ASYNCNS_RESOLVER, LmAsyncnsResolverPrivate))
    42 
    42 
    43 typedef struct LmAsyncnsResolverPriv LmAsyncnsResolverPriv;
    43 typedef struct LmAsyncnsResolverPrivate LmAsyncnsResolverPrivate;
    44 struct LmAsyncnsResolverPriv {
    44 struct LmAsyncnsResolverPrivate {
    45     GSource     *watch_resolv;
    45     GSource     *watch_resolv;
    46     asyncns_query_t *resolv_query;
    46     asyncns_query_t *resolv_query;
    47     asyncns_t   *asyncns_ctx;
    47     asyncns_t   *asyncns_ctx;
    48     GIOChannel  *resolv_channel;
    48     GIOChannel  *resolv_channel;
    49 };
    49 };
    51 static void     asyncns_resolver_dispose       (GObject     *object);
    51 static void     asyncns_resolver_dispose       (GObject     *object);
    52 static void     asyncns_resolver_lookup        (LmResolver  *resolver);
    52 static void     asyncns_resolver_lookup        (LmResolver  *resolver);
    53 static void     asyncns_resolver_cleanup       (LmResolver  *resolver);
    53 static void     asyncns_resolver_cleanup       (LmResolver  *resolver);
    54 static void     asyncns_resolver_cancel        (LmResolver  *resolver);
    54 static void     asyncns_resolver_cancel        (LmResolver  *resolver);
    55 
    55 
    56 G_DEFINE_TYPE (LmAsyncnsResolver, lm_asyncns_resolver, LM_TYPE_RESOLVER)
    56 G_DEFINE_TYPE_WITH_PRIVATE (LmAsyncnsResolver, lm_asyncns_resolver, LM_TYPE_RESOLVER)
    57 
    57 
    58 static void
    58 static void
    59 lm_asyncns_resolver_class_init (LmAsyncnsResolverClass *class)
    59 lm_asyncns_resolver_class_init (LmAsyncnsResolverClass *class)
    60 {
    60 {
    61     GObjectClass    *object_class = G_OBJECT_CLASS (class);
    61     GObjectClass    *object_class = G_OBJECT_CLASS (class);
    63 
    63 
    64     object_class->dispose = asyncns_resolver_dispose;
    64     object_class->dispose = asyncns_resolver_dispose;
    65 
    65 
    66     resolver_class->lookup = asyncns_resolver_lookup;
    66     resolver_class->lookup = asyncns_resolver_lookup;
    67     resolver_class->cancel = asyncns_resolver_cancel;
    67     resolver_class->cancel = asyncns_resolver_cancel;
    68 
       
    69     g_type_class_add_private (object_class, sizeof (LmAsyncnsResolverPriv));
       
    70 }
    68 }
    71 
    69 
    72 static void
    70 static void
    73 lm_asyncns_resolver_init (LmAsyncnsResolver *asyncns_resolver)
    71 lm_asyncns_resolver_init (LmAsyncnsResolver *asyncns_resolver)
    74 {
    72 {
    85 }
    83 }
    86 
    84 
    87 static void
    85 static void
    88 asyncns_resolver_cleanup (LmResolver *resolver)
    86 asyncns_resolver_cleanup (LmResolver *resolver)
    89 {
    87 {
    90     LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
    88     LmAsyncnsResolverPrivate *priv = GET_PRIV (resolver);
    91 
    89 
    92     if (priv->resolv_channel != NULL) {
    90     if (priv->resolv_channel != NULL) {
    93         g_io_channel_unref (priv->resolv_channel);
    91         g_io_channel_unref (priv->resolv_channel);
    94         priv->resolv_channel = NULL;
    92         priv->resolv_channel = NULL;
    95     }
    93     }
   108 }
   106 }
   109 
   107 
   110 static void
   108 static void
   111 asyncns_resolver_done (LmResolver *resolver)
   109 asyncns_resolver_done (LmResolver *resolver)
   112 {
   110 {
   113     LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
   111     LmAsyncnsResolverPrivate *priv = GET_PRIV (resolver);
   114     struct addrinfo       *ans;
   112     struct addrinfo       *ans;
   115     int                err;
   113     int                err;
   116 
   114 
   117     err = asyncns_getaddrinfo_done (priv->asyncns_ctx, priv->resolv_query, &ans);
   115     err = asyncns_getaddrinfo_done (priv->asyncns_ctx, priv->resolv_query, &ans);
   118     priv->resolv_query = NULL;
   116     priv->resolv_query = NULL;
   140 static gboolean
   138 static gboolean
   141 asyncns_resolver_io_cb (GSource      *source,
   139 asyncns_resolver_io_cb (GSource      *source,
   142                         GIOCondition  condition,
   140                         GIOCondition  condition,
   143                         LmResolver   *resolver)
   141                         LmResolver   *resolver)
   144 {
   142 {
   145     LmAsyncnsResolverPriv     *priv = GET_PRIV (resolver);
   143     LmAsyncnsResolverPrivate     *priv = GET_PRIV (resolver);
   146     LmAsyncnsResolverCallback  func;
   144     LmAsyncnsResolverCallback  func;
   147 
   145 
   148     asyncns_wait (priv->asyncns_ctx, FALSE);
   146     asyncns_wait (priv->asyncns_ctx, FALSE);
   149 
   147 
   150     if (!asyncns_isdone (priv->asyncns_ctx, priv->resolv_query)) {
   148     if (!asyncns_isdone (priv->asyncns_ctx, priv->resolv_query)) {
   157 }
   155 }
   158 
   156 
   159 static gboolean
   157 static gboolean
   160 asyncns_resolver_prep (LmResolver *resolver, GError **error)
   158 asyncns_resolver_prep (LmResolver *resolver, GError **error)
   161 {
   159 {
   162     LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
   160     LmAsyncnsResolverPrivate *priv = GET_PRIV (resolver);
   163     GMainContext          *context;
   161     GMainContext          *context;
   164 
   162 
   165     if (priv->asyncns_ctx) {
   163     if (priv->asyncns_ctx) {
   166         return TRUE;
   164         return TRUE;
   167     }
   165     }
   191 }
   189 }
   192 
   190 
   193 static void
   191 static void
   194 asyncns_resolver_lookup_host (LmResolver *resolver)
   192 asyncns_resolver_lookup_host (LmResolver *resolver)
   195 {
   193 {
   196     LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
   194     LmAsyncnsResolverPrivate *priv = GET_PRIV (resolver);
   197     gchar               *host;
   195     gchar               *host;
   198     struct addrinfo      req;
   196     struct addrinfo      req;
   199 
   197 
   200     g_object_get (resolver, "host", &host, NULL);
   198     g_object_get (resolver, "host", &host, NULL);
   201 
   199 
   224 }
   222 }
   225 
   223 
   226 static void
   224 static void
   227 asyncns_resolver_srv_done (LmResolver *resolver)
   225 asyncns_resolver_srv_done (LmResolver *resolver)
   228 {
   226 {
   229     LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
   227     LmAsyncnsResolverPrivate *priv = GET_PRIV (resolver);
   230     unsigned char         *srv_ans;
   228     unsigned char         *srv_ans;
   231     int                    srv_len;
   229     int                    srv_len;
   232     gboolean               result = FALSE;
   230     gboolean               result = FALSE;
   233 
   231 
   234     g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "srv_done callback\n");
   232     g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "srv_done callback\n");
   279 }
   277 }
   280 
   278 
   281 static void
   279 static void
   282 asyncns_resolver_lookup_service (LmResolver *resolver)
   280 asyncns_resolver_lookup_service (LmResolver *resolver)
   283 {
   281 {
   284     LmAsyncnsResolverPriv *priv = GET_PRIV (resolver);
   282     LmAsyncnsResolverPrivate *priv = GET_PRIV (resolver);
   285     gchar                 *domain;
   283     gchar                 *domain;
   286     gchar                 *service;
   284     gchar                 *service;
   287     gchar                 *protocol;
   285     gchar                 *protocol;
   288     gchar                 *srv;
   286     gchar                 *srv;
   289 
   287 
   346 }
   344 }
   347 
   345 
   348 static void
   346 static void
   349 asyncns_resolver_cancel (LmResolver *resolver)
   347 asyncns_resolver_cancel (LmResolver *resolver)
   350 {
   348 {
   351     LmAsyncnsResolverPriv *priv;
   349     LmAsyncnsResolverPrivate *priv;
   352 
   350 
   353     g_return_if_fail (LM_IS_ASYNCNS_RESOLVER (resolver));
   351     g_return_if_fail (LM_IS_ASYNCNS_RESOLVER (resolver));
   354 
   352 
   355     priv = GET_PRIV (resolver);
   353     priv = GET_PRIV (resolver);
   356 
   354