diff --git a/lib/conffile.c b/lib/conffile.c index 9ed74ba1..d7b67e82 100644 --- a/lib/conffile.c +++ b/lib/conffile.c @@ -1,4 +1,5 @@ -/* $Id: conffile.c,v 1.10 1997/03/24 03:56:30 fritz Exp $ +/* $Id: conffile.c,v 1.11 1997/04/03 22:39:11 luethje Exp $ + * * ISDN accounting for isdn4linux. * * Copyright 1996 by Stefan Luethje (luethje@sl-gw.lake.de) @@ -18,6 +19,10 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: conffile.c,v $ + * Revision 1.11 1997/04/03 22:39:11 luethje + * bug fixes: environ variables are working again, no seg. 11 :-) + * improved performance for reading the config files. + * * Revision 1.10 1997/03/24 03:56:30 fritz * Fixed 2 typos * @@ -68,6 +73,7 @@ static const char *Pre_String(int Level); static int Compare_Sections(section* sec1, section *sec2, char **variables); static section *Insert_Section(section **main_sec, section **ins_sec, char **variables, int flags); static int Merge_Sections(section **main_sec, section **ins_sec, char **variables, int flags); +static int Append_Sections(section **main_sec, section *app_sec); static int Find_Include(section **Section, char* String, const char *FileName, int Flags); static section* _Get_Section_From_Path(char **array, section* Section, section **RetSection, entry **RetEntry, int flags); static entry* _Get_Entry_From_Path(char **array, entry* Entry, section **RetSection, entry **RetEntry, int flags); @@ -199,8 +205,11 @@ static section *Read_Lines(section *Section, FILE *fp, const char *FileName, int char String[BUFSIZ]; char *Sectionname, *Variable, *Value; int Res; + int InInclude = 0; section *Ptr = Section; + if (Section != NULL) + InInclude = 1; while (FGets(String, BUFSIZ, fp, Line) != NULL) { @@ -264,7 +273,7 @@ static section *Read_Lines(section *Section, FILE *fp, const char *FileName, int print_msg("Error in file `%s', line %d: there is no valid token!\n",FileName,*Line); } - if (InSubSection != 0) + if (InInclude == 0 && InSubSection != 0) { print_msg("Error in file `%s': Missing a `%c'!\n",FileName,C_END_SUBSECTION); free_section(Section); @@ -879,6 +888,17 @@ static char** Compare_Section_Get_Path(char **array, int *retsize, int *retdepth /****************************************************************************/ +static int Append_Sections(section **main_sec, section *app_sec) +{ + while(*main_sec != NULL) + main_sec = &((*main_sec)->next); + + *main_sec = app_sec; + return 0; +} + +/****************************************************************************/ + static int Merge_Sections(section **main_sec, section **ins_sec, char **variables, int flags) { if (main_sec == NULL) @@ -937,27 +957,13 @@ static void free_cfile(cfile **cfiles) /****************************************************************************/ -/* filenum gibt an, aus wievielen Dateien gelesen werden soll. Die Dateinamen - sind dann in files zu finden. Wenn filnum == -1, dann muss der letzte Eintrag - von files[x] == NULL sein. - variable wird benoetigt, um eine Section eindeutig zu identifizieren zu - koennen. Da viele Sections in der Regel den gleichen Namen verwenden - (z. B. [NUMBER], [MSN]), muessen die einzelnen Eintraege ja eindeutig - erkannt werden koennen, wie es ein Key bei einer Datenbank kann. Dieses - kann dann ueber die Eintraege gemacht werden koennen (z.B. NUMBER=0815). - Wenn man in variables nun z.B. "NUMBER" uebergibt, wird sichergestellt, - das nur einmal ein Eintrag NUMBER=1234 unter allen Sectionen [NUMBER] - existiert. Dieses wird benoetigt, wenn es mehrere Config-Dateien gibt, die - durchsucht/eingelesen werden muessen. Z.B. /etc/isdn/isdn.conf, ~/.isdn. - In dieser Reihenfolge sollte auch die Variable files belegt sein (von - globalen runter zu lokalen Configdateien. - Die Variable flags sollte _immer_ auf 'C_OVERWRITE|C_NOT_UNIQUE' gesetzt +/* Die Variable flags sollte _immer_ auf 'C_OVERWRITE|C_NOT_UNIQUE' gesetzt werden, anderes macht hier zur Zeit keinen Sinn. main_sec darf _NIE_ unintilisiert sein und muss beim ersten mal NULL enthlten!!!! */ -int read_files(section **main_sec, char** files, char **variables, int flags) +int read_files(section **main_sec, char** files, int *fileflag, char **variables, int flags) { int newread = 0; static cfile **cfiles = NULL; @@ -994,6 +1000,7 @@ int read_files(section **main_sec, char** files, char **variables, int flags) return -1; } + cfiles[i]->flag = fileflag[i]; cfiles[i]->name = strdup(files[i]); cfiles[i]->modtime = FileStat.st_mtime; } @@ -1045,7 +1052,14 @@ int read_files(section **main_sec, char** files, char **variables, int flags) else { if ((ins_sec = read_file(NULL,cfiles[i]->name,flags)) != NULL) - Merge_Sections(main_sec,&ins_sec,variables,flags); + switch(cfiles[i]->flag) + { + case APPEND_FILE: Append_Sections(main_sec,ins_sec); + break; + case MERGE_FILE : + default : Merge_Sections(main_sec,&ins_sec,variables,flags); + break; + } } } } @@ -1469,7 +1483,10 @@ int _Get_Type_Value(section *Section, char *Path, int Type, void **Pointer) while (RetCode == -1 && (Ptr = Get_Value(Section,Path)) != NULL) + { RetCode = Set_Ret_Code(Ptr,Type,Pointer); + Section = NULL; + } return RetCode; } diff --git a/lib/conffile.h b/lib/conffile.h index 85cf7538..7ce85977 100644 --- a/lib/conffile.h +++ b/lib/conffile.h @@ -1,9 +1,9 @@ -/* $Id: conffile.h,v 1.4 1997/03/20 00:28:01 luethje Exp $ +/* $Id: conffile.h,v 1.5 1997/04/03 22:39:12 luethje Exp $ * * ISDN accounting for isdn4linux. * - * Copyright 1995, 1996 by Andreas Kool (akool@Kool.f.EUnet.de) + * Copyright 1995, 1996 Stefan Luethje (luethje@sl-gw.lake.de) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,6 +20,10 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: conffile.h,v $ + * Revision 1.5 1997/04/03 22:39:12 luethje + * bug fixes: environ variables are working again, no seg. 11 :-) + * improved performance for reading the config files. + * * Revision 1.4 1997/03/20 00:28:01 luethje * Inserted lines into the files for the revision tool. * @@ -76,6 +80,11 @@ /****************************************************************************/ +#define MERGE_FILE 0 +#define APPEND_FILE 1 + +/****************************************************************************/ + #define Get_Type_Match(a,b,c,d,e,f) _Get_Type_Match(a,b,c,d,e,(void**)f) #define Get_Type_Value(a,b,c,d) _Get_Type_Value(a,b,c,(void**)d) @@ -101,6 +110,7 @@ typedef struct _section { typedef struct _cfiles { char* name; int modtime; + int flag; } cfile; /****************************************************************************/ @@ -122,7 +132,7 @@ _EXTERN section *Del_Section(section **Section, char *Sectionname); _EXTERN section *Set_SubSection(section *Section, char *Variable, section *SubSection, int Flag); _EXTERN void set_print_fct_for_conffile(int (*new_print_msg)(const char *, ...)); _EXTERN void free_section(section *Ptr); -_EXTERN int read_files(section **main_sec, char** files, char **variables, int flags); +_EXTERN int read_files(section **main_sec, char** files, int *fileflag, char **variables, int flags); _EXTERN int Filter_Sections(section **sec, char** path); _EXTERN section* Get_Section_Match(section* Section, char *Path, char* Value, int (*_match)(char*, char*), entry **RetEntry); _EXTERN char *Get_Value(section *Section, char *Path); diff --git a/lib/isdntools.c b/lib/isdntools.c index 2a1b2938..0dc84eaa 100644 --- a/lib/isdntools.c +++ b/lib/isdntools.c @@ -1,8 +1,8 @@ -/* $Id: isdntools.c,v 1.7 1997/03/20 00:19:27 luethje Exp $ +/* $Id: isdntools.c,v 1.8 1997/04/03 22:39:13 luethje Exp $ * * ISDN accounting for isdn4linux. (Utilities) * - * Copyright 1995, 1997 by Andreas Kool (akool@Kool.f.EUnet.de) + * Copyright 1995, 1997 and Stefan Luethje (luethje@sl-gw.lake.de) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,6 +19,10 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: isdntools.c,v $ + * Revision 1.8 1997/04/03 22:39:13 luethje + * bug fixes: environ variables are working again, no seg. 11 :-) + * improved performance for reading the config files. + * * Revision 1.7 1997/03/20 00:19:27 luethje * inserted the line #include in avmb1/avmcapictrl.c and imon/imon.c, * some bugfixes, new structure in isdnlog/isdnrep/isdnrep.c. @@ -306,7 +310,7 @@ char *expand_file(char *s) strcat(file,strchr(s,C_SLASH)); } - return file; + return (file[0] == '\0'?s:file); } /****************************************************************************/ @@ -413,20 +417,21 @@ int Set_Codes(section* Section) entry *Entry; char *ptr2; char s[SHORT_STRING_SIZE]; + section *SPtr; for (i=0; i < _MAX_VARS; i++) if (ptr[i] != NULL) free(ptr[i]); - if ((Section = Get_Section(Section,CONF_SEC_GLOBAL)) == NULL) + if ((SPtr = Get_Section(Section,CONF_SEC_GLOBAL)) == NULL) return -1; #ifdef LIBAREA - if ((Entry = Get_Entry(Section->entries,CONF_ENT_AREALIB)) != NULL && + if ((Entry = Get_Entry(SPtr->entries,CONF_ENT_AREALIB)) != NULL && Entry->value != NULL ) ptr[0] = acFileName = strdup(Entry->value); #else - if ((Entry = Get_Entry(Section->entries,CONF_ENT_AVONLIB)) != NULL && + if ((Entry = Get_Entry(SPtr->entries,CONF_ENT_AVONLIB)) != NULL && Entry->value != NULL ) ptr[0] = avonlib = strdup(Entry->value); else @@ -436,7 +441,7 @@ int Set_Codes(section* Section) } #endif - if ((Entry = Get_Entry(Section->entries,CONF_ENT_AREA)) != NULL && + if ((Entry = Get_Entry(SPtr->entries,CONF_ENT_AREA)) != NULL && Entry->value != NULL ) { ptr2 = Entry->value; @@ -452,7 +457,7 @@ int Set_Codes(section* Section) print_msg("Error: Variable `%s' are not set!\n",CONF_ENT_AREA); } - if ((Entry = Get_Entry(Section->entries,CONF_ENT_COUNTRY)) != NULL && + if ((Entry = Get_Entry(SPtr->entries,CONF_ENT_COUNTRY)) != NULL && Entry->value != NULL ) { ptr2 = Entry->value; @@ -470,9 +475,9 @@ int Set_Codes(section* Section) print_msg("Error: Variable `%s' are not set!\n",CONF_ENT_COUNTRY); } - if ((Section = Get_Section(Section,CONF_SEC_VAR)) != NULL) + if ((SPtr = Get_Section(Section,CONF_SEC_VAR)) != NULL) { - Entry = Section->entries; + Entry = SPtr->entries; while(Entry != NULL) { @@ -667,6 +672,8 @@ int read_conffiles(section **Section, char *groupfile) auto char s[6][BUFSIZ]; auto char **vars = NULL; auto char **files = NULL; + auto int fileflag[6]; + auto int i = 0; auto int RetCode = -1; *Section = NULL; @@ -683,16 +690,20 @@ int read_conffiles(section **Section, char *groupfile) return -1; append_element(&files,s[0]); + fileflag[i++] = MERGE_FILE; append_element(&files,s[1]); + fileflag[i++] = APPEND_FILE; if (groupfile != NULL) { strcpy(s[2],groupfile); append_element(&files,s[2]); + fileflag[i++] = MERGE_FILE; } strcpy(s[3],expand_file(USERCONFFILE)); append_element(&files,s[3]); + fileflag[i++] = MERGE_FILE; } sprintf(s[4],"%s|%s/%s|!%s",CONF_SEC_MSN,CONF_SEC_NUM,CONF_ENT_NUM,CONF_ENT_SI); @@ -703,7 +714,7 @@ int read_conffiles(section **Section, char *groupfile) append_element(&vars,s[5]); */ - if ((RetCode = read_files(&conf_dat, files, vars, C_OVERWRITE|C_NOT_UNIQUE|C_NO_WARN_FILE)) > 0) + if ((RetCode = read_files(&conf_dat, files, fileflag, vars, C_OVERWRITE|C_NOT_UNIQUE|C_NO_WARN_FILE)) > 0) { *Section = conf_dat;