Mercurial > pidgin.yaz
annotate src/upnp.c @ 14133:31d33e7bc0e6
[gaim-migrate @ 16775]
A global buddy icon selector in the statusbox.
This is done totally in the GTK+ UI; the core still sees a buddy icon as
belonging to an account.
Per-account icons can override the global one in Modify Account.
There are some caching issues to work out, still.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Tue, 15 Aug 2006 23:25:29 +0000 |
parents | 8af7f3a7015f |
children |
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 { |
13791 | 190 xmlnode* serviceTypeNode; |
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 |
13791 | 194 if(service == NULL) { |
195 return FALSE; | |
196 } | |
197 | |
198 serviceTypeNode = xmlnode_get_child(service, "serviceType"); | |
199 | |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
200 if(serviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
201 return FALSE; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
202 } |
13621
095fd5936962
[gaim-migrate @ 16007]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
203 |
095fd5936962
[gaim-migrate @ 16007]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
204 tmp = xmlnode_get_data(serviceTypeNode); |
095fd5936962
[gaim-migrate @ 16007]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
205 ret = !g_ascii_strcasecmp(tmp, serviceType); |
095fd5936962
[gaim-migrate @ 16007]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
206 g_free(tmp); |
095fd5936962
[gaim-migrate @ 16007]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
207 |
095fd5936962
[gaim-migrate @ 16007]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
208 return ret; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
209 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
210 |
11195 | 211 |
11391 | 212 static gchar* |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
213 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
|
214 const gchar* httpURL, const gchar* serviceType) |
11391 | 215 { |
13621
095fd5936962
[gaim-migrate @ 16007]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
216 gchar *xmlRoot, *baseURL, *controlURL, *service; |
095fd5936962
[gaim-migrate @ 16007]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
217 xmlnode *xmlRootNode, *serviceTypeNode, *controlURLNode, *baseURLNode; |
095fd5936962
[gaim-migrate @ 16007]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
218 char *tmp; |
11391 | 219 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
220 /* make sure we have a valid http response */ |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
221 if(g_strstr_len(httpResponse, len, HTTP_OK) == NULL) { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
222 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
223 "parse_description_response(): Failed In HTTP_OK\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
224 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
225 } |
11195 | 226 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
227 /* find the root of the xml document */ |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
228 if((xmlRoot = g_strstr_len(httpResponse, len, "<root")) == NULL) { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
229 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
230 "parse_description_response(): Failed finding root\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
231 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
232 } |
11391 | 233 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
234 /* create the xml root node */ |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
235 if((xmlRootNode = xmlnode_from_str(xmlRoot, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
236 len - (xmlRoot - httpResponse))) == NULL) { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
237 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
238 "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
|
239 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
240 } |
11391 | 241 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
242 /* get the baseURL of the device */ |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
243 if((baseURLNode = xmlnode_get_child(xmlRootNode, "URLBase")) != NULL) { |
13621
095fd5936962
[gaim-migrate @ 16007]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
244 baseURL = xmlnode_get_data(baseURLNode); |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
245 } else { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
246 baseURL = g_strdup(httpURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
247 } |
11391 | 248 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
249 /* get the serviceType child that has the service type as its data */ |
11391 | 250 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
251 /* 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
|
252 serviceTypeNode = xmlnode_get_child(xmlRootNode, "device"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
253 while(!gaim_upnp_compare_device(serviceTypeNode, |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
254 "urn:schemas-upnp-org:device:InternetGatewayDevice:1") && |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
255 serviceTypeNode != NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
256 serviceTypeNode = xmlnode_get_next_twin(serviceTypeNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
257 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
258 if(serviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
259 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
260 "parse_description_response(): could not get serviceTypeNode 1\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
261 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
262 xmlnode_free(xmlRootNode); |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
263 return NULL; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
264 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
265 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "deviceList"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
266 if(serviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
267 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
268 "parse_description_response(): could not get serviceTypeNode 2\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
269 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
270 xmlnode_free(xmlRootNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
271 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
272 } |
11195 | 273 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
274 /* 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
|
275 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "device"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
276 while(!gaim_upnp_compare_device(serviceTypeNode, |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
277 "urn:schemas-upnp-org:device:WANDevice:1") && |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
278 serviceTypeNode != NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
279 serviceTypeNode = xmlnode_get_next_twin(serviceTypeNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
280 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
281 if(serviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
282 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
283 "parse_description_response(): could not get serviceTypeNode 3\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
284 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
285 xmlnode_free(xmlRootNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
286 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
287 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
288 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "deviceList"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
289 if(serviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
290 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
291 "parse_description_response(): could not get serviceTypeNode 4\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
292 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
293 xmlnode_free(xmlRootNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
294 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
295 } |
11195 | 296 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
297 /* 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
|
298 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "device"); |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
299 while(serviceTypeNode && !gaim_upnp_compare_device(serviceTypeNode, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
300 "urn:schemas-upnp-org:device:WANConnectionDevice:1")) { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
301 serviceTypeNode = xmlnode_get_next_twin(serviceTypeNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
302 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
303 if(serviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
304 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
305 "parse_description_response(): could not get serviceTypeNode 5\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
306 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
307 xmlnode_free(xmlRootNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
308 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
309 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
310 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "serviceList"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
311 if(serviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
312 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
313 "parse_description_response(): could not get serviceTypeNode 6\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
314 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
315 xmlnode_free(xmlRootNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
316 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
317 } |
11195 | 318 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
319 /* get the serviceType variable passed to this function */ |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
320 service = g_strdup_printf(SEARCH_REQUEST_DEVICE, serviceType); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
321 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "service"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
322 while(!gaim_upnp_compare_service(serviceTypeNode, service) && |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
323 serviceTypeNode != NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
324 serviceTypeNode = xmlnode_get_next_twin(serviceTypeNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
325 } |
11195 | 326 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
327 g_free(service); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
328 if(serviceTypeNode == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
329 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
330 "parse_description_response(): could not get serviceTypeNode 7\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
331 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
332 xmlnode_free(xmlRootNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
333 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
334 } |
11391 | 335 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
336 /* get the controlURL of the service */ |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
337 if((controlURLNode = xmlnode_get_child(serviceTypeNode, |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
338 "controlURL")) == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
339 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
340 "parse_description_response(): Could not find controlURL\n\n"); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
341 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
342 xmlnode_free(xmlRootNode); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
343 return NULL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
344 } |
11391 | 345 |
13621
095fd5936962
[gaim-migrate @ 16007]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
346 tmp = xmlnode_get_data(controlURLNode); |
095fd5936962
[gaim-migrate @ 16007]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
347 if(!gaim_str_has_prefix(tmp, "http://") && |
095fd5936962
[gaim-migrate @ 16007]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
348 !gaim_str_has_prefix(tmp, "HTTP://")) { |
095fd5936962
[gaim-migrate @ 16007]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
349 controlURL = g_strdup_printf("%s%s", baseURL, tmp); |
095fd5936962
[gaim-migrate @ 16007]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
350 g_free(tmp); |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
351 }else{ |
13621
095fd5936962
[gaim-migrate @ 16007]
Richard Laager <rlaager@wiktel.com>
parents:
13200
diff
changeset
|
352 controlURL = tmp; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
353 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
354 g_free(baseURL); |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
355 xmlnode_free(xmlRootNode); |
11195 | 356 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
357 return controlURL; |
11195 | 358 } |
359 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
360 static void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
361 upnp_parse_description_cb(void *data, const char *httpResponse, gsize len) |
11195 | 362 { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
363 UPnPDiscoveryData *dd = data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
364 gchar *control_url = NULL; |
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 (len > 0) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
367 control_url = gaim_upnp_parse_description_response( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
368 httpResponse, len, dd->full_url, dd->service_type); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
369 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
370 g_free(dd->full_url); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
371 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
372 if(control_url == NULL) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
373 gaim_debug_error("upnp", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
374 "gaim_upnp_parse_description(): control URL is NULL\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
375 } |
11195 | 376 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
377 control_info.status = control_url ? GAIM_UPNP_STATUS_DISCOVERED |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
378 : GAIM_UPNP_STATUS_UNABLE_TO_DISCOVER; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
379 control_info.lookup_time = time(NULL); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
380 control_info.control_url = control_url; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
381 strncpy(control_info.service_type, dd->service_type, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
382 sizeof(control_info.service_type)); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
383 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
384 fire_discovery_callbacks(control_url != NULL); |
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 /* Look up the public and internal IPs */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
387 if(control_url != NULL) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
388 lookup_public_ip(); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
389 lookup_internal_ip(); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
390 } |
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 g_free(dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
393 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
394 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
395 static void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
396 gaim_upnp_parse_description(const gchar* descriptionURL, UPnPDiscoveryData *dd) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
397 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
398 gchar* httpRequest; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
399 gchar* descriptionXMLAddress; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
400 gchar* descriptionAddress; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
401 int port = 0; |
11195 | 402 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
403 /* parse the 4 above variables out of the descriptionURL |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
404 example description URL: http://192.168.1.1:5678/rootDesc.xml */ |
11195 | 405 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
406 /* parse the url into address, port, path variables */ |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
407 if(!gaim_url_parse(descriptionURL, &descriptionAddress, |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
408 &port, &descriptionXMLAddress, NULL, NULL)) { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
409 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
410 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
411 if(port == 0 || port == -1) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
412 port = DEFAULT_HTTP_PORT; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
413 } |
11195 | 414 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
415 /* for example... |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
416 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
|
417 httpRequest = g_strdup_printf( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
418 "GET /%s HTTP/1.1\r\n" |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
419 "Connection: close\r\n" |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
420 "Host: %s:%d\r\n\r\n", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
421 descriptionXMLAddress, descriptionAddress, port); |
11195 | 422 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
423 g_free(descriptionXMLAddress); |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
424 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
425 dd->full_url = g_strdup_printf("http://%s:%d", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
426 descriptionAddress, port); |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13096
diff
changeset
|
427 g_free(descriptionAddress); |
11195 | 428 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
429 /* Remove the timeout because everything it is waiting for has |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
430 * successfully completed */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
431 gaim_timeout_remove(dd->tima); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
432 dd->tima = 0; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
433 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
434 gaim_url_fetch_request(descriptionURL, TRUE, NULL, TRUE, httpRequest, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
435 TRUE, upnp_parse_description_cb, dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
436 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
437 g_free(httpRequest); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
438 |
11195 | 439 } |
440 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
441 static void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
442 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
|
443 UPnPDiscoveryData *dd) |
11195 | 444 { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
445 gchar* startDescURL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
446 gchar* endDescURL; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
447 gchar* descURL; |
11195 | 448 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
449 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
|
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 HTTP_OK\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 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
|
456 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
457 "parse_discover_response(): Failed In finding http://\n\n"); |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
458 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
459 } |
11195 | 460 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
461 endDescURL = g_strstr_len(startDescURL, buf_len - (startDescURL - buf), |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
462 "\r"); |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
463 if(endDescURL == NULL) { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
464 endDescURL = g_strstr_len(startDescURL, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
465 buf_len - (startDescURL - buf), "\n"); |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
466 if(endDescURL == NULL) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
467 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
468 "parse_discover_response(): Failed In endDescURL\n\n"); |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
469 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
470 } |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
471 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
472 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
473 /* XXX: I'm not sure how this could ever happen */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
474 if(endDescURL == startDescURL) { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
475 gaim_debug_error("upnp", |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
476 "parse_discover_response(): endDescURL == startDescURL\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
477 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
478 } |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
479 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
480 descURL = g_strndup(startDescURL, endDescURL - startDescURL); |
11195 | 481 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
482 gaim_upnp_parse_description(descURL, dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
483 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
484 g_free(descURL); |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
485 |
11195 | 486 } |
487 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
488 static gboolean |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
489 gaim_upnp_discover_timeout(gpointer data) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
490 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
491 UPnPDiscoveryData* dd = data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
492 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
493 if (dd->inpa) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
494 gaim_input_remove(dd->inpa); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
495 dd->inpa = 0; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
496 dd->tima = 0; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
497 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
498 if (dd->retry_count < NUM_UDP_ATTEMPTS) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
499 dd->retry_count++; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
500 gaim_upnp_discover_send_broadcast(dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
501 } else { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
502 if (dd->fd) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
503 close(dd->fd); |
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 control_info.status = GAIM_UPNP_STATUS_UNABLE_TO_DISCOVER; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
506 control_info.lookup_time = time(NULL); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
507 control_info.service_type[0] = '\0'; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
508 g_free(control_info.control_url); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
509 control_info.control_url = NULL; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
510 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
511 fire_discovery_callbacks(FALSE); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
512 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
513 g_free(dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
514 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
515 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
516 return FALSE; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
517 } |
11195 | 518 |
519 static void | |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
520 gaim_upnp_discover_udp_read(gpointer data, gint sock, GaimInputCondition cond) |
11195 | 521 { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
522 int len; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
523 UPnPDiscoveryData *dd = data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
524 gchar buf[65536]; |
11195 | 525 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
526 do { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
527 len = recv(dd->fd, buf, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
528 sizeof(buf) - 1, 0); |
11195 | 529 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
530 if(len > 0) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
531 buf[len] = '\0'; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
532 break; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
533 } else if(errno != EINTR) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
534 /* We'll either get called again, or time out */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
535 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
536 } |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
537 } while (errno == EINTR); |
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 gaim_input_remove(dd->inpa); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
540 dd->inpa = 0; |
11195 | 541 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
542 close(dd->fd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
543 dd->fd = 0; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
544 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
545 /* parse the response, and see if it was a success */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
546 gaim_upnp_parse_discover_response(buf, len, dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
547 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
548 /* We'll either time out or continue successfully */ |
11195 | 549 } |
550 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
551 void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
552 gaim_upnp_discover_send_broadcast(UPnPDiscoveryData *dd) |
11195 | 553 { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
554 gchar *sendMessage = NULL; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
555 gsize totalSize; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
556 gboolean sentSuccess; |
11195 | 557 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
558 /* 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
|
559 we should retry the send NUM_UDP_ATTEMPTS times. Also, |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
560 try different requests for WANIPConnection and WANPPPConnection*/ |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
561 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
|
562 sentSuccess = FALSE; |
11195 | 563 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
564 if((dd->retry_count % 2) == 0) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
565 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
|
566 } else { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
567 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
|
568 } |
11213 | 569 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
570 sendMessage = g_strdup_printf(SEARCH_REQUEST_STRING, dd->service_type); |
11391 | 571 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
572 totalSize = strlen(sendMessage); |
11213 | 573 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
574 do { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
575 if(sendto(dd->fd, sendMessage, totalSize, 0, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
576 (struct sockaddr*) &(dd->server), |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
577 sizeof(struct sockaddr_in) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
578 ) == totalSize) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
579 sentSuccess = TRUE; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
580 break; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
581 } |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13096
diff
changeset
|
582 } while (errno == EINTR || errno == EAGAIN); |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
583 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
584 g_free(sendMessage); |
11195 | 585 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
586 if(sentSuccess) { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
587 dd->tima = gaim_timeout_add(DISCOVERY_TIMEOUT, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
588 gaim_upnp_discover_timeout, dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
589 dd->inpa = gaim_input_add(dd->fd, GAIM_INPUT_READ, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
590 gaim_upnp_discover_udp_read, dd); |
11391 | 591 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
592 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
593 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
594 } |
11213 | 595 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
596 /* 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
|
597 * doesn't get called before the original function returns */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
598 gaim_timeout_add(10, gaim_upnp_discover_timeout, dd); |
11195 | 599 } |
600 | |
601 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
602 void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
603 gaim_upnp_discover(GaimUPnPCallback cb, gpointer cb_data) |
11195 | 604 { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
605 /* Socket Setup Variables */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
606 int sock; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
607 struct hostent* hp; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
608 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
609 /* UDP RECEIVE VARIABLES */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
610 UPnPDiscoveryData *dd; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
611 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
612 if (control_info.status == GAIM_UPNP_STATUS_DISCOVERING) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
613 if (cb) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
614 discovery_callbacks = g_slist_append( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
615 discovery_callbacks, cb); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
616 discovery_callbacks = g_slist_append( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
617 discovery_callbacks, cb_data); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
618 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
619 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
620 } |
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 dd = g_new0(UPnPDiscoveryData, 1); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
623 if (cb) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
624 discovery_callbacks = g_slist_append(discovery_callbacks, cb); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
625 discovery_callbacks = g_slist_append(discovery_callbacks, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
626 cb_data); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
627 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
628 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
629 /* Set up the sockets */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
630 sock = socket(AF_INET, SOCK_DGRAM, 0); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
631 if(sock == -1) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
632 gaim_debug_error("upnp", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
633 "gaim_upnp_discover(): Failed In sock creation\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
634 /* Short circuit the retry attempts */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
635 dd->retry_count = NUM_UDP_ATTEMPTS; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
636 gaim_timeout_add(10, gaim_upnp_discover_timeout, dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
637 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
638 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
639 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
640 dd->fd = sock; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
641 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
642 /* This shouldn't block */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
643 if((hp = gethostbyname(HTTPMU_HOST_ADDRESS)) == NULL) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
644 gaim_debug_error("upnp", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
645 "gaim_upnp_discover(): Failed In gethostbyname\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
646 /* Short circuit the retry attempts */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
647 dd->retry_count = NUM_UDP_ATTEMPTS; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
648 gaim_timeout_add(10, gaim_upnp_discover_timeout, dd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
649 return; |
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 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
652 memset(&(dd->server), 0, sizeof(struct sockaddr)); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
653 dd->server.sin_family = AF_INET; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
654 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
|
655 dd->server.sin_port = htons(HTTPMU_HOST_PORT); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
656 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
657 control_info.status = GAIM_UPNP_STATUS_DISCOVERING; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
658 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
659 gaim_upnp_discover_send_broadcast(dd); |
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 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
662 static void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
663 gaim_upnp_generate_action_message_and_send(const gchar* actionName, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
664 const gchar* actionParams, GaimURLFetchCallback cb, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
665 gpointer cb_data) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
666 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
667 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
668 gchar* soapMessage; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
669 gchar* totalSendMessage; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
670 gchar* pathOfControl; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
671 gchar* addressOfControl; |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
672 int port = 0; |
11195 | 673 |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
674 /* parse the url into address, port, path variables */ |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
675 if(!gaim_url_parse(control_info.control_url, &addressOfControl, |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
676 &port, &pathOfControl, NULL, NULL)) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
677 gaim_debug_error("upnp", |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
678 "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
|
679 /* XXX: This should probably be async */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
680 if(cb) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
681 cb(cb_data, NULL, 0); |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
682 } |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
683 if(port == 0 || port == -1) { |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
684 port = DEFAULT_HTTP_PORT; |
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
685 } |
11195 | 686 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
687 /* set the soap message */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
688 soapMessage = g_strdup_printf(SOAP_ACTION, actionName, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
689 control_info.service_type, actionParams, actionName); |
11391 | 690 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
691 /* set the HTTP Header, and append the body to it */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
692 totalSendMessage = g_strdup_printf(HTTP_HEADER_ACTION "%s", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
693 pathOfControl, addressOfControl, port, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
694 control_info.service_type, actionName, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
695 strlen(soapMessage), soapMessage); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
696 g_free(pathOfControl); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
697 g_free(soapMessage); |
11195 | 698 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
699 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
|
700 totalSendMessage, TRUE, cb, cb_data); |
11195 | 701 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
702 g_free(totalSendMessage); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
703 g_free(addressOfControl); |
11195 | 704 } |
705 | |
706 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
707 const gchar * |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
708 gaim_upnp_get_public_ip() |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
709 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
710 if (control_info.status == GAIM_UPNP_STATUS_DISCOVERED |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
711 && control_info.publicip |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
712 && strlen(control_info.publicip) > 0) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
713 return control_info.publicip; |
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 /* 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
|
716 * last one, and it wasn't successful */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
717 if (control_info.status < GAIM_UPNP_STATUS_DISCOVERING |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
718 && (time(NULL) - control_info.lookup_time) > 300) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
719 gaim_upnp_discover(NULL, NULL); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
720 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
721 return NULL; |
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 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
724 static void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
725 looked_up_public_ip_cb(gpointer data, const char *httpResponse, gsize len) |
11195 | 726 { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
727 gchar* temp, *temp2; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
728 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
729 if(!httpResponse) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
730 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
731 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
732 /* extract the ip, or see if there is an error */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
733 if((temp = g_strstr_len(httpResponse, len, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
734 "<NewExternalIPAddress")) == NULL) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
735 gaim_debug_error("upnp", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
736 "looked_up_public_ip_cb(): Failed Finding <NewExternalIPAddress\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
737 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
738 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
739 if(!(temp = g_strstr_len(temp, len - (temp - httpResponse), ">"))) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
740 gaim_debug_error("upnp", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
741 "looked_up_public_ip_cb(): Failed In Finding >\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
742 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
743 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
744 if(!(temp2 = g_strstr_len(temp, len - (temp - httpResponse), "<"))) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
745 gaim_debug_error("upnp", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
746 "looked_up_public_ip_cb(): Failed In Finding <\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
747 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
748 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
749 *temp2 = '\0'; |
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 strncpy(control_info.publicip, temp + 1, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
752 sizeof(control_info.publicip)); |
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_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
|
755 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
756 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
757 void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
758 lookup_public_ip() |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
759 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
760 gaim_upnp_generate_action_message_and_send("GetExternalIPAddress", "", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
761 looked_up_public_ip_cb, NULL); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
762 } |
11195 | 763 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
764 /* TODO: This could be exported */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
765 static const gchar * |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
766 gaim_upnp_get_internal_ip() |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
767 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
768 if (control_info.status == GAIM_UPNP_STATUS_DISCOVERED |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
769 && control_info.internalip |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
770 && strlen(control_info.internalip) > 0) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
771 return control_info.internalip; |
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 /* 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
|
774 * last one, and it wasn't successful */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
775 if (control_info.status < GAIM_UPNP_STATUS_DISCOVERING |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
776 && (time(NULL) - control_info.lookup_time) > 300) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
777 gaim_upnp_discover(NULL, NULL); |
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 return NULL; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
780 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
781 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
782 static void |
14121 | 783 looked_up_internal_ip_cb(gpointer data, gint source, const gchar *error_message) |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
784 { |
14089 | 785 if (source) { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
786 strncpy(control_info.internalip, |
14089 | 787 gaim_network_get_local_system_ip(source), |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
788 sizeof(control_info.internalip)); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
789 gaim_debug_info("upnp", "Local IP: %s\n", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
790 control_info.internalip); |
14089 | 791 close(source); |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
792 } else |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
793 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
|
794 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
795 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
796 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
797 void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
798 lookup_internal_ip() |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
799 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
800 gchar* addressOfControl; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
801 int port = 0; |
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(!gaim_url_parse(control_info.control_url, &addressOfControl, &port, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
804 NULL, NULL, NULL)) { |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
805 gaim_debug_error("upnp", |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
806 "lookup_internal_ip(): Failed In Parse URL\n\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
807 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
808 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
809 if(port == 0 || port == -1) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
810 port = DEFAULT_HTTP_PORT; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
811 } |
11195 | 812 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
813 if(gaim_proxy_connect(NULL, addressOfControl, port, |
14108 | 814 looked_up_internal_ip_cb, NULL) == NULL) |
14089 | 815 { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
816 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
|
817 addressOfControl, port); |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
818 } |
11195 | 819 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
820 g_free(addressOfControl); |
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 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
823 static void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
824 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
|
825 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
826 UPnPMappingAddRemove *ar = data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
827 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
828 gboolean success = TRUE; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
829 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
830 /* determine if port mapping was a success */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
831 if(!httpResponse || g_strstr_len(httpResponse, len, HTTP_OK) == NULL) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
832 gaim_debug_error("upnp", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
833 "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
|
834 httpResponse ? httpResponse : "(null)"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
835 success = FALSE; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
836 } else |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
837 gaim_debug_info("upnp", "Successfully completed port mapping operation\n"); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
838 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
839 if (ar->cb) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
840 ar->cb(success, ar->cb_data); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
841 g_free(ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
842 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
843 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
844 static void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
845 do_port_mapping_cb(gboolean has_control_mapping, gpointer data) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
846 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
847 UPnPMappingAddRemove *ar = data; |
11391 | 848 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
849 if (has_control_mapping) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
850 gchar action_name[25]; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
851 gchar *action_params; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
852 if(ar->add) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
853 const gchar *internal_ip; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
854 /* get the internal IP */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
855 if(!(internal_ip = gaim_upnp_get_internal_ip())) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
856 gaim_debug_error("upnp", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
857 "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
|
858 /* UGLY */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
859 if (ar->cb) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
860 ar->cb(FALSE, ar->cb_data); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
861 g_free(ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
862 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
863 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
864 strncpy(action_name, "AddPortMapping", |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
865 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 ADD_PORT_MAPPING_PARAMS, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
868 ar->portmap, ar->protocol, ar->portmap, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
869 internal_ip); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
870 } else { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
871 strncpy(action_name, "DeletePortMapping", sizeof(action_name)); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
872 action_params = g_strdup_printf( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
873 DELETE_PORT_MAPPING_PARAMS, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
874 ar->portmap, ar->protocol); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
875 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
876 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
877 gaim_upnp_generate_action_message_and_send(action_name, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
878 action_params, done_port_mapping_cb, ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
879 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
880 g_free(action_params); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
881 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
882 } |
11195 | 883 |
884 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
885 if (ar->cb) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
886 ar->cb(FALSE, ar->cb_data); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
887 g_free(ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
888 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
889 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
890 static gboolean |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
891 fire_port_mapping_failure_cb(gpointer data) |
11195 | 892 { |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
893 do_port_mapping_cb(FALSE, data); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
894 return FALSE; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
895 } |
11195 | 896 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
897 void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
898 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
|
899 GaimUPnPCallback cb, gpointer cb_data) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
900 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
901 UPnPMappingAddRemove *ar; |
11195 | 902 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
903 ar = g_new0(UPnPMappingAddRemove, 1); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
904 ar->cb = cb; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
905 ar->cb_data = cb_data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
906 ar->add = TRUE; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
907 ar->portmap = portmap; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
908 strncpy(ar->protocol, protocol, sizeof(ar->protocol)); |
11195 | 909 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
910 /* 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
|
911 if(control_info.status == GAIM_UPNP_STATUS_DISCOVERING) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
912 /* TODO: This will fail because when this cb is triggered, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
913 * the internal IP lookup won't be complete */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
914 discovery_callbacks = g_slist_append( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
915 discovery_callbacks, do_port_mapping_cb); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
916 discovery_callbacks = g_slist_append( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
917 discovery_callbacks, ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
918 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
919 } |
11195 | 920 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
921 /* 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
|
922 * elapsed since the last try, try again */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
923 if(control_info.status == GAIM_UPNP_STATUS_UNDISCOVERED || |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
924 (control_info.status == GAIM_UPNP_STATUS_UNABLE_TO_DISCOVER |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
925 && (time(NULL) - control_info.lookup_time) > 300)) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
926 gaim_upnp_discover(do_port_mapping_cb, ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
927 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
928 } 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
|
929 if (cb) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
930 /* Asynchronously trigger a failed response */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
931 gaim_timeout_add(10, fire_port_mapping_failure_cb, ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
932 } else { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
933 /* No need to do anything if nobody expects a response*/ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
934 g_free(ar); |
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 return; |
12734
0f499f27b29a
[gaim-migrate @ 15078]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12207
diff
changeset
|
937 } |
11195 | 938 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
939 do_port_mapping_cb(TRUE, ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
940 } |
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 void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
943 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
|
944 GaimUPnPCallback cb, gpointer cb_data) |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
945 { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
946 UPnPMappingAddRemove *ar; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
947 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
948 ar = g_new0(UPnPMappingAddRemove, 1); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
949 ar->cb = cb; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
950 ar->cb_data = cb_data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
951 ar->add = FALSE; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
952 ar->portmap = portmap; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
953 strncpy(ar->protocol, protocol, sizeof(ar->protocol)); |
11391 | 954 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
955 /* 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
|
956 if(control_info.status == GAIM_UPNP_STATUS_DISCOVERING) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
957 discovery_callbacks = g_slist_append( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
958 discovery_callbacks, do_port_mapping_cb); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
959 discovery_callbacks = g_slist_append( |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
960 discovery_callbacks, ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
961 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
962 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
963 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
964 /* 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
|
965 * elapsed since the last try, try again */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
966 if(control_info.status == GAIM_UPNP_STATUS_UNDISCOVERED || |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
967 (control_info.status == GAIM_UPNP_STATUS_UNABLE_TO_DISCOVER |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
968 && (time(NULL) - control_info.lookup_time) > 300)) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
969 gaim_upnp_discover(do_port_mapping_cb, ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
970 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
971 } 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
|
972 if (cb) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
973 /* Asynchronously trigger a failed response */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
974 gaim_timeout_add(10, fire_port_mapping_failure_cb, ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
975 } else { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
976 /* No need to do anything if nobody expects a response*/ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
977 g_free(ar); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
978 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
979 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
980 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
981 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12734
diff
changeset
|
982 do_port_mapping_cb(TRUE, ar); |
11195 | 983 } |