sync/gen_actions_skeleton.ysl2
author Volker Birk <vb@pep-project.org>
Wed, 18 May 2016 13:59:30 +0200
changeset 655 8413f45947e8
parent 654 0aa96447e38f
child 656 bf63654b3a39
permissions -rw-r--r--
...
vb@623
     1
// generate actions skeleton
vb@623
     2
vb@623
     3
// Copyleft (c) 2016, p≡p foundation
vb@623
     4
vb@623
     5
// Written by Volker Birk
vb@623
     6
vb@623
     7
include yslt.yml2
vb@623
     8
vb@623
     9
tstylesheet {
vb@623
    10
    include ./functions.ysl2
vb@623
    11
vb@623
    12
    template "/protocol/fsm" {
vb@625
    13
    document "../src/sync_driver.c", "text"
vb@623
    14
    ||
vb@623
    15
    // Driver for «@name» state machine
vb@623
    16
vb@623
    17
    #include <assert.h>
vb@623
    18
    #include "sync_fsm.h"
vb@623
    19
vb@623
    20
vb@623
    21
    PEP_STATUS fsm_«@name»_inject(PEP_SESSION session, «@name»_event event)
vb@623
    22
    {
vb@623
    23
        PEP_STATUS status = PEP_STATUS_OK;
vb@623
    24
vb@626
    25
        static «@name»_state state = InitState;
vb@626
    26
        static Identity partner = NULL;
vb@624
    27
vb@627
    28
        state = fsm_«@name»(session, state, event, partner);
vb@623
    29
        return status;
vb@623
    30
    }
vb@626
    31
vb@623
    32
    ||
vb@623
    33
    ||
vb@623
    34
    // Actions for «@name» state machine
vb@623
    35
vb@623
    36
    #include <assert.h>
vb@654
    37
    #include "keymanagement.h"
vb@623
    38
    #include "sync_fsm.h"
vb@650
    39
    #include "map_asn1.h"
vb@651
    40
    `` for "func:distinctName(//action)" if "substring(@name, 1, 4) = 'send'" | #include "../asn.1/«substring(@name, 5, 255)».h"
vb@623
    41
vb@623
    42
    `` for "func:distinctName(//action)" call "action" with "action", ".";
vb@623
    43
vb@623
    44
    ||
vb@623
    45
    }
vb@623
    46
vb@623
    47
    function "action" {
vb@623
    48
        param "action";
vb@650
    49
        choose {
vb@651
    50
            when "substring($action/@name, 1, 4) = 'send'"
vb@650
    51
                call "send_action" with "action", "$action";
vb@650
    52
            otherwise
vb@650
    53
                call "other_action" with "action", "$action";
vb@650
    54
        }
vb@650
    55
    }
vb@650
    56
vb@650
    57
    function "other_action" {
vb@650
    58
        param "action";
vb@623
    59
vb@623
    60
        ||
vb@650
    61
vb@650
    62
        // «$action/@name»() - send
vb@623
    63
        //
vb@623
    64
        //  params:
vb@627
    65
        //      session (in)        session handle
vb@623
    66
        `` if "parm"        | //      partner (in)        partner in sync
vb@623
    67
        `` if "not(parm)"   | //      partner (in)        (must be NULL)
vb@623
    68
        //
vb@623
    69
        //  returns:
vb@623
    70
        //      PEP_STATUS_OK or any other value on error
vb@623
    71
vb@627
    72
        PEP_STATUS «$action/@name»(PEP_SESSION session, const Identity partner)
vb@623
    73
        {
vb@623
    74
            PEP_STATUS status = PEP_STATUS_OK;
vb@623
    75
vb@650
    76
            assert(session);
vb@623
    77
        `` if "parm"        |> assert(partner);
vb@650
    78
        `` if "parm"        |> if (!(session && partner))
vb@623
    79
        `` if "parm"        |>> return PEP_ILLEGAL_VALUE;
vb@650
    80
        `` if "not(parm)"   |> assert(!partner);
vb@650
    81
        `` if "not(parm)"   |> if (!(session && !partner))
vb@623
    82
        `` if "not(parm)"   |>> return PEP_ILLEGAL_VALUE;
vb@623
    83
vb@623
    84
            // working code
vb@623
    85
vb@623
    86
vb@623
    87
            return status;
vb@650
    88
vb@650
    89
        enomem:
vb@650
    90
            status = PEP_OUT_OF_MEMORY;
vb@650
    91
        error:
vb@650
    92
            // free...
vb@650
    93
            return status;
vb@650
    94
        }
vb@650
    95
vb@650
    96
        ||
vb@650
    97
    }
vb@650
    98
vb@650
    99
    function "send_action" {
vb@650
   100
        param "action";
vb@650
   101
        const "name", "substring($action/@name, 5, 255)";
vb@650
   102
vb@650
   103
        ||
vb@650
   104
vb@650
   105
        // «$action/@name»() - send «$name» message
vb@650
   106
        //
vb@650
   107
        //  params:
vb@650
   108
        //      session (in)        session handle
vb@650
   109
        `` if "parm"        | //      partner (in)        partner in sync
vb@650
   110
        `` if "not(parm)"   | //      partner (in)        (must be NULL)
vb@650
   111
        //
vb@650
   112
        //  returns:
vb@650
   113
        //      PEP_STATUS_OK or any other value on error
vb@650
   114
vb@650
   115
        PEP_STATUS «$action/@name»(PEP_SESSION session, const Identity partner)
vb@650
   116
        {
vb@650
   117
            PEP_STATUS status = PEP_STATUS_OK;
vb@650
   118
vb@650
   119
            assert(session);
vb@655
   120
        `` if "parm/partner"        |> assert(partner);
vb@655
   121
        `` if "parm/partner"        |> if (!(session && partner))
vb@655
   122
        `` if "parm/partner"        |>> return PEP_ILLEGAL_VALUE;
vb@655
   123
        `` if "not(parm/partner)"   |> assert(!partner);
vb@655
   124
        `` if "not(parm/partner)"   |> if (!(session && !partner))
vb@655
   125
        `` if "not(parm/partner)"   |>> return PEP_ILLEGAL_VALUE;
vb@650
   126
vb@650
   127
            «$name»_t *msg = («$name»_t *) calloc(1, sizeof(«$name»_t));
vb@650
   128
            assert(msg);
vb@650
   129
            if (!msg)
vb@650
   130
                goto enomem;
vb@650
   131
vb@652
   132
            int32_t seq;
vb@652
   133
            status = sequence_value(session, "DeviceGroup", &seq);
vb@652
   134
            if (status != PEP_STATUS_OK)
vb@652
   135
                goto error;
vb@654
   136
            msg->header.sequence = (long) seq;
vb@652
   137
vb@654
   138
            pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
vb@654
   139
            if (!me)
vb@654
   140
                goto enomem;
vb@654
   141
            status = myself(session, me);
vb@654
   142
            if (status != PEP_STATUS_OK)
vb@654
   143
                goto error;
vb@655
   144
            if (Identity_from_Struct(me, &msg->me) == NULL)
vb@655
   145
                goto enomem;
vb@654
   146
vb@655
   147
         `` if "parm/partner"   |> if (Identity_from_Struct(partner, &msg->partner) == NULL)
vb@655
   148
         `` if "parm/partner"   |>> goto enomem;
vb@655
   149
         `` if "$name='OwnKeys'"|> stringlist_t *sl;
vb@655
   150
         `` if "$name='OwnKeys'"|> status = own_key_retrieve(session, &sl);
vb@655
   151
         `` if "$name='OwnKeys'"|> if (status != PEP_STATUS_OK)
vb@655
   152
         `` if "$name='OwnKeys'"|>> goto error;
vb@655
   153
         `` if "$name='OwnKeys'"|> if (KeyList_from_stringlist(sl, &msg->keylist) == NULL)
vb@655
   154
         `` if "$name='OwnKeys'"|>> goto enomem;
vb@655
   155
         `` if "parm" |
vb@650
   156
            return status;
vb@650
   157
vb@650
   158
        enomem:
vb@650
   159
            status = PEP_OUT_OF_MEMORY;
vb@650
   160
        error:
vb@650
   161
            ASN_STRUCT_FREE(asn_DEF_«$name», msg);
vb@650
   162
            return status;
vb@623
   163
        }
vb@623
   164
vb@623
   165
        ||
vb@623
   166
    }
vb@623
   167
}
vb@623
   168