1 // generate actions skeleton
3 // Copyleft (c) 2016, p≡p foundation
5 // Written by Volker Birk
10 include standardlib.ysl2
11 include ./functions.ysl2
13 template "/protocol" {
14 apply "fsm", mode=send, 0;
15 apply "fsm", mode=other, 0;
18 template "fsm", mode=send document "generated/{@filename}_send_actions.c", "text" {
19 const "name", "@name";
20 const "filename", "@filename";
22 // Send Actions for «@name» state machine
25 #include "pEp_internal.h"
26 #include "keymanagement.h"
28 #include "«@filename»_fsm.h"
29 #include "baseprotocol.h"
31 #include "../asn.1/DeviceGroup-Protocol.h"
32 #include "sync_impl.h"
34 for "func:distinctName(//action)"
35 if "substring(@name, 1, 4) = 'send'"
36 | #include "../asn.1/«substring(@name, 5, 255)».h"
38 for "func:distinctName(//action)"
39 if "substring(@name, 1, 4) = 'send'"
43 with "filename", "$filename";
46 template "fsm", mode=other document "skeletons/{@filename}_actions.c", "text" {
47 const "name", "@name";
48 const "filename", "@filename";
50 // Actions for «@name» state machine
53 #include "pEp_internal.h"
54 #include "keymanagement.h"
56 #include "«@filename»_fsm.h"
57 #include "../asn.1/DeviceGroup-Protocol.h"
60 for "func:distinctName(//action)"
61 if "substring(@name, 1, 4) != 'send'"
65 with "filename", "$filename";
68 function "paramcheck" {
75 if (!(session && partner))
76 return PEP_ILLEGAL_VALUE;
81 if (!(session && !partner))
82 return PEP_ILLEGAL_VALUE;
87 function "other_action" {
90 param "filename", "'###'";
94 // «$action/@name»() -
97 // session (in) session handle
98 // state (in) state the state machine is in
99 `` if "parm" | // partner (in) partner to communicate with
100 `` if "not(parm)" | // partner (in) (must be NULL)
103 // PEP_STATUS_OK or any other value on error
105 PEP_STATUS «$action/@name»(
112 PEP_STATUS status = PEP_STATUS_OK;
114 `` call "paramcheck" with "partner", "parm/partner";
122 status = PEP_OUT_OF_MEMORY;
131 function "send_action" {
134 param "filename", "'###'";
135 const "name", "substring($action/@name, 5, 255)";
136 const "lname", "concat(yml:lcase(substring($name, 1, 1)), substring($name, 2))";
140 // «$action/@name»() - send «$name» message
143 // session (in) session handle
144 // state (in) state the state machine is in
145 `` if "parm" | // partner (in) partner to communicate with
146 `` if "not(parm)" | // partner (in) (must be NULL)
149 // PEP_STATUS_OK or any other value on error
151 PEP_STATUS «$action/@name»(
158 assert(session && state);
159 if (!(session && state))
160 return PEP_ILLEGAL_VALUE;
162 PEP_STATUS status = PEP_STATUS_OK;
163 `` if "$name='GroupKeys' or $name='GroupUpdate'" |> identity_list *kl = new_identity_list(NULL);
165 DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_«$lname»);
170 when "$name='GroupKeys' or $name='GroupUpdate'" {
172 |> status = _own_identities_retrieve(session, &kl, PEP_idf_not_for_sync);
173 |> if (status != PEP_STATUS_OK)
175 |> if (IdentityList_from_identity_list(kl, &msg->payload.choice.«$lname».ownIdentities) == NULL)
180 when "$name='GroupKeys' or $name='HandshakeRequest'" {
182 |> if (Identity_from_Struct(partner,
183 |> &msg->payload.choice.«$lname».partner) == NULL)
191 when "count(/protocol/unencrypted/*[name()=$action/@name]) = 0"
192 |> bool encrypted = true;
194 |> bool encrypted = false;
197 when "count(/protocol/broadcast/*[name()=$action/@name]) = 0"
198 |> status = unicast_msg(session, partner, state, msg, encrypted);
200 |> status = multicast_self_msg(session, state, msg, encrypted);
203 if (status != PEP_STATUS_OK)
206 `` if "$name='GroupKeys' or $name='GroupUpdate'" |> free_identity_list(kl);
207 free_DeviceGroup_Protocol_msg(msg);
208 return PEP_STATUS_OK;
211 status = PEP_OUT_OF_MEMORY;
213 free_DeviceGroup_Protocol_msg(msg);
214 `` if "$name='GroupKeys'" |> free_identity_list(kl);