-
Notifications
You must be signed in to change notification settings - Fork 1
/
pipeserv.c
1211 lines (1046 loc) · 42.3 KB
/
pipeserv.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
/*---------------------------------------------------------------------------+
| Titel: PIPESERV.C |
+-----------------------------------------+---------------------------------+
| Erstellt von: Michael Hohner | Am: 24.8.93 |
+-----------------------------------------+---------------------------------+
| System: OS/2 2.x |
+---------------------------------------------------------------------------+
| Beschreibung: |
| |
| Pipe-Server fuer Fleet Street |
| |
| Kommandos: |
| SCAN [*|area|@filename] |
| ETOSS [filename] |
| LOCK [*|area|@filename] |
| UNLCK [*|area|@filename] |
| DBG [MSG|HD|KL|SB|USR|DOM|STA|AR|SPC] {non-public} |
| |
+---------------------------------------------------------------------------+
| Bemerkungen: |
+---------------------------------------------------------------------------*/
/*----------------------------- Header-Dateien ------------------------------*/
#pragma strings(readonly)
#define INCL_BASE
#include <os2.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys\stat.h>
#include "main.h"
#include "version.h"
#include "structs.h"
#include "msgheader.h"
#include "areaman\areaman.h"
#include "pipeserv.h"
#include "handlemsg\handlemsg.h"
#include "handlemsg\kludgeapi.h"
#include "utility.h"
#include "areadlg.h"
#include "areascan.h"
#include "asciitable.h"
#include "dump\expt.h"
/*--------------------------------- Defines ---------------------------------*/
#define PIPE_INVALID 0
#define PIPE_DISCONNECTED 1
#define PIPE_CONNECTED 2
#define PIPE_CLOSING 3
#define PIPE_END 4
#define COM_QUIET 0
#define COM_WAITCOM 1
#define COM_WAITCOM2 2
#define COM_RXCMD 3
#define PIPENAME "\\PIPE\\FleetStreetDoor"
/*---------------------------- Globale Variablen ----------------------------*/
/* Alle Programmoptionen */
extern AREALIST arealiste;
extern USERDATAOPT userdaten;
extern WINDOWCOLORS windowcolors;
extern WINDOWFONTS windowfonts;
extern WINDOWPOSITIONS windowpositions;
extern PATHNAMES pathnames;
extern MISCOPTIONS miscoptions;
extern MACROTABLEOPT macrotable;
extern GENERALOPT generaloptions;
extern ECHOTOSSOPT echotossoptions;
extern PDOMAINS domains;
extern OUTBOUND outbound[MAX_ADDRESSES];
extern INTLSETTING intlsetting;
extern THREADLISTOPTIONS threadlistoptions;
extern LOOKUPOPTIONS lookupoptions;
extern RESULTSOPTIONS resultsoptions;
/* Derzeitige Message */
extern FTNMESSAGE CurrentMessage;
extern MSGHEADER CurrentHeader;
extern char CurrentAddress[LEN_5DADDRESS+1];
extern char CurrentName[LEN_USERNAME+1];
extern char CurrentArea[LEN_AREATAG+1];
extern int CurrentStatus;
static const char *PipeCommands[]={"SCAN", "ETOSS", "DBG", "LOCK", "UNLCK", ""};
#ifdef DEBUG
static const char *DebugCommands[]={"MSG", "HD", "KL", "SB", "USR", "DOM",
"STA", "AR", "SPC", ""};
#endif
/* Empfangspuffer */
static char pchRx[100]="";
static int iRead=0;
static ULONG bytesread=0;
/*--------------------------- Funktionsprototypen ---------------------------*/
#ifdef DEBUG
static void DumpStatus(HPIPE hPipe);
static void DumpMessageText(HPIPE hPipe);
static void DumpHeader(HPIPE hPipe);
static void DumpSeenby(HPIPE hPipe);
static void DumpKludges(HPIPE hPipe);
static void DumpUser(HPIPE hPipe);
static void DumpDomains(HPIPE hPipe);
static void DumpArea(HPIPE hPipe);
#endif
static int IsValidCommand(int parmc, char **parmv);
static int IsValidParameter(int CmdIndex, int parmc, char **parmv);
static void ExecuteCommand(HPIPE hPipe, int CmdIndex, int parmc, char **parmv);
#ifdef DEBUG
static void ExecuteDebug(HPIPE hPipe, int parmc, char **parmv);
#endif
int ReadPipeText(HFILE hPipe, char *pchBuf, BOOL bSingleByte);
int SendPipeText(HFILE hPipe, const char *pchText, BOOL bAddETX);
static int SeparateCommand(char *pchOrigString, int maxparts, char **retarray);
static int GetLogFile(const char *pchFileName, char **pchDestBuf);
static int ForEachWord(char *pchLines, int (* CallBack)(const char*));
static int MarkAreaToScan(const char *pchAreaTag);
static void ScanLoggedAreas(HPIPE hPipe, const char *pchFileName);
/*---------------------------------------------------------------------------*/
/* Funktionsname: NewPipeServer */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Beschreibung: Pipe-Server Threadfunktion */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Parameter: pThreadParam: Dummy-Parameter */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Rckgabewerte: - */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Sonstiges: FSM eines Pipe-Servers */
/* */
/*---------------------------------------------------------------------------*/
void _Optlink NewPipeServer(PVOID pThreadParam)
{
int PipeStatus = PIPE_INVALID;
int ComStatus = COM_QUIET;
char command[300];
HPIPE DoorPipe=NULLHANDLE;
int CmdIndex=0;
ULONG written;
INSTALLEXPT("Pipe");
pThreadParam = pThreadParam;
while (PipeStatus != PIPE_END) /* Endlosschleife */
switch (PipeStatus)
{
case PIPE_INVALID:
/* Pipe erzeugen */
switch(DosCreateNPipe(PIPENAME, &DoorPipe, NP_INHERIT | NP_ACCESS_DUPLEX,
NP_WAIT | NP_TYPE_BYTE | NP_READMODE_BYTE | 1,
1000, 100, 0))
{
case NO_ERROR:
PipeStatus=PIPE_DISCONNECTED;
break;
default:
PipeStatus=PIPE_END;
break;
}
break;
case PIPE_DISCONNECTED:
/* Pipe connecten */
switch (DosConnectNPipe(DoorPipe))
{
case NO_ERROR:
PipeStatus=PIPE_CONNECTED;
break;
case ERROR_BROKEN_PIPE:
PipeStatus=PIPE_CLOSING;
break;
case ERROR_INTERRUPT:
break;
default:
DosBeep(1000,100);
PipeStatus=PIPE_END;
break;
}
break;
case PIPE_CONNECTED:
switch(ComStatus)
{
case COM_QUIET:
if (!ReadPipeText(DoorPipe, command, TRUE))
{
if (command[0] == C_ENQ)
{
/* Identifikation schicken */
ComStatus = COM_WAITCOM;
SendPipeText(DoorPipe, "FleetStreet", TRUE);
}
}
else
{
ComStatus = COM_QUIET;
PipeStatus=PIPE_CLOSING;
}
break;
case COM_WAITCOM:
if (!ReadPipeText(DoorPipe, command, TRUE))
{
if (command[0] == C_ACK)
{
/* Versionsnummer schicken */
ComStatus = COM_WAITCOM2;
SendPipeText(DoorPipe, FLEETVER, TRUE);
}
else
{
/* NAK erhalten */
DosWrite(DoorPipe, S_EOT, 1, &written);
ComStatus = COM_QUIET;
PipeStatus = PIPE_CLOSING;
}
}
else
{
ComStatus = COM_QUIET;
PipeStatus=PIPE_CLOSING;
}
break;
case COM_WAITCOM2:
if (!ReadPipeText(DoorPipe, command, TRUE))
{
if (command[0] == C_ACK)
{
/* Warten auf Befehl */
ComStatus = COM_RXCMD;
}
else
{
/* NAK erhalten */
DosWrite(DoorPipe, S_EOT, 1, &written);
ComStatus = COM_QUIET;
PipeStatus = PIPE_CLOSING;
}
}
else
{
ComStatus = COM_QUIET;
PipeStatus=PIPE_CLOSING;
}
break;
case COM_RXCMD:
if (!ReadPipeText(DoorPipe, command, TRUE))
{
if (command[0] == C_EOT)
{
DosWrite(DoorPipe, S_EOT, 1, &written);
ComStatus = COM_QUIET;
PipeStatus = PIPE_CLOSING;
}
else
{
int paramtest;
int parmc;
char *parmv[5];
parmc = SeparateCommand(command, 5, parmv);
if (parmc == 0)
SendPipeText(DoorPipe, S_NAK "C", TRUE);
else
if ((CmdIndex = IsValidCommand(parmc, parmv)) == -1)
SendPipeText(DoorPipe, S_NAK "C", TRUE);
else
if (!(paramtest=IsValidParameter(CmdIndex, parmc, parmv)))
SendPipeText(DoorPipe, S_NAK "P", TRUE);
else
{
if (paramtest == -1)
{
SendPipeText(DoorPipe, S_NAK "S", TRUE);
}
else
{
SendPipeText(DoorPipe, S_ACK, TRUE);
ExecuteCommand(DoorPipe, CmdIndex, parmc, parmv);
/* Ende */
DosWrite(DoorPipe, S_ETX, 1, &written);
}
}
}
}
else
{
ComStatus = COM_QUIET;
PipeStatus=PIPE_CLOSING;
}
break;
default:
break;
}
break;
case PIPE_CLOSING:
/* Puffer zurcksetzen */
pchRx[0]=0;
bytesread=0;
iRead=0;
switch (DosDisConnectNPipe(DoorPipe))
{
case ERROR_BROKEN_PIPE:
case NO_ERROR:
PipeStatus=PIPE_DISCONNECTED;
break;
default:
PipeStatus=PIPE_END;
break;
}
break;
default:
break;
}
if (DoorPipe)
DosClose(DoorPipe);
DEINSTALLEXPT;
return;
}
/*---------------------------------------------------------------------------*/
/* Funktionsname: ReadPipeText */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Beschreibung: Liest einen Text aus der Pipe */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Parameter: hPipe: Pipe-Handle */
/* pchBuf: Zeiger auf Puffer */
/* bSingleByte: Liesst auch ein einzelnes Byte */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Rckgabewerte: 0 Text gelesen */
/* -1 Fehler */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Sonstiges: ETX wird abgetrennt, Puffer ist Nullterminiert */
/* */
/*---------------------------------------------------------------------------*/
int ReadPipeText(HFILE hPipe, char *pchBuf, BOOL bSingleByte)
{
char *pchBufPtr = pchBuf;
static int i=100;
while(1) /* endlos */
{
if (i == 100 || iRead == bytesread)
{
/* Empfangspuffer leer, neu lesen */
i=0;
iRead=0;
DosRead(hPipe, pchRx, 100, &bytesread);
}
if (bytesread > 0)
{
while (i < 100 && iRead < bytesread)
{
if (pchRx[i] != C_ETX)
{
if (bSingleByte &&
(pchRx[i] == C_ACK ||
pchRx[i] == C_NAK ||
pchRx[i] == C_ENQ)) /* Einzelbyte lesen, nicht auf ETX warten */
{
*pchBufPtr++ = pchRx[i++];
*pchBufPtr = 0;
iRead++;
return 0;
}
else
{
*pchBufPtr++ = pchRx[i++];
iRead++;
}
}
else
{
*pchBufPtr = 0;
i++;
iRead++;
return 0;
}
}
}
else /* Lesefehler */
{
*pchBufPtr = 0;
return -1;
}
}
}
/*---------------------------------------------------------------------------*/
/* Funktionsname: SendPipeText */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Beschreibung: Schickt einen Text in die Pipe */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Parameter: hPipe: Pipe-Handle */
/* pchText: Text, der gesendet wird. */
/* bAddETX: Ein ETX wird nach dem Text gesendet. */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Rckgabewerte: 0 Text gelesen */
/* -1 Fehler */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Sonstiges: Das Nullbyte wird nicht gesendet */
/*---------------------------------------------------------------------------*/
int SendPipeText(HFILE hPipe, const char *pchText, BOOL bAddETX)
{
ULONG written;
DosWrite(hPipe, (PVOID) pchText, strlen(pchText), &written);
if (bAddETX)
DosWrite(hPipe, S_ETX, 1, &written);
return 0;
}
/*---------------------------------------------------------------------------*/
/* Funktionsname: IsValidCommand */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Beschreibung: Prueft den Kommandostring auf ein gueltiges Kommando */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Parameter: parmc: Anzahl der Parameter */
/* parmv: Parameter-Array */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Rckgabewerte: -1 kein gueltiges Kommando */
/* sonst Kommando-Index */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Sonstiges: */
/* */
/*---------------------------------------------------------------------------*/
static int IsValidCommand(int parmc, char **parmv)
{
int iIndex=0;
if (!parmc)
return -1;
while(PipeCommands[iIndex][0])
{
if (!stricmp(parmv[0], PipeCommands[iIndex]))
break;
iIndex++;
}
if (PipeCommands[iIndex][0])
return iIndex;
else
return -1;
}
/*---------------------------------------------------------------------------*/
/* Funktionsname: IsValidParameter */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Beschreibung: Prueft den Kommandostring auf gueltige Parameter */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Parameter: CmdIndex: Kommando-Index */
/* parmc: Anzahl der Parameter */
/* parmv: Parameter-Array */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Rckgabewerte: 0 kein gueltiger Parameter */
/* 1 Parameter gueltig */
/* -1 Zu viele Parameter */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Sonstiges: */
/* */
/*---------------------------------------------------------------------------*/
static int IsValidParameter(int CmdIndex, int parmc, char **parmv)
{
#ifdef DEBUG
int iCode=0;
#endif
switch(CmdIndex)
{
case 0: /* SCAN */
if (parmc < 2)
return 0;
else
if (parmc > 2)
return -1;
else
if (parmv[1][0]=='*' || /* '*' oder Area-Tag */
parmv[1][0]=='@' ||
AM_FindArea(&arealiste, parmv[1]))
return 1;
else
return 0;
case 1: /* ETOSS */
if (parmc == 1)
return 1;
if (parmc > 2)
return -1;
return 1;
#ifdef DEBUG
case 2: /* DBG */
if (parmc < 2)
return 0;
if (parmc > 2)
return -1;
while(DebugCommands[iCode][0])
if(stricmp(parmv[1], DebugCommands[iCode]))
iCode++;
else
break;
if (DebugCommands[iCode][0])
return 1;
else
return 0;
#endif
default:
return 0;
}
}
/*---------------------------------------------------------------------------*/
/* Funktionsname: ExecuteCommand */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Beschreibung: Fuehrt das Kommando aus */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Parameter: hPipe: Pipe-Handle (fuer Rueckgabewerte) */
/* CmdIndex: Kommando-Index */
/* parmc: Anzahl der Parameter */
/* parmv: Parameter-Array */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Rckgabewerte: - */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Sonstiges: Der Bestaetigungstring muss geschrieben werden, jedoch ohne */
/* ETX. Format: <ACK|NAK>"Ergebnis" */
/*---------------------------------------------------------------------------*/
static void ExecuteCommand(HPIPE hPipe, int CmdIndex, int parmc, char **parmv)
{
extern BOOL DoingAreaScan;
extern int tidAreaScan;
switch(CmdIndex)
{
case 0: /* SCAN */
if (parmv[1][0] == '*')
{
AREADEFLIST *zeiger = arealiste.pFirstArea;
while (zeiger)
{
zeiger->flWork |= WORK_SCAN;
zeiger = zeiger->next;
}
while(DoingAreaScan) /* Warten bis alter Scan vorbei */
DosSleep(1000);
tidAreaScan = _beginthread(ScanAreas, NULL, 16386, &arealiste);
SendPipeText(hPipe, S_ACK "Scan started", FALSE);
}
else
if (parmv[1][0] == '@')
ScanLoggedAreas(hPipe, &(parmv[1][1]));
else
{
if (MarkAreaToScan(parmv[1]))
SendPipeText(hPipe, S_NAK "No areas", FALSE);
else
{
while(DoingAreaScan) /* Warten bis alter Scan vorbei */
DosSleep(1000);
tidAreaScan = _beginthread(ScanAreas, NULL, 16386, &arealiste);
SendPipeText(hPipe, S_ACK "Scan started", FALSE);
}
}
break;
case 1: /* ETOSS */
if (echotossoptions.useechotoss &&
strlen(echotossoptions.pchEchoToss))
{
int rc;
if (parmc > 1)
rc = WriteEchotoss(&arealiste, parmv[1]);
else
rc = WriteEchotoss(&arealiste, echotossoptions.pchEchoToss);
if (rc)
SendPipeText(hPipe, S_NAK "write error", FALSE);
else
SendPipeText(hPipe, S_ACK "written", FALSE);
}
else
SendPipeText(hPipe, S_NAK "not active", FALSE);
break;
#ifdef DEBUG
case 2: /* DBG */
ExecuteDebug(hPipe, parmc, parmv);
break;
#endif
case 3: /* LOCK */
SendPipeText(hPipe, S_NAK "Not implemented", FALSE);
break;
case 4: /* UNLCK */
SendPipeText(hPipe, S_NAK "Not implemented", FALSE);
break;
default:
SendPipeText(hPipe, S_NAK "internal error", FALSE);
break;
}
return;
}
#ifdef DEBUG
/*---------------------------------------------------------------------------*/
/* Funktionsname: ExecuteDebug */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Beschreibung: Fuehrt das Kommando DBG aus */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Parameter: hPipe: Pipe-Handle (fuer Rueckgabewerte) */
/* parmc: Anzahl der Parameter */
/* parmv: Parameter-Array */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Rckgabewerte: - */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Sonstiges: Der Bestaetigungstring muss geschrieben werden, jedoch ohne */
/* ETX. Format: <ACK|NAK>"Ergebnis" */
/*---------------------------------------------------------------------------*/
static void ExecuteDebug(HPIPE hPipe, int parmc, char **parmv)
{
if (parmc < 2)
{
SendPipeText(hPipe, S_NAK "No Code", FALSE);
return;
}
else
{
int iCode=0;
while(DebugCommands[iCode][0])
if(stricmp(parmv[1], DebugCommands[iCode]))
iCode++;
else
break;
if (DebugCommands[iCode][0])
{
switch(iCode)
{
case 0: /* Message */
DumpMessageText(hPipe);
break;
case 1: /* Header */
DumpHeader(hPipe);
break;
case 2: /* Kludges */
DumpKludges(hPipe);
break;
case 3: /* SEEN-BYs */
DumpSeenby(hPipe);
break;
case 4: /* User */
DumpUser(hPipe);
break;
case 5: /* Domains */
DumpDomains(hPipe);
break;
case 6: /* Status */
DumpStatus(hPipe);
break;
case 7: /* Area */
DumpArea(hPipe);
break;
case 8: /* Special */
SendPipeText(hPipe, S_ACK "OK", FALSE);
break;
default:
SendPipeText(hPipe, S_NAK "Not impl.", FALSE);
break;
}
return;
}
else
{
SendPipeText(hPipe, S_NAK "Unknown code", FALSE);
return;
}
}
}
static void DumpMessageText(HPIPE hPipe)
{
ULONG written;
if (CurrentMessage.pchMessageText)
{
DosWrite(hPipe, S_ACK "\r\n", 3, &written);
DosWrite(hPipe, CurrentMessage.pchMessageText, strlen(CurrentMessage.pchMessageText), &written);
}
else
{
DosWrite(hPipe, S_NAK "*No Text*", 10, &written);
}
return;
}
static void DumpHeader(HPIPE hPipe)
{
ULONG written;
char buffer[200];
int i;
DosWrite(hPipe, S_ACK, 1, &written);
DosWrite(hPipe, "\r\n", 2, &written);
sprintf(buffer, "From: >%-35s<\n", CurrentHeader.pchFromName);
DosWrite(hPipe, buffer, strlen(buffer), &written);
sprintf(buffer, "To: >%-35s<\n", CurrentHeader.pchToName);
DosWrite(hPipe, buffer, strlen(buffer), &written);
strcpy(buffer, "O-Address: ");
DosWrite(hPipe, buffer, strlen(buffer), &written);
NetAddrToString(buffer, &CurrentHeader.FromAddress);
DosWrite(hPipe, buffer, strlen(buffer), &written);
DosWrite(hPipe, "\r\n", 2, &written);
strcpy(buffer, "D-Address: ");
DosWrite(hPipe, buffer, strlen(buffer), &written);
NetAddrToString(buffer, &CurrentHeader.ToAddress);
DosWrite(hPipe, buffer, strlen(buffer), &written);
DosWrite(hPipe, "\r\n", 2, &written);
sprintf(buffer, "Subj: >%-71s<\n", CurrentHeader.pchSubject);
DosWrite(hPipe, buffer, strlen(buffer), &written);
strcpy(buffer, "Date written: ");
DosWrite(hPipe, buffer, strlen(buffer), &written);
StampToString(buffer, &CurrentHeader.StampWritten);
DosWrite(hPipe, buffer, strlen(buffer), &written);
DosWrite(hPipe, "\r\n", 2, &written);
strcpy(buffer, "Date arrived: ");
DosWrite(hPipe, buffer, strlen(buffer), &written);
StampToString(buffer, &CurrentHeader.StampArrived);
DosWrite(hPipe, buffer, strlen(buffer), &written);
DosWrite(hPipe, "\r\n", 2, &written);
sprintf(buffer, "Flags: %08x\n", CurrentHeader.ulAttrib);
DosWrite(hPipe, buffer, strlen(buffer), &written);
strcpy(buffer, "Reply to: ");
DosWrite(hPipe, buffer, strlen(buffer), &written);
sprintf(buffer, "%08x\n", CurrentHeader.ulReplyTo);
DosWrite(hPipe, buffer, strlen(buffer), &written);
strcpy(buffer, "Replies: ");
DosWrite(hPipe, buffer, strlen(buffer), &written);
i=0;
while (i<NUM_REPLIES && CurrentHeader.ulReplies[i])
{
sprintf(buffer, "%08x ", CurrentHeader.ulReplies[i]);
DosWrite(hPipe, buffer, strlen(buffer), &written);
i++;
}
DosWrite(hPipe, "\r\n", 2, &written);
return;
}
static void DumpSeenby(HPIPE hPipe)
{
SendPipeText(hPipe, S_ACK "\r\n", FALSE);
if (CurrentMessage.pchSeenPath)
SendPipeText(hPipe, CurrentMessage.pchSeenPath, FALSE);
else
SendPipeText(hPipe, "*No SEEN-BYs", FALSE);
return;
}
static void DumpKludges(HPIPE hPipe)
{
PKLUDGE pKludge=NULL;
SendPipeText(hPipe, S_ACK "\r\n", FALSE);
while (pKludge = MSG_FindKludge(&CurrentMessage, KLUDGE_ANY, pKludge))
{
if (pKludge->ulKludgeType == KLUDGE_OTHER)
SendPipeText(hPipe, pKludge->pchKludgeText, FALSE);
else
{
SendPipeText(hPipe, MSG_QueryKludgeName(pKludge->ulKludgeType), FALSE);
SendPipeText(hPipe, pKludge->pchKludgeText, FALSE);
}
SendPipeText(hPipe, "\r\n", FALSE);
}
return;
}
static void DumpUser(HPIPE hPipe)
{
char buffer[200];
int i;
SendPipeText(hPipe, S_ACK "\r\n", FALSE);
/* usernamen */
for (i=0; i<MAX_USERNAMES; i++)
{
sprintf(buffer, "Name %2d: >%-35s<\r\n", i+1, userdaten.username[i]);
SendPipeText(hPipe, buffer, FALSE);
}
/* adressen */
for (i=0; i<MAX_ADDRESSES; i++)
{
sprintf(buffer, "Address %2d: >%-40s<\r\n", i+1, userdaten.address[i]);
SendPipeText(hPipe, buffer, FALSE);
}
/* origin */
sprintf(buffer, "Origin: >%-50s<\r\n", userdaten.defaultorigin);
SendPipeText(hPipe, buffer, FALSE);
return;
}
static void DumpDomains(HPIPE hPipe)
{
PDOMAINS pDomain;
char buffer[300];
/* Domains */
pDomain=domains;
SendPipeText(hPipe, S_ACK "\r\n", FALSE);
while (pDomain)
{
sprintf(buffer, "Domain: >%s<\r\n", pDomain->domainname);
SendPipeText(hPipe, buffer, FALSE);
sprintf(buffer, "Nodelist-Index: >%s<\r\n", pDomain->indexfile);
SendPipeText(hPipe, buffer, FALSE);
sprintf(buffer, "Nodelist-Daten: >%s<\r\n\r\n", pDomain->nodelistfile);
SendPipeText(hPipe, buffer, FALSE);
pDomain=pDomain->next;
}
return;
}
static void DumpStatus(HPIPE hPipe)
{
SendPipeText(hPipe, S_ACK "\r\nStatus:\r\n", FALSE);
SendPipeText(hPipe, "CurrentAddress: >", FALSE);
SendPipeText(hPipe, CurrentAddress, FALSE);
SendPipeText(hPipe, "<\r\n", FALSE);
SendPipeText(hPipe, "CurrentName: >", FALSE);
SendPipeText(hPipe, CurrentName, FALSE);
SendPipeText(hPipe, "<\r\n", FALSE);
SendPipeText(hPipe, "CurrentArea: >", FALSE);
SendPipeText(hPipe, CurrentArea, FALSE);
SendPipeText(hPipe, "<\r\n", FALSE);
SendPipeText(hPipe, "CurrentStatus: ", FALSE);
switch(CurrentStatus)
{
case PROGSTATUS_NOSETUP:
SendPipeText(hPipe, "No Setup", FALSE);
break;
case PROGSTATUS_READING:
SendPipeText(hPipe, "Reading", FALSE);
break;
case PROGSTATUS_EDITING:
SendPipeText(hPipe, "Editing", FALSE);
break;
case PROGSTATUS_CLEANUP:
SendPipeText(hPipe, "Clean up", FALSE);
break;
default:
SendPipeText(hPipe, "unknown", FALSE);
break;
}
return;
}
static void DumpArea(HPIPE hPipe)
{
AREADEFLIST *zeiger;
char buffer[200];
SendPipeText(hPipe, S_ACK "CurrentArea: >", FALSE);
SendPipeText(hPipe, CurrentArea, FALSE);
SendPipeText(hPipe, "<\r\n", FALSE);
zeiger=AM_FindArea(&arealiste, CurrentArea);
if (!zeiger)
SendPipeText(hPipe, "Invalid Area!\r\n", FALSE);
else
{
sprintf(buffer, "Area Description: >%s<\r\n", zeiger->areadata.areadesc);
SendPipeText(hPipe, buffer, FALSE);
sprintf(buffer, "Address: >%s<\r\n", zeiger->areadata.address);
SendPipeText(hPipe, buffer, FALSE);
sprintf(buffer, "Name: >%s<\r\n", zeiger->areadata.username);
SendPipeText(hPipe, buffer, FALSE);
sprintf(buffer, "Path/File: >%s<\r\n", zeiger->areadata.pathfile);
SendPipeText(hPipe, buffer, FALSE);
sprintf(buffer, "Template: %d\r\n", zeiger->areadata.ulTemplateID);
SendPipeText(hPipe, buffer, FALSE);
sprintf(buffer, "Areatype: %d\r\n", zeiger->areadata.areatype);
SendPipeText(hPipe, buffer, FALSE);
sprintf(buffer, "Format: %d\r\n", zeiger->areadata.areaformat);
SendPipeText(hPipe, buffer, FALSE);
sprintf(buffer, "Optionen: %d\r\n", zeiger->areadata.usAreaOpt);
SendPipeText(hPipe, buffer, FALSE);
sprintf(buffer, "Default flags: %d\r\n", zeiger->areadata.usDefAttrib);
SendPipeText(hPipe, buffer, FALSE);
sprintf(buffer, "Max messages: %d\r\n", zeiger->maxmessages);
SendPipeText(hPipe, buffer, FALSE);
sprintf(buffer, "Current message: %d\r\n", zeiger->currentmessage);
SendPipeText(hPipe, buffer, FALSE);
sprintf(buffer, "Area handle: %08x\r\n", zeiger->areahandle);
SendPipeText(hPipe, buffer, FALSE);
sprintf(buffer, "Scanned: %c\r\n", (zeiger->scanned)? 'Y' : 'N');
SendPipeText(hPipe, buffer, FALSE);
sprintf(buffer, "Mail entered: %c\r\n", (zeiger->mailentered)? 'Y' : 'N');
SendPipeText(hPipe, buffer, FALSE);
}