src/baseprotocol.c
author Volker Birk <vb@pep-project.org>
Tue, 10 May 2016 12:03:45 +0200
changeset 585 8ec129931074
child 587 ed8aa5e5b02c
permissions -rw-r--r--
prepare message
vb@585
     1
#include "pEp_internal.h"
vb@585
     2
vb@585
     3
PEP_STATUS prepare_message(
vb@585
     4
        const pEp_identity *me,
vb@585
     5
        const pEp_identity *partner,
vb@585
     6
        char *payload,
vb@585
     7
        size_t size,
vb@585
     8
        message **result
vb@585
     9
    )
vb@585
    10
{
vb@585
    11
    assert(me);
vb@585
    12
    assert(partner);
vb@585
    13
    assert(payload);
vb@585
    14
vb@585
    15
    *result = NULL;
vb@585
    16
vb@585
    17
    message *msg = new_message(PEP_dir_outgoing);
vb@585
    18
    if (!msg)
vb@585
    19
        goto enomem;
vb@585
    20
vb@585
    21
    msg->from = identity_dup(me);
vb@585
    22
    if (!msg->from)
vb@585
    23
        goto enomem;
vb@585
    24
vb@585
    25
    msg->to = new_identity_list(identity_dup(partner));
vb@585
    26
    if (!msg->to)
vb@585
    27
        goto enomem;
vb@585
    28
vb@585
    29
    msg->shortmsg = strdup("pEp");
vb@585
    30
    assert(msg->shortmsg);
vb@585
    31
    if (!msg->shortmsg)
vb@585
    32
        goto enomem;
vb@585
    33
vb@585
    34
    msg->longmsg = strdup("This message is part of p≡p's concept to synchronize.\n\n"
vb@585
    35
                        "You can safely ignore it. It will be deleted automatically.\n");
vb@585
    36
    assert(msg->longmsg);
vb@585
    37
    if (!msg->longmsg)
vb@585
    38
        goto enomem;
vb@585
    39
vb@585
    40
    msg->attachments = new_bloblist(payload, size, "application/pEp", "auto.pEp");
vb@585
    41
    if (msg->attachments == NULL)
vb@585
    42
        goto enomem;
vb@585
    43
vb@585
    44
    *result = msg;
vb@585
    45
    return PEP_STATUS_OK;
vb@585
    46
vb@585
    47
enomem:
vb@585
    48
    free_message(msg);
vb@585
    49
    return PEP_OUT_OF_MEMORY;
vb@585
    50
}
vb@585
    51