-
Notifications
You must be signed in to change notification settings - Fork 0
/
fdnode.cpp
executable file
·3407 lines (3016 loc) · 91.2 KB
/
fdnode.cpp
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
// A 'C++' class implementation for the FrontDoor nodelist indices.
// Written by Colin Turner; 2:443/13@fidonet
// Copyright 1995-1998
// Initial research by Bill Birrell and Colin Turner.
// FrontDoor is a registered trademark of Joaquim Homrighausen
/****************************************************************************/
/* */
/* Class: FrontDoorNode */
/* Purpose: Reading FrontDoor(TM) nodelist indices and nodelist files */
/* */
/* Related Classes: FDNFind */
/* */
/****************************************************************************/
#ifndef __FDNODE_H_
#include "fdnode.h"
#endif
#if defined(_WINDOWS) || defined(_Windows) || defined(__WINDOWS__)
# define FDN_WINDOWS
# include "windows.h"
#elif defined(__DOS__) || defined(MSDOS) || defined(_MSDOS) || defined(__MSDOS__)
# define FDN_DOS
# include <dos.h>
# if defined(__WATCOMC__)
# include <i86.h>
# endif
#elif defined(__OS2__) || defined(OS2)
# define FDN_OS2
# define INCL_DOSNLS
# include <os2.h>
#endif
#ifndef FDN_CustomCheckFile
#include <dos.h>
#endif
static char *ListFileName[]={
"NODELIST.XXX",
"FDNODE.FDA",
"FDNET.PVT",
"FDPOINT.PVT"
};
/* Much of the configuration data, and history/todo list have been moved to */
/* The top and bottom of FDNODE.H, please see that file for more. */
/****************************************************************************/
/* */
/* P U B L I C F U N C T I O N S */
/* */
/****************************************************************************/
/****************************************************************************/
/* S E R V I C E F U N C T I O N S */
/****************************************************************************/
/*
** GetNodeExt
**
** This function allows the application to determine the nodelist extension
** as stored in the Nodelist Database. This is returned as a string, because
** some values like "PVT" are possible.
**
** Parameters
**
** buffer A region of memory to place the string (4 characters needed)
**
** Returns
**
** A pointer to the modified buffer
**/
FDNPREF char FDNFUNC *FrontDoorNode::GetNodeExt()
{
return(NodeExt);
}
/*
** Find (Address variant)
**
** This function attempts to initialise the FDNFind block passed with the
** information relevant to the specified nodelist address.
**
** Returns
**
** 1 on failure, 0 on success.
*/
FDNPREF int FDNFUNC FrontDoorNode::Find(FDNFind& fblock, unsigned short int zone, unsigned short int net, unsigned short int node, unsigned short point)
{
char search_key[17];
long dud;
if(IsFrozen()){
fblock.Parent = this;
fblock.offset = 0;
SignalError(29);
return(1);
}
fblock.searchtype=1;
strcpy(search_key, MakeKey(zone, net, node, point, 0));
dud=GetNFDXOffset(search_key, first_n.index, fblock);
if(dud && dud!=0xFFFFFFFFL && fblock.Filter()) return(0);
else return(1);
}
/*
** Find (Username variant)
**
** This function attempts to initialise the FDNFind block passed with the
** information relevant to the passed username. (First match).
**
** Parameters
**
** UserName should have surname first, then other names in normal order.
** A '_' character may be appended to the name to match all users with
** this start.
**
** Returns
**
** 1 on failure, 0 on success.
*/
FDNPREF int FDNFUNC FrontDoorNode::Find(FDNFind& fblock, const char FDNDATA *UserName)
{
int loop, length, stillleft=1;
char search_key[20];
if(IsFrozen()){
fblock.Parent=this;
fblock.offset=0;
fblock.finished=1;
SignalError(29);
return(1);
}
fblock.Parent=this;
// Let's clean the find class ready for use. This is deliberately not done
// in the constructor so the same class can be used for repeated searches.
fblock.searchtype=fblock.level=0;
fblock.finished=0;
// Now we generate our search key to the correct format.
for(loop=0; loop<16; loop++) search_key[loop]=0x20;
length=strlen(UserName);
if(length>=15) memcpy(search_key+1, UserName, 15);
else memcpy(search_key+1, UserName, length);
#ifdef FDN_WINDOWS
AnsiUpperBuff(search_key+1,15);
AnsiToOemBuff(search_key+1,search_key+1,15);
#else
for(loop=0; loop<16; loop++) search_key[loop]=(char) ToUpper(search_key[loop]);
#endif
search_key[0]=0x18;
if(GetUFDXOffset(search_key, first_u.index, fblock) !=0){
while(!fblock.Filter() && stillleft){
stillleft=!UGetNextKey(fblock);
}
if(!fblock.Filter() || !stillleft){
fblock.finished=1;
return(1);
}
return(0);
}
else{
fblock.finished=1;
return(1);
}
}
/*
** Find (Continued search variant)
**
** This function is used to continue the search already started
** with details in the FDNFind block. Searches that may be continued
** (to find the next match) are those started with:
**
** Find (Username variant)
** GetZones, GetNets, GetNodes, GetPoints
**
** Parameters
**
** A FDNFind block already initialised by one of the above
** functions.
**
** Returns
**
** 1 on failure, 0 on success.
**
*/
FDNPREF int FDNFUNC FrontDoorNode::Find(FDNFind& fblock)
{
int stillleft=1;
if(IsFrozen()){
fblock.Parent=this;
fblock.offset=0;
SignalError(29);
return(1);
}
if((fblock.UnixStamp < UnixStamp) || (fblock.Parent !=this)){
SignalError(13);
return(1); // Class has been frozen since last search
}
switch(fblock.searchtype){
case 0 : // This is a userfind search.
stillleft=!UGetNextKey(fblock);
if(!stillleft){
fblock.finished=1;
return(1);
}
else while(stillleft && !fblock.Filter()){
stillleft=!UGetNextKey(fblock);
}
return(!stillleft);
case 2 : // This is zone search.
return(GetNextZone(fblock));
case 3 : // This is net search.
return(GetNextNet(fblock));
case 4 : // This is a node search.
return(GetNextNode(fblock));
case 5 : // This is a point search.
return(GetNextPoint(fblock));
default : // Unknown search type, block is probably corrupt, terminate search
fblock.finished=1;
return(1);
}
}
/*
** GetZones
**
** Initiates a search for the Node entries for each Zone.
** Two versions exist, one which starts with the first Zone in
** the index, and the other which starts with the specified
** Zone.
**
** Returns
**
** 1 on failure, 0 on success.
*/
FDNPREF int FDNFUNC FrontDoorNode::GetZones(FDNFind& fblock)
{
return(GetZones(fblock, 0));
}
FDNPREF int FDNFUNC FrontDoorNode::GetZones(FDNFind& fblock, unsigned short start)
{
int found=0, quit=0;
long dud;
char search_key[17];
if(IsFrozen()){
fblock.Parent=this;
fblock.offset=0;
fblock.finished=1;
SignalError(29);
return(1);
}
fblock.searchtype=2;
fblock.finished=0;
while(!found && !quit){
strcpy(search_key, MakeKey(start, (unsigned short) -1, (unsigned short) -1, (unsigned short) -1, 0));
dud=GetNFDXOffset(search_key, first_n.index, fblock);
if(dud){
if(dud==0xFFFFFFFFL) quit=1; // off end of index
else dud=NGetNextKey(fblock); // otherwise we need to move on one more
}
if(!quit){
if(fblock.zone==fblock.net && !fblock.node && !fblock.point){
// We've found a ZC, pass it through Filter
if(fblock.Filter()) found=1;
else start=fblock.zone; // failed filter
}
else{
if(fblock.net >= fblock.zone) start=fblock.zone; // We must have passed any ZC, move to next zone
else{
strcpy(search_key, MakeKey(fblock.zone, fblock.zone, 0, 0, 0));
dud=GetNFDXOffset(search_key, first_n.index, fblock);
if(dud){
if(dud==0xFFFFFFFFL) quit=1; // off index
else{
if(fblock.Filter()) found=1; // We found a ZC after an explicit search for one
else start=fblock.zone; // failed filter, move on
}
}
}
}
}
}
if(!found) fblock.finished=1;
return(!found);
}
/*
** GetNets
**
** Initiates a search for the Node entries for each Net in the
** specified Zone.
** Two versions exist, one which starts with the first Net in
** the Zone, and the other which starts with the specified
** Net.
**
** Returns
**
** 1 on failure, 0 on success.
*/
FDNPREF int FDNFUNC FrontDoorNode::GetNets(FDNFind& fblock, unsigned short zone)
{
return(GetNets(fblock, zone, 0));
}
FDNPREF int FDNFUNC FrontDoorNode::GetNets(FDNFind& fblock, unsigned short zone, unsigned short start)
{
int found=0, quit=0;
long dud;
char search_key[17];
if(IsFrozen()){
fblock.finished=1;
fblock.Parent=this;
fblock.offset=0;
SignalError(29);
return(1);
}
fblock.searchtype=3;
fblock.finished=0;
fblock.zone=zone;
while(!found && !quit && fblock.zone==zone){
strcpy(search_key, MakeKey(zone, start, (unsigned short) -1, (unsigned short) -1, 0));
dud=GetNFDXOffset(search_key, first_n.index, fblock);
if(dud){
if(dud==0xFFFFFFFFL) quit=1; // off end of index
else dud=NGetNextKey(fblock); // otherwise we need to move on one more
}
if(!quit){
if(fblock.zone==zone && !fblock.node && !fblock.point){
// We've found an NC, pass it through Filter
if(fblock.Filter()) found=1;
else start=fblock.net; // failed filter
}
else{
if(fblock.node) start=fblock.net; // We must have passed any NC, move to next zone
if(fblock.zone!=zone) quit=1; // Moved pass the correct zone
}
}
}
if(!found) fblock.finished=1;
return(!found);
}
/*
** GetNodes
**
** Initiates a search for the Node entries for each Node in the
** specified Net.
** Two versions exist, one which starts with the first Node in
** the Net, and the other which starts with the specified
** Node.
**
** Returns
**
** 1 on failure, 0 on success.
*/
FDNPREF int FDNFUNC FrontDoorNode::GetNodes(FDNFind& fblock, unsigned short zone, unsigned short net)
{
return(GetNodes(fblock, zone, net, 0));
}
FDNPREF int FDNFUNC FrontDoorNode::GetNodes(FDNFind& fblock, unsigned short zone, unsigned short net, unsigned short start)
{
int found=0, quit=0;
long dud;
char search_key[17];
if(IsFrozen()){
fblock.finished=1;
fblock.offset=0;
fblock.Parent=this;
SignalError(29);
return(1);
}
fblock.searchtype=4;
fblock.finished=0;
fblock.zone=zone;
fblock.net=net;
while(!found && !quit && fblock.zone==zone && fblock.net==net){
strcpy(search_key, MakeKey(zone, net, start, 0, 0));
dud=GetNFDXOffset(search_key, first_n.index, fblock);
if(dud){
if(dud==0xFFFFFFFFL) quit=1; // off end of index
else{
if(fblock.Filter()) found=1;
else start=(unsigned short) (fblock.node+1);
}
}
else{
if(fblock.point) start=(unsigned short) (fblock.node+1); // Moved pass the node, look for next one
if(fblock.zone!=zone || fblock.net!=net) quit=1; // Moved pass the net
if(!quit && !fblock.point){
// We didn't find the node we were looking for, but this is the next one in the net
if(fblock.Filter()) found=1;
else start=(unsigned short) (fblock.node+1);
}
}
}
if(!found) fblock.finished=1;
return(!found);
}
/*
** GetPoints
**
** Initiates a search for the Node entries for each Point of the
** specified Node.
** Two versions exist, one which starts with the first Point of the
** the Node, and the other which starts with the specified
** Point.
**
** Returns
**
** 1 on failure, 0 on success.
*/
FDNPREF int FDNFUNC FrontDoorNode::GetPoints(FDNFind& fblock, unsigned short zone, unsigned short net, unsigned short node)
{
return(GetPoints(fblock, zone, net, node, 0));
}
FDNPREF int FDNFUNC FrontDoorNode::GetPoints(FDNFind& fblock, unsigned short zone, unsigned short net, unsigned short node, unsigned short start)
{
int found=0, quit=0;
long dud;
char search_key[17];
if(IsFrozen()){
fblock.finished=1;
fblock.offset=0;
fblock.Parent=this;
SignalError(29);
return(1);
}
fblock.searchtype=5;
fblock.finished=0;
fblock.zone=zone;
fblock.net=net;
fblock.node=node;
while(!found && !quit && fblock.zone==zone && fblock.net==net && fblock.node==node){
strcpy(search_key, MakeKey(zone, net, node, start, 0));
dud=GetNFDXOffset(search_key, first_n.index, fblock);
if(dud){
if(dud==0xFFFFFFFFL) quit=1; // off end of index
else{
if(fblock.Filter()) found=1;
else start= (unsigned short) (fblock.point+1);
}
}
else{
if(fblock.zone!=zone || fblock.net!=net || fblock.node!=node) quit=1; // Moved pass the node
if(!quit){
// We didn't find the point we were looking for, but this is the next one for this node
if(fblock.Filter()) found=1;
else start= (unsigned short) (fblock.point+1);
}
}
}
if(!found) fblock.finished=1;
return(!found);
}
/*
** ClearFDAStore
**
** This private function is used to blank the FDAStore, which the
** class uses to store and parse and store fetched information.
** This is done to ensure safe (ie. blank) returns for failed
** fetches.
*/
FDNPREF void FDNFUNC FrontDoorNode::ClearFDAStore(void)
{
NLCurOffset=0;
NodelistLine[0]=0;
FDAStore->Name[0]=FDAStore->Telephone[0]=FDAStore->Location[0]=FDAStore->User[0]=0;
FDAStore->Zone=FDAStore->NetNo=FDAStore->NodeNo=FDAStore->Point=0;
FDAStore->Capability=0;
FDAStore->MaxBaud=0;
FDAStore->Cost=0;
FDAStore->Erased=0;
FDAStoreSpeed=0;
}
/*
** GetNLine
**
** This function accepts an index database offset (composed of
** file and offset parts), retrieves the data from the file (whether
** a text nodelist, or the internal binary database) and parses it into
** FDAStore.
**
** It is often called on the first data fetch for a node entry, and
** subsequently returns already parsed data.
**
** Parameters
**
** An database offset. First byte indicates file, other are offset.
**
** Returns
**
** A pointer to the actual raw nodelist line if applicable.
**
*/
FDNPREF char FDNFUNC *FrontDoorNode::GetNLine(long offset)
{
int file;
char speed[30];
long suboffset=0;
if(IsFrozen()){
SignalError(29);
return(NULL);
}
if(offset==0L || offset==0xFFFFFFFFL){
ClearFDAStore();
return(NULL);
}
if(offset==NLCurOffset) return(NULL); // We're already on this record.
// We have to load this record, Let's see what file it's in.
switch((int) ((offset & 0xFF000000L) >> 24)){
case 0x00 : file=0; break;
case 0x10 : file=2; break;
case 0x20 : file=3; break;
case 0x01 : file=1; break;
default : file=9; break;
}
suboffset = offset & 0x00FFFFFFL;
// Index points to a record in an invalid database file
if(file==9){
SignalError(22);
ClearFDAStore();
return(NodelistLine);
}
if(Reopen[file]) DataFile[file].Open();
if(!DataFile[file].GetStatus()){
SignalError(file+18); // Unable to open specified file
ClearFDAStore();
return(NodelistLine);
}
if(file!=1){
DataFile[file].Seek(suboffset, SEEK_SET);
FCRGetS(NodelistLine, (NODELINELENGTH-1), DataFile[file]);
CSVField(NodelistLine, 0, FDAStore->Name);
CSVField(NodelistLine, 3, FDAStore->Telephone);
CSVField(NodelistLine, 1, FDAStore->Location);
CSVField(NodelistLine, 2, FDAStore->User);
CSVField(NodelistLine, 4, speed);
FDAStore->Name[30]=0;
FDAStore->Telephone[40]=0;
FDAStore->Location[40]=0;
FDAStore->User[36]=0;
FDAStoreSpeed = atol(speed);
}
else{
DataFile[file].Seek(suboffset*sizeof(FDANodeRec), SEEK_SET);
DataFile[file].Read(FDAStore, sizeof(FDANodeRec), 1, 1);
NodelistLine[0]=0;
ConvertToC(FDAStore->Name);
ConvertToC(FDAStore->Location);
ConvertToC(FDAStore->Telephone);
ConvertToC(FDAStore->User);
#ifdef FDN_WINDOWS
OemToAnsi(FDAStore->Name, FDAStore->Name);
OemToAnsi(FDAStore->Location, FDAStore->Location);
OemToAnsi(FDAStore->Telephone, FDAStore->Telephone);
OemToAnsi(FDAStore->User, FDAStore->User);
#endif
FDAStoreSpeed = GetSpeedFromFDA(FDAStore->MaxBaud);
}
NLCurOffset=offset;
if(Reopen[file]) DataFile[file].Close();
return(NodelistLine);
}
/*
** GetNLine (Find block variant)
**
** Calls the above function with the encapsulated
** offset.
*/
FDNPREF char FDNFUNC *FrontDoorNode::GetNLine(FDNFind& fblock)
{
return(GetNLine(fblock.offset));
}
/*
** GetSysop
**
** Returns the Sysop name for the relevant entry with details
** in the find block. (Already initalised by a search function).
*/
FDNPREF char FDNFUNC *FrontDoorNode::GetSysop(FDNFind& fblock)
{
if(IsFrozen()){
SignalError(29);
return(NULL);
}
GetNLine(fblock.offset);
return(FDAStore->User);
}
/*
** GetLocation
**
** Returns the Location data for the relevant entry with details
** in the find block. (Already initalised by a search function).
*/
FDNPREF char FDNFUNC *FrontDoorNode::GetLocation(FDNFind& fblock)
{
if(IsFrozen()){
SignalError(29);
return(NULL);
}
GetNLine(fblock.offset);
return(FDAStore->Location);
}
/*
** GetSysName
**
** Returns the System name for the relevant entry with details
** in the find block. (Already initalised by a search function).
*/
FDNPREF char FDNFUNC *FrontDoorNode::GetSysName(FDNFind& fblock)
{
if(IsFrozen()){
SignalError(29);
return(NULL);
}
GetNLine(fblock.offset);
return(FDAStore->Name);
}
/*
** GetSpeed
**
** Returns the Speed field for the relevant entry with details
** in the find block. (Already initalised by a search function).
*/
FDNPREF unsigned long FDNFUNC FrontDoorNode::GetSpeed(FDNFind& fblock)
{
if(IsFrozen()){
SignalError(29);
return(0);
}
GetNLine(fblock.offset);
return(FDAStoreSpeed);
}
/*
** GetSpeedFromFDA
**
** This private function is used to calculate the Speed field
** (as returned above) from the values stored in an Internal database
** entry.
**
** Parameters
**
** Takes the maxbaud field from FDNODE.FDA
*/
FDNPREF unsigned long FDNFUNC FrontDoorNode::GetSpeedFromFDA(unsigned char maxbaud)
{
switch(NLDBRevision){
case 0 : // FD 2.20 etc.
switch((int) maxbaud){
case 2 : return(300L);
case 4 : return(1200L);
case 5 : return(2400L);
case 6 : return(4800L);
case 10 : return(7200L);
case 7 : return(9600L);
case 11 : return(12000L);
case 12 : return(14400L);
case 13 : return(16800L);
case 14 : return(19200L);
case 15 : return(38400L);
case 16 : return(57600L);
case 17 : return(64000L);
default : return(0L); // Something wrong here!
}
default : // FD 2.30 and above
switch((int) maxbaud){
case 1 : return(300L);
case 2 : return(1200L);
case 3 : return(2400L);
case 4 : return(4800L);
case 5 : return(9600L);
case 6 : return(14400L);
case 7 : return(16800L);
case 8 : return(19200L);
case 9 : return(21600L);
case 10 : return(28800L);
case 11 : return(33600L);
case 12 : return(38400L);
case 13 : return(57600L);
case 14 : return(64000L);
case 15 : return(76800L);
case 16 : return(115200L);
case 17 : return(128000L);
case 18 : return(12000L);
case 19 : return(24000L);
case 20 : return(31200L);
case 21 : return(256000L);
default : return(14400L);
}
}
}
/*
** GetNumber
**
** Returns the raw untranslated number for the relevant entry with
** details in the find block. (Already initalised by a search function).
**
*/
FDNPREF char FDNFUNC *FrontDoorNode::GetNumber(FDNFind& fblock)
{
if(IsFrozen()) return(NULL);
GetNLine(fblock.offset);
return(FDAStore->Telephone);
}
/*
** GetFlags
**
** The behaviour of this function is partially dependant upon the
** whether FDN_NoFlagBuild has been #defined in FDNUSER.H
**
** In general this returns the Flags field of the relevant
** nodelist line (attached to details in the find block).
**
** If the entry is stored in FDNODE.FDA however, a NULL string
** will be returned if FDN_NoFlagBuild has been defined. Otherwise
** a flags string will be constructed and returned.
**
*/
FDNPREF char FDNFUNC *FrontDoorNode::GetFlags(FDNFind& fblock)
{
if(IsFrozen()){
SignalError(29);
return(NULL);
}
#ifdef FDN_NoFlagBuild
if(fblock.IsFDA()) return(NULL);
#endif
GetNLine(fblock.offset);
#ifndef FDN_NoFlagBuild
if(fblock.IsFDA()) return(GetFlagsFromFDA(FDAStore->Capability));
#endif
return(CSVFieldStart(NodelistLine, 5));
}
#ifdef FDN_NoFlagBuild
/*
** GetFDAFlags
**
** This function is only accessible if FDN_NoFlagBuild is defined.
** It returns the long int in the FDNODE.FDA record which defines
** the nodelist flags. If the #define is not made, a string will
** be constructed on GetFlags calls and this function is irrelevant.
*/
FDNPREF long FDNFUNC FrontDoorNode::GetFDAFlags(FDNFind& fblock)
{
if(IsFrozen()){
SignalError(29);
return(0);
}
GetNLine(fblock.offset);
return(FDAStore->Capability);
}
#else
/*
** GetFlagsFromFDA
**
** This function is only included if FDN_NoFlagBuild is not defined.
** It creates a textual flags string for a record in FDNODE.FDA which
** has only a flags long int.
*/
FDNPREF char FDNFUNC *FrontDoorNode::GetFlagsFromFDA(unsigned long flags)
{
*FlagBuild=0;
switch(NLDBRevision){
case 0 :
if(flags & OldNLflagCM) strcat(FlagBuild, "CM,");
if(flags & OldNLflagMO) strcat(FlagBuild, "MO,");
if(flags & OldNLflagLO) strcat(FlagBuild, "LO,");
if(flags & OldNLflagMNP) strcat(FlagBuild, "MNP,");
if(flags & OldNLflagV32) strcat(FlagBuild, "V32,");
if(flags & OldNLflagV32B) strcat(FlagBuild, "V32B,");
if(flags & OldNLflagV42) strcat(FlagBuild, "V42,");
if(flags & OldNLflagV42B) strcat(FlagBuild, "V42B,");
if(flags & OldNLflagV33) strcat(FlagBuild, "V33,");
if(flags & OldNLflagV34) strcat(FlagBuild, "V34,");
if(flags & OldNLflagZYX) strcat(FlagBuild, "ZYX,");
if(flags & OldNLflagHST) strcat(FlagBuild, "HST,");
if(flags & OldNLflagH96) strcat(FlagBuild, "H96,");
if(flags & OldNLflagHST16) strcat(FlagBuild, "H16,");
if(flags & OldNLflagFAX) strcat(FlagBuild, "FAX,");
// HST14?
if(flags & OldNLflagXA) strcat(FlagBuild, "XA,");
if(flags & OldNLflagXB) strcat(FlagBuild, "XB,");
if(flags & OldNLflagXC) strcat(FlagBuild, "XC,");
if(flags & OldNLflagXP) strcat(FlagBuild, "XP,");
if(flags & OldNLflagXR) strcat(FlagBuild, "XR,");
if(flags & OldNLflagXW) strcat(FlagBuild, "XW,");
if(flags & OldNLflagXX) strcat(FlagBuild, "XX,");
if(flags & OldNLflagUISDNA) strcat(FlagBuild, "UISDNA,");
if(flags & OldNLflagUISDNB) strcat(FlagBuild, "UISDNB,");
if(flags & OldNLflagUISDNC) strcat(FlagBuild, "UISDNC,");
if(flags & OldNLflagPEP) strcat(FlagBuild, "PEP,");
if(flags & OldNLflagMAX) strcat(FlagBuild, "MAX,");
break;
default:
if(flags & NLflagCM) strcat(FlagBuild, "CM,");
if(flags & NLflagMO) strcat(FlagBuild, "MO,");
if(flags & NLflagLO) strcat(FlagBuild, "LO,");
if(flags & NLflagMN) strcat(FlagBuild, "MN,");
if(flags & NLflagV32) strcat(FlagBuild, "V32,");
if(flags & NLflagV32B) strcat(FlagBuild, "V32B,");
if(flags & NLflagV42) strcat(FlagBuild, "V42,");
if(flags & NLflagV42B) strcat(FlagBuild, "V42B,");
if(flags & NLflagV34) strcat(FlagBuild, "V34,");
if(flags & NLflagZYX) strcat(FlagBuild, "ZYX,");
if(flags & NLflagHST) strcat(FlagBuild, "HST,");
if(flags & NLflagFAX) strcat(FlagBuild, "FAX,");
if(flags & NLflagX2C) strcat(FlagBuild, "X2C,");
if(flags & NLflagX2S) strcat(FlagBuild, "X2S,");
if(flags & NLflagXA) strcat(FlagBuild, "XA,");
if(flags & NLflagXB) strcat(FlagBuild, "XB,");
if(flags & NLflagXC) strcat(FlagBuild, "XC,");
if(flags & NLflagXP) strcat(FlagBuild, "XP,");
if(flags & NLflagXR) strcat(FlagBuild, "XR,");
if(flags & NLflagXW) strcat(FlagBuild, "XW,");
if(flags & NLflagXX) strcat(FlagBuild, "XX,");
if(flags & NLflagX75) strcat(FlagBuild, "X75,");
if(flags & NLflagV110L) strcat(FlagBuild, "V110L,");
if(flags & NLflagV110H) strcat(FlagBuild, "V110H,");
if(flags & NLflagV120L) strcat(FlagBuild, "V120L,");
if(flags & NLflagV120H) strcat(FlagBuild, "V120H,");
break;
}
// Strip trailing comma
if(*FlagBuild) FlagBuild[strlen(FlagBuild)-1]=0;
return(FlagBuild);
}
#endif
/*
** GetPhoneData
**
** This function is used to retrive a translated phone number and the
** cost to dial a system.
**
** Parameters
**
** fblock The FDNFind for the specified system.
** buffer For storing the translated number. NULL indicates no
** translation will occur.
**
** Returns
**
** The cost to dial the system.
*/
FDNPREF unsigned short FDNFUNC FrontDoorNode::GetPhoneData(FDNFind & fblock, char * buffer)
{
char * test = NULL;
unsigned short TempCost=0;
int Error = 0;
if(IsFrozen()) Error = 29;
if((fblock.UnixStamp < UnixStamp) || (fblock.Parent !=this)) Error = 13;
if(Error){
if(buffer) *buffer = 0;
SignalError(Error);
return(0xFFFF);
}
// If no CountryCode, Dial XLT impossible, we can continue though
if(!NLInfo.CountryCode){
if(buffer) *buffer = 0;
SignalError(15);
}
else test = buffer;
TempCost = GetPFDXData(fblock.GetNumber(), test, first_p.index);
// Should we override the cost?
if(NLDBRevision && fblock.IsFDA() && FDAStore->Cost!=0xFFFE) return(FDAStore->Cost);
return(TempCost);
}
/****************************************************************************/
/* I M P L E M E N T A T I O N F U N C T I O N S */
/****************************************************************************/
// FrontDoorNode()
// This is a constructor to keep the class safe if no path is passed to it.
// It initialises the class in a frozen state with an unknown path.
FDNPREF FrontDoorNode::FrontDoorNode()
{
Constructor("", "", FDNodeCreateFrozen, 0);
}
// FrontDoorNode(directory name)
// This is the default constructor. It initialises the class ready for use
// NO checks are performed on the directory name, you must ensure it has a
// trailing backslash and that the directory is valid. This constructor
// assumes you want to keep ALL the files open for the lifetime of the class.
// This is fast, but uses many file handles.
FDNPREF FrontDoorNode::FrontDoorNode(const char FDNDATA *pathname, const char FDNDATA *path2, unsigned short NewTask)
{
Constructor(pathname, path2, 0, NewTask);
}
// FrontDoorNode(directory name, flags)
// An overloaded constructor, this allows you to specify exactly what index
// and nodelist files should be held open for the duration of the class
// existence. Specify the flags given in FDNODE.H to signify that a file
// should be opened and closed after each use.
FDNPREF FrontDoorNode::FrontDoorNode(const char FDNDATA *pathname, const char *path2, unsigned short setflags, unsigned short NewTask)
{
Constructor(pathname, path2, setflags, NewTask);
}
// ~FrontDoorNode()
// The destructor ensures that all active file handles are closed.
FDNPREF FrontDoorNode::~FrontDoorNode()
{
Freeze(); // Close handles etc.
delete FDAStore;
if(!(Flags & FDNodeNoCacheP)){
delete proot;
}
if(!(Flags & FDNodeNoCacheU)){
delete uroot;
}
if(!(Flags & FDNodeNoCacheN)){
delete nroot; // Remove cache allocation