--- sourceforge.net/trunk/rdesktop/rdesktop.c 2004/04/10 09:34:52 648 +++ sourceforge.net/trunk/rdesktop/rdesktop.c 2004/04/20 07:01:21 676 @@ -69,9 +69,10 @@ BOOL g_console_session = False; BOOL g_numlock_sync = False; BOOL g_owncolmap = False; -BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ +BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ uint32 g_embed_wnd; -uint32 g_rdp5_performanceflags = RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS; +uint32 g_rdp5_performanceflags = + RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS; #ifdef WITH_RDPSND BOOL g_rdpsnd = False; @@ -79,7 +80,7 @@ extern RDPDR_DEVICE g_rdpdr_device[]; extern uint32 g_num_devices; -extern char * g_rdpdr_clientname; +extern char *g_rdpdr_clientname; #ifdef RDP2VNC extern int rfb_port; @@ -123,7 +124,8 @@ fprintf(stderr, " -N: enable numlock syncronization\n"); fprintf(stderr, " -X: embed into another window with a given id.\n"); fprintf(stderr, " -a: connection colour depth\n"); - fprintf(stderr, " -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex number)\n"); + fprintf(stderr, + " -x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex number)\n"); fprintf(stderr, " -r: enable specified device redirection (this flag can be repeated)\n"); fprintf(stderr, " '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n"); @@ -146,6 +148,106 @@ fprintf(stderr, " -5: use RDP version 5 (default)\n"); } +void +print_disconnect_reason(uint16 reason) +{ + char *text; + + switch (reason) + { + case exDiscReasonNoInfo: + text = "No information available"; + break; + + case exDiscReasonAPIInitiatedDisconnect: + text = "Server initiated disconnect"; + break; + + case exDiscReasonAPIInitiatedLogoff: + text = "Server initiated logoff"; + break; + + case exDiscReasonServerIdleTimeout: + text = "Server idle timeout reached"; + break; + + case exDiscReasonServerLogonTimeout: + text = "Server logon timeout reached"; + break; + + case exDiscReasonReplacedByOtherConnection: + text = "The session was replaced"; + break; + + case exDiscReasonOutOfMemory: + text = "The server is out of memory"; + break; + + case exDiscReasonServerDeniedConnection: + text = "The server denied the connection"; + break; + + case exDiscReasonServerDeniedConnectionFips: + text = "The server denied the connection for security reason"; + break; + + case exDiscReasonLicenseInternal: + text = "Internal licensing error"; + break; + + case exDiscReasonLicenseNoLicenseServer: + text = "No license server available"; + break; + + case exDiscReasonLicenseNoLicense: + text = "No valid license available"; + break; + + case exDiscReasonLicenseErrClientMsg: + text = "Invalid licensing message"; + break; + + case exDiscReasonLicenseHwidDoesntMatchLicense: + text = "Hardware id doesn't match software license"; + break; + + case exDiscReasonLicenseErrClientLicense: + text = "Client license error"; + break; + + case exDiscReasonLicenseCantFinishProtocol: + text = "Network error during licensing protocol"; + break; + + case exDiscReasonLicenseClientEndedProtocol: + text = "Licensing protocol was not completed"; + break; + + case exDiscReasonLicenseErrClientEncryption: + text = "Incorrect client license enryption"; + break; + + case exDiscReasonLicenseCantUpgradeLicense: + text = "Can't upgrade license"; + break; + + case exDiscReasonLicenseNoRemoteConnections: + text = "The server is not licensed to accept remote connections"; + break; + + default: + if (reason > 0x1000 && reason < 0x7fff) + { + text = "Internal protocol error"; + } + else + { + text = "Unknown reason"; + } + } + fprintf(stderr, "disconnect: %s.\n", text); +} + static BOOL read_password(char *password, int size) { @@ -240,9 +342,9 @@ char password[64]; char shell[128]; char directory[32]; - BOOL prompt_password, rdp_retval = False; + BOOL prompt_password, deactivated; struct passwd *pw; - uint32 flags; + uint32 flags, ext_disc_reason = 0; char *p; int c; @@ -412,7 +514,7 @@ case 'X': g_embed_wnd = strtol(optarg, NULL, 10); break; - + case 'a': g_server_bpp = strtol(optarg, NULL, 10); if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15 @@ -424,10 +526,12 @@ break; case 'x': - + if (strncmp("modem", optarg, 1) == 0) { - g_rdp5_performanceflags = RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING; + g_rdp5_performanceflags = + RDP5_NO_WALLPAPER | RDP5_NO_FULLWINDOWDRAG | + RDP5_NO_MENUANIMATIONS | RDP5_NO_THEMING; } else if (strncmp("broadband", optarg, 1) == 0) { @@ -442,7 +546,7 @@ g_rdp5_performanceflags = strtol(optarg, NULL, 16); } break; - + case 'r': if (strncmp("sound", optarg, 5) == 0) @@ -498,7 +602,7 @@ } else if (strncmp("clientname", optarg, 7) == 0) { - g_rdpdr_clientname = xmalloc(strlen(optarg+11)+1); + g_rdpdr_clientname = xmalloc(strlen(optarg + 11) + 1); strcpy(g_rdpdr_clientname, optarg + 11); } else @@ -600,7 +704,7 @@ if (ui_create_window()) { - rdp_retval = rdp_main_loop(); + rdp_main_loop(&deactivated, &ext_disc_reason); ui_destroy_window(); } @@ -608,10 +712,28 @@ rdp_disconnect(); ui_deinit(); - if (True == rdp_retval) + if (ext_disc_reason >= 2) + print_disconnect_reason(ext_disc_reason); + + if (deactivated) + { + /* clean disconnect */ return 0; + } else - return 2; + { + if (ext_disc_reason == exDiscReasonAPIInitiatedDisconnect + || ext_disc_reason == exDiscReasonAPIInitiatedLogoff) + { + /* not so clean disconnect, but nothing to worry about */ + return 0; + } + else + { + /* return error */ + return 2; + } + } #endif