From d1997beda6fbe5d26515e32c2296b049e2a501f1 Mon Sep 17 00:00:00 2001 From: luethje Date: Thu, 10 Apr 1997 23:31:59 +0000 Subject: [PATCH] Added the feature, that environment variables are allowed in the config files. --- HOWTO | 27 +++++---- isdnlog/Makefile.in | 11 +++- isdnlog/README | 43 +++++++++---- isdnlog/configure | 1 + isdnlog/isdnconf/isdnconf.c | 20 +++++-- isdnlog/isdnlog/start_prog.c | 31 ++-------- isdnlog/tools/isdnconf.c | 5 +- lib/README.isdntools | 34 ++++------- lib/conffile.c | 39 +++++++++++- lib/conffile.h | 6 +- lib/libtools.c | 113 +++++++++++++++++++++++++++++++++-- lib/libtools.h | 8 ++- scripts/defconfig | 2 +- 13 files changed, 254 insertions(+), 86 deletions(-) diff --git a/HOWTO b/HOWTO index e345521f..c6804664 100644 --- a/HOWTO +++ b/HOWTO @@ -67,6 +67,8 @@ Mit folgenden Schritten kommt man in den Genuss von isdnlog-2.99.2: eine SQL-Relation eintragen. Dies darf nur eingeschaltet werden, wenn postgres95 einsatzbereit installiert ist! +Zur Zeit sind die naechsten beiden Schalter ueberfluessig, da der +xisdn voruebergehend aus der Distribution genommen wurde!!!! # export NEED_GDBM=1 Falls man _nicht_ LIBAREA=1 eingeschaltet hat, und zudem keine Datei "/usr/lib/libdbm.a", dafuer aber "/usr/lib/libgdbm.a" @@ -122,14 +124,14 @@ Mit folgenden Schritten kommt man in den Genuss von isdnlog-2.99.2: Der neue isdnlog arbeitet mit einer vollstaendig anderen Konfigurationsdatei. + Diese wird automatisch aus der bestehenden generiert. + Es wird das alte Verzeichnis "etc/isdnlog" nach "etc/isdn" umkopiert. + isdnlog-2.99.2 versucht daher beim ersten Start, die alte Konfigurationsdatei "isdnlog.conf" in die neue Syntax umzuwandeln. - Damit isdnlog-2.99.2 die alte Konfigurationsdatei finden kann, muss diese - evtl. in das in "policy.h" unter "I4LCONFDIR" angegebene Verzeichnis - kopiert werden: - - $ cp /etc/isdnlog/isdnlog.conf /etc/isdn - + Dieses passiert automatisch mit make install + Es werden in dieser Version alle Telefonnummern in der Datei callerid.conf + ausgelagert, so dass die isdn.conf sehr klien wird. 6. Erster Start des neuen isdnlog: @@ -196,11 +198,10 @@ Mit folgenden Schritten kommt man in den Genuss von isdnlog-2.99.2: Daher muessen diese von Hand uebernommen werden. In der Section [GLOBAL] - muessen die beiden Eintraege + werden automatisch mit make install die beiden Eintraege COUNTRYCODE = +49 AREACODE = xxxx - eingefuegt werden - bei AREACODE ist die eigene Vorwahl _ohne_ - vorlaufende "0" einzutragen. + eingefuegt, wenn vorher diese Daten im Menue eingegeben wurden. Nachdem die neue Konfigurationsdatei fuer gut befunden wurde, sollte die alte Konfigurationsdatei "isdnlog.conf" geloescht werden, da @@ -212,12 +213,13 @@ Mit folgenden Schritten kommt man in den Genuss von isdnlog-2.99.2: ausstossen! Nun ist es endlich an der Zeit, -7.1 Es gibt nun zwei neue Konfigurationsdateien: +7.1 Es gibt nun zwei (oder sogar drei!?!) neue Konfigurationsdateien: /etc/isdn/isdn.conf /etc/isdn/callerid.conf + ~/.isdn Wobei sich in der "isdn.conf" nur noch die rein auf isdnlog beziehenden Eintraege befinden, und in der "callerid.conf" die von isdnlog und - vbox gemeinsam verwendeten Eintraege! + (bald!?!) vbox gemeinsam verwendeten Eintraege! 8. Die neuen Features von isdnlog erkunden @@ -255,6 +257,9 @@ Mit folgenden Schritten kommt man in den Genuss von isdnlog-2.99.2: - ESTIC diese Library, weitere Applikationen werden sicherlich folgen! + Wer unbedingt auf seine AVON besteht, kann diese natuerlich + weiterverwenden. Dieses muss dann allerdings im Menu angegeben werden. + - chargeint (auflegen kurz vor dem naechsten Gebuehrenimpuls) ist mittlerweile offizieller Bestandteil von isdn4linux, und damit aus dem "Patch" Stadium heraus. Die Steuerung durch isdnlog diff --git a/isdnlog/Makefile.in b/isdnlog/Makefile.in index 98517fa8..2ea4ddd6 100644 --- a/isdnlog/Makefile.in +++ b/isdnlog/Makefile.in @@ -1,4 +1,4 @@ -## $Id: Makefile.in,v 1.10 1997/04/08 21:56:42 luethje Exp $ +## $Id: Makefile.in,v 1.11 1997/04/10 23:32:04 luethje Exp $ ## ## ISDN accounting for isdn4linux. ## @@ -19,6 +19,9 @@ ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## ## $Log: Makefile.in,v $ +## Revision 1.11 1997/04/10 23:32:04 luethje +## Added the feature, that environment variables are allowed in the config files. +## ## Revision 1.10 1997/04/08 21:56:42 luethje ## Create the file isdn.conf ## some bug fixes for pid and lock file @@ -106,6 +109,7 @@ LIBISDNDIR := @LIBISDNDIR@ I4LCONFDIR := @I4LCONFDIR@ CONFFILE := @CONFFILE@ OLDCONFDIR := @OLDCONFDIR@ +OLDCONFFILE := @OLDCONFFILE@ LIBAREA := @LIBAREA@ RUNDIR := @RUNDIR@ DBMLIB := @DBMLIB@ @@ -162,7 +166,7 @@ SERVICEFILE = /etc/services # DON'T EDIT BELOW THIS LINE ###################################################################### -VERSION = 2.99.6 +VERSION = 2.99.7 ifeq ($(POSTGRES),1) DEFS += -DPOSTGRES @@ -253,7 +257,8 @@ installdirs: rootperm install: depend all rootperm installdirs if ps -x | fgrep $(ISDNLOG) >/dev/null; then kill `cat $(RUNDIR)/isdnlog.pid`; fi -test ! -d $(OLDCONFDIR) || (cp -auv $(OLDCONFDIR)/* $(I4LCONFDIR) \ - && $(ISDNREP) 1>/dev/null 2>&1) + && $(ISDNREP) 1>/dev/null 2>&1) \ + && mv $(I4LCONFDIR)/$(OLDCONFFILE) $(I4LCONFDIR)/$(OLDCONFFILE).old $(GENCONF) $(I4LCONFDIR)/$(CONFFILE) $(INSTALL_BIN) $(ISDNLOG) $(SBINDIR) $(INSTALL_BIN) $(ISDNREP) $(BINDIR) diff --git a/isdnlog/README b/isdnlog/README index e7c196f0..7d2bf46a 100644 --- a/isdnlog/README +++ b/isdnlog/README @@ -1,3 +1,6 @@ +# Lock und PID-Files +# Beschreibung, was bei der Installation genau gemacht werden muss +# (isdn.conf vorhanden oder neu) ISDNLOG - Version 3.0 - 31-Mar-97 22:09 @@ -754,6 +757,35 @@ anlegen kann, wo auch die Nummer nur beim isdnrep angezeigt werden. Es koennen hier aber die [MSN]-Eintraege ueberschrieben werden fuer die beiden Programme isdnconf und isdnrep. +Es koennen hier Variablen verwendet werden, die entweder in der isdn.conf +gesetzt wurden oder vorher (z.b. auf Shellebene). +In den Dateien "callerid.conf" und "~/.isdn" koennen keine Variablen mehr +gesetzt werden. Das bedeutet also, dass es dort keine Sektion [VARIABLES] +gibt. + +Eine Variable wird allerdings nur ab dem Gleichheitszeichen ersetzt. + +Wenn man an die Variable noch etwas anhaengen will, dann muss man den +Variablenname in geschweifte Klammern setzen. +Im Gegensatz zur frueheren Version koennen die Variablen an beliebiger Stelle +kommen. + +Beispiele: + +[$num] # wobei num=NUMBER ist geht nicht!!!! +$alias=fred # wobei alias=ALIAS ist geht nicht!!!! + +[NUMBER] +NUMBER=$MSN1 # MSN1=1234 -> "1234" +ALIAS=${PHONE}1 # PHONE=Telefon -> "Telefon1" + +... + PROGRAM= auplay ${MY_PATH}ring.au # MY_PATH=/home/fred/ -> "/home/fred/ring.au" + PROGRAM= auplay $MY_PATHring.au # geht nicht!! + PROGRAM= auplay ${MY_PATH}ring.au ${SOUND_PATH}/$RING_FILE + # SOUND_PATH=/home/sound RING_FILE=ring.au -> "/home/sound/ring.au" +... + Es gibt bestimmte Regeln, nachdem Eintraege aus der Datei "~/.isdn" die Eintraege der "callerid.conf" ueberschreiben: @@ -1278,9 +1310,6 @@ Info-Arg Hier wird das Info-Argument angegeben. Es steht dort der gesamte zu startende Befehl -Es koennen hier Variablen verwendet werden, die entweder in der isdn.conf -gesetzt wurden oder vorher (z.b. auf Shellebene). - Es gibt aber drei zusaetzliche Variablen, die verwendet werden duerfen: $1 : Sind die Flags, die den Programmstart ausgeloest haben. @@ -1336,14 +1365,6 @@ Ausgehendes Gspraech (O), Ereignis CONNECT (C) Nummer des Anrufenden (also Meine) Nummer des Angerufenden -Eine Variable muss immer am Anfang eines Argumentes stehen. Also -"/bin$PROG" und "/bin${MYPATH}prog" gehen nicht. - -Wenn ich an die Variable noch etwas anhaengen will, dann muss ich den -Variablenname in geschweifte Klammern setzen: -"${MY_PATH}/ring.au" -"$MY_PATH/ring.au" geht nicht. - Die Variablen von isdnlog ($1, $2, ..) kann man nicht in geschweiften Klammern setzen. Also auch nicht anhaengen. diff --git a/isdnlog/configure b/isdnlog/configure index bbfe22ca..ab82698e 100755 --- a/isdnlog/configure +++ b/isdnlog/configure @@ -1950,6 +1950,7 @@ s%@RUNDIR@%$RUNDIR%g s%@SERV_PORT@%$SERV_PORT%g s%@USERFILE@%$USERFILE%g s%@OLDCONFDIR@%$OLDCONFDIR%g +s%@OLDCONFFILE@%$OLDCONFFILE%g s%@CONFFILE@%$CONFIG_CONFFILE%g s%@LOGFILE@%$LOGFILE%g s%@COUNTRYCODE@%$COUNTRYCODE%g diff --git a/isdnlog/isdnconf/isdnconf.c b/isdnlog/isdnconf/isdnconf.c index 5995ff1b..376d59ac 100644 --- a/isdnlog/isdnconf/isdnconf.c +++ b/isdnlog/isdnconf/isdnconf.c @@ -1,4 +1,4 @@ -/* $Id: isdnconf.c,v 1.4 1997/04/06 21:06:08 luethje Exp $ +/* $Id: isdnconf.c,v 1.5 1997/04/10 23:32:15 luethje Exp $ * * ISDN accounting for isdn4linux. (Report-module) * @@ -19,6 +19,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: isdnconf.c,v $ + * Revision 1.5 1997/04/10 23:32:15 luethje + * Added the feature, that environment variables are allowed in the config files. + * * Revision 1.4 1997/04/06 21:06:08 luethje * problem with empty/not existing file resolved. * @@ -284,7 +287,7 @@ int look_data(section **conf_dat) { int Cnt = 0; auto entry *CEPtr; - char *_number = NULL, *_alias; + char *_number = NULL, *_alias = NULL; char _si[SHORT_STRING_SIZE]; section *old_conf_dat = NULL; @@ -297,18 +300,20 @@ int look_data(section **conf_dat) { int Ret = 0; + free(_number); + free(_alias); _number = _alias = NULL; _si[0] = '\0'; if ((CEPtr = Get_Entry((*conf_dat)->entries,CONF_ENT_NUM)) != NULL) - _number = CEPtr->value; + _number = strdup(Replace_Variable(CEPtr->value)); if ((CEPtr = Get_Entry((*conf_dat)->entries,CONF_ENT_ALIAS)) != NULL) - _alias = CEPtr->value; + _alias = strdup(Replace_Variable(CEPtr->value)); if ((CEPtr = Get_Entry((*conf_dat)->entries,CONF_ENT_SI)) != NULL && CEPtr->value != NULL) - sprintf(_si,"%ld",strtol(CEPtr->value, NIL, 0)); + sprintf(_si,"%ld",strtol(Replace_Variable(CEPtr->value), NIL, 0)); if (and) Ret = 1; @@ -371,6 +376,8 @@ int look_data(section **conf_dat) if (Cnt == 0 && quiet && !del) find_data(NULL,_number,*conf_dat); + free(_number); + free(_alias); return Cnt; } @@ -629,6 +636,9 @@ int main(int argc, char *argv[], char *envp[]) exit(1); } + if (!add && !del && Replace_Variables(conf_dat)) + exit(8); + if (add) Cnt = add_data(&conf_dat); else diff --git a/isdnlog/isdnlog/start_prog.c b/isdnlog/isdnlog/start_prog.c index 3991e2fc..6864e551 100644 --- a/isdnlog/isdnlog/start_prog.c +++ b/isdnlog/isdnlog/start_prog.c @@ -1,4 +1,4 @@ -/* $Id: start_prog.c,v 1.2 1997/04/03 22:58:34 luethje Exp $ +/* $Id: start_prog.c,v 1.3 1997/04/10 23:32:19 luethje Exp $ * * ISDN accounting for isdn4linux. * @@ -20,6 +20,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: start_prog.c,v $ + * Revision 1.3 1997/04/10 23:32:19 luethje + * Added the feature, that environment variables are allowed in the config files. + * * Revision 1.2 1997/04/03 22:58:34 luethje * some primitve changes. * @@ -217,7 +220,6 @@ static int GetArgs(char *Line, char *Args[], char *Opts[], int MaxArgs) char *Arg = NULL; char *Use = Line; char *Ptr = NULL; - char *Ptr2 = NULL; char *Org_Arg; int MaxOpts= 0; int i = 0; @@ -265,31 +267,8 @@ static int GetArgs(char *Line, char *Args[], char *Opts[], int MaxArgs) Arg = NULL; } else - if (*Arg == '$') - { - if (Opts != NULL && (Num = atoi(Arg+1)) > 0 && Num <= MaxOpts) + if (*Arg == '$' && Opts != NULL && (Num = atoi(Arg+1)) > 0 && Num <= MaxOpts) Arg = Opts[Num-1]; - else - if (strlen(Arg) > 3 && Arg[1] == '{' && (Ptr = strrchr(Arg,'}')) != NULL) - { - *Ptr = '\0'; - - if ((Ptr2 = getenv(To_Upper(Arg+2))) != NULL) - { - strcpy(HelpString,Ptr2); - strcat(HelpString,Ptr+1); - Arg = strdup(HelpString); - - MemPtr = (char**) realloc(MemPtr,sizeof(char*)*(j+2)); - MemPtr[j++] = Arg; - MemPtr[j] = NULL; - } - else - Arg = NULL; - } - else - Arg = getenv(To_Upper(Arg+1)); - } if (Arg == NULL || *Arg == '\0') { diff --git a/isdnlog/tools/isdnconf.c b/isdnlog/tools/isdnconf.c index 7d000b7f..2d50cbba 100644 --- a/isdnlog/tools/isdnconf.c +++ b/isdnlog/tools/isdnconf.c @@ -1,4 +1,4 @@ -/* $Id: isdnconf.c,v 1.3 1997/04/03 22:58:39 luethje Exp $ +/* $Id: isdnconf.c,v 1.4 1997/04/10 23:32:24 luethje Exp $ * * ISDN accounting for isdn4linux. (Utilities) * @@ -913,6 +913,9 @@ static int _readconfig(char *_myname) if ((SPtr = read_isdnconf(&conf_dat)) == NULL) return -1; + if (Replace_Variables(conf_dat)) + return -1; + Set_Globals(conf_dat); while (SPtr != NULL) diff --git a/lib/README.isdntools b/lib/README.isdntools index 0e109961..7cedea17 100644 --- a/lib/README.isdntools +++ b/lib/README.isdntools @@ -96,15 +96,22 @@ zurueckgeliefert. Funktion: -int create_runfile(const char *progname) +int handle_runfile(const char *progname, char **devices, int flag) -Legt eine PID-Datei im Verzeichnis RUNDIR (/var/run) an. In der Datei -steht im ASCII-Format die Prozess-ID des aktuellen Prozesses. +Legt eine PID-Datei im Verzeichnis RUNDIR (/var/run) und die +entsprechenden LOCK-Dateien im Verszeichnis LOCKDIR (/var/lock) an. In den +Dateien steht im ASCII-Format die Prozess-ID des aktuellen Prozesses. +Oder Loescht alle angelegt Dateien. -progname: Ist der Name, der als PID-Datei angelegt wird. - "fred" -> "/var/run/fred.pid" - "isdnlog.tty2" -> "/var/run/isdnlog.tty2.pid" +progname: Ist der Name, der als PID-Datei angelegt wird. Es wird dort noch + der erste Name des Devices angehaengt. + progname = "fred", devices[0] = "null" -> "/var/run/fred.null.pid" +devices: Ist eine List mit den verwendeten Devices. Das letzte Element der + Liste muss NULL enthalten. + +flag: Kann zwei Werte beinhalten: START_PROG (legt die o.g. Dateien an) oder + STOP_PROG (loescht die angelegten Dateien wieder). Rueckgabewert: Wenn schon ein gueltiger/laufender Prozess mit der ID besteht liefert @@ -116,21 +123,6 @@ andernfalls -1. Funktion: -int delete_runfile(const char *progname) - -Loescht eine PID-Datei im Verzeichnis RUNDIR (/var/run). - -progname: Ist der Name, der als PID-Datei geloescht werden soll. - "fred" -> "/var/run/fred.pid" - "isdnlog.tty2" -> "/var/run/isdnlog.tty2.pid" - -Rueckgabewert: -Im Erfolgsfall 0, sonst -1. - ------------------------------------------------------------------------------ - -Funktion: - int Set_Codes(section* Section) Setzt die Eintraege der Section [GLOBAL] in die entsprechenden diff --git a/lib/conffile.c b/lib/conffile.c index d7b67e82..33a2ce93 100644 --- a/lib/conffile.c +++ b/lib/conffile.c @@ -1,4 +1,4 @@ -/* $Id: conffile.c,v 1.11 1997/04/03 22:39:11 luethje Exp $ +/* $Id: conffile.c,v 1.12 1997/04/10 23:32:33 luethje Exp $ * * ISDN accounting for isdn4linux. * @@ -19,6 +19,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: conffile.c,v $ + * Revision 1.12 1997/04/10 23:32:33 luethje + * Added the feature, that environment variables are allowed in the config files. + * * 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. @@ -1529,3 +1532,37 @@ static char* Delete_Chars(char *String, char *Quote) /****************************************************************************/ +int Replace_Variables(section *Section) +{ + entry *Entry; + char *Ptr = NULL; + + + while(Section != NULL) + { + Entry = Section->entries; + + while(Entry != NULL) + { + if (Entry->value != NULL && (Ptr = Replace_Variable(Entry->value)) != NULL) + { + free(Entry->value); + + if ((Entry->value = strdup(Ptr)) == NULL) + { + print_msg("%s","Can not allocate memory!\n"); + return -1; + } + } + + Entry = Entry->next; + } + + Section = Section->next; + } + + return 0; +} + +/****************************************************************************/ + diff --git a/lib/conffile.h b/lib/conffile.h index 7ce85977..c967612b 100644 --- a/lib/conffile.h +++ b/lib/conffile.h @@ -1,5 +1,5 @@ -/* $Id: conffile.h,v 1.5 1997/04/03 22:39:12 luethje Exp $ +/* $Id: conffile.h,v 1.6 1997/04/10 23:32:34 luethje Exp $ * * ISDN accounting for isdn4linux. * @@ -20,6 +20,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: conffile.h,v $ + * Revision 1.6 1997/04/10 23:32:34 luethje + * Added the feature, that environment variables are allowed in the config files. + * * 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. @@ -138,6 +141,7 @@ _EXTERN section* Get_Section_Match(section* Section, char *Path, char* Value, in _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); _EXTERN int _Get_Type_Value(section *Section, char *Path, int Type, void **Pointer); +_EXTERN int Replace_Variables(section *Section); #undef _EXTERN diff --git a/lib/libtools.c b/lib/libtools.c index 15c8f515..bbbc9888 100644 --- a/lib/libtools.c +++ b/lib/libtools.c @@ -1,4 +1,4 @@ -/* $Id: libtools.c,v 1.3 1997/03/20 00:28:02 luethje Exp $ +/* $Id: libtools.c,v 1.4 1997/04/10 23:32:35 luethje Exp $ * ISDN accounting for isdn4linux. * * Copyright 1996 by Stefan Luethje (luethje@sl-gw.lake.de) @@ -18,6 +18,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: libtools.c,v $ + * Revision 1.4 1997/04/10 23:32:35 luethje + * Added the feature, that environment variables are allowed in the config files. + * * Revision 1.3 1997/03/20 00:28:02 luethje * Inserted lines into the files for the revision tool. * @@ -28,6 +31,7 @@ /****************************************************************************/ #include +#include #include #include #include @@ -120,7 +124,7 @@ char *FGets(char *String, int StringLen, FILE *fp, int *Line) strcat(String,Help); - if ((Len = strlen(String)) > 0 && String[Len-1] == '\\' ) + if ((Len = strlen(String)) > 0 && String[Len-1] == C_QUOTE_CHAR ) String[Len-1] = '\0'; else break; @@ -152,7 +156,7 @@ char *Check_Quote(char *String, char *Quote, int Flag) while ((Ptr = Strpbrk(Ptr,Quote)) != NULL) { - if (Ptr != String && *(Ptr - 1) == '\\') + if (Ptr != String && *(Ptr - 1) == C_QUOTE_CHAR) { if (Flag == QUOTE_IGNORE) { @@ -210,7 +214,7 @@ const char* Quote_Chars(char *string) for (i = strlen(Ptr); i >= Index; i--) Ptr[i+1] = Ptr[i]; - Ptr[Index] = '\\'; + Ptr[Index] = C_QUOTE_CHAR; Index += 2; } @@ -501,3 +505,104 @@ int is_integer (char *string, long int *value) /****************************************************************************/ +char *Replace_Variable(char *String) +{ + static char *RetCode = NULL; + char *Begin = NULL; + char *Var = NULL; + char *End = NULL; + char *Value = NULL; + int num; + + + if (RetCode != NULL) + free(RetCode); + + if ((RetCode = strdup(String)) == NULL || + (Var = strdup(RetCode)) == NULL || + (End = strdup(RetCode)) == NULL || + (Begin = strdup(RetCode)) == NULL ) + { + print_msg("%s!\n","Can not alllocate memory!\n"); + return NULL; + } + + Begin[0] ='\0'; + + while ((num = sscanf(RetCode,"%[^$]$%[0-9a-zA-Z]%[^\n]",Begin,Var,End)+1) > 2 || + (num = sscanf(RetCode,"%[^$]${%[0-9a-zA-Z]}%[^\n]",Begin,Var,End)+1) > 2 || + (num = sscanf(RetCode,"$%[0-9a-zA-Z]%[^\n]",Var,End)) > 0 || + (num = sscanf(RetCode,"${%[0-9a-zA-Z]}%[^\n]",Var,End)) > 0 ) + { + if ((num > 2 && Begin[strlen(Begin)-1] == C_QUOTE_CHAR) || (Value = getenv(Var)) == NULL) + { + RetCode[strlen(Begin)] = 1; + + if (strlen(Begin) > 0) + memmove(RetCode+strlen(Begin)-1,RetCode+strlen(Begin),strlen(RetCode)-strlen(Begin)+1); + } + else + if (Value != NULL) + { + if ((RetCode = (char*) realloc(RetCode,sizeof(char)*(strlen(RetCode)+strlen(Value)-strlen(Var)))) == NULL) + { + print_msg("%s!\n","Can not alllocate memory!\n"); + return NULL; + } + + switch(num) + { + case 1: sprintf(RetCode,"%s",Value); + break; + case 2: sprintf(RetCode,"%s%s",Value,End); + break; + case 3: sprintf(RetCode,"%s%s",Begin,Value); + break; + case 4: sprintf(RetCode,"%s%s%s",Begin,Value,End); + break; + default: break; + } + + free(Begin); + free(Var); + free(End); + + if ((Var = strdup(RetCode)) == NULL || + (End = strdup(RetCode)) == NULL || + (Begin = strdup(RetCode)) == NULL ) + { + print_msg("%s!\n","Can not alllocate memory!\n"); + return NULL; + } + + Begin[0] ='\0'; + } + else + { + print_msg("Invalid variable `%s'!\n",Var); + free(RetCode); + RetCode = NULL; + break; + } + } + + free(Begin); + free(Var); + free(End); + + if ((Begin = RetCode) != NULL) + { + while (*Begin != '\0') + { + if (*Begin == 1) + *Begin = '$'; + + Begin++; + } + } + + return RetCode; +} + +/****************************************************************************/ + diff --git a/lib/libtools.h b/lib/libtools.h index 7b240727..53499bce 100644 --- a/lib/libtools.h +++ b/lib/libtools.h @@ -1,4 +1,4 @@ -/* $Id: libtools.h,v 1.3 1997/03/20 00:28:03 luethje Exp $ +/* $Id: libtools.h,v 1.4 1997/04/10 23:32:35 luethje Exp $ * * ISDN accounting for isdn4linux. * @@ -19,6 +19,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: libtools.h,v $ + * Revision 1.4 1997/04/10 23:32:35 luethje + * Added the feature, that environment variables are allowed in the config files. + * * Revision 1.3 1997/03/20 00:28:03 luethje * Inserted lines into the files for the revision tool. * @@ -56,6 +59,8 @@ extern char *basename __P((__const char *__name)); #define QUOTE_IGNORE 0 #define QUOTE_DELETE 1 +#define C_QUOTE_CHAR '\\' + /****************************************************************************/ #define F_IGNORE_CASE 1024 @@ -89,6 +94,7 @@ _EXTERN int _delete_element(void ***elem, int deep); _EXTERN int match(register char *p, register char *s, int flags); _EXTERN int is_double (char *string, double *value); _EXTERN int is_integer (char *string, long int *value); +_EXTERN char *Replace_Variable(char *String); #undef _EXTERN diff --git a/scripts/defconfig b/scripts/defconfig index 057cf5b6..d67e5532 100644 --- a/scripts/defconfig +++ b/scripts/defconfig @@ -25,7 +25,7 @@ CONFIG_USERCONFFILE='~/.isdn' CONFIG_COUNTRY_PREFIX='+' CONFIG_AREA_PREFIX='0' CONFIG_COUNTRYCODE='49' -CONFIG_AREACODE='040' +CONFIG_AREACODE='' CONFIG_LIB_AREACODE=y CONFIG_AREACODE_DATA='/usr/lib/isdn'