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
|
|
287 return;
|
|
288 }
|
|
289
|
|
290 buf[len] = '\0';
|
|
291
|
|
292 httpconn->rx_buf = g_realloc(httpconn->rx_buf, len + httpconn->rx_len + 1);
|
|
293 memcpy(httpconn->rx_buf + httpconn->rx_len, buf, len + 1);
|
|
294 httpconn->rx_len += len;
|
|
295
|
|
296 if (!msn_httpconn_parse_data(httpconn, httpconn->rx_buf, httpconn->rx_len,
|
|
297 &result_msg, &result_len, &error))
|
|
298 {
|
|
299 /* We must wait for more input */
|
|
300
|
|
301 return;
|
|
302 }
|
|
303
|
|
304 httpconn->servconn->processing = FALSE;
|
|
305
|
|
306 servconn = httpconn->servconn;
|
|
307
|
|
308 if (error)
|
|
309 {
|
|
310 gaim_debug_error("msn", "HTTP: Special error\n");
|
10481
|
311 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ);
|
10463
|
312
|
|
313 return;
|
|
314 }
|
|
315
|
10533
|
316 if (httpconn->rx_buf != NULL)
|
|
317 g_free(httpconn->rx_buf);
|
|
318 httpconn->rx_buf = NULL;
|
|
319 httpconn->rx_len = 0;
|
|
320
|
10463
|
321 if (result_len == 0)
|
|
322 {
|
|
323 /* Nothing to do here */
|
|
324 #if 0
|
|
325 gaim_debug_info("msn", "HTTP: nothing to do here\n");
|
|
326 #endif
|
10481
|
327 g_free(result_msg);
|
10463
|
328 return;
|
|
329 }
|
|
330
|
10533
|
331 if (servconn->rx_buf != NULL)
|
|
332 g_free(servconn->rx_buf);
|
10463
|
333 servconn->rx_buf = result_msg;
|
|
334 servconn->rx_len = result_len;
|
|
335
|
|
336 end = old_rx_buf = servconn->rx_buf;
|
|
337
|
|
338 servconn->processing = TRUE;
|
|
339
|
|
340 do
|
|
341 {
|
|
342 cur = end;
|
|
343
|
|
344 if (servconn->payload_len)
|
|
345 {
|
|
346 if (servconn->payload_len > servconn->rx_len)
|
|
347 /* The payload is still not complete. */
|
|
348 break;
|
|
349
|
|
350 cur_len = servconn->payload_len;
|
|
351 end += cur_len;
|
|
352 }
|
|
353 else
|
|
354 {
|
|
355 end = strstr(cur, "\r\n");
|
|
356
|
|
357 if (end == NULL)
|
|
358 /* The command is still not complete. */
|
|
359 break;
|
|
360
|
|
361 *end = '\0';
|
|
362 end += 2;
|
|
363 cur_len = end - cur;
|
|
364 }
|
|
365
|
|
366 servconn->rx_len -= cur_len;
|
|
367
|
|
368 if (servconn->payload_len)
|
|
369 {
|
|
370 msn_cmdproc_process_payload(servconn->cmdproc, cur, cur_len);
|
|
371 servconn->payload_len = 0;
|
|
372 }
|
|
373 else
|
|
374 {
|
|
375 msn_cmdproc_process_cmd_text(servconn->cmdproc, cur);
|
|
376 }
|
|
377 } while (servconn->connected && servconn->rx_len > 0);
|
|
378
|
|
379 if (servconn->connected)
|
|
380 {
|
|
381 if (servconn->rx_len > 0)
|
|
382 servconn->rx_buf = g_memdup(cur, servconn->rx_len);
|
|
383 else
|
|
384 servconn->rx_buf = NULL;
|
|
385 }
|
|
386
|
|
387 servconn->processing = FALSE;
|
|
388
|
|
389 if (servconn->wasted)
|
|
390 msn_servconn_destroy(servconn);
|
|
391
|
|
392 g_free(old_rx_buf);
|
|
393 }
|
|
394
|
|
395 void
|
|
396 msn_httpconn_process_queue(MsnHttpConn *httpconn)
|
|
397 {
|
|
398 if (httpconn->queue != NULL)
|
|
399 {
|
|
400 MsnHttpQueueData *queue_data;
|
|
401
|
|
402 queue_data = (MsnHttpQueueData *)httpconn->queue->data;
|
|
403
|
|
404 httpconn->queue = g_list_remove(httpconn->queue, queue_data);
|
|
405
|
|
406 msn_httpconn_write(queue_data->httpconn,
|
10481
|
407 queue_data->data,
|
10463
|
408 queue_data->size);
|
|
409
|
10481
|
410 g_free(queue_data->data);
|
10463
|
411 g_free(queue_data);
|
|
412 }
|
|
413 else
|
|
414 {
|
|
415 httpconn->dirty = TRUE;
|
|
416 }
|
|
417 }
|
|
418
|
|
419 size_t
|
10481
|
420 msn_httpconn_write(MsnHttpConn *httpconn, const char *data, size_t size)
|
10463
|
421 {
|
|
422 char *params;
|
10481
|
423 char *header;
|
10463
|
424 gboolean first;
|
|
425 const char *server_types[] = { "NS", "SB" };
|
|
426 const char *server_type;
|
|
427 size_t r; /* result of the write operation */
|
|
428 char *host;
|
|
429 MsnServConn *servconn;
|
|
430
|
|
431 /* TODO: remove http data from servconn */
|
|
432
|
|
433 g_return_val_if_fail(httpconn != NULL, 0);
|
10481
|
434 g_return_val_if_fail(data != NULL, 0);
|
10463
|
435 g_return_val_if_fail(size > 0, 0);
|
|
436
|
|
437 servconn = httpconn->servconn;
|
|
438
|
|
439 if (httpconn->waiting_response)
|
|
440 {
|
|
441 MsnHttpQueueData *queue_data = g_new0(MsnHttpQueueData, 1);
|
|
442
|
|
443 queue_data->httpconn = httpconn;
|
10481
|
444 queue_data->data = g_memdup(data, size);
|
10463
|
445 queue_data->size = size;
|
|
446
|
|
447 httpconn->queue = g_list_append(httpconn->queue, queue_data);
|
|
448 /* httpconn->dirty = TRUE; */
|
|
449
|
|
450 /* servconn->processing = TRUE; */
|
|
451
|
|
452 return size;
|
|
453 }
|
|
454
|
|
455 first = httpconn->virgin;
|
|
456 server_type = server_types[servconn->type];
|
|
457
|
|
458 if (first)
|
|
459 {
|
|
460 host = "gateway.messenger.hotmail.com";
|
|
461
|
|
462 /* The first time servconn->host is the host we should connect to. */
|
|
463 params = g_strdup_printf("Action=open&Server=%s&IP=%s",
|
|
464 server_type,
|
|
465 servconn->host);
|
|
466 }
|
|
467 else
|
|
468 {
|
|
469 /* The rest of the times servconn->host is the gateway host. */
|
|
470 host = httpconn->host;
|
|
471
|
|
472 params = g_strdup_printf("SessionID=%s",
|
|
473 httpconn->full_session_id);
|
|
474 }
|
|
475
|
10481
|
476 header = g_strdup_printf(
|
10463
|
477 "POST http://%s/gateway/gateway.dll?%s HTTP/1.1\r\n"
|
|
478 "Accept: */*\r\n"
|
|
479 "Accept-Language: en-us\r\n"
|
|
480 "User-Agent: MSMSGS\r\n"
|
|
481 "Host: %s\r\n"
|
|
482 "Proxy-Connection: Keep-Alive\r\n"
|
|
483 "Connection: Keep-Alive\r\n"
|
|
484 "Pragma: no-cache\r\n"
|
|
485 "Content-Type: application/x-msn-messenger\r\n"
|
10481
|
486 "Content-Length: %d\r\n",
|
10463
|
487 host,
|
|
488 params,
|
|
489 host,
|
|
490 (int)size);
|
|
491
|
|
492 g_free(params);
|
|
493
|
10481
|
494 r = write_raw(httpconn, header, data, size);
|
10463
|
495
|
10481
|
496 g_free(header);
|
10463
|
497
|
|
498 if (r > 0)
|
|
499 {
|
|
500 httpconn->virgin = FALSE;
|
|
501 httpconn->waiting_response = TRUE;
|
|
502 httpconn->dirty = FALSE;
|
|
503 }
|
|
504
|
|
505 return r;
|
|
506 }
|
|
507
|
|
508 gboolean
|
|
509 msn_httpconn_parse_data(MsnHttpConn *httpconn, const char *buf,
|
|
510 size_t size, char **ret_buf, size_t *ret_size,
|
|
511 gboolean *error)
|
|
512 {
|
|
513 GaimConnection *gc;
|
|
514 const char *s, *c;
|
10481
|
515 char *header, *body;
|
10463
|
516 const char *body_start;
|
|
517 char *tmp;
|
|
518 size_t body_len = 0;
|
|
519 gboolean wasted = FALSE;
|
|
520
|
|
521 g_return_val_if_fail(httpconn != NULL, FALSE);
|
|
522 g_return_val_if_fail(buf != NULL, FALSE);
|
|
523 g_return_val_if_fail(size > 0, FALSE);
|
|
524 g_return_val_if_fail(ret_buf != NULL, FALSE);
|
|
525 g_return_val_if_fail(ret_size != NULL, FALSE);
|
|
526 g_return_val_if_fail(error != NULL, FALSE);
|
|
527
|
|
528 #if 0
|
|
529 gaim_debug_info("msn", "HTTP: parsing data {%s}\n", buf);
|
|
530 #endif
|
|
531
|
|
532 httpconn->waiting_response = FALSE;
|
|
533
|
|
534 gc = gaim_account_get_connection(httpconn->session->account);
|
|
535
|
|
536 /* Healthy defaults. */
|
|
537 body = NULL;
|
|
538
|
|
539 *ret_buf = NULL;
|
|
540 *ret_size = 0;
|
|
541 *error = FALSE;
|
|
542
|
|
543 /* First, some tests to see if we have a full block of stuff. */
|
|
544 if (((strncmp(buf, "HTTP/1.1 200 OK\r\n", 17) != 0) &&
|
|
545 (strncmp(buf, "HTTP/1.1 100 Continue\r\n", 23) != 0)) &&
|
|
546 ((strncmp(buf, "HTTP/1.0 200 OK\r\n", 17) != 0) &&
|
|
547 (strncmp(buf, "HTTP/1.0 100 Continue\r\n", 23) != 0)))
|
|
548 {
|
|
549 *error = TRUE;
|
|
550
|
|
551 return FALSE;
|
|
552 }
|
|
553
|
|
554 if (strncmp(buf, "HTTP/1.1 100 Continue\r\n", 23) == 0)
|
|
555 {
|
|
556 if ((s = strstr(buf, "\r\n\r\n")) == NULL)
|
|
557 return FALSE;
|
|
558
|
|
559 s += 4;
|
|
560
|
|
561 if (*s == '\0')
|
|
562 {
|
|
563 *ret_buf = g_strdup("");
|
|
564 *ret_size = 0;
|
|
565
|
|
566 msn_httpconn_process_queue(httpconn);
|
|
567
|
|
568 return TRUE;
|
|
569 }
|
|
570
|
|
571 buf = s;
|
|
572 size -= (s - buf);
|
|
573 }
|
|
574
|
|
575 if ((s = strstr(buf, "\r\n\r\n")) == NULL)
|
|
576 return FALSE;
|
|
577
|
10481
|
578 header = g_strndup(buf, s - buf);
|
10463
|
579 s += 4; /* Skip \r\n */
|
|
580 body_start = s;
|
|
581 body_len = size - (body_start - buf);
|
|
582
|
10481
|
583 if ((s = strstr(header, "Content-Length: ")) != NULL)
|
10463
|
584 {
|
|
585 int tmp_len;
|
|
586
|
|
587 s += strlen("Content-Length: ");
|
|
588
|
|
589 if ((c = strchr(s, '\r')) == NULL)
|
|
590 {
|
10481
|
591 g_free(header);
|
10463
|
592
|
|
593 return FALSE;
|
|
594 }
|
|
595
|
|
596 tmp = g_strndup(s, c - s);
|
|
597 tmp_len = atoi(tmp);
|
|
598 g_free(tmp);
|
|
599
|
|
600 if (body_len != tmp_len)
|
|
601 {
|
10481
|
602 g_free(header);
|
10463
|
603
|
|
604 #if 0
|
|
605 gaim_debug_warning("msn",
|
|
606 "body length (%d) != content length (%d)\n",
|
|
607 body_len, tmp_len);
|
|
608 #endif
|
|
609
|
|
610 return FALSE;
|
|
611 }
|
|
612 }
|
|
613
|
10481
|
614 body = g_malloc0(body_len + 1);
|
|
615 memcpy(body, body_start, body_len);
|
10463
|
616
|
|
617 #ifdef MSN_DEBUG_HTTP
|
10481
|
618 gaim_debug_misc("msn", "Incoming HTTP buffer (header): {%s\r\n}\n",
|
|
619 header);
|
10463
|
620 #endif
|
|
621
|
|
622 /* Now we should be able to process the data. */
|
10481
|
623 if ((s = strstr(header, "X-MSN-Messenger: ")) != NULL)
|
10463
|
624 {
|
|
625 char *full_session_id, *gw_ip, *session_action;
|
|
626 char *t, *session_id;
|
|
627 char **elems, **cur, **tokens;
|
|
628
|
|
629 full_session_id = gw_ip = session_action = NULL;
|
|
630
|
|
631 s += strlen("X-MSN-Messenger: ");
|
|
632
|
|
633 if ((c = strchr(s, '\r')) == NULL)
|
|
634 {
|
10481
|
635 msn_session_set_error(httpconn->session,
|
|
636 MSN_ERROR_HTTP_MALFORMED, NULL);
|
10463
|
637 gaim_debug_error("msn", "Malformed X-MSN-Messenger field.\n{%s}",
|
|
638 buf);
|
|
639
|
10481
|
640 g_free(body);
|
10463
|
641 return FALSE;
|
|
642 }
|
|
643
|
|
644 tmp = g_strndup(s, c - s);
|
|
645
|
|
646 elems = g_strsplit(tmp, "; ", 0);
|
|
647
|
|
648 for (cur = elems; *cur != NULL; cur++)
|
|
649 {
|
|
650 tokens = g_strsplit(*cur, "=", 2);
|
|
651
|
|
652 if (strcmp(tokens[0], "SessionID") == 0)
|
|
653 full_session_id = tokens[1];
|
|
654 else if (strcmp(tokens[0], "GW-IP") == 0)
|
|
655 gw_ip = tokens[1];
|
|
656 else if (strcmp(tokens[0], "Session") == 0)
|
|
657 session_action = tokens[1];
|
|
658
|
|
659 g_free(tokens[0]);
|
|
660 /* Don't free each of the tokens, only the array. */
|
|
661 g_free(tokens);
|
|
662 }
|
|
663
|
|
664 g_strfreev(elems);
|
|
665
|
|
666 g_free(tmp);
|
|
667
|
|
668 if ((session_action != NULL) && (strcmp(session_action, "close") == 0))
|
|
669 wasted = TRUE;
|
|
670
|
|
671 g_free(session_action);
|
|
672
|
|
673 t = strchr(full_session_id, '.');
|
|
674 session_id = g_strndup(full_session_id, t - full_session_id);
|
|
675
|
|
676 if (!wasted)
|
|
677 {
|
10504
|
678 if (httpconn->full_session_id != NULL)
|
10463
|
679 g_free(httpconn->full_session_id);
|
|
680
|
|
681 httpconn->full_session_id = full_session_id;
|
|
682
|
10504
|
683 if (httpconn->session_id != NULL)
|
10463
|
684 g_free(httpconn->session_id);
|
|
685
|
|
686 httpconn->session_id = session_id;
|
|
687
|
10504
|
688 if (httpconn->host != NULL)
|
10463
|
689 g_free(httpconn->host);
|
|
690
|
|
691 httpconn->host = gw_ip;
|
|
692 }
|
|
693 else
|
|
694 {
|
|
695 MsnServConn *servconn;
|
|
696
|
|
697 /* It's going to die. */
|
10504
|
698 /* poor thing */
|
10463
|
699
|
|
700 servconn = httpconn->servconn;
|
|
701
|
10533
|
702 /* I'll be honest, I don't fully understand all this, but this
|
|
703 * causes crashes, Stu. */
|
|
704 /* if (servconn != NULL)
|
|
705 servconn->wasted = TRUE; */
|
10463
|
706
|
|
707 g_free(full_session_id);
|
10504
|
708 g_free(session_id);
|
10463
|
709 g_free(gw_ip);
|
|
710 }
|
|
711 }
|
|
712
|
10481
|
713 g_free(header);
|
10463
|
714
|
|
715 *ret_buf = body;
|
|
716 *ret_size = body_len;
|
|
717
|
|
718 msn_httpconn_process_queue(httpconn);
|
|
719
|
|
720 return TRUE;
|
|
721 }
|