Update of /cvsroot/mahogany/M/lib/dspam
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19169/lib/dspam
Modified Files:
Makefile.M config.h util.c
Log Message:
made dspam_set/get_home() available under Unix as well (and not only Win32)
Index: Makefile.M
===================================================================
RCS file: /cvsroot/mahogany/M/lib/dspam/Makefile.M,v
retrieving revision 1.2
retrieving revision 1.3
diff -b -u -2 -r1.2 -r1.3
--- Makefile.M 12 Jul 2004 17:23:14 -0000 1.2
+++ Makefile.M 12 Jul 2004 18:51:20 -0000 1.3
@@ -13,5 +13,5 @@
include ../../makeopts
-CPPFLAGS+=-DHAVE_CONFIG_H -DDSPAM_HOME="\"\"" -I. -I.src
+CPPFLAGS+=-DHAVE_CONFIG_H -DDSPAM_HOME_NO_DATA -I. -I.src
OBJECTS=\
Index: config.h
===================================================================
RCS file: /cvsroot/mahogany/M/lib/dspam/config.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -b -u -2 -r1.5 -r1.6
--- config.h 10 Jul 2004 16:01:18 -0000 1.5
+++ config.h 12 Jul 2004 18:51:20 -0000 1.6
@@ -89,13 +89,18 @@
* Default location of data directories.
*
- * Define below is fallback only and should be never used under the
- * normal conditions.
+ * If it is not defined, dspam_get_home() return value is used (which can be
+ * set using dspam_set_home())
*
* Use --with-userdir configure option for tune this parameter.
*/
#ifndef DSPAM_HOME
-# warning DSPAM_HOME is not defined by configure/Makefile.
-# warning Fallback to hardcoded defaults.
-# define DSPAM_HOME "/var/dspam"
+/*
+ Functions to set/get the value of DSPAM_HOME (unless it had been hard coded
+ */
+extern void dspam_set_home(const char *home);
+extern const char *dspam_get_home(void);
+
+#define DSPAM_HOME_DYNAMIC
+#define DSPAM_HOME (dspam_get_home())
#endif
Index: util.c
===================================================================
RCS file: /cvsroot/mahogany/M/lib/dspam/util.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -b -u -2 -r1.7 -r1.8
--- util.c 12 Jul 2004 14:13:11 -0000 1.7
+++ util.c 12 Jul 2004 18:51:20 -0000 1.8
@@ -302,4 +302,7 @@
}
}
+#elif defined(DSPAM_HOME_NO_DATA)
+ snprintf (path, MAX_FILENAME_LENGTH, "%s/%s.%s",
+ DSPAM_HOME, userpath, extension);
#else
if (extension == NULL)
@@ -592,2 +595,58 @@
#endif
+
+/*
+ DSPAM_HOME
+ */
+#ifdef DSPAM_HOME_DYNAMIC
+
+static char dspam_home[MAX_FILENAME_LENGTH];
+
+void dspam_set_home(const char *home)
+{
+ strlcpy(dspam_home, home, sizeof(dspam_home));
+}
+
+const char *dspam_get_home(void)
+{
+ /* check if we have a valid home */
+ if ( !dspam_home[0] )
+ {
+ /*
+ determine it ourselves if we don't: note that the proper way to do this
+ would be by using SHGetFolderPath() but this function is not available on
+ earlier Windows systems and so we'd have to load it dynamically from
+ shell32.dll which is slightly painful, so let those who really want to do
+ it call our dspam_set_home() themselves instead and use the easy way here
+ */
+ const char *home = getenv("DSPAM_HOME");
+ if ( !home )
+ home = getenv("HOME");
+ if ( !home )
+ {
+#ifdef _WIN32
+ const char *homedrive = getenv("HOMEDRIVE");
+ const char *homepath = getenv("HOMEPATH");
+ if ( homedrive && homepath )
+ {
+ strlcpy(dspam_home, homedrive, sizeof(dspam_home));
+ strlcat(dspam_home, homepath, sizeof(dspam_home));
+ }
+ else
+ {
+ /* what else can we do? */
+ home = "C:\\dspam";
+ }
+#else /* !_WIN32 */
+ home = "/var/dspam";
+#endif /* _WIN32/!_WIN32 */
+ }
+
+ dspam_set_home(home);
+ }
+
+ return dspam_home;
+}
+
+#endif /* DSPAM_HOME_DYNAMIC */
+
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates