From 44582f821b6c8a473380c1c67c605dc41f435bd3 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Fri, 3 Jun 2022 09:59:47 +0200 Subject: [PATCH] Added utility module for string functions --- include/freerdp/utils/string.h | 39 ++++++++++++++++++++++ libfreerdp/utils/CMakeLists.txt | 1 + libfreerdp/utils/string.c | 59 +++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 include/freerdp/utils/string.h create mode 100644 libfreerdp/utils/string.c diff --git a/include/freerdp/utils/string.h b/include/freerdp/utils/string.h new file mode 100644 index 000000000..805930fb2 --- /dev/null +++ b/include/freerdp/utils/string.h @@ -0,0 +1,39 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * String Utils - Helper functions converting something to string + * + * Copyright 2022 Armin Novak + * Copyright 2022 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UTILS_STRING_H +#define FREERDP_UTILS_STRING_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API char* rdp_redirection_flags_to_string(UINT32 flags, char* buffer, size_t size); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UTILS_STRING_H */ diff --git a/libfreerdp/utils/CMakeLists.txt b/libfreerdp/utils/CMakeLists.txt index 442600c0b..dd5055775 100644 --- a/libfreerdp/utils/CMakeLists.txt +++ b/libfreerdp/utils/CMakeLists.txt @@ -26,6 +26,7 @@ set(${MODULE_PREFIX}_SRCS profiler.c ringbuffer.c signal.c + string.c smartcard_operations.c smartcard_pack.c smartcard_call.c diff --git a/libfreerdp/utils/string.c b/libfreerdp/utils/string.c new file mode 100644 index 000000000..195148416 --- /dev/null +++ b/libfreerdp/utils/string.c @@ -0,0 +1,59 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * String Utils - Helper functions converting something to string + * + * Copyright 2022 Armin Novak + * Copyright 2022 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +char* rdp_redirection_flags_to_string(UINT32 flags, char* buffer, size_t size) +{ + size_t x; + struct map_t + { + UINT32 flag; + const char* name; + }; + const struct map_t map[] = { + { LB_TARGET_NET_ADDRESS, "LB_TARGET_NET_ADDRESS" }, + { LB_LOAD_BALANCE_INFO, "LB_LOAD_BALANCE_INFO" }, + { LB_USERNAME, "LB_USERNAME" }, + { LB_DOMAIN, "LB_DOMAIN" }, + { LB_PASSWORD, "LB_PASSWORD" }, + { LB_DONTSTOREUSERNAME, "LB_DONTSTOREUSERNAME" }, + { LB_SMARTCARD_LOGON, "LB_SMARTCARD_LOGON" }, + { LB_NOREDIRECT, "LB_NOREDIRECT" }, + { LB_TARGET_FQDN, "LB_TARGET_FQDN" }, + { LB_TARGET_NETBIOS_NAME, "LB_TARGET_NETBIOS_NAME" }, + { LB_TARGET_NET_ADDRESSES, "LB_TARGET_NET_ADDRESSES" }, + { LB_CLIENT_TSV_URL, "LB_CLIENT_TSV_URL" }, + { LB_SERVER_TSV_CAPABLE, "LB_SERVER_TSV_CAPABLE" }, + }; + + for (x = 0; x < ARRAYSIZE(map); x++) + { + const struct map_t* cur = &map[x]; + if (flags & cur->flag) + { + if (!winpr_str_append(cur->name, buffer, size, "|")) + return NULL; + } + } + return buffer; +}