src/baseprotocol.c
changeset 587 ed8aa5e5b02c
parent 585 8ec129931074
child 952 986fd7b2eb8f
     1.1 --- a/src/baseprotocol.c	Tue May 10 12:15:14 2016 +0200
     1.2 +++ b/src/baseprotocol.c	Tue May 10 12:28:40 2016 +0200
     1.3 @@ -1,5 +1,30 @@
     1.4  #include "pEp_internal.h"
     1.5  
     1.6 +PEP_STATUS decorate_message(
     1.7 +        message *msg,
     1.8 +        char *payload,
     1.9 +        size_t size
    1.10 +    )
    1.11 +{
    1.12 +    assert(msg);
    1.13 +    assert(payload);
    1.14 +    assert(size);
    1.15 +
    1.16 +    if (!(msg && payload && size))
    1.17 +        return PEP_ILLEGAL_VALUE;
    1.18 +
    1.19 +    bloblist_t *bl = bloblist_add(msg->attachments, payload, size,
    1.20 +            "application/pEp", "auto.pEp");
    1.21 +    if (bl == NULL)
    1.22 +        goto enomem;
    1.23 +
    1.24 +    msg->attachments = bl;
    1.25 +    return PEP_STATUS_OK;
    1.26 +
    1.27 +enomem:
    1.28 +    return PEP_OUT_OF_MEMORY;
    1.29 +}
    1.30 +
    1.31  PEP_STATUS prepare_message(
    1.32          const pEp_identity *me,
    1.33          const pEp_identity *partner,
    1.34 @@ -8,9 +33,16 @@
    1.35          message **result
    1.36      )
    1.37  {
    1.38 +    PEP_STATUS status = PEP_STATUS_OK;
    1.39 +
    1.40      assert(me);
    1.41      assert(partner);
    1.42      assert(payload);
    1.43 +    assert(size);
    1.44 +    assert(result);
    1.45 +
    1.46 +    if (!(me && partner && payload && size && result))
    1.47 +        return PEP_ILLEGAL_VALUE;
    1.48  
    1.49      *result = NULL;
    1.50  
    1.51 @@ -37,12 +69,10 @@
    1.52      if (!msg->longmsg)
    1.53          goto enomem;
    1.54  
    1.55 -    msg->attachments = new_bloblist(payload, size, "application/pEp", "auto.pEp");
    1.56 -    if (msg->attachments == NULL)
    1.57 -        goto enomem;
    1.58 -
    1.59 -    *result = msg;
    1.60 -    return PEP_STATUS_OK;
    1.61 +    status = decorate_message(msg, payload, size);
    1.62 +    if (status == PEP_STATUS_OK)
    1.63 +        *result = msg;
    1.64 +    return status;
    1.65  
    1.66  enomem:
    1.67      free_message(msg);