2020-04-11 12:55:11 +03:00
|
|
|
#!/usr/bin/env python3
|
2019-03-21 15:08:59 +03:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
def get_values(entry_dict, entry_type):
|
|
|
|
values = []
|
|
|
|
if '*' == entry_type:
|
2019-11-07 14:39:22 +03:00
|
|
|
for key in list(entry_dict.keys()):
|
2019-03-21 15:08:59 +03:00
|
|
|
if entry_type in key:
|
|
|
|
values += entry_dict[key]
|
|
|
|
entry_dict.pop(key, None)
|
2019-11-07 14:39:22 +03:00
|
|
|
elif entry_type in dict(entry_dict):
|
2019-03-21 15:08:59 +03:00
|
|
|
values = entry_dict[entry_type]
|
|
|
|
entry_dict.pop(entry_type, None)
|
2020-04-11 12:55:11 +03:00
|
|
|
if values:
|
|
|
|
return sorted(values)
|
2019-03-21 15:08:59 +03:00
|
|
|
return values
|
|
|
|
|
|
|
|
def write_entry(f, entry_dict, entry_type, entry_name):
|
|
|
|
values = get_values(entry_dict, entry_type)
|
|
|
|
if not values:
|
|
|
|
return
|
|
|
|
|
|
|
|
f.write('#define have_' + entry_name.lower() + '_list_indices\n')
|
|
|
|
f.write('static const size_t ' + entry_name.lower() + '_list_indices[] =\n')
|
|
|
|
f.write('{\n')
|
|
|
|
|
|
|
|
for val in values:
|
|
|
|
f.write('\tFreeRDP_' + val + ',\n')
|
|
|
|
|
|
|
|
f.write('};\n\n')
|
|
|
|
|
2020-04-11 12:55:11 +03:00
|
|
|
def write_str_case(f, entry_type, val):
|
|
|
|
f.write('\t\t{FreeRDP_' + val + ', ' + str(entry_type) + ', "FreeRDP_' + val + '"},\n')
|
|
|
|
|
|
|
|
def write_str(f, entry_dict):
|
|
|
|
f.write('struct settings_str_entry {\n')
|
|
|
|
f.write('\tsize_t id;\n')
|
|
|
|
f.write('\tsize_t type;\n')
|
|
|
|
f.write('\tconst char* str;\n')
|
|
|
|
f.write('};\n')
|
|
|
|
f.write('static const struct settings_str_entry settings_map[] =\n')
|
|
|
|
f.write('{\n')
|
|
|
|
|
|
|
|
entry_types = ['BOOL', 'UINT16', 'INT16', 'UINT32', 'INT32', 'UINT64', 'INT64', 'char*', '*']
|
|
|
|
for entry_type in entry_types:
|
|
|
|
values = get_values(entry_dict, entry_type)
|
|
|
|
if values:
|
|
|
|
for val in values:
|
|
|
|
write_str_case(f, entry_types.index(entry_type), val)
|
|
|
|
f.write('};\n\n')
|
2020-05-15 13:22:37 +03:00
|
|
|
f.write('\n')
|
|
|
|
f.write('BOOL freerdp_settings_clone_keys(rdpSettings* dst, const rdpSettings* src)\n')
|
|
|
|
f.write('{\n')
|
|
|
|
f.write('\tsize_t x;\n')
|
|
|
|
f.write('\tfor(x=0; x<ARRAYSIZE(settings_map); x++)\n')
|
|
|
|
f.write('\t{\n')
|
|
|
|
f.write('\t\tconst struct settings_str_entry* cur = &settings_map[x];\n')
|
|
|
|
f.write('\t\tswitch(cur->type)\n')
|
|
|
|
f.write('\t\t{\n')
|
|
|
|
f.write('\t\t\tcase 0: /* bool */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tBOOL sval = freerdp_settings_get_bool(src, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tif (!freerdp_settings_set_bool(dst, cur->id, sval))\n')
|
|
|
|
f.write('\t\t\t\t\treturn FALSE;\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 1: /* UINT16 */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tUINT16 sval = freerdp_settings_get_uint16(src, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tif (!freerdp_settings_set_uint16(dst, cur->id, sval))\n')
|
|
|
|
f.write('\t\t\t\t\treturn FALSE;\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 2: /* INT16 */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tINT16 sval = freerdp_settings_get_int16(src, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tif (!freerdp_settings_set_int16(dst, cur->id, sval))\n')
|
|
|
|
f.write('\t\t\t\t\treturn FALSE;\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 3: /* UINT32 */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tUINT32 sval = freerdp_settings_get_uint32(src, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tif (!freerdp_settings_set_uint32(dst, cur->id, sval))\n')
|
|
|
|
f.write('\t\t\t\t\treturn FALSE;\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 4: /* INT32 */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tINT32 sval = freerdp_settings_get_int32(src, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tif (!freerdp_settings_set_int32(dst, cur->id, sval))\n')
|
|
|
|
f.write('\t\t\t\t\treturn FALSE;\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 5: /* UINT64 */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tUINT64 sval = freerdp_settings_get_uint64(src, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tif (!freerdp_settings_set_uint64(dst, cur->id, sval))\n')
|
|
|
|
f.write('\t\t\t\t\treturn FALSE;\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 6: /* INT64 */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tINT64 sval = freerdp_settings_get_int64(src, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tif (!freerdp_settings_set_int64(dst, cur->id, sval))\n')
|
|
|
|
f.write('\t\t\t\t\treturn FALSE;\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 7: /* strings */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tconst char* sval = freerdp_settings_get_string(src, cur->id);\n')
|
2020-11-19 12:09:34 +03:00
|
|
|
f.write('\t\t\t\t\tsize_t len = 0;\n')
|
|
|
|
f.write('\t\t\t\t\tif (sval) len = strlen(sval);\n')
|
|
|
|
f.write('\t\t\t\tif (!freerdp_settings_set_string_(dst, cur->id, sval, len, FALSE))\n')
|
2020-05-15 13:22:37 +03:00
|
|
|
f.write('\t\t\t\t\treturn FALSE;\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 8: /* pointer */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tconst void* sval = freerdp_settings_get_pointer(src, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tif (!freerdp_settings_set_pointer(dst, cur->id, sval))\n')
|
|
|
|
f.write('\t\t\t\t\treturn FALSE;\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t}\n')
|
|
|
|
f.write('\t}\n')
|
|
|
|
f.write('\treturn TRUE;\n')
|
|
|
|
f.write('}\n')
|
|
|
|
f.write('\n')
|
2021-01-18 19:27:40 +03:00
|
|
|
|
|
|
|
f.write('void freerdp_settings_dump(wLog* log, DWORD level, const rdpSettings* settings)\n')
|
|
|
|
f.write('{\n')
|
|
|
|
f.write('\tsize_t x;\n')
|
|
|
|
f.write('\tfor(x=0; x<ARRAYSIZE(settings_map); x++)\n')
|
|
|
|
f.write('\t{\n')
|
|
|
|
f.write('\t\tconst struct settings_str_entry* cur = &settings_map[x];\n')
|
|
|
|
f.write('\t\tswitch(cur->type)\n')
|
|
|
|
f.write('\t\t{\n')
|
|
|
|
f.write('\t\t\tcase 0: /* bool */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tBOOL sval = freerdp_settings_get_bool(settings, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tWLog_Print(log, level, "%s [BOOL]: %s", cur->str, sval ? "TRUE" : "FALSE");\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 1: /* UINT16 */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tUINT16 sval = freerdp_settings_get_uint16(settings, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tWLog_Print(log, level, "%s [UINT16]: %" PRIu16, cur->str, sval);\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 2: /* INT16 */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tINT16 sval = freerdp_settings_get_int16(settings, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tWLog_Print(log, level, "%s [INT16]: %" PRId16, cur->str, sval);\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 3: /* UINT32 */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tUINT32 sval = freerdp_settings_get_uint32(settings, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tWLog_Print(log, level, "%s [UINT32]: %" PRIu32, cur->str, sval);\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 4: /* INT32 */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tINT32 sval = freerdp_settings_get_int32(settings, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tWLog_Print(log, level, "%s [INT32]: %" PRId32, cur->str, sval);\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 5: /* UINT64 */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tUINT64 sval = freerdp_settings_get_uint64(settings, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tWLog_Print(log, level, "%s [UINT64]: %" PRIu64, cur->str, sval);\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 6: /* INT64 */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tINT64 sval = freerdp_settings_get_int64(settings, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tWLog_Print(log, level, "%s [INT64]: %" PRId64, cur->str, sval);\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 7: /* strings */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tconst char* sval = freerdp_settings_get_string(settings, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tWLog_Print(log, level, "%s [STRING]: \'%s\'", cur->str, sval);\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 8: /* pointer */\n')
|
|
|
|
f.write('\t\t\t{\n')
|
|
|
|
f.write('\t\t\t\tconst void* sval = freerdp_settings_get_pointer(settings, cur->id);\n')
|
|
|
|
f.write('\t\t\t\tWLog_Print(log, level, "%s [POINTER]: \'%p\'", cur->str, sval);\n')
|
|
|
|
f.write('\t\t\t}\n')
|
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t}\n')
|
|
|
|
f.write('\t}\n')
|
|
|
|
|
|
|
|
f.write('}\n')
|
|
|
|
f.write('\n')
|
|
|
|
|
2020-05-15 13:22:37 +03:00
|
|
|
f.write('void freerdp_settings_free_keys(rdpSettings* dst, BOOL cleanup)\n')
|
|
|
|
f.write('{\n')
|
|
|
|
f.write('\tsize_t x;\n')
|
|
|
|
f.write('\tfor(x=0; x<ARRAYSIZE(settings_map); x++)\n')
|
|
|
|
f.write('\t{\n')
|
|
|
|
f.write('\t\tconst struct settings_str_entry* cur = &settings_map[x];\n')
|
|
|
|
f.write('\t\tswitch(cur->type)\n')
|
|
|
|
f.write('\t\t{\n')
|
|
|
|
f.write('\t\t\tcase 7: /* strings */\n')
|
2020-11-19 12:09:34 +03:00
|
|
|
f.write('\t\t\t\tfreerdp_settings_set_string_(dst, cur->id, NULL, 0, cleanup);\n')
|
2020-05-15 13:22:37 +03:00
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t\tcase 8: /* pointer */\n')
|
2020-11-19 12:09:34 +03:00
|
|
|
f.write('\t\t\t\tfreerdp_settings_set_pointer_len(dst, cur->id, NULL, 0);\n')
|
2020-05-15 13:22:37 +03:00
|
|
|
f.write('\t\t\tbreak;\n')
|
|
|
|
f.write('\t\t}\n')
|
|
|
|
f.write('\t}\n')
|
|
|
|
f.write('}\n')
|
|
|
|
f.write('\n')
|
|
|
|
|
2020-04-11 12:55:11 +03:00
|
|
|
f.write('SSIZE_T freerdp_settings_get_key_for_name(const char* value)\n')
|
|
|
|
f.write('{\n')
|
|
|
|
f.write('\tsize_t x;\n')
|
|
|
|
f.write('\tfor(x=0; x<ARRAYSIZE(settings_map); x++)\n')
|
|
|
|
f.write('\t{\n')
|
|
|
|
f.write('\t\tconst struct settings_str_entry* cur = &settings_map[x];\n')
|
|
|
|
f.write('\t\tif (strcmp(value, cur->str) == 0)\n')
|
|
|
|
f.write('\t\t\treturn cur->id;\n')
|
|
|
|
f.write('\t}\n')
|
|
|
|
f.write('\treturn -1;\n')
|
|
|
|
f.write('}\n')
|
|
|
|
f.write('\n')
|
|
|
|
f.write('SSIZE_T freerdp_settings_get_type_for_name(const char* value)\n')
|
|
|
|
f.write('{\n')
|
|
|
|
f.write('\tsize_t x;\n')
|
|
|
|
f.write('\tfor(x=0; x<ARRAYSIZE(settings_map); x++)\n')
|
|
|
|
f.write('\t{\n')
|
|
|
|
f.write('\t\tconst struct settings_str_entry* cur = &settings_map[x];\n')
|
|
|
|
f.write('\t\tif (strcmp(value, cur->str) == 0)\n')
|
|
|
|
f.write('\t\t\treturn cur->type;\n')
|
|
|
|
f.write('\t}\n')
|
|
|
|
f.write('\treturn -1;\n')
|
|
|
|
f.write('}\n')
|
|
|
|
f.write('\n')
|
|
|
|
f.write('SSIZE_T freerdp_settings_get_type_for_key(size_t key)\n')
|
|
|
|
f.write('{\n')
|
|
|
|
f.write('\tsize_t x;\n')
|
|
|
|
f.write('\tfor(x=0; x<ARRAYSIZE(settings_map); x++)\n')
|
|
|
|
f.write('\t{\n')
|
|
|
|
f.write('\t\tconst struct settings_str_entry* cur = &settings_map[x];\n')
|
|
|
|
f.write('\t\tif (cur->id == key)\n')
|
|
|
|
f.write('\t\t\treturn cur->type;\n')
|
|
|
|
f.write('\t}\n')
|
|
|
|
f.write('\treturn -1;\n')
|
|
|
|
f.write('}\n')
|
|
|
|
f.write('\n')
|
|
|
|
f.write('const char* freerdp_settings_get_name_for_key(size_t key)\n')
|
|
|
|
f.write('{\n')
|
|
|
|
f.write('\tsize_t x;\n')
|
|
|
|
f.write('\tfor(x=0; x<ARRAYSIZE(settings_map); x++)\n')
|
|
|
|
f.write('\t{\n')
|
|
|
|
f.write('\t\tconst struct settings_str_entry* cur = &settings_map[x];\n')
|
|
|
|
f.write('\t\tif (cur->id == key)\n')
|
|
|
|
f.write('\t\t\treturn cur->str;\n')
|
|
|
|
f.write('\t}\n')
|
|
|
|
f.write('\treturn NULL;\n')
|
|
|
|
f.write('}\n')
|
|
|
|
f.write('\n')
|
|
|
|
|
2019-03-21 15:08:59 +03:00
|
|
|
def write_getter_case(f, val):
|
|
|
|
f.write('\t\tcase FreeRDP_' + val + ':\n')
|
|
|
|
f.write('\t\t\treturn settings->' + val + ';\n\n')
|
|
|
|
|
|
|
|
def write_getter(f, entry_dict, entry_type, entry_name):
|
|
|
|
isString = 'string' in entry_name
|
|
|
|
isPointer = 'pointer' in entry_name
|
|
|
|
values = get_values(entry_dict, entry_type)
|
|
|
|
|
|
|
|
if isPointer:
|
2020-11-19 12:09:34 +03:00
|
|
|
f.write('void*')
|
2019-03-21 15:08:59 +03:00
|
|
|
elif isString:
|
|
|
|
f.write('const ' + entry_type)
|
|
|
|
else:
|
|
|
|
f.write(entry_type)
|
2020-11-19 12:09:34 +03:00
|
|
|
if isPointer:
|
|
|
|
f.write(' freerdp_settings_get_pointer_writable(const rdpSettings* settings, size_t id)\n')
|
|
|
|
else:
|
|
|
|
f.write(' freerdp_settings_get_' + entry_name.lower() + '(const rdpSettings* settings, size_t id)\n')
|
2019-03-21 15:08:59 +03:00
|
|
|
f.write('{\n')
|
2021-09-03 09:26:55 +03:00
|
|
|
f.write('\tWINPR_ASSERT(settings);\n\n')
|
2019-03-21 15:08:59 +03:00
|
|
|
f.write('\tswitch (id)\n')
|
|
|
|
f.write('\t{\n')
|
|
|
|
if values:
|
|
|
|
for val in values:
|
|
|
|
write_getter_case(f, val)
|
|
|
|
f.write('\t\tdefault:\n')
|
|
|
|
f.write('\t\t\tWLog_ERR(TAG, "[%s] Invalid key index %"PRIuz, __FUNCTION__, id);\n')
|
|
|
|
f.write('\t\t\treturn FALSE;\n')
|
|
|
|
f.write('\t}\n')
|
|
|
|
f.write('}\n\n')
|
|
|
|
|
|
|
|
def write_setter_case(f, val, isString, isPointer):
|
|
|
|
f.write('\t\tcase FreeRDP_' + val + ':\n')
|
2020-05-15 13:22:37 +03:00
|
|
|
if isPointer:
|
2021-10-07 10:16:20 +03:00
|
|
|
f.write('\t\t\tsettings->' + val + ' = cnv.v;\n')
|
2020-05-15 13:22:37 +03:00
|
|
|
f.write('\t\t\tbreak;\n\n')
|
|
|
|
elif not isString:
|
2021-10-07 10:16:20 +03:00
|
|
|
f.write('\t\t\tsettings->' + val + ' = cnv.c;\n')
|
2019-03-21 15:08:59 +03:00
|
|
|
f.write('\t\t\tbreak;\n\n')
|
|
|
|
else:
|
2021-10-07 10:16:20 +03:00
|
|
|
f.write('\t\t\treturn update_string(&settings->' + val + ', cnv.cc, len, cleanup);\n\n')
|
2019-03-21 15:08:59 +03:00
|
|
|
|
|
|
|
def write_setter(f, entry_dict, entry_type, entry_name):
|
|
|
|
isString = 'string' in entry_name
|
|
|
|
isPointer = 'pointer' in entry_name
|
|
|
|
values = get_values(entry_dict, entry_type)
|
|
|
|
|
2020-05-15 13:22:37 +03:00
|
|
|
f.write('BOOL freerdp_settings_set_' + entry_name.lower())
|
|
|
|
if isString:
|
|
|
|
f.write('_')
|
|
|
|
f.write('(rdpSettings* settings, size_t id, ')
|
2019-03-21 15:08:59 +03:00
|
|
|
if isString or isPointer:
|
|
|
|
f.write('const ')
|
|
|
|
if not isPointer:
|
2020-05-15 13:22:37 +03:00
|
|
|
f.write(entry_type + ' val')
|
2019-03-21 15:08:59 +03:00
|
|
|
else:
|
2020-05-15 13:22:37 +03:00
|
|
|
f.write('void* val')
|
|
|
|
if isString:
|
2020-11-19 12:09:34 +03:00
|
|
|
f.write(', size_t len, BOOL cleanup)\n')
|
2020-05-15 13:22:37 +03:00
|
|
|
else:
|
|
|
|
f.write(')\n')
|
2019-03-21 15:08:59 +03:00
|
|
|
f.write('{\n')
|
2021-10-07 10:16:20 +03:00
|
|
|
f.write('union\n')
|
|
|
|
f.write('{\n')
|
|
|
|
f.write(' void* v;\n')
|
|
|
|
f.write(' const void* cv;\n')
|
|
|
|
if not isPointer:
|
|
|
|
f.write(' ' + entry_type + ' c;\n')
|
|
|
|
f.write(' const ' + entry_type + ' cc;\n')
|
|
|
|
f.write('} cnv;\n')
|
|
|
|
|
2021-09-03 09:26:55 +03:00
|
|
|
f.write('\tWINPR_ASSERT(settings);\n\n')
|
2021-10-07 10:16:20 +03:00
|
|
|
if isPointer:
|
|
|
|
f.write('\tcnv.cv = val;\n\n')
|
|
|
|
elif isString:
|
|
|
|
f.write('\tcnv.cc = val;\n\n')
|
|
|
|
else:
|
|
|
|
f.write('\tcnv.c = val;\n\n')
|
2019-03-21 15:08:59 +03:00
|
|
|
f.write('\tswitch (id)\n')
|
|
|
|
f.write('\t{\n')
|
|
|
|
if values:
|
|
|
|
for val in values:
|
|
|
|
write_setter_case(f, val, isString, isPointer)
|
|
|
|
f.write('\t\tdefault:\n')
|
|
|
|
f.write('\t\t\tWLog_ERR(TAG, "[%s] Invalid key index %"PRIuz, __FUNCTION__, id);\n')
|
|
|
|
f.write('\t\t\treturn FALSE;\n')
|
|
|
|
f.write('\t}\n')
|
|
|
|
f.write('\treturn TRUE;\n')
|
|
|
|
f.write('}\n\n')
|
2020-05-15 13:22:37 +03:00
|
|
|
f.write('\n')
|
|
|
|
if isString:
|
2020-11-19 12:09:34 +03:00
|
|
|
f.write('BOOL freerdp_settings_set_string_len(rdpSettings* settings, size_t id, const char* val, size_t len)\n')
|
|
|
|
f.write('{\n')
|
|
|
|
f.write('\treturn freerdp_settings_set_string_(settings, id, val, len, TRUE);\n')
|
|
|
|
f.write('}\n')
|
|
|
|
f.write('\n')
|
|
|
|
|
|
|
|
f.write('BOOL freerdp_settings_set_string(rdpSettings* settings, size_t id, const char* val)\n')
|
2020-05-15 13:22:37 +03:00
|
|
|
f.write('{\n')
|
2020-11-19 12:09:34 +03:00
|
|
|
f.write('\tsize_t len = 0;\n')
|
|
|
|
f.write('\tif (val) len = strlen(val);\n')
|
|
|
|
f.write('\treturn freerdp_settings_set_string_(settings, id, val, len, TRUE);\n')
|
2020-05-15 13:22:37 +03:00
|
|
|
f.write('}\n')
|
|
|
|
f.write('\n')
|
2019-03-21 15:08:59 +03:00
|
|
|
|
|
|
|
name = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
begin = "WARNING: this data structure is carefully padded for ABI stability!"
|
|
|
|
end = "WARNING: End of ABI stable zone!"
|
|
|
|
|
|
|
|
print('begin parsing settings header')
|
|
|
|
try:
|
|
|
|
type_list = dict()
|
|
|
|
|
2019-11-07 14:39:22 +03:00
|
|
|
with open(name + "/../include/freerdp/settings.h", "r") as f:
|
2019-03-21 15:08:59 +03:00
|
|
|
lines = f.readlines()
|
|
|
|
started = False
|
|
|
|
for line in lines:
|
|
|
|
if not started:
|
|
|
|
if begin in line:
|
|
|
|
started = True
|
|
|
|
continue
|
|
|
|
|
|
|
|
if end in line:
|
|
|
|
break
|
|
|
|
|
|
|
|
sline = line.strip()
|
|
|
|
if not sline:
|
|
|
|
continue
|
|
|
|
if sline.startswith('/'):
|
|
|
|
continue
|
|
|
|
if sline.startswith('*'):
|
|
|
|
continue
|
|
|
|
if 'padding' in sline:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if sline.startswith('ALIGN64'):
|
|
|
|
sline = sline[7:].strip()
|
|
|
|
|
|
|
|
sline = sline[:sline.find(';')]
|
|
|
|
pair = sline.split()
|
|
|
|
if pair[0] in type_list:
|
|
|
|
type_list[pair[0]].append(pair[1])
|
|
|
|
else:
|
|
|
|
type_list[pair[0]] = [pair[1]]
|
|
|
|
|
|
|
|
with open(name + '/../libfreerdp/common/settings_getters.c', 'w+') as f:
|
|
|
|
f.write('/* Generated by ' + '' + ' */\n\n')
|
2021-09-03 09:26:55 +03:00
|
|
|
f.write('#include <winpr/assert.h>\n')
|
2019-03-21 15:08:59 +03:00
|
|
|
f.write('#include <freerdp/settings.h>\n')
|
|
|
|
f.write('#include <freerdp/log.h>\n\n')
|
2020-11-19 12:09:34 +03:00
|
|
|
f.write('#include "../core/settings.h"\n\n')
|
2019-03-21 15:08:59 +03:00
|
|
|
f.write('#define TAG FREERDP_TAG("common.settings")\n\n')
|
|
|
|
|
2021-05-18 12:22:27 +03:00
|
|
|
f.write('static BOOL update_string(char** current, const char* next, size_t next_len, BOOL cleanup)\n')
|
|
|
|
f.write('{\n')
|
|
|
|
f.write('\tif (cleanup)\n')
|
|
|
|
f.write('\t{\n')
|
|
|
|
f.write('\t\tif (*current)\n')
|
|
|
|
f.write('\t\t\tmemset(*current, 0, strlen(*current));\n')
|
|
|
|
f.write('\t\tfree(*current);\n')
|
|
|
|
f.write('\t}\n')
|
|
|
|
f.write('\n')
|
|
|
|
f.write('\t*current = (next ? strndup(next, next_len) : NULL);\n')
|
|
|
|
f.write('\treturn !next || (*current != NULL);\n')
|
|
|
|
f.write('}\n\n')
|
|
|
|
|
2019-03-21 15:08:59 +03:00
|
|
|
getter_list = dict(type_list)
|
|
|
|
setter_list = dict(type_list)
|
|
|
|
write_getter(f, getter_list, 'BOOL', 'bool')
|
|
|
|
write_setter(f, setter_list, 'BOOL', 'bool')
|
|
|
|
write_getter(f, getter_list, 'UINT16', 'uint16')
|
|
|
|
write_setter(f, setter_list, 'UINT16', 'uint16')
|
|
|
|
write_getter(f, getter_list, 'INT16', 'int16')
|
|
|
|
write_setter(f, setter_list, 'INT16', 'int16')
|
|
|
|
write_getter(f, getter_list, 'UINT32', 'uint32')
|
|
|
|
write_setter(f, setter_list, 'UINT32', 'uint32')
|
|
|
|
write_getter(f, getter_list, 'INT32', 'int32')
|
|
|
|
write_setter(f, setter_list, 'INT32', 'int32')
|
|
|
|
write_getter(f, getter_list, 'UINT64', 'uint64')
|
|
|
|
write_setter(f, setter_list, 'UINT64', 'uint64')
|
|
|
|
write_getter(f, getter_list, 'INT64', 'int64')
|
|
|
|
write_setter(f, setter_list, 'INT64', 'int64')
|
|
|
|
write_getter(f, getter_list, 'char*', 'string')
|
|
|
|
write_setter(f, setter_list, 'char*', 'string')
|
|
|
|
write_getter(f, getter_list, '*', 'pointer')
|
2020-05-15 13:22:37 +03:00
|
|
|
write_setter(f, setter_list, '*', 'pointer')
|
2019-03-21 15:08:59 +03:00
|
|
|
|
|
|
|
f.write('\n')
|
|
|
|
|
2020-04-11 12:55:11 +03:00
|
|
|
with open(name + '/../libfreerdp/common/settings_str.c', 'w+') as f:
|
|
|
|
f.write('/* Generated by ' + '' + ' */\n\n')
|
|
|
|
f.write('#include <freerdp/settings.h>\n')
|
|
|
|
f.write('#include <freerdp/log.h>\n\n')
|
2020-05-15 13:22:37 +03:00
|
|
|
f.write('#include "../core/settings.h"\n\n')
|
2020-04-11 12:55:11 +03:00
|
|
|
f.write('#define TAG FREERDP_TAG("common.settings")\n\n')
|
|
|
|
|
|
|
|
getter_list = dict(type_list)
|
|
|
|
write_str(f, getter_list)
|
|
|
|
f.write('\n')
|
|
|
|
|
|
|
|
|
2019-03-21 15:08:59 +03:00
|
|
|
with open(name + '/../libfreerdp/core/test/settings_property_lists.h', 'w+') as f:
|
|
|
|
f.write('#ifndef TEST_SETTINGS_PROPERTY_LISTS\n')
|
|
|
|
f.write('#define TEST_SETTINGS_PROPERTY_LISTS\n\n')
|
|
|
|
|
|
|
|
write_entry(f, type_list, 'BOOL', 'bool')
|
|
|
|
write_entry(f, type_list, 'UINT16', 'uint16')
|
|
|
|
write_entry(f, type_list, 'INT16', 'int16')
|
|
|
|
write_entry(f, type_list, 'UINT32', 'uint32')
|
|
|
|
write_entry(f, type_list, 'INT32', 'int32')
|
|
|
|
write_entry(f, type_list, 'UINT64', 'uint64')
|
|
|
|
write_entry(f, type_list, 'INT64', 'int64')
|
|
|
|
write_entry(f, type_list, 'char*', 'string')
|
|
|
|
write_entry(f, type_list, '*', 'pointer')
|
|
|
|
|
|
|
|
f.write('#endif /* TEST_SETTINGS_PROPERTY_LISTS */\n\n')
|
|
|
|
|
|
|
|
print('remaining:\n' + str(type_list))
|
|
|
|
except IOError as e:
|
|
|
|
print('failed to parse settings header ' + str(e))
|
|
|
|
sys.exit(-1)
|
|
|
|
print('ended parsing settings header')
|