From 1444be5c948f8b4509cfe3cb30992da74f12b5b8 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 17 Oct 2012 09:23:00 +0200 Subject: Implement jabber message receipts (XEP-0184) This change will make BitlBee acknowledge messages when requested. It will not request message receipts from other clients, mainly because I am not sure if this feature can be mapped to IRC cleanly. --- protocols/jabber/message.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'protocols/jabber/message.c') diff --git a/protocols/jabber/message.c b/protocols/jabber/message.c index 85c71c9d..7792c5a3 100644 --- a/protocols/jabber/message.c +++ b/protocols/jabber/message.c @@ -23,17 +23,46 @@ #include "jabber.h" +static unsigned int next_receipt_id = 1; + xt_status jabber_pkt_message( struct xt_node *node, gpointer data ) { struct im_connection *ic = data; + struct jabber_data *jd = ic->proto_data; char *from = xt_find_attr( node, "from" ); char *type = xt_find_attr( node, "type" ); + char *id = xt_find_attr( node, "id" ); struct xt_node *body = xt_find_node( node->children, "body" ), *c; + struct xt_node *request = xt_find_node( node->children, "request" ); + struct xt_node *received, *receipt; struct jabber_buddy *bud = NULL; char *s, *room = NULL, *reason = NULL; if( !from ) return XT_HANDLED; /* Consider this packet corrupted. */ + + if( request && id ) + { + /* Send a message receipt (XEP-0184), looking like this: + * + * + * */ + received = xt_new_node( "received", NULL, NULL ); + xt_add_attr( received, "xmlns", XMLNS_RECEIPTS ); + xt_add_attr( received, "id", id ); + receipt = jabber_make_packet( "message", NULL, from, received ); + xt_add_attr( receipt, "from", jd->me ); + + char *id = g_strdup_printf( "%sRCPT%05x", JABBER_PACKET_ID, ( next_receipt_id++ ) & 0xfffff ); + xt_add_attr( receipt, "id", id ); + g_free( id ); + + jabber_write_packet( ic, receipt ); + xt_free_node( receipt ); + } bud = jabber_buddy_by_jid( ic, from, GET_BUDDY_EXACT ); -- cgit v1.2.3