]> git.ipfire.org Git - thirdparty/sarg.git/blame - getconf.c
Add support to decompress xz files
[thirdparty/sarg.git] / getconf.c
CommitLineData
25697a35 1/*
94ff9470 2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
110ce984 3 * 1998, 2015
25697a35
GS
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
1164c474
FM
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
25697a35
GS
9 * ---------------------------------------------------------------------
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
24 *
25 */
26
27#include "include/conf.h"
5f3cfd1d 28#include "include/defs.h"
6068ae56 29#include "include/filelist.h"
25697a35 30
085c1e1f
FM
31#define SET_LIST(list) list,sizeof(list)/sizeof(list[0])
32
da94b2c7
FM
33//! The configuration file from which the graph option was loaded
34char GraphConfigFile[MAXLEN]="";
35
36//! How many include directives were followed.
37static int IncludeLevel=0;
38
25697a35 39extern numlist hours, weekdays;
6068ae56 40extern FileListObject AccessLog;
2e29ae23
FM
41extern int PerUserLimitsNumber;
42extern struct PerUserLimitStruct PerUserLimits[MAX_USER_LIMITS];
0b5356bb 43extern enum PerUserFileCreationEnum PerUserFileCreation;
66f507aa 44extern char ImageDir[MAXLEN];
137eb63d
FM
45extern FileListObject UserAgentLog;
46extern bool UserAgentFromCmdLine;
36a0b94c 47extern char StripUserSuffix[MAX_USER_LEN];
2c058416 48extern int StripSuffixLen;
25697a35 49
085c1e1f
FM
50struct param_list
51{
9bd92830
FM
52 //! The name of the value of the parameter.
53 const char *name;
54 //! The bit to set if the value is found.
55 unsigned long int value;
56 //! The value is invalid if any bit of this mask is set in the parameter.
57 unsigned long int exclude;
085c1e1f
FM
58};
59
15d5372b
FM
60struct sort_list
61{
9bd92830
FM
62 //! The name of the value of the parameter.
63 const char *name;
64 //! The bit to set if the value is found.
65 unsigned long int value;
15d5372b
FM
66};
67
0b5356bb
FM
68struct select_list
69{
70 //! The name of the value of the parameter.
71 const char *name;
72 //! The value to assign when the name is selected.
73 int value;
74};
75
e43854ef 76static struct param_list report_type_values[]=
085c1e1f 77{
9bd92830
FM
78 {"users_sites",REPORT_TYPE_USERS_SITES,0},
79 {"topusers",REPORT_TYPE_TOPUSERS,0},
80 {"topsites",REPORT_TYPE_TOPSITES,0},
81 {"sites_users",REPORT_TYPE_SITES_USERS,0},
82 {"date_time",REPORT_TYPE_DATE_TIME,0},
83 {"denied",REPORT_TYPE_DENIED,0},
84 {"auth_failures",REPORT_TYPE_AUTH_FAILURES,0},
85 {"site_user_time_date",REPORT_TYPE_SITE_USER_TIME_DATE,0},
86 {"downloads",REPORT_TYPE_DOWNLOADS,0},
34ad8e64 87 {"user_agent",REPORT_TYPE_USERAGENT,0},
085c1e1f
FM
88};
89
e43854ef 90static struct param_list data_field_values[]=
085c1e1f 91{
9bd92830
FM
92 {"user",DATA_FIELD_USER,0},
93 {"date",DATA_FIELD_DATE,0},
94 {"time",DATA_FIELD_TIME,0},
95 {"url",DATA_FIELD_URL,0},
96 {"connect",DATA_FIELD_CONNECT,0},
97 {"bytes",DATA_FIELD_BYTES,0},
98 {"in_cache",DATA_FIELD_IN_CACHE,0},
99 {"out_cache",DATA_FIELD_OUT_CACHE,0},
100 {"elapsed",DATA_FIELD_ELAPSED,0},
085c1e1f
FM
101};
102
e43854ef 103static struct param_list topuserfields_values[]=
085c1e1f 104{
9bd92830
FM
105 {"NUM",TOPUSERFIELDS_NUM,0},
106 {"DATE_TIME",TOPUSERFIELDS_DATE_TIME,0},
107 {"USERID",TOPUSERFIELDS_USERID,0},
8e134f1a 108 {"USERIP",TOPUSERFIELDS_USERIP,0},
9bd92830
FM
109 {"CONNECT",TOPUSERFIELDS_CONNECT,0},
110 {"BYTES",TOPUSERFIELDS_BYTES,0},
111 {"%BYTES",TOPUSERFIELDS_SETYB,0},
112 {"SETYB",TOPUSERFIELDS_SETYB,0},
113 {"IN-CACHE-OUT",TOPUSERFIELDS_IN_CACHE_OUT,0},
114 {"USED_TIME",TOPUSERFIELDS_USED_TIME,0},
115 {"MILISEC",TOPUSERFIELDS_MILISEC,0},
116 {"%TIME",TOPUSERFIELDS_PTIME,0},
117 {"TOTAL",TOPUSERFIELDS_TOTAL,0},
118 {"AVERAGE",TOPUSERFIELDS_AVERAGE,0},
085c1e1f
FM
119};
120
e43854ef 121static struct param_list userreportfields_values[]=
085c1e1f 122{
9bd92830
FM
123 {"CONNECT",USERREPORTFIELDS_CONNECT,0},
124 {"BYTES",USERREPORTFIELDS_BYTES,0},
125 {"%BYTES",USERREPORTFIELDS_SETYB,0},
126 {"SETYB",USERREPORTFIELDS_SETYB,0},
127 {"IN-CACHE-OUT",USERREPORTFIELDS_IN_CACHE_OUT,0},
128 {"USED_TIME",USERREPORTFIELDS_USED_TIME,0},
129 {"MILISEC",USERREPORTFIELDS_MILISEC,0},
130 {"%TIME",USERREPORTFIELDS_PTIME,0},
131 {"TOTAL",USERREPORTFIELDS_TOTAL,0},
132 {"AVERAGE",USERREPORTFIELDS_AVERAGE,0},
085c1e1f
FM
133};
134
e43854ef 135static struct param_list index_values[]=
0349fa24 136{
9bd92830
FM
137 {"yes",INDEX_YES,~INDEX_YES},
138 {"no",INDEX_NO,~INDEX_NO},
139 {"only",INDEX_ONLY,~INDEX_ONLY},
0349fa24
FM
140};
141
e43854ef 142static struct param_list index_tree_values[]=
0349fa24 143{
9bd92830
FM
144 {"date",INDEX_TREE_DATE,~INDEX_TREE_DATE},
145 {"file",INDEX_TREE_FILE,~INDEX_TREE_FILE},
0349fa24
FM
146};
147
9aaa3361
FM
148static struct param_list indexfields_values[]=
149{
150 {"DIRSIZE",INDEXFIELDS_DIRSIZE,0},
151};
152
e43854ef 153static struct param_list ntml_userformat_values[]=
f2ec8c75 154{
9bd92830
FM
155 {"user",NTLMUSERFORMAT_USER,~NTLMUSERFORMAT_USER},
156 {"domainname+username",NTLMUSERFORMAT_DOMAINUSER,~NTLMUSERFORMAT_DOMAINUSER},
f2ec8c75
FM
157};
158
e43854ef 159static struct param_list recnouser_values[]=
f2ec8c75 160{
9bd92830
FM
161 {"ip",RECORDWITHOUTUSER_IP,~RECORDWITHOUTUSER_IP},
162 {"ignore",RECORDWITHOUTUSER_IGNORE,~RECORDWITHOUTUSER_IGNORE},
163 {"everybody",RECORDWITHOUTUSER_EVERYBODY,~RECORDWITHOUTUSER_EVERYBODY},
f2ec8c75
FM
164};
165
e43854ef 166static struct param_list datafileurl_values[]=
f84a35a3 167{
9bd92830
FM
168 {"ip",DATAFILEURL_IP,~DATAFILEURL_IP},
169 {"name",DATAFILEURL_NAME,~DATAFILEURL_NAME},
f84a35a3
FM
170};
171
e43854ef
FM
172static struct param_list displayvalue_values[]=
173{
9bd92830
FM
174 {"bytes",DISPLAY_BYTES,~DISPLAY_BYTES},
175 {"abbreviation",DISPLAY_ABBREV,~DISPLAY_ABBREV},
e43854ef
FM
176};
177
43cc1649
FM
178static struct param_list datetime_values[]=
179{
9bd92830
FM
180 {"elap",DATETIME_ELAP,0},
181 {"bytes",DATETIME_BYTE,0},
43cc1649
FM
182};
183
71d78774
FM
184static struct param_list realtime_unauth_values[]=
185{
9bd92830
FM
186 {"show",REALTIME_UNAUTH_REC_SHOW,~REALTIME_UNAUTH_REC_SHOW},
187 {"ignore",REALTIME_UNAUTH_REC_IGNORE,~REALTIME_UNAUTH_REC_IGNORE},
71d78774
FM
188};
189
15d5372b
FM
190struct sort_list topuser_sort[]=
191{
9bd92830
FM
192 {"BYTES",TOPUSER_SORT_BYTES},
193 {"USER",TOPUSER_SORT_USER},
194 {"CONNECT",TOPUSER_SORT_CONNECT},
195 {"TIME",TOPUSER_SORT_TIME},
15d5372b
FM
196};
197
198struct sort_list topsite_sort[]=
199{
9bd92830
FM
200 {"BYTES",TOPSITE_SORT_BYTES},
201 {"CONNECT",TOPSITE_SORT_CONNECT},
202 {"TIME",TOPSITE_SORT_TIME},
7d82ea1a 203 {"USER",TOPSITE_SORT_USER},
15d5372b
FM
204};
205
206struct sort_list user_sort[]=
207{
9bd92830
FM
208 {"BYTES",USER_SORT_BYTES},
209 {"SITE",USER_SORT_SITE},
210 {"CONNECT",USER_SORT_CONNECT},
211 {"TIME",USER_SORT_TIME},
15d5372b
FM
212};
213
0b5356bb
FM
214static struct select_list per_user_limit_create_file[]=
215{
216 {"always",PUFC_Always}, //always create an empty file
217 {"as_required",PUFC_AsRequired}, //create the file if necessary (no empty file is created)
218};
219
6e792ade 220static int is_param(const char *param,const char *buf)
0a4e18e1 221{
9bd92830 222 int plen;
0a4e18e1 223
9bd92830
FM
224 plen=strlen(param);
225 if (strncmp(buf,param,plen) != 0) return(0);
226 buf+=plen;
227 if ((unsigned char)*buf>' ') return(0);
228 return(1);
0a4e18e1
FM
229}
230
4af2f8ff
FM
231static int getparam_string(const char *param,char *buf,char *value,int value_size)
232{
9bd92830
FM
233 int plen;
234
235 plen=strlen(param);
236 if (strncmp(buf,param,plen) != 0) return(0);
237 buf+=plen;
238 if ((unsigned char)*buf>' ') return(0);
239 while (*buf && (unsigned char)*buf<=' ') buf++;
240
241 if (strlen(buf)>=value_size) {
af961877 242 debuga(__FILE__,__LINE__,_("The string value of parameter \"%s\" is too long\n"),param);
9bd92830
FM
243 exit(EXIT_FAILURE);
244 }
245 strcpy(value,buf);
246 fixnone(value);
247 return(1);
4af2f8ff 248}
25697a35 249
6068ae56
FM
250/*!
251 * Get a pointer to the beginning of the string value defined by the
252 * parameter. The returned value is NULL if the buffer doesn't contain
253 * the parameter.
254 *
255 * \param param The parameter to look for.
256 * \param buf The buffer containing the line read from the configuration
257 * file.
258 *
259 * \return A pointer to the beginning of the parameter value or NULL if
137eb63d 260 * the line is not for the requested parameter.
6068ae56
FM
261 */
262static char *getparam_stringptr(const char *param,char *buf)
263{
264 int plen;
265
266 plen=strlen(param);
267 if (strncmp(buf,param,plen) != 0) return(NULL);
268 buf+=plen;
269 if ((unsigned char)*buf>' ') return(NULL);
270 while (*buf && (unsigned char)*buf<=' ') buf++;
271
272 return(buf);
273}
274
4af2f8ff 275static int getparam_quoted(const char *param,char *buf,char *value,int value_size)
25697a35 276{
9bd92830
FM
277 int plen;
278 int i;
279
280 plen=strlen(param);
281 if (strncmp(buf,param,plen) != 0) return(0);
282 buf+=plen;
283 if ((unsigned char)*buf>' ') return(0);
284 while (*buf && (unsigned char)*buf<=' ') buf++;
285
286 if (*buf != '\"') {
af961877 287 debuga(__FILE__,__LINE__,_("Missing double quote after parameter \"%s\"\n"),param);
9bd92830
FM
288 exit(EXIT_FAILURE);
289 }
290 buf++;
291
292 value_size--;
293 for (i=0 ; i<value_size && *buf && *buf!='\"' ; i++) {
294 value[i]=*buf++;
295 }
296 value[i]='\0';
297
298 if (*buf != '\"') {
af961877 299 debuga(__FILE__,__LINE__,_("Missing double quote after parameter \"%s\" or value is more than %d bytes long\n"),param,value_size);
9bd92830
FM
300 exit(EXIT_FAILURE);
301 }
302 fixnone(value);
303 return(1);
4af2f8ff 304}
25697a35 305
4af2f8ff
FM
306static int getparam_2words(const char *param,char *buf,char *word1,int word1_size,char *word2,int word2_size)
307{
9bd92830
FM
308 int plen;
309 int i;
310
311 plen=strlen(param);
312 if (strncmp(buf,param,plen) != 0) return(0);
313 buf+=plen;
314 if ((unsigned char)*buf>' ') return(0);
315 while (*buf && (unsigned char)*buf<=' ') buf++;
316
317 for (i=0 ; i<word1_size && *buf && (unsigned char)*buf>' ' ; i++)
318 word1[i]=*buf++;
319 if (i>=word1_size) {
af961877 320 debuga(__FILE__,__LINE__,_("The first word of parameter \"%s\" is more than %d bytes long\n"),param,word1_size-1);
9bd92830
FM
321 exit(EXIT_FAILURE);
322 }
323 if (*buf!=' ') {
af961877 324 debuga(__FILE__,__LINE__,_("Missing second word for parameter \"%s\"\n"),param);
9bd92830
FM
325 exit(EXIT_FAILURE);
326 }
327 word1[i]=0;
328
329 while (*buf && (unsigned char)*buf<=' ') buf++;
330
331 for (i=0 ; i<word2_size && *buf && (unsigned char)*buf>' ' ; i++)
332 word2[i]=*buf++;
333 if (i>=word2_size) {
af961877 334 debuga(__FILE__,__LINE__,_("The second word of parameter \"%s\" is more than %d bytes long\n"),param,word2_size-1);
9bd92830
FM
335 exit(EXIT_FAILURE);
336 }
337 word2[i]=0;
338
339 fixnone(word1);
340 fixnone(word2);
341 return(1);
4af2f8ff 342}
25697a35 343
4af2f8ff
FM
344static int getparam_int(const char *param,char *buf,int *value)
345{
9bd92830
FM
346 int plen;
347 int next;
348
349 plen=strlen(param);
350 if (strncmp(buf,param,plen) != 0) return(0);
351 buf+=plen;
352 if ((unsigned char)*buf>' ') return(0);
353 while (*buf && (unsigned char)*buf<=' ') buf++;
354
355 next=0;
356 if (sscanf(buf,"%d%n",value,&next) != 1 || (unsigned char)buf[next] > ' ') {
af961877 357 debuga(__FILE__,__LINE__,_("The integer value of parameter \"%s\" is invalid\n"),param);
9bd92830
FM
358 exit(EXIT_FAILURE);
359 }
360 return(1);
4af2f8ff 361}
25697a35 362
06b39c87 363static int getparam_bool(const char *param,char *buf,bool *value)
246c8489 364{
9bd92830
FM
365 int plen;
366 int i;
367 const char *bool_str="yes,true,on,1";
368
369 plen=strlen(param);
370 if (strncmp(buf,param,plen) != 0) return(0);
371 buf+=plen;
372 if ((unsigned char)*buf>' ') return(0);
373 while (*buf && (unsigned char)*buf<=' ') buf++;
374
375 *value=false;
376 for ( ; *bool_str ; bool_str+=i) {
377 for (i=0 ; bool_str[i] && bool_str[i]!=',' ; i++);
378 if (strncasecmp(bool_str,buf,i)==0) {
379 *value=true;
380 break;
381 }
382 if (bool_str[i]==',') i++;
383 }
384 return(1);
246c8489
FM
385}
386
085c1e1f
FM
387static int getparam_list(const char *param,struct param_list *options,int noptions,char *buf,unsigned long int *value)
388{
9bd92830
FM
389 int plen;
390 char *str;
391 int i;
392
393 plen=strlen(param);
394 if (strncmp(buf,param,plen) != 0) return(0);
395 buf+=plen;
396 if ((unsigned char)*buf>' ') return(0);
397 while (*buf && (unsigned char)*buf<=' ') buf++;
398
399 *value=0UL;
400 while (*buf) {
401 str=buf;
402 while (*str && (unsigned char)*str>' ' && *str!=';') str++;
403 if (*str) {
404 *str++='\0';
405 while (*str && ((unsigned char)*str<=' ' || *str==';')) str++;
406 }
407 for (i=0 ; i<noptions && strcasecmp(buf,options[i].name) ; i++);
408 if (i>=noptions) {
af961877 409 debuga(__FILE__,__LINE__,_("Unknown value \"%s\" for parameter \"%s\"\n"),buf,param);
9bd92830
FM
410 exit(EXIT_FAILURE);
411 }
412 if ((*value & options[i].exclude)!=0) {
af961877 413 debuga(__FILE__,__LINE__,_("Value \"%s\" conflicts with other selected values for parameter \"%s\"\n"),buf,param);
9bd92830
FM
414 exit(EXIT_FAILURE);
415 }
416 *value|=options[i].value;
417 buf=str;
418 }
419 return(1);
085c1e1f
FM
420}
421
15d5372b
FM
422static int getparam_sort(const char *param,struct sort_list *options,int noptions,char *buf,unsigned long int *value)
423{
9bd92830
FM
424 int plen;
425 char *str, *order;
426 int i;
427
428 plen=strlen(param);
429 if (strncmp(buf,param,plen) != 0) return(0);
430 buf+=plen;
431 if ((unsigned char)*buf>' ') return(0);
432 while (*buf && (unsigned char)*buf<=' ') buf++;
433
434 str=buf;
435 order=NULL;
436 while (*str && (unsigned char)*str>' ') str++;
437 if (*str) {
438 *str++='\0';
439 while (*str && (unsigned char)*str<=' ') str++;
440 order=str;
441 }
442 for (i=0 ; i<noptions && strcasecmp(buf,options[i].name) ; i++);
443 if (i>=noptions) {
af961877 444 debuga(__FILE__,__LINE__,_("Unknown sort criterion \"%s\" for parameter \"%s\"\n"),buf,param);
9bd92830
FM
445 exit(EXIT_FAILURE);
446 }
447 *value=options[i].value;
448
449 if (order) {
450 str=order;
451 while (*str && (unsigned char)*str>' ') str++;
452 if (*str) {
453 *str++='\0';
454 while (*str && (unsigned char)*str<=' ') str++;
455 }
456 if (strcasecmp(order,"reverse")==0 || strcasecmp(order,"D")==0) {
457 *value|=SORT_REVERSE;
458 } else if (strcasecmp(order,"normal")!=0 && strcasecmp(order,"A")!=0) {
af961877 459 debuga(__FILE__,__LINE__,_("Unknown sort order \"%s\" for parameter \"%s\"\n"),order,param);
9bd92830
FM
460 exit(EXIT_FAILURE);
461 }
462 }
463
464 buf=str;
465 return(1);
15d5372b
FM
466}
467
0b5356bb
FM
468static int getparam_select(const char *param,struct select_list *options,int noptions,char *buf,int *value)
469{
470 int plen;
471 char *str;
472 int i;
473
474 plen=strlen(param);
475 if (strncmp(buf,param,plen) != 0) return(0);
476 buf+=plen;
477 if ((unsigned char)*buf>' ') return(0);
478 while (*buf && (unsigned char)*buf<=' ') buf++;
479
480 str=buf;
481 while (*buf && (unsigned char)*buf>' ' && *buf!=';') buf++;
482 *buf='\0';
483 for (i=0 ; i<noptions && strcasecmp(str,options[i].name) ; i++);
484 if (i>=noptions) {
af961877 485 debuga(__FILE__,__LINE__,_("Unknown value \"%s\" for parameter \"%s\"\n"),str,param);
0b5356bb
FM
486 exit(EXIT_FAILURE);
487 }
488 *value=options[i].value;
489 return(1);
490}
491
2e29ae23
FM
492static int getparam_userlimit(const char *param,char *buf)
493{
494 int plen;
495 char *file_begin,*file_end;
496 int limit;
497 int digit;
3877d630
FM
498 char *str;
499 int i;
500 enum PerUserOutputEnum output;
501 const struct
502 {
503 const char *name;
504 enum PerUserOutputEnum value;
505 } output_types[]=
506 {
507 {"id",PUOE_UserId},
508 {"ip",PUOE_UserIp},
509 };
2e29ae23
FM
510
511 plen=strlen(param);
512 if (strncmp(buf,param,plen) != 0) return(0);
513 buf+=plen;
514 if ((unsigned char)*buf>' ') return(0);
515 while (*buf && (unsigned char)*buf<=' ') buf++;
516
517 /*
518 options are made of a file name, an integer limit and an optional
519 integer flag. The file name may contain spaces. We keep searching
520 until a valid number is found after a space.
521 */
522 file_begin=buf;
523 do {
524 while (*buf && (unsigned char)*buf>' ') buf++;
525 if (*buf!=' ') {
af961877 526 debuga(__FILE__,__LINE__,_("Missing limit in per_user_limit\n"));
2e29ae23
FM
527 exit(EXIT_FAILURE);
528 }
529 file_end=buf;
530 while (*buf && (unsigned char)*buf<=' ') buf++;
531 limit=0;
532 while (*buf && isdigit(*buf)) {
533 digit=*buf-'0';
534 if (limit>=(INT_MAX-digit)/10) break;
535 limit=limit*10+digit;
536 buf++;
537 }
538 } while (*buf && *buf!=' ');
539
3877d630 540 output=PUOE_UserId;
2e29ae23
FM
541 if (*buf==' ') {
542 while (*buf && (unsigned char)*buf<=' ') buf++;
3877d630
FM
543 str=buf;
544 while (*buf && (unsigned char)*buf>' ') buf++;
545 *buf='\0';
546 for (i=sizeof(output_types)/sizeof(output_types[0])-1 ; i>=0 ; i--)
547 if (strcasecmp(output_types[i].name,str)==0) {
548 output=output_types[i].value;
549 break;
550 }
551 if (i<0) {
af961877 552 debuga(__FILE__,__LINE__,_("Invalid output type in per_user_limit\n"));
2e29ae23
FM
553 exit(EXIT_FAILURE);
554 }
2e29ae23
FM
555 }
556
557 if (PerUserLimitsNumber>=MAX_USER_LIMITS) {
af961877 558 debuga(__FILE__,__LINE__,_("Too many per_user_limit\n"));
2e29ae23
FM
559 exit(EXIT_FAILURE);
560 }
561 *file_end='\0';
562 safe_strcpy(PerUserLimits[PerUserLimitsNumber].File,file_begin,sizeof(PerUserLimits[PerUserLimitsNumber].File));
563 PerUserLimits[PerUserLimitsNumber].Limit=limit;
3877d630 564 PerUserLimits[PerUserLimitsNumber].Output=output;
2e29ae23
FM
565 PerUserLimitsNumber++;
566
567 return(1);
568}
569
26810f86
FM
570static void ccharset(char *CharSet)
571{
572 if (strcmp(CharSet,"Latin2") == 0) strcpy(CharSet,"ISO-8859-2");
573 else if (strcmp(CharSet,"Latin3") == 0) strcpy(CharSet,"ISO-8859-3");
574 else if (strcmp(CharSet,"Latin4") == 0) strcpy(CharSet,"ISO-8859-4");
575 else if (strcmp(CharSet,"Cyrillic") == 0) strcpy(CharSet,"ISO-8859-5");
576 else if (strcmp(CharSet,"Arabic") == 0) strcpy(CharSet,"ISO-8859-6");
577 else if (strcmp(CharSet,"Greek") == 0) strcpy(CharSet,"ISO-8859-7");
578 else if (strcmp(CharSet,"Hebrew") == 0) strcpy(CharSet,"ISO-8859-8");
579 else if (strcmp(CharSet,"Latin5") == 0) strcpy(CharSet,"ISO-8859-9");
580 else if (strcmp(CharSet,"Latin6") == 0) strcpy(CharSet,"ISO-8859-10");
581 else if (strcmp(CharSet,"Japan") == 0) strcpy(CharSet,"EUC-JP");
582 else if (strcmp(CharSet,"Koi8-r") == 0) strcpy(CharSet,"KOI8-R");
583 /*
584 * Any other encoding name is left unchanged.
585 */
586 return;
587}
588
da94b2c7 589static void parmtest(char *buf,const char *File)
4af2f8ff 590{
9bd92830
FM
591 char wbuf[2048];
592 struct getwordstruct gwarea;
0b5356bb 593 int iVal;
25697a35 594
9bd92830 595 while (*buf && (unsigned char)*buf<=' ') buf++;
25697a35 596
9bd92830
FM
597 if(*buf == '#' || *buf == '\0')
598 return;
25697a35 599
cb59dc47 600 if(debugz>=LogLevel_Process)
9bd92830 601 printf(_("SARG: TAG: %s\n"),buf);
25697a35 602
9bd92830 603 if (getparam_string("background_color",buf,BgColor,sizeof(BgColor))>0) return;
25697a35 604
9bd92830 605 if (getparam_string("text_color",buf,TxColor,sizeof(TxColor))>0) return;
25697a35 606
9bd92830 607 if (getparam_string("text_bgcolor",buf,TxBgColor,sizeof(TxBgColor))>0) return;
25697a35 608
9bd92830 609 if (getparam_string("title_color",buf,TiColor,sizeof(TiColor))>0) return;
25697a35 610
9bd92830 611 if (getparam_string("logo_image",buf,LogoImage,sizeof(LogoImage))>0) return;
25697a35 612
9bd92830 613 if (getparam_quoted("logo_text",buf,LogoText,sizeof(LogoText))>0) return;
25697a35 614
9bd92830 615 if (getparam_string("logo_text_color",buf,LogoTextColor,sizeof(LogoTextColor))>0) return;
25697a35 616
9bd92830 617 if (getparam_string("background_image",buf,BgImage,sizeof(BgImage))>0) return;
25697a35 618
9bd92830 619 if (getparam_bool("show_sarg_info",buf,&ShowSargInfo)>0) return;
25697a35 620
9bd92830 621 if (getparam_bool("show_sarg_logo",buf,&ShowSargLogo)>0) return;
25697a35 622
9bd92830 623 if (getparam_string("font_face",buf,FontFace,sizeof(FontFace))>0) return;
25697a35 624
9bd92830 625 if (getparam_string("header_color",buf,HeaderColor,sizeof(HeaderColor))>0) return;
25697a35 626
9bd92830 627 if (getparam_string("header_bgcolor",buf,HeaderBgColor,sizeof(HeaderBgColor))>0) return;
25697a35 628
9bd92830 629 if (getparam_string("font_size",buf,FontSize,sizeof(FontSize))>0) return;
25697a35 630
9bd92830 631 if (getparam_string("header_font_size",buf,HeaderFontSize,sizeof(HeaderFontSize))>0) return;
25697a35 632
9bd92830 633 if (getparam_string("title_font_size",buf,TitleFontSize,sizeof(TitleFontSize))>0) return;
25697a35 634
9bd92830 635 if (getparam_2words("image_size",buf,Width,sizeof(Width),Height,sizeof(Height))>0) return;
25697a35 636
9bd92830 637 if (getparam_quoted("title",buf,Title,sizeof(Title))>0) return;
25697a35 638
51b166d4
FM
639 if (strncasecmp(buf,"resolve_ip",10)==0) {
640 if (ip2name_config(buf+10)>0) return;
641 }
25697a35 642
9bd92830 643 if (getparam_bool("user_ip",buf,&UserIp)>0) return;
4af2f8ff 644
9bd92830 645 if (getparam_string("max_elapsed",buf,MaxElapsed,sizeof(MaxElapsed))>0) return;
25697a35 646
9bd92830
FM
647 if (is_param("date_format",buf)) {
648 getword_start(&gwarea,buf);
649 if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
af961877 650 debuga(__FILE__,__LINE__,_("Invalid record in \"date_format\" parameter\n"));
9bd92830
FM
651 exit(EXIT_FAILURE);
652 }
81a022d8 653 DateFormat=gwarea.current[0];
9bd92830
FM
654 return;
655 }
25697a35 656
9bd92830
FM
657 if (is_param("hours",buf)) {
658 if( getnumlist( buf, &hours, 24, 24 ) ) {
af961877 659 debuga(__FILE__,__LINE__,_("Error: Invalid syntax in hours tag!\n"));
9bd92830
FM
660 exit( 1 );
661 }
662 return;
663 }
25697a35 664
9bd92830
FM
665 if (is_param("weekdays",buf)) {
666 if( getnumlist( buf, &weekdays, 7, 7 ) ) {
af961877 667 debuga(__FILE__,__LINE__,_("Error: Invalid syntax in weekdays tag!\n"));
9bd92830
FM
668 exit( 1 );
669 }
670 return;
671 }
25697a35 672
9bd92830 673 if (getparam_sort("topuser_sort_field",SET_LIST(topuser_sort),buf,&TopuserSort)>0) return;
25697a35 674
9bd92830 675 if (getparam_sort("user_sort_field",SET_LIST(user_sort),buf,&UserSort)>0) return;
25697a35 676
9bd92830
FM
677 if (is_param("access_log",buf)>0) {
678 if (AccessLogFromCmdLine==0) {
6068ae56
FM
679 char *FileName=getparam_stringptr("access_log",buf);
680 if (!AccessLog)
681 AccessLog=FileList_Create();
682 if (!FileList_AddFile(AccessLog,FileName)) {
af961877 683 debuga(__FILE__,__LINE__,_("Not enough memory to store the input log file names\n"));
9bd92830
FM
684 exit(EXIT_FAILURE);
685 }
9bd92830
FM
686 }
687 return;
688 }
25697a35 689
9bd92830
FM
690 if (is_param("redirector_log",buf)>0) {
691 if (RedirectorLogFromCmdLine==0) {
692 if (NRedirectorLogs>=MAX_REDIRECTOR_LOGS) {
af961877 693 debuga(__FILE__,__LINE__,_("Too many redirector log files in configuration file\n"));
9bd92830
FM
694 exit(EXIT_FAILURE);
695 }
696 getparam_string("redirector_log",buf,RedirectorLogs[NRedirectorLogs],MAX_REDIRECTOR_FILELEN);
697 NRedirectorLogs++;
698 }
699 return;
700 }
1f482a8d 701
137eb63d
FM
702 if (is_param("useragent_log",buf)>0) {
703 if (!UserAgentFromCmdLine) {
704 if (!UserAgentLog)
705 UserAgentLog=FileList_Create();
706 char *FileName=getparam_stringptr("useragent_log",buf);
707 if (!FileList_AddFile(UserAgentLog,FileName)) {
708 debuga(__FILE__,__LINE__,_("Not enough memory to store a user agent file name\n"));
709 exit(EXIT_FAILURE);
710 }
711 }
712 return;
713 }
25697a35 714
9bd92830 715 if (getparam_string("exclude_hosts",buf,ExcludeHosts,sizeof(ExcludeHosts))>0) return;
25697a35 716
9bd92830 717 if (getparam_string("exclude_codes",buf,ExcludeCodes,sizeof(ExcludeCodes))>0) return;
25697a35 718
9bd92830 719 if (getparam_string("exclude_users",buf,ExcludeUsers,sizeof(ExcludeUsers))>0) return;
25697a35 720
9bd92830 721 if (getparam_string("password",buf,PasswdFile,sizeof(PasswdFile))>0) return;
25697a35 722
9bd92830 723 if (getparam_string("temporary_dir",buf,TempDir,sizeof(TempDir))>0) return;
25697a35 724
9bd92830 725 if (getparam_list("report_type",SET_LIST(report_type_values),buf,&ReportType)>0) return;
25697a35 726
9bd92830 727 if (getparam_string("output_dir",buf,OutputDir,sizeof(OutputDir))>0) return;
25697a35 728
829a53c2
FM
729 if (getparam_bool("anonymous_output_files",buf,&AnonymousOutputFiles)>0) return;
730
9bd92830 731 if (getparam_string("output_email",buf,OutputEmail,sizeof(OutputEmail))>0) return;
25697a35 732
2e29ae23 733 if (getparam_userlimit("per_user_limit",buf)>0) return;
25697a35 734
0b5356bb
FM
735 if (getparam_select("per_user_limit_file_create",SET_LIST(per_user_limit_create_file),buf,&iVal)>0) {
736 PerUserFileCreation=(enum PerUserFileCreationEnum)iVal;
737 return;
738 }
739
9bd92830 740 if (getparam_int("lastlog",buf,&LastLog)>0) return;
25697a35 741
9bd92830 742 if (getparam_bool("remove_temp_files",buf,&RemoveTempFiles)>0) return;
25697a35 743
9bd92830 744 if (getparam_string("replace_index",buf,ReplaceIndex,sizeof(ReplaceIndex))>0) return;
25697a35 745
9bd92830 746 if (getparam_list("index_tree",SET_LIST(index_tree_values),buf,&IndexTree)>0) return;
25697a35 747
9bd92830 748 if (getparam_list("index",SET_LIST(index_values),buf,&Index)>0) return;
25697a35 749
9aaa3361
FM
750 if (getparam_list("index_fields",SET_LIST(indexfields_values),buf,&IndexFields)>0) return;
751
9bd92830 752 if (getparam_bool("overwrite_report",buf,&OverwriteReport)>0) return;
25697a35 753
9bd92830 754 if (getparam_list("records_without_userid",SET_LIST(recnouser_values),buf,&RecordsWithoutUser)>0) return;
25697a35 755
9bd92830 756 if (getparam_bool("use_comma",buf,&UseComma)>0) return;
25697a35 757
9bd92830 758 if (getparam_string("mail_utility",buf,MailUtility,sizeof(MailUtility))>0) return;
25697a35 759
9bd92830 760 if (getparam_int("topsites_num",buf,&TopSitesNum)>0) return;
25697a35 761
9bd92830 762 if (getparam_int("topuser_num",buf,&TopUsersNum)>0) return;
25697a35 763
9bd92830 764 if (getparam_string("usertab",buf,UserTabFile,sizeof(UserTabFile))>0) return;
25697a35 765
9bd92830 766 if (getparam_string("index_sort_order",buf,IndexSortOrder,sizeof(IndexSortOrder))>0) return;
25697a35 767
9bd92830 768 if (getparam_sort("topsites_sort_order",SET_LIST(topsite_sort),buf,&TopsitesSort)>0) return;
25697a35 769
9bd92830 770 if (getparam_bool("long_url",buf,&LongUrl)>0) return;
25697a35 771
9bd92830 772 if (getparam_string("dansguardian_conf",buf,DansGuardianConf,sizeof(DansGuardianConf))>0) return;
25697a35 773
9bd92830 774 if (getparam_string("squidguard_conf",buf,SquidGuardConf,sizeof(SquidGuardConf))>0) return;
25697a35 775
9bd92830 776 if (getparam_list("date_time_by",SET_LIST(datetime_values),buf,&datetimeby)>0) return;
25697a35 777
9bd92830
FM
778 if (getparam_string("charset",buf,CharSet,sizeof(CharSet))>0) {
779 ccharset(CharSet);
780 return;
781 }
25697a35 782
9bd92830 783 if (getparam_quoted("user_invalid_char",buf,UserInvalidChar,sizeof(UserInvalidChar))>0) return;
25697a35 784
9bd92830
FM
785 if (getparam_quoted("include_users",buf,IncludeUsers+1,sizeof(IncludeUsers)-2)>0) {
786 IncludeUsers[0]=':';
787 strcat(IncludeUsers,":");
788 return;
789 }
491b862f 790
9bd92830 791 if (getparam_quoted("exclude_string",buf,ExcludeString,sizeof(ExcludeString))>0) return;
25697a35 792
9bd92830 793 if (getparam_bool("privacy",buf,&Privacy)>0) return;
25697a35 794
9bd92830 795 if (getparam_quoted("privacy_string",buf,PrivacyString,sizeof(PrivacyString))>0) return;
25697a35 796
9bd92830 797 if (getparam_string("privacy_string_color",buf,PrivacyStringColor,sizeof(PrivacyStringColor))>0) return;
25697a35 798
9bd92830 799 if (getparam_bool("show_successful_message",buf,&SuccessfulMsg)>0) return;
25697a35 800
9bd92830 801 if (getparam_bool("show_read_statistics",buf,&ShowReadStatistics)>0) return;
25697a35 802
2f4787e6
FM
803 if (getparam_bool("show_read_percent",buf,&ShowReadPercent)>0) return;
804
9bd92830 805 if (getparam_list("topuser_fields",SET_LIST(topuserfields_values),buf,&TopUserFields)>0) return;
25697a35 806
9bd92830 807 if (getparam_bool("bytes_in_sites_users_report",buf,&BytesInSitesUsersReport)>0) return;
25697a35 808
9bd92830 809 if (getparam_list("user_report_fields",SET_LIST(userreportfields_values),buf,&UserReportFields)>0) return;
25697a35 810
9bd92830 811 if (getparam_string("datafile",buf,DataFile,sizeof(DataFile))>0) return;
25697a35 812
9bd92830 813 if (getparam_quoted("datafile_delimiter",buf,DataFileDelimiter,sizeof(DataFileDelimiter))>0) return;
25697a35 814
9bd92830 815 if (getparam_list("datafile_fields",SET_LIST(data_field_values),buf,&DataFileFields)>0) return;
25697a35 816
9bd92830 817 if (getparam_list("datafile_url",SET_LIST(datafileurl_values),buf,&DataFileUrl)>0) return;
25697a35 818
9bd92830 819 if (getparam_string("parsed_output_log",buf,ParsedOutputLog,sizeof(ParsedOutputLog))>0) return;
25697a35 820
9bd92830 821 if (getparam_string("parsed_output_log_compress",buf,ParsedOutputLogCompress,sizeof(ParsedOutputLogCompress))>0) return;
25697a35 822
9bd92830 823 if (getparam_list("displayed_values",SET_LIST(displayvalue_values),buf,&DisplayedValues)>0) return;
25697a35 824
9bd92830 825 if (getparam_int("authfail_report_limit",buf,&AuthfailReportLimit)>0) return;
25697a35 826
9bd92830 827 if (getparam_int("denied_report_limit",buf,&DeniedReportLimit)>0) return;
25697a35 828
9bd92830 829 if (getparam_int("siteusers_report_limit",buf,&SiteUsersReportLimit)>0) return;
25697a35 830
9bd92830 831 if (getparam_int("dansguardian_report_limit",buf,&DansGuardianReportLimit)>0) return;
25697a35 832
9bd92830 833 if (getparam_int("squidguard_report_limit",buf,&SquidGuardReportLimit)>0) return;
25697a35 834
9bd92830 835 if (getparam_int("user_report_limit",buf,&UserReportLimit)>0) return;
491b862f 836
9bd92830 837 if (getparam_int("download_report_limit",buf,&DownloadReportLimit)>0) return;
491b862f 838
9bd92830 839 if (getparam_string("www_document_root",buf,wwwDocumentRoot,sizeof(wwwDocumentRoot))>0) return;
25697a35 840
9bd92830 841 if (getparam_string("block_it",buf,BlockIt,sizeof(BlockIt))>0) return;
491b862f 842
9bd92830 843 if (getparam_string("external_css_file",buf,ExternalCSSFile,sizeof(ExternalCSSFile))>0) return;
491b862f 844
9bd92830 845 if (getparam_bool("user_authentication",buf,&UserAuthentication)>0) return;
491b862f 846
9bd92830 847 if (getparam_string("AuthUserTemplateFile",buf,wbuf,sizeof(wbuf))>0) {
9bd92830
FM
848 if (is_absolute(wbuf)) {
849 if (strlen(wbuf)>=sizeof(AuthUserTemplateFile)) {
af961877 850 debuga(__FILE__,__LINE__,_("Template file name is too long in parameter \"AuthUserTemplateFile\"\n"));
9bd92830
FM
851 exit(EXIT_FAILURE);
852 }
a87d4d11 853 safe_strcpy(AuthUserTemplateFile,wbuf,sizeof(AuthUserTemplateFile));
9bd92830 854 } else {
da94b2c7
FM
855 char dir[MAXLEN];
856
857 safe_strcpy(dir,File,sizeof(dir));
9bd92830 858 if (snprintf(AuthUserTemplateFile,sizeof(AuthUserTemplateFile),"%s/%s",dirname(dir),wbuf)>=sizeof(AuthUserTemplateFile)) {
af961877 859 debuga(__FILE__,__LINE__,_("Template file name is too long in parameter \"AuthUserTemplateFile\"\n"));
9bd92830
FM
860 exit(EXIT_FAILURE);
861 }
862 }
863 return;
864 }
4af2f8ff 865
9bd92830
FM
866 if (is_param("download_suffix",buf)) {
867 char warea[MAXLEN];
6e792ade 868
9bd92830
FM
869 getparam_quoted("download_suffix",buf,warea,sizeof(warea));
870 set_download_suffix(warea);
871 return;
872 }
d6e703cc 873
8ddc656a
FM
874 if (getparam_bool("graphs",buf,&Graphs)>0) {
875#ifndef HAVE_GD
876 if (Graphs)
af961877 877 debugaz(__FILE__,__LINE__,_("No graphs available as sarg was not compiled with libgd. Set \"graphs\" to \"no\" in %s to disable this warning\n"),
da94b2c7 878 File);
8ddc656a 879#endif
da94b2c7 880 safe_strcpy(GraphConfigFile,File,sizeof(GraphConfigFile));
8ddc656a
FM
881 return;
882 }
4af2f8ff 883
9bd92830 884 if (getparam_string("graph_days_bytes_bar_color",buf,GraphDaysBytesBarColor,sizeof(GraphDaysBytesBarColor))>0) return;
4af2f8ff 885
9bd92830
FM
886 if (getparam_string("redirector_log_format",buf,RedirectorLogFormat,sizeof(RedirectorLogFormat))>0) return;
887 if (getparam_string("squidguard_log_format",buf,RedirectorLogFormat,sizeof(RedirectorLogFormat))>0) {
af961877 888 debuga(__FILE__,__LINE__,_("squidguard_log_format is deprecated and has been replaced by redirector_log_format. Please update your configuration file.\n"));
9bd92830
FM
889 return;
890 }
4af2f8ff 891
9bd92830
FM
892 if (getparam_bool("redirector_filter_out_date",buf,&RedirectorFilterOutDate)>0) return;
893 if (getparam_bool("redirector_ignore_date",buf,&RedirectorFilterOutDate)>0) {
894 /*
895 Due to an old bug in sarg before version 2.3, the option was having the opposite action than implied by the name.
896 */
af961877 897 debuga(__FILE__,__LINE__,_("redirector_ignore_date is deprecated and has been replaced by redirector_filter_out_date that does the action implied by its name as opposed to redirector_ignore_date. Please update your configuration file.\n"));
9bd92830
FM
898 RedirectorFilterOutDate=!RedirectorFilterOutDate;
899 return;
900 }
901 if (getparam_bool("squidguard_ignore_date",buf,&RedirectorFilterOutDate)>0) {
af961877 902 debuga(__FILE__,__LINE__,_("squidguard_ignore_date is deprecated and has been replaced by redirector_filter_out_date that does the action implied by its name as opposed to squidguard_ignore_date. Please update your configuration file.\n"));
9bd92830
FM
903 RedirectorFilterOutDate=!RedirectorFilterOutDate;
904 return;
905 }
4af2f8ff 906
9bd92830
FM
907 if (getparam_bool("dansguardian_filter_out_date",buf,&DansguardianFilterOutDate)>0) return;
908 if (getparam_bool("dansguardian_ignore_date",buf,&DansguardianFilterOutDate)>0) {
af961877 909 debuga(__FILE__,__LINE__,_("dansguardian_ignore_date is deprecated and has been replaced by dansguardian_filter_out_date that does the action implied by its name as opposed to dansguardian_ignore_date. Please update your configuration file.\n"));
9bd92830
FM
910 DansguardianFilterOutDate=!DansguardianFilterOutDate;
911 return;
912 }
4af2f8ff 913
9bd92830 914 if (getparam_string("ulimit",buf,Ulimit,sizeof(Ulimit))>0) return;
4af2f8ff 915
9bd92830 916 if (getparam_list("ntlm_user_format",SET_LIST(ntml_userformat_values),buf,&NtlmUserFormat)>0) return;
4af2f8ff 917
2c058416
FM
918 if (getparam_string("strip_user_suffix",buf,StripUserSuffix,sizeof(StripUserSuffix))>0) {
919 StripSuffixLen=strlen(StripUserSuffix);
920 return;
921 }
36a0b94c 922
9bd92830 923 if (getparam_string("realtime_types",buf,RealtimeTypes,sizeof(RealtimeTypes))>0) return;
4af2f8ff 924
9bd92830 925 if (getparam_list("realtime_unauthenticated_records",SET_LIST(realtime_unauth_values),buf,&RealtimeUnauthRec)>0) return;
4af2f8ff 926
9bd92830 927 if (getparam_int("realtime_refresh_time",buf,&realtime_refresh)>0) return;
4af2f8ff 928
9bd92830 929 if (getparam_int("realtime_access_log_lines",buf,&realtime_access_log_lines)>0) return;
4af2f8ff 930
9bd92830 931 if (getparam_string("LDAPHost",buf,LDAPHost,sizeof(LDAPHost))>0) return;
e3af0ae9 932
9bd92830 933 if (getparam_int("LDAPPort",buf,&LDAPPort)>0) return;
e3af0ae9 934
9bd92830 935 if (getparam_int("LDAPProtocolVersion",buf,&LDAPProtocolVersion)>0) return;
e3af0ae9 936
9bd92830 937 if (getparam_string("LDAPBindDN",buf,LDAPBindDN,sizeof(LDAPBindDN))>0) return;
e3af0ae9 938
9bd92830 939 if (getparam_string("LDAPBindPW",buf,LDAPBindPW,sizeof(LDAPBindPW))>0) return;
e3af0ae9 940
9bd92830 941 if (getparam_string("LDAPBaseSearch",buf,LDAPBaseSearch,sizeof(LDAPBaseSearch))>0) return;
e3af0ae9 942
9bd92830 943 if (getparam_string("LDAPFilterSearch",buf,LDAPFilterSearch,sizeof(LDAPFilterSearch))>0) return;
e3af0ae9 944
9bd92830 945 if (getparam_string("LDAPTargetAttr",buf,LDAPTargetAttr,sizeof(LDAPTargetAttr))>0) return;
e3af0ae9 946
fd75cd90
FM
947 if (getparam_string("LDAPNativeCharset",buf,LDAPNativeCharset,sizeof(LDAPNativeCharset))>0) return;
948
9bd92830 949 if (getparam_string("graph_font",buf,GraphFont,sizeof(GraphFont))>0) return;
3becf85c 950
9bd92830 951 if (getparam_string("sorttable",buf,SortTableJs,sizeof(SortTableJs))>0) return;
ea275279 952
22715352 953 if (getparam_string("hostalias",buf,HostAliasFile,sizeof(HostAliasFile))>0) return;
11767c6a 954
c4f0ea8f
FM
955 if (getparam_string("useralias",buf,UserAliasFile,sizeof(UserAliasFile))>0) return;
956
11767c6a 957 if (getparam_bool("keep_temp_log",buf,&KeepTempLog)>0) return;
4d62cb0a
FM
958
959 if (getparam_int("max_successive_log_errors",buf,&NumLogSuccessiveErrors)>0) return;
960
961 if (getparam_int("max_total_log_errors",buf,&NumLogTotalErrors)>0) return;
962
9bd92830
FM
963 if(strstr(buf,"squid24") != 0) {
964 squid24=true;
965 return;
966 }
4af2f8ff 967
9bd92830
FM
968 if(strstr(buf,"byte_cost") != 0) {
969 getword_start(&gwarea,buf);
970 if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
af961877 971 debuga(__FILE__,__LINE__,_("The \"byte_cost\" parameter of the configuration file is invalid\n"));
9bd92830
FM
972 exit(EXIT_FAILURE);
973 }
974 cost=atol(gwarea.current);
975 if (getword_multisep(wbuf,sizeof(wbuf),&gwarea,' ')<0) {
af961877 976 debuga(__FILE__,__LINE__,_("The \"byte_cost\" parameter of the configuration file is invalid\n"));
9bd92830
FM
977 exit(EXIT_FAILURE);
978 }
979 nocost=my_atoll(gwarea.current);
980 return;
981 }
4af2f8ff 982
66f507aa
FM
983 if (getparam_string("image_dir",buf,ImageDir,sizeof(ImageDir))>0) return;
984
9bd92830 985 printf(_("SARG: Unknown option %s\n"),buf);
d6e703cc
FM
986}
987
da94b2c7 988void getconf(const char *File)
d6e703cc 989{
9bd92830
FM
990 FILE *fp_in;
991 char buf[MAXLEN];
da94b2c7
FM
992 char IncludeFile[MAXLEN];
993
994 IncludeLevel++;
995 if (debug) {
996 if (IncludeLevel<=1)
997 debuga(__FILE__,__LINE__,_("Loading configuration file \"%s\"\n"),File);
998 else
999 debuga(__FILE__,__LINE__,_("Including configuration file \"%s\"\n"),File);
1000 }
d6e703cc 1001
da94b2c7
FM
1002 // stop if include files are producing a loop
1003 if (IncludeLevel>5) {
1004 debuga(__FILE__,__LINE__,_("Too many nested configuration files included in \"%s\""),ConfigFile);
1005 exit(EXIT_FAILURE);
1006 }
d6e703cc 1007
da94b2c7
FM
1008 if ((fp_in = fopen(File, "r")) == NULL) {
1009 debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),File,strerror(errno));
9bd92830
FM
1010 exit(EXIT_FAILURE);
1011 }
d6e703cc 1012
9bd92830
FM
1013 while (fgets(buf, sizeof(buf), fp_in) != NULL) {
1014 fixendofline(buf);
d6e703cc 1015
da94b2c7
FM
1016 if (getparam_string("include",buf,IncludeFile,sizeof(IncludeFile))>0) {
1017 getconf(IncludeFile);
1018 continue;
1019 }
1020
4246ae8d 1021 if (debugz>=LogLevel_Data)
9bd92830 1022 printf("SYSCONFDIR %s\n",buf);
d6e703cc 1023
da94b2c7 1024 parmtest(buf,File);
9bd92830 1025 }
d6e703cc 1026
204781f4 1027 if (fclose(fp_in)==EOF) {
da94b2c7 1028 debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),File,strerror(errno));
204781f4
FM
1029 exit(EXIT_FAILURE);
1030 }
da94b2c7 1031 IncludeLevel--;
25697a35 1032}