sync/gen_actions_skeleton.ysl2
author Volker Birk <vb@pep-project.org>
Thu, 19 May 2016 11:48:12 +0200
changeset 665 51b2e250297a
parent 657 224eeaf88a65
child 666 4bac9007324a
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@657
    57
    function "paramcheck" {
vb@657
    58
        param "partner";
vb@657
    59
        choose {
vb@657
    60
            when "$partner"
vb@657
    61
            ||
vb@665
    62
                assert(partner);
vb@665
    63
                if (!(session && partner))
vb@665
    64
                    return PEP_ILLEGAL_VALUE;
vb@657
    65
            ||
vb@657
    66
            otherwise
vb@657
    67
            ||
vb@665
    68
                assert(!partner);
vb@665
    69
                if (!(session && !partner))
vb@665
    70
                    return PEP_ILLEGAL_VALUE;
vb@657
    71
            ||
vb@657
    72
        }
vb@657
    73
    }
vb@657
    74
vb@650
    75
    function "other_action" {
vb@650
    76
        param "action";
vb@623
    77
vb@623
    78
        ||
vb@650
    79
vb@657
    80
        // «$action/@name»() - 
vb@623
    81
        //
vb@623
    82
        //  params:
vb@627
    83
        //      session (in)        session handle
vb@623
    84
        `` if "parm"        | //      partner (in)        partner in sync
vb@623
    85
        `` if "not(parm)"   | //      partner (in)        (must be NULL)
vb@623
    86
        //
vb@623
    87
        //  returns:
vb@623
    88
        //      PEP_STATUS_OK or any other value on error
vb@623
    89
vb@627
    90
        PEP_STATUS «$action/@name»(PEP_SESSION session, const Identity partner)
vb@623
    91
        {
vb@623
    92
            PEP_STATUS status = PEP_STATUS_OK;
vb@623
    93
vb@650
    94
            assert(session);
vb@657
    95
            `` call "paramcheck" with "partner", "parm/partner";
vb@623
    96
vb@623
    97
            // working code
vb@623
    98
vb@623
    99
vb@623
   100
            return status;
vb@650
   101
vb@650
   102
        enomem:
vb@650
   103
            status = PEP_OUT_OF_MEMORY;
vb@650
   104
        error:
vb@650
   105
            // free...
vb@650
   106
            return status;
vb@650
   107
        }
vb@650
   108
vb@650
   109
        ||
vb@650
   110
    }
vb@650
   111
vb@650
   112
    function "send_action" {
vb@650
   113
        param "action";
vb@650
   114
        const "name", "substring($action/@name, 5, 255)";
vb@650
   115
vb@650
   116
        ||
vb@650
   117
vb@650
   118
        // «$action/@name»() - send «$name» message
vb@650
   119
        //
vb@650
   120
        //  params:
vb@650
   121
        //      session (in)        session handle
vb@650
   122
        `` if "parm"        | //      partner (in)        partner in sync
vb@650
   123
        `` if "not(parm)"   | //      partner (in)        (must be NULL)
vb@650
   124
        //
vb@650
   125
        //  returns:
vb@650
   126
        //      PEP_STATUS_OK or any other value on error
vb@650
   127
vb@650
   128
        PEP_STATUS «$action/@name»(PEP_SESSION session, const Identity partner)
vb@650
   129
        {
vb@650
   130
            PEP_STATUS status = PEP_STATUS_OK;
vb@650
   131
vb@650
   132
            assert(session);
vb@657
   133
            `` call "paramcheck" with "partner", "parm/partner";
vb@650
   134
vb@650
   135
            «$name»_t *msg = («$name»_t *) calloc(1, sizeof(«$name»_t));
vb@650
   136
            assert(msg);
vb@650
   137
            if (!msg)
vb@650
   138
                goto enomem;
vb@650
   139
vb@652
   140
            int32_t seq;
vb@652
   141
            status = sequence_value(session, "DeviceGroup", &seq);
vb@652
   142
            if (status != PEP_STATUS_OK)
vb@652
   143
                goto error;
vb@654
   144
            msg->header.sequence = (long) seq;
vb@652
   145
vb@654
   146
            pEp_identity *me = new_identity(NULL, NULL, NULL, NULL);
vb@654
   147
            if (!me)
vb@654
   148
                goto enomem;
vb@654
   149
            status = myself(session, me);
vb@654
   150
            if (status != PEP_STATUS_OK)
vb@654
   151
                goto error;
vb@655
   152
            if (Identity_from_Struct(me, &msg->me) == NULL)
vb@655
   153
                goto enomem;
vb@665
   154
         `` if "parm or $name='OwnKeys'" |
vb@655
   155
         `` if "parm/partner"   |> if (Identity_from_Struct(partner, &msg->partner) == NULL)
vb@655
   156
         `` if "parm/partner"   |>> goto enomem;
vb@655
   157
         `` if "$name='OwnKeys'"|> stringlist_t *sl;
vb@655
   158
         `` if "$name='OwnKeys'"|> status = own_key_retrieve(session, &sl);
vb@655
   159
         `` if "$name='OwnKeys'"|> if (status != PEP_STATUS_OK)
vb@655
   160
         `` if "$name='OwnKeys'"|>> goto error;
vb@655
   161
         `` if "$name='OwnKeys'"|> if (KeyList_from_stringlist(sl, &msg->keylist) == NULL)
vb@655
   162
         `` if "$name='OwnKeys'"|>> goto enomem;
vb@665
   163
vb@650
   164
            return status;
vb@650
   165
vb@650
   166
        enomem:
vb@650
   167
            status = PEP_OUT_OF_MEMORY;
vb@650
   168
        error:
vb@650
   169
            ASN_STRUCT_FREE(asn_DEF_«$name», msg);
vb@650
   170
            return status;
vb@623
   171
        }
vb@623
   172
vb@623
   173
        ||
vb@623
   174
    }
vb@623
   175
}
vb@623
   176