isdnlog-3.64

- new "Sonderrufnummern" handling
This commit is contained in:
akool 1999-11-07 13:29:25 +00:00
parent c48c1ed339
commit 8eb5be904e
21 changed files with 461 additions and 983 deletions

View File

@ -1,4 +1,4 @@
## $Id: Makefile.in,v 1.118 1999/11/05 20:21:59 akool Exp $
## $Id: Makefile.in,v 1.119 1999/11/07 13:29:25 akool Exp $
##
## ISDN accounting for isdn4linux.
##
@ -19,6 +19,10 @@
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##
## $Log: Makefile.in,v $
## Revision 1.119 1999/11/07 13:29:25 akool
## isdnlog-3.64
## - new "Sonderrufnummern" handling
##
## Revision 1.118 1999/11/05 20:21:59 akool
## isdnlog-3.63
## - many new rates
@ -792,9 +796,6 @@ export ILABEL := %b %e %T %ICall to tei %t from %N2 on %n2
export OLABEL := %b %e %T %Itei %t calling %N2 with %n2
export CHARGEMAX := 1000.00
USE_DESTINATION =1
ifndef ROOTDIR
export ROOTDIR=$(shell pwd)
MAKELIB =1
@ -821,10 +822,6 @@ INCLUDE = -I./isdnlog -I./connect -I./tools -I$(PREFIXDIR) -I$(LIBISDNDIR) -
LIB = $(DBMLIB) -lm
ifeq ($(USE_DESTINATION),1)
DEFS += -DUSE_DESTINATION
endif
SERVICEFILE = /etc/services
@ -832,7 +829,7 @@ SERVICEFILE = /etc/services
# DON'T EDIT BELOW THIS LINE
######################################################################
VERSION = 3.63
VERSION = 3.64
MANPAGES = isdnlog/callerid.conf.5 isdnlog/isdn.conf.5 \
isdnlog/isdnformat.5 isdnlog/isdnlog.5 isdnlog/isdnlog.8 \
@ -870,7 +867,7 @@ ISDNLOG_OBJS = isdnlog/isdnlog.o isdnlog/processor.o isdnlog/functions.o \
isdnlog/server.o isdnlog/start_prog.o isdnlog/messages.o \
connect/connect.o connect/socket.o tools/tools.o \
connect/conv_address.o isdnlog/user_access.o \
tools/isdnconf.o tools/telnum.o \
tools/isdnconf.o tools/telnum.o tools/dest.o \
tools/rate.o tools/zone.o tools/holiday.o \
isdnlog/asn1.o isdnlog/asn1_generic.o isdnlog/asn1_aoc.o \
isdnlog/asn1_address.o isdnlog/asn1_diversion.o \
@ -892,32 +889,21 @@ endif
ISDNREP_OBJS = isdnrep/rep_main.o tools/tools.o tools/isdnconf.o \
isdnlog/messages.o isdnrep/isdnrep.o \
tools/rate.o tools/zone.o tools/holiday.o \
tools/rate.o tools/zone.o tools/holiday.o tools/dest.o \
tools/telnum.o \
$(LIBISDNDIR)/libisdn.a
ISDNCONF_OBJS= isdnconf/isdnconf.o tools/tools.o tools/isdnconf.o \
tools/rate.o tools/zone.o tools/holiday.o \
tools/telnum.o \
tools/telnum.o tools/dest.o \
$(LIBISDNDIR)/libisdn.a
ISDNRATE_OBJS= tools/isdnrate.o tools/isdnconf.o tools/tools.o \
tools/rate.o tools/zone.o \
tools/rate.o tools/zone.o tools/dest.o \
tools/holiday.o \
tools/telnum.o \
$(LIBISDNDIR)/libisdn.a
ifeq ($(USE_DESTINATION),1)
ISDNRATE_OBJS += tools/dest.o
ISDNCONF_OBJS += tools/dest.o
ISDNLOG_OBJS += tools/dest.o
ISDNREP_OBJS += tools/dest.o
else
ISDNRATE_OBJS += tools/country.o
ISDNCONF_OBJS += tools/country.o
ISDNLOG_OBJS += tools/country.o
ISDNREP_OBJS += tools/country.o
endif
ISDNLOG = bin/isdnlog
ISDNCONF = bin/isdnconf

View File

@ -1,10 +1,11 @@
ISDNLOG - Version 3.60 - 29-Oct-1999
ISDNLOG - Version 3.64 - 29-Oct-1999
isdnlog ist ein Utility zur Auswertung des D-Kanals eines
ISDN-BRI Anschlusses.
isdnlog-3.60 wurde ausgiebig mit Linux-2.0.38 sowie Linux 2.3.24 getestet.
isdnlog-3.64 wurde ausgiebig mit Linux-2.0.38, Linux-2.2.13 sowie
Linux-2.3.25 getestet.
Fuer alle, die es nun ueberhaupt nicht mehr abwarten koennen, hier das

View File

@ -1,4 +1,4 @@
/* $Id: isdnlog.c,v 1.53 1999/10/30 18:03:31 akool Exp $
/* $Id: isdnlog.c,v 1.54 1999/11/07 13:29:27 akool Exp $
*
* ISDN accounting for isdn4linux. (log-module)
*
@ -19,6 +19,10 @@
* along with this program; if not, write to the Free Software
*
* $Log: isdnlog.c,v $
* Revision 1.54 1999/11/07 13:29:27 akool
* isdnlog-3.64
* - new "Sonderrufnummern" handling
*
* Revision 1.53 1999/10/30 18:03:31 akool
* - fixed "-q" option
* - workaround for "Sonderrufnummern"
@ -377,11 +381,7 @@
#include <termios.h>
#include "isdnlog.h"
#ifdef USE_DESTINATION
#include "dest.h"
#else
#include "telnum.h"
#endif
#ifdef POSTGRES
#include "postgres.h"
#endif
@ -1427,11 +1427,7 @@ int main(int argc, char *argv[], char *envp[])
if (!Q931dmp && *version)
print_msg(PRT_NORMAL, "%s\n", version);
#ifdef USE_DESTINATION
initDest(destfile, &version);
#else
initCountry(countryfile, &version);
#endif
if (!Q931dmp && *version)
print_msg(PRT_NORMAL, "%s\n", version);

View File

@ -1,4 +1,4 @@
/* $Id: processor.c,v 1.88 1999/11/05 20:22:01 akool Exp $
/* $Id: processor.c,v 1.89 1999/11/07 13:29:27 akool Exp $
*
* ISDN accounting for isdn4linux. (log-module)
*
@ -19,6 +19,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: processor.c,v $
* Revision 1.89 1999/11/07 13:29:27 akool
* isdnlog-3.64
* - new "Sonderrufnummern" handling
*
* Revision 1.88 1999/11/05 20:22:01 akool
* isdnlog-3.63
* - many new rates
@ -1019,7 +1023,7 @@ void buildnumber(char *num, int oc3, int oc3a, char *result, int version,
} /* while */
} /* if */
#if 0
#if 0 /* Fixme: delete */
if (!dir && (who == CALLED) && !memcmp(num, vbn, strlen(vbn))) { /* Provider */
register int l, c;
@ -1075,7 +1079,7 @@ void buildnumber(char *num, int oc3, int oc3a, char *result, int version,
if (*provider == UNKNOWN)
*provider = preselect;
if (*num && !dir && (who == CALLED) && getArea(*provider, num) && (*sondernummer == UNKNOWN))
if (*num && !dir && (who == CALLED) && getSpecial(num) && (*sondernummer == UNKNOWN))
*sondernummer = strlen(num);
} /* if */

View File

@ -1,4 +1,4 @@
/* $Id: isdnrep.c,v 1.80 1999/10/25 18:33:16 akool Exp $
/* $Id: isdnrep.c,v 1.81 1999/11/07 13:29:28 akool Exp $
*
* ISDN accounting for isdn4linux. (Report-module)
*
@ -24,6 +24,10 @@
*
*
* $Log: isdnrep.c,v $
* Revision 1.81 1999/11/07 13:29:28 akool
* isdnlog-3.64
* - new "Sonderrufnummern" handling
*
* Revision 1.80 1999/10/25 18:33:16 akool
* isdnlog-3.57
* WARNING: Experimental version!
@ -601,13 +605,7 @@
#include "isdnrep.h"
#include "../../vbox/src/libvbox.h"
#include "libisdn.h"
#ifdef USE_DESTINATION
#include "dest.h"
#else
#include "telnum.h"
#endif
#define END_TIME 1
@ -975,11 +973,7 @@ int read_logfile(char *myname)
initHoliday(holifile, NULL);
#ifdef USE_DESTINATION
initDest(destfile, NULL);
#else
initCountry(countryfile, NULL);
#endif
initRate(rateconf, ratefile, zonefile, NULL);
initTelNum();
@ -2586,18 +2580,10 @@ static void repair(one_call *cur_call)
call[0].sondernummer[CALLED] = destnum.ncountry==0;
clearRate(&Rate);
#ifdef USE_DESTINATION
Rate.src[0] = srcnum.country;
#else
Rate.src[0] = srcnum.country ? srcnum.country->Code[0] : "";
#endif
Rate.src[1] = srcnum.area;
Rate.src[2] = "";
#ifdef USE_DESTINATION
Rate.dst[0] = destnum.country;
#else
Rate.dst[0] = destnum.country ? destnum.country->Code[0] : "";
#endif
Rate.dst[1] = destnum.area;
Rate.dst[2] = destnum.msn;
Rate.start = cur_call->t;

View File

@ -11,10 +11,64 @@
# for collecting and preparing most of the call charges.
V:1.88-Austria [27-Oct-1999]
V:1.90-Austria [06-Nov-1999]
U:%.3f öS
# Service aka Sondernummern
S:Euro-Notruf
N:112
S:Feuerwehr
N:122
S:Polizei
N:133
S:Rettung
N:144
S:Bergrettung
N:140
S:Ärztenotdienst
N:141
S:Xxxx
N:142
S:Arbö
N:123
S:Öamtc
N:120
S:Internet
N:07189*,19411,19430,19440,019088333
S:Störung
N:111*
S:Auskuft AT,DE
N:11811
S:Auskuft Int
N:11812
S:Diverse Dienste
N:11820,15*,114,16*,190
S:EMS
N:02290414
S:Telegramm
N:022900
S:Diverse Ortstarif
N:02290* # Wildcard after special
###########################
P:01,1 Telekom Austria Minimumtarif
B:1001
@ -41,7 +95,7 @@ Z:1 Regionalzone
T:W/08-18=1.116/72 Geschäftszeit
T:W/18-08=1.116/160 Freizeit
T:E,H/*=1.116/160 Freizeit
A:111*,11820,15*,+437111,+437112,+437113,+437114,+43810
A:111*,11820,15*,+437111,+437112,+437113,+437114,+43810,02290
Z:2 Österreichzone
T:W/08-18=1.116/25 Geschäftszeit
@ -62,11 +116,10 @@ T:E,H/*=1.116/16.18 Freizeit
A:+43699
Z:5 Online
S:Internet by call
T:W/08-18=1.116/120 Geschäftszeit
T:W/18-08=1.116/360 Freizeit
T:E,H/*=1.116/360 Freizeit
A:+437189,19411,19430,19440
A:07189*,19411,19430,19440
Z:6 Ausland Zone 1
T:W/08-18=1.116/15 Geschäftszeit
@ -248,7 +301,7 @@ Z:1 Regionalzone
T:W/08-18=1.056/72 Geschäftszeit
T:W/18-08=1.056/160 Freizeit
T:E,H/*=1.056/160 Freizeit
A:111*,11820,15*,+437111,+437112,+437113,+437114,+43810
A:111*,11820,15*,+437111,+437112,+437113,+437114,+43810,02290
Z:2 Österreichzone
T:W/08-18=1.056/25 Geschäftszeit
@ -269,11 +322,10 @@ T:E,H/*=1.056/16.18 Freizeit
A:+43699
Z:5 Online
S:Internet by call
T:W/08-18=1.056/120 Geschäftszeit
T:W/18-08=1.056/360 Freizeit
T:E,H/*=1.056/360 Freizeit
A:+437189,19411,19430,19440
A:07189*,19411,19430,19440
Z:6 Ausland Zone 1
T:W/08-18=1.056/15 Geschäftszeit
@ -455,7 +507,7 @@ Z:1 Regionalzone
T:W/08-18=0.996/72 Geschäftszeit
T:W/18-08=0.996/160 Freizeit
T:E,H/*=0.996/160 Freizeit
A:111*,11820,15*,+437111,+437112,+437113,+437114,+43810
A:111*,11820,15*,+437111,+437112,+437113,+437114,+43810,02290
Z:2 Österreichzone
T:W/08-18=0.996/25 Geschäftszeit
@ -476,11 +528,10 @@ T:E,H/*=0.996/16.18 Freizeit
A:+43699
Z:5 Online
S:Internet by call
T:W/08-18=0.996/120 Geschäftszeit
T:W/18-08=0.996/360 Freizeit
T:E,H/*=0.996/360 Freizeit
A:+437189,19411,19430,19440
A:07189*,19411,19430,19440
Z:6 Ausland Zone 1
T:W/08-18=0.996/15 Geschäftszeit
@ -662,7 +713,7 @@ Z:1 Regionalzone
T:W/08-18=0.936/72 Geschäftszeit
T:W/18-08=0.936/160 Freizeit
T:E,H/*=0.936/160 Freizeit
A:111*,11820,15*,+437111,+437112,+437113,+437114,+43810
A:111*,11820,15*,+437111,+437112,+437113,+437114,+43810,02290
Z:2 Österreichzone
T:W/08-18=0.936/25 Geschäftszeit
@ -683,11 +734,10 @@ T:E,H/*=0.936/16.18 Freizeit
A:+43699
Z:5 Online
S:Internet by call
T:W/08-18=0.936/120 Geschäftszeit
T:W/18-08=0.936/360 Freizeit
T:E,H/*=0.936/360 Freizeit
A:+437189,19411,19430,19440
A:07189*,19411,19430,19440
Z:6 Ausland Zone 1
T:W/08-18=0.936/15 Geschäftszeit
@ -869,7 +919,7 @@ Z:1 Regionalzone
T:W/08-18=0.816/72 Geschäftszeit
T:W/18-08=0.816/160 Freizeit
T:E,H/*=0.816/160 Freizeit
A:111*,11820,15*,+437111,+437112,+437113,+437114,+43810
A:111*,11820,15*,+437111,+437112,+437113,+437114,+43810,02290
Z:2 Österreichzone
T:W/08-18=0.816/25 Geschäftszeit
@ -890,11 +940,10 @@ T:E,H/*=0.816/16.18 Freizeit
A:+43699
Z:5 Online
S:Internet by call
T:W/08-18=0.816/120 Geschäftszeit
T:W/18-08=0.816/360 Freizeit
T:E,H/*=0.816/360 Freizeit
A:+437189,19411,19430,19440
A:07189*,19411,19430,19440
Z:6 Ausland Zone 1
T:W/08-18=0.816/15 Geschäftszeit
@ -1496,7 +1545,7 @@ A:MC,NO,SE
Z:7 Deutschland Mobilfunk ...
T:*/*=4.78(60)/1 0-24h
A:_DEMF,_CHMF
A:_DEME2,_CHMF
Z:8 Israel ...
T:*/*=5.62(60)/1 0-24h
@ -1946,10 +1995,10 @@ A:DE,IT,CH
Z:4 TransEuro1
T:*/*=3.50(60)/1 0-24h
A:AD,BE,DK,_DEMF,FO,FI
A:FR,GI,UK,IE,IS,IT
A:LI,LU,MC,NL,NO,PL,SM
A:SE,SK,SI,ES
A:AD,BE,DK,_DEME2,FO,FI
A:FR,GI,UK,IE,IS,LI
A:LU,MC,NL,NO,PL,SM,SE
A:SK,SI,ES
A:CZ,HU,CY
Z:5 TransEuro2
@ -3048,7 +3097,6 @@ T:E,H/*=3.33(60)/60/1 Weekend
A:+43663,+43664,+43676,+43699
Z:3 Internet
S:Internet by call
T:*/*=0.49(60)/60/1 0-24h
A:0800400600

View File

@ -1,4 +1,4 @@
V:1.10-Germany [05-Nov-1999 21:11:20]
V:1.10-Germany [07-Nov-1999 12:13:59]
# Währungsformat
U:%.3f DM
@ -8,7 +8,7 @@ U:%.3f DM
#
# (C) Copyright 1999 by Andreas Kool (akool@isdn4linux.de)
#
# $Id: rate-de.dat,v 1.58 1999/11/05 20:21:59 akool Exp $
# $Id: rate-de.dat,v 1.59 1999/11/07 13:29:25 akool Exp $
#
#
# Das "A:" Tag muß folgendermaßen gefüllt werden:
@ -168,6 +168,111 @@ U:%.3f DM
# Interntarif Draht-Draht
# D1Ext
# werden z.Zt. nicht unterstützt
#
#####################################################################
#
#
# Sonderrufnummern:
S:Internet zzgl. Grundgebuehr
N:0191999 # UUnet classic
N:01910 # T-Online SLIP
N:0191011 # T-Online PPP
N:01914 # AOL
N:019161 # AOL
S:Internet by call
N:0191501, 01929, 01924924, 0192340, 0192343, 0192070, 0192340, 0191501, 01924924
N:019251
S:T-VoteCall
N:01371, 01372, 01373, 01374, 0138
S:Cityruf
N:01640, 01641, 01642, 01643, 01644, 01645, 01646, 01647, 01648, 01649
N:01682, 01683, 01684, 01685, 01686, 01687, 01688, 01689, 01690, 01691
N:016951, 016952
S:Quix
N:016500, 016501, 016502, 016503, 016504, 016505, 016506, 016507
N:016508, 01651, 01653, 01654, 01655, 01656, 016591, 016592, 016593
S:TeLMI
N:01660, 01661, 01665, 01669
S:Scall
N:01680, 01681, 01696, 01699
S:Skyper
N:01692, 01693, 016953
S:Shared Cost Service 01801
N:01801
S:Shared Cost Service 01802
N:01802
S:Shared Cost Service 01803
N:01803
S:Shared Cost Service 01804
N:01804
S:Shared Cost Service 01805
N:01805
S:Service 01901
N:01901
S:Service 01902
N:01902
S:Service 01903
N:01903
S:Service 01904
N:01904
S:Service 01905
N:01905
S:Service 01906
N:01906
S:Service 01907
N:01907
S:Service 01908
N:01908
S:Service 01909
N:01909
S:Expo 2000 Hotline
N:02000
S:Persönliche Rufnummer
N:0700
S:freecall
N:0130, 0800
S:Polizei / Notruf
N:110
S:Feuerwehr / Rettungsleitstelle
N:112
S:Auskunft
N:11811 # DTV
N:11818 # Debitel
N:11833 # DTAG Inland
N:11834 # DTAG Ausland
N:11850 # Talkline
N:11870 # Mannesmann Arcor
N:11871 # Mannesmann Arcor
N:11880 # Telegate
N:11890 # Telegate
#####################################################################
#
#

View File

@ -1,4 +1,4 @@
V:1.10-Germany [05-Nov-1999 21:11:20]
V:1.10-Germany [07-Nov-1999 12:13:59]
# Währungsformat
U:%.3f DM
@ -8,7 +8,7 @@ U:%.3f DM
#
# (C) Copyright 1999 by Andreas Kool (akool@isdn4linux.de)
#
# $Id: rate-de.dat.src,v 1.8 1999/11/05 20:21:59 akool Exp $
# $Id: rate-de.dat.src,v 1.9 1999/11/07 13:29:26 akool Exp $
#
#
# Das "A:" Tag muß folgendermaßen gefüllt werden:
@ -168,6 +168,111 @@ U:%.3f DM
# Interntarif Draht-Draht
# D1Ext
# werden z.Zt. nicht unterstützt
#
#####################################################################
#
#
# Sonderrufnummern:
S:Internet zzgl. Grundgebuehr
N:0191999 # UUnet classic
N:01910 # T-Online SLIP
N:0191011 # T-Online PPP
N:01914 # AOL
N:019161 # AOL
S:Internet by call
N:0191501, 01929, 01924924, 0192340, 0192343, 0192070, 0192340, 0191501, 01924924
N:019251
S:T-VoteCall
N:01371, 01372, 01373, 01374, 0138
S:Cityruf
N:01640, 01641, 01642, 01643, 01644, 01645, 01646, 01647, 01648, 01649
N:01682, 01683, 01684, 01685, 01686, 01687, 01688, 01689, 01690, 01691
N:016951, 016952
S:Quix
N:016500, 016501, 016502, 016503, 016504, 016505, 016506, 016507
N:016508, 01651, 01653, 01654, 01655, 01656, 016591, 016592, 016593
S:TeLMI
N:01660, 01661, 01665, 01669
S:Scall
N:01680, 01681, 01696, 01699
S:Skyper
N:01692, 01693, 016953
S:Shared Cost Service 01801
N:01801
S:Shared Cost Service 01802
N:01802
S:Shared Cost Service 01803
N:01803
S:Shared Cost Service 01804
N:01804
S:Shared Cost Service 01805
N:01805
S:Service 01901
N:01901
S:Service 01902
N:01902
S:Service 01903
N:01903
S:Service 01904
N:01904
S:Service 01905
N:01905
S:Service 01906
N:01906
S:Service 01907
N:01907
S:Service 01908
N:01908
S:Service 01909
N:01909
S:Expo 2000 Hotline
N:02000
S:Persönliche Rufnummer
N:0700
S:freecall
N:0130, 0800
S:Polizei / Notruf
N:110
S:Feuerwehr / Rettungsleitstelle
N:112
S:Auskunft
N:11811 # DTV
N:11818 # Debitel
N:11833 # DTAG Inland
N:11834 # DTAG Ausland
N:11850 # Talkline
N:11870 # Mannesmann Arcor
N:11871 # Mannesmann Arcor
N:11880 # Telegate
N:11890 # Telegate
#####################################################################
#
#

View File

@ -1,4 +1,4 @@
CC=gcc -m486 -O2 -Wall -DSTANDALONE -I. -I.. -I../isdnlog -I../connect -I../../lib -DUSE_DESTINATION
CC=gcc -m486 -O2 -Wall -DSTANDALONE -I. -I.. -I../isdnlog -I../connect -I../../lib
#CC=gcc -m486 -O2 -g -pg -Wall -DSTANDALONE -I. -I.. -I../isdnlog
all: rate-at

View File

@ -7,7 +7,6 @@
BZIP2 = @BZIP2@
SHELL = /bin/sh
CFLAGS = -Wall -g
DEFS = -DUSE_DESTINATION
INCLUDES =
LDFLAGS = @DBMLIB@
DBEXT = @DBEXT@

View File

@ -1,4 +1,4 @@
/* $Id: isdnrate.c,v 1.23 1999/11/02 21:01:57 akool Exp $
/* $Id: isdnrate.c,v 1.24 1999/11/07 13:29:28 akool Exp $
* ISDN accounting for isdn4linux. (rate evaluation)
*
@ -19,12 +19,15 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: isdnrate.c,v $
* Revision 1.23 1999/11/02 21:01:57 akool
* Revision 1.24 1999/11/07 13:29:28 akool
* isdnlog-3.64
* - new "Sonderrufnummern" handling
*
* Revision 1.22 1999/10/26 18:17:14 akool
* isdnlog-3.62
* - many new rates
* - next try to fix "Sonderrufnummern"
*
* Revision 1.22 1999/10/26 18:17:14 akool
* isdnlog-3.58
* - big cleanup ( > 1.3 Mb removed!)
* - v0.02 of destination support - better, but not perfect
@ -111,11 +114,7 @@
#include "isdnlog.h"
#include "tools/zone.h"
#include <unistd.h>
#ifdef USE_DESTINATION
#include "dest.h"
#else
#include "telnum.h"
#endif
#define WIDTH 19
#define _MAXLAST 20 /* the real max */
@ -210,11 +209,7 @@ static void init()
if (verbose && *version)
print_msg(PRT_V, "%s\n", version);
#ifdef USE_DESTINATION
initDest(destfile, message);
#else
initCountry(countryfile, message);
#endif
if (verbose && *version)
print_msg(PRT_V, "%s\n", version);
@ -229,11 +224,7 @@ static void init()
static void deinit(void)
{
exitRate();
#ifdef USE_DESTINATION
exitDest();
#else
exitCountry();
#endif
exitHoliday();
}
/* calc a day/time W | E | H */
@ -716,11 +707,7 @@ static int compute(char *num)
continue;
}
clearRate(&Rate);
#ifdef USE_DESTINATION
Rate.src[0] = srcnum.country;
#else
Rate.src[0] = srcnum.country ? srcnum.country->Code[0] : "";
#endif
Rate.src[1] = srcnum.area;
Rate.src[2] = "";
@ -730,11 +717,7 @@ static int compute(char *num)
continue;
}
#ifdef USE_DESTINATION
Rate.dst[0] = destnum.country;
#else
Rate.dst[0] = destnum.country ? destnum.country->Code[0] : "";
#endif
Rate.dst[1] = destnum.area;
Rate.dst[2] = destnum.msn;
print_msg(PRT_V, "Rate dst0='%s' dst1='%s' dst2='%s'\n", Rate.dst[0], Rate.dst[1], Rate.dst[2]);
@ -1511,6 +1494,6 @@ int main(int argc, char *argv[], char *envp[])
print_msg(PRT_A, "\t-X comment\tprint <comment> from C:tag\n");
print_msg(PRT_A, "\n\te.g.\t%s -b5 -f30 -TH -t1 Zaire\n", myshortname);
} /* else */
/* deinit(); Fixme: this SIGSEGs in exitHoliday */
return (0);
} /* isdnrate */

View File

@ -14,6 +14,32 @@
*/
static int leo=0;
void sv_printf(char *s, char *n) {
printf("S:%s\nN:%s\n\n",s,n);
}
void write_services(void) {
printf("\n# Service aka Sondernummern\n");
sv_printf("Euro-Notruf","112");
sv_printf("Feuerwehr","122");
sv_printf("Polizei","133");
sv_printf("Rettung","144");
sv_printf("Bergrettung","140");
sv_printf("Ärztenotdienst","141");
sv_printf("Xxxx","142");
sv_printf("Arbö","123");
sv_printf("Öamtc","120");
sv_printf("Internet","07189*,19411,19430,19440,019088333");
sv_printf("Störung","111*");
sv_printf("Auskuft AT,DE","11811");
sv_printf("Auskuft Int","11812");
sv_printf("Diverse Dienste","11820,15*,114,16*,190");
sv_printf("EMS","02290414");
sv_printf("Telegramm","022900");
sv_printf("Diverse Ortstarif","02290*\t# Wildcard after special");
printf("\n");
}
char *strip (char *s)
{
char *p;
@ -70,7 +96,7 @@ void rprintf (char *fmt, char *name, ...)
break;
}
printf ("%s%s\n", buf, name);
if (strcmp(name, "Online") == 0 || strcmp(name, "Internet") == 0)
if (0 && (strcmp(name, "Online") == 0 || strcmp(name, "Internet") == 0))
printf("S:Internet by call\n");
} else {
printf ("%s\n", buf);
@ -287,7 +313,7 @@ void rate_1001(void)
double Tarif[] = { 1.116, 1.056, 0.996, 0.936, 0.816 };
char *Zone[][2] = {{ "FreePhone", "112,122,133,141,142,144,+43800,+43801,+43802,+43803,+43804" },
{ "Regionalzone", "111*,11820,15*,+437111,+437112,+437113,+437114,+43810" },
{ "Regionalzone", "111*,11820,15*,+437111,+437112,+437113,+437114,+43810,02290" },
{ "Österreichzone", "Österreich" },
{ "Mobilfunk 1", "+43663,+43664,+43676" },
{ "Mobilfunk 2", "+43699" },
@ -1023,10 +1049,10 @@ void rate_10elf(void) {
char *Zone[][2] = {{ "Bundesland", "+43" },
{ "Mobilfunk", "+43663,+43664,+43676,+43699" },
{ "TransAlp", "Deutschland, Italien, Schweiz" },
{ "TransEuro1", "Andorra, Belgien, Dänemark, Deutschland Mobil, Färöer Inseln, Finnland, Frankreich, Gibraltar, Großbritannien, Irland, Island, Italien, Liechtenstein, Luxemburg, Monaco, Niederlande, Norwegen, Polen, San Marino, Schweden, Slowakei, Slowenien, Spanien (einschließlich Kanar. Inseln), Tschechische Rep., Ungarn, Zypern." },
{ "TransEuro2","Albanien, Bosnien-Herzegowina, Bulgarien, Estland, Griechenland, Israel, Jugoslawien, Kroatien, Lettland, Libyen, Litauen, Malta, Marokko, Mazedonien, Moldau, Portugal (einschließlich Azoren und Madeira), Rumänien, Rußland, Türkei, Ukraine, Weißrußland " },
{ "TransEuro1", "Andorra, Belgien, Dänemark, Deutschland Mobil, Färöer Inseln, Finnland, Frankreich, Gibraltar, Großbritannien, Irland, Island, Liechtenstein, Luxemburg, Monaco, Niederlande, Norwegen, Polen, San Marino, Schweden, Slowakei, Slowenien, Spanien (einschließlich Kanar. Inseln), Tschechische Rep., Ungarn, Zypern" },
{ "TransEuro2","Albanien, Bosnien-Herzegowina, Bulgarien, Estland, Griechenland, Israel, Jugoslawien, Kroatien, Lettland, Libyen, Litauen, Malta, Marokko, Mazedonien, Moldau, Portugal (einschließlich Azoren und Madeira), Rumänien, Rußland, Türkei, Ukraine, Weißrußland" },
{ "TransAmerika","Kanada, Vereinigte Staaten"},
{ "TransPazifik","Australien, Hong Kong, Japan, Korea (Süd), Malaysia, Neuseeland, Singapur "},
{ "TransPazifik","Australien, Hong Kong, Japan, Korea (Süd), Malaysia, Neuseeland, Singapur"},
{ "TransWelt","+"}};
double Tarif[][2] = {{ 0.90, 0.90 },
@ -2325,8 +2351,9 @@ int main (int argc, char *argv[])
printf ("# Many thanks to Daniela Bruder <dbruder@sime.com>\n");
printf ("# for collecting and preparing most of the call charges.\n\n\n");
printf ("V:1.89-Austria [02-Nov-1999]\n\n");
printf ("V:1.90-Austria [06-Nov-1999]\n\n");
printf ("U:%%.3f öS\n");
write_services();
#if 0
rate_1066();

View File

@ -1,4 +1,4 @@
/* $Id: rate.c,v 1.57 1999/11/05 20:22:01 akool Exp $
/* $Id: rate.c,v 1.58 1999/11/07 13:29:29 akool Exp $
*
* Tarifdatenbank
*
@ -19,6 +19,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: rate.c,v $
* Revision 1.58 1999/11/07 13:29:29 akool
* isdnlog-3.64
* - new "Sonderrufnummern" handling
*
* Revision 1.57 1999/11/05 20:22:01 akool
* isdnlog-3.63
* - many new rates
@ -352,10 +356,13 @@
* char* getComment(int prefix, char *key)
* liefert einen C:-Eintrag
*
* int getArea (int prefix, char *number)
* überprüft, ob die Nummer einem A:-Tag entspricht
* int getSpecial (char *number)
* überprüft, ob die Nummer einem N:-Tag = Service entspricht
* wird für die Sondernummern benötigt
*
* char *getSpecialName(char *number)
* get the Service Name of a special number
*
* void clearRate (RATE *Rate)
* setzt alle Felder von *Rate zurück
*
@ -404,11 +411,7 @@ extern const char *basename (const char *name);
#include "holiday.h"
#include "zone.h"
#ifdef USE_DESTINATION
#include "dest.h"
#else
#include "telnum.h"
#endif
#include "rate.h"
#define LENGTH 1024 /* max length of lines in data file */
@ -463,7 +466,8 @@ typedef struct {
typedef struct {
char *Name;
int Zone;
int nCode;
char **Codes;
} SERVICE;
typedef struct {
@ -479,17 +483,18 @@ typedef struct {
ZONE *Zone;
int nArea;
AREA *Area;
int nService;
SERVICE *Service;
int nComment;
COMMENT *Comment;
} PROVIDER;
static char Format[STRINGL]="";
static PROVIDER *Provider=NULL;
static int nProvider=0;
static int line=0;
static SERVICE * Service=NULL;
static int nService=0;
static void notice (char *fmt, ...)
{
@ -502,7 +507,7 @@ static void notice (char *fmt, ...)
#ifdef STANDALONE
fprintf(stderr, "%s\n", msg);
#else
print_msg(PRT_ERR, "%s\n", msg);
print_msg(PRT_INFO, "%s\n", msg);
#endif
}
@ -668,9 +673,6 @@ void exitRate(void)
if (Provider[i].Area[j].Name) free (Provider[i].Area[j].Name);
} /* for */
if(Provider[i].Area) free (Provider[i].Area);
for (j=0; j<Provider[i].nService; j++)
if (Provider[i].Service[j].Name) free (Provider[i].Service[j].Name);
if(Provider[i].Service) free (Provider[i].Service);
for (j=0; j<Provider[i].nComment; j++) {
if (Provider[i].Comment[j].Key) free (Provider[i].Comment[j].Key);
if (Provider[i].Comment[j].Value) free (Provider[i].Comment[j].Value);
@ -680,22 +682,28 @@ void exitRate(void)
Provider[i].used=0;
}
}
for (i=0; i<nService; i++) {
for(j=0; j<Service[i].nCode; j++)
free(Service[i].Codes[j]);
if(Service[i].Codes) free(Service[i].Codes);
if(Service[i].Name) free(Service[i].Name);
}
/* if(Service) free(Service); this SIGSEGVs - why ??? */
Service=0;
nService=0;
}
int initRate(char *conf, char *dat, char *dom, char **msg)
{
static char message[LENGTH];
FILE *stream;
#ifndef USE_DESTINATION
COUNTRY *Country;
int d;
#endif
bitfield day, hour;
double price, divider, duration;
char buffer[LENGTH], path[LENGTH], Version[LENGTH]="";
char *c, *s;
int booked[MAXPROVIDER], variant[MAXPROVIDER];
int Providers=0, Comments=0, Services=0, Areas=0, Specials=0, Zones=0, Hours=0;
int Providers=0, Comments=0;
int Areas=0, Specials=0, Zones=0, Hours=0;
int ignore=0, where=0, prefix=UNKNOWN;
int zone, zone1, zone2, day1, day2, hour1, hour2, freeze, delay;
int *number, numbers;
@ -871,8 +879,6 @@ int initRate(char *conf, char *dat, char *dom, char **msg)
Provider[prefix].Zone=NULL;
Provider[prefix].nArea=0;
Provider[prefix].Area=NULL;
Provider[prefix].nService=0;
Provider[prefix].Service=NULL;
Provider[prefix].nComment=0;
Provider[prefix].Comment=NULL;
Providers++;
@ -1024,26 +1030,9 @@ int initRate(char *conf, char *dat, char *dom, char **msg)
s+=2;
while(1) {
if (*(c=strip(str2list(&s)))) {
#ifndef USE_DESTINATION
if (!isdigit(*c) && (d=getCountry(c, &Country)) != UNKNOWN) {
if (*c=='+') {
Areas += appendArea (prefix, c, Country->Name, zone, &where, dat);
} else if (d>2) {
whimper (dat, "Unknown country '%s' (%s?), ignoring", c, Country->Name);
} else {
if (d>0)
whimper (dat, "Unknown country '%s', using '%s'", c, Country->Name);
for (i=0; i<Country->nCode; i++)
Areas += appendArea (prefix, Country->Code[i], Country->Name, zone, &where, dat);
}
} else { /* unknown country or Sondernummer */
#endif
/* append areas as they are -lt- */
Areas += appendArea (prefix, c, NULL, zone, &where, dat);
Specials++;
#ifndef USE_DESTINATION
}
#endif
} else {
warning (dat, "Ignoring empty areacode");
}
@ -1055,36 +1044,35 @@ int initRate(char *conf, char *dat, char *dom, char **msg)
}
break;
case 'N': /* N:Nirvana[,Nirvana...] */
case 'S': /* S:service */
if (ignore) continue;
/* S:Service
N:nn[,nn]
...
*/
if (Providers) continue;
s+=2;
s=strip(s);
Service=realloc(Service, (++nService)*sizeof(SERVICE));
Service[nService-1].Name=strdup(s);
Service[nService-1].Codes=0;
Service[nService-1].nCode=0;
break;
case 'S': /* S:service[,service...] */
case 'N': /* N:serviceNum[,serviceNum...] */
if (ignore) continue;
if (zone==UNKNOWN) {
if (Providers) continue;
if (Service==NULL) {
warning (dat, "Unexpected tag '%c'", *s);
break;
}
s+=2;
while(1) {
if (*(c=strip(str2list(&s)))) {
for (i=0; i<Provider[prefix].nService; i++) {
if (strcmp (Provider[prefix].Service[i].Name,c)==0) {
warning (dat, "Duplicate Service %s", c);
c=NULL;
break;
}
}
if (c) {
Provider[prefix].Service=realloc(Provider[prefix].Service, (Provider[prefix].nService+1)*sizeof(SERVICE));
Provider[prefix].Service[Provider[prefix].nService].Name=strdup(c);
Provider[prefix].Service[Provider[prefix].nService].Zone=zone;
Provider[prefix].nService++;
Services++;
}
} else {
warning (dat, "Ignoring empty service");
}
Service[nService-1].Codes=realloc(Service[nService-1].Codes,
++Service[nService-1].nCode * sizeof(char*));
Service[nService-1].Codes[Service[nService-1].nCode-1]=strdup(c);
}
if (*s==',') {
s++;
continue;
@ -1373,7 +1361,7 @@ int initRate(char *conf, char *dat, char *dom, char **msg)
if (msg) snprintf (message, LENGTH,
"Rates Version %s loaded [%d Providers, %d Zones, %d Areas, %d Specials, %d Services, %d Comments, %d Rates from %s]",
Version, Providers, Zones, Areas, Specials, Services, Comments, Hours, dat);
Version, Providers, Zones, Areas, Specials, nService, Comments, Hours, dat);
return 0;
}
@ -1405,20 +1393,25 @@ char *getComment (int prefix, char *key)
return NULL;
}
int getArea (int prefix, char *number)
{
int l, i;
if (prefix<0 || prefix>=nProvider || !Provider[prefix].used)
return 0;
int getSpecial (char *number) {
int i,j,l;
l=strlen(number);
for (i=0; i<Provider[prefix].nArea; i++) {
if (strmatch(Provider[prefix].Area[i].Code, number)>=l)
return 1;
}
return 0;
}
for (i=0; i<nService; i++)
for(j=0; j<Service[i].nCode; j++)
if(strmatch(Service[i].Codes[j], number)>=l)
return 1;
return 0;
}
char *getSpecialName(char *number) {
int i,j,l;
l=strlen(number);
for (i=0; i<nService; i++)
for(j=0; j<Service[i].nCode; j++)
if(strmatch(Service[i].Codes[j], number)>=l)
return Service[i].Name;
return 0;
}
void clearRate (RATE *Rate)
{
@ -1453,6 +1446,7 @@ int getRate(RATE *Rate, char **msg)
char *day;
time_t time;
struct tm tm;
char *number=0;
if (msg)
*(*msg=message)='\0';
@ -1469,7 +1463,7 @@ int getRate(RATE *Rate, char **msg)
if (Rate->_area==UNKNOWN) {
int a, x=0;
TELNUM num;
char *number=strcat3(Rate->dst);
number=strcat3(Rate->dst);
if (*Rate->dst[0] && getDest(number, &num) == 0 && num.keys && *num.keys) {
char *p;
#if 0
@ -1536,7 +1530,10 @@ int getRate(RATE *Rate, char **msg)
Rate->Provider = Provider[prefix].Name;
Rate->Country = Provider[prefix].Area[Rate->_area].Name;
Rate->Zone = Provider[prefix].Zone[Rate->_zone].Name;
if (Rate->dst[0] && *Rate->dst[0])
Rate->Zone = Provider[prefix].Zone[Rate->_zone].Name;
else if(number && *number)
Rate->Zone = getSpecialName(number);
Rate->zone = Provider[prefix].Zone[Rate->_zone].Number[0];
Rate->Basic=0;
@ -1818,14 +1815,9 @@ int main (int argc, char *argv[])
initHoliday ("../holiday-at.dat", &msg);
printf ("%s\n", msg);
#ifdef USE_DESTINATION
initDest ("dest/dest.gdbm", &msg);
printf ("%s\n", msg);
initTelnum();
#else
initCountry ("../country-de.dat", &msg);
printf ("%s\n", msg);
#endif
initRate ("/etc/isdn/rate.conf", "../rate-at.dat", "../zone-at-%s.gdbm", &msg);
printf ("%s\n", msg);

View File

@ -1,4 +1,4 @@
/* $Id: rate.h,v 1.13 1999/09/26 10:55:20 akool Exp $
/* $Id: rate.h,v 1.14 1999/11/07 13:29:29 akool Exp $
*
* Tarifdatenbank
*
@ -19,6 +19,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: rate.h,v $
* Revision 1.14 1999/11/07 13:29:29 akool
* isdnlog-3.64
* - new "Sonderrufnummern" handling
*
* Revision 1.13 1999/09/26 10:55:20 akool
* isdnlog-3.55
* - Patch from Oliver Lauer <Oliver.Lauer@coburg.baynet.de>
@ -169,13 +173,13 @@ typedef struct {
void exitRate(void);
int initRate(char *conf, char *dat, char *dom, char **msg);
char *getProvider(int prefix);
int getArea(int prefix, char *number);
int getSpecial(char *number);
char* getSpecialName(char *number);
char *getComment(int prefix, char *key);
void clearRate (RATE *Rate);
int getRate(RATE *Rate, char **msg);
int getLeastCost(RATE *Current, RATE *Cheapest, int booked, int skip);
int getZoneRate(RATE* Rate, int domestic, int first);
int guessZone (RATE *Rate, int aoc_units);
char *explainRate (RATE *Rate);
char *printRate (double value);

View File

@ -86,11 +86,7 @@
*
*/
#ifdef USE_DESTINATION
#include "dest.h"
#else
#include "telnum.h"
#endif
#define DEFAULT (UNKNOWN-1)
@ -150,160 +146,6 @@ static void clearArea(TELNUM *num, int a) {
num->narea= a==DEFAULT?defnum.narea:a;
}
#ifndef USE_DESTINATION
static inline void clearCountry(TELNUM *num, int c) {
num->country=0;
num->ncountry=c;
}
static inline void setCountry(TELNUM *num) {
num->country=defnum.country;
num->ncountry=defnum.ncountry;
}
static int _getCountrycode(char *country, char ** t) {
char c[TN_MAX_COUNTRY_LEN];
int res, l, last;
if ((last=res = getCountrycode(country, t)) == UNKNOWN)
return UNKNOWN;
if(res>=TN_MAX_COUNTRY_LEN) {
print_msg(PRT_A, "Problem getCountrycode \"%s\" returned\n", country,res);
return UNKNOWN;
}
if (country[1] == '1' || country[1] == '7') /* Fixme: quick hack fuer USA/GUS */
return last;
Strncpy(c, country, res); /* try shorter because of towns in country.dat */
l=strlen(c);
while(l>1) {
if ((res = getCountrycode(c, t)) != UNKNOWN)
last=res;
#if DEBUG
print_msg(PRT_V, "_getCountrycode(%s)=%d ", c,res);
#endif
c[--l] = '\0'; /* try shorter */
}
return last;
}
static int split_country(char **p, TELNUM *num) {
int res=0;
int len=0;
char *country=0;
#if DEBUG
print_msg(PRT_V, "cou: '%s' ", *p);
#endif
if (!memcmp(*p,"00", 2) || !isdigit(**p)) {
res = 0; /* len of country known ? */
if (!isdigit(**p)) { /* alnum or + */
if (**p == '+')
country = strdup(*p);
else { /* alpha */
while (!isdigit(**p) && **p)
(*p)++, res++;
while (Isspace(**p))
(*p)--,res--;
country = malloc(res+1);
Strncpy(country, (*p)-res, res+1);
}
}
else {
country = malloc(strlen(*p)+2);
sprintf(country, "+%s", (*p)+2);
(*p)++;len++;
}
if (res == 0) {
if((res = _getCountrycode(country, 0)) != UNKNOWN) {
#if DEBUG
print_msg(PRT_V, "getCountrycode(%s)= ", country);
#endif
country[res]='\0';
#if DEBUG
print_msg(PRT_V, "\"%s\" ", country);
#endif
*p += res;
}
else {
print_msg(PRT_A, "Unknown Country \"%s\"\n", *p);
clearCountry(num, UNKNOWN);
res=-10;
}
}
if (getCountry(country, &num->country) != UNKNOWN) {
#if DEBUG
print_msg(PRT_V, "Country \"%s\"\n", num->country->Code[0]);
#endif
num->ncountry=atoi(num->country->Code[0]+1);
}
else {
clearCountry(num, UNKNOWN);
print_msg(PRT_A, "Unknown Country \"%s\"\n", *p);
res=-10;
}
free(country);
}
else {
int ga;
#if DEBUG
print_msg(PRT_V, "getArea(%d,%s) => " ,num->nprovider, *p);
#endif
if((ga=getArea(num->nprovider, *p))) /* sondernummer */
clearCountry(num, 0);
else
clearCountry(num, DEFAULT);
#if DEBUG
print_msg(PRT_V, "%d ", ga);
#endif
}
#if DEBUG
print_msg(PRT_V, "Country %d\n", num->ncountry);
#endif
return res+len;
}
static int split_area(char **p, TELNUM *num, int first) {
int res=0;
int len=0;
char *s;
#if DEBUG
print_msg(PRT_V, "are: '%s' ", *p);
#endif
if (num->ncountry == 0) { /* sondernummer */
clearArea(num, 0);
return 0;
}
if (**p == '0' && first)
(*p)++, len++;
if (len || num->ncountry>0) {
if (num->ncountry == DEFAULT)
setCountry(num);
if((res=getAreacode(num->ncountry, *p, &s)) != UNKNOWN) {
Strncpy(num->sarea, s, TN_MAX_SAREA_LEN);
Strncpy(num->area, *p, min(res+1, TN_MAX_AREA_LEN));
(*p) += res;
num->narea=atoi(num->area);
#if DEBUG
print_msg(PRT_V,"getAreacode(%d, %s)= '%s'\n",num->ncountry,num->area,num->sarea);
#endif
}
else {
clearArea(num, UNKNOWN);
#if DEBUG
print_msg(PRT_V,"getAreacode(%d, %s)= 'UNKNOWN'\n",num->ncountry,*p);
#endif
return -1;
}
}
else
clearArea(num, DEFAULT);
if (num->ncountry == DEFAULT)
setCountry(num);
return res+len;
}
#endif
#ifdef USE_DESTINATION
static inline void clearCountry(TELNUM *num, int c) {
*num->scountry='\0';
*num->country='\0';
@ -329,7 +171,7 @@ int normalizeNumber(char *target, TELNUM *num, int flag) {
/* subst '00' => '+' */
if (p[0]=='0' && p[1]=='0')
*++p='+';
if (getArea(num->nprovider, p)) { /* sondernummer */
if (getSpecial(p)) { /* sondernummer */
goto is_sonder;
}
if(!isdigit(*p)) {
@ -339,7 +181,7 @@ int normalizeNumber(char *target, TELNUM *num, int flag) {
q = malloc(strlen(num->area)+strlen(num->msn)+1);
strcpy(q, num->area);
strcat(q, num->msn);
if(getArea(num->nprovider, q)) { /* sondernummer */
if(getSpecial(q)) { /* sondernummer */
clearCountry(num, 0);
*num->sarea='\0';
Strncpy(num->area, q, TN_MAX_AREA_LEN);
@ -350,7 +192,7 @@ int normalizeNumber(char *target, TELNUM *num, int flag) {
}
}
else {
if(getArea(num->nprovider, p)) { /* sondernummer */
if(getSpecial(p)) { /* sondernummer */
is_sonder:
clearCountry(num, 0);
*num->sarea='\0';
@ -366,7 +208,7 @@ is_sonder:
strcat(q, p+1);
free(origp);
origp=p=q;
if (getArea(num->nprovider, p)) { /* sondernummer */
if (getSpecial(p)) { /* sondernummer */
goto is_sonder;
}
res=getDest(p, num);
@ -383,37 +225,6 @@ is_sonder:
return(res);
}
#else
int normalizeNumber(char *target, TELNUM *num, int flag) {
int res=0;
int first=0;
char n[TN_MAX_NUM_LEN];
char *p, *q;
for (p=target, q=n; *p; p++)
if (!Isspace(*p))
*q++ = *p;
*q = '\0';
p = n;
clearNum(num);
if (flag & TN_PROVIDER)
split_vbn(&p, num);
if (flag & TN_COUNTRY) {
res = split_country(&p, num);
if (res<0)
return UNKNOWN;
else if(res==0)
first=1;
}
if (flag & TN_AREA)
res = split_area(&p, num, first);
Strncpy(num->msn, p, TN_MAX_MSN_LEN);
if (res<0)
return 1;
return(0);
}
#endif
#define VBN_LEN (*vbnlen-'0')
char *prefix2provider(int prefix, char*s) {
@ -456,7 +267,6 @@ void initNum(TELNUM *num) {
if(!*num->area)
Strncpy(num->area, myarea, TN_MAX_AREA_LEN);
num->ncountry=defnum.ncountry;
#ifdef USE_DESTINATION
strcpy(num->scountry,defnum.scountry);
strcpy(num->country,defnum.country);
num->narea=atoi(num->area); /* 1.01 */
@ -465,16 +275,6 @@ void initNum(TELNUM *num) {
strcat(s,num->area);
getDest(s, num);
free(s);
#else
num->country=defnum.country;
num->narea=atoi(num->area);
if (getAreacode(num->ncountry, num->area, &s) != UNKNOWN) {
Strncpy(num->sarea, s, TN_MAX_SAREA_LEN);
free(s);
}
else
clearArea(num, UNKNOWN);
#endif
strcpy(num->vbn, defnum.vbn);
}
@ -482,20 +282,10 @@ static void _init(void) {
char *s;
clearNum(&defnum);
Strncpy(defnum.area, myarea, TN_MAX_AREA_LEN);
#ifdef USE_DESTINATION
s=malloc(strlen(mycountry)+strlen(myarea)+1);
strcpy(s,mycountry);
strcat(s,myarea);
getDest(s, &defnum);
#else
if (getCountry(mycountry, &defnum.country) != UNKNOWN) {
defnum.ncountry=atoi(defnum.country->Code[0]+1);
if (getAreacode(defnum.ncountry, defnum.area, &s) != UNKNOWN) {
Strncpy(defnum.sarea, s, TN_MAX_SAREA_LEN);
free(s);
}
}
#endif
Strncpy(defnum.vbn, vbn, TN_MAX_VBN_LEN);
}
@ -548,24 +338,15 @@ again:
break;
case 'c':
if(num->ncountry>0 && num->country) {
#ifdef USE_DESTINATION
q=stpcpy(q,num->country);
#else
q=stpcpy(q, num->country->Code[0]);
#endif
first=0;
}
else
SKIP;
break;
case 'C':
#ifdef USE_DESTINATION
if(num->ncountry>0)
q=stpcpy(q, num->scountry);
#else
if(num->ncountry>0 && num->country)
q=stpcpy(q, num->country->Name);
#endif
else
SKIP;
break;
@ -648,11 +429,7 @@ static void init()
if (verbose && *version)
print_msg(PRT_V, "%s\n", version);
#ifdef USE_DESTINATION
initDest("/usr/lib/isdn/dest.gdbm", message); /* Fixme: */
#else
initCountry(countryfile, message);
#endif
if (verbose && *version)
print_msg(PRT_V, "%s\n", version);
@ -667,13 +444,10 @@ static void init()
static void deinit(void)
{
exitRate();
#ifdef USE_DESTINATION
exitDest();
#else
exitCountry();
#endif
exitHoliday();
}
int main(int argc, char *argv[], char *envp[])
{
register int i;

View File

@ -29,14 +29,10 @@ typedef struct {
char vbn[TN_MAX_VBN_LEN]; /* "10" */
char provider[TN_MAX_PROVIDER_LEN]; /* "UTA" */
int nprovider; /* 2 */
#ifdef USE_DESTINATION
char scountry[TN_MAX_SCOUNTRY_LEN]; /* "Austria" */
char country[TN_MAX_COUNTRY_LEN]; /* "+43" */
char keys[TN_MAX_SCOUNTRY_LEN]; /* "VIA/AT" */
char tld[3]; /* "AT" */
#else
COUNTRY *country;
#endif
int ncountry; /* 43 */
char area[TN_MAX_AREA_LEN]; /* "1" */
int narea; /* 1 */

View File

@ -1,4 +1,4 @@
/* $Id: tools.c,v 1.40 1999/10/30 18:03:31 akool Exp $
/* $Id: tools.c,v 1.41 1999/11/07 13:29:29 akool Exp $
*
* ISDN accounting for isdn4linux. (Utilities)
*
@ -19,6 +19,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: tools.c,v $
* Revision 1.41 1999/11/07 13:29:29 akool
* isdnlog-3.64
* - new "Sonderrufnummern" handling
*
* Revision 1.40 1999/10/30 18:03:31 akool
* - fixed "-q" option
* - workaround for "Sonderrufnummern"
@ -740,27 +744,6 @@ char *vnum(int chan, int who)
return(retstr[retnum]);
}
else {
#ifndef USE_DESTINATION
if (!memcmp(call[chan].num[who], countryprefix, strlen(countryprefix)) &&
memcmp(call[chan].num[who], mycountry, strlen(mycountry))) { /* Ausland */
register int i;
auto char *s;
if ((i = getCountrycode(call[chan].num[who], &s)) != UNKNOWN) {
Strncpy(call[chan].areacode[who], call[chan].num[who], i + 1);
strcpy(call[chan].rufnummer[who], call[chan].num[who] + i);
*call[chan].vorwahl[who] = 0;
strcpy(call[chan].area[who], s);
sprintf(retstr[retnum], "%s %s, %s",
call[chan].areacode[who],
call[chan].rufnummer[who],
call[chan].area[who]);
return(retstr[retnum]);
} /* if */
} /* if */
#else
if (!q931dmp) {
normalizeNumber(call[chan].num[who], &number, TN_ALL);
@ -770,34 +753,6 @@ char *vnum(int chan, int who)
strcpy(s, formatNumber("%F", &number));
} /* if */
#endif
#if 0
normalizeNumber(call[chan].num[who], &number, TN_ALL);
/* Fixme: use number fields directly, no need to format a string -lt- */
strcpy(s, formatNumber("%F", &number));
/* +49 6441/443431, Wetzlar */
if ((p1 = strchr(s, ' '))) {
*p1 = 0;
strcpy(call[chan].areacode[who], s);
*p1 = ' ';
if ((p2 = strchr(p1 + 1, '/'))) {
*p2 = 0;
strcpy(call[chan].vorwahl[who], p1 + 1);
*p2 = '/';
if ((p1 = strchr(p2 + 1, ','))) {
*p1 = 0;
strcpy(call[chan].rufnummer[who], p2 + 1);
*p1 = ',';
strcpy(call[chan].area[who], p1 + 2);
} /* if */
} /* if */
} /* if */
#endif
if (cnf > -1)
strcpy(retstr[retnum], call[chan].alias[who]);
@ -806,7 +761,7 @@ char *vnum(int chan, int who)
return(retstr[retnum]);
} /* else */
#if 0 /* -lt- dead code ??? */
#if 0 /* -lt- dead code ??? Fixme: */
if (l > 1) {
if (call[chan].num[who][prefix] == '1')
cc_len = 1; /* USA is only country with country code length 1 */

View File

@ -1,4 +1,4 @@
/* $Id: zone.c,v 1.18 1999/10/25 18:30:04 akool Exp $
/* $Id: zone.c,v 1.19 1999/11/07 13:29:29 akool Exp $
*
* Zonenberechnung
*
@ -19,6 +19,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: zone.c,v $
* Revision 1.19 1999/11/07 13:29:29 akool
* isdnlog-3.64
* - new "Sonderrufnummern" handling
*
* Revision 1.18 1999/10/25 18:30:04 akool
* isdnlog-3.57
* WARNING: Experimental version!
@ -92,12 +96,12 @@
* int getZone(int provider, char *from, char *to)
* returns zone for provider, UNKNOWN on not found, -2 on error
*
* int getAreacode(int countrycode, char *num, char **text)
* returns len of areacode in num and in text a malloced string
* UNKNOWN on not found
*
* Changes:
*
* 1.24 1999.10.06 lt removed getAreacode
*
* 1.23 1999.10... lt switch to getDest
*
* 1.22 1999.07.26 lt bug fix, getZone returned junk, when diff. providers
* used the same zone file
*
@ -157,10 +161,7 @@ struct sth {
static struct sth *sthp;
static int count;
static char version[] = "1.23";
#ifndef USE_DESTINATION
static bool area_read = false;
#endif
static char version[] = "1.24";
#define LINK 127
#define INFO_LEN 80
@ -240,72 +241,9 @@ int initZone(int provider, char *path, char **msg)
{
static char message[LENGTH];
int res;
#ifndef USE_DESTINATION
char * dir;
char * file;
char *p;
DIR *dp;
struct dirent *ep;
int len, i;
#endif
if (msg)
*(*msg=message)='\0';
res = _initZone(provider, path, msg, ZONES);
#ifndef USE_DESTINATION
if (area_read || res)
return res;
area_read = true;
if ((p = strrchr(path, '/')) == 0) {
dir = "./";
file = path;
}
else {
if ((dir = strdup(path)) == 0) {
if (msg)
snprintf (message, LENGTH,
"Zone V%s: Error: Out of mem 10", version);
return res;
}
p = strrchr(dir, '/');
if ((file = strdup(p+1)) == 0) {
if (msg)
snprintf (message, LENGTH,
"Zone V%s: Error: Out of mem 11", version);
return res;
}
p[1] = '\0';
}
if ((dp = opendir(dir)) == 0) {
if (msg)
snprintf (message, LENGTH,
"Zone V%s: Error: Out of mem 11", version);
return res;
}
len = strchr(file,'-')-file;
i = 0;
while ((ep = readdir(dp))) { /* zone-cc-xx */
if (memcmp(ep->d_name, file, len) == 0 && memcmp(ep->d_name, file, len+3) != 0) {
int l=strlen(dir)+strlen(ep->d_name)+1;
char *npath=malloc(l);
strcpy(npath, dir);
strcat(npath, ep->d_name);
_initZone(10000+i, npath, 0, AREACODES);
i++;
free(npath);
}
}
closedir(dp);
if ((p = strrchr(path, '/')) != 0) {
free(dir);
free(file);
}
if (msg && strlen(message) < LENGTH-5) {
strcat(message, " - ");
for (i=0; i<count; i++)
if(sthp[i].provider>=10000 && sthp[i].cc && strlen(message) < LENGTH-5)
sprintf(message+strlen(message),"%d ",sthp[i].cc);
}
#endif
return res;
}
@ -454,13 +392,6 @@ static int _initZone(int provider, char *path, char **msg, bool area_only)
sthp[ocount].numlen = strtol(p, &p, 10);
p--; /* get's incr after, so we miss 0x0*/
break;
#ifndef USE_DESTINATION
case 'A' : /* this provider has the areacodes for county A */
p++;
sthp[ocount].cc = strtol(p, &p, 10);
p--; /* get's incr after, so we miss 0x0*/
break;
#endif
}
} /* for */
if (*dbv == 'G')
@ -518,21 +449,12 @@ static int _initZone(int provider, char *path, char **msg, bool area_only)
if (*dbv == 'G')
free(value.dptr);
if (msg) {
#ifdef USE_DESTINATION
snprintf (message, LENGTH,
"Zone V%s: Provider %d File '%s' opened fine - "
"V%s K%d C%d N%d T%d O%d L%d",
version, provider, path,
dversion, sthp[ocount].pack_key, sthp[ocount].pack_table,
csize, tsize, sthp[ocount].oz, sthp[ocount].numlen);
#else
snprintf (message, LENGTH,
"Zone V%s: Provider %d File '%s' opened fine - "
"V%s K%d C%d N%d T%d O%d L%d A%d",
version, provider, path,
dversion, sthp[ocount].pack_key, sthp[ocount].pack_table,
csize, tsize, sthp[ocount].oz, sthp[ocount].numlen, sthp[ocount].cc);
#endif
}
}
else {
@ -635,85 +557,6 @@ int getZone(int provider, char *from, char *to)
return UNKNOWN;
}
#ifndef USE_DESTINATION
static int _getAreacode(struct sth *sthp, char *from, char **text) {
_DB fh = sthp->fh;
datum key, value;
char newfrom[LENGTH];
int len;
UL lifrom; /* keys could be long */
US ifrom;
int dummy1; /* if these are not here 2.7.2.3 destroys ifrom !§@$%&@ */
int dummy2;
char *p;
dummy1 = dummy2 = 0; /* keep the compiler happy */
strncpy(newfrom, from, sthp->numlen);
newfrom[sthp->numlen] = '\0';
len=strlen(newfrom);
while (len) {
lifrom = (UL) strtoul(newfrom, &p, 10); /* keys could be long */
ifrom = (US) lifrom;
if (sthp->pack_key == 2) {
if (lifrom >= 0x10000) { /* can't be, so cut a dig */
newfrom[--len] = '\0';
continue;
}
key.dptr = (char *) &ifrom;
key.dsize = sizeof(US);
}
else {
if (lifrom >= 0x10000000L) { /* can't be, so cut a dig */
newfrom[--len] = '\0';
continue;
}
key.dptr = (char *) &lifrom;
key.dsize = sizeof(UL);
}
value = FETCH(fh, key);
if (value.dptr) {
if (!*value.dptr) {/* found shortcut */
if (*dbv == 'G') /* GDBM has a malloced string in dptr */
free(value.dptr);
return UNKNOWN;
}
if ((p = strchr(value.dptr, '\t')) != 0) { /* NL */
*p = '\0';
len = p[1] - '0'; /* gcc2.7.2.3 segfaults here if strtoul ?? */
if (text)
*text = strdup(value.dptr);
if (*dbv == 'G')
free(value.dptr);
}
else {
if (*dbv == 'G')
if(text)
*text = value.dptr;
else
free(value.dptr);
else if(text)
*text = strdup(value.dptr);
}
return len;
} /* if dptr */
newfrom[--len] = '\0';
}
return UNKNOWN;
}
int getAreacode(int country, char *from, char **text)
{
int i;
for (i=0; i<count; i++)
if (sthp[i].cc == country) {
if (sthp[i].fh == 0)
return UNKNOWN;
return _getAreacode(&sthp[i], from, text);
}
return UNKNOWN;
}
#endif
#ifdef ZONETEST
@ -732,27 +575,10 @@ static int checkZone(char *zf, char* df,int num1,int num2, bool verbose)
if(verbose)
printf("%s\n", msg);
if (num1 && num2) {
#ifndef USE_DESTINATION
char *ort1, *ort2;
#endif
snprintf(from, 9, "%d",num1);
snprintf(to, 9, "%d",num2);
ret = getZone(1, from, to);
#ifndef USE_DESTINATION
if (cc) {
if (getAreacode(cc, from, &ort1) >0 &&
getAreacode(cc, to, &ort2) >0) {
printf("%s(%s) %s(%s) = %d\n", from, ort1, to, ort2, ret);
free(ort1);
free(ort2);
}
else
goto no_ort;
}
else
no_ort:
#endif
printf("%s %s = %d\n", from, to, ret);
printf("%s %s = %d\n", from, to, ret);
}
else {
FILE *fp;
@ -805,131 +631,21 @@ no_ort:
return ret;
}
#ifndef USE_DESTINATION
static int checkArea(char *df, int cc, char *from, int verbose) {
char *msg, *text;
int ret=0;
if (initZone(1, df, &msg)) {
fprintf(stderr,"%s\n", msg);
exit(1);
}
if(verbose)
printf("%s\n", msg);
ret = getAreacode(cc, from, &text);
if(ret != UNKNOWN) {
printf("%s:%d '%s'\n", from, ret, text);
free(text);
}
else
printf("%s - UNKNOWN\n", from);
exitZone(1);
return ret;
}
static int checkAllArea(char *df, char *cf, int cc, int verbose) {
char *msg;
int ret=0;
FILE *fp;
char line[BUFSIZ];
char from[20];
char *ort;
char *p, *q;
int i, n, len, olen;
int ifrom;
if (initZone(1, df, &msg)) {
fprintf(stderr,"%s\n", msg);
exit(1);
}
if(verbose)
printf("%s\n", msg);
if ((fp = fopen(cf, "r")) == 0) {
fprintf(stderr, "Can't read %s\n", cf);
exitZone(1);
exit(1);
}
n=0;
while (!feof(fp)) {
if (!fgets(line, BUFSIZ, fp))
break;
line[strlen(line)-1] = '\0';
p=line;
q=from;
if (!isdigit(*p))
continue;
i=0;
while (isdigit(*p) && ++i<9) {
*q++ = *p++;
}
*q = '\0';
p++;
/* NL */
if ((q = strchr(p, '\t'))) {
*q = '\0';
olen = strtoul(q+1,0, 10);
}
else
olen = strlen(from);
ifrom=atol(from);
/* append some randoms - this doesn't in NL !!! */
#ifdef APPEND_RANDS
for (i=0; i< 20; i++) {
sprintf(from, "%d%d%d", ifrom, i, rand() % 999999);
#endif
if((++n % 1000) == 0 && verbose) {
fprintf(stderr,"%d\r",n);
fflush(stderr);
}
len = getAreacode(cc, from, &ort);
if (olen != len || strcmp(ort, p)) {
fprintf(stderr, "Err: %s:%s not %s Len %d\n", from, p, ort, len);
free(ort);
ret = 1;
break;
}
free(ort);
#ifdef APPEND_RANDS
}
#endif
}
fclose(fp);
exitZone(1);
if (verbose)
printf("'%s' verified %s.\n", df, ret==0? "Ok": "NoNo");
free(cf);
free(df);
return ret;
}
#endif
int main (int argc, char *argv[])
{
int verbose=false;
char *df=0;
char *zf=0;
#ifndef USE_DESTINATION
int cc=0;
char *cf=0;
#endif
int c;
int num1=0, num2=0;
char snum1[LENGTH];
#ifdef USE_DESTINATION
while ( (c=getopt(argc, argv, "vVd:z:")) != EOF) {
#else
while ( (c=getopt(argc, argv, "vVd:z:a:c:")) != EOF) {
#endif
switch (c) {
case 'v' : verbose = true; break;
case 'V' : printf("%s: V%s\n", basename(argv[0]), version); exit(1);
case 'd' : df = strdup(optarg); break;
case 'z' : zf = strdup(optarg); break;
#ifndef USE_DESTINATION
case 'a' : cc = atoi(optarg); break;
case 'c' : cf = strdup(optarg); break;
#endif
}
}
while (optind < argc) {
@ -948,19 +664,7 @@ int main (int argc, char *argv[])
}
if (df && (zf || (num1 && num2)))
return checkZone(zf, df, num1, num2, verbose);
#ifndef USE_DESTINATION
if (df && num1 && cc)
return checkArea(df, cc, snum1, verbose);
if (df && cf && cc)
return checkAllArea(df, cf, cc, verbose);
#endif
#ifdef USE_DESTINATION
fprintf(stderr, "Usage:\n%s -d DBfile -v -V { -z Zonefile | num1 num2 }\n", basename(argv[0]));
#else
fprintf(stderr, "Usage:\n%s -d DBfile -v -V { -z Zonefile | num1 num2 | -a cc num}\n", basename(argv[0]));
fprintf(stderr, "\t-d DBfile -v -V -a CC num1 \n");
fprintf(stderr, "\t-d DBfile -c Codefile -a CC -v -V\n");
#endif
return 0;
}
#endif

View File

@ -1,4 +1,4 @@
/* $Id: zone.h,v 1.2 1999/06/26 12:26:35 akool Exp $
/* $Id: zone.h,v 1.3 1999/11/07 13:29:29 akool Exp $
*
* Verzonungsberechnung
*
@ -19,6 +19,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: zone.h,v $
* Revision 1.3 1999/11/07 13:29:29 akool
* isdnlog-3.64
* - new "Sonderrufnummern" handling
*
* Revision 1.2 1999/06/26 12:26:35 akool
* isdnlog Version 3.37
* fixed some warnings
@ -37,6 +41,5 @@
int initZone (int provider, char *path, char **msg);
void exitZone (int provider);
int getZone (int provider, char *from, char *to);
int getAreacode(int country, char *from, char **text);
#endif

View File

@ -6,7 +6,6 @@
BZIP2 = @BZIP2@
SHELL = /bin/sh
CFLAGS = -Wall -g
DEFS = -DUSE_DESTINATION
INCLUDES =
LDFLAGS = @DBMLIB@
DBEXT = @DBEXT@

View File

@ -4,9 +4,6 @@
* Copyright 1999 by Leopold Toetsch <lt@toetsch.at>
*
* SYNOPSIS
* mkzonedb -r Zonefile -d database -c Codef [-f] [-v] [-V] [-o Oz] [-l L]
*
* 1.23: w. USE_DESTINATION
* mkzonedb -r Zonefile -d database [-f] [-v] [-V] [-o Oz] [-l L]
*
* This program is free software; you can redistribute it and/or modify
@ -25,11 +22,7 @@
*
*/
#ifdef USE_DESTINATION
static char progversion[] = "1.23";
#else
static char progversion[] = "1.11";
#endif
static char progversion[] = "1.24";
/*
* Changes:
@ -69,11 +62,7 @@ extern const char *basename (const char *name);
void usage(char *argv[]) {
#ifdef USE_DESTINATION
fprintf(stderr, "%s: -r RedZonefile -d Database [ -v ] [ -V ] [ -o Localzone ] [ -l Len ]\n",
#else
fprintf(stderr, "%s: -r RedZonefile -d Database -c Code [-a CC] [ -v ] [ -V ] [ -o Localzone ] [ -l Len ]\n",
#endif
basename(argv[0]));
exit(EXIT_FAILURE);
}
@ -84,73 +73,9 @@ static bool verbose=false;
static int table[256];
static int tablelen, keylen, keydigs, maxnum;
static int n, nn;
#ifndef USE_DESTINATION
typedef struct {
int num;
char *code;
} code_t;
static code_t *codes = 0;
static int nc;
static int country=0;
#endif
static int ortszone=1;
static int numlen;
#ifndef USE_DESTINATION
static void read_codefile(char *cf) {
FILE *fp;
char *p;
auto char line[BUFSIZ];
nc = 0;
if (verbose)
printf("Reading %s\n", cf);
if ((fp=fopen(cf, "r")) == 0) {
fprintf(stderr, "Coudn't read '%s'\n", cf);
exit(EXIT_FAILURE);
}
maxnum = 0;
while (fgets(line, BUFSIZ, fp)) {
if (verbose && (nc % 1000) == 0) {
printf("%d\r", nc);
fflush(stdout);
}
if (!isdigit(*line))
break;
line[strlen(line)-1] = '\0';
if ((codes=realloc(codes, (nc+1)*sizeof(code_t))) == 0) {
fprintf(stderr, "Out of mem\n");
exit(EXIT_FAILURE);
}
codes[nc].num = strtoul(line, &p, 10);
if (codes[nc].num > maxnum)
maxnum = codes[nc].num;
if (*p != '\t') {
fprintf(stderr, "'%s' seems to be an invalide codfile\n", cf);
exit(EXIT_FAILURE);
}
if ( (codes[nc].code = strdup(++p)) == 0) {
fprintf(stderr, "Out of mem\n");
exit(EXIT_FAILURE);
}
nc++;
}
if (verbose) {
printf("%d Codes read\n", nc);
fflush(stdout);
}
fclose(fp);
/* we append a dummy for not defined nums */
if ((codes=realloc(codes, (nc+1)*sizeof(code_t))) == 0) {
fprintf(stderr, "Out of mem\n");
exit(EXIT_FAILURE);
}
codes[nc].num=-1;
codes[nc].code=strdup("");
free(cf);
}
#endif
static void read_rzfile(char *rf) {
int i;
char line[BUFSIZ], *p, *op;
@ -161,9 +86,7 @@ static void read_rzfile(char *rf) {
fprintf(stderr, "Coudn't read '%s'\n", rf);
exit(EXIT_FAILURE);
}
#ifdef USE_DESTINATION
maxnum = numlen==5 ? 40000 : 10000;
#endif
if ((numbers = calloc(maxnum+1, sizeof(int))) == 0) {
fprintf(stderr, "Out of mem\n");
exit(EXIT_FAILURE);
@ -206,7 +129,6 @@ static void read_rzfile(char *rf) {
keylen=from;
if (to > keylen)
keylen=to;
#ifdef USE_DESTINATION
if(to>maxnum) {
maxnum=to;
if ((numbers = realloc(numbers,(maxnum+1)*sizeof(int))) == 0) {
@ -214,14 +136,11 @@ static void read_rzfile(char *rf) {
exit(EXIT_FAILURE);
}
}
#endif
numbers[to]++;
n++;
}
free(rf);
#ifdef USE_DESTINATION
maxnum=keylen<maxnum?keylen:maxnum;
#endif
}
/* get the 256 top used nums in table */
@ -256,73 +175,6 @@ static void make_table() {
nn = 256;
}
#ifndef USE_DESTINATION
static int comp_func(const void *p1, const void *p2) {
return ((code_t*)p1)->num - ((code_t*)p2)->num;
}
/* insert the code of from into value */
static void insert_code(datum *value, int ifrom) {
int l;
code_t *cp, key;
key.num = ifrom;
cp = bsearch(&key, codes, nc, sizeof(code_t), comp_func);
if (!cp)
cp = &codes[nc];
l = strlen(cp->code) + 1;
if ((value->dptr = realloc(value->dptr, value->dsize+l)) == 0) {
fprintf(stderr, "Out of mem\n");
exit(EXIT_FAILURE);
}
memmove(value->dptr+l, value->dptr, value->dsize);
value->dsize += l;
memcpy(value->dptr, cp->code, l);
*cp->code = '\0'; /* invalidate */
return;
}
static void write_remaining_codes(_DB db) {
int i,l;
UL kul;
US kus;
datum key, value;
char *val;
if (verbose)
printf("Writing remaining\n");
for (i=0 ; i< nc; i++)
if (codes[i].num > 0 && *codes[i].code) {
if (verbose && (i % 1000) == 0) {
printf("%d\r", i);
fflush(stdout);
}
if (keylen == 4) {
kul = (UL)codes[i].num;
key.dptr = (char*)&kul;
}
else {
kus = (US)codes[i].num;
key.dptr = (char*)&kus;
}
key.dsize = keylen;
val = malloc(l=(strlen(codes[i].code)+3));
strcpy(val, codes[i].code);
val[l-1] = val[l-2] = '\0'; /* count=0 */
value.dptr = val;
value.dsize = l;
if(STORE(db, key, value)) {
fprintf(stderr, "Error storing key '%d' - %s\n",codes[i].num,GET_ERR);
exit(EXIT_FAILURE);
}
free(val);
}
}
#endif
static void write_db(char * df) {
_DB db;
datum key, value;
@ -335,10 +187,6 @@ static void write_db(char * df) {
int i, j;
char version[80];
#ifndef USE_DESTINATION
if (country)
qsort(codes, nc, sizeof(code_t), comp_func);
#endif
if (verbose)
printf("Writing\n");
if((db=OPEN(df,WRITE)) == 0) {
@ -356,15 +204,9 @@ static void write_db(char * df) {
key.dptr = "vErSiO";
key.dsize = 7;
/* version of zone.c must be not smaller than dataversion */
#ifndef USE_DESTINATION
sprintf(version,"V1.23 K%c C%c N%d T%d O%d L%d A%d",
keylen==2?'S':'L',tablelen==1?'C':tablelen==2?'S':'L',
nn,n, ortszone, numlen?numlen:keydigs, country);
#else
sprintf(version,"V1.20 K%c C%c N%d T%d O%d L%d",
keylen==2?'S':'L',tablelen==1?'C':tablelen==2?'S':'L',
nn,n, ortszone, numlen?numlen:keydigs);
#endif
value.dptr = version;
value.dsize = strlen(version)+1;
if(STORE(db, key, value)) {
@ -410,10 +252,6 @@ static void write_db(char * df) {
*((US*)val) = count;
value.dptr = val;
value.dsize = vlen;
#ifndef USE_DESTINATION
if (country)
insert_code(&value, ofrom);
#endif
if(STORE(db, key, value)) {
fprintf(stderr, "Error storing key '%d' - %s\n",ofrom,GET_ERR);
exit(EXIT_FAILURE);
@ -469,59 +307,32 @@ static void write_db(char * df) {
*((US*)val) = count;
value.dptr = val;
value.dsize = vlen;
#ifndef USE_DESTINATION
if (country)
insert_code(&value, ofrom);
#endif
STORE(db, key, value);
free(value.dptr);
#ifndef USE_DESTINATION
if (country)
write_remaining_codes(db);
#endif
CLOSE(db);
free(zones);
free(df);
#ifndef USE_DESTINATION
for (i = 0; i <= nc; i++)
free(codes[i].code);
free(codes);
#endif
}
int main (int argc, char *argv[])
{
char *df=0;
char *rf=0;
#ifndef USE_DESTINATION
char *cf=0;
#endif
int c;
if (argc < 2)
usage(argv);
#ifdef USE_DESTINATION
while ( (c=getopt(argc, argv, "vVr:d:o:l:")) != EOF) {
#else
while ( (c=getopt(argc, argv, "vVr:d:c:o:l:a:")) != EOF) {
#endif
switch (c) {
case 'v' : verbose = true; break;
case 'V' : printf("%s: V%s Db=%s\n",
basename(argv[0]), progversion, dbv); exit(1);
case 'd' : df = strdup(optarg); break;
case 'r' : rf = strdup(optarg); break;
#ifndef USE_DESTINATION
case 'c' : cf = strdup(optarg); break;
case 'a' : country = atoi(optarg); break;
#endif
case 'o' : ortszone = atoi(optarg); break;
case 'l' : numlen = atoi(optarg); break;
}
}
#ifndef USE_DESTINATION
read_codefile(cf);
#endif
read_rzfile(rf);
make_table();
write_db(df);