changeset 534:3569d38f7bbb

Add presnew()
author Mikael Berthe <mikael@lilotux.net>
date Fri, 25 Nov 2005 22:09:30 +0100
parents c478e8f7f074
children b407d19c39ab
files mcabber/src/jabglue.c
diffstat 1 files changed, 25 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/jabglue.c	Thu Nov 24 00:11:40 2005 +0100
+++ b/mcabber/src/jabglue.c	Fri Nov 25 22:09:30 2005 +0100
@@ -288,14 +288,14 @@
   g_free(to);
 }
 
-void jb_setstatus(enum imstatus st, const char *recipient, const char *msg)
+//  presnew(status, recipient, message)
+// Create an xmlnode with default presence attributes
+// Note: the caller must free the node after use
+static xmlnode presnew(enum imstatus st, const char *recipient,
+                        const char *msg)
 {
+  unsigned int prio;
   xmlnode x;
-  gchar *utf8_msg;
-  unsigned int prio;
-  struct T_presence room_presence;
-
-  if (!online) return;
 
   x = jutil_presnew(JPACKET__UNKNOWN, 0, 0);
 
@@ -340,9 +340,26 @@
     char strprio[8];
     snprintf(strprio, 8, "%u", prio);
     xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"),
-            strprio, (unsigned) -1);
+                         strprio, (unsigned) -1);
+  }
+
+  if (msg) {
+    gchar *utf8_msg = to_utf8(msg);
+    xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), utf8_msg,
+                         (unsigned) -1);
+    g_free(utf8_msg);
   }
 
+  return x;
+}
+
+void jb_setstatus(enum imstatus st, const char *recipient, const char *msg)
+{
+  xmlnode x;
+  struct T_presence room_presence;
+
+  if (!online) return;
+
   if (msg) {
     // The status message has been specified.  We'll use it, unless it is
     // "-" which is a special case (option meaning "no status message").
@@ -362,12 +379,8 @@
     }
   }
 
-  utf8_msg = to_utf8(msg);
-  xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), utf8_msg,
-          (unsigned) -1);
-
+  x = presnew(st, recipient, msg);
   jab_send(jc, x);
-  g_free(utf8_msg);
   xmlnode_free(x);
 
   // If we didn't change our _global_ status, we are done