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