Browse Source

branch generate API: generating API and adapters, experimental branch

generate_api
Volker Birk 3 years ago
parent
commit
eca7cad6e7
8 changed files with 360 additions and 0 deletions
  1. +12
    -0
      api/Makefile
  2. +109
    -0
      api/basic_api.yml2
  3. +80
    -0
      api/gen_c_header.ysl2
  4. +8
    -0
      api/keymanagement_api.yml2
  5. +69
    -0
      api/message_api.yml2
  6. +34
    -0
      api/pEp.yml2
  7. +40
    -0
      api/to_c.ysl2
  8. +8
    -0
      api/transport_api.yml2

+ 12
- 0
api/Makefile View File

@ -0,0 +1,12 @@
all: basic_api.h
%.xml: %.yml2
yml2proc -P $< -o $@
%.h: %.yml2 pEp.yml2 gen_c_header.ysl2 to_c.ysl2
yml2proc -y gen_c_header.ysl2 pEp.yml2
.PHONY: clean
clean:
rm -f *.xml *.h

+ 109
- 0
api/basic_api.yml2 View File

@ -0,0 +1,109 @@
// p≡p API version 2.0
// Basic API version 0.1
// Copyleft (c) 2019, p≡p foundation
// written by Volker Birk
type ISO639_1 extends string size=2 > a-z
type Hex extends string > a-f0-9
type hash extends hex min=16, max=128,
doc="32bit Key ID to SHA512 in hex";
type TID extends binary size=16,
doc="UUID version 4 variant 1";
enum comm_type {
hex unknown 0;
doc > range 0x01 to 0x09: no encryption, 0x0a to 0x0e: nothing reasonable
hex no_encryption 0x01 doc="generic";
hex no_encrypted_channel 0x02;
hex key_not_found 0x03;
hex key_expired 0x04;
hex key_revoked 0x05;
hex key_b0rken 0x06;
hex key_expired_but_confirmed 0x07
doc="NOT with confirmed bit. Just retaining info here in case of renewal.";
hex my_key_not_included 0x09;
hex security_by_obscurity 0x0a;
hex b0rken_crypto 0x0b;
hex key_too_short 0x0c;
hex compromised 0x0e doc="known compromised connection";
hex compromized 0x0e doc="deprecated misspelling";
hex mistrusted 0x0f doc="known mistrusted key";
doc > range 0x10 to 0x3f: unconfirmed encryption
hex unconfirmed_encryption 0x10 doc="generic";
hex OpenPGP_weak_unconfirmed 0x11 doc="RSA 1024 is weak";
hex to_be_checked 0x20 doc="generic";
hex SMIME_unconfirmed 0x21;
hex CMS_unconfirmed 0x22;
hex strong_but_unconfirmed 0x30 doc="generic";
hex OpenPGP_unconfirmed 0x38 doc="key at least 2048 bit RSA or EC";
hex OTR_unconfirmed 0x3a;
doc > range 0x40 to 0x7f: unconfirmed encryption and anonymization
hex unconfirmed_enc_anon 0x40 doc="generic";
hex pEp_unconfirmed 0x7f
hex confirmed 0x80 doc="this bit decides if trust is confirmed";
doc > range 0x81 to 0x8f: reserved
doc > range 0x90 to 0xbf: confirmed encryption
hex confirmed_encryption 0x90 doc="generic";
hex OpenPGP_weak 0x91 doc="RSA 1024 is weak (unused)";
hex to_be_checked_confirmed 0xa0 doc="generic";
hex SMIME 0xa1;
hex CMS 0xa2;
hex strong_encryption 0xb0 doc="generic";
hex OpenPGP 0xb8 doc="key at least 2048 bit RSA or EC";
hex OTR 0xba;
doc > range 0xc0 to 0xff: confirmed encryption and anonymization
hex confirmed_enc_anon 0xc0 doc="generic";
hex pEp 0xff
} // enum comm_type
struct identity {
field string address;
field hash fpr;
field string user_id;
field string username;
field ISO639_1 lang;
flags {
flag not_for_sync 0x0001
doc="don't use this identity for Sync";
flag list 0x0002
doc="identity of list of persons";
doc | the second octet flags are calculated
flag devicegroup 0x0100
doc="identity of a device group member"
}
} // struct Identity

+ 80
- 0
api/gen_c_header.ysl2 View File

@ -0,0 +1,80 @@
// p≡p API version 2.0
// C header generator
// Copyleft (c) 2019, p≡p foundation
// written by Volker Birk
include yslt.yml2
tstylesheet {
include ./to_c.ysl2
template "/"
apply "package/package[type='api']", 0;
template "package" document "{@name}_api.h", "text" {
||
// pEp API version 2.0
// «../@name»_api.h
// Copyleft (c) 2019, p≡p foundation
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
||
apply "doc|enum|struct", 0;
||
#ifdef __cplusplus
} // extern "C"
#endif
||
}
template "struct" {
||
typedef struct _«func:name()» {
||
apply "field";
||
} «func:name()»;
||
}
template "field" | «@type» «@name»;
template "enum" {
||
typedef enum _«func:name(false)» {
||
apply "item|doc";
||
} «func:name()»;
||
}
template "doc"
||
// «.»
||
template "item" {
0> «func:name(1)»`if "text()" { " = " value "." }``if "position()!=last()" > ,`
choose {
when "@doc" > /* «@doc» */\n
otherwise > \n
}
}
}

+ 8
- 0
api/keymanagement_api.yml2 View File

@ -0,0 +1,8 @@
// p≡p API version 2.0
// Keymanagement API version 0.1
// Copyleft (c) 2019, p≡p foundation
// written by Volker Birk

+ 69
- 0
api/message_api.yml2 View File

@ -0,0 +1,69 @@
// p≡p API version 2.0
// Message API version 0.1
// Copyleft (c) 2019, p≡p foundation
// written by Volker Birk
api message {
/*
struct message {
typedef enum _PEP_text_format {
PEP_text_format_plain = 0,
PEP_text_format_html,
PEP_text_format_other = 0xff
} PEP_text_format;
typedef enum _PEP_msg_direction {
PEP_dir_incoming = 0,
PEP_dir_outgoing
} PEP_msg_direction;
typedef enum _PEP_enc_format {
PEP_enc_none = 0, // message is not encrypted
PEP_enc_pieces, // inline PGP + PGP extensions
PEP_enc_S_MIME, // RFC5751
PEP_enc_PGP_MIME, // RFC3156
PEP_enc_PEP, // pEp encryption format
PEP_enc_PGP_MIME_Outlook1 // Message B0rken by Outlook type 1
} PEP_enc_format;
struct _message_ref_list;
typedef struct _message {
PEP_msg_direction dir;
char *id; // UTF-8 string of message ID
char *shortmsg; // UTF-8 string of short message
char *longmsg; // UTF-8 string of long message
// (plain)
char *longmsg_formatted; // UTF-8 string of long message
// (formatted)
bloblist_t *attachments; // blobs with attachements
char *rawmsg_ref; // reference to raw message data
size_t rawmsg_size; // size of raw message data
timestamp *sent; // when the message is sent
timestamp *recv; // when the message is received
pEp_identity *from; // whom the message is from
identity_list *to; // whom the message is to
pEp_identity *recv_by; // via which identity the message
// is received
identity_list *cc; // whom a CC is being sent
identity_list *bcc; // whom a BCC is being sent
identity_list *reply_to; // where a reply should go to
stringlist_t *in_reply_to; // list of UTF-8 strings with
// MessageIDs of refering messages
struct _message *refering_msg_ref; // reference to refering message
stringlist_t *references; // list of UTF-8 strings with references
struct _message_ref_list *refered_by; // list of references to messages being
// refered
stringlist_t *keywords; // list of UTF-8 strings with keywords
char *comments; // UTF-8 string with comments
stringpair_list_t *opt_fields; // optional fields
PEP_enc_format enc_format; // format of encrypted data
} message;
}
*/
}

+ 34
- 0
api/pEp.yml2 View File

@ -0,0 +1,34 @@
// p≡p API version 2.0
// Copyleft (c) 2019, p≡p foundation
// written by Volker Birk
decl package @name;
decl api @name (type=api) alias package;
decl type @name;
decl extends @type;
decl enum @name;
decl item @name;
decl struct @name;
decl field @type @name;
decl hex is item (output=hex);
decl flag @name;
package pEp {
api transport {
include ./transport_api.yml2
}
api message {
include ./message_api.yml2
}
api keymanagement {
include ./keymanagement_api.yml2
}
api basic {
include ./basic_api.yml2
}
}

+ 40
- 0
api/to_c.ysl2 View File

@ -0,0 +1,40 @@
// p≡p API version 2.0
// C data types
// Copyleft (c) 2019, p≡p foundation
// written by Volker Birk
function "abbr" {
param "text";
if "$text" {
> «substring($text, 1, 1)»
call "abbr" with "text", "substring-after($text, '_')";
}
}
template "*", mode=name {
param "abbr", "false()";
if ".!=/*" {
apply "..", 0, mode=name;
> _
}
choose {
when "name()='enum' and $abbr"
call "abbr" with "text", "@name";
otherwise
> «@name»
}
}
function "name" {
param "abbr", "false()";
apply ".", mode=name with "abbr", "$abbr";
}
def "func:name" {
param "abbr", "false()";
result call "name" with "abbr", "$abbr";
}

+ 8
- 0
api/transport_api.yml2 View File

@ -0,0 +1,8 @@
// p≡p API version 2.0
// Transport API version 0.1
// Copyleft (c) 2019, p≡p foundation
// written by Volker Birk

Loading…
Cancel
Save