sync/gen_actions.ysl2
author Volker Birk <vb@pep.foundation>
Wed, 29 Aug 2018 21:40:59 +0200
branchsync
changeset 2902 5692b0768f9e
parent 2844 6fce34991f7d
child 2903 33549a7c7191
permissions -rw-r--r--
resolve handshake symmetry
     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                 if (t1->size > t2->size)
    41                     return true;
    42 
    43                 if (t2->size > t1->size)
    44                     return false;
    45 
    46                 for (int i=0; i<t1->size; i++) {
    47                     if (t1->buf[i] > t2->buf[i])
    48                         return true;
    49                 }
    50 
    51                 return false;
    52             }
    53 
    54             ||
    55             apply "func:distinctName(//condition)", 0;
    56             apply "func:distinctName(//action[not(starts-with(@name, 'send'))])", 0;
    57         }
    58     }
    59 
    60     template "condition" | #error condition «@name» not implemented\n
    61     template "action" | #error action «@name» not implemented\n
    62 
    63     function "condition" {
    64         param "content";
    65         ||
    66         PEP_STATUS «@name»(PEP_SESSION session, bool *result)
    67         {
    68             assert(session && result);
    69             if (!(session && result))
    70                 return PEP_ILLEGAL_VALUE;
    71 
    72         ||
    73         copy "$content";
    74         ||
    75 
    76             return PEP_STATUS_OK;
    77         }
    78 
    79         ||
    80     }
    81 
    82     function "action" {
    83         param "content";
    84         ||
    85         PEP_STATUS «@name»(PEP_SESSION session)
    86         {
    87             assert(session);
    88             if (!session)
    89                 return PEP_ILLEGAL_VALUE;
    90 
    91         ||
    92         copy "$content";
    93         ||
    94 
    95             return PEP_STATUS_OK;
    96         }
    97 
    98         ||
    99     }
   100 }
   101