[NeoStats-Devel] [Commits] r2744 - in trunk: . include modules/statserv src

[email protected] Thu, 18 Aug 2005 09:57:44 +1000
Newsgroups gmane.comp.neostats.devel
Message-ID <[email protected]>
Author: Mark
Date: Thu Aug 18 07:57:40 2005
New Revision: 2744

Modified:
   trunk/ChangeLog
   trunk/configure
   trunk/configure.in
   trunk/include/config.h.in
   trunk/include/configwin32.h
   trunk/include/neostats.h
   trunk/include/support.h
   trunk/modules/statserv/htmlstats.c
   trunk/src/nsdba.c
   trunk/src/support.c
Log:
Add strcasestr support function since not all systems support it

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	(original)
+++ trunk/ChangeLog	Thu Aug 18 07:57:40 2005
@@ -4,6 +4,7 @@
 Fish (F), Mark (M), DeadNotBuried (D)
 ===============================================================================
 * NeoStats * Version 3.0.a3-dev
+ - Add strcasestr support function since not all systems support it. (M)
  - New macros NS_CMD_END() and NS_SETTING_END() for terminating command and set
    lists. (M)
  - ConnectServ colour logging is now settable via IRC (F)

Modified: trunk/configure
==============================================================================
--- trunk/configure	(original)
+++ trunk/configure	Thu Aug 18 07:57:40 2005
@@ -22389,10 +22389,12 @@
 
 
 
+
 for ac_func in socket \
                 select \
                 strdup \
                 strstr \
+                strcasestr \
                 strtok_r \
                 strftime \
                 uname \

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Thu Aug 18 07:57:40 2005
@@ -148,6 +148,7 @@
                 select \
                 strdup \
                 strstr \
+                strcasestr \
                 strtok_r \
                 strftime \
                 uname \

Modified: trunk/include/config.h.in
==============================================================================
--- trunk/include/config.h.in	(original)
+++ trunk/include/config.h.in	Thu Aug 18 07:57:40 2005
@@ -296,6 +296,9 @@
 /* Define to 1 if you have the `strstr' function. */
 #undef HAVE_STRSTR
 
+/* Define to 1 if you have the `strstr' function. */
+#undef HAVE_STRCASESTR
+
 /* Define to 1 if you have the `strtok_r' function. */
 #undef HAVE_STRTOK_R
 

Modified: trunk/include/configwin32.h
==============================================================================
--- trunk/include/configwin32.h	(original)
+++ trunk/include/configwin32.h	Thu Aug 18 07:57:40 2005
@@ -278,6 +278,9 @@
 /* Define to 1 if you have the `strstr' function. */
 #define HAVE_STRSTR 1
 
+/* Define to 1 if you have the `strcasestr' function. */
+#undef HAVE_STRCASESTR
+
 /* Define to 1 if you have the `strtok_r' function. */
 #define HAVE_STRTOK_R 1
 

Modified: trunk/include/neostats.h
==============================================================================
--- trunk/include/neostats.h	(original)
+++ trunk/include/neostats.h	Thu Aug 18 07:57:40 2005
@@ -1379,12 +1379,12 @@
 /* DB API */
 EXPORTFUNC int DBAOpenDatabase( void );
 EXPORTFUNC int DBACloseDatabase( void );
-EXPORTFUNC int DBAOpenTable( char *table );
-EXPORTFUNC int DBACloseTable( char *table );
-EXPORTFUNC int DBAStore( char *table, char *key, void *data, int size );
-EXPORTFUNC int DBAFetch( char *table, char *key, void *data, int size );
-EXPORTFUNC int DBADelete( char *table, char * key );
-EXPORTFUNC int DBAFetchRows( char * table, DBRowHandler handler );
+EXPORTFUNC int DBAOpenTable( const char *table );
+EXPORTFUNC int DBACloseTable( const char *table );
+EXPORTFUNC int DBAStore( const char *table, char *key, void *data, int size );
+EXPORTFUNC int DBAFetch( const char *table, char *key, void *data, int size );
+EXPORTFUNC int DBADelete( const char *table, char * key );
+EXPORTFUNC int DBAFetchRows( const char * table, DBRowHandler handler );
 /* DB API Macros to wrap common types */
 #define DBAStoreBool( table, key, data ) DBAStore( table, key, ( void* )data, sizeof ( int ) )
 #define DBAStoreInt( table, key, data ) DBAStore( table, key, ( void* )data, sizeof ( int ) )

Modified: trunk/include/support.h
==============================================================================
--- trunk/include/support.h	(original)
+++ trunk/include/support.h	Thu Aug 18 07:57:40 2005
@@ -37,8 +37,11 @@
 EXPORTFUNC char *strndup( const char *src, size_t count );
 #endif /* HAVE_STRNDUP */
 #ifndef HAVE_STRDUP
-char *strdup( const char *src );
+EXPORTFUNC char *strdup( const char *src );
 #endif /* HAVE_STRDUP */
+#ifndef HAVE_STRCASESTR
+EXPORTFUNC char *strcasestr( const char *s1, const char *s2 );
+#endif /* HAVE_STRCASESTR */
 #ifndef HAVE_INET_NTOP
 EXPORTFUNC char *inet_ntop( int af, const unsigned char *src, char *dst, size_t size ); 
 #endif /* HAVE_INET_NTOP */
@@ -51,7 +54,7 @@
 	int tz_dsttime;
 };
 
-int gettimeofday(struct timeval *tv, struct timezone *tz);
+EXPORTFUNC int gettimeofday(struct timeval *tv, struct timezone *tz);
 #endif /* HAVE_GETTIMEOFDAY */
 
 

Modified: trunk/modules/statserv/htmlstats.c
==============================================================================
--- trunk/modules/statserv/htmlstats.c	(original)
+++ trunk/modules/statserv/htmlstats.c	Thu Aug 18 07:57:40 2005
@@ -469,7 +469,7 @@
 			}		
 			htmlfuncptr++;
 		}
-		buftemp = strstr( bufptr, "</html>" );
+		buftemp = strcasestr( bufptr, "</html>" );
 		if( buftemp ) {
 			os_fwrite( bufptr,( int )buftemp -( int )bufptr, 1, opf );
 			put_copyright();

Modified: trunk/src/nsdba.c
==============================================================================
--- trunk/src/nsdba.c	(original)
+++ trunk/src/nsdba.c	Thu Aug 18 07:57:40 2005
@@ -249,7 +249,7 @@
  *  @return NS_SUCCESS if succeeds, NS_FAILURE if not 
  */
 
-int DBAOpenTable( char *table )
+int DBAOpenTable( const char *table )
 {
 	dbentry *dbe;
 	tableentry *tbe;
@@ -285,7 +285,7 @@
  *  @return table entry or NULL for none
  */
 
-static tableentry *DBAFetchTableEntry( char *table )
+static tableentry *DBAFetchTableEntry( const char *table )
 {
 	dbentry *dbe;
 	tableentry *tbe;
@@ -318,7 +318,7 @@
  *  @return NS_SUCCESS if succeeds, NS_FAILURE if not 
  */
 
-int DBACloseTable( char *table )
+int DBACloseTable( const char *table )
 {
 	dbentry *dbe;
 	tableentry *tbe;
@@ -356,7 +356,7 @@
  *  @return NS_SUCCESS if succeeds, NS_FAILURE if not 
  */
 
-int DBAFetch( char *table, char *key, void *data, int size )
+int DBAFetch( const char *table, char *key, void *data, int size )
 {
 	tableentry *tbe;
 
@@ -379,7 +379,7 @@
  *  @return NS_SUCCESS if succeeds, NS_FAILURE if not 
  */
 
-int DBAStore( char *table, char *key, void *data, int size )
+int DBAStore( const char *table, char *key, void *data, int size )
 {
 	tableentry *tbe;
 
@@ -400,7 +400,7 @@
  *  @return number of rows processed by handler
  */
 
-int DBAFetchRows( char *table, DBRowHandler handler )
+int DBAFetchRows( const char *table, DBRowHandler handler )
 {
 	tableentry *tbe;
 
@@ -421,7 +421,7 @@
  *  @return NS_SUCCESS if succeeds, NS_FAILURE if not 
  */
 
-int DBADelete( char *table, char *key )
+int DBADelete( const char *table, char *key )
 {
 	tableentry *tbe;
 

Modified: trunk/src/support.c
==============================================================================
--- trunk/src/support.c	(original)
+++ trunk/src/support.c	Thu Aug 18 07:57:40 2005
@@ -27,20 +27,25 @@
 #include "neostats.h"
 
 #ifndef HAVE_STRNLEN
-/* @brief find length of string up to count max
+/** @brief strnlen
  *
- * @return length of string excluding NULL or count if longer
+ *  Find length of string up to count max
  *
+ *  @param src string to find length of
+ *  @param count limit of search
+ *
+ *  @return length of string excluding NULL or count if longer
  */
+
 size_t strnlen( const char * src, size_t count )
 {
 	size_t len;
 
 	/* Run through the string until we find NULL or reach count */
-	for( len = 0; len < count; len++, src++ ) {
-		if( *src == 0 ){
+	for( len = 0; len < count; len++, src++ )
+	{
+		if( *src == 0 )
 			return len;
-		}
 	}
 	/* src is longer or equal to count so return count */
 	return count;
@@ -48,11 +53,17 @@
 #endif /* HAVE_STRNLEN */
 
 #ifndef HAVE_STRLCPY
-/* @brief copy up to size-1 characters from src to dst and NULL terminate
+/** @brief strlcpy
+ *
+ *  Copy up to size-1 characters from src to dst and NULL terminate
  *
- * @return total characters written to string.
+ *  @param dst to copy to
+ *  @param src to copy from
+ *  @param count max size to copy
  *
+ *  @return total characters written to string.
  */
+
 size_t strlcpy( char *dst, const char *src, size_t size )
 {
 	size_t copycount;
@@ -74,11 +85,18 @@
 #endif /* HAVE_STRLCPY */
 
 #ifndef HAVE_STRLCAT
-/* @brief append at most size-len( dst )-1 chars from src to dst and NULL terminate
+
+/** @brief strlcat
  *
- * @return total characters written to string.
+ *  Append at most size-len( dst )-1 chars from src to dst and NULL terminate
  *
+ *  @param dst to copy to
+ *  @param src to copy from
+ *  @param count max size to copy
+ *
+ *  @return total characters written to string.
  */
+
 size_t strlcat( char *dst, const char *src, size_t size )
 {
 	size_t lendst;
@@ -116,14 +134,19 @@
 #endif /* HAVE_STRLCAT */
 
 #ifndef HAVE_STRNDUP
-/* @brief allocate RAM and duplicate the passed string into the created buffer. 
+/** @brief strndup
+ *
+ *  allocate RAM and duplicate the passed string into the created buffer. 
  *  Always NULL terminates the new string.
  *  Suitable for partial string copies.
  *  Returned string will be count + 1 in length
  *
- * @return pointer to new string or NULL if failed to allocate
+ *  @param src to copy from
+ *  @param count max size to copy
  *
+ *  @return pointer to new string or NULL if failed to allocate
  */
+
 char *strndup( const char *src, size_t count )
 {
 	char *dup;
@@ -139,14 +162,18 @@
 	/* Return pointer to duplicated string */
 	return dup;
 }
-#endif
+#endif /* HAVE_STRNDUP */
 
 #ifndef HAVE_STRDUP
-/* @brief allocate RAM and duplicate the passed string into the created buffer. 
+/** @brief strdup
  *
- * @return pointer to new string or NULL if failed to allocate
+ *  allocate RAM and duplicate the passed string into the created buffer. 
  *
+ *  @param src to copy from
+ *
+ *  @return pointer to new string or NULL if failed to allocate
  */
+
 char *strdup( const char *src )
 {
 	char *dup;
@@ -161,28 +188,80 @@
 	/* Return pointer to duplicated string */
 	return dup;
 }
-#endif
+#endif /* HAVE_STRDUP */
+
+#ifndef HAVE_STRCASESTR
+/** @brief strcasestr
+ *
+ *  case insensitive sub string search
+ *
+ *  @param s1 string to search
+ *  @param s2 substring to locate
+ *
+ *  @return pointer to location of substring or NULL if not found
+ */
+
+char *strcasestr( const char *s1, const char *s2 )
+{
+	while( *s1 )
+	{
+		const char *ps1 = s1;
+		const char *ps2 = s2;
+
+		while( *ps2 )
+		{
+			if( toupper( *ps2 ) != toupper( *ps1 ) ) 
+				break;
+			ps2++;
+			ps1++;
+		}
+		if( !*ps2 ) 
+			return (char *) s1;
+		s1++;
+	}
+	return NULL;
+}
+#endif /* HAVE_STRCASESTR */
 
 #ifndef HAVE_INET_NTOP
+/** @brief inet_ntop
+ *
+ *  convert IPv4 addresses between binary and text form
+ *
+ *  @param af AF_INET
+ *  @param src buffer containing IPv4 address in network byte order
+ *  @param dst buffer to store result
+ *  @param size of dst
+ *
+ *  @return pointer to the buffer containing the text string if succeeds else NULL
+ */
+
 char *inet_ntop( int af, const unsigned char *src, char *dst, size_t size )
 { 
 	static const char *fmt = "%u.%u.%u.%u";
-	char tmp[sizeof ( "255.255.255.255" )];
+	char tmp[ sizeof( "255.255.255.255" )];
 
 	if ( ( size_t ) sprintf( tmp, fmt, src[0], src[1], src[2], src[3] ) >= size )
 		return NULL;
 	strlcpy( dst, tmp, size );
 	return dst;
 }
-#endif
+#endif /* HAVE_INET_NTOP */
 
 #ifndef HAVE_INET_ATON
-/* Convert from "a.b.c.d" IP address string into an in_addr structure.  
- * Return 0 on failure, 1 on success.
+/** @brief inet_ntop
+ *
+ *  Convert from "a.b.c.d" IP address string into an in_addr structure.  
+ *
+ *  @param 
+ *  @param 
+ *
+ *  @return 0 on failure, 1 on success.
  */
+
 int inet_aton( const char *name, struct in_addr *addr )
 {
     addr->s_addr = inet_addr( name );
     return ( addr->s_addr == INADDR_NONE  ? 0 : 1 );
 }
-#endif
+#endif /* HAVE_INET_ATON */