/pidgin/main: 0b957b80c46a: This should do it for XMPP
Gary Kramlich
grim at reaperworld.com
Wed Dec 23 23:33:34 EST 2015
Changeset: 0b957b80c46a12d897ba7c8cbcb2c18e64245565
Author: Gary Kramlich <grim at reaperworld.com>
Date: 2015-12-18 18:26 -0600
Branch: use-gresolver
URL: https://hg.pidgin.im/pidgin/main/rev/0b957b80c46a
Description:
This should do it for XMPP
diffstat:
libpurple/protocols/jabber/disco.c | 93 ++++---------
libpurple/protocols/jabber/google/jingleinfo.c | 70 +++------
libpurple/protocols/jabber/jabber.c | 170 ++++++++++++++----------
libpurple/protocols/jabber/jabber.h | 11 +-
4 files changed, 152 insertions(+), 192 deletions(-)
diffs (truncated from 534 to 300 lines):
diff --git a/libpurple/protocols/jabber/disco.c b/libpurple/protocols/jabber/disco.c
--- a/libpurple/protocols/jabber/disco.c
+++ b/libpurple/protocols/jabber/disco.c
@@ -419,77 +419,39 @@ jabber_disco_finish_server_info_result_c
}
-/* should probably share this code with google.c, or maybe from 2.7.0
- introduce an abstracted hostname -> IP function in dns.c */
static void
-jabber_disco_stun_lookup_cb(GSList *hosts, gpointer data,
- const char *error_message)
-{
+jabber_disco_stun_srv_resolve_cb(GObject *sender, GAsyncResult *result, gpointer data) {
+ GError *error = NULL;
+ GList *services = NULL;
JabberStream *js = (JabberStream *) data;
+ gint results = 0;
- if (error_message) {
- purple_debug_error("jabber", "STUN lookup failed: %s\n",
- error_message);
- g_slist_free(hosts);
- js->stun_query = NULL;
+ services = g_resolver_lookup_service_finish(g_resolver_get_default(), result, &error);
+
+ if(error != NULL) {
+ purple_debug_info("jabber", "Failed to look up a STUN record : %s\n", error->message);
+
+ g_error_free(error);
+
return;
}
- if (hosts && g_slist_next(hosts)) {
- common_sockaddr_t addr;
- char dst[INET6_ADDRSTRLEN];
- int port;
+ results = g_list_length(services);
- memcpy(&addr, g_slist_next(hosts)->data, sizeof(addr));
+ purple_debug_info("jabber", "got %d SRV responses for STUN.\n", results);
- if (addr.sa.sa_family == AF_INET6) {
- inet_ntop(addr.sa.sa_family, &addr.in6.sin6_addr,
- dst, sizeof(dst));
- port = ntohs(addr.in6.sin6_port);
- } else {
- inet_ntop(addr.sa.sa_family, &addr.in.sin_addr,
- dst, sizeof(dst));
- port = ntohs(addr.in.sin_port);
- }
+ if (results > 0) {
+ GSrvTarget *target = (GSrvTarget *)services->data;
+ const gchar *hostname = g_srv_target_get_hostname(target);
- if (js->stun_ip)
- g_free(js->stun_ip);
- js->stun_ip = g_strdup(dst);
- js->stun_port = port;
+ js->stun_ip = g_strdup(hostname);
+ js->stun_port = g_srv_target_get_port(target);
- purple_debug_info("jabber", "set STUN IP/port address: "
- "%s:%d\n", dst, port);
-
- /* unmark ongoing query */
- js->stun_query = NULL;
+ purple_debug_info("jabber", "set stun address to %s:%d\n",
+ hostname, js->stun_port);
}
- while (hosts != NULL) {
- hosts = g_slist_delete_link(hosts, hosts);
- /* Free the address */
- g_free(hosts->data);
- hosts = g_slist_delete_link(hosts, hosts);
- }
-}
-
-
-static void
-jabber_disco_stun_srv_resolve_cb(PurpleSrvResponse *resp, int results, gpointer data)
-{
- JabberStream *js = (JabberStream *) data;
-
- purple_debug_info("jabber", "got %d SRV responses for STUN.\n", results);
- js->srv_query_data = NULL;
-
- if (results > 0) {
- PurpleAccount *account;
- purple_debug_info("jabber", "looking up IP for %s:%d\n",
- resp[0].hostname, resp[0].port);
- account = purple_connection_get_account(js->gc);
- js->stun_query =
- purple_dnsquery_a(account, resp[0].hostname, resp[0].port,
- jabber_disco_stun_lookup_cb, js);
- }
+ g_resolver_free_targets(services);
}
@@ -553,11 +515,14 @@ jabber_disco_server_info_result_cb(Jabbe
}
} else if (purple_network_get_stun_ip() == NULL ||
purple_strequal(purple_network_get_stun_ip(), "")) {
- js->srv_query_data =
- purple_srv_resolve(
- purple_connection_get_account(js->gc), "stun", "udp",
- js->user->domain,
- jabber_disco_stun_srv_resolve_cb, js);
+
+ g_resolver_lookup_service_async(g_resolver_get_default(),
+ "stun",
+ "udp",
+ js->user->domain,
+ NULL,
+ jabber_disco_stun_srv_resolve_cb,
+ js);
/* TODO: add TURN support later... */
}
}
diff --git a/libpurple/protocols/jabber/google/jingleinfo.c b/libpurple/protocols/jabber/google/jingleinfo.c
--- a/libpurple/protocols/jabber/google/jingleinfo.c
+++ b/libpurple/protocols/jabber/google/jingleinfo.c
@@ -22,55 +22,36 @@
#include "debug.h"
#include "jingleinfo.h"
+#include <gio/gio.h>
+
static void
-jabber_google_stun_lookup_cb(GSList *hosts, gpointer data,
- const char *error_message)
-{
+jabber_google_stun_lookup_cb(GObject *sender, GAsyncResult *result, gpointer data) {
+ GError *error = NULL;
+ GList *addresses = NULL;
JabberStream *js = (JabberStream *) data;
- if (error_message) {
+ addresses = g_resolver_lookup_by_name_finish(g_resolver_get_default(), result, &error);
+
+ if(error) {
purple_debug_error("jabber", "Google STUN lookup failed: %s\n",
- error_message);
- g_slist_free(hosts);
- js->stun_query = NULL;
+ error->message);
+
+ g_error_free(error);
+
return;
}
- if (hosts && g_slist_next(hosts)) {
- common_sockaddr_t addr;
- char dst[INET6_ADDRSTRLEN];
- int port;
+ if(g_list_length(addresses) > 0) {
+ GInetAddress *inet_address = G_INET_ADDRESS(addresses->data);
- memcpy(&addr, g_slist_next(hosts)->data, sizeof(addr));
-
- if (addr.sa.sa_family == AF_INET6) {
- inet_ntop(addr.sa.sa_family, &addr.in6.sin6_addr,
- dst, sizeof(dst));
- port = ntohs(addr.in6.sin6_port);
- } else {
- inet_ntop(addr.sa.sa_family, &addr.in.sin_addr,
- dst, sizeof(dst));
- port = ntohs(addr.in.sin_port);
- }
-
- if (js->stun_ip)
- g_free(js->stun_ip);
- js->stun_ip = g_strdup(dst);
- js->stun_port = port;
+ g_free(js->stun_ip);
+ js->stun_ip = g_inet_address_to_string(inet_address);
purple_debug_info("jabber", "set Google STUN IP/port address: "
- "%s:%d\n", dst, port);
-
- /* unmark ongoing query */
- js->stun_query = NULL;
+ "%s:%d\n", js->stun_ip, js->stun_port);
}
- while (hosts != NULL) {
- hosts = g_slist_delete_link(hosts, hosts);
- /* Free the address */
- g_free(hosts->data);
- hosts = g_slist_delete_link(hosts, hosts);
- }
+ g_resolver_free_addresses(addresses);
}
static void
@@ -111,16 +92,13 @@ jabber_google_jingle_info_common(JabberS
const gchar *udp = purple_xmlnode_get_attrib(server, "udp");
if (host && udp) {
- PurpleAccount *account;
- int port = atoi(udp);
- /* if there, would already be an ongoing query,
- cancel it */
- if (js->stun_query)
- purple_dnsquery_destroy(js->stun_query);
+ js->stun_port = atoi(udp);
- account = purple_connection_get_account(js->gc);
- js->stun_query = purple_dnsquery_a(account, host, port,
- jabber_google_stun_lookup_cb, js);
+ g_resolver_lookup_by_name_async(g_resolver_get_default(),
+ host,
+ NULL,
+ jabber_google_stun_lookup_cb,
+ js);
}
}
}
diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c
--- a/libpurple/protocols/jabber/jabber.c
+++ b/libpurple/protocols/jabber/jabber.c
@@ -30,7 +30,6 @@
#include "connection.h"
#include "conversation.h"
#include "debug.h"
-#include "dnssrv.h"
#include "http.h"
#include "message.h"
#include "notify.h"
@@ -95,7 +94,6 @@ static GHashTable *jabber_cmds = NULL; /
static gint plugin_ref = 0;
static void jabber_unregister_account_cb(JabberStream *js);
-static void try_srv_connect(JabberStream *js);
static void jabber_stream_init(JabberStream *js)
{
@@ -765,28 +763,54 @@ jabber_login_callback_ssl(gpointer data,
}
static void
-txt_resolved_cb(GList *responses, gpointer data)
+txt_resolved_cb(GObject *sender, GAsyncResult *result, gpointer data)
{
+ GError *error = NULL;
+ GList *records = NULL, *l = NULL;
JabberStream *js = data;
gboolean found = FALSE;
- js->srv_query_data = NULL;
-
- while (responses) {
- PurpleTxtResponse *resp = responses->data;
- gchar **token;
- token = g_strsplit(purple_txt_response_get_content(resp), "=", 2);
- if (!strcmp(token[0], "_xmpp-client-xbosh")) {
- purple_debug_info("jabber","Found alternative connection method using %s at %s.\n", token[0], token[1]);
- js->bosh = jabber_bosh_connection_new(js, token[1]);
+ records = g_resolver_lookup_service_finish(g_resolver_get_default(), result, &error);
+ if(error) {
+ purple_debug_warning("jabber", "Unable to find alternative XMPP connection "
+ "methods after failing to connect directly. : %s\n",
+ error->message);
+
+ purple_connection_error(js->gc,
+ PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
+ _("Unable to connect"));
+
+ g_error_free(error);
+
+ return;
+ }
+
+ for(l = records; l; l = l->next) {
+ GVariantIter *iter = NULL;
+ gchar *str = NULL;
+
+ g_variant_get((GVariant *)l->data, "(as)", &iter);
+ while(g_variant_iter_loop(iter, "s", &str)) {
+ gchar **token = g_strsplit(str, "=", 2);
+
+ if(!g_ascii_strcasecmp(token[0], "_xmpp-client-xbosh")) {
+ purple_debug_info("jabber","Found alternative connection method using %s at %s.\n", token[0], token[1]);
+
+ js->bosh = jabber_bosh_connection_new(js, token[1]);
+
+ g_strfreev(token);
+
+ break;
+ }
+
g_strfreev(token);
- break;
}
- g_strfreev(token);
- purple_txt_response_destroy(resp);
More information about the Commits
mailing list