Browse Source

CodeGen: New enhanced enums, now all enums got .toString(), all enums can have .getInternalStringValue() (This was needed to avoid mapping table in the app, for "casting" Ratings to Engine internal string values for X-Opts .e.g)

JNI-118
heck 5 months ago
parent
commit
c0e2a91578
5 changed files with 118 additions and 88 deletions
  1. +2
    -7
      src/codegen/Makefile
  2. +34
    -4
      src/codegen/gen_java_Message.ysl2
  3. +62
    -64
      src/codegen/pEp.yml2
  4. +6
    -0
      src/codegen/textutils.ysl2
  5. +14
    -13
      utils/gen_status_codes.sh

+ 2
- 7
src/codegen/Makefile View File

@ -38,13 +38,8 @@ codegen: create-dirs gen-status-codes $(YML2_MARKERS)
$(YML2_MARKERS): $(MARKER_DIR)/%.marker : %.ysl2 pEp.yml2 $(YML2_INCLUDES)
$(YML2_PROC) -y $< pEp.yml2
gen-status-codes: status_list.yml2 passphrase_status_list.yml2
status_list.yml2: pEp.yml2
bash ../../utils/extract_pEp_status_codes_from_engine.sh "$(PEP_HEADER)" $@
passphrase_status_list.yml2: status_list.yml2
grep passphrase $< > $@
gen-status-codes: pEp.yml2
bash ../../utils/gen_status_codes.sh "$(PEP_HEADER)"
# ------------- Housekeeping ---------------
create-dirs:


+ 34
- 4
src/codegen/gen_java_Message.ysl2 View File

@ -113,7 +113,7 @@ tstylesheet {
||
// CodeGen template enum, mode=inner
public enum «$jname» {
`` apply "*", mode=value
`` apply "enumitem"
;
public final int value;
@ -319,9 +319,39 @@ tstylesheet {
||
}
template "*", mode=value {
const "name" call "toJava" with "type", "name(.)";
| «$name» («.»)`if "position()!=last()" > , `
template "enumitem" {
const "name_hyphenized" call "hyphenize" with "text", "@name";
const "javaname" call "toJava" with "type", "$name_hyphenized";
const "enum_index", ".";
||
«$javaname» («$enum_index») {
public String toString() {
||
choose {
when "@toString" {
||
return "«@toString»";
||
} otherwise {
||
return "«$javaname»";
||
}
}
||
}
||
choose {
when "@int_str_val" {
||
public String getInternalStringValue() {
return "«@int_str_val»";
}
||
}
}
| }`if "position()!=last()" > , `
}
}

+ 62
- 64
src/codegen/pEp.yml2 View File

@ -1,5 +1,6 @@
decl namespace @name;
decl enum @name;
decl enumitem @name;
decl interface @name;
decl exception @name;
decl method @name;
@ -16,77 +17,74 @@ namespace pEp {
};
enum Color {
PEP_color_no_color > 0
PEP_color_yellow > 1
PEP_color_green > 2
PEP_color_red > -1
enumitem PEP_color_no_color toString="None" > 0
enumitem PEP_color_yellow toString="Yellow" > 1
enumitem PEP_color_green toString="Green" > 2
enumitem PEP_color_red toString="Red" > -1
};
enum Rating {
pEp_rating_undefined > 0
pEp_rating_cannot_decrypt > 1
pEp_rating_have_no_key > 2
pEp_rating_unencrypted > 3
pEp_rating_unencrypted_for_some > 4
pEp_rating_unreliable > 5
pEp_rating_reliable > 6
pEp_rating_trusted > 7
pEp_rating_trusted_and_anonymized > 8
pEp_rating_fully_anonymous > 9
pEp_rating_mistrust > -1
pEp_rating_b0rken > -2
pEp_rating_under_attack > -3
enumitem pEp_rating_undefined int_str_val=undefined toString="undefined" > 0
enumitem pEp_rating_cannot_decrypt int_str_val=cannot_decrypt toString="cannot decrypt" > 1
enumitem pEp_rating_have_no_key int_str_val=have_no_key toString="have no key" > 2
enumitem pEp_rating_unencrypted int_str_val=unencrypted toString="unencrypted" > 3
enumitem pEp_rating_unencrypted_for_some int_str_val=unencrypted_for_some toString="unencrypted for some" > 4
enumitem pEp_rating_unreliable int_str_val=unreliable toString="unreliable" > 5
enumitem pEp_rating_reliable int_str_val=reliable toString="reliable" > 6
enumitem pEp_rating_trusted int_str_val=trusted toString="trusted" > 7
enumitem pEp_rating_trusted_and_anonymized int_str_val=trusted_and_anonymized toString="trusted and anonymized" > 8
enumitem pEp_rating_fully_anonymous int_str_val=fully_anonymous toString="fully anonymous" > 9
enumitem pEp_rating_mistrust int_str_val=mistrust toString="mistrust" > -1
enumitem pEp_rating_b0rken int_str_val=b0rken toString="b0rken" > -2
enumitem pEp_rating_under_attack int_str_val=under_attack toString="under attack" > -3
};
enum DecryptFlags {
pEp_decrypt_flag_own_private_key > 1
pEp_decrypt_flag_consumed > 2
pEp_decrypt_flag_ignored > 4
pEp_decrypt_flag_src_modified > 8
pEp_decrypt_flag_untrusted_server > 0x100
pEp_decrypt_flag_dont_trigger_sync > 0x200
enumitem pEp_decrypt_flag_own_private_key > 1
enumitem pEp_decrypt_flag_consumed > 2
enumitem pEp_decrypt_flag_ignored > 4
enumitem pEp_decrypt_flag_src_modified > 8
enumitem pEp_decrypt_flag_untrusted_server > 0x100
enumitem pEp_decrypt_flag_dont_trigger_sync > 0x200
};
enum IdentityFlags {
pEp_idf_not_for_sync > 1
pEp_idf_list > 2
pEp_idf_devicegroup > 256
enumitem pEp_idf_not_for_sync > 1
enumitem pEp_idf_list > 2
enumitem pEp_idf_devicegroup > 256
};
enum SyncHandshakeResult {
sync_handshake_cancel > -1
sync_handshake_accepted > 0
sync_handshake_rejected > 1
enumitem sync_handshake_cancel > -1
enumitem sync_handshake_accepted > 0
enumitem sync_handshake_rejected > 1
};
enum SyncHandshakeSignal {
sync_notify_undefined > 0
sync_notify_init_add_our_device > 1
sync_notify_init_add_other_device > 2
sync_notify_init_form_group > 3
// sync_notify_init_move_our_device > 4
sync_notify_timeout > 5
sync_notify_accepted_device_added > 6
sync_notify_accepted_group_created > 7
sync_notify_accepted_device_accepted > 8
// sync_notify_overtaken > 9
// sync_notify_forming_group > 10
sync_passphrase_required > 128
sync_notify_sole > 254
sync_notify_in_group > 255
enumitem sync_notify_undefined > 0
enumitem sync_notify_init_add_our_device > 1
enumitem sync_notify_init_add_other_device > 2
enumitem sync_notify_init_form_group > 3
enumitem sync_notify_timeout > 5
enumitem sync_notify_accepted_device_added > 6
enumitem sync_notify_accepted_group_created > 7
enumitem sync_notify_accepted_device_accepted > 8
enumitem sync_passphrase_required > 128
enumitem sync_notify_sole > 254
enumitem sync_notify_in_group > 255
};
enum CipherSuite {
pEp_cipher_suite_default > 0
pEp_cipher_suite_cv25519 > 1
pEp_cipher_suite_p256 > 2
pEp_cipher_suite_p384 > 3
pEp_cipher_suite_p521 > 4
pEp_cipher_suite_rsa2k > 5
pEp_cipher_suite_rsa3k > 6
pEp_cipher_suite_rsa4k > 7
pEp_cipher_suite_rsa8k > 8
enumitem pEp_cipher_suite_default > 0
enumitem pEp_cipher_suite_cv25519 > 1
enumitem pEp_cipher_suite_p256 > 2
enumitem pEp_cipher_suite_p384 > 3
enumitem pEp_cipher_suite_p521 > 4
enumitem pEp_cipher_suite_rsa2k > 5
enumitem pEp_cipher_suite_rsa3k > 6
enumitem pEp_cipher_suite_rsa4k > 7
enumitem pEp_cipher_suite_rsa8k > 8
};
interface Engine {
@ -275,23 +273,23 @@ namespace pEp {
struct message {
enum TextFormat {
plain > 0
html > 1
other > 255
enumitem plain > 0
enumitem html > 1
enumitem other > 255
}
enum direction {
incoming > 0
outgoing > 1
enumitem incoming > 0
enumitem outgoing > 1
}
enum EncFormat {
none > 0
inline > 1
SMIME > 2
PGPMIME > 3
PEP > 4
PEP_enc_inline_EA > 6
enumitem none > 0
enumitem inline > 1
enumitem SMIME > 2
enumitem PGPMIME > 3
enumitem PEP > 4
enumitem PEP_enc_inline_EA > 6
}
direction dir;


+ 6
- 0
src/codegen/textutils.ysl2 View File

@ -10,6 +10,12 @@ function "lcase" {
value "translate($text, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ-', 'abcdefghijklmnopqrstuvwxyz_')";
}
function "hyphenize" {
param "text";
value "translate($text, '_', '-')";
}
function "CamelCase" {
param "text";
const "tokens", "str:tokenize($text, '-')";


utils/extract_pEp_status_codes_from_engine.sh → utils/gen_status_codes.sh View File

@ -6,15 +6,14 @@ if [ ! -f $1 ]; then
echo -e "\e[1m\e[31mInput file not found!\e[0m"
fi
if [ -z "$2" ]; then
echo -e "\e[1m\e[31mNo output file supplied\e[0m"
fi
if [ "$#" -ne 2 ]; then
echo "Expected use is: $0 input_file output_file"
if [ "$#" -ne 1 ]; then
echo "Expected use is: $0 input_file"
exit 1
fi
STAT_FILE=status_list.yml2
PASS_FILE=passphrase_status_list.yml2
################################################################################
# Select GNU SED #
################################################################################
@ -33,15 +32,17 @@ esac
# Transform input file PEP_STATUS to yml2 status #
################################################################################
$SED -n '/} PEP_STATUS/q;p' $1 > $2
$SED -i -n '/STATUS_OK/,$p' $2
$SED -i -e 's/\(.*\)/\L\1/' $2
$SED -i "-e s/ pep/ pEp/g" $2
$SED -i s/=/\>/g $2
$SED -i s/,//g $2
$SED -n '/} PEP_STATUS/q;p' $1 > $STAT_FILE
$SED -i -n '/STATUS_OK/,$p' $STAT_FILE
$SED -i -e 's/\(.*\)/\L\1/' $STAT_FILE
$SED -i "-e s/ pep/ pEp/g" $STAT_FILE
$SED -i s/=/\>/g $STAT_FILE
$SED -i s/,//g $STAT_FILE
grep -i passphrase $STAT_FILE | sed -e 's/^/enumitem/' > $PASS_FILE
################################################################################
# Show results #
################################################################################
cat $2
cat $STAT_FILE
cat $PASS_FILE

Loading…
Cancel
Save