1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
|
diff -Naur isdn4k-utils-orig//eicon/eiconctrl.c isdn4k-utils/eicon/eiconctrl.c
--- isdn4k-utils-orig//eicon/eiconctrl.c 2001-06-22 02:34:45.000000000 +1000
+++ isdn4k-utils/eicon/eiconctrl.c 2010-12-04 20:44:11.093338893 +1000
@@ -1970,7 +1970,7 @@
val = strtol(p, &q, 16);
p = q;
val = strtol(p, &q, 16);
- (unsigned short) *buffer = (unsigned short) val;
+ *buffer = (unsigned short) val;
pos = 2;
while ((p != q) && (*q != 0)) {
p = q;
diff -Naur isdn4k-utils-orig//hisax/hisaxctrl.c isdn4k-utils/hisax/hisaxctrl.c
--- isdn4k-utils-orig//hisax/hisaxctrl.c 2000-06-30 19:37:38.000000000 +1000
+++ isdn4k-utils/hisax/hisaxctrl.c 2010-12-04 20:44:11.093338893 +1000
@@ -43,7 +43,8 @@
fprintf(stderr, "cannot open file %s\n", fname);
exit(-1);
}
- p = (int *) buffer = (unsigned char *) malloc(MAX_SIZE+4);
+ buffer = (unsigned char *) malloc(MAX_SIZE+4);
+ p = (int *) buffer;
if (!buffer) {
fprintf(stderr, "cannot get %d byte memory\n", MAX_SIZE+4);
exit(-1);
diff -Naur isdn4k-utils-orig//hisax/Makefile.in isdn4k-utils/hisax/Makefile.in
--- isdn4k-utils-orig//hisax/Makefile.in 2002-07-20 05:03:51.000000000 +1000
+++ isdn4k-utils/hisax/Makefile.in 2010-12-04 20:44:03.726672225 +1000
@@ -30,7 +30,7 @@
#.SUFFIXES:
#.SUFFIXES: .c .o
-%.8: %.man
+%.8: %.man.in
cp $< $@
all: $(PROGRAMS) $(MANPAGES)
diff -Naur isdn4k-utils-orig//ipppd/main.c isdn4k-utils/ipppd/main.c
--- isdn4k-utils-orig//ipppd/main.c 2002-07-18 10:06:21.000000000 +1000
+++ isdn4k-utils/ipppd/main.c 2010-12-04 20:44:11.093338893 +1000
@@ -1041,9 +1041,14 @@
static char line[256]; /* line to be logged accumulated here */
static char *linep;
+#ifdef __STDC__
+static void pr_log(void *arg, char *fmt, ...);
+#else /* __STDC__ */
+static void pr_log(arg, fmt, va_alist);
+#endif
+
void log_packet(u_char *p,int len,char *prefix,int linkunit)
{
- static void pr_log __P((void *, char *, ...));
int i, n;
u_short proto;
diff -Naur isdn4k-utils-orig//ipppd/options.c isdn4k-utils/ipppd/options.c
--- isdn4k-utils-orig//ipppd/options.c 2002-07-06 10:34:08.000000000 +1000
+++ isdn4k-utils/ipppd/options.c 2010-12-04 20:43:57.890005560 +1000
@@ -479,26 +479,24 @@
#define IMPLEMENTATION ""
#endif
-static char *usage_string = "\
-ipppd version %s patch level %d%s\n\
-Usage: %s [ options ], where options are:\n\
-\t<device> Communicate over the named device\n\
+static char *usage_string = "ipppd version %s patch level %d%s\n"
+"Usage: %s [ options ], where options are:\n"
+"\t<device> Communicate over the named device\n"
#ifdef INCLUDE_OBSOLETE_FEATURES
-\tcrtscts Use hardware RTS/CTS flow control\n\
-\t<speed> Set the baud rate to <speed>\n\
-\tmodem Use modem control lines\n\
+"\tcrtscts Use hardware RTS/CTS flow control\n"
+"\t<speed> Set the baud rate to <speed>\n"
+"\tmodem Use modem control lines\n"
#endif
-\t<loc>:<rem> Set the local and/or remote interface IP\n\
-\t\taddresses. (you also may use the option 'useifip' to get IPs).\n\
-\tasyncmap <n> Set the desired async map to hex <n>\n\
-\tauth Require authentication from peer\n\
-\tconnect <p> Invoke shell command <p> to set up the serial line\n\
-\tdefaultroute Add default route through interface\n\
-\tfile <f> Take options from file <f>\n\
-\tmru <n> Set MRU value to <n> for negotiation\n\
-\tnetmask <n> Set interface netmask to <n>\n\
-See ipppd(8) for more options.\n\
-";
+"\t<loc>:<rem> Set the local and/or remote interface IP\n"
+"\t\t\taddresses. (you also may use the option 'useifip' to get IPs).\n"
+"\tasyncmap <n> Set the desired async map to hex <n>\n"
+"\tauth Require authentication from peer\n"
+"\tconnect <p> Invoke shell command <p> to set up the serial line\n"
+"\tdefaultroute Add default route through interface\n"
+"\tfile <f> Take options from file <f>\n"
+"\tmru <n> Set MRU value to <n> for negotiation\n"
+"\tnetmask <n> Set interface netmask to <n>\n"
+"See ipppd(8) for more options.\n";
static char *current_option; /* the name of the option being parsed */
diff -Naur isdn4k-utils-orig//isdnlog/isdnlog/isdnlog.h isdn4k-utils/isdnlog/isdnlog/isdnlog.h
--- isdn4k-utils-orig//isdnlog/isdnlog/isdnlog.h 2001-06-22 02:34:56.000000000 +1000
+++ isdn4k-utils/isdnlog/isdnlog/isdnlog.h 2010-12-04 20:44:03.780005559 +1000
@@ -460,7 +460,7 @@
_EXTERN void dotrace(void);
_EXTERN int morectrl(int card);
-_EXTERN void moreinfo(void);
+extern void moreinfo(void);
_EXTERN void morekbd(void);
_EXTERN void processcint(void);
_EXTERN void processflow(void);
diff -Naur isdn4k-utils-orig//isdnlog/isdnlog/processor.c isdn4k-utils/isdnlog/isdnlog/processor.c
--- isdn4k-utils-orig//isdnlog/isdnlog/processor.c 2002-04-02 04:06:10.000000000 +1000
+++ isdn4k-utils/isdnlog/isdnlog/processor.c 2010-12-04 20:44:03.783338893 +1000
@@ -5293,7 +5293,7 @@
tei = BROADCAST; /* Wenn nach einer tei-Zeile keine hex:-Zeile kommt, tei ungueltig machen! */
if ((type == SETUP) && !replay) { /* fetch additional info from "/dev/isdninfo" */
- static void moreinfo(); /* soviel zu Objektorientiertem Denken ;-) */
+ /*static void moreinfo(); */ /* soviel zu Objektorientiertem Denken ;-) */
moreinfo();
} /* if */
diff -Naur isdn4k-utils-orig//isdnlog/Makefile.in isdn4k-utils/isdnlog/Makefile.in
--- isdn4k-utils-orig//isdnlog/Makefile.in 2002-07-20 05:03:55.000000000 +1000
+++ isdn4k-utils/isdnlog/Makefile.in 2010-12-04 20:44:03.730005560 +1000
@@ -1842,9 +1842,6 @@
$(INSTALL_DATA) $$f $(DESTDIR)$(DATADIR); \
echo Installing $(DESTDIR)$(DATADIR)/$$f; \
done
- @(grep isdnlog $(SERVICEFILE) >/dev/null) || \
- (echo "";echo "";echo "Add a line to the file $(SERVICEFILE)" ;echo "";echo ""; \
- echo "isdnlog $(SERV_PORT)/tcp isdnlog" >> $(SERVICEFILE))
install-strip:
$(MAKE) INSTALL_BIN='$(INSTALL_BIN) -s' \
diff -Naur isdn4k-utils-orig//isdnlog/tools/cdb/cdbmake.c isdn4k-utils/isdnlog/tools/cdb/cdbmake.c
--- isdn4k-utils-orig//isdnlog/tools/cdb/cdbmake.c 2002-02-22 21:10:25.000000000 +1000
+++ isdn4k-utils/isdnlog/tools/cdb/cdbmake.c 2010-12-04 20:44:03.786672226 +1000
@@ -3,8 +3,6 @@
#include "freecdbmake.h"
#include <unistd.h>
-extern char *malloc();
-
void diesys(why) char *why; { perror(why); exit(111); }
void writeerror() { diesys("cdbmake: fatal: unable to write"); }
diff -Naur isdn4k-utils-orig//isdnlog/tools/isdnrate.c isdn4k-utils/isdnlog/tools/isdnrate.c
--- isdn4k-utils-orig//isdnlog/tools/isdnrate.c 2001-06-22 02:34:56.000000000 +1000
+++ isdn4k-utils/isdnlog/tools/isdnrate.c 2010-12-04 20:44:11.096672226 +1000
@@ -304,7 +304,7 @@
static void print_header(void);
-static char *myname, *myshortname;
+char *myname, *myshortname;
static char options[] = "ab:d:f:h:l:op:st:v::x:CD::G:HLNP:O:S:TUVX::Z";
static char usage[] = "%s: usage: %s [ -%s ] Destination ...\n";
@@ -313,7 +313,7 @@
static int usestat = 0;
static int duration = LCR_DURATION;
static time_t start;
-static int day, month, year, hour, min, sec;
+int day, month, year, hour, min, sec;
static char ignore[MAXPROVIDER];
static char *fromarea = 0;
static char wanted_day;
diff -Naur isdn4k-utils-orig//isdnlog/tools/isdnrate.c.orig isdn4k-utils/isdnlog/tools/isdnrate.c.orig
--- isdn4k-utils-orig//isdnlog/tools/isdnrate.c.orig 1970-01-01 10:00:00.000000000 +1000
+++ isdn4k-utils/isdnlog/tools/isdnrate.c.orig 2001-06-22 02:34:56.000000000 +1000
@@ -0,0 +1,1806 @@
+/* $Id: isdnrate.c,v 1.38 2001/03/01 14:59:16 paul Exp $
+
+ * ISDN accounting for isdn4linux. (rate evaluation)
+ *
+ * Copyright 1995 .. 2000 by Andreas Kool (akool@isdn4linux.de)
+ *
+ * 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.
+ *
+ * $Log: isdnrate.c,v $
+ * Revision 1.38 2001/03/01 14:59:16 paul
+ * Various patches to fix errors when using the newest glibc,
+ * replaced use of insecure tempnam() function
+ * and to remove warnings etc.
+ *
+ * Revision 1.37 2000/07/17 16:34:23 akool
+ * isdnlog-4.32
+ * - added new Prefixes 0160 (D1) and 0162 (D2) to "country-de.dat"
+ * - corrected all german mobil phone numbers (many thank's to
+ * Tobias Becker <i4l-projects@talypso.de> for the tool "fix_rates.pl")
+ * - isdnlog/tools/rate.c ... New R:-tag
+ * - isdnlog/tools/isdnrate.c ... print warnings from getRate if verbose
+ * - isdnlog/tools/rate-files.man ... New R:-tag
+ * - isdnlog/tools/NEWS ... New R:-tag
+ * - isdnlog/README ... New R:-tag
+ * - isdnlog/samples/rtest.dat ... example rate-file for testing R:
+ *
+ * Revision 1.36 2000/03/09 18:50:03 akool
+ * isdnlog-4.16
+ * - isdnlog/samples/isdn.conf.no ... changed VBN
+ * - isdnlog/isdnlog/isdnlog.c .. ciInterval
+ * - isdnlog/isdnlog/processor.c .. ciInterval
+ * - isdnlog/tools/tools.h .. ciInterval, abclcr conf option
+ * - isdnlog/tools/isdnconf.c .. ciInterval, abclcr conf option
+ * - isdnlog/tools/isdnrate.c .. removed a warning
+ * - isdnlog/NEWS ... updated
+ * - isdnlog/README ... updated
+ * - isdnlog/isdnlog/isdnlog.8.in ... updated
+ * - isdnlog/isdnlog/isdnlog.5.in ... updated
+ * - isdnlog/samples/provider ... NEW
+ *
+ * ==> Please run a make clean, and be sure to read isdnlog/NEWS for changes
+ * ==> and new features.
+ *
+ * Revision 1.35 2000/03/06 07:03:21 akool
+ * isdnlog-4.15
+ * - isdnlog/tools/tools.h ... moved one_call, sum_calls to isdnrep.h
+ * ==> DO A 'make clean' PLEASE
+ * - isdnlog/tools/telnum.c ... fixed a small typo
+ * - isdnlog/isdnrep/rep_main.c ... incl. dest.h
+ * - isdnlog/isdnrep/isdnrep.c ... fixed %l, %L
+ * - isdnlog/isdnrep/isdnrep.h ... struct one_call, sum_calls are now here
+ *
+ * Support for Norway added. Many thanks to Tore Ferner <torfer@pvv.org>
+ * - isdnlog/rate-no.dat ... NEW
+ * - isdnlog/holiday-no.dat ... NEW
+ * - isdnlog/samples/isdn.conf.no ... NEW
+ * - isdnlog/samples/rate.conf.no ... NEW
+ *
+ * Revision 1.34 2000/02/28 19:53:56 akool
+ * isdnlog-4.14
+ * - Patch from Roland Rosenfeld <roland@spinnaker.de> fix for isdnrep
+ * - isdnlog/tools/rate.c ... epnum
+ * - isdnlog/tools/rate-at.c ... new rates
+ * - isdnlog/rate-at.dat
+ * - isdnlog/tools/rate-files.man ... %.3f
+ * - doc/Configure.help ... unknown cc
+ * - isdnlog/configure.in ... unknown cc
+ * - isdnlog/.Config.in ... unknown cc
+ * - isdnlog/Makefile.in ... unknown cc
+ * - isdnlog/tools/dest/Makefile.in ... LANG => DEST_LANG
+ * - isdnlog/samples/rate.conf.pl ... NEW
+ * - isdnlog/samples/isdn.conf.pl ... NEW
+ * - isdnlog/rate-pl.dat ... NEW
+ * - isdnlog/tools/isdnrate.c ... fixed -P pid_dir, restarts on HUP now
+ * - isdnlog/tools/isdnrate.man ... SIGHUP documented
+ *
+ * Revision 1.33 2000/02/12 16:40:24 akool
+ * isdnlog-4.11
+ * - isdnlog/Makefile.in ... sep install-targets, installs samples, no isdnconf
+ * - isdnlog/samples/rate.conf.{lu,nl} ... NEW
+ * - isdnlog/samples/isdn.conf.lu ... chg provider
+ * - isdnlog/samples/stop ... chg \d,\d => \d.\d
+ * - isdnlog/samples/isdnlog.isdnctrl0.options ... NEW
+ * - isdnlog/samples/isdnlog.users ... NEW
+ * - isdnlog/country-de.dat ... _DEMF again
+ * - isdnlog/isdnlog/processor.c ... LCR
+ * - isdnlog/tools/isdnrate.c ... fmt of s
+ *
+ * Old config is not installed anymore, to acomplish this do
+ *
+ * make install-old-conf
+ * make install
+ *
+ * A running isdnlog is now HUP-ed not KILL-ed
+ *
+ * Revision 1.32 2000/02/03 18:24:51 akool
+ * isdnlog-4.08
+ * isdnlog/tools/rate.c ... LCR patch again
+ * isdnlog/tools/isdnrate.c ... LCR patch again
+ * isdnbill enhanced/fixed
+ * DTAG AktivPlus fixed
+ *
+ * Revision 1.31 1999/12/31 13:57:20 akool
+ * isdnlog-4.00 (Millenium-Edition)
+ * - Oracle support added by Jan Bolt (Jan.Bolt@t-online.de)
+ * - resolved *any* warnings against rate-de.dat
+ * - Many new rates
+ * - CREDITS file added
+ *
+ * Revision 1.30 1999/12/24 14:17:05 akool
+ * isdnlog-3.81
+ * - isdnlog/tools/NEWS
+ * - isdnlog/tools/telrate/info.html.in ... bugfix
+ * - isdnlog/tools/telrate/telrate.cgi.in ... new Service query
+ * - isdnlog/tools/telrate/Makefile.in ... moved tmp below telrate
+ * - isdnlog/samples/rate.conf.at ... fixed
+ * - isdnlog/tools/rate-at.c ... some changes
+ * - isdnlog/rate-at.dat ... ditto
+ * - isdnlog/tools/Makefile ... added path to pp_rate
+ * - isdnlog/tools/rate.{c,h} ... getServiceNames, Date-Range in T:-Tag
+ * - isdnlog/tools/isdnrate.c ... fixed sorting of services, -X52 rets service names
+ * - isdnlog/tools/rate-files.man ... Date-Range in T:-Tag, moved from doc
+ * - isdnlog/tools/isdnrate.man ... moved from doc
+ * - doc/Makefile.in ... moved man's from doc to tools
+ * - isdnlog/Makefile.in ... man's, install isdn.conf.5
+ * - isdnlog/configure{,.in} ... sed, awk for man's
+ * - isdnlog/tools/zone/Makefile.in ... dataclean
+ * - isdnlog/tools/dest/Makefile.in ... dataclean
+ * - isdnlog/isdnlog/isdnlog.8.in ... upd
+ * - isdnlog/isdnlog/isdn.conf.5.in ... upd
+ *
+ * Revision 1.29 1999/12/17 22:51:55 akool
+ * isdnlog-3.79
+ * - isdnlog/isdnrep/isdnrep.{c,h} ... error -handling, print_msg
+ * - isdnlog/isdnrep/rep_main.c
+ * - isdnlog/isdnrep/isdnrep.1.in
+ * - isdnlog/tools/rate.c ... dupl entry in rate.conf
+ * - isdnlog/tools/NEWS
+ * - isdnlog/tools/isdnrate.c
+ * - isdnlog/tools/dest/configure{,.in}
+ * - isdnlog/tools/zone/configure{,.in}
+ *
+ * Revision 1.28 1999/12/16 23:08:28 akool
+ * isdnlog-3.78
+ * - isdnlog/tools/isdnrate.c ... new sOcket option
+ * - isdnlog/tools/NEWS ... new sOcket option
+ * - doc/isdnrate.man ... ditto
+ * - isdnlog/tools/telrate/config.in ... ditto
+ * - isdnlog/tools/telrate/telrate.cgi.in ... ditto
+ * - isdnlog/tools/telrate/README-telrate ditto
+ *
+ * Revision 1.27 1999/12/02 19:28:02 akool
+ * isdnlog-3.73
+ * - isdnlog/tools/telrate/telrate.cgi.in faster
+ * - doc/isdnrate.man ... -P
+ * - isdnlog/tools/isdnrate.c ... -P
+ * - isdnlog/tools/NEWS ... -P
+ * - isdnlog/tools/rate-at.c ... 194040
+ * - isdnlog/rate-at.dat
+ * - isdnlog/tools/rate.c ... SIGSEGV
+ *
+ * Revision 1.26 1999/12/01 21:47:25 akool
+ * isdnlog-3.72
+ * - new rates for 01051
+ * - next version of isdnbill
+ *
+ * - isdnlog/tools/telnum.c ... cleanup
+ * - isdnlog/tools/isdnrate.c ... -s Service
+ * - isdnlog/tools/rate.{c,h} ... -s
+ * - isdnlog/tools/NEWS ... -s
+ * - doc/isdnrate.man .. updated -o, -s
+ * - doc/rate-files.man ... updated
+ * - isdnlog/tools/dest/README.makedest ... updt.
+ * - isdnlog/isdnlog/isdnlog.8.in .. updt.
+ *
+ * Telrate
+ * - isdnlog/tools/telrate/README-telrate
+ * - isdnlog/tools/telrate/config.in NEW
+ * - isdnlog/tools/telrate/configure NEW
+ * - isdnlog/tools/telrate/Makefile.in NEW
+ * - isdnlog/tools/telrate/index.html.in was index.html
+ * - isdnlog/tools/telrate/info.html.in was info.html
+ * - isdnlog/tools/telrate/telrate.cgi.in was telrate.cgi
+ * - isdnlog/tools/telrate/leo.sample NEW sample config
+ * - isdnlog/tools/telrate/alex.sample NEW sample config
+ *
+ * Revision 1.25 1999/11/08 21:09:41 akool
+ * isdnlog-3.65
+ * - added "B:" Tag to "rate-xx.dat"
+ *
+ * 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"
+ *
+ * isdnlog-3.58
+ * - big cleanup ( > 1.3 Mb removed!)
+ * - v0.02 of destination support - better, but not perfect
+ * (does't work with gcc-2.7.2.3 yet - use egcs!)
+ *
+ * Revision 1.21 1999/10/25 18:30:03 akool
+ * isdnlog-3.57
+ * WARNING: Experimental version!
+ * Please use isdnlog-3.56 for production systems!
+ *
+ * Revision 1.20 1999/09/19 14:16:27 akool
+ * isdnlog-3.53
+ *
+ * Revision 1.19 1999/09/16 20:27:21 akool
+ * isdnlog-3.52
+ *
+ * Revision 1.18 1999/09/13 09:09:44 akool
+ * isdnlog-3.51
+ * - changed getProvider() to not return NULL on unknown providers
+ * many thanks to Matthias Eder <mateder@netway.at>
+ * - corrected zone-processing when doing a internal -> world call
+ *
+ * Revision 1.17 1999/09/09 11:21:05 akool
+ * isdnlog-3.49
+ *
+ * Revision 1.16 1999/08/04 23:06:52 akool
+ * Better codeall for .at
+ *
+ * Revision 1.15 1999/07/31 09:25:36 akool
+ * getRate() speedup
+ *
+ * Revision 1.14 1999/07/26 16:28:41 akool
+ * getRate() speedup from Leo
+ *
+ * Revision 1.13 1999/07/25 15:57:46 akool
+ * isdnlog-3.43
+ * added "telnum" module
+ *
+ * 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
+ *
+ * Revision 1.10 1999/07/07 19:44:07 akool
+ * patches from Michael and Leo
+ *
+ * Revision 1.9 1999/07/04 20:47:05 akool
+ * rate-de.dat V:1.02-Germany [04-Jul-1999 22:56:37]
+ *
+ * Revision 1.8 1999/07/03 10:24:14 akool
+ * fixed Makefile
+ *
+ * Revision 1.7 1999/07/02 19:18:00 akool
+ * rate-de.dat V:1.02-Germany [02-Jul-1999 21:27:20]
+ *
+ * Revision 1.6 1999/07/02 18:20:50 akool
+ * rate-de.dat V:1.02-Germany [02-Jul-1999 20:29:21]
+ * country-de.dat V:1.02-Germany [02-Jul-1999 19:13:54]
+ *
+ * Revision 1.5 1999/07/01 20:40:07 akool
+ * isdnrate optimized
+ *
+ * Revision 1.4 1999/06/30 20:53:28 akool
+ * added "-t" option to "isdnrate"
+ *
+ * Revision 1.3 1999/06/30 17:17:37 akool
+ * isdnlog Version 3.39
+ *
+ * Revision 1.2 1999/06/29 20:11:25 akool
+ * now compiles with ndbm
+ * (many thanks to Nima <nima_ghasseminejad@public.uni-hamburg.de>)
+ *
+ * Revision 1.1 1999/06/28 19:16:33 akool
+ * isdnlog Version 3.38
+ * - new utility "isdnrate" started
+ *
+ */
+
+#include "isdnlog.h"
+#include "tools/zone.h"
+#include <unistd.h>
+#include "dest.h"
+
+#define WIDTH 19
+#define _MAXLAST 20 /* the real max */
+#define MAXLAST ((best>=_MAXLAST||best<=2)?5:best)
+
+
+static void print_header(void);
+
+static char *myname, *myshortname;
+static char options[] = "ab:d:f:h:l:op:st:v::x:CD::G:HLNP:O:S:TUVX::Z";
+static char usage[] = "%s: usage: %s [ -%s ] Destination ...\n";
+
+static int header = 0, best = MAXPROVIDER, table = 0, explain = 0;
+int verbose = 0;
+static int usestat = 0;
+static int duration = LCR_DURATION;
+static time_t start;
+static int day, month, year, hour, min, sec;
+static char ignore[MAXPROVIDER];
+static char *fromarea = 0;
+static char wanted_day;
+static int list = 0;
+static char *comment;
+static char **providers = 0; /* incl these */
+static int n_providers = 0;
+static int business = 0;
+static char **xproviders = 0; /* excl these */
+static int nx_providers = 0;
+static int xbusiness = 0;
+static int all = 0;
+static int booked = 0;
+static int service = 0;
+
+#define SOCKNAME "/tmp/isdnrate"
+static int is_daemon = 0;
+static int is_client = 0;
+static int we_are_daemon = 0;
+static int takt = 99999;
+static char sortby;
+static int need_dest;
+static int h_param = 0;
+static int lcr = 0;
+static TELNUM srcnum, destnum;
+static char *pid_dir = 0;
+static char *pid_file = 0;
+static char *socket_file = 0;
+static char **hup_argv; /* args to restart with */
+
+typedef struct {
+ int prefix;
+ double rate;
+ char *name;
+ char *explain;
+} SORT;
+
+typedef struct {
+ int weight;
+ int index;
+} SORT2;
+
+static SORT sort[MAXPROVIDER];
+
+#undef MAXPROVIDER
+#define MAXPROVIDER getNProvider()
+
+#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;
+ auto char String[BUFSIZ * 3];
+
+ if ((Level > PRT_ERR && !verbose) || (Level > PRT_WARN && verbose < 2))
+ return (1);
+
+ va_start(ap, fmt);
+ (void) vsnprintf(String, BUFSIZ * 3, fmt, ap);
+ va_end(ap);
+
+ fprintf(stderr, "%s", String);
+
+ return (0);
+} /* print_msg */
+
+
+static void init()
+{
+ auto char *version, **message;
+
+ if (readconfig(myshortname) < 0)
+ exit(1);
+
+ if (verbose)
+ message = &version;
+ else
+ message = NULL;
+
+ initHoliday(holifile, message);
+
+ if (verbose && *version)
+ print_msg(PRT_V, "%s\n", version);
+ initDest(destfile, message);
+ if (verbose && *version)
+ print_msg(PRT_V, "%s\n", version);
+
+ initRate(rateconf, ratefile, zonefile, message);
+
+ if (verbose && *version)
+ print_msg(PRT_V, "%s\n", version);
+
+} /* init */
+
+#if 0
+static void deinit(void)
+{
+ exitRate();
+ exitDest();
+ exitHoliday();
+}
+#endif
+
+/* calc a day/time W | E | H */
+static void get_day(char d)
+{
+ struct tm *tm;
+ bitfield mask;
+ int what = 0;
+
+ tm = localtime(&start); /* now */
+ switch (d) {
+ case 'W': /* we need a normal weekday, so we take
+ today and inc. day if today is
+ holiday */
+ what = WORKDAY;
+ if (!h_param)
+ hour = 10;
+ break;
+ case 'N':
+ what = WORKDAY;
+ if (!h_param)
+ hour = 23;
+ break;
+ case 'E':
+ what = SUNDAY;
+ if (!h_param)
+ hour = 10;
+ break;
+ }
+ mask = 1 << what;
+ while (isDay(tm, mask, 0) != what) {
+ tm->tm_mday++;
+ }
+ min = sec = 0;
+ day = tm->tm_mday;
+ month = tm->tm_mon + 1;
+ year = tm->tm_year + 1900;
+}
+
+static void post_init()
+{
+
+ clearNum(&srcnum);
+ if (fromarea) {
+ Strncpy(srcnum.area, fromarea, TN_MAX_AREA_LEN);
+ free(fromarea);
+ fromarea = 0;
+ }
+ initNum(&srcnum);
+
+ if (wanted_day)
+ get_day(wanted_day);
+} /* post_init */
+
+static int opts(int argc, char *argv[])
+{
+ register int c;
+ register char *p;
+ int x;
+
+ h_param = 0;
+
+ optind = 0; /* make it repeatable */
+ need_dest = 1;
+ while ((c = getopt(argc, argv, options)) != EOF) {
+ switch (c) {
+ case 'a': /* all rates old/newer */
+ all++;
+ break;
+ case 'b':
+ best = strtol(optarg, NIL, 0);
+ break;
+
+/* case 'c': country */
+ break;
+
+ case 'd':
+ for (p = optarg; *p && isspace(*p); p++) ;
+ if (isdigit(*p)) {
+ wanted_day = '\0';
+ day = atoi(optarg);
+ if ((p = strchr(optarg, '.'))) {
+ month = atoi(p + 1);
+ if ((p = strchr(p + 1, '.'))) {
+ year = atoi(p + 1);
+ if (year < 50)
+ year += 2000;
+ else if (year < 100)
+ year += 1900;
+ }
+ }
+ } /* isdigit */
+ else {
+ wanted_day = *p;
+ }
+ break;
+
+ case 'f':
+ if (optarg) { /* from */
+ for (p = optarg; (isspace(*p) || *p == '0') && *p; p++) ;
+ fromarea = strdup(p);
+ }
+ break;
+
+ case 'h':
+ hour = atoi(optarg);
+ h_param++;
+ sec = 0;
+ if ((p = strchr(optarg + 1, ':'))) {
+ min = atoi(p + 1);
+ if ((p = strchr(p + 1, ':')))
+ sec = atoi(p + 1);
+ }
+ else
+ min = 0;
+ break;
+
+ case 'l':
+ duration = strtol(optarg, NIL, 0); /* l wie lt */
+ break;
+
+ case 'o': /* booked only */
+ booked++;
+ break;
+
+ case 's': /* service */
+ service++;
+ break;
+
+ case 't':
+ x = strtol(optarg, NIL, 0);
+ if (x > 0)
+ takt = x;
+ break;
+
+ case 'x': /* eXclude Poviders */
+ {
+ char *arg = strdup(optarg);
+
+ p = strtok(arg, ",");
+ while (p) {
+ if (*p == 'B') { /* Business Provider */
+ xbusiness = 1;
+ p = strtok(0, ",");
+ continue;
+ }
+ xproviders = realloc(xproviders, (nx_providers + 1) * sizeof(char *));
+
+ xproviders[nx_providers] = strdup(p);
+ p = strtok(0, ",");
+ nx_providers++;
+ }
+ free(arg);
+ }
+ break;
+
+ case 'p': /* Providers ... */
+ {
+ char *arg = strdup(optarg);
+
+ p = strtok(arg, ",");
+ while (p) {
+ if (*p == 'B') { /* Business Provider */
+ business = 1;
+ p = strtok(0, ",");
+ continue;
+ }
+ providers = realloc(providers, (n_providers + 1) * sizeof(char *));
+
+ providers[n_providers] = strdup(p);
+ p = strtok(0, ",");
+ n_providers++;
+ }
+ free(arg);
+ }
+ break;
+
+ case 'v':
+ verbose++;
+ if (optarg && (x = atoi(optarg)))
+ verbose = x;
+ break;
+/* Uppercase options are for output format */
+
+ case 'C':
+ is_client = 1;
+ break;
+
+ case 'D':
+ is_daemon = 1;
+ need_dest = 0;
+ if (optarg) {
+ x = atoi(optarg);
+ is_daemon = x;
+ if (we_are_daemon && x == 3) {
+ kill(getppid(), SIGTERM);
+ exit(EXIT_SUCCESS);
+ }
+ }
+ break;
+
+ case 'G':
+ explain = atoi(optarg);
+ break;
+ case 'H':
+ header++;
+ break;
+ case 'L':
+ list++;
+ explain = 9;
+ break;
+ case 'N':
+ explain = 55;
+ break;
+ case 'P':
+ pid_dir = strdup(optarg);
+ break;
+ case 'O':
+ free(socket_file);
+ socket_file = strdup(optarg);
+ break;
+ case 'S':
+ sortby = *optarg;
+ break;
+ case 'T':
+ table++;
+ break;
+/* Fixme: check/warn illegal kombinations of options */
+ case 'U':
+ usestat++;
+ break;
+
+ case 'V':
+ print_version(myshortname);
+ exit(0);
+
+ case 'X':
+ if (explain == 0) {
+ explain++;
+ if (optarg && isdigit(*optarg) && (x = atoi(optarg))) {
+ explain = x;
+ if (x == 50 || x == 51 || x == 52)
+ need_dest = 0;
+ }
+ else if (optarg) {
+ comment = strdup(optarg);
+ explain = 8;
+ need_dest = 0;
+ }
+ break;
+ }
+ /* fallthrough */
+ case '?':
+ print_msg(PRT_A, usage, myshortname, myshortname, options);
+ break;
+
+ case 'Z':
+ lcr++;
+ break;
+ } /* switch */
+ } /* while */
+ if (is_client && is_daemon != 3 && is_daemon) {
+ is_daemon = 0;
+ print_msg(PRT_V, "Conflicting options, -D disabled\n");
+ }
+ if (list && table) {
+ table = 0;
+ print_msg(PRT_V, "Conflicting options, -T disabled\n");
+ }
+ if (usestat && !table)
+ print_msg(PRT_V, "Conflicting options, -U ignored\n");
+ if ((list || table) && explain >= 10) {
+ list = table = 0;
+ print_msg(PRT_V, "Conflicting options, -T, -L disabled\n");
+ }
+ if (best < 1) {
+ best = MAXPROVIDER;
+ print_msg(PRT_V, "Illegal options, -b ignored\n");
+ }
+ if ((explain == 50 || explain == 51 || explain == 52) && header) {
+ print_msg(PRT_V, "Conflicting options, -H ignored\n");
+ }
+ if (explain >= 10 && service) {
+ print_msg(PRT_V, "Conflicting options, -s ignored\n");
+ service = 0;
+ }
+ if (argc > optind)
+ return (optind);
+ else
+ return (0);
+} /* opts */
+
+
+static int (*compare_func) (const void *s1, const void *s2);
+static int compare(const void *s1, const void *s2)
+{
+ return (((SORT *) s1)->rate > ((SORT *) s2)->rate);
+} /* compare */
+static int compare_vbn(const void *s1, const void *s2)
+{
+ return (((SORT *) s1)->prefix > ((SORT *) s2)->prefix);
+}
+static int compare_name(const void *s1, const void *s2)
+{
+ return strcasecmp(((SORT *) s1)->name, ((SORT *) s2)->name);
+}
+
+static int compare2(const void *s1, const void *s2)
+{
+ return (((SORT2 *) s1)->weight < ((SORT2 *) s2)->weight);
+} /* compare2 */
+
+char *short_explainRate(RATE * Rate)
+{
+
+ static char buffer[BUFSIZ];
+ char *p = buffer;
+
+ if (service && Rate->dst[1] && *Rate->dst[1])
+ p += sprintf(p, "%s, ", Rate->dst[1]);
+
+ if (Rate->Zone && *Rate->Zone)
+ p += sprintf(p, "%s", Rate->Zone);
+ else
+ p += sprintf(p, "Zone %d", Rate->zone);
+
+ if (!Rate->domestic && Rate->Country && *Rate->Country)
+ p += sprintf(p, " (%s)", Rate->Country);
+
+ if (Rate->Day && *Rate->Day)
+ p += sprintf(p, ", %s", Rate->Day);
+
+ if (Rate->Hour && *Rate->Hour)
+ p += sprintf(p, ", %s", Rate->Hour);
+
+ return buffer;
+}
+
+static char *printrate(RATE * Rate)
+{
+ static char message[BUFSIZ];
+
+ if (Rate->Basic > 0)
+ sprintf(message, "%s + %s/%.1fs = %s + %s/Min (%s)",
+ printRate(Rate->Basic),
+ printRate(Rate->Price),
+ Rate->Duration,
+ printRate(Rate->Basic),
+ printRate(60 * Rate->Price / Rate->Duration),
+ short_explainRate(Rate));
+ else
+ sprintf(message, "%s/%.1fs = %s/Min (%s)",
+ printRate(Rate->Price),
+ Rate->Duration,
+ printRate(60 * Rate->Price / Rate->Duration),
+ short_explainRate(Rate));
+
+ return (message);
+} /* printrate */
+
+
+static void buildtime()
+{
+ auto struct tm tm;
+
+ tm.tm_sec = sec;
+ tm.tm_min = min;
+ tm.tm_hour = hour;
+ tm.tm_mday = day;
+ tm.tm_mon = month - 1;
+ tm.tm_year = year - 1900; /* ja, ja, ich weiá ;-) */
+ tm.tm_isdst = -1;
+
+ start = mktime(&tm);
+} /* buildtime */
+
+
+static void splittime()
+{
+ auto struct tm *tm;
+
+ tm = localtime(&start);
+ sec = tm->tm_sec;
+ min = tm->tm_min;
+ hour = tm->tm_hour;
+ day = tm->tm_mday;
+ month = tm->tm_mon + 1;
+ year = tm->tm_year + 1900;
+} /* splittime */
+
+static char *Provider(int prefix)
+{
+ register char *p, *p1;
+ register int l;
+ static char s[BUFSIZ];
+ char prov[TN_MAX_PROVIDER_LEN];
+
+ if (prefix == UNKNOWN)
+ return ("?");
+
+ p = getProvider(prefix);
+
+ l = max(WIDTH, strlen(p)) - strlen(p);
+
+ p1 = prefix2provider_variant(prefix, prov);
+
+ l += (8 - strlen(p1));
+
+ sprintf(s, "%s:%s%*s", p1, p, l, "");
+
+ return (s);
+} /* Provider */
+
+static char *takt_str(RATE * Rate)
+{
+ static char s[BUFSIZ];
+
+ if (floor(Rate->Rhythm[0]) == Rate->Rhythm[0])
+ sprintf(s, "%.0f/", Rate->Rhythm[0]);
+ else
+ sprintf(s, "%.3f/", Rate->Rhythm[0]);
+ if (floor(Rate->Rhythm[1]) == Rate->Rhythm[1])
+ sprintf(s + strlen(s), "%.0f", Rate->Rhythm[1]);
+ else
+ sprintf(s + strlen(s), "%.3f", Rate->Rhythm[1]);
+ return s;
+}
+
+static inline char *P_EMPTY(char *s)
+{
+ char *p = s;
+
+ return p ? p : "";
+}
+
+#define DEL ';'
+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 first = 1;
+ static char BUSINESS[] = "Business"; /* in C:GT:Tag */
+
+ if (destnum.nprovider != UNKNOWN) {
+ low = high = destnum.nprovider;
+ } /* if */
+ compare_func = compare;
+ switch (sortby) {
+ case 'v':
+ compare_func = compare_vbn;
+ break;
+ case 'n':
+ compare_func = compare_name;
+ break;
+ }
+
+ buildtime();
+ if (explain == 98 || explain == 97) { /* Minutenpreis fuer
+ diese Woche */
+ tm = localtime(&start);
+ tm->tm_hour = 0;
+ tm->tm_min = 1;
+ tm->tm_sec = 0;
+ start = mktime(tm);
+ if (explain == 98) {
+ while (tm->tm_wday) { /* find last monday */
+ start -= (60 * 60 * 24);
+ tm = localtime(&start);
+ } /* while */
+ start += (60 * 60 * 24);
+ }
+ }
+ if (service) {
+ num = getServiceNum(num);
+ if (!num || !*num) {
+ return 0;
+ }
+ }
+ do {
+ for (i = low; i <= high; i++) {
+ int found, p;
+ char *t;
+
+ if (ignore[i]) /* Fixme: */
+ continue;
+ if (booked && !isProviderBooked(i))
+ continue;
+ if (!all && !isProviderValid(i, start))
+ continue;
+ t = getProvider(i);
+ if (!t || t[strlen(t) - 1] == '?') /* UNKNOWN Provider */
+ continue;
+
+ t = getComment(i, "GT"); /* get Geb. Text comment */
+ if (business) { /* only business wanted */
+ if (t == 0)
+ continue;
+ else if (strstr(t, BUSINESS) == 0)
+ continue;
+ }
+ if (xbusiness) { /* no business wanted */
+ if (t && strstr(t, BUSINESS) > 0)
+ continue;
+ }
+ found = 0;
+ if (n_providers) {
+ for (p = 0; p < n_providers; p++)
+ if (pnum2prefix_variant(providers[p], start) == i) {
+ found = 1;
+ break;
+ }
+ if (!found)
+ continue;
+ }
+ if (nx_providers) {
+ for (p = 0; p < nx_providers; p++)
+ if (pnum2prefix_variant(xproviders[p], start) == i) {
+ found = 1;
+ break;
+ }
+ if (found)
+ continue;
+ }
+ clearRate(&Rate);
+ Rate.src[0] = srcnum.country;
+ Rate.src[1] = srcnum.area;
+ Rate.src[2] = "";
+
+ destnum.nprovider = i;
+ Strncpy(destnum.provider, getProvider(i), TN_MAX_PROVIDER_LEN);
+ if (normalizeNumber(num, &destnum, TN_ALL) == UNKNOWN) {
+ continue;
+ }
+
+ Rate.dst[0] = destnum.country;
+ Rate.dst[1] = destnum.area;
+ Rate.dst[2] = destnum.msn;
+ /* Rate.Service = "Internet by call"; */
+
+ Rate.prefix = i;
+
+ Rate.start = start;
+ Rate.now = start + duration - 1;
+ if (explain == 99) {
+ int j;
+ double oldCharge = -1.0;
+
+ if (first && header)
+ print_header();
+ first = 0;
+ printf("@ %s\n", prefix2provider_variant(Rate.prefix, prov));
+ Rate.now = start + 1;
+ for (j = 1; j < duration; j++) {
+ if (!getRate(&Rate, NULL) && (Rate.Price != 99.99)) {
+ if (Rate.Charge != oldCharge || j == duration - 1) {
+ printf("%d %.4f\n", j, Rate.Charge);
+ oldCharge = Rate.Charge;
+ }
+ }
+ else
+ break;
+ Rate.now++;
+ }
+ if (Rate.Duration <= takt)
+ printf("@----- %s %s\n", currency, Rate.Provider);
+ }
+ if (explain == 98 || explain == 97) { /* Minutenpreis fuer
+ diese Woche/Tag */
+ int j;
+
+ if (first && header)
+ print_header();
+ first = 0;
+ printf("@ %s\n", prefix2provider_variant(Rate.prefix, prov));
+ 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);
+ }
+ else
+ break;
+ Rate.now += 3600;
+ Rate.start += 3600;
+ }
+ if (Rate.Duration <= takt)
+ printf("@----- %s %s\n", currency, Rate.Provider);
+ }
+ else if (explain == 50 || explain == 51) {
+ int fi = 1;
+
+ while (getZoneRate(&Rate, explain - 50, fi) == 0) {
+ double cpm = Rate.Duration > 0 ? 60 * Rate.Price / Rate.Duration : 99.99;
+
+ if (Rate.Price == 0)
+ cpm = Rate.Basic;
+
+ fi = 0;
+ if (Rate.Price != 99.99)
+ printf("%s%c%s%c%s%c%.2f%c%.2f%c%s\n", prefix2provider(Rate.prefix, prov), DEL,
+ Rate.Provider, DEL, currency, DEL, Rate.Charge, DEL, cpm, DEL,
+ P_EMPTY(Rate.Country));
+ free(Rate.Country);
+ }
+ }
+ else {
+ /* kludge to suppress "impossible" Rates */
+ char **message, *msg;
+ if(verbose)
+ message = &msg;
+ else
+ message = NULL;
+ if (!getRate(&Rate, message) && (Rate.Price != 99.99)) {
+ if (!(Rate.Duration <= takt))
+ continue;
+ sort[n].prefix = Rate.prefix;
+ sort[n].rate = Rate.Charge;
+ sort[n].name = Rate.Provider;
+ switch (explain) {
+ case 1:
+ if (service)
+ sprintf(s, " (%s, %s)", P_EMPTY(Rate.dst[1]), Rate.Zone);
+ else
+ sprintf(s, " (%s)", Rate.Zone);
+ sort[n].explain = strdup(s);
+ break;
+ case 2:
+ sprintf(s, " (%s)", printrate(&Rate));
+ sort[n].explain = strdup(s);
+ break;
+ case 8:
+ sort[n].explain = strdup(P_EMPTY(getComment(i, comment)));
+ break;
+ case 9: /* used by list */
+ {
+ double cpm = Rate.Duration > 0 ? 60 * Rate.Price / Rate.Duration : 99.99;
+
+ if (Rate.Price == 0)
+ cpm = Rate.Basic;
+
+ sprintf(s, "%s%c"
+ "%s%c%s%c%s%c%s%c"
+ "%s%c"
+ "%.3f%c%.4f%c%.4f%c%.2f%c%.3f%c"
+ "%s%c%.2f",
+ prefix2provider_variant(Rate.prefix, prov), 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.Basic, DEL, Rate.Price, DEL, Rate.Duration, DEL, cpm, DEL,
+ takt_str(&Rate), DEL, Rate.Sales);
+ sort[n].explain = strdup(s);
+ }
+ break;
+ default:
+ sort[n].explain = strdup("");
+ break;
+ }
+
+ n++;
+ } /* if */
+ else if(verbose && *msg)
+ print_msg(PRT_V, "%s\n", msg);
+
+ } /* else 99 */
+ } /* for i */
+ if (service)
+ num = getServiceNum(0); /* get next service num */
+ else
+ num = 0;
+ } while (num && *num);
+ if (explain < 10) {
+ qsort((void *) sort, n, sizeof(SORT), compare_func);
+ if (lcr && n) {
+ RATE Cheap;
+ int res = getLeastCost(&Rate, &Cheap, booked, -1);
+
+ if (res != UNKNOWN) {
+ sort[n].prefix = Cheap.prefix;
+ sort[n].rate = Cheap.Charge;
+ sort[n].name = Cheap.Provider;
+ sprintf(s, "(Cheapest: %s %s %s %s)", Cheap.dst[0], Cheap.dst[1], Cheap.dst[2], P_EMPTY(Cheap.Zone));
+ sort[n].explain = strdup(s);
+ n++;
+ } /* res */
+ } /* lcr */
+ } /* explain */
+ return (n);
+} /* compute */
+
+static void print_header(void)
+{
+ printf("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(int n)
+{
+ int i;
+
+ if (header)
+ print_header();
+ if (n > best)
+ n = best;
+
+ for (i = 0; i < n; i++)
+ printf("%s\n", sort[i].explain);
+}
+
+static void result(int n)
+{
+
+ register int i;
+
+ if (header)
+ print_header();
+
+ if (n > best)
+ n = best;
+ for (i = 0; i < n; i++)
+ printf("%s %s %8.3f %s\n",
+ Provider(sort[i].prefix), currency, sort[i].rate, sort[i].explain);
+} /* result */
+
+
+static void purge(int n)
+{
+ register int i;
+
+ for (i = 0; i < n; i++)
+ if (sort[i].explain)
+ free(sort[i].explain);
+} /* purge */
+
+/*
+ Werktag
+ Wochenende
+ Ortszone
+ Regionalzone
+ Fernzone
+ Handy
+ Internet
+ 0..23 Uhr
+ */
+
+#define STARTHOUR 8
+
+static void printTable(char *num)
+{
+ register int n, d, i, h, lasthour;
+ auto struct tm *tm;
+ auto SORT last[_MAXLAST];
+ auto int used[MAXPROVIDER];
+ auto int hours[MAXPROVIDER];
+ auto int weight[MAXPROVIDER];
+ auto int useds = 0, maxhour;
+ auto SORT2 wsort[MAXPROVIDER];
+ static int firsttime = 1;
+ int first;
+ int prefix;
+
+ memset(used, 0, sizeof(used));
+ memset(hours, 0, sizeof(hours));
+ memset(weight, 0, sizeof(weight));
+
+ for (d = 0; d < 3; d++) { /* Werktag, Samstag, Sonntag */
+ last[0].prefix = UNKNOWN;
+ lasthour = UNKNOWN;
+
+ buildtime();
+ tm = localtime(&start);
+
+ if (!d) { /* first time */
+ while (tm->tm_wday != 5) { /* find next Friday */
+ start += (60 * 60 * 24);
+ tm = localtime(&start);
+ } /* while */
+ }
+ else /* erst Samstag, dann */
+ start += (60 * 60 * 24); /* Sonntag */
+
+ splittime();
+ buildtime();
+
+ hour = STARTHOUR;
+ min = 0;
+
+ first = 1;
+
+ while (1) {
+ destnum.nprovider = UNKNOWN;
+ if (provider2prefix(num, &prefix)) /* set provider if it is in number */
+ normalizeNumber(num, &destnum, TN_PROVIDER);
+ n = compute(num);
+
+ if (header && first && d == 0 && firsttime)
+ print_header();
+
+ if (header && first) {
+ switch (d) {
+ case 0 : printf("\nWerktag:\n"); break;
+ case 1 : printf("\nSamstag:\n"); break;
+ case 2 : printf("\nSonntag:\n"); break;
+ } /* switch */
+
+ first = 0;
+ } /* if */
+
+ if (last[0].prefix == UNKNOWN) {
+ for (i = 0; i < min(n, MAXLAST); i++) {
+ if (sort[i].prefix) {
+ last[i].prefix = sort[i].prefix;
+ last[i].rate = sort[i].rate;
+ last[i].explain = strdup(sort[i].explain);
+ } /* if */
+ } /* for */
+ } /* if */
+
+ if (lasthour == UNKNOWN)
+ lasthour = hour;
+
+ if (sort[0].prefix != last[0].prefix) {
+ for (i = 0; i < min(n, MAXLAST); i++) {
+
+ if (!i)
+ printf(" %02d:00 .. %02d:59 %s = %s %s%s\n",
+ lasthour, hour - 1, Provider(last[i].prefix),
+ currency,
+ double2str(last[i].rate, 5, 3, DEB),
+ last[i].explain);
+ else
+ printf(" %s = %s %s%s\n",
+ Provider(last[i].prefix),
+ currency,
+ double2str(last[i].rate, 5, 3, DEB),
+ last[i].explain);
+ } /* for */
+
+ used[last[0].prefix]++;
+
+ if (lasthour >= hour)
+ h = ((24 - lasthour) + hour);
+ else
+ h = hour - lasthour;
+
+ hours[last[0].prefix] += h;
+
+ if ((lasthour > 8) && (lasthour < 21))
+ h *= 2;
+
+ weight[last[0].prefix] += h * (d ? 1 : 5);
+
+ 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);
+ } /* for */
+
+ lasthour = hour;
+ } /* if */
+
+ purge(n);
+
+ hour++;
+
+ if (hour == 24)
+ hour = 0;
+ else if (hour == STARTHOUR)
+ break;
+ } /* while */
+
+ for (i = 0; i < min(n, MAXLAST); i++) {
+
+ if (!i) {
+ if ((lasthour == STARTHOUR) && (hour == STARTHOUR))
+ printf(" immer %s = %s %s%s\n",
+ Provider(last[i].prefix),
+ currency,
+ double2str(last[i].rate, 5, 3, DEB),
+ last[i].explain);
+ else
+ printf(" %02d:00 .. %02d:59 %s = %s %s%s\n",
+ lasthour, hour - 1, Provider(last[i].prefix),
+ currency,
+ double2str(last[i].rate, 5, 3, DEB),
+ last[i].explain);
+ }
+ else
+ printf(" %s = %s %s%s\n",
+ Provider(last[i].prefix),
+ currency,
+ double2str(last[i].rate, 5, 3, DEB),
+ last[i].explain);
+ } /* for */
+
+ used[last[0].prefix]++;
+
+ if (lasthour >= hour)
+ h = ((24 - lasthour) + hour);
+ else
+ h = hour - lasthour;
+
+ hours[last[0].prefix] += h;
+
+ if ((lasthour > 8) && (lasthour < 21))
+ h *= 2;
+
+ weight[last[0].prefix] += h * (d ? 1 : 5);
+
+ } /* for */
+
+ if (usestat) {
+ printf("\nProvider(s) used:\n");
+
+ maxhour = 9999999;
+ useds = 0;
+
+ for (i = 0; i < MAXPROVIDER; i++)
+ if (used[i]) {
+ printf("%s %d times, %d hours, weight = %d\n",
+ Provider(i), used[i], hours[i], weight[i]);
+
+ wsort[useds].weight = weight[i];
+ wsort[useds].index = i;
+
+ useds++;
+
+ if (hours[i] < maxhour)
+ maxhour = hours[i];
+ } /* if */
+
+ if ((best < MAXPROVIDER) && (best < useds)) {
+ printf("Retrying with only %d provider(s), eliminating %d provider(s)\n", best, useds - best);
+
+ qsort((void *) wsort, useds, sizeof(SORT2), compare2);
+
+ for (i = 0; i < useds; i++) {
+ printf("%s %d times, %d hours, weight = %d\n",
+ Provider(wsort[i].index), used[wsort[i].index], hours[wsort[i].index], weight[wsort[i].index]);
+
+ if (i == best - 1)
+ printf("\n");
+
+ if (i >= best - 1)
+ ignore[wsort[i].index]++;
+ } /* for */
+
+ if (firsttime)
+ printTable(num);
+
+ firsttime = 0;
+
+ } /* if */
+ } /* if */
+} /* printTable */
+
+
+static void clean_up()
+{
+ if (providers)
+ free(providers);
+ providers = 0;
+ fromarea = 0;
+ table = list = header = explain = 0;
+ usestat = 0;
+ duration = LCR_DURATION;
+ wanted_day = '\0';
+ takt = 99999;
+ if (comment)
+ free(comment);
+ comment = 0;
+ sortby = 0;
+ need_dest = 1;
+}
+
+static char * sub_sp(char *p)
+{
+ char *o = p;
+ int allupper=1;
+ for (; *p; p++)
+ if(!isupper(*p) && *p != '_' && !isdigit(*p)) { /* e.g. _DEMD1 */
+ allupper = 0;
+ break;
+ }
+ if (!allupper)
+ for (p = o; *p; p++)
+ if(*p == '_')
+ *p = ' ';
+ return o;
+}
+static void doit(int i, int argc, char *argv[])
+{
+ int n;
+ int prefix;
+ char *num;
+
+ post_init();
+ memset(ignore, 0, sizeof(ignore));
+ if (!need_dest && i == 0) {
+ i = 0;
+ argc = 1;
+ argv[0] = "2345";
+ }
+ while (i < argc) {
+ num = sub_sp(argv[i]);
+ if (explain == 55) {
+ if (n_providers) {
+ destnum.nprovider = pnum2prefix_variant(providers[0], 0);
+ Strncpy(destnum.provider, getProvider(destnum.nprovider), TN_MAX_PROVIDER_LEN);
+ normalizeNumber(num, &destnum, TN_NO_PROVIDER);
+ }
+ else
+ normalizeNumber(num, &destnum, TN_ALL);
+ printf("%s => %s \n", num, formatNumber("%l - %p", &destnum));
+ i++;
+ continue;
+ }
+ else if (explain == 52) { // enum Servce names
+
+ int first = 1;
+ char *p;
+
+ do {
+ p = getServiceNames(first);
+ if (p)
+ printf("%s\n", p);
+ first = 0;
+ }
+ while (p);
+ return;
+ }
+ destnum.nprovider = UNKNOWN;
+ if (provider2prefix(num, &prefix)) /* set provider if it is in
+ number */
+ normalizeNumber(num, &destnum, TN_PROVIDER);
+ if (table)
+ printTable(num);
+ else {
+ n = compute(num);
+ if (list)
+ printList(n);
+ else if (explain < 10)
+ result(n);
+ purge(n);
+ }
+ i++;
+ } /* while */
+ clean_up();
+}
+
+static void err(char *s)
+{
+ print_msg(PRT_A, "%s - '%s'\n", s, strerror(errno));
+ if (is_daemon == 2)
+ kill(getppid(), SIGTERM);
+ exit(2);
+}
+
+static int handle_client(int fd)
+{
+ char buffer[BUFSIZ];
+ int argc, n, i;
+ char **argv;
+ char *p;
+
+ if ((n = read(fd, buffer, BUFSIZ)) < 0)
+ err("Read");
+ if (n) {
+ argv = calloc(sizeof(char *), 20);
+
+ buffer[n] = '\0';
+ if (verbose)
+ fprintf(stderr, "got '%s'\n", buffer);
+ argc = 0;
+ argv[argc++] = strdup(myname);
+ p = strtok(buffer, "\t\n ");
+ while (p) {
+ argv[argc++] = strdup(p);
+ p = strtok(0, "\t\n ");
+ if (argc >= 20)
+ break;
+ }
+ time(&start); /* set time of call */
+ splittime(); /* date time my be overridden by opts */
+ we_are_daemon = 1;
+ if ((i = opts(argc, argv)) || need_dest == 0) {
+ if (shutdown(fd, 0) < 0) /* no read any more */
+ err("shutdown");
+ if (dup2(fd, STDOUT_FILENO) < 0) /* stdout to sock */
+ err("dup");
+ doit(i, argc, argv);
+ fflush(stdout);
+ fclose(stdout);
+ }
+ for (i = 0; i < argc; i++)
+ free(argv[i]);
+ free(argv);
+ }
+ return n == 0 ? -1 : 0;
+}
+
+void catch_sig(int sig)
+{
+ print_msg(PRT_A, "Signal %d\n", sig);
+ unlink(socket_file);
+ if (pid_dir)
+ unlink(pid_file);
+ err("Sig");
+}
+
+static void del_sock(void)
+{
+ if (getppid() > 0) {
+ unlink(socket_file);
+ if (pid_dir)
+ unlink(pid_file);
+ }
+}
+
+static volatile sig_atomic_t stopped = 0;
+static volatile sig_atomic_t reinit = 0;
+
+static void catch_term(int sig)
+{
+ stopped = 1;
+}
+
+static void catch_hup(int sig)
+{
+ print_msg(PRT_A, "Signal %d restarting %s\n", sig, myname);
+ del_sock();
+ execvp(myname, hup_argv);
+ print_msg(PRT_A, "- failed\n");
+}
+
+static void do_reinit(void)
+{
+ /* deinit(), init() doesn't */
+ reinit=0;
+}
+
+/* thank's to Jochen Erwied for this: */
+#ifndef TEMP_FAILURE_RETRY
+#define TEMP_FAILURE_RETRY(expression) \
+ (__extension__ \
+ ({ long int __result; \
+ do __result = (long int) (expression); \
+ while (__result == -1L && errno == EINTR); \
+ __result; })) \
+
+#endif
+
+static void setup_daemon()
+{
+ int sock;
+ struct sockaddr_un sa;
+ struct sockaddr_in client;
+ fd_set active_fd_set, read_fd_set;
+ char *sock_name = socket_file;
+ socklen_t size;
+ struct stat stat_buf;
+ int i;
+ pid_t pid;
+ char pidname[] = "isdnrate.pid";
+ FILE *fp;
+
+ if (verbose)
+ fprintf(stderr, "Setup sockets\n");
+ signal(SIGTERM, catch_term);
+ signal(SIGINT, catch_sig);
+ signal(SIGHUP, catch_hup);
+
+ if (is_daemon == 2) { /* go background */
+
+ fprintf(stderr, "Going background\n");
+ verbose = 0;
+ pid = fork();
+ if (pid < 0)
+ err("Going bg failed");
+ else if (pid > 0) {
+ exit(EXIT_SUCCESS);
+ }
+ }
+ if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
+ err("Can't open socket");
+ sa.sun_family = AF_UNIX;
+ strcpy(sa.sun_path, sock_name);
+ size = offsetof(struct sockaddr_un, sun_path) + strlen(sa.sun_path) + 1;
+
+ if (bind(sock, (struct sockaddr *) &sa, size) < 0)
+ err("Can't bind sock");
+
+ stat(sock_name, &stat_buf);
+ chmod(sock_name, stat_buf.st_mode | S_IWOTH | S_IWGRP);
+/* should better have perm wwwrun.nogroup */
+
+ if (listen(sock, SOMAXCONN) < 0)
+ err("Can't listen");
+ if (pid_dir) {
+ pid_file = malloc(strlen(pid_dir) + strlen(pidname) + 2);
+ strcpy(pid_file, pid_dir);
+ if (pid_file[strlen(pid_file) - 1] != '/')
+ strcat(pid_file, "/");
+ strcat(pid_file, pidname);
+ if ((fp = fopen(pid_file, "w")) == 0)
+ fprintf(stderr, "Can't write %s\n", pid_file);
+ else {
+ fprintf(fp, "%d\n", getpid());
+ fclose(fp);
+ }
+ }
+ atexit(del_sock);
+ FD_ZERO(&active_fd_set);
+ FD_SET(sock, &active_fd_set);
+ while (!stopped) {
+ if (reinit)
+ do_reinit();
+ read_fd_set = active_fd_set;
+ if (TEMP_FAILURE_RETRY(select(FD_SETSIZE, &read_fd_set, 0, 0, 0)) < 0)
+ err("select");
+ for (i = 0; i < FD_SETSIZE; i++)
+ if (FD_ISSET(i, &read_fd_set)) {
+ if (i == sock) { /* request on orig */
+ int new;
+
+ size = sizeof(client);
+ if ((new = accept(sock, (struct sockaddr *) &client, &size)) < 0)
+ err("accept");
+ if (verbose)
+ fprintf(stderr, "Accepted %d\n", new);
+ FD_SET(new, &active_fd_set);
+ }
+ else { /* already connected */
+ pid_t pid;
+ int status;
+
+ if (verbose)
+ fprintf(stderr, "Handle client %d\n", i);
+ pid = fork();
+ if (pid == 0) {
+ handle_client(i);
+ _exit(EXIT_SUCCESS);
+ }
+ else if (pid < 0)
+ err("fork");
+ else {
+ if (waitpid(pid, &status, 0) != pid)
+ err("waitpid");
+ close(i);
+ FD_CLR(i, &active_fd_set);
+ }
+ } /* if i */
+ } /* if ISSET */
+ } /* while */
+ del_sock();
+ exit(EXIT_SUCCESS);
+}
+
+static int connect_2_daemon(int argc, char *argv[])
+{
+ int sock;
+ struct sockaddr_un sa;
+ char *sock_name = socket_file;
+ size_t size;
+ int i, c, len;
+ char *p, *q, buffer[BUFSIZ];
+
+ if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
+ err("Can't open socket");
+ sa.sun_family = AF_UNIX;
+ strcpy(sa.sun_path, sock_name);
+ size = offsetof(struct sockaddr_un, sun_path) + strlen(sa.sun_path) + 1;
+
+ if (connect(sock, (struct sockaddr *) &sa, size) < 0)
+ err("Can't connect sock");
+ p = buffer;
+ optind = 0; /* reinit */
+ len = 0;
+ while ((c = getopt(argc, argv, options)) != EOF && len < BUFSIZ - 10) {
+ switch (c) {
+ case '?':
+ case 'C':
+ break;
+ case 'D':
+ if (optarg && atoi(optarg) == 3) ; /* goon, kill a running
+ daemon */
+ else
+ break;
+ default:
+ *p++ = '-';
+ *p++ = c;
+ len += 3;
+ if (optarg)
+ for (q = optarg; *q && len < BUFSIZ - 10; len++)
+ *p++ = *q++;
+ *p++ = ' ';
+ break;
+ }
+ }
+ for (i = optind; i < argc; i++) {
+ for (q = argv[i]; *q && len < BUFSIZ - 10; len++)
+ *p++ = *q++;
+ *p++ = ' ';
+ len++;
+ }
+ *--p = '\x0';
+ i = write(sock, buffer, strlen(buffer) + 1);
+ if (i < 0)
+ err("Write sock");
+ while ((i = read(sock, buffer, BUFSIZ)) > 0)
+ write(1, buffer, i);
+ close(sock);
+ return EXIT_SUCCESS;
+}
+
+
+int main(int argc, char *argv[], char *envp[])
+{
+ register int i;
+ sigset_t unblock_set;
+
+ myname = argv[0];
+ myshortname = basename(myname);
+
+ time(&start);
+ splittime();
+ socket_file = strdup(SOCKNAME);
+ /* borrowed from isdnlog.c, thanks */
+ hup_argv = argv;
+ sigemptyset(&unblock_set);
+ sigaddset(&unblock_set, SIGHUP);
+ sigprocmask(SIG_UNBLOCK, &unblock_set, NULL);
+
+ if ((i = opts(argc, argv)) || need_dest == 0) {
+ if (is_client)
+ exit(connect_2_daemon(argc, argv));
+ else
+ init();
+ if (is_daemon) {
+ clean_up();
+ setup_daemon();
+ }
+ else
+ doit(i, argc, argv);
+ }
+ else {
+ print_msg(PRT_A, usage, myshortname, myshortname, options);
+ print_msg(PRT_A, "\n");
+ print_msg(PRT_A, "\t-a \tall=show old and newer rates (default actual only)\n", MAXPROVIDER);
+ print_msg(PRT_A, "\t-b best\tshow only the first <best> provider(s) (default %d)\n", MAXPROVIDER);
+ print_msg(PRT_A, "\t-d d[.m[.y]] | {W|N|E}\tstart date of call (default now)\n");
+ print_msg(PRT_A, "\t-f areacode\tyou are calling from <areacode>\n");
+ print_msg(PRT_A, "\t-h h[:m[:s]]\tstart time of call (default now)\n");
+ print_msg(PRT_A, "\t-l duration\tduration of call in seconds (default %d seconds)\n", LCR_DURATION);
+ print_msg(PRT_A, "\t-o \t show only booked providers\n");
+ print_msg(PRT_A, "\t-p prov|B[,prov...]\t show only these providers\n");
+ print_msg(PRT_A, "\t-s \t consider 'Destination' as a service name\n");
+ print_msg(PRT_A, "\t-t takt\t\tshow providers if chargeduration<=takt\n");
+ print_msg(PRT_A, "\t-v [level]\tverbose\n");
+ print_msg(PRT_A, "\t-x prov|B[,prov...]\t exclude these providers\n");
+
+ print_msg(PRT_A, "\tOutput and run options\n");
+ print_msg(PRT_A, "\t-C\trun as client, connecting to a running daemon\n");
+ print_msg(PRT_A, "\t-CD3\tkill a running daemon\n");
+ print_msg(PRT_A, "\t-D\trun as daemon\n");
+ print_msg(PRT_A, "\t-D2\trun as daemon & go background\n");
+ print_msg(PRT_A, "\t-G which\tshow raw data\n");
+ print_msg(PRT_A, "\t-H\tshow a header\n");
+ print_msg(PRT_A, "\t-L\tshow a detailed list\n");
+ print_msg(PRT_A, "\t-O sOcket-path\twrite socket to this file (def:tmp/isdnrate)\n");
+ print_msg(PRT_A, "\t-P pid-dir\twrite own PID to pid-dir/isdnrate.pid\n");
+ print_msg(PRT_A, "\t-N\tparse the given telefon numbers\n");
+ print_msg(PRT_A, "\t-S[v|n]\tsort by v=VBN, n=Name, default=Charge\n");
+ print_msg(PRT_A, "\t-T\tshow a table of day/night week/weekend\n");
+ print_msg(PRT_A, "\t-U\tshow usage stats for table\n");
+ print_msg(PRT_A, "\t-V\tshow version info\n");
+ print_msg(PRT_A, "\t-X\texplain each rate\n");
+ print_msg(PRT_A, "\t-X2\texplain more\n");
+ print_msg(PRT_A, "\t-X comment\tprint <comment> from C:tag\n");
+ print_msg(PRT_A, "\t-Z show entry from getLeastCost\n");
+ print_msg(PRT_A, "\n\te.g.\t%s -b5 -f30 -TH -t1 Zaire\n", myshortname);
+ } /* else */
+/* deinit(); Fixme: this SIGSEGVs in exitHoliday */
+ return (0);
+} /* isdnrate */
diff -Naur isdn4k-utils-orig//isdnlog/tools/rate.c isdn4k-utils/isdnlog/tools/rate.c
--- isdn4k-utils-orig//isdnlog/tools/rate.c 2002-07-06 09:22:33.000000000 +1000
+++ isdn4k-utils/isdnlog/tools/rate.c 2010-12-04 20:44:03.786672226 +1000
@@ -1773,6 +1773,7 @@
number=realloc(number, numbers*sizeof(int));
number[numbers-1]=i;
skip:
+ ;
}
while (isblank(*s)) s++;
@@ -2344,6 +2345,7 @@
}
return UNKNOWN;
done:
+ ;
}
}
}
diff -Naur isdn4k-utils-orig//lib/libtools.c isdn4k-utils/lib/libtools.c
--- isdn4k-utils-orig//lib/libtools.c 1999-11-04 02:13:36.000000000 +1000
+++ isdn4k-utils/lib/libtools.c 2010-12-04 20:44:03.786672226 +1000
@@ -711,6 +711,7 @@
case 'r': _mode |= R_OK;
break;
default :
+ ;
}
}
diff -Naur isdn4k-utils-orig//Makefile isdn4k-utils/Makefile
--- isdn4k-utils-orig//Makefile 2002-07-20 05:03:49.000000000 +1000
+++ isdn4k-utils/Makefile 2010-12-04 20:43:57.890005560 +1000
@@ -132,12 +132,6 @@
install: rootperm
set -e; for i in `echo $(SUBDIRS)`; do $(MAKE) -C $$i install; done
- @if [ -c $(DESTDIR)/dev/isdnctrl0 ] && ls -l $(DESTDIR)/dev/isdnctrl0 | egrep "[[:space:]]45,[[:space:]]+64[[:space:]]" > /dev/null; \
- then \
- /bin/echo -e '(some) ISDN devices already exist, not creating them.\nUse scripts/makedev.sh manually if necessary.'; \
- else \
- sh scripts/makedev.sh $(DESTDIR) ; \
- fi
uninstall: rootperm
set -e; for i in `echo $(SUBDIRS)`; do $(MAKE) -C $$i uninstall; done
|