# HG changeset patch # User Mikael Berthe # Date 1162247878 -3600 # Node ID 6e2bfd1ffded6969b8811639f5de03aaf18ca039 # Parent f47e312560aff73455ad1e71e1d2e2525f44bfe9 Add ids to message stanzas if needed diff -r f47e312560af -r 6e2bfd1ffded mcabber/src/commands.c --- a/mcabber/src/commands.c Mon Oct 30 20:18:00 2006 +0100 +++ b/mcabber/src/commands.c Mon Oct 30 23:37:58 2006 +0100 @@ -320,7 +320,7 @@ } // Network part - jb_send_msg(jid, msg, buddy_gettype(BUDDATA(current_buddy)), subj); + jb_send_msg(jid, msg, buddy_gettype(BUDDATA(current_buddy)), subj, NULL); } // process_command(line) @@ -825,7 +825,7 @@ if (hmsg != msg) g_free(hmsg); // Network part - jb_send_msg(jid, msg, ROSTER_TYPE_USER, subj); + jb_send_msg(jid, msg, ROSTER_TYPE_USER, subj, NULL); if (rp) g_free(bare_jid); return 0; @@ -1912,7 +1912,7 @@ arg = to_utf8(arg); // Set the topic msg = g_strdup_printf("%s has set the topic to: %s", mkcmdstr("me"), arg); - jb_send_msg(buddy_getjid(bud), msg, ROSTER_TYPE_ROOM, arg); + jb_send_msg(buddy_getjid(bud), msg, ROSTER_TYPE_ROOM, arg, NULL); g_free(arg); g_free(msg); } diff -r f47e312560af -r 6e2bfd1ffded mcabber/src/jabglue.c --- a/mcabber/src/jabglue.c Mon Oct 30 20:18:00 2006 +0100 +++ b/mcabber/src/jabglue.c Mon Oct 30 23:37:58 2006 +0100 @@ -411,8 +411,21 @@ scr_UpdateMainStatus(TRUE); } +// new_msgid() +// Generate a new id string. The caller should free it. +static char *new_msgid(void) +{ + static guint msg_idn; + time_t now; + time(&now); + if (!msg_idn) + srand(now); + msg_idn += 1U + (unsigned int) (9.0 * (rand() / (RAND_MAX + 1.0))); + return g_strdup_printf("%u%d", msg_idn, (int)(now%10L)); +} + void jb_send_msg(const char *jid, const char *text, int type, - const char *subject) + const char *subject, const char *msgid) { xmlnode x; gchar *strtype; @@ -479,9 +492,19 @@ event = xmlnode_insert_tag(x, "x"); xmlnode_put_attrib(event, "xmlns", NS_EVENT); xmlnode_insert_tag(event, "composing"); + + // An id is mandatory when using JEP-0022. + if (!msgid) { + msgid = new_msgid(); + // FIXME update last_msgid_sent + // We do not update it when the msgid is provided by the caller, + // because this is probably a special message (e.g. delivered...) + } } #endif + xmlnode_put_attrib(x, "id", msgid); + jab_send(jc, x); xmlnode_free(x); diff -r f47e312560af -r 6e2bfd1ffded mcabber/src/jabglue.h --- a/mcabber/src/jabglue.h Mon Oct 30 20:18:00 2006 +0100 +++ b/mcabber/src/jabglue.h Mon Oct 30 23:37:58 2006 +0100 @@ -50,7 +50,7 @@ inline const char *jb_getstatusmsg(void); void jb_setstatus(enum imstatus st, const char *recipient, const char *msg); void jb_send_msg(const char *jid, const char *text, int type, - const char *subject); + const char *subject, const char *id); void jb_send_raw(const char *str); void jb_keepalive(void); inline void jb_reset_keepalive(void);