comparison libpurple/protocols/jabber/bosh.c @ 26929:f82f3dc29f9b

Don't try to process BOSH packet if there's no data (avoid a purple_strcasestr assertion). Also print friendlier error messages.
author Paul Aurich <paul@darkrain42.org>
date Thu, 21 May 2009 21:09:17 +0000
parents 45271de9c65d
children 6105fa42b60c
comparison
equal deleted inserted replaced
26926:fdd2952d8639 26929:f82f3dc29f9b
299 purple_circ_buffer_append(conn->pending, data, len); 299 purple_circ_buffer_append(conn->pending, data, len);
300 } 300 }
301 return; 301 return;
302 } 302 }
303 303
304 packet = g_string_new(""); 304 packet = g_string_new(NULL);
305 305
306 g_string_printf(packet, "<body " 306 g_string_printf(packet, "<body "
307 "rid='%" G_GUINT64_FORMAT "' " 307 "rid='%" G_GUINT64_FORMAT "' "
308 "sid='%s' " 308 "sid='%s' "
309 "to='%s' " 309 "to='%s' "
486 conn->receive_cb = auth_response_cb; 486 conn->receive_cb = auth_response_cb;
487 jabber_stream_features_parse(conn->js, packet); 487 jabber_stream_features_parse(conn->js, packet);
488 } 488 }
489 489
490 static void jabber_bosh_connection_boot(PurpleBOSHConnection *conn) { 490 static void jabber_bosh_connection_boot(PurpleBOSHConnection *conn) {
491 GString *buf = g_string_new(""); 491 GString *buf = g_string_new(NULL);
492 492
493 g_string_printf(buf, "<body content='text/xml; charset=utf-8' " 493 g_string_printf(buf, "<body content='text/xml; charset=utf-8' "
494 "secure='true' " 494 "secure='true' "
495 "to='%s' " 495 "to='%s' "
496 "xml:lang='en' " 496 "xml:lang='en' "
684 { 684 {
685 char buffer[1025]; 685 char buffer[1025];
686 int cnt, count = 0; 686 int cnt, count = 0;
687 687
688 if (!conn->buf) 688 if (!conn->buf)
689 conn->buf = g_string_new(""); 689 conn->buf = g_string_new(NULL);
690 690
691 /* Read once to prime cnt before the loop */ 691 /* Read once to prime cnt before the loop */
692 if (conn->psc) 692 if (conn->psc)
693 cnt = purple_ssl_read(conn->psc, buffer, sizeof(buffer)); 693 cnt = purple_ssl_read(conn->psc, buffer, sizeof(buffer));
694 else 694 else
703 cnt = read(conn->fd, buffer, sizeof(buffer)); 703 cnt = read(conn->fd, buffer, sizeof(buffer));
704 } 704 }
705 705
706 if (cnt == 0 || (cnt < 0 && errno != EAGAIN)) { 706 if (cnt == 0 || (cnt < 0 && errno != EAGAIN)) {
707 if (cnt < 0) 707 if (cnt < 0)
708 purple_debug_info("jabber", "bosh read=%d, errno=%d\n", cnt, errno); 708 purple_debug_info("jabber", "bosh read=%d, errno=%d, error=%s\n",
709 cnt, errno, g_strerror(errno));
709 else 710 else
710 purple_debug_info("jabber", "bosh server closed the connection\n"); 711 purple_debug_info("jabber", "bosh server closed the connection\n");
711 712
712 /* 713 /*
713 * If the socket is closed, the processing really needs to know about 714 * If the socket is closed, the processing really needs to know about
716 http_connection_disconnected(conn); 717 http_connection_disconnected(conn);
717 718
718 /* Process what we do have */ 719 /* Process what we do have */
719 } 720 }
720 721
721 722 if (conn->buf->len > 0)
722 jabber_bosh_http_connection_process(conn); 723 jabber_bosh_http_connection_process(conn);
723 } 724 }
724 725
725 static void 726 static void
726 http_connection_read_cb(gpointer data, gint fd, PurpleInputCondition condition) 727 http_connection_read_cb(gpointer data, gint fd, PurpleInputCondition condition)
727 { 728 {