Browse Source

empty address allowed for myself()

doc_update_sequoia
Volker Birk 6 years ago
parent
commit
becce8c271
9 changed files with 166 additions and 49 deletions
  1. +15
    -9
      src/keymanagement.c
  2. +2
    -0
      src/pEp_internal.h
  3. +48
    -4
      src/sync.c
  4. +55
    -4
      src/sync.h
  5. +2
    -2
      src/sync_actions.c
  6. +1
    -1
      src/sync_driver.c
  7. +26
    -26
      src/sync_fsm.c
  8. +7
    -0
      src/sync_fsm.h
  9. +10
    -3
      sync/gen_statemachine.ysl2

+ 15
- 9
src/keymanagement.c View File

@ -356,31 +356,37 @@ DYNAMIC_API PEP_STATUS myself(PEP_SESSION session, pEp_identity * identity)
assert(session);
assert(identity);
assert(identity->address);
assert(identity->username);
assert(EMPTYSTR(identity->user_id) ||
strcmp(identity->user_id, PEP_OWN_USERID) == 0);
if (!(session && identity && identity->address && identity->username &&
(EMPTYSTR(identity->user_id) ||
strcmp(identity->user_id, PEP_OWN_USERID) == 0)))
if (!(session && identity &&
(EMPTYSTR(identity->user_id) ||
strcmp(identity->user_id, PEP_OWN_USERID) == 0)))
return PEP_ILLEGAL_VALUE;
identity->comm_type = PEP_ct_pEp;
identity->me = true;
if(EMPTYSTR(identity->user_id))
if (EMPTYSTR(identity->user_id))
{
free(identity->user_id);
identity->user_id = strdup(PEP_OWN_USERID);
assert(identity->user_id);
if (identity->user_id == NULL)
{
return PEP_OUT_OF_MEMORY;
}
}
DEBUG_LOG("myself", "debug", identity->address);
if (!identity->address)
{
identity->address = strdup("");
assert(identity->address);
if (!identity->address)
return PEP_OUT_OF_MEMORY;
}
DEBUG_LOG("myself", "debug", EMPTYSTR(identity->address) ?
"<default address>" : identity->address);
status = get_identity(session,
identity->address,


+ 2
- 0
src/pEp_internal.h View File

@ -131,6 +131,8 @@ typedef struct _pEpSession {
void *sync_obj;
messageToSend_t messageToSend;
showHandshake_t showHandshake;
inject_sync_msg_t inject_sync_msg;
retrieve_next_sync_msg_t retrieve_next_sync_msg;
// state machines
DeviceState_state sync_state;


+ 48
- 4
src/sync.c View File

@ -5,17 +5,27 @@
#include "../asn.1/DeviceGroup-Protocol.h"
// receive_sync_msg is defined in the sync_actions
PEP_STATUS receive_sync_msg(
PEP_SESSION session,
DeviceGroup_Protocol_t *msg
);
DYNAMIC_API PEP_STATUS register_sync_callbacks(
PEP_SESSION session,
void *obj,
messageToSend_t messageToSend,
showHandshake_t showHandshake
showHandshake_t showHandshake,
inject_sync_msg_t inject_sync_msg,
retrieve_next_sync_msg_t retrieve_next_sync_msg
)
{
session->sync_obj = obj;
session->messageToSend = messageToSend;
session->showHandshake = showHandshake;
session->inject_sync_msg = inject_sync_msg;
session->retrieve_next_sync_msg = retrieve_next_sync_msg;
// start state machine
session->sync_state = InitState;
@ -34,6 +44,7 @@ DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session) {
session->sync_obj = NULL;
session->messageToSend = NULL;
session->showHandshake = NULL;
session->retrieve_next_sync_msg = NULL;
}
DYNAMIC_API PEP_STATUS deliverHandshakeResult(
@ -45,20 +56,53 @@ DYNAMIC_API PEP_STATUS deliverHandshakeResult(
if (!session)
return PEP_ILLEGAL_VALUE;
PEP_STATUS status = PEP_STATUS_OK;
switch (result) {
case SYNC_HANDSHAKE_CANCEL:
fsm_DeviceState_inject(session, Cancel, NULL, 0);
status = fsm_DeviceState_inject(session, Cancel, NULL, 0);
break;
case SYNC_HANDSHAKE_ACCEPTED:
fsm_DeviceState_inject(session, HandshakeAccepted, NULL, 0);
status = fsm_DeviceState_inject(session, HandshakeAccepted, NULL, 0);
break;
case SYNC_HANDSHAKE_REJECTED:
fsm_DeviceState_inject(session, HandshakeRejected, NULL, 0);
status = fsm_DeviceState_inject(session, HandshakeRejected, NULL, 0);
break;
default:
return PEP_ILLEGAL_VALUE;
}
return status;
}
DYNAMIC_API PEP_STATUS do_sync_protocol(
PEP_SESSION session,
void *management
)
{
DeviceGroup_Protocol_t *msg;
PEP_STATUS status = PEP_STATUS_OK;
assert(session && session->retrieve_next_sync_msg);
assert(management);
if (!(session && session->retrieve_next_sync_msg) || !management)
return PEP_ILLEGAL_VALUE;
log_event(session, "sync_protocol thread started", "pEp sync protocol", NULL, NULL);
while ((msg = (DeviceGroup_Protocol_t *) session->retrieve_next_sync_msg(management)))
{
if ((status = receive_sync_msg(session, msg) != PEP_STATUS_OK)) {
char buffer[MAX_LINELENGTH];
memset(buffer, 0, MAX_LINELENGTH);
snprintf(buffer, MAX_LINELENGTH, "problem with msg received: %d\n", (int) status);
log_event(session, buffer, "pEp sync protocol", NULL, NULL);
}
}
log_event(session, "sync_protocol thread shutdown", "pEp sync protocol", NULL, NULL);
return PEP_STATUS_OK;
}

+ 55
- 4
src/sync.h View File

@ -12,7 +12,7 @@
extern "C" {
#endif
// messageToSend() - send a beacon message
// messageToSend() - send a message
//
// parameters:
// obj (in) object handle (implementation defined)
@ -56,8 +56,8 @@ typedef PEP_STATUS (*showHandshake_t)(
// deliverHandshakeResult() - give the result of the handshake dialog
//
// parameters:
// session (in) session handle
// result (in) handshake result
// session (in) session handle
// result (in) handshake result
DYNAMIC_API PEP_STATUS deliverHandshakeResult(
PEP_SESSION session,
@ -65,6 +65,29 @@ DYNAMIC_API PEP_STATUS deliverHandshakeResult(
);
// inject_sync_msg - inject sync protocol message
//
// parameters:
// msg (in) message to inject
// management (in) application defined
//
// return value:
// 0 if msg could be stored successfully or nonzero otherwise
typedef int (*inject_sync_msg_t)(void *msg, void *management);
// retrieve_next_sync_msg - receive next sync message
//
// parameters:
// management (in) application defined
//
// return value:
// next message or NULL for termination
typedef void *(*retrieve_next_sync_msg_t)(void *management);
// register_sync_callbacks() - register adapter's callbacks
//
// parameters:
@ -72,6 +95,7 @@ DYNAMIC_API PEP_STATUS deliverHandshakeResult(
// obj (in) object handle (implementation defined)
// messageToSend (in) callback for sending message
// showHandshake (in) callback for doing the handshake
// retrieve_next_sync_msg (in) callback for receiving sync messages
//
// return value:
// PEP_STATUS_OK or any other value on errror
@ -83,7 +107,9 @@ DYNAMIC_API PEP_STATUS register_sync_callbacks(
PEP_SESSION session,
void *obj,
messageToSend_t messageToSend,
showHandshake_t showHandshake
showHandshake_t showHandshake,
inject_sync_msg_t inject_sync_msg,
retrieve_next_sync_msg_t retrieve_next_sync_msg
);
@ -95,6 +121,31 @@ DYNAMIC_API PEP_STATUS register_sync_callbacks(
DYNAMIC_API void unregister_sync_callbacks(PEP_SESSION session);
// do_sync_protocol - function to be run on an extra thread
//
// parameters:
// session pEp session to use
// retrieve_next_sync_msg pointer to retrieve_next_identity() callback
// which returns at least a valid address field in
// the identity struct
// management management data to give to keymanagement
// (implementation defined)
//
// return value:
// PEP_STATUS_OK if thread has to terminate successfully or any other
// value on failure
//
// caveat:
// to ensure proper working of this library, a thread has to be started
// with this function immediately after initialization
// do_keymanagement() calls retrieve_next_identity(management)
DYNAMIC_API PEP_STATUS do_sync_protocol(
PEP_SESSION session,
void *management
);
#ifdef __cplusplus
}
#endif


+ 2
- 2
src/sync_actions.c View File

@ -228,7 +228,7 @@ enomem:
return status;
}
static PEP_STATUS receive_sync_msg(
PEP_STATUS receive_sync_msg(
PEP_SESSION session,
DeviceGroup_Protocol_t *msg
)
@ -295,7 +295,7 @@ PEP_STATUS receive_DeviceState_msg(PEP_SESSION session, message *src)
(void **) &msg, bl->value, bl->size);
if (msg) {
found = true;
PEP_STATUS status = receive_sync_msg(session, msg);
PEP_STATUS status = session->inject_sync_msg(msg, session->sync_obj);
ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
if (status != PEP_STATUS_OK)
return status;


+ 1
- 1
src/sync_driver.c View File

@ -17,7 +17,7 @@ DYNAMIC_API PEP_STATUS fsm_DeviceState_inject(
DeviceState_state state = fsm_DeviceState(session,
session->sync_state, event, partner, extra);
if (state == invalid_out_of_memory)
if (state == DeviceState_state_invalid_out_of_memory)
return PEP_OUT_OF_MEMORY;
if (state < 0)
return PEP_SYNC_STATEMACHINE_ERROR - state;


+ 26
- 26
src/sync_fsm.c View File

@ -34,30 +34,30 @@ DeviceState_state fsm_DeviceState(
case KeyGen:
status = sendBeacon(session, state, NULL, NULL);
if (status == PEP_OUT_OF_MEMORY)
return invalid_out_of_memory;
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return invalid_action;
return (int) invalid_action;
break;
case CannotDecrypt:
status = sendBeacon(session, state, NULL, NULL);
if (status == PEP_OUT_OF_MEMORY)
return invalid_out_of_memory;
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return invalid_action;
return (int) invalid_action;
break;
case Beacon:
status = sendHandshakeRequest(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return invalid_out_of_memory;
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return invalid_action;
return (int) invalid_action;
break;
case HandshakeRequest:
status = sendHandshakeRequest(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return invalid_out_of_memory;
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return invalid_action;
return (int) invalid_action;
return HandshakingSole;
default:
return (DeviceState_state) invalid_event;
@ -69,16 +69,16 @@ DeviceState_state fsm_DeviceState(
case Init:
status = showHandshake(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return invalid_out_of_memory;
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return invalid_action;
return (int) invalid_action;
break;
case HandshakeRejected:
status = reject(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return invalid_out_of_memory;
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return invalid_action;
return (int) invalid_action;
return Sole;
case HandshakeAccepted:
cond_result = keyElectionWon(session, partner);
@ -98,18 +98,18 @@ DeviceState_state fsm_DeviceState(
case GroupKeys:
status = storeGroupKeys(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return invalid_out_of_memory;
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return invalid_action;
return (int) invalid_action;
return Grouped;
case Cancel:
return Sole;
case Reject:
status = reject(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return invalid_out_of_memory;
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return invalid_action;
return (int) invalid_action;
return Sole;
default:
return (DeviceState_state) invalid_event;
@ -121,37 +121,37 @@ DeviceState_state fsm_DeviceState(
case KeyGen:
status = sendGroupKeys(session, state, NULL, NULL);
if (status == PEP_OUT_OF_MEMORY)
return invalid_out_of_memory;
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return invalid_action;
return (int) invalid_action;
break;
case HandshakeRequest:
status = sendHandshakeRequest(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return invalid_out_of_memory;
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return invalid_action;
return (int) invalid_action;
status = showHandshake(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return invalid_out_of_memory;
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return invalid_action;
return (int) invalid_action;
break;
case HandshakeRejected:
status = reject(session, state, partner, NULL);
if (status == PEP_OUT_OF_MEMORY)
return invalid_out_of_memory;
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return invalid_action;
return (int) invalid_action;
break;
case Hand:
break;
case Reject:
status = reject(session, state, NULL, NULL);
if (status == PEP_OUT_OF_MEMORY)
return invalid_out_of_memory;
return (int) invalid_out_of_memory;
if (status != PEP_STATUS_OK)
return invalid_action;
return (int) invalid_action;
break;
default:
return (DeviceState_state) invalid_event;


+ 7
- 0
src/sync_fsm.h View File

@ -37,6 +37,13 @@ int keyElectionWon(PEP_SESSION session, Identity partner);
// states
typedef enum _DeviceState_state {
// error values also in this namespace
DeviceState_state_invalid_state = (int) invalid_state,
DeviceState_state_invalid_event = (int) invalid_event,
DeviceState_state_invalid_condition = (int) invalid_condition,
DeviceState_state_invalid_action = (int) invalid_action,
DeviceState_state_invalid_out_of_memory = (int) invalid_out_of_memory,
DeviceState_state_NONE = 0,
InitState,
Sole,


+ 10
- 3
sync/gen_statemachine.ysl2 View File

@ -62,6 +62,13 @@ tstylesheet {
// states
typedef enum _«@name»_state {
// error values also in this namespace
«@name»_state_invalid_state = (int) invalid_state,
«@name»_state_invalid_event = (int) invalid_event,
«@name»_state_invalid_condition = (int) invalid_condition,
«@name»_state_invalid_action = (int) invalid_action,
«@name»_state_invalid_out_of_memory = (int) invalid_out_of_memory,
«@name»_state_NONE = 0,
`` for "func:distinctName(state)" |> «@name»`if "position()!=last()" > , `
} «@name»_state;
@ -135,7 +142,7 @@ tstylesheet {
«@name»_state state = fsm_«@name»(session,
session->«@filename»_state, event, partner, extra);
if (state == invalid_out_of_memory)
if (state == «@name»_state_invalid_out_of_memory)
return PEP_OUT_OF_MEMORY;
if (state < 0)
return PEP_SYNC_STATEMACHINE_ERROR - state;
@ -202,9 +209,9 @@ tstylesheet {
}
> , NULL);\n
| if (status == PEP_OUT_OF_MEMORY)
|> return invalid_out_of_memory;
|> return (int) invalid_out_of_memory;
| if (status != PEP_STATUS_OK)
|> return invalid_action;
|> return (int) invalid_action;
}
template "condition" {


Loading…
Cancel
Save