From 5b75525080e17ba85be102d277ae889738dda255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C3=85strand?= Date: Wed, 13 Jan 2010 16:07:29 +0000 Subject: [PATCH] Re-wrote top main loop. The patch for session directory / load balancing redirection made it *way* too complicated. We shouldn't really need two extra state variables in addition to g_redirect. The current approach also does not support future features such as automatic reconnection in case of network problems. The new loop should be functionally equivalent to the previous one, though it hasn't yet been tested with a load balancing server. git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/rdesktop/trunk@1547 423420c4-83ab-492f-b58f-81f9feb106b5 --- rdesktop.c | 54 ++++++++++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/rdesktop.c b/rdesktop.c index 24a80c8..b3e26f2 100644 --- a/rdesktop.c +++ b/rdesktop.c @@ -455,8 +455,6 @@ main(int argc, char *argv[]) char *locale = NULL; int username_option = 0; RD_BOOL geometry_option = False; - int run_count = 0; /* Session Directory support */ - RD_BOOL continue_connect = True; /* Session Directory support */ #ifdef WITH_RDPSND char *rdpsnd_optarg = NULL; #endif @@ -963,16 +961,23 @@ main(int argc, char *argv[]) rdpdr_init(); - while (run_count < 2 && continue_connect) /* add support for Session Directory; only reconnect once */ + while (1) { - ui_init_connection(); + rdesktop_reset_state(); - if (run_count == 0) + if (g_redirect) { - if (!rdp_connect(server, flags, domain, password, shell, directory, False)) - return EX_PROTOCOL; + STRNCPY(domain, g_redirect_domain, sizeof(domain)); + xfree(g_username); + g_username = (char *) xmalloc(strlen(g_redirect_username) + 1); + STRNCPY(g_username, g_redirect_username, sizeof(g_username)); + STRNCPY(password, g_redirect_password, sizeof(password)); + STRNCPY(server, g_redirect_server, sizeof(server)); + flags |= RDP_LOGON_AUTO; } - else if (!rdp_connect(server, flags, domain, password, shell, directory, True)) + + ui_init_connection(); + if (!rdp_connect(server, flags, domain, password, shell, directory, g_redirect)) return EX_PROTOCOL; /* By setting encryption to False here, we have an encrypted login @@ -984,39 +989,20 @@ main(int argc, char *argv[]) DEBUG(("Connection successful.\n")); memset(password, 0, sizeof(password)); - if (run_count == 0) + if (!g_redirect) if (!ui_create_window()) return EX_OSERR; - if (continue_connect) - rdp_main_loop(&deactivated, &ext_disc_reason); + g_redirect = False; + rdp_main_loop(&deactivated, &ext_disc_reason); DEBUG(("Disconnecting...\n")); rdp_disconnect(); - if ((g_redirect == True) && (run_count == 0)) /* Support for Session Directory */ - { - /* reset state of major globals */ - rdesktop_reset_state(); - - STRNCPY(domain, g_redirect_domain, sizeof(domain)); - xfree(g_username); - g_username = (char *) xmalloc(strlen(g_redirect_username) + 1); - STRNCPY(g_username, g_redirect_username, sizeof(g_username)); - STRNCPY(password, g_redirect_password, sizeof(password)); - STRNCPY(server, g_redirect_server, sizeof(server)); - flags |= RDP_LOGON_AUTO; - - g_redirect = False; - } - else - { - continue_connect = False; - ui_destroy_window(); - break; - } - - run_count++; + if (g_redirect) + continue; + ui_destroy_window(); + break; } cache_save_state();