ENGINE-152 ENGINE-153 ENGINE-74 ENGINE-118: merged in default. ENGINE-152
authorKrista Grothoff <krista@pep-project.org>
Tue, 20 Dec 2016 11:23:44 +0100
branchENGINE-152
changeset 1499e841d7759915
parent 1487 1773a82f460d
parent 1496 eacf1934b6cc
child 1500 6cc35643fed0
child 2710 8c044883bf2e
ENGINE-152 ENGINE-153 ENGINE-74 ENGINE-118: merged in default.
     1.1 --- a/build-android/jni/Android.mk	Tue Dec 13 17:16:36 2016 +0100
     1.2 +++ b/build-android/jni/Android.mk	Tue Dec 20 11:23:44 2016 +0100
     1.3 @@ -16,6 +16,10 @@
     1.4  LOCAL_MODULE    := pEpEngine
     1.5  LOCAL_CFLAGS    += -std=c99
     1.6  
     1.7 +ifneq ($(NDEBUG),)
     1.8 +LOCAL_CFLAGS    += -DNDEBUG=1
     1.9 +endif
    1.10 +
    1.11  # from http://www.sqlite.org/android/finfo?name=jni/sqlite/Android.mk 
    1.12  #      http://www.sqlite.org/android/artifact/e8ed354b3e58c835
    1.13  
     2.1 --- a/src/keymanagement.c	Tue Dec 13 17:16:36 2016 +0100
     2.2 +++ b/src/keymanagement.c	Tue Dec 20 11:23:44 2016 +0100
     2.3 @@ -292,7 +292,7 @@
     2.4      free(identity->user_id);
     2.5      identity->user_id = strdup(temp_id->user_id);
     2.6      free(identity->username);
     2.7 -    identity->username = strdup(temp_id->username);
     2.8 +    identity->username = strdup(temp_id->username ? temp_id->username : "anonymous");
     2.9      identity->comm_type = temp_id->comm_type;
    2.10      identity->lang[0] = temp_id->lang[0];
    2.11      identity->lang[1] = temp_id->lang[1];
    2.12 @@ -438,6 +438,15 @@
    2.13              return PEP_OUT_OF_MEMORY;
    2.14      }
    2.15  
    2.16 +    if (EMPTYSTR(identity->username))
    2.17 +    {
    2.18 +        free(identity->username);
    2.19 +        identity->username = strdup("anonymous");
    2.20 +        assert(identity->username);
    2.21 +        if (identity->username == NULL)
    2.22 +            return PEP_OUT_OF_MEMORY;
    2.23 +    }
    2.24 +
    2.25      DEBUG_LOG("myself", "debug", identity->address);
    2.26   
    2.27      status = get_identity(session,
     3.1 --- a/src/sync.c	Tue Dec 13 17:16:36 2016 +0100
     3.2 +++ b/src/sync.c	Tue Dec 20 11:23:44 2016 +0100
     3.3 @@ -170,17 +170,21 @@
     3.4              break;
     3.5          else if(msg == NULL && timeout != 0){
     3.6              status = fsm_DeviceState_inject(session, Timeout, NULL, NULL, &timeout);
     3.7 +#ifndef NDEBUG
     3.8              char buffer[MAX_LINELENGTH];
     3.9              memset(buffer, 0, MAX_LINELENGTH);
    3.10              snprintf(buffer, MAX_LINELENGTH, "problem with timeout event : %d\n", (int) status);
    3.11              log_event(session, buffer, "pEp sync protocol", NULL, NULL);
    3.12              continue;
    3.13 +#endif
    3.14          }
    3.15          else if ((status = receive_sync_msg(session, msg, &timeout) != PEP_STATUS_OK)) {
    3.16 +#ifndef NDEBUG
    3.17              char buffer[MAX_LINELENGTH];
    3.18              memset(buffer, 0, MAX_LINELENGTH);
    3.19              snprintf(buffer, MAX_LINELENGTH, "problem with msg received: %d\n", (int) status);
    3.20              log_event(session, buffer, "pEp sync protocol", NULL, NULL);
    3.21 +#endif
    3.22          }
    3.23      }
    3.24  
     4.1 --- a/src/sync.h	Tue Dec 13 17:16:36 2016 +0100
     4.2 +++ b/src/sync.h	Tue Dec 20 11:23:44 2016 +0100
     4.3 @@ -5,7 +5,7 @@
     4.4  
     4.5  In the engine, KeySync is implemented through a state machine [1]. KeySync
     4.6  state machine is driven [2] by events, triggering actions [3] and transitions
     4.7 -to new states. Events happens on decryption of email messages, on key
     4.8 +to new states. Events happen on decryption of email messages, on key
     4.9  generation, on user interaction through the app and in case of timeout when
    4.10  staying too long in some particular states.
    4.11  
    4.12 @@ -26,7 +26,7 @@
    4.13  collected from decrypted messages. They are jobs to be processed by the state
    4.14  machine.
    4.15  
    4.16 -KeySync messages can be emitted by multiple session, and could naturally come
    4.17 +KeySync messages can be emitted by multiple sessions, and could naturally come
    4.18  from different threads. They must be serialized in a locked queue. Attached
    4.19  sessions inject [8] KeySync messages in the queue. Protocol loop retrieves [9]
    4.20  them from the queue. KeySync message is received [10] by the state machine,
    4.21 @@ -38,7 +38,7 @@
    4.22  passed as a parameter of the call to the blocking queue retrieve operation on 
    4.23  next protocol loop iteraton.
    4.24  
    4.25 -[1] sync/device_group.fsm , src/sync_fsm.c (generated)
    4.26 +[1] sync/devicegroup.fsm , src/sync_fsm.c (generated)
    4.27  [2] src/sync_driver.c (generated)
    4.28  [3] src/sync_actions.c , src/sync_send_actions.c (generated)
    4.29  [4] register_sync_callbacks()
     5.1 --- a/src/sync_impl.c	Tue Dec 13 17:16:36 2016 +0100
     5.2 +++ b/src/sync_impl.c	Tue Dec 20 11:23:44 2016 +0100
     5.3 @@ -484,6 +484,21 @@
     5.4      ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
     5.5  }
     5.6  
     5.7 +
     5.8 +#ifndef NDEBUG
     5.9 +static int _append(const void *buffer, size_t size, void *appkey)
    5.10 +{
    5.11 +    char **dest_ptr = (char **)appkey;
    5.12 +    size_t osize = strlen(*dest_ptr);
    5.13 +    size_t nsize = size + osize;
    5.14 +    *dest_ptr = realloc(*dest_ptr, nsize + 1);
    5.15 +    if(*dest_ptr == NULL) return -1;
    5.16 +    memcpy(*dest_ptr + osize, buffer, size);
    5.17 +    (*dest_ptr)[nsize] = '\0';
    5.18 +    return 0;
    5.19 +}
    5.20 +#endif
    5.21 +
    5.22  PEP_STATUS unicast_msg(
    5.23          PEP_SESSION session,
    5.24          const Identity partner,
    5.25 @@ -566,6 +581,14 @@
    5.26      free_identity(me);
    5.27      me = NULL;
    5.28  
    5.29 +#ifndef NDEBUG
    5.30 +    asn_enc_rval_t er;
    5.31 +    er = xer_encode(&asn_DEF_DeviceGroup_Protocol, msg, 
    5.32 +                    XER_F_BASIC, _append, &_message->longmsg);
    5.33 +    if(er.encoded == -1)
    5.34 +        goto error;
    5.35 +#endif
    5.36 +
    5.37      if (encrypted) {
    5.38          if (msg->payload.present == DeviceGroup_Protocol__payload_PR_groupKeys || 
    5.39              msg->payload.present == DeviceGroup_Protocol__payload_PR_groupUpdate) {
     6.1 --- a/sync/gen_statemachine.ysl2	Tue Dec 13 17:16:36 2016 +0100
     6.2 +++ b/sync/gen_statemachine.ysl2	Tue Dec 20 11:23:44 2016 +0100
     6.3 @@ -217,8 +217,9 @@
     6.4          `` if "count(parm) > 1" error | # TODO composite state payload 
     6.5          `` apply "parm", 1 mode="stateParm"
     6.6          *timeout = «@timeout»;
     6.7 +        DEBUG_LOG("Entering FSM state", "«../@filename»_fsm.c", "state=«@name»")
     6.8          switch (event) {
     6.9 -        `` if "not(event[@name='Init'])" |>> case Init: break;
    6.10 +        `` if "not(event[@name='Init'])" |>> case Init: DEBUG_LOG("FSM event", "«../@filename»_fsm.c, state=«@name»", "event=Init") break;
    6.11          `` apply "event", 2
    6.12              default:
    6.13                  return («../@name»_state) invalid_event;
    6.14 @@ -236,12 +237,14 @@
    6.15      ||
    6.16      case «@name»:
    6.17      {
    6.18 +        DEBUG_LOG("FSM event", "«../../@filename»_fsm.c, state=«../@name»", "event=«@name»")
    6.19      `` apply "action|transition|condition";
    6.20      `` if "name(*[position()=last()]) != 'transition'" |> break;
    6.21      }
    6.22      ||
    6.23  
    6.24      template "action" {
    6.25 +        | DEBUG_LOG("FSM action", "«ancestor::fsm/@filename»_fsm.c, state=«ancestor::state/@name», event=«ancestor::event/@name»", "action=«@name»")
    6.26          indent(0);
    6.27          > status = «@name»(session, state, 
    6.28          choose {
    6.29 @@ -261,6 +264,11 @@
    6.30  
    6.31      template "condition" {
    6.32          | cond_result = «@name»(session`apply "parm", 0`);
    6.33 +        | #ifndef NDEBUG
    6.34 +        | char resstr[11] = {0,};
    6.35 +        | snprintf(resstr,10,"result=%d",cond_result);
    6.36 +        | #endif
    6.37 +        | DEBUG_LOG("FSM condition", "«ancestor::fsm/@filename»_fsm.c, state=«ancestor::state/@name», event=«ancestor::event/@name», condition=«@name»", resstr)
    6.38          | if (cond_result < 0)
    6.39          |> return cond_result;
    6.40          | if (cond_result) {
    6.41 @@ -294,6 +302,7 @@
    6.42              const "nextstateparm", "ancestor::fsm/child::state[@name = $nextstatename]/child::parm";
    6.43              | session->sync_state_payload = «yml:lcase(name($nextstateparm/*))»_dup(«name(parm/*)»);
    6.44          }
    6.45 +        | DEBUG_LOG("FSM transition", "«ancestor::fsm/@filename»_fsm.c, state=«ancestor::state/@name», event=«ancestor::event/@name»", "target=«@target»")
    6.46          | return «@target»;
    6.47      }
    6.48  }
     7.1 --- a/sync/generated/sync_fsm.c	Tue Dec 13 17:16:36 2016 +0100
     7.2 +++ b/sync/generated/sync_fsm.c	Tue Dec 20 11:23:44 2016 +0100
     7.3 @@ -19,15 +19,24 @@
     7.4          case InitState:
     7.5          {
     7.6              *timeout = 0;
     7.7 +            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=InitState")
     7.8              switch (event) {
     7.9                  case Init:
    7.10                  {
    7.11 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=InitState", "event=Init")
    7.12                      cond_result = storedGroupKeys(session);
    7.13 +                    #ifndef NDEBUG
    7.14 +                    char resstr[11] = {0,};
    7.15 +                    snprintf(resstr,10,"result=%d",cond_result);
    7.16 +                    #endif
    7.17 +                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=InitState, event=Init, condition=storedGroupKeys", resstr)
    7.18                      if (cond_result < 0)
    7.19                          return cond_result;
    7.20                      if (cond_result) {
    7.21 +                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=InitState, event=Init", "target=Grouped")
    7.22                          return Grouped;
    7.23                      }
    7.24 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=InitState, event=Init", "target=Sole")
    7.25                      return Sole;
    7.26                  }
    7.27                  default:
    7.28 @@ -38,10 +47,13 @@
    7.29          case Sole:
    7.30          {
    7.31              *timeout = 0;
    7.32 +            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=Sole")
    7.33              switch (event) {
    7.34 -                case Init: break;
    7.35 +                case Init: DEBUG_LOG("FSM event", "sync_fsm.c, state=Sole", "event=Init") break;
    7.36                  case KeyGen:
    7.37                  {
    7.38 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Sole", "event=KeyGen")
    7.39 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Sole, event=KeyGen", "action=sendBeacon")
    7.40                      status = sendBeacon(session, state, NULL, NULL);
    7.41                      if (status == PEP_OUT_OF_MEMORY)
    7.42                          return (int) invalid_out_of_memory;
    7.43 @@ -51,6 +63,8 @@
    7.44                  }
    7.45                  case CannotDecrypt:
    7.46                  {
    7.47 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Sole", "event=CannotDecrypt")
    7.48 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Sole, event=CannotDecrypt", "action=sendBeacon")
    7.49                      status = sendBeacon(session, state, NULL, NULL);
    7.50                      if (status == PEP_OUT_OF_MEMORY)
    7.51                          return (int) invalid_out_of_memory;
    7.52 @@ -60,6 +74,8 @@
    7.53                  }
    7.54                  case Beacon:
    7.55                  {
    7.56 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Sole", "event=Beacon")
    7.57 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Sole, event=Beacon", "action=sendHandshakeRequest")
    7.58                      status = sendHandshakeRequest(session, state, partner, NULL);
    7.59                      if (status == PEP_OUT_OF_MEMORY)
    7.60                          return (int) invalid_out_of_memory;
    7.61 @@ -69,12 +85,15 @@
    7.62                  }
    7.63                  case HandshakeRequest:
    7.64                  {
    7.65 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Sole", "event=HandshakeRequest")
    7.66 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Sole, event=HandshakeRequest", "action=sendHandshakeRequest")
    7.67                      status = sendHandshakeRequest(session, state, partner, NULL);
    7.68                      if (status == PEP_OUT_OF_MEMORY)
    7.69                          return (int) invalid_out_of_memory;
    7.70                      if (status != PEP_STATUS_OK)
    7.71                          return (int) invalid_action;
    7.72                      session->sync_state_payload = identity_dup(partner);
    7.73 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Sole, event=HandshakeRequest", "target=HandshakingSole")
    7.74                      return HandshakingSole;
    7.75                  }
    7.76                  default:
    7.77 @@ -86,13 +105,21 @@
    7.78          {
    7.79              Identity expected = (Identity)session->sync_state_payload;
    7.80              *timeout = 600;
    7.81 +            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=HandshakingSole")
    7.82              switch (event) {
    7.83                  case Init:
    7.84                  {
    7.85 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=Init")
    7.86                      cond_result = keyElectionWon(session, partner);
    7.87 +                    #ifndef NDEBUG
    7.88 +                    char resstr[11] = {0,};
    7.89 +                    snprintf(resstr,10,"result=%d",cond_result);
    7.90 +                    #endif
    7.91 +                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=Init, condition=keyElectionWon", resstr)
    7.92                      if (cond_result < 0)
    7.93                          return cond_result;
    7.94                      if (cond_result) {
    7.95 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Init", "action=notifyInitFormGroup")
    7.96                          status = notifyInitFormGroup(session, state, partner, NULL);
    7.97                          if (status == PEP_OUT_OF_MEMORY)
    7.98                              return (int) invalid_out_of_memory;
    7.99 @@ -100,6 +127,7 @@
   7.100                              return (int) invalid_action;
   7.101                      }
   7.102                      else {
   7.103 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Init", "action=notifyInitAddOurDevice")
   7.104                          status = notifyInitAddOurDevice(session, state, partner, NULL);
   7.105                          if (status == PEP_OUT_OF_MEMORY)
   7.106                              return (int) invalid_out_of_memory;
   7.107 @@ -110,6 +138,8 @@
   7.108                  }
   7.109                  case HandshakeRejected:
   7.110                  {
   7.111 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=HandshakeRejected")
   7.112 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeRejected", "action=rejectHandshake")
   7.113                      status = rejectHandshake(session, state, partner, NULL);
   7.114                      if (status == PEP_OUT_OF_MEMORY)
   7.115                          return (int) invalid_out_of_memory;
   7.116 @@ -119,24 +149,34 @@
   7.117                          free_identity((Identity)session->sync_state_payload);
   7.118                          session->sync_state_payload = NULL;
   7.119                      }
   7.120 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeRejected", "target=Sole")
   7.121                      return Sole;
   7.122                  }
   7.123                  case HandshakeAccepted:
   7.124                  {
   7.125 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=HandshakeAccepted")
   7.126 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=acceptHandshake")
   7.127                      status = acceptHandshake(session, state, partner, NULL);
   7.128                      if (status == PEP_OUT_OF_MEMORY)
   7.129                          return (int) invalid_out_of_memory;
   7.130                      if (status != PEP_STATUS_OK)
   7.131                          return (int) invalid_action;
   7.132                      cond_result = keyElectionWon(session, partner);
   7.133 +                    #ifndef NDEBUG
   7.134 +                    char resstr[11] = {0,};
   7.135 +                    snprintf(resstr,10,"result=%d",cond_result);
   7.136 +                    #endif
   7.137 +                    DEBUG_LOG("FSM condition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted, condition=keyElectionWon", resstr)
   7.138                      if (cond_result < 0)
   7.139                          return cond_result;
   7.140                      if (cond_result) {
   7.141 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=sendGroupKeys")
   7.142                          status = sendGroupKeys(session, state, partner, NULL);
   7.143                          if (status == PEP_OUT_OF_MEMORY)
   7.144                              return (int) invalid_out_of_memory;
   7.145                          if (status != PEP_STATUS_OK)
   7.146                              return (int) invalid_action;
   7.147 +                        DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "action=notifyAcceptedGroupCreated")
   7.148                          status = notifyAcceptedGroupCreated(session, state, partner, NULL);
   7.149                          if (status == PEP_OUT_OF_MEMORY)
   7.150                              return (int) invalid_out_of_memory;
   7.151 @@ -146,6 +186,7 @@
   7.152                              free_identity((Identity)session->sync_state_payload);
   7.153                              session->sync_state_payload = NULL;
   7.154                          }
   7.155 +                        DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "target=Grouped")
   7.156                          return Grouped;
   7.157                      }
   7.158                      if(session->sync_state_payload){
   7.159 @@ -153,18 +194,23 @@
   7.160                          session->sync_state_payload = NULL;
   7.161                      }
   7.162                      session->sync_state_payload = identity_dup(partner);
   7.163 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=HandshakeAccepted", "target=WaitForGroupKeysSole")
   7.164                      return WaitForGroupKeysSole;
   7.165                  }
   7.166                  case Cancel:
   7.167                  {
   7.168 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=Cancel")
   7.169                      if(session->sync_state_payload){
   7.170                          free_identity((Identity)session->sync_state_payload);
   7.171                          session->sync_state_payload = NULL;
   7.172                      }
   7.173 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=Cancel", "target=Sole")
   7.174                      return Sole;
   7.175                  }
   7.176                  case Timeout:
   7.177                  {
   7.178 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingSole", "event=Timeout")
   7.179 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingSole, event=Timeout", "action=notifyTimeout")
   7.180                      status = notifyTimeout(session, state, expected, NULL);
   7.181                      if (status == PEP_OUT_OF_MEMORY)
   7.182                          return (int) invalid_out_of_memory;
   7.183 @@ -174,6 +220,7 @@
   7.184                          free_identity((Identity)session->sync_state_payload);
   7.185                          session->sync_state_payload = NULL;
   7.186                      }
   7.187 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingSole, event=Timeout", "target=Sole")
   7.188                      return Sole;
   7.189                  }
   7.190                  default:
   7.191 @@ -185,15 +232,19 @@
   7.192          {
   7.193              Identity expected = (Identity)session->sync_state_payload;
   7.194              *timeout = 600;
   7.195 +            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=WaitForGroupKeysSole")
   7.196              switch (event) {
   7.197 -                case Init: break;
   7.198 +                case Init: DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=Init") break;
   7.199                  case GroupKeys:
   7.200                  {
   7.201 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=GroupKeys")
   7.202 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=storeGroupKeys")
   7.203                      status = storeGroupKeys(session, state, partner, extra /*keys*/);
   7.204                      if (status == PEP_OUT_OF_MEMORY)
   7.205                          return (int) invalid_out_of_memory;
   7.206                      if (status != PEP_STATUS_OK)
   7.207                          return (int) invalid_action;
   7.208 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "action=notifyAcceptedDeviceAdded")
   7.209                      status = notifyAcceptedDeviceAdded(session, state, partner, NULL);
   7.210                      if (status == PEP_OUT_OF_MEMORY)
   7.211                          return (int) invalid_out_of_memory;
   7.212 @@ -203,10 +254,13 @@
   7.213                          free_identity((Identity)session->sync_state_payload);
   7.214                          session->sync_state_payload = NULL;
   7.215                      }
   7.216 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysSole, event=GroupKeys", "target=Grouped")
   7.217                      return Grouped;
   7.218                  }
   7.219                  case Timeout:
   7.220                  {
   7.221 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=WaitForGroupKeysSole", "event=Timeout")
   7.222 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=WaitForGroupKeysSole, event=Timeout", "action=notifyTimeout")
   7.223                      status = notifyTimeout(session, state, expected, NULL);
   7.224                      if (status == PEP_OUT_OF_MEMORY)
   7.225                          return (int) invalid_out_of_memory;
   7.226 @@ -216,6 +270,7 @@
   7.227                          free_identity((Identity)session->sync_state_payload);
   7.228                          session->sync_state_payload = NULL;
   7.229                      }
   7.230 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=WaitForGroupKeysSole, event=Timeout", "target=Sole")
   7.231                      return Sole;
   7.232                  }
   7.233                  default:
   7.234 @@ -226,9 +281,12 @@
   7.235          case Grouped:
   7.236          {
   7.237              *timeout = 0;
   7.238 +            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=Grouped")
   7.239              switch (event) {
   7.240                  case Init:
   7.241                  {
   7.242 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=Init")
   7.243 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=Init", "action=enterGroup")
   7.244                      status = enterGroup(session, state, NULL, NULL);
   7.245                      if (status == PEP_OUT_OF_MEMORY)
   7.246                          return (int) invalid_out_of_memory;
   7.247 @@ -238,6 +296,8 @@
   7.248                  }
   7.249                  case KeyGen:
   7.250                  {
   7.251 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=KeyGen")
   7.252 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=KeyGen", "action=sendGroupUpdate")
   7.253                      status = sendGroupUpdate(session, state, NULL, NULL);
   7.254                      if (status == PEP_OUT_OF_MEMORY)
   7.255                          return (int) invalid_out_of_memory;
   7.256 @@ -247,6 +307,8 @@
   7.257                  }
   7.258                  case CannotDecrypt:
   7.259                  {
   7.260 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=CannotDecrypt")
   7.261 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=CannotDecrypt", "action=sendUpdateRequest")
   7.262                      status = sendUpdateRequest(session, state, NULL, NULL);
   7.263                      if (status == PEP_OUT_OF_MEMORY)
   7.264                          return (int) invalid_out_of_memory;
   7.265 @@ -256,6 +318,8 @@
   7.266                  }
   7.267                  case UpdateRequest:
   7.268                  {
   7.269 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=UpdateRequest")
   7.270 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=UpdateRequest", "action=sendGroupUpdate")
   7.271                      status = sendGroupUpdate(session, state, NULL, NULL);
   7.272                      if (status == PEP_OUT_OF_MEMORY)
   7.273                          return (int) invalid_out_of_memory;
   7.274 @@ -265,6 +329,8 @@
   7.275                  }
   7.276                  case Beacon:
   7.277                  {
   7.278 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=Beacon")
   7.279 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=Beacon", "action=sendHandshakeRequest")
   7.280                      status = sendHandshakeRequest(session, state, partner, NULL);
   7.281                      if (status == PEP_OUT_OF_MEMORY)
   7.282                          return (int) invalid_out_of_memory;
   7.283 @@ -274,16 +340,21 @@
   7.284                  }
   7.285                  case HandshakeRequest:
   7.286                  {
   7.287 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=HandshakeRequest")
   7.288 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=HandshakeRequest", "action=sendHandshakeRequest")
   7.289                      status = sendHandshakeRequest(session, state, partner, NULL);
   7.290                      if (status == PEP_OUT_OF_MEMORY)
   7.291                          return (int) invalid_out_of_memory;
   7.292                      if (status != PEP_STATUS_OK)
   7.293                          return (int) invalid_action;
   7.294                      session->sync_state_payload = identity_dup(partner);
   7.295 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=Grouped, event=HandshakeRequest", "target=HandshakingGrouped")
   7.296                      return HandshakingGrouped;
   7.297                  }
   7.298                  case GroupUpdate:
   7.299                  {
   7.300 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=Grouped", "event=GroupUpdate")
   7.301 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=Grouped, event=GroupUpdate", "action=storeGroupKeys")
   7.302                      status = storeGroupKeys(session, state, partner, extra /*keys*/);
   7.303                      if (status == PEP_OUT_OF_MEMORY)
   7.304                          return (int) invalid_out_of_memory;
   7.305 @@ -300,9 +371,12 @@
   7.306          {
   7.307              Identity expected = (Identity)session->sync_state_payload;
   7.308              *timeout = 600;
   7.309 +            DEBUG_LOG("Entering FSM state", "sync_fsm.c", "state=HandshakingGrouped")
   7.310              switch (event) {
   7.311                  case Init:
   7.312                  {
   7.313 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=Init")
   7.314 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=Init", "action=notifyInitAddOurDevice")
   7.315                      status = notifyInitAddOurDevice(session, state, partner, NULL);
   7.316                      if (status == PEP_OUT_OF_MEMORY)
   7.317                          return (int) invalid_out_of_memory;
   7.318 @@ -312,6 +386,8 @@
   7.319                  }
   7.320                  case HandshakeRejected:
   7.321                  {
   7.322 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=HandshakeRejected")
   7.323 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeRejected", "action=rejectHandshake")
   7.324                      status = rejectHandshake(session, state, partner, NULL);
   7.325                      if (status == PEP_OUT_OF_MEMORY)
   7.326                          return (int) invalid_out_of_memory;
   7.327 @@ -321,15 +397,19 @@
   7.328                          free_identity((Identity)session->sync_state_payload);
   7.329                          session->sync_state_payload = NULL;
   7.330                      }
   7.331 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeRejected", "target=Grouped")
   7.332                      return Grouped;
   7.333                  }
   7.334                  case HandshakeAccepted:
   7.335                  {
   7.336 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=HandshakeAccepted")
   7.337 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "action=acceptHandshake")
   7.338                      status = acceptHandshake(session, state, partner, NULL);
   7.339                      if (status == PEP_OUT_OF_MEMORY)
   7.340                          return (int) invalid_out_of_memory;
   7.341                      if (status != PEP_STATUS_OK)
   7.342                          return (int) invalid_action;
   7.343 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "action=sendGroupKeys")
   7.344                      status = sendGroupKeys(session, state, partner, NULL);
   7.345                      if (status == PEP_OUT_OF_MEMORY)
   7.346                          return (int) invalid_out_of_memory;
   7.347 @@ -339,10 +419,13 @@
   7.348                          free_identity((Identity)session->sync_state_payload);
   7.349                          session->sync_state_payload = NULL;
   7.350                      }
   7.351 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=HandshakeAccepted", "target=Grouped")
   7.352                      return Grouped;
   7.353                  }
   7.354                  case Timeout:
   7.355                  {
   7.356 +                    DEBUG_LOG("FSM event", "sync_fsm.c, state=HandshakingGrouped", "event=Timeout")
   7.357 +                    DEBUG_LOG("FSM action", "sync_fsm.c, state=HandshakingGrouped, event=Timeout", "action=notifyTimeout")
   7.358                      status = notifyTimeout(session, state, expected, NULL);
   7.359                      if (status == PEP_OUT_OF_MEMORY)
   7.360                          return (int) invalid_out_of_memory;
   7.361 @@ -352,6 +435,7 @@
   7.362                          free_identity((Identity)session->sync_state_payload);
   7.363                          session->sync_state_payload = NULL;
   7.364                      }
   7.365 +                    DEBUG_LOG("FSM transition", "sync_fsm.c, state=HandshakingGrouped, event=Timeout", "target=Grouped")
   7.366                      return Grouped;
   7.367                  }
   7.368                  default:
     8.1 --- a/test/trustwords_test.cc	Tue Dec 13 17:16:36 2016 +0100
     8.2 +++ b/test/trustwords_test.cc	Tue Dec 20 11:23:44 2016 +0100
     8.3 @@ -1,22 +1,23 @@
     8.4  #include <iostream>
     8.5  #include <string>
     8.6 -#include <assert.h>
     8.7 +#include <cassert>
     8.8  #include "pEpEngine.h"
     8.9  #include "message_api.h"
    8.10  
    8.11  using namespace std;
    8.12  
    8.13 +
    8.14  int main() {
    8.15      cout << "\n*** get_trustwords test ***\n\n";
    8.16  
    8.17 -    PEP_SESSION session;
    8.18 +    PEP_SESSION session = nullptr;
    8.19      
    8.20      cout << "calling init()\n";
    8.21 -    PEP_STATUS status1 = init(&session);   
    8.22 +    PEP_STATUS status1 = init(&session);
    8.23      assert(status1 == PEP_STATUS_OK);
    8.24      assert(session);
    8.25      cout << "init() completed.\n";
    8.26 -        
    8.27 +    
    8.28      pEp_identity* identity1  = new_identity(
    8.29          "leon.schumacher@digitalekho.com",
    8.30          "8BD08954C74D830EEFFB5DEB2682A17F7C87F73D",
    8.31 @@ -31,12 +32,12 @@
    8.32      
    8.33      string fingerprint1 = identity1->fpr;
    8.34      string fingerprint2 = identity2->fpr;
    8.35 -    char* words1;
    8.36 -    char* words2;
    8.37 -    char* full_wordlist;
    8.38 -    size_t wsize1;
    8.39 -    size_t wsize2;
    8.40 -    size_t wsize_full;
    8.41 +    char* words1 = nullptr;
    8.42 +    char* words2 = nullptr;
    8.43 +    char* full_wordlist = nullptr;
    8.44 +    size_t wsize1 = 0;
    8.45 +    size_t wsize2 = 0;
    8.46 +    size_t wsize_full = 0;
    8.47      
    8.48      cout << "\nTest 1: fpr1 > fpr2, short" << endl;
    8.49      
    8.50 @@ -57,8 +58,11 @@
    8.51      
    8.52      
    8.53      pEp_free(words1);
    8.54 +    words1 = nullptr;
    8.55      pEp_free(words2);
    8.56 +    words2 = nullptr;
    8.57      pEp_free(full_wordlist);
    8.58 +    full_wordlist = nullptr;
    8.59  
    8.60      cout << "\nTest 2: fpr1 == fpr1, short" << endl;
    8.61      
    8.62 @@ -73,7 +77,9 @@
    8.63      cout << full_wordlist << "\n";
    8.64  
    8.65      pEp_free(words1);
    8.66 +    words1 = nullptr;
    8.67      pEp_free(full_wordlist);
    8.68 +    full_wordlist = nullptr;
    8.69  
    8.70      cout << "\nTest 3: fpr1 < fpr2, long" << endl;
    8.71      
    8.72 @@ -93,9 +99,11 @@
    8.73      cout << full_wordlist << "\n";
    8.74      
    8.75      pEp_free(words1);
    8.76 +    words1 = nullptr;
    8.77      pEp_free(words2);
    8.78 +    words2 = nullptr;
    8.79      pEp_free(full_wordlist);
    8.80 -    
    8.81 +    full_wordlist = nullptr;
    8.82      
    8.83      cout << "\nTest 4: fpr1 < fpr2, leading zeros (fpr1 has more), long" << endl;
    8.84      
    8.85 @@ -137,8 +145,11 @@
    8.86      cout << full_wordlist << "\n";
    8.87  
    8.88      pEp_free(words1);
    8.89 +    words1 = nullptr;
    8.90      pEp_free(words2);
    8.91 +    words2 = nullptr;
    8.92      pEp_free(full_wordlist);
    8.93 +    full_wordlist = nullptr;
    8.94  
    8.95      cout << "\nTest 5: fpr1 > fpr2, leading zeros (same number), interior digit difference, short" << endl;
    8.96      
    8.97 @@ -158,8 +169,11 @@
    8.98      cout << full_wordlist << "\n";
    8.99      
   8.100      pEp_free(words1);
   8.101 +    words1 = nullptr;
   8.102      pEp_free(words2);
   8.103 +    words2 = nullptr;
   8.104      pEp_free(full_wordlist);
   8.105 +    full_wordlist = nullptr;
   8.106  
   8.107      cout << "\nTest 6: fpr2 is too short" << endl;
   8.108      
   8.109 @@ -188,13 +202,13 @@
   8.110      cout << "Illegal digit value correctly recognised." << "\n";
   8.111      
   8.112      
   8.113 -    free(identity1);
   8.114 -    free(identity2);
   8.115 -    free(identity3);
   8.116 -    free(identity4);
   8.117 -    free(identity5);
   8.118 -    free(identity6);
   8.119 -    free(identity7);
   8.120 +    free_identity(identity1);
   8.121 +    free_identity(identity2);
   8.122 +    free_identity(identity3);
   8.123 +    free_identity(identity4);
   8.124 +    free_identity(identity5);
   8.125 +    free_identity(identity6);
   8.126 +    free_identity(identity7);
   8.127      
   8.128      cout << "calling release()\n";
   8.129      release(session);