| 176 const char *type = xmlnode_get_attrib(packet, "type"); |
176 const char *type = xmlnode_get_attrib(packet, "type"); |
| 177 |
177 |
| 178 if(type && !strcmp(type, "result")) { |
178 if(type && !strcmp(type, "result")) { |
| 179 jabber_stream_set_state(js, JABBER_STREAM_CONNECTED); |
179 jabber_stream_set_state(js, JABBER_STREAM_CONNECTED); |
| 180 } else { |
180 } else { |
| 181 xmlnode *error = xmlnode_get_child(packet, "error"); |
181 char *msg = jabber_parse_error(js, packet); |
| 182 const char *err_code = NULL; |
182 xmlnode *error; |
| 183 char *err_text = NULL; |
183 const char *err_code; |
| 184 char *buf; |
184 |
| 185 |
185 if((error = xmlnode_get_child(packet, "error")) && |
| 186 if(error) { |
186 (err_code = xmlnode_get_attrib(error, "code")) && |
| 187 err_code = xmlnode_get_attrib(error, "code"); |
187 !strcmp(err_code, "401")) { |
| 188 err_text = xmlnode_get_data(error); |
|
| 189 } |
|
| 190 |
|
| 191 if(!err_code) |
|
| 192 err_code = ""; |
|
| 193 if(!err_text) |
|
| 194 err_text = g_strdup(_("Unknown")); |
|
| 195 |
|
| 196 if(!strcmp(err_code, "401")) |
|
| 197 js->gc->wants_to_die = TRUE; |
188 js->gc->wants_to_die = TRUE; |
| 198 |
189 } |
| 199 buf = g_strdup_printf("Error %s: %s", |
190 |
| 200 err_code, err_text); |
191 gaim_connection_error(js->gc, msg); |
| 201 |
192 g_free(msg); |
| 202 gaim_connection_error(js->gc, buf); |
|
| 203 g_free(err_text); |
|
| 204 g_free(buf); |
|
| 205 } |
193 } |
| 206 } |
194 } |
| 207 |
195 |
| 208 static void auth_old_cb(JabberStream *js, xmlnode *packet, gpointer data) |
196 static void auth_old_cb(JabberStream *js, xmlnode *packet, gpointer data) |
| 209 { |
197 { |
| 214 |
202 |
| 215 if(!type) { |
203 if(!type) { |
| 216 gaim_connection_error(js->gc, _("Invalid response from server.")); |
204 gaim_connection_error(js->gc, _("Invalid response from server.")); |
| 217 return; |
205 return; |
| 218 } else if(!strcmp(type, "error")) { |
206 } else if(!strcmp(type, "error")) { |
| 219 /* XXX: still need to handle XMPP-style errors */ |
207 char *msg = jabber_parse_error(js, packet); |
| 220 xmlnode *error; |
208 gaim_connection_error(js->gc, msg); |
| 221 char *buf, *err_txt = NULL; |
209 g_free(msg); |
| 222 const char *code = NULL; |
|
| 223 if((error = xmlnode_get_child(packet, "error"))) { |
|
| 224 code = xmlnode_get_attrib(error, "code"); |
|
| 225 err_txt = xmlnode_get_data(error); |
|
| 226 } |
|
| 227 buf = g_strdup_printf("%s%s%s", code ? code : "", code ? ": " : "", |
|
| 228 err_txt ? err_txt : _("Unknown Error")); |
|
| 229 gaim_connection_error(js->gc, buf); |
|
| 230 if(err_txt) |
|
| 231 g_free(err_txt); |
|
| 232 g_free(buf); |
|
| 233 } else if(!strcmp(type, "result")) { |
210 } else if(!strcmp(type, "result")) { |
| 234 query = xmlnode_get_child(packet, "query"); |
211 query = xmlnode_get_child(packet, "query"); |
| 235 if(js->stream_id && xmlnode_get_child(query, "digest")) { |
212 if(js->stream_id && xmlnode_get_child(query, "digest")) { |
| 236 unsigned char hashval[20]; |
213 unsigned char hashval[20]; |
| 237 char *s, h[41], *p; |
214 char *s, h[41], *p; |
| 479 jabber_stream_set_state(js, JABBER_STREAM_REINITIALIZING); |
456 jabber_stream_set_state(js, JABBER_STREAM_REINITIALIZING); |
| 480 } |
457 } |
| 481 |
458 |
| 482 void jabber_auth_handle_failure(JabberStream *js, xmlnode *packet) |
459 void jabber_auth_handle_failure(JabberStream *js, xmlnode *packet) |
| 483 { |
460 { |
| 484 const char *ns = xmlnode_get_attrib(packet, "xmlns"); |
461 char *msg = jabber_parse_error(js, packet); |
| 485 |
462 |
| 486 if(!ns) |
463 if(!msg) { |
| 487 gaim_connection_error(js->gc, _("Invalid response from server.")); |
464 gaim_connection_error(js->gc, _("Invalid response from server.")); |
| 488 else if(!strcmp(ns, "urn:ietf:params:xml:ns:xmpp-sasl")) { |
465 } else { |
| 489 if(xmlnode_get_child(packet, "bad-protocol")) { |
466 gaim_connection_error(js->gc, msg); |
| 490 gaim_connection_error(js->gc, _("Bad Protocol")); |
467 g_free(msg); |
| 491 } else if(xmlnode_get_child(packet, "encryption-required")) { |
468 } |
| 492 js->gc->wants_to_die = TRUE; |
469 } |
| 493 gaim_connection_error(js->gc, _("Encryption Required")); |
|
| 494 } else if(xmlnode_get_child(packet, "invalid-authzid")) { |
|
| 495 js->gc->wants_to_die = TRUE; |
|
| 496 gaim_connection_error(js->gc, _("Invalid authzid")); |
|
| 497 } else if(xmlnode_get_child(packet, "invalid-mechanism")) { |
|
| 498 js->gc->wants_to_die = TRUE; |
|
| 499 gaim_connection_error(js->gc, _("Invalid Mechanism")); |
|
| 500 } else if(xmlnode_get_child(packet, "invalid-realm")) { |
|
| 501 gaim_connection_error(js->gc, _("Invalid Realm")); |
|
| 502 } else if(xmlnode_get_child(packet, "mechanism-too-weak")) { |
|
| 503 js->gc->wants_to_die = TRUE; |
|
| 504 gaim_connection_error(js->gc, _("Mechanism Too Weak")); |
|
| 505 } else if(xmlnode_get_child(packet, "not-authorized")) { |
|
| 506 js->gc->wants_to_die = TRUE; |
|
| 507 gaim_connection_error(js->gc, _("Not Authorized")); |
|
| 508 } else if(xmlnode_get_child(packet, "temporary-auth-failure")) { |
|
| 509 gaim_connection_error(js->gc, |
|
| 510 _("Temporary Authentication Failure")); |
|
| 511 } else { |
|
| 512 gaim_connection_error(js->gc, _("Authentication Failure")); |
|
| 513 } |
|
| 514 } |
|
| 515 } |
|