annotate src/upnp.c @ 13161:02268b52ced3

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