From 1f9916eba2dd5fdd73c55287aaf35c8f153cb07f Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 19 Apr 2022 11:35:35 +0200 Subject: [PATCH] Added settings comparison function --- include/freerdp/settings.h | 2 + libfreerdp/common/settings_str.c | 95 ++++++++++++++++++++++++++++++++ tools/update-settings-tests | 88 +++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+) diff --git a/include/freerdp/settings.h b/include/freerdp/settings.h index 3a3ba2302..a2cbe8483 100644 --- a/include/freerdp/settings.h +++ b/include/freerdp/settings.h @@ -1646,6 +1646,8 @@ extern "C" FREERDP_API void freerdp_settings_free(rdpSettings* settings); FREERDP_API void freerdp_settings_dump(wLog* log, DWORD level, const rdpSettings* settings); + FREERDP_API BOOL freerdp_settings_print_diff(wLog* log, DWORD level, const rdpSettings* src, + const rdpSettings* other); FREERDP_API ADDIN_ARGV* freerdp_addin_argv_new(size_t argc, const char* argv[]); FREERDP_API ADDIN_ARGV* freerdp_addin_argv_clone(const ADDIN_ARGV* args); diff --git a/libfreerdp/common/settings_str.c b/libfreerdp/common/settings_str.c index f238a1743..f4d7b42d7 100644 --- a/libfreerdp/common/settings_str.c +++ b/libfreerdp/common/settings_str.c @@ -499,6 +499,101 @@ BOOL freerdp_settings_clone_keys(rdpSettings* dst, const rdpSettings* src) return TRUE; } +BOOL freerdp_settings_print_diff(wLog* log, DWORD level, const rdpSettings* settings, + const rdpSettings* other) +{ + size_t x; + for (x = 0; x < ARRAYSIZE(settings_map); x++) + { + const struct settings_str_entry* cur = &settings_map[x]; + switch (cur->type) + { + case 0: /* bool */ + { + BOOL sval = freerdp_settings_get_bool(settings, cur->id); + BOOL cval = freerdp_settings_get_bool(other, cur->id); + if (sval != cval) + WLog_Print(log, level, "%s [BOOL]: %s -> %s", cur->str, sval ? "TRUE" : "FALSE", + cval ? "TRUE" : "FALSE"); + } + break; + case 1: /* UINT16 */ + { + UINT16 sval = freerdp_settings_get_uint16(settings, cur->id); + UINT16 cval = freerdp_settings_get_uint16(other, cur->id); + if (sval != cval) + WLog_Print(log, level, "%s [UINT16]: %" PRIu16 " -> %" PRIu16, cur->str, sval, + cval); + } + break; + case 2: /* INT16 */ + { + INT16 sval = freerdp_settings_get_int16(settings, cur->id); + INT16 cval = freerdp_settings_get_int16(other, cur->id); + if (sval != cval) + WLog_Print(log, level, "%s [INT16]: %" PRId16 " -> %" PRId16, cur->str, sval, + cval); + } + break; + case 3: /* UINT32 */ + { + UINT32 sval = freerdp_settings_get_uint32(settings, cur->id); + UINT32 cval = freerdp_settings_get_uint32(other, cur->id); + if (sval != cval) + WLog_Print(log, level, "%s [UINT32]: %" PRIu32 " -> %" PRIu32, cur->str, sval, + cval); + } + break; + case 4: /* INT32 */ + { + INT32 sval = freerdp_settings_get_int32(settings, cur->id); + INT32 cval = freerdp_settings_get_int32(other, cur->id); + if (sval != cval) + WLog_Print(log, level, "%s [INT32]: %" PRId32 " -> %" PRId32, cur->str, sval, + cval); + } + break; + case 5: /* UINT64 */ + { + UINT64 sval = freerdp_settings_get_uint64(settings, cur->id); + UINT64 cval = freerdp_settings_get_uint64(other, cur->id); + if (sval != cval) + WLog_Print(log, level, "%s [UINT64]: %" PRIu64 " -> %" PRIu64, cur->str, sval, + cval); + } + break; + case 6: /* INT64 */ + { + INT64 sval = freerdp_settings_get_int64(settings, cur->id); + INT64 cval = freerdp_settings_get_int64(other, cur->id); + if (sval != cval) + WLog_Print(log, level, "%s [INT64]: %" PRId64 " -> %" PRId64, cur->str, sval, + cval); + } + break; + case 7: /* strings */ + { + const char* sval = freerdp_settings_get_string(settings, cur->id); + const char* cval = freerdp_settings_get_string(other, cur->id); + if (sval != cval) + { + if (!sval || !cval || (strcmp(sval, cval) != 0)) + WLog_Print(log, level, "%s [STRING]: '%s' -> '%s'", cur->str, sval, cval); + } + } + break; + case 8: /* pointer */ + { + const void* sval = freerdp_settings_get_pointer(settings, cur->id); + const void* cval = freerdp_settings_get_pointer(other, cur->id); + if (sval != cval) + WLog_Print(log, level, "%s [POINTER]: '%p' -> '%p'", cur->str, sval, cval); + } + break; + } + } + return TRUE; +} void freerdp_settings_dump(wLog* log, DWORD level, const rdpSettings* settings) { size_t x; diff --git a/tools/update-settings-tests b/tools/update-settings-tests index 4be49f0f3..1d4319f88 100755 --- a/tools/update-settings-tests +++ b/tools/update-settings-tests @@ -129,6 +129,94 @@ def write_str(f, entry_dict): f.write('}\n') f.write('\n') + f.write('BOOL freerdp_settings_print_diff(wLog* log, DWORD level, const rdpSettings* settings, const rdpSettings* other)\n') + f.write('{\n') + f.write('\tsize_t x;\n') + f.write('\tfor(x=0; xtype)\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\tBOOL cval = freerdp_settings_get_bool(other, cur->id);\n') + f.write('\t\t\t\tif (sval != cval)\n') + f.write('\t\t\t\t\tWLog_Print(log, level, "%s [BOOL]: %s -> %s", cur->str, sval ? "TRUE" : "FALSE", cval ? "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\tUINT16 cval = freerdp_settings_get_uint16(other, cur->id);\n') + f.write('\t\t\t\tif (sval != cval)\n') + f.write('\t\t\t\tWLog_Print(log, level, "%s [UINT16]: %" PRIu16 " -> %" PRIu16, cur->str, sval, cval);\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\tINT16 cval = freerdp_settings_get_int16(other, cur->id);\n') + f.write('\t\t\t\tif (sval != cval)\n') + f.write('\t\t\t\tWLog_Print(log, level, "%s [INT16]: %" PRId16 " -> %" PRId16, cur->str, sval, cval);\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\tUINT32 cval = freerdp_settings_get_uint32(other, cur->id);\n') + f.write('\t\t\t\tif (sval != cval)\n') + f.write('\t\t\t\tWLog_Print(log, level, "%s [UINT32]: %" PRIu32 " -> %" PRIu32, cur->str, sval, cval);\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\tINT32 cval = freerdp_settings_get_int32(other, cur->id);\n') + f.write('\t\t\t\tif (sval != cval)\n') + f.write('\t\t\t\tWLog_Print(log, level, "%s [INT32]: %" PRId32 " -> %" PRId32, cur->str, sval, cval);\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\tUINT64 cval = freerdp_settings_get_uint64(other, cur->id);\n') + f.write('\t\t\t\tif (sval != cval)\n') + f.write('\t\t\t\tWLog_Print(log, level, "%s [UINT64]: %" PRIu64 " -> %" PRIu64, cur->str, sval, cval);\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\tINT64 cval = freerdp_settings_get_int64(other, cur->id);\n') + f.write('\t\t\t\tif (sval != cval)\n') + f.write('\t\t\t\tWLog_Print(log, level, "%s [INT64]: %" PRId64 " -> %" PRId64, cur->str, sval, cval);\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\tconst char* cval = freerdp_settings_get_string(other, cur->id);\n') + f.write('\t\t\t\tif (sval != cval)\n') + f.write('\t\t\t\t{\n') + f.write('\t\t\t\t\tif (!sval || !cval || (strcmp(sval, cval) != 0))\n') + f.write('\t\t\t\t\t\tWLog_Print(log, level, "%s [STRING]: \'%s\' -> \'%s\'", cur->str, sval, cval);\n') + f.write('\t\t\t\t}\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\tconst void* cval = freerdp_settings_get_pointer(other, cur->id);\n') + f.write('\t\t\t\tif (sval != cval)\n') + f.write('\t\t\t\tWLog_Print(log, level, "%s [POINTER]: \'%p\' -> \'%p\'", cur->str, sval, cval);\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('void freerdp_settings_dump(wLog* log, DWORD level, const rdpSettings* settings)\n') f.write('{\n') f.write('\tsize_t x;\n')