| 386 txt = xmlnode_to_str(packet, &len); |
386 txt = xmlnode_to_str(packet, &len); |
| 387 jabber_send_raw(js, txt, len); |
387 jabber_send_raw(js, txt, len); |
| 388 g_free(txt); |
388 g_free(txt); |
| 389 } |
389 } |
| 390 |
390 |
| |
391 static void jabber_pong_cb(JabberStream *js, xmlnode *packet, gpointer timeout) |
| |
392 { |
| |
393 g_source_remove(GPOINTER_TO_INT(timeout)); |
| |
394 } |
| |
395 |
| |
396 static gboolean jabber_pong_timeout(PurpleConnection *gc) |
| |
397 { |
| |
398 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
| |
399 _("Ping timeout")); |
| |
400 return FALSE; |
| |
401 } |
| |
402 |
| 391 void jabber_keepalive(PurpleConnection *gc) |
403 void jabber_keepalive(PurpleConnection *gc) |
| 392 { |
404 { |
| 393 jabber_send_raw(gc->proto_data, "\t", -1); |
405 JabberIq *iq = jabber_iq_new(gc->proto_data, JABBER_IQ_GET); |
| |
406 guint timeout; |
| |
407 |
| |
408 xmlnode *ping = xmlnode_new_child(iq->node, "ping"); |
| |
409 xmlnode_set_namespace(ping, "urn:xmpp:ping"); |
| |
410 |
| |
411 timeout = purple_timeout_add_seconds(20, (GSourceFunc)(jabber_pong_timeout), gc); |
| |
412 jabber_iq_set_callback(iq, jabber_pong_cb, GINT_TO_POINTER(timeout)); |
| |
413 jabber_iq_send(iq); |
| 394 } |
414 } |
| 395 |
415 |
| 396 static void |
416 static void |
| 397 jabber_recv_cb_ssl(gpointer data, PurpleSslConnection *gsc, |
417 jabber_recv_cb_ssl(gpointer data, PurpleSslConnection *gsc, |
| 398 PurpleInputCondition cond) |
418 PurpleInputCondition cond) |