10463
|
1 /**
|
|
2 * @file httpmethod.c HTTP connection method
|
|
3 *
|
|
4 * gaim
|
|
5 *
|
|
6 * Gaim is the legal property of its developers, whose names are too numerous
|
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
8 * source distribution.
|
|
9 *
|
|
10 * This program is free software; you can redistribute it and/or modify
|
|
11 * it under the terms of the GNU General Public License as published by
|
|
12 * the Free Software Foundation; either version 2 of the License, or
|
|
13 * (at your option) any later version.
|
|
14 *
|
|
15 * This program is distributed in the hope that it will be useful,
|
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 * GNU General Public License for more details.
|
|
19 *
|
|
20 * You should have received a copy of the GNU General Public License
|
|
21 * along with this program; if not, write to the Free Software
|
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
23 */
|
|
24 #include "msn.h"
|
|
25 #include "debug.h"
|
|
26 #include "httpconn.h"
|
|
27
|
|
28 typedef struct
|
|
29 {
|
|
30 MsnHttpConn *httpconn;
|
10481
|
31 char *data;
|
10463
|
32 size_t size;
|
|
33
|
|
34 } MsnHttpQueueData;
|
|
35
|
|
36 static void read_cb(gpointer data, gint source, GaimInputCondition cond);
|
|
37 void msn_httpconn_process_queue(MsnHttpConn *httpconn);
|
|
38 gboolean msn_httpconn_parse_data(MsnHttpConn *httpconn, const char *buf,
|
|
39 size_t size, char **ret_buf, size_t *ret_size,
|
|
40 gboolean *error);
|
|
41
|
|
42 MsnHttpConn *
|
|
43 msn_httpconn_new(MsnServConn *servconn)
|
|
44 {
|
|
45 MsnHttpConn *httpconn;
|
|
46
|
|
47 g_return_val_if_fail(servconn != NULL, NULL);
|
|
48
|
|
49 httpconn = g_new0(MsnHttpConn, 1);
|
|
50
|
10481
|
51 gaim_debug_info("msn", "new httpconn (%p)\n", httpconn);
|
|
52
|
10463
|
53 /* TODO: Remove this */
|
|
54 httpconn->session = servconn->session;
|
|
55
|
|
56 httpconn->servconn = servconn;
|
|
57
|
|
58 return httpconn;
|
|
59 }
|
|
60
|
|
61 void
|
|
62 msn_httpconn_destroy(MsnHttpConn *httpconn)
|
|
63 {
|
|
64 g_return_if_fail(httpconn != NULL);
|
|
65
|
10481
|
66 gaim_debug_info("msn", "destroy httpconn (%p)\n", httpconn);
|
|
67
|
10463
|
68 if (httpconn->connected)
|
|
69 msn_httpconn_disconnect(httpconn);
|
|
70
|
|
71 g_free(httpconn);
|
|
72 }
|
|
73
|
10481
|
74 static ssize_t
|
|
75 write_raw(MsnHttpConn *httpconn, const char *header,
|
|
76 const char *body, size_t body_len)
|
10463
|
77 {
|
10481
|
78 char *buf;
|
|
79 size_t buf_len;
|
10463
|
80
|
|
81 ssize_t s;
|
|
82 ssize_t res; /* result of the write operation */
|
|
83
|
|
84 #ifdef MSN_DEBUG_HTTP
|
10481
|
85 gaim_debug_misc("msn", "Writing HTTP (header): {%s}\n", header);
|
10463
|
86 #endif
|
|
87
|
10481
|
88 buf = g_strdup_printf("%s\r\n", header);
|
|
89 buf_len = strlen(buf);
|
|
90
|
|
91 if (body != NULL)
|
|
92 {
|
|
93 buf = g_realloc(buf, buf_len + body_len);
|
|
94 memcpy(buf + buf_len, body, body_len);
|
|
95 buf_len += body_len;
|
|
96 }
|
|
97
|
10463
|
98 s = 0;
|
|
99
|
|
100 do
|
|
101 {
|
10481
|
102 res = write(httpconn->fd, buf, buf_len);
|
10463
|
103 if (res >= 0)
|
|
104 {
|
|
105 s += res;
|
|
106 }
|
|
107 else if (errno != EAGAIN)
|
|
108 {
|
10481
|
109 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_WRITE);
|
10463
|
110 return -1;
|
|
111 }
|
10481
|
112 } while (s < buf_len);
|
|
113
|
|
114 g_free(buf);
|
10463
|
115
|
|
116 return s;
|
|
117 }
|
|
118
|
|
119 void
|
|
120 msn_httpconn_poll(MsnHttpConn *httpconn)
|
|
121 {
|
10481
|
122 char *header;
|
10463
|
123 int r;
|
|
124
|
|
125 g_return_if_fail(httpconn != NULL);
|
|
126
|
|
127 if (httpconn->waiting_response ||
|
|
128 httpconn->queue != NULL)
|
|
129 {
|
|
130 return;
|
|
131 }
|
|
132
|
10481
|
133 header = g_strdup_printf(
|
10463
|
134 "POST http://%s/gateway/gateway.dll?Action=poll&SessionID=%s HTTP/1.1\r\n"
|
|
135 "Accept: */*\r\n"
|
|
136 "Accept-Language: en-us\r\n"
|
|
137 "User-Agent: MSMSGS\r\n"
|
|
138 "Host: %s\r\n"
|
|
139 "Proxy-Connection: Keep-Alive\r\n"
|
|
140 "Connection: Keep-Alive\r\n"
|
|
141 "Pragma: no-cache\r\n"
|
|
142 "Content-Type: application/x-msn-messenger\r\n"
|
10481
|
143 "Content-Length: 0\r\n",
|
10463
|
144 httpconn->host,
|
|
145 httpconn->full_session_id,
|
|
146 httpconn->host);
|
|
147
|
10481
|
148 r = write_raw(httpconn, header, NULL, -1);
|
10463
|
149
|
10481
|
150 g_free(header);
|
10463
|
151
|
|
152 if (r > 0)
|
|
153 {
|
|
154 httpconn->waiting_response = TRUE;
|
|
155 httpconn->dirty = FALSE;
|
|
156 }
|
|
157 }
|
|
158
|
|
159 static gboolean
|
|
160 poll(gpointer data)
|
|
161 {
|
|
162 MsnHttpConn *httpconn;
|
|
163
|
|
164 httpconn = data;
|
|
165
|
|
166 #if 0
|
|
167 gaim_debug_info("msn", "polling from %s\n", httpconn->session_id);
|
|
168 #endif
|
|
169
|
|
170 if (httpconn->dirty)
|
|
171 msn_httpconn_poll(httpconn);
|
|
172
|
|
173 return TRUE;
|
|
174 }
|
|
175
|
|
176 static void
|
|
177 connect_cb(gpointer data, gint source, GaimInputCondition cond)
|
|
178 {
|
|
179 MsnHttpConn *httpconn = data;
|
|
180
|
|
181 httpconn->fd = source;
|
|
182
|
|
183 if (source > 0)
|
|
184 {
|
|
185 httpconn->inpa = gaim_input_add(httpconn->fd, GAIM_INPUT_READ,
|
|
186 read_cb, data);
|
|
187
|
|
188 httpconn->timer = gaim_timeout_add(2000, poll, httpconn);
|
|
189
|
|
190 httpconn->waiting_response = FALSE;
|
|
191 msn_httpconn_process_queue(httpconn);
|
|
192 }
|
|
193 else
|
|
194 {
|
|
195 gaim_debug_error("msn", "HTTP: Connection error\n");
|
10481
|
196 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_CONNECT);
|
10463
|
197 }
|
|
198 }
|
|
199
|
|
200 gboolean
|
|
201 msn_httpconn_connect(MsnHttpConn *httpconn, const char *host, int port)
|
|
202 {
|
|
203 int r;
|
|
204
|
|
205 g_return_val_if_fail(httpconn != NULL, FALSE);
|
|
206 g_return_val_if_fail(host != NULL, FALSE);
|
|
207 g_return_val_if_fail(port > 0, FALSE);
|
|
208
|
|
209 if (httpconn->connected)
|
|
210 msn_httpconn_disconnect(httpconn);
|
|
211
|
|
212 r = gaim_proxy_connect(httpconn->session->account,
|
|
213 "gateway.messenger.hotmail.com", 80, connect_cb,
|
|
214 httpconn);
|
|
215
|
|
216 if (r == 0)
|
|
217 {
|
|
218 httpconn->waiting_response = TRUE;
|
|
219 httpconn->connected = TRUE;
|
|
220 }
|
|
221
|
|
222 return httpconn->connected;
|
|
223 }
|
|
224
|
|
225 void
|
|
226 msn_httpconn_disconnect(MsnHttpConn *httpconn)
|
|
227 {
|
|
228 g_return_if_fail(httpconn != NULL);
|
10481
|
229
|
|
230 if (!httpconn->connected)
|
|
231 return;
|
10463
|
232
|
|
233 if (httpconn->timer)
|
|
234 gaim_timeout_remove(httpconn->timer);
|
|
235
|
|
236 httpconn->timer = 0;
|
|
237
|
|
238 if (httpconn->inpa > 0)
|
|
239 {
|
|
240 gaim_input_remove(httpconn->inpa);
|
|
241 httpconn->inpa = 0;
|
|
242 }
|
|
243
|
|
244 close(httpconn->fd);
|
|
245
|
|
246 httpconn->rx_buf = NULL;
|
|
247 httpconn->rx_len = 0;
|
|
248
|
|
249 httpconn->connected = FALSE;
|
|
250
|
|
251 /* msn_servconn_disconnect(httpconn->servconn); */
|
|
252 }
|
|
253
|
|
254 static void
|
|
255 read_cb(gpointer data, gint source, GaimInputCondition cond)
|
|
256 {
|
|
257 MsnHttpConn *httpconn;
|
|
258 MsnServConn *servconn;
|
|
259 MsnSession *session;
|
|
260 char buf[MSN_BUF_LEN];
|
|
261 char *cur, *end, *old_rx_buf;
|
|
262 int len, cur_len;
|
|
263 char *result_msg = NULL;
|
|
264 size_t result_len = 0;
|
|
265 gboolean error;
|
|
266
|
|
267 httpconn = data;
|
|
268 servconn = NULL;
|
|
269 session = httpconn->session;
|
|
270
|
|
271 len = read(httpconn->fd, buf, sizeof(buf) - 1);
|
|
272
|
|
273 if (len <= 0)
|
|
274 {
|
|
275 gaim_debug_error("msn", "HTTP: Read error\n");
|
10481
|
276 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ);
|
10463
|
277 msn_httpconn_disconnect(httpconn);
|
|
278
|
|
279 return;
|
|
280 }
|
|
281
|
|
282 buf[len] = '\0';
|
|
283
|
|
284 httpconn->rx_buf = g_realloc(httpconn->rx_buf, len + httpconn->rx_len + 1);
|
|
285 memcpy(httpconn->rx_buf + httpconn->rx_len, buf, len + 1);
|
|
286 httpconn->rx_len += len;
|
|
287
|
|
288 if (!msn_httpconn_parse_data(httpconn, httpconn->rx_buf, httpconn->rx_len,
|
|
289 &result_msg, &result_len, &error))
|
|
290 {
|
|
291 /* We must wait for more input */
|
|
292
|
|
293 return;
|
|
294 }
|
|
295
|
|
296 httpconn->servconn->processing = FALSE;
|
|
297
|
|
298 servconn = httpconn->servconn;
|
|
299
|
|
300 if (error)
|
|
301 {
|
|
302 gaim_debug_error("msn", "HTTP: Special error\n");
|
10481
|
303 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ);
|
10463
|
304 msn_httpconn_disconnect(httpconn);
|
|
305
|
|
306 return;
|
|
307 }
|
|
308
|
|
309 if (result_len == 0)
|
|
310 {
|
|
311 /* Nothing to do here */
|
|
312 #if 0
|
|
313 gaim_debug_info("msn", "HTTP: nothing to do here\n");
|
|
314 #endif
|
10481
|
315 g_free(result_msg);
|
10463
|
316 g_free(httpconn->rx_buf);
|
|
317 httpconn->rx_buf = NULL;
|
|
318 httpconn->rx_len = 0;
|
|
319 return;
|
|
320 }
|
|
321
|
|
322 g_free(httpconn->rx_buf);
|
|
323 httpconn->rx_buf = NULL;
|
|
324 httpconn->rx_len = 0;
|
|
325
|
10481
|
326 g_free(servconn->rx_buf);
|
10463
|
327 servconn->rx_buf = result_msg;
|
|
328 servconn->rx_len = result_len;
|
|
329
|
|
330 end = old_rx_buf = servconn->rx_buf;
|
|
331
|
|
332 servconn->processing = TRUE;
|
|
333
|
|
334 do
|
|
335 {
|
|
336 cur = end;
|
|
337
|
|
338 if (servconn->payload_len)
|
|
339 {
|
|
340 if (servconn->payload_len > servconn->rx_len)
|
|
341 /* The payload is still not complete. */
|
|
342 break;
|
|
343
|
|
344 cur_len = servconn->payload_len;
|
|
345 end += cur_len;
|
|
346 }
|
|
347 else
|
|
348 {
|
|
349 end = strstr(cur, "\r\n");
|
|
350
|
|
351 if (end == NULL)
|
|
352 /* The command is still not complete. */
|
|
353 break;
|
|
354
|
|
355 *end = '\0';
|
|
356 end += 2;
|
|
357 cur_len = end - cur;
|
|
358 }
|
|
359
|
|
360 servconn->rx_len -= cur_len;
|
|
361
|
|
362 if (servconn->payload_len)
|
|
363 {
|
|
364 msn_cmdproc_process_payload(servconn->cmdproc, cur, cur_len);
|
|
365 servconn->payload_len = 0;
|
|
366 }
|
|
367 else
|
|
368 {
|
|
369 msn_cmdproc_process_cmd_text(servconn->cmdproc, cur);
|
|
370 }
|
|
371 } while (servconn->connected && servconn->rx_len > 0);
|
|
372
|
|
373 if (servconn->connected)
|
|
374 {
|
|
375 if (servconn->rx_len > 0)
|
|
376 servconn->rx_buf = g_memdup(cur, servconn->rx_len);
|
|
377 else
|
|
378 servconn->rx_buf = NULL;
|
|
379 }
|
|
380
|
|
381 servconn->processing = FALSE;
|
|
382
|
|
383 if (servconn->wasted)
|
|
384 msn_servconn_destroy(servconn);
|
|
385
|
|
386 g_free(old_rx_buf);
|
|
387 }
|
|
388
|
|
389 void
|
|
390 msn_httpconn_process_queue(MsnHttpConn *httpconn)
|
|
391 {
|
|
392 if (httpconn->queue != NULL)
|
|
393 {
|
|
394 MsnHttpQueueData *queue_data;
|
|
395
|
|
396 queue_data = (MsnHttpQueueData *)httpconn->queue->data;
|
|
397
|
|
398 httpconn->queue = g_list_remove(httpconn->queue, queue_data);
|
|
399
|
|
400 msn_httpconn_write(queue_data->httpconn,
|
10481
|
401 queue_data->data,
|
10463
|
402 queue_data->size);
|
|
403
|
10481
|
404 g_free(queue_data->data);
|
10463
|
405 g_free(queue_data);
|
|
406 }
|
|
407 else
|
|
408 {
|
|
409 httpconn->dirty = TRUE;
|
|
410 }
|
|
411 }
|
|
412
|
|
413 size_t
|
10481
|
414 msn_httpconn_write(MsnHttpConn *httpconn, const char *data, size_t size)
|
10463
|
415 {
|
|
416 char *params;
|
10481
|
417 char *header;
|
10463
|
418 gboolean first;
|
|
419 const char *server_types[] = { "NS", "SB" };
|
|
420 const char *server_type;
|
|
421 size_t r; /* result of the write operation */
|
|
422 char *host;
|
|
423 MsnServConn *servconn;
|
|
424
|
|
425 /* TODO: remove http data from servconn */
|
|
426
|
|
427 g_return_val_if_fail(httpconn != NULL, 0);
|
10481
|
428 g_return_val_if_fail(data != NULL, 0);
|
10463
|
429 g_return_val_if_fail(size > 0, 0);
|
|
430
|
|
431 servconn = httpconn->servconn;
|
|
432
|
|
433 if (httpconn->waiting_response)
|
|
434 {
|
|
435 MsnHttpQueueData *queue_data = g_new0(MsnHttpQueueData, 1);
|
|
436
|
|
437 queue_data->httpconn = httpconn;
|
10481
|
438 queue_data->data = g_memdup(data, size);
|
10463
|
439 queue_data->size = size;
|
|
440
|
|
441 httpconn->queue = g_list_append(httpconn->queue, queue_data);
|
|
442 /* httpconn->dirty = TRUE; */
|
|
443
|
|
444 /* servconn->processing = TRUE; */
|
|
445
|
|
446 return size;
|
|
447 }
|
|
448
|
|
449 first = httpconn->virgin;
|
|
450 server_type = server_types[servconn->type];
|
|
451
|
|
452 if (first)
|
|
453 {
|
|
454 host = "gateway.messenger.hotmail.com";
|
|
455
|
|
456 /* The first time servconn->host is the host we should connect to. */
|
|
457 params = g_strdup_printf("Action=open&Server=%s&IP=%s",
|
|
458 server_type,
|
|
459 servconn->host);
|
|
460 }
|
|
461 else
|
|
462 {
|
|
463 /* The rest of the times servconn->host is the gateway host. */
|
|
464 host = httpconn->host;
|
|
465
|
|
466 params = g_strdup_printf("SessionID=%s",
|
|
467 httpconn->full_session_id);
|
|
468 }
|
|
469
|
10481
|
470 header = g_strdup_printf(
|
10463
|
471 "POST http://%s/gateway/gateway.dll?%s HTTP/1.1\r\n"
|
|
472 "Accept: */*\r\n"
|
|
473 "Accept-Language: en-us\r\n"
|
|
474 "User-Agent: MSMSGS\r\n"
|
|
475 "Host: %s\r\n"
|
|
476 "Proxy-Connection: Keep-Alive\r\n"
|
|
477 "Connection: Keep-Alive\r\n"
|
|
478 "Pragma: no-cache\r\n"
|
|
479 "Content-Type: application/x-msn-messenger\r\n"
|
10481
|
480 "Content-Length: %d\r\n",
|
10463
|
481 host,
|
|
482 params,
|
|
483 host,
|
|
484 (int)size);
|
|
485
|
|
486 g_free(params);
|
|
487
|
10481
|
488 r = write_raw(httpconn, header, data, size);
|
10463
|
489
|
10481
|
490 g_free(header);
|
10463
|
491
|
|
492 if (r > 0)
|
|
493 {
|
|
494 httpconn->virgin = FALSE;
|
|
495 httpconn->waiting_response = TRUE;
|
|
496 httpconn->dirty = FALSE;
|
|
497 }
|
|
498
|
|
499 return r;
|
|
500 }
|
|
501
|
|
502 gboolean
|
|
503 msn_httpconn_parse_data(MsnHttpConn *httpconn, const char *buf,
|
|
504 size_t size, char **ret_buf, size_t *ret_size,
|
|
505 gboolean *error)
|
|
506 {
|
|
507 GaimConnection *gc;
|
|
508 const char *s, *c;
|
10481
|
509 char *header, *body;
|
10463
|
510 const char *body_start;
|
|
511 char *tmp;
|
|
512 size_t body_len = 0;
|
|
513 gboolean wasted = FALSE;
|
|
514
|
|
515 g_return_val_if_fail(httpconn != NULL, FALSE);
|
|
516 g_return_val_if_fail(buf != NULL, FALSE);
|
|
517 g_return_val_if_fail(size > 0, FALSE);
|
|
518 g_return_val_if_fail(ret_buf != NULL, FALSE);
|
|
519 g_return_val_if_fail(ret_size != NULL, FALSE);
|
|
520 g_return_val_if_fail(error != NULL, FALSE);
|
|
521
|
|
522 #if 0
|
|
523 gaim_debug_info("msn", "HTTP: parsing data {%s}\n", buf);
|
|
524 #endif
|
|
525
|
|
526 httpconn->waiting_response = FALSE;
|
|
527
|
|
528 gc = gaim_account_get_connection(httpconn->session->account);
|
|
529
|
|
530 /* Healthy defaults. */
|
|
531 body = NULL;
|
|
532
|
|
533 *ret_buf = NULL;
|
|
534 *ret_size = 0;
|
|
535 *error = FALSE;
|
|
536
|
|
537 /* First, some tests to see if we have a full block of stuff. */
|
|
538 if (((strncmp(buf, "HTTP/1.1 200 OK\r\n", 17) != 0) &&
|
|
539 (strncmp(buf, "HTTP/1.1 100 Continue\r\n", 23) != 0)) &&
|
|
540 ((strncmp(buf, "HTTP/1.0 200 OK\r\n", 17) != 0) &&
|
|
541 (strncmp(buf, "HTTP/1.0 100 Continue\r\n", 23) != 0)))
|
|
542 {
|
|
543 *error = TRUE;
|
|
544
|
|
545 return FALSE;
|
|
546 }
|
|
547
|
|
548 if (strncmp(buf, "HTTP/1.1 100 Continue\r\n", 23) == 0)
|
|
549 {
|
|
550 if ((s = strstr(buf, "\r\n\r\n")) == NULL)
|
|
551 return FALSE;
|
|
552
|
|
553 s += 4;
|
|
554
|
|
555 if (*s == '\0')
|
|
556 {
|
|
557 *ret_buf = g_strdup("");
|
|
558 *ret_size = 0;
|
|
559
|
|
560 msn_httpconn_process_queue(httpconn);
|
|
561
|
|
562 return TRUE;
|
|
563 }
|
|
564
|
|
565 buf = s;
|
|
566 size -= (s - buf);
|
|
567 }
|
|
568
|
|
569 if ((s = strstr(buf, "\r\n\r\n")) == NULL)
|
|
570 return FALSE;
|
|
571
|
10481
|
572 header = g_strndup(buf, s - buf);
|
10463
|
573 s += 4; /* Skip \r\n */
|
|
574 body_start = s;
|
|
575 body_len = size - (body_start - buf);
|
|
576
|
10481
|
577 if ((s = strstr(header, "Content-Length: ")) != NULL)
|
10463
|
578 {
|
|
579 int tmp_len;
|
|
580
|
|
581 s += strlen("Content-Length: ");
|
|
582
|
|
583 if ((c = strchr(s, '\r')) == NULL)
|
|
584 {
|
10481
|
585 g_free(header);
|
10463
|
586
|
|
587 return FALSE;
|
|
588 }
|
|
589
|
|
590 tmp = g_strndup(s, c - s);
|
|
591 tmp_len = atoi(tmp);
|
|
592 g_free(tmp);
|
|
593
|
|
594 if (body_len != tmp_len)
|
|
595 {
|
10481
|
596 g_free(header);
|
10463
|
597
|
|
598 #if 0
|
|
599 gaim_debug_warning("msn",
|
|
600 "body length (%d) != content length (%d)\n",
|
|
601 body_len, tmp_len);
|
|
602 #endif
|
|
603
|
|
604 return FALSE;
|
|
605 }
|
|
606 }
|
|
607
|
10481
|
608 body = g_malloc0(body_len + 1);
|
|
609 memcpy(body, body_start, body_len);
|
10463
|
610
|
|
611 #ifdef MSN_DEBUG_HTTP
|
10481
|
612 gaim_debug_misc("msn", "Incoming HTTP buffer (header): {%s\r\n}\n",
|
|
613 header);
|
10463
|
614 #endif
|
|
615
|
|
616 /* Now we should be able to process the data. */
|
10481
|
617 if ((s = strstr(header, "X-MSN-Messenger: ")) != NULL)
|
10463
|
618 {
|
|
619 char *full_session_id, *gw_ip, *session_action;
|
|
620 char *t, *session_id;
|
|
621 char **elems, **cur, **tokens;
|
|
622
|
|
623 full_session_id = gw_ip = session_action = NULL;
|
|
624
|
|
625 s += strlen("X-MSN-Messenger: ");
|
|
626
|
|
627 if ((c = strchr(s, '\r')) == NULL)
|
|
628 {
|
10481
|
629 msn_session_set_error(httpconn->session,
|
|
630 MSN_ERROR_HTTP_MALFORMED, NULL);
|
10463
|
631 gaim_debug_error("msn", "Malformed X-MSN-Messenger field.\n{%s}",
|
|
632 buf);
|
|
633
|
10481
|
634 g_free(body);
|
10463
|
635 return FALSE;
|
|
636 }
|
|
637
|
|
638 tmp = g_strndup(s, c - s);
|
|
639
|
|
640 elems = g_strsplit(tmp, "; ", 0);
|
|
641
|
|
642 for (cur = elems; *cur != NULL; cur++)
|
|
643 {
|
|
644 tokens = g_strsplit(*cur, "=", 2);
|
|
645
|
|
646 if (strcmp(tokens[0], "SessionID") == 0)
|
|
647 full_session_id = tokens[1];
|
|
648 else if (strcmp(tokens[0], "GW-IP") == 0)
|
|
649 gw_ip = tokens[1];
|
|
650 else if (strcmp(tokens[0], "Session") == 0)
|
|
651 session_action = tokens[1];
|
|
652
|
|
653 g_free(tokens[0]);
|
|
654 /* Don't free each of the tokens, only the array. */
|
|
655 g_free(tokens);
|
|
656 }
|
|
657
|
|
658 g_strfreev(elems);
|
|
659
|
|
660 g_free(tmp);
|
|
661
|
|
662 if ((session_action != NULL) && (strcmp(session_action, "close") == 0))
|
|
663 wasted = TRUE;
|
|
664
|
|
665 g_free(session_action);
|
|
666
|
|
667 t = strchr(full_session_id, '.');
|
|
668 session_id = g_strndup(full_session_id, t - full_session_id);
|
|
669
|
|
670 if (!wasted)
|
|
671 {
|
|
672 if (httpconn->full_session_id != NULL);
|
|
673 g_free(httpconn->full_session_id);
|
|
674
|
|
675 httpconn->full_session_id = full_session_id;
|
|
676
|
|
677 if (httpconn->session_id != NULL);
|
|
678 g_free(httpconn->session_id);
|
|
679
|
|
680 httpconn->session_id = session_id;
|
|
681
|
|
682 if (httpconn->host != NULL);
|
|
683 g_free(httpconn->host);
|
|
684
|
|
685 httpconn->host = gw_ip;
|
|
686 }
|
|
687 else
|
|
688 {
|
|
689 MsnServConn *servconn;
|
|
690
|
|
691 /* It's going to die. */
|
|
692
|
|
693 servconn = httpconn->servconn;
|
|
694
|
|
695 if (servconn != NULL)
|
|
696 servconn->wasted = TRUE;
|
|
697
|
|
698 g_free(full_session_id);
|
|
699 g_free(gw_ip);
|
|
700 }
|
|
701 }
|
|
702
|
10481
|
703 g_free(header);
|
10463
|
704
|
|
705 *ret_buf = body;
|
|
706 *ret_size = body_len;
|
|
707
|
|
708 msn_httpconn_process_queue(httpconn);
|
|
709
|
|
710 return TRUE;
|
|
711 }
|