commit: r363 - in trunk: daemon libspread

[email protected] Tue, 14 Nov 2006 02:42:20 -0500
Newsgroups gmane.network.spread.cvs
Message-ID <[email protected]>
Author: jonathan
Date: 2006-11-14 02:42:20 -0500 (Tue, 14 Nov 2006)
New Revision: 363

Modified:
   trunk/daemon/Changelog
   trunk/daemon/arch.h
   trunk/libspread/sp.c
Log:
Remove explicit port number from library source, it is now defined in terms of DEFAULT_SPREAD_PORT.
Make code more readable by renaming variables
Define the length of a spread_name in SP_connect in terms of maximum host name length. 
Add check for a spread_name that is too long.


Modified: trunk/daemon/Changelog
===================================================================
--- trunk/daemon/Changelog	2006-11-14 05:54:11 UTC (rev 362)
+++ trunk/daemon/Changelog	2006-11-14 07:42:20 UTC (rev 363)
@@ -1,3 +1,17 @@
+Tue Nov 14 01:40:43 2006  Jonathan Stanton  <[email protected]>
+
+	* sp.c (SP_connect_timeout): Rename variables to make more 
+	readable. Define length of spread_name parameter in terms
+	of MAXHOSTNAMELEN because it is determined by how large a 
+	host name can be. 
+
+	Define the default spread connection port (4803) in terms 
+	of the DEFAULT_SPREAD_PORT to remove explicit port number
+	from source code.
+
+	* arch.h: Add Q() and QQ() macros in order to make strings 
+	from #define macros.
+	
 Tue Nov 14 00:38:14 2006  Jonathan Stanton  <[email protected]>
 
 	* sp.c (connect_nointr_timeout): Fix bug where tv_sec was

Modified: trunk/daemon/arch.h
===================================================================
--- trunk/daemon/arch.h	2006-11-14 05:54:11 UTC (rev 362)
+++ trunk/daemon/arch.h	2006-11-14 07:42:20 UTC (rev 363)
@@ -198,9 +198,12 @@
 #else
 #define get_rand rand
 #endif
-  
 
+/* Useful CPP macros to make strings from #defines */  
+#define Q(x)    # x
+#define QQ(x)   Q(x)
 
+
 #define         ENDIAN_TYPE             0x80000080
 
 #define		Get_endian( type )	( (type) &  ENDIAN_TYPE )

Modified: trunk/libspread/sp.c
===================================================================
--- trunk/libspread/sp.c	2006-11-14 05:54:11 UTC (rev 362)
+++ trunk/libspread/sp.c	2006-11-14 07:42:20 UTC (rev 363)
@@ -47,6 +47,7 @@
 #include <netinet/in.h> 
 #include <netinet/tcp.h> 
 #include <sys/un.h>
+#include <sys/param.h>
 #include <netdb.h>
 #include <signal.h>
 #include <sys/ioctl.h>
@@ -103,6 +104,16 @@
         void    *auth_data;
 };
 
+/* length of spread_name connect field is limited to 5 digit port # + '@' + hostname */
+#define SPREAD_MAXCONNECT_NAMELEN       MAXHOSTNAMELEN + 6
+
+/* default spread connection method depends on whether unix sockets are available */
+#ifndef ARCH_PC_WIN95
+# define DEFAULT_SPREAD_CONNECTION      QQ(DEFAULT_SPREAD_PORT)
+#else
+# define DEFAULT_SPREAD_CONNECTION      QQ(DEFAULT_SPREAD_PORT) "@localhost"
+#endif	/* ARCH_PC_WIN95 */
+
 static  int     sp_null_authenticate(int, void *);
 static  struct auth_method_info Auth_Methods[MAX_AUTH_METHODS] = { {"NULL", sp_null_authenticate, NULL} };
 static  int     Num_Reg_Auth_Methods = 1;
@@ -548,9 +559,9 @@
 	int32			host_address;
 	int32			lport, i1, i2, i3, i4;
 	char			*c_ptr;
-	char			host_name[80];
-	char			s_name[80];
-	char			dummy_s[80];
+	char			host_name[MAXHOSTNAMELEN];
+	char			s_name[SPREAD_MAXCONNECT_NAMELEN + 1];
+	char			dummy_s[20];
 	char			conn[MAX_PRIVATE_NAME+5];
         signed char                    auth_list_len;
         char                    auth_list[MAX_AUTH_NAME * MAX_AUTH_METHODS];
@@ -563,7 +574,7 @@
 	int			ret, i;
         unsigned int            len;
 	int			sp_v1, sp_v2, sp_v3;
-	char			l;
+	char		        cval;
 	int32			on;
 
 	struct	sockaddr_in	inet_addr;
@@ -594,19 +605,18 @@
 	 *	[email protected]
 	 */
 
-	if( spread_name == 0 || (!strcmp( spread_name, "" ) ) ) 
-#ifndef ARCH_PC_WIN95
-		strcpy( s_name, "4803" );
-#else
-		strcpy( s_name, "4803@localhost" );
-#endif	/* ARCH_PC_WIN95 */
-
-	else strcpy( s_name, spread_name );
+	if( spread_name == NULL || (!strcmp( spread_name, "" ) ) ) {
+		strcpy( s_name, DEFAULT_SPREAD_CONNECTION );
+        } else {
+            if (strlen(spread_name) > SPREAD_MAXCONNECT_NAMELEN) 
+                return( ILLEGAL_SPREAD );
+            strcpy( s_name, spread_name );
+        }
 	c_ptr = strchr( s_name, ' ');
-	if( c_ptr != 0 ) return ( ILLEGAL_SPREAD );
+	if( c_ptr != NULL ) return ( ILLEGAL_SPREAD );
 	c_ptr = strchr( s_name, '@');
 
-	if( c_ptr == 0 )
+	if( c_ptr == NULL )
 	{
 
 #ifndef	ARCH_PC_WIN95
@@ -623,7 +633,7 @@
 		ret = sscanf( s_name,"%d%s", &lport, host_name );
 		if( ret != 2) return( ILLEGAL_SPREAD );
 		host_ptr = gethostbyname( host_name );
-		if( host_ptr != 0 )
+		if( host_ptr != NULL )
 		{
 			/* option [email protected] */
 			memcpy( &host_address, host_ptr->h_addr, sizeof(int32) );
@@ -632,7 +642,7 @@
 			for(i=0; i< 3; i++)
 			{
 				c_ptr = strchr(host_name, '.' );
-				if ( c_ptr == 0) return( ILLEGAL_SPREAD );
+				if ( c_ptr == NULL) return( ILLEGAL_SPREAD );
 				*c_ptr = ' ';
 			}
 			ret = sscanf( host_name, "%d%d%d%d%s", &i1, &i2, &i3, &i4, dummy_s );
@@ -818,46 +828,46 @@
                 return( REJECT_AUTH );
         }
 
-	l=0;
-        ret = recv_nointr_timeout( s, &l, 1, 0, &time_out);
+	cval=0;
+        ret = recv_nointr_timeout( s, &cval, 1, 0, &time_out);
 	if( ret <= 0 )
 	{
 		Alarm( SESSION, "SP_connect: unable to read answer %d: %s\n", ret, sock_strerror(sock_errno));
 		close( s );
 		return( CONNECTION_CLOSED );
 	}
-	if( l != ACCEPT_SESSION )
+	if( cval != ACCEPT_SESSION )
 	{
-		Alarm( SESSION, "SP_connect: session rejected %d\n", l);
+		Alarm( SESSION, "SP_connect: session rejected %d\n", cval);
 		close( s );
-		return( l );
+		return( cval );
 	}
-        ret = recv_nointr_timeout( s, &l, 1, 0, &time_out);
+        ret = recv_nointr_timeout( s, &cval, 1, 0, &time_out);
 	if( ret <= 0 )
 	{
 		Alarm( SESSION, "SP_connect: unable to read version %d: %s\n", ret, sock_strerror(sock_errno));
 		close( s );
 		return( CONNECTION_CLOSED );
 	}
-	sp_v1 = l;
+	sp_v1 = cval;
 
-        ret = recv_nointr_timeout( s, &l, 1, 0, &time_out);
+        ret = recv_nointr_timeout( s, &cval, 1, 0, &time_out);
 	if( ret <= 0 )
 	{
 		Alarm( SESSION, "SP_connect: unable to read subversion %d: %s\n", ret, sock_strerror(sock_errno));
 		close( s );
 		return( CONNECTION_CLOSED );
 	}
-	sp_v2 = l;
+	sp_v2 = cval;
 
-        ret = recv_nointr_timeout( s, &l, 1, 0, &time_out);
+        ret = recv_nointr_timeout( s, &cval, 1, 0, &time_out);
 	if( ret <= 0 )
 	{
 		Alarm( SESSION, "SP_connect: unable to read patch version %d: %s\n", ret, sock_strerror(sock_errno));
 		close( s );
 		return( CONNECTION_CLOSED );
 	}
-	sp_v3 = l;
+	sp_v3 = cval;
 
 	/* checking spread version. Should be at least 3.01 */
 	if( sp_v1*10000 + sp_v2*100 + sp_v3 < 30100 )
@@ -875,14 +885,14 @@
 		return( REJECT_VERSION );
 	}
 
-        ret = recv_nointr_timeout( s, &l, 1, 0, &time_out);
+        ret = recv_nointr_timeout( s, &cval, 1, 0, &time_out);
 	if( ret <= 0 )
 	{
 		Alarm( SESSION, "SP_connect: unable to read size of group %d: %s\n", ret, sock_strerror(sock_errno));
                 close( s );
 		return( CONNECTION_CLOSED );
 	}
-	len = l;
+	len = cval;
         ret = recv_nointr_timeout( s, private_group, len, 0, &time_out);
 	if( ret <= 0 )
 	{
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.