forked from ResistanceVault/preservation-abbs20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QWK.c
1649 lines (1443 loc) · 39.6 KB
/
QWK.c
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
/****************************************************************
*
* NAME
* QWK.c
*
* DESCRIPTION
* QWK routines for abbs
*
* AUTHOR
* Geir Inge Høsteng
*
* $Id: QWK.c 1.1 1995/06/24 10:34:52 geirhos Exp geirhos $
*
* MODIFICATION HISTORY
* $Log: QWK.c $
* Revision 1.1 1995/06/24 10:34:52 geirhos
* Initial revision
*
*
****************************************************************/
#include <exec/types.h>
#include <exec/memory.h>
#include <bbs.h>
#include <node.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <dos/filehandler.h>
#include <utility/date.h>
#include <devices/SCSIdisk.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/utility.h>
#include <string.h>
#include <ctype.h>
#include <dos.h>
#define a4a5 register __a4 struct ramblocks *nodebase,register __a5 struct Mainmemory *mainmeory
#define usea4a5 nodebase,mainmeory
__asm int packmessages(a4a5);
__asm int unpackmessages (a4a5);
__asm int dograbmsg (register __d0 int nr, register __d1 int conf,register __d2 BPTR msgfil,a4a5,
register __d3 int *msgnr,register __d4 int *touser,register __d5 int *numgrabbed);
__asm int unpackmsg (register __d0 BPTR msgfil,a4a5);
__asm int doctrldatfile(register __d0 int msgnr,a4a5);
__asm ULONG mygetusernumber (register __a2 char *name,a4a5);
__asm int initdatafile (register __d0 BPTR msgfil,a4a5);
__asm void getbiggestdisksub (register __a0 char *name,register __d0 ULONG num);
__asm void getbiggestdisk (void);
int mystricmp (char *ptr, char *ptr2);
int strincmp (char *ptr, char *ptr2,int len);
char *removespace(char *string,int maxlength);
__asm void convertstringfromiso (register __a0 unsigned char *string,a4a5);
__asm unsigned char convertcharfromiso (register __d0 unsigned char c,a4a5);
__asm unsigned char convertchartoiso (register __d0 unsigned char c,a4a5);
__asm void convertstringtoiso (register __a0 unsigned char *string,a4a5);
int readblocks (struct IOStdReq *SCSIIO,int num,ULONG length,void *buffer);
__asm ULONG copybulletin (register __a0 char *fromname,
register __a1 char *toname,a4a5);
extern far int msprintf(char *, const char *, ...);
extern __asm far writecontext (register __a0 char *text,a4a5);
extern __asm far writetexto (register __a0 char *text,a4a5);
extern __asm far writetexti (register __a0 char *text,a4a5);
extern __asm far writeerroro (register __a0 char *text,a4a5);
__asm far VOID ANSIwriteerroro (register __a0 char *text,a4a5);
extern __asm far UWORD loadmsg (register __a0 char *msgtext,
register __a1 struct MessageRecord *msgheader,
register __d0 ULONG msgnr, register __d1 UWORD confnr,a4a5);
extern __asm far UWORD savemsg (register __a0 char *msgtext,
register __a1 struct MessageRecord *msgheader,
register __d0 UWORD confnr,a4a5);
extern __asm far UWORD loadmsgheader (register __a0 struct MessageRecord *msgheader,
register __d0 ULONG msgnr, register __d1 UWORD confnr,a4a5);
extern __asm far UWORD loadmsgtext (register __a0 UBYTE *msgbyf,
register __a1 struct MessageRecord *msgheader,register __d0 UWORD confnr,a4a5);
extern __asm far UWORD savemsgheader (register __a0 struct MessageRecord *msgheader,
register __d0 UWORD confnr,a4a5);
extern __asm far UWORD savemsgheader (register __a0 struct MessageRecord *msgheader,
register __d0 UWORD confnr,a4a5);
extern __asm far strcopylen (register __a0 char *from,register __a1 char *to,
register __d0 UWORD length,a4a5);
extern __asm far char *getusername (register __d0 ULONG usernr,a4a5);
extern __asm far void removefromqueue (register __d0 ULONG msgnr,a4a5);
extern __asm far ULONG getusernumber (register __a0 char *name,a4a5);
extern __asm far ULONG atoi (register __a0 char *text);
extern __asm far int checkmemberofconf (register __d0 ULONG usernr,register __d1 ULONG confnr,a4a5);
extern far int checkformsgerror (void);
extern far void clearmsgerror (void);
extern __asm far void unjoin (a4a5);
extern __asm far ULONG gettopqueue (a4a5);
extern __asm void stopreviewmessages (register __d0 ULONG msgnr,a4a5);
extern __asm void sendintermsgmsg (register __a0 struct MessageRecord *msgheader,
register __a1 char *text,register __d0 UWORD confnr,a4a5);
extern __asm void killrepwritelog (register __a0 char *logtext,register __d0 UWORD confnr,
register __d1 ULONG msgnr,a4a5);
extern __asm void killrepwritelog (register __a0 char *logtext,register __d0 UWORD confnr,
register __d1 ULONG msgnr,a4a5);
extern __asm int kanskrive (register __a0 struct MessageRecord *msgheader,
register __d0 UWORD confnr,a4a5);
extern __asm int getfromname (register __a0 struct MessageRecord *msgheader,
register __a1 UBYTE *msgtext,a4a5);
extern __asm int gettoname (register __a0 struct MessageRecord *msgheader,
register __a1 UBYTE *msgtext,a4a5);
extern __asm int skipnetnames (register __a0 UBYTE *msgtext,register __d0 int msgsize,a4a5);
extern __asm int checkupdatedbulletins (register __d0 UWORD confnr,register __d1 int mode,a4a5);
extern __asm short getnextconfnr (register __d0 short conf,a4a5);
extern __asm int getnetsubject (register __a0 char *msgtext);
extern far ULONG exebase;
extern far struct DosLibrary *DOSBase;
extern far struct Library *UtilityBase;
extern far UBYTE fraISOtilIBN[128];
extern far UBYTE fraIBNtilISO[128];
extern far char logentermsgtext[];
extern far char logreplymsgtext[];
extern far char CursorOffData[];
extern far char CursorOnData[];
__asm int unpackmessages (a4a5)
{
BPTR msgfil = 0;
char tmpstring[80];
int ret = 1,tmp,nottotalok = 0;
char buffer[128+2];
struct ConfigRecord *configdata = &mainmeory->config;
int tmplines;
// Wait 3 seconds for slow Ncomm response
Delay (3*TICKS_PER_SECOND);
tmplines = nodebase->linesleft;
nodebase->linesleft = 65535; // Vi vil ikke ha noen more her..
while (1)
{
msprintf (tmpstring, "%ls/%ls.MSG", nodebase->Nodemem.TmpPath, configdata->BaseName);
if (!(msgfil = Open(tmpstring,MODE_OLDFILE)))
{
putreg (REG_A6,exebase);
ANSIwriteerroro ("Error opening msg file!",usea4a5);
break;
}
if (128 != Read (msgfil,buffer,128))
{
putreg (REG_A6,exebase);
ANSIwriteerroro ("File error!",usea4a5);
break;
}
if (strlen (configdata->BaseName) > 8)
{
if (strincmp (configdata->BaseName,buffer,8))
{
putreg (REG_A6,exebase);
ANSIwriteerroro ("Wrong BBSid!",usea4a5);
break;
}
}
else
{
if (mystricmp (configdata->BaseName,buffer))
{
putreg (REG_A6,exebase);
ANSIwriteerroro ("Wrong BBSid!",usea4a5);
break;
}
}
putreg (REG_A6,exebase);
writetexto ("\n[32m******************************** Reading REP ********************************\n",usea4a5);
putreg (REG_A6,exebase);
writetexto ("[36mNumber Ref # Conference To Subject",usea4a5);
putreg (REG_A6,exebase);
writetexto ("------ ------ ------------------ ------------------------- ------------------",usea4a5);
while (1)
{
putreg (REG_A6,exebase);
tmp = unpackmsg(msgfil,usea4a5);
if (!tmp)
continue;
if (tmp == 2)
{
nottotalok = 1;
continue;
}
break;
}
if (tmp == 1)
{
ret = 0;
putreg (REG_A6,exebase);
writetexto ("[36m------ ------ ------------------ ------------------------- ------------------",usea4a5);
if (nottotalok)
{
putreg (REG_A6,exebase);
writetexto ("\n[31mREPly file parsed with some errors!\n[0m",usea4a5);
}
else
{
putreg (REG_A6,exebase);
writetexto ("\n32mREPly file parsed successfully.\n[0m",usea4a5);
}
}
break;
}
if (msgfil)
Close (msgfil);
DeleteFile (tmpstring);
nodebase->linesleft = tmplines;
putreg (REG_A6,exebase);
return (ret ? -1L : 0);
}
/* returns -1 for fatal errors, 1 for endoffile, 2 for non-fatal error (msg skipped)
and 0 for all ok (1 message parsed)
*/
__asm int unpackmsg (register __d0 BPTR msgfil,a4a5)
{
int ret = -1;
int confnr,tmp,numblocks,replyto,msgnr;
int dobreak = 0,havreadmsg = 0,netmsg = 0;
UBYTE *ptr,*msgstart;
struct ClockData dt;
struct DateStamp ds;
struct MessageRecord *msgheader;
char buffer[128+2],tmpbuf[30],string[100],tmpbuf2[20],tmpbuf3[9];
struct ConfigRecord *configdata = &mainmeory->config;
msgheader = &nodebase->tmpmsgheader;
while (1)
{
tmp = Read (msgfil,buffer,128); /* Read first block in message */
if (!tmp)
{ /* if eof, return 1 */
ret = 1;
break;
}
if (128 != tmp)
{
putreg (REG_A6,exebase);
ANSIwriteerroro ("Error reading first block a message!",usea4a5);
break;
}
confnr = (buffer[124] * 256) + buffer[123];
if ((confnr >= configdata->Maxconferences) ||
!(*(configdata->firstconference[confnr].n_ConfName)))
{
buffer[71+25-1] = '\0';
msprintf (string,"Unknown conference for message \"%ls\"!",removespace(&buffer[71],25));
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
ret = 2; /* non fatal error */
break;
}
if (!(nodebase->CU.firstuserconf[confnr].uc_Access & ACCF_Write) ||
!(nodebase->CU.firstuserconf[confnr].uc_Access & ACCF_Read)) {
msprintf (string,"You are not allowed to write to conference %ls!",
configdata->firstconference[confnr].n_ConfName);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
ret = 2; /* non fatal error */
break;
}
msgstart = nodebase->tmpmsgmem;
/* Reference to... */
putreg (REG_A6,exebase);
strcopylen (&buffer[108],tmpbuf,6,usea4a5);
tmpbuf[6] = '\0';
ptr = &tmpbuf[0];
while (*ptr == ' ')
ptr += 1;
replyto = atoi (ptr);
if (replyto)
{
putreg (REG_A6,exebase);
if (loadmsgheader (msgheader,replyto,confnr*2,usea4a5))
{
msprintf (string,"Message refered to (%ld) not found. Removing reply number...",replyto);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
// ret = 2; // non fatal error
replyto = FALSE;
goto safe;
// break;
}
putreg (REG_A6,exebase);
if (kanskrive (msgheader,confnr*2,usea4a5))
{
msprintf (string,"Message refered to (%ld) not available for reply!",replyto);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
ret = 2; /* non fatal error */
break;
}
/* Sjekker om det er svar til en net bruker
*/
if (msgheader->NrLines < 0)
{
putreg (REG_A6,exebase);
if (loadmsgtext (nodebase->tmpmsgmem,msgheader,confnr*2,usea4a5))
{
msprintf (string,"Message refered to (%ld) not found!",replyto);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
ret = 2; /* non fatal error */
break;
}
ptr = nodebase->tmpmsgmem;
if (*ptr == '\x1e') {
*ptr = '\x1f';
while (*(ptr++) != '\n') ;
msgstart = ptr;
netmsg = 1;
}
}
// Can't check if netusers are member of conference
if (!netmsg)
{
putreg (REG_A6,exebase);
tmp = checkmemberofconf (msgheader->MsgFrom,confnr*2,usea4a5);
if (!tmp)
{
if (tmp > 0)
{
msprintf (string,"Author of message %ld is not a member of conference %ls!",
replyto,configdata->firstconference[confnr].n_ConfName);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
}
else
{
msprintf (string,"Error checking author of message %ld in conference %ls!",
replyto,configdata->firstconference[confnr].n_ConfName);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
}
ret = 2; /* non fatal error */
break;
}
}
msgheader->RefTo = msgheader->Number;
msgheader->MsgTo = msgheader->MsgFrom;
msgheader->MsgFrom = nodebase->CU.Usernr;
if (!(msgheader->Security & SECF_SecReceiver))
{
if (buffer[0] == '*' || buffer[0] == '+')
msgheader->Security = SECF_SecReceiver;
else
msgheader->Security = SECF_SecNone;
}
}
else
safe:
{
msgheader->RefTo = 0;
msgheader->Security = SECF_SecNone;
}
msgheader->MsgStatus = MSTATF_NormalMsg;
msgheader->RefBy = 0;
msgheader->RefNxt = 0;
msgheader->MsgBits = '\0';
dt.mday = (buffer[11]-'0') * 10 + (buffer[12]-'0');
dt.month = (buffer[8]-'0') * 10 + (buffer[9]-'0');
dt.year = (buffer[14]-'0') * 10 + (buffer[15]-'0');
dt.year += (dt.year >= 78 ? 1900 : 2000);
if (buffer[16] == ' ')
dt.hour = (buffer[17]-'0');
else
dt.hour = (buffer[16]-'0') * 10 + (buffer[17]-'0');
if (buffer[19] == ' ')
dt.min = (buffer[20]-'0');
else
dt.min = (buffer[19]-'0') * 10 + (buffer[20]-'0');
dt.sec = 0;
tmp = CheckDate (&dt);
if (!tmp) {
putreg (REG_A6,exebase);
buffer[71+25-1] = '\0';
msprintf (string,"Illegal date for message \"%ls\"!",removespace(&buffer[71],25));
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
ret = 2; /* non fatal error (?)*/
break;
}
msgheader->MsgTimeStamp.ds_Days = tmp / (24*60*60);
tmp -= msgheader->MsgTimeStamp.ds_Days * (24*60*60);
msgheader->MsgTimeStamp.ds_Minute = tmp / 60;
msgheader->MsgTimeStamp.ds_Tick = 0;
DateStamp (&ds);
putreg (REG_A6,exebase);
if (msgheader->MsgTimeStamp.ds_Days != ds.ds_Days) {
msgheader->MsgTimeStamp.ds_Days = ds.ds_Days;
msgheader->MsgTimeStamp.ds_Minute = ds.ds_Minute;
msgheader->MsgTimeStamp.ds_Tick = ds.ds_Tick;
}
strncpy (msgheader->Subject,removespace(&buffer[71],25),25);
for (tmp = 25; tmp < Sizeof_NameT; tmp++)
msgheader->Subject[tmp] = '\0';
putreg (REG_A6,exebase);
convertstringtoiso (msgheader->Subject,usea4a5);
if (!(msgheader->RefTo)) {
msgheader->MsgFrom = nodebase->CU.Usernr;
/*
Tillater ikke folk å jukse med avsender..
memset (tmpbuf,'\0',31);
strncpy (tmpbuf,removespace(&buffer[46],25),25);
putreg (REG_A6,exebase);
convertstringtoiso (tmpbuf,usea4a5);
putreg (REG_A6,exebase);
msgheader->MsgFrom = mygetusernumber (tmpbuf,usea4a5);
if (checkformsgerror ())
{
putreg (REG_A6,exebase);
msprintf (string,"Unknown author for message \"%ls\"!",msgheader->Subject);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
break;
}
*/
memset (tmpbuf,'\0',31);
strncpy (tmpbuf,removespace(&buffer[21],25),25);
putreg (REG_A6,exebase);
convertstringtoiso (tmpbuf,usea4a5);
if (strchr (tmpbuf,'@'))
{
if (!(configdata->firstconference[confnr].n_ConfSW & CONFSWF_Network))
{
msprintf (string,"No net addresses allowed in conference %ls!",
configdata->firstconference[confnr].n_ConfName);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
ret = 2; /* non fatal error */
break;
}
netmsg = 1;
msprintf (msgstart,"\x1f%ls\n\0",tmpbuf);
msgstart += strlen (msgstart);
msgheader->MsgTo = configdata->SYSOPUsernr;
}
else
{
putreg (REG_A6,exebase);
msgheader->MsgTo = mygetusernumber (tmpbuf,usea4a5);
if (checkformsgerror ())
{
msprintf (string,"Unknown recipiant for message \"%ls\"!",msgheader->Subject);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
ret = 2; /* non fatal error */
break;
}
putreg (REG_A6,exebase);
tmp = checkmemberofconf (msgheader->MsgTo,confnr*2,usea4a5);
if (!tmp)
{
if (tmp > 0)
{
msprintf (string,"Receiver of message %ls is not a member of conference %ls!",
msgheader->Subject,configdata->firstconference[confnr].n_ConfName);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
}
else
{
msprintf (string,"Error checking receiver of message %ls in conference %ls!",
msgheader->Subject,configdata->firstconference[confnr].n_ConfName);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
}
ret = 2; /* non fatal error */
break;
}
}
}
if (configdata->firstconference[confnr].n_ConfSW & CONFSWF_PostBox)
{
if (msgheader->MsgTo == -1) // ALL
{
msprintf (string,"No public messages in Post conference %ls (%ls)!",
configdata->firstconference[confnr].n_ConfName,
msgheader->Subject);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
ret = 2; /* non fatal error */
break;
}
else
msgheader->Security = SECF_SecReceiver; /* Tvinger privat melding i post'er */
}
putreg (REG_A6,exebase);
strcopylen (&buffer[116],tmpbuf,6,usea4a5);
tmpbuf[6] = '\0';
ptr = &tmpbuf[0];
while (*ptr == ' ')
ptr += 1;
numblocks = atoi (ptr)-1;
if (numblocks < 1)
{
msprintf (string,"To few msg text blocks for message %ls!",msgheader->Subject);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
break; /* Fatale error */
}
ptr = msgstart;
for (tmp = 0 ; numblocks; numblocks--)
{
if (nodebase->msgmemsize < ((tmp+1) * 128))
{
Seek (msgfil,128,OFFSET_CURRENT);
if (IoErr())
{
putreg (REG_A6,exebase);
msprintf (string,"File error in message %ls!", msgheader->Subject);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
dobreak = 1;
break;
}
}
else if (128 != Read (msgfil,ptr + (tmp*128),128))
{
putreg (REG_A6,exebase);
msprintf (string,"File error in message %ls!",msgheader->Subject);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
dobreak = 1;
break;
}
tmp += 1;
}
putreg (REG_A6,exebase);
havreadmsg = 1;
if (dobreak)
break;
*(ptr + (tmp*128)) = 0;
removespace(ptr + ((tmp-1)*128),128);
msgheader->NrLines = 1;
tmp = 0;
for (ptr = msgstart; *ptr; ptr++)
{
if (*ptr == 227)
{
if (*(ptr+1))
{
*ptr = '\n';
tmp = 0;
msgheader->NrLines += 1;
}
else
{
*ptr = 0;
break;
}
}
else
{
tmp += 1;
if (tmp > 79)
{
*ptr = '\n';
tmp = 0;
msgheader->NrLines += 1;
}
else if (*ptr > 127)
{
putreg (REG_A6,exebase);
*ptr = convertchartoiso (*ptr,usea4a5);
}
else if (*ptr < 32)
*ptr = ' ';
}
}
while (*(ptr-1) == '\n')
{
ptr -= 1;
*ptr = 0;
msgheader->NrLines -= 1;
}
msgheader->NrBytes = (ULONG) ((ULONG) ptr - (ULONG) nodebase->tmpmsgmem);
if (!msgheader->NrBytes)
{
msprintf (string,"Empty message : %ls!",msgheader->Subject);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
ret = 2;
break; /* Non Fatale error */
}
if (netmsg)
msgheader->NrLines = -msgheader->NrLines;
putreg (REG_A6,exebase);
if (savemsg (nodebase->tmpmsgmem,msgheader,confnr*2,usea4a5))
{
msprintf (string,"Error saving message %ls!",msgheader->Subject);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
break; /* Fatale */
}
tmp = msgheader->MsgTo; /* Husker hvem den var til */
msgnr = msgheader->Number;
putreg (REG_A6,exebase);
stopreviewmessages (msgnr,usea4a5);
nodebase->CU.MsgsLeft += 1;
putreg (REG_A6,exebase);
sendintermsgmsg (msgheader,nodebase->tmpmsgmem,confnr*2,usea4a5);
putreg (REG_A6,exebase);
killrepwritelog ((replyto ? logreplymsgtext : logentermsgtext),confnr*2,msgnr,usea4a5);
while (replyto)
{
putreg (REG_A6,exebase);
if (!(loadmsgheader (msgheader,replyto,confnr*2,usea4a5)))
{
if (!(msgheader->RefBy))
{
msgheader->RefBy = msgnr;
putreg (REG_A6,exebase);
if (savemsgheader (msgheader,confnr*2,usea4a5))
{
msprintf (string,"Error updating reply message (%sd:%ld)!", replyto,msgheader->Subject);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
}
break;
}
msgheader->RefNxt = msgheader->RefBy;
while (msgheader->RefNxt)
{
putreg (REG_A6,exebase);
if (loadmsgheader (msgheader,msgheader->RefNxt,confnr*2,usea4a5))
{
msprintf (string,"Error scanning reply message chain (from %sd:%ld)!",msgheader->RefNxt,msgheader->Subject);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
dobreak = 1;
break;
}
}
if (dobreak)
break;
msgheader->RefNxt = msgnr;
putreg (REG_A6,exebase);
if (savemsgheader (msgheader,confnr*2,usea4a5))
{
msprintf (string,"Error updating last reply message (%sd:%ld)!",msgheader->Number,msgheader->Subject);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
dobreak = 1;
break;
}
}
else
{
msprintf (string,"Error reading reply message (%sd:%ld)!",replyto,msgheader->Subject);
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
dobreak = 1;
ret = 2; /* non fatal error */
}
break;
}
if (dobreak)
break;
if (netmsg)
{
ptr = nodebase->tmpmsgmem; ptr += 1;
while (*(ptr++) != '\n') ;
*(--ptr) = '\0';
ptr = nodebase->tmpmsgmem; ptr += 1;
}
else
{
putreg (REG_A6,exebase);
getusername (tmp,usea4a5);
ptr = (UBYTE *) getreg (REG_A0);
}
strncpy (tmpbuf,removespace(&buffer[71],19),19);
tmpbuf[19] = '\0';
strncpy (tmpbuf2,configdata->firstconference[confnr].n_ConfName,18);
tmpbuf2[18] = '\0';
if (replyto)
msprintf (tmpbuf3,"%ld",replyto);
else
strcpy (tmpbuf3,"None ");
msprintf (string,"[32m%6ld %6ls [33m%-18s [0m%-25ls [35m%ls[32m",msgnr,tmpbuf3,tmpbuf2,ptr,tmpbuf);
putreg (REG_A6,exebase);
writetexto (string,usea4a5);
ret = 0;
break;
}
if (ret == 2 && !havreadmsg)
{
while (1)
{
putreg (REG_A6,exebase);
strcopylen (&buffer[116],tmpbuf,6,usea4a5);
tmpbuf[6] = '\0';
ptr = &tmpbuf[0];
while (*ptr == ' ')
ptr += 1;
numblocks = atoi (ptr)-1;
if (numblocks < 1)
{
buffer[71+25-1] = '\0';
msprintf (string,"To few msg text blocks in \"%ls\"!",removespace(&buffer[71],25));
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
ret = -1; /* Fatale error */
break;
}
ptr = nodebase->tmpmsgmem;
for ( ; numblocks; numblocks--)
{
if (128 != Read (msgfil,ptr,128))
{
// putreg (REG_A6,exebase);
buffer[71+25-1] = '\0';
msprintf (string,"File Error while reading message \"%ls\"!",removespace(&buffer[71],25));
putreg (REG_A6,exebase);
ANSIwriteerroro (string,usea4a5);
ret = -1; /* Fatale error */
break;
}
}
break;
}
}
putreg (REG_A6,exebase);
return (ret);
}
char *removespace(char *string,int maxlength)
{
char *ptr;
ptr = string + maxlength-2;
if (*ptr != ' ')
return (string);
while (*(ptr--) == ' ')
;
*(ptr+2) = 0;
return (string);
}
__asm int packmessages (a4a5)
{
BPTR msgfil;
char tmpstring[40];
int conf;
int message,msgpacked,touser,tousertot,totbul = 0;
int dobreak,highmsg;
int ret = 1;
int msgnr = 1,tmp;
int startconf;
char string[80];
struct ConfigRecord *configdata = &mainmeory->config;
char Scan_text[4][2] = { "|", "/", "-", "\\" };
UBYTE scan_count, next_count;
BOOL first_scan;
int tmplines;
putreg (REG_A6,exebase);
writecontext (CursorOffData,usea4a5);
if (nodebase->CU.ScratchFormat == 0)
{
putreg (REG_A6,exebase);
ANSIwriteerroro ("QWK cannot be used with Archiveformat TEXT!",usea4a5);
return (-1);
}
tmplines = nodebase->linesleft;
nodebase->linesleft = 65535;
putreg (REG_A6,exebase);
writetexto ("[32m\n***************************** Making QWK Packet *****************************\n",usea4a5);
putreg (REG_A6,exebase);
writetexto ("[36mConference High # Total For You", usea4a5);
putreg (REG_A6,exebase);
writetexto ("------------------------------ ------- ------- -------", usea4a5);
while (1)
{
msprintf (tmpstring,"%ls/messages.dat",nodebase->Nodemem.TmpPath);
if (!(msgfil = Open(tmpstring,MODE_NEWFILE)))
{
putreg (REG_A6,exebase);
ANSIwriteerroro ("Error opening msg file!",usea4a5);
break;
}
putreg (REG_A6,exebase);
if (initdatafile (msgfil,usea4a5))
break;
startconf = nodebase->confnr/2;
dobreak = 0;
msgpacked = 0;
touser = 0;
scan_count = 0;
next_count = 1;
first_scan = FALSE;
putreg (REG_A6,exebase);
writetexti ("[31m", usea4a5);
putreg (REG_A6,exebase);
while ((message = gettopqueue(usea4a5)) && !dobreak)
{
if (nodebase->CU.Userbits & USERF_ANSIMenus)
{
if (next_count == 1)
{
next_count = 1;
if (first_scan) // Har vi printet ut noe?
{
putreg (REG_A6,exebase);
writetexti ("[D",usea4a5); // JA ... til venstre
}
else
first_scan = TRUE;
putreg (REG_A6,exebase);
writetexti (Scan_text[scan_count],usea4a5);
if (scan_count == 3)
scan_count = 0;
else
scan_count++;
}
else
next_count++;
}
putreg (REG_A6,exebase);
if (dograbmsg (message,startconf,msgfil,usea4a5,&msgnr,&touser,&msgpacked))
{
dobreak = 1;
break;
}
putreg (REG_A6,exebase);
removefromqueue (message,usea4a5);
}
if (dobreak)
break;
putreg (REG_A6,exebase);
unjoin(usea4a5);
if (first_scan) // Har vi printet ut noe?
{
putreg (REG_A6,exebase);
writetexti ("[D",usea4a5); // JA ... til venstre
}
if (msgpacked)
{
msprintf (string,"[33m%-30ls [32m%7ld %7ld %7ld",
configdata->firstconference[startconf].n_ConfName,
configdata->firstconference[startconf].n_ConfDefaultMsg,
msgpacked,touser);
putreg (REG_A6,exebase);
writetexto (string,usea4a5);
}
tousertot = touser;
if (nodebase->CU.Userbits & USERF_SendBulletins)
{
putreg (REG_A6,exebase);
totbul = checkupdatedbulletins (startconf,-1L,usea4a5);
}
conf = startconf;
do
{
putreg (REG_A6,exebase);
conf = getnextconfnr (conf*2, usea4a5) / 2;
if (conf >= configdata->Maxconferences)
conf = 0;
tmp = 0;
if (!*(configdata->firstconference[conf].n_ConfName))
continue;
if (!(nodebase->CU.firstuserconf[conf].uc_Access & ACCF_Read))
continue;
if ((nodebase->CU.Userbits & USERF_SendBulletins) && (startconf != conf))
{
putreg (REG_A6,exebase);
totbul += checkupdatedbulletins (conf,-1L,usea4a5);
}
msgpacked = 0;
touser = 0;
highmsg = configdata->firstconference[conf].n_ConfDefaultMsg;
message = nodebase->CU.firstuserconf[conf].uc_LastRead+1;
/* Sjekker om vi skal bruke max scan */
if (message == 1) {
if ((highmsg - message) > configdata->firstconference[conf].n_ConfMaxScan)
message = highmsg - configdata->firstconference[conf].n_ConfMaxScan;
}
scan_count = 0;
next_count = 1;
first_scan = FALSE;
putreg (REG_A6,exebase);
writetexti ("[31m", usea4a5);
for (; message <= highmsg; message++)
{
if (!message)
continue;
if (next_count == 1)
{
next_count = 1;
if (first_scan) // Har vi printet ut noe?
{
putreg (REG_A6,exebase);
writetexti ("[D",usea4a5); // JA ... til venstre
}
else
first_scan = TRUE;
putreg (REG_A6,exebase);
writetexti (Scan_text[scan_count],usea4a5);
if (scan_count == 3)
scan_count = 0;
else
scan_count++;
}
else
next_count++;
tmp = 1;
putreg (REG_A6,exebase);
if (dograbmsg (message,conf,msgfil,usea4a5,&msgnr,&touser,&msgpacked))
{
dobreak = 1;
break;
}
}