/src/FreeRDP/libfreerdp/utils/string.c
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * FreeRDP: A Remote Desktop Protocol Implementation |
3 | | * |
4 | | * String Utils - Helper functions converting something to string |
5 | | * |
6 | | * Copyright 2022 Armin Novak <armin.novak@thincast.com> |
7 | | * Copyright 2022 Thincast Technologies GmbH |
8 | | * |
9 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
10 | | * you may not use this file except in compliance with the License. |
11 | | * You may obtain a copy of the License at |
12 | | * |
13 | | * http://www.apache.org/licenses/LICENSE-2.0 |
14 | | * |
15 | | * Unless required by applicable law or agreed to in writing, software |
16 | | * distributed under the License is distributed on an "AS IS" BASIS, |
17 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
18 | | * See the License for the specific language governing permissions and |
19 | | * limitations under the License. |
20 | | */ |
21 | | |
22 | | #include <errno.h> |
23 | | |
24 | | #include <freerdp/utils/string.h> |
25 | | #include <freerdp/settings.h> |
26 | | |
27 | | const char* rdp_redirection_flags_to_string(UINT32 flags, char* buffer, size_t size) |
28 | 0 | { |
29 | 0 | struct map_t |
30 | 0 | { |
31 | 0 | UINT32 flag; |
32 | 0 | const char* name; |
33 | 0 | }; |
34 | 0 | const struct map_t map[] = { |
35 | 0 | { LB_TARGET_NET_ADDRESS, "LB_TARGET_NET_ADDRESS" }, |
36 | 0 | { LB_LOAD_BALANCE_INFO, "LB_LOAD_BALANCE_INFO" }, |
37 | 0 | { LB_USERNAME, "LB_USERNAME" }, |
38 | 0 | { LB_DOMAIN, "LB_DOMAIN" }, |
39 | 0 | { LB_PASSWORD, "LB_PASSWORD" }, |
40 | 0 | { LB_DONTSTOREUSERNAME, "LB_DONTSTOREUSERNAME" }, |
41 | 0 | { LB_SMARTCARD_LOGON, "LB_SMARTCARD_LOGON" }, |
42 | 0 | { LB_NOREDIRECT, "LB_NOREDIRECT" }, |
43 | 0 | { LB_TARGET_FQDN, "LB_TARGET_FQDN" }, |
44 | 0 | { LB_TARGET_NETBIOS_NAME, "LB_TARGET_NETBIOS_NAME" }, |
45 | 0 | { LB_TARGET_NET_ADDRESSES, "LB_TARGET_NET_ADDRESSES" }, |
46 | 0 | { LB_CLIENT_TSV_URL, "LB_CLIENT_TSV_URL" }, |
47 | 0 | { LB_SERVER_TSV_CAPABLE, "LB_SERVER_TSV_CAPABLE" }, |
48 | 0 | { LB_PASSWORD_IS_PK_ENCRYPTED, "LB_PASSWORD_IS_PK_ENCRYPTED" }, |
49 | 0 | { LB_REDIRECTION_GUID, "LB_REDIRECTION_GUID" }, |
50 | 0 | { LB_TARGET_CERTIFICATE, "LB_TARGET_CERTIFICATE" }, |
51 | 0 | }; |
52 | |
|
53 | 0 | for (size_t x = 0; x < ARRAYSIZE(map); x++) |
54 | 0 | { |
55 | 0 | const struct map_t* cur = &map[x]; |
56 | 0 | if (flags & cur->flag) |
57 | 0 | { |
58 | 0 | if (!winpr_str_append(cur->name, buffer, size, "|")) |
59 | 0 | return NULL; |
60 | 0 | } |
61 | 0 | } |
62 | 0 | return buffer; |
63 | 0 | } |
64 | | |
65 | | const char* rdp_cluster_info_flags_to_string(UINT32 flags, char* buffer, size_t size) |
66 | 0 | { |
67 | 0 | const UINT32 version = (flags & ServerSessionRedirectionVersionMask) >> 2; |
68 | 0 | if (flags & REDIRECTION_SUPPORTED) |
69 | 0 | winpr_str_append("REDIRECTION_SUPPORTED", buffer, size, "|"); |
70 | 0 | if (flags & REDIRECTED_SESSIONID_FIELD_VALID) |
71 | 0 | winpr_str_append("REDIRECTED_SESSIONID_FIELD_VALID", buffer, size, "|"); |
72 | 0 | if (flags & REDIRECTED_SMARTCARD) |
73 | 0 | winpr_str_append("REDIRECTED_SMARTCARD", buffer, size, "|"); |
74 | |
|
75 | 0 | const char* str = NULL; |
76 | 0 | switch (version) |
77 | 0 | { |
78 | 0 | case REDIRECTION_VERSION1: |
79 | 0 | str = "REDIRECTION_VERSION1"; |
80 | 0 | break; |
81 | 0 | case REDIRECTION_VERSION2: |
82 | 0 | str = "REDIRECTION_VERSION2"; |
83 | 0 | break; |
84 | 0 | case REDIRECTION_VERSION3: |
85 | 0 | str = "REDIRECTION_VERSION3"; |
86 | 0 | break; |
87 | 0 | case REDIRECTION_VERSION4: |
88 | 0 | str = "REDIRECTION_VERSION4"; |
89 | 0 | break; |
90 | 0 | case REDIRECTION_VERSION5: |
91 | 0 | str = "REDIRECTION_VERSION5"; |
92 | 0 | break; |
93 | 0 | case REDIRECTION_VERSION6: |
94 | 0 | str = "REDIRECTION_VERSION6"; |
95 | 0 | break; |
96 | 0 | default: |
97 | 0 | str = "REDIRECTION_VERSION_UNKNOWN"; |
98 | 0 | break; |
99 | 0 | } |
100 | 0 | winpr_str_append(str, buffer, size, "|"); |
101 | 0 | { |
102 | 0 | char msg[32] = { 0 }; |
103 | 0 | (void)_snprintf(msg, sizeof(msg), "[0x%08" PRIx32 "]", flags); |
104 | 0 | winpr_str_append(msg, buffer, size, ""); |
105 | 0 | } |
106 | 0 | return buffer; |
107 | 0 | } |
108 | | |
109 | | BOOL freerdp_extract_key_value(const char* str, UINT32* pkey, UINT32* pvalue) |
110 | 0 | { |
111 | 0 | if (!str || !pkey || !pvalue) |
112 | 0 | return FALSE; |
113 | | |
114 | 0 | char* end1 = NULL; |
115 | 0 | errno = 0; |
116 | 0 | unsigned long key = strtoul(str, &end1, 0); |
117 | 0 | if ((errno != 0) || !end1 || (*end1 != '=') || (key > UINT32_MAX)) |
118 | 0 | return FALSE; |
119 | | |
120 | 0 | errno = 0; |
121 | 0 | unsigned long val = strtoul(&end1[1], NULL, 0); |
122 | 0 | if ((errno != 0) || (val > UINT32_MAX)) |
123 | 0 | return FALSE; |
124 | | |
125 | 0 | *pkey = (UINT32)key; |
126 | 0 | *pvalue = (UINT32)val; |
127 | 0 | return TRUE; |
128 | 0 | } |