KeySync: changed handshakeRequest and groupKeys messages content (TODO:increment protocol number when finished). Now use string instead of Identity to just store uuid. Added group uuid in handshakeRequest
1 // This file is under GNU General Public License 3.0
4 // generate actions skeleton
6 // Copyleft (c) 2016, p≡p foundation
8 // Written by Volker Birk
13 include standardlib.ysl2
14 include ./functions.ysl2
16 template "/protocol" {
17 apply "fsm", mode=send, 0;
18 apply "fsm", mode=other, 0;
21 template "fsm", mode=send document "generated/{@filename}_send_actions.c", "text" {
22 const "name", "@name";
23 const "filename", "@filename";
25 // Send Actions for «@name» state machine
28 #include "pEp_internal.h"
29 #include "keymanagement.h"
31 #include "«@filename»_fsm.h"
32 #include "baseprotocol.h"
34 #include "../asn.1/DeviceGroup-Protocol.h"
35 #include "sync_impl.h"
37 for "func:distinctName(//action)"
38 if "substring(@name, 1, 4) = 'send'"
39 | #include "../asn.1/«substring(@name, 5, 255)».h"
41 for "func:distinctName(//action)"
42 if "substring(@name, 1, 4) = 'send'"
46 with "filename", "$filename";
50 PEP_STATUS _notifyHandshake(
53 sync_handshake_signal signal
57 for "func:distinctName(//action)"
58 if "substring(@name, 1, 6) = 'notify'"
62 with "filename", "$filename";
65 template "fsm", mode=other document "skeletons/{@filename}_actions.c", "text" {
66 const "name", "@name";
67 const "filename", "@filename";
69 // Actions for «@name» state machine
72 #include "pEp_internal.h"
73 #include "keymanagement.h"
75 #include "«@filename»_fsm.h"
76 #include "../asn.1/DeviceGroup-Protocol.h"
79 for "func:distinctName(//action)"
80 if "substring(@name, 1, 4) != 'send'"
84 with "filename", "$filename";
87 function "paramcheck" {
94 if (!(session && partner))
95 return PEP_ILLEGAL_VALUE;
100 if (!(session && !partner))
101 return PEP_ILLEGAL_VALUE;
106 function "other_action" {
109 param "filename", "'###'";
113 // «$action/@name»() -
116 // session (in) session handle
117 // state (in) state the state machine is in
118 `` if "parm" | // partner (in) partner to communicate with
119 `` if "not(parm)" | // partner (in) (must be NULL)
122 // PEP_STATUS_OK or any other value on error
124 PEP_STATUS «$action/@name»(
131 PEP_STATUS status = PEP_STATUS_OK;
133 `` call "paramcheck" with "partner", "parm/partner";
141 status = PEP_OUT_OF_MEMORY;
150 function "send_action" {
153 param "filename", "'###'";
154 const "name", "substring($action/@name, 5, 255)";
155 const "lname", "concat(yml:lcase(substring($name, 1, 1)), substring($name, 2))";
159 // «$action/@name»() - send «$name» message
162 // session (in) session handle
163 // state (in) state the state machine is in
164 `` if "parm" | // partner (in) partner to communicate with
165 `` if "not(parm)" | // partner (in) (must be NULL)
168 // PEP_STATUS_OK or any other value on error
170 PEP_STATUS «$action/@name»(
177 assert(session && state);
178 if (!(session && state))
179 return PEP_ILLEGAL_VALUE;
181 PEP_STATUS status = PEP_STATUS_OK;
182 `` if "$name='GroupKeys' or $name='GroupUpdate'" |> identity_list *kl = new_identity_list(NULL);
184 DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_«$lname»);
189 when "$name='GroupKeys' or $name='GroupUpdate'" {
191 |> status = _own_identities_retrieve(session, &kl, PEP_idf_not_for_sync);
192 |> if (status != PEP_STATUS_OK)
194 |> if (IdentityList_from_identity_list(kl, &msg->payload.choice.«$lname».ownIdentities) == NULL)
199 when "$name='GroupKeys' or $name='HandshakeRequest'" {
201 |> msg->payload.choice.«$lname».partner_id =
202 |> OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
203 |> partner->user_id, -1);
204 |> if (partner->user_id && !msg->payload.choice.«$lname».partner_id)
212 when "count(/protocol/unencrypted/*[name()=$action/@name]) = 0"
213 |> bool encrypted = true;
215 |> bool encrypted = false;
218 when "count(/protocol/broadcast/*[name()=$action/@name]) = 0"
219 |> status = unicast_msg(session, partner, state, msg, encrypted);
221 |> status = multicast_self_msg(session, state, msg, encrypted);
224 if (status != PEP_STATUS_OK)
227 `` if "$name='GroupKeys' or $name='GroupUpdate'" |> free_identity_list(kl);
228 free_DeviceGroup_Protocol_msg(msg);
229 return PEP_STATUS_OK;
232 status = PEP_OUT_OF_MEMORY;
234 free_DeviceGroup_Protocol_msg(msg);
235 `` if "$name='GroupKeys'" |> free_identity_list(kl);
242 function "UnCamelUp" {
244 const "tokens", "str:tokenize($text, '')";
248 when "contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ',.)" > _«.»
249 otherwise value "yml:ucase(.)";
254 function "notify_action" {
257 param "filename", "'###'";
258 const "name", "substring($action/@name, 7, 255)";
259 const "uname" call "UnCamelUp" with "text", "$name";
262 // «$action/@name»() - notify «$name» to app
265 // session (in) session handle
266 // state (in) state the state machine is in
267 // partner (in) partner to communicate with
270 // PEP_STATUS_OK or any other value on error
272 PEP_STATUS «$action/@name»(
279 assert(session && state);
280 assert(extra == NULL);
281 if (!(session && state && extra == NULL))
282 return PEP_ILLEGAL_VALUE;
284 return _notifyHandshake(session, partner, SYNC_NOTIFY«$uname»);