add state HandshakeRequested sync
authorVolker Birk <vb@pep-project.org>
Fri, 15 Mar 2019 22:29:23 +0100
branchsync
changeset 334118d3eed4c32f
parent 3340 4b4b1262b415
child 3344 1f1e81725e53
add state HandshakeRequested
src/message_api.c
sync/gen_statemachine.ysl2
sync/sync.fsm
     1.1 --- a/src/message_api.c	Fri Mar 15 17:21:19 2019 +0100
     1.2 +++ b/src/message_api.c	Fri Mar 15 22:29:23 2019 +0100
     1.3 @@ -3855,16 +3855,22 @@
     1.4          char *sync_fpr = NULL;
     1.5          PEP_STATUS tmpstatus = base_extract_message(session, msg, &size, &data, &sync_fpr);
     1.6          if (!tmpstatus && size && data) {
     1.7 -            pEp_identity *_from = identity_dup(msg->from);
     1.8 -            if (!_from) {
     1.9 -                free_message(*dst);
    1.10 -                *dst = NULL;
    1.11 -                free_stringlist(*keylist);
    1.12 -                *keylist = NULL;
    1.13 -                return PEP_OUT_OF_MEMORY;
    1.14 +            if ((*keylist && strcasecmp(msg->from->fpr, (*keylist)->value))
    1.15 +                    || (sync_fpr && strcasecmp(msg->from->fpr, sync_fpr))) {
    1.16 +                pEp_identity *_from = identity_dup(msg->from);
    1.17 +                if (!_from) {
    1.18 +                    free_message(*dst);
    1.19 +                    *dst = NULL;
    1.20 +                    free_stringlist(*keylist);
    1.21 +                    *keylist = NULL;
    1.22 +                    free(sync_fpr);
    1.23 +                    return PEP_OUT_OF_MEMORY;
    1.24 +                }
    1.25 +                if (session->sync_state.common.from)
    1.26 +                    free_identity(session->sync_state.common.from);
    1.27 +                session->sync_state.common.from = _from;
    1.28 +                signal_Sync_message(session, *rating, data, size, sync_fpr);
    1.29              }
    1.30 -            session->sync_state.common.from = _from;
    1.31 -            signal_Sync_message(session, *rating, data, size, sync_fpr);
    1.32          }
    1.33          free(sync_fpr);
    1.34      }
     2.1 --- a/sync/gen_statemachine.ysl2	Fri Mar 15 17:21:19 2019 +0100
     2.2 +++ b/sync/gen_statemachine.ysl2	Fri Mar 15 22:29:23 2019 +0100
     2.3 @@ -321,23 +321,9 @@
     2.4                  if (!session->inject_«yml:lcase(@name)»_event)
     2.5                     return PEP_«yml:ucase(@name)»_NO_INJECT_CALLBACK;
     2.6  
     2.7 -                «@name»_t *msg = NULL;
     2.8 -                PEP_STATUS status = decode_«@name»_message(data, size, &msg);
     2.9 -                if (status)
    2.10 -                    return status;
    2.11 -
    2.12 +                PEP_STATUS status = PEP_STATUS_OK;
    2.13                  «@name»_event_t *ev = NULL;
    2.14  
    2.15 -                «@name»_PR fsm = msg->present;
    2.16 -                int event = 0;
    2.17 -
    2.18 -                switch (fsm) {
    2.19 -                    `` apply "fsm", 2, mode=signal_message
    2.20 -                    default:
    2.21 -                        status = PEP_«yml:ucase(@name)»_ILLEGAL_MESSAGE;
    2.22 -                        goto the_end;
    2.23 -                }
    2.24 -
    2.25                  if (fpr) {
    2.26                      if (session->«yml:lcase(@name)»_state.common.from->fpr)
    2.27                          free(session->«yml:lcase(@name)»_state.common.from->fpr);
    2.28 @@ -349,6 +335,21 @@
    2.29                      }
    2.30                  }
    2.31  
    2.32 +                «@name»_t *msg = NULL;
    2.33 +                status = decode_«@name»_message(data, size, &msg);
    2.34 +                if (status)
    2.35 +                    return status;
    2.36 +
    2.37 +                «@name»_PR fsm = msg->present;
    2.38 +                int event = 0;
    2.39 +
    2.40 +                switch (fsm) {
    2.41 +                    `` apply "fsm", 2, mode=signal_message
    2.42 +                    default:
    2.43 +                        status = PEP_«yml:ucase(@name)»_ILLEGAL_MESSAGE;
    2.44 +                        goto the_end;
    2.45 +                }
    2.46 +
    2.47                  ev = new_«@name»_event(fsm, event, msg);
    2.48                  if (!ev) {
    2.49                      status = PEP_OUT_OF_MEMORY;
     3.1 --- a/sync/sync.fsm	Fri Mar 15 17:21:19 2019 +0100
     3.2 +++ b/sync/sync.fsm	Fri Mar 15 22:29:23 2019 +0100
     3.3 @@ -42,6 +42,7 @@
     3.4                      do openTransaction;
     3.5                      do storeTransaction;
     3.6                      send HandshakeRequest;
     3.7 +                    go HandshakeRequested;
     3.8                  }
     3.9              }
    3.10  
    3.11 @@ -56,6 +57,9 @@
    3.12                  }
    3.13              }
    3.14  
    3.15 +        }
    3.16 +
    3.17 +        state HandshakeRequested {
    3.18              on HandshakeAnswer
    3.19                  go HandshakingNew();
    3.20          }