Coverage Report

Created: 2024-05-20 06:11

/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 <freerdp/utils/string.h>
23
#include <freerdp/settings.h>
24
25
char* rdp_redirection_flags_to_string(UINT32 flags, char* buffer, size_t size)
26
688
{
27
688
  struct map_t
28
688
  {
29
688
    UINT32 flag;
30
688
    const char* name;
31
688
  };
32
688
  const struct map_t map[] = {
33
688
    { LB_TARGET_NET_ADDRESS, "LB_TARGET_NET_ADDRESS" },
34
688
    { LB_LOAD_BALANCE_INFO, "LB_LOAD_BALANCE_INFO" },
35
688
    { LB_USERNAME, "LB_USERNAME" },
36
688
    { LB_DOMAIN, "LB_DOMAIN" },
37
688
    { LB_PASSWORD, "LB_PASSWORD" },
38
688
    { LB_DONTSTOREUSERNAME, "LB_DONTSTOREUSERNAME" },
39
688
    { LB_SMARTCARD_LOGON, "LB_SMARTCARD_LOGON" },
40
688
    { LB_NOREDIRECT, "LB_NOREDIRECT" },
41
688
    { LB_TARGET_FQDN, "LB_TARGET_FQDN" },
42
688
    { LB_TARGET_NETBIOS_NAME, "LB_TARGET_NETBIOS_NAME" },
43
688
    { LB_TARGET_NET_ADDRESSES, "LB_TARGET_NET_ADDRESSES" },
44
688
    { LB_CLIENT_TSV_URL, "LB_CLIENT_TSV_URL" },
45
688
    { LB_SERVER_TSV_CAPABLE, "LB_SERVER_TSV_CAPABLE" },
46
688
    { LB_PASSWORD_IS_PK_ENCRYPTED, "LB_PASSWORD_IS_PK_ENCRYPTED" },
47
688
    { LB_REDIRECTION_GUID, "LB_REDIRECTION_GUID" },
48
688
    { LB_TARGET_CERTIFICATE, "LB_TARGET_CERTIFICATE" },
49
688
  };
50
51
11.6k
  for (size_t x = 0; x < ARRAYSIZE(map); x++)
52
10.9k
  {
53
10.9k
    const struct map_t* cur = &map[x];
54
10.9k
    if (flags & cur->flag)
55
2.00k
    {
56
2.00k
      if (!winpr_str_append(cur->name, buffer, size, "|"))
57
24
        return NULL;
58
2.00k
    }
59
10.9k
  }
60
664
  return buffer;
61
688
}
62
63
char* rdp_cluster_info_flags_to_string(UINT32 flags, char* buffer, size_t size)
64
0
{
65
0
  const UINT32 version = (flags & ServerSessionRedirectionVersionMask) >> 2;
66
0
  if (flags & REDIRECTION_SUPPORTED)
67
0
    winpr_str_append("REDIRECTION_SUPPORTED", buffer, size, "|");
68
0
  if (flags & REDIRECTED_SESSIONID_FIELD_VALID)
69
0
    winpr_str_append("REDIRECTED_SESSIONID_FIELD_VALID", buffer, size, "|");
70
0
  if (flags & REDIRECTED_SMARTCARD)
71
0
    winpr_str_append("REDIRECTED_SMARTCARD", buffer, size, "|");
72
73
0
  const char* str = NULL;
74
0
  switch (version)
75
0
  {
76
0
    case REDIRECTION_VERSION1:
77
0
      str = "REDIRECTION_VERSION1";
78
0
      break;
79
0
    case REDIRECTION_VERSION2:
80
0
      str = "REDIRECTION_VERSION2";
81
0
      break;
82
0
    case REDIRECTION_VERSION3:
83
0
      str = "REDIRECTION_VERSION3";
84
0
      break;
85
0
    case REDIRECTION_VERSION4:
86
0
      str = "REDIRECTION_VERSION4";
87
0
      break;
88
0
    case REDIRECTION_VERSION5:
89
0
      str = "REDIRECTION_VERSION5";
90
0
      break;
91
0
    case REDIRECTION_VERSION6:
92
0
      str = "REDIRECTION_VERSION6";
93
0
      break;
94
0
    default:
95
0
      str = "REDIRECTION_VERSION_UNKNOWN";
96
0
      break;
97
0
  }
98
0
  winpr_str_append(str, buffer, size, "|");
99
0
  {
100
0
    char msg[32] = { 0 };
101
0
    _snprintf(msg, sizeof(msg), "[0x%08" PRIx32 "]", flags);
102
0
    winpr_str_append(msg, buffer, size, "");
103
0
  }
104
0
  return buffer;
105
0
}