| 85 js->reinit = FALSE; |
85 js->reinit = FALSE; |
| 86 g_free(open_stream); |
86 g_free(open_stream); |
| 87 } |
87 } |
| 88 |
88 |
| 89 static void |
89 static void |
| 90 jabber_session_initialized_cb(JabberStream *js, xmlnode *packet, gpointer data) |
90 jabber_session_initialized_cb(JabberStream *js, const char *from, |
| 91 { |
91 JabberIqType type, const char *id, |
| 92 const char *type = xmlnode_get_attrib(packet, "type"); |
92 xmlnode *packet, gpointer data) |
| 93 if(type && !strcmp(type, "result")) { |
93 { |
| |
94 if (type == JABBER_IQ_RESULT) { |
| 94 jabber_stream_set_state(js, JABBER_STREAM_CONNECTED); |
95 jabber_stream_set_state(js, JABBER_STREAM_CONNECTED); |
| 95 if(js->unregistration) |
96 if(js->unregistration) |
| 96 jabber_unregister_account_cb(js); |
97 jabber_unregister_account_cb(js); |
| 97 } else { |
98 } else { |
| 98 purple_connection_error_reason (js->gc, |
99 purple_connection_error_reason (js->gc, |
| 112 xmlnode_set_namespace(session, "urn:ietf:params:xml:ns:xmpp-session"); |
113 xmlnode_set_namespace(session, "urn:ietf:params:xml:ns:xmpp-session"); |
| 113 |
114 |
| 114 jabber_iq_send(iq); |
115 jabber_iq_send(iq); |
| 115 } |
116 } |
| 116 |
117 |
| 117 static void jabber_bind_result_cb(JabberStream *js, xmlnode *packet, |
118 static void jabber_bind_result_cb(JabberStream *js, const char *from, |
| 118 gpointer data) |
119 JabberIqType type, const char *id, |
| 119 { |
120 xmlnode *packet, gpointer data) |
| 120 const char *type = xmlnode_get_attrib(packet, "type"); |
121 { |
| 121 xmlnode *bind; |
122 xmlnode *bind; |
| 122 |
123 |
| 123 if(type && !strcmp(type, "result") && |
124 if (type == JABBER_IQ_RESULT && |
| 124 (bind = xmlnode_get_child_with_namespace(packet, "bind", "urn:ietf:params:xml:ns:xmpp-bind"))) { |
125 (bind = xmlnode_get_child_with_namespace(packet, "bind", "urn:ietf:params:xml:ns:xmpp-bind"))) { |
| 125 xmlnode *jid; |
126 xmlnode *jid; |
| 126 char *full_jid; |
127 char *full_jid; |
| 127 if((jid = xmlnode_get_child(bind, "jid")) && (full_jid = xmlnode_get_data(jid))) { |
128 if((jid = xmlnode_get_child(bind, "jid")) && (full_jid = xmlnode_get_data(jid))) { |
| 128 JabberBuddy *my_jb = NULL; |
129 JabberBuddy *my_jb = NULL; |
| 446 txt = xmlnode_to_str(packet, &len); |
447 txt = xmlnode_to_str(packet, &len); |
| 447 jabber_send_raw(js, txt, len); |
448 jabber_send_raw(js, txt, len); |
| 448 g_free(txt); |
449 g_free(txt); |
| 449 } |
450 } |
| 450 |
451 |
| 451 static void jabber_pong_cb(JabberStream *js, xmlnode *packet, gpointer unused) |
452 static gboolean jabber_keepalive_timeout(PurpleConnection *gc) |
| 452 { |
|
| 453 purple_timeout_remove(js->keepalive_timeout); |
|
| 454 js->keepalive_timeout = -1; |
|
| 455 } |
|
| 456 |
|
| 457 static gboolean jabber_pong_timeout(PurpleConnection *gc) |
|
| 458 { |
453 { |
| 459 JabberStream *js = gc->proto_data; |
454 JabberStream *js = gc->proto_data; |
| 460 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
455 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
| 461 _("Ping timeout")); |
456 _("Ping timeout")); |
| 462 js->keepalive_timeout = -1; |
457 js->keepalive_timeout = -1; |
| 466 void jabber_keepalive(PurpleConnection *gc) |
461 void jabber_keepalive(PurpleConnection *gc) |
| 467 { |
462 { |
| 468 JabberStream *js = gc->proto_data; |
463 JabberStream *js = gc->proto_data; |
| 469 |
464 |
| 470 if (js->keepalive_timeout == -1) { |
465 if (js->keepalive_timeout == -1) { |
| 471 JabberIq *iq = jabber_iq_new(js, JABBER_IQ_GET); |
466 jabber_ping_jid(js, NULL); |
| 472 |
467 js->keepalive_timeout = purple_timeout_add_seconds(120, |
| 473 xmlnode *ping = xmlnode_new_child(iq->node, "ping"); |
468 (GSourceFunc)(jabber_keepalive_timeout), gc); |
| 474 xmlnode_set_namespace(ping, "urn:xmpp:ping"); |
|
| 475 |
|
| 476 js->keepalive_timeout = purple_timeout_add_seconds(120, (GSourceFunc)(jabber_pong_timeout), gc); |
|
| 477 jabber_iq_set_callback(iq, jabber_pong_cb, NULL); |
|
| 478 jabber_iq_send(iq); |
|
| 479 } |
469 } |
| 480 } |
470 } |
| 481 |
471 |
| 482 static void |
472 static void |
| 483 jabber_recv_cb_ssl(gpointer data, PurpleSslConnection *gsc, |
473 jabber_recv_cb_ssl(gpointer data, PurpleSslConnection *gsc, |
| 800 { |
790 { |
| 801 purple_timeout_add(0, conn_close_cb, js); |
791 purple_timeout_add(0, conn_close_cb, js); |
| 802 } |
792 } |
| 803 |
793 |
| 804 static void |
794 static void |
| 805 jabber_registration_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
795 jabber_registration_result_cb(JabberStream *js, const char *from, |
| |
796 JabberIqType type, const char *id, |
| |
797 xmlnode *packet, gpointer data) |
| 806 { |
798 { |
| 807 PurpleAccount *account = purple_connection_get_account(js->gc); |
799 PurpleAccount *account = purple_connection_get_account(js->gc); |
| 808 const char *type = xmlnode_get_attrib(packet, "type"); |
|
| 809 char *buf; |
800 char *buf; |
| 810 char *to = data; |
801 char *to = data; |
| 811 |
802 |
| 812 if(!strcmp(type, "result")) { |
803 if (type == JABBER_IQ_RESULT) { |
| 813 if(js->registration) { |
804 if(js->registration) { |
| 814 buf = g_strdup_printf(_("Registration of %s@%s successful"), |
805 buf = g_strdup_printf(_("Registration of %s@%s successful"), |
| 815 js->user->node, js->user->domain); |
806 js->user->node, js->user->domain); |
| 816 if(account->registration_cb) |
807 if(account->registration_cb) |
| 817 (account->registration_cb)(account, TRUE, account->registration_cb_user_data); |
808 (account->registration_cb)(account, TRUE, account->registration_cb_user_data); |
| 835 if(account->registration_cb) |
826 if(account->registration_cb) |
| 836 (account->registration_cb)(account, FALSE, account->registration_cb_user_data); |
827 (account->registration_cb)(account, FALSE, account->registration_cb_user_data); |
| 837 } |
828 } |
| 838 g_free(to); |
829 g_free(to); |
| 839 if(js->registration) |
830 if(js->registration) |
| 840 jabber_connection_schedule_close(js); |
831 jabber_connection_schedule_close(js); |
| 841 } |
832 } |
| 842 |
833 |
| 843 static void |
834 static void |
| 844 jabber_unregistration_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
835 jabber_unregistration_result_cb(JabberStream *js, const char *from, |
| 845 { |
836 JabberIqType type, const char *id, |
| 846 const char *type = xmlnode_get_attrib(packet, "type"); |
837 xmlnode *packet, gpointer data) |
| |
838 { |
| 847 char *buf; |
839 char *buf; |
| 848 char *to = data; |
840 char *to = data; |
| 849 |
841 |
| 850 /* This function is never called for unregistering our XMPP account from |
842 /* This function is never called for unregistering our XMPP account from |
| 851 * the server, so there should always be a 'to' address. */ |
843 * the server, so there should always be a 'to' address. */ |
| 852 g_return_if_fail(to != NULL); |
844 g_return_if_fail(to != NULL); |
| 853 |
845 |
| 854 if(!strcmp(type, "result")) { |
846 if (type == JABBER_IQ_RESULT) { |
| 855 buf = g_strdup_printf(_("Registration from %s successfully removed"), |
847 buf = g_strdup_printf(_("Registration from %s successfully removed"), |
| 856 to); |
848 to); |
| 857 purple_notify_info(NULL, _("Unregistration Successful"), |
849 purple_notify_info(NULL, _("Unregistration Successful"), |
| 858 _("Unregistration Successful"), buf); |
850 _("Unregistration Successful"), buf); |
| 859 g_free(buf); |
851 g_free(buf); |
| 998 |
990 |
| 999 jabber_iq_set_callback(iq, jabber_registration_result_cb, to); |
991 jabber_iq_set_callback(iq, jabber_registration_result_cb, to); |
| 1000 jabber_iq_send(iq); |
992 jabber_iq_send(iq); |
| 1001 } |
993 } |
| 1002 |
994 |
| 1003 void jabber_register_parse(JabberStream *js, xmlnode *packet) |
995 void jabber_register_parse(JabberStream *js, const char *from, JabberIqType type, |
| |
996 const char *id, xmlnode *query) |
| 1004 { |
997 { |
| 1005 PurpleAccount *account = purple_connection_get_account(js->gc); |
998 PurpleAccount *account = purple_connection_get_account(js->gc); |
| 1006 const char *type; |
|
| 1007 const char *from; |
|
| 1008 PurpleRequestFields *fields; |
999 PurpleRequestFields *fields; |
| 1009 PurpleRequestFieldGroup *group; |
1000 PurpleRequestFieldGroup *group; |
| 1010 PurpleRequestField *field; |
1001 PurpleRequestField *field; |
| 1011 xmlnode *query, *x, *y; |
1002 xmlnode *x, *y; |
| 1012 char *instructions; |
1003 char *instructions; |
| 1013 JabberRegisterCBData *cbdata; |
1004 JabberRegisterCBData *cbdata; |
| 1014 gboolean registered = FALSE; |
1005 gboolean registered = FALSE; |
| 1015 |
1006 |
| 1016 if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result")) |
1007 if (type != JABBER_IQ_RESULT) |
| 1017 return; |
1008 return; |
| 1018 |
1009 |
| 1019 from = xmlnode_get_attrib(packet, "from"); |
1010 if (!from) |
| |
1011 from = js->serverFQDN; |
| |
1012 g_return_if_fail(from != NULL); |
| 1020 |
1013 |
| 1021 if(js->registration) { |
1014 if(js->registration) { |
| 1022 /* get rid of the login thingy */ |
1015 /* get rid of the login thingy */ |
| 1023 purple_connection_set_state(js->gc, PURPLE_CONNECTED); |
1016 purple_connection_set_state(js->gc, PURPLE_CONNECTED); |
| 1024 } |
1017 } |
| 1025 |
|
| 1026 query = xmlnode_get_child(packet, "query"); |
|
| 1027 |
1018 |
| 1028 if(xmlnode_get_child(query, "registered")) { |
1019 if(xmlnode_get_child(query, "registered")) { |
| 1029 registered = TRUE; |
1020 registered = TRUE; |
| 1030 |
1021 |
| 1031 if(js->registration) { |
1022 if(js->registration) { |
| 1260 js); |
1251 js); |
| 1261 } |
1252 } |
| 1262 } |
1253 } |
| 1263 } |
1254 } |
| 1264 |
1255 |
| 1265 static void jabber_unregister_account_iq_cb(JabberStream *js, xmlnode *packet, gpointer data) { |
1256 static void |
| |
1257 jabber_unregister_account_iq_cb(JabberStream *js, const char *from, |
| |
1258 JabberIqType type, const char *id, |
| |
1259 xmlnode *packet, gpointer data) |
| |
1260 { |
| 1266 PurpleAccount *account = purple_connection_get_account(js->gc); |
1261 PurpleAccount *account = purple_connection_get_account(js->gc); |
| 1267 const char *type = xmlnode_get_attrib(packet,"type"); |
1262 |
| 1268 if(!strcmp(type,"error")) { |
1263 if (type == JABBER_IQ_ERROR) { |
| 1269 char *msg = jabber_parse_error(js, packet, NULL); |
1264 char *msg = jabber_parse_error(js, packet, NULL); |
| 1270 |
1265 |
| 1271 purple_notify_error(js->gc, _("Error unregistering account"), |
1266 purple_notify_error(js->gc, _("Error unregistering account"), |
| 1272 _("Error unregistering account"), msg); |
1267 _("Error unregistering account"), msg); |
| 1273 g_free(msg); |
1268 g_free(msg); |
| 1274 if(js->unregistration_cb) |
1269 if(js->unregistration_cb) |
| 1275 js->unregistration_cb(account, FALSE, js->unregistration_user_data); |
1270 js->unregistration_cb(account, FALSE, js->unregistration_user_data); |
| 1276 } else if(!strcmp(type,"result")) { |
1271 } else { |
| 1277 purple_notify_info(js->gc, _("Account successfully unregistered"), |
1272 purple_notify_info(js->gc, _("Account successfully unregistered"), |
| 1278 _("Account successfully unregistered"), NULL); |
1273 _("Account successfully unregistered"), NULL); |
| 1279 if(js->unregistration_cb) |
1274 if(js->unregistration_cb) |
| 1280 js->unregistration_cb(account, TRUE, js->unregistration_user_data); |
1275 js->unregistration_cb(account, TRUE, js->unregistration_user_data); |
| 1281 } |
1276 } |
| 1512 JabberStream *js = gc->proto_data; |
1507 JabberStream *js = gc->proto_data; |
| 1513 |
1508 |
| 1514 js->idle = idle ? time(NULL) - idle : idle; |
1509 js->idle = idle ? time(NULL) - idle : idle; |
| 1515 } |
1510 } |
| 1516 |
1511 |
| 1517 static void jabber_blocklist_parse(JabberStream *js, xmlnode *packet, gpointer data) |
1512 static void jabber_blocklist_parse(JabberStream *js, const char *from, |
| |
1513 JabberIqType type, const char *id, |
| |
1514 xmlnode *packet, gpointer data) |
| 1518 { |
1515 { |
| 1519 xmlnode *blocklist, *item; |
1516 xmlnode *blocklist, *item; |
| 1520 PurpleAccount *account; |
1517 PurpleAccount *account; |
| 1521 |
1518 |
| 1522 blocklist = xmlnode_get_child_with_namespace(packet, |
1519 blocklist = xmlnode_get_child_with_namespace(packet, |
| 1936 |
1933 |
| 1937 return types; |
1934 return types; |
| 1938 } |
1935 } |
| 1939 |
1936 |
| 1940 static void |
1937 static void |
| 1941 jabber_password_change_result_cb(JabberStream *js, xmlnode *packet, |
1938 jabber_password_change_result_cb(JabberStream *js, const char *from, |
| 1942 gpointer data) |
1939 JabberIqType type, const char *id, |
| 1943 { |
1940 xmlnode *packet, gpointer data) |
| 1944 const char *type; |
1941 { |
| 1945 |
1942 if (type == JABBER_IQ_RESULT) { |
| 1946 type = xmlnode_get_attrib(packet, "type"); |
|
| 1947 |
|
| 1948 if(type && !strcmp(type, "result")) { |
|
| 1949 purple_notify_info(js->gc, _("Password Changed"), _("Password Changed"), |
1943 purple_notify_info(js->gc, _("Password Changed"), _("Password Changed"), |
| 1950 _("Your password has been changed.")); |
1944 _("Your password has been changed.")); |
| 1951 |
1945 |
| 1952 purple_account_set_password(js->gc->account, (char *)data); |
1946 purple_account_set_password(js->gc->account, (char *)data); |
| 1953 } else { |
1947 } else { |
| 2475 } |
2469 } |
| 2476 |
2470 |
| 2477 static PurpleCmdRet jabber_cmd_ping(PurpleConversation *conv, |
2471 static PurpleCmdRet jabber_cmd_ping(PurpleConversation *conv, |
| 2478 const char *cmd, char **args, char **error, void *data) |
2472 const char *cmd, char **args, char **error, void *data) |
| 2479 { |
2473 { |
| |
2474 PurpleAccount *account; |
| |
2475 PurpleConnection *pc; |
| |
2476 |
| 2480 if(!args || !args[0]) |
2477 if(!args || !args[0]) |
| 2481 return PURPLE_CMD_RET_FAILED; |
2478 return PURPLE_CMD_RET_FAILED; |
| 2482 |
2479 |
| 2483 if(!jabber_ping_jid(conv, args[0])) { |
2480 account = purple_conversation_get_account(conv); |
| |
2481 pc = purple_account_get_connection(account); |
| |
2482 |
| |
2483 if(!jabber_ping_jid(purple_connection_get_protocol_data(pc), args[0])) { |
| 2484 *error = g_strdup_printf(_("Unable to ping user %s"), args[0]); |
2484 *error = g_strdup_printf(_("Unable to ping user %s"), args[0]); |
| 2485 return PURPLE_CMD_RET_FAILED; |
2485 return PURPLE_CMD_RET_FAILED; |
| 2486 } |
2486 } |
| 2487 |
2487 |
| 2488 return PURPLE_CMD_RET_OK; |
2488 return PURPLE_CMD_RET_OK; |