sync/gen_actions.ysl2
author Volker Birk <vb@pep.foundation>
Thu, 30 Aug 2018 08:30:30 +0200
branchsync
changeset 2916 8ed7fc2762b9
parent 2915 f53f154a4fc2
child 2921 8bae76a4f918
permissions -rw-r--r--
...
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@2906
     6
// Copyleft (c) 2017, 2018, 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@2916
    19
decl timeout is _func (*type="fsm");
vb@2914
    20
krista@2271
    21
tstylesheet {
krista@2271
    22
    include standardlib.ysl2
krista@2271
    23
    include ./functions.ysl2
krista@2271
    24
vb@2844
    25
    include ./cond_act_*.yml2
vb@2829
    26
krista@2271
    27
    template "/protocol" {
vb@2829
    28
        document "generated/{@name}_actions.c", "text" {
vb@2829
    29
            ||
vb@2829
    30
            // This file is under GNU General Public License 3.0
vb@2829
    31
            // see LICENSE.txt
krista@2271
    32
vb@2830
    33
            #include "pEp_internal.h"
vb@2830
    34
            #include "map_asn1.h"
vb@2830
    35
vb@2829
    36
            #include "«@name»_impl.h"
vb@2829
    37
            `` for "fsm" | #include "«@name»_fsm.h"
krista@2271
    38
vb@2902
    39
            static bool _TID_greater(TID_t *t1, TID_t *t2)
vb@2902
    40
            {
vb@2903
    41
                assert(t1 && t2);
vb@2903
    42
                if (t1 && !t2)
vb@2903
    43
                    return true;
vb@2903
    44
                if (!t1)
vb@2903
    45
                    return false;
vb@2903
    46
vb@2902
    47
                if (t1->size > t2->size)
vb@2902
    48
                    return true;
vb@2902
    49
                if (t2->size > t1->size)
vb@2902
    50
                    return false;
vb@2902
    51
vb@2902
    52
                for (int i=0; i<t1->size; i++) {
vb@2902
    53
                    if (t1->buf[i] > t2->buf[i])
vb@2902
    54
                        return true;
vb@2904
    55
                    if (t2->buf[i] > t1->buf[i])
vb@2904
    56
                        return false;
vb@2902
    57
                }
vb@2902
    58
vb@2902
    59
                return false;
vb@2902
    60
            }
vb@2902
    61
krista@2271
    62
            ||
vb@2829
    63
            apply "func:distinctName(//condition)", 0;
vb@2913
    64
            apply "func:distinctName(//action)", 0;
vb@2915
    65
            apply "/protocol/fsm", 0;
krista@2271
    66
        }
krista@2271
    67
    }
krista@2271
    68
vb@2829
    69
    template "condition" | #error condition «@name» not implemented\n
vb@2829
    70
    template "action" | #error action «@name» not implemented\n
vb@2829
    71
vb@2829
    72
    function "condition" {
vb@2829
    73
        param "content";
vb@2829
    74
        ||
vb@2829
    75
        PEP_STATUS «@name»(PEP_SESSION session, bool *result)
vb@2829
    76
        {
vb@2829
    77
            assert(session && result);
vb@2829
    78
            if (!(session && result))
vb@2829
    79
                return PEP_ILLEGAL_VALUE;
krista@2271
    80
krista@2271
    81
        ||
vb@2829
    82
        copy "$content";
vb@2829
    83
        ||
krista@2271
    84
vb@2829
    85
            return PEP_STATUS_OK;
krista@2271
    86
        }
krista@2271
    87
krista@2271
    88
        ||
krista@2271
    89
    }
krista@2271
    90
vb@2829
    91
    function "action" {
vb@2829
    92
        param "content";
vb@2829
    93
        ||
vb@2829
    94
        PEP_STATUS «@name»(PEP_SESSION session)
vb@2829
    95
        {
vb@2829
    96
            assert(session);
vb@2829
    97
            if (!session)
vb@2829
    98
                return PEP_ILLEGAL_VALUE;
krista@2271
    99
krista@2271
   100
        ||
vb@2829
   101
        copy "$content";
krista@2271
   102
        ||
krista@2271
   103
krista@2271
   104
            return PEP_STATUS_OK;
krista@2271
   105
        }
krista@2271
   106
krista@2271
   107
        ||
krista@2271
   108
    }
vb@2914
   109
vb@2914
   110
    function "fsm" {
vb@2914
   111
        param "content";
vb@2914
   112
        ||
vb@2914
   113
        PEP_STATUS «@name»TimeoutHandler(PEP_SESSION session)
vb@2914
   114
        {
vb@2914
   115
            assert(session);
vb@2914
   116
            if (!session)
vb@2914
   117
                return PEP_ILLEGAL_VALUE;
vb@2914
   118
vb@2914
   119
        ||
vb@2914
   120
        copy "$content";
vb@2914
   121
        ||
vb@2914
   122
vb@2914
   123
            return PEP_STATUS_OK;
vb@2914
   124
        }
vb@2914
   125
vb@2914
   126
        ||
vb@2914
   127
    }
krista@2271
   128
}
krista@2271
   129