summaryrefslogtreecommitdiff
path: root/gresolv/gresolv.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2010-07-27 18:21:09 -0700
committerMarcel Holtmann <marcel@holtmann.org>2010-07-27 18:21:09 -0700
commit9e91d338e83a804473da043a1a980cbae6ebbc52 (patch)
tree384ec52585e0de694a15e4aedac8a372d60f2bb1 /gresolv/gresolv.c
parentacf9c645730f2955d289071e188615da414ddcf8 (diff)
downloadconnman-9e91d338e83a804473da043a1a980cbae6ebbc52.tar.gz
connman-9e91d338e83a804473da043a1a980cbae6ebbc52.tar.bz2
connman-9e91d338e83a804473da043a1a980cbae6ebbc52.zip
Add function to cancel requests from resolver library
Diffstat (limited to 'gresolv/gresolv.c')
-rw-r--r--gresolv/gresolv.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/gresolv/gresolv.c b/gresolv/gresolv.c
index 0acff4fe..09ecd5c3 100644
--- a/gresolv/gresolv.c
+++ b/gresolv/gresolv.c
@@ -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;
+}