sync/gen_actions.ysl2
author Volker Birk <vb@pep.foundation>
Thu, 30 Aug 2018 04:33:59 +0200
branchsync
changeset 2913 b2c2eed5be7a
parent 2906 2d5db5aa47d6
child 2914 f14346676e85
permissions -rw-r--r--
notify the app
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@2913
    63
            apply "func:distinctName(//action)", 0;
vb@2913
    64
            callTimeoutHandler KeySync;
krista@2271
    65
        }
krista@2271
    66
    }
krista@2271
    67
vb@2829
    68
    template "condition" | #error condition «@name» not implemented\n
vb@2829
    69
    template "action" | #error action «@name» not implemented\n
vb@2829
    70
vb@2829
    71
    function "condition" {
vb@2829
    72
        param "content";
vb@2829
    73
        ||
vb@2829
    74
        PEP_STATUS «@name»(PEP_SESSION session, bool *result)
vb@2829
    75
        {
vb@2829
    76
            assert(session && result);
vb@2829
    77
            if (!(session && result))
vb@2829
    78
                return PEP_ILLEGAL_VALUE;
krista@2271
    79
krista@2271
    80
        ||
vb@2829
    81
        copy "$content";
vb@2829
    82
        ||
krista@2271
    83
vb@2829
    84
            return PEP_STATUS_OK;
krista@2271
    85
        }
krista@2271
    86
krista@2271
    87
        ||
krista@2271
    88
    }
krista@2271
    89
vb@2829
    90
    function "action" {
vb@2829
    91
        param "content";
vb@2829
    92
        ||
vb@2829
    93
        PEP_STATUS «@name»(PEP_SESSION session)
vb@2829
    94
        {
vb@2829
    95
            assert(session);
vb@2829
    96
            if (!session)
vb@2829
    97
                return PEP_ILLEGAL_VALUE;
krista@2271
    98
krista@2271
    99
        ||
vb@2829
   100
        copy "$content";
krista@2271
   101
        ||
krista@2271
   102
krista@2271
   103
            return PEP_STATUS_OK;
krista@2271
   104
        }
krista@2271
   105
krista@2271
   106
        ||
krista@2271
   107
    }
krista@2271
   108
}
krista@2271
   109