libpurple/protocols/jabber/jabber.c

branch
cpw.resiak.disconnectreason
changeset 21150
bedd1215fb5e
parent 20882
04bbf1786e15
child 21151
2eadc7d7c8ab
equal deleted inserted replaced
21149:160a0845b527 21150:bedd1215fb5e
127 if((my_jb = jabber_buddy_find(js, full_jid, TRUE))) 127 if((my_jb = jabber_buddy_find(js, full_jid, TRUE)))
128 my_jb->subscription |= JABBER_SUB_BOTH; 128 my_jb->subscription |= JABBER_SUB_BOTH;
129 g_free(full_jid); 129 g_free(full_jid);
130 } 130 }
131 } else { 131 } else {
132 char *msg = jabber_parse_error(js, packet); 132 PurpleDisconnectReason reason = PURPLE_REASON_NETWORK_ERROR;
133 purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR, msg); 133 char *msg = jabber_parse_error(js, packet, &reason);
134 purple_connection_error_reason (js->gc, reason, msg);
134 g_free(msg); 135 g_free(msg);
135 } 136 }
136 137
137 jabber_session_init(js); 138 jabber_session_init(js);
138 } 139 }
174 } 175 }
175 } 176 }
176 177
177 static void jabber_stream_handle_error(JabberStream *js, xmlnode *packet) 178 static void jabber_stream_handle_error(JabberStream *js, xmlnode *packet)
178 { 179 {
179 char *msg = jabber_parse_error(js, packet); 180 PurpleDisconnectReason reason = PURPLE_REASON_NETWORK_ERROR;
180 181 char *msg = jabber_parse_error(js, packet, &reason);
181 if (js->gc->wants_to_die) 182
182 purple_connection_error_reason (js->gc, PURPLE_REASON_OTHER_ERROR, msg); 183 purple_connection_error_reason (js->gc, reason, msg);
183 else 184
184 purple_connection_error_reason (js->gc, PURPLE_REASON_NETWORK_ERROR, msg);
185 g_free(msg); 185 g_free(msg);
186 } 186 }
187 187
188 static void tls_init(JabberStream *js); 188 static void tls_init(JabberStream *js);
189 189
685 to); 685 to);
686 purple_notify_info(NULL, _("Registration Successful"), 686 purple_notify_info(NULL, _("Registration Successful"),
687 _("Registration Successful"), buf); 687 _("Registration Successful"), buf);
688 g_free(buf); 688 g_free(buf);
689 } else { 689 } else {
690 char *msg = jabber_parse_error(js, packet); 690 char *msg = jabber_parse_error(js, packet, NULL);
691 691
692 if(!msg) 692 if(!msg)
693 msg = g_strdup(_("Unknown Error")); 693 msg = g_strdup(_("Unknown Error"));
694 694
695 purple_notify_error(NULL, _("Registration Failed"), 695 purple_notify_error(NULL, _("Registration Failed"),
715 to); 715 to);
716 purple_notify_info(NULL, _("Unregistration Successful"), 716 purple_notify_info(NULL, _("Unregistration Successful"),
717 _("Unregistration Successful"), buf); 717 _("Unregistration Successful"), buf);
718 g_free(buf); 718 g_free(buf);
719 } else { 719 } else {
720 char *msg = jabber_parse_error(js, packet); 720 char *msg = jabber_parse_error(js, packet, NULL);
721 721
722 if(!msg) 722 if(!msg)
723 msg = g_strdup(_("Unknown Error")); 723 msg = g_strdup(_("Unknown Error"));
724 724
725 purple_notify_error(NULL, _("Unregistration Failed"), 725 purple_notify_error(NULL, _("Unregistration Failed"),
1139 1139
1140 static void jabber_unregister_account_iq_cb(JabberStream *js, xmlnode *packet, gpointer data) { 1140 static void jabber_unregister_account_iq_cb(JabberStream *js, xmlnode *packet, gpointer data) {
1141 PurpleAccount *account = purple_connection_get_account(js->gc); 1141 PurpleAccount *account = purple_connection_get_account(js->gc);
1142 const char *type = xmlnode_get_attrib(packet,"type"); 1142 const char *type = xmlnode_get_attrib(packet,"type");
1143 if(!strcmp(type,"error")) { 1143 if(!strcmp(type,"error")) {
1144 char *msg = jabber_parse_error(js, packet); 1144 char *msg = jabber_parse_error(js, packet, NULL);
1145 1145
1146 purple_notify_error(js->gc, _("Error unregistering account"), 1146 purple_notify_error(js->gc, _("Error unregistering account"),
1147 _("Error unregistering account"), msg); 1147 _("Error unregistering account"), msg);
1148 g_free(msg); 1148 g_free(msg);
1149 if(js->unregistration_cb) 1149 if(js->unregistration_cb)
1689 1689
1690 if(type && !strcmp(type, "result")) { 1690 if(type && !strcmp(type, "result")) {
1691 purple_notify_info(js->gc, _("Password Changed"), _("Password Changed"), 1691 purple_notify_info(js->gc, _("Password Changed"), _("Password Changed"),
1692 _("Your password has been changed.")); 1692 _("Your password has been changed."));
1693 } else { 1693 } else {
1694 char *msg = jabber_parse_error(js, packet); 1694 char *msg = jabber_parse_error(js, packet, NULL);
1695 1695
1696 purple_notify_error(js->gc, _("Error changing password"), 1696 purple_notify_error(js->gc, _("Error changing password"),
1697 _("Error changing password"), msg); 1697 _("Error changing password"), msg);
1698 g_free(msg); 1698 g_free(msg);
1699 } 1699 }
1853 1853
1854 jabber_id_free(jid); 1854 jabber_id_free(jid);
1855 } 1855 }
1856 1856
1857 1857
1858 char *jabber_parse_error(JabberStream *js, xmlnode *packet) 1858 char *jabber_parse_error(JabberStream *js,
1859 xmlnode *packet,
1860 PurpleDisconnectReason *reason)
1859 { 1861 {
1860 xmlnode *error; 1862 xmlnode *error;
1861 const char *code = NULL, *text = NULL; 1863 const char *code = NULL, *text = NULL;
1862 const char *xmlns = xmlnode_get_namespace(packet); 1864 const char *xmlns = xmlnode_get_namespace(packet);
1863 char *cdata = NULL; 1865 char *cdata = NULL;
1866
1867 #define SET_REASON(x) \
1868 if(reason != NULL) { *reason = x; }
1864 1869
1865 if((error = xmlnode_get_child(packet, "error"))) { 1870 if((error = xmlnode_get_child(packet, "error"))) {
1866 cdata = xmlnode_get_data(error); 1871 cdata = xmlnode_get_data(error);
1867 code = xmlnode_get_attrib(error, "code"); 1872 code = xmlnode_get_attrib(error, "code");
1868 1873
1911 text = _("Unexpected Request"); 1916 text = _("Unexpected Request");
1912 } else if(xmlnode_get_child(error, "undefined-condition")) { 1917 } else if(xmlnode_get_child(error, "undefined-condition")) {
1913 text = _("Unknown Error"); 1918 text = _("Unknown Error");
1914 } 1919 }
1915 } else if(xmlns && !strcmp(xmlns, "urn:ietf:params:xml:ns:xmpp-sasl")) { 1920 } else if(xmlns && !strcmp(xmlns, "urn:ietf:params:xml:ns:xmpp-sasl")) {
1921 /* Most common reason can be the default */
1922 SET_REASON(PURPLE_REASON_AUTHENTICATION_FAILED);
1916 if(xmlnode_get_child(packet, "aborted")) { 1923 if(xmlnode_get_child(packet, "aborted")) {
1917 js->gc->wants_to_die = TRUE;
1918 text = _("Authorization Aborted"); 1924 text = _("Authorization Aborted");
1919 } else if(xmlnode_get_child(packet, "incorrect-encoding")) { 1925 } else if(xmlnode_get_child(packet, "incorrect-encoding")) {
1926 SET_REASON(PURPLE_REASON_NETWORK_ERROR);
1920 text = _("Incorrect encoding in authorization"); 1927 text = _("Incorrect encoding in authorization");
1921 } else if(xmlnode_get_child(packet, "invalid-authzid")) { 1928 } else if(xmlnode_get_child(packet, "invalid-authzid")) {
1922 js->gc->wants_to_die = TRUE;
1923 text = _("Invalid authzid"); 1929 text = _("Invalid authzid");
1924 } else if(xmlnode_get_child(packet, "invalid-mechanism")) { 1930 } else if(xmlnode_get_child(packet, "invalid-mechanism")) {
1925 js->gc->wants_to_die = TRUE;
1926 text = _("Invalid Authorization Mechanism"); 1931 text = _("Invalid Authorization Mechanism");
1927 } else if(xmlnode_get_child(packet, "mechanism-too-weak")) { 1932 } else if(xmlnode_get_child(packet, "mechanism-too-weak")) {
1928 js->gc->wants_to_die = TRUE;
1929 text = _("Authorization mechanism too weak"); 1933 text = _("Authorization mechanism too weak");
1930 } else if(xmlnode_get_child(packet, "not-authorized")) { 1934 } else if(xmlnode_get_child(packet, "not-authorized")) {
1931 js->gc->wants_to_die = TRUE;
1932 /* Clear the pasword if it isn't being saved */ 1935 /* Clear the pasword if it isn't being saved */
1933 if (!purple_account_get_remember_password(js->gc->account)) 1936 if (!purple_account_get_remember_password(js->gc->account))
1934 purple_account_set_password(js->gc->account, NULL); 1937 purple_account_set_password(js->gc->account, NULL);
1935 text = _("Not Authorized"); 1938 text = _("Not Authorized");
1936 } else if(xmlnode_get_child(packet, "temporary-auth-failure")) { 1939 } else if(xmlnode_get_child(packet, "temporary-auth-failure")) {
1940 SET_REASON(PURPLE_REASON_NETWORK_ERROR);
1937 text = _("Temporary Authentication Failure"); 1941 text = _("Temporary Authentication Failure");
1938 } else { 1942 } else {
1939 js->gc->wants_to_die = TRUE;
1940 text = _("Authentication Failure"); 1943 text = _("Authentication Failure");
1941 } 1944 }
1942 } else if(!strcmp(packet->name, "stream:error") || 1945 } else if(!strcmp(packet->name, "stream:error") ||
1943 (!strcmp(packet->name, "error") && 1946 (!strcmp(packet->name, "error") &&
1944 !strcmp(xmlns, "http://etherx.jabber.org/streams"))) { 1947 !strcmp(xmlns, "http://etherx.jabber.org/streams"))) {
1948 /* Most common reason as default: */
1949 SET_REASON(PURPLE_REASON_NETWORK_ERROR);
1945 if(xmlnode_get_child(packet, "bad-format")) { 1950 if(xmlnode_get_child(packet, "bad-format")) {
1946 text = _("Bad Format"); 1951 text = _("Bad Format");
1947 } else if(xmlnode_get_child(packet, "bad-namespace-prefix")) { 1952 } else if(xmlnode_get_child(packet, "bad-namespace-prefix")) {
1948 text = _("Bad Namespace Prefix"); 1953 text = _("Bad Namespace Prefix");
1949 } else if(xmlnode_get_child(packet, "conflict")) { 1954 } else if(xmlnode_get_child(packet, "conflict")) {
1950 js->gc->wants_to_die = TRUE; 1955 SET_REASON(PURPLE_REASON_NAME_IN_USE);
1951 text = _("Resource Conflict"); 1956 text = _("Resource Conflict");
1952 } else if(xmlnode_get_child(packet, "connection-timeout")) { 1957 } else if(xmlnode_get_child(packet, "connection-timeout")) {
1953 text = _("Connection Timeout"); 1958 text = _("Connection Timeout");
1954 } else if(xmlnode_get_child(packet, "host-gone")) { 1959 } else if(xmlnode_get_child(packet, "host-gone")) {
1955 text = _("Host Gone"); 1960 text = _("Host Gone");
1993 text = _("XML Not Well Formed"); 1998 text = _("XML Not Well Formed");
1994 } else { 1999 } else {
1995 text = _("Stream Error"); 2000 text = _("Stream Error");
1996 } 2001 }
1997 } 2002 }
2003
2004 #undef SET_REASON
1998 2005
1999 if(text || cdata) { 2006 if(text || cdata) {
2000 char *ret = g_strdup_printf("%s%s%s", code ? code : "", 2007 char *ret = g_strdup_printf("%s%s%s", code ? code : "",
2001 code ? ": " : "", text ? text : cdata); 2008 code ? ": " : "", text ? text : cdata);
2002 g_free(cdata); 2009 g_free(cdata);

mercurial