Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/jabglue.c @ 988:6e2bfd1ffded
Add ids to message stanzas if needed
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 30 Oct 2006 23:37:58 +0100 |
parents | f47e312560af |
children | 859ab76e5093 |
comparison
equal
deleted
inserted
replaced
987:f47e312560af | 988:6e2bfd1ffded |
---|---|
409 | 409 |
410 // Update status line | 410 // Update status line |
411 scr_UpdateMainStatus(TRUE); | 411 scr_UpdateMainStatus(TRUE); |
412 } | 412 } |
413 | 413 |
414 // new_msgid() | |
415 // Generate a new id string. The caller should free it. | |
416 static char *new_msgid(void) | |
417 { | |
418 static guint msg_idn; | |
419 time_t now; | |
420 time(&now); | |
421 if (!msg_idn) | |
422 srand(now); | |
423 msg_idn += 1U + (unsigned int) (9.0 * (rand() / (RAND_MAX + 1.0))); | |
424 return g_strdup_printf("%u%d", msg_idn, (int)(now%10L)); | |
425 } | |
426 | |
414 void jb_send_msg(const char *jid, const char *text, int type, | 427 void jb_send_msg(const char *jid, const char *text, int type, |
415 const char *subject) | 428 const char *subject, const char *msgid) |
416 { | 429 { |
417 xmlnode x; | 430 xmlnode x; |
418 gchar *strtype; | 431 gchar *strtype; |
419 #if defined JEP0022 || defined JEP0085 | 432 #if defined JEP0022 || defined JEP0085 |
420 xmlnode event; | 433 xmlnode event; |
477 */ | 490 */ |
478 if (!which_jep) { | 491 if (!which_jep) { |
479 event = xmlnode_insert_tag(x, "x"); | 492 event = xmlnode_insert_tag(x, "x"); |
480 xmlnode_put_attrib(event, "xmlns", NS_EVENT); | 493 xmlnode_put_attrib(event, "xmlns", NS_EVENT); |
481 xmlnode_insert_tag(event, "composing"); | 494 xmlnode_insert_tag(event, "composing"); |
495 | |
496 // An id is mandatory when using JEP-0022. | |
497 if (!msgid) { | |
498 msgid = new_msgid(); | |
499 // FIXME update last_msgid_sent | |
500 // We do not update it when the msgid is provided by the caller, | |
501 // because this is probably a special message (e.g. delivered...) | |
502 } | |
482 } | 503 } |
483 #endif | 504 #endif |
505 | |
506 xmlnode_put_attrib(x, "id", msgid); | |
484 | 507 |
485 jab_send(jc, x); | 508 jab_send(jc, x); |
486 xmlnode_free(x); | 509 xmlnode_free(x); |
487 | 510 |
488 jb_reset_keepalive(); | 511 jb_reset_keepalive(); |