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"
26
jabber_google_stun_lookup_cb(GSList *hosts, gpointer data,
27
const char *error_message)
29
JabberStream *js = (JabberStream *) data;
32
purple_debug_error("jabber", "Google STUN lookup failed: %s\n",
35
js->stun_query = NULL;
39
if (hosts && g_slist_next(hosts)) {
40
struct sockaddr *addr = g_slist_next(hosts)->data;
41
char dst[INET6_ADDRSTRLEN];
44
if (addr->sa_family == AF_INET6) {
45
inet_ntop(addr->sa_family, &((struct sockaddr_in6 *) addr)->sin6_addr,
47
port = ntohs(((struct sockaddr_in6 *) addr)->sin6_port);
49
inet_ntop(addr->sa_family, &((struct sockaddr_in *) addr)->sin_addr,
51
port = ntohs(((struct sockaddr_in *) addr)->sin_port);
56
js->stun_ip = g_strdup(dst);
59
purple_debug_info("jabber", "set Google STUN IP/port address: "
60
"%s:%d\n", dst, port);
62
/* unmark ongoing query */
63
js->stun_query = NULL;
66
while (hosts != NULL) {
67
hosts = g_slist_delete_link(hosts, hosts);
68
/* Free the address */
70
hosts = g_slist_delete_link(hosts, hosts);
75
jabber_google_jingle_info_common(JabberStream *js, const char *from,
76
JabberIqType type, xmlnode *query)
78
const xmlnode *stun = xmlnode_get_child(query, "stun");
79
const xmlnode *relay = xmlnode_get_child(query, "relay");
83
* Make sure that random people aren't sending us STUN servers. Per
84
* http://code.google.com/apis/talk/jep_extensions/jingleinfo.html, these
85
* stanzas are stamped from our bare JID.
88
my_bare_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
89
if (!purple_strequal(from, my_bare_jid)) {
90
purple_debug_warning("jabber", "got google:jingleinfo with invalid from (%s)\n",
99
if (type == JABBER_IQ_ERROR || type == JABBER_IQ_GET)
102
purple_debug_info("jabber", "got google:jingleinfo\n");
105
xmlnode *server = xmlnode_get_child(stun, "server");
108
const gchar *host = xmlnode_get_attrib(server, "host");
109
const gchar *udp = xmlnode_get_attrib(server, "udp");
112
int port = atoi(udp);
113
/* if there, would already be an ongoing query,
116
purple_dnsquery_destroy(js->stun_query);
118
js->stun_query = purple_dnsquery_a(host, port,
119
jabber_google_stun_lookup_cb, js);
125
xmlnode *token = xmlnode_get_child(relay, "token");
126
xmlnode *server = xmlnode_get_child(relay, "server");
129
gchar *relay_token = xmlnode_get_data(token);
131
/* we let js own the string returned from xmlnode_get_data */
132
js->google_relay_token = relay_token;
136
js->google_relay_host =
137
g_strdup(xmlnode_get_attrib(server, "host"));
143
jabber_google_jingle_info_cb(JabberStream *js, const char *from,
144
JabberIqType type, const char *id,
145
xmlnode *packet, gpointer data)
147
xmlnode *query = xmlnode_get_child_with_namespace(packet, "query",
148
NS_GOOGLE_JINGLE_INFO);
151
jabber_google_jingle_info_common(js, from, type, query);
153
purple_debug_warning("jabber", "Got invalid google:jingleinfo\n");
157
jabber_google_handle_jingle_info(JabberStream *js, const char *from,
158
JabberIqType type, const char *id,
161
jabber_google_jingle_info_common(js, from, type, child);
165
jabber_google_send_jingle_info(JabberStream *js)
167
JabberIq *jingle_info =
168
jabber_iq_new_query(js, JABBER_IQ_GET, NS_GOOGLE_JINGLE_INFO);
170
jabber_iq_set_callback(jingle_info, jabber_google_jingle_info_cb,
172
purple_debug_info("jabber", "sending google:jingleinfo query\n");
173
jabber_iq_send(jingle_info);