isdnlog-3.43

added "telnum" module
This commit is contained in:
Andreas Kool 1999-07-25 15:58:13 +00:00
parent f3c68a63bf
commit df18cc532e
10 changed files with 860 additions and 296 deletions

View File

@ -19,6 +19,13 @@
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##
## $Log$
## Revision 1.95 1999/07/24 08:43:38 akool
## isdnlog-3.42
## rate-de.dat 1.02-Germany [18-Jul-1999 10:44:21]
## better Support for Ackermann Euracom
## WEB-Interface for isdnrate
## many small fixes
##
## Revision 1.94 1999/07/10 21:37:36 akool
## isdnlog-3.41
## rate-de.dat V:1.02-Germany [10-Jul-1999 23:32:27]
@ -717,7 +724,7 @@ SERVICEFILE = /etc/services
# DON'T EDIT BELOW THIS LINE
######################################################################
VERSION = 3.42
VERSION = 3.43
MANPAGES = isdnlog/callerid.conf.5 isdnlog/isdn.conf.5 \
isdnlog/isdnformat.5 isdnlog/isdnlog.5 isdnlog/isdnlog.8 \
@ -784,6 +791,7 @@ ISDNCONF_OBJS= isdnconf/isdnconf.o tools/tools.o tools/isdnconf.o \
ISDNRATE_OBJS= tools/isdnrate.o tools/isdnconf.o tools/tools.o \
tools/rate.o tools/zone.o tools/country.o tools/holiday.o \
tools/telnum.o \
$(LIBISDNDIR)/libisdn.a
ISDNLOG = bin/isdnlog

View File

@ -359,7 +359,7 @@ C:+673
N:Weihnachtsinseln
A:Weihnachtsinsel (Australien), Christmas Island, Christmas Island (Antarctica)
A:Christmas Inseln,Weihnachtsinsel
A:Christmas Islands, Christmas Inseln,Weihnachtsinsel
C:+6724
N:Norfolkinseln
@ -368,7 +368,7 @@ C:+6723
N:Kokosinseln
A:Kokosinseln (Australien), Cocos Island, Cocos Island (Antarctica)
A:Cocos Inseln
A:Cocos Islands, Cocos Inseln
C:+6722, +6189162
N:Antarktis
@ -412,6 +412,7 @@ A:Australia
C:+61
N:Malaysia
A:Malaysien
C:+60
N:Niederl. Antillen
@ -1175,7 +1176,7 @@ C:+1809946, +1809941, +1649
N:Amerikanische Jungferninseln
A:Jungferninseln (USA), Amerikan. Jungferninseln, American Virgin Isles
A:US Jungferninseln
A:US Jungferninseln, Virgin Islands (US)
C:+180977, +1809719, +1809715, +1809714, +1809713, +1809712, +1809693, +1809692, +1809690, +1809611, +1809513, +1340
N:Britische Jungferninseln

View File

@ -19,6 +19,13 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log$
* Revision 1.78 1999/07/24 08:44:19 akool
* isdnlog-3.42
* rate-de.dat 1.02-Germany [18-Jul-1999 10:44:21]
* better Support for Ackermann Euracom
* WEB-Interface for isdnrate
* many small fixes
*
* Revision 1.77 1999/07/15 16:41:32 akool
* small enhancement's and fixes
*
@ -4766,8 +4773,14 @@ retry:
if (((ignoreRR & 2) == 2) && !memcmp(p1 + 14, "AA", 2))
go = 0;
if (go)
processctrl(card, p1);
if (go) {
if (!memcmp(p1, "ECHO:", 5)) { /* Echo-channel from HFC card */
memcpy(p1 + 1, "HEX", 3);
processctrl(card + 1, p1 + 1);
}
else
processctrl(card, p1);
} /* if */
} /* else */
p1 = p2 + 1;

View File

@ -11,7 +11,7 @@
# for collecting and preparing most of the call charges.
V:1.81-Austria [22-Jul-1999]
V:1.83-Austria [25-Jul-1999]
U:%.3f öS
@ -1793,27 +1793,55 @@ A:Zentralafrikanische Republik
P:67 max.plus
C:maintained by: Michael Reinelt <reinelt@eunet.at>
C:Fixme: Taktung unbekannt
Z:1 Festnetz
T:*/*=1.00(60)/1 rund um die Uhr
T:*/*=1.00(60)/30 rund um die Uhr
A:Österreich
Z:2 max.box
T:*/*=1.00(60)/1 rund um die Uhr
T:*/*=1.00(60)/30 rund um die Uhr
A:+4367622
Z:3 max.online
T:*/*=1.00(60)/1 rund um die Uhr
A:+4367620
T:*/*=1.00(60)/30 rund um die Uhr
A:+436762323
Z:4 max.mobil
T:*/*=2.70(60)/1 rund um die Uhr
T:*/*=2.70(60)/30 rund um die Uhr
A:+43676
Z:5 andere Mobilfunknetze
T:*/*=3.90(60)/1 rund um die Uhr
T:*/*=3.90(60)/30 rund um die Uhr
A:+43663, +43664, +43669
Z:6 Nachbarländer
T:*/*=3.30(60)/1 rund um die Uhr
A:Deutschland, Italien
T:*/*=3.30(60)/30 rund um die Uhr
A:Deutschland, Italien, Schweiz, Tschechische Republik, Ungarn
A:Slowakische Republik, Slowenien, Liechtenstein
Z:7 EU
T:*/*=3.50(60)/1 rund um die Uhr
T:*/*=3.50(60)/30 rund um die Uhr
A:Belgien, Dänemark, Finnland, Frankreich, Griechenland, Irland, Luxemburg
A:Niederlande, Portugal, Spanien, Schweden, Großbritannien, Nordirland
Z:8 Weltzone 1
T:*/*=5.50(60)/30 rund um die Uhr
A:Andorra, Australien, Bahamas, Bosnien-Herzegowina, Kanada, Kroatien, Faröer
A:Gibraltar, Island, Japan, Lettland, Malta, Mazedonien, Monaco, Neuseeland
A:Norwegen, Polen, Puerto Rico, San Marino, Singapur, USA, Vatikan
A:Jugoslawien
Z:9 Weltzone 2
T:*/*=9.70(60)/30 rund um die Uhr
A:Albanien, Algerien, Belarus, Bulgarien, Zypern, Estland, Hong Kong, Litauen
A:Marokko, Oman, Rumänien, Rußland, Tunesien, Türkei, Ukraine
A:Virgin Islands (US)
Z:10 Weltzone 3
T:*/*=15.00(60)/30 rund um die Uhr
A:Bermuda, Brasilien, Brunei, Chile, Christmas Islands, Cocos Islands
A:Dominikanische Republik, Georgien, Ghana, Grönland, Israel, Jamaica
A:Kasachstan, Korea, Kirgisistan, Libyen, Macau, Malaysien, Mexiko, Südafrika
A:Taiwan, Tadschikistan
Z:11 Weltzone 4
T:*/*=22.00(60)/30 rund um die Uhr
A:+ alle übrigen Länder
Z:12 Iridium 8816
T:*/*=122.00(60)/30 rund um die Uhr
A:Iridium 008816
Z:13 Iridium 8817
T:*/*=62.00(60)/30 rund um die Uhr
A:Iridium 008817
P:69 ONE
Z:1 Festnetz

View File

@ -9,6 +9,7 @@
# For commercial usage on public webservers contact the author.
use CGI qw(:standard);
use CGI::Carp 'fatalsToBrowser';
use strict;
use GD;
use IO::Handle;
@ -19,8 +20,9 @@ my $server='/tmp/isdnrate';
# configure adjusts these n/y :-(
my $MKTEMP= '/bin/mktemp';
my $ISDNRATE='/home/lt/src/testi4l/isdnlog/bin/isdnrate';
my $CODEF= '/home/lt/src/testi4l/isdnlog/tools/zone/de/code';
my $CODEF= '/home/lt/src/testi4l/isdnlog/tools/zone/at/code';
my $tempdir=$ENV{'DOCUMENT_ROOT'};
my $DEFLEN=153;
# end configurable
my $debug=0;
@ -94,6 +96,7 @@ my @countries=($LEER, "Afghanistan","
"West-Samoa","Zaire","Zentralafrikanische Republik","Zypern");
my %towns = (0 => $LEER);
my (%url, $len);
# main
&html_header;
@ -102,11 +105,23 @@ if ($debug==2) {
$q->print(hr, $q->dump());
$q->print(hr);
}
my ($weekly, $daily);
my ($weekly, $daily, @names, $help);
$weekly=param('graf') =~ /Wo/;
$daily=param('graf') =~ /Tag/;
&get_results if(param('tab') eq 'Tabelle');
&make_graf if(param('graf'));
@names=param();
$help=0;
push(@names, 'help_tel.x') if (@names &&
!param('tel') && !param('town') && !param('country'));
foreach (@names) {
if (/help_(.*?)\.x/) {
show_help($1);
$help=1
}
}
if (!$help) {
&get_results if(param('tab') eq 'Tabelle');
&make_graf if(param('graf'));
}
&print_form;
&clean_up;
$q->print(end_html);
@ -144,6 +159,7 @@ sub html_header {
<!--
.t {font-face:Sans Serif;font-size:10pt}
.sm {font-face:Sans Serif;font-size:9pt}
i {color:#000080}
-->
</STYLE>
<SCRIPT>
@ -162,7 +178,60 @@ sub read_towns {
}
close(IN);
}
sub help {
my $help = 'help_'. $_[0];
image_button(-name=>$help, -src=>'/pic/help.gif');
}
sub show_help {
my $what = $_[0];
if ($what eq 'from') {
$q->print('Normalerweise weiß isdnrate, von wo Sie telefonieren. ');
$q->print('Sie können hier aber einen anderen Standort eingeben. ');
$q->print('Dann werden die Gebühren von dieser Vorwahl aus berechnet');
$q->print(br,'Z.b. ', tt('02345'));
}
elsif($what eq 'tel') {
$q->print('Geben Sie die Nummer ein, zu der Sie die Gebühren ');
$q->print('berechnet haben möchten.',br);
$q->print(ul(li(tt("1234\t"),'Ortsnetz'),
li(tt("012345\t"),'Anderer Ort'),
li(tt("00156789\t"),'Ausland'),
li(tt("[0]1012012345\t"),'Provider+Nummer')),
'oder wählen Sie aus der Liste der Städte oder Länder.',br,
'Hinweis: eine ausgewählte Stadt hat Priorität vor einem Land, ',
'dieses vor einer manuellen Eingabe.');
}
elsif($what eq 'len') {
$q->print('Wählen Sie hier Dauer und Zeitpunkt des Gesprächs. ');
$q->print('Mittels ',i('Start'),' können Sie aktuelle Gespräche mitstoppen ');
$q->print('und sich so die laufenden Gesprächsgebühen anzeigen lassen.',br);
$q->print('Wenn ',i('Jetzt'),' nicht angekreuzt ist, können Sie einen beliebigen ');
$q->print('Zeitpunkt eingeben.');
}
elsif($what eq 'tab') {
$q->print('Mit der Schaltfläche ',i('Tabelle'),' erhalten Sie eine ');
$q->print('Aufstellung der Telefongebühen pro Provider.');
}
elsif($what eq 'graf') {
$q->print('Mit der Schaltfläche ',i('Grafik'),' erhalten Sie eine ');
$q->print('grafische Darstellung des Verlaufs der Telefongebühen bis ');
$q->print('zur gewählten Dauer. Damit sehen Sie sehr übersichtlich, ');
$q->print('ob der Provider Sekundentakt oder einen anderen vewendet.');
}
elsif($what eq 'tag') {
$q->print('Die Schaltflächen ',i('Tag'),' und ',i('Woche'),' zeigen die ');
$q->print('Gebühren für die gewählte Dauer und den gewählten Tag im Verlauf eines Tages bzw. einer Woche.');
}
elsif($what eq 'prov') {
$q->print('Wählen Sie hier welche und wie viele Provider angzeigt werden. ');
$q->print('Sind ',i('nur Provider'),' angegeben, werden nur diese angezeigt. ');
$q->print('Sind ',i('nicht Provider'),' angegeben, werden diese nicht angezeigt.');
$q->print(br,'Hinweis: wenn Sie mehrere Provider eingeben, trennen Sie diese ');
$q->print('mit einem Beistrich oder Leerzeichen.');
$q->print(br,i('Reset'),' stellt den vorhergehenden Zustand wieder her, ');
$q->print(i('Löschen'),' löscht alle Eingabefelder, bzw. stellt Standardwerte ein.');
}
}
sub print_form {
my($t, @cod);
foreach $t (sort {$towns{$a} cmp $towns{$b} } (keys(%towns))) {
@ -174,6 +243,7 @@ sub print_form {
else {
param('now','on');
param('best',20);
param('len',$DEFLEN);
}
$q->print(
start_form(-name=>'form'),
@ -181,55 +251,60 @@ sub print_form {
Tr(td(table({-bgcolor=>'#ffffe0', -cellspacing=>0, -cellpadding=>0},
Tr([
td([ b("Ich wähle von: "),
textfield(-name=>'from', -size=>20, -maxlength=>20),'&nbsp;','&nbsp;']),
td({-colspan=>4},hr),
textfield(-name=>'from', -size=>20, -maxlength=>20),'&nbsp;',
'&nbsp;',&help('from')
]),
td({-colspan=>5},hr),
td(["<b>nach</b> TelefonNummer: ",
textfield(-name=>'tel', -size=>20, -maxlength=>20),'&nbsp;','&nbsp;']),
textfield(-name=>'tel', -size=>20, -maxlength=>20),'&nbsp;',
'&nbsp;',&help('tel')]),
td(["oder Stadt: ",
popup_menu(-name=>'town', -values=> \@cod, -labels=> \%towns),
"oder Ausland: ",
popup_menu(-name=>'country', -values=> \@countries)]),
td({-colspan=>4},hr),
popup_menu(-name=>'country', -values=> \@countries),'&nbsp;']),
td({-colspan=>5},hr),
td(["<b>Dauer</b> (sec)",
textfield(-name=>'len', -size=>4, -maxlength=>4, -value=>60),
textfield(-name=>'len', -size=>4, -maxlength=>4),
"Stoppuhr",
button(-name=>'Start',-value=>'Start', -onClick=>'start()')]),
button(-name=>'Start',-value=>'Start', -onClick=>'start()'),
&help('len')]),
td([checkbox(-name=>'now', -label=>'Jetzt - oder am'),
popup_menu(-name=>'dday', -values=> ['W','N','E'],
-labels=> {'W' =>'Wochentag-10 h','N'=>'Nacht','E'=>'Sonntag'}),
'&nbsp;','&nbsp;']),
'&nbsp;','&nbsp;','&nbsp;']),
td(["oder um (hh[:mm[:ss]]) ",
textfield(-name=>'hour', -size=>8, -maxlength=>8),
"am (dd[.mm[.jj]]) ",
textfield(-name=>'day', -size=>10, -maxlength=>10)]),
td({-colspan=>4},hr),
textfield(-name=>'day', -size=>10, -maxlength=>10),'&nbsp;']),
td({-colspan=>5},hr),
td({-bgcolor=>'#ffc080'},[b(" Ausgabe "),
submit('tab','Tabelle'),
"mit",
popup_menu(-name=>'explain', -values=> [0,1,2],
-labels=> {0 =>'Nur Kosten',1=>'Zonen',2=>'Details'})]),
-labels=> {0 =>'Nur Kosten',1=>'Zonen',2=>'Details'}),&help('tab')]),
td({-bgcolor=>'#00bfff'},["oder",
submit('graf',' Grafik '),
"Größe",
popup_menu(-name=>'swidth', -values=> ['1024','800','640'],
-labels=> {'1024' =>'groß','800'=>'mittel','640'=>'klein'})]),
-labels=> {'1024' =>'groß','800'=>'mittel','640'=>'klein'}),
&help('graf')]),
td({-bgcolor=>'#ffdead'},[
"oder Tagespreise",
submit('graf',' Tag '),
"oder Wochenpreise",
submit('graf','Woche ')
submit('graf','Woche '),&help('tag')
]),
td({-colspan=>4},hr),
td({-colspan=>5},hr),
td([" der besten ",
textfield(-name=>'best', -size=>2, -maxlength=>2),
"Provider",'&nbsp;']),
"Provider",'&nbsp;',&help('prov')]),
td(['oder nur Provider',
textfield(-name=>'prov', -size=>20, -maxlength=>100),
'oder nicht Provider',
textfield(-name=>'xprov', -size=>20, -maxlength=>100)]),
textfield(-name=>'xprov', -size=>20, -maxlength=>100),'&nbsp;']),
td(['&nbsp;','&nbsp;',
reset('Reset'),
defaults('Löschen')])
defaults('Löschen'),'&nbsp;'])
]))))),
end_form,
p,
@ -249,9 +324,20 @@ sub print_form {
);
}
sub del_vbn {
my @p = split(/,/, $_[0]);
my (@np, $ret);
foreach (@p) {
s/^0?10//;
$_=100+$_ if (length($_) == 3);
push(@np, $_);
}
$ret=join(',',@np);
$ret;
}
sub call_isdnrate {
my ($hour, $day);
my ($len, $lines) = @_;
my ($lines) = @_;
my ($now, $explain, $tel, $from, $best, $prov);
if (param('town') != '0') {
param('country', $LEER);
@ -262,11 +348,11 @@ sub call_isdnrate {
param('tel','');
param('town', $LEER);
$tel=param('country');
$tel =~s/ /_/g; # preserv spaces
}
else {
$tel = param('tel') =~ /\d+/ ? $& : '';
$tel = param('tel');
}
$tel =~s/ /_/g; # preserv spaces
return if($tel eq '');
my @args=($ISDNRATE,"-H", $tel);
unless (param('now')) {
@ -274,11 +360,13 @@ sub call_isdnrate {
push(@args, "-d$day") if ($day=param('day')||param('hour')?param('day'):param('dday'));
}
if ($prov=param('xprov')) {
$prov =~ s/\s//g;
$prov =~ s/\s+/,/g;
$prov=&del_vbn($prov);
push(@args, "-x$prov");
}
elsif ($prov=param('prov')) {
$prov =~ s/\s//g;
$prov =~ s/\s/,/g;
$prov=&del_vbn($prov);
push(@args, "-p$prov");
}
push(@args, "-f$from") if ($from=param('from'));
@ -288,6 +376,9 @@ sub call_isdnrate {
else {
push(@args, "-X$explain") if ($explain=param('explain'));
}
$len=sprintf("%d",param('len')) || $DEFLEN;
$len=min($len, 1200);
param('len', $len);
push(@args, "-l$len");
$best=param('best');
param('best', $best>0 ? $best: 20);
@ -315,13 +406,11 @@ sub call_isdnrate {
}
sub get_results {
my (@lines, $len);
my($pnum, $prov, $cur, $charge, $bgcolor, $i, $rest);
$len=sprintf("%d",param('len')) || 60;
&call_isdnrate($len, \@lines);
param('len',$len);
my (@lines);
my($pnum, $prov, $cur, $charge, $bgcolor, $i, $rest, $url);
&call_isdnrate(\@lines);
$lines[0] = &fmt_date($lines[0]);
$q->print(hr, $lines[0], p);
$q->print(p({-class=>'t'},$lines[0]));
shift(@lines); # -H
shift(@lines); # empty
(undef, $cur) = split(/ +/, $lines[0]);
@ -331,8 +420,10 @@ sub get_results {
$i=0;
foreach (@lines) {
($pnum, $prov, $cur, $charge, $rest) = &split_line($_);
$url{$pnum}="#$pnum"; # TODO
$url=a({-href=>$url{$pnum}}, $prov);
$bgcolor=++$i&1?' bgcolor="#e0e0e0"':'';
$q->print(qq(<tr$bgcolor><td>$pnum</td><td>$prov</td><td align="right">$charge</td>));
$q->print(qq(<tr$bgcolor><td>$pnum</td><td>$url</td><td align="right">$charge</td>));
$q->print(qq(<td><font size="-1">$rest</font></td>)) if(param('explain'));
$q->print("</tr>\n");
}
@ -385,19 +476,17 @@ sub max {
sub make_graf {
my ($W, $H, $LEG, $LIN, $white, $black, $lgrey, $llgrey, $tempf, $i);
my (@lines, $n, $xo, $yo, $dx, @rawcolors, @colors, %pstring, %unused);
my ($prov, $cur, $charge, $pnum, %pc, %pt, $r, $g, $bl, $len);
my ($prov, $cur, $charge, $pnum, %pc, %pt, $r, $g, $bl);
my ($swidth, %dim);
$swidth=param('swidth')||1024;
# dimensions
%dim = (1024=>[700,350,240], 800=>[500,250,200],640=>[300,200,200]);
%dim = (1024=>[700,370,240], 800=>[500,250,200],640=>[300,200,200]);
$W=$dim{$swidth}[0];
$H=$dim{$swidth}[1];
$LEG=$dim{$swidth}[2];
$LIN=50;
$dx = 10;
$xo=25; $yo=20;
$len=min(param('len'), 600);
param('len', $len);
# make some colors
$n=0;
foreach $g ('00','33','66','99') {
@ -427,7 +516,7 @@ sub make_graf {
$im->filledPolygon($poly, $lgrey);
# get data
my ($c,$text);
&call_isdnrate($len, \@lines);
&call_isdnrate(\@lines);
foreach (@lines) {
if (/^\@--+ (\S+) (\S.*)/) { # end
if ($pnum && $#{ $pc{$pnum} } == 0) { # any data
@ -439,13 +528,20 @@ sub make_graf {
}
$pstring{$pnum} = $2;
$cur=$1;
if ($daily || $weekly) {
push( @{ $pt{$pnum} }, $daily?24:7*24); # time
push( @{ $pc{$pnum} }, $pc{$pnum}[0]); # charge
}
$url{$pnum}="#$pnum"; # TODO
$pnum = '';
}
elsif (/^\@ (\d+)/) { # start
$pnum=$1;
if (!$daily && !$weekly) {
push( @{ $pt{$pnum} }, 0); # time
push( @{ $pc{$pnum} }, 0); # charge
}
}
elsif (/(\d+) (\d+\.\d+)/ && $pnum) {
push( @{ $pt{$pnum} }, $1==1?0.1:$1); # time
push( @{ $pc{$pnum} }, $2); # charge
@ -488,11 +584,11 @@ sub make_graf {
$im->string($font, 4, $H-$yo-$my*$ys+3+$font->height, $cur, $black);
# x-axis
if ($weekly) {
$len=7*24;
$len=7*24+1;
$dx=1;
}
elsif ($daily) {
$len=24;
$len=25;
$dx=1;
}
else {
@ -515,7 +611,7 @@ sub make_graf {
$tx = $i;
}
else {
$tx = $i == int($len/$dx)-2 ? $i ." s" : $i; # nn s
$tx = $i == $dx*(int($len/$dx)-1) ? $i ." s" : $i; # nn s
}
$im->string($font, $xo+$i*$xs+3, $H-$yo+2, $tx, $black);
}
@ -544,7 +640,7 @@ sub make_graf {
$im->rectangle($xo,0,$W-1,$H-$yo,$black);
# legend
$im->filledRectangle($W+1,0,$W+$LEG-1,$H-1,$llgrey);
my ($ndy, $y, $sy);
my ($ndy, $y, $sy, $mapx, $mapy, @map);
$y=2;
$i=min($n,keys(%rcols));
$n=0;
@ -554,8 +650,9 @@ sub make_graf {
$y = max($y,min($ndy,$sy));
$im->dashedLine($W+2,$H-$yo-$sy, $W+$LIN,$H-$yo-$y, $rcols{$p});
$im->dashedLine(1+$W+2,1+$H-$yo-$sy,1+$W+$LIN,1+$H-$yo-$y, $rcols{$p});
$im->string($font, $W+$LIN+5, $H-$yo-$y-$font->height/2, "$p ".$pstring{$p}, $rcols{$p});
$im->string($font, $mapx=$W+$LIN+5, $mapy=$H-$yo-$y-$font->height/2, "$p ".$pstring{$p}, $rcols{$p});
$y += $font->height+1;
&add_map($p, $mapx, $mapy, $font->height, $W,$LEG, \@map);
$i--;
# last if (++$n >= param('best'));
}
@ -569,8 +666,23 @@ sub make_graf {
close(TEMP);
# ret img tag
$tempf =~ s!^$tempdir/!!;
$q->print(img({-src=>"$tempdir_url/$tempf", -height=>$H,
-width=>$W+$LEG, -align=>'"CENTER"'}));
$q->print(qq(<MAP NAME="map">\n));
foreach (@map) {
$q->print("$_\n");
}
$q->print(qq(</MAP>\n));
$q->print(img({-src=>"$tempdir_url/$tempf", -height=>$H, -border=>0,
-width=>$W+$LEG, -align=>'"CENTER"', -usemap=>'#map'}));
}
sub add_map {
my ($p, $mapx, $mapy, $height, $W,$LEG, $mref) = @_;
my($xu,$yu, $url);
$mapx=int($mapx);
$mapy=int($mapy);
$xu=int($W+$LEG-2);
$yu=int($mapy+$height);
$url=$url{$p};
push(@$mref,qq(<AREA SHAPE="RECT" COORDS="$mapx,$mapy,$xu,$yu" href="$url">));
}
# del gifs older then 1 hour
@ -585,4 +697,4 @@ sub clean_up {
unlink("$tempdir/$file");
}
}
}
}

View File

@ -1,4 +1,3 @@
#undef LEOx
/* $Id$
*
* ISDN accounting for isdn4linux. (rate evaluation)
@ -20,6 +19,13 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log$
* Revision 1.12 1999/07/24 08:45:17 akool
* isdnlog-3.42
* rate-de.dat 1.02-Germany [18-Jul-1999 10:44:21]
* better Support for Ackermann Euracom
* WEB-Interface for isdnrate
* many small fixes
*
* Revision 1.11 1999/07/15 16:42:04 akool
* small enhancement's and fixes
*
@ -61,22 +67,24 @@
#include "isdnlog.h"
#include "tools/zone.h"
#include <unistd.h>
#include "telnum.h"
#define WIDTH 19
#define MAXLAST ((best>=20||best<=2)?5:best)
#define _MAXLAST 20 /* the real max */
#define MAXLAST ((best>=_MAXLAST||best<=2)?5:best)
#define ZAUNPFAHL 1 /* FIXME: Michi: Offset */
#define P_EMPTY(s) (s) ? (s) : ""
static char *myname, *myshortname;
static char options[] = "b:d:f:h:l:p:vx:DG:HLTUVX::";
static char usage[] = "%s: usage: %s [ -%s ] Destination ...\n";
static int verbose = 0, header = 0, best = MAXPROVIDER, table = 0, explain = 0;
static int usestat = 0, provider = UNKNOWN;
static int usestat = 0;
static int duration = LCR_DURATION;
static time_t start;
static int day, month, year, hour, min, sec;
static char country[BUFSIZ], area[BUFSIZ], msn[BUFSIZ];
static char smyarea[BUFSIZ], sarea[BUFSIZ];
static char ignore[MAXPROVIDER];
static char * fromarea = 0;
static char wanted_day;
@ -86,6 +94,8 @@ static int n_providers=0;
static int exclude=0;
static int is_daemon=0;
static TELNUM srcnum, destnum;
typedef struct {
int prefix;
double rate;
@ -99,8 +109,9 @@ typedef struct {
static SORT sort[MAXPROVIDER];
#define PRT_V 17 /* verbose */
#define PRT_A 18 /* always on stderr */
#undef BUFSIZ /* sorry but 8192 is too much for me */
#define BUFSIZ 256
int print_msg(int Level, const char *fmt, ...)
{
auto va_list ap;
@ -118,21 +129,6 @@ int print_msg(int Level, const char *fmt, ...)
return(0);
} /* print_msg */
#ifdef LEO
#undef DTAG
#define DTAG 1
static void pre_init()
{
preselect = DTAG; /* Telekomik */
vbn = strdup("10"); /* austria */
} /* pre_init */
#else
static void pre_init()
{
preselect = DTAG; /* Telekomik */
vbn = strdup("010"); /* Germany */
} /* pre_init */
#endif
static void init()
{
@ -148,18 +144,20 @@ static void init()
initHoliday(holifile, message);
if (*version && verbose)
if (verbose && *version)
print_msg(PRT_V, "%s\n", version);
initCountry(countryfile, message);
if (*version && verbose)
if (verbose && *version)
print_msg(PRT_V, "%s\n", version);
initRate(rateconf, ratefile, zonefile, message);
if (*version && verbose)
if (verbose && *version)
print_msg(PRT_V, "%s\n", version);
initTelNum();
} /* init */
/* calc a day/time W | E | H */
@ -195,18 +193,17 @@ static void get_day(char d) {
static void post_init()
{
auto char s[BUFSIZ];
clearNum(&srcnum);
if (fromarea) {
free(myarea);
myarea = fromarea;
Strncpy(srcnum.area, fromarea, TN_MAX_AREA_LEN);
free(fromarea);
fromarea=0;
}
initNum(&srcnum);
if (wanted_day)
get_day(wanted_day);
*smyarea = 0;
sprintf(s, "%s%s", mycountry, myarea);
mynum = strdup(s);
} /* post_init */
static int opts(int argc, char *argv[])
@ -408,7 +405,7 @@ static char *Provider(int prefix)
register char *p;
register int l;
static char s[BUFSIZ];
char prov[TN_MAX_PROVIDER_LEN];
if (prefix == UNKNOWN)
return("?");
@ -417,160 +414,25 @@ static char *Provider(int prefix)
l = max(WIDTH, strlen(p)) - strlen(p);
if (prefix < 100)
sprintf(s, "%s%02d:%s%*s", vbn, prefix, p, l, "");
else
sprintf(s, "%s%03d:%s%*s", vbn, prefix - 100, p, l - 1, "");
sprintf(s, "%s:%s%*s", prefix2provider(prefix, prov, &destnum), p, l, "");
return(s);
} /* Provider */
static void numsplit(char *num)
{
register int l1, l3, zone;
auto int l2;
register char *p = 0;
auto char *s;
print_msg(PRT_V, "NUMSPLIT(%s)\n", num);
*country = *area = *msn = 0;
*sarea = 0;
if (verbose && (provider != UNKNOWN))
print_msg(PRT_V, " Provider %s\n", Provider(provider));
if ((l1 = getCountrycode(num, &s)) != UNKNOWN) {
Strncpy(country, num, l1 + 1);
if (verbose)
print_msg(PRT_V, " Country %s : %s\n", country, s);
strcpy(sarea, s);
if ((p = get_areacode(num, &l2, C_NO_WARN | C_NO_EXPAND | C_NO_ERROR))) {
Strncpy(area, num + l1, l2 + 1 - l1);
if (verbose)
print_msg(PRT_V, " Area %s : %s\n", area, p);
strcpy(msn, num + l2);
if (verbose && *msn)
print_msg(PRT_V, " Number %s\n", msn);
} /* if */
p = country;
while (*p && !isdigit(*p))
p++;
l3 = getAreacode(atoi(p), num + l1, &s);
if (1) {
print_msg(PRT_V, "getAreacode(%d, %s, %s)=%d\n", atoi(p), num + l1, s, l3);
zone = getZone(DTAG, myarea, num + l1);
print_msg(PRT_V, "getZone(%d,%s,%s)=%d\n", DTAG, myarea, num + l1, zone);
switch (zone) {
case 1 : print_msg(PRT_V, "Ortszone\n"); break;
case 2 : print_msg(PRT_V, "Cityzone\n"); break;
case 3 : print_msg(PRT_V, "Regionalzone\n"); break;
case 4 : print_msg(PRT_V, "Fernzone\n"); break;
default : print_msg(PRT_V, "*** BUG ***\n"); break;
} /* switch */
} /* if */
if (l3 != UNKNOWN) {
strcpy(sarea, s);
free(s);
}
}
else {
l3 = getAreacode(49, num, &s);
if (l3 != UNKNOWN) {
print_msg(PRT_V, "getAreacode(%d, %s, %s)=%d\n", atoi(p), num + l1, s, l3);
free(s);
zone = getZone(DTAG, mynum, num);
print_msg(PRT_V, "getZone=%d\n", zone);
} /* if */
} /* else */
} /* numsplit */
static int normalizeNumber(char *target)
{
register int l1, l2;
register char c;
auto COUNTRY *Country;
auto char num[BUFSIZ];
if (isalpha(*target)) {
if (getCountry(target, &Country) != UNKNOWN)
strcpy(num, Country->Code[0]);
else {
print_msg(PRT_A, "Unknown country \"%s\"\n", target);
return(0);
} /* else */
}
else {
l1 = strlen(vbn);
if (!memcmp(target, vbn, l1)) {
if (target[l1] == '0') /* dreistellige Verbindungsnetzbetreiberkennzahl? */
l2 = l1 + 3;
else
l2 = l1 + 2;
c = target[l2];
target[l2] = 0;
provider = atoi(target + l1);
if (l2 == 6)
provider += 100;
target[l2] = c;
memmove(target, target + l2, strlen(target) - l2);
} /* if */
if (*target == '+')
strcpy(num, target);
else if (!memcmp(target, "00", 2))
sprintf(num, "+%s", target + 2);
else if (*target == '0') {
#if 0
if (!strchr("18", target[1])) /* FIXME: "18" ist Deutsche-Sonderrufnummernerkennung! */
#endif
sprintf(num, "%s%s", mycountry, target + 1);
#if 0
else
sprintf(num, "%s%s", mycountry, target);
#endif
}
else
sprintf(num, "%s%s%s", mycountry, myarea, target);
} /* else */
numsplit(num);
return(1);
} /* normalizeNumber */
#define P_EMPTY(s) s ? s : ""
#define DEL ';'
static int compute()
static int compute(char *num)
{
register int i, n = 0;
register int low = 0, high = MAXPROVIDER - 1;
auto RATE Rate;
auto char s[BUFSIZ];
struct tm *tm;
char prov[TN_MAX_PROVIDER_LEN];
int oldprov;
if (provider != UNKNOWN) {
low = high = provider;
if (destnum.nprovider != UNKNOWN) {
low = high = destnum.nprovider;
} /* if */
buildtime();
@ -606,14 +468,23 @@ static int compute()
continue;
}
clearRate(&Rate);
Rate.src[0] = mycountry;
Rate.src[1] = myarea;
Rate.src[0] = srcnum.country?srcnum.country->Code[0] : "";
Rate.src[1] = srcnum.area;
Rate.src[2] = "";
Rate.dst[0] = country;
Rate.dst[1] = area;
Rate.dst[2] = msn;
oldprov = destnum.nprovider;
if (destnum.nprovider == UNKNOWN)
destnum.nprovider=i;
if (normalizeNumber(num, &destnum, TN_ALL) == UNKNOWN) {
destnum.nprovider=oldprov;
continue;
}
destnum.nprovider=oldprov;
Rate.dst[0] = destnum.country?destnum.country->Code[0] : "";
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]);
/* Rate.Service = "Internet by call"; */
Rate.prefix = i;
@ -621,13 +492,11 @@ static int compute()
Rate.start = start;
Rate.now = start + duration - ZAUNPFAHL;
if(verbose==2)
fprintf(stderr,"@ %s%0*d ", vbn, Rate.prefix>100?3:2,
Rate.prefix>100?Rate.prefix-100:Rate.prefix);
fprintf(stderr,"@ %s ", prefix2provider(Rate.prefix, prov, &destnum));
if (explain == 99) {
int j;
double oldCharge = -1.0;
printf("@ %s%0*d\n", vbn, Rate.prefix>100?3:2,
Rate.prefix>100?Rate.prefix-100:Rate.prefix);
printf("@ %s\n", prefix2provider(Rate.prefix, prov, &destnum));
Rate.now = start+1;
for (j=1;j<duration; j++) {
if (!getRate(&Rate, NULL) && (Rate.Price != 99.99)) {
@ -644,8 +513,7 @@ static int compute()
}
if (explain == 98||explain==97) { /* Minutenpreis fuer diese Woche/Tag */
int j;
printf("@ %s%0*d\n", vbn, Rate.prefix>100?3:2,
Rate.prefix>100?Rate.prefix-100:Rate.prefix);
printf("@ %s\n", prefix2provider(Rate.prefix, prov, &destnum));
for (j=0;j < (explain==98 ? 7*24 : 24); j++) {
if (!getRate(&Rate, NULL) && (Rate.Price != 99.99)) {
printf("%d %.4f\n",j, Rate.Charge);
@ -664,11 +532,11 @@ static int compute()
sort[n].rate = Rate.Charge;
if (explain == 9) { /* used by list */
double cpm = Rate.Duration > 0 ? 60 * Rate.Price / Rate.Duration : 99.99;
sprintf(s, "%s%0*d%c"
sprintf(s, "%s%c"
"%s%c%s%c%s%c%s%c"
"%s%c"
"%.3f%c%.4f%c%.2f%c%.3f",
vbn, Rate.prefix>100?3:2, Rate.prefix>100?Rate.prefix-100:Rate.prefix,DEL,
prefix2provider(Rate.prefix, prov, &destnum), DEL,
Rate.Provider,DEL,P_EMPTY(Rate.Zone),DEL, P_EMPTY(Rate.Day),DEL, P_EMPTY(Rate.Hour),DEL,
currency,DEL, /* Fixme: global or per Provider?? wg. EURO */
Rate.Charge,DEL, Rate.Price,DEL, Rate.Duration,DEL, cpm);
@ -692,24 +560,18 @@ static int compute()
if (explain <10)
qsort((void *)sort, n, sizeof(SORT), compare);
{ char *p;
char *a;
for (p=mycountry; !isdigit(*p); p++)
;
if (getAreacode(atoi(p), myarea, &a) != UNKNOWN) {
strcpy(smyarea, a);
free(a);
}}
return(n);
} /* compute */
#undef P_EMPTY
static void print_header(void) {
print_msg(PRT_NORMAL, "Eine %d Sekunden lange Verbindung von %s nach %s kostet am %s\n",
duration, formatNumber("%f",&srcnum), formatNumber("%f",&destnum),
ctime(&start));
}
static void printList(char *target, int n) {
int i;
if (header)
print_msg(PRT_NORMAL, "Eine %d Sekunden lange Verbindung von %s %s (%s) nach %s %s %s (%s) kostet am %s\n",
duration, mycountry, myarea, smyarea, country, area, msn, sarea, ctime(&start));
print_header();
if (n > best)
n = best;
@ -727,8 +589,7 @@ static void result(char *target, int n)
*num = 0; /* FIXME */
if (header)
print_msg(PRT_NORMAL, "Eine %d Sekunden lange Verbindung von %s %s (%s) nach %s %s %s (%s) kostet am %s\n",
duration, mycountry, myarea, smyarea, country, area, msn, sarea, ctime(&start));
print_header();
if (n > best)
n = best;
@ -761,11 +622,11 @@ static void purge(int n)
0..23 Uhr
*/
static void printTable()
static void printTable(char *num)
{
register int n, d, i, h, lasthour;
auto struct tm *tm;
auto SORT last[MAXLAST];
auto SORT last[_MAXLAST];
auto int used[MAXPROVIDER];
auto int hours[MAXPROVIDER];
auto int weight[MAXPROVIDER];
@ -779,8 +640,7 @@ static void printTable()
memset(weight, 0, sizeof(weight));
if (header)
print_msg(PRT_NORMAL, "Eine %d Sekunden lange Verbindung von %s %s nach %s %s %s kostet\n",
duration, mycountry, myarea, country, area, msn);
print_header();
for (d = 0; d < 2; d++) {
last[0].prefix = UNKNOWN;
@ -809,10 +669,10 @@ static void printTable()
while (1) {
n = compute();
n = compute(num);
if (last[0].prefix == UNKNOWN) {
for (i = 0; i < MAXLAST; i++) {
for (i = 0; i < min(n,MAXLAST); i++) {
if (sort[i].prefix) {
last[i].prefix = sort[i].prefix;
last[i].rate = sort[i].rate;
@ -825,7 +685,7 @@ static void printTable()
lasthour = hour;
if (sort[0].prefix != last[0].prefix) {
for (i = 0; i < MAXLAST; i++) {
for (i = 0; i < min(n,MAXLAST); i++) {
if (!i)
print_msg(PRT_NORMAL, " %02d:00 .. %02d:59 %s = %s %s%s\n",
@ -855,7 +715,7 @@ static void printTable()
weight[last[0].prefix] += h * (d ? 5 : 2);
for (i = 0; i < MAXLAST; i++) {
for (i = 0; i < min(n,MAXLAST); i++) {
last[i].prefix = sort[i].prefix;
last[i].rate = sort[i].rate;
last[i].explain = strdup(sort[i].explain);
@ -874,7 +734,7 @@ static void printTable()
break;
} /* while */
for (i = 0; i < MAXLAST; i++) {
for (i = 0; i < min(n,MAXLAST); i++) {
if (!i) {
if ((lasthour == 7) && (hour == 7))
@ -951,7 +811,7 @@ static void printTable()
} /* for */
if (firsttime)
printTable();
printTable(num);
firsttime = 0;
@ -968,7 +828,6 @@ static void clean_up() {
fromarea=0;
is_daemon=table=list=header=explain=0;
usestat = 0;
provider = UNKNOWN;
duration = LCR_DURATION;
wanted_day = '\0';
}
@ -979,18 +838,18 @@ static void doit(int i, int argc, char *argv[]) {
memset(ignore, 0, sizeof(ignore));
while (i < argc) {
if (normalizeNumber(argv[i])) {
destnum.nprovider=UNKNOWN;
normalizeNumber(argv[i], &destnum, TN_PROVIDER);
if (table)
printTable();
printTable(argv[i]);
else {
n = compute();
n = compute(argv[i]);
if(list)
printList(argv[i], n);
else
result(argv[i], n);
purge(n);
} /* else */
} /* if */
}
i++;
} /* while */
clean_up();
@ -1023,6 +882,8 @@ static int handle_client(int fd) {
if (argc >= 20)
break;
}
time(&start); /* set time of call */
splittime(); /* date time my be overridden by opts */
if ((i = opts(argc, argv))) {
if (shutdown(fd, 0)<0) /* no read any more */
err("shutdown");
@ -1118,7 +979,6 @@ int main(int argc, char *argv[], char *envp[])
splittime();
if ((i = opts(argc, argv)) || is_daemon) {
pre_init();
init();
if (is_daemon) {
clean_up();

View File

@ -950,15 +950,17 @@ void rate_1067(void) {
char *Zone[][2] = {{ "Festnetz", "Österreich" },
{ "max.box", "+4367622" },
{ "max.online", "+4367620" }, /* Fixme */
{ "max.online", "+436762323" },
{ "max.mobil", "+43676" },
{ "andere Mobilfunknetze", "+43663,+43664,+43669" },
{ "Nachbarländer", "Deutschland, Italien" },
{ "EU", "" },
{ "Weltzone 1", "Griechenland, Portugal" },
{ "Weltzone 2", "" },
{ "Weltzone 3", "" },
{ "Weltzone 4", "+" }};
{ "Nachbarländer", "Deutschland, Italien, Schweiz, Tschechische Republik, Ungarn, Slowakische Republik, Slowenien, Liechtenstein" },
{ "EU", "Belgien, Dänemark, Finnland, Frankreich, Griechenland, Irland, Luxemburg, Niederlande, Portugal, Spanien, Schweden, Großbritannien, Nordirland" },
{ "Weltzone 1", "Andorra, Australien, Bahamas, Bosnien-Herzegowina, Kanada, Kroatien, Faröer, Gibraltar, Island, Japan, Lettland, Malta, Mazedonien, Monaco, Neuseeland, Norwegen, Polen, Puerto Rico, San Marino, Singapur, USA, Vatikan, Jugoslawien" },
{ "Weltzone 2", "Albanien, Algerien, Belarus, Bulgarien, Zypern, Estland, Hong Kong, Litauen, Marokko, Oman, Rumänien, Rußland, Tunesien, Türkei, Ukraine, Virgin Islands (US)" },
{ "Weltzone 3", "Bermuda, Brasilien, Brunei, Chile, Christmas Islands, Cocos Islands, Dominikanische Republik, Georgien, Ghana, Grönland, Israel, Jamaica, Kasachstan, Korea, Kirgisistan, Libyen, Macau, Malaysien, Mexiko, Südafrika, Taiwan, Tadschikistan" },
{ "Weltzone 4", "+" },
{ "Iridium 8816", "Iridium 008816"},
{ "Iridium 8817", "Iridium 008817"}};
double Tarif[] = { 01.00,
01.00,
@ -970,18 +972,18 @@ void rate_1067(void) {
05.50,
09.70,
15.00,
22.00 };
22.00,
122.00,
62.00 };
int z;
printf ("\n");
rprintf ("max.plus","P:67");
rprintf ("Michael Reinelt <reinelt@eunet.at>", "C:maintained by:");
rprintf ("Taktung unbekannt", "C:Fixme:");
for (z=0; z<7; z++) {
for (z=0; z<COUNT(Zone); z++) {
rprintf (Zone[z][0], "Z:%d", z+1);
/* Fixme: Taktung? */
rprintf ("rund um die Uhr", "T:*/*=%.2f(60)/1", Tarif[z]);
rprintf ("rund um die Uhr", "T:*/*=%.2f(60)/30", Tarif[z]);
print_area(Zone[z][1]);
}
}
@ -1030,7 +1032,7 @@ 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.81-Austria [22-Jul-1999]\n\n");
printf ("V:1.83-Austria [25-Jul-1999]\n\n");
printf ("U:%%.3f öS\n");
#if 0

478
isdnlog/tools/telnum.c Normal file
View File

@ -0,0 +1,478 @@
#define TESTat
/* telnum.c
* (c) 1999 by Leopold Toetsch <lt@toetsch.at>
*
* telefon number utils
*
* Copyright 1999 by Leopold Toetsch <lt@toetsch.at>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
* Interface
*
* void initTelNum(void)
* ---------------------
* init the package, call this once on startup
*
* int normalizeNumber(char *number, TELNUM *num, int flag)
* --------------------------------------------------------
* number is "[provider] [country] [area] [msn]"
* country may be name of country
* spaces or '_' are allowd to separate parts of number
* fills struct TELNUM *num with parts of number
* for flag look at telnum.h
* ret 0 .. ok
* ret 1 .. area not found
* ret UNKNOWN .. country not found
*
* Input number e.g.
* 10055 0049 89 1234567
* 100550049891234567
* 1033 Deutschland 89 1234567
* +49 89 1234567
* 089 1234567
* 1234567
*
* char * formatNumber(char* format, TELNUM* num)
* ----------------------------------------------
* takes a format string
* %Np .. Provider
* %Nc .. country +49
* %NC .. countryname
* %Na .. area 89 or 089 if no country/Provider
* %NA .. areaname
* %Nm .. msn
* %f .. full +49 89 12356 (Deutschland, Berlin)
* %s .. short +48 89 123456
* %n .. number 004889123456
*
* N is number of chars to skip in format if part is not present
* e.g. "%1c %1a %m"
* +4930123 => "+49 39 123"
* 123 => "123" not " 123"
*
*
* char* prefix2provider(int prefix, char* provider, TELNUM *num)
* --------------------------------------------------------------
* returns formatted provider for prefix
*
* int provider2prefix(char* provider, int*prefix, TELNUM *num)
* ------------------------------------------------------------
* ret len of provider
*
* void clearNum(TELNUM *num)
* --------------------------
* call this if you have a number on stack or want to reuse it
* normalizeNumber calls this for you
*
* void initNum(TELNUM *num)
* inits a number with myarea, mycountry
* you may set the area yourself prior to calling this
*
*/
#include "telnum.h"
#define DEFAULT (UNKNOWN-1)
static TELNUM defnum;
static void _init(void);
#ifdef TESTde
#undef ISDN_AT
#define ISDN_DE
#endif
/* --------------------- ADJUST here ----------------*/
#ifdef ISDN_AT
void initTelNum(void)
{
vbn = strdup("10"); /* Fixme: VBN is defined in isdn.conf but not read yet */
preselect=1;
#define VBN_LEN 2 /* len of digits following vbn */
#define VBN_GERMANY 0
_init();
} /* pre_init */
#endif
#ifdef ISDN_DE
void initTelNum(void)
{
vbn = strdup("010"); /* Fixme: VBN is defined in isdn.conf but not read yet */
preselect=33;
#define VBN_LEN 2
#define VBN_GERMANY 1 /* vbn[3] == '0' => 3 stellig folgt */
_init();
} /* pre_init */
#endif
#ifdef ISDN_NL
static void initTelNum()
{
vbn = strdup("16:17"); /* Fixme: VBN is defined in isdn.conf but not read yet */
preselect=999;
#define VBN_LEN 2 /* Paul: ? is this correct */
#define VBN_GERMANY 0
_init();
} /* pre_init */
#endif
/* ----------------- end ADJUST here ----------------*/
static inline int Isspace(c) {
return isspace(c) || c == '_';
}
static int split_vbn(char **p, TELNUM *num) {
int l;
print_msg(PRT_V, "vbn: p(%d) '%s' ", num->nprovider,*p);
if ((l = provider2prefix(*p, &num->nprovider, num))) {
Strncpy(num->provider, *p, l+1);
*p += l;
print_msg(PRT_V, "Provider \"%s\" %d\n", num->provider, num->nprovider);
return l;
}
print_msg(PRT_V, "No Provider\n");
return 0;
}
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;
}
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;
print_msg(PRT_V, "_getCountrycode(%s)=%d ", c,res);
c[--l] = '\0'; /* try shorter */
}
return last;
}
static int split_country(char **p, TELNUM *num) {
int res=0;
int len=0;
char *country=0;
print_msg(PRT_V, "cou: '%s' ", *p);
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) {
print_msg(PRT_V, "getCountrycode(%s)= ", country);
country[res]='\0';
print_msg(PRT_V, "\"%s\" ", country);
*p += res;
}
else {
print_msg(PRT_A, "Unknown Country \"%s\"\n", *p);
clearCountry(num, UNKNOWN);
res=-10;
}
}
if (getCountry(country, &num->country) != UNKNOWN) {
print_msg(PRT_V, "Country \"%s\"\n", num->country->Code[0]);
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;
print_msg(PRT_V, "getArea(%d,%s) => " ,num->nprovider, *p);
if((ga=getArea(num->nprovider, *p))) /* sondernummer */
clearCountry(num, 0);
else
clearCountry(num, DEFAULT);
print_msg(PRT_V, "%d ", ga);
}
print_msg(PRT_V, "Country %d\n", num->ncountry);
return res+len;
}
static void clearArea(TELNUM *num, int a) {
strcpy(num->area,a==DEFAULT?defnum.area:"");
strcpy(num->sarea,a==DEFAULT?defnum.sarea:"?");
num->narea= a==DEFAULT?defnum.narea:a;
}
static int split_area(char **p, TELNUM *num, int first) {
int res=0;
int len=0;
char *s;
print_msg(PRT_V, "are: '%s' ", *p);
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);
print_msg(PRT_V,"getAreacode(%d, %s)= '%s'\n",num->ncountry,num->area,num->sarea);
}
else {
clearArea(num, UNKNOWN);
print_msg(PRT_V,"getAreacode(%d, %s)= 'UNKNOWN'\n",num->ncountry,*p);
return -1;
}
}
else
clearArea(num, DEFAULT);
if (num->ncountry == DEFAULT)
setCountry(num);
return res+len;
}
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);
}
char *prefix2provider(int prefix, char*s, TELNUM *num) {
if (prefix < 100)
sprintf(s, "%s%0*d", num->vbn, VBN_LEN, prefix);
else
sprintf(s, "%s%03d", num->vbn, prefix - 100);
return s;
}
int provider2prefix(char *p, int *prefix, TELNUM *num) {
char prov[TN_MAX_PROVIDER_LEN];
int l1, l2=0;
char *q;
char *vbns=strdup(vbn);
q = strtok(vbns, ":");
while (q) {
l1=strlen(vbns);
if (!memcmp(p, q, l1)) {
Strncpy(num->vbn, q, TN_MAX_VBN_LEN);
print_msg(PRT_V, "VBN \"%s\"\n", q);
if (p[l1] == '0' && VBN_GERMANY) /* dreistellige Verbindungsnetzbetreiberkennzahl? */
l2 = l1 + 3; /* 1002 is provider UTA in AT */
else
l2 = l1 + VBN_LEN;
Strncpy(prov, p+l1, l2+1-l1);
*prefix = (l2==6) ? 100+atoi(prov) : atoi(prov);
break;
}
q = strtok(0, ":");
}
free(vbns);
return l2;
}
void initNum(TELNUM *num) {
char *s;
if(!*num->area)
Strncpy(num->area, myarea, TN_MAX_AREA_LEN);
num->country=defnum.country;
num->ncountry=defnum.ncountry;
num->narea=atoi(num->area);
if (getAreacode(num->ncountry, num->area, &s) != UNKNOWN) {
Strncpy(num->sarea, s, TN_MAX_SAREA_LEN);
free(s);
}
strcpy(num->vbn, defnum.vbn);
}
static void _init(void) {
char *s;
clearNum(&defnum);
Strncpy(defnum.area, myarea, TN_MAX_AREA_LEN);
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);
}
}
Strncpy(defnum.vbn, vbn, TN_MAX_VBN_LEN);
}
void clearNum(TELNUM *num) {
strcpy(num->provider,"");
/* num->nprovider=preselect; */
strcpy(num->area,"");
initNum(num);
strcpy(num->msn,"");
Strncpy(num->vbn, vbn, TN_MAX_VBN_LEN);
}
/* %Np .. Provider
* %Nc .. country +49
* %NC .. countryname
* %Na .. area 89 or 089 if no country/Provider
* %NA .. areaname
* %Nm .. msn
* %f .. full +49 89 12356 (Deutschland, Berlin)
* %s .. short +48 89 123456
* %n .. number 004889123456
* N is number of chars to skip in format if part is not present
* e.g. "%1c %1a %m"
* +4930123 => "+49 39 123"
* 123 => "123" not " 123"
*/
#define SKIP if(skip>0) \
while(skip-- && *p && p[1]) \
p++
char * formatNumber(char* format, TELNUM* num) {
char *s=retstr[++retnum];
char *p, *q, *r;
int first=1;
int skip;
retnum %= MAXRET;
*s = '\0';
for (p=format, q=s; *p; p++) {
if (*p =='%') {
skip = 0;
again:
switch (*++p) {
case 'p':
if (num->nprovider>0) {
q=stpcpy(q, num->provider);
first=0;
}
else
SKIP;
break;
case 'c':
if(num->ncountry>0 && num->country) {
q=stpcpy(q, num->country->Code[0]);
first=0;
}
else
SKIP;
break;
case 'C':
if(num->ncountry>0 && num->country)
q=stpcpy(q, num->country->Name);
else
SKIP;
break;
case 'a':
if(num->narea>0) {
if(first) *q++ = '0'; /* areaprefix ?? */
q=stpcpy(q,num->area);
}
else
SKIP;
break;
case 'A':
if(num->narea>0)
q=stpcpy(q,num->sarea);
else
SKIP;
break;
case 'm':
if(*num->msn)
q=stpcpy(q,num->msn);
else
SKIP;
break;
case 'f': q=stpcpy(q,formatNumber("%1c %1a %1m (%2C, %A)", num)); break;
case 's': q=stpcpy(q,formatNumber("%1c %1a %m", num)); break;
case 'n':
if(num->ncountry>0 && num->country) {
q=stpcpy(r=++q,formatNumber("%c%a%m", num));
r[0]=r[1]='0';
}
else
q=stpcpy(q,formatNumber("%a%m", num));
break;
default:
if (isdigit(*p)) {
skip = strtol(p, &p, 10);
p--;
goto again;
}
}
}
else
*q++ = *p;
}
*q = '\0';
return s;
}

52
isdnlog/tools/telnum.h Normal file
View File

@ -0,0 +1,52 @@
/* telnum.h
(c) 1999 by Leopold Toetsch <lt@toetsch.at>
*/
#ifndef _TELNUM_H_
#define _TELNUM_H_
#include "isdnlog.h"
#include "tools/zone.h"
/* print_msg */
#define PRT_V 17 /* verbose */
#define PRT_A 18 /* always on stderr */
/* string lens */
#define TN_MAX_VBN_LEN 4
#define TN_MAX_PROVIDER_LEN 8
#define TN_MAX_COUNTRY_LEN 8
#define TN_MAX_AREA_LEN 10
#define TN_MAX_SAREA_LEN 40
#define TN_MAX_MSN_LEN 10
#define TN_MAX_NUM_LEN (TN_MAX_PROVIDER_LEN+TN_MAX_COUNTRY_LEN+TN_MAX_AREA_LEN+TN_MAX_MSN_LEN+4)
typedef struct {
char vbn[TN_MAX_VBN_LEN];
char provider[TN_MAX_PROVIDER_LEN];
int nprovider;
COUNTRY *country;
int ncountry;
char area[TN_MAX_AREA_LEN];
int narea;
char sarea[TN_MAX_SAREA_LEN];
char msn[TN_MAX_MSN_LEN];
} TELNUM;
/* flags */
#define TN_PROVIDER 1
#define TN_COUNTRY 2
#define TN_AREA 4
#define TN_MSN 8
#define TN_ALL 15
#define TN_NO_PROVIDER 14
/* functions */
void initTelNum(void);
int normalizeNumber(char *target, TELNUM *num, int flag);
char * formatNumber(char* format, TELNUM* num);
char *prefix2provider(int prefix, char*prov, TELNUM *num);
int provider2prefix(char *p, int *prefix, TELNUM *num);
void clearNum(TELNUM *num);
void initNum(TELNUM *num);
#endif

View File

@ -19,6 +19,12 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log$
* Revision 1.13 1999/07/10 21:38:54 akool
* isdnlog-3.41
* rate-de.dat V:1.02-Germany [10-Jul-1999 23:32:27]
* country-de.dat V:1.02-Germany [10-Jul-1999 23:32:36]
* added all "zone-*" files in binary mode
*
* Revision 1.12 1999/07/07 19:44:20 akool
* patches from Michael and Leo
*
@ -74,6 +80,9 @@
*
* Changes:
*
* 1.21 1997.07.22 lt fixed bug, were T was overwritten, when an 'A'
* followed versio, occured w. DTAG
*
* 1.20 1999.07.08 lt added support for NL
*
* in NL areacode may be shorter than actual aeracodenumber
@ -127,7 +136,7 @@ struct sth {
static struct sth *sthp;
static int count;
static char version[] = "1.20";
static char version[] = "1.21";
static bool area_read = false;
#define LINK 127
@ -421,6 +430,7 @@ static int _initZone(int provider, char *path, char **msg, bool area_only)
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;
}
} /* for */