src/baseprotocol.c
author Krista Bennett <krista@pep-project.org>
Fri, 04 May 2018 16:30:21 +0200
branchlocal_cpptest
changeset 2652 43b913f99a27
parent 1871 51337eb65533
child 2846 7444832c5c6e
permissions -rw-r--r--
Shelving broken things to break other things
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #include "pEp_internal.h"
     5 #include "message_api.h"
     6 
     7 PEP_STATUS decorate_message(
     8         message *msg,
     9         char *payload,
    10         size_t size
    11     )
    12 {
    13     assert(msg);
    14     assert(payload);
    15     assert(size);
    16 
    17     if (!(msg && payload && size))
    18         return PEP_ILLEGAL_VALUE;
    19 
    20     bloblist_t *bl = bloblist_add(msg->attachments, payload, size,
    21             "application/pEp.sync", "ignore_this_attachment.pEp");
    22     if (bl == NULL)
    23         goto enomem;
    24 
    25     msg->attachments = bl;
    26     return PEP_STATUS_OK;
    27 
    28 enomem:
    29     return PEP_OUT_OF_MEMORY;
    30 }
    31 
    32 PEP_STATUS prepare_message(
    33         const pEp_identity *me,
    34         const pEp_identity *partner,
    35         char *payload,
    36         size_t size,
    37         message **result
    38     )
    39 {
    40     PEP_STATUS status = PEP_STATUS_OK;
    41 
    42     assert(me);
    43     assert(partner);
    44     assert(payload);
    45     assert(size);
    46     assert(result);
    47 
    48     if (!(me && partner && payload && size && result))
    49         return PEP_ILLEGAL_VALUE;
    50 
    51     *result = NULL;
    52 
    53     message *msg = new_message(PEP_dir_outgoing);
    54     if (!msg)
    55         goto enomem;
    56 
    57     add_opt_field(msg, "pEp-auto-consume", "yes");
    58 
    59     msg->from = identity_dup(me);
    60     if (!msg->from)
    61         goto enomem;
    62 
    63     msg->to = new_identity_list(identity_dup(partner));
    64     if (!msg->to)
    65         goto enomem;
    66 
    67     msg->shortmsg = strdup("p≡p synchronization message - please ignore");
    68     assert(msg->shortmsg);
    69     if (!msg->shortmsg)
    70         goto enomem;
    71 
    72     msg->longmsg = strdup("This message is part of p≡p's concept to synchronize.\n\n"
    73                         "You can safely ignore it. It will be deleted automatically.\n");
    74     assert(msg->longmsg);
    75     if (!msg->longmsg)
    76         goto enomem;
    77 
    78     status = decorate_message(msg, payload, size);
    79     if (status == PEP_STATUS_OK)
    80         *result = msg;
    81     return status;
    82 
    83 enomem:
    84     free_message(msg);
    85     return PEP_OUT_OF_MEMORY;
    86 }
    87