comparison src/protocols/jabber/jabber.c @ 8401:c13a4913a071

[gaim-migrate @ 9130] better error processing for jabber committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Fri, 05 Mar 2004 23:42:34 +0000
parents 0383e55cd658
children fcfb1c08d402
comparison
equal deleted inserted replaced
8400:0383e55cd658 8401:c13a4913a071
88 } 88 }
89 89
90 static void jabber_bind_result_cb(JabberStream *js, xmlnode *packet, 90 static void jabber_bind_result_cb(JabberStream *js, xmlnode *packet,
91 gpointer data) 91 gpointer data)
92 { 92 {
93 /* XXX: check for errors, re-set our own js->user JID */ 93 const char *type = xmlnode_get_attrib(packet, "type");
94 xmlnode *bind;
95
96 if(type && !strcmp(type, "result") &&
97 (bind = xmlnode_get_child_with_namespace(packet, "bind", "urn:ietf:params:xml:ns:xmpp-bind"))) {
98 xmlnode *jid;
99 char *full_jid;
100 if((jid = xmlnode_get_child(bind, "jid")) && (full_jid = xmlnode_get_data(jid))) {
101 jabber_id_free(js->user);
102 if(!(js->user = jabber_id_new(full_jid))) {
103 gaim_connection_error(js->gc, _("Invalid response from server."));
104 }
105 }
106 } else {
107 char *msg = jabber_parse_error(js, packet);
108 gaim_connection_error(js->gc, msg);
109 g_free(msg);
110 }
94 111
95 jabber_session_init(js); 112 jabber_session_init(js);
96 } 113 }
97 114
98 static void jabber_stream_features_parse(JabberStream *js, xmlnode *packet) 115 static void jabber_stream_features_parse(JabberStream *js, xmlnode *packet)
125 } 142 }
126 } 143 }
127 144
128 static void jabber_stream_handle_error(JabberStream *js, xmlnode *packet) 145 static void jabber_stream_handle_error(JabberStream *js, xmlnode *packet)
129 { 146 {
130 xmlnode *textnode; 147 char *msg = jabber_parse_error(js, packet);
131 char *error_text = NULL; 148
132 const char *text; 149 gaim_connection_error(js->gc, msg);
133 char *buf; 150 g_free(msg);
134
135 if(xmlnode_get_child(packet, "bad-format")) {
136 text = _("Bad Format");
137 } else if(xmlnode_get_child(packet, "bad-namespace-prefix")) {
138 text = _("Bad Namespace Prefix");
139 } else if(xmlnode_get_child(packet, "conflict")) {
140 js->gc->wants_to_die = TRUE;
141 text = _("Resource Conflict");
142 } else if(xmlnode_get_child(packet, "connection-timeout")) {
143 text = _("Connection Timeout");
144 } else if(xmlnode_get_child(packet, "host-gone")) {
145 text = _("Host Gone");
146 } else if(xmlnode_get_child(packet, "host-unknown")) {
147 text = _("Host Unknown");
148 } else if(xmlnode_get_child(packet, "improper-addressing")) {
149 text = _("Improper Addressing");
150 } else if(xmlnode_get_child(packet, "internal-server-error")) {
151 text = _("Internal Server Error");
152 } else if(xmlnode_get_child(packet, "invalid-id")) {
153 text = _("Invalid ID");
154 } else if(xmlnode_get_child(packet, "invalid-namespace")) {
155 text = _("Invalid Namespace");
156 } else if(xmlnode_get_child(packet, "invalid-xml")) {
157 text = _("Invalid XML");
158 } else if(xmlnode_get_child(packet, "nonmatching-hosts")) {
159 text = _("Non-matching Hosts");
160 } else if(xmlnode_get_child(packet, "not-authorized")) {
161 text = _("Not Authorized");
162 } else if(xmlnode_get_child(packet, "policy-violation")) {
163 text = _("Policy Violation");
164 } else if(xmlnode_get_child(packet, "remote-connection-failed")) {
165 text = _("Remote Connection Failed");
166 } else if(xmlnode_get_child(packet, "resource-constraint")) {
167 text = _("Resource Constraint");
168 } else if(xmlnode_get_child(packet, "restricted-xml")) {
169 text = _("Restricted XML");
170 } else if(xmlnode_get_child(packet, "see-other-host")) {
171 text = _("See Other Host");
172 } else if(xmlnode_get_child(packet, "system-shutdown")) {
173 text = _("System Shutdown");
174 } else if(xmlnode_get_child(packet, "undefined-condition")) {
175 text = _("Undefined Condition");
176 } else if(xmlnode_get_child(packet, "unsupported-encoding")) {
177 text = _("Unsupported Encoding");
178 } else if(xmlnode_get_child(packet, "unsupported-stanza-type")) {
179 text = _("Unsupported Stanza Type");
180 } else if(xmlnode_get_child(packet, "unsupported-version")) {
181 text = _("Unsupported Version");
182 } else if(xmlnode_get_child(packet, "xml-not-well-formed")) {
183 text = _("XML Not Well Formed");
184 } else {
185 text = _("Stream Error");
186 }
187
188 if((textnode = xmlnode_get_child(packet, "text")))
189 error_text = xmlnode_get_data(textnode);
190
191 buf = g_strdup_printf("%s%s%s", text,
192 error_text ? ": " : "",
193 error_text ? error_text : "");
194 gaim_connection_error(js->gc, buf);
195 g_free(buf);
196 if(error_text)
197 g_free(error_text);
198 } 151 }
199 152
200 static void tls_init(JabberStream *js); 153 static void tls_init(JabberStream *js);
201 154
202 void jabber_process_packet(JabberStream *js, xmlnode *packet) 155 void jabber_process_packet(JabberStream *js, xmlnode *packet)
233 { 186 {
234 int ret; 187 int ret;
235 188
236 /* because printing a tab to debug every minute gets old */ 189 /* because printing a tab to debug every minute gets old */
237 if(strcmp(data, "\t")) 190 if(strcmp(data, "\t"))
238 gaim_debug(GAIM_DEBUG_MISC, "jabber", "Sending%s: %s\n", 191 gaim_debug(GAIM_DEBUG_MISC, "jabber", "Sending%s: %s\n",
239 js->gsc ? " (ssl)" : "", data); 192 js->gsc ? " (ssl)" : "", data);
240 193
241 if(js->gsc) { 194 if(js->gsc) {
242 ret = gaim_ssl_write(js->gsc, data, len == -1 ? strlen(data) : len); 195 ret = gaim_ssl_write(js->gsc, data, len == -1 ? strlen(data) : len);
243 } else { 196 } else {
473 js->user->node, js->user->domain); 426 js->user->node, js->user->domain);
474 gaim_notify_info(NULL, _("Registration Successful"), 427 gaim_notify_info(NULL, _("Registration Successful"),
475 _("Registration Successful"), buf); 428 _("Registration Successful"), buf);
476 g_free(buf); 429 g_free(buf);
477 } else { 430 } else {
478 char *error; 431 char *msg = jabber_parse_error(js, packet);
479 xmlnode *y; 432
480 433 if(!msg)
481 if((y = xmlnode_get_child(packet, "error"))) { 434 msg = g_strdup(_("Unknown Error"));
482 error = xmlnode_get_data(y); 435
483 } else {
484 error = g_strdup(_("Unknown Error"));
485 }
486
487 buf = g_strdup_printf(_("Registration of %s@%s failed: %s"),
488 js->user->node, js->user->domain, error);
489 gaim_notify_error(NULL, _("Registration Failed"), 436 gaim_notify_error(NULL, _("Registration Failed"),
490 _("Registration Failed"), buf); 437 _("Registration Failed"), msg);
491 g_free(buf); 438 g_free(msg);
492 g_free(error);
493 } 439 }
494 jabber_connection_schedule_close(js); 440 jabber_connection_schedule_close(js);
495 } 441 }
496 442
497 static void 443 static void
1031 977
1032 if(!strcmp(type, "result")) { 978 if(!strcmp(type, "result")) {
1033 gaim_notify_info(js->gc, _("Password Changed"), _("Password Changed"), 979 gaim_notify_info(js->gc, _("Password Changed"), _("Password Changed"),
1034 _("Your password has been changed.")); 980 _("Your password has been changed."));
1035 } else { 981 } else {
1036 xmlnode *error; 982 char *msg = jabber_parse_error(js, packet);
1037 char *buf, *error_txt = NULL; 983
1038 984 gaim_notify_error(js->gc, _("Error changing password"),
1039 985 _("Error changing password"), msg);
1040 if((error = xmlnode_get_child(packet, "error"))) 986 g_free(msg);
1041 error_txt = xmlnode_get_data(error);
1042
1043 if(error_txt) {
1044 buf = g_strdup_printf(_("Error changing password: %s"),
1045 error_txt);
1046 g_free(error_txt);
1047 } else {
1048 buf = g_strdup(_("Unknown error occurred changing password"));
1049 }
1050
1051 gaim_notify_error(js->gc, _("Error"), _("Error"), buf);
1052 g_free(buf);
1053 } 987 }
1054 } 988 }
1055 989
1056 static void jabber_password_change_cb(JabberStream *js, 990 static void jabber_password_change_cb(JabberStream *js,
1057 GaimRequestFields *fields) 991 GaimRequestFields *fields)
1186 jbr->thread_id = NULL; 1120 jbr->thread_id = NULL;
1187 } 1121 }
1188 } 1122 }
1189 1123
1190 jabber_id_free(jid); 1124 jabber_id_free(jid);
1125 }
1126
1127
1128 char *jabber_parse_error(JabberStream *js, xmlnode *packet)
1129 {
1130 xmlnode *error;
1131 const char *code = NULL, *text = NULL;
1132 const char *xmlns = xmlnode_get_attrib(packet, "xmlns");
1133 char *cdata = NULL;
1134
1135 if((error = xmlnode_get_child(packet, "error"))) {
1136 cdata = xmlnode_get_data(error);
1137 code = xmlnode_get_attrib(error, "code");
1138
1139 /* Stanza errors */
1140 if(xmlnode_get_child(error, "bad-request")) {
1141 text = _("Bad Request");
1142 } else if(xmlnode_get_child(error, "conflict")) {
1143 text = _("Conflict");
1144 } else if(xmlnode_get_child(error, "feature-not-implemented")) {
1145 text = _("Feature Not Implemented");
1146 } else if(xmlnode_get_child(error, "forbidden")) {
1147 text = _("Forbidden");
1148 } else if(xmlnode_get_child(error, "gone")) {
1149 text = _("Gone");
1150 } else if(xmlnode_get_child(error, "internal-server-error")) {
1151 text = _("Internal Server Error");
1152 } else if(xmlnode_get_child(error, "item-not-found")) {
1153 text = _("Item Not Found");
1154 } else if(xmlnode_get_child(error, "jid-malformed")) {
1155 text = _("Malformed Jabber ID");
1156 } else if(xmlnode_get_child(error, "not-acceptable")) {
1157 text = _("Not Acceptable");
1158 } else if(xmlnode_get_child(error, "not-allowed")) {
1159 text = _("Not Allowed");
1160 } else if(xmlnode_get_child(error, "not-authorized")) {
1161 text = _("Not Authorized");
1162 } else if(xmlnode_get_child(error, "payment-required")) {
1163 text = _("Payment Required");
1164 } else if(xmlnode_get_child(error, "recipient-unavailable")) {
1165 text = _("Recipient Unavailable");
1166 } else if(xmlnode_get_child(error, "redirect")) {
1167 /* XXX */
1168 } else if(xmlnode_get_child(error, "registration-required")) {
1169 text = _("Registration Required");
1170 } else if(xmlnode_get_child(error, "remote-server-not-found")) {
1171 text = _("Remote Server Not Found");
1172 } else if(xmlnode_get_child(error, "remote-server-timeout")) {
1173 text = _("Remote Server Timeout");
1174 } else if(xmlnode_get_child(error, "resource-constraint")) {
1175 text = _("Server Overloaded");
1176 } else if(xmlnode_get_child(error, "service-unavailable")) {
1177 text = _("Service Unavailable");
1178 } else if(xmlnode_get_child(error, "subscription-required")) {
1179 text = _("Subscription Required");
1180 } else if(xmlnode_get_child(error, "unexpected-request")) {
1181 text = _("Unexpected Request");
1182 } else if(xmlnode_get_child(error, "undefined-condition")) {
1183 text = _("Unknown Error");
1184 }
1185 } else if(xmlns && !strcmp(xmlns, "urn:ietf:params:xml:ns:xmpp-sasl")) {
1186 if(xmlnode_get_child(packet, "aborted")) {
1187 js->gc->wants_to_die = TRUE;
1188 text = _("Authorization Aborted");
1189 } else if(xmlnode_get_child(error, "incorrect-encoding")) {
1190 text = _("Incorrect encoding in authorization");
1191 } else if(xmlnode_get_child(error, "invalid-authzid")) {
1192 js->gc->wants_to_die = TRUE;
1193 text = _("Invalid authzid");
1194 } else if(xmlnode_get_child(error, "invalid-mechanism")) {
1195 js->gc->wants_to_die = TRUE;
1196 text = _("Invalid Authorization Mechanism");
1197 } else if(xmlnode_get_child(error, "mechanism-too-weak")) {
1198 js->gc->wants_to_die = TRUE;
1199 text = _("Authorization mechanism too weak");
1200 } else if(xmlnode_get_child(error, "not-authorized")) {
1201 js->gc->wants_to_die = TRUE;
1202 text = _("Not Authorized");
1203 } else if(xmlnode_get_child(error, "temporary-auth-failure")) {
1204 text = _("Temporary Authentication Failure");
1205 } else {
1206 text = _("Authentication Failure");
1207 }
1208 }
1209
1210 if(text || cdata) {
1211 char *ret = g_strdup_printf("%s%s%s", code ? code : "",
1212 code ? ": " : "", text ? text : cdata);
1213 g_free(cdata);
1214 return ret;
1215 } else {
1216 return NULL;
1217 }
1191 } 1218 }
1192 1219
1193 static GaimPluginProtocolInfo prpl_info = 1220 static GaimPluginProtocolInfo prpl_info =
1194 { 1221 {
1195 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME, 1222 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME,
1326 ppref->label = _("Privacy"); 1353 ppref->label = _("Privacy");
1327 prpl_info.protocol_prefs = g_list_append(prpl_info.protocol_prefs, ppref); 1354 prpl_info.protocol_prefs = g_list_append(prpl_info.protocol_prefs, ppref);
1328 1355
1329 ppref = g_new0(struct proto_pref, 1); 1356 ppref = g_new0(struct proto_pref, 1);
1330 ppref->key = "/plugins/prpl/jabber/hide_os"; 1357 ppref->key = "/plugins/prpl/jabber/hide_os";
1331 ppref->label = _("Hide Operating System"); /* XXX: come up with a better name for this */ 1358 ppref->label = _("Hide Operating System");
1332 prpl_info.protocol_prefs = g_list_append(prpl_info.protocol_prefs, ppref); 1359 prpl_info.protocol_prefs = g_list_append(prpl_info.protocol_prefs, ppref);
1333 } 1360 }
1334 1361
1335 GAIM_INIT_PLUGIN(jabber, init_plugin, info); 1362 GAIM_INIT_PLUGIN(jabber, init_plugin, info);