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