sync: distinguish management pointer (for queuing sync_messages, i.e. sync job 'management') from obj pointer (for sending email messages, notifying user, alias sync 'object'), thus following original design convention ENGINE-133
authorEdouard Tisserant <edouard@pep-project.org>
Wed, 07 Dec 2016 15:39:06 +0100
branchENGINE-133
changeset 1462b93663bfc7c6
parent 1460 66ceb5a7f718
child 1463 be664aafb70e
child 1464 173d47d14f17
sync: distinguish management pointer (for queuing sync_messages, i.e. sync job 'management') from obj pointer (for sending email messages, notifying user, alias sync 'object'), thus following original design convention
src/pEp_internal.h
src/sync.c
src/sync.h
src/sync_impl.c
     1.1 --- a/src/pEp_internal.h	Sun Dec 04 02:51:59 2016 +0100
     1.2 +++ b/src/pEp_internal.h	Wed Dec 07 15:39:06 2016 +0100
     1.3 @@ -134,6 +134,7 @@
     1.4      // callbacks
     1.5      examine_identity_t examine_identity;
     1.6      void *examine_management;
     1.7 +    void *sync_management;
     1.8      void *sync_obj;
     1.9      messageToSend_t messageToSend;
    1.10      notifyHandshake_t notifyHandshake;
     2.1 --- a/src/sync.c	Sun Dec 04 02:51:59 2016 +0100
     2.2 +++ b/src/sync.c	Wed Dec 07 15:39:06 2016 +0100
     2.3 @@ -16,22 +16,22 @@
     2.4  
     2.5  DYNAMIC_API PEP_STATUS register_sync_callbacks(
     2.6          PEP_SESSION session,
     2.7 -        void *obj,
     2.8 +        void *management,
     2.9          messageToSend_t messageToSend,
    2.10          notifyHandshake_t notifyHandshake,
    2.11          inject_sync_msg_t inject_sync_msg,
    2.12          retrieve_next_sync_msg_t retrieve_next_sync_msg
    2.13      )
    2.14  {
    2.15 -    assert(session && obj && messageToSend && notifyHandshake && inject_sync_msg && retrieve_next_sync_msg);
    2.16 -    if (!(session && obj && messageToSend && notifyHandshake && inject_sync_msg && retrieve_next_sync_msg))
    2.17 +    assert(session && management && messageToSend && notifyHandshake && inject_sync_msg && retrieve_next_sync_msg);
    2.18 +    if (!(session && management && messageToSend && notifyHandshake && inject_sync_msg && retrieve_next_sync_msg))
    2.19          return PEP_ILLEGAL_VALUE;
    2.20  
    2.21      pEpUUID uuid;
    2.22      uuid_generate_random(uuid);
    2.23      uuid_unparse_upper(uuid, session->sync_uuid);
    2.24  
    2.25 -    session->sync_obj = obj;
    2.26 +    session->sync_management = management;
    2.27      session->messageToSend = messageToSend;
    2.28      session->notifyHandshake = notifyHandshake;
    2.29      session->inject_sync_msg = inject_sync_msg;
    2.30 @@ -52,13 +52,13 @@
    2.31          PEP_SESSION sync_session
    2.32      )
    2.33  {
    2.34 -    assert(session && sync_session && sync_session->sync_obj && sync_session->inject_sync_msg );
    2.35 -    if (!(session && sync_session && sync_session->sync_obj && sync_session->inject_sync_msg ))
    2.36 +    assert(session && sync_session && sync_session->sync_management && sync_session->inject_sync_msg );
    2.37 +    if (!(session && sync_session && sync_session->sync_management && sync_session->inject_sync_msg ))
    2.38          return PEP_ILLEGAL_VALUE;
    2.39  
    2.40      memcpy(session->sync_uuid, sync_session->sync_uuid, 37);
    2.41  
    2.42 -    session->sync_obj = sync_session->sync_obj;
    2.43 +    session->sync_management = sync_session->sync_management;
    2.44      session->inject_sync_msg = sync_session->inject_sync_msg;
    2.45  
    2.46      return PEP_STATUS_OK;
    2.47 @@ -66,13 +66,13 @@
    2.48  
    2.49  DYNAMIC_API PEP_STATUS detach_sync_session(PEP_SESSION session)
    2.50  {
    2.51 -    assert(session && session->sync_obj && session->inject_sync_msg );
    2.52 -    if (!(session && session->sync_obj && session->inject_sync_msg ))
    2.53 +    assert(session && session->sync_management && session->inject_sync_msg );
    2.54 +    if (!(session && session->sync_management && session->inject_sync_msg ))
    2.55          return PEP_ILLEGAL_VALUE;
    2.56  
    2.57      memset(session->sync_uuid, 0, 37);
    2.58  
    2.59 -    session->sync_obj = NULL;
    2.60 +    session->sync_management = NULL;
    2.61      session->inject_sync_msg = NULL;
    2.62  
    2.63      return PEP_STATUS_OK;
    2.64 @@ -80,8 +80,8 @@
    2.65  
    2.66  int call_inject_sync_msg(PEP_SESSION session, void *msg)
    2.67  {
    2.68 -    if(session->inject_sync_msg && session->sync_obj)
    2.69 -        return session->inject_sync_msg(msg, session->sync_obj);
    2.70 +    if(session->inject_sync_msg && session->sync_management)
    2.71 +        return session->inject_sync_msg(msg, session->sync_management);
    2.72      else
    2.73         return PEP_SYNC_NO_INJECT_CALLBACK;
    2.74  }
    2.75 @@ -91,7 +91,7 @@
    2.76      session->sync_state = DeviceState_state_NONE;
    2.77  
    2.78      // unregister
    2.79 -    session->sync_obj = NULL;
    2.80 +    session->sync_management = NULL;
    2.81      session->messageToSend = NULL;
    2.82      session->notifyHandshake = NULL;
    2.83      session->inject_sync_msg = NULL;
    2.84 @@ -146,7 +146,7 @@
    2.85  
    2.86  DYNAMIC_API PEP_STATUS do_sync_protocol(
    2.87          PEP_SESSION session,
    2.88 -        void *management
    2.89 +        void *obj
    2.90      )
    2.91  {
    2.92      sync_msg_t *msg = NULL;
    2.93 @@ -154,16 +154,18 @@
    2.94      time_t timeout = 0;
    2.95  
    2.96      assert(session && session->retrieve_next_sync_msg);
    2.97 -    assert(management);
    2.98 +    assert(obj);
    2.99  
   2.100 -    if (!(session && session->retrieve_next_sync_msg) || !management)
   2.101 +    if (!(session && session->retrieve_next_sync_msg) || !obj)
   2.102          return PEP_ILLEGAL_VALUE;
   2.103  
   2.104      log_event(session, "sync_protocol thread started", "pEp sync protocol", NULL, NULL);
   2.105  
   2.106 +    session->sync_obj = obj;
   2.107 +
   2.108      while (true) 
   2.109      {
   2.110 -        msg = (sync_msg_t *) session->retrieve_next_sync_msg(management, &timeout);
   2.111 +        msg = (sync_msg_t *) session->retrieve_next_sync_msg(session->sync_management, &timeout);
   2.112          if(msg == NULL && timeout == 0)
   2.113              break;
   2.114          else if(msg == NULL && timeout != 0){
   2.115 @@ -184,6 +186,8 @@
   2.116  
   2.117      log_event(session, "sync_protocol thread shutdown", "pEp sync protocol", NULL, NULL);
   2.118  
   2.119 +    session->sync_obj = NULL;
   2.120 +
   2.121      return PEP_STATUS_OK;
   2.122  }
   2.123  
     3.1 --- a/src/sync.h	Sun Dec 04 02:51:59 2016 +0100
     3.2 +++ b/src/sync.h	Wed Dec 07 15:39:06 2016 +0100
     3.3 @@ -107,9 +107,9 @@
     3.4  //
     3.5  //  parameters:
     3.6  //      session (in)                session where to store obj handle
     3.7 -//      obj (in)                    object handle (implementation defined)
     3.8 +//      management (in)             application defined
     3.9  //      messageToSend (in)          callback for sending message
    3.10 -//      notifyHandshake (in)          callback for doing the handshake
    3.11 +//      notifyHandshake (in)        callback for doing the handshake
    3.12  //      retrieve_next_sync_msg (in) callback for receiving sync messages
    3.13  //
    3.14  //  return value:
    3.15 @@ -120,7 +120,7 @@
    3.16  
    3.17  DYNAMIC_API PEP_STATUS register_sync_callbacks(
    3.18          PEP_SESSION session,
    3.19 -        void *obj,
    3.20 +        void *management,
    3.21          messageToSend_t messageToSend,
    3.22          notifyHandshake_t notifyHandshake,
    3.23          inject_sync_msg_t inject_sync_msg,
    3.24 @@ -166,8 +166,7 @@
    3.25  //      retrieve_next_sync_msg  pointer to retrieve_next_identity() callback
    3.26  //                              which returns at least a valid address field in
    3.27  //                              the identity struct
    3.28 -//      management              management data to give to keymanagement
    3.29 -//                              (implementation defined)
    3.30 +//      obj                     application defined sync object
    3.31  //
    3.32  //  return value:
    3.33  //      PEP_STATUS_OK if thread has to terminate successfully or any other
    3.34 @@ -176,11 +175,10 @@
    3.35  //  caveat:
    3.36  //      to ensure proper working of this library, a thread has to be started
    3.37  //      with this function immediately after initialization
    3.38 -//      do_keymanagement() calls retrieve_next_identity(management)
    3.39  
    3.40  DYNAMIC_API PEP_STATUS do_sync_protocol(
    3.41          PEP_SESSION session,
    3.42 -        void *management
    3.43 +        void *obj
    3.44      );
    3.45  
    3.46  // free_sync_msg() - free sync_msg_t struct when not passed to do_sync_protocol  
     4.1 --- a/src/sync_impl.c	Sun Dec 04 02:51:59 2016 +0100
     4.2 +++ b/src/sync_impl.c	Wed Dec 07 15:39:06 2016 +0100
     4.3 @@ -646,7 +646,6 @@
     4.4      if (status != PEP_STATUS_OK)
     4.5          return status;
     4.6  
     4.7 -    // FIXME: exclude previously rejected identities
     4.8      for (identity_list *_i = own_identities; _i && _i->ident; _i = _i->next) {
     4.9          pEp_identity *me = _i->ident;
    4.10