comparison src/protocols/jabber/chat.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 dc818b62379e
comparison
equal deleted inserted replaced
8400:0383e55cd658 8401:c13a4913a071
325 chat->config_dialog_handle = jabber_x_data_request(js, x, jabber_chat_room_configure_x_data_cb, chat); 325 chat->config_dialog_handle = jabber_x_data_request(js, x, jabber_chat_room_configure_x_data_cb, chat);
326 return; 326 return;
327 } 327 }
328 } 328 }
329 } else if(!strcmp(type, "error")) { 329 } else if(!strcmp(type, "error")) {
330 xmlnode *errnode = xmlnode_get_child(packet, "error"); 330 char *msg = jabber_parse_error(js, packet);
331 const char *code = NULL; 331
332 char *code_txt = NULL;
333 char *msg;
334 char *text = NULL;
335
336 if(errnode) {
337 code = xmlnode_get_attrib(errnode, "code");
338 text = xmlnode_get_data(errnode);
339 }
340
341 if(code)
342 code_txt = g_strdup_printf(_(" (Code %s)"), code);
343
344 msg = g_strdup_printf("%s%s", text ? text : "", code_txt ? code_txt : "");
345 gaim_notify_error(js->gc, _("Configuration error"), _("Configuration error"), msg); 332 gaim_notify_error(js->gc, _("Configuration error"), _("Configuration error"), msg);
346 333
347 g_free(msg); 334 if(msg)
348 if(code_txt) 335 g_free(msg);
349 g_free(code_txt);
350
351 return; 336 return;
352 } 337 }
353 338
354 msg = g_strdup_printf("Unable to configure room %s", from); 339 msg = g_strdup_printf("Unable to configure room %s", from);
355 340
416 static void jabber_chat_register_x_data_result_cb(JabberStream *js, xmlnode *packet, gpointer data) 401 static void jabber_chat_register_x_data_result_cb(JabberStream *js, xmlnode *packet, gpointer data)
417 { 402 {
418 const char *type = xmlnode_get_attrib(packet, "type"); 403 const char *type = xmlnode_get_attrib(packet, "type");
419 404
420 if(type && !strcmp(type, "error")) { 405 if(type && !strcmp(type, "error")) {
421 /* XXX: handle an error (you'll get a 409 if the nick is already registered) */ 406 char *msg = jabber_parse_error(js, packet);
407
408 gaim_notify_error(js->gc, _("Registration error"), _("Registration error"), msg);
409
410 if(msg)
411 g_free(msg);
412 return;
422 } 413 }
423 } 414 }
424 415
425 static void jabber_chat_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) 416 static void jabber_chat_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data)
426 { 417 {
479 jabber_x_data_request(js, x, jabber_chat_register_x_data_cb, chat); 470 jabber_x_data_request(js, x, jabber_chat_register_x_data_cb, chat);
480 return; 471 return;
481 } 472 }
482 } 473 }
483 } else if(!strcmp(type, "error")) { 474 } else if(!strcmp(type, "error")) {
484 /* XXX: how many places is this code duplicated? Fix it, immediately */ 475 char *msg = jabber_parse_error(js, packet);
485 xmlnode *errnode = xmlnode_get_child(packet, "error"); 476
486 const char *code = NULL;
487 char *code_txt = NULL;
488 char *msg;
489 char *text = NULL;
490
491 if(errnode) {
492 code = xmlnode_get_attrib(errnode, "code");
493 text = xmlnode_get_data(errnode);
494 }
495
496 if(code)
497 code_txt = g_strdup_printf(_(" (Code %s)"), code);
498
499 msg = g_strdup_printf("%s%s", text ? text : "", code_txt ? code_txt : "");
500 gaim_notify_error(js->gc, _("Registration error"), _("Registration error"), msg); 477 gaim_notify_error(js->gc, _("Registration error"), _("Registration error"), msg);
501 478
502 g_free(msg); 479 if(msg)
503 if(code_txt) 480 g_free(msg);
504 g_free(code_txt);
505
506 return; 481 return;
507 } 482 }
508 483
509 msg = g_strdup_printf("Unable to configure room %s", from); 484 msg = g_strdup_printf("Unable to configure room %s", from);
510 485
618 593
619 if(!js->roomlist) 594 if(!js->roomlist)
620 return; 595 return;
621 596
622 if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result")) { 597 if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "result")) {
623 /* XXX: error msg */ 598 char *err = jabber_parse_error(js,packet);
599 gaim_notify_error(js->gc, _("Roomlist Error"),
600 _("Error retreiving roomlist"), err);
624 gaim_roomlist_set_in_progress(js->roomlist, FALSE); 601 gaim_roomlist_set_in_progress(js->roomlist, FALSE);
625 gaim_roomlist_unref(js->roomlist); 602 gaim_roomlist_unref(js->roomlist);
626 js->roomlist = NULL; 603 js->roomlist = NULL;
604 g_free(err);
627 return; 605 return;
628 } 606 }
629 607
630 if(!(query = xmlnode_get_child(packet, "query"))) { 608 if(!(query = xmlnode_get_child(packet, "query"))) {
631 /* XXX: error msg */ 609 char *err = jabber_parse_error(js, packet);
610 gaim_notify_error(js->gc, _("Roomlist Error"),
611 _("Error retreiving roomlist"), err);
632 gaim_roomlist_set_in_progress(js->roomlist, FALSE); 612 gaim_roomlist_set_in_progress(js->roomlist, FALSE);
633 gaim_roomlist_unref(js->roomlist); 613 gaim_roomlist_unref(js->roomlist);
634 js->roomlist = NULL; 614 js->roomlist = NULL;
615 g_free(err);
635 return; 616 return;
636 } 617 }
637 618
638 for(item = xmlnode_get_child(query, "item"); item; 619 for(item = xmlnode_get_child(query, "item"); item;
639 item = xmlnode_get_next_twin(item)) { 620 item = xmlnode_get_next_twin(item)) {