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