sync/gen_actions_skeleton.ysl2
author Krista Grothoff <krista@pep-project.org>
Mon, 24 Oct 2016 14:35:42 +0200
branchENGINE-128
changeset 1325 5f2e643a4fd7
parent 1281 efff88dcdc59
child 1412 51341b8d69d0
permissions -rw-r--r--
ENGINE-128: MIME_encrypt/decrypt convenience functions almost up and running/tested! Need to fix bug in default first.
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 extra
vb@623
   119
            return status;
vb@650
   120
vb@650
   121
        enomem:
vb@650
   122
            status = PEP_OUT_OF_MEMORY;
vb@650
   123
        error:
vb@951
   124
            // free extra
vb@650
   125
            return status;
vb@650
   126
        }
vb@650
   127
vb@650
   128
        ||
vb@650
   129
    }
vb@650
   130
vb@650
   131
    function "send_action" {
vb@650
   132
        param "action";
vb@690
   133
        param "fsm";
vb@807
   134
        param "filename", "'###'";
vb@650
   135
        const "name", "substring($action/@name, 5, 255)";
vb@1058
   136
        const "lname", "concat(yml:lcase(substring($name, 1, 1)), substring($name, 2))";
vb@650
   137
vb@650
   138
        ||
vb@650
   139
vb@650
   140
        // «$action/@name»() - send «$name» message
vb@650
   141
        //
vb@650
   142
        //  params:
vb@650
   143
        //      session (in)        session handle
vb@690
   144
        //      state (in)          state the state machine is in
vb@807
   145
        `` if "parm"        | //      partner (in)        partner to communicate with
vb@650
   146
        `` if "not(parm)"   | //      partner (in)        (must be NULL)
vb@650
   147
        //
vb@650
   148
        //  returns:
vb@650
   149
        //      PEP_STATUS_OK or any other value on error
vb@650
   150
vb@690
   151
        PEP_STATUS «$action/@name»(
vb@690
   152
                PEP_SESSION session,
vb@690
   153
                «$fsm»_state state,
vb@939
   154
                Identity partner,
vb@939
   155
                void *extra
vb@690
   156
            )
vb@650
   157
        {
vb@1060
   158
            assert(session && state);
vb@1060
   159
            if (!(session && state))
vb@1060
   160
                return PEP_ILLEGAL_VALUE;
vb@1060
   161
vb@650
   162
            PEP_STATUS status = PEP_STATUS_OK;
edouard@1281
   163
            `` if "$name='GroupKeys' or $name='GroupUpdate'" |> identity_list *kl = new_identity_list(NULL);
vb@650
   164
vb@1058
   165
            DeviceGroup_Protocol_t *msg = new_DeviceGroup_Protocol_msg(DeviceGroup_Protocol__payload_PR_«$lname»);
vb@650
   166
            if (!msg)
vb@650
   167
                goto enomem;
vb@1058
   168
        ||
vb@1058
   169
        choose {
edouard@1281
   170
            when "$name='GroupKeys' or $name='GroupUpdate'" {
vb@1058
   171
                |
vb@1058
   172
                |> status = own_identities_retrieve(session, &kl);
vb@1058
   173
                |> if (status != PEP_STATUS_OK)
vb@1058
   174
                |>> goto error;
edouard@1281
   175
                |> if (IdentityList_from_identity_list(kl, &msg->payload.choice.«$lname».ownIdentities) == NULL)
vb@1058
   176
                |>> goto enomem;
vb@951
   177
            }
vb@951
   178
        }
edouard@1233
   179
        choose {
edouard@1233
   180
            when "$name='GroupKeys' or $name='HandshakeRequest'" {
edouard@1233
   181
                |
edouard@1233
   182
                |> if (Identity_from_Struct(partner,
edouard@1233
   183
                |>                          &msg->payload.choice.«$lname».partner) == NULL)
edouard@1233
   184
                |>> goto enomem;
edouard@1233
   185
            }
edouard@1233
   186
        }
vb@851
   187
        ||
vb@665
   188
vb@1060
   189
        ||
vb@1060
   190
        choose {
vb@1097
   191
            when "count(/protocol/unencrypted/*[name()=$action/@name]) = 0"
vb@1098
   192
                |> bool encrypted = true;
vb@1098
   193
            otherwise
vb@1097
   194
                |> bool encrypted = false;
vb@1097
   195
        }
vb@1097
   196
        choose {
vb@1060
   197
            when "count(/protocol/broadcast/*[name()=$action/@name]) = 0"
vb@1097
   198
                |> status = unicast_msg(session, partner, state, msg, encrypted);
vb@1060
   199
            otherwise
vb@1097
   200
                |> status = multicast_self_msg(session, state, msg, encrypted);
vb@1060
   201
        }
vb@1060
   202
        ||
vb@690
   203
            if (status != PEP_STATUS_OK)
vb@690
   204
                goto error;
vb@690
   205
edouard@1281
   206
            `` if "$name='GroupKeys' or $name='GroupUpdate'" |> free_identity_list(kl);
vb@1066
   207
            free_DeviceGroup_Protocol_msg(msg);
vb@1058
   208
            return PEP_STATUS_OK;
vb@650
   209
vb@650
   210
        enomem:
vb@650
   211
            status = PEP_OUT_OF_MEMORY;
vb@650
   212
        error:
vb@1058
   213
            free_DeviceGroup_Protocol_msg(msg);
vb@955
   214
            `` if "$name='GroupKeys'" |> free_identity_list(kl);
vb@650
   215
            return status;
vb@623
   216
        }
vb@623
   217
vb@623
   218
        ||
vb@623
   219
    }
vb@623
   220
}
vb@623
   221