Mercurial > pidgin.yaz
annotate src/upnp.c @ 13085:3382d7aa9ca3
[gaim-migrate @ 15447]
correctly parse NTLM realm
committer: Tailor Script <tailor@pidgin.im>
author | Thomas Butter <tbutter> |
---|---|
date | Tue, 31 Jan 2006 21:35:43 +0000 |
parents | 8e3b85fe4a55 |
children | ef1b5208bda9 |
rev | line source |
---|---|
11195 | 1 /** |
2 * @file upnp.c UPnP Implementation | |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
7 * Gaim is the legal property of its developers, whose names are too numerous | |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 #include "internal.h" | |
11566
7897207b522d
[gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11492
diff
changeset
|
26 #include "gaim.h" |
11195 | 27 |
28 #include "debug.h" | |
11391 | 29 #include "util.h" |
30 #include "proxy.h" | |
31 #include "xmlnode.h" | |
11195 | 32 #include "network.h" |
33 #include "eventloop.h" | |
34 #include "upnp.h" | |
35 | |
36 | |
37 /*************************************************************** | |
38 ** General Defines * | |
39 ****************************************************************/ | |
40 #define HTTP_OK "200 OK" | |
11391 | 41 #define DEFAULT_HTTP_PORT 80 |
42 #define SIZEOF_HTTP 7 /* size of "http://" string */ | |
11195 | 43 #define DISCOVERY_TIMEOUT 1000 |
44 | |
45 /*************************************************************** | |
46 ** Discovery/Description Defines * | |
47 ****************************************************************/ | |
48 #define NUM_UDP_ATTEMPTS 2 | |
49 | |
50 /* Address and port of an SSDP request used for discovery */ | |
51 #define HTTPMU_HOST_ADDRESS "239.255.255.250" | |
52 #define HTTPMU_HOST_PORT 1900 | |
53 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
54 #define SEARCH_REQUEST_DEVICE "urn:schemas-upnp-org:service:%s" |
11195 | 55 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
56 #define SEARCH_REQUEST_STRING \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
57 "M-SEARCH * HTTP/1.1\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
58 "MX: 2\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
59 "HOST: 239.255.255.250:1900\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
60 "MAN: \"ssdp:discover\"\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
61 "ST: urn:schemas-upnp-org:service:%s\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
62 "\r\n" |
11195 | 63 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
64 #define WAN_IP_CONN_SERVICE "WANIPConnection:1" |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
65 #define WAN_PPP_CONN_SERVICE "WANPPPConnection:1" |
11195 | 66 |
67 /****************************************************************** | |
68 ** Action Defines * | |
69 *******************************************************************/ | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
70 #define HTTP_HEADER_ACTION \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
71 "POST /%s HTTP/1.1\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
72 "HOST: %s:%d\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
73 "SOAPACTION: \"urn:schemas-upnp-org:service:%s#%s\"\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
74 "CONTENT-TYPE: text/xml ; charset=\"utf-8\"\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
75 "CONTENT-LENGTH: %" G_GSIZE_FORMAT "\r\n\r\n" |
11195 | 76 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
77 #define SOAP_ACTION \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
78 "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
79 "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" " \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
80 "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
81 "<s:Body>\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
82 "<u:%s xmlns:u=\"urn:schemas-upnp-org:service:%s\">\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
83 "%s" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
84 "</u:%s>\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
85 "</s:Body>\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
86 "</s:Envelope>" |
11195 | 87 |
88 #define PORT_MAPPING_LEASE_TIME "0" | |
89 #define PORT_MAPPING_DESCRIPTION "GAIM_UPNP_PORT_FORWARD" | |
90 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
91 #define ADD_PORT_MAPPING_PARAMS \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
92 "<NewRemoteHost></NewRemoteHost>\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
93 "<NewExternalPort>%i</NewExternalPort>\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
94 "<NewProtocol>%s</NewProtocol>\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
95 "<NewInternalPort>%i</NewInternalPort>\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
96 "<NewInternalClient>%s</NewInternalClient>\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
97 "<NewEnabled>1</NewEnabled>\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
98 "<NewPortMappingDescription>" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
99 PORT_MAPPING_DESCRIPTION \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
100 "</NewPortMappingDescription>\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
101 "<NewLeaseDuration>" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
102 PORT_MAPPING_LEASE_TIME \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
103 "</NewLeaseDuration>\r\n" |
11195 | 104 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
105 #define DELETE_PORT_MAPPING_PARAMS \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
106 "<NewRemoteHost></NewRemoteHost>\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
107 "<NewExternalPort>%i</NewExternalPort>\r\n" \ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
108 "<NewProtocol>%s</NewProtocol>\r\n" |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
109 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
110 typedef enum { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
111 GAIM_UPNP_STATUS_UNDISCOVERED = -1, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
112 GAIM_UPNP_STATUS_UNABLE_TO_DISCOVER, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
113 GAIM_UPNP_STATUS_DISCOVERING, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
114 GAIM_UPNP_STATUS_DISCOVERED |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
115 } GaimUPnPStatus; |
11195 | 116 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
117 typedef struct { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
118 GaimUPnPStatus status; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
119 gchar* control_url; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
120 gchar service_type[20]; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
121 char publicip[16]; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
122 char internalip[16]; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
123 time_t lookup_time; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
124 } GaimUPnPControlInfo; |
11195 | 125 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
126 typedef struct { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
127 guint inpa; /* gaim_input_add handle */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
128 guint tima; /* gaim_timeout_add handle */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
129 int fd; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
130 struct sockaddr_in server; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
131 gchar service_type[25]; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
132 int retry_count; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
133 gchar *full_url; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
134 } UPnPDiscoveryData; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
135 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
136 typedef struct { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
137 unsigned short portmap; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
138 gchar protocol[4]; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
139 gboolean add; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
140 GaimUPnPCallback cb; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
141 gpointer cb_data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
142 } UPnPMappingAddRemove; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
143 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
144 static GaimUPnPControlInfo control_info = { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
145 GAIM_UPNP_STATUS_UNDISCOVERED, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
146 NULL, "\0", "\0", "\0", 0}; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
147 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
148 static GSList *discovery_callbacks = NULL; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
149 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
150 static void gaim_upnp_discover_send_broadcast(UPnPDiscoveryData *dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
151 static void lookup_public_ip(void); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
152 static void lookup_internal_ip(void); |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
153 |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
154 |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
155 static void |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
156 fire_discovery_callbacks(gboolean success) |
11195 | 157 { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
158 while(discovery_callbacks) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
159 gpointer data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
160 GaimUPnPCallback cb = discovery_callbacks->data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
161 discovery_callbacks = g_slist_remove(discovery_callbacks, cb); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
162 data = discovery_callbacks->data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
163 discovery_callbacks = g_slist_remove(discovery_callbacks, data); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
164 cb(success, data); |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
165 } |
11391 | 166 } |
11195 | 167 |
11391 | 168 |
169 static gboolean | |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
170 gaim_upnp_compare_device(const xmlnode* device, const gchar* deviceType) |
11195 | 171 { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
172 xmlnode* deviceTypeNode = xmlnode_get_child(device, "deviceType"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
173 if(deviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
174 return FALSE; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
175 } |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
176 return !g_ascii_strcasecmp(xmlnode_get_data(deviceTypeNode), |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
177 deviceType); |
11391 | 178 } |
179 | |
180 | |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
181 static gboolean |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
182 gaim_upnp_compare_service(const xmlnode* service, const gchar* serviceType) |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
183 { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
184 xmlnode* serviceTypeNode = xmlnode_get_child(service, "serviceType"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
185 if(serviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
186 return FALSE; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
187 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
188 return !g_ascii_strcasecmp(xmlnode_get_data(serviceTypeNode), |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
189 serviceType); |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
190 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
191 |
11195 | 192 |
11391 | 193 static gchar* |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
194 gaim_upnp_parse_description_response(const gchar* httpResponse, gsize len, |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
195 const gchar* httpURL, const gchar* serviceType) |
11391 | 196 { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
197 gchar* xmlRoot; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
198 gchar* baseURL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
199 gchar* controlURL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
200 gchar* service; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
201 xmlnode* xmlRootNode; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
202 xmlnode* serviceTypeNode; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
203 xmlnode* controlURLNode; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
204 xmlnode* baseURLNode; |
11391 | 205 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
206 /* make sure we have a valid http response */ |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
207 if(g_strstr_len(httpResponse, len, HTTP_OK) == NULL) { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
208 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
209 "parse_description_response(): Failed In HTTP_OK\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
210 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
211 } |
11195 | 212 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
213 /* find the root of the xml document */ |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
214 if((xmlRoot = g_strstr_len(httpResponse, len, "<root")) == NULL) { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
215 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
216 "parse_description_response(): Failed finding root\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
217 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
218 } |
11391 | 219 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
220 /* create the xml root node */ |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
221 if((xmlRootNode = xmlnode_from_str(xmlRoot, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
222 len - (xmlRoot - httpResponse))) == NULL) { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
223 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
224 "parse_description_response(): Could not parse xml root node\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
225 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
226 } |
11391 | 227 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
228 /* get the baseURL of the device */ |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
229 if((baseURLNode = xmlnode_get_child(xmlRootNode, "URLBase")) != NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
230 baseURL = g_strdup(xmlnode_get_data(baseURLNode)); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
231 } else { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
232 baseURL = g_strdup(httpURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
233 } |
11391 | 234 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
235 /* get the serviceType child that has the service type as its data */ |
11391 | 236 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
237 /* get urn:schemas-upnp-org:device:InternetGatewayDevice:1 and its devicelist */ |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
238 serviceTypeNode = xmlnode_get_child(xmlRootNode, "device"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
239 while(!gaim_upnp_compare_device(serviceTypeNode, |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
240 "urn:schemas-upnp-org:device:InternetGatewayDevice:1") && |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
241 serviceTypeNode != NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
242 serviceTypeNode = xmlnode_get_next_twin(serviceTypeNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
243 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
244 if(serviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
245 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
246 "parse_description_response(): could not get serviceTypeNode 1\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
247 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
248 xmlnode_free(xmlRootNode); |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
249 return NULL; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
250 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
251 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "deviceList"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
252 if(serviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
253 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
254 "parse_description_response(): could not get serviceTypeNode 2\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
255 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
256 xmlnode_free(xmlRootNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
257 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
258 } |
11195 | 259 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
260 /* get urn:schemas-upnp-org:device:WANDevice:1 and its devicelist */ |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
261 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "device"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
262 while(!gaim_upnp_compare_device(serviceTypeNode, |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
263 "urn:schemas-upnp-org:device:WANDevice:1") && |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
264 serviceTypeNode != NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
265 serviceTypeNode = xmlnode_get_next_twin(serviceTypeNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
266 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
267 if(serviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
268 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
269 "parse_description_response(): could not get serviceTypeNode 3\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
270 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
271 xmlnode_free(xmlRootNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
272 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
273 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
274 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "deviceList"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
275 if(serviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
276 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
277 "parse_description_response(): could not get serviceTypeNode 4\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
278 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
279 xmlnode_free(xmlRootNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
280 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
281 } |
11195 | 282 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
283 /* get urn:schemas-upnp-org:device:WANConnectionDevice:1 and its servicelist */ |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
284 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "device"); |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
285 while(serviceTypeNode && !gaim_upnp_compare_device(serviceTypeNode, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
286 "urn:schemas-upnp-org:device:WANConnectionDevice:1")) { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
287 serviceTypeNode = xmlnode_get_next_twin(serviceTypeNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
288 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
289 if(serviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
290 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
291 "parse_description_response(): could not get serviceTypeNode 5\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
292 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
293 xmlnode_free(xmlRootNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
294 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
295 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
296 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "serviceList"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
297 if(serviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
298 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
299 "parse_description_response(): could not get serviceTypeNode 6\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
300 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
301 xmlnode_free(xmlRootNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
302 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
303 } |
11195 | 304 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
305 /* get the serviceType variable passed to this function */ |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
306 service = g_strdup_printf(SEARCH_REQUEST_DEVICE, serviceType); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
307 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "service"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
308 while(!gaim_upnp_compare_service(serviceTypeNode, service) && |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
309 serviceTypeNode != NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
310 serviceTypeNode = xmlnode_get_next_twin(serviceTypeNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
311 } |
11195 | 312 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
313 g_free(service); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
314 if(serviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
315 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
316 "parse_description_response(): could not get serviceTypeNode 7\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
317 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
318 xmlnode_free(xmlRootNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
319 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
320 } |
11391 | 321 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
322 /* get the controlURL of the service */ |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
323 if((controlURLNode = xmlnode_get_child(serviceTypeNode, |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
324 "controlURL")) == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
325 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
326 "parse_description_response(): Could not find controlURL\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
327 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
328 xmlnode_free(xmlRootNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
329 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
330 } |
11391 | 331 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
332 if(g_strstr_len(xmlnode_get_data(controlURLNode), |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
333 SIZEOF_HTTP, "http://") == NULL && |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
334 g_strstr_len(xmlnode_get_data(controlURLNode), |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
335 SIZEOF_HTTP, "HTTP://") == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
336 controlURL = g_strdup_printf("%s%s", baseURL, |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
337 xmlnode_get_data(controlURLNode)); |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
338 }else{ |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
339 controlURL = g_strdup(xmlnode_get_data(controlURLNode)); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
340 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
341 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
342 xmlnode_free(xmlRootNode); |
11195 | 343 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
344 return controlURL; |
11195 | 345 } |
346 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
347 static void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
348 upnp_parse_description_cb(void *data, const char *httpResponse, gsize len) |
11195 | 349 { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
350 UPnPDiscoveryData *dd = data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
351 gchar *control_url = NULL; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
352 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
353 if (len > 0) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
354 control_url = gaim_upnp_parse_description_response( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
355 httpResponse, len, dd->full_url, dd->service_type); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
356 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
357 g_free(dd->full_url); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
358 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
359 if(control_url == NULL) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
360 gaim_debug_error("upnp", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
361 "gaim_upnp_parse_description(): control URL is NULL\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
362 } |
11195 | 363 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
364 control_info.status = control_url ? GAIM_UPNP_STATUS_DISCOVERED |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
365 : GAIM_UPNP_STATUS_UNABLE_TO_DISCOVER; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
366 control_info.lookup_time = time(NULL); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
367 control_info.control_url = control_url; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
368 strncpy(control_info.service_type, dd->service_type, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
369 sizeof(control_info.service_type)); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
370 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
371 fire_discovery_callbacks(control_url != NULL); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
372 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
373 /* Look up the public and internal IPs */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
374 if(control_url != NULL) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
375 lookup_public_ip(); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
376 lookup_internal_ip(); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
377 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
378 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
379 g_free(dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
380 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
381 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
382 static void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
383 gaim_upnp_parse_description(const gchar* descriptionURL, UPnPDiscoveryData *dd) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
384 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
385 gchar* httpRequest; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
386 gchar* descriptionXMLAddress; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
387 gchar* descriptionAddress; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
388 int port = 0; |
11195 | 389 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
390 /* parse the 4 above variables out of the descriptionURL |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
391 example description URL: http://192.168.1.1:5678/rootDesc.xml */ |
11195 | 392 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
393 /* parse the url into address, port, path variables */ |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
394 if(!gaim_url_parse(descriptionURL, &descriptionAddress, |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
395 &port, &descriptionXMLAddress, NULL, NULL)) { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
396 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
397 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
398 if(port == 0 || port == -1) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
399 port = DEFAULT_HTTP_PORT; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
400 } |
11195 | 401 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
402 /* for example... |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
403 GET /rootDesc.xml HTTP/1.1\r\nHost: 192.168.1.1:5678\r\n\r\n */ |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
404 httpRequest = g_strdup_printf( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
405 "GET /%s HTTP/1.1\r\n" |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
406 "Connection: close\r\n" |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
407 "Host: %s:%d\r\n\r\n", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
408 descriptionXMLAddress, descriptionAddress, port); |
11195 | 409 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
410 g_free(descriptionXMLAddress); |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
411 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
412 dd->full_url = g_strdup_printf("http://%s:%d", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
413 descriptionAddress, port); |
11195 | 414 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
415 /* Remove the timeout because everything it is waiting for has |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
416 * successfully completed */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
417 gaim_timeout_remove(dd->tima); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
418 dd->tima = 0; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
419 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
420 gaim_url_fetch_request(descriptionURL, TRUE, NULL, TRUE, httpRequest, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
421 TRUE, upnp_parse_description_cb, dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
422 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
423 g_free(descriptionAddress); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
424 g_free(httpRequest); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
425 |
11195 | 426 } |
427 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
428 static void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
429 gaim_upnp_parse_discover_response(const gchar* buf, unsigned int buf_len, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
430 UPnPDiscoveryData *dd) |
11195 | 431 { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
432 gchar* startDescURL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
433 gchar* endDescURL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
434 gchar* descURL; |
11195 | 435 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
436 if(g_strstr_len(buf, buf_len, HTTP_OK) == NULL) { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
437 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
438 "parse_discover_response(): Failed In HTTP_OK\n\n"); |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
439 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
440 } |
11195 | 441 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
442 if((startDescURL = g_strstr_len(buf, buf_len, "http://")) == NULL) { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
443 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
444 "parse_discover_response(): Failed In finding http://\n\n"); |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
445 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
446 } |
11195 | 447 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
448 endDescURL = g_strstr_len(startDescURL, buf_len - (startDescURL - buf), |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
449 "\r"); |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
450 if(endDescURL == NULL) { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
451 endDescURL = g_strstr_len(startDescURL, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
452 buf_len - (startDescURL - buf), "\n"); |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
453 if(endDescURL == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
454 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
455 "parse_discover_response(): Failed In endDescURL\n\n"); |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
456 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
457 } |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
458 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
459 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
460 /* XXX: I'm not sure how this could ever happen */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
461 if(endDescURL == startDescURL) { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
462 gaim_debug_error("upnp", |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
463 "parse_discover_response(): endDescURL == startDescURL\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
464 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
465 } |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
466 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
467 descURL = g_strndup(startDescURL, endDescURL - startDescURL); |
11195 | 468 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
469 gaim_upnp_parse_description(descURL, dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
470 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
471 g_free(descURL); |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
472 |
11195 | 473 } |
474 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
475 static gboolean |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
476 gaim_upnp_discover_timeout(gpointer data) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
477 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
478 UPnPDiscoveryData* dd = data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
479 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
480 if (dd->inpa) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
481 gaim_input_remove(dd->inpa); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
482 dd->inpa = 0; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
483 dd->tima = 0; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
484 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
485 if (dd->retry_count < NUM_UDP_ATTEMPTS) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
486 dd->retry_count++; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
487 gaim_upnp_discover_send_broadcast(dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
488 } else { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
489 if (dd->fd) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
490 close(dd->fd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
491 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
492 control_info.status = GAIM_UPNP_STATUS_UNABLE_TO_DISCOVER; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
493 control_info.lookup_time = time(NULL); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
494 control_info.service_type[0] = '\0'; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
495 g_free(control_info.control_url); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
496 control_info.control_url = NULL; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
497 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
498 fire_discovery_callbacks(FALSE); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
499 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
500 g_free(dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
501 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
502 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
503 return FALSE; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
504 } |
11195 | 505 |
506 static void | |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
507 gaim_upnp_discover_udp_read(gpointer data, gint sock, GaimInputCondition cond) |
11195 | 508 { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
509 int len; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
510 UPnPDiscoveryData *dd = data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
511 gchar buf[65536]; |
11195 | 512 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
513 do { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
514 len = recv(dd->fd, buf, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
515 sizeof(buf) - 1, 0); |
11195 | 516 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
517 if(len > 0) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
518 buf[len] = '\0'; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
519 break; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
520 } else if(errno != EINTR) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
521 /* We'll either get called again, or time out */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
522 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
523 } |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
524 } while (errno == EINTR); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
525 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
526 gaim_input_remove(dd->inpa); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
527 dd->inpa = 0; |
11195 | 528 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
529 close(dd->fd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
530 dd->fd = 0; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
531 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
532 /* parse the response, and see if it was a success */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
533 gaim_upnp_parse_discover_response(buf, len, dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
534 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
535 /* We'll either time out or continue successfully */ |
11195 | 536 } |
537 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
538 void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
539 gaim_upnp_discover_send_broadcast(UPnPDiscoveryData *dd) |
11195 | 540 { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
541 gchar *sendMessage = NULL; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
542 gsize totalSize; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
543 gboolean sentSuccess; |
11195 | 544 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
545 /* because we are sending over UDP, if there is a failure |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
546 we should retry the send NUM_UDP_ATTEMPTS times. Also, |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
547 try different requests for WANIPConnection and WANPPPConnection*/ |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
548 for(; dd->retry_count < NUM_UDP_ATTEMPTS; dd->retry_count++) { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
549 sentSuccess = TRUE; |
11195 | 550 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
551 if((dd->retry_count % 2) == 0) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
552 strncpy(dd->service_type, WAN_IP_CONN_SERVICE, sizeof(dd->service_type)); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
553 } else { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
554 strncpy(dd->service_type, WAN_PPP_CONN_SERVICE, sizeof(dd->service_type)); |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
555 } |
11213 | 556 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
557 sendMessage = g_strdup_printf(SEARCH_REQUEST_STRING, dd->service_type); |
11391 | 558 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
559 totalSize = strlen(sendMessage); |
11213 | 560 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
561 do { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
562 if(sendto(dd->fd, sendMessage, totalSize, 0, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
563 (struct sockaddr*) &(dd->server), |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
564 sizeof(struct sockaddr_in) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
565 ) == totalSize) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
566 sentSuccess = TRUE; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
567 break; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
568 } |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
569 } while (errno == EINTR); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
570 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
571 g_free(sendMessage); |
11195 | 572 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
573 if(sentSuccess) { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
574 dd->tima = gaim_timeout_add(DISCOVERY_TIMEOUT, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
575 gaim_upnp_discover_timeout, dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
576 dd->inpa = gaim_input_add(dd->fd, GAIM_INPUT_READ, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
577 gaim_upnp_discover_udp_read, dd); |
11391 | 578 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
579 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
580 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
581 } |
11213 | 582 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
583 /* We have already done all our retries. Make sure that the callback |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
584 * doesn't get called before the original function returns */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
585 gaim_timeout_add(10, gaim_upnp_discover_timeout, dd); |
11195 | 586 } |
587 | |
588 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
589 void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
590 gaim_upnp_discover(GaimUPnPCallback cb, gpointer cb_data) |
11195 | 591 { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
592 /* Socket Setup Variables */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
593 int sock; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
594 struct hostent* hp; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
595 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
596 /* UDP RECEIVE VARIABLES */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
597 UPnPDiscoveryData *dd; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
598 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
599 if (control_info.status == GAIM_UPNP_STATUS_DISCOVERING) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
600 if (cb) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
601 discovery_callbacks = g_slist_append( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
602 discovery_callbacks, cb); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
603 discovery_callbacks = g_slist_append( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
604 discovery_callbacks, cb_data); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
605 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
606 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
607 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
608 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
609 dd = g_new0(UPnPDiscoveryData, 1); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
610 if (cb) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
611 discovery_callbacks = g_slist_append(discovery_callbacks, cb); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
612 discovery_callbacks = g_slist_append(discovery_callbacks, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
613 cb_data); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
614 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
615 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
616 /* Set up the sockets */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
617 sock = socket(AF_INET, SOCK_DGRAM, 0); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
618 if(sock == -1) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
619 gaim_debug_error("upnp", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
620 "gaim_upnp_discover(): Failed In sock creation\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
621 /* Short circuit the retry attempts */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
622 dd->retry_count = NUM_UDP_ATTEMPTS; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
623 gaim_timeout_add(10, gaim_upnp_discover_timeout, dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
624 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
625 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
626 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
627 dd->fd = sock; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
628 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
629 /* This shouldn't block */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
630 if((hp = gethostbyname(HTTPMU_HOST_ADDRESS)) == NULL) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
631 gaim_debug_error("upnp", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
632 "gaim_upnp_discover(): Failed In gethostbyname\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
633 /* Short circuit the retry attempts */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
634 dd->retry_count = NUM_UDP_ATTEMPTS; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
635 gaim_timeout_add(10, gaim_upnp_discover_timeout, dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
636 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
637 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
638 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
639 memset(&(dd->server), 0, sizeof(struct sockaddr)); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
640 dd->server.sin_family = AF_INET; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
641 memcpy(&(dd->server.sin_addr), hp->h_addr_list[0], hp->h_length); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
642 dd->server.sin_port = htons(HTTPMU_HOST_PORT); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
643 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
644 control_info.status = GAIM_UPNP_STATUS_DISCOVERING; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
645 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
646 gaim_upnp_discover_send_broadcast(dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
647 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
648 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
649 static void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
650 gaim_upnp_generate_action_message_and_send(const gchar* actionName, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
651 const gchar* actionParams, GaimURLFetchCallback cb, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
652 gpointer cb_data) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
653 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
654 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
655 gchar* soapMessage; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
656 gchar* totalSendMessage; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
657 gchar* pathOfControl; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
658 gchar* addressOfControl; |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
659 int port = 0; |
11195 | 660 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
661 /* parse the url into address, port, path variables */ |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
662 if(!gaim_url_parse(control_info.control_url, &addressOfControl, |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
663 &port, &pathOfControl, NULL, NULL)) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
664 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
665 "generate_action_message_and_send(): Failed In Parse URL\n\n"); |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
666 /* XXX: This should probably be async */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
667 if(cb) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
668 cb(cb_data, NULL, 0); |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
669 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
670 if(port == 0 || port == -1) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
671 port = DEFAULT_HTTP_PORT; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
672 } |
11195 | 673 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
674 /* set the soap message */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
675 soapMessage = g_strdup_printf(SOAP_ACTION, actionName, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
676 control_info.service_type, actionParams, actionName); |
11391 | 677 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
678 /* set the HTTP Header, and append the body to it */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
679 totalSendMessage = g_strdup_printf(HTTP_HEADER_ACTION "%s", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
680 pathOfControl, addressOfControl, port, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
681 control_info.service_type, actionName, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
682 strlen(soapMessage), soapMessage); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
683 g_free(pathOfControl); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
684 g_free(soapMessage); |
11195 | 685 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
686 gaim_url_fetch_request(control_info.control_url, FALSE, NULL, TRUE, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
687 totalSendMessage, TRUE, cb, cb_data); |
11195 | 688 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
689 g_free(totalSendMessage); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
690 g_free(addressOfControl); |
11195 | 691 } |
692 | |
693 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
694 const gchar * |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
695 gaim_upnp_get_public_ip() |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
696 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
697 if (control_info.status == GAIM_UPNP_STATUS_DISCOVERED |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
698 && control_info.publicip |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
699 && strlen(control_info.publicip) > 0) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
700 return control_info.publicip; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
701 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
702 /* Trigger another UPnP discovery if 5 minutes have elapsed since the |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
703 * last one, and it wasn't successful */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
704 if (control_info.status < GAIM_UPNP_STATUS_DISCOVERING |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
705 && (time(NULL) - control_info.lookup_time) > 300) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
706 gaim_upnp_discover(NULL, NULL); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
707 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
708 return NULL; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
709 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
710 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
711 static void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
712 looked_up_public_ip_cb(gpointer data, const char *httpResponse, gsize len) |
11195 | 713 { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
714 gchar* temp, *temp2; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
715 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
716 if(!httpResponse) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
717 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
718 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
719 /* extract the ip, or see if there is an error */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
720 if((temp = g_strstr_len(httpResponse, len, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
721 "<NewExternalIPAddress")) == NULL) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
722 gaim_debug_error("upnp", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
723 "looked_up_public_ip_cb(): Failed Finding <NewExternalIPAddress\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
724 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
725 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
726 if(!(temp = g_strstr_len(temp, len - (temp - httpResponse), ">"))) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
727 gaim_debug_error("upnp", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
728 "looked_up_public_ip_cb(): Failed In Finding >\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
729 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
730 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
731 if(!(temp2 = g_strstr_len(temp, len - (temp - httpResponse), "<"))) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
732 gaim_debug_error("upnp", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
733 "looked_up_public_ip_cb(): Failed In Finding <\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
734 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
735 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
736 *temp2 = '\0'; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
737 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
738 strncpy(control_info.publicip, temp + 1, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
739 sizeof(control_info.publicip)); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
740 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
741 gaim_debug_info("upnp", "NAT Returned IP: %s\n", control_info.publicip); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
742 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
743 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
744 void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
745 lookup_public_ip() |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
746 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
747 gaim_upnp_generate_action_message_and_send("GetExternalIPAddress", "", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
748 looked_up_public_ip_cb, NULL); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
749 } |
11195 | 750 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
751 /* TODO: This could be exported */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
752 static const gchar * |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
753 gaim_upnp_get_internal_ip() |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
754 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
755 if (control_info.status == GAIM_UPNP_STATUS_DISCOVERED |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
756 && control_info.internalip |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
757 && strlen(control_info.internalip) > 0) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
758 return control_info.internalip; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
759 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
760 /* Trigger another UPnP discovery if 5 minutes have elapsed since the |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
761 * last one, and it wasn't successful */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
762 if (control_info.status < GAIM_UPNP_STATUS_DISCOVERING |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
763 && (time(NULL) - control_info.lookup_time) > 300) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
764 gaim_upnp_discover(NULL, NULL); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
765 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
766 return NULL; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
767 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
768 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
769 static void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
770 looked_up_internal_ip_cb(gpointer data, gint sock, GaimInputCondition cond) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
771 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
772 if (sock) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
773 strncpy(control_info.internalip, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
774 gaim_network_get_local_system_ip(sock), |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
775 sizeof(control_info.internalip)); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
776 gaim_debug_info("upnp", "Local IP: %s\n", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
777 control_info.internalip); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
778 close(sock); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
779 } else |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
780 gaim_debug_info("upnp", "Unable to look up local IP\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
781 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
782 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
783 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
784 void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
785 lookup_internal_ip() |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
786 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
787 gchar* addressOfControl; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
788 int port = 0; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
789 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
790 if(!gaim_url_parse(control_info.control_url, &addressOfControl, &port, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
791 NULL, NULL, NULL)) { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
792 gaim_debug_error("upnp", |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
793 "lookup_internal_ip(): Failed In Parse URL\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
794 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
795 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
796 if(port == 0 || port == -1) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
797 port = DEFAULT_HTTP_PORT; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
798 } |
11195 | 799 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
800 if(gaim_proxy_connect(NULL, addressOfControl, port, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
801 looked_up_internal_ip_cb, NULL) != 0) { |
11195 | 802 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
803 gaim_debug_error("upnp", "Get Local IP Connect Failed: Address: %s @@@ Port %d\n", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
804 addressOfControl, port); |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
805 } |
11195 | 806 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
807 g_free(addressOfControl); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
808 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
809 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
810 static void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
811 done_port_mapping_cb(gpointer data, const gchar *httpResponse, gsize len) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
812 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
813 UPnPMappingAddRemove *ar = data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
814 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
815 gboolean success = TRUE; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
816 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
817 /* determine if port mapping was a success */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
818 if(!httpResponse || g_strstr_len(httpResponse, len, HTTP_OK) == NULL) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
819 gaim_debug_error("upnp", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
820 "gaim_upnp_set_port_mapping(): Failed HTTP_OK\n\n%s\n\n", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
821 httpResponse ? httpResponse : "(null)"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
822 success = FALSE; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
823 } else |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
824 gaim_debug_info("upnp", "Successfully completed port mapping operation\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
825 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
826 if (ar->cb) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
827 ar->cb(success, ar->cb_data); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
828 g_free(ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
829 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
830 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
831 static void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
832 do_port_mapping_cb(gboolean has_control_mapping, gpointer data) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
833 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
834 UPnPMappingAddRemove *ar = data; |
11391 | 835 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
836 if (has_control_mapping) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
837 gchar action_name[25]; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
838 gchar *action_params; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
839 if(ar->add) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
840 const gchar *internal_ip; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
841 /* get the internal IP */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
842 if(!(internal_ip = gaim_upnp_get_internal_ip())) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
843 gaim_debug_error("upnp", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
844 "gaim_upnp_set_port_mapping(): couldn't get local ip\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
845 /* UGLY */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
846 if (ar->cb) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
847 ar->cb(FALSE, ar->cb_data); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
848 g_free(ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
849 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
850 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
851 strncpy(action_name, "AddPortMapping", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
852 sizeof(action_name)); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
853 action_params = g_strdup_printf( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
854 ADD_PORT_MAPPING_PARAMS, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
855 ar->portmap, ar->protocol, ar->portmap, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
856 internal_ip); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
857 } else { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
858 strncpy(action_name, "DeletePortMapping", sizeof(action_name)); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
859 action_params = g_strdup_printf( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
860 DELETE_PORT_MAPPING_PARAMS, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
861 ar->portmap, ar->protocol); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
862 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
863 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
864 gaim_upnp_generate_action_message_and_send(action_name, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
865 action_params, done_port_mapping_cb, ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
866 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
867 g_free(action_params); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
868 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
869 } |
11195 | 870 |
871 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
872 if (ar->cb) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
873 ar->cb(FALSE, ar->cb_data); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
874 g_free(ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
875 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
876 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
877 static gboolean |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
878 fire_port_mapping_failure_cb(gpointer data) |
11195 | 879 { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
880 do_port_mapping_cb(FALSE, data); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
881 return FALSE; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
882 } |
11195 | 883 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
884 void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
885 gaim_upnp_set_port_mapping(unsigned short portmap, const gchar* protocol, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
886 GaimUPnPCallback cb, gpointer cb_data) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
887 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
888 UPnPMappingAddRemove *ar; |
11195 | 889 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
890 ar = g_new0(UPnPMappingAddRemove, 1); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
891 ar->cb = cb; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
892 ar->cb_data = cb_data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
893 ar->add = TRUE; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
894 ar->portmap = portmap; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
895 strncpy(ar->protocol, protocol, sizeof(ar->protocol)); |
11195 | 896 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
897 /* If we're waiting for a discovery, add to the callbacks list */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
898 if(control_info.status == GAIM_UPNP_STATUS_DISCOVERING) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
899 /* TODO: This will fail because when this cb is triggered, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
900 * the internal IP lookup won't be complete */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
901 discovery_callbacks = g_slist_append( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
902 discovery_callbacks, do_port_mapping_cb); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
903 discovery_callbacks = g_slist_append( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
904 discovery_callbacks, ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
905 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
906 } |
11195 | 907 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
908 /* If we haven't had a successful UPnP discovery, check if 5 minutes has |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
909 * elapsed since the last try, try again */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
910 if(control_info.status == GAIM_UPNP_STATUS_UNDISCOVERED || |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
911 (control_info.status == GAIM_UPNP_STATUS_UNABLE_TO_DISCOVER |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
912 && (time(NULL) - control_info.lookup_time) > 300)) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
913 gaim_upnp_discover(do_port_mapping_cb, ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
914 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
915 } else if(control_info.status == GAIM_UPNP_STATUS_UNABLE_TO_DISCOVER) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
916 if (cb) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
917 /* Asynchronously trigger a failed response */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
918 gaim_timeout_add(10, fire_port_mapping_failure_cb, ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
919 } else { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
920 /* No need to do anything if nobody expects a response*/ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
921 g_free(ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
922 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
923 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
924 } |
11195 | 925 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
926 do_port_mapping_cb(TRUE, ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
927 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
928 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
929 void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
930 gaim_upnp_remove_port_mapping(unsigned short portmap, const char* protocol, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
931 GaimUPnPCallback cb, gpointer cb_data) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
932 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
933 UPnPMappingAddRemove *ar; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
934 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
935 ar = g_new0(UPnPMappingAddRemove, 1); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
936 ar->cb = cb; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
937 ar->cb_data = cb_data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
938 ar->add = FALSE; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
939 ar->portmap = portmap; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
940 strncpy(ar->protocol, protocol, sizeof(ar->protocol)); |
11391 | 941 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
942 /* If we're waiting for a discovery, add to the callbacks list */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
943 if(control_info.status == GAIM_UPNP_STATUS_DISCOVERING) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
944 discovery_callbacks = g_slist_append( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
945 discovery_callbacks, do_port_mapping_cb); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
946 discovery_callbacks = g_slist_append( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
947 discovery_callbacks, ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
948 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
949 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
950 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
951 /* If we haven't had a successful UPnP discovery, check if 5 minutes has |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
952 * elapsed since the last try, try again */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
953 if(control_info.status == GAIM_UPNP_STATUS_UNDISCOVERED || |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
954 (control_info.status == GAIM_UPNP_STATUS_UNABLE_TO_DISCOVER |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
955 && (time(NULL) - control_info.lookup_time) > 300)) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
956 gaim_upnp_discover(do_port_mapping_cb, ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
957 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
958 } else if(control_info.status == GAIM_UPNP_STATUS_UNABLE_TO_DISCOVER) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
959 if (cb) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
960 /* Asynchronously trigger a failed response */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
961 gaim_timeout_add(10, fire_port_mapping_failure_cb, ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
962 } else { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
963 /* No need to do anything if nobody expects a response*/ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
964 g_free(ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
965 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
966 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
967 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
968 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
969 do_port_mapping_cb(TRUE, ar); |
11195 | 970 } |