Revision: 7171
          http://svn.sourceforge.net/mahogany/?rev=7171&view=rev
Author:   vadz
Date:     2006-12-17 16:05:52 -0800 (Sun, 17 Dec 2006)

Log Message:
-----------
minimally possible fixes to make dspam (with hash driver) compile under Windows 
with MSVC

Modified Paths:
--------------
    trunk/M/lib/dspam/src/base64.c
    trunk/M/lib/dspam/src/bnr.c
    trunk/M/lib/dspam/src/diction.c
    trunk/M/lib/dspam/src/error.h
    trunk/M/lib/dspam/src/hash_drv.c
    trunk/M/lib/dspam/src/hash_drv.h
    trunk/M/lib/dspam/src/heap.c
    trunk/M/lib/dspam/src/libdspam.c
    trunk/M/lib/dspam/src/pref.c
    trunk/M/lib/dspam/src/read_config.c
    trunk/M/lib/dspam/src/storage_driver.h
    trunk/M/lib/dspam/src/tokenizer.c
    trunk/M/lib/dspam/src/util.c
    trunk/M/lib/dspam/src/util.h

Added Paths:
-----------
    trunk/M/lib/dspam/dspam.vcproj
    trunk/M/lib/dspam/src/auto-config.h.win32

Added: trunk/M/lib/dspam/dspam.vcproj
===================================================================
--- trunk/M/lib/dspam/dspam.vcproj                              (rev 0)
+++ trunk/M/lib/dspam/dspam.vcproj      2006-12-18 00:05:52 UTC (rev 7171)
@@ -0,0 +1,284 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+       ProjectType="Visual C++"
+       Version="7.10"
+       Name="dspam"
+       ProjectGUID="{62156246-DCEA-4713-95E0-C01F595F1A20}"
+       RootNamespace="dspam"
+       SccProjectName=""
+       SccLocalPath="">
+       <Platforms>
+               <Platform
+                       Name="Win32"/>
+       </Platforms>
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       OutputDirectory="debug"
+                       IntermediateDirectory="debug"
+                       ConfigurationType="4"
+                       UseOfMFC="0"
+                       ATLMinimizesCRunTimeLibraryUsage="FALSE"
+                       CharacterSet="2">
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="0"
+                               AdditionalIncludeDirectories="src"
+                               PreprocessorDefinitions="HAVE_CONFIG_H;_DEBUG"
+                               ExceptionHandling="FALSE"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="3"
+                               UsePrecompiledHeader="0"
+                               PrecompiledHeaderFile="debug\dspam.pch"
+                               WarningLevel="4"
+                               SuppressStartupBanner="TRUE"
+                               DebugInformationFormat="3"
+                               CompileAs="1"/>
+                       <Tool
+                               Name="VCCustomBuildTool"/>
+                       <Tool
+                               Name="VCLibrarianTool"
+                               OutputFile="debug\dspam.lib"
+                               SuppressStartupBanner="TRUE"/>
+                       <Tool
+                               Name="VCMIDLTool"/>
+                       <Tool
+                               Name="VCPostBuildEventTool"/>
+                       <Tool
+                               Name="VCPreBuildEventTool"/>
+                       <Tool
+                               Name="VCPreLinkEventTool"/>
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                               PreprocessorDefinitions="_DEBUG"
+                               Culture="1033"/>
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"/>
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"/>
+                       <Tool
+                               Name="VCManagedWrapperGeneratorTool"/>
+                       <Tool
+                               Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       OutputDirectory="release"
+                       IntermediateDirectory="release"
+                       ConfigurationType="4"
+                       UseOfMFC="0"
+                       ATLMinimizesCRunTimeLibraryUsage="FALSE"
+                       CharacterSet="2">
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="2"
+                               InlineFunctionExpansion="1"
+                               AdditionalIncludeDirectories="src"
+                               PreprocessorDefinitions="HAVE_CONFIG_H;NDEBUG"
+                               StringPooling="TRUE"
+                               ExceptionHandling="FALSE"
+                               RuntimeLibrary="2"
+                               EnableFunctionLevelLinking="TRUE"
+                               UsePrecompiledHeader="0"
+                               PrecompiledHeaderFile="release\dspam.pch"
+                               WarningLevel="4"
+                               SuppressStartupBanner="TRUE"
+                               DebugInformationFormat="3"
+                               CompileAs="1"/>
+                       <Tool
+                               Name="VCCustomBuildTool"/>
+                       <Tool
+                               Name="VCLibrarianTool"
+                               OutputFile="release\dspam.lib"
+                               SuppressStartupBanner="TRUE"/>
+                       <Tool
+                               Name="VCMIDLTool"/>
+                       <Tool
+                               Name="VCPostBuildEventTool"/>
+                       <Tool
+                               Name="VCPreBuildEventTool"/>
+                       <Tool
+                               Name="VCPreLinkEventTool"/>
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                               PreprocessorDefinitions="NDEBUG"
+                               Culture="1033"/>
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"/>
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"/>
+                       <Tool
+                               Name="VCManagedWrapperGeneratorTool"/>
+                       <Tool
+                               Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+               </Configuration>
+               <Configuration
+                       Name="Debug Purify|Win32"
+                       OutputDirectory="debugpurify"
+                       IntermediateDirectory="debugpurify"
+                       ConfigurationType="4"
+                       UseOfMFC="0"
+                       ATLMinimizesCRunTimeLibraryUsage="FALSE"
+                       CharacterSet="2">
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="0"
+                               AdditionalIncludeDirectories="src"
+                               PreprocessorDefinitions="HAVE_CONFIG_H;_DEBUG"
+                               ExceptionHandling="FALSE"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="3"
+                               UsePrecompiledHeader="0"
+                               PrecompiledHeaderFile="debug\dspam.pch"
+                               WarningLevel="4"
+                               SuppressStartupBanner="TRUE"
+                               DebugInformationFormat="3"
+                               CompileAs="1"/>
+                       <Tool
+                               Name="VCCustomBuildTool"/>
+                       <Tool
+                               Name="VCLibrarianTool"
+                               OutputFile="debugpurify\dspam.lib"
+                               SuppressStartupBanner="TRUE"/>
+                       <Tool
+                               Name="VCMIDLTool"/>
+                       <Tool
+                               Name="VCPostBuildEventTool"/>
+                       <Tool
+                               Name="VCPreBuildEventTool"/>
+                       <Tool
+                               Name="VCPreLinkEventTool"/>
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                               PreprocessorDefinitions="_DEBUG"
+                               Culture="1033"/>
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"/>
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"/>
+                       <Tool
+                               Name="VCManagedWrapperGeneratorTool"/>
+                       <Tool
+                               Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+               </Configuration>
+       </Configurations>
+       <References>
+       </References>
+       <Files>
+               <Filter
+                       Name="Source Files"
+                       Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
+                       <File
+                               RelativePath="src\base64.c">
+                       </File>
+                       <File
+                               RelativePath="src\bnr.c">
+                       </File>
+                       <File
+                               RelativePath="src\buffer.c">
+                       </File>
+                       <File
+                               RelativePath="src\config_shared.c">
+                       </File>
+                       <File
+                               RelativePath="src\decode.c">
+                       </File>
+                       <File
+                               RelativePath=".\src\diction.c">
+                       </File>
+                       <File
+                               RelativePath="src\error.c">
+                       </File>
+                       <File
+                               RelativePath=".\src\hash.c">
+                       </File>
+                       <File
+                               RelativePath=".\src\hash_drv.c">
+                       </File>
+                       <File
+                               RelativePath=".\src\heap.c">
+                       </File>
+                       <File
+                               RelativePath="src\libdspam.c">
+                       </File>
+                       <File
+                               RelativePath=".\src\list.c">
+                       </File>
+                       <File
+                               RelativePath="src\nodetree.c">
+                       </File>
+                       <File
+                               RelativePath="src\pref.c">
+                       </File>
+                       <File
+                               RelativePath="src\read_config.c">
+                       </File>
+                       <File
+                               RelativePath=".\src\tokenizer.c">
+                       </File>
+                       <File
+                               RelativePath="src\util.c">
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Header Files"
+                       Filter="h;hpp;hxx;hm;inl">
+                       <File
+                               RelativePath="src\auto-config.h">
+                       </File>
+                       <File
+                               RelativePath="src\buffer.h">
+                       </File>
+                       <File
+                               RelativePath="src\decode.h">
+                       </File>
+                       <File
+                               RelativePath="src\error.h">
+                       </File>
+                       <File
+                               RelativePath="src\lht.h">
+                       </File>
+                       <File
+                               RelativePath="src\libdspam.h">
+                       </File>
+                       <File
+                               RelativePath="src\libdspam_objects.h">
+                       </File>
+                       <File
+                               RelativePath="src\nodetree.h">
+                       </File>
+                       <File
+                               RelativePath="src\storage_driver.h">
+                       </File>
+               </Filter>
+               <File
+                       RelativePath=".\src\auto-config.h.win32">
+                       <FileConfiguration
+                               Name="Debug|Win32">
+                               <Tool
+                                       Name="VCCustomBuildTool"
+                                       Description="Creating auto-config.h"
+                                       CommandLine="copy $(InputPath) 
$(InputDir)\auto-config.h"
+                                       Outputs="$(InputDir)\auto-config.h"/>
+                       </FileConfiguration>
+                       <FileConfiguration
+                               Name="Release|Win32">
+                               <Tool
+                                       Name="VCCustomBuildTool"
+                                       Description="Creating auto-config.h"
+                                       CommandLine="copy $(InputPath) 
$(InputDir)\auto-config.h"
+                                       Outputs="$(InputDir)\auto-config.h"/>
+                       </FileConfiguration>
+                       <FileConfiguration
+                               Name="Debug Purify|Win32">
+                               <Tool
+                                       Name="VCCustomBuildTool"
+                                       Description="Creating auto-config.h"
+                                       CommandLine="copy $(InputPath) 
$(InputDir)\auto-config.h"
+                                       Outputs="$(InputDir)\auto-config.h"/>
+                       </FileConfiguration>
+               </File>
+       </Files>
+       <Globals>
+       </Globals>
+</VisualStudioProject>


Property changes on: trunk/M/lib/dspam/dspam.vcproj
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/M/lib/dspam/src/auto-config.h.win32
===================================================================
--- trunk/M/lib/dspam/src/auto-config.h.win32                           (rev 0)
+++ trunk/M/lib/dspam/src/auto-config.h.win32   2006-12-18 00:05:52 UTC (rev 
7171)
@@ -0,0 +1,38 @@
+/* src/auto-config.h for Win32 systems */
+
+
+#ifndef __auto_config_h
+#define __auto_config_h
+
+#define CONFIG_DEFAULT (_ds_win32_configfile())
+#define LOGDIR  (_ds_win32_dir())
+
+/* Dynamic drivers loading not supported under Windows currently */
+#define STATIC_DRIVER
+
+#ifdef _DEBUG
+  #define DEBUG
+#endif
+
+#if defined(_MSC_VER) && (_MSC_VER < 1400)
+  #undef HAVE_VARIADIC_MACROS
+#endif
+
+#ifdef _MSC_VER
+  #define inline _inline
+  #define snprintf _snprintf
+  #define strcasecmp _stricmp
+  #define strncasecmp _strnicmp
+  #define vsnprintf _vsnprintf
+
+  /*
+     this is a potentially useful warning (about possible loss of data due to
+     implicit conversions between types) but there are too many instances of it
+     in dspam sources currently so disable it to be able to compile at max
+     warning level otherwise
+   */
+  #pragma warning(disable:4244)
+#endif
+
+#endif /* !__auto_config_h */
+


Property changes on: trunk/M/lib/dspam/src/auto-config.h.win32
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: trunk/M/lib/dspam/src/base64.c
===================================================================
--- trunk/M/lib/dspam/src/base64.c      2006-12-17 23:59:05 UTC (rev 7170)
+++ trunk/M/lib/dspam/src/base64.c      2006-12-18 00:05:52 UTC (rev 7171)
@@ -40,7 +40,7 @@
 char *
 base64decode (const char *buf)
 {
-  unsigned char alphabet[64] =
+  unsigned char alphabet[] =
     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
   static char first_time = 1,inalphabet[256], decoder[256];
   int i, bits, c, char_count, errors = 0;
@@ -130,7 +130,7 @@
 char *
 base64encode (const char *buf)
 {
-  unsigned char alphabet[64] =
+  unsigned char alphabet[] =
     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
   int cols, bits, c, char_count;
   char *out;

Modified: trunk/M/lib/dspam/src/bnr.c
===================================================================
--- trunk/M/lib/dspam/src/bnr.c 2006-12-17 23:59:05 UTC (rev 7170)
+++ trunk/M/lib/dspam/src/bnr.c 2006-12-18 00:05:52 UTC (rev 7171)
@@ -68,7 +68,7 @@
   BTX->identifier  = identifier;
   BTX->window_size = 3;
   BTX->ex_radius   = 0.25;
-  BTX->in_radius   = 0.33;
+  BTX->in_radius   = 0.33f;
   BTX->stream     = bnr_list_create(type);
   BTX->patterns   = bnr_hash_create(1543ul);
   if (BTX->stream == NULL || BTX->patterns == NULL) {
@@ -120,7 +120,7 @@
 
 int bnr_instantiate(BNR_CTX *BTX) {
   int BNR_SIZE = BTX->window_size;
-  float previous_bnr_probs[BNR_SIZE];
+  float *previous_bnr_probs = malloc(BNR_SIZE*sizeof(float));
   struct bnr_list_node *node_list;
   struct bnr_list_c c_list;
   char bnr_token[64];
@@ -152,6 +152,8 @@
     node_list = c_bnr_list_next(BTX->stream, &c_list);
   }
 
+  free(previous_bnr_probs);
+
   return 0;
 }
 
@@ -256,8 +258,9 @@
 
 int bnr_finalize(BNR_CTX *BTX) {
   int BNR_SIZE = BTX->window_size;
-  struct bnr_list_node * previous_bnr_tokens[BNR_SIZE];
-  float previous_bnr_probs[BNR_SIZE];
+  struct bnr_list_node **
+    previous_bnr_tokens = malloc(BNR_SIZE*sizeof(struct bnr_list_node *));
+  float *previous_bnr_probs = malloc(BNR_SIZE*sizeof(float));
   struct bnr_list_node *node_list;
   struct bnr_list_c c_list;
   char bnr_token[64];
@@ -321,6 +324,9 @@
     node_list = c_bnr_list_next(BTX->stream, &c_list);
   }
 
+  free(previous_bnr_probs);
+  free(previous_bnr_tokens);
+
   return 0;
 }
 

Modified: trunk/M/lib/dspam/src/diction.c
===================================================================
--- trunk/M/lib/dspam/src/diction.c     2006-12-17 23:59:05 UTC (rev 7170)
+++ trunk/M/lib/dspam/src/diction.c     2006-12-18 00:05:52 UTC (rev 7171)
@@ -157,7 +157,7 @@
   const char *name, 
   int flags)
 {
-  unsigned long bucket = key % diction->size;
+  unsigned long long bucket = key % diction->size;
   ds_term_t parent = NULL;
   ds_term_t insert = NULL;
   ds_term_t term;
@@ -202,7 +202,7 @@
 void
 ds_diction_delete(ds_diction_t diction, ds_key_t key)
 {
-  unsigned long bucket = key % diction->size;
+  unsigned long long bucket = key % diction->size;
   ds_term_t parent = NULL;
   ds_term_t delete = NULL;
   ds_term_t term;

Modified: trunk/M/lib/dspam/src/error.h
===================================================================
--- trunk/M/lib/dspam/src/error.h       2006-12-17 23:59:05 UTC (rev 7170)
+++ trunk/M/lib/dspam/src/error.h       2006-12-18 00:05:52 UTC (rev 7171)
@@ -45,14 +45,22 @@
 #endif
 
 #ifndef DEBUG
+#ifdef HAVE_VARIADIC_MACROS
 #define LOGDEBUG( ... );
 #else
+inline void LOGDEBUG (const char *err, ...) { }
+#endif
+#else
 void LOGDEBUG (const char *err, ... );
 #endif
 
 #ifdef _WIN32
+#ifdef HAVE_VARIADIC_MACROS
 #define LOG ( ... );
 #else
+inline void LOG (int priority, const char *err, ... ) { priority; err; }
+#endif
+#else
 void LOG (int priority, const char *err, ... );
 #endif
 

Modified: trunk/M/lib/dspam/src/hash_drv.c
===================================================================
--- trunk/M/lib/dspam/src/hash_drv.c    2006-12-17 23:59:05 UTC (rev 7170)
+++ trunk/M/lib/dspam/src/hash_drv.c    2006-12-18 00:05:52 UTC (rev 7171)
@@ -40,11 +40,13 @@
 
 #include <string.h>
 #include <sys/types.h>
+#include <sys/stat.h>
+#ifndef _WIN32
 #include <sys/mman.h>
-#include <sys/stat.h>
 #include <sys/uio.h>
 #include <dirent.h>
 #include <unistd.h>
+#endif
 #include <errno.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -62,6 +64,23 @@
 #   endif
 #endif
 
+#ifdef _WIN32
+#   include <winsock2.h>
+#   include <windows.h>
+#   include <io.h>
+#   include <process.h>
+
+#   define close _close
+#   define getpid _getpid
+#   define lseek _lseek
+#   define open _open
+#   define stat _stat
+#   define write _write
+
+#   define O_RDWR _O_RDWR
+#   define MAP_FAILED NULL
+#endif
+
 #include "storage_driver.h"
 #include "config_shared.h"
 #include "hash_drv.h"
@@ -244,6 +263,8 @@
       }
     }
   }
+#else
+  DTX; /* unused parameter */
 #endif
 
   return 0;
@@ -305,9 +326,11 @@
   int flags) 
 {
   struct _hash_drv_header header;
+#ifdef _WIN32
+  HANDLE hMapping;
+#endif
+
   int open_flags = O_RDWR;
-  int mmap_flags = PROT_READ + PROT_WRITE;
-
   map->fd = open(filename, open_flags);
 
   /*
@@ -319,7 +342,7 @@
   if (map->fd < 0 && recmaxifnew) {
     FILE *f;
     struct _hash_drv_spam_record rec;
-    int i;
+    unsigned i;
 
     memset(&header, 0, sizeof(struct _hash_drv_header));
     memset(&rec, 0, sizeof(struct _hash_drv_spam_record));
@@ -355,7 +378,19 @@
   read(map->fd, map->header, sizeof(struct _hash_drv_header));
   map->file_len = lseek(map->fd, 0, SEEK_END); 
 
-  map->addr = mmap(NULL, map->file_len, mmap_flags, MAP_SHARED, map->fd, 0);
+#ifndef _WIN32
+  map->addr = mmap(NULL, map->file_len, PROT_READ | PROT_WRITE,
+                   MAP_SHARED, map->fd, 0);
+#else /* _WIN32 */
+  hMapping = CreateFileMapping((HANDLE)_get_osfhandle(map->fd), NULL,
+                               PAGE_READWRITE, 0, 0, NULL);
+  map->addr = MapViewOfFile(hMapping, FILE_MAP_WRITE, 0, 0, 0);
+
+  /* we can close this handle immediately because the mapping created by
+   * MapViewOfFile() uses it too so the file mapping will continue to exist
+   * until we call UnmapViewOfFile() later */
+  CloseHandle(hMapping);
+#endif /* !_WIN32/_WIN32 */
   if (map->addr == MAP_FAILED) {
     free(map->header);
     close(map->fd);
@@ -383,10 +418,19 @@
 
   memcpy(&header, map->header, sizeof(struct _hash_drv_header));
 
+#ifndef _WIN32
   r = munmap(map->addr, map->file_len);
   if (r) {
     LOG(LOG_WARNING, "munmap failed on error %d: %s", r, strerror(errno));
   }
+#else /* _WIN32 */
+  if ( !UnmapViewOfFile(map->addr) ) {
+    LOG(LOG_WARNING, "UnmapViewOfFile failed with error %lu", GetLastError());
+    r = -1;
+  }
+  else
+    r = 0;
+#endif /* !_WIN32/_WIN32 */
  
   lseek (map->fd, 0, SEEK_SET);
   write (map->fd, &header, sizeof(struct _hash_drv_header));
@@ -525,8 +569,10 @@
 _ds_shutdown_storage (DSPAM_CTX * CTX)
 {
   struct _hash_drv_storage *s;
+#ifndef _WIN32
   struct nt_node *node_nt;
   struct nt_c c_nt;
+#endif
   int lock_result;
 
   if (!CTX || !CTX->storage)
@@ -536,6 +582,8 @@
 
   /* Close open file handles to directories (iteration functions) */
 
+  /* FIXME-WIN32: this code is currently unused and doesn't compile */
+#ifndef _WIN32
   node_nt = c_nt_first (s->dir_handles, &c_nt);
   while (node_nt != NULL)
   {
@@ -544,6 +592,7 @@
     closedir (dir);
     node_nt = c_nt_next (s->dir_handles, &c_nt);
   }
+#endif /* _WIN32 */
   nt_destroy (s->dir_handles);
 
   if (CTX->operating_mode != DSM_CLASSIFY)
@@ -785,6 +834,7 @@
 
 void *_ds_connect (DSPAM_CTX *CTX)
 {
+  CTX; /* unused parameter */
   return NULL;
 }
 
@@ -795,6 +845,8 @@
   char digit[6];
   int pid, j;
  
+  CTX; /* unused parameter */
+
   pid = getpid ();
   snprintf (session, sizeof (session), "%8lx%d", (long) time (NULL), pid);
  
@@ -835,7 +887,7 @@
   struct _hash_drv_storage *s = (struct _hash_drv_storage *) CTX->storage;
   struct _hash_drv_spam_record rec;
   struct _ds_storage_record *sr;
-  struct _ds_spam_stat stat;
+  struct _ds_spam_stat stat = { 0 };
 
   rec.hashcode = 0;
 
@@ -846,7 +898,7 @@
   }
 
   if (s->offset_nexttoken == 0) {
-    s->offset_header = s->map->addr;
+    s->offset_header = (hash_drv_header_t)s->map->addr;
     s->offset_nexttoken = sizeof(struct _hash_drv_header);
     memcpy(&rec,
            s->map->addr+s->offset_nexttoken, 
@@ -867,8 +919,8 @@
       (s->offset_header->hash_rec_max * sizeof(struct _hash_drv_spam_record)))
     { 
       if (s->offset_nexttoken < s->map->file_len) {
-        s->offset_header = s->map->addr + 
-          (s->offset_nexttoken - sizeof(struct _hash_drv_spam_record));
+        s->offset_header = (hash_drv_header_t)(s->map->addr + 
+          (s->offset_nexttoken - sizeof(struct _hash_drv_spam_record)));
 
         s->offset_nexttoken += sizeof(struct _hash_drv_header);
         s->offset_nexttoken -= sizeof(struct _hash_drv_spam_record);
@@ -907,6 +959,8 @@
   return unlink(filename);
 }
 
+/* FIXME-WIN32: this code doesn't compile currently but it's only for tools */
+#ifndef _WIN32
 char * 
 _ds_get_nextuser (DSPAM_CTX * CTX) 
 {
@@ -1021,16 +1075,19 @@
   user[0] = 0;
   return NULL;
 }
+#endif /* _WIN32 */
 
 struct _ds_storage_signature *
 _ds_get_nextsignature (DSPAM_CTX * CTX)
 {
+  CTX; /* unused parameter */
   return NULL;
 }
 
 int
 _ds_delall_spamrecords (DSPAM_CTX * CTX, ds_diction_t diction)
 {
+  CTX; diction; /* unused parameter */
   return 0;
 }
 
@@ -1041,7 +1098,7 @@
 {
   struct _hash_drv_header header;
   struct _hash_drv_spam_record rec;
-  int i;
+  unsigned i;
 
   _hash_drv_close(map);
 
@@ -1079,7 +1136,7 @@
   unsigned long long hashcode,
   int flags)
 {
-  hash_drv_header_t header = map->addr + offset;
+  hash_drv_header_t header = (hash_drv_header_t)(map->addr + offset);
   hash_drv_spam_record_t rec;
   unsigned long long fpos;
   unsigned long iterations = 0;
@@ -1090,7 +1147,7 @@
   fpos = sizeof(struct _hash_drv_header) + 
     ((hashcode % header->hash_rec_max) * sizeof(struct _hash_drv_spam_record));
 
-  rec = map->addr + offset + fpos;
+  rec = (hash_drv_spam_record_t)(map->addr + offset + fpos);
   while(rec->hashcode != hashcode  &&   /* Match token     */ 
         rec->hashcode != 0         &&   /* Insert on empty */
         iterations < map->max_seek)     /* Max Iterations  */
@@ -1100,7 +1157,7 @@
 
     if (fpos >= (header->hash_rec_max * sizeof(struct _hash_drv_spam_record)))
       fpos = sizeof(struct _hash_drv_header);
-    rec = map->addr + offset + fpos;
+    rec = (hash_drv_spam_record_t)(map->addr + offset + fpos);
   }     
 
   if (rec->hashcode == hashcode) 
@@ -1125,13 +1182,13 @@
     return EINVAL;
 
   if (map_offset) {
-    rec = map->addr + map_offset;
+    rec = (hash_drv_spam_record_t)(map->addr + map_offset);
   } else {
     while(rec_offset <= 0 && offset < map->file_len)
     {
       rec_offset = _hash_drv_seek(map, offset, wrec->hashcode, HSEEK_INSERT);
       if (rec_offset <= 0) {
-        hash_drv_header_t header = map->addr + offset;
+        hash_drv_header_t header = (hash_drv_header_t)(map->addr + offset);
         offset += sizeof(struct _hash_drv_header) +
           (sizeof(struct _hash_drv_spam_record) * header->hash_rec_max);
         last_extent_size = header->hash_rec_max;
@@ -1153,7 +1210,7 @@
       }
     }
   
-    rec = map->addr + offset + rec_offset;
+    rec = (hash_drv_spam_record_t)(map->addr + offset + rec_offset);
   }
   rec->hashcode = wrec->hashcode;
   rec->nonspam  = wrec->nonspam;
@@ -1181,7 +1238,7 @@
   {
     rec_offset = _hash_drv_seek(map, offset, wrec->hashcode, 0);
     if (rec_offset <= 0) {
-      hash_drv_header_t header = map->addr + offset;
+      hash_drv_header_t header = (hash_drv_header_t)(map->addr + offset);
       offset += sizeof(struct _hash_drv_header) +
         (sizeof(struct _hash_drv_spam_record) * header->hash_rec_max);
       extents++;
@@ -1192,7 +1249,7 @@
     return 0;
 
   offset += rec_offset;
-  rec = map->addr + offset;
+  rec = (hash_drv_spam_record_t)(map->addr + offset);
   
   wrec->nonspam  = rec->nonspam;
   wrec->spam     = rec->spam;

Modified: trunk/M/lib/dspam/src/hash_drv.h
===================================================================
--- trunk/M/lib/dspam/src/hash_drv.h    2006-12-17 23:59:05 UTC (rev 7170)
+++ trunk/M/lib/dspam/src/hash_drv.h    2006-12-18 00:05:52 UTC (rev 7171)
@@ -44,7 +44,7 @@
 
 typedef struct _hash_drv_map
 {
-  void *addr;
+  char *addr;
   int fd;
   size_t file_len;
   hash_drv_header_t header;

Modified: trunk/M/lib/dspam/src/heap.c
===================================================================
--- trunk/M/lib/dspam/src/heap.c        2006-12-17 23:59:05 UTC (rev 7170)
+++ trunk/M/lib/dspam/src/heap.c        2006-12-18 00:05:52 UTC (rev 7171)
@@ -28,6 +28,10 @@
  *   is a small window-size of 'peak' values, such as the 15 bayes slots.
  */
 
+#ifdef HAVE_CONFIG_H
+#include <auto-config.h>
+#endif
+
 #include <stdlib.h>
 #include <math.h>
 #include "heap.h"

Modified: trunk/M/lib/dspam/src/libdspam.c
===================================================================
--- trunk/M/lib/dspam/src/libdspam.c    2006-12-17 23:59:05 UTC (rev 7170)
+++ trunk/M/lib/dspam/src/libdspam.c    2006-12-18 00:05:52 UTC (rev 7171)
@@ -49,7 +49,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#ifndef _WIN32
 #include <dlfcn.h>
+#endif
 
 #ifdef TIME_WITH_SYS_TIME
 #   include <sys/time.h>
@@ -90,8 +92,14 @@
 
 #ifdef DEBUG
 int DO_DEBUG = 0;
+
+/* TODO-WIN32: timings debugging code currently doesn't compile */
+#ifndef _WIN32
+#define DEBUG_TIMINGS
 #endif
 
+#endif
+
 #ifdef NCORE
 nc_dev_t g_ncDevice;
 
@@ -452,14 +460,14 @@
 int
 dspam_process (DSPAM_CTX * CTX, const char *message)
 {
-#ifdef DEBUG
+#ifdef DEBUG_TIMINGS
   struct timeval tp1, tp2;
   struct timezone tzp;
 #endif
   buffer *header, *body;
   int spam_result = 0, is_toe = 0, is_undertrain = 0;
 
-#ifdef DEBUG
+#ifdef DEBUG_TIMINGS
   if (DO_DEBUG)
     gettimeofday(&tp1, &tzp);
 #endif
@@ -604,7 +612,7 @@
   if (is_undertrain)
     CTX->training_mode = DST_TOE;
 
-#ifdef DEBUG
+#ifdef DEBUG_TIMINGS
   if (DO_DEBUG) {
     if (CTX->source == DSS_NONE) {
       gettimeofday(&tp2, &tzp);
@@ -1547,9 +1555,10 @@
 int
 _ds_calc_result(DSPAM_CTX *CTX, ds_heap_t heap_sort, ds_diction_t diction)
 {
-  struct _ds_spam_stat stat;
+  struct _ds_spam_stat stat = { 0. };
   ds_heap_element_t node_heap;
-  ds_heap_element_t heap_list[heap_sort->items];
+  ds_heap_element_t *
+    heap_list = malloc(heap_sort->items*sizeof(ds_heap_element_t));
 
   /* Naive-Bayesian */
   float nbay_top = 0.0;
@@ -1585,7 +1594,7 @@
   long chi_used  = 0, chi_sx = 0, chi_hx = 0;
   double chi_s = 1.0, chi_h = 1.0;
   struct nt *factor_chi = nt_create(NT_PTR);
-  int i;
+  unsigned i;
 
   /* Invert the heap */
   node_heap = heap_sort->root;
@@ -1759,6 +1768,8 @@
     }
   }
 
+  free(heap_list);
+
   /* END Combine Token Values */
 
   /* Fisher-Robinson's Inverse Chi-Square */
@@ -2147,6 +2158,8 @@
       return EFAILURE;
     }
   }
+#else
+  driver; /* unused parameter */
 #endif
 
 #ifdef NCORE

Modified: trunk/M/lib/dspam/src/pref.c
===================================================================
--- trunk/M/lib/dspam/src/pref.c        2006-12-17 23:59:05 UTC (rev 7170)
+++ trunk/M/lib/dspam/src/pref.c        2006-12-18 00:05:52 UTC (rev 7171)
@@ -170,6 +170,8 @@
   char *p, *q, *bufptr;
   int i = 0;
 
+  config; ignore; /* unused parameters */
+
   if (PTX == NULL) {
     LOG(LOG_CRIT, ERR_MEM_ALLOC);
     return NULL;
@@ -306,6 +308,8 @@
   char filename[MAX_FILENAME_LENGTH];
   FILE *out_file;
 
+  config; ignore; /* unused parameters */
+
   if (username == NULL) {
     snprintf(filename, MAX_FILENAME_LENGTH, "%s/default.prefs", home);
   } else {
@@ -333,6 +337,8 @@
   FILE *out_file;
   int nlines; 
 
+  config; ignore; /* unused parameters */
+
   if (username == NULL) {
     snprintf(filename, MAX_FILENAME_LENGTH, "%s/default.prefs", home);
   } else {

Modified: trunk/M/lib/dspam/src/read_config.c
===================================================================
--- trunk/M/lib/dspam/src/read_config.c 2006-12-17 23:59:05 UTC (rev 7170)
+++ trunk/M/lib/dspam/src/read_config.c 2006-12-18 00:05:52 UTC (rev 7171)
@@ -122,11 +122,15 @@
     chomp(buffer);
 
     /* Remove comments */
-    if ((c = strchr(buffer, '#')) || (c = strchr(buffer, ';')))
+    c = strchr(buffer, '#');
+    if (!c)
+      c = strchr(buffer, ';');
+    if (c)
       *c = 0;
 
     /* Parse attribute name */
-    if (!(a = tokenize(buffer, &bufptr)))
+    a = tokenize(buffer, &bufptr);
+    if (!a)
       continue; /* Ignore whitespace-only lines */
 
     while ((v = tokenize(NULL, &bufptr)) != NULL) {

Modified: trunk/M/lib/dspam/src/storage_driver.h
===================================================================
--- trunk/M/lib/dspam/src/storage_driver.h      2006-12-17 23:59:05 UTC (rev 
7170)
+++ trunk/M/lib/dspam/src/storage_driver.h      2006-12-18 00:05:52 UTC (rev 
7171)
@@ -186,7 +186,13 @@
 #define DRS_OFFLINE    0x02
 #define DRS_UNKNOWN    0xFF
 
-#define CONTROL_TOKEN  11624422384514212933llu
+#ifdef _MSC_VER
+  #define ULL_CONST(x)  x ## ui64
+#else
+  #define ULL_CONST(x)  x ## llu
+#endif
+
+#define CONTROL_TOKEN  ULL_CONST(11624422384514212933)
                        /* $$CONTROL$$ */
 
 #endif /* _STORAGE_DRIVER_H */

Modified: trunk/M/lib/dspam/src/tokenizer.c
===================================================================
--- trunk/M/lib/dspam/src/tokenizer.c   2006-12-17 23:59:05 UTC (rev 7170)
+++ trunk/M/lib/dspam/src/tokenizer.c   2006-12-18 00:05:52 UTC (rev 7171)
@@ -528,8 +528,8 @@
                       char **previous_tokens, ds_diction_t diction,
                       const char *heading, const char *bitpattern)
 {
-  int i, t, keylen, breadth;
-  u_int32_t mask;
+  int i, t, keylen;
+  u_int32_t mask, breadth;
   unsigned long long crc;
   char key[256];
   int active = 0, top, tokenizer = CTX->tokenizer;
@@ -633,12 +633,12 @@
   ds_diction_t diction, 
   const char *bitpattern)
 {
-  int i, t, keylen, breadth;
+  int i, t, keylen;
   int top, tokenizer = CTX->tokenizer;
   unsigned long long crc;
   char key[256];
   int active = 0;
-  u_int32_t mask;
+  u_int32_t mask, breadth;
 
   /* Shift all previous tokens up */
   for(i=0;i<SPARSE_WINDOW_SIZE-1;i++) {
@@ -1052,7 +1052,7 @@
 
   bitpattern = malloc(SPARSE_WINDOW_SIZE * breadth);
 
-  for(mask=0;mask<breadth;mask++) {
+  for(mask=0;mask<(unsigned long)breadth;mask++) {
       for(i=0;i<SPARSE_WINDOW_SIZE;i++) {
           exp = (i) ? _ds_pow2(i) : 1;
           /* Reverse pos = SPARSE_WINDOW_SIZE - (i+1); */

Modified: trunk/M/lib/dspam/src/util.c
===================================================================
--- trunk/M/lib/dspam/src/util.c        2006-12-17 23:59:05 UTC (rev 7170)
+++ trunk/M/lib/dspam/src/util.c        2006-12-18 00:05:52 UTC (rev 7171)
@@ -58,6 +58,7 @@
 #include "libdspam.h"
 
 #ifdef _WIN32
+    #include <winsock.h>
     #include <direct.h>
 
     #define mkdir(filename, perm) _mkdir(filename)
@@ -175,10 +176,7 @@
  * If retval >= siz, truncation occurred.
  */
 size_t
-strlcat (dst, src, siz)
-     char *dst;
-     const char *src;
-     size_t siz;
+strlcat (char *dst, const char *src, size_t siz)
 {
   register char *d = dst;
   register const char *s = src;
@@ -213,10 +211,7 @@
  * Returns strlen(src); if retval >= siz, truncation occurred.
  */
 size_t
-strlcpy (dst, src, siz)
-     char *dst;
-     const char *src;
-     size_t siz;
+strlcpy (char *dst, const char *src, size_t siz)
 {
   register char *d = dst;
   register const char *s = src;
@@ -631,6 +626,8 @@
 
 int _ds_get_fcntl_lock(int fd) {
 #ifdef _WIN32
+  fd;
+
   return 0;
 #else
   struct flock f;
@@ -646,6 +643,8 @@
 
 int _ds_free_fcntl_lock(int fd) {
 #ifdef _WIN32
+  fd;
+
   return 0;
 #else
   struct flock f;
@@ -677,8 +676,7 @@
 
 #ifndef HAVE_STRCASESTR
 char *
-strcasestr(s, find)
-       const char *s, *find;
+strcasestr(const char *s, const char *find)
 {
        char c, sc;
        size_t len;
@@ -743,7 +741,7 @@
   snprintf(b, sizeof(b),
   "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));
 
-  if (len <= strlen(b)) {
+  if (len <= (int)strlen(b)) {
     errno = ERANGE;
     return(NULL);
   }
@@ -751,3 +749,44 @@
   return strcpy(buf, b);
 }
 #endif
+
+#ifdef _WIN32
+
+const char *_ds_win32_configfile()
+{
+  static char s_dspamConfig[MAX_FILENAME_LENGTH];
+
+  if ( !*s_dspamConfig ) {
+    snprintf(s_dspamConfig, sizeof(s_dspamConfig) - 1,
+             "%s/dspam.conf", _ds_win32_dir());
+    s_dspamConfig[sizeof(s_dspamConfig) - 1] = '\0';
+  }
+
+  return s_dspamConfig;
+}
+
+const char *_ds_win32_dir()
+{
+  static char s_dspamDir[MAX_FILENAME_LENGTH];
+
+  if ( !*s_dspamDir ) {
+    /*
+       We should normally use SHGetFolderLocation() for this but it doesn't
+       exist on all Win32 systems and loading it dynamically is painful.
+       SHGetSpecialFolderLocation() does exist everywhere but we need to
+       initialize OLE and use IMalloc to free its return value which is quite
+       painful too. So just use the standard environment variables instead.
+     */
+    const char *home = getenv("USERPROFILE");
+    if ( !home )
+      home = getenv("HOME");
+    if ( !home )
+      home = "c:"; /* have to fall back on something... */
+
+    strlcpy(s_dspamDir, home, sizeof(s_dspamDir));
+  }
+
+  return s_dspamDir;
+}
+
+#endif /* _WIN32 */

Modified: trunk/M/lib/dspam/src/util.h
===================================================================
--- trunk/M/lib/dspam/src/util.h        2006-12-17 23:59:05 UTC (rev 7170)
+++ trunk/M/lib/dspam/src/util.h        2006-12-18 00:05:52 UTC (rev 7171)
@@ -28,13 +28,15 @@
 #endif
 
 #include <sys/types.h>
+
+#ifndef _WIN32
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-
-#ifndef _WIN32
 #include <pwd.h>
-#endif
+#else /* _WIN32 */
+#include <winsock2.h>
+#endif /* !_WIN32/_WIN32 */
 
 void   chomp   (char *string);
 char * ltrim   (char *str);
@@ -121,4 +123,19 @@
 float _ds_round
   (float n);
 
+#ifdef _WIN32
+
+/*
+ * Win32 support functions:
+ *
+ *   _ds_win32_dir() returns the directory for DSPAM data/config files
+ *
+ *   _ds_win32_configfile() returns the default config file name
+ */
+
+const char *_ds_win32_configfile();
+const char *_ds_win32_dir();
+
+#endif /* _WIN32 */
+
 #endif /* _UTIL_H */


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to