more sample code for Nana ;-) generate_api
authorVolker Birk <vb@pep-project.org>
Fri, 08 Feb 2019 21:51:42 +0100
branchgenerate_api
changeset 32888422831543bd
parent 3287 8688e31f7960
child 3289 a33792c2fb30
more sample code for Nana ;-)
.hgignore
api/Makefile
api/basic_api.yml2
api/message_api.yml2
api/pEp.yml2
     1.1 --- a/.hgignore	Fri Feb 08 20:47:32 2019 +0100
     1.2 +++ b/.hgignore	Fri Feb 08 21:51:42 2019 +0100
     1.3 @@ -77,4 +77,5 @@
     1.4  sync/.statemachines
     1.5  test/msg_2.0.asc
     1.6  test/*Tests
     1.7 +api/*.h
     1.8  
     2.1 --- a/api/Makefile	Fri Feb 08 20:47:32 2019 +0100
     2.2 +++ b/api/Makefile	Fri Feb 08 21:51:42 2019 +0100
     2.3 @@ -1,12 +1,15 @@
     2.4 -all: basic_api.h
     2.5 +all: pEp.xml basic_api.h
     2.6  
     2.7 -%.xml: %.yml2
     2.8 +YML2=$(wildcard *.yml2)
     2.9 +YSL2=$(wildcard *.ysl2)
    2.10 +
    2.11 +%.xml: %.yml2 $(YML2) $(YSL2)
    2.12  	yml2proc -P $< -o $@
    2.13  
    2.14  %.xsl: %.ysl2
    2.15  	yml2proc -DP $< -o $@
    2.16  
    2.17 -%.h: %.yml2 pEp.yml2 gen_c_header.ysl2 to_c.ysl2
    2.18 +%.h: $(YML2) $(YSL2)
    2.19  	yml2proc -y gen_c_header.ysl2 pEp.yml2
    2.20  
    2.21  .PHONY: clean
     3.1 --- a/api/basic_api.yml2	Fri Feb 08 20:47:32 2019 +0100
     3.2 +++ b/api/basic_api.yml2	Fri Feb 08 21:51:42 2019 +0100
     3.3 @@ -14,9 +14,13 @@
     3.4  type hash doc="32bit Key ID to SHA512 in hex"
     3.5      extends hex min=16, max=128;
     3.6  
     3.7 +type hash_list doc="sequence of fingerprints of keys"
     3.8 +    extends list< hash >;
     3.9 +
    3.10  type TID doc="UUID version 4 variant 1"
    3.11      extends binary size=16;
    3.12  
    3.13 +
    3.14  enum comm_type {
    3.15      hex unknown 0;
    3.16  
     4.1 --- a/api/message_api.yml2	Fri Feb 08 20:47:32 2019 +0100
     4.2 +++ b/api/message_api.yml2	Fri Feb 08 21:51:42 2019 +0100
     4.3 @@ -7,62 +7,46 @@
     4.4  // written by Volker Birk
     4.5  
     4.6  
     4.7 -/*
     4.8 -    struct message {
     4.9 -typedef enum _PEP_text_format {
    4.10 -    PEP_text_format_plain = 0,
    4.11 -    PEP_text_format_html,
    4.12 -    PEP_text_format_other = 0xff
    4.13 -} PEP_text_format;
    4.14 +protocol session {
    4.15 +    method encrypt_message
    4.16 +        doc="encrypt message in memory"
    4.17 +    {
    4.18 +        // parms
    4.19  
    4.20 -typedef enum _PEP_msg_direction {
    4.21 -    PEP_dir_incoming = 0,
    4.22 -    PEP_dir_outgoing
    4.23 -} PEP_msg_direction;
    4.24 +        supply message src
    4.25 +        doc="""
    4.26 +            message to encrypt - usually in-only, but can be in-out for
    4.27 +            unencrypted messages; in that case, we may attach the key and
    4.28 +            decorate the message
    4.29 +            """;
    4.30  
    4.31 -typedef enum _PEP_enc_format {
    4.32 -    PEP_enc_none = 0,                       // message is not encrypted
    4.33 -    PEP_enc_pieces,                         // inline PGP + PGP extensions
    4.34 -    PEP_enc_S_MIME,                         // RFC5751
    4.35 -    PEP_enc_PGP_MIME,                       // RFC3156
    4.36 -    PEP_enc_PEP,                            // pEp encryption format
    4.37 -    PEP_enc_PGP_MIME_Outlook1               // Message B0rken by Outlook type 1
    4.38 -} PEP_enc_format;
    4.39 +        use hash_list extra doc="extra keys for encryption";
    4.40  
    4.41 -struct _message_ref_list;
    4.42 +        create message dst
    4.43 +        doc="""
    4.44 +            pointer to new encrypted message or #NV if no encryption could
    4.45 +            take place
    4.46 +            """
    4.47  
    4.48 -typedef struct _message {
    4.49 -    PEP_msg_direction dir;
    4.50 -    char *id;                               // UTF-8 string of message ID
    4.51 -    char *shortmsg;                         // UTF-8 string of short message
    4.52 -    char *longmsg;                          // UTF-8 string of long message
    4.53 -                                            // (plain)
    4.54 -    char *longmsg_formatted;                // UTF-8 string of long message
    4.55 -                                            // (formatted)
    4.56 -    bloblist_t *attachments;                // blobs with attachements
    4.57 -    char *rawmsg_ref;                       // reference to raw message data
    4.58 -    size_t rawmsg_size;                     // size of raw message data
    4.59 -    timestamp *sent;                        // when the message is sent
    4.60 -    timestamp *recv;                        // when the message is received
    4.61 -    pEp_identity *from;                     // whom the message is from
    4.62 -    identity_list *to;                      // whom the message is to
    4.63 -    pEp_identity *recv_by;                  // via which identity the message
    4.64 -                                            // is received
    4.65 -    identity_list *cc;                      // whom a CC is being sent
    4.66 -    identity_list *bcc;                     // whom a BCC is being sent
    4.67 -    identity_list *reply_to;                // where a reply should go to
    4.68 -    stringlist_t *in_reply_to;              // list of UTF-8 strings with
    4.69 -                                            // MessageIDs of refering messages
    4.70 -    struct _message *refering_msg_ref;      // reference to refering message
    4.71 -    stringlist_t *references;               // list of UTF-8 strings with references
    4.72 -    struct _message_ref_list *refered_by;   // list of references to messages being
    4.73 -                                            // refered
    4.74 -    stringlist_t *keywords;                 // list of UTF-8 strings with keywords
    4.75 -    char *comments;                         // UTF-8 string with comments
    4.76 -    stringpair_list_t *opt_fields;          // optional fields
    4.77 -    PEP_enc_format enc_format;              // format of encrypted data
    4.78 -} message;
    4.79 +        use encformat format doc="encrypted format";
    4.80  
    4.81 +        // flags
    4.82 +
    4.83 +        flags {
    4.84 +            flag default 0x0;
    4.85 +            flag force_encryption 0x1;
    4.86 +        }
    4.87 +
    4.88 +        // exceptions
    4.89 +
    4.90 +        throws key_has_ambig_name
    4.91 +            doc="at least one of the receipient keys has an ambiguous name";
    4.92 +
    4.93 +        throws unencrypted
    4.94 +        doc="""
    4.95 +            on demand or no recipients with usable key, is left unencrypted,
    4.96 +            and key is attached to it 
    4.97 +            """
    4.98      }
    4.99 -*/
   4.100 +}
   4.101  
     5.1 --- a/api/pEp.yml2	Fri Feb 08 20:47:32 2019 +0100
     5.2 +++ b/api/pEp.yml2	Fri Feb 08 21:51:42 2019 +0100
     5.3 @@ -17,6 +17,26 @@
     5.4  decl field @type @name;
     5.5  decl hex is item (output=hex);
     5.6  decl flag @name;
     5.7 +decl protocol @name;
     5.8 +decl method @name;
     5.9 +
    5.10 +// use: readonly in param, ownership remains with caller
    5.11 +decl use @type @name (mode=use) alias parm;
    5.12 +
    5.13 +// supply: inout param, ownership remains with caller
    5.14 +decl supply @type @name (mode=supply) alias parm;
    5.15 +
    5.16 +// create: factory delivers this, ownership goes to caller
    5.17 +decl create @type @name (mode=create) alias parm;
    5.18 +
    5.19 +// provide: in param, ownership goes to callee
    5.20 +decl provide @type @name (mode=provide) alias parm;
    5.21 +
    5.22 +// return: out param, ownership goes to callee
    5.23 +decl return @type @name (mode=return) alias parm;
    5.24 +
    5.25 +decl throws @except;
    5.26 +decl caveat(mode=caveat) alias doc;
    5.27  
    5.28  
    5.29  package pEp {