| 444 txt = xmlnode_to_str(packet, &len); |
444 txt = xmlnode_to_str(packet, &len); |
| 445 jabber_send_raw(js, txt, len); |
445 jabber_send_raw(js, txt, len); |
| 446 g_free(txt); |
446 g_free(txt); |
| 447 } |
447 } |
| 448 |
448 |
| 449 static void jabber_pong_cb(JabberStream *js, xmlnode *packet, gpointer unused) |
449 static gboolean jabber_keepalive_timeout(PurpleConnection *gc) |
| 450 { |
|
| 451 purple_timeout_remove(js->keepalive_timeout); |
|
| 452 js->keepalive_timeout = -1; |
|
| 453 } |
|
| 454 |
|
| 455 static gboolean jabber_pong_timeout(PurpleConnection *gc) |
|
| 456 { |
450 { |
| 457 JabberStream *js = gc->proto_data; |
451 JabberStream *js = gc->proto_data; |
| 458 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
452 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
| 459 _("Ping timeout")); |
453 _("Ping timeout")); |
| 460 js->keepalive_timeout = -1; |
454 js->keepalive_timeout = -1; |
| 464 void jabber_keepalive(PurpleConnection *gc) |
458 void jabber_keepalive(PurpleConnection *gc) |
| 465 { |
459 { |
| 466 JabberStream *js = gc->proto_data; |
460 JabberStream *js = gc->proto_data; |
| 467 |
461 |
| 468 if (js->keepalive_timeout == -1) { |
462 if (js->keepalive_timeout == -1) { |
| 469 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_GET); |
463 jabber_ping_jid(js, NULL); |
| 470 |
464 js->keepalive_timeout = purple_timeout_add_seconds(120, |
| 471 xmlnode *ping = xmlnode_new_child(iq->node, "ping"); |
465 (GSourceFunc)(jabber_keepalive_timeout), gc); |
| 472 xmlnode_set_namespace(ping, "urn:xmpp:ping"); |
|
| 473 |
|
| 474 js->keepalive_timeout = purple_timeout_add_seconds(120, (GSourceFunc)(jabber_pong_timeout), gc); |
|
| 475 jabber_iq_set_callback(iq, jabber_pong_cb, NULL); |
|
| 476 jabber_iq_send(iq); |
|
| 477 } |
466 } |
| 478 } |
467 } |
| 479 |
468 |
| 480 static void |
469 static void |
| 481 jabber_recv_cb_ssl(gpointer data, PurpleSslConnection *gsc, |
470 jabber_recv_cb_ssl(gpointer data, PurpleSslConnection *gsc, |
| 992 |
981 |
| 993 jabber_iq_set_callback(iq, jabber_registration_result_cb, to); |
982 jabber_iq_set_callback(iq, jabber_registration_result_cb, to); |
| 994 jabber_iq_send(iq); |
983 jabber_iq_send(iq); |
| 995 } |
984 } |
| 996 |
985 |
| 997 void jabber_register_parse(JabberStream *js, xmlnode *packet) |
986 void jabber_register_parse(JabberStream *js, const char *from, JabberIqType type, |
| |
987 const char *id, xmlnode *query) |
| 998 { |
988 { |
| 999 PurpleAccount *account = purple_connection_get_account(js->gc); |
989 PurpleAccount *account = purple_connection_get_account(js->gc); |
| 1000 const char *type; |
|
| 1001 const char *from; |
|
| 1002 PurpleRequestFields *fields; |
990 PurpleRequestFields *fields; |
| 1003 PurpleRequestFieldGroup *group; |
991 PurpleRequestFieldGroup *group; |
| 1004 PurpleRequestField *field; |
992 PurpleRequestField *field; |
| 1005 xmlnode *query, *x, *y; |
993 xmlnode *x, *y; |
| 1006 char *instructions; |
994 char *instructions; |
| 1007 JabberRegisterCBData *cbdata; |
995 JabberRegisterCBData *cbdata; |
| 1008 gboolean registered = FALSE; |
996 gboolean registered = FALSE; |
| 1009 |
997 |
| 1010 if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result")) |
998 if (type != JABBER_IQ_RESULT) |
| 1011 return; |
999 return; |
| 1012 |
1000 |
| 1013 from = xmlnode_get_attrib(packet, "from"); |
1001 if (!from) |
| |
1002 from = js->serverFQDN; |
| |
1003 g_return_if_fail(from != NULL); |
| 1014 |
1004 |
| 1015 if(js->registration) { |
1005 if(js->registration) { |
| 1016 /* get rid of the login thingy */ |
1006 /* get rid of the login thingy */ |
| 1017 purple_connection_set_state(js->gc, PURPLE_CONNECTED); |
1007 purple_connection_set_state(js->gc, PURPLE_CONNECTED); |
| 1018 } |
1008 } |
| 1019 |
|
| 1020 query = xmlnode_get_child(packet, "query"); |
|
| 1021 |
1009 |
| 1022 if(xmlnode_get_child(query, "registered")) { |
1010 if(xmlnode_get_child(query, "registered")) { |
| 1023 registered = TRUE; |
1011 registered = TRUE; |
| 1024 |
1012 |
| 1025 if(js->registration) { |
1013 if(js->registration) { |