src/baseprotocol.c
author Volker Birk <vb@pep.foundation>
Tue, 27 Dec 2016 21:13:41 +0100
changeset 1513 e7f7e42385b5
parent 1132 acf75ee0d834
child 1829 909cb53fc069
permissions -rw-r--r--
adding license info to each file
vb@1513
     1
// This file is under GNU General Public License 3.0
vb@1513
     2
// see LICENSE.txt
vb@1513
     3
vb@585
     4
#include "pEp_internal.h"
vb@952
     5
#include "message_api.h"
vb@585
     6
vb@587
     7
PEP_STATUS decorate_message(
vb@587
     8
        message *msg,
vb@587
     9
        char *payload,
vb@587
    10
        size_t size
vb@587
    11
    )
vb@587
    12
{
vb@587
    13
    assert(msg);
vb@587
    14
    assert(payload);
vb@587
    15
    assert(size);
vb@587
    16
vb@587
    17
    if (!(msg && payload && size))
vb@587
    18
        return PEP_ILLEGAL_VALUE;
vb@587
    19
vb@587
    20
    bloblist_t *bl = bloblist_add(msg->attachments, payload, size,
vb@1132
    21
            "application/pEp.sync", "ignore_this_attachment.pEp");
vb@587
    22
    if (bl == NULL)
vb@587
    23
        goto enomem;
vb@587
    24
vb@587
    25
    msg->attachments = bl;
vb@587
    26
    return PEP_STATUS_OK;
vb@587
    27
vb@587
    28
enomem:
vb@587
    29
    return PEP_OUT_OF_MEMORY;
vb@587
    30
}
vb@587
    31
vb@585
    32
PEP_STATUS prepare_message(
vb@585
    33
        const pEp_identity *me,
vb@585
    34
        const pEp_identity *partner,
vb@585
    35
        char *payload,
vb@585
    36
        size_t size,
vb@585
    37
        message **result
vb@585
    38
    )
vb@585
    39
{
vb@587
    40
    PEP_STATUS status = PEP_STATUS_OK;
vb@587
    41
vb@585
    42
    assert(me);
vb@585
    43
    assert(partner);
vb@585
    44
    assert(payload);
vb@587
    45
    assert(size);
vb@587
    46
    assert(result);
vb@587
    47
vb@587
    48
    if (!(me && partner && payload && size && result))
vb@587
    49
        return PEP_ILLEGAL_VALUE;
vb@585
    50
vb@585
    51
    *result = NULL;
vb@585
    52
vb@585
    53
    message *msg = new_message(PEP_dir_outgoing);
vb@585
    54
    if (!msg)
vb@585
    55
        goto enomem;
vb@585
    56
vb@1132
    57
    add_opt_field(msg, "pEp-auto-consume", "yes");
vb@952
    58
vb@585
    59
    msg->from = identity_dup(me);
vb@585
    60
    if (!msg->from)
vb@585
    61
        goto enomem;
vb@585
    62
vb@585
    63
    msg->to = new_identity_list(identity_dup(partner));
vb@585
    64
    if (!msg->to)
vb@585
    65
        goto enomem;
vb@585
    66
vb@952
    67
    msg->shortmsg = strdup("p≡p synchronization message - please ignore");
vb@585
    68
    assert(msg->shortmsg);
vb@585
    69
    if (!msg->shortmsg)
vb@585
    70
        goto enomem;
vb@585
    71
vb@585
    72
    msg->longmsg = strdup("This message is part of p≡p's concept to synchronize.\n\n"
vb@585
    73
                        "You can safely ignore it. It will be deleted automatically.\n");
vb@585
    74
    assert(msg->longmsg);
vb@585
    75
    if (!msg->longmsg)
vb@585
    76
        goto enomem;
vb@585
    77
vb@587
    78
    status = decorate_message(msg, payload, size);
vb@587
    79
    if (status == PEP_STATUS_OK)
vb@587
    80
        *result = msg;
vb@587
    81
    return status;
vb@585
    82
vb@585
    83
enomem:
vb@585
    84
    free_message(msg);
vb@585
    85
    return PEP_OUT_OF_MEMORY;
vb@585
    86
}
vb@585
    87