broadcast, anycast, unicast… sync
authorVolker Birk <vb@pep.foundation>
Wed, 22 Aug 2018 17:04:03 +0200
branchsync
changeset 28709c0567977ed2
parent 2869 e06e7024a1cd
child 2871 4593a7b8b6a8
broadcast, anycast, unicast…
sync/gen_statemachine.ysl2
     1.1 --- a/sync/gen_statemachine.ysl2	Wed Aug 22 15:28:03 2018 +0200
     1.2 +++ b/sync/gen_statemachine.ysl2	Wed Aug 22 17:04:03 2018 +0200
     1.3 @@ -117,137 +117,188 @@
     1.4          ||
     1.5  
     1.6          document "generated/{@name}_impl.h", "text" {
     1.7 -        ||
     1.8 -        // This file is under GNU General Public License 3.0
     1.9 -        // see LICENSE.txt
    1.10 +            ||
    1.11 +            // This file is under GNU General Public License 3.0
    1.12 +            // see LICENSE.txt
    1.13  
    1.14 -        #pragma once
    1.15 +            #pragma once
    1.16  
    1.17 -        #include "fsm_common.h"
    1.18 -        #include "message_api.h"
    1.19 -        #include "«@name»_event.h"
    1.20 +            #include "fsm_common.h"
    1.21 +            #include "message_api.h"
    1.22 +            #include "«@name»_event.h"
    1.23 +            
    1.24 +            #ifdef __cplusplus
    1.25 +            extern "C" {
    1.26 +            #endif
    1.27 +
    1.28 +            // conditions
    1.29 +
    1.30 +            ||
    1.31 +            for "func:distinctName(*//condition)"
    1.32 +                | PEP_STATUS «@name»(PEP_SESSION session, bool *result);
    1.33 +            ||
    1.34 +
    1.35 +            // actions
    1.36 +
    1.37 +            ||
    1.38 +            for "func:distinctName(*//action)"
    1.39 +                | PEP_STATUS «@name»(PEP_SESSION session);
    1.40 +            ||
    1.41 +
    1.42 +            // notify state machine from event
    1.43 +            // use state to generate «@name» message if necessary
    1.44 +
    1.45 +            PEP_STATUS «@name»_notify(
    1.46 +                    PEP_SESSION session, 
    1.47 +                    «@name»_PR fsm,
    1.48 +                    int message_type
    1.49 +                );
    1.50 +
    1.51 +            // send message about an event to communication partners using state
    1.52 +
    1.53 +            PEP_STATUS send_«@name»_message(
    1.54 +                    PEP_SESSION session, 
    1.55 +                    «@name»_PR fsm,
    1.56 +                    int message_type
    1.57 +                );
    1.58 +
    1.59 +            // receive message and store it in state
    1.60 +
    1.61 +            PEP_STATUS recv_«@name»_event(
    1.62 +                    PEP_SESSION session,
    1.63 +                    «@name»_event_t *ev
    1.64 +                );
    1.65          
    1.66 -        #ifdef __cplusplus
    1.67 -        extern "C" {
    1.68 -        #endif
    1.69 +            // state machine driver
    1.70 +            // if fsm or event set to 0 use fields in src if present
    1.71  
    1.72 -        // conditions
    1.73 +            PEP_STATUS «@name»_driver(
    1.74 +                    PEP_SESSION session,
    1.75 +                    «@name»_PR fsm,
    1.76 +                    int event
    1.77 +                );
    1.78  
    1.79 -        ||
    1.80 -        for "func:distinctName(*//condition)"
    1.81 -            | PEP_STATUS «@name»(PEP_SESSION session, bool *result);
    1.82 -        ||
    1.83 +            PEP_STATUS inject_«@name»_event(
    1.84 +                    PEP_SESSION session, 
    1.85 +                    «@name»_PR fsm,
    1.86 +                    int event
    1.87 +                );
    1.88  
    1.89 -        // actions
    1.90  
    1.91 -        ||
    1.92 -        for "func:distinctName(*//action)"
    1.93 -            | PEP_STATUS «@name»(PEP_SESSION session);
    1.94 -        ||
    1.95 +            #ifdef __cplusplus
    1.96 +            }
    1.97 +            #endif
    1.98  
    1.99 -        // notify state machine from event
   1.100 -        // use state to generate «@name» message if necessary
   1.101 -
   1.102 -        PEP_STATUS «@name»_notify(
   1.103 -                PEP_SESSION session, 
   1.104 -                «@name»_PR fsm,
   1.105 -                int message_type
   1.106 -            );
   1.107 -
   1.108 -        // send message about an event to communication partners using state
   1.109 -
   1.110 -        PEP_STATUS send_«@name»_message(
   1.111 -                PEP_SESSION session, 
   1.112 -                «@name»_PR fsm,
   1.113 -                int message_type
   1.114 -            );
   1.115 -
   1.116 -        // receive message and store it in state
   1.117 -
   1.118 -        PEP_STATUS recv_«@name»_event(
   1.119 -                PEP_SESSION session,
   1.120 -                «@name»_event_t *ev
   1.121 -            );
   1.122 -    
   1.123 -        // state machine driver
   1.124 -        // if fsm or event set to 0 use fields in src if present
   1.125 -
   1.126 -        PEP_STATUS «@name»_driver(
   1.127 -                PEP_SESSION session,
   1.128 -                «@name»_PR fsm,
   1.129 -                int event
   1.130 -            );
   1.131 -
   1.132 -        PEP_STATUS inject_«@name»_event(
   1.133 -                PEP_SESSION session, 
   1.134 -                «@name»_PR fsm,
   1.135 -                int event
   1.136 -            );
   1.137 -
   1.138 -
   1.139 -        #ifdef __cplusplus
   1.140 -        }
   1.141 -        #endif
   1.142 -
   1.143 -        ||
   1.144 +            ||
   1.145          }
   1.146  
   1.147 -        document "generated/{@name}_impl.c", "text"
   1.148 -        ||
   1.149 -        // This file is under GNU General Public License 3.0
   1.150 -        // see LICENSE.txt
   1.151 -    
   1.152 -        #include "«@name»_impl.h"
   1.153 -        #include "pEp_internal.h"
   1.154 -        #include "«@name»_event.h"
   1.155 -        #include "«@name»_codec.h"
   1.156 -        #include "baseprotocol.h"
   1.157 -        `` for "fsm" | #include "«@name»_fsm.h"
   1.158 +        document "generated/{@name}_impl.c", "text" {
   1.159 +            ||
   1.160 +            // This file is under GNU General Public License 3.0
   1.161 +            // see LICENSE.txt
   1.162 +        
   1.163 +            #include "«@name»_impl.h"
   1.164 +            #include "pEp_internal.h"
   1.165 +            #include "«@name»_event.h"
   1.166 +            #include "«@name»_codec.h"
   1.167 +            #include "baseprotocol.h"
   1.168 +            `` for "fsm" | #include "«@name»_fsm.h"
   1.169  
   1.170 -        PEP_STATUS «@name»_driver(
   1.171 -                PEP_SESSION session,
   1.172 -                «@name»_PR fsm,
   1.173 -                int event
   1.174 -            )
   1.175 -        {
   1.176 -            assert(session && fsm);
   1.177 -            if (!(session && fsm))
   1.178 -                return PEP_ILLEGAL_VALUE;
   1.179 +            PEP_STATUS «@name»_driver(
   1.180 +                    PEP_SESSION session,
   1.181 +                    «@name»_PR fsm,
   1.182 +                    int event
   1.183 +                )
   1.184 +            {
   1.185 +                assert(session && fsm);
   1.186 +                if (!(session && fsm))
   1.187 +                    return PEP_ILLEGAL_VALUE;
   1.188  
   1.189 -            int next_state = None;
   1.190 -            do {
   1.191 -                switch (fsm) {
   1.192 -                    `` apply "fsm", 3, mode=driver               
   1.193 -                    default:
   1.194 -                        return PEP_ILLEGAL_VALUE;
   1.195 -                }
   1.196 -            }  while (next_state);
   1.197 +                int next_state = None;
   1.198 +                do {
   1.199 +                    switch (fsm) {
   1.200 +                        `` apply "fsm", 3, mode=driver               
   1.201 +                        default:
   1.202 +                            return PEP_ILLEGAL_VALUE;
   1.203 +                    }
   1.204 +                }  while (next_state);
   1.205  
   1.206 -            return PEP_STATUS_OK;
   1.207 -        }
   1.208 -
   1.209 -        PEP_STATUS inject_«@name»_event(
   1.210 -                PEP_SESSION session, 
   1.211 -                «@name»_PR fsm,
   1.212 -                int event
   1.213 -            )
   1.214 -        {
   1.215 -            «@name»_t *msg = NULL;
   1.216 -            «@name»_event_t *ev = NULL;
   1.217 -
   1.218 -            assert(session && fsm > 0 && event > None);
   1.219 -            if (!(session && fsm > 0 && event > None))
   1.220 -                return PEP_ILLEGAL_VALUE;
   1.221 -
   1.222 -            PEP_STATUS status = PEP_STATUS_OK;
   1.223 -
   1.224 -            if (!session->inject_«yml:lcase(@name)»_event) {
   1.225 -               status = PEP_«yml:ucase(@name)»_NO_INJECT_CALLBACK;
   1.226 -               goto error;
   1.227 +                return PEP_STATUS_OK;
   1.228              }
   1.229  
   1.230 -            if (event < Extra) {
   1.231 -                msg = new_«@name»_message(fsm, event);
   1.232 +            PEP_STATUS inject_«@name»_event(
   1.233 +                    PEP_SESSION session, 
   1.234 +                    «@name»_PR fsm,
   1.235 +                    int event
   1.236 +                )
   1.237 +            {
   1.238 +                «@name»_t *msg = NULL;
   1.239 +                «@name»_event_t *ev = NULL;
   1.240 +
   1.241 +                assert(session && fsm > 0 && event > None);
   1.242 +                if (!(session && fsm > 0 && event > None))
   1.243 +                    return PEP_ILLEGAL_VALUE;
   1.244 +
   1.245 +                PEP_STATUS status = PEP_STATUS_OK;
   1.246 +
   1.247 +                if (!session->inject_«yml:lcase(@name)»_event) {
   1.248 +                   status = PEP_«yml:ucase(@name)»_NO_INJECT_CALLBACK;
   1.249 +                   goto error;
   1.250 +                }
   1.251 +
   1.252 +                if (event < Extra) {
   1.253 +                    msg = new_«@name»_message(fsm, event);
   1.254 +                    if (!msg) {
   1.255 +                        status = PEP_OUT_OF_MEMORY;
   1.256 +                        goto error;
   1.257 +                    }
   1.258 +
   1.259 +                    status = update_«@name»_message(session, msg);
   1.260 +                    if (status)
   1.261 +                        goto error;
   1.262 +                }
   1.263 +
   1.264 +                ev = («@name»_event_t *) calloc(1, sizeof(«@name»_event_t));
   1.265 +                assert(ev);
   1.266 +                if (!ev) {
   1.267 +                    status = PEP_OUT_OF_MEMORY;
   1.268 +                    goto error;
   1.269 +                }
   1.270 +                
   1.271 +                ev->fsm = fsm;
   1.272 +                ev->event = event;
   1.273 +                ev->msg = msg;
   1.274 +
   1.275 +                int result = session->inject_«yml:lcase(@name)»_event(ev,
   1.276 +                        session->«yml:lcase(@name)»_management);
   1.277 +                if (result) {
   1.278 +                    status = PEP_STATEMACHINE_ERROR;
   1.279 +                    goto error;
   1.280 +                }
   1.281 +
   1.282 +                goto the_end;
   1.283 +
   1.284 +            error:
   1.285 +                free(ev);
   1.286 +                free_«@name»_message(msg);
   1.287 +
   1.288 +            the_end:
   1.289 +                return status;
   1.290 +            }
   1.291 +
   1.292 +            PEP_STATUS «@name»_notify(
   1.293 +                    PEP_SESSION session, 
   1.294 +                    «@name»_PR fsm,
   1.295 +                    int message_type
   1.296 +                )
   1.297 +            {
   1.298 +                assert(session && fsm > 0 && message_type > 1 && message_type < Extra);
   1.299 +                if (!(session && fsm > 0 && message_type > 1 && message_type < Extra))
   1.300 +                    return PEP_ILLEGAL_VALUE;
   1.301 +
   1.302 +                PEP_STATUS status = PEP_STATUS_OK;
   1.303 +
   1.304 +                «@name»_t *msg = new_«@name»_message(fsm, message_type);
   1.305                  if (!msg) {
   1.306                      status = PEP_OUT_OF_MEMORY;
   1.307                      goto error;
   1.308 @@ -256,200 +307,164 @@
   1.309                  status = update_«@name»_message(session, msg);
   1.310                  if (status)
   1.311                      goto error;
   1.312 +
   1.313 +                goto the_end;
   1.314 +
   1.315 +            error:
   1.316 +                free_«@name»_message(msg);
   1.317 +
   1.318 +            the_end:
   1.319 +                return status;
   1.320              }
   1.321  
   1.322 -            ev = («@name»_event_t *) calloc(1, sizeof(«@name»_event_t));
   1.323 -            assert(ev);
   1.324 -            if (!ev) {
   1.325 -                status = PEP_OUT_OF_MEMORY;
   1.326 -                goto error;
   1.327 -            }
   1.328 -            
   1.329 -            ev->fsm = fsm;
   1.330 -            ev->event = event;
   1.331 -            ev->msg = msg;
   1.332 +            PEP_STATUS send_«@name»_message(
   1.333 +                    PEP_SESSION session, 
   1.334 +                    «@name»_PR fsm,
   1.335 +                    int message_type
   1.336 +                )
   1.337 +            {
   1.338 +                PEP_STATUS status = PEP_STATUS_OK;
   1.339  
   1.340 -            int result = session->inject_«yml:lcase(@name)»_event(ev,
   1.341 -                    session->«yml:lcase(@name)»_management);
   1.342 -            if (result) {
   1.343 -                status = PEP_STATEMACHINE_ERROR;
   1.344 -                goto error;
   1.345 +                assert(session && fsm > None && message_type > None);
   1.346 +                if (!(session && fsm > None && message_type > None))
   1.347 +                    return PEP_ILLEGAL_VALUE;
   1.348 +                
   1.349 +                «@name»_t *msg = new_«@name»_message(fsm, message_type);
   1.350 +                if (!msg)
   1.351 +                    return PEP_OUT_OF_MEMORY;
   1.352 +
   1.353 +                char *data = NULL;
   1.354 +                message *m = NULL;
   1.355 +                identity_list *channels = NULL;
   1.356 +
   1.357 +                status = update_«@name»_message(session, msg);
   1.358 +                if (status)
   1.359 +                    goto the_end;
   1.360 +
   1.361 +                size_t size = 0;
   1.362 +                status = encode_«@name»_message(msg, &data, &size);
   1.363 +                if (status)
   1.364 +                    goto the_end;
   1.365 +
   1.366 +                switch (message_type) {
   1.367 +                    // these messages are broadcasted
   1.368 +                    `` for "fsm/message[@type='broadcast']" |>> case «@name»:
   1.369 +                        status = _own_identities_retrieve(session, &channels, PEP_idf_not_for_sync);
   1.370 +                        if (!status)
   1.371 +                            goto the_end;
   1.372 +                        break;
   1.373 +
   1.374 +                    // all other go anycast; previously used address is sticky (unicast)
   1.375 +                    default: {
   1.376 +                        if (!session->«yml:lcase(@name)»_state.common.from `> |`|
   1.377 +                            (session->«yml:lcase(@name)»_state.common.from->flags &
   1.378 +                            PEP_idf_not_for_sync)) {
   1.379 +
   1.380 +                            // no address available yet, try to find one
   1.381 +                            status = _own_identities_retrieve(session, &channels, PEP_idf_not_for_sync);
   1.382 +                            if (!status)
   1.383 +                                goto the_end;
   1.384 +                            break;
   1.385 +
   1.386 +                            if (channels && channels->ident) {
   1.387 +                                // only need the first one
   1.388 +                                free_identity_list(channels->next);
   1.389 +                                channels->next = NULL;
   1.390 +                            }
   1.391 +                            else {
   1.392 +                                status = PEP_SYNC_NO_CHANNEL;
   1.393 +                                goto the_end;
   1.394 +                            }
   1.395 +                        }
   1.396 +                        else {
   1.397 +                            pEp_identity *channel = identity_dup(session->«yml:lcase(@name)»_state.common.from);
   1.398 +                            if (!channel) {
   1.399 +                                status = PEP_OUT_OF_MEMORY;
   1.400 +                                goto the_end;
   1.401 +                            }
   1.402 +
   1.403 +                            channels = new_identity_list(channel);
   1.404 +                            if (!channels) {
   1.405 +                                status = PEP_OUT_OF_MEMORY;
   1.406 +                                goto the_end;
   1.407 +                            }
   1.408 +                        }
   1.409 +                    }
   1.410 +                }
   1.411 +
   1.412 +                for (identity_list *li = channels; li && li->ident ; li = li->next) {
   1.413 +                    status = base_prepare_message(
   1.414 +                            li->ident,
   1.415 +                            li->ident,
   1.416 +                            data,
   1.417 +                            size,
   1.418 +                            &m
   1.419 +                        );
   1.420 +                    if (status)
   1.421 +                        goto the_end;
   1.422 +                    
   1.423 +                    status = session->messageToSend(session->«yml:lcase(@name)»_obj, m);
   1.424 +                    free_message(m);
   1.425 +                    m = NULL;
   1.426 +                }
   1.427 +
   1.428 +            the_end:
   1.429 +                free_identity_list(channels);
   1.430 +                free_message(m);
   1.431 +                free(data);
   1.432 +                free_«@name»_message(msg);
   1.433 +                return status;
   1.434              }
   1.435  
   1.436 -            goto the_end;
   1.437 +            PEP_STATUS recv_«@name»_event(
   1.438 +                    PEP_SESSION session,
   1.439 +                    «@name»_event_t *ev
   1.440 +                )
   1.441 +            {
   1.442 +                assert(session && ev);
   1.443 +                if (!(session && ev))
   1.444 +                    return PEP_ILLEGAL_VALUE;
   1.445  
   1.446 -        error:
   1.447 -            free(ev);
   1.448 -            free_«@name»_message(msg);
   1.449 +                PEP_STATUS status = PEP_STATUS_OK;
   1.450  
   1.451 -        the_end:
   1.452 -            return status;
   1.453 -        }
   1.454 +                if (ev->event < Extra) {
   1.455 +                    «@name»_PR fsm = (int) None;
   1.456 +                    int event = None;
   1.457  
   1.458 -        PEP_STATUS «@name»_notify(
   1.459 -                PEP_SESSION session, 
   1.460 -                «@name»_PR fsm,
   1.461 -                int message_type
   1.462 -            )
   1.463 -        {
   1.464 -            assert(session && fsm > 0 && message_type > 1 && message_type < Extra);
   1.465 -            if (!(session && fsm > 0 && message_type > 1 && message_type < Extra))
   1.466 -                return PEP_ILLEGAL_VALUE;
   1.467 +                    status = update_«@name»_state(session, ev->msg, &fsm, &event);
   1.468 +                    if (status)
   1.469 +                        goto error;
   1.470  
   1.471 -            PEP_STATUS status = PEP_STATUS_OK;
   1.472 +                    if (ev->fsm) {
   1.473 +                        if (ev->fsm != fsm |`> |` ev->event != event) {
   1.474 +                            status = PEP_«yml:ucase(@name)»_ILLEGAL_MESSAGE;
   1.475 +                            goto error;
   1.476 +                        }
   1.477 +                    }
   1.478 +                    else {
   1.479 +                        if (ev->event) {
   1.480 +                            status = PEP_«yml:ucase(@name)»_ILLEGAL_MESSAGE;
   1.481 +                            goto error;
   1.482 +                        }
   1.483 +                        ev->fsm = fsm;
   1.484 +                        ev->event = event;
   1.485 +                    }
   1.486 +                }
   1.487  
   1.488 -            «@name»_t *msg = new_«@name»_message(fsm, message_type);
   1.489 -            if (!msg) {
   1.490 -                status = PEP_OUT_OF_MEMORY;
   1.491 -                goto error;
   1.492 +                free_«@name»_message(ev->msg);
   1.493 +                free(ev);
   1.494 +                status = «@name»_driver(session, ev->fsm, ev->event);
   1.495 +                return status;
   1.496 +
   1.497 +            error:
   1.498 +                free_«@name»_message(ev->msg);
   1.499 +                free(ev);
   1.500 +                return status;
   1.501              }
   1.502  
   1.503 -            status = update_«@name»_message(session, msg);
   1.504 -            if (status)
   1.505 -                goto error;
   1.506 -
   1.507 -            goto the_end;
   1.508 -
   1.509 -        error:
   1.510 -            free_«@name»_message(msg);
   1.511 -
   1.512 -        the_end:
   1.513 -            return status;
   1.514 +            ||
   1.515          }
   1.516  
   1.517 -        PEP_STATUS send_«@name»_message(
   1.518 -                PEP_SESSION session, 
   1.519 -                «@name»_PR fsm,
   1.520 -                int message_type
   1.521 -            )
   1.522 -        {
   1.523 -            PEP_STATUS status = PEP_STATUS_OK;
   1.524 -
   1.525 -            assert(session && fsm > None && message_type > None);
   1.526 -            if (!(session && fsm > None && message_type > None))
   1.527 -                return PEP_ILLEGAL_VALUE;
   1.528 -            
   1.529 -            «@name»_t *msg = new_«@name»_message(fsm, message_type);
   1.530 -            if (!msg)
   1.531 -                return PEP_OUT_OF_MEMORY;
   1.532 -
   1.533 -            char *data = NULL;
   1.534 -            message *m = NULL;
   1.535 -            identity_list *channels = NULL;
   1.536 -
   1.537 -            status = update_«@name»_message(session, msg);
   1.538 -            if (status)
   1.539 -                goto the_end;
   1.540 -
   1.541 -            size_t size = 0;
   1.542 -            status = encode_«@name»_message(msg, &data, &size);
   1.543 -            if (status)
   1.544 -                goto the_end;
   1.545 -
   1.546 -            switch (message_type) {
   1.547 -                // these messages are broadcasted
   1.548 -                `` for "fsm/message[@type='broadcast']" |>> case «@name»:
   1.549 -                    status = _own_identities_retrieve(session, &channels, PEP_idf_not_for_sync);
   1.550 -                    if (!status)
   1.551 -                        goto the_end;
   1.552 -                    break;
   1.553 -
   1.554 -                // all other go unicast
   1.555 -                default: {
   1.556 -                    if (!session->«yml:lcase(@name)»_state.common.from `> |`|
   1.557 -                        (session->«yml:lcase(@name)»_state.common.from->flags &
   1.558 -                        PEP_idf_not_for_sync))
   1.559 -                    {
   1.560 -                        status = PEP_SYNC_NO_CHANNEL;
   1.561 -                        goto the_end;
   1.562 -                    }
   1.563 -
   1.564 -                    pEp_identity *channel = identity_dup(session->«yml:lcase(@name)»_state.common.from);
   1.565 -                    if (!channel) {
   1.566 -                        status = PEP_OUT_OF_MEMORY;
   1.567 -                        goto the_end;
   1.568 -                    }
   1.569 -
   1.570 -                    channels = new_identity_list(channel);
   1.571 -                    if (!channels) {
   1.572 -                        status = PEP_OUT_OF_MEMORY;
   1.573 -                        goto the_end;
   1.574 -                    }
   1.575 -                }
   1.576 -            }
   1.577 -
   1.578 -            for (identity_list *li = channels; li && li->ident ; li = li->next) {
   1.579 -                status = base_prepare_message(
   1.580 -                        li->ident,
   1.581 -                        li->ident,
   1.582 -                        data,
   1.583 -                        size,
   1.584 -                        &m
   1.585 -                    );
   1.586 -                if (status)
   1.587 -                    goto the_end;
   1.588 -                
   1.589 -                status = session->messageToSend(session->«yml:lcase(@name)»_obj, m);
   1.590 -                free_message(m);
   1.591 -                m = NULL;
   1.592 -            }
   1.593 -
   1.594 -        the_end:
   1.595 -            free_identity_list(channels);
   1.596 -            free_message(m);
   1.597 -            free(data);
   1.598 -            free_«@name»_message(msg);
   1.599 -            return status;
   1.600 -        }
   1.601 -
   1.602 -        PEP_STATUS recv_«@name»_event(
   1.603 -                PEP_SESSION session,
   1.604 -                «@name»_event_t *ev
   1.605 -            )
   1.606 -        {
   1.607 -            assert(session && ev);
   1.608 -            if (!(session && ev))
   1.609 -                return PEP_ILLEGAL_VALUE;
   1.610 -
   1.611 -            PEP_STATUS status = PEP_STATUS_OK;
   1.612 -
   1.613 -            if (ev->event < Extra) {
   1.614 -                «@name»_PR fsm = (int) None;
   1.615 -                int event = None;
   1.616 -
   1.617 -                status = update_«@name»_state(session, ev->msg, &fsm, &event);
   1.618 -                if (status)
   1.619 -                    goto error;
   1.620 -
   1.621 -                if (ev->fsm) {
   1.622 -                    if (ev->fsm != fsm |`> |` ev->event != event) {
   1.623 -                        status = PEP_«yml:ucase(@name)»_ILLEGAL_MESSAGE;
   1.624 -                        goto error;
   1.625 -                    }
   1.626 -                }
   1.627 -                else {
   1.628 -                    if (ev->event) {
   1.629 -                        status = PEP_«yml:ucase(@name)»_ILLEGAL_MESSAGE;
   1.630 -                        goto error;
   1.631 -                    }
   1.632 -                    ev->fsm = fsm;
   1.633 -                    ev->event = event;
   1.634 -                }
   1.635 -            }
   1.636 -
   1.637 -            free_«@name»_message(ev->msg);
   1.638 -            free(ev);
   1.639 -            status = «@name»_driver(session, ev->fsm, ev->event);
   1.640 -            return status;
   1.641 -
   1.642 -        error:
   1.643 -            free_«@name»_message(ev->msg);
   1.644 -            free(ev);
   1.645 -            return status;
   1.646 -        }
   1.647 -
   1.648 -        ||
   1.649 -
   1.650          apply "fsm", 0, mode=gen;
   1.651      }
   1.652