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