Browse code

shared/misc.c: re-enable freshdbdir()

git-svn: trunk@4590

Tomasz Kojm authored on 2009/01/03 06:45:46
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri Jan  2 23:00:52 CET 2009 (tk)
2
+---------------------------------
3
+ * shared/misc.c: re-enable freshdbdir()
4
+
1 5
 Fri Jan  2 18:16:45 CET 2009 (tk)
2 6
 ---------------------------------
3 7
  * shared, clamconf: drop old stuff; replace getopt.[ch] with my_getopt
... ...
@@ -36,7 +36,7 @@
36 36
 #include <ctype.h>
37 37
 #include <errno.h>
38 38
 
39
-/* #include "shared/cfgparser.h" */
39
+#include "shared/optparser.h"
40 40
 #include "shared/output.h"
41 41
 
42 42
 #include "libclamav/clamav.h"
... ...
@@ -66,25 +66,22 @@ const char *get_version(void)
66 66
 #ifndef CL_NOLIBCLAMAV
67 67
 char *freshdbdir(void)
68 68
 {
69
-/* FIXME
70 69
 	struct cl_cvd *d1, *d2;
71
-	struct cfgstruct *copt;
72
-	const struct cfgstruct *cpt;
73
-*/
70
+	struct optstruct *opts;
71
+	const struct optstruct *opt;
74 72
 	const char *dbdir;
75 73
 	char *retdir;
76 74
 
77 75
 
78
-    /* try to find fresh directory */
76
+    /* try to find the most up-to-date db directory */
79 77
     dbdir = cl_retdbdir();
80
-    /*
81
-    if((copt = getcfg(CONFDIR"/freshclam.conf", 0, OPT_FRESHCLAM))) {
82
-	if((cpt = cfgopt(copt, "DatabaseDirectory"))->enabled || (cpt = cfgopt(copt, "DataDirectory"))->enabled) {
83
-	    if(strcmp(dbdir, cpt->strarg)) {
84
-		    char *daily = (char *) malloc(strlen(cpt->strarg) + strlen(dbdir) + 30);
85
-		sprintf(daily, "%s/daily.cvd", cpt->strarg);
78
+    if((opts = optparse(CONFDIR"/freshclam.conf", 0, NULL, 0, OPT_FRESHCLAM, 0, NULL))) {
79
+	if((opt = optget(opts, "DatabaseDirectory"))->enabled) {
80
+	    if(strcmp(dbdir, opt->strarg)) {
81
+		    char *daily = (char *) malloc(strlen(opt->strarg) + strlen(dbdir) + 30);
82
+		sprintf(daily, "%s/daily.cvd", opt->strarg);
86 83
 		if(access(daily, R_OK))
87
-		    sprintf(daily, "%s/daily.cld", cpt->strarg);
84
+		    sprintf(daily, "%s/daily.cld", opt->strarg);
88 85
 
89 86
 		if(!access(daily, R_OK) && (d1 = cl_cvdhead(daily))) {
90 87
 		    sprintf(daily, "%s/daily.cvd", dbdir);
... ...
@@ -94,11 +91,11 @@ char *freshdbdir(void)
94 94
 		    if(!access(daily, R_OK) && (d2 = cl_cvdhead(daily))) {
95 95
 			free(daily);
96 96
 			if(d1->version > d2->version)
97
-			    dbdir = cpt->strarg;
97
+			    dbdir = opt->strarg;
98 98
 			cl_cvdfree(d2);
99 99
 		    } else {
100 100
 			free(daily);
101
-			dbdir = cpt->strarg;
101
+			dbdir = opt->strarg;
102 102
 		    }
103 103
 		    cl_cvdfree(d1);
104 104
 		} else {
... ...
@@ -107,14 +104,11 @@ char *freshdbdir(void)
107 107
 	    }
108 108
 	}
109 109
     }
110
-    */
111 110
 
112 111
     retdir = strdup(dbdir);
113 112
 
114
-/*
115
-    if(copt)
116
-	freecfg(copt);
117
-*/
113
+    if(opts)
114
+	optfree(opts);
118 115
 
119 116
     return retdir;
120 117
 }