summaryrefslogtreecommitdiffstats
path: root/libfreerdp/common/settings_str.c
blob: 50729514233ed32f8a1d7dce7cf3c444d43f4b38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
/* Generated by  */

#include "../core/settings.h"
#include "settings_str.h"

BOOL freerdp_settings_clone_keys(rdpSettings* dst, const rdpSettings* src)
{
	WINPR_ASSERT(dst);
	WINPR_ASSERT(src);

	for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
	{
		const struct settings_str_entry* cur = &settings_map[x];
		switch (cur->type)
		{
			case FREERDP_SETTINGS_TYPE_BOOL: /* bool */
			{
				BOOL sval = freerdp_settings_get_bool(src, (FreeRDP_Settings_Keys_Bool)cur->id);
				if (!freerdp_settings_set_bool(dst, (FreeRDP_Settings_Keys_Bool)cur->id, sval))
					return FALSE;
			}
			break;
			case FREERDP_SETTINGS_TYPE_UINT16: /* UINT16 */
			{
				UINT16 sval =
				    freerdp_settings_get_uint16(src, (FreeRDP_Settings_Keys_UInt16)cur->id);
				if (!freerdp_settings_set_uint16(dst, (FreeRDP_Settings_Keys_UInt16)cur->id, sval))
					return FALSE;
			}
			break;
			case FREERDP_SETTINGS_TYPE_INT16: /* INT16 */
			{
				INT16 sval = freerdp_settings_get_int16(src, (FreeRDP_Settings_Keys_Int16)cur->id);
				if (!freerdp_settings_set_int16(dst, (FreeRDP_Settings_Keys_Int16)cur->id, sval))
					return FALSE;
			}
			break;
			case FREERDP_SETTINGS_TYPE_UINT32: /* UINT32 */
			{
				UINT32 sval =
				    freerdp_settings_get_uint32(src, (FreeRDP_Settings_Keys_UInt32)cur->id);
				if (!freerdp_settings_set_uint32(dst, (FreeRDP_Settings_Keys_UInt32)cur->id, sval))
					return FALSE;
			}
			break;
			case FREERDP_SETTINGS_TYPE_INT32: /* INT32 */
			{
				INT32 sval = freerdp_settings_get_int32(src, (FreeRDP_Settings_Keys_Int32)cur->id);
				if (!freerdp_settings_set_int32(dst, (FreeRDP_Settings_Keys_Int32)cur->id, sval))
					return FALSE;
			}
			break;
			case FREERDP_SETTINGS_TYPE_UINT64: /* UINT64 */
			{
				UINT64 sval =
				    freerdp_settings_get_uint64(src, (FreeRDP_Settings_Keys_UInt64)cur->id);
				if (!freerdp_settings_set_uint64(dst, (FreeRDP_Settings_Keys_UInt64)cur->id, sval))
					return FALSE;
			}
			break;
			case FREERDP_SETTINGS_TYPE_INT64: /* INT64 */
			{
				INT64 sval = freerdp_settings_get_int64(src, (FreeRDP_Settings_Keys_Int64)cur->id);
				if (!freerdp_settings_set_int64(dst, (FreeRDP_Settings_Keys_Int64)cur->id, sval))
					return FALSE;
			}
			break;
			case FREERDP_SETTINGS_TYPE_STRING: /* strings */
			{
				const char* sval =
				    freerdp_settings_get_string(src, (FreeRDP_Settings_Keys_String)cur->id);
				size_t len = 0;
				if (sval)
					len = strlen(sval);
				if (!freerdp_settings_set_string_copy_(dst, (FreeRDP_Settings_Keys_String)cur->id,
				                                       sval, len, FALSE))
					return FALSE;
			}
			break;
			case FREERDP_SETTINGS_TYPE_POINTER: /* pointer */
			{
				const void* sval =
				    freerdp_settings_get_pointer(src, (FreeRDP_Settings_Keys_Pointer)cur->id);
				if (!freerdp_settings_set_pointer(dst, (FreeRDP_Settings_Keys_Pointer)cur->id,
				                                  sval))
					return FALSE;
			}
			break;
		}
	}
	return TRUE;
}

BOOL freerdp_settings_print_diff(wLog* log, DWORD level, const rdpSettings* settings,
                                 const rdpSettings* other)
{
	BOOL rc = FALSE;

	WINPR_ASSERT(log);
	WINPR_ASSERT(settings);
	WINPR_ASSERT(other);

	for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
	{
		const struct settings_str_entry* cur = &settings_map[x];
		switch (cur->type)
		{
			case FREERDP_SETTINGS_TYPE_BOOL: /* bool */
			{
				BOOL sval =
				    freerdp_settings_get_bool(settings, (FreeRDP_Settings_Keys_Bool)cur->id);
				BOOL cval = freerdp_settings_get_bool(other, (FreeRDP_Settings_Keys_Bool)cur->id);
				if (sval != cval)
				{
					rc = TRUE;
					WLog_Print(log, level, "%s [BOOL]: %s -> %s", cur->str, sval ? "TRUE" : "FALSE",
					           cval ? "TRUE" : "FALSE");
				}
			}
			break;
			case FREERDP_SETTINGS_TYPE_UINT16: /* UINT16 */
			{
				UINT16 sval =
				    freerdp_settings_get_uint16(settings, (FreeRDP_Settings_Keys_UInt16)cur->id);
				UINT16 cval =
				    freerdp_settings_get_uint16(other, (FreeRDP_Settings_Keys_UInt16)cur->id);
				if (sval != cval)
				{
					rc = TRUE;
					WLog_Print(log, level, "%s [UINT16]: %" PRIu16 " -> %" PRIu16, cur->str, sval,
					           cval);
				}
			}
			break;
			case FREERDP_SETTINGS_TYPE_INT16: /* INT16 */
			{
				INT16 sval =
				    freerdp_settings_get_int16(settings, (FreeRDP_Settings_Keys_Int16)cur->id);
				INT16 cval =
				    freerdp_settings_get_int16(other, (FreeRDP_Settings_Keys_Int16)cur->id);
				if (sval != cval)
				{
					rc = TRUE;
					WLog_Print(log, level, "%s [INT16]: %" PRId16 " -> %" PRId16, cur->str, sval,
					           cval);
				}
			}
			break;
			case FREERDP_SETTINGS_TYPE_UINT32: /* UINT32 */
			{
				UINT32 sval =
				    freerdp_settings_get_uint32(settings, (FreeRDP_Settings_Keys_UInt32)cur->id);
				UINT32 cval =
				    freerdp_settings_get_uint32(other, (FreeRDP_Settings_Keys_UInt32)cur->id);
				if (sval != cval)
				{
					rc = TRUE;
					WLog_Print(log, level, "%s [UINT32]: %" PRIu32 " -> %" PRIu32, cur->str, sval,
					           cval);
				}
			}
			break;
			case FREERDP_SETTINGS_TYPE_INT32: /* INT32 */
			{
				INT32 sval =
				    freerdp_settings_get_int32(settings, (FreeRDP_Settings_Keys_Int32)cur->id);
				INT32 cval =
				    freerdp_settings_get_int32(other, (FreeRDP_Settings_Keys_Int32)cur->id);
				if (sval != cval)
				{
					rc = TRUE;
					WLog_Print(log, level, "%s [INT32]: %" PRId32 " -> %" PRId32, cur->str, sval,
					           cval);
				}
			}
			break;
			case FREERDP_SETTINGS_TYPE_UINT64: /* UINT64 */
			{
				UINT64 sval =
				    freerdp_settings_get_uint64(settings, (FreeRDP_Settings_Keys_UInt64)cur->id);
				UINT64 cval =
				    freerdp_settings_get_uint64(other, (FreeRDP_Settings_Keys_UInt64)cur->id);
				if (sval != cval)
				{
					rc = TRUE;
					WLog_Print(log, level, "%s [UINT64]: %" PRIu64 " -> %" PRIu64, cur->str, sval,
					           cval);
				}
			}
			break;
			case FREERDP_SETTINGS_TYPE_INT64: /* INT64 */
			{
				INT64 sval =
				    freerdp_settings_get_int64(settings, (FreeRDP_Settings_Keys_Int64)cur->id);
				INT64 cval =
				    freerdp_settings_get_int64(other, (FreeRDP_Settings_Keys_Int64)cur->id);
				if (sval != cval)
				{
					rc = TRUE;
					WLog_Print(log, level, "%s [INT64]: %" PRId64 " -> %" PRId64, cur->str, sval,
					           cval);
				}
			}
			break;
			case FREERDP_SETTINGS_TYPE_STRING: /* strings */
			{
				const char* sval =
				    freerdp_settings_get_string(settings, (FreeRDP_Settings_Keys_String)cur->id);
				const char* cval =
				    freerdp_settings_get_string(other, (FreeRDP_Settings_Keys_String)cur->id);
				if (sval != cval)
				{
					if (!sval || !cval || (strcmp(sval, cval) != 0))
					{
						rc = TRUE;
						WLog_Print(log, level, "%s [STRING]: '%s' -> '%s'", cur->str, sval, cval);
					}
				}
			}
			break;
			case FREERDP_SETTINGS_TYPE_POINTER: /* pointer */
			{
				const void* sval =
				    freerdp_settings_get_pointer(settings, (FreeRDP_Settings_Keys_Pointer)cur->id);
				const void* cval =
				    freerdp_settings_get_pointer(other, (FreeRDP_Settings_Keys_Pointer)cur->id);
				if (sval != cval)
				{
					if ((sval && !cval) || (!sval && cval))
					{
						rc = TRUE;
						WLog_Print(log, level, "%s [POINTER]: '%p' -> '%p'", cur->str, sval, cval);
					}
				}
			}
			break;
		}
	}
	return rc;
}

void freerdp_settings_dump(wLog* log, DWORD level, const rdpSettings* settings)
{
	WINPR_ASSERT(log);
	WINPR_ASSERT(settings);

	for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
	{
		const struct settings_str_entry* cur = &settings_map[x];
		switch (cur->type)
		{
			case FREERDP_SETTINGS_TYPE_BOOL: /* bool */
			{
				BOOL sval =
				    freerdp_settings_get_bool(settings, (FreeRDP_Settings_Keys_Bool)cur->id);
				WLog_Print(log, level, "%s [BOOL]: %s", cur->str, sval ? "TRUE" : "FALSE");
			}
			break;
			case FREERDP_SETTINGS_TYPE_UINT16: /* UINT16 */
			{
				UINT16 sval =
				    freerdp_settings_get_uint16(settings, (FreeRDP_Settings_Keys_UInt16)cur->id);
				WLog_Print(log, level, "%s [UINT16]: %" PRIu16, cur->str, sval);
			}
			break;
			case FREERDP_SETTINGS_TYPE_INT16: /* INT16 */
			{
				INT16 sval =
				    freerdp_settings_get_int16(settings, (FreeRDP_Settings_Keys_Int16)cur->id);
				WLog_Print(log, level, "%s [INT16]: %" PRId16, cur->str, sval);
			}
			break;
			case FREERDP_SETTINGS_TYPE_UINT32: /* UINT32 */
			{
				UINT32 sval =
				    freerdp_settings_get_uint32(settings, (FreeRDP_Settings_Keys_UInt32)cur->id);
				WLog_Print(log, level, "%s [UINT32]: %" PRIu32, cur->str, sval);
			}
			break;
			case FREERDP_SETTINGS_TYPE_INT32: /* INT32 */
			{
				INT32 sval =
				    freerdp_settings_get_int32(settings, (FreeRDP_Settings_Keys_Int32)cur->id);
				WLog_Print(log, level, "%s [INT32]: %" PRId32, cur->str, sval);
			}
			break;
			case FREERDP_SETTINGS_TYPE_UINT64: /* UINT64 */
			{
				UINT64 sval =
				    freerdp_settings_get_uint64(settings, (FreeRDP_Settings_Keys_UInt64)cur->id);
				WLog_Print(log, level, "%s [UINT64]: %" PRIu64, cur->str, sval);
			}
			break;
			case FREERDP_SETTINGS_TYPE_INT64: /* INT64 */
			{
				INT64 sval =
				    freerdp_settings_get_int64(settings, (FreeRDP_Settings_Keys_Int64)cur->id);
				WLog_Print(log, level, "%s [INT64]: %" PRId64, cur->str, sval);
			}
			break;
			case FREERDP_SETTINGS_TYPE_STRING: /* strings */
			{
				const char* sval =
				    freerdp_settings_get_string(settings, (FreeRDP_Settings_Keys_String)cur->id);
				WLog_Print(log, level, "%s [STRING]: '%s'", cur->str, sval);
			}
			break;
			case FREERDP_SETTINGS_TYPE_POINTER: /* pointer */
			{
				const void* sval =
				    freerdp_settings_get_pointer(settings, (FreeRDP_Settings_Keys_Pointer)cur->id);
				WLog_Print(log, level, "%s [POINTER]: '%p'", cur->str, sval);
			}
			break;
		}
	}
}

void freerdp_settings_free_keys(rdpSettings* dst, BOOL cleanup)
{
	WINPR_ASSERT(dst);

	for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
	{
		const struct settings_str_entry* cur = &settings_map[x];
		switch (cur->type)
		{
			case FREERDP_SETTINGS_TYPE_STRING: /* strings */
				freerdp_settings_set_string_copy_(dst, (FreeRDP_Settings_Keys_String)cur->id, NULL,
				                                  0, cleanup);
				break;
			case FREERDP_SETTINGS_TYPE_POINTER: /* pointer */
				freerdp_settings_set_pointer_len(dst, (FreeRDP_Settings_Keys_Pointer)cur->id, NULL,
				                                 0);
				break;
		}
	}
}

SSIZE_T freerdp_settings_get_key_for_name(const char* value)
{
	WINPR_ASSERT(value);

	for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
	{
		const struct settings_str_entry* cur = &settings_map[x];
		if (strcmp(value, cur->str) == 0)
			return cur->id;
	}
	return -1;
}

SSIZE_T freerdp_settings_get_type_for_name(const char* value)
{
	WINPR_ASSERT(value);

	for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
	{
		const struct settings_str_entry* cur = &settings_map[x];
		if (strcmp(value, cur->str) == 0)
			return cur->type;
	}
	return -1;
}

const char* freerdp_settings_get_type_name_for_key(SSIZE_T key)
{
	const SSIZE_T type = freerdp_settings_get_type_for_key(key);
	return freerdp_settings_get_type_name_for_type(type);
}

const char* freerdp_settings_get_type_name_for_type(SSIZE_T type)
{
	switch (type)
	{
		case FREERDP_SETTINGS_TYPE_BOOL:
			return "FREERDP_SETTINGS_TYPE_BOOL";
		case FREERDP_SETTINGS_TYPE_UINT16:
			return "FREERDP_SETTINGS_TYPE_UINT16";
		case FREERDP_SETTINGS_TYPE_INT16:
			return "FREERDP_SETTINGS_TYPE_INT16";
		case FREERDP_SETTINGS_TYPE_UINT32:
			return "FREERDP_SETTINGS_TYPE_UINT32";
		case FREERDP_SETTINGS_TYPE_INT32:
			return "FREERDP_SETTINGS_TYPE_INT32";
		case FREERDP_SETTINGS_TYPE_UINT64:
			return "FREERDP_SETTINGS_TYPE_UINT64";
		case FREERDP_SETTINGS_TYPE_INT64:
			return "FREERDP_SETTINGS_TYPE_INT64";
		case FREERDP_SETTINGS_TYPE_STRING:
			return "FREERDP_SETTINGS_TYPE_STRING";
		case FREERDP_SETTINGS_TYPE_POINTER:
			return "FREERDP_SETTINGS_TYPE_POINTER";
		default:
			return "FREERDP_SETTINGS_TYPE_UNKNOWN";
	}
}

SSIZE_T freerdp_settings_get_type_for_key(SSIZE_T key)
{
	for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
	{
		const struct settings_str_entry* cur = &settings_map[x];
		if (cur->id == key)
			return cur->type;
	}
	return -1;
}

const char* freerdp_settings_get_name_for_key(SSIZE_T key)
{
	for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
	{
		const struct settings_str_entry* cur = &settings_map[x];
		if (cur->id == key)
			return cur->str;
	}
	return NULL;
}

BOOL freerdp_settings_copy_item(rdpSettings* dst, const rdpSettings* src, SSIZE_T id)
{
	WINPR_ASSERT(dst);
	WINPR_ASSERT(src);

	const SSIZE_T key = freerdp_settings_get_type_for_key(id);
	switch (key)
	{
		case FREERDP_SETTINGS_TYPE_BOOL:
		{
			const BOOL val = freerdp_settings_get_bool(src, (FreeRDP_Settings_Keys_Bool)id);
			return freerdp_settings_set_bool(dst, (FreeRDP_Settings_Keys_Bool)id, val);
		}
		case FREERDP_SETTINGS_TYPE_INT16:
		{
			const INT16 val = freerdp_settings_get_int16(src, (FreeRDP_Settings_Keys_Int16)id);
			return freerdp_settings_set_int16(dst, (FreeRDP_Settings_Keys_Int16)id, val);
		}
		case FREERDP_SETTINGS_TYPE_INT32:
		{
			const INT32 val = freerdp_settings_get_int32(src, (FreeRDP_Settings_Keys_Int32)id);
			return freerdp_settings_set_int32(dst, (FreeRDP_Settings_Keys_Int32)id, val);
		}
		case FREERDP_SETTINGS_TYPE_INT64:
		{
			const INT64 val = freerdp_settings_get_int64(src, (FreeRDP_Settings_Keys_Int64)id);
			return freerdp_settings_set_int64(dst, (FreeRDP_Settings_Keys_Int64)id, val);
		}
		case FREERDP_SETTINGS_TYPE_UINT16:
		{
			const UINT16 val = freerdp_settings_get_uint16(src, (FreeRDP_Settings_Keys_UInt16)id);
			return freerdp_settings_set_uint16(dst, (FreeRDP_Settings_Keys_UInt16)id, val);
		}
		case FREERDP_SETTINGS_TYPE_UINT32:
		{
			const UINT32 val = freerdp_settings_get_uint32(src, (FreeRDP_Settings_Keys_UInt32)id);
			return freerdp_settings_set_uint32(dst, (FreeRDP_Settings_Keys_UInt32)id, val);
		}
		case FREERDP_SETTINGS_TYPE_UINT64:
		{
			const UINT64 val = freerdp_settings_get_uint64(src, (FreeRDP_Settings_Keys_UInt64)id);
			return freerdp_settings_set_uint64(dst, (FreeRDP_Settings_Keys_UInt64)id, val);
		}
		case FREERDP_SETTINGS_TYPE_STRING:
		{
			const char* val = freerdp_settings_get_string(src, (FreeRDP_Settings_Keys_String)id);
			return freerdp_settings_set_string(dst, (FreeRDP_Settings_Keys_String)id, val);
		}
		case FREERDP_SETTINGS_TYPE_POINTER:
		{
			const void* val = freerdp_settings_get_pointer(src, (FreeRDP_Settings_Keys_Pointer)id);
			return freerdp_settings_set_pointer(dst, (FreeRDP_Settings_Keys_Pointer)id, val);
		}
		default:
			return FALSE;
	}
}