comparison mcabber/mcabber/xmpp_helper.c @ 1704:ab502d645378

Update display_server_error() Do not display the error code if we can give a tag or description.
author Mikael Berthe <mikael@lilotux.net>
date Mon, 08 Feb 2010 19:36:56 +0100
parents d080e7cda46c
children e6e89b1d7831
comparison
equal deleted inserted replaced
1703:65ba89949252 1704:ab502d645378
344 // display_server_error(x) 344 // display_server_error(x)
345 // Display the error to the user 345 // Display the error to the user
346 // x: error tag xmlnode pointer 346 // x: error tag xmlnode pointer
347 void display_server_error(LmMessageNode *x) 347 void display_server_error(LmMessageNode *x)
348 { 348 {
349 const char *desc = NULL, *p=NULL, *s; 349 const char *desc = NULL, *errname=NULL, *s;
350 char *sdesc, *tmp; 350 char *sdesc, *tmp;
351 int code = 0;
352 351
353 if (!x) return; 352 if (!x) return;
354 353
355 /* RFC3920: 354 /* RFC3920:
356 * The <error/> element: 355 * The <error/> element:
357 * o MUST contain a child element corresponding to one of the defined 356 * o MUST contain a child element corresponding to one of the defined
358 * stanza error conditions specified below; this element MUST be 357 * stanza error conditions specified below; this element MUST be
359 * qualified by the 'urn:ietf:params:xml:ns:xmpp-stanzas' namespace. 358 * qualified by the 'urn:ietf:params:xml:ns:xmpp-stanzas' namespace.
360 */ 359 */
361 if (x->children) 360 if (x->children)
362 p = x->children->name; 361 errname = x->children->name;
363 if (p) 362 scr_LogPrint(LPRINT_LOGNORM, "Received error packet [%s]",
364 scr_LogPrint(LPRINT_LOGNORM, "Received error packet [%s]", p); 363 (errname ? errname : ""));
365 364
366 // For backward compatibility 365 // For backward compatibility
367 if ((s = lm_message_node_get_attribute(x, "code")) != NULL) { 366 if (!errname && ((s = lm_message_node_get_attribute(x, "code")) != NULL)) {
368 code = atoi(s);
369 // Default message 367 // Default message
370 desc = defaulterrormsg(code); 368 desc = defaulterrormsg(atoi(s));
371 } 369 }
372 370
373 // Error tag data is better, if available 371 // Error tag data is better, if available
374 s = lm_message_node_get_value(x); 372 s = lm_message_node_get_value(x);
375 if (s && *s) desc = s; 373 if (s && *s) desc = s;
378 s = lm_message_node_get_child_value(x, "text"); 376 s = lm_message_node_get_child_value(x, "text");
379 377
380 if (s && *s) desc = s; 378 if (s && *s) desc = s;
381 379
382 // If we still have no description, let's give up 380 // If we still have no description, let's give up
383 if (!desc) 381 if (!desc || !*desc)
384 return; 382 return;
385 383
386 // Strip trailing newlines 384 // Strip trailing newlines
387 sdesc = g_strdup(desc); 385 sdesc = g_strdup(desc);
388 for (tmp = sdesc; *tmp; tmp++) ; 386 for (tmp = sdesc; *tmp; tmp++) ;
389 if (tmp > sdesc) 387 if (tmp > sdesc)
390 tmp--; 388 tmp--;
391 while (tmp >= sdesc && (*tmp == '\n' || *tmp == '\r')) 389 while (tmp >= sdesc && (*tmp == '\n' || *tmp == '\r'))
392 *tmp-- = '\0'; 390 *tmp-- = '\0';
393 391
394 scr_LogPrint(LPRINT_LOGNORM, "Error code from server: %d %s", code, sdesc); 392 if (*sdesc)
393 scr_LogPrint(LPRINT_LOGNORM, "Error message from server: %s", sdesc);
395 g_free(sdesc); 394 g_free(sdesc);
396 } 395 }
397 396
398 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ 397 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */