X11: X11: handling error info -> disconnect reason

This commit is contained in:
Eduardo Beloni 2011-10-24 16:46:19 -02:00
parent b9a008ae8a
commit f0ea4fa43b
2 changed files with 75 additions and 5 deletions

View File

@ -67,6 +67,7 @@
freerdp_sem g_sem;
static int g_thread_count = 0;
static uint8 g_disconnect_reason = 0;
static long xv_port = 0;
const size_t password_size = 512;
@ -424,7 +425,7 @@ boolean xf_pre_connect(freerdp* instance)
xf_process_plugin_args, instance->context->channels, xf_process_client_args, xfi) < 0)
{
printf("failed to parse arguments.\n");
exit(0);
exit(XF_EXIT_PARSE_ARGUMENTS);
}
settings = instance->settings;
@ -866,12 +867,13 @@ int xfreerdp_run(freerdp* instance)
fd_set rfds_set;
fd_set wfds_set;
rdpChannels* channels;
int ret = 0;
memset(rfds, 0, sizeof(rfds));
memset(wfds, 0, sizeof(wfds));
if (!freerdp_connect(instance))
return 0;
return XF_EXIT_CONN_FAILED;
xfi = ((xfContext*) instance->context)->xfi;
channels = instance->context->channels;
@ -884,16 +886,19 @@ int xfreerdp_run(freerdp* instance)
if (freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount) != True)
{
printf("Failed to get FreeRDP file descriptor\n");
ret = XF_EXIT_CONN_FAILED;
break;
}
if (freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount) != True)
{
printf("Failed to get channel manager file descriptor\n");
ret = XF_EXIT_CONN_FAILED;
break;
}
if (xf_get_fds(instance, rfds, &rcount, wfds, &wcount) != True)
{
printf("Failed to get xfreerdp file descriptor\n");
ret = XF_EXIT_CONN_FAILED;
break;
}
@ -945,6 +950,9 @@ int xfreerdp_run(freerdp* instance)
xf_process_channel_event(channels, instance);
}
if (!ret)
ret = freerdp_error_info(instance);
freerdp_channels_close(channels, instance);
freerdp_channels_free(channels);
freerdp_disconnect(instance);
@ -952,7 +960,7 @@ int xfreerdp_run(freerdp* instance)
freerdp_free(instance);
xf_free(xfi);
return 0;
return ret;
}
void* thread_func(void* param)
@ -960,7 +968,7 @@ void* thread_func(void* param)
struct thread_data* data;
data = (struct thread_data*) param;
xfreerdp_run(data->instance);
g_disconnect_reason = xfreerdp_run(data->instance);
xfree(data);
@ -974,6 +982,27 @@ void* thread_func(void* param)
return NULL;
}
static uint8 exit_code_from_disconnect_reason(uint32 reason)
{
if (reason == 0 ||
(reason >= XF_EXIT_PARSE_ARGUMENTS && reason <= XF_EXIT_CONN_FAILED))
return reason;
/* Licence error set */
else if (reason >= 0x100 && reason <= 0x10A)
reason -= 0x100 + XF_EXIT_LICENSE_INTERNAL;
/* RDP protocol error set */
else if (reason >= 0x10c9 && reason <= 0x1193)
reason = XF_EXIT_RDP;
/* There's no need to test protocol-independent codes: they match */
else if (!(reason <= 0xB))
reason = XF_EXIT_UNKNOWN;
return reason;
}
int main(int argc, char* argv[])
{
pthread_t thread;
@ -1022,5 +1051,5 @@ int main(int argc, char* argv[])
freerdp_channels_global_uninit();
return 0;
return exit_code_from_disconnect_reason(g_disconnect_reason);
}

View File

@ -147,6 +147,47 @@ struct xf_info
void xf_toggle_fullscreen(xfInfo* xfi);
boolean xf_post_connect(freerdp* instance);
enum XF_EXIT_CODE
{
/* section 0-15: protocol-independent codes */
XF_EXIT_SUCCESS = 0,
XF_EXIT_DISCONNECT = 1,
XF_EXIT_LOGOFF = 2,
XF_EXIT_IDLE_TIMEOUT = 3,
XF_EXIT_LOGON_TIMEOUT = 4,
XF_EXIT_CONN_REPLACED = 5,
XF_EXIT_OUT_OF_MEMORY = 6,
XF_EXIT_CONN_DENIED = 7,
XF_EXIT_CONN_DENIED_FIPS = 8,
XF_EXIT_USER_PRIVILEGES = 9,
XF_EXIT_FRESH_CREDENTIALS_REQUIRED = 10,
XF_EXIT_DISCONNECT_BY_USER = 11,
/* section 16-31: license error set */
XF_EXIT_LICENSE_INTERNAL = 16,
XF_EXIT_LICENSE_NO_LICENSE_SERVER = 17,
XF_EXIT_LICENSE_NO_LICENSE = 18,
XF_EXIT_LICENSE_BAD_CLIENT_MSG = 19,
XF_EXIT_LICENSE_HWID_DOESNT_MATCH = 20,
XF_EXIT_LICENSE_BAD_CLIENT = 21,
XF_EXIT_LICENSE_CANT_FINISH_PROTOCOL = 22,
XF_EXIT_LICENSE_CLIENT_ENDED_PROTOCOL = 23,
XF_EXIT_LICENSE_BAD_CLIENT_ENCRYPTION = 24,
XF_EXIT_LICENSE_CANT_UPGRADE = 25,
XF_EXIT_LICENSE_NO_REMOTE_CONNECTIONS = 26,
/* section 32-127: RDP protocol error set */
XF_EXIT_RDP = 32,
/* section 128-254: xfreerdp specific exit codes */
XF_EXIT_PARSE_ARGUMENTS = 128,
XF_EXIT_MEMORY = 129,
XF_EXIT_PROTOCOL = 130,
XF_EXIT_CONN_FAILED = 131,
XF_EXIT_UNKNOWN = 255,
};
#ifdef WITH_DEBUG_X11
#define DEBUG_X11(fmt, ...) DEBUG_CLASS(X11, fmt, ## __VA_ARGS__)
#else