... keysync
authorVolker Birk <vb@pep.foundation>
Sun, 31 Jul 2016 20:25:27 +0200
branchkeysync
changeset 952986fd7b2eb8f
parent 951 dec407deb10e
child 953 1572660086e7
...
src/baseprotocol.c
src/message_api.c
src/message_api.h
src/pEpEngine.h
src/sync_actions.c
src/sync_fsm.h
sync/gen_statemachine.ysl2
     1.1 --- a/src/baseprotocol.c	Sun Jul 31 19:38:23 2016 +0200
     1.2 +++ b/src/baseprotocol.c	Sun Jul 31 20:25:27 2016 +0200
     1.3 @@ -1,4 +1,5 @@
     1.4  #include "pEp_internal.h"
     1.5 +#include "message_api.h"
     1.6  
     1.7  PEP_STATUS decorate_message(
     1.8          message *msg,
     1.9 @@ -14,7 +15,7 @@
    1.10          return PEP_ILLEGAL_VALUE;
    1.11  
    1.12      bloblist_t *bl = bloblist_add(msg->attachments, payload, size,
    1.13 -            "application/pEp", "auto.pEp");
    1.14 +            "application/pEp", "ignore_this_attachment.pEp");
    1.15      if (bl == NULL)
    1.16          goto enomem;
    1.17  
    1.18 @@ -50,6 +51,8 @@
    1.19      if (!msg)
    1.20          goto enomem;
    1.21  
    1.22 +    add_opt_field(msg, "pEp-auto-consume", "yes");
    1.23 +
    1.24      msg->from = identity_dup(me);
    1.25      if (!msg->from)
    1.26          goto enomem;
    1.27 @@ -58,7 +61,7 @@
    1.28      if (!msg->to)
    1.29          goto enomem;
    1.30  
    1.31 -    msg->shortmsg = strdup("pEp");
    1.32 +    msg->shortmsg = strdup("p≡p synchronization message - please ignore");
    1.33      assert(msg->shortmsg);
    1.34      if (!msg->shortmsg)
    1.35          goto enomem;
     2.1 --- a/src/message_api.c	Sun Jul 31 19:38:23 2016 +0200
     2.2 +++ b/src/message_api.c	Sun Jul 31 20:25:27 2016 +0200
     2.3 @@ -3,6 +3,7 @@
     2.4  
     2.5  #include "platform.h"
     2.6  #include "mime.h"
     2.7 +#include "sync_fsm.h"
     2.8  
     2.9  #include <assert.h>
    2.10  #include <string.h>
    2.11 @@ -60,9 +61,9 @@
    2.12      return strcmp(bl->filename + (fn_len - fe_len), fe) == 0;
    2.13  }
    2.14  
    2.15 -static void add_opt_field(message *msg, const char *name, const char *value)
    2.16 +void add_opt_field(message *msg, const char *name, const char *value)
    2.17  {
    2.18 -    assert(msg);
    2.19 +    assert(msg && name && value);
    2.20  
    2.21      if (msg && name && value) {
    2.22          stringpair_t *pair = new_stringpair(name, value);
    2.23 @@ -1559,6 +1560,12 @@
    2.24              remove_attached_keys(msg);
    2.25      }
    2.26  
    2.27 +    status = receive_DeviceState_msg(session, msg);
    2.28 +    if (status == PEP_MESSAGE_CONSUMED) {
    2.29 +        free_message(msg);
    2.30 +        msg = NULL;
    2.31 +    }
    2.32 +
    2.33      *dst = msg;
    2.34      *keylist = _keylist;
    2.35  
     3.1 --- a/src/message_api.h	Sun Jul 31 19:38:23 2016 +0200
     3.2 +++ b/src/message_api.h	Sun Jul 31 20:25:27 2016 +0200
     3.3 @@ -17,6 +17,7 @@
     3.4      );
     3.5  void attach_own_key(PEP_SESSION session, message *msg);
     3.6  PEP_cryptotech determine_encryption_format(message *msg);
     3.7 +void add_opt_field(message *msg, const char *name, const char *value);
     3.8  
     3.9  typedef enum _PEP_encrypt_flags {
    3.10      PEP_encrypt_flag_force_encryption = 0x1
     4.1 --- a/src/pEpEngine.h	Sun Jul 31 19:38:23 2016 +0200
     4.2 +++ b/src/pEpEngine.h	Sun Jul 31 20:25:27 2016 +0200
     4.3 @@ -75,6 +75,7 @@
     4.4      PEP_SYNC_ILLEGAL_MESSAGE                        = 0x0902,
     4.5  
     4.6      PEP_COMMIT_FAILED                               = 0xff01,
     4.7 +    PEP_MESSAGE_CONSUMED                            = 0xff02,
     4.8  
     4.9      PEP_CANNOT_CREATE_TEMP_FILE                     = -5,
    4.10      PEP_ILLEGAL_VALUE                               = -4,
     5.1 --- a/src/sync_actions.c	Sun Jul 31 19:38:23 2016 +0200
     5.2 +++ b/src/sync_actions.c	Sun Jul 31 20:25:27 2016 +0200
     5.3 @@ -208,7 +208,7 @@
     5.4      return status;
     5.5  }
     5.6  
     5.7 -PEP_STATUS receive_sync_msg(PEP_SESSION session, DeviceGroup_Protocol_t *msg)
     5.8 +static PEP_STATUS receive_sync_msg(PEP_SESSION session, DeviceGroup_Protocol_t *msg)
     5.9  {
    5.10      assert(session && msg && msg->present != DeviceGroup_Protocol_PR_NOTHING);
    5.11      if (!(session && msg && msg->present != DeviceGroup_Protocol_PR_NOTHING))
    5.12 @@ -254,3 +254,12 @@
    5.13      return fsm_DeviceState_inject(session, event, partner, extra);
    5.14  }
    5.15  
    5.16 +PEP_STATUS receive_DeviceState_msg(PEP_SESSION session, message *src)
    5.17 +{
    5.18 +    assert(session && src);
    5.19 +    if (!(session && src))
    5.20 +        return PEP_ILLEGAL_VALUE;
    5.21 +
    5.22 +    return PEP_STATUS_OK;
    5.23 +}
    5.24 +
     6.1 --- a/src/sync_fsm.h	Sun Jul 31 19:38:23 2016 +0200
     6.2 +++ b/src/sync_fsm.h	Sun Jul 31 20:25:27 2016 +0200
     6.3 @@ -3,6 +3,7 @@
     6.4  // state machine for DeviceState
     6.5  
     6.6  #include "pEpEngine.h"
     6.7 +#include "message.h"
     6.8  #include "../asn.1/DeviceGroup-Protocol.h"
     6.9  
    6.10  #ifdef __cplusplus
    6.11 @@ -66,7 +67,7 @@
    6.12  
    6.13  // message receiver
    6.14  
    6.15 -PEP_STATUS receive_DeviceState_msg(PEP_SESSION session, DeviceGroup_Protocol_t *msg);
    6.16 +PEP_STATUS receive_DeviceState_msg(PEP_SESSION session, message *msg);
    6.17  
    6.18  // state machine
    6.19  
     7.1 --- a/sync/gen_statemachine.ysl2	Sun Jul 31 19:38:23 2016 +0200
     7.2 +++ b/sync/gen_statemachine.ysl2	Sun Jul 31 20:25:27 2016 +0200
     7.3 @@ -29,6 +29,7 @@
     7.4          // state machine for «@name»
     7.5  
     7.6          #include "pEpEngine.h"
     7.7 +        #include "message.h"
     7.8          #include "../asn.1/«../@name»-Protocol.h"
     7.9          
    7.10          #ifdef __cplusplus
    7.11 @@ -80,7 +81,7 @@
    7.12  
    7.13          // message receiver
    7.14          
    7.15 -        PEP_STATUS receive_«@name»_msg(PEP_SESSION session, «../@name»_Protocol_t *msg);
    7.16 +        PEP_STATUS receive_«@name»_msg(PEP_SESSION session, message *msg);
    7.17  
    7.18          // state machine
    7.19