1.1 --- a/sync/gen_actions.ysl2 Tue Aug 07 14:24:15 2018 +0200
1.2 +++ b/sync/gen_actions.ysl2 Tue Aug 07 17:16:03 2018 +0200
1.3 @@ -1,297 +1,79 @@
1.4 // This file is under GNU General Public License 3.0
1.5 // see LICENSE.txt
1.6
1.7 -// generate actions skeleton
1.8 +// generate conditions and actions
1.9
1.10 -// Copyleft (c) 2016, p≡p foundation
1.11 +// Copyleft (c) 2017, p≡p foundation
1.12
1.13 // Written by Volker Birk
1.14
1.15 include yslt.yml2
1.16
1.17 +decl _func *name (*type) alias - {
1.18 + template %name=*name, %type=*type, "%type[@name='%name']"
1.19 + call *type with "content" content;
1.20 +};
1.21 +
1.22 +decl condition is _func (*type="condition");
1.23 +decl action is _func (*type="action");
1.24 +
1.25 tstylesheet {
1.26 include standardlib.ysl2
1.27 include ./functions.ysl2
1.28
1.29 - template "/protocol" {
1.30 - apply "fsm", mode=send, 0;
1.31 - apply "fsm", mode=other, 0;
1.32 - }
1.33 -
1.34 - template "fsm", mode=send document "generated/{@filename}_send_actions.c", "text" {
1.35 - const "name", "@name";
1.36 - const "filename", "@filename";
1.37 - ||
1.38 - // Send Actions for «@name» state machine
1.39 -
1.40 - #include <assert.h>
1.41 - #include "pEp_internal.h"
1.42 - #include "keymanagement.h"
1.43 - #include "message.h"
1.44 - #include "«@filename»_fsm.h"
1.45 - #include "baseprotocol.h"
1.46 - #include "map_asn1.h"
1.47 - #include "../asn.1/DeviceGroup-Protocol.h"
1.48 - #include "sync_impl.h"
1.49 - ||
1.50 - for "func:distinctName(//action)"
1.51 - if "substring(@name, 1, 4) = 'send'"
1.52 - | #include "../asn.1/«substring(@name, 5, 255)».h"
1.53 - |
1.54 - for "func:distinctName(//action)"
1.55 - if "substring(@name, 1, 4) = 'send'"
1.56 - call "send_action"
1.57 - with "action", ".",
1.58 - with "fsm", "$name",
1.59 - with "filename", "$filename";
1.60 -
1.61 - ||
1.62 -
1.63 - PEP_STATUS _notifyHandshake(
1.64 - PEP_SESSION session,
1.65 - Identity partner,
1.66 - sync_handshake_signal signal
1.67 - );
1.68 - ||
1.69 + include ./cond_act.yml2
1.70
1.71 - for "func:distinctName(//action)"
1.72 - if "substring(@name, 1, 6) = 'notify'"
1.73 - call "notify_action"
1.74 - with "action", ".",
1.75 - with "fsm", "$name",
1.76 - with "filename", "$filename";
1.77 - }
1.78 -
1.79 - template "fsm", mode=other document "skeletons/{@filename}_actions.c", "text" {
1.80 - const "name", "@name";
1.81 - const "filename", "@filename";
1.82 - ||
1.83 - // Actions for «@name» state machine
1.84 -
1.85 - #include <assert.h>
1.86 - #include "pEp_internal.h"
1.87 - #include "keymanagement.h"
1.88 - #include "message.h"
1.89 - #include "«@filename»_fsm.h"
1.90 - #include "../asn.1/DeviceGroup-Protocol.h"
1.91 + template "/protocol" {
1.92 + document "generated/{@name}_actions.c", "text" {
1.93 + ||
1.94 + // This file is under GNU General Public License 3.0
1.95 + // see LICENSE.txt
1.96
1.97 - ||
1.98 - for "func:distinctName(//action)"
1.99 - if "substring(@name, 1, 4) != 'send'"
1.100 - call "other_action"
1.101 - with "action", ".",
1.102 - with "fsm", "$name",
1.103 - with "filename", "$filename";
1.104 - }
1.105 + #include "«@name»_impl.h"
1.106 + `` for "fsm" | #include "«@name»_fsm.h"
1.107
1.108 - function "paramcheck" {
1.109 - param "partner";
1.110 - |> assert(session);
1.111 - choose {
1.112 - when "$partner"
1.113 ||
1.114 - assert(partner);
1.115 - if (!(session && partner))
1.116 - return PEP_ILLEGAL_VALUE;
1.117 - ||
1.118 - otherwise
1.119 - ||
1.120 - assert(!partner);
1.121 - if (!(session && !partner))
1.122 - return PEP_ILLEGAL_VALUE;
1.123 - ||
1.124 + apply "func:distinctName(//condition)", 0;
1.125 + apply "func:distinctName(//action[not(starts-with(@name, 'send'))])", 0;
1.126 }
1.127 }
1.128
1.129 - function "other_action" {
1.130 - param "action";
1.131 - param "fsm";
1.132 - param "filename", "'###'";
1.133 + template "condition" | #error condition «@name» not implemented\n
1.134 + template "action" | #error action «@name» not implemented\n
1.135
1.136 + function "condition" {
1.137 + param "content";
1.138 + ||
1.139 + PEP_STATUS «@name»(PEP_SESSION session, bool *result)
1.140 + {
1.141 + assert(session && result);
1.142 + if (!(session && result))
1.143 + return PEP_ILLEGAL_VALUE;
1.144 +
1.145 + ||
1.146 + copy "$content";
1.147 ||
1.148
1.149 - // «$action/@name»() -
1.150 - //
1.151 - // params:
1.152 - // session (in) session handle
1.153 - // state (in) state the state machine is in
1.154 - `` if "parm" | // partner (in) partner to communicate with
1.155 - `` if "not(parm)" | // partner (in) (must be NULL)
1.156 - //
1.157 - // returns:
1.158 - // PEP_STATUS_OK or any other value on error
1.159 -
1.160 - PEP_STATUS «$action/@name»(
1.161 - PEP_SESSION session,
1.162 - «$fsm»_state state,
1.163 - Identity partner,
1.164 - void *extra
1.165 - )
1.166 - {
1.167 - PEP_STATUS status = PEP_STATUS_OK;
1.168 -
1.169 - `` call "paramcheck" with "partner", "parm/partner";
1.170 -
1.171 - // working code
1.172 -
1.173 - // free extra
1.174 - return status;
1.175 -
1.176 - enomem:
1.177 - status = PEP_OUT_OF_MEMORY;
1.178 - error:
1.179 - // free extra
1.180 - return status;
1.181 + return PEP_STATUS_OK;
1.182 }
1.183
1.184 ||
1.185 }
1.186
1.187 - function "send_action" {
1.188 - param "action";
1.189 - param "fsm";
1.190 - param "filename", "'###'";
1.191 - const "name", "substring($action/@name, 5, 255)";
1.192 - const "lname", "concat(yml:lcase(substring($name, 1, 1)), substring($name, 2))";
1.193 -
1.194 + function "action" {
1.195 + param "content";
1.196 ||
1.197 -
1.198 - // «$action/@name»() - send «$name» message
1.199 - //
1.200 - // params:
1.201 - // session (in) session handle
1.202 - // state (in) state the state machine is in
1.203 - `` if "parm" | // partner (in) partner to communicate with
1.204 - `` if "not(parm)" | // partner (in) (must be NULL)
1.205 - //
1.206 - // returns:
1.207 - // PEP_STATUS_OK or any other value on error
1.208 -
1.209 - PEP_STATUS «$action/@name»(
1.210 - PEP_SESSION session,
1.211 - «$fsm»_state state,
1.212 - Identity partner,
1.213 - void *extra
1.214 - )
1.215 + PEP_STATUS «@name»(PEP_SESSION session)
1.216 {
1.217 - assert(session && state);
1.218 - if (!(session && state))
1.219 + assert(session);
1.220 + if (!session)
1.221 return PEP_ILLEGAL_VALUE;
1.222
1.223 - PEP_STATUS status = PEP_STATUS_OK;
1.224 - `` if "$name='GroupKeys' or $name='GroupUpdate'" |> identity_list *kl = new_identity_list(NULL);
1.225 -
1.226 - DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_«$lname»);
1.227 - if (!msg)
1.228 - goto enomem;
1.229 - ||
1.230 - choose {
1.231 - when "$name='GroupKeys' or $name='GroupUpdate'" {
1.232 - |
1.233 - |> status = _own_identities_retrieve(session, &kl, PEP_idf_not_for_sync);
1.234 - |> if (status != PEP_STATUS_OK)
1.235 - |>> goto error;
1.236 - |> if (IdentityList_from_identity_list(kl, &msg->payload.choice.«$lname».ownIdentities) == NULL)
1.237 - |>> goto enomem;
1.238 - }
1.239 - }
1.240 - choose {
1.241 - when "$name='GroupKeys' or $name='HandshakeRequest'" {
1.242 - |
1.243 - |> msg->payload.choice.«$lname».partner_id =
1.244 - |> OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
1.245 - |> partner->user_id, -1);
1.246 - |> if (partner->user_id && !msg->payload.choice.«$lname».partner_id)
1.247 - |> goto enomem;
1.248 - |
1.249 - |> char *devgrp = NULL;
1.250 - |> status = get_device_group(session, &devgrp);
1.251 - |> if (status == PEP_STATUS_OK && devgrp && devgrp[0])
1.252 - |> msg->payload.choice.«$lname».group_id =
1.253 - |> OCTET_STRING_new_fromBuf(&asn_DEF_UTF8String,
1.254 - |> devgrp, -1);
1.255 - |> free(devgrp);
1.256 - |> if (devgrp && !msg->payload.choice.«$lname».partner_id)
1.257 - |> goto enomem;
1.258 - }
1.259 - }
1.260 - ||
1.261 -
1.262 ||
1.263 - choose {
1.264 - when "count(/protocol/unencrypted/*[name()=$action/@name]) = 0"
1.265 - |> bool encrypted = true;
1.266 - otherwise
1.267 - |> bool encrypted = false;
1.268 - }
1.269 - choose {
1.270 - when "count(/protocol/broadcast/*[name()=$action/@name]) = 0"
1.271 - |> status = unicast_msg(session, partner, state, msg, encrypted);
1.272 - otherwise
1.273 - |> status = multicast_self_msg(session, state, msg, encrypted);
1.274 - }
1.275 - ||
1.276 - if (status != PEP_STATUS_OK)
1.277 - goto error;
1.278 -
1.279 - `` if "$name='GroupKeys' or $name='GroupUpdate'" |> free_identity_list(kl);
1.280 - free_DeviceGroup_Protocol_msg(msg);
1.281 - return PEP_STATUS_OK;
1.282 -
1.283 - enomem:
1.284 - status = PEP_OUT_OF_MEMORY;
1.285 - error:
1.286 - free_DeviceGroup_Protocol_msg(msg);
1.287 - `` if "$name='GroupKeys'" |> free_identity_list(kl);
1.288 - return status;
1.289 - }
1.290 -
1.291 - ||
1.292 - }
1.293 -
1.294 - function "UnCamelUp" {
1.295 - param "text";
1.296 - const "tokens", "str:tokenize($text, '')";
1.297 -
1.298 - for "$tokens" {
1.299 - choose {
1.300 - when "contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ',.)" > _«.»
1.301 - otherwise value "yml:ucase(.)";
1.302 - }
1.303 - }
1.304 - }
1.305 -
1.306 - function "notify_action" {
1.307 - param "action";
1.308 - param "fsm";
1.309 - param "filename", "'###'";
1.310 - const "name", "substring($action/@name, 7, 255)";
1.311 - const "uname" call "UnCamelUp" with "text", "$name";
1.312 + copy "$content";
1.313 ||
1.314
1.315 - // «$action/@name»() - notify «$name» to app
1.316 - //
1.317 - // params:
1.318 - // session (in) session handle
1.319 - // state (in) state the state machine is in
1.320 - // partner (in) partner to communicate with
1.321 - //
1.322 - // returns:
1.323 - // PEP_STATUS_OK or any other value on error
1.324 -
1.325 - PEP_STATUS «$action/@name»(
1.326 - PEP_SESSION session,
1.327 - «$fsm»_state state,
1.328 - Identity partner,
1.329 - void *extra
1.330 - )
1.331 - {
1.332 - assert(session && state);
1.333 - assert(extra == NULL);
1.334 - if (!(session && state && extra == NULL))
1.335 - return PEP_ILLEGAL_VALUE;
1.336 -
1.337 - return _notifyHandshake(session, partner, SYNC_NOTIFY«$uname»);
1.338 + return PEP_STATUS_OK;
1.339 }
1.340
1.341 ||