sync/gen_actions.ysl2
author Volker Birk <vb@pep.foundation>
Wed, 29 Aug 2018 21:49:28 +0200
branchsync
changeset 2903 33549a7c7191
parent 2902 5692b0768f9e
child 2904 de437ca2e367
permissions -rw-r--r--
safeguards
     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, p≡p foundation
     7 
     8 // Written by Volker Birk
     9 
    10 include yslt.yml2
    11 
    12 decl _func *name (*type) alias - {
    13     template %name=*name, %type=*type, "%type[@name='%name']"
    14         call *type with "content" content;
    15 };
    16 
    17 decl condition is _func (*type="condition");
    18 decl action is _func (*type="action");
    19 
    20 tstylesheet {
    21     include standardlib.ysl2
    22     include ./functions.ysl2
    23 
    24     include ./cond_act_*.yml2
    25 
    26     template "/protocol" {
    27         document "generated/{@name}_actions.c", "text" {
    28             ||
    29             // This file is under GNU General Public License 3.0
    30             // see LICENSE.txt
    31 
    32             #include "pEp_internal.h"
    33             #include "map_asn1.h"
    34 
    35             #include "«@name»_impl.h"
    36             `` for "fsm" | #include "«@name»_fsm.h"
    37 
    38             static bool _TID_greater(TID_t *t1, TID_t *t2)
    39             {
    40                 assert(t1 && t2);
    41                 if (t1 && !t2)
    42                     return true;
    43                 if (!t1)
    44                     return false;
    45 
    46                 if (t1->size > t2->size)
    47                     return true;
    48 
    49                 if (t2->size > t1->size)
    50                     return false;
    51 
    52                 for (int i=0; i<t1->size; i++) {
    53                     if (t1->buf[i] > t2->buf[i])
    54                         return true;
    55                 }
    56 
    57                 return false;
    58             }
    59 
    60             ||
    61             apply "func:distinctName(//condition)", 0;
    62             apply "func:distinctName(//action[not(starts-with(@name, 'send'))])", 0;
    63         }
    64     }
    65 
    66     template "condition" | #error condition «@name» not implemented\n
    67     template "action" | #error action «@name» not implemented\n
    68 
    69     function "condition" {
    70         param "content";
    71         ||
    72         PEP_STATUS «@name»(PEP_SESSION session, bool *result)
    73         {
    74             assert(session && result);
    75             if (!(session && result))
    76                 return PEP_ILLEGAL_VALUE;
    77 
    78         ||
    79         copy "$content";
    80         ||
    81 
    82             return PEP_STATUS_OK;
    83         }
    84 
    85         ||
    86     }
    87 
    88     function "action" {
    89         param "content";
    90         ||
    91         PEP_STATUS «@name»(PEP_SESSION session)
    92         {
    93             assert(session);
    94             if (!session)
    95                 return PEP_ILLEGAL_VALUE;
    96 
    97         ||
    98         copy "$content";
    99         ||
   100 
   101             return PEP_STATUS_OK;
   102         }
   103 
   104         ||
   105     }
   106 }
   107