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