FreeRDP
libfreerdp/utils/string.c
1 
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 {
29  struct map_t
30  {
31  UINT32 flag;
32  const char* name;
33  };
34  const struct map_t map[] = {
35  { LB_TARGET_NET_ADDRESS, "LB_TARGET_NET_ADDRESS" },
36  { LB_LOAD_BALANCE_INFO, "LB_LOAD_BALANCE_INFO" },
37  { LB_USERNAME, "LB_USERNAME" },
38  { LB_DOMAIN, "LB_DOMAIN" },
39  { LB_PASSWORD, "LB_PASSWORD" },
40  { LB_DONTSTOREUSERNAME, "LB_DONTSTOREUSERNAME" },
41  { LB_SMARTCARD_LOGON, "LB_SMARTCARD_LOGON" },
42  { LB_NOREDIRECT, "LB_NOREDIRECT" },
43  { LB_TARGET_FQDN, "LB_TARGET_FQDN" },
44  { LB_TARGET_NETBIOS_NAME, "LB_TARGET_NETBIOS_NAME" },
45  { LB_TARGET_NET_ADDRESSES, "LB_TARGET_NET_ADDRESSES" },
46  { LB_CLIENT_TSV_URL, "LB_CLIENT_TSV_URL" },
47  { LB_SERVER_TSV_CAPABLE, "LB_SERVER_TSV_CAPABLE" },
48  { LB_PASSWORD_IS_PK_ENCRYPTED, "LB_PASSWORD_IS_PK_ENCRYPTED" },
49  { LB_REDIRECTION_GUID, "LB_REDIRECTION_GUID" },
50  { LB_TARGET_CERTIFICATE, "LB_TARGET_CERTIFICATE" },
51  };
52 
53  for (size_t x = 0; x < ARRAYSIZE(map); x++)
54  {
55  const struct map_t* cur = &map[x];
56  if (flags & cur->flag)
57  {
58  if (!winpr_str_append(cur->name, buffer, size, "|"))
59  return NULL;
60  }
61  }
62  return buffer;
63 }
64 
65 const char* rdp_cluster_info_flags_to_string(UINT32 flags, char* buffer, size_t size)
66 {
67  const UINT32 version = (flags & ServerSessionRedirectionVersionMask) >> 2;
68  if (flags & REDIRECTION_SUPPORTED)
69  winpr_str_append("REDIRECTION_SUPPORTED", buffer, size, "|");
70  if (flags & REDIRECTED_SESSIONID_FIELD_VALID)
71  winpr_str_append("REDIRECTED_SESSIONID_FIELD_VALID", buffer, size, "|");
72  if (flags & REDIRECTED_SMARTCARD)
73  winpr_str_append("REDIRECTED_SMARTCARD", buffer, size, "|");
74 
75  const char* str = NULL;
76  switch (version)
77  {
78  case REDIRECTION_VERSION1:
79  str = "REDIRECTION_VERSION1";
80  break;
81  case REDIRECTION_VERSION2:
82  str = "REDIRECTION_VERSION2";
83  break;
84  case REDIRECTION_VERSION3:
85  str = "REDIRECTION_VERSION3";
86  break;
87  case REDIRECTION_VERSION4:
88  str = "REDIRECTION_VERSION4";
89  break;
90  case REDIRECTION_VERSION5:
91  str = "REDIRECTION_VERSION5";
92  break;
93  case REDIRECTION_VERSION6:
94  str = "REDIRECTION_VERSION6";
95  break;
96  default:
97  str = "REDIRECTION_VERSION_UNKNOWN";
98  break;
99  }
100  winpr_str_append(str, buffer, size, "|");
101  {
102  char msg[32] = { 0 };
103  (void)_snprintf(msg, sizeof(msg), "[0x%08" PRIx32 "]", flags);
104  winpr_str_append(msg, buffer, size, "");
105  }
106  return buffer;
107 }
108 
109 BOOL freerdp_extract_key_value(const char* str, UINT32* pkey, UINT32* pvalue)
110 {
111  if (!str || !pkey || !pvalue)
112  return FALSE;
113 
114  char* end1 = NULL;
115  errno = 0;
116  unsigned long key = strtoul(str, &end1, 0);
117  if ((errno != 0) || !end1 || (*end1 != '=') || (key > UINT32_MAX))
118  return FALSE;
119 
120  errno = 0;
121  unsigned long val = strtoul(&end1[1], NULL, 0);
122  if ((errno != 0) || (val > UINT32_MAX))
123  return FALSE;
124 
125  *pkey = (UINT32)key;
126  *pvalue = (UINT32)val;
127  return TRUE;
128 }