prepare message
authorVolker Birk <vb@pep-project.org>
Tue, 10 May 2016 12:03:45 +0200
changeset 5858ec129931074
parent 583 2392a33ae121
child 586 2eac603617fe
prepare message
src/baseprotocol.c
src/baseprotocol.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/baseprotocol.c	Tue May 10 12:03:45 2016 +0200
     1.3 @@ -0,0 +1,51 @@
     1.4 +#include "pEp_internal.h"
     1.5 +
     1.6 +PEP_STATUS prepare_message(
     1.7 +        const pEp_identity *me,
     1.8 +        const pEp_identity *partner,
     1.9 +        char *payload,
    1.10 +        size_t size,
    1.11 +        message **result
    1.12 +    )
    1.13 +{
    1.14 +    assert(me);
    1.15 +    assert(partner);
    1.16 +    assert(payload);
    1.17 +
    1.18 +    *result = NULL;
    1.19 +
    1.20 +    message *msg = new_message(PEP_dir_outgoing);
    1.21 +    if (!msg)
    1.22 +        goto enomem;
    1.23 +
    1.24 +    msg->from = identity_dup(me);
    1.25 +    if (!msg->from)
    1.26 +        goto enomem;
    1.27 +
    1.28 +    msg->to = new_identity_list(identity_dup(partner));
    1.29 +    if (!msg->to)
    1.30 +        goto enomem;
    1.31 +
    1.32 +    msg->shortmsg = strdup("pEp");
    1.33 +    assert(msg->shortmsg);
    1.34 +    if (!msg->shortmsg)
    1.35 +        goto enomem;
    1.36 +
    1.37 +    msg->longmsg = strdup("This message is part of p≡p's concept to synchronize.\n\n"
    1.38 +                        "You can safely ignore it. It will be deleted automatically.\n");
    1.39 +    assert(msg->longmsg);
    1.40 +    if (!msg->longmsg)
    1.41 +        goto enomem;
    1.42 +
    1.43 +    msg->attachments = new_bloblist(payload, size, "application/pEp", "auto.pEp");
    1.44 +    if (msg->attachments == NULL)
    1.45 +        goto enomem;
    1.46 +
    1.47 +    *result = msg;
    1.48 +    return PEP_STATUS_OK;
    1.49 +
    1.50 +enomem:
    1.51 +    free_message(msg);
    1.52 +    return PEP_OUT_OF_MEMORY;
    1.53 +}
    1.54 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/baseprotocol.h	Tue May 10 12:03:45 2016 +0200
     2.3 @@ -0,0 +1,36 @@
     2.4 +#pragma once
     2.5 +
     2.6 +#include "message.h"
     2.7 +
     2.8 +#ifdef __cplusplus
     2.9 +extern "C" {
    2.10 +#endif
    2.11 +
    2.12 +// prepare_message() - prepare a sync message with payload
    2.13 +//
    2.14 +//  parameters:
    2.15 +//      me (in)         identity to use for the sender
    2.16 +//      partner (in)    identity to use for the receiver
    2.17 +//      payload (in)    payload to send
    2.18 +//      size (in)       size of payload
    2.19 +//      result (out)    message with payload
    2.20 +//
    2.21 +//  returns:
    2.22 +//      PEP_STATUS_OK on success or PEP_OUT_OF_MEMORY
    2.23 +//
    2.24 +//  caveat:
    2.25 +//      on success (and only then) payload goes to the ownership of the message
    2.26 +//      created
    2.27 +
    2.28 +PEP_STATUS prepare_message(
    2.29 +        const pEp_identity *me,
    2.30 +        const pEp_identity *partner,
    2.31 +        char *payload,
    2.32 +        size_t size,
    2.33 +        message **result
    2.34 +    );
    2.35 +
    2.36 +#ifdef __cplusplus
    2.37 +}
    2.38 +#endif
    2.39 +