comparison libpurple/protocols/jabber/jabber.c @ 26547:ae41d8e827e3

Convert all the XMPP IQ callbacks to a typedef similar to the IQ Handlers.
author Paul Aurich <paul@darkrain42.org>
date Fri, 13 Mar 2009 02:26:45 +0000
parents a4a5825fb1bb
children 4f14455a86d2
comparison
equal deleted inserted replaced
26546:a4a5825fb1bb 26547:ae41d8e827e3
83 js->reinit = FALSE; 83 js->reinit = FALSE;
84 g_free(open_stream); 84 g_free(open_stream);
85 } 85 }
86 86
87 static void 87 static void
88 jabber_session_initialized_cb(JabberStream *js, xmlnode *packet, gpointer data) 88 jabber_session_initialized_cb(JabberStream *js, const char *from,
89 { 89 JabberIqType type, const char *id,
90 const char *type = xmlnode_get_attrib(packet, "type"); 90 xmlnode *packet, gpointer data)
91 if(type && !strcmp(type, "result")) { 91 {
92 if (type == JABBER_IQ_RESULT) {
92 jabber_stream_set_state(js, JABBER_STREAM_CONNECTED); 93 jabber_stream_set_state(js, JABBER_STREAM_CONNECTED);
93 if(js->unregistration) 94 if(js->unregistration)
94 jabber_unregister_account_cb(js); 95 jabber_unregister_account_cb(js);
95 } else { 96 } else {
96 purple_connection_error_reason (js->gc, 97 purple_connection_error_reason (js->gc,
110 xmlnode_set_namespace(session, "urn:ietf:params:xml:ns:xmpp-session"); 111 xmlnode_set_namespace(session, "urn:ietf:params:xml:ns:xmpp-session");
111 112
112 jabber_iq_send(iq); 113 jabber_iq_send(iq);
113 } 114 }
114 115
115 static void jabber_bind_result_cb(JabberStream *js, xmlnode *packet, 116 static void jabber_bind_result_cb(JabberStream *js, const char *from,
116 gpointer data) 117 JabberIqType type, const char *id,
117 { 118 xmlnode *packet, gpointer data)
118 const char *type = xmlnode_get_attrib(packet, "type"); 119 {
119 xmlnode *bind; 120 xmlnode *bind;
120 121
121 if(type && !strcmp(type, "result") && 122 if (type == JABBER_IQ_RESULT &&
122 (bind = xmlnode_get_child_with_namespace(packet, "bind", "urn:ietf:params:xml:ns:xmpp-bind"))) { 123 (bind = xmlnode_get_child_with_namespace(packet, "bind", "urn:ietf:params:xml:ns:xmpp-bind"))) {
123 xmlnode *jid; 124 xmlnode *jid;
124 char *full_jid; 125 char *full_jid;
125 if((jid = xmlnode_get_child(bind, "jid")) && (full_jid = xmlnode_get_data(jid))) { 126 if((jid = xmlnode_get_child(bind, "jid")) && (full_jid = xmlnode_get_data(jid))) {
126 JabberBuddy *my_jb = NULL; 127 JabberBuddy *my_jb = NULL;
783 { 784 {
784 purple_timeout_add(0, conn_close_cb, js); 785 purple_timeout_add(0, conn_close_cb, js);
785 } 786 }
786 787
787 static void 788 static void
788 jabber_registration_result_cb(JabberStream *js, xmlnode *packet, gpointer data) 789 jabber_registration_result_cb(JabberStream *js, const char *from,
790 JabberIqType type, const char *id,
791 xmlnode *packet, gpointer data)
789 { 792 {
790 PurpleAccount *account = purple_connection_get_account(js->gc); 793 PurpleAccount *account = purple_connection_get_account(js->gc);
791 const char *type = xmlnode_get_attrib(packet, "type");
792 char *buf; 794 char *buf;
793 char *to = data; 795 char *to = data;
794 796
795 if(!strcmp(type, "result")) { 797 if (type == JABBER_IQ_RESULT) {
796 if(js->registration) { 798 if(js->registration) {
797 buf = g_strdup_printf(_("Registration of %s@%s successful"), 799 buf = g_strdup_printf(_("Registration of %s@%s successful"),
798 js->user->node, js->user->domain); 800 js->user->node, js->user->domain);
799 if(account->registration_cb) 801 if(account->registration_cb)
800 (account->registration_cb)(account, TRUE, account->registration_cb_user_data); 802 (account->registration_cb)(account, TRUE, account->registration_cb_user_data);
818 if(account->registration_cb) 820 if(account->registration_cb)
819 (account->registration_cb)(account, FALSE, account->registration_cb_user_data); 821 (account->registration_cb)(account, FALSE, account->registration_cb_user_data);
820 } 822 }
821 g_free(to); 823 g_free(to);
822 if(js->registration) 824 if(js->registration)
823 jabber_connection_schedule_close(js); 825 jabber_connection_schedule_close(js);
824 } 826 }
825 827
826 static void 828 static void
827 jabber_unregistration_result_cb(JabberStream *js, xmlnode *packet, gpointer data) 829 jabber_unregistration_result_cb(JabberStream *js, const char *from,
828 { 830 JabberIqType type, const char *id,
829 const char *type = xmlnode_get_attrib(packet, "type"); 831 xmlnode *packet, gpointer data)
832 {
830 char *buf; 833 char *buf;
831 char *to = data; 834 char *to = data;
832 835
833 /* This function is never called for unregistering our XMPP account from 836 /* This function is never called for unregistering our XMPP account from
834 * the server, so there should always be a 'to' address. */ 837 * the server, so there should always be a 'to' address. */
835 g_return_if_fail(to != NULL); 838 g_return_if_fail(to != NULL);
836 839
837 if(!strcmp(type, "result")) { 840 if (type == JABBER_IQ_RESULT) {
838 buf = g_strdup_printf(_("Registration from %s successfully removed"), 841 buf = g_strdup_printf(_("Registration from %s successfully removed"),
839 to); 842 to);
840 purple_notify_info(NULL, _("Unregistration Successful"), 843 purple_notify_info(NULL, _("Unregistration Successful"),
841 _("Unregistration Successful"), buf); 844 _("Unregistration Successful"), buf);
842 g_free(buf); 845 g_free(buf);
1238 js); 1241 js);
1239 } 1242 }
1240 } 1243 }
1241 } 1244 }
1242 1245
1243 static void jabber_unregister_account_iq_cb(JabberStream *js, xmlnode *packet, gpointer data) { 1246 static void
1247 jabber_unregister_account_iq_cb(JabberStream *js, const char *from,
1248 JabberIqType type, const char *id,
1249 xmlnode *packet, gpointer data)
1250 {
1244 PurpleAccount *account = purple_connection_get_account(js->gc); 1251 PurpleAccount *account = purple_connection_get_account(js->gc);
1245 const char *type = xmlnode_get_attrib(packet,"type"); 1252
1246 if(!strcmp(type,"error")) { 1253 if (type == JABBER_IQ_ERROR) {
1247 char *msg = jabber_parse_error(js, packet, NULL); 1254 char *msg = jabber_parse_error(js, packet, NULL);
1248 1255
1249 purple_notify_error(js->gc, _("Error unregistering account"), 1256 purple_notify_error(js->gc, _("Error unregistering account"),
1250 _("Error unregistering account"), msg); 1257 _("Error unregistering account"), msg);
1251 g_free(msg); 1258 g_free(msg);
1252 if(js->unregistration_cb) 1259 if(js->unregistration_cb)
1253 js->unregistration_cb(account, FALSE, js->unregistration_user_data); 1260 js->unregistration_cb(account, FALSE, js->unregistration_user_data);
1254 } else if(!strcmp(type,"result")) { 1261 } else {
1255 purple_notify_info(js->gc, _("Account successfully unregistered"), 1262 purple_notify_info(js->gc, _("Account successfully unregistered"),
1256 _("Account successfully unregistered"), NULL); 1263 _("Account successfully unregistered"), NULL);
1257 if(js->unregistration_cb) 1264 if(js->unregistration_cb)
1258 js->unregistration_cb(account, TRUE, js->unregistration_user_data); 1265 js->unregistration_cb(account, TRUE, js->unregistration_user_data);
1259 } 1266 }
1478 JabberStream *js = gc->proto_data; 1485 JabberStream *js = gc->proto_data;
1479 1486
1480 js->idle = idle ? time(NULL) - idle : idle; 1487 js->idle = idle ? time(NULL) - idle : idle;
1481 } 1488 }
1482 1489
1483 static void jabber_blocklist_parse(JabberStream *js, xmlnode *packet, gpointer data) 1490 static void jabber_blocklist_parse(JabberStream *js, const char *from,
1491 JabberIqType type, const char *id,
1492 xmlnode *packet, gpointer data)
1484 { 1493 {
1485 xmlnode *blocklist, *item; 1494 xmlnode *blocklist, *item;
1486 PurpleAccount *account; 1495 PurpleAccount *account;
1487 1496
1488 blocklist = xmlnode_get_child_with_namespace(packet, 1497 blocklist = xmlnode_get_child_with_namespace(packet,
1902 1911
1903 return types; 1912 return types;
1904 } 1913 }
1905 1914
1906 static void 1915 static void
1907 jabber_password_change_result_cb(JabberStream *js, xmlnode *packet, 1916 jabber_password_change_result_cb(JabberStream *js, const char *from,
1908 gpointer data) 1917 JabberIqType type, const char *id,
1909 { 1918 xmlnode *packet, gpointer data)
1910 const char *type; 1919 {
1911 1920 if (type == JABBER_IQ_RESULT) {
1912 type = xmlnode_get_attrib(packet, "type");
1913
1914 if(type && !strcmp(type, "result")) {
1915 purple_notify_info(js->gc, _("Password Changed"), _("Password Changed"), 1921 purple_notify_info(js->gc, _("Password Changed"), _("Password Changed"),
1916 _("Your password has been changed.")); 1922 _("Your password has been changed."));
1917 1923
1918 purple_account_set_password(js->gc->account, (char *)data); 1924 purple_account_set_password(js->gc->account, (char *)data);
1919 } else { 1925 } else {