// This file is under GNU General Public License 3.0
|
|
// see LICENSE.txt
|
|
|
|
// generate conditions and actions
|
|
|
|
// Copyleft (c) 2017, 2018, p≡p foundation
|
|
|
|
// Written by Volker Birk
|
|
|
|
|
|
include yslt.yml2
|
|
|
|
decl _func *name (*type) alias - {
|
|
template %name=*name, %type=*type, "%type[@name='%name']"
|
|
call *type with "content" content;
|
|
};
|
|
|
|
decl condition is _func (*type="condition");
|
|
decl action is _func (*type="action");
|
|
decl timeout is _func (*type="fsm");
|
|
|
|
tstylesheet {
|
|
include standardlib.ysl2
|
|
include ./functions.ysl2
|
|
|
|
include from *actfile
|
|
|
|
template "/protocol" {
|
|
document "generated/{@name}_actions.c", "text" {
|
|
||
|
|
/**
|
|
* @file «@name»_actions.c
|
|
* @brief Implementation of «@name» conditions, actions, and timeout handlers defined in «@name»_impl.h,
|
|
* with supporting static (internal) functions
|
|
* @generated from ../sync/gen_actions.ysl2
|
|
*
|
|
* @license GNU General Public License 3.0 - see LICENSE.txt
|
|
*/
|
|
|
|
#include "pEp_internal.h"
|
|
#include "map_asn1.h"
|
|
|
|
#include "«@name»_impl.h"
|
|
`` for "fsm" | #include "«@name»_fsm.h"
|
|
|
|
/**
|
|
* <!-- _TID_greater() -->
|
|
*
|
|
* @internal
|
|
*
|
|
* @brief Compare two traffic identifiers and see if the first is greater than the second
|
|
*
|
|
* @param[in] t1 pointer to the first TID
|
|
* @param[in] t2 pointer to the second TID
|
|
*
|
|
* @retval true if t2 is NULL and t1 is not, or the size of t1 is greater than t2, or
|
|
* the first non-matching byte of t1 is greater than that of t2
|
|
* false otherwise
|
|
*/
|
|
static bool _TID_greater(TID_t *t1, TID_t *t2)
|
|
{
|
|
assert(t1 && t2);
|
|
if (t1 && !t2)
|
|
return true;
|
|
if (!t1)
|
|
return false;
|
|
|
|
if (t1->size > t2->size)
|
|
return true;
|
|
if (t2->size > t1->size)
|
|
return false;
|
|
|
|
return memcmp(t1->buf, t2->buf, t1->size) > 0;
|
|
}
|
|
|
|
/**
|
|
* <!-- _same_identity() -->
|
|
*
|
|
* @internal
|
|
*
|
|
* @brief Determine if two identity refer to the same identity (by comparing the unique identifier
|
|
* of user_id + address)
|
|
*
|
|
* @param[in] ident1 pointer to the first identity
|
|
* @param[in] ident2 pointer to the second identity
|
|
*
|
|
* @retval true if user_id and address match on both identities
|
|
* false otherwise
|
|
*/
|
|
static bool _same_identity(pEp_identity *ident1, pEp_identity *ident2)
|
|
{
|
|
if (!(ident1 && ident1->user_id && ident1->address && ident2 && ident2->user_id && ident2->address))
|
|
return false;
|
|
|
|
return strcmp(ident1->user_id, ident2->user_id) == 0
|
|
&& strcmp(ident1->address, ident2->address) == 0;
|
|
}
|
|
|
|
/**
|
|
* <!-- _have_identity_in() -->
|
|
*
|
|
* @internal
|
|
*
|
|
* @brief Given an identity list and an identity, determine if there is an identity in
|
|
* the list that refers to the same identity as the identity struct.
|
|
*
|
|
* @param[in] il pointer to the identity list
|
|
* @param[in] ident pointer to the identity to search for
|
|
* @param[out] found true if an identity with matching unique identifiers is in the list, else false
|
|
*
|
|
* @retval PEP_ILLEGAL_VALUE any of the input pointers are NULL
|
|
* PEP_OUT_OF_MEMORY if memory problems occur
|
|
* PEP_STATUS_OK otherwise
|
|
*/
|
|
static PEP_STATUS _have_identity_in(identity_list *il, pEp_identity *ident, bool *found)
|
|
{
|
|
assert(il && ident && found);
|
|
if (!(il && ident && found))
|
|
return PEP_ILLEGAL_VALUE;
|
|
|
|
bool _found = false;
|
|
for (identity_list *_il = il; _il && _il->ident; _il = _il->next) {
|
|
if (_same_identity(_il->ident, ident)) {
|
|
_found = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!_found) {
|
|
pEp_identity *_ident = identity_dup(ident);
|
|
if (!_ident)
|
|
return PEP_OUT_OF_MEMORY;
|
|
identity_list *_il = identity_list_add(il, _ident);
|
|
if (!_il) {
|
|
free(_ident);
|
|
return PEP_OUT_OF_MEMORY;
|
|
}
|
|
}
|
|
|
|
*found = _found;
|
|
return PEP_STATUS_OK;
|
|
}
|
|
|
|
||
|
|
apply "func:distinctName(//condition)", 0;
|
|
apply "func:distinctName(//action)", 0;
|
|
apply "/protocol/fsm", 0;
|
|
}
|
|
}
|
|
|
|
template "condition" | #error condition «@name» not implemented\n
|
|
template "action" | #error action «@name» not implemented\n
|
|
|
|
function "condition" {
|
|
param "content";
|
|
||
|
|
PEP_STATUS «@name»(PEP_SESSION session, bool *result)
|
|
{
|
|
assert(session && result);
|
|
if (!(session && result))
|
|
return PEP_ILLEGAL_VALUE;
|
|
|
|
||
|
|
copy "$content";
|
|
||
|
|
|
|
return PEP_STATUS_OK;
|
|
}
|
|
|
|
||
|
|
}
|
|
|
|
function "action" {
|
|
param "content";
|
|
||
|
|
PEP_STATUS «@name»(PEP_SESSION session)
|
|
{
|
|
assert(session);
|
|
if (!session)
|
|
return PEP_ILLEGAL_VALUE;
|
|
|
|
||
|
|
copy "$content";
|
|
||
|
|
|
|
return PEP_STATUS_OK;
|
|
}
|
|
|
|
||
|
|
}
|
|
|
|
function "fsm" {
|
|
param "content";
|
|
||
|
|
PEP_STATUS «@name»TimeoutHandler(PEP_SESSION session)
|
|
{
|
|
assert(session);
|
|
if (!session)
|
|
return PEP_ILLEGAL_VALUE;
|
|
|
|
||
|
|
copy "$content";
|
|
||
|
|
|
|
return PEP_STATUS_OK;
|
|
}
|
|
|
|
||
|
|
}
|
|
}
|
|
|