Mercurial > pidgin
comparison libpurple/protocols/jabber/google/jingleinfo.c @ 30473:34f586bffe4e
Added new files in sub directory google
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Thu, 25 Mar 2010 20:18:54 +0000 |
parents | |
children | 2e26b90a28dd |
comparison
equal
deleted
inserted
replaced
30472:ae615b3d3e47 | 30473:34f586bffe4e |
---|---|
1 /** | |
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 | |
4 * source distribution. | |
5 * | |
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. | |
10 * | |
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. | |
15 * | |
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 | |
19 */ | |
20 | |
21 #include "internal.h" | |
22 #include "debug.h" | |
23 #include "jingleinfo.h" | |
24 | |
25 static void | |
26 jabber_google_stun_lookup_cb(GSList *hosts, gpointer data, | |
27 const char *error_message) | |
28 { | |
29 JabberStream *js = (JabberStream *) data; | |
30 | |
31 if (error_message) { | |
32 purple_debug_error("jabber", "Google STUN lookup failed: %s\n", | |
33 error_message); | |
34 g_slist_free(hosts); | |
35 js->stun_query = NULL; | |
36 return; | |
37 } | |
38 | |
39 if (hosts && g_slist_next(hosts)) { | |
40 struct sockaddr *addr = g_slist_next(hosts)->data; | |
41 char dst[INET6_ADDRSTRLEN]; | |
42 int port; | |
43 | |
44 if (addr->sa_family == AF_INET6) { | |
45 inet_ntop(addr->sa_family, &((struct sockaddr_in6 *) addr)->sin6_addr, | |
46 dst, sizeof(dst)); | |
47 port = ntohs(((struct sockaddr_in6 *) addr)->sin6_port); | |
48 } else { | |
49 inet_ntop(addr->sa_family, &((struct sockaddr_in *) addr)->sin_addr, | |
50 dst, sizeof(dst)); | |
51 port = ntohs(((struct sockaddr_in *) addr)->sin_port); | |
52 } | |
53 | |
54 if (js->stun_ip) | |
55 g_free(js->stun_ip); | |
56 js->stun_ip = g_strdup(dst); | |
57 js->stun_port = port; | |
58 | |
59 purple_debug_info("jabber", "set Google STUN IP/port address: " | |
60 "%s:%d\n", dst, port); | |
61 | |
62 /* unmark ongoing query */ | |
63 js->stun_query = NULL; | |
64 } | |
65 | |
66 while (hosts != NULL) { | |
67 hosts = g_slist_delete_link(hosts, hosts); | |
68 /* Free the address */ | |
69 g_free(hosts->data); | |
70 hosts = g_slist_delete_link(hosts, hosts); | |
71 } | |
72 } | |
73 | |
74 static void | |
75 jabber_google_jingle_info_common(JabberStream *js, const char *from, | |
76 JabberIqType type, xmlnode *query) | |
77 { | |
78 const xmlnode *stun = xmlnode_get_child(query, "stun"); | |
79 gchar *my_bare_jid; | |
80 | |
81 /* | |
82 * Make sure that random people aren't sending us STUN servers. Per | |
83 * http://code.google.com/apis/talk/jep_extensions/jingleinfo.html, these | |
84 * stanzas are stamped from our bare JID. | |
85 */ | |
86 if (from) { | |
87 my_bare_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); | |
88 if (!purple_strequal(from, my_bare_jid)) { | |
89 purple_debug_warning("jabber", "got google:jingleinfo with invalid from (%s)\n", | |
90 from); | |
91 g_free(my_bare_jid); | |
92 return; | |
93 } | |
94 | |
95 g_free(my_bare_jid); | |
96 } | |
97 | |
98 if (type == JABBER_IQ_ERROR || type == JABBER_IQ_GET) | |
99 return; | |
100 | |
101 purple_debug_info("jabber", "got google:jingleinfo\n"); | |
102 | |
103 if (stun) { | |
104 xmlnode *server = xmlnode_get_child(stun, "server"); | |
105 | |
106 if (server) { | |
107 const gchar *host = xmlnode_get_attrib(server, "host"); | |
108 const gchar *udp = xmlnode_get_attrib(server, "udp"); | |
109 | |
110 if (host && udp) { | |
111 int port = atoi(udp); | |
112 /* if there, would already be an ongoing query, | |
113 cancel it */ | |
114 if (js->stun_query) | |
115 purple_dnsquery_destroy(js->stun_query); | |
116 | |
117 js->stun_query = purple_dnsquery_a(host, port, | |
118 jabber_google_stun_lookup_cb, js); | |
119 } | |
120 } | |
121 } | |
122 /* should perhaps handle relays later on, or maybe wait until | |
123 Google supports a common standard... */ | |
124 } | |
125 | |
126 static void | |
127 jabber_google_jingle_info_cb(JabberStream *js, const char *from, | |
128 JabberIqType type, const char *id, | |
129 xmlnode *packet, gpointer data) | |
130 { | |
131 xmlnode *query = xmlnode_get_child_with_namespace(packet, "query", | |
132 NS_GOOGLE_JINGLE_INFO); | |
133 | |
134 if (query) | |
135 jabber_google_jingle_info_common(js, from, type, query); | |
136 else | |
137 purple_debug_warning("jabber", "Got invalid google:jingleinfo\n"); | |
138 } | |
139 | |
140 void | |
141 jabber_google_handle_jingle_info(JabberStream *js, const char *from, | |
142 JabberIqType type, const char *id, | |
143 xmlnode *child) | |
144 { | |
145 jabber_google_jingle_info_common(js, from, type, child); | |
146 } | |
147 | |
148 void | |
149 jabber_google_send_jingle_info(JabberStream *js) | |
150 { | |
151 JabberIq *jingle_info = | |
152 jabber_iq_new_query(js, JABBER_IQ_GET, NS_GOOGLE_JINGLE_INFO); | |
153 | |
154 jabber_iq_set_callback(jingle_info, jabber_google_jingle_info_cb, | |
155 NULL); | |
156 purple_debug_info("jabber", "sending google:jingleinfo query\n"); | |
157 jabber_iq_send(jingle_info); | |
158 } |