From fa05d6b60f168eb403ce056c90caaa04e2986469 Mon Sep 17 00:00:00 2001 From: luethje Date: Mon, 3 Mar 1997 22:05:37 +0000 Subject: [PATCH] merging of the current version and my tree --- lib/Makefile.in | 1 + lib/conffile.c | 295 +++++++++++++++++++++++----------------------- lib/conffile.h | 16 ++- lib/isdntools.c | 115 +++++++++++++++--- lib/libisdn.h | 33 ++++-- lib/libtools.c | 20 +++- lib/libtools.h | 21 +--- scripts/config.in | 5 +- scripts/defconfig | 3 +- 9 files changed, 298 insertions(+), 211 deletions(-) diff --git a/lib/Makefile.in b/lib/Makefile.in index 32473bc7..ce6e66e2 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -34,6 +34,7 @@ config: @echo '#include "../scripts/autoconf.h"' >> policy.h @echo '#define I4LCONFDIR CONFIG_I4LCONFDIR' >> policy.h @echo '#define CONFFILE CONFIG_CONFFILE' >> policy.h +# @echo '#define CALLERIDFILE CONFIG_CALLERIDFILE' >> policy.h @echo '#define USERCONFFILE CONFIG_USERCONFFILE' >> policy.h @echo '#define RUNDIR CONFIG_RUNDIR' >> policy.h @echo '#define S_COUNTRY_PRFIX CONFIG_COUNTRY_PREFIX' >> policy.h diff --git a/lib/conffile.c b/lib/conffile.c index a9d27037..270a6731 100644 --- a/lib/conffile.c +++ b/lib/conffile.c @@ -1,3 +1,4 @@ + /* * ISDN accounting for isdn4linux. * @@ -17,7 +18,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * */ #define _CONFFILE_C_ @@ -34,6 +34,11 @@ /****************************************************************************/ +#define F_TAG 1 +#define F_UNTAG 2 + +/****************************************************************************/ + static int (*print_msg)(const char *, ...) = printf; /****************************************************************************/ @@ -49,16 +54,17 @@ 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 Find_Include(section **Section, char* String, int Flags); -static section* _Get_Section_From_Path(char **array, section* Section, section **RetSection, entry **RetEntry); -static entry* _Get_Entry_From_Path(char **array, entry* Entry, section **RetSection, entry **RetEntry); +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); static section* Get_Section_From_Path(section* NewSection, char *Path, entry **RetEntry); static char* Delete_Chars(char *String, char *Quote); static int Set_Ret_Code(char *Value, int Type, void **Pointer); +static int del_untagged_items(section **sec); /****************************************************************************/ -void set_print_fkt_for_conffile(int (*new_print_msg)(const char *, ...)) +void set_print_fct_for_conffile(int (*new_print_msg)(const char *, ...)) { print_msg = new_print_msg; } @@ -177,11 +183,14 @@ static section *Read_Lines(section *Section, FILE *fp, const char *FileName, int char String[BUFSIZ]; char *Sectionname, *Variable, *Value; int Res; + int InSubSection = 0; section *Ptr = Section; while (FGets(String, BUFSIZ, fp, Line) != NULL) { + InSubSection = 0; + if ((Sectionname = Find_Section(String)) != NULL) { if ((Ptr = Set_Section(&Section,Sectionname,C_OVERWRITE | C_WARN | Flags)) == NULL) @@ -191,9 +200,16 @@ static section *Read_Lines(section *Section, FILE *fp, const char *FileName, int } } else - if (Find_Include(&Section,String,Flags) == 0) + if (Find_Include(&Section,String,FileName,Flags) == 0) { + Ptr = Section; + + if (Ptr != NULL) + while (Ptr->next != NULL) + Ptr = Ptr->next; + /* Ptr = NULL; + */ } else if ((Res = Find_Entry(FileName,*Line,String,&Variable,&Value)) == 0) @@ -206,6 +222,7 @@ static section *Read_Lines(section *Section, FILE *fp, const char *FileName, int { if (*Value == C_BEGIN_SUBSECTION && Not_Space(Value+1) == NULL) { + InSubSection = 1; if (Set_SubSection(Ptr,Variable,Read_Lines(NULL,fp,FileName,Line,Flags),C_OVERWRITE | C_WARN) == NULL) { free_section(Section); @@ -228,6 +245,12 @@ 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 == 1) + { + print_msg("Error in file `%s': Missing a `%c'!\n",FileName,C_END_SUBSECTION); + return NULL; + } + return Section; } @@ -298,10 +321,12 @@ static int Find_Entry(const char *FileName, int Line, char* String, char** Varia /****************************************************************************/ -static int Find_Include(section **Section, char* String, int Flags) +static int Find_Include(section **Section, char* String, const char *FileName, int Flags) { + char *sPtr; section *Ptr = NULL; char Help1[SHORT_STRING_SIZE]; + char Help2[SHORT_STRING_SIZE] = ""; strcpy(Help1,String); Kill_Blanks(Help1); @@ -310,11 +335,29 @@ static int Find_Include(section **Section, char* String, int Flags) Help1[strlen(S_KEY_INCLUDE)] == C_BEGIN_INCLUDE && Help1[strlen(Help1)-1] == C_END_INCLUDE ) { + Ptr = *Section; + + if (Ptr != NULL) + while (Ptr->next != NULL) + Ptr = Ptr->next; + + if (*(Help1+strlen(S_KEY_INCLUDE)+1) != C_SLASH) + { + if ((sPtr = strrchr(Help2,C_SLASH)) != NULL) + { + strcpy(Help2,FileName); + sPtr[1] = '\0'; + } + } + Help1[strlen(Help1)-1] = '\0'; - if ((Ptr = read_file(*Section,Help1+strlen(S_KEY_INCLUDE)+1,Flags)) == NULL) + strcat(Help2,Help1+strlen(S_KEY_INCLUDE)+1); + + if ((Ptr = read_file(Ptr,Help2,Flags & ~C_NO_WARN_FILE)) == NULL) return -1; else - *Section = Ptr; + if (*Section == NULL) + *Section = Ptr; return 0; } @@ -641,8 +684,8 @@ static int Compare_Sections(section* sec1, section *sec2, char ***variables) { for (i=0; variables[i] != NULL && variables[i][0] != NULL && variables[i][1] != NULL; i++) { - if (!strcmp(sec1->name,sec2->name) && - !strcmp(sec1->name,variables[i][0]) && + if (!strcmp(sec1->name,variables[i][0]) && + !strcmp(sec1->name,sec2->name) && (Entry1 = Get_Entry(sec1->entries,variables[i][1])) != NULL && Entry1->value != NULL && (Entry2 = Get_Entry(sec2->entries,variables[i][1])) != NULL && @@ -734,7 +777,7 @@ static void free_cfile(cfile **cfiles) enthlten!!!! */ -section *read_files(section **main_sec, char** files, char ***variables, int flags) +int read_files(section **main_sec, char** files, char ***variables, int flags) { int newread = 0; static cfile **cfiles = NULL; @@ -754,13 +797,13 @@ section *read_files(section **main_sec, char** files, char ***variables, int fla if ((cfiles = (cfile**) realloc(cfiles,sizeof(cfile*)*(i+2))) == NULL) { print_msg("%s","Can not allocate memory!\n"); - return NULL; + return -1; } if ((cfiles[i] = (cfile*) calloc(1,sizeof(cfile))) == NULL) { print_msg("%s","Can not allocate memory!\n"); - return NULL; + return -1; } cfiles[i+1] = NULL; @@ -768,7 +811,7 @@ section *read_files(section **main_sec, char** files, char ***variables, int fla if (stat(files[i],&FileStat) != 0 && !(flags & C_NO_WARN_FILE)) { print_msg("Can not open file `%s': %s!\n",files[i],strerror(errno)); - return NULL; + return -1; } cfiles[i]->name = strdup(files[i]); @@ -781,7 +824,7 @@ section *read_files(section **main_sec, char** files, char ***variables, int fla if (cfiles == NULL) { print_msg("%s","There is no file!\n"); - return NULL; + return -1; } else { @@ -792,7 +835,7 @@ section *read_files(section **main_sec, char** files, char ***variables, int fla if (!(flags & C_NO_WARN_FILE)) { print_msg("Can not open file `%s': %s!\n",cfiles[i]->name,strerror(errno)); - return NULL; + return -1; } } else @@ -827,70 +870,18 @@ section *read_files(section **main_sec, char** files, char ***variables, int fla } } - return *main_sec; + return ((*main_sec != NULL && newread)?1:(*main_sec == NULL?-1:0)); } /****************************************************************************/ -#if 0 -/* Filtert aus den gesamten Sectionen die heraus, die in secnames - enthalten sind. Wenn also nur die Sectionen [MSN] und [NUMBER] benoetigt - werden, dann werden diese hier uebergeben("MSN","NUMBER"), und secnum - auf 2 gesetzt. secnum hat die gleich Bedeutung wie filenum in - read_files(). -*/ - -int Filter_Sections(section **sec, char** secnames) -{ - int i; - int del; - section *Ptr; - - - if (sec == NULL) - { - print_msg("%s","Section is emtpy!\n"); - return -1; - } - - while(*sec != NULL) - { - del = 1; - - for (i=0; secnames[i] != NULL && *sec != NULL; i++) - { - if (!strcmp(secnames[i],(*sec)->name)) - del = 0; - } - - if (del == 1) - { - Ptr = *sec; - *sec = (*sec)->next; - Ptr->next = NULL; - free_section(Ptr); - } - - if (*sec != NULL && del == 0) - sec = &((*sec)->next); - } - - return 0; -} -#endif - -/****************************************************************************/ - -#if 0 /* AK:24-Feb-97 */ int Filter_Sections(section **sec, char** path) { - int j,i = 0; - int del; - section *Ptr; - section *retsec; - entry *retent; + int i; char **array; - char **array2; + section *secptr; + section *retsec = NULL; + entry *retent = NULL; if (path == NULL || path[0] == NULL) @@ -902,56 +893,26 @@ int Filter_Sections(section **sec, char** path) return -1; } - while(*sec != NULL) + for (i=0; path[i] != NULL; i++) { - del = 1; + if ((array = String_to_Array(path[i],C_SLASH)) == NULL) + return -1; - for (i=0; path[i] != NULL && *sec != NULL && del == 1; i++) - { - if (_Get_Section_From_Path(sec,path[i],&retsec,&retent) == sec) - { - if ((array = String_to_Array(path,C_SLASH)) == NULL) - return NULL; + secptr = *sec; - j=0; - while(array[j] != NULL); + while ((secptr = _Get_Section_From_Path(array,secptr,&retsec,&retent,F_TAG)) != NULL); - del_Array(array); - - del = 0; - } - } - - if (del == 1) - { - Ptr = *sec; - *sec = (*sec)->next; - Ptr->next = NULL; - free_section(Ptr); - } - - if (*sec != NULL && del == 0) - sec = &((*sec)->next); + del_Array(array); } - return 0; + return del_untagged_items(sec); } -#endif /****************************************************************************/ -/* Nur die erlaubten Entries sind in entnames enthalten */ -/* Filter aus _allen_ Sections die Eintraege heraus, die in entnames - enthalten sind. So kann man in alles Sections z.B. nur die Entries - NUMBER=blabla und ALIAS=blabla behalten ("NUMBER","ALIAS") - uebergeben. entnum hat die gleiche Bedeutung wie filenum in - read_files(). -*/ - -int Filter_Entries(section **sec, char ** entnames) +static int del_untagged_items(section **sec) { - int i; - int del; + int del = 0; entry **ent; entry *Ptr; section *Ptr2; @@ -961,31 +922,7 @@ int Filter_Entries(section **sec, char ** entnames) while (*sec != NULL) { - ent = &((*sec)->entries); - - while(*ent != NULL) - { - del = 1; - - for (i=0; entnames[i] != NULL && *ent != NULL; i++) - { - if ((*ent)->name != NULL && !strcmp(entnames[i],(*ent)->name)) - del = 0; - } - - if (del == 1) - { - Ptr = *ent; - *ent = (*ent)->next; - Ptr->next = NULL; - free_entry(Ptr); - } - - if (*ent != NULL && del == 0) - ent = &((*ent)->next); - } - - if ((*sec)->entries == NULL) + if ((*sec)->flag != F_TAGGED) { Ptr2 = *sec; *sec = (*sec)->next; @@ -993,7 +930,47 @@ int Filter_Entries(section **sec, char ** entnames) free_section(Ptr2); } else - sec = &((*sec)->next); + { + (*sec)->flag = F_NOT_TAGGED; + + ent = &((*sec)->entries); + + while(*ent != NULL) + { + del = 0; + + if ((*ent)->flag == F_TAGGED && (*ent)->subsection != NULL) + { + del_untagged_items(&((*ent)->subsection)); + + if ((*ent)->subsection == NULL) + del = 1; + } + + if ((*ent)->flag != F_TAGGED || del == 1) + { + Ptr = *ent; + *ent = (*ent)->next; + Ptr->next = NULL; + free_entry(Ptr); + } + else + { + (*ent)->flag = F_NOT_TAGGED; + ent = &((*ent)->next); + } + } + + if ((*sec)->entries == NULL) + { + Ptr2 = *sec; + *sec = (*sec)->next; + Ptr2->next = NULL; + free_section(Ptr2); + } + else + sec = &((*sec)->next); + } } return 0; @@ -1031,7 +1008,7 @@ static section* Get_Section_From_Path(section* NewSection, char *Path, entry **E return NULL; - if ((RootSection = _Get_Section_From_Path(array,RootSection,&RetSection,&RetEntry)) == NULL) + if ((RootSection = _Get_Section_From_Path(array,RootSection,&RetSection,&RetEntry,0)) == NULL) RetSection = NULL; if (Entry != NULL) @@ -1042,7 +1019,7 @@ static section* Get_Section_From_Path(section* NewSection, char *Path, entry **E /****************************************************************************/ -static entry* _Get_Entry_From_Path(char **array, entry* Entry, section **RetSection, entry **RetEntry) +static entry* _Get_Entry_From_Path(char **array, entry* Entry, section **RetSection, entry **RetEntry, int flags) { int index; int found = 0; @@ -1050,7 +1027,7 @@ static entry* _Get_Entry_From_Path(char **array, entry* Entry, section **RetSect char **array2 = NULL; - if (array[0] == NULL) + if (array != NULL && array[0] == NULL) return NULL; if ((array2 = String_to_Array(array[0],C_OR)) == NULL) @@ -1072,6 +1049,10 @@ static entry* _Get_Entry_From_Path(char **array, entry* Entry, section **RetSect (*RetEntry == NULL || found_first != 0) ) { found = 1; + + if (flags == F_TAG) + Entry->flag = F_TAGGED; + *RetEntry = Entry; } else @@ -1080,10 +1061,13 @@ static entry* _Get_Entry_From_Path(char **array, entry* Entry, section **RetSect } else { - if (_Get_Section_From_Path(array+1,Entry->subsection,RetSection,RetEntry) != NULL) + if (_Get_Section_From_Path(array+1,Entry->subsection,RetSection,RetEntry,flags) != NULL) { found = 1; + if (flags == F_TAG) + Entry->flag = F_TAGGED; + if (array[2] == NULL) *RetEntry = Entry; } @@ -1107,7 +1091,7 @@ static entry* _Get_Entry_From_Path(char **array, entry* Entry, section **RetSect /****************************************************************************/ -static section* _Get_Section_From_Path(char **array, section* Section, section **RetSection, entry **RetEntry) +static section* _Get_Section_From_Path(char **array, section* Section, section **RetSection, entry **RetEntry, int flags) { int index; int found = 0; @@ -1115,7 +1099,7 @@ static section* _Get_Section_From_Path(char **array, section* Section, section * char **array2 = NULL; - if (array[0] == NULL) + if (array != NULL && array[0] == NULL) return NULL; if ((array2 = String_to_Array(array[0],C_OR)) == NULL) @@ -1136,6 +1120,10 @@ static section* _Get_Section_From_Path(char **array, section* Section, section * if (*RetSection != Section && (*RetSection == NULL || found_first != 0)) { found = 1; + + if (flags == F_TAG) + Section->flag = F_TAGGED; + *RetSection = Section; } else @@ -1144,10 +1132,13 @@ static section* _Get_Section_From_Path(char **array, section* Section, section * } else { - if (_Get_Entry_From_Path(array+1,Section->entries,RetSection,RetEntry) != NULL) + if (_Get_Entry_From_Path(array+1,Section->entries,RetSection,RetEntry,flags) != NULL) { found = 1; + if (flags == F_TAG) + Section->flag = F_TAGGED; + if (array[2] == NULL) *RetSection = Section; } @@ -1180,12 +1171,17 @@ section* Get_Section_Match(section* Section, char *Path, while ((Section = Get_Section_From_Path(Section,Path,&Entry)) != NULL) { if (RetEntry != NULL) - *RetEntry = Entry; + *RetEntry = NULL; if (Entry->subsection != NULL) { if (Value == NULL) + { + if (RetEntry != NULL) + *RetEntry = Entry; + return Entry->subsection; + } /* Die naechsten Zeilen sind fuer Syntax-DAU's auskommentiert: NUMBER={ [blabla] @@ -1204,7 +1200,12 @@ section* Get_Section_Match(section* Section, char *Path, { if ((_match == NULL && !strcmp(Entry->value,Value)) || !_match(Entry->value,Value) ) + { + if (RetEntry != NULL) + *RetEntry = Entry; + return Section; + } } } diff --git a/lib/conffile.h b/lib/conffile.h index eb7e7f7b..5feea452 100644 --- a/lib/conffile.h +++ b/lib/conffile.h @@ -1,5 +1,5 @@ -/* $Id: conffile.h,v 1.1 1997/03/03 04:23:14 fritz Exp $ +/* $Id: conffile.h,v 1.2 1997/03/03 22:05:39 luethje Exp $ * * ISDN accounting for isdn4linux. * @@ -67,6 +67,11 @@ /****************************************************************************/ +#define F_NOT_TAGGED 0 +#define F_TAGGED 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) @@ -79,12 +84,14 @@ typedef struct _entry { char *value; struct _section *subsection; struct _entry *next; + char flag; } entry; typedef struct _section { char *name; entry *entries; struct _section *next; + char flag; } section; typedef struct _cfiles { @@ -109,11 +116,10 @@ _EXTERN entry *Set_Entry(section *Section, char *Sectionname, char *Variable, ch _EXTERN section *Set_Section(section **Section, char *Sectionname, int Flag); _EXTERN section *Del_Section(section **Section, char *Sectionname); _EXTERN section *Set_SubSection(section *Section, char *Variable, section *SubSection, int Flag); -_EXTERN void set_print_fkt_for_conffile(int (*new_print_msg)(const char *, ...)); +_EXTERN void set_print_fct_for_conffile(int (*new_print_msg)(const char *, ...)); _EXTERN void free_section(section *Ptr); -_EXTERN section *read_files(section **main_sec, char** files, char ***variables, int flags); -_EXTERN int Filter_Sections(section **sec, char** secnames); -_EXTERN int Filter_Entries(section **sec, char ** entnames); +_EXTERN int read_files(section **main_sec, char** files, 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); _EXTERN int _Get_Type_Match(section *Section, char *Path, char* Pattern, int (*_match)(char*, char*), int Type, void **Pointer); diff --git a/lib/isdntools.c b/lib/isdntools.c index 72f1d8eb..fef99597 100644 --- a/lib/isdntools.c +++ b/lib/isdntools.c @@ -1,4 +1,4 @@ -/* $Id: isdntools.c,v 1.1 1997/03/03 04:23:15 fritz Exp $ +/* $Id: isdntools.c,v 1.2 1997/03/03 22:05:39 luethje Exp $ * * ISDN accounting for isdn4linux. (Utilities) * @@ -19,8 +19,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: isdntools.c,v $ - * Revision 1.1 1997/03/03 04:23:15 fritz - * Added files in lib + * Revision 1.2 1997/03/03 22:05:39 luethje + * merging of the current version and my tree * * Revision 2.6.26 1997/01/19 22:23:43 akool * Weitere well-known number's hinzugefuegt @@ -73,7 +73,6 @@ /****************************************************************************/ -#include #include #include #include @@ -139,13 +138,13 @@ char *avonlib; /****************************************************************************/ -void set_print_fkt_for_lib(int (*new_print_msg)(const char *, ...)) +void set_print_fct_for_lib(int (*new_print_msg)(const char *, ...)) { print_msg = new_print_msg; - set_print_fkt_for_conffile(new_print_msg); - set_print_fkt_for_libtools(new_print_msg); + set_print_fct_for_conffile(new_print_msg); + set_print_fct_for_libtools(new_print_msg); #ifndef LIBAREA - set_print_fkt_for_avon(new_print_msg); + set_print_fct_for_avon(new_print_msg); #endif } @@ -205,17 +204,11 @@ char *expand_number(char *s) while(*Ptr != '\0') { - switch (*Ptr) + if (isdigit(*Ptr) || *Ptr == '?' || *Ptr == '*') { - case '\t': - case ' ': - case '-': - case '/': - break; - default : Index = strlen(Help); - Help[Index] = *Ptr; - Help[Index+1] = '\0'; - break; + Index = strlen(Help); + Help[Index] = *Ptr; + Help[Index+1] = '\0'; } Ptr++; @@ -407,7 +400,7 @@ int Set_Codes(section* Section) ptr[0] = avonlib = strdup(Entry->value); else { - sprintf(s, "%s%c%s", CONFIG_AVON_DATA, C_SLASH, AVON); + sprintf(s, "%s%c%s", confdir(), C_SLASH, AVON); ptr[0] = avonlib = strdup(s); } #endif @@ -424,6 +417,8 @@ int Set_Codes(section* Section) if (ptr[1] != NULL) RetCode++; + else + print_msg("Error: Variable `%s' are not set!\n",CONF_ENT_AREA); } if ((Entry = Get_Entry(Section->entries,CONF_ENT_COUNTRY)) != NULL && @@ -440,6 +435,21 @@ int Set_Codes(section* Section) if ((ptr[2] = mycountry = strdup(ptr2)) != NULL) RetCode++; + else + print_msg("Error: Variable `%s' are not set!\n",CONF_ENT_COUNTRY); + } + + if ((Section = Get_Section(Section,CONF_SEC_VAR)) != NULL) + { + Entry = Section->entries; + + while(Entry != NULL) + { + if (setenv(Entry->name, Entry->value, 1) != 0) + print_msg("Warning: Can not set environment variable `%s=%s'!\n", Entry->name, Entry->value); + + Entry = Entry->next; + } } return (RetCode==2?0:-1); @@ -619,3 +629,70 @@ static char *_get_areacode(char *code, int *Len, int flag) /****************************************************************************/ +int read_conffiles(section **Section, char *groupfile) +{ + static section *conf_dat = NULL; + static int read_again = 0; + auto char s[4][BUFSIZ]; + auto char ***vars = NULL; + auto char **svars = NULL; + auto char **files = NULL; + auto int RetCode = -1; + + *Section = NULL; + + if (!read_again) + { + sprintf(s[0], "%s%c%s", confdir(), C_SLASH, CONFFILE); + append_element(&files,s[0]); + + sprintf(s[1], "%s%c%s", confdir(), C_SLASH, CALLERIDFILE); + append_element(&files,s[1]); + + if (groupfile != NULL) + { + strcpy(s[2],groupfile); + append_element(&files,s[2]); + } + + strcpy(s[3],expand_file(USERCONFFILE)); + append_element(&files,s[3]); + } + + append_element(&svars,CONF_SEC_MSN); + append_element(&svars,CONF_ENT_ALIAS); + append_element(&vars,svars); + svars = NULL; + append_element(&svars,CONF_SEC_NUM); + append_element(&svars,CONF_ENT_ALIAS); + append_element(&vars,svars); + svars = NULL; + append_element(&svars,CONF_SEC_MSN); + append_element(&svars,CONF_ENT_NUM); + append_element(&vars,svars); + svars = NULL; + append_element(&svars,CONF_SEC_NUM); + append_element(&svars,CONF_ENT_NUM); + append_element(&vars,svars); + + if ((RetCode = read_files(&conf_dat, files, vars, C_OVERWRITE|C_NOT_UNIQUE|C_NO_WARN_FILE)) > 0) + { + *Section = conf_dat; + + if (Set_Codes(conf_dat) != 0) + return -1; + } + else + *Section = conf_dat; + + if (!read_again) + delete_element(&files,0); + + delete_element(&vars,1); + + read_again = 1; + return RetCode; +} + +/****************************************************************************/ + diff --git a/lib/libisdn.h b/lib/libisdn.h index e2517ea2..37732677 100644 --- a/lib/libisdn.h +++ b/lib/libisdn.h @@ -1,5 +1,5 @@ -/* $Id: libisdn.h,v 1.1 1997/03/03 04:23:16 fritz Exp $ +/* $Id: libisdn.h,v 1.2 1997/03/03 22:05:41 luethje Exp $ * * ISDN accounting for isdn4linux. * @@ -41,7 +41,8 @@ extern char *basename __P((__const char *__name)); /****************************************************************************/ -#define CONFDIR_VAR "ISDN" +#define CONFDIR_VAR "ISDN_CONF_PATH" + #define C_SLASH '/' /* #define C_SLASH '\\' */ @@ -61,6 +62,10 @@ extern char *basename __P((__const char *__name)); # define CONFFILE "isdn.conf" #endif +#ifndef CALLERIDFILE +# define CALLERIDFILE "callerid.conf" +#endif + #ifndef USERCONFFILE # define USERCONFFILE "~/.isdn" #endif @@ -85,22 +90,23 @@ extern char *basename __P((__const char *__name)); #define CONF_ENT_AREALIB "AREALIB" #define CONF_ENT_AVONLIB "AVON" +#define CONF_SEC_VAR "VARIABLES" + +#define CONF_SEC_NUM "NUMBER" +#define CONF_SEC_MSN "MSN" +#define CONF_ENT_NUM "NUMBER" +#define CONF_ENT_ALIAS "ALIAS" +#define CONF_ENT_ZONE "ZONE" +#define CONF_ENT_INTFAC "INTERFACE" +#define CONF_ENT_SI "SI" +#define CONF_ENT_START "START" + /****************************************************************************/ #define C_NUM_DELIM ',' /****************************************************************************/ -#define SHORT_STRING_SIZE 256 -#define LONG_STRING_SIZE 1024 -#define BUF_SIZE 4096 - -/****************************************************************************/ - -#define F_IGNORE_CASE 1024 - -/****************************************************************************/ - #define C_NO_ERROR 1 #define C_NO_WARN 2 #define C_NO_EXPAND 4 @@ -118,7 +124,7 @@ extern char *basename __P((__const char *__name)); _EXTERN char *mycountry SET_NULL; _EXTERN char *myarea SET_NULL; -_EXTERN void set_print_fkt_for_lib(int (*new_print_msg)(const char *, ...)); +_EXTERN void set_print_fct_for_lib(int (*new_print_msg)(const char *, ...)); _EXTERN int num_match(char *Pattern, char *number); _EXTERN char *expand_number(char *s); _EXTERN char *expand_file(char *s); @@ -127,6 +133,7 @@ _EXTERN int create_runfile(const char* progname); _EXTERN int delete_runfile(const char* progname); _EXTERN int Set_Codes(section* Section); _EXTERN char *get_areacode(char *code, int *Len, int flag); +_EXTERN int read_conffiles(section **Section, char *groupfile); #undef SET_NULL #undef _EXTERN diff --git a/lib/libtools.c b/lib/libtools.c index f940feb3..43c42901 100644 --- a/lib/libtools.c +++ b/lib/libtools.c @@ -37,7 +37,7 @@ static int (*print_msg)(const char *, ...) = printf; /****************************************************************************/ -void set_print_fkt_for_libtools(int (*new_print_msg)(const char *, ...)) +void set_print_fct_for_libtools(int (*new_print_msg)(const char *, ...)) { print_msg = new_print_msg; } @@ -413,8 +413,18 @@ int match(register char *p, register char *s, int flags) if (!strcmp(p,s)) return 0; +#ifdef OWN_MATCH + return _match(p,s); +#else return fnmatch(p,s,flags); -/* +#endif +} /* match */ + +/****************************************************************************/ + +#ifdef OWN_MATCH +int _match(char* p,char* s) +{ register int sc, pcc; @@ -435,7 +445,7 @@ int match(register char *p, register char *s, int flags) case '*' : s--; do { - if (!*p || !match(p, s)) + if (!*p || !_match(p, s)) return(0); } while (*s++); return(-1); @@ -446,8 +456,8 @@ int match(register char *p, register char *s, int flags) } return(*s); -*/ -} /* match */ +} /* _match */ +#endif /****************************************************************************/ diff --git a/lib/libtools.h b/lib/libtools.h index 9d04a6a8..b8b993d0 100644 --- a/lib/libtools.h +++ b/lib/libtools.h @@ -1,5 +1,5 @@ -/* $Id: libtools.h,v 1.1 1997/03/03 04:23:17 fritz Exp $ +/* $Id: libtools.h,v 1.2 1997/03/03 22:05:42 luethje Exp $ * * ISDN accounting for isdn4linux. * @@ -32,7 +32,6 @@ extern char *basename __P((__const char *__name)); /****************************************************************************/ -#define CONFDIR_VAR "ISDN" #define C_SLASH '/' /* #define C_SLASH '\\' */ @@ -40,22 +39,6 @@ extern char *basename __P((__const char *__name)); # define TMPDIR P_tmpdir #endif -#ifndef I4LCONFDIR -# define I4LCONFDIR "/etc/isdn" -#endif - -#ifndef RUNDIR -# define RUNDIR "/var/run" -#endif - -#ifndef CONFFILE -# define CONFFILE "isdn.conf" -#endif - -#ifndef USERCONFFILE -# define USERCONFFILE "~/.isdn" -#endif - /****************************************************************************/ #define SHORT_STRING_SIZE 256 @@ -88,7 +71,7 @@ extern char *basename __P((__const char *__name)); #define _EXTERN extern #endif -_EXTERN void set_print_fkt_for_libtools(int (*new_print_msg)(const char *, ...)); +_EXTERN void set_print_fct_for_libtools(int (*new_print_msg)(const char *, ...)); _EXTERN char *Not_Space(char *String); _EXTERN char *To_Upper (char *String); _EXTERN char *Kill_Blanks(char *String); diff --git a/scripts/config.in b/scripts/config.in index 5cb99499..21a95525 100644 --- a/scripts/config.in +++ b/scripts/config.in @@ -1,5 +1,5 @@ # -# $Id: config.in,v 1.6 1997/03/03 12:59:13 fritz Exp $ +# $Id: config.in,v 1.7 1997/03/03 22:05:47 luethje Exp $ # # The whole configuration stuff is borrowed from the kernel # configuration. @@ -28,7 +28,8 @@ comment 'Runtime defaults' string 'Write .pid files here' CONFIG_RUNDIR /var/run string 'General configuration directory' CONFIG_I4LCONFDIR /etc/isdn string 'Global configuration file' CONFIG_CONFFILE isdn.conf -string 'User configuration file' CONFIG_USERCONFFILE .isdn +string 'Global phone number file file' CONFIG_CALLERIDFILE callerid.conf +string 'User configuration file' CONFIG_USERCONFFILE ~/.isdn comment 'Configuration library options' string 'Default country prefix' CONFIG_COUNTRY_PREFIX + string 'Default area prefix' CONFIG_AREA_PREFIX 0 diff --git a/scripts/defconfig b/scripts/defconfig index 59a51f58..626cd73f 100644 --- a/scripts/defconfig +++ b/scripts/defconfig @@ -16,7 +16,8 @@ CONFIG_MANDIR='/usr/man' CONFIG_RUNDIR='/var/run' CONFIG_I4LCONFDIR='/etc/isdn' CONFIG_CONFFILE='isdn.conf' -CONFIG_USERCONFFILE='.isdn' +CONFIG_CALLERIDFILE='callerid.conf' +CONFIG_USERCONFFILE='~/.isdn' CONFIG_COUNTRY_PREFIX='+' CONFIG_AREA_PREFIX='0' CONFIG_LIB_AREACODE=y