CVS: rdesktop constants.h,1.32,1.33 proto.h,1.60,1.61 rdesktop.c,1.103,1.104 rdp.c,1.55,1.56

Peter ?strand <[email protected]>
Newsgroups gmane.network.rdesktop.cvs
Message-ID <[email protected]>
Update of /cvsroot/rdesktop/rdesktop
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22392

Modified Files:
	constants.h proto.h rdesktop.c rdp.c 
Log Message:
Applied disconnect handling patch from Jeroen Meijer

Index: constants.h
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/constants.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** constants.h	15 Apr 2004 20:12:31 -0000	1.32
--- constants.h	20 Apr 2004 07:01:17 -0000	1.33
***************
*** 357,358 ****
--- 357,380 ----
  #define FILE_NON_DIRECTORY_FILE         0x00000040
  #define FILE_OPEN_FOR_FREE_SPACE_QUERY  0x00800000
+ 
+ /* RDP5 disconnect PDU */
+ #define exDiscReasonNoInfo				0x0000
+ #define exDiscReasonAPIInitiatedDisconnect		0x0001
+ #define exDiscReasonAPIInitiatedLogoff			0x0002
+ #define exDiscReasonServerIdleTimeout			0x0003
+ #define exDiscReasonServerLogonTimeout			0x0004
+ #define exDiscReasonReplacedByOtherConnection		0x0005
+ #define exDiscReasonOutOfMemory				0x0006
+ #define exDiscReasonServerDeniedConnection		0x0007
+ #define exDiscReasonServerDeniedConnectionFips		0x0008
+ #define exDiscReasonLicenseInternal			0x0100
+ #define exDiscReasonLicenseNoLicenseServer		0x0101
+ #define exDiscReasonLicenseNoLicense			0x0102
+ #define exDiscReasonLicenseErrClientMsg			0x0103
+ #define exDiscReasonLicenseHwidDoesntMatchLicense	0x0104
+ #define exDiscReasonLicenseErrClientLicense		0x0105
+ #define exDiscReasonLicenseCantFinishProtocol		0x0106
+ #define exDiscReasonLicenseClientEndedProtocol		0x0107
+ #define exDiscReasonLicenseErrClientEncryption		0x0108
+ #define exDiscReasonLicenseCantUpgradeLicense		0x0109
+ #define exDiscReasonLicenseNoRemoteConnections		0x010a

Index: proto.h
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/proto.h,v
retrieving revision 1.60
retrieving revision 1.61
diff -C2 -d -r1.60 -r1.61
*** proto.h	17 Apr 2004 07:32:52 -0000	1.60
--- proto.h	20 Apr 2004 07:01:17 -0000	1.61
***************
*** 86,90 ****
  void process_bitmap_updates(STREAM s);
  void process_palette(STREAM s);
! BOOL rdp_main_loop(void);
  BOOL rdp_connect(char *server, uint32 flags, char *domain, char *password, char *command,
  		 char *directory);
--- 86,90 ----
  void process_bitmap_updates(STREAM s);
  void process_palette(STREAM s);
! void rdp_main_loop(BOOL * deactivated, uint32 * ext_disc_reason);
  BOOL rdp_connect(char *server, uint32 flags, char *domain, char *password, char *command,
  		 char *directory);

Index: rdesktop.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/rdesktop.c,v
retrieving revision 1.103
retrieving revision 1.104
diff -C2 -d -r1.103 -r1.104
*** rdesktop.c	15 Apr 2004 20:12:31 -0000	1.103
--- rdesktop.c	20 Apr 2004 07:01:17 -0000	1.104
***************
*** 149,152 ****
--- 149,252 ----
  }
  
+ 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)
***************
*** 243,249 ****
  	char shell[128];
  	char directory[32];
! 	BOOL prompt_password, rdp_retval = False;
  	struct passwd *pw;
! 	uint32 flags;
  	char *p;
  	int c;
--- 343,349 ----
  	char shell[128];
  	char directory[32];
! 	BOOL prompt_password, deactivated;
  	struct passwd *pw;
! 	uint32 flags, ext_disc_reason = 0;
  	char *p;
  	int c;
***************
*** 605,609 ****
  	if (ui_create_window())
  	{
! 		rdp_retval = rdp_main_loop();
  		ui_destroy_window();
  	}
--- 705,709 ----
  	if (ui_create_window())
  	{
! 		rdp_main_loop(&deactivated, &ext_disc_reason);
  		ui_destroy_window();
  	}
***************
*** 613,620 ****
  	ui_deinit();
  
! 	if (True == rdp_retval)
  		return 0;
  	else
! 		return 2;
  
  #endif
--- 713,738 ----
  	ui_deinit();
  
! 	if (ext_disc_reason >= 2)
! 		print_disconnect_reason(ext_disc_reason);
! 
! 	if (deactivated)
! 	{
! 		/* clean disconnect */
  		return 0;
+ 	}
  	else
! 	{
! 		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

Index: rdp.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/rdp.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -C2 -d -r1.55 -r1.56
*** rdp.c	17 Apr 2004 07:37:07 -0000	1.55
--- rdp.c	20 Apr 2004 07:01:21 -0000	1.56
***************
*** 887,893 ****
  }
  
  /* Process data PDU */
! static void
! process_data_pdu(STREAM s)
  {
  	uint8 data_pdu_type;
--- 887,902 ----
  }
  
+ /* Process a disconnect PDU */
+ void
+ process_disconnect_pdu(STREAM s, uint32 * ext_disc_reason)
+ {
+ 	in_uint32_le(s, *ext_disc_reason);
+ 
+ 	DEBUG(("Received disconnect PDU\n"));
+ }
+ 
  /* Process data PDU */
! static BOOL
! process_data_pdu(STREAM s, uint32 * ext_disc_reason)
  {
  	uint8 data_pdu_type;
***************
*** 940,943 ****
--- 949,960 ----
  			break;
  
+ 		case RDP_DATA_PDU_CONTROL:
+ 			DEBUG(("Received Control PDU\n"));
+ 			break;
+ 
+ 		case RDP_DATA_PDU_SYNCHRONISE:
+ 			DEBUG(("Received Sync PDU\n"));
+ 			break;
+ 
  		case RDP_DATA_PDU_POINTER:
  			process_pointer_pdu(s);
***************
*** 954,972 ****
  
  		case RDP_DATA_PDU_DISCONNECT:
! 			/* Normally received when user logs out or disconnects from a
! 			   console session on Windows XP and 2003 Server */
! 			DEBUG(("Received disconnect PDU\n"));
! 			break;
  
  		default:
  			unimpl("data PDU %d\n", data_pdu_type);
  	}
  }
  
  /* Process incoming packets */
! BOOL
! rdp_main_loop(void)
  {
  	uint8 type;
  	STREAM s;
  
--- 971,989 ----
  
  		case RDP_DATA_PDU_DISCONNECT:
! 			process_disconnect_pdu(s, ext_disc_reason);
! 			return True;
  
  		default:
  			unimpl("data PDU %d\n", data_pdu_type);
  	}
+ 	return False;
  }
  
  /* Process incoming packets */
! void
! rdp_main_loop(BOOL * deactivated, uint32 * ext_disc_reason)
  {
  	uint8 type;
+ 	BOOL disc = False;	/* True when a disconnect PDU was received */
  	STREAM s;
  
***************
*** 977,994 ****
  			case RDP_PDU_DEMAND_ACTIVE:
  				process_demand_active(s);
  				break;
  
  			case RDP_PDU_DEACTIVATE:
! 				DEBUG(("RDP_PDU_DEACTIVATE\n"));
! 				/* We thought we could detect a clean
! 				   shutdown of the session by this
! 				   packet, but it seems Windows 2003
! 				   is sending us one of these when we
! 				   reconnect to a disconnected session
! 				   return True; */
  				break;
  
  			case RDP_PDU_DATA:
! 				process_data_pdu(s);
  				break;
  
--- 994,1006 ----
  			case RDP_PDU_DEMAND_ACTIVE:
  				process_demand_active(s);
+ 				*deactivated = False;
  				break;
  
  			case RDP_PDU_DEACTIVATE:
! 				*deactivated = True;
  				break;
  
  			case RDP_PDU_DATA:
! 				disc = process_data_pdu(s, ext_disc_reason);
  				break;
  
***************
*** 999,1007 ****
  				unimpl("PDU %d\n", type);
  		}
  	}
! 	return True;
! 	/* We want to detect if we got a clean shutdown, but we
! 	   can't. Se above.  
! 	   return False;  */
  }
  
--- 1011,1021 ----
  				unimpl("PDU %d\n", type);
  		}
+ 
+ 		if (disc)
+ 		{
+ 			return;
+ 		}
  	}
! 	return;
  }
  



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.