-
Notifications
You must be signed in to change notification settings - Fork 9
/
hadr.cpp
1308 lines (1245 loc) · 38.1 KB
/
hadr.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
/***************************************************************
BayCom(R) Packet-Radio fuer IBM PC
OpenBCM-Mailbox
---------------------------
Verwaltung von Box-Adressen
---------------------------
Copyright (C) Florian Radlherr
Taubenbergstr. 32
83627 Warngau
Alle Rechte vorbehalten / All Rights Reserved
***************************************************************/
//19980126 OE3DZW head -> long, output of p -s
//19980202 OE3DZW removed trailing \n in adr of hadr-file
//19980205 OE3DZW removed above fix, added \r fix for lastheader
//19980309 OE3DZW added \r,\n fix for headerline
//19980428 OE3DZW cutting off "ro" from ".euro"
//19980614 hrx removed structure definitions hadr_t and hadr_old_t,
// moved to mail.h.
//19990110 OE3DZW removed "newformat" from code, was commented out anyway
//19990214 OE3DZW added dummy function for future extensions
//19990817 JJ removed static near (needed in afwd)
//20000105 OE3DZW added fwd-check
//20000107 OE3DZW replaced -e by -n in "path -sfn"
//20000118 OE3DZW text "no fwd" -> "here", sounds better
//20021212 DF3VI show_hadr: nur noch Statistik von vorhandenen Fwd-Partnern
// browse_hadr: "p -sfn" fix mit dummy-user 3DA
#include "baycom.h"
/*---------------------------------------------------------------------------*/
static handle fa = EOF;
static handle fah = EOF;
static int is_null = 0;
/*---------------------------------------------------------------------------*/
long hadr_len (int max)
//*************************************************************************
//
//
//
//*************************************************************************
{
if (max)
return 65535L;
else
return filesize(HADRNAME) / sizeof(hadr_t);
}
/*---------------------------------------------------------------------------*/
//#ifdef _AUTOFWD
void
//#else
//static void near
//#endif
uclose (void)
//*************************************************************************
//
//
//
//*************************************************************************
{
if (fa != EOF)
{
s_close(fa);
fa = EOF;
}
if (fah != EOF)
{
s_close(fah);
fah = EOF;
}
}
/*---------------------------------------------------------------------------*/
void hadrfile_newformat (void)
//*************************************************************************
//
//
//
//*************************************************************************
{
if (file_isreg(HADRNAME) < file_isreg(HADROLDNAME))
{
FILE *fi = s_fopen(HADROLDNAME, "srb");
FILE *fo = s_fopen(HADRNAME, "swb");
hadrold_t *hi = (hadrold_t *) t_malloc(sizeof(hadrold_t), "haol");
hadr_t *ho = (hadr_t*) t_malloc(sizeof(hadr_t), "hadr");
trace(replog, "hadr", "converting format");
wdelay(334);
if (fi && fo)
{
while (fread(hi, sizeof(hadrold_t), 1, fi))
{
memset(ho, 0, sizeof(hadr_t));
ho->bulletins = hi->bulletins;
ho->usermails = hi->usermails;
memcpy(ho->delay, hi->delay, sizeof(hi->delay));
memcpy(ho->lastupdate, hi->lastupdate, sizeof(hi->lastupdate));
ho->lasthtime = hi->lasthtime;
memcpy(ho->rel_mails, hi->rel_mails, sizeof(hi->rel_mails));
memcpy(ho->hops, hi->hops, sizeof(hi->hops));
ho->nextsamehash = hi->nextsamehash;
memcpy(ho->adr, hi->adr, sizeof(hi->adr));
memcpy(ho->adjacent, hi->adjacent, sizeof(hi->adjacent));
memcpy(ho->lastheader, hi->lastheader, sizeof(hi->lastheader));
memcpy(ho->lastbid, hi->lastbid, sizeof(hi->lastbid));
memcpy(ho->lastboard, hi->lastboard, sizeof(hi->lastboard));
memcpy(ho->lastuser, hi->lastuser, sizeof(hi->lastuser));
fwrite(ho, sizeof(hadr_t), 1, fo);
}
}
if (fi) s_fclose(fi);
if (fo) s_fclose(fo);
t_free(hi);
t_free(ho);
}
}
/*---------------------------------------------------------------------------*/
static void near newhadrfile (void)
//*************************************************************************
//
//
//
//*************************************************************************
{
hadr_t *ha = (hadr_t*) t_malloc(sizeof(hadr_t), "hadr");
xunlink(HADRHASHNAME);
fa = s_open(HADRNAME, "sw+b");
if (fa == EOF)
trace(tr_abbruch, "hadr_tryopen", "can't create");
memset(ha, 0, sizeof(hadr_t));
_write(fa, ha, sizeof(hadr_t));
s_close(fa);
t_free(ha);
}
/*---------------------------------------------------------------------------*/
//#ifdef _AUTOFWD
void
//#else
//static void near
//#endif
hadr_tryopen (void)
//*************************************************************************
//
//
//
//*************************************************************************
{
static int first = 1;
if (sizeof(hadr_t) != 1024 || is_null)
trace(tr_abbruch, "hadr_t", "size %d", sizeof(hadr_t));
if (fa == EOF)
{
if (! file_isreg(HADRNAME) || ! filesize(HADRNAME))
{
if (! first) return;
xunlink(HADRHASHNAME);
newhadrfile();
fa = s_open(HADRNAME, "sr+b");
}
else
{
fa = s_open(HADRNAME, "sr+b");
if (fa == EOF) return;
}
}
if (fah == EOF)
fah = s_open(HADRHASHNAME, "sr+b");
if (fah == EOF)
{
if (first)
fah = s_open(HADRHASHNAME, "sw+b");
else return;
}
if (first) hashinit(fah, HASH16);
first = 0;
}
/*---------------------------------------------------------------------------*/
static unsigned near newhadr (hadr_t *hu, handle fau, handle fahu)
//*************************************************************************
//
// legt einen hadr_t im HADR-File ab
//
// Achtung: es muss an der Stelle sichergestellt sein, dass nicht
// schon ein hadr_t mit gleichem Namen existiert!
//
//*************************************************************************
{
lastfunc("newhadr");
short unsigned hsh = strcrc(atcall(hu->adr));
short unsigned idx = 0;
lseek(fahu, (long) hsh * 2L, SEEK_SET); // Eintrag im Hashfile
if (! _read(fahu, &idx, sizeof(short unsigned)))
return 0;
hu->nextsamehash = idx; // verketten
lseek(fau, 0L, SEEK_END);
lseek(fahu, (long) hsh * 2L, SEEK_SET);
idx = (short unsigned) (filelength(fau) / sizeof(hadr_t));
if (! _write(fahu, &idx, sizeof(short unsigned)))
return 0; // zurueckschreiben
if (! _write(fau, hu, sizeof(hadr_t)))
return 0; // User hinausschreiben
return idx;
}
/*---------------------------------------------------------------------------*/
static int near hdrin (char *hadrcall, handle fau, handle fahu)
//*************************************************************************
//
//
//*************************************************************************
{
lastfunc("hdrin");
short unsigned idx;
hadr_t *hu = (hadr_t *) t_malloc(sizeof(hadr_t), "hadr");
char atc[10];
strcpy(atc, atcall(hadrcall));
short unsigned hsh = strcrc(atc);
lseek(fahu, (long) hsh * 2L, SEEK_SET);
_read(fahu, &idx, sizeof(short unsigned));
if (idx)
{
int num = 0;
while (idx)
{
lseek(fau, (long) idx * sizeof(hadr_t), SEEK_SET);
if (! _read(fau, hu, sizeof(hadr_t)))
{
t_free(hu);
return 0;
}
if ((num++) > 200)
{
t_free(hu);
return 0;
}
if (! strcmp(atc, atcall(hu->adr)))
{
t_free(hu);
return idx;
}
idx = hu->nextsamehash;
}
}
t_free(hu);
return 0;
}
/*---------------------------------------------------------------------------*/
//#ifdef _AUTOFWD
int
//#else
//static int near
//#endif
loadhadr (char *hadrcall, hadr_t *hu, int anlegen)
//*************************************************************************
//
//
//*************************************************************************
{
short unsigned idx;
unsigned retwert = 0;
char atc[10];
strcpy(atc, atcall(hadrcall));
short unsigned hsh = strcrc(atc);
if (mbhadrok(hadrcall) == 1)
{
lseek(fah, (long) hsh * 2L, SEEK_SET);
_read(fah, &idx, sizeof(short unsigned));
if (idx)
{
int num = 0;
while (idx)
{
lseek(fa, (long) idx * sizeof(hadr_t), SEEK_SET);
if (! _read(fa, hu, sizeof(hadr_t)))
goto ende;
if ((num++) > 500)
goto ende;
if (! strcmp(atc, atcall(hu->adr)))
{
retwert = idx;
goto ende;
}
idx = hu->nextsamehash;
}
}
if (anlegen)
{
memset(hu, 0, sizeof(hadr_t));
strcpy(hu->adr, hadrcall);
retwert = newhadr(hu, fa, fah);
}
}
ende:
return retwert;
}
/*---------------------------------------------------------------------------*/
void reorg_hadr (void)
//*************************************************************************
//
//
//*************************************************************************
{
handle ualt, uneu, uhneu;
hadr_t *ux = (hadr_t *) t_malloc(sizeof(hadr_t), "hadr");
unsigned pos = 0, errors = 0;
time_t ti = ad_time(); // current UTC time
if (m.hadrstore)
{
trace(replog, "reorg", "hadr");
xunlink(HTMP);
xunlink(HHTMP);
ualt = s_open(HADRNAME, "lrb");
if (hd_space(filelength(ualt)))
{
s_close(ualt);
trace(serious, "reorghadr", "disk full");
t_free(ux);
return;
}
uneu = s_open(HTMP, "lw+b");
uhneu = s_open(HHTMP, "lw+b");
if (ualt != EOF && uneu != EOF && uhneu != EOF)
{
hashinit(uhneu, HASH16);
_read(ualt, ux, sizeof(hadr_t));
_write(uneu, ux, sizeof(hadr_t));
while (1)
{
waitfor(e_ticsfull);
if (! _read(ualt, ux, sizeof(hadr_t))) break;
subst1(ux->lastheader, CR, 0);
subst1(ux->lastheader, LF, 0);
if (! *ux->adr) continue;
if ( ux->lasthtime < ti - (DAY * 180) //180d
&& ux->lastwprcvd < ti - (DAY * 720) ) //2y if WP-received
continue;
if ( ux->adr[HADRESSLEN] || mbhadrok(ux->adr) != 1
|| hdrin(ux->adr, uneu, uhneu))
{
errors++;
continue;
}
if (strlen(ux->lastheader) < 10)
*ux->lastheader = 0;
newhadr(ux, uneu, uhneu);
pos++;
}
trace(replog, "reorghadr", "%u hadrs, %u errors", pos, errors);
s_close(ualt);
s_close(uneu);
s_close(uhneu);
xrename(HTMP, HADRNAME);
xrename(HHTMP, HADRHASHNAME);
}
}
t_free(ux);
}
/*---------------------------------------------------------------------------*/
int update_hadr (char *headerline, int hops, int uplink)
//*************************************************************************
//
//
// used globals
// b->bid (if uplink != 0)
// b->boardname (if uplink != 0)
// b->usermail (if uplink != 0)
// b->frombox (not if hops = -1)
//
//*************************************************************************
{
lastfunc("update_hadr");
hadr_t *ha = (hadr_t*) t_malloc(sizeof(hadr_t), "hadr");
int i;
char *hpos;
char *ptr;
char ptr2[HEADERLEN];
unsigned pos; // position within hadr-file
char hadr[HADRESSLEN+1]; // received H-Address
subst1(headerline, CR, 0);
subst1(headerline, LF, 0);
time_t htime = getheadertime(headerline); // received time
time_t mtime = ad_time(); // current UTC time
time_t hdelay = mtime - htime; // delay of delivery
int adj = (-1); // index of adjacent box call
// if the mail is much newer than current time, the clock of the uplink-box
// seems to be adjusted incorrectly. Add a time for always positive delay
hdelay += 7200;
hpos = getheaderadress(headerline);
if (hpos && m.hadrstore)
strcpy(hadr, hpos);
else
{
t_free(ha);
return 0;
}
waitfor(e_ticsfull);
if (hadr)
{
strupr(hadr);
hadr_tryopen();
if (fa == EOF || fah == EOF)
{
uclose();
t_free(ha);
return 0;
}
pos = loadhadr(hadr, ha, 1);
if (pos)
{
if (uplink)
{
if (b->usermail)
{
ha->usermails++;
strcpy(ha->lastuser, b->boardname);
}
else
{
ha->bulletins++;
strcpy(ha->lastboard, b->boardname);
}
if (*b->bid && strstr(b->bid, atcall(ha->adr)))
strcpy(ha->lastbid, b->bid);
}
if (htime > mtime)
htime = mtime;
char adrname[CALLEN + 1];
strcpy(adrname, atcall(hadr));
if (hops >= 0 && ha->lasthtime <= htime)
// only accept headers in ascending order
{
// look for an appropriate entry in list of adjacent box calls
strcpy(ha->adr, hadr);
for (i = 0; i < ADJNUM; i++)
{
if (! strcmp(b->frombox, ha->adjacent[i]))
{
adj = i; // found the current active call
break;
}
}
// if no such entry exists, look for an empty location in the list
// of the adjacent box calls
if (adj < 0)
{
for (i = 0; i < ADJNUM; i++)
{
if (! ha->adjacent[i][0])
{
strcpy(ha->adjacent[i], b->frombox);
adj = i;
break;
}
}
}
// if no empty position is left, remove the oldest position which
// is reached through more hops or with a longer delivery time
if (adj < 0)
{
time_t last = mtime;
for (i = 0; i < ADJNUM; i++)
{ // search for the oldest entry with one of following criteria TRUE
// - the hop-count is greater than the current one
// - the delay timer is longer than the current one
// - the entry has not been updated for more than 30 days
if ( ha->lastupdate[i] < last
&& (hops < ha->hops[i] || hdelay < ha->delay[i])
|| ha->lastupdate[i] < (mtime - MAXAGE) )
{
last = ha->lastupdate[i];
adj = i;
}
}
if (adj >= 0)
{
strcpy(ha->adjacent[adj], b->frombox); // change call
ha->rel_mails[adj] = 0; // call has changed, count new
}
else
{
uclose();
t_free(ha);
return 0; // direction could not be updated, ignore the mail
}
}
ha->rel_mails[adj]++; // increase normalised mail counter
if (ha->rel_mails[adj] > 50) // normalise the counters to values < 50
{
for (i = 0; i < ADJNUM; i++)
ha->rel_mails[i] >>= 1; // take the half
}
ha->delay[adj] = hdelay;
ha->lastupdate[adj] = mtime;
ha->hops[adj] = hops;
ha->lasthtime = htime;
// now search for the rest of the "received"-header, excluding
// date/time and h-address. Both are stored in other members of ha.
hpos = strstr(headerline, hadr);
if (hpos)
{
hpos += strlen(hadr);
while (*hpos == ' ') hpos++;
// jetzt noch evtl BID und LT herausfiltern (DH8YMB)
ptr = strstr(hpos, "$:");
if (ptr)
{
strncpy(ptr2, hpos, (strlen(hpos) - strlen(ptr)));
ptr2[(strlen(hpos) - strlen(ptr))]= 0;
strcpy(hpos, ptr2);
}
ptr = strstr(hpos, "LT:");
if (ptr)
{
strncpy(ptr2, hpos, (strlen(hpos) - strlen(ptr)));
ptr2[(strlen(hpos) - strlen(ptr))]= 0;
strcpy(hpos, ptr2);
}
if (strlen(hpos) > 10)
{
if (uplink || ! strstr(ha->lastheader, BCMLOGO))
{
strncpy(ha->lastheader, hpos, HEADERLEN);
ha->lastheader[HEADERLEN] = 0;
}
}
}
// trace(report, "update_hadr", "lastheader: %s", ha->lastheader);
}
if (! strcmp(adrname, m.boxname))
{ //dummy for local bbs
// folgender Dummy-Aufruf von makeheader verhindert Speicherueberlauf
// von ha->lastheader[61] bei zu langem m.boxheader[60] (db1ras)
makeheader(1);
sprintf(ha->lastheader, "[%s] "BCMLOGO VNUMMER, m.boxheader);
ha->lasthtime = htime;
ha->lastwprcvd = htime;
strncpy(ha->sysopcall, m.sysopcall, sizeof(ha->sysopcall) - 1);
ha->sysopcall[sizeof(ha->sysopcall) - 1] = 0;
strcpy(ha->protocol, "AX25");
strncpy(ha->hwaddress, m.mycall[0], sizeof(ha->hwaddress) - 1);
ha->hwaddress[sizeof(ha->hwaddress) - 1] = 0;
ha->bversion = BVERSION;
strcpy(ha->bstatus, BSTATUS);
}
lseek(fa, (long) pos * sizeof(hadr_t), SEEK_SET);
_write(fa, ha, sizeof(hadr_t));
}
}
uclose();
t_free(ha);
return 1;
}
/*---------------------------------------------------------------------------*/
void browse_hadr (char *search)
//*************************************************************************
//
//
//*************************************************************************
{
lastfunc("browse_hadr");
hadr_t *ha = (hadr_t*) t_malloc(sizeof(hadr_t), "hadr");
time_t upd;
int i, ok, f_mode = 0;
unsigned count = 0, found = 0;
long head = 0;
long f_known = 0;
long f_active = 0;
#ifdef _AUTOFWD
long f_auto = 0;
#endif
long f_unknown = 0;
long f_nofwd = 0;
search += blkill(search);
strupr(search);
if (m.hadrstore)
{
FILE *f = s_fopen(HADRNAME, "lrb");
if (f)
{
setvbuf(f, NULL, _IOFBF, 4096); // buffer for increasing performance
fseek(f, sizeof(hadr_t), SEEK_SET);
while (fread(ha, sizeof(hadr_t), 1, f))
{
if (! *ha->adr) continue;
count++;
ok = 0;
if (*search)
{
if (! (b->optplus & o_p))
ok += (stristr(ha->lastheader, search) != NULL);
if (! (b->optplus & o_h))
ok += (strstr(ha->adr, search) != NULL);
if (b->optplus & o_r) ok++;
}
else
ok++;
if (ok)
{
found++;
upd = 0;
for (i = 0; i < ADJNUM; i++)
{
if (ha->adjacent[i][0] && ha->lastupdate[i] > upd)
upd = ha->lastupdate[i];
}
if (b->optplus & o_f || b->optplus & o_r)
{
safe_strcpy(b->at, ha->adr);
f_mode = weiterleiten(0, "3DA"); //dummy user Swaziland benutzen
// *search = 0;
// f_mode = weiterleiten(0, search);
switch (f_mode) //update statistics
{
case bekannt: f_known++; break;
case active_bekannt: f_active++; break;
#ifdef _AUTOFWD
case auto_bekannt: f_auto++; break;
#endif
case unbekannt: f_unknown++; break;
case bleibtliegen: f_nofwd++; break;
}
}
if (b->optplus & o_r && (f_mode != active_bekannt))
found--;
else
{
//output result, on -nf only fwd-errors
//on -c do not output anything (count)
if ( (! (b->optplus & o_n)
|| (b->optplus & o_f && f_mode == unbekannt)
)
&& ! (b->optplus & o_c) )
{
if (! (head++))
{
if (b->optplus & o_r)
putf(" Time Address Forward Qlty Hops\n");
else
{
putf("Mails Since Address");
if (b->optplus & o_f) //check forwardpath (-f)
putf(" Forward\n");
else
if (b->optplus & o_h)
putf(" Header\n");
else
putf("/Header\n");
}
}
if (b->optplus & o_r)
{
if (*search)
{
if (strstr(b->destboxlist, search) != NULL)
putf("%7s: %-39s %-6.6s %5ld %3d\n",
zeitspanne((ad_time() - ha->r_time_rx), zs_seconds),
ha->adr, b->destboxlist, ha->r_qual_rx, ha->r_hops);
else
found--;
}
else
putf("%7s: %-39s %-6.6s %5ld %3d\n",
zeitspanne((ad_time() - ha->r_time_rx), zs_seconds),
ha->adr, b->destboxlist, ha->r_qual_rx, ha->r_hops);
}
else
{
if (b->optplus & o_h)
{
char cut_adr[40];
cut_adr[0] = 0;
sprintf(cut_adr, "%s", ha->adr);
cut_adr[22] = 0;
putf("%5ld%5s: %-22s", ha->usermails + ha->bulletins,
zeitspanne(ad_time() - upd, zs_seconds), cut_adr);
}
else
putf("%5ld%5s: %-39s", ha->usermails + ha->bulletins,
zeitspanne(ad_time() - upd, zs_seconds), ha->adr);
if (b->optplus & o_f) //output fwd-result
switch (f_mode)
{
case bekannt: putf("%s\n", b->destboxlist); break;
case active_bekannt: putf("%s (Active Routing)\n", b->destboxlist);
break;
#ifdef _AUTOFWD
case auto_bekannt: putf("%s(AutoFwd)\n", b->destboxlist);
break;
#endif
case unbekannt: putf("-unknown-\n"); break;
case bleibtliegen: putf("-here-\n"); break;
default: putf("???\n"); //this should never happen
}
else
if (b->optplus & o_h)
putf(" %1.44s\n", ha->lastheader);
else
putf("\n %1.44s\n", ha->lastheader);
}
}
}
}
waitfor(e_ticsfull);
if (testabbruch()) break;
}
//output summary
if ((b->optplus & o_f) && found)
#ifndef _AUTOFWD
putf("%ld active-routing, %ld fwd, %ld unknown, %ld nofwd, ",
f_active, f_known, f_unknown, f_nofwd);
#else
putf("%ld active-routing, %ld fwd, %ld autofwd, %ld unknown, %ld nofwd, ",
f_active, f_known, f_auto, f_unknown, f_nofwd);
#endif
putf("\n%u searched, %u found.\n", count, found);
s_fclose(f);
}
}
t_free(ha);
}
/*---------------------------------------------------------------------------*/
void showpath (char *adr, int alles)
//*************************************************************************
//
// Zeigt die Nachbarbox(en) zur angegebenen H-Adresse an
//
//*************************************************************************
{
lastfunc("showpath");
int fwdmode;
if (alles)
{
scanoptions(adr);
if (b->optplus & o_s)
{
browse_hadr(adr);
return;
}
if (b->sysop && (b->optplus & o_e))
{
edit_hadr(b->optplus, adr);
return;
}
}
if (*adr == '@') adr++;
while (*adr == ' ') adr++;
if (*adr)
{
strupr(adr);
strncpy(b->at, adr, HADRESSLEN);
b->at[HADRESSLEN] = 0;
if (strchr(b->at, ' '))
*strchr(b->at, ' ') = 0;
fwdmode = weiterleiten(0, b->at);
if (alles || fwdmode == unbekannt)
putf(ms(m_address), b->at);
switch (fwdmode)
{
case unbekannt: putf(ms(m_fwdunknown)); break;
case bekannt:
case active_bekannt:
#ifdef _AUTOFWD
case auto_bekannt:
#endif
{
if (! alles) break;
putf(ms(m_isknown));
if (strlen(b->destboxlist) > 37) putf(":\n");
putf("%s", b->destboxlist);
if (fwdmode == active_bekannt) putf(" (Active Routing)");
#ifdef _AUTOFWD
if (fwdmode == auto_bekannt) putf(" (AutoFwd)");
#endif
putv(LF);
}
break;
case bleibtliegen:
if (! alles) break;
putf(ms(m_noforwarding));
break;
}
if (alles == 2 || (alles && (b->optplus & o_a)))
show_hadr(adr);
}
else putf(ms(m_syntaxpath));
}
/*---------------------------------------------------------------------------*/
void edit_hadr (bitfeld opt, char *line)
//*************************************************************************
//
// Edit hadress entry
// Only ONE of the following commands can be given at a time:
//
// Syntax:
// p -ea <h-address> sets a new address
// (entry will be created if it does not exist)
// p -ed <call> deletes an entry
// p -eh <call> <header> sets a new R: header line
// p -et <call> <date> sets header received date to <date>
// p -ew <call> deletes active routing info
//
//*************************************************************************
{
hadr_t *ha = (hadr_t*) t_malloc(sizeof(hadr_t), "hadr");
unsigned pos;
char call[HADRESSLEN+1];
time_t mtime = ad_time();
line = nexttoken(line, call, HADRESSLEN);
strupr(call);
if (m.hadrstore)
{
strupr(call);
hadr_tryopen();
pos = loadhadr(call, ha, 0);
if (pos)
{
if (opt & o_d)
{
*ha->adr = 0;
*ha->lastheader = 0;
}
else if (opt & o_w)
{
ha->r_time_rx = 0;
ha->r_time_tx = 0;
strcpy(ha->r_from, call);
ha->bversion = 10;
ha->r_hops = 1;
ha->r_qual_rx = 0;
}
else if (opt & o_h)
{
strncpy(ha->lastheader, line, HEADERLEN);
ha->lastheader[HEADERLEN] = 0;
ha->lasthtime = mtime;
}
else if (opt & o_a)
{
strncpy(ha->adr, call, HADRESSLEN);
ha->adr[HADRESSLEN] = 0;
ha->lasthtime = mtime;
}
else if (opt & o_t)
ha->lasthtime = parse_time(line);
lseek(fa, (long) pos * sizeof(hadr_t), SEEK_SET);
_write(fa, ha, sizeof(hadr_t));
}
else if (opt & o_a)
{
loadhadr(call, ha, 1);
ha->lasthtime = mtime;
}
else
putf(ms(m_notfound), call);
uclose();
show_hadr(call);
}
t_free(ha);
}
/*---------------------------------------------------------------------------*/
int wpupdate_hadr (wpdata_t *wp)
//*************************************************************************
//
// Store WP data received in store and forward
//
//*************************************************************************
{
lastfunc("wpupdate_hadr");
hadr_t *ha = (hadr_t*) t_malloc(sizeof(hadr_t), "hadr");
unsigned pos;
int isnew = 0;
time_t ti = ad_time();
if (m.hadrstore)
{
strupr(wp->hadr);
hadr_tryopen();
pos = loadhadr(wp->hadr, ha, 0);
if (pos)
{
if (ha->lastwprcvd < wp->mybbstime)
{
ha->lastwprcvd = wp->mybbstime;
if (*wp->hadr) strcpy(ha->adr, wp->hadr);
strupr(wp->sysopcall);
if (*wp->sysopcall)
{
if (strcmp(ha->sysopcall, wp->sysopcall))
isnew++;
strcpy(ha->sysopcall, wp->sysopcall);
}
if (*wp->protocol && *wp->hwaddress)
{
if ( stricmp(ha->protocol, wp->protocol)
|| stricmp(ha->hwaddress, wp->hwaddress))
isnew++;
strcpy(ha->protocol, wp->protocol);
strcpy(ha->hwaddress, wp->hwaddress);
}
if (*wp->bstatus) strcpy(ha->bstatus, wp->bstatus);
ha->bversion = wp->bversion;
if (isnew || ha->lastwpsend < (ti - MAXAGE))
{
ha->lastwpsend = ti;
isnew++;
}
if (wp->hops > 50) isnew = 0;
lseek(fa, (long) pos * sizeof(hadr_t), SEEK_SET);
_write(fa, ha, sizeof(hadr_t));
}
}
uclose();
}
t_free(ha);
return isnew;
}
/*---------------------------------------------------------------------------*/
time_t find_hadr (char *call)
//*************************************************************************
//
// checks if call is found in hadr-database
// returns 0 .. not found
// else .. time of last update
//
//*************************************************************************
{
hadr_t *ha = (hadr_t*) t_malloc(sizeof(hadr_t), "hadr");
unsigned pos;
time_t stamp = 0;
if (m.hadrstore)
{
strupr(call);
hadr_tryopen();
pos = loadhadr(call, ha, 0);
if (pos)
{
stamp = ha->lastwprcvd;
if (! stamp) stamp = ha->lasthtime;
}
uclose();
}
t_free(ha);
return stamp;
}
/*---------------------------------------------------------------------------*/
int rupdate_hadr(wpdata_t *wp)
//*************************************************************************
//
// saves received/calculated WPROT routing infos in hadr-database
// falls Bedingungen erfuellt sind, Returnwert = 1, sonst 0
//
//*************************************************************************
{