sync/gen_actions.ysl2
author Krista 'DarthMama' Bennett <krista@pep.foundation>
Wed, 16 Oct 2019 16:35:08 +0200
branchENGINE-654
changeset 4118 b0995cc07d02
parent 3515 287699a9aa7c
permissions -rw-r--r--
merged in sync
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 // generate conditions and actions
     5 
     6 // Copyleft (c) 2017, 2018, p≡p foundation
     7 
     8 // Written by Volker Birk
     9 
    10 
    11 include yslt.yml2
    12 
    13 decl _func *name (*type) alias - {
    14     template %name=*name, %type=*type, "%type[@name='%name']"
    15         call *type with "content" content;
    16 };
    17 
    18 decl condition is _func (*type="condition");
    19 decl action is _func (*type="action");
    20 decl timeout is _func (*type="fsm");
    21 
    22 tstylesheet {
    23     include standardlib.ysl2
    24     include ./functions.ysl2
    25 
    26     include ./cond_act_*.yml2
    27 
    28     template "/protocol" {
    29         document "generated/{@name}_actions.c", "text" {
    30             ||
    31             // This file is under GNU General Public License 3.0
    32             // see LICENSE.txt
    33 
    34             #include "pEp_internal.h"
    35             #include "map_asn1.h"
    36 
    37             #include "«@name»_impl.h"
    38             `` for "fsm" | #include "«@name»_fsm.h"
    39 
    40             static bool _TID_greater(TID_t *t1, TID_t *t2)
    41             {
    42                 assert(t1 && t2);
    43                 if (t1 && !t2)
    44                     return true;
    45                 if (!t1)
    46                     return false;
    47 
    48                 if (t1->size > t2->size)
    49                     return true;
    50                 if (t2->size > t1->size)
    51                     return false;
    52 
    53                 return memcmp(t1->buf, t2->buf, t1->size) > 0;
    54             }
    55 
    56             ||
    57             apply "func:distinctName(//condition)", 0;
    58             apply "func:distinctName(//action)", 0;
    59             apply "/protocol/fsm", 0;
    60         }
    61     }
    62 
    63     template "condition" | #error condition «@name» not implemented\n
    64     template "action" | #error action «@name» not implemented\n
    65 
    66     function "condition" {
    67         param "content";
    68         ||
    69         PEP_STATUS «@name»(PEP_SESSION session, bool *result)
    70         {
    71             assert(session && result);
    72             if (!(session && result))
    73                 return PEP_ILLEGAL_VALUE;
    74 
    75         ||
    76         copy "$content";
    77         ||
    78 
    79             return PEP_STATUS_OK;
    80         }
    81 
    82         ||
    83     }
    84 
    85     function "action" {
    86         param "content";
    87         ||
    88         PEP_STATUS «@name»(PEP_SESSION session)
    89         {
    90             assert(session);
    91             if (!session)
    92                 return PEP_ILLEGAL_VALUE;
    93 
    94         ||
    95         copy "$content";
    96         ||
    97 
    98             return PEP_STATUS_OK;
    99         }
   100 
   101         ||
   102     }
   103 
   104     function "fsm" {
   105         param "content";
   106         ||
   107         PEP_STATUS «@name»TimeoutHandler(PEP_SESSION session)
   108         {
   109             assert(session);
   110             if (!session)
   111                 return PEP_ILLEGAL_VALUE;
   112 
   113         ||
   114         copy "$content";
   115         ||
   116 
   117             return PEP_STATUS_OK;
   118         }
   119 
   120         ||
   121     }
   122 }
   123