Browse Source

basic structure and skeleton

import_own_key
Volker Birk 6 years ago
parent
commit
3c52f6df37
10 changed files with 281 additions and 121 deletions
  1. +2
    -0
      Makefile.conf
  2. +12
    -0
      src/fsm_driver.c
  3. +160
    -0
      src/sync_actions.c
  4. +0
    -15
      src/sync_codec.c
  5. +8
    -9
      src/sync_fsm.h
  6. +9
    -8
      sync/Makefile
  7. +12
    -0
      sync/functions.ysl2
  8. +73
    -0
      sync/gen_actions_skeleton.ysl2
  9. +0
    -84
      sync/gen_codec.ysl2
  10. +5
    -5
      sync/gen_statemachine.ysl2

+ 2
- 0
Makefile.conf View File

@ -8,6 +8,8 @@ LD=$(CC)
# the next two lines are ignored on Windoze
SYSTEM_DB=/usr/local/share/pEp/system.db
PREFIX=$(HOME)
YML2PROC=$(HOME)/yml2/yml2proc
YML_HOME=$(HOME)
# C makros (not environment variables) to overwrite:
#


+ 12
- 0
src/fsm_driver.c View File

@ -0,0 +1,12 @@
// Driver for DeviceState state machine
#include <assert.h>
#include "sync_fsm.h"
PEP_STATUS fsm_DeviceState_inject(PEP_SESSION session, DeviceState_event event)
{
PEP_STATUS status = PEP_STATUS_OK;
return status;
}

+ 160
- 0
src/sync_actions.c View File

@ -0,0 +1,160 @@
// Actions for DeviceState state machine
#include <assert.h>
#include "sync_fsm.h"
// sendBeacon() -
//
// params:
// partner (in) (must be NULL)
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS sendBeacon(const Identity partner)
{
PEP_STATUS status = PEP_STATUS_OK;
assert(partner == NULL);
if (partner)
return PEP_ILLEGAL_VALUE;
// working code
return status;
}
// sendHandshakeRequest() -
//
// params:
// partner (in) partner in sync
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS sendHandshakeRequest(const Identity partner)
{
PEP_STATUS status = PEP_STATUS_OK;
assert(partner);
if (!partner)
return PEP_ILLEGAL_VALUE;
// working code
return status;
}
// showHandshake() -
//
// params:
// partner (in) partner in sync
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS showHandshake(const Identity partner)
{
PEP_STATUS status = PEP_STATUS_OK;
assert(partner);
if (!partner)
return PEP_ILLEGAL_VALUE;
// working code
return status;
}
// reject() -
//
// params:
// partner (in) partner in sync
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS reject(const Identity partner)
{
PEP_STATUS status = PEP_STATUS_OK;
assert(partner);
if (!partner)
return PEP_ILLEGAL_VALUE;
// working code
return status;
}
// storeGroupKeys() -
//
// params:
// partner (in) partner in sync
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS storeGroupKeys(const Identity partner)
{
PEP_STATUS status = PEP_STATUS_OK;
assert(partner);
if (!partner)
return PEP_ILLEGAL_VALUE;
// working code
return status;
}
// sendOwnKeys() -
//
// params:
// partner (in) (must be NULL)
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS sendOwnKeys(const Identity partner)
{
PEP_STATUS status = PEP_STATUS_OK;
assert(partner == NULL);
if (partner)
return PEP_ILLEGAL_VALUE;
// working code
return status;
}
// transmitGroupKeys() -
//
// params:
// partner (in) partner in sync
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS transmitGroupKeys(const Identity partner)
{
PEP_STATUS status = PEP_STATUS_OK;
assert(partner);
if (!partner)
return PEP_ILLEGAL_VALUE;
// working code
return status;
}

+ 0
- 15
src/sync_codec.c View File

@ -1,15 +0,0 @@
// encoders and decoders state for DeviceGroup protocol
#include "sync_fsm.h"
// decoders
void readBeacon(const char *buf, size_t size);
void readHandshakeRequest(const char *buf, size_t size, Identity partner);
void readOwnKeys(const char *buf, size_t size, Stringlist *ownKeys);
// encoders
void createBeacon(const char **bufp, size_t *sizep);
void createHandshakeRequest(const char **bufp, size_t *sizep, Identity partner);
void createOwnKeys(const char **bufp, size_t *sizep, Stringlist *ownKeys);

+ 8
- 9
src/sync_fsm.h View File

@ -7,7 +7,6 @@
// types
typedef pEp_identity * Identity;
typedef stringlist_t * Stringlist;
typedef union _param { const Identity partner; const stringlist_t *keylist; } param_t;
// error values
@ -43,15 +42,15 @@ typedef enum _DeviceState_event {
// actions
void sendBeacon(const Identity partner);
void sendHandshakeRequest(const Identity partner);
void showHandshake(const Identity partner);
void reject(const Identity partner);
void storeGroupKeys(const Identity partner);
void sendOwnKeys(const Identity partner);
void transmitGroupKeys(const Identity partner);
PEP_STATUS sendBeacon(const Identity partner);
PEP_STATUS sendHandshakeRequest(const Identity partner);
PEP_STATUS showHandshake(const Identity partner);
PEP_STATUS reject(const Identity partner);
PEP_STATUS storeGroupKeys(const Identity partner);
PEP_STATUS sendOwnKeys(const Identity partner);
PEP_STATUS transmitGroupKeys(const Identity partner);
// driver
void fsm_DeviceState_inject(PEP_SESSION session, DeviceState_event event);
PEP_STATUS fsm_DeviceState_inject(PEP_SESSION session, DeviceState_event event);

+ 9
- 8
sync/Makefile View File

@ -1,15 +1,16 @@
all: ../src/sync_fsm.c ../src/sync_codec.c
include ../Makefile.conf
../src/sync_fsm.c: sync.fsm gen_statemachine.ysl2 fsm.yml2
yml2proc -y gen_statemachine.ysl2 $< -o $@
all: ../src/sync_fsm.c
../src/sync_codec.c: sync.fsm gen_codec.ysl2 fsm.yml2
yml2proc -y gen_codec.ysl2 $< -o $@
skeleton: ../src/sync_actions.c
sync.xml: sync.fsm fsm.yml2
yml2proc -P sync.fsm -o sync.xml
../src/sync_actions.c: sync.fsm gen_actions_skeleton.ysl2 fsm.yml2 functions.ysl2
$(YML2PROC) -y gen_actions_skeleton.ysl2 $< -o $@
../src/sync_fsm.c: sync.fsm gen_statemachine.ysl2 fsm.yml2 functions.ysl2
$(YML2PROC) -y gen_statemachine.ysl2 $< -o $@
.PHONY: clean
clean:
rm -f *.xml ../src/sync_fsm.c
rm -f *.xml *.xsl ../src/sync_fsm.*

+ 12
- 0
sync/functions.ysl2 View File

@ -0,0 +1,12 @@
// function library
def "func:distinctName" {
param "nodes", "/..";
choose {
when "not($nodes)"
result "/..";
otherwise {
result "$nodes[1] | func:distinctName($nodes[position() > 1])[@name != $nodes[1]/@name]";
}
}
}

+ 73
- 0
sync/gen_actions_skeleton.ysl2 View File

@ -0,0 +1,73 @@
// generate actions skeleton
// Copyleft (c) 2016, p≡p foundation
// Written by Volker Birk
include yslt.yml2
tstylesheet {
include ./functions.ysl2
template "/protocol/fsm" {
document "../src/fsm_driver.c", "text"
||
// Driver for «@name» state machine
#include <assert.h>
#include "sync_fsm.h"
PEP_STATUS fsm_«@name»_inject(PEP_SESSION session, «@name»_event event)
{
PEP_STATUS status = PEP_STATUS_OK;
return status;
}
||
||
// Actions for «@name» state machine
#include <assert.h>
#include "sync_fsm.h"
`` for "func:distinctName(//action)" call "action" with "action", ".";
||
}
function "action" {
param "action";
||
// «$action/@name»() -
//
// params:
`` if "parm" | // partner (in) partner in sync
`` if "not(parm)" | // partner (in) (must be NULL)
//
// returns:
// PEP_STATUS_OK or any other value on error
PEP_STATUS «$action/@name»(const Identity partner)
{
PEP_STATUS status = PEP_STATUS_OK;
`` if "parm" |> assert(partner);
`` if "parm" |> if (!partner)
`` if "parm" |>> return PEP_ILLEGAL_VALUE;
`` if "not(parm)" |> assert(partner == NULL);
`` if "not(parm)" |> if (partner)
`` if "not(parm)" |>> return PEP_ILLEGAL_VALUE;
// working code
return status;
}
||
}
}

+ 0
- 84
sync/gen_codec.ysl2 View File

@ -1,84 +0,0 @@
// generate encoder and decoders for protocol messages
// Copyleft (c) 2016, p≡p foundation
include yslt.yml2
tstylesheet {
key "ActionByNames", "/protocol/fsm/state/event//action", "@name";
variable "UniqueActions", "/protocol/fsm/state/event//action[generate-id()=generate-id(key('ActionByNames',@name)[1])]";
variable "UniqueSendActions", "$UniqueActions[starts-with(@name,'send')]";
template "/protocol" {
||
// encoders and decoders state for «@name» protocol
#include "sync_fsm.h"
// decoders
||
apply "$UniqueSendActions",0 mode="proto" {
with "pfx", "'read'";
with "baseParms" > const char *buf, size_t size
}
||
// encoders
||
apply "$UniqueSendActions",0 mode="proto" {
with "pfx", "'create'";
with "baseParms" > const char **bufp, size_t *sizep
}
||
||
}
def "xsl:typeOfActionParam" {
param "n", "name(.)";
result "ancestor::event/child::parm[child::*[position()=2 and name(.)=$n]]/child::*[position()=1]";
}
function "interfaces_params" {
param "ifaceName";
// variable "ifaceCommons", "/protocol/interface[@name = 'commons']/*";
variable "ifaceParams", "$UniqueActions[@name = concat('send',$ifaceName)]/parm/*";
variable "ifaceAdditions", "/protocol/interface[@name = $ifaceName]/*";
// if "count($ifaceCommons) != 0" > ,
// for "$ifaceCommons" > «name(.)» *«name(./*)»`if "position() != last()" > ,`
if "count($ifaceParams) != 0" > ,
for "set:distinct($ifaceParams)" {
> «name(xsl:typeOfActionParam())» «name(.)»
if "position() != last()" > ,
}
if "count($ifaceAdditions) != 0" > ,
for "$ifaceAdditions" > «name(.)» *«name(./*)»`if "position() != last()" > ,`
}
template "action", mode="func_header" {
param "pfx";
param "baseParms";
variable "ifaceName", "substring-after(@name, 'send')";
> void «$pfx»«$ifaceName»(«$baseParms»
call("interfaces_params") with "ifaceName", "$ifaceName";
> )
}
template "action", mode="proto" {
param "pfx";
param "baseParms";
apply ".",0 mode="func_header" {
with "pfx", "$pfx" ;
with "baseParms", "$baseParms" ;
}
| ;
}
}

+ 5
- 5
sync/gen_statemachine.ysl2 View File

@ -7,6 +7,7 @@
include yslt.yml2
tstylesheet {
include ./functions.ysl2
template "/protocol/fsm" {
document "../src/sync_fsm.h", "text"
@ -20,7 +21,6 @@ tstylesheet {
// types
typedef pEp_identity * Identity;
typedef stringlist_t * Stringlist;
typedef union _param { const Identity partner; const stringlist_t *keylist; } param_t;
// error values
@ -33,22 +33,22 @@ tstylesheet {
// states
typedef enum _«@name»_state {
`` for "set:distinct(state/@name)" |> «.»`if "position()!=last()" > , `
`` for "func:distinctName(state)" |> «@name»`if "position()!=last()" > , `
} «@name»_state;
// events
typedef enum _«@name»_event {
`` for "set:distinct(state/event/@name)" |> «.»`if "position()!=last()" > , `
`` for "func:distinctName(state/event)" |> «@name»`if "position()!=last()" > , `
} «@name»_event;
// actions
`` for "set:distinct(state/event//action/@name)" | void «.»(const Identity partner);
`` for "func:distinctName(//action)" | PEP_STATUS «@name»(const Identity partner);
// driver
void fsm_«@name»_inject(PEP_SESSION session, «@name»_event event);
PEP_STATUS fsm_«@name»_inject(PEP_SESSION session, «@name»_event event);
||
||


Loading…
Cancel
Save