changeset 430:d03663d2e7d9

Display error messages as specified in RFC3920 (9.3) If possible, we display the child element corresponding to the stanza error conditions defined in RFC3920. Error code and error text will be displayed if available.
author Mikael Berthe <mikael@lilotux.net>
date Sun, 11 Sep 2005 22:01:57 +0200
parents 0bb3d37579aa
children 89aeb8fdd215
files mcabber/src/jabglue.c
diffstat 1 files changed, 26 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/jabglue.c	Sat Sep 10 14:53:01 2005 +0200
+++ b/mcabber/src/jabglue.c	Sun Sep 11 22:01:57 2005 +0200
@@ -621,28 +621,42 @@
   return desc;
 }
 
+//  display_server_error(x)
+// Display the error to the user
+// x: error tag xmlnode pointer
 void display_server_error(xmlnode x)
 {
+  const char *desc = NULL;
+  int code = 0;
   char *s;
-  const char *desc;
-  int code;
+  const char *p;
 
+  /* RFC3920:
+   *    The <error/> element:
+   *       o  MUST contain a child element corresponding to one of the defined
+   *          stanza error conditions specified below; this element MUST be
+   *          qualified by the 'urn:ietf:params:xml:ns:xmpp-stanzas' namespace.
+   */
+  p = xmlnode_get_name(xmlnode_get_firstchild(x));
+  if (p)
+    scr_LogPrint(LPRINT_LOGNORM, "Received error packet [%s]", p);
+
+  // For backward compatibility
   if ((s = xmlnode_get_attrib(x, "code")) != NULL) {
     code = atoi(s);
-
     // Default message
-    desc = defaulterrormsg(atoi(s));
+    desc = defaulterrormsg(code);
+  }
 
-    // Error tag data is better, if available
-    s = xmlnode_get_data(x);
-    if (s && *s) desc = s;
+  // Error tag data is better, if available
+  s = xmlnode_get_data(x);
+  if (s && *s) desc = s;
 
-    // And sometimes there is a text message
-    s = xmlnode_get_tag_data(x, "text");
-    if (s && *s) desc = s; // FIXME utf8??
+  // And sometimes there is a text message
+  s = xmlnode_get_tag_data(x, "text");
+  if (s && *s) desc = s; // FIXME utf8??
 
-    scr_LogPrint(LPRINT_LOGNORM, "Error code from server: %d %s", code, desc);
-  }
+  scr_LogPrint(LPRINT_LOGNORM, "Error code from server: %d %s", code, desc);
 }
 
 void statehandler(jconn conn, int state)