2 * Purple is the legal property of its developers, whose names are too numerous
3 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #include "jingleinfo.h"
28 jabber_google_stun_lookup_cb(GObject
*sender
, GAsyncResult
*result
, gpointer data
) {
30 GList
*addresses
= NULL
;
31 JabberStream
*js
= (JabberStream
*) data
;
33 addresses
= g_resolver_lookup_by_name_finish(G_RESOLVER(sender
),
37 purple_debug_error("jabber", "Google STUN lookup failed: %s\n",
45 if(g_list_length(addresses
) > 0) {
46 GInetAddress
*inet_address
= G_INET_ADDRESS(addresses
->data
);
49 js
->stun_ip
= g_inet_address_to_string(inet_address
);
51 purple_debug_info("jabber", "set Google STUN IP/port address: "
52 "%s:%d\n", js
->stun_ip
, js
->stun_port
);
55 g_resolver_free_addresses(addresses
);
59 jabber_google_jingle_info_common(JabberStream
*js
, const char *from
,
60 JabberIqType type
, PurpleXmlNode
*query
)
62 const PurpleXmlNode
*stun
= purple_xmlnode_get_child(query
, "stun");
63 const PurpleXmlNode
*relay
= purple_xmlnode_get_child(query
, "relay");
67 * Make sure that random people aren't sending us STUN servers. Per
68 * https://developers.google.com/talk/jep_extensions/jingleinfo, these
69 * stanzas are stamped from our bare JID.
72 my_bare_jid
= g_strdup_printf("%s@%s", js
->user
->node
, js
->user
->domain
);
73 if (!purple_strequal(from
, my_bare_jid
)) {
74 purple_debug_warning("jabber", "got google:jingleinfo with invalid from (%s)\n",
83 if (type
== JABBER_IQ_ERROR
|| type
== JABBER_IQ_GET
)
86 purple_debug_info("jabber", "got google:jingleinfo\n");
89 PurpleXmlNode
*server
= purple_xmlnode_get_child(stun
, "server");
92 const gchar
*host
= purple_xmlnode_get_attrib(server
, "host");
93 const gchar
*udp
= purple_xmlnode_get_attrib(server
, "udp");
96 GResolver
*resolver
= g_resolver_get_default();
98 js
->stun_port
= atoi(udp
);
100 g_resolver_lookup_by_name_async(resolver
,
103 jabber_google_stun_lookup_cb
,
105 g_object_unref(resolver
);
111 PurpleXmlNode
*token
= purple_xmlnode_get_child(relay
, "token");
112 PurpleXmlNode
*server
= purple_xmlnode_get_child(relay
, "server");
115 gchar
*relay_token
= purple_xmlnode_get_data(token
);
117 /* we let js own the string returned from purple_xmlnode_get_data */
118 js
->google_relay_token
= relay_token
;
122 js
->google_relay_host
=
123 g_strdup(purple_xmlnode_get_attrib(server
, "host"));
129 jabber_google_jingle_info_cb(JabberStream
*js
, const char *from
,
130 JabberIqType type
, const char *id
,
131 PurpleXmlNode
*packet
, gpointer data
)
133 PurpleXmlNode
*query
= purple_xmlnode_get_child_with_namespace(packet
, "query",
134 NS_GOOGLE_JINGLE_INFO
);
137 jabber_google_jingle_info_common(js
, from
, type
, query
);
139 purple_debug_warning("jabber", "Got invalid google:jingleinfo\n");
143 jabber_google_handle_jingle_info(JabberStream
*js
, const char *from
,
144 JabberIqType type
, const char *id
,
145 PurpleXmlNode
*child
)
147 jabber_google_jingle_info_common(js
, from
, type
, child
);
151 jabber_google_send_jingle_info(JabberStream
*js
)
153 JabberIq
*jingle_info
=
154 jabber_iq_new_query(js
, JABBER_IQ_GET
, NS_GOOGLE_JINGLE_INFO
);
156 jabber_iq_set_callback(jingle_info
, jabber_google_jingle_info_cb
,
158 purple_debug_info("jabber", "sending google:jingleinfo query\n");
159 jabber_iq_send(jingle_info
);