sync/gen_actions_skeleton.ysl2
author Volker Birk <vb@pep.foundation>
Tue, 23 Aug 2016 11:37:37 +0200
branchkeysync
changeset 1058 1d34706c62d1
parent 1047 2a4a2ec1340b
child 1060 fcfc07caa0f6
permissions -rw-r--r--
some redesign for unicast_msg()
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@1058
    10
    include standardlib.ysl2
vb@623
    11
    include ./functions.ysl2
vb@623
    12
vb@883
    13
    template "/protocol" {
vb@883
    14
        apply "fsm", mode=send, 0;
vb@883
    15
        apply "fsm", mode=other, 0;
vb@883
    16
    }
vb@883
    17
vb@883
    18
    template "fsm", mode=send document "../src/{@filename}_send_actions.c", "text" {
vb@807
    19
        const "name", "@name";
vb@807
    20
        const "filename", "@filename";
vb@851
    21
        ||
vb@883
    22
        // Send Actions for «@name» state machine
vb@623
    23
vb@851
    24
        #include <assert.h>
vb@851
    25
        #include "pEp_internal.h"
vb@851
    26
        #include "keymanagement.h"
vb@851
    27
        #include "message.h"
vb@851
    28
        #include "«@filename»_fsm.h"
vb@851
    29
        #include "baseprotocol.h"
vb@851
    30
        #include "map_asn1.h"
vb@985
    31
        #include "../asn.1/DeviceGroup-Protocol.h"
vb@1047
    32
        #include "sync_impl.h"
vb@851
    33
        ||
vb@851
    34
        for "func:distinctName(//action)"
vb@851
    35
            if "substring(@name, 1, 4) = 'send'"
vb@851
    36
                | #include "../asn.1/«substring(@name, 5, 255)».h"
vb@851
    37
        |
vb@851
    38
        for "func:distinctName(//action)"
vb@883
    39
            if "substring(@name, 1, 4) = 'send'"
vb@883
    40
                call "send_action"
vb@883
    41
                    with "action", ".",
vb@883
    42
                    with "fsm", "$name",
vb@883
    43
                    with "filename", "$filename";
vb@623
    44
    }
vb@623
    45
vb@883
    46
    template "fsm", mode=other document "../src/{@filename}_actions.c.skeleton", "text" {
vb@883
    47
        const "name", "@name";
vb@883
    48
        const "filename", "@filename";
vb@883
    49
        ||
vb@883
    50
        // Actions for «@name» state machine
vb@883
    51
vb@883
    52
        #include <assert.h>
vb@883
    53
        #include "pEp_internal.h"
vb@883
    54
        #include "keymanagement.h"
vb@883
    55
        #include "message.h"
vb@883
    56
        #include "«@filename»_fsm.h"
vb@985
    57
        #include "../asn.1/DeviceGroup-Protocol.h"
vb@883
    58
vb@883
    59
        ||
vb@883
    60
        for "func:distinctName(//action)"
vb@883
    61
            if "substring(@name, 1, 4) != 'send'"
vb@883
    62
                call "other_action"
vb@883
    63
                    with "action", ".",
vb@883
    64
                    with "fsm", "$name",
vb@851
    65
                    with "filename", "$filename";
vb@650
    66
    }
vb@650
    67
vb@657
    68
    function "paramcheck" {
vb@657
    69
        param "partner";
vb@666
    70
        |> assert(session);
vb@657
    71
        choose {
vb@657
    72
            when "$partner"
vb@657
    73
            ||
vb@665
    74
                assert(partner);
vb@665
    75
                if (!(session && partner))
vb@665
    76
                    return PEP_ILLEGAL_VALUE;
vb@657
    77
            ||
vb@657
    78
            otherwise
vb@657
    79
            ||
vb@665
    80
                assert(!partner);
vb@665
    81
                if (!(session && !partner))
vb@665
    82
                    return PEP_ILLEGAL_VALUE;
vb@657
    83
            ||
vb@657
    84
        }
vb@657
    85
    }
vb@657
    86
vb@650
    87
    function "other_action" {
vb@650
    88
        param "action";
vb@690
    89
        param "fsm";
vb@807
    90
        param "filename", "'###'";
vb@623
    91
vb@623
    92
        ||
vb@650
    93
vb@657
    94
        // «$action/@name»() - 
vb@623
    95
        //
vb@623
    96
        //  params:
vb@627
    97
        //      session (in)        session handle
vb@690
    98
        //      state (in)          state the state machine is in
vb@807
    99
        `` if "parm"        | //      partner (in)        partner to communicate with
vb@623
   100
        `` if "not(parm)"   | //      partner (in)        (must be NULL)
vb@623
   101
        //
vb@623
   102
        //  returns:
vb@623
   103
        //      PEP_STATUS_OK or any other value on error
vb@623
   104
vb@690
   105
        PEP_STATUS «$action/@name»(
vb@690
   106
                PEP_SESSION session,
vb@690
   107
                «$fsm»_state state,
vb@939
   108
                Identity partner,
vb@939
   109
                void *extra
vb@690
   110
            )
vb@623
   111
        {
vb@623
   112
            PEP_STATUS status = PEP_STATUS_OK;
vb@623
   113
vb@657
   114
            `` call "paramcheck" with "partner", "parm/partner";
vb@623
   115
vb@623
   116
            // working code
vb@623
   117
vb@951
   118
            free_identity(partner);
vb@951
   119
            // free extra
vb@623
   120
            return status;
vb@650
   121
vb@650
   122
        enomem:
vb@650
   123
            status = PEP_OUT_OF_MEMORY;
vb@650
   124
        error:
vb@951
   125
            free_identity(partner);
vb@951
   126
            // free extra
vb@650
   127
            return status;
vb@650
   128
        }
vb@650
   129
vb@650
   130
        ||
vb@650
   131
    }
vb@650
   132
vb@650
   133
    function "send_action" {
vb@650
   134
        param "action";
vb@690
   135
        param "fsm";
vb@807
   136
        param "filename", "'###'";
vb@650
   137
        const "name", "substring($action/@name, 5, 255)";
vb@1058
   138
        const "lname", "concat(yml:lcase(substring($name, 1, 1)), substring($name, 2))";
vb@650
   139
vb@650
   140
        ||
vb@650
   141
vb@650
   142
        // «$action/@name»() - send «$name» message
vb@650
   143
        //
vb@650
   144
        //  params:
vb@650
   145
        //      session (in)        session handle
vb@690
   146
        //      state (in)          state the state machine is in
vb@807
   147
        `` if "parm"        | //      partner (in)        partner to communicate with
vb@650
   148
        `` if "not(parm)"   | //      partner (in)        (must be NULL)
vb@650
   149
        //
vb@650
   150
        //  returns:
vb@650
   151
        //      PEP_STATUS_OK or any other value on error
vb@650
   152
vb@690
   153
        PEP_STATUS «$action/@name»(
vb@690
   154
                PEP_SESSION session,
vb@690
   155
                «$fsm»_state state,
vb@939
   156
                Identity partner,
vb@939
   157
                void *extra
vb@690
   158
            )
vb@650
   159
        {
vb@650
   160
            PEP_STATUS status = PEP_STATUS_OK;
vb@1058
   161
            `` if "$name='GroupKeys'" |> identity_list *kl = new_identity_list(NULL);
vb@650
   162
vb@1058
   163
            DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_«$lname»);
vb@650
   164
            if (!msg)
vb@650
   165
                goto enomem;
vb@1058
   166
        ||
vb@1058
   167
        choose {
vb@1058
   168
            when "$name='GroupKeys'" {
vb@1058
   169
                |
vb@1058
   170
                |> status = own_identities_retrieve(session, &kl);
vb@1058
   171
                |> if (status != PEP_STATUS_OK)
vb@1058
   172
                |>> goto error;
vb@1058
   173
                |> if (IdentityList_from_identity_list(kl, &msg->payload.choice.groupKeys.ownIdentities) == NULL)
vb@1058
   174
                |>> goto enomem;
vb@951
   175
            }
vb@951
   176
        }
vb@851
   177
        ||
vb@665
   178
vb@1058
   179
            status = unicast_msg(session, partner, state, msg);
vb@690
   180
            if (status != PEP_STATUS_OK)
vb@690
   181
                goto error;
vb@690
   182
vb@955
   183
            `` if "$name='GroupKeys'" |> free_identity_list(kl);
vb@1058
   184
            return PEP_STATUS_OK;
vb@650
   185
vb@650
   186
        enomem:
vb@650
   187
            status = PEP_OUT_OF_MEMORY;
vb@650
   188
        error:
vb@1058
   189
            free_DeviceGroup_Protocol_msg(msg);
vb@955
   190
            `` if "$name='GroupKeys'" |> free_identity_list(kl);
vb@650
   191
            return status;
vb@623
   192
        }
vb@623
   193
vb@623
   194
        ||
vb@623
   195
    }
vb@623
   196
}
vb@623
   197