Mercurial > pidgin
annotate src/protocols/msn/httpmethod.c @ 8671:d99d2572d1a9
[gaim-migrate @ 9423]
This is a feature requested by warren from the Fedora project. If a
/etc/gaim/prefs.xml file exists, and no $HOME/.gaim/prefs.xml exists,
/etc/gaim/prefs.xml will be read in. This is currently only enabled if Gaim
isn't compiled on Windows, and it really shouldn't cause any trouble.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Fri, 16 Apr 2004 04:39:03 +0000 |
parents | 06f57183e29f |
children | 9885420f049f |
rev | line source |
---|---|
7288 | 1 /** |
2 * @file httpmethod.c HTTP connection method | |
3 * | |
4 * gaim | |
5 * | |
8475
06f57183e29f
[gaim-migrate @ 9208]
Christian Hammond <chipx86@chipx86.com>
parents:
8299
diff
changeset
|
6 * Copyright (C) 2003-2004 Christian Hammond <chipx86@gnupdate.org> |
7288 | 7 * |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
22 #include "debug.h" | |
23 #include "httpmethod.h" | |
24 | |
25 #define GET_NEXT(tmp) \ | |
26 while (*(tmp) && *(tmp) != ' ' && *(tmp) != '\r') \ | |
27 (tmp)++; \ | |
28 if (*(tmp) != '\0') *(tmp)++ = '\0'; \ | |
29 if (*(tmp) == '\n') (tmp)++; \ | |
30 while (*(tmp) && *(tmp) == ' ') \ | |
31 (tmp)++ | |
32 | |
33 #define GET_NEXT_LINE(tmp) \ | |
34 while (*(tmp) && *(tmp) != '\r') \ | |
35 (tmp)++; \ | |
36 if (*(tmp) != '\0') *(tmp)++ = '\0'; \ | |
37 if (*(tmp) == '\n') (tmp)++ | |
38 | |
39 typedef struct | |
40 { | |
41 MsnServConn *servconn; | |
42 char *buffer; | |
43 size_t size; | |
44 const char *server_type; | |
45 | |
46 } MsnHttpQueueData; | |
47 | |
48 static gboolean | |
49 http_poll(gpointer data) | |
50 { | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
51 MsnSession *session = data; |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
52 MsnServConn *servconn; |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
53 GList *l; |
7288 | 54 |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
55 for (l = session->servconns; l != NULL; l = l->next) |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
56 { |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
57 servconn = (MsnServConn *)l->data; |
7288 | 58 |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
59 if (servconn->http_data->dirty) |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
60 { |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
61 #if 0 |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
62 gaim_debug_info("msn", "Polling server %s.\n", |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
63 servconn->http_data->gateway_ip); |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
64 #endif |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
65 msn_http_servconn_poll(servconn); |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
66 } |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
67 } |
7288 | 68 |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
69 return TRUE; |
7288 | 70 } |
71 | |
72 static void | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
73 stop_timer(MsnSession *session) |
7288 | 74 { |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
75 if (session->http_poll_timer) |
7288 | 76 { |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
77 gaim_timeout_remove(session->http_poll_timer); |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
78 session->http_poll_timer = 0; |
7288 | 79 } |
80 } | |
81 | |
82 static void | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
83 start_timer(MsnSession *session) |
7288 | 84 { |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
85 stop_timer(session); |
7288 | 86 |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
87 session->http_poll_timer = gaim_timeout_add(2000, http_poll, session); |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
88 } |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
89 |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
90 void |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
91 msn_http_session_init(MsnSession *session) |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
92 { |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
93 g_return_if_fail(session != NULL); |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
94 |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
95 start_timer(session); |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
96 } |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
97 |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
98 void |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
99 msn_http_session_uninit(MsnSession *session) |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
100 { |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
101 g_return_if_fail(session != NULL); |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
102 |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
103 stop_timer(session); |
7288 | 104 } |
105 | |
106 size_t | |
107 msn_http_servconn_write(MsnServConn *servconn, const char *buf, size_t size, | |
108 const char *server_type) | |
109 { | |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
110 size_t s, needed; |
7288 | 111 char *params; |
112 char *temp; | |
113 gboolean first; | |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
114 int res; /* result of the write operation */ |
7288 | 115 |
116 g_return_val_if_fail(servconn != NULL, 0); | |
117 g_return_val_if_fail(buf != NULL, 0); | |
118 g_return_val_if_fail(size > 0, 0); | |
119 g_return_val_if_fail(servconn->http_data != NULL, 0); | |
120 | |
121 if (servconn->http_data->waiting_response || | |
122 servconn->http_data->queue != NULL) | |
123 { | |
124 MsnHttpQueueData *queue_data = g_new0(MsnHttpQueueData, 1); | |
125 | |
126 queue_data->servconn = servconn; | |
127 queue_data->buffer = g_strdup(buf); | |
128 queue_data->size = size; | |
129 queue_data->server_type = server_type; | |
130 | |
131 servconn->http_data->queue = | |
132 g_list_append(servconn->http_data->queue, queue_data); | |
133 | |
134 return size; | |
135 } | |
136 | |
137 first = servconn->http_data->virgin; | |
138 | |
139 if (first) | |
140 { | |
141 if (server_type) | |
142 { | |
143 params = g_strdup_printf("Action=open&Server=%s&IP=%s", | |
144 server_type, | |
145 servconn->http_data->gateway_ip); | |
146 } | |
147 else | |
148 { | |
149 params = g_strdup_printf("Action=open&IP=%s", | |
150 servconn->http_data->gateway_ip); | |
151 } | |
152 } | |
153 else | |
154 { | |
155 params = g_strdup_printf("SessionID=%s", | |
156 servconn->http_data->session_id); | |
157 } | |
158 | |
159 temp = g_strdup_printf( | |
160 "POST http://%s/gateway/gateway.dll?%s HTTP/1.1\r\n" | |
161 "Accept: */*\r\n" | |
162 "Accept-Language: en-us\r\n" | |
163 "User-Agent: MSMSGS\r\n" | |
164 "Host: %s\r\n" | |
165 "Proxy-Connection: Keep-Alive\r\n" | |
166 "Connection: Keep-Alive\r\n" | |
167 "Pragma: no-cache\r\n" | |
168 "Content-Type: application/x-msn-messenger\r\n" | |
169 "Content-Length: %d\r\n" | |
170 "\r\n" | |
171 "%s", | |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
172 ((strcmp(server_type, "SB") == 0) && first |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
173 ? "gateway.messenger.hotmail.com" |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
174 : servconn->http_data->gateway_ip), |
7288 | 175 params, |
176 servconn->http_data->gateway_ip, | |
7386 | 177 (int)size, |
7288 | 178 buf); |
179 | |
180 g_free(params); | |
181 | |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
182 #if 0 |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
183 gaim_debug_misc("msn", "Writing HTTP to fd %d: {%s}\n", |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
184 servconn->fd, temp); |
7288 | 185 #endif |
186 | |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
187 s = 0; |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
188 needed = strlen(temp); |
8207
aa44049e8891
[gaim-migrate @ 8930]
Christian Hammond <chipx86@chipx86.com>
parents:
7834
diff
changeset
|
189 |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
190 do { |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
191 res = write(servconn->fd, temp, needed); |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
192 if (res >= 0) |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
193 s += res; |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
194 else if (errno != EAGAIN) { |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
195 char *msg = g_strdup_printf("Unable to write to MSN server via HTTP (error %d)", errno); |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
196 gaim_connection_error(servconn->session->account->gc, msg); |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
197 g_free(msg); |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
198 return -1; |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
199 } |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
200 } while (s < needed); |
8207
aa44049e8891
[gaim-migrate @ 8930]
Christian Hammond <chipx86@chipx86.com>
parents:
7834
diff
changeset
|
201 |
7288 | 202 g_free(temp); |
203 | |
204 servconn->http_data->waiting_response = TRUE; | |
205 servconn->http_data->virgin = FALSE; | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
206 servconn->http_data->dirty = FALSE; |
7288 | 207 |
208 return s; | |
209 } | |
210 | |
211 void | |
212 msn_http_servconn_poll(MsnServConn *servconn) | |
213 { | |
214 size_t s; | |
215 char *temp; | |
216 | |
217 g_return_if_fail(servconn != NULL); | |
218 g_return_if_fail(servconn->http_data != NULL); | |
219 | |
220 if (servconn->http_data->waiting_response || | |
221 servconn->http_data->queue != NULL) | |
222 { | |
223 return; | |
224 } | |
225 | |
226 temp = g_strdup_printf( | |
227 "POST http://%s/gateway/gateway.dll?Action=poll&SessionID=%s HTTP/1.1\r\n" | |
228 "Accept: */*\r\n" | |
229 "Accept-Language: en-us\r\n" | |
230 "User-Agent: MSMSGS\r\n" | |
231 "Host: %s\r\n" | |
232 "Proxy-Connection: Keep-Alive\r\n" | |
233 "Connection: Keep-Alive\r\n" | |
234 "Pragma: no-cache\r\n" | |
235 "Content-Type: application/x-msn-messenger\r\n" | |
236 "Content-Length: 0\r\n" | |
237 "\r\n", | |
238 servconn->http_data->gateway_ip, | |
239 servconn->http_data->session_id, | |
240 servconn->http_data->gateway_ip); | |
241 | |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
242 #if 0 |
7288 | 243 gaim_debug_misc("msn", "Writing to HTTP: {%s}\n", temp); |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
244 #endif |
7288 | 245 |
246 s = write(servconn->fd, temp, strlen(temp)); | |
247 | |
248 g_free(temp); | |
249 | |
250 servconn->http_data->waiting_response = TRUE; | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
251 servconn->http_data->dirty = FALSE; |
7288 | 252 |
253 if (s <= 0) | |
254 gaim_connection_error(servconn->session->account->gc, | |
255 _("Write error")); | |
256 } | |
257 | |
258 gboolean | |
259 msn_http_servconn_parse_data(MsnServConn *servconn, const char *buf, | |
260 size_t size, char **ret_buf, size_t *ret_size, | |
261 gboolean *error) | |
262 { | |
263 GaimConnection *gc; | |
264 const char *s, *c; | |
265 char *headers, *body; | |
266 char *tmp; | |
267 size_t len = 0; | |
268 | |
269 g_return_val_if_fail(servconn != NULL, FALSE); | |
270 g_return_val_if_fail(buf != NULL, FALSE); | |
271 g_return_val_if_fail(size > 0, FALSE); | |
272 g_return_val_if_fail(ret_buf != NULL, FALSE); | |
273 g_return_val_if_fail(ret_size != NULL, FALSE); | |
274 g_return_val_if_fail(error != NULL, FALSE); | |
275 | |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
276 #if 0 |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
277 gaim_debug_info("msn", "parsing data {%s} from fd %d\n", buf, servconn->fd); |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
278 #endif |
7288 | 279 servconn->http_data->waiting_response = FALSE; |
280 | |
281 gc = gaim_account_get_connection(servconn->session->account); | |
282 | |
283 /* Healthy defaults. */ | |
284 *ret_buf = NULL; | |
285 *ret_size = 0; | |
286 *error = FALSE; | |
287 | |
288 /* First, some tests to see if we have a full block of stuff. */ | |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
289 if (((strncmp(buf, "HTTP/1.1 200 OK\r\n", 17) != 0) && |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
290 (strncmp(buf, "HTTP/1.1 100 Continue\r\n", 23) != 0)) && |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
291 ((strncmp(buf, "HTTP/1.0 200 OK\r\n", 17) != 0) && |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
292 (strncmp(buf, "HTTP/1.0 100 Continue\r\n", 23) != 0))) |
7288 | 293 { |
294 *error = TRUE; | |
295 return FALSE; | |
296 } | |
297 | |
298 if (strncmp(buf, "HTTP/1.1 100 Continue\r\n", 23) == 0) | |
299 { | |
300 if ((s = strstr(buf, "\r\n\r\n")) == NULL) | |
301 return FALSE; | |
302 | |
303 s += 4; | |
304 | |
305 if (*s == '\0') | |
306 { | |
307 *ret_buf = g_strdup(""); | |
308 *ret_size = 0; | |
309 | |
310 return TRUE; | |
311 } | |
312 | |
313 buf = s; | |
314 size -= (s - buf); | |
315 } | |
316 | |
317 if ((s = strstr(buf, "\r\n\r\n")) == NULL) | |
318 return FALSE; | |
319 | |
320 headers = g_strndup(buf, s - buf); | |
321 s += 4; /* Skip \r\n */ | |
322 body = g_strndup(s, size - (s - buf)); | |
323 | |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
324 #if 0 |
7288 | 325 gaim_debug_misc("msn", "Incoming HTTP buffer: {%s\r\n%s}", headers, body); |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
326 #endif |
7288 | 327 |
328 if ((s = strstr(headers, "Content-Length: ")) != NULL) | |
329 { | |
330 s += strlen("Content-Length: "); | |
331 | |
332 if ((c = strchr(s, '\r')) == NULL) | |
333 { | |
334 g_free(headers); | |
335 g_free(body); | |
336 | |
337 return FALSE; | |
338 } | |
339 | |
340 tmp = g_strndup(s, c - s); | |
341 len = atoi(tmp); | |
342 g_free(tmp); | |
343 | |
344 if (strlen(body) != len) | |
345 { | |
346 g_free(headers); | |
347 g_free(body); | |
348 | |
349 gaim_debug_warning("msn", | |
350 "body length (%d) != content length (%d)\n", | |
351 strlen(body), len); | |
352 return FALSE; | |
353 } | |
354 } | |
355 | |
356 /* Now we should be able to process the data. */ | |
357 if ((s = strstr(headers, "X-MSN-Messenger: ")) != NULL) | |
358 { | |
359 char *session_id, *gw_ip; | |
360 char *c2, *s2; | |
361 | |
362 s += strlen("X-MSN-Messenger: "); | |
363 | |
364 if ((c = strchr(s, '\r')) == NULL) | |
365 { | |
366 gaim_connection_error(gc, "Malformed X-MSN-Messenger field."); | |
367 return FALSE; | |
368 } | |
369 | |
370 tmp = g_strndup(s, c - s); | |
371 | |
372 /* Find the value for the Session ID */ | |
373 if ((s2 = strchr(tmp, '=')) == NULL) | |
374 { | |
375 gaim_connection_error(gc, "Malformed X-MSN-Messenger field."); | |
376 return FALSE; | |
377 } | |
378 | |
379 s2++; | |
380 | |
381 /* Terminate the ; so we can g_strdup it. */ | |
382 if ((c2 = strchr(s2, ';')) == NULL) | |
383 { | |
384 gaim_connection_error(gc, "Malformed X-MSN-Messenger field."); | |
385 return FALSE; | |
386 } | |
387 | |
388 *c2 = '\0'; | |
389 c2++; | |
390 | |
391 /* Now grab that session ID. */ | |
392 session_id = g_strdup(s2); | |
393 | |
394 /* Continue to the gateway IP */ | |
395 if ((s2 = strchr(c2, '=')) == NULL) | |
396 { | |
397 gaim_connection_error(gc, "Malformed X-MSN-Messenger field."); | |
398 return FALSE; | |
399 } | |
400 | |
401 s2++; | |
402 | |
403 /* Grab the gateway IP */ | |
404 gw_ip = g_strdup(s2); | |
405 | |
406 g_free(tmp); | |
407 | |
408 /* Set the new data. */ | |
409 if (servconn->http_data->session_id != NULL) | |
410 g_free(servconn->http_data->session_id); | |
411 | |
412 if (servconn->http_data->old_gateway_ip != NULL) | |
413 g_free(servconn->http_data->old_gateway_ip); | |
414 | |
415 servconn->http_data->old_gateway_ip = servconn->http_data->gateway_ip; | |
416 | |
417 servconn->http_data->session_id = session_id; | |
418 servconn->http_data->gateway_ip = gw_ip; | |
419 } | |
420 | |
421 g_free(headers); | |
422 | |
423 *ret_buf = body; | |
424 *ret_size = len; | |
425 | |
426 if (servconn->http_data->queue != NULL) | |
427 { | |
428 MsnHttpQueueData *queue_data; | |
429 | |
430 queue_data = (MsnHttpQueueData *)servconn->http_data->queue->data; | |
431 | |
432 servconn->http_data->queue = | |
433 g_list_remove(servconn->http_data->queue, queue_data); | |
434 | |
435 msn_http_servconn_write(queue_data->servconn, | |
436 queue_data->buffer, | |
437 queue_data->size, | |
438 queue_data->server_type); | |
439 | |
440 g_free(queue_data->buffer); | |
441 g_free(queue_data); | |
442 } | |
443 else | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
444 servconn->http_data->dirty = TRUE; |
7288 | 445 |
446 return TRUE; | |
447 } | |
448 |