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