gweb: added the capability to restrict the requests to a specific address family.
authorTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Wed, 22 Jun 2011 06:28:54 +0000 (09:28 +0300)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 27 Jun 2011 14:15:08 +0000 (16:15 +0200)
gweb/gweb.c
gweb/gweb.h

index 1183cc6..536de00 100644 (file)
@@ -101,6 +101,8 @@ struct _GWeb {
 
        guint next_query_id;
 
+       int family;
+
        int index;
        GList *session_list;
 
@@ -203,6 +205,8 @@ GWeb *g_web_new(int index)
 
        web->next_query_id = 1;
 
+       web->family = AF_UNSPEC;
+
        web->index = index;
        web->session_list = NULL;
 
@@ -280,6 +284,19 @@ gboolean g_web_set_proxy(GWeb *web, const char *proxy)
        return TRUE;
 }
 
+gboolean g_web_set_address_family(GWeb *web, int family)
+{
+       if (web == NULL)
+               return FALSE;
+
+       if (family != AF_UNSPEC && family != AF_INET && family != AF_INET6)
+               return FALSE;
+
+       web->family = family;
+
+       return TRUE;
+}
+
 gboolean g_web_add_nameserver(GWeb *web, const char *address)
 {
        if (web == NULL)
@@ -1059,6 +1076,7 @@ static void resolv_result(GResolvResultStatus status,
 
        memset(&hints, 0, sizeof(struct addrinfo));
        hints.ai_flags = AI_NUMERICHOST;
+       hints.ai_family = session->web->family;
 
        if (session->addr != NULL) {
                freeaddrinfo(session->addr);
@@ -1155,6 +1173,7 @@ static guint do_request(GWeb *web, const char *url,
 
                memset(&hints, 0, sizeof(struct addrinfo));
                hints.ai_flags = AI_NUMERICHOST;
+               hints.ai_family = session->web->family;
 
                if (session->addr != NULL) {
                        freeaddrinfo(session->addr);
index 3a76778..cfeceb6 100644 (file)
@@ -54,6 +54,8 @@ void g_web_set_debug(GWeb *web, GWebDebugFunc func, gpointer user_data);
 
 gboolean g_web_set_proxy(GWeb *web, const char *proxy);
 
+gboolean g_web_set_address_family(GWeb *web, int family);
+
 gboolean g_web_add_nameserver(GWeb *web, const char *address);
 
 gboolean g_web_set_accept(GWeb *web, const char *format, ...)