comparison libpurple/protocols/jabber/bosh.c @ 25667:bf7338765863

BOSH: Fix an off-by-one g_memdup that was missing the null terminator. Also, change some printf()s to purple_debug_* and a g_return_if_fail.
author Paul Aurich <paul@darkrain42.org>
date Mon, 19 Jan 2009 18:25:38 +0000
parents 7856dccb02fb
children 8c58f31f41eb
comparison
equal deleted inserted replaced
25666:7856dccb02fb 25667:bf7338765863
400 printf("\njabber_bosh_connection_http_received_cb\n%s\n", txt); 400 printf("\njabber_bosh_connection_http_received_cb\n%s\n", txt);
401 g_free(txt); 401 g_free(txt);
402 conn->receive_cb(conn, node); 402 conn->receive_cb(conn, node);
403 xmlnode_free(node); 403 xmlnode_free(node);
404 } else { 404 } else {
405 printf("\njabber_bosh_connection_http_received_cb: XML ERROR: %s\n", res->data); 405 purple_debug_warning("jabber", "BOSH: Received invalid XML\n");
406 } 406 }
407 } else purple_debug_info("jabber", "missing receive_cb of PurpleBOSHConnection.\n"); 407 } else {
408 g_return_if_reached();
409 }
408 } 410 }
409 411
410 void jabber_bosh_connection_send(PurpleBOSHConnection *conn, xmlnode *node) { 412 void jabber_bosh_connection_send(PurpleBOSHConnection *conn, xmlnode *node) {
411 xmlnode *packet = xmlnode_new("body"); 413 xmlnode *packet = xmlnode_new("body");
412 /* XEP-0124: The rid must not exceed 16 characters */ 414 /* XEP-0124: The rid must not exceed 16 characters */
529 cb = g_queue_pop_head(conn->requests); 531 cb = g_queue_pop_head(conn->requests);
530 532
531 #warning For a pure HTTP 1.1 stack, this would need to be handled elsewhere. 533 #warning For a pure HTTP 1.1 stack, this would need to be handled elsewhere.
532 if (bosh_conn->ready && g_queue_is_empty(conn->requests)) { 534 if (bosh_conn->ready && g_queue_is_empty(conn->requests)) {
533 jabber_bosh_connection_send(bosh_conn, NULL); 535 jabber_bosh_connection_send(bosh_conn, NULL);
534 printf("\n SEND AN EMPTY REQUEST \n"); 536 purple_debug_misc("jabber", "BOSH: Sending an empty request\n");
535 } 537 }
536 538
537 if (cb) { 539 if (cb) {
538 conn->current_response->data_len = conn->body_len; 540 conn->current_response->data_len = conn->body_len;
539 conn->current_response->data = g_memdup(conn->buf->str + conn->handled_len, conn->body_len); 541 conn->current_response->data = g_memdup(conn->buf->str + conn->handled_len, conn->body_len + 1);
540 542
541 cb(conn->current_response, conn->userdata); 543 cb(conn->current_response, conn->userdata);
542 } else { 544 } else {
543 purple_debug_warning("jabber", "Received HTTP response before POST\n"); 545 purple_debug_warning("jabber", "Received HTTP response before POST\n");
544 } 546 }
648 "Content-Length: %d\r\n\r\n", 650 "Content-Length: %d\r\n\r\n",
649 req->path, conn->host, bosh_useragent, req->data_len); 651 req->path, conn->host, bosh_useragent, req->data_len);
650 652
651 packet = g_string_append(packet, req->data); 653 packet = g_string_append(packet, req->data);
652 654
653 printf("Sending %s\n", packet->str); 655 purple_debug_misc("jabber", "BOSH out: %s\n", packet->str);
654 /* TODO: Better error handling, circbuffer or possible integration with 656 /* TODO: Better error handling, circbuffer or possible integration with
655 * low-level code in jabber.c */ 657 * low-level code in jabber.c */
656 ret = write(conn->fd, packet->str, packet->len); 658 ret = write(conn->fd, packet->str, packet->len);
657 659
658 g_string_free(packet, TRUE); 660 g_string_free(packet, TRUE);