branch generate API: generating API and adapters, experimental branch generate_api
authorVolker Birk <vb@pep-project.org>
Tue, 05 Feb 2019 20:42:07 +0100
branchgenerate_api
changeset 3258c65d654c3133
parent 3253 891e6ca8aced
child 3259 5faaa9a5e945
branch generate API: generating API and adapters, experimental branch
api/Makefile
api/basic_api.yml2
api/gen_c_header.ysl2
api/keymanagement_api.yml2
api/message_api.yml2
api/pEp.yml2
api/to_c.ysl2
api/transport_api.yml2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/api/Makefile	Tue Feb 05 20:42:07 2019 +0100
     1.3 @@ -0,0 +1,12 @@
     1.4 +all: basic_api.h
     1.5 +
     1.6 +%.xml: %.yml2
     1.7 +	yml2proc -P $< -o $@
     1.8 +
     1.9 +%.h: %.yml2 pEp.yml2 gen_c_header.ysl2 to_c.ysl2
    1.10 +	yml2proc -y gen_c_header.ysl2 pEp.yml2
    1.11 +
    1.12 +.PHONY: clean
    1.13 +
    1.14 +clean:
    1.15 +	rm -f *.xml *.h
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/api/basic_api.yml2	Tue Feb 05 20:42:07 2019 +0100
     2.3 @@ -0,0 +1,109 @@
     2.4 +// p≡p API version 2.0
     2.5 +// Basic API version 0.1
     2.6 +
     2.7 +// Copyleft (c) 2019, p≡p foundation
     2.8 +
     2.9 +// written by Volker Birk
    2.10 +
    2.11 +
    2.12 +type ISO639_1 extends string size=2 > a-z
    2.13 +
    2.14 +type Hex extends string > a-f0-9
    2.15 +
    2.16 +type hash extends hex min=16, max=128,
    2.17 +    doc="32bit Key ID to SHA512 in hex";
    2.18 +
    2.19 +type TID extends binary size=16,
    2.20 +    doc="UUID version 4 variant 1";
    2.21 +
    2.22 +
    2.23 +enum comm_type {
    2.24 +    hex unknown 0;
    2.25 +
    2.26 +    doc > range 0x01 to 0x09: no encryption, 0x0a to 0x0e: nothing reasonable
    2.27 +
    2.28 +    hex no_encryption 0x01                 doc="generic";
    2.29 +    hex no_encrypted_channel 0x02;
    2.30 +    hex key_not_found 0x03;
    2.31 +    hex key_expired 0x04;
    2.32 +    hex key_revoked 0x05;
    2.33 +    hex key_b0rken 0x06;
    2.34 +
    2.35 +    hex key_expired_but_confirmed 0x07
    2.36 +        doc="NOT with confirmed bit. Just retaining info here in case of renewal.";
    2.37 +
    2.38 +    hex my_key_not_included 0x09;
    2.39 +
    2.40 +    hex security_by_obscurity 0x0a;
    2.41 +    hex b0rken_crypto 0x0b;
    2.42 +    hex key_too_short 0x0c;
    2.43 +
    2.44 +    hex compromised 0x0e                   doc="known compromised connection";
    2.45 +    hex compromized 0x0e                   doc="deprecated misspelling";
    2.46 +    hex mistrusted 0x0f                    doc="known mistrusted key";
    2.47 +
    2.48 +    doc > range 0x10 to 0x3f: unconfirmed encryption
    2.49 +
    2.50 +    hex unconfirmed_encryption 0x10        doc="generic";
    2.51 +    hex OpenPGP_weak_unconfirmed 0x11      doc="RSA 1024 is weak";
    2.52 +
    2.53 +    hex to_be_checked 0x20                 doc="generic";
    2.54 +    hex SMIME_unconfirmed 0x21;
    2.55 +    hex CMS_unconfirmed 0x22;
    2.56 +
    2.57 +    hex strong_but_unconfirmed 0x30        doc="generic";
    2.58 +    hex OpenPGP_unconfirmed 0x38           doc="key at least 2048 bit RSA or EC";
    2.59 +    hex OTR_unconfirmed 0x3a;
    2.60 +
    2.61 +    doc > range 0x40 to 0x7f: unconfirmed encryption and anonymization
    2.62 +
    2.63 +    hex unconfirmed_enc_anon 0x40          doc="generic";
    2.64 +    hex pEp_unconfirmed 0x7f 
    2.65 +
    2.66 +    hex confirmed 0x80                     doc="this bit decides if trust is confirmed";
    2.67 +
    2.68 +    doc > range 0x81 to 0x8f: reserved
    2.69 +    doc > range 0x90 to 0xbf: confirmed encryption
    2.70 +
    2.71 +    hex confirmed_encryption 0x90          doc="generic";
    2.72 +    hex OpenPGP_weak 0x91                  doc="RSA 1024 is weak (unused)";
    2.73 +
    2.74 +    hex to_be_checked_confirmed 0xa0       doc="generic";
    2.75 +    hex SMIME 0xa1;
    2.76 +    hex CMS 0xa2;
    2.77 +
    2.78 +    hex strong_encryption 0xb0             doc="generic";
    2.79 +    hex OpenPGP 0xb8                       doc="key at least 2048 bit RSA or EC";
    2.80 +    hex OTR 0xba;
    2.81 +
    2.82 +    doc > range 0xc0 to 0xff: confirmed encryption and anonymization
    2.83 +
    2.84 +    hex confirmed_enc_anon 0xc0            doc="generic";
    2.85 +    hex pEp 0xff
    2.86 +
    2.87 +} // enum comm_type
    2.88 +
    2.89 +
    2.90 +struct identity {
    2.91 +    
    2.92 +    field string address;
    2.93 +    field hash fpr;
    2.94 +    field string user_id;
    2.95 +    field string username;
    2.96 +    field ISO639_1 lang;
    2.97 +
    2.98 +    flags {
    2.99 +        flag not_for_sync 0x0001
   2.100 +            doc="don't use this identity for Sync";
   2.101 +
   2.102 +        flag list 0x0002
   2.103 +            doc="identity of list of persons";
   2.104 +
   2.105 +        doc | the second octet flags are calculated
   2.106 +
   2.107 +        flag devicegroup 0x0100
   2.108 +            doc="identity of a device group member"
   2.109 +    }
   2.110 +
   2.111 +} // struct Identity
   2.112 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/api/gen_c_header.ysl2	Tue Feb 05 20:42:07 2019 +0100
     3.3 @@ -0,0 +1,80 @@
     3.4 +// p≡p API version 2.0
     3.5 +// C header generator
     3.6 +
     3.7 +// Copyleft (c) 2019, p≡p foundation
     3.8 +
     3.9 +// written by Volker Birk
    3.10 +
    3.11 +
    3.12 +include yslt.yml2
    3.13 +
    3.14 +tstylesheet {
    3.15 +    include ./to_c.ysl2
    3.16 +
    3.17 +    template "/"
    3.18 +        apply "package/package[type='api']", 0;
    3.19 +
    3.20 +    template "package" document "{@name}_api.h", "text" {
    3.21 +    ||
    3.22 +    // pEp API version 2.0
    3.23 +    // «../@name»_api.h
    3.24 +
    3.25 +    // Copyleft (c) 2019, p≡p foundation
    3.26 +
    3.27 +    #pragma once
    3.28 +
    3.29 +    #ifdef __cplusplus
    3.30 +    extern "C" {
    3.31 +    #endif
    3.32 +
    3.33 +    ||
    3.34 +    apply "doc|enum|struct", 0;
    3.35 +    ||
    3.36 +
    3.37 +    #ifdef __cplusplus
    3.38 +    } // extern "C"
    3.39 +    #endif
    3.40 +
    3.41 +    ||
    3.42 +    }
    3.43 +
    3.44 +    template "struct" {
    3.45 +    ||
    3.46 +    typedef struct _«func:name()» {
    3.47 +    ||
    3.48 +    apply "field";
    3.49 +    ||
    3.50 +    } «func:name()»;
    3.51 +
    3.52 +    ||
    3.53 +    }
    3.54 +
    3.55 +    template "field" | «@type» «@name»;
    3.56 +
    3.57 +    template "enum" {
    3.58 +    ||
    3.59 +    typedef enum _«func:name(false)» {
    3.60 +    ||
    3.61 +    apply "item|doc";
    3.62 +    ||
    3.63 +    } «func:name()»;
    3.64 +
    3.65 +    ||
    3.66 +    }
    3.67 +
    3.68 +    template "doc"
    3.69 +    ||
    3.70 +
    3.71 +    // «.»
    3.72 +
    3.73 +    ||
    3.74 +
    3.75 +    template "item" {
    3.76 +        0> «func:name(1)»`if "text()" { " = " value "." }``if "position()!=last()" > ,`
    3.77 +        choose {
    3.78 +            when "@doc" >  /* «@doc» */\n
    3.79 +            otherwise > \n
    3.80 +        }
    3.81 +    }
    3.82 +}
    3.83 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/api/keymanagement_api.yml2	Tue Feb 05 20:42:07 2019 +0100
     4.3 @@ -0,0 +1,8 @@
     4.4 +// p≡p API version 2.0
     4.5 +// Keymanagement API version 0.1
     4.6 +
     4.7 +// Copyleft (c) 2019, p≡p foundation
     4.8 +
     4.9 +// written by Volker Birk
    4.10 +
    4.11 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/api/message_api.yml2	Tue Feb 05 20:42:07 2019 +0100
     5.3 @@ -0,0 +1,69 @@
     5.4 +// p≡p API version 2.0
     5.5 +// Message API version 0.1
     5.6 +
     5.7 +// Copyleft (c) 2019, p≡p foundation
     5.8 +
     5.9 +// written by Volker Birk
    5.10 +
    5.11 +
    5.12 +api message {
    5.13 +/*
    5.14 +    struct message {
    5.15 +typedef enum _PEP_text_format {
    5.16 +    PEP_text_format_plain = 0,
    5.17 +    PEP_text_format_html,
    5.18 +    PEP_text_format_other = 0xff
    5.19 +} PEP_text_format;
    5.20 +
    5.21 +typedef enum _PEP_msg_direction {
    5.22 +    PEP_dir_incoming = 0,
    5.23 +    PEP_dir_outgoing
    5.24 +} PEP_msg_direction;
    5.25 +
    5.26 +typedef enum _PEP_enc_format {
    5.27 +    PEP_enc_none = 0,                       // message is not encrypted
    5.28 +    PEP_enc_pieces,                         // inline PGP + PGP extensions
    5.29 +    PEP_enc_S_MIME,                         // RFC5751
    5.30 +    PEP_enc_PGP_MIME,                       // RFC3156
    5.31 +    PEP_enc_PEP,                            // pEp encryption format
    5.32 +    PEP_enc_PGP_MIME_Outlook1               // Message B0rken by Outlook type 1
    5.33 +} PEP_enc_format;
    5.34 +
    5.35 +struct _message_ref_list;
    5.36 +
    5.37 +typedef struct _message {
    5.38 +    PEP_msg_direction dir;
    5.39 +    char *id;                               // UTF-8 string of message ID
    5.40 +    char *shortmsg;                         // UTF-8 string of short message
    5.41 +    char *longmsg;                          // UTF-8 string of long message
    5.42 +                                            // (plain)
    5.43 +    char *longmsg_formatted;                // UTF-8 string of long message
    5.44 +                                            // (formatted)
    5.45 +    bloblist_t *attachments;                // blobs with attachements
    5.46 +    char *rawmsg_ref;                       // reference to raw message data
    5.47 +    size_t rawmsg_size;                     // size of raw message data
    5.48 +    timestamp *sent;                        // when the message is sent
    5.49 +    timestamp *recv;                        // when the message is received
    5.50 +    pEp_identity *from;                     // whom the message is from
    5.51 +    identity_list *to;                      // whom the message is to
    5.52 +    pEp_identity *recv_by;                  // via which identity the message
    5.53 +                                            // is received
    5.54 +    identity_list *cc;                      // whom a CC is being sent
    5.55 +    identity_list *bcc;                     // whom a BCC is being sent
    5.56 +    identity_list *reply_to;                // where a reply should go to
    5.57 +    stringlist_t *in_reply_to;              // list of UTF-8 strings with
    5.58 +                                            // MessageIDs of refering messages
    5.59 +    struct _message *refering_msg_ref;      // reference to refering message
    5.60 +    stringlist_t *references;               // list of UTF-8 strings with references
    5.61 +    struct _message_ref_list *refered_by;   // list of references to messages being
    5.62 +                                            // refered
    5.63 +    stringlist_t *keywords;                 // list of UTF-8 strings with keywords
    5.64 +    char *comments;                         // UTF-8 string with comments
    5.65 +    stringpair_list_t *opt_fields;          // optional fields
    5.66 +    PEP_enc_format enc_format;              // format of encrypted data
    5.67 +} message;
    5.68 +
    5.69 +    }
    5.70 +*/
    5.71 +}
    5.72 +
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/api/pEp.yml2	Tue Feb 05 20:42:07 2019 +0100
     6.3 @@ -0,0 +1,34 @@
     6.4 +// p≡p API version 2.0
     6.5 +
     6.6 +// Copyleft (c) 2019, p≡p foundation
     6.7 +
     6.8 +// written by Volker Birk
     6.9 +
    6.10 +
    6.11 +decl package @name;
    6.12 +decl api @name (type=api) alias package;
    6.13 +decl type @name;
    6.14 +decl extends @type;
    6.15 +decl enum @name;
    6.16 +decl item @name;
    6.17 +decl struct @name;
    6.18 +decl field @type @name;
    6.19 +decl hex is item (output=hex);
    6.20 +decl flag @name;
    6.21 +
    6.22 +
    6.23 +package pEp {
    6.24 +    api transport {
    6.25 +        include ./transport_api.yml2
    6.26 +    }
    6.27 +    api message {
    6.28 +        include ./message_api.yml2
    6.29 +    }
    6.30 +    api keymanagement {
    6.31 +        include ./keymanagement_api.yml2
    6.32 +    }
    6.33 +    api basic {
    6.34 +        include ./basic_api.yml2
    6.35 +    }
    6.36 +}
    6.37 +
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/api/to_c.ysl2	Tue Feb 05 20:42:07 2019 +0100
     7.3 @@ -0,0 +1,40 @@
     7.4 +// p≡p API version 2.0
     7.5 +// C data types
     7.6 +
     7.7 +// Copyleft (c) 2019, p≡p foundation
     7.8 +
     7.9 +// written by Volker Birk
    7.10 +
    7.11 +
    7.12 +function "abbr" {
    7.13 +    param "text";
    7.14 +    if "$text" {
    7.15 +        > «substring($text, 1, 1)»
    7.16 +        call "abbr" with "text", "substring-after($text, '_')";
    7.17 +    }
    7.18 +}
    7.19 +
    7.20 +template "*", mode=name {
    7.21 +    param "abbr", "false()";
    7.22 +    if ".!=/*" {
    7.23 +        apply "..", 0, mode=name;
    7.24 +        > _
    7.25 +    }
    7.26 +    choose {
    7.27 +        when "name()='enum' and $abbr"
    7.28 +            call "abbr" with "text", "@name";
    7.29 +        otherwise
    7.30 +            > «@name»
    7.31 +    }
    7.32 +}
    7.33 +
    7.34 +function "name" {
    7.35 +    param "abbr", "false()";
    7.36 +    apply ".", mode=name with "abbr", "$abbr";
    7.37 +}
    7.38 +
    7.39 +def "func:name" {
    7.40 +    param "abbr", "false()";
    7.41 +    result call "name" with "abbr", "$abbr";
    7.42 +}
    7.43 +
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/api/transport_api.yml2	Tue Feb 05 20:42:07 2019 +0100
     8.3 @@ -0,0 +1,8 @@
     8.4 +// p≡p API version 2.0
     8.5 +// Transport API version 0.1
     8.6 +
     8.7 +// Copyleft (c) 2019, p≡p foundation
     8.8 +
     8.9 +// written by Volker Birk
    8.10 +
    8.11 +