Coverage Report

Created: 2024-09-08 06:20

/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
613
{
27
613
  struct map_t
28
613
  {
29
613
    UINT32 flag;
30
613
    const char* name;
31
613
  };
32
613
  const struct map_t map[] = {
33
613
    { LB_TARGET_NET_ADDRESS, "LB_TARGET_NET_ADDRESS" },
34
613
    { LB_LOAD_BALANCE_INFO, "LB_LOAD_BALANCE_INFO" },
35
613
    { LB_USERNAME, "LB_USERNAME" },
36
613
    { LB_DOMAIN, "LB_DOMAIN" },
37
613
    { LB_PASSWORD, "LB_PASSWORD" },
38
613
    { LB_DONTSTOREUSERNAME, "LB_DONTSTOREUSERNAME" },
39
613
    { LB_SMARTCARD_LOGON, "LB_SMARTCARD_LOGON" },
40
613
    { LB_NOREDIRECT, "LB_NOREDIRECT" },
41
613
    { LB_TARGET_FQDN, "LB_TARGET_FQDN" },
42
613
    { LB_TARGET_NETBIOS_NAME, "LB_TARGET_NETBIOS_NAME" },
43
613
    { LB_TARGET_NET_ADDRESSES, "LB_TARGET_NET_ADDRESSES" },
44
613
    { LB_CLIENT_TSV_URL, "LB_CLIENT_TSV_URL" },
45
613
    { LB_SERVER_TSV_CAPABLE, "LB_SERVER_TSV_CAPABLE" },
46
613
    { LB_PASSWORD_IS_PK_ENCRYPTED, "LB_PASSWORD_IS_PK_ENCRYPTED" },
47
613
    { LB_REDIRECTION_GUID, "LB_REDIRECTION_GUID" },
48
613
    { LB_TARGET_CERTIFICATE, "LB_TARGET_CERTIFICATE" },
49
613
  };
50
51
10.3k
  for (size_t x = 0; x < ARRAYSIZE(map); x++)
52
9.78k
  {
53
9.78k
    const struct map_t* cur = &map[x];
54
9.78k
    if (flags & cur->flag)
55
1.68k
    {
56
1.68k
      if (!winpr_str_append(cur->name, buffer, size, "|"))
57
20
        return NULL;
58
1.68k
    }
59
9.78k
  }
60
593
  return buffer;
61
613
}
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
    (void)_snprintf(msg, sizeof(msg), "[0x%08" PRIx32 "]", flags);
102
0
    winpr_str_append(msg, buffer, size, "");
103
0
  }
104
0
  return buffer;
105
0
}