adding broadcast function keysync
authorVolker Birk <vb@pep.foundation>
Sat, 20 Aug 2016 18:04:13 +0200
branchkeysync
changeset 104673be5d9af815
parent 1045 3b77f5e254c1
child 1047 2a4a2ec1340b
adding broadcast function
src/sync_actions.c
src/sync_fsm.h
sync/gen_statemachine.ysl2
     1.1 --- a/src/sync_actions.c	Sat Aug 20 16:03:54 2016 +0200
     1.2 +++ b/src/sync_actions.c	Sat Aug 20 18:04:13 2016 +0200
     1.3 @@ -5,6 +5,7 @@
     1.4  #include "message.h"
     1.5  #include "sync_fsm.h"
     1.6  #include "map_asn1.h"
     1.7 +#include "baseprotocol.h"
     1.8  #include "../asn.1/DeviceGroup-Protocol.h"
     1.9  
    1.10  // conditions
    1.11 @@ -318,3 +319,56 @@
    1.12      return PEP_STATUS_OK;
    1.13  }
    1.14  
    1.15 +PEP_STATUS broadcast_msg(PEP_SESSION session, Identity partner, char *payload,
    1.16 +        size_t size)
    1.17 +{
    1.18 +    PEP_STATUS status = PEP_STATUS_OK;
    1.19 +
    1.20 +    assert(session && partner && payload);
    1.21 +    if (!(session && partner && payload))
    1.22 +        return PEP_ILLEGAL_VALUE;
    1.23 +
    1.24 +    if (size == 0)
    1.25 +        return PEP_STATUS_OK;
    1.26 +
    1.27 +    stringlist_t *own_addresses = NULL;
    1.28 +    status = get_own_addresses(session, &own_addresses);
    1.29 +    if (status != PEP_STATUS_OK)
    1.30 +        return status;
    1.31 +
    1.32 +    Identity me = NULL;
    1.33 +    message *_message = NULL;
    1.34 +
    1.35 +    for (stringlist_t *_a = own_addresses; _a && _a->value; _a = _a->next) {
    1.36 +        me = new_identity(_a->value, NULL, PEP_OWN_USERID, NULL);
    1.37 +        if (!me) {
    1.38 +            status = PEP_OUT_OF_MEMORY;
    1.39 +            goto the_end;
    1.40 +        }
    1.41 +
    1.42 +        status = myself(session, me);
    1.43 +        if (status == PEP_OUT_OF_MEMORY)
    1.44 +            goto the_end;
    1.45 +        if (status != PEP_STATUS_OK)
    1.46 +            continue;
    1.47 +
    1.48 +        status = prepare_message(me, partner, payload, size, &_message);
    1.49 +        if (status != PEP_STATUS_OK)
    1.50 +            goto the_end;
    1.51 +        
    1.52 +        free_identity(me);
    1.53 +        me = NULL;
    1.54 +
    1.55 +        status = session->messageToSend(session->sync_obj, _message);
    1.56 +        if (status == PEP_OUT_OF_MEMORY)
    1.57 +            goto the_end;
    1.58 +        assert(status == PEP_STATUS_OK);
    1.59 +    }
    1.60 +
    1.61 +the_end:
    1.62 +    free_stringlist(own_addresses);
    1.63 +    free_identity(me);
    1.64 +    free_message(_message);
    1.65 +    return status;
    1.66 +}
    1.67 +
     2.1 --- a/src/sync_fsm.h	Sat Aug 20 16:03:54 2016 +0200
     2.2 +++ b/src/sync_fsm.h	Sat Aug 20 18:04:13 2016 +0200
     2.3 @@ -101,6 +101,11 @@
     2.4          void *extra
     2.5      );
     2.6  
     2.7 +// misc
     2.8 +
     2.9 +PEP_STATUS broadcast_msg(PEP_SESSION session, Identity partner, char
    2.10 +        *payload, size_t size);
    2.11 +
    2.12  #ifdef __cplusplus
    2.13  }
    2.14  #endif
     3.1 --- a/sync/gen_statemachine.ysl2	Sat Aug 20 16:03:54 2016 +0200
     3.2 +++ b/sync/gen_statemachine.ysl2	Sat Aug 20 18:04:13 2016 +0200
     3.3 @@ -115,6 +115,11 @@
     3.4                  void *extra
     3.5              );
     3.6  
     3.7 +        // misc
     3.8 +
     3.9 +        PEP_STATUS broadcast_msg(PEP_SESSION session, Identity partner, char
    3.10 +                *payload, size_t size);
    3.11 +
    3.12          #ifdef __cplusplus
    3.13          }
    3.14          #endif