Mercurial > pidgin.yaz
comparison libpurple/protocols/msn/httpconn.c @ 15823:32c366eeeb99
sed -ie 's/gaim/purple/g'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 19 Mar 2007 07:01:17 +0000 |
parents | 5fe8042783c1 |
children | 941965d6fd88 |
comparison
equal
deleted
inserted
replaced
15822:84b0f9b23ede | 15823:32c366eeeb99 |
---|---|
1 /** | 1 /** |
2 * @file httpmethod.c HTTP connection method | 2 * @file httpmethod.c HTTP connection method |
3 * | 3 * |
4 * gaim | 4 * purple |
5 * | 5 * |
6 * Gaim is the legal property of its developers, whose names are too numerous | 6 * Purple 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 | 7 * to list here. Please refer to the COPYRIGHT file distributed with this |
8 * source distribution. | 8 * source distribution. |
9 * | 9 * |
10 * This program is free software; you can redistribute it and/or modify | 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 | 11 * it under the terms of the GNU General Public License as published by |
72 g_return_val_if_fail(ret_buf != NULL, FALSE); | 72 g_return_val_if_fail(ret_buf != NULL, FALSE); |
73 g_return_val_if_fail(ret_size != NULL, FALSE); | 73 g_return_val_if_fail(ret_size != NULL, FALSE); |
74 g_return_val_if_fail(error != NULL, FALSE); | 74 g_return_val_if_fail(error != NULL, FALSE); |
75 | 75 |
76 #if 0 | 76 #if 0 |
77 gaim_debug_info("msn", "HTTP: parsing data {%s}\n", buf); | 77 purple_debug_info("msn", "HTTP: parsing data {%s}\n", buf); |
78 #endif | 78 #endif |
79 | 79 |
80 /* Healthy defaults. */ | 80 /* Healthy defaults. */ |
81 body = NULL; | 81 body = NULL; |
82 | 82 |
123 s += 4; /* Skip \r\n */ | 123 s += 4; /* Skip \r\n */ |
124 header = g_strndup(buf, s - buf); | 124 header = g_strndup(buf, s - buf); |
125 body_start = s; | 125 body_start = s; |
126 body_len = size - (body_start - buf); | 126 body_len = size - (body_start - buf); |
127 | 127 |
128 if ((s = gaim_strcasestr(header, "Content-Length: ")) != NULL) | 128 if ((s = purple_strcasestr(header, "Content-Length: ")) != NULL) |
129 { | 129 { |
130 int tmp_len; | 130 int tmp_len; |
131 | 131 |
132 s += strlen("Content-Length: "); | 132 s += strlen("Content-Length: "); |
133 | 133 |
147 /* Need to wait for the full packet to arrive */ | 147 /* Need to wait for the full packet to arrive */ |
148 | 148 |
149 g_free(header); | 149 g_free(header); |
150 | 150 |
151 #if 0 | 151 #if 0 |
152 gaim_debug_warning("msn", | 152 purple_debug_warning("msn", |
153 "body length (%d) != content length (%d)\n", | 153 "body length (%d) != content length (%d)\n", |
154 body_len, tmp_len); | 154 body_len, tmp_len); |
155 #endif | 155 #endif |
156 | 156 |
157 return FALSE; | 157 return FALSE; |
160 | 160 |
161 body = g_malloc0(body_len + 1); | 161 body = g_malloc0(body_len + 1); |
162 memcpy(body, body_start, body_len); | 162 memcpy(body, body_start, body_len); |
163 | 163 |
164 #ifdef MSN_DEBUG_HTTP | 164 #ifdef MSN_DEBUG_HTTP |
165 gaim_debug_misc("msn", "Incoming HTTP buffer (header): {%s\r\n}\n", | 165 purple_debug_misc("msn", "Incoming HTTP buffer (header): {%s\r\n}\n", |
166 header); | 166 header); |
167 #endif | 167 #endif |
168 | 168 |
169 /* Now we should be able to process the data. */ | 169 /* Now we should be able to process the data. */ |
170 if ((s = gaim_strcasestr(header, "X-MSN-Messenger: ")) != NULL) | 170 if ((s = purple_strcasestr(header, "X-MSN-Messenger: ")) != NULL) |
171 { | 171 { |
172 char *full_session_id, *gw_ip, *session_action; | 172 char *full_session_id, *gw_ip, *session_action; |
173 char *t, *session_id; | 173 char *t, *session_id; |
174 char **elems, **cur, **tokens; | 174 char **elems, **cur, **tokens; |
175 | 175 |
179 | 179 |
180 if ((c = strchr(s, '\r')) == NULL) | 180 if ((c = strchr(s, '\r')) == NULL) |
181 { | 181 { |
182 msn_session_set_error(httpconn->session, | 182 msn_session_set_error(httpconn->session, |
183 MSN_ERROR_HTTP_MALFORMED, NULL); | 183 MSN_ERROR_HTTP_MALFORMED, NULL); |
184 gaim_debug_error("msn", "Malformed X-MSN-Messenger field.\n{%s}", | 184 purple_debug_error("msn", "Malformed X-MSN-Messenger field.\n{%s}", |
185 buf); | 185 buf); |
186 | 186 |
187 g_free(body); | 187 g_free(body); |
188 return FALSE; | 188 return FALSE; |
189 } | 189 } |
262 | 262 |
263 return TRUE; | 263 return TRUE; |
264 } | 264 } |
265 | 265 |
266 static void | 266 static void |
267 read_cb(gpointer data, gint source, GaimInputCondition cond) | 267 read_cb(gpointer data, gint source, PurpleInputCondition cond) |
268 { | 268 { |
269 MsnHttpConn *httpconn; | 269 MsnHttpConn *httpconn; |
270 MsnServConn *servconn; | 270 MsnServConn *servconn; |
271 MsnSession *session; | 271 MsnSession *session; |
272 char buf[MSN_BUF_LEN]; | 272 char buf[MSN_BUF_LEN]; |
284 | 284 |
285 if (len < 0 && errno == EAGAIN) | 285 if (len < 0 && errno == EAGAIN) |
286 return; | 286 return; |
287 else if (len <= 0) | 287 else if (len <= 0) |
288 { | 288 { |
289 gaim_debug_error("msn", "HTTP: Read error\n"); | 289 purple_debug_error("msn", "HTTP: Read error\n"); |
290 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ); | 290 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ); |
291 | 291 |
292 return; | 292 return; |
293 } | 293 } |
294 | 294 |
312 | 312 |
313 servconn = httpconn->servconn; | 313 servconn = httpconn->servconn; |
314 | 314 |
315 if (error) | 315 if (error) |
316 { | 316 { |
317 gaim_debug_error("msn", "HTTP: Special error\n"); | 317 purple_debug_error("msn", "HTTP: Special error\n"); |
318 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ); | 318 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ); |
319 | 319 |
320 return; | 320 return; |
321 } | 321 } |
322 | 322 |
326 | 326 |
327 if (result_len == 0) | 327 if (result_len == 0) |
328 { | 328 { |
329 /* Nothing to do here */ | 329 /* Nothing to do here */ |
330 #if 0 | 330 #if 0 |
331 gaim_debug_info("msn", "HTTP: nothing to do here\n"); | 331 purple_debug_info("msn", "HTTP: nothing to do here\n"); |
332 #endif | 332 #endif |
333 g_free(result_msg); | 333 g_free(result_msg); |
334 return; | 334 return; |
335 } | 335 } |
336 | 336 |
396 | 396 |
397 g_free(old_rx_buf); | 397 g_free(old_rx_buf); |
398 } | 398 } |
399 | 399 |
400 static void | 400 static void |
401 httpconn_write_cb(gpointer data, gint source, GaimInputCondition cond) | 401 httpconn_write_cb(gpointer data, gint source, PurpleInputCondition cond) |
402 { | 402 { |
403 MsnHttpConn *httpconn; | 403 MsnHttpConn *httpconn; |
404 int ret, writelen; | 404 int ret, writelen; |
405 | 405 |
406 httpconn = data; | 406 httpconn = data; |
407 writelen = gaim_circ_buffer_get_max_read(httpconn->tx_buf); | 407 writelen = purple_circ_buffer_get_max_read(httpconn->tx_buf); |
408 | 408 |
409 if (writelen == 0) | 409 if (writelen == 0) |
410 { | 410 { |
411 gaim_input_remove(httpconn->tx_handler); | 411 purple_input_remove(httpconn->tx_handler); |
412 httpconn->tx_handler = 0; | 412 httpconn->tx_handler = 0; |
413 return; | 413 return; |
414 } | 414 } |
415 | 415 |
416 ret = write(httpconn->fd, httpconn->tx_buf->outptr, writelen); | 416 ret = write(httpconn->fd, httpconn->tx_buf->outptr, writelen); |
423 /* Error! */ | 423 /* Error! */ |
424 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_WRITE); | 424 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_WRITE); |
425 return; | 425 return; |
426 } | 426 } |
427 | 427 |
428 gaim_circ_buffer_mark_read(httpconn->tx_buf, ret); | 428 purple_circ_buffer_mark_read(httpconn->tx_buf, ret); |
429 | 429 |
430 /* TODO: I don't think these 2 lines are needed. Remove them? */ | 430 /* TODO: I don't think these 2 lines are needed. Remove them? */ |
431 if (ret == writelen) | 431 if (ret == writelen) |
432 httpconn_write_cb(data, source, cond); | 432 httpconn_write_cb(data, source, cond); |
433 } | 433 } |
454 if (res < 0 || res < data_len) | 454 if (res < 0 || res < data_len) |
455 { | 455 { |
456 if (res < 0) | 456 if (res < 0) |
457 res = 0; | 457 res = 0; |
458 if (httpconn->tx_handler == 0 && httpconn->fd) | 458 if (httpconn->tx_handler == 0 && httpconn->fd) |
459 httpconn->tx_handler = gaim_input_add(httpconn->fd, | 459 httpconn->tx_handler = purple_input_add(httpconn->fd, |
460 GAIM_INPUT_WRITE, httpconn_write_cb, httpconn); | 460 PURPLE_INPUT_WRITE, httpconn_write_cb, httpconn); |
461 gaim_circ_buffer_append(httpconn->tx_buf, data + res, | 461 purple_circ_buffer_append(httpconn->tx_buf, data + res, |
462 data_len - res); | 462 data_len - res); |
463 } | 463 } |
464 | 464 |
465 return TRUE; | 465 return TRUE; |
466 } | 466 } |
467 | 467 |
468 static char * | 468 static char * |
469 msn_httpconn_proxy_auth(MsnHttpConn *httpconn) | 469 msn_httpconn_proxy_auth(MsnHttpConn *httpconn) |
470 { | 470 { |
471 GaimAccount *account; | 471 PurpleAccount *account; |
472 GaimProxyInfo *gpi; | 472 PurpleProxyInfo *gpi; |
473 const char *username, *password; | 473 const char *username, *password; |
474 char *auth = NULL; | 474 char *auth = NULL; |
475 | 475 |
476 account = httpconn->session->account; | 476 account = httpconn->session->account; |
477 | 477 |
478 gpi = gaim_proxy_get_setup(account); | 478 gpi = purple_proxy_get_setup(account); |
479 | 479 |
480 if (gpi == NULL || !(gaim_proxy_info_get_type(gpi) == GAIM_PROXY_HTTP || | 480 if (gpi == NULL || !(purple_proxy_info_get_type(gpi) == PURPLE_PROXY_HTTP || |
481 gaim_proxy_info_get_type(gpi) == GAIM_PROXY_USE_ENVVAR)) | 481 purple_proxy_info_get_type(gpi) == PURPLE_PROXY_USE_ENVVAR)) |
482 return NULL; | 482 return NULL; |
483 | 483 |
484 username = gaim_proxy_info_get_username(gpi); | 484 username = purple_proxy_info_get_username(gpi); |
485 password = gaim_proxy_info_get_password(gpi); | 485 password = purple_proxy_info_get_password(gpi); |
486 | 486 |
487 if (username != NULL) { | 487 if (username != NULL) { |
488 char *tmp; | 488 char *tmp; |
489 auth = g_strdup_printf("%s:%s", username, password ? password : ""); | 489 auth = g_strdup_printf("%s:%s", username, password ? password : ""); |
490 tmp = gaim_base64_encode((const guchar *)auth, strlen(auth)); | 490 tmp = purple_base64_encode((const guchar *)auth, strlen(auth)); |
491 g_free(auth); | 491 g_free(auth); |
492 auth = g_strdup_printf("Proxy-Authorization: Basic %s\r\n", tmp); | 492 auth = g_strdup_printf("Proxy-Authorization: Basic %s\r\n", tmp); |
493 g_free(tmp); | 493 g_free(tmp); |
494 } | 494 } |
495 | 495 |
598 /* The rest of the times servconn->host is the gateway host. */ | 598 /* The rest of the times servconn->host is the gateway host. */ |
599 host = httpconn->host; | 599 host = httpconn->host; |
600 | 600 |
601 if (host == NULL || httpconn->full_session_id == NULL) | 601 if (host == NULL || httpconn->full_session_id == NULL) |
602 { | 602 { |
603 gaim_debug_warning("msn", "Attempted HTTP write before session is established\n"); | 603 purple_debug_warning("msn", "Attempted HTTP write before session is established\n"); |
604 return -1; | 604 return -1; |
605 } | 605 } |
606 | 606 |
607 params = g_strdup_printf("SessionID=%s", | 607 params = g_strdup_printf("SessionID=%s", |
608 httpconn->full_session_id); | 608 httpconn->full_session_id); |
651 | 651 |
652 g_return_val_if_fail(servconn != NULL, NULL); | 652 g_return_val_if_fail(servconn != NULL, NULL); |
653 | 653 |
654 httpconn = g_new0(MsnHttpConn, 1); | 654 httpconn = g_new0(MsnHttpConn, 1); |
655 | 655 |
656 gaim_debug_info("msn", "new httpconn (%p)\n", httpconn); | 656 purple_debug_info("msn", "new httpconn (%p)\n", httpconn); |
657 | 657 |
658 /* TODO: Remove this */ | 658 /* TODO: Remove this */ |
659 httpconn->session = servconn->session; | 659 httpconn->session = servconn->session; |
660 | 660 |
661 httpconn->servconn = servconn; | 661 httpconn->servconn = servconn; |
662 | 662 |
663 httpconn->tx_buf = gaim_circ_buffer_new(MSN_BUF_LEN); | 663 httpconn->tx_buf = purple_circ_buffer_new(MSN_BUF_LEN); |
664 httpconn->tx_handler = 0; | 664 httpconn->tx_handler = 0; |
665 | 665 |
666 return httpconn; | 666 return httpconn; |
667 } | 667 } |
668 | 668 |
669 void | 669 void |
670 msn_httpconn_destroy(MsnHttpConn *httpconn) | 670 msn_httpconn_destroy(MsnHttpConn *httpconn) |
671 { | 671 { |
672 g_return_if_fail(httpconn != NULL); | 672 g_return_if_fail(httpconn != NULL); |
673 | 673 |
674 gaim_debug_info("msn", "destroy httpconn (%p)\n", httpconn); | 674 purple_debug_info("msn", "destroy httpconn (%p)\n", httpconn); |
675 | 675 |
676 if (httpconn->connected) | 676 if (httpconn->connected) |
677 msn_httpconn_disconnect(httpconn); | 677 msn_httpconn_disconnect(httpconn); |
678 | 678 |
679 g_free(httpconn->full_session_id); | 679 g_free(httpconn->full_session_id); |
680 | 680 |
681 g_free(httpconn->session_id); | 681 g_free(httpconn->session_id); |
682 | 682 |
683 g_free(httpconn->host); | 683 g_free(httpconn->host); |
684 | 684 |
685 gaim_circ_buffer_destroy(httpconn->tx_buf); | 685 purple_circ_buffer_destroy(httpconn->tx_buf); |
686 if (httpconn->tx_handler > 0) | 686 if (httpconn->tx_handler > 0) |
687 gaim_input_remove(httpconn->tx_handler); | 687 purple_input_remove(httpconn->tx_handler); |
688 | 688 |
689 g_free(httpconn); | 689 g_free(httpconn); |
690 } | 690 } |
691 | 691 |
692 static void | 692 static void |
698 httpconn->connect_data = NULL; | 698 httpconn->connect_data = NULL; |
699 httpconn->fd = source; | 699 httpconn->fd = source; |
700 | 700 |
701 if (source >= 0) | 701 if (source >= 0) |
702 { | 702 { |
703 httpconn->inpa = gaim_input_add(httpconn->fd, GAIM_INPUT_READ, | 703 httpconn->inpa = purple_input_add(httpconn->fd, PURPLE_INPUT_READ, |
704 read_cb, data); | 704 read_cb, data); |
705 | 705 |
706 httpconn->timer = gaim_timeout_add(2000, msn_httpconn_poll, httpconn); | 706 httpconn->timer = purple_timeout_add(2000, msn_httpconn_poll, httpconn); |
707 | 707 |
708 msn_httpconn_process_queue(httpconn); | 708 msn_httpconn_process_queue(httpconn); |
709 } | 709 } |
710 else | 710 else |
711 { | 711 { |
712 gaim_debug_error("msn", "HTTP: Connection error\n"); | 712 purple_debug_error("msn", "HTTP: Connection error\n"); |
713 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_CONNECT); | 713 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_CONNECT); |
714 } | 714 } |
715 } | 715 } |
716 | 716 |
717 gboolean | 717 gboolean |
722 g_return_val_if_fail(port > 0, FALSE); | 722 g_return_val_if_fail(port > 0, FALSE); |
723 | 723 |
724 if (httpconn->connected) | 724 if (httpconn->connected) |
725 msn_httpconn_disconnect(httpconn); | 725 msn_httpconn_disconnect(httpconn); |
726 | 726 |
727 httpconn->connect_data = gaim_proxy_connect(NULL, httpconn->session->account, | 727 httpconn->connect_data = purple_proxy_connect(NULL, httpconn->session->account, |
728 "gateway.messenger.hotmail.com", 80, connect_cb, httpconn); | 728 "gateway.messenger.hotmail.com", 80, connect_cb, httpconn); |
729 | 729 |
730 if (httpconn->connect_data != NULL) | 730 if (httpconn->connect_data != NULL) |
731 { | 731 { |
732 httpconn->waiting_response = TRUE; | 732 httpconn->waiting_response = TRUE; |
744 if (!httpconn->connected) | 744 if (!httpconn->connected) |
745 return; | 745 return; |
746 | 746 |
747 if (httpconn->connect_data != NULL) | 747 if (httpconn->connect_data != NULL) |
748 { | 748 { |
749 gaim_proxy_connect_cancel(httpconn->connect_data); | 749 purple_proxy_connect_cancel(httpconn->connect_data); |
750 httpconn->connect_data = NULL; | 750 httpconn->connect_data = NULL; |
751 } | 751 } |
752 | 752 |
753 if (httpconn->timer) | 753 if (httpconn->timer) |
754 { | 754 { |
755 gaim_timeout_remove(httpconn->timer); | 755 purple_timeout_remove(httpconn->timer); |
756 httpconn->timer = 0; | 756 httpconn->timer = 0; |
757 } | 757 } |
758 | 758 |
759 if (httpconn->inpa > 0) | 759 if (httpconn->inpa > 0) |
760 { | 760 { |
761 gaim_input_remove(httpconn->inpa); | 761 purple_input_remove(httpconn->inpa); |
762 httpconn->inpa = 0; | 762 httpconn->inpa = 0; |
763 } | 763 } |
764 | 764 |
765 close(httpconn->fd); | 765 close(httpconn->fd); |
766 httpconn->fd = -1; | 766 httpconn->fd = -1; |