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