Browse code

shared/optparser.c, freshclam: use the new option parser (bb#1215)

git-svn: trunk@4573

Tomasz Kojm authored on 2008/12/19 04:42:53
Showing 11 changed files
... ...
@@ -1,3 +1,7 @@
1
+Thu Dec 18 20:52:00 CET 2008 (tk)
2
+---------------------------------
3
+ * shared/optparser.c, freshclam: use the new option parser (bb#1215)
4
+
1 5
 Wed Dec 17 22:43:54 CET 2008 (tk)
2 6
 ---------------------------------
3 7
  * shared/optparser.[ch]: initial version of the unified option parser (bb#1215)
... ...
@@ -22,14 +22,12 @@ bin_PROGRAMS = freshclam
22 22
 freshclam_SOURCES = \
23 23
     $(top_srcdir)/shared/output.c \
24 24
     $(top_srcdir)/shared/output.h \
25
-    $(top_srcdir)/shared/cfgparser.c \
26
-    $(top_srcdir)/shared/cfgparser.h \
25
+    $(top_srcdir)/shared/optparser.c \
26
+    $(top_srcdir)/shared/optparser.h \
27 27
     $(top_srcdir)/shared/getopt.c \
28 28
     $(top_srcdir)/shared/getopt.h \
29 29
     $(top_srcdir)/shared/misc.c \
30 30
     $(top_srcdir)/shared/misc.h \
31
-    $(top_srcdir)/shared/options.c \
32
-    $(top_srcdir)/shared/options.h \
33 31
     $(top_srcdir)/shared/sha256.c \
34 32
     $(top_srcdir)/shared/cdiff.c \
35 33
     $(top_srcdir)/shared/cdiff.h \
... ...
@@ -72,12 +72,11 @@ CONFIG_CLEAN_FILES =
72 72
 am__installdirs = "$(DESTDIR)$(bindir)"
73 73
 binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
74 74
 PROGRAMS = $(bin_PROGRAMS)
75
-am_freshclam_OBJECTS = output.$(OBJEXT) cfgparser.$(OBJEXT) \
76
-	getopt.$(OBJEXT) misc.$(OBJEXT) options.$(OBJEXT) \
77
-	sha256.$(OBJEXT) cdiff.$(OBJEXT) tar.$(OBJEXT) \
78
-	freshclam.$(OBJEXT) manager.$(OBJEXT) notify.$(OBJEXT) \
79
-	dns.$(OBJEXT) execute.$(OBJEXT) nonblock.$(OBJEXT) \
80
-	mirman.$(OBJEXT)
75
+am_freshclam_OBJECTS = output.$(OBJEXT) optparser.$(OBJEXT) \
76
+	getopt.$(OBJEXT) misc.$(OBJEXT) sha256.$(OBJEXT) \
77
+	cdiff.$(OBJEXT) tar.$(OBJEXT) freshclam.$(OBJEXT) \
78
+	manager.$(OBJEXT) notify.$(OBJEXT) dns.$(OBJEXT) \
79
+	execute.$(OBJEXT) nonblock.$(OBJEXT) mirman.$(OBJEXT)
81 80
 freshclam_OBJECTS = $(am_freshclam_OBJECTS)
82 81
 freshclam_LDADD = $(LDADD)
83 82
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
... ...
@@ -256,14 +255,12 @@ top_srcdir = @top_srcdir@
256 256
 freshclam_SOURCES = \
257 257
     $(top_srcdir)/shared/output.c \
258 258
     $(top_srcdir)/shared/output.h \
259
-    $(top_srcdir)/shared/cfgparser.c \
260
-    $(top_srcdir)/shared/cfgparser.h \
259
+    $(top_srcdir)/shared/optparser.c \
260
+    $(top_srcdir)/shared/optparser.h \
261 261
     $(top_srcdir)/shared/getopt.c \
262 262
     $(top_srcdir)/shared/getopt.h \
263 263
     $(top_srcdir)/shared/misc.c \
264 264
     $(top_srcdir)/shared/misc.h \
265
-    $(top_srcdir)/shared/options.c \
266
-    $(top_srcdir)/shared/options.h \
267 265
     $(top_srcdir)/shared/sha256.c \
268 266
     $(top_srcdir)/shared/cdiff.c \
269 267
     $(top_srcdir)/shared/cdiff.h \
... ...
@@ -374,7 +371,6 @@ distclean-compile:
374 374
 	-rm -f *.tab.c
375 375
 
376 376
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdiff.Po@am__quote@
377
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cfgparser.Po@am__quote@
378 377
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dns.Po@am__quote@
379 378
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/execute.Po@am__quote@
380 379
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/freshclam.Po@am__quote@
... ...
@@ -384,7 +380,7 @@ distclean-compile:
384 384
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Po@am__quote@
385 385
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nonblock.Po@am__quote@
386 386
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/notify.Po@am__quote@
387
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/options.Po@am__quote@
387
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/optparser.Po@am__quote@
388 388
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/output.Po@am__quote@
389 389
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sha256.Po@am__quote@
390 390
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tar.Po@am__quote@
... ...
@@ -424,19 +420,19 @@ output.obj: $(top_srcdir)/shared/output.c
424 424
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
425 425
 @am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o output.obj `if test -f '$(top_srcdir)/shared/output.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/output.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/output.c'; fi`
426 426
 
427
-cfgparser.o: $(top_srcdir)/shared/cfgparser.c
428
-@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cfgparser.o -MD -MP -MF $(DEPDIR)/cfgparser.Tpo -c -o cfgparser.o `test -f '$(top_srcdir)/shared/cfgparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/cfgparser.c
429
-@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/cfgparser.Tpo $(DEPDIR)/cfgparser.Po
430
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.o' libtool=no @AMDEPBACKSLASH@
427
+optparser.o: $(top_srcdir)/shared/optparser.c
428
+@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT optparser.o -MD -MP -MF $(DEPDIR)/optparser.Tpo -c -o optparser.o `test -f '$(top_srcdir)/shared/optparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/optparser.c
429
+@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/optparser.Tpo $(DEPDIR)/optparser.Po
430
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$(top_srcdir)/shared/optparser.c' object='optparser.o' libtool=no @AMDEPBACKSLASH@
431 431
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
432
-@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.o `test -f '$(top_srcdir)/shared/cfgparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/cfgparser.c
432
+@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o optparser.o `test -f '$(top_srcdir)/shared/optparser.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/optparser.c
433 433
 
434
-cfgparser.obj: $(top_srcdir)/shared/cfgparser.c
435
-@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cfgparser.obj -MD -MP -MF $(DEPDIR)/cfgparser.Tpo -c -o cfgparser.obj `if test -f '$(top_srcdir)/shared/cfgparser.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/cfgparser.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/cfgparser.c'; fi`
436
-@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/cfgparser.Tpo $(DEPDIR)/cfgparser.Po
437
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$(top_srcdir)/shared/cfgparser.c' object='cfgparser.obj' libtool=no @AMDEPBACKSLASH@
434
+optparser.obj: $(top_srcdir)/shared/optparser.c
435
+@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT optparser.obj -MD -MP -MF $(DEPDIR)/optparser.Tpo -c -o optparser.obj `if test -f '$(top_srcdir)/shared/optparser.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/optparser.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/optparser.c'; fi`
436
+@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/optparser.Tpo $(DEPDIR)/optparser.Po
437
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$(top_srcdir)/shared/optparser.c' object='optparser.obj' libtool=no @AMDEPBACKSLASH@
438 438
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
439
-@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cfgparser.obj `if test -f '$(top_srcdir)/shared/cfgparser.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/cfgparser.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/cfgparser.c'; fi`
439
+@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o optparser.obj `if test -f '$(top_srcdir)/shared/optparser.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/optparser.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/optparser.c'; fi`
440 440
 
441 441
 getopt.o: $(top_srcdir)/shared/getopt.c
442 442
 @am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT getopt.o -MD -MP -MF $(DEPDIR)/getopt.Tpo -c -o getopt.o `test -f '$(top_srcdir)/shared/getopt.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/getopt.c
... ...
@@ -466,20 +462,6 @@ misc.obj: $(top_srcdir)/shared/misc.c
466 466
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
467 467
 @am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o misc.obj `if test -f '$(top_srcdir)/shared/misc.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/misc.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/misc.c'; fi`
468 468
 
469
-options.o: $(top_srcdir)/shared/options.c
470
-@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT options.o -MD -MP -MF $(DEPDIR)/options.Tpo -c -o options.o `test -f '$(top_srcdir)/shared/options.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/options.c
471
-@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/options.Tpo $(DEPDIR)/options.Po
472
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$(top_srcdir)/shared/options.c' object='options.o' libtool=no @AMDEPBACKSLASH@
473
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
474
-@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o options.o `test -f '$(top_srcdir)/shared/options.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/options.c
475
-
476
-options.obj: $(top_srcdir)/shared/options.c
477
-@am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT options.obj -MD -MP -MF $(DEPDIR)/options.Tpo -c -o options.obj `if test -f '$(top_srcdir)/shared/options.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/options.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/options.c'; fi`
478
-@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/options.Tpo $(DEPDIR)/options.Po
479
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$(top_srcdir)/shared/options.c' object='options.obj' libtool=no @AMDEPBACKSLASH@
480
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
481
-@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o options.obj `if test -f '$(top_srcdir)/shared/options.c'; then $(CYGPATH_W) '$(top_srcdir)/shared/options.c'; else $(CYGPATH_W) '$(srcdir)/$(top_srcdir)/shared/options.c'; fi`
482
-
483 469
 sha256.o: $(top_srcdir)/shared/sha256.c
484 470
 @am__fastdepCC_TRUE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sha256.o -MD -MP -MF $(DEPDIR)/sha256.Tpo -c -o sha256.o `test -f '$(top_srcdir)/shared/sha256.c' || echo '$(srcdir)/'`$(top_srcdir)/shared/sha256.c
485 471
 @am__fastdepCC_TRUE@	mv -f $(DEPDIR)/sha256.Tpo $(DEPDIR)/sha256.Po
... ...
@@ -33,21 +33,21 @@
33 33
 #endif
34 34
 
35 35
 #include "shared/output.h"
36
-#include "shared/options.h"
36
+#include "shared/optparser.h"
37 37
 #include "execute.h"
38 38
 
39 39
 #define MAX_CHILDREN 5
40 40
 
41 41
 int active_children;
42 42
 
43
-void execute( const char *type, const char *text, const struct optstruct *opt )
43
+void execute( const char *type, const char *text, const struct optstruct *opts )
44 44
 {
45 45
 	int ret;
46 46
 #ifndef C_WINDOWS
47 47
 	pid_t pid;
48 48
 #endif
49 49
 
50
-    if(!opt_check(opt, "daemon")) {
50
+    if(!optget(opts, "daemon")->enabled) {
51 51
 	if(sscanf(text, "EXIT_%d", &ret) == 1) {
52 52
 	    logg("*%s: EXIT_%d\n", type, ret);
53 53
 	    exit(ret);
... ...
@@ -21,8 +21,8 @@
21 21
 #ifndef __EXECUTE_H
22 22
 #define __EXECUTE_H
23 23
 
24
-#include "shared/options.h"
24
+#include "shared/optparser.h"
25 25
 
26
-void execute( const char *type, const char *text, const struct optstruct *opt );
26
+void execute( const char *type, const char *text, const struct optstruct *opts );
27 27
 
28 28
 #endif
... ...
@@ -50,7 +50,7 @@
50 50
 #include "target.h"
51 51
 #include "clamav.h"
52 52
 
53
-#include "shared/options.h"
53
+#include "shared/optparser.h"
54 54
 #include "shared/output.h"
55 55
 #include "shared/misc.h"
56 56
 
... ...
@@ -98,7 +98,7 @@ static void daemon_sighandler(int sig) {
98 98
     return;
99 99
 }
100 100
 
101
-static void writepid(char *pidfile)
101
+static void writepid(const char *pidfile)
102 102
 {
103 103
 	FILE *fd;
104 104
 	int old_umask;
... ...
@@ -149,21 +149,21 @@ static void help(void)
149 149
     mprintf("\n");
150 150
 }
151 151
 
152
-static int download(const struct cfgstruct *copt, const struct optstruct *opt, const char *datadir, const char *cfgfile)
152
+static int download(const struct optstruct *opts, const char *datadir, const char *cfgfile)
153 153
 {
154 154
 	int ret = 0, try = 0, maxattempts = 0;
155
-	const struct cfgstruct *cpt;
155
+	const struct optstruct *opt;
156 156
 
157 157
 
158
-    maxattempts = cfgopt(copt, "MaxAttempts")->numarg;
158
+    maxattempts = optget(opts, "MaxAttempts")->numarg;
159 159
     logg("*Max retries == %d\n", maxattempts);
160 160
 
161
-    if(!(cpt = cfgopt(copt, "DatabaseMirror"))->enabled) {
161
+    if(!(opt = optget(opts, "DatabaseMirror"))->enabled) {
162 162
 	logg("^You must specify at least one database mirror in %s\n", cfgfile);
163 163
 	return 56;
164 164
     } else {
165
-	while(cpt) {
166
-	    ret = downloadmanager(copt, opt, cpt->strarg, datadir, try == maxattempts - 1);
165
+	while(opt) {
166
+	    ret = downloadmanager(opts, opt->strarg, datadir, try == maxattempts - 1);
167 167
 	    alarm(0);
168 168
 
169 169
 	    if(ret == 52 || ret == 54 || ret == 58 || ret == 59) {
... ...
@@ -173,9 +173,9 @@ static int download(const struct cfgstruct *copt, const struct optstruct *opt, c
173 173
 		    sleep(5);
174 174
 		    continue;
175 175
 		} else {
176
-		    logg("Giving up on %s...\n", cpt->strarg);
177
-		    cpt = (struct cfgstruct *) cpt->nextarg;
178
-		    if(!cpt) {
176
+		    logg("Giving up on %s...\n", opt->strarg);
177
+		    opt = (struct optstruct *) opt->nextarg;
178
+		    if(!opt) {
179 179
 			logg("Update failed. Your network may be down or none of the mirrors listed in %s is working. Check http://www.clamav.net/support/mirror-problem for possible reasons.\n", cfgfile);
180 180
 		    }
181 181
 		    try = 0;
... ...
@@ -193,116 +193,70 @@ static int download(const struct cfgstruct *copt, const struct optstruct *opt, c
193 193
 int main(int argc, char **argv)
194 194
 {
195 195
 	int ret = 52;
196
-	const char *newdir, *cfgfile, *arg = NULL;
197
-	char *pidfile = NULL;
198
-	struct cfgstruct *copt;
199
-	const struct cfgstruct *cpt;
196
+	const char *dbdir, *cfgfile, *arg = NULL, *pidfile = NULL;
197
+	char *pt;
198
+	struct optstruct *opts;
199
+	const struct optstruct *opt;
200 200
 #ifndef	C_WINDOWS
201 201
 	struct sigaction sigact;
202 202
 	struct sigaction oldact;
203 203
 #endif
204 204
 #if !defined(C_OS2) && !defined(C_WINDOWS)
205
-	char *unpuser;
205
+	const char *dbowner;
206 206
 	struct passwd *user;
207 207
 #endif
208 208
 	struct stat statbuf;
209 209
 	struct mirdat mdat;
210
-	struct optstruct *opt;
211
-	const char *short_options = "hvdp:Vl:c:u:a:";
212
-	static struct option long_options[] = {
213
-	    {"help", 0, 0, 'h'},
214
-	    {"quiet", 0, 0, 0},
215
-	    {"no-warnings", 0, 0, 0},
216
-	    {"verbose", 0, 0, 'v'},
217
-	    {"debug", 0, 0, 0},
218
-	    {"version", 0, 0, 'V'},
219
-	    {"datadir", 1, 0, 0},
220
-	    {"log", 1, 0, 'l'},
221
-	    {"log-verbose", 0, 0, 0}, /* not used */
222
-	    {"stdout", 0, 0, 0},
223
-	    {"daemon", 0, 0, 'd'},
224
-	    {"pid", 1, 0, 'p'},
225
-	    {"user", 1, 0, 'u'}, /* not used */
226
-	    {"config-file", 1, 0, 0},
227
-	    {"no-dns", 0, 0, 0},
228
-	    {"checks", 1, 0, 'c'},
229
-	    {"http-proxy", 1, 0, 0},
230
-	    {"local-address", 1, 0, 'a'},
231
-	    {"proxy-user", 1, 0, 0},
232
-	    {"daemon-notify", 2, 0, 0},
233
-	    {"on-update-execute", 1, 0, 0},
234
-	    {"on-error-execute", 1, 0, 0},
235
-	    {"on-outdated-execute", 1, 0, 0},
236
-	    {"list-mirrors", 0, 0, 0},
237
-	    {"submit-stats", 2, 0, 0},
238
-	    {0, 0, 0, 0}
239
-    	};
240
-
241
-
242
-    opt = opt_parse(argc, argv, short_options, long_options, NULL, NULL);
243
-    if(!opt) {
244
-	mprintf("!Can't parse the command line\n");
245
-	return 40;
210
+
211
+
212
+    if((opts = optparse(NULL, argc, argv, 1, OPT_FRESHCLAM, NULL)) == NULL) {
213
+	mprintf("!Can't parse command line options\n");
214
+	return 1;
246 215
     }
247 216
 
248
-    if(opt_check(opt, "help")) {
217
+    if(optget(opts, "help")->enabled) {
249 218
     	help();
250
-	opt_free(opt);
219
+	optfree(opts);
251 220
 	return 0;
252 221
     }
253 222
 
254 223
     /* parse the config file */
255
-    if((cfgfile = opt_arg(opt, "config-file"))) {
256
-        copt = getcfg(cfgfile, 1, OPT_FRESHCLAM);
257
-    } else {
258
-	/* TODO: force strict permissions on freshclam.conf */
259
-	if((copt = getcfg((cfgfile = CONFDIR"/freshclam.conf"), 1, OPT_FRESHCLAM)) == NULL)
260
-	    copt = getcfg((cfgfile = CONFDIR"/clamd.conf"), 1, OPT_FRESHCLAM);
261
-    }
262
-
263
-    if(!copt) {
264
-	logg("!Can't parse the config file %s\n", cfgfile);
265
-	opt_free(opt);
266
-	return 56;
224
+    cfgfile = optget(opts, "config-file")->strarg;
225
+    pt = strdup(cfgfile);
226
+    if((opts = optparse(cfgfile, 0, NULL, 1, OPT_FRESHCLAM, opts)) == NULL) {
227
+	fprintf(stderr, "ERROR: Can't open/parse the config file %s\n", pt);
228
+	free(pt);
229
+	return 1;
267 230
     }
231
+    free(pt);
268 232
 
269
-    if(opt_check(opt, "datadir"))
270
-	newdir = opt_arg(opt, "datadir");
271
-    else
272
-	newdir = cfgopt(copt, "DatabaseDirectory")->strarg;
233
+    dbdir = optget(opts, "DatabaseDirectory")->strarg;
273 234
 
274
-    if(opt_check(opt, "version")) {
275
-	print_version(newdir);
276
-	opt_free(opt);
277
-	freecfg(copt);
235
+    if(optget(opts, "version")->enabled) {
236
+	print_version(dbdir);
237
+	optfree(opts);
278 238
 	return 0;
279 239
     }
280 240
 
281 241
 #ifdef C_WINDOWS
282 242
     if(!pthread_win32_process_attach_np()) {
283 243
 	mprintf("!Can't start the win32 pthreads layer\n");
284
-	opt_free(opt);
285
-	freecfg(copt);
244
+	optfree(opts);
286 245
 	return 63;
287 246
     }
288 247
 #endif
289 248
 
290
-    if(opt_check(opt, "http-proxy") || opt_check(opt, "proxy-user"))
291
-	logg("WARNING: Proxy settings are now only configurable in the config file.\n");
292
-
293
-    if(cfgopt(copt, "HTTPProxyPassword")->enabled) {
249
+    if(optget(opts, "HTTPProxyPassword")->enabled) {
294 250
 	if(stat(cfgfile, &statbuf) == -1) {
295 251
 	    logg("^Can't stat %s (critical error)\n", cfgfile);
296
-	    opt_free(opt);
297
-	    freecfg(copt);
252
+	    optfree(opts);
298 253
 	    return 56;
299 254
 	}
300 255
 
301 256
 #ifndef C_WINDOWS
302 257
 	if(statbuf.st_mode & (S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH)) {
303 258
 	    logg("^Insecure permissions (for HTTPProxyPassword): %s must have no more than 0700 permissions.\n", cfgfile);
304
-	    opt_free(opt);
305
-	    freecfg(copt);
259
+	    optfree(opts);
306 260
 	    return 56;
307 261
 	}
308 262
 #endif
... ...
@@ -310,25 +264,20 @@ int main(int argc, char **argv)
310 310
 
311 311
 #if !defined(C_OS2) && !defined(C_WINDOWS)
312 312
     /* freshclam shouldn't work with root privileges */
313
-    if(opt_check(opt, "user"))
314
-	unpuser = opt_arg(opt, "user");
315
-    else
316
-	unpuser = cfgopt(copt, "DatabaseOwner")->strarg;
313
+    dbowner = optget(opts, "DatabaseOwner")->strarg;
317 314
 
318 315
     if(!geteuid()) {
319
-	if((user = getpwnam(unpuser)) == NULL) {
320
-	    logg("^Can't get information about user %s.\n", unpuser);
321
-	    opt_free(opt);
322
-	    freecfg(copt);
316
+	if((user = getpwnam(dbowner)) == NULL) {
317
+	    logg("^Can't get information about user %s.\n", dbowner);
318
+	    optfree(opts);
323 319
 	    return 60;
324 320
 	}
325 321
 
326
-	if(cfgopt(copt, "AllowSupplementaryGroups")->enabled) {
322
+	if(optget(opts, "AllowSupplementaryGroups")->enabled) {
327 323
 #ifdef HAVE_INITGROUPS
328
-	    if(initgroups(unpuser, user->pw_gid)) {
324
+	    if(initgroups(dbowner, user->pw_gid)) {
329 325
 		logg("^initgroups() failed.\n");
330
-		opt_free(opt);
331
-		freecfg(copt);
326
+		optfree(opts);
332 327
 		return 61;
333 328
 	    }
334 329
 #endif
... ...
@@ -336,8 +285,7 @@ int main(int argc, char **argv)
336 336
 #ifdef HAVE_SETGROUPS
337 337
 	    if(setgroups(1, &user->pw_gid)) {
338 338
 		logg("^setgroups() failed.\n");
339
-		opt_free(opt);
340
-		freecfg(copt);
339
+		optfree(opts);
341 340
 		return 61;
342 341
 	    }
343 342
 #endif
... ...
@@ -345,15 +293,13 @@ int main(int argc, char **argv)
345 345
 
346 346
 	if(setgid(user->pw_gid)) {
347 347
 	    logg("^setgid(%d) failed.\n", (int) user->pw_gid);
348
-	    opt_free(opt);
349
-	    freecfg(copt);
348
+	    optfree(opts);
350 349
 	    return 61;
351 350
 	}
352 351
 
353 352
 	if(setuid(user->pw_uid)) {
354 353
 	    logg("^setuid(%d) failed.\n", (int) user->pw_uid);
355
-	    opt_free(opt);
356
-	    freecfg(copt);
354
+	    optfree(opts);
357 355
 	    return 61;
358 356
 	}
359 357
     }
... ...
@@ -361,56 +307,46 @@ int main(int argc, char **argv)
361 361
 
362 362
     /* initialize some important variables */
363 363
 
364
-    if(opt_check(opt, "debug") || cfgopt(copt, "Debug")->enabled)
364
+    if(optget(opts, "Debug")->enabled)
365 365
 	cl_debug();
366 366
 
367
-    if(opt_check(opt, "verbose"))
367
+    if(optget(opts, "verbose")->enabled)
368 368
 	mprintf_verbose = 1;
369 369
 
370
-    if(opt_check(opt, "quiet"))
370
+    if(optget(opts, "quiet")->enabled)
371 371
 	mprintf_quiet = 1;
372 372
 
373
-    if(opt_check(opt, "no-warnings")) {
373
+    if(optget(opts, "no-warnings")->enabled) {
374 374
 	mprintf_nowarn = 1;
375 375
 	logg_nowarn = 1;
376 376
     }
377 377
 
378
-    if(opt_check(opt, "stdout"))
378
+    if(optget(opts, "stdout")->enabled)
379 379
 	mprintf_stdout = 1;
380 380
 
381 381
     /* initialize logger */
382
-    logg_verbose = cfgopt(copt, "LogVerbose")->enabled;
383
-    logg_time = cfgopt(copt, "LogTime")->enabled;
384
-    logg_size = cfgopt(copt, "LogFileMaxSize")->numarg;
382
+    logg_verbose = optget(opts, "LogVerbose")->enabled;
383
+    logg_time = optget(opts, "LogTime")->enabled;
384
+    logg_size = optget(opts, "LogFileMaxSize")->numarg;
385 385
 
386
-    if(opt_check(opt, "log")) {
387
-	logg_file = opt_arg(opt, "log");
388
-	if(logg("#--------------------------------------\n")) {
389
-	    mprintf("!Problem with internal logger (--log=%s).\n", logg_file);
390
-	    opt_free(opt);
391
-	    freecfg(copt);
392
-	    return 62;
393
-	}
394
-    } else if((cpt = cfgopt(copt, "UpdateLogFile"))->enabled) {
395
-	logg_file = cpt->strarg; 
386
+    if((opt = optget(opts, "UpdateLogFile"))->enabled) {
387
+	logg_file = opt->strarg; 
396 388
 	if(logg("#--------------------------------------\n")) {
397 389
 	    mprintf("!Problem with internal logger (UpdateLogFile = %s).\n", logg_file);
398
-	    opt_free(opt);
399
-	    freecfg(copt);
390
+	    optfree(opts);
400 391
 	    return 62;
401 392
 	}
402 393
     } else
403 394
 	logg_file = NULL;
404 395
 
405 396
 #if defined(USE_SYSLOG) && !defined(C_AIX)
406
-    if(cfgopt(copt, "LogSyslog")->enabled) {
397
+    if(optget(opts, "LogSyslog")->enabled) {
407 398
 	    int fac = LOG_LOCAL6;
408 399
 
409
-	if((cpt = cfgopt(copt, "LogFacility"))->enabled) {
410
-	    if((fac = logg_facility(cpt->strarg)) == -1) {
411
-		mprintf("!LogFacility: %s: No such facility.\n", cpt->strarg);
412
-		opt_free(opt);
413
-		freecfg(copt);
400
+	if((opt = optget(opts, "LogFacility"))->enabled) {
401
+	    if((fac = logg_facility(opt->strarg)) == -1) {
402
+		mprintf("!LogFacility: %s: No such facility.\n", opt->strarg);
403
+		optfree(opts);
414 404
 		return 62;
415 405
 	    }
416 406
 	}
... ...
@@ -421,26 +357,23 @@ int main(int argc, char **argv)
421 421
 #endif
422 422
 
423 423
     /* change the current working directory */
424
-    if(chdir(newdir)) {
425
-	logg("Can't change dir to %s\n", newdir);
426
-	opt_free(opt);
427
-	freecfg(copt);
424
+    if(chdir(dbdir)) {
425
+	logg("Can't change dir to %s\n", dbdir);
426
+	optfree(opts);
428 427
 	return 50;
429 428
     } else
430
-	logg("*Current working dir is %s\n", newdir);
429
+	logg("*Current working dir is %s\n", dbdir);
431 430
 
432 431
 
433
-    if(opt_check(opt, "list-mirrors")) {
432
+    if(optget(opts, "list-mirrors")->enabled) {
434 433
 	if(mirman_read("mirrors.dat", &mdat, 1) == -1) {
435 434
 	    printf("Can't read mirrors.dat\n");
436
-	    opt_free(opt);
437
-	    freecfg(copt);
435
+	    optfree(opts);
438 436
 	    return 55;
439 437
 	}
440 438
 	mirman_list(&mdat);
441 439
 	mirman_free(&mdat);
442
-	opt_free(opt);
443
-	freecfg(copt);
440
+	optfree(opts);
444 441
 	return 0;
445 442
     }
446 443
 
... ...
@@ -450,14 +383,13 @@ int main(int argc, char **argv)
450 450
 
451 451
 	if(WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) {
452 452
 	    logg("!Error at WSAStartup(): %d\n", WSAGetLastError());
453
-	    opt_free(opt);
454
-	    freecfg(copt);
453
+	    optfree(opts);
455 454
 	    return 1;
456 455
 	}
457 456
     }
458 457
 #endif
459 458
 
460
-    if(opt_check(opt, "daemon")) {
459
+    if(optget(opts, "daemon")->enabled) {
461 460
 	    int bigsleep, checks;
462 461
 #ifndef	C_WINDOWS
463 462
 	    time_t now, wakeup;
... ...
@@ -466,23 +398,18 @@ int main(int argc, char **argv)
466 466
 	sigact.sa_handler = daemon_sighandler;
467 467
 #endif
468 468
 
469
-	if(opt_check(opt, "checks"))
470
-	    checks = atoi(opt_arg(opt, "checks"));
471
-	else
472
-	    checks = cfgopt(copt, "Checks")->numarg;
469
+	checks = optget(opts, "Checks")->numarg;
473 470
 
474 471
 	if(checks <= 0) {
475 472
 	    logg("^Number of checks must be a positive integer.\n");
476
-	    opt_free(opt);
477
-	    freecfg(copt);
473
+	    optfree(opts);
478 474
 	    return 41;
479 475
 	}
480 476
 
481
-	if(!cfgopt(copt, "DNSDatabaseInfo")->enabled || opt_check(opt, "no-dns")) {
477
+	if(!optget(opts, "DNSDatabaseInfo")->enabled || optget(opt, "no-dns")->enabled) {
482 478
 	    if(checks > 50) {
483 479
 		logg("^Number of checks must be between 1 and 50.\n");
484
-		opt_free(opt);
485
-		freecfg(copt);
480
+		optfree(opts);
486 481
 		return 41;
487 482
 	    }
488 483
 	}
... ...
@@ -490,11 +417,10 @@ int main(int argc, char **argv)
490 490
 	bigsleep = 24 * 3600 / checks;
491 491
 
492 492
 #if !defined(C_OS2) && !defined(C_WINDOWS)
493
-	if(!cfgopt(copt, "Foreground")->enabled) {
493
+	if(!optget(opts, "Foreground")->enabled) {
494 494
 	    if(daemonize() == -1) {
495 495
 		logg("!daemonize() failed\n");
496
-		opt_free(opt);
497
-		freecfg(copt);
496
+		optfree(opts);
498 497
 		return 70; /* FIXME */
499 498
 	    }
500 499
             foreground = 0;
... ...
@@ -502,12 +428,8 @@ int main(int argc, char **argv)
502 502
         }
503 503
 #endif
504 504
 
505
-	if(opt_check(opt, "pid")) {
506
-	    pidfile = opt_arg(opt, "pid");
507
-	} else if ((cpt = cfgopt(copt, "PidFile"))->enabled) {
508
-	    pidfile = cpt->strarg;
509
-	}
510
-	if (pidfile) {
505
+	if((opt = optget(opts, "PidFile"))->enabled) {
506
+	    pidfile = opt->strarg;
511 507
 	    writepid(pidfile);
512 508
 	}
513 509
 
... ...
@@ -526,16 +448,14 @@ int main(int argc, char **argv)
526 526
 #endif
527 527
 
528 528
 	while(!terminate) {
529
-	    ret = download(copt, opt, newdir, cfgfile);
529
+	    ret = download(opts, dbdir, cfgfile);
530 530
 
531 531
 	    if(ret <= 1) {
532
-		if((cpt = cfgopt(copt, "SubmitDetectionStats"))->enabled)
533
-		    submitstats(cpt->strarg, copt);
532
+		if((opt = optget(opts, "SubmitDetectionStats"))->enabled)
533
+		    submitstats(opt->strarg, opts);
534 534
             } else  {
535
-	        if(opt_check(opt, "on-error-execute"))
536
-		    arg = opt_arg(opt, "on-error-execute");
537
-		else if((cpt = cfgopt(copt, "OnErrorExecute"))->enabled)
538
-		    arg = cpt->strarg;
535
+		if((opt = optget(opts, "OnErrorExecute"))->enabled)
536
+		    arg = opt->strarg;
539 537
 
540 538
 		if(arg)
541 539
 		    execute("OnErrorExecute", arg, opt);
... ...
@@ -581,37 +501,28 @@ int main(int argc, char **argv)
581 581
 	}
582 582
 
583 583
     } else {
584
-	if(opt_check(opt, "submit-stats")) {
585
-	    cfgfile = opt_arg(opt, "submit-stats");
586
-	    if(!cfgfile)
587
-		cfgfile = CONFDIR"/clamd.conf";
588
-	    if(!opt_check(opt, "no-warnings"))
584
+	if((opt = optget(opts, "submit-stats"))->active) {
585
+	    if(!optget(opts, "no-warnings")->enabled)
589 586
 		logg(" *** Virus databases are not updated in this mode ***\n");
590
-	    ret = submitstats(cfgfile, copt);
587
+	    ret = submitstats(opt->strarg, opts);
591 588
 	} else {
592
-	    ret = download(copt, opt, newdir, cfgfile);
589
+	    ret = download(opts, dbdir, cfgfile);
593 590
 
594
-	    if((cpt = cfgopt(copt, "SubmitDetectionStats"))->enabled)
595
-		submitstats(cpt->strarg, copt);
591
+	    if((opt = optget(opts, "SubmitDetectionStats"))->enabled)
592
+		submitstats(opt->strarg, opts);
596 593
 	}
597 594
     }
598 595
 
599 596
     if(ret > 1) {
600
-	if(opt_check(opt, "on-error-execute"))
601
-	    arg = opt_arg(opt, "on-error-execute");
602
-	else if((cpt = cfgopt(copt, "OnErrorExecute"))->enabled)
603
-	    arg = cpt->strarg;
604
-
605
-	if(arg)
606
-            execute("OnErrorExecute", arg, opt);
597
+	if((opt = optget(opts, "OnErrorExecute"))->enabled)
598
+            execute("OnErrorExecute", opt->strarg, opts);
607 599
     }
608 600
 
609 601
     if (pidfile) {
610 602
         unlink(pidfile);
611 603
     }
612 604
 
613
-    opt_free(opt);
614
-    freecfg(copt);
605
+    optfree(opts);
615 606
 
616 607
 #ifdef C_WINDOWS
617 608
     WSACleanup();
... ...
@@ -74,8 +74,7 @@
74 74
 #include "nonblock.h"
75 75
 #include "mirman.h"
76 76
 
77
-#include "shared/options.h"
78
-#include "shared/cfgparser.h"
77
+#include "shared/optparser.h"
79 78
 #include "shared/output.h"
80 79
 #include "shared/misc.h"
81 80
 #include "shared/cdiff.h"
... ...
@@ -535,7 +534,7 @@ static char *proxyauth(const char *user, const char *pass)
535 535
  * TODO:
536 536
  * - strptime() is most likely not portable enough
537 537
  */
538
-int submitstats(const char *clamdcfg, const struct cfgstruct *copt)
538
+int submitstats(const char *clamdcfg, const struct optstruct *opts)
539 539
 {
540 540
 	int fd, sd, bread, lread = 0, cnt, ret;
541 541
 	char post[SUBMIT_MIN_ENTRIES * 256 + 512];
... ...
@@ -544,41 +543,41 @@ int submitstats(const char *clamdcfg, const struct cfgstruct *copt)
544 544
 	char logfile[256], fbuff[FILEBUFF];
545 545
 	char *pt, *pt2, *auth = NULL;
546 546
 	const char *line, *country = NULL, *user, *proxy = NULL;
547
-	struct cfgstruct *clamdopt;
548
-	const struct cfgstruct *cpt;
547
+	struct optstruct *clamdopt;
548
+	const struct optstruct *opt;
549 549
 	struct stat sb;
550 550
 	struct tm tms;
551 551
 	time_t epoch;
552 552
 	unsigned int qcnt, entries, submitted = 0, permfail = 0, port = 0;
553 553
 
554 554
 
555
-    if((cpt = cfgopt(copt, "DetectionStatsCountry"))->enabled) {
556
-	if(strlen(cpt->strarg) != 2 || !isalpha(cpt->strarg[0]) || !isalpha(cpt->strarg[1])) {
555
+    if((opt = optget(opts, "DetectionStatsCountry"))->enabled) {
556
+	if(strlen(opt->strarg) != 2 || !isalpha(opt->strarg[0]) || !isalpha(opt->strarg[1])) {
557 557
 	    logg("!SubmitDetectionStats: DetectionStatsCountry requires a two-letter country code\n");
558 558
 	    return 56;
559 559
 	}
560
-	country = cpt->strarg;
560
+	country = opt->strarg;
561 561
     }
562 562
 
563
-    if(!(clamdopt = getcfg(clamdcfg, 1, OPT_CLAMD))) {
563
+    if(!(clamdopt = optparse(clamdcfg, 0, NULL, 1, OPT_CLAMD, NULL))) {
564 564
 	logg("!SubmitDetectionStats: Can't open or parse configuration file %s\n", clamdcfg);
565 565
 	return 56;
566 566
     }
567 567
 
568
-    if(!(cpt = cfgopt(clamdopt, "LogFile"))->enabled) {
568
+    if(!(opt = optget(clamdopt, "LogFile"))->enabled) {
569 569
 	logg("!SubmitDetectionStats: LogFile needs to be enabled in %s\n", clamdcfg);
570
-	freecfg(clamdopt);
570
+	optfree(clamdopt);
571 571
 	return 56;
572 572
     }
573
-    strncpy(logfile, cpt->strarg, sizeof(logfile));
573
+    strncpy(logfile, opt->strarg, sizeof(logfile));
574 574
     logfile[sizeof(logfile) - 1] = 0;
575 575
 
576
-    if(!cfgopt(clamdopt, "LogTime")->enabled) {
576
+    if(!optget(clamdopt, "LogTime")->enabled) {
577 577
 	logg("!SubmitDetectionStats: LogTime needs to be enabled in %s\n", clamdcfg);
578
-	freecfg(clamdopt);
578
+	optfree(clamdopt);
579 579
 	return 56;
580 580
     }
581
-    freecfg(clamdopt);
581
+    optfree(clamdopt);
582 582
 
583 583
     if((fd = open("stats.dat", O_RDONLY)) != -1) {
584 584
 	if((bread = read(fd, statsdat, sizeof(statsdat) - 1)) == -1) {
... ...
@@ -620,33 +619,33 @@ int submitstats(const char *clamdcfg, const struct cfgstruct *copt)
620 620
 	strncpy(newstatsdat, line, sizeof(newstatsdat));
621 621
     }
622 622
 
623
-    if((cpt = cfgopt(copt, "HTTPUserAgent"))->enabled)
624
-	strncpy(uastr, cpt->strarg, sizeof(uastr));
623
+    if((opt = optget(opts, "HTTPUserAgent"))->enabled)
624
+	strncpy(uastr, opt->strarg, sizeof(uastr));
625 625
     else
626 626
 	snprintf(uastr, sizeof(uastr), PACKAGE"/%s (OS: "TARGET_OS_TYPE", ARCH: "TARGET_ARCH_TYPE", CPU: "TARGET_CPU_TYPE")%s%s", get_version(), country ? ":" : "", country ? country : "");
627 627
     uastr[sizeof(uastr) - 1] = 0;
628 628
 
629
-    if((cpt = cfgopt(copt, "HTTPProxyServer"))->enabled) {
630
-	proxy = cpt->strarg;
629
+    if((opt = optget(opts, "HTTPProxyServer"))->enabled) {
630
+	proxy = opt->strarg;
631 631
 	if(!strncasecmp(proxy, "http://", 7))
632 632
 	    proxy += 7;
633 633
 
634
-	if((cpt = cfgopt(copt, "HTTPProxyUsername"))->enabled) {
635
-	    user = cpt->strarg;
636
-	    if(!(cpt = cfgopt(copt, "HTTPProxyPassword"))->enabled) {
634
+	if((opt = optget(opts, "HTTPProxyUsername"))->enabled) {
635
+	    user = opt->strarg;
636
+	    if(!(opt = optget(opts, "HTTPProxyPassword"))->enabled) {
637 637
 		logg("!SubmitDetectionStats: HTTPProxyUsername requires HTTPProxyPassword\n");
638 638
 		close(fd);
639 639
 		return 56;
640 640
 	    }
641
-	    auth = proxyauth(user, cpt->strarg);
641
+	    auth = proxyauth(user, opt->strarg);
642 642
 	    if(!auth) {
643 643
 		close(fd);
644 644
 		return 56;
645 645
 	    }
646 646
 	}
647 647
 
648
-	if((cpt = cfgopt(copt, "HTTPProxyPort"))->enabled)
649
-	    port = cpt->numarg;
648
+	if((opt = optget(opts, "HTTPProxyPort"))->enabled)
649
+	    port = opt->numarg;
650 650
 
651 651
 	logg("*Connecting via %s\n", proxy);
652 652
     }
... ...
@@ -702,7 +701,7 @@ int submitstats(const char *clamdcfg, const struct cfgstruct *copt)
702 702
 	entries++;
703 703
 
704 704
 	if(entries == SUBMIT_MIN_ENTRIES) {
705
-	    sd = wwwconnect("stats.clamav.net", proxy, port, NULL, cfgopt(copt, "LocalIPAddress")->strarg, cfgopt(copt, "ConnectTimeout")->numarg, NULL, 0, 0);
705
+	    sd = wwwconnect("stats.clamav.net", proxy, port, NULL, optget(opts, "LocalIPAddress")->strarg, optget(opts, "ConnectTimeout")->numarg, NULL, 0, 0);
706 706
 	    if(sd == -1) {
707 707
 		logg("!SubmitDetectionStats: Can't connect to server\n");
708 708
 		ret = 52;
... ...
@@ -729,7 +728,7 @@ int submitstats(const char *clamdcfg, const struct cfgstruct *copt)
729 729
 	    pt = post;
730 730
 	    cnt = sizeof(post) - 1;
731 731
 #ifdef SO_ERROR
732
-	    while((bread = wait_recv(sd, pt, cnt, 0, cfgopt(copt, "ReceiveTimeout")->numarg)) > 0) {
732
+	    while((bread = wait_recv(sd, pt, cnt, 0, optget(opts, "ReceiveTimeout")->numarg)) > 0) {
733 733
 #else
734 734
 	    while((bread = recv(sd, pt, cnt, 0)) > 0) {
735 735
 #endif
... ...
@@ -1457,10 +1456,10 @@ static int buildcld(const char *tmpdir, const char *dbname, const char *newfile,
1457 1457
     return 0;
1458 1458
 }
1459 1459
 
1460
-static int updatedb(const char *dbname, const char *hostname, char *ip, int *signo, const struct cfgstruct *copt, const char *dnsreply, char *localip, int outdated, struct mirdat *mdat, int logerr)
1460
+static int updatedb(const char *dbname, const char *hostname, char *ip, int *signo, const struct optstruct *opts, const char *dnsreply, char *localip, int outdated, struct mirdat *mdat, int logerr)
1461 1461
 {
1462 1462
 	struct cl_cvd *current, *remote;
1463
-	const struct cfgstruct *cpt;
1463
+	const struct optstruct *opt;
1464 1464
 	unsigned int nodb = 0, currver = 0, newver = 0, port = 0, i, j;
1465 1465
 	int ret, ims = -1;
1466 1466
 	char *pt, cvdfile[32], localname[32], *tmpdir = NULL, *newfile, newdb[32], cwd[512];
... ...
@@ -1514,15 +1513,15 @@ static int updatedb(const char *dbname, const char *hostname, char *ip, int *sig
1514 1514
     }
1515 1515
 
1516 1516
     /* Initialize proxy settings */
1517
-    if((cpt = cfgopt(copt, "HTTPProxyServer"))->enabled) {
1518
-	proxy = cpt->strarg;
1517
+    if((opt = optget(opts, "HTTPProxyServer"))->enabled) {
1518
+	proxy = opt->strarg;
1519 1519
 	if(strncasecmp(proxy, "http://", 7) == 0)
1520 1520
 	    proxy += 7;
1521 1521
 
1522
-	if((cpt = cfgopt(copt, "HTTPProxyUsername"))->enabled) {
1523
-	    user = cpt->strarg;
1524
-	    if((cpt = cfgopt(copt, "HTTPProxyPassword"))->enabled) {
1525
-		pass = cpt->strarg;
1522
+	if((opt = optget(opts, "HTTPProxyUsername"))->enabled) {
1523
+	    user = opt->strarg;
1524
+	    if((opt = optget(opts, "HTTPProxyPassword"))->enabled) {
1525
+		pass = opt->strarg;
1526 1526
 	    } else {
1527 1527
 		logg("HTTPProxyUsername requires HTTPProxyPassword\n");
1528 1528
 		if(current)
... ...
@@ -1531,17 +1530,17 @@ static int updatedb(const char *dbname, const char *hostname, char *ip, int *sig
1531 1531
 	    }
1532 1532
 	}
1533 1533
 
1534
-	if((cpt = cfgopt(copt, "HTTPProxyPort"))->enabled)
1535
-	    port = cpt->numarg;
1534
+	if((opt = optget(opts, "HTTPProxyPort"))->enabled)
1535
+	    port = opt->numarg;
1536 1536
 
1537 1537
 	logg("Connecting via %s\n", proxy);
1538 1538
     }
1539 1539
 
1540
-    if((cpt = cfgopt(copt, "HTTPUserAgent"))->enabled)
1541
-	uas = cpt->strarg;
1540
+    if((opt = optget(opts, "HTTPUserAgent"))->enabled)
1541
+	uas = opt->strarg;
1542 1542
 
1543
-    ctimeout = cfgopt(copt, "ConnectTimeout")->numarg;
1544
-    rtimeout = cfgopt(copt, "ReceiveTimeout")->numarg;
1543
+    ctimeout = optget(opts, "ConnectTimeout")->numarg;
1544
+    rtimeout = optget(opts, "ReceiveTimeout")->numarg;
1545 1545
 
1546 1546
     if(!nodb && !newver) {
1547 1547
 
... ...
@@ -1603,7 +1602,7 @@ static int updatedb(const char *dbname, const char *hostname, char *ip, int *sig
1603 1603
     };
1604 1604
     */
1605 1605
 
1606
-    if(!cfgopt(copt, "ScriptedUpdates")->enabled)
1606
+    if(!optget(opts, "ScriptedUpdates")->enabled)
1607 1607
 	nodb = 1;
1608 1608
 
1609 1609
     if(!getcwd(cwd, sizeof(cwd))) {
... ...
@@ -1625,7 +1624,7 @@ static int updatedb(const char *dbname, const char *hostname, char *ip, int *sig
1625 1625
 	ret = 0;
1626 1626
 
1627 1627
 	tmpdir = cli_gentemp(".");
1628
-	maxattempts = cfgopt(copt, "MaxAttempts")->numarg;
1628
+	maxattempts = optget(opts, "MaxAttempts")->numarg;
1629 1629
 	for(i = currver + 1; i <= newver; i++) {
1630 1630
 	    for(j = 0; j < maxattempts; j++) {
1631 1631
 		    int llogerr = logerr;
... ...
@@ -1654,7 +1653,7 @@ static int updatedb(const char *dbname, const char *hostname, char *ip, int *sig
1654 1654
 	    }
1655 1655
 	    snprintf(newdb, sizeof(newdb), "%s.cvd", dbname);
1656 1656
 	} else {
1657
-	    if(buildcld(tmpdir, dbname, newfile, cfgopt(copt, "CompressLocalDatabase")->enabled) == -1) {
1657
+	    if(buildcld(tmpdir, dbname, newfile, optget(opts, "CompressLocalDatabase")->enabled) == -1) {
1658 1658
 		logg("!Can't create local database\n");
1659 1659
 		cli_rmdirs(tmpdir);
1660 1660
 		free(tmpdir);
... ...
@@ -1711,14 +1710,13 @@ static int updatedb(const char *dbname, const char *hostname, char *ip, int *sig
1711 1711
     return 0;
1712 1712
 }
1713 1713
 
1714
-int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, const char *hostname, const char *dbdir, int logerr)
1714
+int downloadmanager(const struct optstruct *opts, const char *hostname, const char *dbdir, int logerr)
1715 1715
 {
1716 1716
 	time_t currtime;
1717 1717
 	int ret, updated = 0, outdated = 0, signo = 0;
1718 1718
 	unsigned int ttl;
1719 1719
 	char ipaddr[46], *dnsreply = NULL, *pt, *localip = NULL, *newver = NULL;
1720
-	const char *arg = NULL;
1721
-	const struct cfgstruct *cpt;
1720
+	const struct optstruct *opt;
1722 1721
 	struct mirdat mdat;
1723 1722
 #ifdef HAVE_RESOLV_H
1724 1723
 	const char *dnsdbinfo;
... ...
@@ -1736,9 +1734,9 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c
1736 1736
 #endif
1737 1737
 
1738 1738
 #ifdef HAVE_RESOLV_H
1739
-    dnsdbinfo = cfgopt(copt, "DNSDatabaseInfo")->strarg;
1739
+    dnsdbinfo = optget(opts, "DNSDatabaseInfo")->strarg;
1740 1740
 
1741
-    if(opt_check(opt, "no-dns")) {
1741
+    if(optget(opts, "no-dns")->enabled) {
1742 1742
 	dnsreply = NULL;
1743 1743
     } else {
1744 1744
 	if((dnsreply = txtquery(dnsdbinfo, &ttl))) {
... ...
@@ -1799,20 +1797,17 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c
1799 1799
     }
1800 1800
 #endif /* HAVE_RESOLV_H */
1801 1801
 
1802
-    if(opt_check(opt, "local-address")) {
1803
-        localip = opt_arg(opt, "local-address");
1804
-    } else if((cpt = cfgopt(copt, "LocalIPAddress"))->enabled) {
1805
-	localip = cpt->strarg;
1806
-    }
1802
+    if((opt = optget(opts, "LocalIPAddress"))->enabled)
1803
+	localip = opt->strarg;
1807 1804
 
1808
-    if(cfgopt(copt, "HTTPProxyServer")->enabled)
1805
+    if(optget(opts, "HTTPProxyServer")->enabled)
1809 1806
 	mirman_read("mirrors.dat", &mdat, 0);
1810 1807
     else
1811 1808
 	mirman_read("mirrors.dat", &mdat, 1);
1812 1809
 
1813 1810
     memset(ipaddr, 0, sizeof(ipaddr));
1814 1811
 
1815
-    if((ret = updatedb("main", hostname, ipaddr, &signo, copt, dnsreply, localip, outdated, &mdat, logerr)) > 50) {
1812
+    if((ret = updatedb("main", hostname, ipaddr, &signo, opts, dnsreply, localip, outdated, &mdat, logerr)) > 50) {
1816 1813
 	if(dnsreply)
1817 1814
 	    free(dnsreply);
1818 1815
 
... ...
@@ -1826,7 +1821,7 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c
1826 1826
 	updated = 1;
1827 1827
 
1828 1828
     /* if ipaddr[0] != 0 it will use it to connect to the web host */
1829
-    if((ret = updatedb("daily", hostname, ipaddr, &signo, copt, dnsreply, localip, outdated, &mdat, logerr)) > 50) {
1829
+    if((ret = updatedb("daily", hostname, ipaddr, &signo, opts, dnsreply, localip, outdated, &mdat, logerr)) > 50) {
1830 1830
 	if(dnsreply)
1831 1831
 	    free(dnsreply);
1832 1832
 
... ...
@@ -1845,41 +1840,24 @@ int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, c
1845 1845
     mirman_write("mirrors.dat", &mdat);
1846 1846
 
1847 1847
     if(updated) {
1848
-	if(cfgopt(copt, "HTTPProxyServer")->enabled) {
1848
+	if(optget(opts, "HTTPProxyServer")->enabled) {
1849 1849
 	    logg("Database updated (%d signatures) from %s\n", signo, hostname);
1850 1850
 	} else {
1851 1851
 	    logg("Database updated (%d signatures) from %s (IP: %s)\n", signo, hostname, ipaddr);
1852 1852
 	}
1853 1853
 
1854 1854
 #ifdef BUILD_CLAMD
1855
-	if(opt_check(opt, "daemon-notify")) {
1856
-		const char *clamav_conf = opt_arg(opt, "daemon-notify");
1857
-	    if(!clamav_conf)
1858
-		clamav_conf = CONFDIR"/clamd.conf";
1859
-
1860
-	    notify(clamav_conf);
1861
-	} else if((cpt = cfgopt(copt, "NotifyClamd"))->enabled) {
1862
-	    notify(cpt->strarg);
1863
-	}
1855
+	if((opt = optget(opts, "NotifyClamd"))->active)
1856
+	    notify(opt->strarg);
1864 1857
 #endif
1865 1858
 
1866
-	if(opt_check(opt, "on-update-execute"))
1867
-	    arg = opt_arg(opt, "on-update-execute");
1868
-	else if((cpt = cfgopt(copt, "OnUpdateExecute"))->enabled)
1869
-	    arg = cpt->strarg;
1870
-
1871
-	if(arg)
1872
-	    execute("OnUpdateExecute", arg, opt);
1859
+	if((opt = optget(opts, "OnUpdateExecute"))->enabled)
1860
+	    execute("OnUpdateExecute", opt->strarg, opts);
1873 1861
     }
1874 1862
 
1875 1863
     if(outdated) {
1876
-	if(opt_check(opt, "on-outdated-execute"))
1877
-	    arg = opt_arg(opt, "on-outdated-execute");
1878
-	else if((cpt = cfgopt(copt, "OnOutdatedExecute"))->enabled)
1879
-	    arg = cpt->strarg;
1880
-
1881
-	if(arg) {
1882
-		char *cmd = strdup(arg);
1864
+	if((opt = optget(opts, "OnOutdatedExecute"))->enabled) {
1865
+		char *cmd = strdup(opt->strarg);
1883 1866
 
1884 1867
 	    if((pt = newver)) {
1885 1868
 		while(*pt) {
... ...
@@ -23,11 +23,10 @@
23 23
 #define SUBMIT_MIN_ENTRIES    10
24 24
 #define SUBMIT_MAX_ENTRIES    50
25 25
 
26
-#include "shared/cfgparser.h"
27
-#include "shared/options.h"
26
+#include "shared/optparser.h"
28 27
 
29
-int downloadmanager(const struct cfgstruct *copt, const struct optstruct *opt, const char *hostname, const char *dbdir, int logerr);
28
+int downloadmanager(const struct optstruct *opts, const char *hostname, const char *dbdir, int logerr);
30 29
 
31
-int submitstats(const char *clamdcfg, const struct cfgstruct *copt);
30
+int submitstats(const char *clamdcfg, const struct optstruct *opts);
32 31
 
33 32
 #endif
... ...
@@ -41,7 +41,7 @@
41 41
 #endif
42 42
 #include <string.h>
43 43
 
44
-#include "shared/cfgparser.h"
44
+#include "shared/optparser.h"
45 45
 #include "shared/output.h"
46 46
 #include "notify.h"
47 47
 
... ...
@@ -64,42 +64,42 @@ int notify(const char *cfgfile)
64 64
         struct sockaddr_in server2;
65 65
 	struct hostent *he;
66 66
 #endif
67
-	struct cfgstruct *copt;
68
-	const struct cfgstruct *cpt;
67
+	struct optstruct *opts;
68
+	const struct optstruct *opt;
69 69
 	int sockd, bread;
70 70
 	const char *socktype;
71 71
 
72 72
 
73
-    if((copt = getcfg(cfgfile, 1, OPT_CLAMD)) == NULL) {
73
+    if((opts = optparse(cfgfile, 0, NULL, 1, OPT_CLAMD, NULL)) == NULL) {
74 74
 	logg("^Clamd was NOT notified: Can't find or parse configuration file %s\n", cfgfile);
75 75
 	return 1;
76 76
     }
77 77
 
78 78
 #ifndef	C_WINDOWS
79
-    if((cpt = cfgopt(copt, "LocalSocket"))->enabled) {
79
+    if((opt = optget(opts, "LocalSocket"))->enabled) {
80 80
 	socktype = "UNIX";
81 81
 	server.sun_family = AF_UNIX;
82
-	strncpy(server.sun_path, cpt->strarg, sizeof(server.sun_path));
82
+	strncpy(server.sun_path, opt->strarg, sizeof(server.sun_path));
83 83
 	server.sun_path[sizeof(server.sun_path)-1]='\0';
84 84
 
85 85
 	if((sockd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
86
-	    logg("^Clamd was NOT notified: Can't create socket endpoint for %s\n", cpt->strarg);
86
+	    logg("^Clamd was NOT notified: Can't create socket endpoint for %s\n", opt->strarg);
87 87
 	    perror("socket()");
88
-	    freecfg(copt);
88
+	    optfree(opts);
89 89
 	    return 1;
90 90
 	}
91 91
 
92 92
 	if(connect(sockd, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) < 0) {
93 93
 	    closesocket(sockd);
94
-	    logg("^Clamd was NOT notified: Can't connect to clamd through %s\n", cpt->strarg);
94
+	    logg("^Clamd was NOT notified: Can't connect to clamd through %s\n", opt->strarg);
95 95
 	    perror("connect()");
96
-	    freecfg(copt);
96
+	    optfree(opts);
97 97
 	    return 1;
98 98
 	}
99 99
 
100 100
     } else
101 101
 #endif
102
-    if((cpt = cfgopt(copt, "TCPSocket"))->enabled) {
102
+    if((opt = optget(opts, "TCPSocket"))->enabled) {
103 103
 	socktype = "TCP";
104 104
 
105 105
 #ifdef HAVE_GETADDRINFO
... ...
@@ -110,11 +110,11 @@ int notify(const char *cfgfile)
110 110
 	hints.ai_family = AF_INET;
111 111
 #endif
112 112
 	hints.ai_socktype = SOCK_STREAM;
113
-	snprintf(port, 5, "%d", cpt->numarg);
113
+	snprintf(port, 5, "%d", opt->numarg);
114 114
 	port[5] = 0;
115 115
 
116
-	if((cpt = cfgopt(copt, "TCPAddr"))->enabled)
117
-	    addr = cpt->strarg;
116
+	if((opt = optget(opts, "TCPAddr"))->enabled)
117
+	    addr = opt->strarg;
118 118
 	else
119 119
 	    addr = NULL;
120 120
 
... ...
@@ -123,14 +123,14 @@ int notify(const char *cfgfile)
123 123
 	if(ret) {
124 124
 	    perror("getaddrinfo()");
125 125
 	    logg("^Clamd was NOT notified: Can't resolve hostname %s\n", addr ? addr : "");
126
-	    freecfg(copt);
126
+	    optfree(opts);
127 127
 	    return 1;
128 128
 	}
129 129
 
130 130
 	if((sockd = socket(res->ai_family, SOCK_STREAM, 0)) < 0) {
131 131
 	    perror("socket()");
132 132
 	    logg("^Clamd was NOT notified: Can't create TCP socket\n");
133
-	    freecfg(copt);
133
+	    optfree(opts);
134 134
 	    freeaddrinfo(res);
135 135
 	    return 1;
136 136
 	}
... ...
@@ -139,7 +139,7 @@ int notify(const char *cfgfile)
139 139
 	    perror("connect()");
140 140
 	    closesocket(sockd);
141 141
 	    logg("^Clamd was NOT notified: Can't connect to clamd on %s:%s\n", addr ? addr : "localhost", port);
142
-	    freecfg(copt);
142
+	    optfree(opts);
143 143
 	    freeaddrinfo(res);
144 144
 	    return 1;
145 145
 	}
... ...
@@ -150,18 +150,18 @@ int notify(const char *cfgfile)
150 150
 	if((sockd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
151 151
 	    logg("^Clamd was NOT notified: Can't create TCP socket\n");
152 152
 	    perror("socket()");
153
-	    freecfg(copt);
153
+	    optfree(opts);
154 154
 	    return 1;
155 155
 	}
156 156
 
157 157
 	server2.sin_family = AF_INET;
158
-	server2.sin_port = htons(cpt->numarg);
158
+	server2.sin_port = htons(opt->numarg);
159 159
 
160
-	if((cpt = cfgopt(copt, "TCPAddr"))->enabled) {
161
-	    if((he = gethostbyname(cpt->strarg)) == 0) {
160
+	if((opt = optget(opts, "TCPAddr"))->enabled) {
161
+	    if((he = gethostbyname(opt->strarg)) == 0) {
162 162
 		perror("gethostbyname()");
163
-		logg("^Clamd was NOT notified: Can't resolve hostname '%s'\n", cpt->strarg);
164
-		freecfg(copt);
163
+		logg("^Clamd was NOT notified: Can't resolve hostname '%s'\n", opt->strarg);
164
+		optfree(opts);
165 165
 		closesocket(sockd);
166 166
 		return 1;
167 167
 	    }
... ...
@@ -175,7 +175,7 @@ int notify(const char *cfgfile)
175 175
 	    logg("^Clamd was NOT notified: Can't connect to clamd on %s:%d\n",
176 176
 		    inet_ntoa(server2.sin_addr), ntohs(server2.sin_port));
177 177
 	    perror("connect()");
178
-	    freecfg(copt);
178
+	    optfree(opts);
179 179
 	    return 1;
180 180
 	}
181 181
 
... ...
@@ -183,7 +183,7 @@ int notify(const char *cfgfile)
183 183
 
184 184
     } else {
185 185
 	logg("^Clamd was NOT notified: No socket specified in %s\n", cfgfile);
186
-	freecfg(copt);
186
+	optfree(opts);
187 187
 	return 1;
188 188
     }
189 189
 
... ...
@@ -191,7 +191,7 @@ int notify(const char *cfgfile)
191 191
 	logg("^Clamd was NOT notified: Could not write to %s socket\n", socktype);
192 192
 	perror("write()");
193 193
 	closesocket(sockd);
194
-	freecfg(copt);
194
+	optfree(opts);
195 195
 	return 1;
196 196
     }
197 197
 
... ...
@@ -201,13 +201,13 @@ int notify(const char *cfgfile)
201 201
 	if(!strstr(buff, "RELOADING")) {
202 202
 	    logg("^Clamd was NOT notified: Unknown answer from clamd: '%s'\n", buff);
203 203
 	    closesocket(sockd);
204
-	    freecfg(copt);
204
+	    optfree(opts);
205 205
 	    return 1;
206 206
 	}
207 207
 
208 208
     closesocket(sockd);
209 209
     logg("Clamd successfully notified about the update.\n");
210
-    freecfg(copt);
210
+    optfree(opts);
211 211
     return 0;
212 212
 }
213 213
 
... ...
@@ -19,8 +19,6 @@
19 19
 #ifndef __NOTIFY_H
20 20
 #define __NOTIFY_H
21 21
 
22
-#include "shared/cfgparser.h"
23
-
24 22
 int notify(const char *cfgfile);
25 23
 
26 24
 #endif
... ...
@@ -66,11 +66,24 @@ static const struct clam_option {
66 66
 } clam_options[] = {
67 67
     /* name,   longopt, sopt, argtype, regex, num, str, mul, owner, description, suggested */
68 68
 
69
-    { NULL, "help", 'h', OPT_BOOL, NULL, 0, NULL, 0, OPT_CLAMD, "", "" },
69
+    /* cmdline only */
70
+    { NULL, "help", 'h', OPT_BOOL, NULL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM, "", "" },
70 71
     { NULL, "config-file", 'c', OPT_STRING, NULL, 0, CONFDIR"/clamd.conf", 0, OPT_CLAMD, "", "" },
71
-    { NULL, "version", 'V', OPT_BOOL, NULL, 0, NULL, 0, OPT_CLAMD, "", "" },
72
-    { NULL, "debug", 0, OPT_BOOL, NULL, 0, NULL, 0, OPT_CLAMD, "", "" },
73
-
72
+    { NULL, "config-file", 0, OPT_STRING, NULL, 0, CONFDIR"/freshclam.conf", 0, OPT_FRESHCLAM, "", "" },
73
+    { NULL, "version", 'V', OPT_BOOL, NULL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM, "", "" },
74
+    { NULL, "debug", 0, OPT_BOOL, NULL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM, "", "" },
75
+    { NULL, "verbose", 'v', OPT_BOOL, NULL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
76
+    { NULL, "quiet", 0, OPT_BOOL, NULL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
77
+    { NULL, "no-warnings", 0, OPT_BOOL, NULL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
78
+    { NULL, "stdout", 0, OPT_BOOL, NULL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
79
+    { NULL, "daemon", 'd', OPT_BOOL, NULL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
80
+    { NULL, "no-dns", 0, OPT_BOOL, NULL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
81
+    { NULL, "http-proxy", 0, OPT_STRING, NULL, 0, NULL, 0, OPT_FRESHCLAM | OPT_DEPRECATED, "", "" },
82
+    { NULL, "proxy-user", 0, OPT_STRING, NULL, 0, NULL, 0, OPT_FRESHCLAM | OPT_DEPRECATED, "", "" },
83
+    { NULL, "list-mirrors", 0, OPT_BOOL, NULL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
84
+    { NULL, "submit-stats", 0, OPT_STRING, NULL, 0, CONFDIR"/clamd.conf", 0, OPT_FRESHCLAM, "", "" }, /* Don't merge this one with SubmitDetectionStats */
85
+
86
+    /* config file/cmdline options */
74 87
     { "LogFile", "log", 'l', OPT_STRING, NULL, -1, NULL, 0, OPT_CLAMD | OPT_MILTER, "Save all reports to a log file.", "/tmp/clamav.log" },
75 88
 
76 89
     { "LogFileUnlock", NULL, 0, OPT_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_MILTER, "By default the log file is locked for writing and only a single\ndaemon process can write to it. This option disables the lock.", "no" },
... ...
@@ -87,11 +100,11 @@ static const struct clam_option {
87 87
 
88 88
     { "LogFacility", NULL, 0, OPT_STRING, NULL, -1, "LOG_LOCAL6", 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER, "Type of syslog messages.\nPlease refer to 'man syslog' for the facility names.", "LOG_MAIL" },
89 89
 
90
-    { "PidFile", NULL, 0, OPT_STRING, NULL, -1, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER, "Save the process ID to a file.", "/var/run/clamd.pid" },
90
+    { "PidFile", "pid", 'p', OPT_STRING, NULL, -1, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER, "Save the process ID to a file.", "/var/run/clamd.pid" },
91 91
 
92 92
     { "TemporaryDirectory", NULL, 0, OPT_STRING, NULL, -1, NULL, 0, OPT_CLAMD | OPT_MILTER, "This option allows you to change the default temporary directory.", "/tmp" },
93 93
 
94
-    { "DatabaseDirectory", NULL, 0, OPT_STRING, NULL, -1, DATADIR, 0, OPT_CLAMD | OPT_FRESHCLAM, "This option allows you to change the default database directory.\nIf you enable it, please make sure it points to the same directory in\nboth clamd and freshclam.", "/var/lib/clamav" },
94
+    { "DatabaseDirectory", "datadir", 0, OPT_STRING, NULL, -1, DATADIR, 0, OPT_CLAMD | OPT_FRESHCLAM, "This option allows you to change the default database directory.\nIf you enable it, please make sure it points to the same directory in\nboth clamd and freshclam.", "/var/lib/clamav" },
95 95
 
96 96
     { "LocalSocket", NULL, 0, OPT_STRING, NULL, -1, NULL, 0, OPT_CLAMD, "Path to a local socket file the daemon will listen on.", "/tmp/clamd.socket" },
97 97
 
... ...
@@ -222,11 +235,11 @@ static const struct clam_option {
222 222
     /* Freshclam-only entries */
223 223
 
224 224
     /* FIXME: drop this entry and use LogFile */
225
-    { "UpdateLogFile", NULL, 0, OPT_STRING, NULL, -1, NULL, 0, OPT_FRESHCLAM, "Save all reports to a log file.", "/var/log/freshclam.log" },
225
+    { "UpdateLogFile", "log", 'l', OPT_STRING, NULL, -1, NULL, 0, OPT_FRESHCLAM, "Save all reports to a log file.", "/var/log/freshclam.log" },
226 226
 
227 227
     { "DatabaseOwner", NULL, 0, OPT_STRING, NULL, -1, CLAMAVUSER, 0, OPT_FRESHCLAM, "When started by root freshclam will drop privileges and switch to the user\ndefined in this option.", CLAMAVUSER },
228 228
 
229
-    { "Checks", NULL, 0, OPT_NUMBER, MATCH_NUMBER, 12, NULL, 0, OPT_FRESHCLAM, "This option defined how many times daily freshclam should check for\na database update.", "24" },
229
+    { "Checks", "checks", 'c', OPT_NUMBER, MATCH_NUMBER, 12, NULL, 0, OPT_FRESHCLAM, "This option defined how many times daily freshclam should check for\na database update.", "24" },
230 230
 
231 231
     { "DNSDatabaseInfo", NULL, 0, OPT_STRING, NULL, -1, "current.cvd.clamav.net", 0, OPT_FRESHCLAM, "Use DNS to verify the virus database version. Freshclam uses DNS TXT records\nto verify the versions of the database and software itself. With this\ndirective you can change the database verification domain.\nWARNING: Please don't change it unless you're configuring freshclam to use\nyour own database verification domain.", "current.cvd.clamav.net" },
232 232
 
... ...
@@ -252,16 +265,16 @@ static const struct clam_option {
252 252
 
253 253
     { "HTTPUserAgent", NULL, 0, OPT_STRING, NULL, -1, NULL, 0, OPT_FRESHCLAM, "If your servers are behind a firewall/proxy which does a User-Agent\nfiltering you can use this option to force the use of a different\nUser-Agent header.", "default" },
254 254
 
255
-    { "NotifyClamd", NULL, 0, OPT_STRING, NULL, -1, NULL, 0, OPT_FRESHCLAM, "Send the RELOAD command to clamd after a successful update.", "yes" },
255
+    { "NotifyClamd", "daemon-notify", 0, OPT_STRING, NULL, -1, CONFDIR"/clamd.conf", 0, OPT_FRESHCLAM, "Send the RELOAD command to clamd after a successful update.", "yes" },
256 256
 
257
-    { "OnUpdateExecute", NULL, 0, OPT_STRING, NULL, -1, NULL, 0, OPT_FRESHCLAM, "Run a command after a successful database update.", "command" },
257
+    { "OnUpdateExecute", "on-update-execute", 0, OPT_STRING, NULL, -1, NULL, 0, OPT_FRESHCLAM, "Run a command after a successful database update.", "command" },
258 258
 
259
-    { "OnErrorExecute", NULL, 0, OPT_STRING, NULL, -1, NULL, 0, OPT_FRESHCLAM, "Run a command when a database update error occurs.", "command" },
259
+    { "OnErrorExecute", "on-error-execute", 0, OPT_STRING, NULL, -1, NULL, 0, OPT_FRESHCLAM, "Run a command when a database update error occurs.", "command" },
260 260
 
261
-    { "OnOutdatedExecute", NULL, 0, OPT_STRING, NULL, -1, NULL, 0, OPT_FRESHCLAM, "Run a command when freshclam reports an outdated version.\nIn the command string %v will be replaced with the new version number.", "command" },
261
+    { "OnOutdatedExecute", "on-outdated-execute", 0, OPT_STRING, NULL, -1, NULL, 0, OPT_FRESHCLAM, "Run a command when freshclam reports an outdated version.\nIn the command string %v will be replaced with the new version number.", "command" },
262 262
 
263 263
     /* FIXME: MATCH_IPADDR */
264
-    { "LocalIPAddress", NULL, 0, OPT_STRING, NULL, -1, NULL, 0, OPT_FRESHCLAM, "With this option you can provide a client address for the database downlading.\nUseful for multi-homed systems.", "aaa.bbb.ccc.ddd" },
264
+    { "LocalIPAddress", "local-address", 'a', OPT_STRING, NULL, -1, NULL, 0, OPT_FRESHCLAM, "With this option you can provide a client address for the database downlading.\nUseful for multi-homed systems.", "aaa.bbb.ccc.ddd" },
265 265
 
266 266
     { "ConnectTimeout", NULL, 0, OPT_NUMBER, MATCH_NUMBER, 30, NULL, 0, OPT_FRESHCLAM, "Timeout in seconds when connecting to database server.", "30" },
267 267
 
... ...
@@ -461,6 +474,9 @@ static int optaddarg(struct optstruct *opts, const char *name, const char *strar
461 461
 	    h->nextarg = new;
462 462
 	}
463 463
     } else {
464
+	if(pt->active)
465
+	    return 0;
466
+
464 467
 	if(strarg) {
465 468
 	    pt->strarg = strdup(strarg);
466 469
 	    if(!pt->strarg) {
... ...
@@ -544,7 +560,7 @@ struct optstruct *optparse(const char *cfgfile, int argc, char * const *argv, in
544 544
 			return NULL;
545 545
 		    }
546 546
 		    longopts[lc].name = optentry->longopt;
547
-		    if(optentry->argtype == OPT_BOOL)
547
+		    if(optentry->argtype == OPT_BOOL || optentry->strarg)
548 548
 			longopts[lc].has_arg = 2;
549 549
 		    else
550 550
 			longopts[lc].has_arg = 1;
... ...
@@ -738,6 +754,8 @@ struct optstruct *optparse(const char *cfgfile, int argc, char * const *argv, in
738 738
 	numarg = -1;
739 739
 	switch(optentry->argtype) {
740 740
 	    case OPT_STRING:
741
+		if(!arg)
742
+		    arg = optentry->strarg;
741 743
 		if(!cfgfile && !strlen(arg)) {
742 744
 		    if(optentry->shortopt)
743 745
 			fprintf(stderr, "ERROR: Option --%s (-%c) requires a non-empty string argument\n", optentry->longopt, optentry->shortopt);