1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Extracted carbons handling

This commit is contained in:
James Booth 2015-05-04 21:31:05 +01:00
parent ac940c2c8a
commit a0c872edf8

View File

@ -608,18 +608,14 @@ _private_chat_handler(xmpp_stanza_t * const stanza, const char * const fulljid)
xmpp_free(ctx, message); xmpp_free(ctx, message);
} }
static int static gboolean
_chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) _handle_carbons(xmpp_stanza_t * const stanza)
{ {
// ignore if type not chat or absent xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS);
char *type = xmpp_stanza_get_type(stanza); if (!carbons) {
if (!(g_strcmp0(type, "chat") == 0 || type == NULL)) { return FALSE;
return 1;
} }
// check if carbon message
xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS);
if (carbons) {
char *name = xmpp_stanza_get_name(carbons); char *name = xmpp_stanza_get_name(carbons);
if ((g_strcmp0(name, "received") == 0) || (g_strcmp0(name, "sent")) == 0) { if ((g_strcmp0(name, "received") == 0) || (g_strcmp0(name, "sent")) == 0) {
xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD); xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD);
@ -657,8 +653,26 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con
jid_destroy(jid_from); jid_destroy(jid_from);
jid_destroy(jid_to); jid_destroy(jid_to);
jid_destroy(my_jid); jid_destroy(my_jid);
return TRUE;
}
return FALSE;
}
static int
_chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata)
{
// ignore if type not chat or absent
char *type = xmpp_stanza_get_type(stanza);
if (!(g_strcmp0(type, "chat") == 0 || type == NULL)) {
return 1; return 1;
} }
// check if carbon message
gboolean res = _handle_carbons(stanza);
if (res) {
return 1;
} }
// ignore handled namespaces // ignore handled namespaces