Add function to cancel requests from resolver library
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 28 Jul 2010 01:21:09 +0000 (18:21 -0700)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 28 Jul 2010 01:21:09 +0000 (18:21 -0700)
gresolv/gresolv.c
gresolv/gresolv.h

index 0acff4f..09ecd5c 100644 (file)
@@ -161,7 +161,21 @@ static int send_query(GResolv *resolv, const unsigned char *buf, int len)
        return 0;
 }
 
-static gint compare_msgid(gconstpointer a, gconstpointer b)
+static gint compare_query_id(gconstpointer a, gconstpointer b)
+{
+       const struct resolv_query *query = a;
+       guint id = GPOINTER_TO_UINT(b);
+
+       if (query->id < id)
+               return -1;
+
+       if (query->id > id)
+               return 1;
+
+       return 0;
+}
+
+static gint compare_query_msgid(gconstpointer a, gconstpointer b)
 {
        const struct resolv_query *query = a;
        uint16_t msgid = GPOINTER_TO_UINT(b);
@@ -221,7 +235,7 @@ static void parse_response(struct resolv_nameserver *nameserver,
        results[n] = NULL;
 
        list = g_queue_find_custom(resolv->query_queue,
-                       GUINT_TO_POINTER(ns_msg_id(msg)), compare_msgid);
+                       GUINT_TO_POINTER(ns_msg_id(msg)), compare_query_msgid);
 
        if (list != NULL) {
                struct resolv_query *query = list->data;
@@ -439,3 +453,19 @@ guint g_resolv_lookup_hostname(GResolv *resolv, const char *hostname,
 
        return 0;
 }
+
+gboolean g_resolv_cancel_lookup(GResolv *resolv, guint id)
+{
+       GList *list;
+
+       list = g_queue_find_custom(resolv->query_queue,
+                               GUINT_TO_POINTER(id), compare_query_id);
+
+       if (list == NULL)
+               return FALSE;
+
+       destroy_query(list->data);
+       g_queue_remove(resolv->query_queue, list->data);
+
+       return TRUE;
+}
index d247246..1f678de 100644 (file)
@@ -59,6 +59,8 @@ void g_resolv_flush_nameservers(GResolv *resolv);
 guint g_resolv_lookup_hostname(GResolv *resolv, const char *hostname,
                                GResolvResultFunc func, gpointer user_data);
 
+gboolean g_resolv_cancel_lookup(GResolv *resolv, guint tag);
+
 #ifdef __cplusplus
 }
 #endif