merged sync
authorKrista Bennett <krista@pep-project.org>
Tue, 20 Nov 2018 13:57:47 +0100
branchsync
changeset 313813a1ac115f2d
parent 3137 93877eafa715
parent 3130 7416d52013ff
child 3139 d9b3c218af20
merged
src/message_api.c
     1.1 --- a/src/baseprotocol.c	Tue Nov 20 13:55:19 2018 +0100
     1.2 +++ b/src/baseprotocol.c	Tue Nov 20 13:57:47 2018 +0100
     1.3 @@ -7,7 +7,8 @@
     1.4  PEP_STATUS base_decorate_message(
     1.5          message *msg,
     1.6          char *payload,
     1.7 -        size_t size
     1.8 +        size_t size,
     1.9 +        char *fpr
    1.10      )
    1.11  {
    1.12      assert(msg);
    1.13 @@ -22,6 +23,10 @@
    1.14      if (bl == NULL)
    1.15          goto enomem;
    1.16  
    1.17 +    if (fpr) {
    1.18 +        // add signature
    1.19 +    }
    1.20 +
    1.21      msg->attachments = bl;
    1.22      return PEP_STATUS_OK;
    1.23  
    1.24 @@ -34,6 +39,7 @@
    1.25          const pEp_identity *partner,
    1.26          char *payload,
    1.27          size_t size,
    1.28 +        char *fpr,
    1.29          message **result
    1.30      )
    1.31  {
    1.32 @@ -75,7 +81,7 @@
    1.33      if (!msg->longmsg)
    1.34          goto enomem;
    1.35  
    1.36 -    status = base_decorate_message(msg, payload, size);
    1.37 +    status = base_decorate_message(msg, payload, size, fpr);
    1.38      if (status == PEP_STATUS_OK)
    1.39          *result = msg;
    1.40      return status;
    1.41 @@ -85,3 +91,25 @@
    1.42      return PEP_OUT_OF_MEMORY;
    1.43  }
    1.44  
    1.45 +PEP_STATUS base_extract_message(message *msg, size_t *size, const char **payload)
    1.46 +{
    1.47 +    PEP_STATUS status = PEP_STATUS_OK;
    1.48 +
    1.49 +    assert(msg && size && payload);
    1.50 +    if (!(msg && size && payload))
    1.51 +        return PEP_ILLEGAL_VALUE;
    1.52 +
    1.53 +    *size = 0;
    1.54 +    *payload = NULL;
    1.55 +
    1.56 +    for (bloblist_t *bl = msg->attachments; bl ; bl = bl->next) {
    1.57 +        if (bl->mime_type && strcasecmp(bl->mime_type, "application/pEp.sync") == 0) {
    1.58 +            *size = bl->size;
    1.59 +            *payload = bl->value;
    1.60 +            break;
    1.61 +        }
    1.62 +    }
    1.63 +
    1.64 +    return status;
    1.65 +}
    1.66 +
     2.1 --- a/src/baseprotocol.h	Tue Nov 20 13:55:19 2018 +0100
     2.2 +++ b/src/baseprotocol.h	Tue Nov 20 13:57:47 2018 +0100
     2.3 @@ -16,6 +16,7 @@
     2.4  //      msg (inout)     message to decorate
     2.5  //      payload (in)    payload to send
     2.6  //      size (in)       size of payload
     2.7 +//      fpr (in)        optional key to sign or NULL
     2.8  //
     2.9  //  returns:
    2.10  //      PEP_STATUS_OK and result on success or an error on failure
    2.11 @@ -27,7 +28,8 @@
    2.12  PEP_STATUS base_decorate_message(
    2.13          message *msg,
    2.14          char *payload,
    2.15 -        size_t size
    2.16 +        size_t size,
    2.17 +        char *fpr
    2.18      );
    2.19  
    2.20  
    2.21 @@ -38,6 +40,7 @@
    2.22  //      partner (in)    identity to use for the receiver
    2.23  //      payload (in)    payload to send
    2.24  //      size (in)       size of payload
    2.25 +//      fpr (in)        optional key to sign or NULL
    2.26  //      result (out)    message with payload
    2.27  //
    2.28  //  returns:
    2.29 @@ -52,10 +55,29 @@
    2.30          const pEp_identity *partner,
    2.31          char *payload,
    2.32          size_t size,
    2.33 +        char *fpr,
    2.34          message **result
    2.35      );
    2.36  
    2.37  
    2.38 +// base_extract_message() - extract a sync message from a pEp message
    2.39 +//
    2.40 +//  parameters:
    2.41 +//      msg (in)        message to analyze
    2.42 +//      size (out)      size of extracted payload or 0 if not found
    2.43 +//      payload (out)   extraced payload
    2.44 +//
    2.45 +//  returns:
    2.46 +//      PEP_STATUS_OK and payload == NULL if no sync message
    2.47 +//      PEP_STATUS_OK and payload, size if sync message found
    2.48 +//      any other value on error
    2.49 +//
    2.50 +//  caveat:
    2.51 +//      payload may point to msg attachment, the ownership does not change
    2.52 +
    2.53 +PEP_STATUS base_extract_message(message *msg, size_t *size, const char **payload);
    2.54 +
    2.55 +
    2.56  #ifdef __cplusplus
    2.57  }
    2.58  #endif
     3.1 --- a/src/message_api.c	Tue Nov 20 13:55:19 2018 +0100
     3.2 +++ b/src/message_api.c	Tue Nov 20 13:57:47 2018 +0100
     3.3 @@ -7,6 +7,7 @@
     3.4  #include "platform.h"
     3.5  #include "mime.h"
     3.6  #include "blacklist.h"
     3.7 +#include "baseprotocol.h"
     3.8  #include "KeySync_fsm.h"
     3.9  #include "base64.h"
    3.10  
    3.11 @@ -3752,11 +3753,12 @@
    3.12  
    3.13      message *msg = *dst ? *dst : src;
    3.14  
    3.15 -    if (session->inject_sync_event && msg && msg->attachments) {
    3.16 -        for (bloblist_t *bl = msg->attachments; bl ; bl = bl->next) {
    3.17 -            if (bl->mime_type && strcasecmp(bl->mime_type, "application/pEp.sync") == 0)
    3.18 -                signal_Sync_message(session, *rating, bl->value, bl->size);
    3.19 -        }
    3.20 +    if (session->inject_sync_event && msg) {
    3.21 +        size_t size;
    3.22 +        const char *data;
    3.23 +        status = base_extract_message(msg, &size, &data);
    3.24 +        if (size && data)
    3.25 +            signal_Sync_message(session, *rating, data, size);
    3.26      }
    3.27  
    3.28      return status;
     4.1 --- a/sync/gen_statemachine.ysl2	Tue Nov 20 13:55:19 2018 +0100
     4.2 +++ b/sync/gen_statemachine.ysl2	Tue Nov 20 13:57:47 2018 +0100
     4.3 @@ -451,25 +451,38 @@
     4.4                          goto the_end;
     4.5                      }
     4.6                      memcpy(_data, data, size);
     4.7 -                    status = base_prepare_message(
     4.8 -                            li->ident,
     4.9 -                            li->ident,
    4.10 -                            _data,
    4.11 -                            size,
    4.12 -                            &_m
    4.13 -                        );
    4.14 -                    if (status) {
    4.15 -                        free(_data);
    4.16 -                        goto the_end;
    4.17 -                    }
    4.18  
    4.19                      switch (message_type) {
    4.20                      `` for "fsm/message[@security='unencrypted']" |>>> case «../@name»__payload_PR_«yml:mixedCase(@name)»:
    4.21 +                            status = base_prepare_message(
    4.22 +                                    li->ident,
    4.23 +                                    li->ident,
    4.24 +                                    _data,
    4.25 +                                    size,
    4.26 +                                    li->ident->fpr,
    4.27 +                                    &_m
    4.28 +                                );
    4.29 +                            if (status) {
    4.30 +                                free(_data);
    4.31 +                                goto the_end;
    4.32 +                            }
    4.33                              attach_own_key(session, _m);
    4.34                              m = _m;
    4.35                              break;
    4.36  
    4.37                          default:
    4.38 +                            status = base_prepare_message(
    4.39 +                                    li->ident,
    4.40 +                                    li->ident,
    4.41 +                                    _data,
    4.42 +                                    size,
    4.43 +                                    NULL,
    4.44 +                                    &_m
    4.45 +                                );
    4.46 +                            if (status) {
    4.47 +                                free(_data);
    4.48 +                                goto the_end;
    4.49 +                            }
    4.50                              status = encrypt_message(session, _m, NULL, &m, PEP_enc_PEP, 0);
    4.51                              if (status) {
    4.52                                  status = PEP_«yml:ucase(@name)»_CANNOT_ENCRYPT;