annotate src/upnp.c @ 12215:31b91bfab029

[gaim-migrate @ 14517] make this stuff compile without iLBC. Really I want to rip out anything that references iLBC, but I don't know exactly how optional it is or if I'd get shot for doing that. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Thu, 24 Nov 2005 20:38:24 +0000
parents 201be1b681a4
children 0f499f27b29a
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 * Information on the httpResponse callback
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
39 */
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
40 typedef struct
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
41 {
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
42 guint inpa; /* gaim_input_add handle */
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
43 guint tima; /* gaim_timout_add handle */
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
44 gchar* sendBuffer; /* send data */
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
45 gchar* recvBuffer; /* response data */
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
46 guint totalSizeRecv;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
47 gboolean done;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
48
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
49 } NetResponseData;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
50
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
51
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
52 /***************************************************************
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
53 ** General Defines *
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
54 ****************************************************************/
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
55 #define HTTP_OK "200 OK"
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
56 #define DEFAULT_HTTP_PORT 80
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
57 #define MAX_PORT_SIZE 6
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
58 #define SIZEOF_HTTP 7 /* size of "http://" string */
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
59 #define RECEIVE_TIMEOUT 10000
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
60 #define CONSECUTIVE_RECEIVE_TIMEOUT 500
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
61 #define DISCOVERY_TIMEOUT 1000
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
62
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
63
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
64 /***************************************************************
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
65 ** Discovery/Description Defines *
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
66 ****************************************************************/
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
67 #define NUM_UDP_ATTEMPTS 2
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
68
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
69 /* Address and port of an SSDP request used for discovery */
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
70 #define HTTPMU_HOST_ADDRESS "239.255.255.250"
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
71 #define HTTPMU_HOST_PORT 1900
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
72
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
73 #define SEARCH_REQUEST_DEVICE "urn:schemas-upnp-org:service:" \
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
74 "%s"
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
75
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
76 #define SEARCH_REQUEST_STRING "M-SEARCH * HTTP/1.1\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
77 "MX: 2\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
78 "HOST: 239.255.255.250:1900\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
79 "MAN: \"ssdp:discover\"\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
80 "ST: urn:schemas-upnp-org:service:" \
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
81 "%s\r\n" \
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
82 "\r\n"
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
83
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
84 #define MAX_DISCOVERY_RECEIVE_SIZE 400
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
85 #define MAX_DESCRIPTION_RECEIVE_SIZE 7000
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
86 #define MAX_DESCRIPTION_HTTP_HEADER_SIZE 100
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
87
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
88
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
89 /******************************************************************
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
90 ** Action Defines *
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
91 *******************************************************************/
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
92 #define HTTP_HEADER_ACTION "POST /%s HTTP/1.1\r\n" \
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
93 "HOST: %s\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
94 "SOAPACTION: " \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
95 "\"urn:schemas-upnp-org:" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
96 "service:%s#%s\"\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
97 "CONTENT-TYPE: text/xml ; charset=\"utf-8\"\r\n"\
11656
f9c5480ad0ce [gaim-migrate @ 13940]
Richard Laager <rlaager@wiktel.com>
parents: 11586
diff changeset
98 "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n"
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
99
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
100 #define SOAP_ACTION "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
101 "<s:Envelope xmlns:s=" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
102 "\"http://schemas.xmlsoap.org/soap/envelope/\" " \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
103 "s:encodingStyle=" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
104 "\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
105 "<s:Body>\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
106 "<u:%s xmlns:u=" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
107 "\"urn:schemas-upnp-org:service:%s\">\r\n%s" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
108 "</u:%s>\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
109 "</s:Body>\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
110 "</s:Envelope>\r\n"
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
111
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
112 #define PORT_MAPPING_LEASE_TIME "0"
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
113 #define PORT_MAPPING_DESCRIPTION "GAIM_UPNP_PORT_FORWARD"
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
114
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
115 #define ADD_PORT_MAPPING_PARAMS "<NewRemoteHost></NewRemoteHost>\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
116 "<NewExternalPort>%i</NewExternalPort>\r\n"\
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
117 "<NewProtocol>%s</NewProtocol>\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
118 "<NewInternalPort>%i</NewInternalPort>\r\n"\
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
119 "<NewInternalClient>%s" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
120 "</NewInternalClient>\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
121 "<NewEnabled>1</NewEnabled>\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
122 "<NewPortMappingDescription>" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
123 PORT_MAPPING_DESCRIPTION \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
124 "</NewPortMappingDescription>\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
125 "<NewLeaseDuration>" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
126 PORT_MAPPING_LEASE_TIME \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
127 "</NewLeaseDuration>\r\n"
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
128
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
129 #define DELETE_PORT_MAPPING_PARAMS "<NewRemoteHost></NewRemoteHost>\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
130 "<NewExternalPort>%i" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
131 "</NewExternalPort>\r\n" \
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
132 "<NewProtocol>%s</NewProtocol>\r\n"
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
133
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
134
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
135 static void
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
136 gaim_upnp_timeout(gpointer data,
11213
ff728e84d59a [gaim-migrate @ 13344]
Thomas Butter <tbutter>
parents: 11204
diff changeset
137 gint source,
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
138 GaimInputCondition cond)
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
139 {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
140 NetResponseData* nrd = data;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
141
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
142 gaim_input_remove(nrd->inpa);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
143 gaim_timeout_remove(nrd->tima);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
144
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
145 if(nrd->totalSizeRecv == 0 && nrd->recvBuffer != NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
146 g_free(nrd->recvBuffer);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
147 nrd->recvBuffer = NULL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
148 } else if(nrd->recvBuffer != NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
149 nrd->recvBuffer[nrd->totalSizeRecv] = '\0';
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
150 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
151
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
152 nrd->done = TRUE;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
153 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
154
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
155
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
156 static void
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
157 gaim_upnp_http_read(gpointer data,
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
158 gint sock,
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
159 GaimInputCondition cond)
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
160 {
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
161 int sizeRecv;
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
162 NetResponseData* nrd = data;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
163
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
164 sizeRecv = recv(sock, &(nrd->recvBuffer[nrd->totalSizeRecv]),
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
165 MAX_DESCRIPTION_RECEIVE_SIZE-nrd->totalSizeRecv, 0);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
166 if(sizeRecv < 0 && errno != EINTR) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
167 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
168 "gaim_upnp_http_read(): recv < 0: %i!\n\n", errno);
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
169 g_free(nrd->recvBuffer);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
170 nrd->recvBuffer = NULL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
171 gaim_timeout_remove(nrd->tima);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
172 gaim_input_remove(nrd->inpa);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
173 nrd->done = TRUE;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
174 return;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
175 }else if(errno == EINTR) {
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
176 sizeRecv = 0;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
177 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
178 nrd->totalSizeRecv += sizeRecv;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
179
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
180 if(sizeRecv == 0) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
181 gaim_timeout_remove(nrd->tima);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
182 gaim_input_remove(nrd->inpa);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
183 if(nrd->totalSizeRecv == 0) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
184 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
185 "gaim_upnp_http_read(): totalSizeRecv == 0\n\n");
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
186 g_free(nrd->recvBuffer);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
187 nrd->recvBuffer = NULL;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
188 } else {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
189 nrd->recvBuffer[nrd->totalSizeRecv] = '\0';
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
190 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
191 nrd->done = TRUE;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
192 } else {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
193 gaim_timeout_remove(nrd->tima);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
194 gaim_input_remove(nrd->inpa);
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
195 nrd->tima = gaim_timeout_add(CONSECUTIVE_RECEIVE_TIMEOUT,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
196 (GSourceFunc)gaim_upnp_timeout, nrd);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
197 nrd->inpa = gaim_input_add(sock, GAIM_INPUT_READ,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
198 gaim_upnp_http_read, nrd);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
199 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
200 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
201
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
202 static void
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
203 gaim_upnp_http_send(gpointer data,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
204 gint sock,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
205 GaimInputCondition cond)
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
206 {
11586
03cd74ca2562 [gaim-migrate @ 13856]
Nathan Walp <nwalp@pidgin.im>
parents: 11566
diff changeset
207 gsize sizeSent, totalSizeSent = 0;
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
208 NetResponseData* nrd = data;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
209
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
210 gaim_timeout_remove(nrd->tima);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
211 while(totalSizeSent < strlen(nrd->sendBuffer)) {
11586
03cd74ca2562 [gaim-migrate @ 13856]
Nathan Walp <nwalp@pidgin.im>
parents: 11566
diff changeset
212 sizeSent = send(sock,(gchar*)(nrd->sendBuffer+totalSizeSent),
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
213 strlen(nrd->sendBuffer)-totalSizeSent,0);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
214 if(sizeSent <= 0 && errno != EINTR) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
215 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
216 "gaim_upnp_http_request(): Failed In send\n\n");
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
217 nrd->done = TRUE;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
218 g_free(nrd->recvBuffer);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
219 nrd->recvBuffer = NULL;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
220 close(sock);
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
221 return;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
222 }else if(errno == EINTR) {
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
223 sizeSent = 0;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
224 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
225 totalSizeSent += sizeSent;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
226 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
227
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
228 nrd->tima = gaim_timeout_add(RECEIVE_TIMEOUT,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
229 (GSourceFunc)gaim_upnp_timeout, nrd);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
230 nrd->inpa = gaim_input_add(sock, GAIM_INPUT_READ,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
231 gaim_upnp_http_read, nrd);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
232 while (!nrd->done) {
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
233 g_main_context_iteration(NULL, TRUE);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
234 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
235 close(sock);
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
236 }
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
237
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
238 static gchar*
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
239 gaim_upnp_http_request(const gchar* address,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
240 int port,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
241 gchar* httpRequest)
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
242 {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
243 gchar* recvBuffer;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
244 NetResponseData* nrd = (NetResponseData*)g_malloc0(sizeof(NetResponseData));
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
245 nrd->sendBuffer = httpRequest;
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
246 nrd->recvBuffer = (gchar*)g_malloc(MAX_DESCRIPTION_RECEIVE_SIZE);
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
247
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
248 nrd->tima = gaim_timeout_add(RECEIVE_TIMEOUT,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
249 (GSourceFunc)gaim_upnp_timeout, nrd);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
250
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
251 if(gaim_proxy_connect(NULL, address, port,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
252 gaim_upnp_http_send, nrd)) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
253
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
254 gaim_debug_error("upnp", "Connect Failed: Address: %s @@@ Port %d @@@ Request %s\n\n",
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
255 address, port, nrd->sendBuffer);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
256
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
257 gaim_timeout_remove(nrd->tima);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
258 g_free(nrd->recvBuffer);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
259 nrd->recvBuffer = NULL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
260 } else {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
261 while (!nrd->done) {
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
262 g_main_context_iteration(NULL, TRUE);
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
263 }
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
264 }
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
265
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
266 recvBuffer = nrd->recvBuffer;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
267 g_free(nrd);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
268
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
269 return recvBuffer;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
270 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
271
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
272
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
273
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
274 static gboolean
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
275 gaim_upnp_compare_device(const xmlnode* device,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
276 const gchar* deviceType)
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
277 {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
278 xmlnode* deviceTypeNode = xmlnode_get_child(device, "deviceType");
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
279 if(deviceTypeNode == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
280 return FALSE;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
281 }
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
282 return !g_ascii_strcasecmp(xmlnode_get_data(deviceTypeNode), deviceType);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
283 }
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
284
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
285
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
286 static gboolean
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
287 gaim_upnp_compare_service(const xmlnode* service,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
288 const gchar* serviceType)
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
289 {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
290 xmlnode* serviceTypeNode = xmlnode_get_child(service, "serviceType");
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
291 if(serviceTypeNode == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
292 return FALSE;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
293 }
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
294 return !g_ascii_strcasecmp(xmlnode_get_data(serviceTypeNode), serviceType);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
295 }
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
296
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
297
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
298
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
299 static gchar*
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
300 gaim_upnp_parse_description_response(const gchar* httpResponse,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
301 const gchar* httpURL,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
302 const gchar* serviceType)
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
303 {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
304 gchar* xmlRoot;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
305 gchar* baseURL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
306 gchar* controlURL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
307 gchar* service;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
308 xmlnode* xmlRootNode;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
309 xmlnode* serviceTypeNode;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
310 xmlnode* controlURLNode;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
311 xmlnode* baseURLNode;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
312
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
313 /* make sure we have a valid http response */
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
314 if(g_strstr_len(httpResponse, strlen(httpResponse), HTTP_OK) == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
315 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
316 "parse_description_response(): Failed In HTTP_OK\n\n");
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
317 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
318 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
319
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
320 /* find the root of the xml document */
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
321 if((xmlRoot = g_strstr_len(httpResponse, strlen(httpResponse),
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
322 "<root")) == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
323 gaim_debug_error("upnp",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
324 "parse_description_response(): Failed finding root\n\n");
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
325 return NULL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
326 }
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
327
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
328 /* create the xml root node */
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
329 if((xmlRootNode = xmlnode_from_str(xmlRoot, -1)) == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
330 gaim_debug_error("upnp",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
331 "parse_description_response(): Could not parse xml root node\n\n");
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
332 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
333 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
334
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
335 /* get the baseURL of the device */
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
336 if((baseURLNode = xmlnode_get_child(xmlRootNode,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
337 "URLBase")) != NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
338 baseURL = g_strdup(xmlnode_get_data(baseURLNode));
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
339 } else {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
340 baseURL = g_strdup(httpURL);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
341 }
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
342
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
343 /* get the serviceType child that has the service type as it's data */
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
344
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
345 /* get urn:schemas-upnp-org:device:InternetGatewayDevice:1
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
346 and it's devicelist */
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
347 serviceTypeNode = xmlnode_get_child(xmlRootNode, "device");
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
348 while(!gaim_upnp_compare_device(serviceTypeNode,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
349 "urn:schemas-upnp-org:device:InternetGatewayDevice:1") &&
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
350 serviceTypeNode != NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
351 serviceTypeNode = xmlnode_get_next_twin(serviceTypeNode);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
352 }
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
353 if(serviceTypeNode == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
354 gaim_debug_error("upnp",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
355 "parse_description_response(): could not get serviceTypeNode 1\n\n");
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
356 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
357 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
358 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "deviceList");
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
359 if(serviceTypeNode == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
360 gaim_debug_error("upnp",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
361 "parse_description_response(): could not get serviceTypeNode 2\n\n");
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
362 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
363 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
364
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
365 /* get urn:schemas-upnp-org:device:WANDevice:1
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
366 and it's devicelist */
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
367 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "device");
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
368 while(!gaim_upnp_compare_device(serviceTypeNode,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
369 "urn:schemas-upnp-org:device:WANDevice:1") &&
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
370 serviceTypeNode != NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
371 serviceTypeNode = xmlnode_get_next_twin(serviceTypeNode);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
372 }
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
373 if(serviceTypeNode == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
374 gaim_debug_error("upnp",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
375 "parse_description_response(): could not get serviceTypeNode 3\n\n");
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
376 return NULL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
377 }
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
378 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "deviceList");
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
379 if(serviceTypeNode == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
380 gaim_debug_error("upnp",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
381 "parse_description_response(): could not get serviceTypeNode 4\n\n");
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
382 return NULL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
383 }
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
384
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
385 /* get urn:schemas-upnp-org:device:WANConnectionDevice:1
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
386 and it's servicelist */
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
387 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "device");
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
388 while(!gaim_upnp_compare_device(serviceTypeNode,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
389 "urn:schemas-upnp-org:device:WANConnectionDevice:1") &&
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
390 serviceTypeNode != NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
391 serviceTypeNode = xmlnode_get_next_twin(serviceTypeNode);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
392 }
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
393 if(serviceTypeNode == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
394 gaim_debug_error("upnp",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
395 "parse_description_response(): could not get serviceTypeNode 5\n\n");
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
396 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
397 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
398 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "serviceList");
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
399 if(serviceTypeNode == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
400 gaim_debug_error("upnp",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
401 "parse_description_response(): could not get serviceTypeNode 6\n\n");
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
402 return NULL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
403 }
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
404
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
405 /* get the serviceType variable passed to this function */
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
406 service = g_strdup_printf(SEARCH_REQUEST_DEVICE, serviceType);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
407 serviceTypeNode = xmlnode_get_child(serviceTypeNode, "service");
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
408 while(!gaim_upnp_compare_service(serviceTypeNode, service) &&
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
409 serviceTypeNode != NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
410 serviceTypeNode = xmlnode_get_next_twin(serviceTypeNode);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
411 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
412
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
413 g_free(service);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
414 if(serviceTypeNode == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
415 gaim_debug_error("upnp",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
416 "parse_description_response(): could not get serviceTypeNode 7\n\n");
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
417 return NULL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
418 }
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
419
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
420 /* get the controlURL of the service */
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
421 if((controlURLNode = xmlnode_get_child(serviceTypeNode,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
422 "controlURL")) == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
423 gaim_debug_error("upnp",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
424 "parse_description_response(): Could not find controlURL\n\n");
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
425 return NULL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
426 }
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
427
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
428 if(g_strstr_len(xmlnode_get_data(controlURLNode),
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
429 SIZEOF_HTTP, "http://") == NULL &&
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
430 g_strstr_len(xmlnode_get_data(controlURLNode),
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
431 SIZEOF_HTTP, "HTTP://") == NULL) {
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
432 controlURL = g_strdup_printf("%s%s", baseURL,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
433 xmlnode_get_data(controlURLNode));
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
434 }else{
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
435 controlURL = g_strdup(xmlnode_get_data(controlURLNode));
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
436 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
437 g_free(baseURL);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
438 xmlnode_free(xmlRootNode);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
439
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
440 return controlURL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
441 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
442
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
443
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
444 static gchar*
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
445 gaim_upnp_parse_description(const gchar* descriptionURL,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
446 const gchar* serviceType)
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
447 {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
448 gchar* fullURL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
449 gchar* controlURL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
450 gchar* httpResponse;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
451 gchar* httpRequest;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
452
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
453 gchar* descriptionXMLAddress;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
454 gchar* descriptionAddressPort;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
455 gchar* descriptionAddress;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
456 gchar descriptionPort[MAX_PORT_SIZE];
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
457 int port = 0;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
458
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
459 /* parse the 4 above variables out of the descriptionURL
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
460 example description URL: http://192.168.1.1:5678/rootDesc.xml */
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
461
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
462 /* parse the url into address, port, path variables */
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
463 if(!gaim_url_parse(descriptionURL, &descriptionAddress,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
464 &port, &descriptionXMLAddress, NULL, NULL)) {
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
465 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
466 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
467 if(port == 0 || port == -1) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
468 port = DEFAULT_HTTP_PORT;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
469 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
470 g_ascii_dtostr(descriptionPort, MAX_PORT_SIZE, port);
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
471 descriptionAddressPort = g_strdup_printf("%s:%s", descriptionAddress,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
472 descriptionPort);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
473
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
474 fullURL = g_strdup_printf("http://%s", descriptionAddressPort);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
475
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
476 /* for example...
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
477 GET /rootDesc.xml HTTP/1.1\r\nHost: 192.168.1.1:5678\r\n\r\n */
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
478 httpRequest = g_strdup_printf("GET /%s HTTP/1.1\r\nHost: %s\r\n\r\n",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
479 descriptionXMLAddress, descriptionAddressPort);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
480
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
481 httpResponse = gaim_upnp_http_request(descriptionAddress,
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
482 port, httpRequest);
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
483 if(httpResponse == NULL) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
484 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
485 "gaim_upnp_parse_description(): httpResponse is NULL\n\n");
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
486 g_free(descriptionXMLAddress);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
487 g_free(descriptionAddress);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
488 g_free(descriptionAddressPort);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
489 g_free(httpRequest);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
490 g_free(fullURL);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
491 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
492 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
493
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
494 controlURL = gaim_upnp_parse_description_response(httpResponse,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
495 fullURL, serviceType);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
496
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
497 g_free(descriptionXMLAddress);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
498 g_free(descriptionAddress);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
499 g_free(descriptionAddressPort);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
500 g_free(fullURL);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
501 g_free(httpRequest);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
502 g_free(httpResponse);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
503
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
504 if(controlURL == NULL) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
505 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
506 "gaim_upnp_parse_description(): controlURL is NULL\n\n");
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
507 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
508 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
509
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
510 return controlURL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
511 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
512
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
513
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
514 static gchar*
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
515 gaim_upnp_parse_discover_response(const gchar* buf,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
516 unsigned int bufSize,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
517 const gchar* serviceType)
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
518 {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
519 gchar* startDescURL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
520 gchar* endDescURL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
521 gchar* descURL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
522 gchar* retVal;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
523
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
524 if(g_strstr_len(buf, strlen(buf), HTTP_OK) == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
525 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
526 "parse_discover_response(): Failed In HTTP_OK\n\n");
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
527 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
528 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
529
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
530 if((startDescURL = g_strstr_len(buf, strlen(buf), "http://")) == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
531 gaim_debug_error("upnp",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
532 "parse_discover_response(): Failed In finding http://\n\n");
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
533 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
534 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
535
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
536 endDescURL = g_strstr_len(startDescURL, strlen(startDescURL), "\r");
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
537 if(endDescURL == NULL) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
538 endDescURL = g_strstr_len(startDescURL, strlen(startDescURL), "\n");
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
539 if(endDescURL == NULL) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
540 gaim_debug_error("upnp",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
541 "parse_discover_response(): Failed In endDescURL\n\n");
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
542 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
543 }else if(endDescURL == startDescURL) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
544 gaim_debug_error("upnp",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
545 "parse_discover_response(): endDescURL == startDescURL\n\n");
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
546 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
547 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
548 }else if(endDescURL == startDescURL) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
549 gaim_debug_error("upnp",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
550 "parse_discover_response(): 2nd endDescURL == startDescURL\n\n");
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
551 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
552 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
553 descURL = g_strndup(startDescURL, endDescURL-startDescURL);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
554
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
555 retVal = gaim_upnp_parse_description(descURL, serviceType);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
556 g_free(descURL);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
557 return retVal;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
558 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
559
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
560
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
561
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
562 static void
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
563 gaim_upnp_discover_udp_read(gpointer data,
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
564 gint sock,
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
565 GaimInputCondition cond)
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
566 {
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
567 unsigned int length;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
568 struct sockaddr_in from;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
569 int sizeRecv;
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
570 NetResponseData* nrd = data;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
571
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
572 gaim_timeout_remove(nrd->tima);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
573 length = sizeof(struct sockaddr_in);
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
574
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
575 do {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
576 sizeRecv = recvfrom(sock, nrd->recvBuffer,
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
577 MAX_DISCOVERY_RECEIVE_SIZE, 0,
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
578 (struct sockaddr*)&from, &length);
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
579
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
580 if(sizeRecv > 0) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
581 nrd->recvBuffer[sizeRecv] = '\0';
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
582 }else if(errno != EINTR) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
583 g_free(nrd->recvBuffer);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
584 nrd->recvBuffer = NULL;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
585 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
586 }while(errno == EINTR);
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
587
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
588 gaim_input_remove(nrd->inpa);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
589 nrd->done = TRUE;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
590 return;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
591 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
592
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
593
11213
ff728e84d59a [gaim-migrate @ 13344]
Thomas Butter <tbutter>
parents: 11204
diff changeset
594
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
595 GaimUPnPControlInfo*
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
596 gaim_upnp_discover(void)
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
597 {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
598 /* Socket Setup Variables */
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
599 int sock, i;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
600 struct sockaddr_in server;
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
601 struct hostent* hp;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
602
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
603 /* UDP SEND VARIABLES */
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
604 gboolean sentSuccess, recvSuccess;
12207
201be1b681a4 [gaim-migrate @ 14509]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
605 ssize_t sizeSent;
201be1b681a4 [gaim-migrate @ 14509]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
606 ssize_t totalSizeSent;
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
607 gchar wanIP[] = "WANIPConnection:1";
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
608 gchar wanPPP[] = "WANPPPConnection:1";
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
609 gchar* serviceToUse;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
610 gchar* sendMessage = NULL;
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
611
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
612 /* UDP RECEIVE VARIABLES */
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
613 GaimUPnPControlInfo* controlInfo = g_malloc(sizeof(GaimUPnPControlInfo));
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
614 NetResponseData* nrd = g_malloc(sizeof(NetResponseData));
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
615
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
616 /* Set up the sockets */
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
617 sock = socket(AF_INET, SOCK_DGRAM, 0);
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
618 if (sock == -1) {
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
619 close(sock);
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
620 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
621 "gaim_upnp_discover(): Failed In sock creation\n\n");
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
622 g_free(nrd);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
623 g_free(controlInfo);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
624 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
625 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
626 memset(&server, 0, sizeof(struct sockaddr));
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
627 server.sin_family = AF_INET;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
628 if((hp = gethostbyname(HTTPMU_HOST_ADDRESS)) == NULL) {
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
629 close(sock);
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
630 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
631 "gaim_upnp_discover(): Failed In gethostbyname\n\n");
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
632 g_free(nrd);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
633 g_free(controlInfo);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
634 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
635 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
636 memcpy(&server.sin_addr,
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
637 hp->h_addr_list[0],
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
638 hp->h_length);
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
639 server.sin_port = htons(HTTPMU_HOST_PORT);
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
640
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
641 /* because we are sending over UDP, if there is a failure
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
642 we should retry the send NUM_UDP_ATTEMPTS times. Also,
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
643 try different requests for WANIPConnection and
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
644 WANPPPConnection*/
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
645 for(i = 0; i < NUM_UDP_ATTEMPTS; i++) {
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
646 sentSuccess = TRUE;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
647 recvSuccess = TRUE;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
648 totalSizeSent = 0;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
649
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
650 nrd->recvBuffer = NULL;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
651 nrd->totalSizeRecv = 0;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
652 nrd->done = FALSE;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
653
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
654 if(sendMessage != NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
655 g_free(sendMessage);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
656 }
11213
ff728e84d59a [gaim-migrate @ 13344]
Thomas Butter <tbutter>
parents: 11204
diff changeset
657
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
658 if(i%2 == 0) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
659 serviceToUse = wanIP;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
660 } else {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
661 serviceToUse = wanPPP;
11213
ff728e84d59a [gaim-migrate @ 13344]
Thomas Butter <tbutter>
parents: 11204
diff changeset
662 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
663 sendMessage = g_strdup_printf(SEARCH_REQUEST_STRING, serviceToUse);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
664
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
665 nrd->recvBuffer = (char*)g_malloc(MAX_DISCOVERY_RECEIVE_SIZE);
11213
ff728e84d59a [gaim-migrate @ 13344]
Thomas Butter <tbutter>
parents: 11204
diff changeset
666
12207
201be1b681a4 [gaim-migrate @ 14509]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
667 while(totalSizeSent < (ssize_t)strlen(sendMessage)) {
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
668 sizeSent = sendto(sock,(void*)&sendMessage[totalSizeSent],
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
669 strlen(&sendMessage[totalSizeSent]),0,
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
670 (struct sockaddr*)&server,
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
671 sizeof(struct sockaddr_in));
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
672 if(sizeSent <= 0 && errno != EINTR) {
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
673 sentSuccess = FALSE;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
674 break;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
675 }else if(errno == EINTR) {
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
676 sizeSent = 0;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
677 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
678 totalSizeSent += sizeSent;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
679 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
680
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
681 if(sentSuccess) {
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
682 nrd->tima = gaim_timeout_add(DISCOVERY_TIMEOUT,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
683 (GSourceFunc)gaim_upnp_timeout, nrd);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
684 nrd->inpa = gaim_input_add(sock, GAIM_INPUT_READ,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
685 gaim_upnp_discover_udp_read, nrd);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
686 while (!nrd->done) {
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
687 g_main_context_iteration(NULL, TRUE);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
688 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
689 if(nrd->recvBuffer == NULL) {
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
690 recvSuccess = FALSE;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
691 } else {
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
692 /* parse the response, and see if it was a success */
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
693 close(sock);
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
694 if((controlInfo->controlURL=
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
695 gaim_upnp_parse_discover_response(nrd->recvBuffer,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
696 strlen(nrd->recvBuffer),
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
697 serviceToUse))==NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
698 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
699 "gaim_upnp_discover(): Failed In parse response\n\n");
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
700 g_free(nrd->recvBuffer);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
701 g_free(nrd);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
702 g_free(controlInfo);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
703 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
704 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
705
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
706 controlInfo->serviceType = g_strdup(serviceToUse);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
707 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
708 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
709
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
710 /* if sent success and recv successful, then break */
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
711 if(sentSuccess && recvSuccess) {
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
712 i = NUM_UDP_ATTEMPTS;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
713 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
714 }
11213
ff728e84d59a [gaim-migrate @ 13344]
Thomas Butter <tbutter>
parents: 11204
diff changeset
715
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
716 if(nrd->recvBuffer != NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
717 g_free(nrd->recvBuffer);
11213
ff728e84d59a [gaim-migrate @ 13344]
Thomas Butter <tbutter>
parents: 11204
diff changeset
718 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
719 g_free(sendMessage);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
720 g_free(nrd);
11213
ff728e84d59a [gaim-migrate @ 13344]
Thomas Butter <tbutter>
parents: 11204
diff changeset
721
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
722 if(!sentSuccess || !recvSuccess) {
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
723 close(sock);
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
724 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
725 "gaim_upnp_discover(): Failed In sent/recv success\n\n");
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
726 g_free(controlInfo);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
727 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
728 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
729
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
730 return controlInfo;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
731 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
732
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
733
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
734 static char*
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
735 gaim_upnp_generate_action_message_and_send(const GaimUPnPControlInfo* controlInfo,
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
736 const gchar* actionName,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
737 const gchar* actionParams)
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
738 {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
739 gchar* actionMessage;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
740 gchar* soapMessage;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
741 gchar* totalSendMessage;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
742 gchar* httpResponse;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
743
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
744 gchar* pathOfControl;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
745 gchar* addressOfControl;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
746 gchar* addressPortOfControl;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
747 gchar portOfControl[MAX_PORT_SIZE];
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
748 int port=0;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
749
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
750 /* set the soap message */
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
751 soapMessage = g_strdup_printf(SOAP_ACTION, actionName,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
752 controlInfo->serviceType,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
753 actionParams, actionName);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
754
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
755 /* parse the url into address, port, path variables */
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
756 if(!gaim_url_parse(controlInfo->controlURL, &addressOfControl,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
757 &port, &pathOfControl, NULL, NULL)) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
758 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
759 "generate_action_message_and_send(): Failed In Parse URL\n\n");
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
760 g_free(soapMessage);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
761 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
762 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
763 if(port == 0 || port == -1) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
764 port = DEFAULT_HTTP_PORT;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
765 }
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
766 g_ascii_dtostr(portOfControl, MAX_PORT_SIZE, port);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
767
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
768 /* set the addressPortOfControl variable which should have a
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
769 form like the following: 192.168.1.1:8000 */
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
770 addressPortOfControl = g_strdup_printf("%s:%s",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
771 addressOfControl, portOfControl);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
772
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
773 /* set the HTTP Header */
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
774 actionMessage = g_strdup_printf(HTTP_HEADER_ACTION,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
775 pathOfControl, addressPortOfControl,
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
776 controlInfo->serviceType, actionName,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
777 strlen(soapMessage));
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
778
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
779 /* append to the header the body */
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
780 totalSendMessage = g_strdup_printf("%s%s", actionMessage, soapMessage);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
781
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
782 /* get the return of the http response */
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
783 httpResponse = gaim_upnp_http_request(addressOfControl,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
784 port, totalSendMessage);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
785 if(httpResponse == NULL) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
786 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
787 "generate_action_message_and_send(): Failed In httpResponse\n\n");
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
788 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
789
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
790 g_free(actionMessage);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
791 g_free(soapMessage);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
792 g_free(totalSendMessage);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
793 g_free(pathOfControl);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
794 g_free(addressOfControl);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
795 g_free(addressPortOfControl);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
796
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
797 return httpResponse;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
798 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
799
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
800
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
801
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
802
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
803 gchar*
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
804 gaim_upnp_get_public_ip(const GaimUPnPControlInfo* controlInfo)
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
805 {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
806 gchar* extIPAddress;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
807 gchar* httpResponse;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
808 gchar actionName[] = "GetExternalIPAddress";
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
809 gchar actionParams[] = "";
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
810 gchar* temp, *temp2;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
811
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
812 httpResponse = gaim_upnp_generate_action_message_and_send(controlInfo,
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
813 actionName,
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
814 actionParams);
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
815 if(httpResponse == NULL) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
816 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
817 "gaim_upnp_get_public_ip(): Failed In httpResponse\n\n");
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
818 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
819 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
820
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
821 /* extract the ip, or see if there is an error */
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
822 if((temp = g_strstr_len(httpResponse, strlen(httpResponse),
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
823 "<NewExternalIPAddress")) == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
824 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
825 "gaim_upnp_get_public_ip(): Failed Finding <NewExternalIPAddress\n\n");
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
826 g_free(httpResponse);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
827 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
828 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
829 if((temp = g_strstr_len(temp, strlen(temp), ">")) == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
830 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
831 "gaim_upnp_get_public_ip(): Failed In Finding >\n\n");
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
832 g_free(httpResponse);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
833 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
834 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
835 if((temp2 = g_strstr_len(temp, strlen(temp), "<")) == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
836 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
837 "gaim_upnp_get_public_ip(): Failed In Finding <\n\n");
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
838 g_free(httpResponse);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
839 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
840 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
841
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
842 extIPAddress = g_strndup(&temp[1], (temp2-1)-temp);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
843
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
844 g_free(httpResponse);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
845
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
846 gaim_debug_info("upnp", "NAT Returned IP: %s\n", extIPAddress);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
847 return extIPAddress;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
848 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
849
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
850 static void
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
851 gaim_upnp_get_local_system_ip(gpointer data,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
852 gint sock,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
853 GaimInputCondition cond)
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
854 {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
855 NetResponseData* nrd = data;
11443
d9d60002065b [gaim-migrate @ 13682]
Richard Laager <rlaager@wiktel.com>
parents: 11391
diff changeset
856 nrd->recvBuffer = g_strdup(gaim_network_get_local_system_ip(sock));
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
857
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
858 gaim_timeout_remove(nrd->tima);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
859 nrd->done = TRUE;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
860
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
861 close(sock);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
862 }
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
863
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
864 static gchar*
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
865 gaim_upnp_get_local_ip_address(const gchar* address)
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
866 {
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
867 gchar* ip;
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
868 gchar* pathOfControl;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
869 gchar* addressOfControl;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
870 int port = 0;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
871 NetResponseData* nrd = (NetResponseData*)g_malloc0(sizeof(NetResponseData));
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
872
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
873 if(!gaim_url_parse(address, &addressOfControl,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
874 &port, &pathOfControl, NULL, NULL)) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
875 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
876 "get_local_ip_address(): Failed In Parse URL\n\n");
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
877 return NULL;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
878 }
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
879 if(port == 0 || port == -1) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
880 port = DEFAULT_HTTP_PORT;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
881 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
882
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
883 nrd->tima = gaim_timeout_add(RECEIVE_TIMEOUT,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
884 (GSourceFunc)gaim_upnp_timeout, nrd);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
885
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
886 if(gaim_proxy_connect(NULL, addressOfControl, port,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
887 gaim_upnp_get_local_system_ip, nrd)) {
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
888
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
889 gaim_debug_error("upnp", "Get Local IP Connect Failed: Address: %s @@@ Port %d @@@ Request %s\n\n",
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
890 address, port, nrd->sendBuffer);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
891
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
892 gaim_timeout_remove(nrd->tima);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
893 } else {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
894 while (!nrd->done) {
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
895 g_main_context_iteration(NULL, TRUE);
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
896 }
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
897 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
898
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
899 ip = nrd->recvBuffer;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
900 g_free(nrd);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
901
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
902 gaim_debug_info("upnp", "local ip: %s\n", ip);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
903
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
904 return ip;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
905 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
906
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
907
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
908
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
909 gboolean
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
910 gaim_upnp_set_port_mapping(const GaimUPnPControlInfo* controlInfo,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
911 unsigned short portMap,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
912 const gchar* protocol)
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
913 {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
914 gchar* httpResponse;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
915 gchar actionName[] = "AddPortMapping";
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
916 gchar* actionParams;
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
917 gchar* internalIP;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
918
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
919 /* get the internal IP */
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
920 if((internalIP = gaim_upnp_get_local_ip_address(controlInfo->controlURL))
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
921 == NULL) {
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
922 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
923 "gaim_upnp_set_port_mapping(): couldn't get local ip\n\n");
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
924 return FALSE;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
925 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
926
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
927 /* make the portMappingParams variable */
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
928 actionParams = g_strdup_printf(ADD_PORT_MAPPING_PARAMS, portMap,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
929 protocol, portMap, internalIP);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
930
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
931 httpResponse = gaim_upnp_generate_action_message_and_send(controlInfo,
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
932 actionName,
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
933 actionParams);
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
934 if(httpResponse == NULL) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
935 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
936 "gaim_upnp_set_port_mapping(): Failed In httpResponse\n\n");
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
937 g_free(actionParams);
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
938 g_free(internalIP);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
939 return FALSE;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
940 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
941
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
942 /* determine if port mapping was a success */
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
943 if(strstr(httpResponse, HTTP_OK) == NULL) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
944 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
945 "gaim_upnp_set_port_mapping(): Failed HTTP_OK\n\n%s\n\n", httpResponse);
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
946 g_free(actionParams);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
947 g_free(httpResponse);
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
948 g_free(internalIP);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
949 return FALSE;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
950 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
951
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
952 g_free(actionParams);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
953 g_free(httpResponse);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
954
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
955 gaim_debug_info("upnp", "NAT Added Port Forward On Port: %d: To IP: %s\n", portMap, internalIP);
11492
18c6a6659770 [gaim-migrate @ 13735]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11443
diff changeset
956 g_free(internalIP);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
957 return TRUE;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
958 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
959
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
960
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
961 gboolean
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
962 gaim_upnp_remove_port_mapping(const GaimUPnPControlInfo* controlInfo,
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
963 unsigned short portMap,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
964 const char* protocol)
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
965 {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
966 gchar* httpResponse;
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
967 gchar actionName[] = "DeletePortMapping";
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
968 gchar* actionParams;
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
969
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
970 /* make the portMappingParams variable */
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
971 actionParams = g_strdup_printf(DELETE_PORT_MAPPING_PARAMS,
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
972 portMap, protocol);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
973
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
974 httpResponse = gaim_upnp_generate_action_message_and_send(controlInfo,
11566
7897207b522d [gaim-migrate @ 13832]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11492
diff changeset
975 actionName,
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
976 actionParams);
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
977
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
978 if(httpResponse == NULL) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
979 gaim_debug_error("upnp",
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
980 "gaim_upnp_remove_port_mapping(): Failed In httpResponse\n\n");
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
981 g_free(actionParams);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
982 return FALSE;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
983 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
984
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
985 /* determine if port mapping was a success */
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
986 if(strstr(httpResponse, HTTP_OK) == NULL) {
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
987 gaim_debug_error("upnp",
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
988 "gaim_upnp_set_port_mapping(): Failed HTTP_OK\n\n%s\n\n", httpResponse);
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
989 g_free(actionParams);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
990 g_free(httpResponse);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
991 return FALSE;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
992 }
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
993
11391
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
994 g_free(actionParams);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
995 g_free(httpResponse);
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
996
d3755a7ddd82 [gaim-migrate @ 13620]
Adam Warrington <awarring>
parents: 11213
diff changeset
997 gaim_debug_info("upnp", "NAT Removed Port Forward On Port: %d\n", portMap);
11195
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
998 return TRUE;
3aeb85cc9cda [gaim-migrate @ 13319]
Adam Warrington <awarring>
parents:
diff changeset
999 }