1 // This file is under GNU General Public License 3.0
4 // generate conditions and actions
6 // Copyleft (c) 2017, 2018, p≡p foundation
8 // Written by Volker Birk
13 decl _func *name (*type) alias - {
14 template %name=*name, %type=*type, "%type[@name='%name']"
15 call *type with "content" content;
18 decl condition is _func (*type="condition");
19 decl action is _func (*type="action");
20 decl timeout is _func (*type="fsm");
23 include standardlib.ysl2
24 include ./functions.ysl2
26 include ./cond_act_*.yml2
28 template "/protocol" {
29 document "generated/{@name}_actions.c", "text" {
32 * @file «@name»_actions.c
33 * @brief Implementation of «@name» conditions, actions, and timeout handlers defined in «@name»_impl.h,
34 * with supporting static (internal) functions
35 * @generated from ../sync/gen_actions.ysl2
37 * @license GNU General Public License 3.0 - see LICENSE.txt
40 #include "pEp_internal.h"
43 #include "«@name»_impl.h"
44 `` for "fsm" | #include "«@name»_fsm.h"
47 * <!-- _TID_greater() -->
51 * @brief Compare two traffic identifiers and see if the first is greater than the second
53 * @param[in] t1 pointer to the first TID
54 * @param[in] t2 pointer to the second TID
56 * @retval true if t2 is NULL and t1 is not, or the size of t1 is greater than t2, or
57 * the first non-matching byte of t1 is greater than that of t2
60 static bool _TID_greater(TID_t *t1, TID_t *t2)
68 if (t1->size > t2->size)
70 if (t2->size > t1->size)
73 return memcmp(t1->buf, t2->buf, t1->size) > 0;
77 * <!-- _same_identity() -->
81 * @brief Determine if two identity refer to the same identity (by comparing the unique identifier
82 * of user_id + address)
84 * @param[in] ident1 pointer to the first identity
85 * @param[in] ident2 pointer to the second identity
87 * @retval true if user_id and address match on both identities
90 static bool _same_identity(pEp_identity *ident1, pEp_identity *ident2)
92 if (!(ident1 && ident1->user_id && ident1->address && ident2 && ident2->user_id && ident2->address))
95 return strcmp(ident1->user_id, ident2->user_id) == 0
96 && strcmp(ident1->address, ident2->address) == 0;
100 * <!-- _have_identity_in() -->
104 * @brief Given an identity list and an identity, determine if there is an identity in
105 * the list that refers to the same identity as the identity struct.
107 * @param[in] il pointer to the identity list
108 * @param[in] ident pointer to the identity to search for
109 * @param[out] found true if an identity with matching unique identifiers is in the list, else false
111 * @retval PEP_ILLEGAL_VALUE any of the input pointers are NULL
112 * PEP_OUT_OF_MEMORY if memory problems occur
113 * PEP_STATUS_OK otherwise
115 static PEP_STATUS _have_identity_in(identity_list *il, pEp_identity *ident, bool *found)
117 assert(il && ident && found);
118 if (!(il && ident && found))
119 return PEP_ILLEGAL_VALUE;
122 for (identity_list *_il = il; _il && _il->ident; _il = _il->next) {
123 if (_same_identity(_il->ident, ident)) {
129 pEp_identity *_ident = identity_dup(ident);
131 return PEP_OUT_OF_MEMORY;
132 identity_list *_il = identity_list_add(il, _ident);
135 return PEP_OUT_OF_MEMORY;
140 return PEP_STATUS_OK;
144 apply "func:distinctName(//condition)", 0;
145 apply "func:distinctName(//action)", 0;
146 apply "/protocol/fsm", 0;
150 template "condition" | #error condition «@name» not implemented\n
151 template "action" | #error action «@name» not implemented\n
153 function "condition" {
156 PEP_STATUS «@name»(PEP_SESSION session, bool *result)
158 assert(session && result);
159 if (!(session && result))
160 return PEP_ILLEGAL_VALUE;
166 return PEP_STATUS_OK;
175 PEP_STATUS «@name»(PEP_SESSION session)
179 return PEP_ILLEGAL_VALUE;
185 return PEP_STATUS_OK;
194 PEP_STATUS «@name»TimeoutHandler(PEP_SESSION session)
198 return PEP_ILLEGAL_VALUE;
204 return PEP_STATUS_OK;