-
Notifications
You must be signed in to change notification settings - Fork 9
/
dir.cpp
1401 lines (1335 loc) · 38.7 KB
/
dir.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
-----------------------------------------
Ausgaben und Zubehoer zum DIR/LIST-Befehl
-----------------------------------------
Copyright (C) Florian Radlherr
Taubenbergstr. 32
83627 Warngau
Alle Rechte vorbehalten / All Rights Reserved
***************************************************************/
//19980118 OE3DZW removed sec from dir/list - timestr
//19980218 OE3DZW renamed flag5 to msgty
//19980308 OE3DZW dir-option "-r" -> only held msg
//19980312 OE3DZW above option replaced by "-p", above did not work correctly
//19980407 OE3DZW bytes korrekt
//19980423 OE3DZW new "holdusers" shows all usermails held
//19980430 OE3DZW fixed holdusers, only showed results on first call
//19980526 OE3DZW added debug-logoutput, to find "d b" bug
//19980824 CZ4WAY added headerfile to mailbeacon
// CZ4WAY (CB)
// = Jan Wasserbauer <[email protected]>
//19980831 OE3DZW added usermail=0 to dir news etc. (else wrong options
// could eventually be read
//19980906 DG0CDC added macro support to headerfile of mailbeacon
//19980903 OE3DZW fixed s_fclose not open bug (related to beacon update)
//19980914 OE3DZW added header for dir/list
//19980915 OE3DZW fixed header - was missing for usermails
// fixed search algorithm - will find correct boards
//19980924 OE3DZW d n shows correct boardinfo
//19980924 OE3DZW added oldestbeacon
//19980924 OE3DZW shows only local mail in mailbeacon
//19980925 OE3DZW fixed mailbeacon, will only show mail to local users
// not logged in since mail received
//19981001 OE3DZW becon could become longer 256 Bytes
//19990824 DH3MB Changed format of "DIR BOARDS *"
//19991212 DF3VI added DIR DEST in mbdir()
//19991221 DF3VI removed bereich for o_g in do_dir()
//20000101 dk2ui dir news is only updated at logout
//20000116 DK2UI (dzw) added ui-options
//20000622 DK2UI list for HTTP changed to boardname
//20000713 DK2UI added regex_match to dir and list
//20001005 DK2UI dir headline option o_w and LF corrected
//20010120 DK2UI option dir reject from DF3VI included
//20010620 DF3VI putdirkopf() options corrected
//20010719 DF3VI new options for dir
//20040529 DH8YMB renamed msgty to conttype
//20111005 OE5HPM added support to put mailbeacon into file
#include "baycom.h"
/*---------------------------------------------------------------------------*/
#define BEACON_LEN 3000
/*---------------------------------------------------------------------------*/
int finddir (char *path, int one_letter_boards)
//***********************************************************************
//
// Sucht einen Bulletin- oder Benutzernamen
//
// Rueckgabewerte:
// 0 Board nicht gefunden
// -1 Usermail, keine Nachricht vorhanden
// -2 Usermail, Nachricht vorhanden
//
//***********************************************************************
{
int ret = (-2);
unsigned j;
char cmp[DIRLEN+1];
unsigned int i, found;
*b->boardname = 0;
*b->boardpath = 0;
*b->boardfullname = 0;
strupr(path);
j = strlen(path) - 1;
while (j && (path[j - 1] != '/')) j--;
strncpy(cmp, path + j, DIRLEN);
cmp[DIRLEN] = 0;
cut_blank(cmp);
if ((strlen(cmp) == 1) && ! one_letter_boards && ! b->forwarding) return 0;
if (mbcallok(path))
{
sprintf(b->boardpath, "%s/%s", m.userpath, path);
strlwr(b->boardpath);
if (! filetime(b->boardpath)) ret = (-1);
strcpy(b->boardname, path);
strcpy(b->boardfullname, path);
b->boardlife_max = m.userlife;
b->boardlife_min = 0;
b->usermail = 1;
}
else
{
found = 0;
b->usermail = 0;
strcpy(b->boardpath, m.infopath);
strcat(b->boardpath, "/");
// first try to find a board with 8 characters matching, and
// if not found try with 6 characters because a mailsystem which
// only supports 6 characters may have cut the original board name
for (i = 0; i < treelen; i++)
{
if (! strncmp(cmp, tree[i].name + tree[i].flatoffset, 8))
{
strcat(b->boardpath, tree[i].name);
strcpy(b->boardfullname, tree[i].name);
strcpy(b->boardname, tree[i].name + tree[i].flatoffset);
b->boardlife_max = tree[i].lifetime_max;
b->boardlife_min = tree[i].lifetime_min;
found = 1;
ret = i + 1;
break;
}
}
if (! found) return 0;
}
return ret;
}
/*---------------------------------------------------------------------------*/
char *make_mask (char *mask, char *path)
//*************************************************************************
//
//
//*************************************************************************
{
if (mbcallok(path))
strcpy(mask, m.userpath);
else
strcpy(mask, m.infopath);
strcat(mask, "/");
strcat(mask, path);
strcat(mask, "/*.*");
return mask;
}
/*---------------------------------------------------------------------------*/
handle preparedir (char *selektor, int printerror)
//*************************************************************************
//
//
//*************************************************************************
{
handle fh = EOF;
static char ts[25];
waitfor(e_ticsfull);
if ((b->index = finddir(selektor, b->sysop)) != 0)
{
make_mask(b->mask, b->boardfullname);
strcpy(b->listpath, b->mask);
if (! strstr(b->listpath, "*.*"))
trace(fatal, "preparedir", "mask %s", b->listpath);
strcpy(strstr(b->listpath, "*.*"), DIRLISTNAME);
strlwr(b->listpath);
if ((fh = s_open(b->listpath, "lrb")) != EOF)
{
if (filelength(fh) < LBLEN)
{
s_close(fh);
trace(serious, "prepdir", "len0 %s", b->listpath);
// not really serious - why not?? (DH3MB)
xunlink(b->listpath);
fh = EOF;
}
else
{
_read(fh, ts, 24);
lseek(fh, 0L, SEEK_SET);
if ((ts[7] != '<') || (ts[23] != '~'))
{
s_close(fh);
trace(serious, "prepdir", "defect %s", b->listpath);
xunlink(b->listpath);
fh = EOF;
}
}
}
if ((fh == EOF) && ! b->semalock)
{
createdirlist(0);
strlwr(b->listpath);
fh = s_open(b->listpath, "lrb");
}
}
else
if (printerror && ! b->index)
putf(ms(m_noboxfound), selektor);
waitfor(e_ticsfull);
return fh;
}
/*---------------------------------------------------------------------------*/
time_t dirline_data (char *dirline)
//*************************************************************************
//
//
//*************************************************************************
{
time_t dirtime;
int life;
cut_blank(dirline);
dirline[7] = 0;
dirtime = filename2time(dirline);
if (dirline[14] != '>') b->geloescht = dirline[14];
else b->geloescht = 0;
dirline[14] = 0;
skip(dirline + 8);
strcpy(b->herkunft, dirline + 8);
dirline[23] = 0;
skip(dirline + 15);
strcpy(b->ziel, dirline + 15);
b->usermail = mbcallok(b->ziel);
if (b->usermail)
b->gelesen = (dirline[22] == 'R');
else
b->gelesen = 0;
dirline[30] = 0;
skip(dirline + 24);
strcpy(b->frombox, dirline + 24);
dirline[37] = 0;
skip(dirline + 31);
strcpy(b->at, dirline + 31);
dirline[50] = 0;
skip(dirline + 38);
strcpy(b->bid, dirline + 38);
life = atoi(dirline + 51);
if (life == 999) b->lifetime = 999;
else b->lifetime = life - (int) ((ad_time() - dirtime) / DAY);
if (b->lifetime < (-99)) b->lifetime = (-99);
b->lines = (unsigned) ascdez(dirline + 55, 2);
b->bytes = inonlin(ascdez(dirline + 57, 3));
//OE3DZW Anfangsposition von Betreff veraendert
if (dirline[60] == '|')
{
b->mailtype = dirline[61];
b->fwdhold = dirline[62];
b->fwdprop = dirline[63];
b->replied = dirline[64];
b->conttype = dirline[65];
b->eraseinfo = dirline[66];
b->flag7 = dirline[67];
b->flag8 = dirline[68];
b->flag9 = dirline[69];
b->flaga = dirline[70];
b->flagb = dirline[71];
b->flagc = dirline[72];
b->flagd = dirline[73];
b->flage = dirline[74];
b->flagf = dirline[75];
b->flag0 = dirline[76];
strcpy(b->betreff, dirline + 78);
}
//OE3DZW: alte Position war 61, falls noch altes dir/check vorhanden ist
else
{
strcpy(b->betreff, dirline + 61);
b->fwdhold = b->fwdprop = b->replied =
b->conttype = b->eraseinfo = b->flag7 = b->flag8 = b->flag9 =
b->flaga = b->flagb = b->flagc = b->flagd = b->flage =
b->flagf = b->flag0 = '!';
if (b->usermail)
b->mailtype = 'P';
else
b->mailtype = 'B';
}
return dirtime;
}
/*---------------------------------------------------------------------------*/
static void near dir_line (unsigned long lfd, char *dirline)
//*************************************************************************
//
// Gibt eine DIR Zeile aus
//
//*************************************************************************
{
char line[140];
time_t timed;
char flag;
if (b->usermail)
flag = ')';
else
{
if (b->opt & o_r) flag = ')';
else flag = ' ';
}
if (strlen(dirline) == 7) timed = filename2time(dirline);
else timed = dirline_data(dirline);
if (b->gelesen) flag = 'R';
if (b->replied == '1') flag = 'r';
if (b->fwdhold != '!') flag = 'H'; //display hold flag (db1ras)
if (b->geloescht) flag = b->geloescht;
if (b->opt & o_k)
sprintf(line, "%c ", flag);
else
strcpy(line, " ");
if (b->opt & o_a) sprintf(line + strlen(line), "%-6s ", b->herkunft);
if (b->opt & o_e) sprintf(line + strlen(line), "> %-8s ", b->ziel);
if (b->opt & o_d)
sprintf(line + strlen(line), "%s ",
datestr(timed, !! (b->opt & o_y) + (8 * u->dirformat)));
if (b->opt & o_t)
sprintf(line + strlen(line), "%-5.5s ", datestr(timed, 3));
if (b->opt & o_z) sprintf(line + strlen(line), "%4u ", b->lines);
if (b->opt & o_b)
{
if (b->bytes < 1000000L || ! stricmp(b->uplink, "POP3"))
//dh8ymb: bei POP3 muss Lockfile Bytesanzahl haben!
sprintf(line + strlen(line), "%6lu ", b->bytes);
else
sprintf(line + strlen(line), "%5luk ", b->bytes >> 10);
}
if (b->opt & o_i) sprintf(line + strlen(line), "$%-12s ", b->bid);
if (b->opt & o_l) sprintf(line + strlen(line), "#%-3d ", b->lifetime);
if (b->opt & o_f)
{
sprintf(line + strlen(line), "%-6s ", b->frombox);
if (! (b->opt & o_m)) strcat(line, "@ ");
}
if (b->opt & o_m) sprintf(line + strlen(line), "@%-6s ", b->at);
if (b->opt & o_x) strcat(line, " ");
line[73] = 0;
if (b->opt & o_p)
sprintf(line + strlen(line), "%c%c%c%c%c%c ", b->mailtype, b->fwdhold,
b->fwdprop, b->replied, b->conttype, b->eraseinfo);
b->betreff[74 - strlen(line)] = 0; //df3vi: betreff erst nach flags kuerzen
cut_blank(b->betreff);
if (b->opt & o_w) strcat(line, b->betreff);
#ifdef __FLAT__
if (b->http)
{
int i = 1;
putf("%4ld", lfd);
putv(*line);
if (*line != ' ') putv(line[i++]);
if (b->opt & o_k && flag == ' ') putv(line[i++]);
if (! (b->opt & o_u))
html_putf("<a href=\"/cmd?cmd=READ+%s+%lu\">", b->boardname, lfd);
while (line[i] != ' ') putv(line[i++]);
html_putf("</a>");
putf("%s\n", line + i);
}
else
#endif
putf("%4ld%s\n", lfd, line);
waitfor(e_ticsfull);
}
/*---------------------------------------------------------------------------*/
static char near dir_users (char *bake)
//*************************************************************************
//
//
//*************************************************************************
{
int n = 0, i = 0, cnt = 0;
char *userlist;
handle fh;
char buf[32];
time_t timed = (ad_time() - (long) m.oldestbeacon * DAY);
time_t usrlastlogin;
int prozent = 0;
char buffer[50];
char *msg;
char *btmp = NULL;
if (! bake)
putf(ms(m_dirofusers));
else
{
FILE *f;
if ((f = s_fopen(BEACONHEADNAME, "srt")) != NULL)
{
i = fgetc(f);
while (i != EOF && n < 150)
{ // DG0CDC: added support for macros
if (prozent)
{
msg = chartomakro(i, buffer);
if (n + strlen(msg) < BEACON_LEN - 100)
while (*msg)
{
bake[n] = *msg;
msg++;
n++;
}
prozent = 0;
}
else if (i == '%') prozent = 1;
else
{
bake[n] = i;
n++;
}
i = fgetc(f);
}
if (bake[n - 1] != LF)
{
bake[n] = LF;
n++;
}
s_fclose(f);
}
bake[n] = 0;
btmp = bake + n;
}
i = 0;
n = 0;
sprintf(b->mask, "%s/*.*", m.userpath);
userlist = dirsort(m.userpath, 1);
if (userlist)
{
for (i = 0; userlist[i * 8]; i++)
{
sprintf(b->listpath, "%s/%s/" DIRLISTNAME, m.userpath, userlist+i*8);
strlwr(b->listpath);
if ((fh = s_open(b->listpath, "srb")) != EOF)
{
unsigned len = (unsigned) (filelength(fh) >> 7);
while (len)
{
len--;
waitfor(e_ticsfull);
lseek(fh, LBLEN * (long)len, SEEK_SET);
_read(fh, buf, 32);
if ( (buf[14] == '>' || (b->optplus & o_v))
&& (! bake || toupper(buf[22]) != 'R'))
{
if (bake)
{
buf[7] = 0;
time_t mailtime = filename2time(buf);
if ( mailtime > timed
&& get_usr_local(userlist + i * 8, usrlastlogin)
&& mailtime > usrlastlogin)
{
// end of frame ?
if (strlen(bake) > 220 && ! n)
{ // insert zero delimiter
strupr(btmp);
bake += (strlen(bake) + 1);
*bake = 0;
btmp = bake;
n = 0;
}
// + 7 Bytes
strcat(bake, userlist + i * 8);
cnt++;
//make sure that beacon is not longer than 256 bytes
if (++n > 10 || strlen(bake) > 243)
{ // + 2 Bytes
strcat(bake, "\n");
n = 0;
}
else
strcat(bake, " ");
}
}
else
{
putf("%-7s", userlist + i * 8);
if (++n > 10)
{
putv(LF);
n = 0;
}
}
break;
}
}
s_close(fh);
}
}
t_free(userlist);
}
if (n)
{
if (bake) strcat(bake, "\n");
else putv(LF);
}
if (bake)
{
if (cnt == 0 && m.mailbeacon == 1) strcat(bake, "NONE\n");
// append double zero to terminate beacon string
i = strlen(bake);
bake[i] = 0;
bake[i + 1] = 0;
strupr(btmp);
}
return cnt;
}
/*---------------------------------------------------------------------------*/
void sendmailbake (char *)
//*************************************************************************
//
//
//*************************************************************************
{
char s[100];
FILE *f, *f1;
unsigned int i = 0;
char *buffer = (char *) t_malloc(BEACON_LEN, "beac");
char *pb = buffer;
int frames = 0;
int users = 0;
if (! sema_lock("beacon")) return;
if (! m.disable && ! sema_test("purgereorg"))
{
users = dir_users(buffer);
if (m.mailbeacon || users)
{
f = s_fopen(BEACONNAME, "srt");
if (f)
{
while (fgets(s, 70, f))
{
if (*s)
{
s[strlen(s) - 1] = 0; // gelesenen String 0-terminieren
if (strlen(s) >= 4 && s[0] == 'F' && s[1] == 'I' && s[2] == 'L' && s[3] == 'E')
{
f1 = s_fopen("beacon.txt", "swt");
fputs(buffer, f1);
s_fclose(f1);
frames++;
}
else
{
pb = buffer;
while (*pb)
{
for (unsigned int j = 0; pb[j]; j++)
if (pb[j] == LF) pb[j] = CR;
putbeacon_tnc(s, pb);
pb += (strlen(pb) + 1);
frames++;
}
}
i++;
}
}
s_fclose(f);
}
}
trace(report, "mailbeacon", "len=%lu num=%d frames=%d users=%d",
((unsigned long) pb - (unsigned long) buffer), i, frames, users);
}
t_free(buffer);
sema_unlock("beacon");
}
/*---------------------------------------------------------------------------*/
static time_t near seek_time (handle fh, time_t zeit)
//*************************************************************************
//
//
//*************************************************************************
{
char schwelle[8];
strcpy(schwelle, time2filename(zeit));
return seek_fname(fh, schwelle, schwelle, 0);
}
/*---------------------------------------------------------------------------*/
static void near dir_boards (char *selektor)
//*************************************************************************
//
//
//*************************************************************************
{
unsigned int i, tab = 0;
handle fh;
//char name[20];
//strcpy(name, "dir_boards");
strupr(selektor);
if (! *selektor)
{
putf(ms(m_dirofbulletins));
//trace(report, name, "size %d", treelen);
for (i = 0; i < treelen; i++)
{
if ( b->sysop || strstr(tree[i].name, "TMP") != tree[i].name)
{
char *slash = strchr(tree[i].name, '/');
if (slash)
{ //Einbuchstabige Subboards nur fuer Sysop
if (! b->sysop && strlen(slash) < 3) continue;
if (tab < 9)
{
putf(" /");
tab = 11;
}
else
if((tab + strlen(slash)) > 79)
{
putf("\n%9c/", ' ');
tab = 11;
}
putf(" ");
#ifdef __FLAT__
if (b->http)
html_putf("<a href=\"/cmd?cmd=d+%s+-50\">", slash + 1);
#endif
putf("%s", slash + 1);
#ifdef __FLAT__
if (b->http) html_putf("</a>");
#endif
tab += strlen(slash);
}
else
{
if ((strlen(tree[i].name) != 1) || b->sysop)
{
if(tab)
putv(LF);
#ifdef __FLAT__
if (b->http)
html_putf("<a href=\"/cmd?cmd=d+%s+-50\">", tree[i].name);
#endif
putf("%-8s", tree[i].name);
#ifdef __FLAT__
if (b->http) html_putf("</a>");
#endif
tab = 8;
}
}
if (testabbruch()) break;
}
}
if (tab) putv(LF);
}
else
{
putf(ms(m_boardlifemails));
//trace(report, name, "size %d,%s", treelen, selektor);
for (i = 0; i < treelen; i++)
{
if (*selektor == '*' || strstr(tree[i].name, selektor))
{
char *slash = strchr(tree[i].name, '/');
//Anzeige nur Main- oder auch Subboards
if (slash && ! (b->opt & o_s)) continue;
//Anzeige einbuchstabiger Boards nur fuer Sysops
if (! b->sysop && (strlen(tree[i].name) < 2)) continue;
//Anzeige einbuchstabiger Sub-Boards nur fuer Sysops
if (! b->sysop && (slash && (strlen(slash) < 3))) continue;
{
if ((! m.altboardinfo) && (b->opt & o_j))
board_info(tree[i].name);
putf("%-18s %3d-%3d", tree[i].name, tree[i].lifetime_min,
tree[i].lifetime_max);
fh = preparedir(tree[i].name, 0);
if (fh != EOF)
{
time_t tim = seek_time(fh, ad_time());
if (tim > 0)
{
putf("%6ld %4s", ltell(fh) >> 7,
zeitspanne(ad_time() - tim, zs_seconds));
}
else
{
if (m.altboardinfo)
putf(" ");
}
s_close(fh);
waitfor(e_reschedule);
}
else
{
if (m.altboardinfo)
putf(" ");
}
if ((m.altboardinfo) && (b->opt & o_j))
board_info(tree[i].name);
putv(LF);
}
}
if (testabbruch()) break;
}
}
}
/*---------------------------------------------------------------------------*/
static int near line_reject (char *line)
//*************************************************************************
//
// df3vi: reject nach call, verteiler
//
//*************************************************************************
{
char board[12];
int nott = (u->notvisible[1] != '-');
unsigned int i = 0, j;
if ( u->notvisible[1]
&& (strchr(u->notvisible, '<') || strchr(u->notvisible, '@')))
{
for (j = 1; j < 3; j++) //df3vi: bei DIR ist board schon geprueft.
{
*board = ' ';
switch (j)
{
// case 0: i = 8;
// strncpy(board + 1, line + 15, i);
// break;
case 1: i = 7; //Auf Absender pruefen " <CALL "
strncpy(board + 1, line + 7, i);
break;
case 2: i = 7; //Auf Verteiler pruefen " @ADR "
strncpy(board + 1, line + 30, i);
break;
}
board[i + 1] = 0;
cut_blank(board);
strcat(board, " ");
if (strstr(u->notvisible, board)) return nott;
}
return ! nott;
}
else return 0;
}
/*---------------------------------------------------------------------------*/
static int near do_dir (char *search, char *dirline,
int *oldmail, int *notfound, int readlock)
//*************************************************************************
//
//
//*************************************************************************
{
CRegEx reg;
char cmpline[BLEN];
char fromcall[CALLEN+1];
if (search && *search)
{
strcpy(cmpline, dirline);
cut_blank(cmpline);
strcat(cmpline, "\n");
if (! reg.regex_match(search, cmpline))
{
(*notfound)++;
return 0; // Suchkriterium nicht erfuellt
}
}
if (readlock)
{
strncpy(fromcall, dirline + DIRLEN, CALLEN);
fromcall[CALLEN] = 0;
cut_blank(fromcall);
if (strcmp(fromcall, b->logincall) && ! b->sysop)
{
if (readlock == 2 || toupper(dirline[22]) != 'R') return 0;
}
}
// -g ... only show unread mail // dirline[22] ... R marks mail as read
if ((b->opt & o_g) && toupper(dirline[22]) == 'R' && b->usermail)
{
(*oldmail)++;
return 0; // G aktiv und Nachricht schon gelesen
}
if (! (b->opt & o_v) && (dirline[14] != '>'))
return 0; // V nicht aktiv aber Nachricht geloescht
if ((b->opt & o_p) && (dirline[62] == '!') && (dirline[77] == '-'))
return 0; // Only held messages, check for new format
if (! *search && ! mbcallok(b->boardname)) return ! line_reject(dirline);
return OK;
}
/*---------------------------------------------------------------------------*/
void board_info (char *board)
//*************************************************************************
//
// outputs some info on a certain bulletin board
//
//*************************************************************************
{
char line[LINELEN+1];
char *p;
char *tmpb = board;
FILE *f = s_fopen(BOARDINFO, "srt");
if (! f) return;
if (strchr(tmpb, '/')) tmpb = strchr(tmpb, '/') + 1;
while (! feof(f))
{
if (fgets(line, LINELEN, f))
{
p = line;
while (*p == ' ') p++;
if ( stristr(p, tmpb) == p //Board is found
&& (strlen(p) > strlen(tmpb) + 2) //String is long enough
&& p[strlen(tmpb)] == ' ') //It is not a fragment (eg T TAUSCH)
{
p = strchr(p, ' ') + 1;
while (*p == ' ') p++;
strtok(p, "\n\r");
if (m.altboardinfo)
putf(" - %s", p);
else
putf("%s\n", p);
}
}
}
s_fclose(f);
}
/*---------------------------------------------------------------------------*/
static int near putdirkopf (void)
//*************************************************************************
//
//
//*************************************************************************
{
char mybbs[HADRESSLEN + 1];
int ok = 0;
int is_user = mbcallok(b->boardname);
strcpy(mybbs, "");
if (is_user)
{
ok = get_mybbs(b->boardname, mybbs, 0);
if ((b->opt & o_n) && ! strcmp(atcall(mybbs), m.boxname)) return 0;
}
if (! (b->opt & o_h))
{
putf(ms(m_directoryof), b->boardfullname);
if (mybbs[0]) putf(" %c %s", ok ? '@' : '?', mybbs);
if (! m.altboardinfo) putf(":\n");
if (! is_user) board_info(b->boardfullname);
if (m.altboardinfo) putf(":\n");
if (b->opt & o_j)
{
putf(" ");
putf(ms(m_list_nr));
if (b->opt & o_k)
putf(" ");
if (b->opt & o_a)
putf(ms(m_list_call));
if (b->opt & o_e)
{
putf(" ");
putf(ms(m_list_board));
}
if (b->opt & o_d)
{
putf(ms(m_list_date));
if (b->opt & o_y) putf(" ");
}
if (b->opt & o_t)
putf(ms(m_list_time));
if (b->opt & o_z)
putf(ms(m_list_lines));
if (b->opt & o_b)
{
putf(" ");
putf(ms(m_list_bytes));
}
if (b->opt & o_i)
putf(ms(m_list_bid));
if (b->opt & o_l)
{
putf(ms(m_list_life));
putf(" ");
}
if ((b->opt & o_f) || (b->opt & o_m))
{
putf(ms(m_list_forw));
putf(" ");
}
if (b->opt & o_x)
putf(" ");
if (b->opt & o_w)
putf(ms(m_list_subject));
else
putv(LF);
leerzeile();
}
}
return OK;
}
/*---------------------------------------------------------------------------*/
static void near dir_einboard (char *selektor,
int printerror, char *search, char *lastkopf)
//*************************************************************************
//
//
//*************************************************************************
{
unsigned kopf = 0;
unsigned long pos = 0;
char *line= b->line;
int oldmail = 0, notfound = 0;
handle fh;
int nixneues = 0;
int readlock = 0;
char callmybbs[HADRESSLEN + CALLEN + 4];
char mybbs[HADRESSLEN + 1];
strcpy(mybbs, "");
strcpy(b->ziel, "x");
strcpy(b->zielboard, b->ziel);
time_t ftime;
fh = preparedir(selektor, printerror);
formoptions();
if (fh != EOF)
{
if (b->abwann)
{
ftime = seek_time(fh, b->abwann);
if (b->index > 0) tree[b->index - 1].newestmail = ftime;
if (printerror && leof(fh)) nixneues = 1;
}
else if (b->beginn > 0)
{
if (b->beginn > (unsigned long) (filelength(fh) >> 7))
nixneues = 1;
else
lseek(fh, (long) (b->beginn - 1) << 7, SEEK_SET);
}
else
{
if (! seek_lastentry(fh, b->ende))
nixneues = 1;
b->ende = MAXBEREICH;
}
if (nixneues)
{
if (seek_lastentry(fh, 1)) putf(ms(m_lastmessage));
else pos = b->ende;
}
if (mbcallok(b->boardname) && strcmp(b->boardname, b->logincall))
{
readlock = get_readlock(b->boardname);
if (readlock != 1 && u->rlimit) readlock = u->rlimit;
}
while (_read(fh, line, BLEN) && pos < b->ende && ! testabbruch())
{
waitfor(e_ticsfull);
line[BLEN-2] = 0;
pos = (unsigned) (ltell(fh) >> 7);
if (do_dir(search, line, &oldmail, ¬found, readlock))
{
if (! kopf)
{
if (! printerror && ! mbcallok(b->boardname))
{
char *slash = strchr(b->boardfullname, '/');
if (slash) *slash = 0;
if (! strcmp(b->boardfullname, lastkopf))
kopf = OK;
else
strcpy(lastkopf, b->boardfullname);
}
if (! kopf) kopf = putdirkopf();
}
if (kopf) dir_line(pos, line);
}
}
s_close(fh);
}
else if (b->index > 0) tree[b->index - 1].newestmail = BOARDLEER;
if (! kopf && printerror && *b->boardname)
{ // oe3dzw: Ausgabe der Mybbs, falls keine (ungelesenen)
// Nachrichten gefunden wurden.
if (! mbcallok (b->boardname))
strcpy(callmybbs, b->boardname);
else
if (get_mybbs(b->boardname, mybbs, 0))