mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-14 00:14:11 +09:00
[client,sdl] add utils functions
* Add HighDpiScaleMode platformScaleMode(): get the platform specific high dpi hangling type * Move and rename sdl exit codes to separate namespace * mark all functions [[nodiscard]]
This commit is contained in:
@@ -74,206 +74,15 @@
|
||||
|
||||
#define SDL_TAG CLIENT_TAG("SDL")
|
||||
|
||||
enum SDL_EXIT_CODE
|
||||
{
|
||||
/* section 0-15: protocol-independent codes */
|
||||
SDL_EXIT_SUCCESS = 0,
|
||||
SDL_EXIT_DISCONNECT = 1,
|
||||
SDL_EXIT_LOGOFF = 2,
|
||||
SDL_EXIT_IDLE_TIMEOUT = 3,
|
||||
SDL_EXIT_LOGON_TIMEOUT = 4,
|
||||
SDL_EXIT_CONN_REPLACED = 5,
|
||||
SDL_EXIT_OUT_OF_MEMORY = 6,
|
||||
SDL_EXIT_CONN_DENIED = 7,
|
||||
SDL_EXIT_CONN_DENIED_FIPS = 8,
|
||||
SDL_EXIT_USER_PRIVILEGES = 9,
|
||||
SDL_EXIT_FRESH_CREDENTIALS_REQUIRED = 10,
|
||||
SDL_EXIT_DISCONNECT_BY_USER = 11,
|
||||
|
||||
/* section 16-31: license error set */
|
||||
SDL_EXIT_LICENSE_INTERNAL = 16,
|
||||
SDL_EXIT_LICENSE_NO_LICENSE_SERVER = 17,
|
||||
SDL_EXIT_LICENSE_NO_LICENSE = 18,
|
||||
SDL_EXIT_LICENSE_BAD_CLIENT_MSG = 19,
|
||||
SDL_EXIT_LICENSE_HWID_DOESNT_MATCH = 20,
|
||||
SDL_EXIT_LICENSE_BAD_CLIENT = 21,
|
||||
SDL_EXIT_LICENSE_CANT_FINISH_PROTOCOL = 22,
|
||||
SDL_EXIT_LICENSE_CLIENT_ENDED_PROTOCOL = 23,
|
||||
SDL_EXIT_LICENSE_BAD_CLIENT_ENCRYPTION = 24,
|
||||
SDL_EXIT_LICENSE_CANT_UPGRADE = 25,
|
||||
SDL_EXIT_LICENSE_NO_REMOTE_CONNECTIONS = 26,
|
||||
|
||||
/* section 32-127: RDP protocol error set */
|
||||
SDL_EXIT_RDP = 32,
|
||||
|
||||
/* section 128-254: xfreerdp specific exit codes */
|
||||
SDL_EXIT_PARSE_ARGUMENTS = 128,
|
||||
SDL_EXIT_MEMORY = 129,
|
||||
SDL_EXIT_PROTOCOL = 130,
|
||||
SDL_EXIT_CONN_FAILED = 131,
|
||||
SDL_EXIT_AUTH_FAILURE = 132,
|
||||
SDL_EXIT_NEGO_FAILURE = 133,
|
||||
SDL_EXIT_LOGON_FAILURE = 134,
|
||||
SDL_EXIT_ACCOUNT_LOCKED_OUT = 135,
|
||||
SDL_EXIT_PRE_CONNECT_FAILED = 136,
|
||||
SDL_EXIT_CONNECT_UNDEFINED = 137,
|
||||
SDL_EXIT_POST_CONNECT_FAILED = 138,
|
||||
SDL_EXIT_DNS_ERROR = 139,
|
||||
SDL_EXIT_DNS_NAME_NOT_FOUND = 140,
|
||||
SDL_EXIT_CONNECT_FAILED = 141,
|
||||
SDL_EXIT_MCS_CONNECT_INITIAL_ERROR = 142,
|
||||
SDL_EXIT_TLS_CONNECT_FAILED = 143,
|
||||
SDL_EXIT_INSUFFICIENT_PRIVILEGES = 144,
|
||||
SDL_EXIT_CONNECT_CANCELLED = 145,
|
||||
|
||||
SDL_EXIT_CONNECT_TRANSPORT_FAILED = 147,
|
||||
SDL_EXIT_CONNECT_PASSWORD_EXPIRED = 148,
|
||||
SDL_EXIT_CONNECT_PASSWORD_MUST_CHANGE = 149,
|
||||
SDL_EXIT_CONNECT_KDC_UNREACHABLE = 150,
|
||||
SDL_EXIT_CONNECT_ACCOUNT_DISABLED = 151,
|
||||
SDL_EXIT_CONNECT_PASSWORD_CERTAINLY_EXPIRED = 152,
|
||||
SDL_EXIT_CONNECT_CLIENT_REVOKED = 153,
|
||||
SDL_EXIT_CONNECT_WRONG_PASSWORD = 154,
|
||||
SDL_EXIT_CONNECT_ACCESS_DENIED = 155,
|
||||
SDL_EXIT_CONNECT_ACCOUNT_RESTRICTION = 156,
|
||||
SDL_EXIT_CONNECT_ACCOUNT_EXPIRED = 157,
|
||||
SDL_EXIT_CONNECT_LOGON_TYPE_NOT_GRANTED = 158,
|
||||
SDL_EXIT_CONNECT_NO_OR_MISSING_CREDENTIALS = 159,
|
||||
SDL_EXIT_CONNECT_TARGET_BOOTING = 160,
|
||||
|
||||
SDL_EXIT_UNKNOWN = 255,
|
||||
};
|
||||
|
||||
struct sdl_exit_code_map_t
|
||||
{
|
||||
DWORD error;
|
||||
int code;
|
||||
const char* code_tag;
|
||||
};
|
||||
|
||||
#define ENTRY(x, y) { x, y, #y }
|
||||
static const struct sdl_exit_code_map_t sdl_exit_code_map[] = {
|
||||
ENTRY(FREERDP_ERROR_SUCCESS, SDL_EXIT_SUCCESS), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_DISCONNECT),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LOGOFF), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_IDLE_TIMEOUT),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LOGON_TIMEOUT),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_REPLACED),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_OUT_OF_MEMORY),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_DENIED),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_DENIED_FIPS),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_USER_PRIVILEGES),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_FRESH_CREDENTIALS_REQUIRED),
|
||||
ENTRY(ERRINFO_LOGOFF_BY_USER, SDL_EXIT_DISCONNECT_BY_USER),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_UNKNOWN),
|
||||
|
||||
/* section 16-31: license error set */
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_INTERNAL),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_NO_LICENSE_SERVER),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_NO_LICENSE),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_BAD_CLIENT_MSG),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_HWID_DOESNT_MATCH),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_BAD_CLIENT),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CANT_FINISH_PROTOCOL),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CLIENT_ENDED_PROTOCOL),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_BAD_CLIENT_ENCRYPTION),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CANT_UPGRADE),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_NO_REMOTE_CONNECTIONS),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_LICENSE_CANT_UPGRADE),
|
||||
|
||||
/* section 32-127: RDP protocol error set */
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_RDP),
|
||||
|
||||
/* section 128-254: xfreerdp specific exit codes */
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_PARSE_ARGUMENTS), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_MEMORY),
|
||||
ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_PROTOCOL), ENTRY(FREERDP_ERROR_NONE, SDL_EXIT_CONN_FAILED),
|
||||
|
||||
ENTRY(FREERDP_ERROR_AUTHENTICATION_FAILED, SDL_EXIT_AUTH_FAILURE),
|
||||
ENTRY(FREERDP_ERROR_SECURITY_NEGO_CONNECT_FAILED, SDL_EXIT_NEGO_FAILURE),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_LOGON_FAILURE, SDL_EXIT_LOGON_FAILURE),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_TARGET_BOOTING, SDL_EXIT_CONNECT_TARGET_BOOTING),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_LOCKED_OUT, SDL_EXIT_ACCOUNT_LOCKED_OUT),
|
||||
ENTRY(FREERDP_ERROR_PRE_CONNECT_FAILED, SDL_EXIT_PRE_CONNECT_FAILED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_UNDEFINED, SDL_EXIT_CONNECT_UNDEFINED),
|
||||
ENTRY(FREERDP_ERROR_POST_CONNECT_FAILED, SDL_EXIT_POST_CONNECT_FAILED),
|
||||
ENTRY(FREERDP_ERROR_DNS_ERROR, SDL_EXIT_DNS_ERROR),
|
||||
ENTRY(FREERDP_ERROR_DNS_NAME_NOT_FOUND, SDL_EXIT_DNS_NAME_NOT_FOUND),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_FAILED, SDL_EXIT_CONNECT_FAILED),
|
||||
ENTRY(FREERDP_ERROR_MCS_CONNECT_INITIAL_ERROR, SDL_EXIT_MCS_CONNECT_INITIAL_ERROR),
|
||||
ENTRY(FREERDP_ERROR_TLS_CONNECT_FAILED, SDL_EXIT_TLS_CONNECT_FAILED),
|
||||
ENTRY(FREERDP_ERROR_INSUFFICIENT_PRIVILEGES, SDL_EXIT_INSUFFICIENT_PRIVILEGES),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_CANCELLED, SDL_EXIT_CONNECT_CANCELLED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_TRANSPORT_FAILED, SDL_EXIT_CONNECT_TRANSPORT_FAILED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_EXPIRED, SDL_EXIT_CONNECT_PASSWORD_EXPIRED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_MUST_CHANGE, SDL_EXIT_CONNECT_PASSWORD_MUST_CHANGE),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_KDC_UNREACHABLE, SDL_EXIT_CONNECT_KDC_UNREACHABLE),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_DISABLED, SDL_EXIT_CONNECT_ACCOUNT_DISABLED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_CERTAINLY_EXPIRED,
|
||||
SDL_EXIT_CONNECT_PASSWORD_CERTAINLY_EXPIRED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_CLIENT_REVOKED, SDL_EXIT_CONNECT_CLIENT_REVOKED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_WRONG_PASSWORD, SDL_EXIT_CONNECT_WRONG_PASSWORD),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_ACCESS_DENIED, SDL_EXIT_CONNECT_ACCESS_DENIED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_RESTRICTION, SDL_EXIT_CONNECT_ACCOUNT_RESTRICTION),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_EXPIRED, SDL_EXIT_CONNECT_ACCOUNT_EXPIRED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_LOGON_TYPE_NOT_GRANTED, SDL_EXIT_CONNECT_LOGON_TYPE_NOT_GRANTED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_NO_OR_MISSING_CREDENTIALS,
|
||||
SDL_EXIT_CONNECT_NO_OR_MISSING_CREDENTIALS)
|
||||
};
|
||||
|
||||
static const struct sdl_exit_code_map_t* sdl_map_entry_by_code(int exit_code)
|
||||
{
|
||||
for (const auto& x : sdl_exit_code_map)
|
||||
{
|
||||
const struct sdl_exit_code_map_t* cur = &x;
|
||||
if (cur->code == exit_code)
|
||||
return cur;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static const struct sdl_exit_code_map_t* sdl_map_entry_by_error(UINT32 error)
|
||||
{
|
||||
for (const auto& x : sdl_exit_code_map)
|
||||
{
|
||||
const struct sdl_exit_code_map_t* cur = &x;
|
||||
if (cur->error == error)
|
||||
return cur;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int sdl_map_error_to_exit_code(DWORD error)
|
||||
{
|
||||
const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_error(error);
|
||||
if (entry)
|
||||
return entry->code;
|
||||
|
||||
return SDL_EXIT_CONN_FAILED;
|
||||
}
|
||||
|
||||
static const char* sdl_map_error_to_code_tag(UINT32 error)
|
||||
{
|
||||
const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_error(error);
|
||||
if (entry)
|
||||
return entry->code_tag;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static const char* sdl_map_to_code_tag(int code)
|
||||
{
|
||||
const struct sdl_exit_code_map_t* entry = sdl_map_entry_by_code(code);
|
||||
if (entry)
|
||||
return entry->code_tag;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int error_info_to_error(freerdp* instance, DWORD* pcode, char** msg, size_t* len)
|
||||
{
|
||||
const DWORD code = freerdp_error_info(instance);
|
||||
const char* name = freerdp_get_error_info_name(code);
|
||||
const char* str = freerdp_get_error_info_string(code);
|
||||
const int exit_code = sdl_map_error_to_exit_code(code);
|
||||
const int exit_code = sdl::error::errorToExitCode(code);
|
||||
|
||||
winpr_asprintf(msg, len, "Terminate with %s due to ERROR_INFO %s [0x%08" PRIx32 "]: %s",
|
||||
sdl_map_error_to_code_tag(code), name, code, str);
|
||||
sdl::error::errorToExitCodeTag(code), name, code, str);
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "%s", *msg);
|
||||
if (pcode)
|
||||
*pcode = code;
|
||||
@@ -1177,16 +986,16 @@ static void sdl_client_cleanup(SdlContext* sdl, int exit_code, const std::string
|
||||
bool showError = false;
|
||||
if (freerdp_settings_get_bool(settings, FreeRDP_AuthenticationOnly))
|
||||
WLog_Print(sdl->log, WLOG_INFO, "Authentication only, exit status %s [%" PRId32 "]",
|
||||
sdl_map_to_code_tag(exit_code), exit_code);
|
||||
sdl::error::exitCodeToTag(exit_code), exit_code);
|
||||
else
|
||||
{
|
||||
switch (exit_code)
|
||||
{
|
||||
case SDL_EXIT_SUCCESS:
|
||||
case SDL_EXIT_DISCONNECT:
|
||||
case SDL_EXIT_LOGOFF:
|
||||
case SDL_EXIT_DISCONNECT_BY_USER:
|
||||
case SDL_EXIT_CONNECT_CANCELLED:
|
||||
case sdl::error::SUCCESS:
|
||||
case sdl::error::DISCONNECT:
|
||||
case sdl::error::LOGOFF:
|
||||
case sdl::error::DISCONNECT_BY_USER:
|
||||
case sdl::error::CONNECT_CANCELLED:
|
||||
break;
|
||||
default:
|
||||
{
|
||||
@@ -1218,11 +1027,11 @@ static int sdl_client_thread_connect(SdlContext* sdl, std::string& error_msg)
|
||||
rdpSettings* settings = context->settings;
|
||||
WINPR_ASSERT(settings);
|
||||
|
||||
int exit_code = SDL_EXIT_SUCCESS;
|
||||
int exit_code = sdl::error::SUCCESS;
|
||||
if (!rc)
|
||||
{
|
||||
UINT32 error = freerdp_get_last_error(context);
|
||||
exit_code = sdl_map_error_to_exit_code(error);
|
||||
exit_code = sdl::error::errorToExitCode(error);
|
||||
}
|
||||
|
||||
if (freerdp_settings_get_bool(settings, FreeRDP_AuthenticationOnly))
|
||||
@@ -1237,7 +1046,7 @@ static int sdl_client_thread_connect(SdlContext* sdl, std::string& error_msg)
|
||||
if (!rc)
|
||||
{
|
||||
DWORD code = freerdp_error_info(instance);
|
||||
if (exit_code == SDL_EXIT_SUCCESS)
|
||||
if (exit_code == sdl::error::SUCCESS)
|
||||
{
|
||||
char* msg = nullptr;
|
||||
size_t len = 0;
|
||||
@@ -1260,12 +1069,12 @@ static int sdl_client_thread_connect(SdlContext* sdl, std::string& error_msg)
|
||||
free(msg);
|
||||
}
|
||||
|
||||
if (exit_code == SDL_EXIT_SUCCESS)
|
||||
if (exit_code == sdl::error::SUCCESS)
|
||||
{
|
||||
if (last == FREERDP_ERROR_AUTHENTICATION_FAILED)
|
||||
exit_code = SDL_EXIT_AUTH_FAILURE;
|
||||
exit_code = sdl::error::AUTH_FAILURE;
|
||||
else if (code == ERRINFO_SUCCESS)
|
||||
exit_code = SDL_EXIT_CONN_FAILED;
|
||||
exit_code = sdl::error::CONN_FAILED;
|
||||
}
|
||||
|
||||
sdl->dialog.show(false);
|
||||
@@ -1284,7 +1093,7 @@ static int sdl_client_thread_run(SdlContext* sdl, std::string& error_msg)
|
||||
auto instance = context->instance;
|
||||
WINPR_ASSERT(instance);
|
||||
|
||||
int exit_code = SDL_EXIT_SUCCESS;
|
||||
int exit_code = sdl::error::SUCCESS;
|
||||
while (!freerdp_shall_disconnect_context(context))
|
||||
{
|
||||
HANDLE handles[MAXIMUM_WAIT_OBJECTS] = {};
|
||||
@@ -1331,7 +1140,7 @@ static int sdl_client_thread_run(SdlContext* sdl, std::string& error_msg)
|
||||
* did not succeed and no other error was specified.
|
||||
*/
|
||||
if (freerdp_error_info(instance) == 0)
|
||||
exit_code = SDL_EXIT_CONN_FAILED;
|
||||
exit_code = sdl::error::CONN_FAILED;
|
||||
}
|
||||
|
||||
if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
|
||||
@@ -1343,7 +1152,7 @@ static int sdl_client_thread_run(SdlContext* sdl, std::string& error_msg)
|
||||
}
|
||||
}
|
||||
|
||||
if (exit_code == SDL_EXIT_SUCCESS)
|
||||
if (exit_code == sdl::error::SUCCESS)
|
||||
{
|
||||
DWORD code = 0;
|
||||
{
|
||||
@@ -1370,7 +1179,7 @@ static int sdl_client_thread_run(SdlContext* sdl, std::string& error_msg)
|
||||
|
||||
/* This situation might be limited to Windows XP. */
|
||||
WLog_Print(sdl->log, WLOG_INFO, "%s", msg);
|
||||
exit_code = SDL_EXIT_LOGOFF;
|
||||
exit_code = sdl::error::LOGOFF;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1388,7 +1197,7 @@ static DWORD WINAPI sdl_client_thread_proc(SdlContext* sdl)
|
||||
|
||||
std::string error_msg;
|
||||
int exit_code = sdl_client_thread_connect(sdl, error_msg);
|
||||
if (exit_code == SDL_EXIT_SUCCESS)
|
||||
if (exit_code == sdl::error::SUCCESS)
|
||||
exit_code = sdl_client_thread_run(sdl, error_msg);
|
||||
sdl_client_cleanup(sdl, exit_code, error_msg);
|
||||
|
||||
|
||||
@@ -390,3 +390,169 @@ std::string sdl::utils::generate_uuid_v4()
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
sdl::utils::HighDpiScaleMode sdl::utils::platformScaleMode()
|
||||
{
|
||||
const auto platform = SDL_GetPlatform();
|
||||
if (!platform)
|
||||
return SCALE_MODE_INVALID;
|
||||
if (strcmp("Windows", platform) == 0)
|
||||
return SCALE_MODE_X11;
|
||||
if (strcmp("macOS", platform) == 0)
|
||||
return SCALE_MODE_WAYLAND;
|
||||
if (strcmp("Linux", platform) == 0)
|
||||
{
|
||||
const auto driver = SDL_GetCurrentVideoDriver();
|
||||
if (!driver)
|
||||
return SCALE_MODE_WAYLAND;
|
||||
if (strcmp("x11", driver) == 0)
|
||||
return SCALE_MODE_X11;
|
||||
if (strcmp("wayland", driver) == 0)
|
||||
return SCALE_MODE_WAYLAND;
|
||||
}
|
||||
return SCALE_MODE_INVALID;
|
||||
}
|
||||
|
||||
std::string sdl::utils::windowTitle(const rdpSettings* settings)
|
||||
{
|
||||
const char* prefix = "FreeRDP:";
|
||||
|
||||
if (!settings)
|
||||
return {};
|
||||
|
||||
const auto windowTitle = freerdp_settings_get_string(settings, FreeRDP_WindowTitle);
|
||||
if (windowTitle)
|
||||
return {};
|
||||
|
||||
const auto name = freerdp_settings_get_server_name(settings);
|
||||
const auto port = freerdp_settings_get_uint32(settings, FreeRDP_ServerPort);
|
||||
|
||||
const auto addPort = (port != 3389);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << prefix << " ";
|
||||
if (!addPort)
|
||||
ss << name;
|
||||
else
|
||||
ss << name << ":" << port;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
namespace sdl::error
|
||||
{
|
||||
struct sdl_exitCode_map_t
|
||||
{
|
||||
DWORD error;
|
||||
int code;
|
||||
const char* code_tag;
|
||||
};
|
||||
|
||||
#define ENTRY(x, y) { x, y, #y }
|
||||
static const struct sdl_exitCode_map_t sdl_exitCode_map[] = {
|
||||
ENTRY(FREERDP_ERROR_SUCCESS, SUCCESS), ENTRY(FREERDP_ERROR_NONE, DISCONNECT),
|
||||
ENTRY(FREERDP_ERROR_NONE, LOGOFF), ENTRY(FREERDP_ERROR_NONE, IDLE_TIMEOUT),
|
||||
ENTRY(FREERDP_ERROR_NONE, LOGON_TIMEOUT), ENTRY(FREERDP_ERROR_NONE, CONN_REPLACED),
|
||||
ENTRY(FREERDP_ERROR_NONE, OUT_OF_MEMORY), ENTRY(FREERDP_ERROR_NONE, CONN_DENIED),
|
||||
ENTRY(FREERDP_ERROR_NONE, CONN_DENIED_FIPS), ENTRY(FREERDP_ERROR_NONE, USER_PRIVILEGES),
|
||||
ENTRY(FREERDP_ERROR_NONE, FRESH_CREDENTIALS_REQUIRED),
|
||||
ENTRY(ERRINFO_LOGOFF_BY_USER, DISCONNECT_BY_USER), ENTRY(FREERDP_ERROR_NONE, UNKNOWN),
|
||||
|
||||
/* section 16-31: license error set */
|
||||
ENTRY(FREERDP_ERROR_NONE, LICENSE_INTERNAL),
|
||||
ENTRY(FREERDP_ERROR_NONE, LICENSE_NO_LICENSE_SERVER),
|
||||
ENTRY(FREERDP_ERROR_NONE, LICENSE_NO_LICENSE),
|
||||
ENTRY(FREERDP_ERROR_NONE, LICENSE_BAD_CLIENT_MSG),
|
||||
ENTRY(FREERDP_ERROR_NONE, LICENSE_HWID_DOESNT_MATCH),
|
||||
ENTRY(FREERDP_ERROR_NONE, LICENSE_BAD_CLIENT),
|
||||
ENTRY(FREERDP_ERROR_NONE, LICENSE_CANT_FINISH_PROTOCOL),
|
||||
ENTRY(FREERDP_ERROR_NONE, LICENSE_CLIENT_ENDED_PROTOCOL),
|
||||
ENTRY(FREERDP_ERROR_NONE, LICENSE_BAD_CLIENT_ENCRYPTION),
|
||||
ENTRY(FREERDP_ERROR_NONE, LICENSE_CANT_UPGRADE),
|
||||
ENTRY(FREERDP_ERROR_NONE, LICENSE_NO_REMOTE_CONNECTIONS),
|
||||
ENTRY(FREERDP_ERROR_NONE, LICENSE_CANT_UPGRADE),
|
||||
|
||||
/* section 32-127: RDP protocol error set */
|
||||
ENTRY(FREERDP_ERROR_NONE, RDP),
|
||||
|
||||
/* section 128-254: xfreerdp specific exit codes */
|
||||
ENTRY(FREERDP_ERROR_NONE, PARSE_ARGUMENTS), ENTRY(FREERDP_ERROR_NONE, MEMORY),
|
||||
ENTRY(FREERDP_ERROR_NONE, PROTOCOL), ENTRY(FREERDP_ERROR_NONE, CONN_FAILED),
|
||||
|
||||
ENTRY(FREERDP_ERROR_AUTHENTICATION_FAILED, AUTH_FAILURE),
|
||||
ENTRY(FREERDP_ERROR_SECURITY_NEGO_CONNECT_FAILED, NEGO_FAILURE),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_LOGON_FAILURE, LOGON_FAILURE),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_TARGET_BOOTING, CONNECT_TARGET_BOOTING),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_LOCKED_OUT, ACCOUNT_LOCKED_OUT),
|
||||
ENTRY(FREERDP_ERROR_PRE_CONNECT_FAILED, PRE_CONNECT_FAILED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_UNDEFINED, CONNECT_UNDEFINED),
|
||||
ENTRY(FREERDP_ERROR_POST_CONNECT_FAILED, POST_CONNECT_FAILED),
|
||||
ENTRY(FREERDP_ERROR_DNS_ERROR, DNS_ERROR),
|
||||
ENTRY(FREERDP_ERROR_DNS_NAME_NOT_FOUND, DNS_NAME_NOT_FOUND),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_FAILED, CONNECT_FAILED),
|
||||
ENTRY(FREERDP_ERROR_MCS_CONNECT_INITIAL_ERROR, MCS_CONNECT_INITIAL_ERROR),
|
||||
ENTRY(FREERDP_ERROR_TLS_CONNECT_FAILED, TLS_CONNECT_FAILED),
|
||||
ENTRY(FREERDP_ERROR_INSUFFICIENT_PRIVILEGES, INSUFFICIENT_PRIVILEGES),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_CANCELLED, CONNECT_CANCELLED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_TRANSPORT_FAILED, CONNECT_TRANSPORT_FAILED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_EXPIRED, CONNECT_PASSWORD_EXPIRED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_MUST_CHANGE, CONNECT_PASSWORD_MUST_CHANGE),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_KDC_UNREACHABLE, CONNECT_KDC_UNREACHABLE),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_DISABLED, CONNECT_ACCOUNT_DISABLED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_PASSWORD_CERTAINLY_EXPIRED, CONNECT_PASSWORD_CERTAINLY_EXPIRED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_CLIENT_REVOKED, CONNECT_CLIENT_REVOKED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_WRONG_PASSWORD, CONNECT_WRONG_PASSWORD),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_ACCESS_DENIED, CONNECT_ACCESS_DENIED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_RESTRICTION, CONNECT_ACCOUNT_RESTRICTION),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_ACCOUNT_EXPIRED, CONNECT_ACCOUNT_EXPIRED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_LOGON_TYPE_NOT_GRANTED, CONNECT_LOGON_TYPE_NOT_GRANTED),
|
||||
ENTRY(FREERDP_ERROR_CONNECT_NO_OR_MISSING_CREDENTIALS, CONNECT_NO_OR_MISSING_CREDENTIALS)
|
||||
};
|
||||
|
||||
static const sdl_exitCode_map_t* mapEntryByCode(int exit_code)
|
||||
{
|
||||
for (const auto& x : sdl_exitCode_map)
|
||||
{
|
||||
auto cur = &x;
|
||||
if (cur->code == exit_code)
|
||||
return cur;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static const sdl_exitCode_map_t* mapEntryByError(UINT32 error)
|
||||
{
|
||||
for (const auto& x : sdl_exitCode_map)
|
||||
{
|
||||
auto cur = &x;
|
||||
if (cur->error == error)
|
||||
return cur;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
int sdl::error::errorToExitCode(DWORD error)
|
||||
{
|
||||
auto entry = mapEntryByError(error);
|
||||
if (entry)
|
||||
return entry->code;
|
||||
|
||||
return CONN_FAILED;
|
||||
}
|
||||
|
||||
const char* sdl::error::errorToExitCodeTag(UINT32 error)
|
||||
{
|
||||
auto entry = mapEntryByError(error);
|
||||
if (entry)
|
||||
return entry->code_tag;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char* sdl::error::exitCodeToTag(int code)
|
||||
{
|
||||
auto entry = mapEntryByCode(code);
|
||||
if (entry)
|
||||
return entry->code_tag;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include <winpr/synch.h>
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include <freerdp/settings.h>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -67,23 +69,112 @@ typedef struct
|
||||
Sint32 result;
|
||||
} SDL_UserAuthArg;
|
||||
|
||||
bool sdl_push_user_event(Uint32 type, ...);
|
||||
[[nodiscard]] bool sdl_push_user_event(Uint32 type, ...);
|
||||
|
||||
bool sdl_push_quit();
|
||||
[[nodiscard]] bool sdl_push_quit();
|
||||
|
||||
std::string sdl_window_event_str(Uint32 ev);
|
||||
const char* sdl_event_type_str(Uint32 type);
|
||||
const char* sdl_error_string(Sint32 res);
|
||||
[[nodiscard]] std::string sdl_window_event_str(Uint32 ev);
|
||||
[[nodiscard]] const char* sdl_event_type_str(Uint32 type);
|
||||
[[nodiscard]] const char* sdl_error_string(Sint32 res);
|
||||
|
||||
#define sdl_log_error(res, log, what) sdl_log_error_ex(res, log, what, __FILE__, __LINE__, __func__)
|
||||
BOOL sdl_log_error_ex(Sint32 res, wLog* log, const char* what, const char* file, size_t line,
|
||||
const char* fkt);
|
||||
[[nodiscard]] BOOL sdl_log_error_ex(Sint32 res, wLog* log, const char* what, const char* file,
|
||||
size_t line, const char* fkt);
|
||||
|
||||
namespace sdl::utils
|
||||
{
|
||||
std::string rdp_orientation_to_str(uint32_t orientation);
|
||||
std::string sdl_orientation_to_str(SDL_DisplayOrientation orientation);
|
||||
UINT32 orientaion_to_rdp(SDL_DisplayOrientation orientation);
|
||||
[[nodiscard]] std::string rdp_orientation_to_str(uint32_t orientation);
|
||||
[[nodiscard]] std::string sdl_orientation_to_str(SDL_DisplayOrientation orientation);
|
||||
[[nodiscard]] UINT32 orientaion_to_rdp(SDL_DisplayOrientation orientation);
|
||||
|
||||
[[nodiscard]] std::string generate_uuid_v4();
|
||||
|
||||
enum HighDpiScaleMode
|
||||
{
|
||||
SCALE_MODE_INVALID,
|
||||
SCALE_MODE_X11,
|
||||
SCALE_MODE_WAYLAND
|
||||
};
|
||||
|
||||
HighDpiScaleMode platformScaleMode();
|
||||
|
||||
[[nodiscard]] std::string windowTitle(const rdpSettings* settings);
|
||||
|
||||
std::string generate_uuid_v4();
|
||||
} // namespace sdl::utils
|
||||
|
||||
namespace sdl::error
|
||||
{
|
||||
enum EXIT_CODE
|
||||
{
|
||||
/* section 0-15: protocol-independent codes */
|
||||
SUCCESS = 0,
|
||||
DISCONNECT = 1,
|
||||
LOGOFF = 2,
|
||||
IDLE_TIMEOUT = 3,
|
||||
LOGON_TIMEOUT = 4,
|
||||
CONN_REPLACED = 5,
|
||||
OUT_OF_MEMORY = 6,
|
||||
CONN_DENIED = 7,
|
||||
CONN_DENIED_FIPS = 8,
|
||||
USER_PRIVILEGES = 9,
|
||||
FRESH_CREDENTIALS_REQUIRED = 10,
|
||||
DISCONNECT_BY_USER = 11,
|
||||
|
||||
/* section 16-31: license error set */
|
||||
LICENSE_INTERNAL = 16,
|
||||
LICENSE_NO_LICENSE_SERVER = 17,
|
||||
LICENSE_NO_LICENSE = 18,
|
||||
LICENSE_BAD_CLIENT_MSG = 19,
|
||||
LICENSE_HWID_DOESNT_MATCH = 20,
|
||||
LICENSE_BAD_CLIENT = 21,
|
||||
LICENSE_CANT_FINISH_PROTOCOL = 22,
|
||||
LICENSE_CLIENT_ENDED_PROTOCOL = 23,
|
||||
LICENSE_BAD_CLIENT_ENCRYPTION = 24,
|
||||
LICENSE_CANT_UPGRADE = 25,
|
||||
LICENSE_NO_REMOTE_CONNECTIONS = 26,
|
||||
|
||||
/* section 32-127: RDP protocol error set */
|
||||
RDP = 32,
|
||||
|
||||
/* section 128-254: xfreerdp specific exit codes */
|
||||
PARSE_ARGUMENTS = 128,
|
||||
MEMORY = 129,
|
||||
PROTOCOL = 130,
|
||||
CONN_FAILED = 131,
|
||||
AUTH_FAILURE = 132,
|
||||
NEGO_FAILURE = 133,
|
||||
LOGON_FAILURE = 134,
|
||||
ACCOUNT_LOCKED_OUT = 135,
|
||||
PRE_CONNECT_FAILED = 136,
|
||||
CONNECT_UNDEFINED = 137,
|
||||
POST_CONNECT_FAILED = 138,
|
||||
DNS_ERROR = 139,
|
||||
DNS_NAME_NOT_FOUND = 140,
|
||||
CONNECT_FAILED = 141,
|
||||
MCS_CONNECT_INITIAL_ERROR = 142,
|
||||
TLS_CONNECT_FAILED = 143,
|
||||
INSUFFICIENT_PRIVILEGES = 144,
|
||||
CONNECT_CANCELLED = 145,
|
||||
|
||||
CONNECT_TRANSPORT_FAILED = 147,
|
||||
CONNECT_PASSWORD_EXPIRED = 148,
|
||||
CONNECT_PASSWORD_MUST_CHANGE = 149,
|
||||
CONNECT_KDC_UNREACHABLE = 150,
|
||||
CONNECT_ACCOUNT_DISABLED = 151,
|
||||
CONNECT_PASSWORD_CERTAINLY_EXPIRED = 152,
|
||||
CONNECT_CLIENT_REVOKED = 153,
|
||||
CONNECT_WRONG_PASSWORD = 154,
|
||||
CONNECT_ACCESS_DENIED = 155,
|
||||
CONNECT_ACCOUNT_RESTRICTION = 156,
|
||||
CONNECT_ACCOUNT_EXPIRED = 157,
|
||||
CONNECT_LOGON_TYPE_NOT_GRANTED = 158,
|
||||
CONNECT_NO_OR_MISSING_CREDENTIALS = 159,
|
||||
CONNECT_TARGET_BOOTING = 160,
|
||||
|
||||
UNKNOWN = 255,
|
||||
};
|
||||
|
||||
[[nodiscard]] int errorToExitCode(DWORD error);
|
||||
[[nodiscard]] const char* errorToExitCodeTag(UINT32 error);
|
||||
[[nodiscard]] const char* exitCodeToTag(int code);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user