src/sync_actions.c
author Volker Birk <vb@pep-project.org>
Wed, 18 May 2016 14:29:22 +0200
changeset 657 224eeaf88a65
parent 656 bf63654b3a39
child 665 51b2e250297a
permissions -rw-r--r--
paramcheck to a function
     1 // Actions for DeviceState state machine
     2 
     3 #include <assert.h>
     4 #include "keymanagement.h"
     5 #include "sync_fsm.h"
     6 #include "map_asn1.h"
     7 #include "../asn.1/Beacon.h"
     8 #include "../asn.1/HandshakeRequest.h"
     9 #include "../asn.1/OwnKeys.h"
    10 
    11 
    12 // sendBeacon() - send Beacon message
    13 //
    14 //  params:
    15 //      session (in)        session handle
    16 //      partner (in)        (must be NULL)
    17 //
    18 //  returns:
    19 //      PEP_STATUS_OK or any other value on error
    20 
    21 PEP_STATUS sendBeacon(PEP_SESSION session, const Identity partner)
    22 {
    23     PEP_STATUS status = PEP_STATUS_OK;
    24 
    25     assert(session);
    26 assert(!partner);
    27 if (!(session && !partner))
    28     return PEP_ILLEGAL_VALUE;
    29 
    30     Beacon_t *msg = (Beacon_t *) calloc(1, sizeof(Beacon_t));
    31     assert(msg);
    32     if (!msg)
    33         goto enomem;
    34 
    35     int32_t seq;
    36     status = sequence_value(session, "DeviceGroup", &seq);
    37     if (status != PEP_STATUS_OK)
    38         goto error;
    39     msg->header.sequence = (long) seq;
    40 
    41     pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
    42     if (!me)
    43         goto enomem;
    44     status = myself(session, me);
    45     if (status != PEP_STATUS_OK)
    46         goto error;
    47     if (Identity_from_Struct(me, &msg->me) == NULL)
    48         goto enomem;
    49 
    50     return status;
    51 
    52 enomem:
    53     status = PEP_OUT_OF_MEMORY;
    54 error:
    55     ASN_STRUCT_FREE(asn_DEF_Beacon, msg);
    56     return status;
    57 }
    58 
    59 
    60 // sendHandshakeRequest() - send HandshakeRequest message
    61 //
    62 //  params:
    63 //      session (in)        session handle
    64 //      partner (in)        partner in sync
    65 //
    66 //  returns:
    67 //      PEP_STATUS_OK or any other value on error
    68 
    69 PEP_STATUS sendHandshakeRequest(PEP_SESSION session, const Identity partner)
    70 {
    71     PEP_STATUS status = PEP_STATUS_OK;
    72 
    73     assert(session);
    74 assert(partner);
    75 if (!(session && partner))
    76     return PEP_ILLEGAL_VALUE;
    77 
    78     HandshakeRequest_t *msg = (HandshakeRequest_t *) calloc(1, sizeof(HandshakeRequest_t));
    79     assert(msg);
    80     if (!msg)
    81         goto enomem;
    82 
    83     int32_t seq;
    84     status = sequence_value(session, "DeviceGroup", &seq);
    85     if (status != PEP_STATUS_OK)
    86         goto error;
    87     msg->header.sequence = (long) seq;
    88 
    89     pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
    90     if (!me)
    91         goto enomem;
    92     status = myself(session, me);
    93     if (status != PEP_STATUS_OK)
    94         goto error;
    95     if (Identity_from_Struct(me, &msg->me) == NULL)
    96         goto enomem;
    97 
    98     if (Identity_from_Struct(partner, &msg->partner) == NULL)
    99         goto enomem;
   100 
   101     return status;
   102 
   103 enomem:
   104     status = PEP_OUT_OF_MEMORY;
   105 error:
   106     ASN_STRUCT_FREE(asn_DEF_HandshakeRequest, msg);
   107     return status;
   108 }
   109 
   110 
   111 // showHandshake() - 
   112 //
   113 //  params:
   114 //      session (in)        session handle
   115 //      partner (in)        partner in sync
   116 //
   117 //  returns:
   118 //      PEP_STATUS_OK or any other value on error
   119 
   120 PEP_STATUS showHandshake(PEP_SESSION session, const Identity partner)
   121 {
   122     PEP_STATUS status = PEP_STATUS_OK;
   123 
   124     assert(session);
   125 assert(partner);
   126 if (!(session && partner))
   127     return PEP_ILLEGAL_VALUE;
   128 
   129     // working code
   130 
   131 
   132     return status;
   133 
   134 enomem:
   135     status = PEP_OUT_OF_MEMORY;
   136 error:
   137     // free...
   138     return status;
   139 }
   140 
   141 
   142 // reject() - 
   143 //
   144 //  params:
   145 //      session (in)        session handle
   146 //      partner (in)        partner in sync
   147 //
   148 //  returns:
   149 //      PEP_STATUS_OK or any other value on error
   150 
   151 PEP_STATUS reject(PEP_SESSION session, const Identity partner)
   152 {
   153     PEP_STATUS status = PEP_STATUS_OK;
   154 
   155     assert(session);
   156 assert(partner);
   157 if (!(session && partner))
   158     return PEP_ILLEGAL_VALUE;
   159 
   160     // working code
   161 
   162 
   163     return status;
   164 
   165 enomem:
   166     status = PEP_OUT_OF_MEMORY;
   167 error:
   168     // free...
   169     return status;
   170 }
   171 
   172 
   173 // storeGroupKeys() - 
   174 //
   175 //  params:
   176 //      session (in)        session handle
   177 //      partner (in)        partner in sync
   178 //
   179 //  returns:
   180 //      PEP_STATUS_OK or any other value on error
   181 
   182 PEP_STATUS storeGroupKeys(PEP_SESSION session, const Identity partner)
   183 {
   184     PEP_STATUS status = PEP_STATUS_OK;
   185 
   186     assert(session);
   187 assert(partner);
   188 if (!(session && partner))
   189     return PEP_ILLEGAL_VALUE;
   190 
   191     // working code
   192 
   193 
   194     return status;
   195 
   196 enomem:
   197     status = PEP_OUT_OF_MEMORY;
   198 error:
   199     // free...
   200     return status;
   201 }
   202 
   203 
   204 // sendOwnKeys() - send OwnKeys message
   205 //
   206 //  params:
   207 //      session (in)        session handle
   208 //      partner (in)        (must be NULL)
   209 //
   210 //  returns:
   211 //      PEP_STATUS_OK or any other value on error
   212 
   213 PEP_STATUS sendOwnKeys(PEP_SESSION session, const Identity partner)
   214 {
   215     PEP_STATUS status = PEP_STATUS_OK;
   216 
   217     assert(session);
   218 assert(!partner);
   219 if (!(session && !partner))
   220     return PEP_ILLEGAL_VALUE;
   221 
   222     OwnKeys_t *msg = (OwnKeys_t *) calloc(1, sizeof(OwnKeys_t));
   223     assert(msg);
   224     if (!msg)
   225         goto enomem;
   226 
   227     int32_t seq;
   228     status = sequence_value(session, "DeviceGroup", &seq);
   229     if (status != PEP_STATUS_OK)
   230         goto error;
   231     msg->header.sequence = (long) seq;
   232 
   233     pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
   234     if (!me)
   235         goto enomem;
   236     status = myself(session, me);
   237     if (status != PEP_STATUS_OK)
   238         goto error;
   239     if (Identity_from_Struct(me, &msg->me) == NULL)
   240         goto enomem;
   241 
   242     stringlist_t *sl;
   243     status = own_key_retrieve(session, &sl);
   244     if (status != PEP_STATUS_OK)
   245         goto error;
   246     if (KeyList_from_stringlist(sl, &msg->keylist) == NULL)
   247         goto enomem;
   248 
   249     return status;
   250 
   251 enomem:
   252     status = PEP_OUT_OF_MEMORY;
   253 error:
   254     ASN_STRUCT_FREE(asn_DEF_OwnKeys, msg);
   255     return status;
   256 }
   257 
   258 
   259 // transmitGroupKeys() - 
   260 //
   261 //  params:
   262 //      session (in)        session handle
   263 //      partner (in)        partner in sync
   264 //
   265 //  returns:
   266 //      PEP_STATUS_OK or any other value on error
   267 
   268 PEP_STATUS transmitGroupKeys(PEP_SESSION session, const Identity partner)
   269 {
   270     PEP_STATUS status = PEP_STATUS_OK;
   271 
   272     assert(session);
   273 assert(partner);
   274 if (!(session && partner))
   275     return PEP_ILLEGAL_VALUE;
   276 
   277     // working code
   278 
   279 
   280     return status;
   281 
   282 enomem:
   283     status = PEP_OUT_OF_MEMORY;
   284 error:
   285     // free...
   286     return status;
   287 }
   288