comparison mcabber/src/xmpp.c @ 1602:f4a2c6f767d1

Message Receipts support (XEP-0184)
author franky
date Wed, 24 Sep 2008 11:41:29 +0200
parents c5ee395fbc8c
children 351427ef0b4b
comparison
equal deleted inserted replaced
1601:3efc92a48945 1602:f4a2c6f767d1
312 g_free(p_res->data); 312 g_free(p_res->data);
313 } 313 }
314 g_slist_free(resources); 314 g_slist_free(resources);
315 } 315 }
316 316
317 static LmHandlerResult cb_xep184(LmMessageHandler *h, LmConnection *c,
318 LmMessage *m, gpointer user_data)
319 {
320 char *from = jidtodisp(lm_message_get_from(m));
321 scr_RemoveReceiptFlag(from, h);
322 g_free(from);
323 return LM_HANDLER_RESULT_REMOVE_MESSAGE;
324 }
325
317 // xmpp_send_msg(jid, text, type, subject, 326 // xmpp_send_msg(jid, text, type, subject,
318 // otrinject, *encrypted, type_overwrite) 327 // otrinject, *encrypted, type_overwrite)
319 // When encrypted is not NULL, the function set *encrypted to 1 if the 328 // When encrypted is not NULL, the function set *encrypted to 1 if the
320 // message has been PGP-encrypted. If encryption enforcement is set and 329 // message has been PGP-encrypted. If encryption enforcement is set and
321 // encryption fails, *encrypted is set to -1. 330 // encryption fails, *encrypted is set to -1.
322 void xmpp_send_msg(const char *fjid, const char *text, int type, 331 void xmpp_send_msg(const char *fjid, const char *text, int type,
323 const char *subject, gboolean otrinject, gint *encrypted, 332 const char *subject, gboolean otrinject, gint *encrypted,
324 LmMessageSubType type_overwrite) 333 LmMessageSubType type_overwrite, gpointer *xep184)
325 { 334 {
326 LmMessage *x; 335 LmMessage *x;
327 LmMessageSubType subtype; 336 LmMessageSubType subtype;
328 #ifdef HAVE_LIBOTR 337 #ifdef HAVE_LIBOTR
329 int otr_msg = 0; 338 int otr_msg = 0;
431 if (encrypted) 440 if (encrypted)
432 *encrypted = ENCRYPTED_PGP; 441 *encrypted = ENCRYPTED_PGP;
433 g_free(enc); 442 g_free(enc);
434 } 443 }
435 444
445 //XEP-0184: Message Receipts
446 if (sl_buddy && rname && xep184 &&
447 caps_has_feature(buddy_resource_getcaps(sl_buddy->data, rname),
448 NS_RECEIPTS)) {
449 lm_message_node_set_attribute
450 (lm_message_node_add_child(x->node, "request", NULL),
451 "xmlns", NS_RECEIPTS);
452 *xep184 = lm_message_handler_new(cb_xep184, NULL, NULL);
453 }
454
436 #if defined JEP0022 || defined JEP0085 455 #if defined JEP0022 || defined JEP0085
437 // If typing notifications are disabled, we can skip all this stuff... 456 // If typing notifications are disabled, we can skip all this stuff...
438 if (chatstates_disabled || type == ROSTER_TYPE_ROOM) 457 if (chatstates_disabled || type == ROSTER_TYPE_ROOM)
439 goto xmpp_send_msg_no_chatstates; 458 goto xmpp_send_msg_no_chatstates;
440 459
490 #endif 509 #endif
491 510
492 xmpp_send_msg_no_chatstates: 511 xmpp_send_msg_no_chatstates:
493 if (mystatus != invisible) 512 if (mystatus != invisible)
494 update_last_use(); 513 update_last_use();
495 lm_connection_send(lconnection, x, NULL); 514 if (xep184 && *xep184) {
515 lm_connection_send_with_reply(lconnection, x, *xep184, NULL);
516 lm_message_handler_unref(*xep184);
517 } else
518 lm_connection_send(lconnection, x, NULL);
496 lm_message_unref(x); 519 lm_message_unref(x);
497 } 520 }
498 521
499 #ifdef JEP0085 522 #ifdef JEP0085
500 // xmpp_send_jep85_chatstate() 523 // xmpp_send_jep85_chatstate()
1241 handle_state_events(from, m->node); 1264 handle_state_events(from, m->node);
1242 } 1265 }
1243 if (from && (body || subject)) 1266 if (from && (body || subject))
1244 gotmessage(lm_message_get_sub_type(m), from, body, enc, subject, timestamp, 1267 gotmessage(lm_message_get_sub_type(m), from, body, enc, subject, timestamp,
1245 lm_message_node_find_xmlns(m->node, NS_SIGNED)); 1268 lm_message_node_find_xmlns(m->node, NS_SIGNED));
1269 //report received message if message receipt was requested
1270 if (lm_message_node_get_child(m->node, "request")) {
1271 LmMessage *rcvd = lm_message_new(from, LM_MESSAGE_TYPE_MESSAGE);
1272 lm_message_node_set_attribute(rcvd->node, "id", lm_message_get_id(m));
1273 lm_message_node_set_attribute
1274 (lm_message_node_add_child(rcvd->node, "received", NULL),
1275 "xmlns", NS_RECEIPTS);
1276 lm_connection_send(connection, rcvd, NULL);
1277 lm_message_unref(rcvd);
1278 }
1246 1279
1247 if (from) { 1280 if (from) {
1248 x = lm_message_node_find_xmlns(m->node, 1281 x = lm_message_node_find_xmlns(m->node,
1249 "http://jabber.org/protocol/muc#user"); 1282 "http://jabber.org/protocol/muc#user");
1250 if (x && !strcmp(x->name, "x")) 1283 if (x && !strcmp(x->name, "x"))