Package: dhttpd
Severity: wishlist
Tags: patch

Attached are 2 patches that correct some problems with the source.

 1. the 'char*' => 'const char *' fixes the warnings
 2. static local functions do not pollute global namespace (as small
 as it is!)
 3. use of a predefined constant as an argument to shutdown instead of
 hardcoded value makes code clearer

- Adam


-- System Information:
Debian Release: 5.0
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.26-1-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_CA.UTF-8, LC_CTYPE=en_CA.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
commit c640c585e690e5a1cf3a82d55062ad286e316a8d
Author: Adam Majer <ad...@zombino.com>
Date:   Wed Feb 18 21:13:02 2009 -0600

    Use 'const char*' instead of 'char *' and static local functions

diff --git a/httpsock.cc b/httpsock.cc
index 5725dc5..f7ad7a1 100644
--- a/httpsock.cc
+++ b/httpsock.cc
@@ -48,21 +48,21 @@
 
 extern char ROOT_DIR[];
 
-char *dayName[] = {
+static const char *dayName[] = {
 	"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
 };
 
-char *monthName[] = {
+static const char *monthName[] = {
 	"Jan", "Feb", "Mar", "Apr", "May", "Jun",
 	"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
 };
 
 struct AssocType
 {
-	char *ext, *type;
+	const char *ext, *type;
 };
 
-AssocType assocNames[] =
+static AssocType assocNames[] =
 {
 	{ ".mp2", "audio/mpeg" },
 	{ ".mpa", "audio/mpeg" },
@@ -105,7 +105,7 @@ AssocType assocNames[] =
 	{ NULL, NULL }
 };
 
-char *getMimeTime( tm *t )
+static char *getMimeTime( tm *t )
 {
 	static char out[ 44 ];
 	
@@ -119,14 +119,14 @@ char *getMimeTime( tm *t )
 	return out;
 }
 
-char *curTime()
+static char *curTime()
 {
 	time_t t;
 	t = time( NULL );
 	return getMimeTime( gmtime( &t ) );
 }
 
-char *guessType( char *f )
+static const char *guessType( char *f )
 {
 	int flen;
 	int tlen;
@@ -149,7 +149,7 @@ char *guessType( char *f )
 	return "application/x-unknown";
 }
 
-int findMonth( char *s )
+static int findMonth( const char *s )
 {
 	int g;
 
@@ -164,7 +164,7 @@ int findMonth( char *s )
 	return -1;
 }
 
-int badFileName( char *s )
+static int badFileName( const char *s )
 {
 	if( strstr( s, ".." ) )
 	{
@@ -179,7 +179,7 @@ int badFileName( char *s )
 	return 0;
 }
 
-void error( FILE *out, int num, char *status, char *msg, char *str )
+static void error( FILE *out, int num, const char *status, const char *msg, const char *str )
 {
 	FILE *in;
 	int numch;
@@ -222,7 +222,7 @@ void error( FILE *out, int num, char *status, char *msg, char *str )
 	free(file);
 }
 
-void screwed( FILE *out )
+static void screwed( FILE *out )
 {
 	error( out,
 		400,
@@ -233,7 +233,7 @@ void screwed( FILE *out )
 	);
 }
 
-void sendError( FILE *out, int status )
+static void sendError( FILE *out, int status )
 {
 	switch( status )
 	{
@@ -259,7 +259,7 @@ void sendError( FILE *out, int status )
 }
 
 /* Should the web browser used the cached version? */
-int useCache( struct tm *modTime, char *s )
+static int useCache( struct tm *modTime, char *s )
 {
 	char *pos;
 	char mname[ 1024 ];
@@ -341,7 +341,7 @@ int useCache( struct tm *modTime, char *s )
 	return 1;
 }
 
-void sendNotMod( FILE *out )
+static void sendNotMod( FILE *out )
 {
 	fprintf( out, "HTTP/1.0 304 Not modified\r\n" );
 	fprintf( out, "Date: %s\r\n",curTime() );
@@ -349,7 +349,7 @@ void sendNotMod( FILE *out )
 	fprintf( out, "\r\n" );
 }
 
-void sendHead( FILE *out, char *name, time_t tmMod, long filesize )
+static void sendHead( FILE *out, char *name, time_t tmMod, long filesize )
 {
 	fprintf( out, "HTTP/1.0 200 OK\r\n" );
 	fprintf( out, "Date: %s\n", curTime() );
@@ -360,7 +360,7 @@ void sendHead( FILE *out, char *name, time_t tmMod, long filesize )
 	fprintf( out, "\r\n" );
 }
 
-int sendFile( FILE *out, char *name, char *modTime, bool simple, bool headOnly )
+static int sendFile( FILE *out, char *name, char *modTime, bool simple, bool headOnly )
 {
 	FILE *in;
 	struct stat fs;
commit b63def5352c32ef8a904ae4beed55f27a3c40aff
Author: Adam Majer <ad...@zombino.com>
Date:   Wed Feb 18 21:12:34 2009 -0600

    Use names instead of hardcoded numbers

diff --git a/socket.cc b/socket.cc
index 90dfc09..f244530 100644
--- a/socket.cc
+++ b/socket.cc
@@ -62,7 +62,7 @@ Socket::~Socket()
 {
   if( sock!=-1 )
   {
-    shutdown( sock, 2 );
+    shutdown( sock, SHUT_RDWR );
     sock = -1;
   }
 
@@ -121,7 +121,7 @@ ListenSocket::ListenSocket( int port, char *bind_addr )
 	}
 	if( status )
 	{
-		shutdown( sock, 2 );
+		shutdown( sock, SHUT_RDWR );
 		sock = -1;
 	}
 }
@@ -138,7 +138,7 @@ ListenSocket::~ListenSocket()
 {
 	if( sock!=-1 )
 	{
-		shutdown( sock, 2 );
+		shutdown( sock, SHUT_RDWR );
 	}
 }
 

Reply via email to