Fix libravatar depending on auto_configure_service in a synchronous manner.
authorColin Leroy <colin@colino.net>
Fri, 2 May 2014 08:04:17 +0000 (10:04 +0200)
committerColin Leroy <colin@colino.net>
Fri, 2 May 2014 08:04:17 +0000 (10:04 +0200)
src/gtk/gtkutils.c
src/gtk/gtkutils.h
src/plugins/libravatar/libravatar_federation.c

index e2c0a71..4b227e7 100644 (file)
@@ -1984,4 +1984,44 @@ void auto_configure_service(AutoConfigureData *data)
                                        data->cancel, resolve_done, data);
        }
 }
+
+gboolean auto_configure_service_sync(const gchar *service, const gchar *domain, gchar **srvhost, guint16 *srvport)
+{
+       GResolver *resolver;
+       GList *answers, *cur;
+       GError *error = NULL;
+       gboolean result = FALSE;
+
+       cm_return_val_if_fail(service != NULL, FALSE);
+       cm_return_val_if_fail(domain != NULL, FALSE);
+
+       resolver = g_resolver_get_default();
+       if (resolver == NULL)
+               return FALSE;
+
+       answers = g_resolver_lookup_service(resolver, service, "tcp", domain, NULL, &error);
+
+       *srvhost = NULL;
+       *srvport = 0;
+
+       if (answers) {
+               for (cur = g_srv_target_list_sort(answers); cur; cur = cur->next) {
+                       GSrvTarget *target = (GSrvTarget *)cur->data;
+                       const gchar *hostname = g_srv_target_get_hostname(target);
+                       guint16 port = g_srv_target_get_port(target);
+                       if (hostname && strcmp(hostname,"") && port > 0) {
+                               result = TRUE;
+                               *srvhost = g_strdup(hostname);
+                               *srvport = port;
+                               break;
+                       }
+               }
+               g_resolver_free_targets(answers);
+       } else if (error) {
+               g_error_free(error);
+       }
+
+       g_object_unref(resolver);
+       return result;
+}
 #endif
\ No newline at end of file
index 8c3849f..39a8a32 100644 (file)
@@ -231,6 +231,7 @@ typedef struct _AutoConfigureData {
 } AutoConfigureData;
 
 void auto_configure_service(AutoConfigureData *data);
+gboolean auto_configure_service_sync(const gchar *service, const gchar *domain, gchar **srvhost, guint16 *srvport);
 #endif
 
 
index 106fdfb..aee618e 100644 (file)
@@ -111,14 +111,14 @@ gchar *federated_url_for_address(const gchar *address)
        }
 
        /* not cached, try secure service first */
-       if (auto_configure_service("avatars-sec", domain, &host, &port)) {
+       if (auto_configure_service_sync("avatars-sec", domain, &host, &port)) {
                if (port != 443) {
                        url = g_strdup_printf("https://%s:%d/avatar", host, port);
                } else {
                        url = g_strdup_printf("https://%s/avatar", host);
                }
        } else { /* try standard one if no secure service available */
-               if (auto_configure_service("avatars", domain, &host, &port)) {
+               if (auto_configure_service_sync("avatars", domain, &host, &port)) {
                        if (port != 80) {
                                url = g_strdup_printf("http://%s:%d/avatar", host, port);
                        } else {