# HG changeset patch # User Mikael Berthe # Date 1132952970 -3600 # Node ID 3569d38f7bbb997d9366e5b7213c49dfad12177e # Parent c478e8f7f074fb53110eedbdbfeb74f4941b5073 Add presnew() diff -r c478e8f7f074 -r 3569d38f7bbb mcabber/src/jabglue.c --- 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