sync/gen_actions.ysl2
author Dirk Zimmermann <dz@pep.security>
Tue, 09 Apr 2019 16:02:46 +0200
branchIOS-1482
changeset 3480 689c15d6bef7
parent 2921 8bae76a4f918
child 3515 287699a9aa7c
permissions -rw-r--r--
IOS-1482 Xcode: Change organization name.
     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                 for (int i=0; i<t1->size; i++) {
    54                     if (t1->buf[i] > t2->buf[i])
    55                         return true;
    56                     if (t2->buf[i] > t1->buf[i])
    57                         return false;
    58                 }
    59 
    60                 return false;
    61             }
    62 
    63             ||
    64             apply "func:distinctName(//condition)", 0;
    65             apply "func:distinctName(//action)", 0;
    66             apply "/protocol/fsm", 0;
    67         }
    68     }
    69 
    70     template "condition" | #error condition «@name» not implemented\n
    71     template "action" | #error action «@name» not implemented\n
    72 
    73     function "condition" {
    74         param "content";
    75         ||
    76         PEP_STATUS «@name»(PEP_SESSION session, bool *result)
    77         {
    78             assert(session && result);
    79             if (!(session && result))
    80                 return PEP_ILLEGAL_VALUE;
    81 
    82         ||
    83         copy "$content";
    84         ||
    85 
    86             return PEP_STATUS_OK;
    87         }
    88 
    89         ||
    90     }
    91 
    92     function "action" {
    93         param "content";
    94         ||
    95         PEP_STATUS «@name»(PEP_SESSION session)
    96         {
    97             assert(session);
    98             if (!session)
    99                 return PEP_ILLEGAL_VALUE;
   100 
   101         ||
   102         copy "$content";
   103         ||
   104 
   105             return PEP_STATUS_OK;
   106         }
   107 
   108         ||
   109     }
   110 
   111     function "fsm" {
   112         param "content";
   113         ||
   114         PEP_STATUS «@name»TimeoutHandler(PEP_SESSION session)
   115         {
   116             assert(session);
   117             if (!session)
   118                 return PEP_ILLEGAL_VALUE;
   119 
   120         ||
   121         copy "$content";
   122         ||
   123 
   124             return PEP_STATUS_OK;
   125         }
   126 
   127         ||
   128     }
   129 }
   130