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