Added support for VORWAHLEN2.EXE

This commit is contained in:
Stefan Luethje 1998-05-10 22:12:04 +00:00
parent 04f23a200e
commit d7bedaa9e3
5 changed files with 297 additions and 7 deletions

View File

@ -19,6 +19,9 @@
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##
## $Log$
## Revision 1.37 1998/03/29 23:17:47 luethje
## mySQL-Patch of Sascha Matzke
##
## Revision 1.36 1998/03/29 19:54:04 luethje
## idnrep: added html feature (incoming/outgoing calls)
##
@ -264,7 +267,7 @@ SERVICEFILE = /etc/services
# DON'T EDIT BELOW THIS LINE
######################################################################
VERSION = 2.99.27
VERSION = 2.99.28
ifeq ($(POSTGRES),1)
DEFS += -DPOSTGRES

View File

@ -19,6 +19,12 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log$
* Revision 1.9 1997/05/25 19:40:53 luethje
* isdnlog: close all files and open again after kill -HUP
* isdnrep: support vbox version 2.0
* isdnconf: changes by Roderich Schupp <roderich@syntec.m.EUnet.de>
* conffile: ignore spaces at the end of a line
*
* Revision 1.8 1997/05/05 21:21:42 luethje
* bugfix for option -M
*
@ -52,6 +58,7 @@ int find_data(char *_alias, char *_number, section *conf_dat);
const char* make_word(const char *in);
char* tmp_dup(const char *in);
int add_line(section **Ptr, const char *Name);
char *get_area(char *number);
/*****************************************************************************/
@ -230,6 +237,7 @@ int find_data(char *_alias, char *_number, section *conf_dat)
auto char *ptr;
auto entry *CEPtr;
auto section *SPtr;
char *area;
if (quiet)
{
@ -248,7 +256,8 @@ int find_data(char *_alias, char *_number, section *conf_dat)
ptr = (CEPtr = Get_Entry(conf_dat->entries,CONF_ENT_SI))?(CEPtr->value?CEPtr->value:"0"):"0";
print_msg(PRT_NORMAL,"%s:\t\t%s\n",CONF_ENT_SI,ptr);
ptr = (CEPtr = Get_Entry(conf_dat->entries,CONF_ENT_ZONE))?(CEPtr->value?CEPtr->value:""):"";
area = get_area(_number);
ptr = area[0] != '\0'?area:(CEPtr = Get_Entry(conf_dat->entries,CONF_ENT_ZONE))?(CEPtr->value?CEPtr->value:""):"";
print_msg(PRT_NORMAL,"%s:\t\t%s\n",make_word(CONF_ENT_ZONE),ptr);
ptr = (CEPtr = Get_Entry(conf_dat->entries,CONF_ENT_INTFAC))?(CEPtr->value?CEPtr->value:""):"";
@ -466,6 +475,17 @@ int print_in_modules(const char *fmt, ...)
/*****************************************************************************/
char *get_area(char *number)
{
int area;
area = area_diff(NULL,number);
return area == AREA_LOCAL?"Nahbereich":area == AREA_R50?"Region 50":area == AREA_FAR?"Fernzone":"";
}
/*****************************************************************************/
int main(int argc, char *argv[], char *envp[])
{
int c;
@ -633,9 +653,11 @@ int main(int argc, char *argv[], char *envp[])
{
if (!isdnmon)
{
print_msg(PRT_NORMAL,"%s\n",ptr);
char *area = get_area(areacode);
print_msg(PRT_NORMAL,"%s%s%s\n",ptr,area[0] != '\0'?" / ":"", area[0] != '\0'?area:"");
exit(0);
}
}
print_msg(PRT_NORMAL,"%s\t%d\t",ptr,len);
}

View File

@ -28,7 +28,7 @@ endif
# USER CONFIGURATION AREA
######################################################################
CFLAGS = -Wall -pipe -O6
CFLAGS = -g -Wall -pipe #-O6
DEFS =
ifndef _CC
export _CC = gcc

View File

@ -19,6 +19,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log$
* Revision 1.18 1998/04/28 08:34:36 paul
* Fixed compiler warnings from egcs.
*
* Revision 1.17 1998/03/08 12:13:49 luethje
* Patches by Paul Slootman
*
@ -144,15 +147,30 @@
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
#include <netinet/in.h>
#include "libisdn.h"
/****************************************************************************/
#define GERMAN_CODE 49
/****************************************************************************/
typedef struct {
char code[15];
long int pointer;
} s_areacode;
/****************************************************************************/
static int (*print_msg)(const char *, ...) = printf;
static char *_get_avon(char *code, int *Len, int flag);
static char *_get_areacode(char *code, int *Len, int flag);
static int create_runfile(const char *file, const char *format);
static long int area_read_value(FILE *fp, int size);
static int area_read_file(void);
static int area_get_index(char *code);
/****************************************************************************/
@ -200,6 +218,8 @@ static char countrycodes[][2][30] = {
static char *avonlib = NULL;
static char *codelib = NULL;
static s_areacode *codes = NULL;
static int codes_number = 0;
/****************************************************************************/
@ -547,11 +567,11 @@ static int create_runfile(const char *file, const char *format)
muss von jedem Programm aufgerufen werden!!!
*/
#define _MAX_VARS 7
#define _MAX_VARS 8
int Set_Codes(section* Section)
{
static char *ptr[_MAX_VARS] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
static char *ptr[_MAX_VARS] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
int i;
int RetCode = 0;
entry *Entry;
@ -628,6 +648,27 @@ int Set_Codes(section* Section)
print_msg("Error: Variable `%s' are not set!\n",CONF_ENT_COUNTRY);
}
if ((Entry = Get_Entry(SPtr->entries,CONF_ENT_AREADIFF)) != NULL &&
Entry->value != NULL )
ptr[7] = areadifffile = strdup(Entry->value);
else
{
if ((areadifffile = (char*) calloc(strlen(confdir())+strlen(S_AREA_DIFF_FILE)+2,sizeof(char))) == NULL)
print_msg("Can not allocate memory!\n");
else
{
sprintf(areadifffile,"%s%c%s",confdir(),C_SLASH,S_AREA_DIFF_FILE);
if (access(areadifffile,R_OK))
{
free(areadifffile);
areadifffile = NULL;
}
else
ptr[7] = areadifffile;
}
}
SPtr = Section;
while ((SPtr = Get_Section(SPtr,CONF_SEC_VAR)) != NULL)
@ -930,3 +971,202 @@ int paranoia_check(char *cmd)
/****************************************************************************/
static long int area_read_value(FILE *fp, int size)
{
long value = 0;
static int endian = -1;
if (size != 2 && size != 4 && size != 1)
{
print_msg("Can not read lenght %d, only 1, 2, 4\n");
return -1;
}
if (endian == -1)
{
if (htons(0x0101) == 0x0101)
endian = 0;
else
endian = 1;
}
if (fread(&value,size,1,fp) != 1)
{
print_msg("Can not read from file `%s': Too less data!\n", areadifffile);
return -1;
}
if (endian)
{
if (size == 2)
value = ntohs(value);
else
if (size == 4)
value = ntohl(value);
}
return value;
}
/****************************************************************************/
const char* area_diff_string(char* number1, char* number2)
{
int area = area_diff(number1,number2);
return area == AREA_LOCAL?"Nahbereich":area == AREA_R50?"Region 50":area == AREA_FAR?"Fernzone":"";
}
/****************************************************************************/
int area_diff(char* _code, char *_diffcode)
{
FILE *fp = NULL;
char code[15];
char diffcode[15];
char value[15];
int index;
int number;
int i = 0;
if (codes == NULL)
if (area_read_file() == -1)
return AREA_ERROR;
if (_code == NULL)
{
strcpy(code,mycountry);
strcat(code,myarea);
}
else
strcpy(code,expand_number(_code));
if (_diffcode == NULL)
return AREA_ERROR;
else
strcpy(diffcode,expand_number(_diffcode));
if ((index = area_get_index(code)) == -1)
return AREA_ERROR;
if ((fp = fopen(areadifffile,"r")) == NULL)
{
print_msg("Can not open file `%s': %s\n", areadifffile, strerror(errno));
return -1;
}
fseek(fp,codes[index].pointer,SEEK_SET);
number = area_read_value(fp,2);
while(i++<number)
{
sprintf(value,"%s%d%ld",countryprefix,GERMAN_CODE,(area_read_value(fp,2)+32768)%65536);
if (!strncmp(value,diffcode,strlen(value)))
{
fclose(fp);
return AREA_LOCAL;
}
}
number = area_read_value(fp,2);
while(i++<number)
{
sprintf(value,"%s%d%ld",countryprefix,GERMAN_CODE,(area_read_value(fp,2)+32768)%65536);
if (!strncmp(value,diffcode,strlen(value)))
{
fclose(fp);
return AREA_R50;
}
}
fclose(fp);
if (!strncmp(mycountry,diffcode,strlen(mycountry)))
return AREA_FAR;
return AREA_UNKNOWN;
}
/****************************************************************************/
static int area_get_index(char *code)
{
int index = -1;
if (codes == NULL)
return -1;
while(++index < codes_number)
if (!strcmp(codes[index].code,code))
break;
if (index == codes_number)
{
print_msg("Can not find area code `%s'!\n", code);
index = -1;
}
return index;
}
/****************************************************************************/
static int area_read_file(void)
{
FILE *fp = NULL;
int i = 0;
if (areadifffile == NULL)
{
// print_msg("There is no file name for vorwahl database!\n");
return -1;
}
if ((fp = fopen(areadifffile,"r")) == NULL)
{
print_msg("Can not open file `%s': %s\n", areadifffile, strerror(errno));
return -1;
}
if ((codes_number = area_read_value(fp,2)) < 0)
{
print_msg("Number of areacodes is wrong: %d\n", codes_number);
return -1;
}
if (codes != NULL)
free(codes);
if ((codes = (s_areacode*) calloc(codes_number,sizeof(s_areacode))) == NULL)
{
print_msg("%s\n", strerror(errno));
return -1;
}
if (fseek(fp,3,SEEK_SET) != 0)
{
print_msg("Can not seek file `%s' to position %d: %s\n", areadifffile, 4*codes_number+3, strerror(errno));
return -1;
}
while (i<codes_number)
codes[i++].pointer = area_read_value(fp,4) -1;
if (fseek(fp,4*codes_number+3,SEEK_SET) != 0)
{
print_msg("Can not seek file `%s' to position %d: %s\n", areadifffile, 4*codes_number+3, strerror(errno));
return -1;
}
i = 0;
while (i<codes_number)
sprintf(codes[i++].code,"%s%d%ld",countryprefix,GERMAN_CODE,(area_read_value(fp,2)+32768)%65536);
fclose(fp);
return 0;
}
/****************************************************************************/

View File

@ -20,6 +20,12 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log$
* Revision 1.7 1997/05/19 22:58:29 luethje
* - bugfix: it is possible to install isdnlog now
* - improved performance for read files for vbox files and mgetty files.
* - it is possible to decide via config if you want to use avon or
* areacode.
*
* Revision 1.6 1997/04/08 21:57:07 luethje
* Create the file isdn.conf
* some bug fixes for pid and lock file
@ -99,6 +105,10 @@ extern char *basename __P((__const char *__name));
# define S_AREA_PREFIX "0"
#endif
#ifndef S_AREA_DIFF_FILE
# define S_AREA_DIFF_FILE "vorwahlen.dat"
#endif
#ifndef AVON
# define AVON "avon"
#endif
@ -113,6 +123,7 @@ extern char *basename __P((__const char *__name));
#define CONF_ENT_AREALIB "AREALIB"
#define CONF_ENT_AVONLIB "AVON"
#define CONF_ENT_CODELIB "CODELIB"
#define CONF_ENT_AREADIFF "AREADIFF"
#define CONF_SEC_VAR "VARIABLES"
@ -142,14 +153,24 @@ extern char *basename __P((__const char *__name));
/****************************************************************************/
#define AREA_ERROR -1
#define AREA_UNKNOWN 0
#define AREA_LOCAL 1
#define AREA_R50 2
#define AREA_FAR 3
/****************************************************************************/
#ifdef _ISDNTOOLS_C_
#define _EXTERN
#define SET_NULL = ""
#define SET_NULL2 = NULL
#define SET_AREA_PREFIX = S_AREA_PREFIX
#define SET_COUNTRY_PREFIX = S_COUNTRY_PREFIX
#else
#define _EXTERN extern
#define SET_NULL
#define SET_NULL2
#define SET_AREA_PREFIX
#define SET_COUNTRY_PREFIX
#endif
@ -158,6 +179,7 @@ _EXTERN char *mycountry SET_NULL;
_EXTERN char *myarea SET_NULL;
_EXTERN char *areaprefix SET_AREA_PREFIX;
_EXTERN char *countryprefix SET_COUNTRY_PREFIX;
_EXTERN char *areadifffile SET_NULL2;
_EXTERN void set_print_fct_for_lib(int (*new_print_msg)(const char *, ...));
_EXTERN int num_match(char *Pattern, char *number);
@ -169,8 +191,11 @@ _EXTERN int Set_Codes(section* Section);
_EXTERN char *get_areacode(char *code, int *Len, int flag);
_EXTERN int read_conffiles(section **Section, char *groupfile);
_EXTERN int paranoia_check(char *cmd);
_EXTERN int area_diff(char* _code, char *_diffcode);
_EXTERN const char* area_diff_string(char* number1, char* number2);
#undef SET_NULL
#undef SET_NULL2
#undef SET_AREA_PREFIX
#undef SET_COUNTRY_PREFIX
#undef _EXTERN