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