Changeset 82b0295 for protocols/jabber


Ignore:
Timestamp:
2016-03-20T03:58:05Z (8 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
b1634a8
Parents:
3c3b916
git-author:
dequis <dx@…> (26-01-16 16:11:53)
git-committer:
dequis <dx@…> (20-03-16 03:58:05)
Message:

jabber: Properly handle rejected file transfers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/si.c

    r3c3b916 r82b0295  
    393393        struct jabber_transfer *tf = NULL;
    394394        struct jabber_data *jd = ic->proto_data;
     395        struct jabber_error *err;
    395396
    396397        if (!(tgt_jid = xt_find_attr(node, "from")) ||
    397             !(ini_jid = xt_find_attr(node, "to"))) {
     398            !(ini_jid = xt_find_attr(node, "to")) ||
     399            !(iq_id   = xt_find_attr(node, "id"))) {
    398400                imcb_log(ic, "Invalid SI response from=%s to=%s", tgt_jid, ini_jid);
     401                return XT_HANDLED;
     402        }
     403
     404        /* Let's see if we can find out what this bytestream should be for... */
     405
     406        for (tflist = jd->filetransfers; tflist; tflist = g_slist_next(tflist)) {
     407                struct jabber_transfer *tft = tflist->data;
     408                if ((strcmp(tft->iq_id, iq_id) == 0)) {
     409                        tf = tft;
     410                        break;
     411                }
     412        }
     413
     414        if (!tf) {
     415                imcb_log(ic, "WARNING: Received bytestream request from %s that doesn't match an SI request", ini_jid);
     416                return XT_HANDLED;
     417        }
     418
     419        err = jabber_error_parse(xt_find_node(node->children, "error"), XMLNS_STANZA_ERROR);
     420
     421        if (err) {
     422                if (g_strcmp0(err->code, "forbidden") == 0) {
     423                        imcb_log(ic, "File %s: %s rejected the transfer", tf->ft->file_name, tgt_jid);
     424                } else {
     425                        imcb_log(ic, "Error: Stream initiation request failed: %s (%s)", err->code, err->text);
     426                }
     427                imcb_file_canceled(ic, tf->ft, "Stream initiation request failed");
     428                jabber_error_free(err);
    399429                return XT_HANDLED;
    400430        }
     
    409439         *                                      <value>
    410440         */
    411         if (!(tgt_jid = xt_find_attr(node, "from")) ||
    412             !(ini_jid = xt_find_attr(node, "to")) ||
    413             !(iq_id   = xt_find_attr(node, "id")) ||
    414             !(c = xt_find_node(node->children, "si")) ||
     441        if (!(c = xt_find_node(node->children, "si")) ||
    415442            !(cmp = xt_find_attr(c, "xmlns")) ||
    416443            !(strcmp(cmp, XMLNS_SI) == 0) ||
     
    439466        }
    440467
    441         /* Let's see if we can find out what this bytestream should be for... */
    442 
    443         for (tflist = jd->filetransfers; tflist; tflist = g_slist_next(tflist)) {
    444                 struct jabber_transfer *tft = tflist->data;
    445                 if ((strcmp(tft->iq_id, iq_id) == 0)) {
    446                         tf = tft;
    447                         break;
    448                 }
    449         }
    450 
    451         if (!tf) {
    452                 imcb_log(ic, "WARNING: Received bytestream request from %s that doesn't match an SI request", ini_jid);
    453                 return XT_HANDLED;
    454         }
    455 
    456468        tf->ini_jid = g_strdup(ini_jid);
    457469        tf->tgt_jid = g_strdup(tgt_jid);
Note: See TracChangeset for help on using the changeset viewer.