comparison libpurple/protocols/jabber/bosh.c @ 29772:3ac7f10d13d4

jabber: Send whitespace keepalives every two minutes of (outgoing) silence. This works around stupid behavior of Openfire hopefully (otherwise we may need to send a full IQ ping instead of a whitespace tab). Closes #10767
author Paul Aurich <paul@darkrain42.org>
date Wed, 21 Apr 2010 19:07:19 +0000
parents 618c4165d4f8
children 22afdd5a9290
comparison
equal deleted inserted replaced
29771:fb270a3d0732 29772:3ac7f10d13d4
76 BOSH_CONN_BOOTING, 76 BOSH_CONN_BOOTING,
77 BOSH_CONN_ONLINE 77 BOSH_CONN_ONLINE
78 } state; 78 } state;
79 guint8 failed_connections; 79 guint8 failed_connections;
80 80
81 int max_inactivity;
82 int wait; 81 int wait;
83 82
84 int max_requests; 83 int max_requests;
85 int requests; 84 int requests;
86 85
87 guint inactivity_timer;
88 guint send_timer; 86 guint send_timer;
89 }; 87 };
90 88
91 struct _PurpleHTTPConnection { 89 struct _PurpleHTTPConnection {
92 PurpleBOSHConnection *bosh; 90 PurpleBOSHConnection *bosh;
237 g_free(conn->host); 235 g_free(conn->host);
238 g_free(conn->path); 236 g_free(conn->path);
239 237
240 if (conn->send_timer) 238 if (conn->send_timer)
241 purple_timeout_remove(conn->send_timer); 239 purple_timeout_remove(conn->send_timer);
242 if (conn->inactivity_timer)
243 purple_timeout_remove(conn->inactivity_timer);
244 240
245 purple_circ_buffer_destroy(conn->pending); 241 purple_circ_buffer_destroy(conn->pending);
246 242
247 for (i = 0; i < NUM_HTTP_CONNECTIONS; ++i) { 243 for (i = 0; i < NUM_HTTP_CONNECTIONS; ++i) {
248 if (conn->connections[i]) 244 if (conn->connections[i])
431 jabber_bosh_connection_send(bosh, PACKET_FLUSH, NULL); 427 jabber_bosh_connection_send(bosh, PACKET_FLUSH, NULL);
432 428
433 return FALSE; 429 return FALSE;
434 } 430 }
435 431
436 static gboolean 432 void
437 bosh_inactivity_cb(gpointer data) 433 jabber_bosh_connection_send_keepalive(PurpleBOSHConnection *bosh)
438 { 434 {
439 PurpleBOSHConnection *bosh = data;
440 bosh->inactivity_timer = 0;
441
442 if (bosh->send_timer != 0) 435 if (bosh->send_timer != 0)
443 purple_timeout_remove(bosh->send_timer); 436 purple_timeout_remove(bosh->send_timer);
444 437
445 /* clears bosh->send_timer */ 438 /* clears bosh->send_timer */
446 send_timer_cb(bosh); 439 send_timer_cb(bosh);
447
448 return FALSE;
449 }
450
451 static void
452 restart_inactivity_timer(PurpleBOSHConnection *conn)
453 {
454 if (conn->inactivity_timer != 0) {
455 purple_timeout_remove(conn->inactivity_timer);
456 conn->inactivity_timer = 0;
457 }
458
459 if (conn->max_inactivity != 0) {
460 conn->inactivity_timer =
461 purple_timeout_add_seconds(conn->max_inactivity - 5 /* rounding */,
462 bosh_inactivity_cb, conn);
463 }
464 } 440 }
465 441
466 static void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node) { 442 static void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node) {
467 xmlnode *child; 443 xmlnode *child;
468 JabberStream *js = conn->js; 444 JabberStream *js = conn->js;
539 } else { 515 } else {
540 purple_debug_info("jabber", "Missing version in BOSH initiation\n"); 516 purple_debug_info("jabber", "Missing version in BOSH initiation\n");
541 } 517 }
542 518
543 if (inactivity) { 519 if (inactivity) {
544 conn->max_inactivity = atoi(inactivity); 520 js->max_inactivity = atoi(inactivity);
545 if (conn->max_inactivity <= 5) { 521 if (js->max_inactivity <= 5) {
546 purple_debug_warning("jabber", "Ignoring bogusly small inactivity: %s\n", 522 purple_debug_warning("jabber", "Ignoring bogusly small inactivity: %s\n",
547 inactivity); 523 inactivity);
548 conn->max_inactivity = 0; 524 /* Leave it at the default */
549 } else { 525 } else {
550 /* TODO: Integrate this with jabber.c keepalive checks... */
551 /* TODO: Can this check fail? It shouldn't */ 526 /* TODO: Can this check fail? It shouldn't */
552 if (conn->inactivity_timer == 0) { 527 js->max_inactivity -= 5; /* rounding */
528
529 if (js->inactivity_timer == 0) {
553 purple_debug_misc("jabber", "Starting BOSH inactivity timer " 530 purple_debug_misc("jabber", "Starting BOSH inactivity timer "
554 "for %d secs (compensating for rounding)\n", 531 "for %d secs (compensating for rounding)\n",
555 conn->max_inactivity - 5); 532 js->max_inactivity);
556 restart_inactivity_timer(conn); 533 jabber_stream_restart_inactivity_timer(js);
557 } 534 }
558 } 535 }
559 } 536 }
560 537
561 if (requests) 538 if (requests)
974 char *data; 951 char *data;
975 int ret; 952 int ret;
976 size_t len; 953 size_t len;
977 954
978 /* Sending something to the server, restart the inactivity timer */ 955 /* Sending something to the server, restart the inactivity timer */
979 restart_inactivity_timer(conn->bosh); 956 jabber_stream_restart_inactivity_timer(conn->bosh->js);
980 957
981 data = g_strdup_printf("POST %s HTTP/1.1\r\n" 958 data = g_strdup_printf("POST %s HTTP/1.1\r\n"
982 "Host: %s\r\n" 959 "Host: %s\r\n"
983 "User-Agent: %s\r\n" 960 "User-Agent: %s\r\n"
984 "Content-Encoding: text/xml; charset=utf-8\r\n" 961 "Content-Encoding: text/xml; charset=utf-8\r\n"