Ignore:
Timestamp:
2016-09-24T20:14:34Z (8 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
ba52ac5
Parents:
63cad66 (diff), 82cb190 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into parson

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/message.c

    r63cad66 r3fbce97  
    2424#include "jabber.h"
    2525
    26 xt_status jabber_pkt_message(struct xt_node *node, gpointer data)
     26static xt_status jabber_pkt_message_normal(struct xt_node *node, gpointer data, gboolean carbons_sent)
    2727{
    2828        struct im_connection *ic = data;
    29         char *from = xt_find_attr(node, "from");
     29        struct jabber_data *jd = ic->proto_data;
     30        char *from = xt_find_attr(node, carbons_sent ? "to" : "from");
    3031        char *type = xt_find_attr(node, "type");
    3132        char *id = xt_find_attr(node, "id");
     
    3738        if (!from) {
    3839                return XT_HANDLED; /* Consider this packet corrupted. */
    39 
    40         }
    41         if (request && id) {
     40        }
     41
     42        /* try to detect hipchat's own version of self-messages */
     43        if (jd->flags & JFLAG_HIPCHAT) {
     44                struct xt_node *c;
     45
     46                if ((c = xt_find_node_by_attr(node->children, "delay", "xmlns", XMLNS_DELAY)) &&
     47                    (s = xt_find_attr(c, "from_jid")) &&
     48                    jabber_compare_jid(s, jd->me)) {
     49                        carbons_sent = TRUE;
     50                }
     51        }
     52
     53        if (request && id && g_strcmp0(type, "groupchat") != 0 && !carbons_sent) {
    4254                /* Send a message receipt (XEP-0184), looking like this:
    43                  * <message
    44                  *  from='kingrichard@royalty.england.lit/throne'
    45                  *  id='bi29sg183b4v'
    46                  *  to='northumberland@shakespeare.lit/westminster'>
     55                 * <message from='...' id='...' to='...'>
    4756                 *  <received xmlns='urn:xmpp:receipts' id='richard2-4.1.247'/>
    48                  * </message> */
     57                 * </message>
     58                 *
     59                 * MUC messages are excluded, since receipts aren't supposed to be sent over MUCs
     60                 * (XEP-0184 section 5.3) and replying to those may result in 'forbidden' errors.
     61                 */
    4962                struct xt_node *received, *receipt;
    5063
     
    127140                if (fullmsg->len > 0) {
    128141                        imcb_buddy_msg(ic, from, fullmsg->str,
    129                                        0, jabber_get_timestamp(node));
     142                                       carbons_sent ? OPT_SELFMESSAGE : 0, jabber_get_timestamp(node));
    130143                }
    131144                if (room) {
     
    136149
    137150                /* Handling of incoming typing notifications. */
    138                 if (bud == NULL) {
    139                         /* Can't handle these for unknown buddies. */
     151                if (bud == NULL || carbons_sent) {
     152                        /* Can't handle these for unknown buddies.
     153                           And ignore them if it's just carbons */
    140154                } else if (xt_find_node(node->children, "composing")) {
    141155                        bud->flags |= JBFLAG_DOES_XEP85;
    142156                        imcb_buddy_typing(ic, from, OPT_TYPING);
    143157                }
    144                 /* No need to send a "stopped typing" signal when there's a message. */
    145                 else if (xt_find_node(node->children, "active") && (body == NULL)) {
     158                else if (xt_find_node(node->children, "active")) {
    146159                        bud->flags |= JBFLAG_DOES_XEP85;
    147                         imcb_buddy_typing(ic, from, 0);
     160
     161                        /* No need to send a "stopped typing" signal when there's a message. */
     162                        if (body == NULL) {
     163                                imcb_buddy_typing(ic, from, 0);
     164                        }
    148165                } else if (xt_find_node(node->children, "paused")) {
    149166                        bud->flags |= JBFLAG_DOES_XEP85;
     
    158175        return XT_HANDLED;
    159176}
     177
     178static xt_status jabber_carbons_message(struct xt_node *node, gpointer data)
     179{
     180        struct im_connection *ic = data;
     181        struct xt_node *wrap, *fwd, *msg;
     182        gboolean carbons_sent;
     183
     184        if ((wrap = xt_find_node(node->children, "received"))) {
     185                carbons_sent = FALSE;
     186        } else if ((wrap = xt_find_node(node->children, "sent"))) {
     187                carbons_sent = TRUE;
     188        }
     189
     190        if (wrap == NULL || g_strcmp0(xt_find_attr(wrap, "xmlns"), XMLNS_CARBONS) != 0) {
     191                return XT_NEXT;
     192        }
     193
     194        if (!(fwd = xt_find_node(wrap->children, "forwarded")) ||
     195             (g_strcmp0(xt_find_attr(fwd, "xmlns"), XMLNS_FORWARDING) != 0) ||
     196            !(msg = xt_find_node(fwd->children, "message"))) {
     197                imcb_log(ic, "Error: Invalid carbons message received");
     198                return XT_ABORT;
     199        }
     200
     201        return jabber_pkt_message_normal(msg, data, carbons_sent);
     202}
     203
     204xt_status jabber_pkt_message(struct xt_node *node, gpointer data)
     205{
     206        struct im_connection *ic = data;
     207        struct jabber_data *jd = ic->proto_data;
     208        char *from = xt_find_attr(node, "from");
     209
     210        if (jabber_compare_jid(jd->me, from)) {    /* Probably a Carbons message */
     211                xt_status st = jabber_carbons_message(node, data);
     212                if (st == XT_HANDLED || st == XT_ABORT) {
     213                        return st;
     214                }
     215        }
     216        return jabber_pkt_message_normal(node, data, FALSE);
     217}
Note: See TracChangeset for help on using the changeset viewer.