comparison libpurple/protocols/jabber/jabber.c @ 26546:a4a5825fb1bb

propagate from branch 'im.pidgin.pidgin' (head 54da791ad8d26949571afcbd931518f5b27f2bfd) to branch 'im.pidgin.cpw.darkrain42.xmpp.iq-handlers' (head d2baa98bd1e1a039ec6e1da16ded71318214691a)
author Paul Aurich <paul@darkrain42.org>
date Thu, 12 Mar 2009 23:46:34 +0000
parents 7ace7bf0bfad d24b476cc60f
children ae41d8e827e3
comparison
equal deleted inserted replaced
26260:37a3f30a8d80 26546:a4a5825fb1bb
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) {
2453 } 2441 }
2454 2442
2455 static PurpleCmdRet jabber_cmd_ping(PurpleConversation *conv, 2443 static PurpleCmdRet jabber_cmd_ping(PurpleConversation *conv,
2456 const char *cmd, char **args, char **error, void *data) 2444 const char *cmd, char **args, char **error, void *data)
2457 { 2445 {
2446 PurpleAccount *account;
2447 PurpleConnection *pc;
2448
2458 if(!args || !args[0]) 2449 if(!args || !args[0])
2459 return PURPLE_CMD_RET_FAILED; 2450 return PURPLE_CMD_RET_FAILED;
2460 2451
2461 if(!jabber_ping_jid(conv, args[0])) { 2452 account = purple_conversation_get_account(conv);
2453 pc = purple_account_get_connection(account);
2454
2455 if(!jabber_ping_jid(purple_connection_get_protocol_data(pc), args[0])) {
2462 *error = g_strdup_printf(_("Unable to ping user %s"), args[0]); 2456 *error = g_strdup_printf(_("Unable to ping user %s"), args[0]);
2463 return PURPLE_CMD_RET_FAILED; 2457 return PURPLE_CMD_RET_FAILED;
2464 } 2458 }
2465 2459
2466 return PURPLE_CMD_RET_OK; 2460 return PURPLE_CMD_RET_OK;