-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathModel3270.ts
6312 lines (5961 loc) · 235 KB
/
Model3270.ts
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
/*
This program and the accompanying materials are
made available under the terms of the Eclipse Public License v2.0 which accompanies
this distribution, and is available at https://www.eclipse.org/legal/epl-v20.html
SPDX-License-Identifier: EPL-2.0
Copyright Contributors to the Zowe Project.
Copyright Contributors to the Open Mainframe Project's TSTerm Project
*/
import { Exception,Utils } from "./Utils";
import { CharacterAttributes, FieldData, KeyboardMap, RowAndColumn,
VirtualScreen, OIALine, CharsetInfo, BaseRenderer } from "./Generic";
import { ScreenElement, PagedVirtualScreen, PagedRenderer } from "./Paged";
import { GraphicsState } from "./Graphics";
class Ebcdic {
/*
static th = 28; // what is this?? EBCDIC IFS?, ASCII FS
static lh = 30; // Field mark, record separator, was lh
*/
static fieldMark = 28; // was th, See EBCDIC docs
static recordMark = 30; // was lh
static hyphen = 0x60;
static specialMarks = [ 28, 30]; // keep in sync with above definitions
static boxTRight = 0xC6;
static boxTUp = 0xC7;
static boxCrossedLines = 0xD3;
static boxTLeft = 0xD6;
static boxTDown = 0xD7;
static boxHLine = 0xA2;
static boxLowLCorner = 0xC4;
static boxLowRCorner = 0xD4;
static boxTopLCorner = 0xC5;
static boxTopRCorner = 0xC6;
}
class Unicode {
static euro = 0x20AC; // 8364
static space2000 = 0x2000; // 8192
}
class CharacterAttributes3270 extends CharacterAttributes { // minified as Xo
classicBits:number;
highlighting:number;
color:number;
backgroundColor:number;
characterSet:number;
outlining:number;
transparency:number;
validation:number;
sisoAllowed:number;
// These are not well-understood yet
hn:number;
rn:number;
an:number;
constructor(classicBits?:number){
super();
this.classicBits = (classicBits ? classicBits : 0); // minified "this.sn"
this.highlighting = 0; // minified as .wn
this.color = 0;
this.backgroundColor = 0;
this.characterSet = 0;
this.outlining = 0; // minified .mn
this.transparency = 0; // minified .hs
this.validation = 0; // minified .rs
this.sisoAllowed = 0; // DBCS shift in-out -- minified .ql
this.hn = 0; // not yet known from minified code, not in toString Method
this.rn = 0;
this.an = 0;
}
copy(){ // minified as prototype.yi()
let c = new CharacterAttributes3270(this.classicBits);
c.highlighting = this.highlighting;
c.color = this.color;
c.backgroundColor = this.backgroundColor;
c.characterSet = this.characterSet;
c.outlining = this.outlining;
c.transparency = this.transparency;
c.validation = this.validation;
c.sisoAllowed = this.sisoAllowed;
c.hn = this.hn;
c.rn = this.rn;
c.an = this.an;
return c;
}
toString(){
let t = ("<CharAttrs3270 std=0x" + Utils.hexString(this.classicBits) +
" color=0x" + Utils.hexString(this.color) +
" bgCol=0x" + Utils.hexString(this.backgroundColor));
if (this.outlining != 0){
t += " outln=0x" + Utils.hexString(this.outlining);
}
if (this.highlighting != 0){
t += " hilite=0x" + Utils.hexString(this.highlighting);
}
if (this.characterSet != 0){
t += " charSet=0x" + Utils.hexString(this.characterSet);
}
if (this.transparency != 0){
t += " transpcy=0x" + Utils.hexString(this.transparency);
}
if (this.validation != 0){
t += " valdtn=0x" + Utils.hexString(this.validation);
}
if (this.sisoAllowed != 0){
t += " SI/SO Allowed";
}
t += ">"
return t;
}
/*
os is only called from lc.prototype._h = function (t) {}
the trace messages indicate this is VirtualScreen3270 generating some sort of read response
*/
os(){ // (Xo.prototype.os = function () { -- not well understood yet
let t = [];
return (
64 != this.classicBits && 0 != this.classicBits && (t.push(192), t.push(this.classicBits)),
0 != this.highlighting && (t.push(65), t.push(this.highlighting)),
0 != this.color && (t.push(66), t.push(this.color)),
0 != this.backgroundColor && (t.push(69), t.push(this.backgroundColor)),
0 != this.characterSet && (t.push(67), t.push(this.characterSet)),
0 != this.outlining && (t.push(194), t.push(this.outlining)),
0 != this.transparency && (t.push(70), t.push(this.transparency)),
0 != this.validation && (t.push(193), t.push(this.validation)),
0 != this.sisoAllowed && (t.push(254), t.push(this.sisoAllowed)),
0 != this.hn && (t.push(113), t.push(this.hn)),
0 != this.rn && (t.push(114), t.push(this.rn)),
0 != this.an && (t.push(115), t.push(this.an)),
t
);
}
/*
cs (like os() above) is only called from lc.prototype._h = function (t) {}
the trace messages indicate this is VirtualScreen3270 generating some sort of read response
*/
cs(t:CharacterAttributes3270):Map<number,number>|null { // (Xo.prototype.cs = function (t) { -- not well understood yet
if (null == t) {
return null;
}
let l = new Map<number,number>();
let n:boolean = false;
if (this.classicBits != t.classicBits){
l.set(192, t.classicBits);
n = true;
}
if (this.highlighting != t.highlighting){
l.set(65, t.highlighting);
n = true;
}
if (this.color != t.color){
l.set(66, t.color);
n = true;
}
if (this.backgroundColor != t.backgroundColor){
l.set(69, t.backgroundColor);
n = !0;
}
if (this.characterSet != t.characterSet){
l.set(67, t.characterSet);
n = true;
}
if (this.outlining != t.outlining){
l.set(194, t.outlining);
n = true;
}
if (this.transparency != t.transparency){
l.set(70, t.transparency);
n = true;
}
if (this.validation != t.validation){
l.set(193, t.validation);
n = true;
}
if (this.sisoAllowed != t.sisoAllowed){
l.set(254, t.sisoAllowed);
n = true;
}
if (this.hn != t.hn){
l.set(113, t.hn);
n = true;
}
if (this.rn != t.rn){
l.set(114, t.rn);
n = true;
}
if (this.an != t.an){
l.set(115, t.an);
n = true;
}
if (n && !t.isNonDefault()){
l = new Map<number,number>();
l.set(0,0);
}
return n ? l : null;
}
isProtected():boolean{ // minified as ".ds"
return (this.classicBits & FieldConstants.FIELD_ATTRIBUTE_PROTECTED) != 0;
}
ws():boolean{ // prototype.ws - no nice name yet
return 0 != (4 & this.validation);
}
vs():boolean{ // prototype.vs - no nice name yet
return 0 != (2 & this.validation);
}
isNonDefault():boolean{ // minified as "prototype.fs"
return ((0 != this.classicBits) ||
(0 != this.highlighting) ||
(0 != this.color) ||
(0 != this.backgroundColor) ||
(0 != this.characterSet) ||
(0 != this.outlining) ||
(0 != this.transparency) ||
(0 != this.validation) ||
(0 != this.sisoAllowed) ||
(0 != this.hn) ||
(0 != this.rn) ||
(0 != this.an));
}
un():boolean{ // (Xo.prototype.un = function () { no nice name yet
return 0 != this.hn || 0 != this.rn || 0 != this.an;
}
getHighlightingString():string{ // minified as "ps"
switch (this.highlighting) {
case 0:
return "00 Default";
case 240:
return "F0 Normal (By 3270 Attribute)";
case 241:
return "F1 Blink";
case 242:
return "F2 Reverse";
case 244:
return "F3 Underscore";
default:
return "Unknown " + this.highlighting;
}
}
getColorString(useBackground:boolean):string{ // minified as As(t)
if (!useBackground && this.un()){
return "RGB " + this.hn + "," + this.rn + "," + this.an;
}
var color = useBackground ? this.backgroundColor : this.color;
switch (color) {
case 0:
return "00 Default (By QueryReply)";
case 240:
return "F0 Neutral (Black on Display)";
case 241:
return "F1 Blue";
case 242:
return "F2 Red";
case 243:
return "F3 Pink";
case 244:
return "F4 Green";
case 245:
return "F5 Turquoise";
case 246:
return "F6 Yellow";
case 247:
return "F7 Neutral (White on Displays)";
case 248:
return "F8 Black";
case 249:
return "F9 Deep Blue";
case 250:
return "FA Orange";
case 251:
return "FB Purple";
case 252:
return "FC Pale Green";
case 253:
return "FD Pale Turquoise";
case 254:
return "FE Grey";
case 255:
return "FF White";
default:
return "Unknown Color" + color;
}
}
/*
This is only called from lc.prototype.$u (handleWriteOrders(t)
lc == VirtualScreen3270
t is a numerical key probably from orders or structuredFields, or some such
mabye bs(orderType,order) orders of 40 (SET_ATTR) and 41 (START_FIELD_EXTENDED) seen
// returns true if any garbage data seen
*/
incorporateSFE(orderKey:number,order:any):any[]|null { // (Xo.prototype.bs = function (t, l) {
var props = Object.keys(order);
let updateResults:any[] = [];
for (var n = 0; n < props.length; n++) {
var propertyName = props[n];
var value = order[propertyName];
if (propertyName.startsWith("0x")) {
var numericalKey = parseInt(propertyName.substring(2), 16);
let l = this.update(orderKey, numericalKey, value);
updateResults.push(l);
}
}
if (updateResults && !updateResults.every((t) => t.status)){
return updateResults;
} else {
return null; // implicitly return unbound, ugh - now null, but still falsy
}
}
static ATTRIBUTE_CLASSIC_BITS = 0xC0;
static ATTRIBUTE_VALIDATION = 0xC1;
static ATTRIBUTE_OUTLINING = 0xC2;
static ATTRIBUTE_HIGHLIGHTING = 0x41;
static ATTRIBUTE_COLOR = 0x42;
static ATTRIBUTE_CHARSET = 0x43;
static ATTRIBUTE_BACKGROUND_COLOR = 0x45;
static ATTRIBUTE_TRANSPARENCY = 0x46;
static ATTRIBUTE_SISO = 0xFE;
update(t:any, attributeType:number, attributeValue:number):any{ // (Xo.prototype.update = function (t, l, n) {
let logger = Utils.protocolLogger;
switch (attributeType) {
case 0:
if (0 != attributeValue){
logger.warn("Character attribute update: clear attribute (0x0) must be followed by 0x0, but was=0x" + Utils.hexString(attributeValue));
}
this.classicBits = 0;
this.highlighting = 0;
this.color = 0;
this.characterSet = 0;
this.outlining = 0;
this.transparency = 0;
this.validation = 0;
this.sisoAllowed = 0;
this.hn = 0;
this.rn = 0;
this.an = 0;
break;
case CharacterAttributes3270.ATTRIBUTE_CLASSIC_BITS:
this.classicBits = attributeValue;
break;
case CharacterAttributes3270.ATTRIBUTE_VALIDATION:
this.validation = attributeValue;
break;
case CharacterAttributes3270.ATTRIBUTE_OUTLINING:
this.outlining = attributeValue;
break;
case CharacterAttributes3270.ATTRIBUTE_HIGHLIGHTING:
if (0 !== attributeValue){
let i = attributeValue - 240;
if (3 == i || i > 4 || i < 0){
logger.warn("Unexpected invaild attribute type=0x" +
Utils.hexString(attributeValue));
return { code: "753", type: "ext_highlingting", status: !1, gs: "1003" };
}
}
this.highlighting = attributeValue;;
break;
case CharacterAttributes3270.ATTRIBUTE_COLOR:
if (0 !== attributeValue){
let i = attributeValue - 240;
if (i > 15 || i < 0) {
logger.warn("Unexpected invaild attribute type=0x" +
Utils.hexString(attributeValue));
return { code: "753", type: "ext_color", status: !1, gs: "1003" };
}
}
this.color = attributeValue;
break;
case CharacterAttributes3270.ATTRIBUTE_CHARSET:
this.characterSet = attributeValue;
break;
case CharacterAttributes3270.ATTRIBUTE_BACKGROUND_COLOR:
this.backgroundColor = attributeValue;
break;
case CharacterAttributes3270.ATTRIBUTE_TRANSPARENCY:
this.transparency = attributeValue;
break;
case 113:
this.hn = attributeValue;
break;
case 114:
this.rn = attributeValue;
break;
case 115:
this.an = attributeValue;
break;
case 254:
this.sisoAllowed = attributeValue;
break;
default:
logger.warn("Unexpected field/char attribute type=0x" + Utils.hexString(attributeType));
return (41 === t ?
{ code: "752", type: "attribute_type", status: false, gs: "1005" } :
{ code: "752", type: "attribute_type", status: false, gs: "1003" }
);
}
return { status: true };
}
}
class FieldConstants {
static FIELD_ATTRIBUTE_PRINTABLILITY_MASK =0xC0;
static FIELD_ATTRIBUTE_PROTECTED = 0x20;
static FIELD_ATTRIBUTE_NUMERIC = 0x10;
static FIELD_ATTRIBUTE_DISPLAY_MASK = 0x0c;
static FIELD_ATTRIBUTE_MODIFIED = 0x01;
static FIELD_ATTRIBUTE_DISPLAY_NOT_DETECTABLE = 0x00;
static FIELD_ATTRIBUTE_DISPLAY_DETECTABLE = 0x04;
static FIELD_ATTRIBUTE_INTENSIFIED_DETECTABLE = 0x08;
static FIELD_ATTRIBUTE_NO_DISPLAY_NOT_DETECTABLE = 0x0c;
}
class FieldData3270 extends FieldData { // minified $o
attributes:CharacterAttributes3270;
precedingSBAOrder:any;
length:number;
constructor(attributes:CharacterAttributes3270, position:number){
super(position);
this.attributes = attributes;
this.precedingSBAOrder = null; // not renamed yet from minification was this.as
this.length = 0; // what does this mean in this context
}
toString():string{
return ("<FieldData3270: position=" +
this.position +
" color=0x" +
Utils.hexString(this.attributes.color) +
" attr=0x" +
Utils.hexString(this.attributes.classicBits) +
(0 != this.attributes.sisoAllowed ? " SO/SI allowed" : "") +
(0 != this.attributes.characterSet ? " charset=0x" + Utils.hexString(this.attributes.characterSet) : "") +
">"
);
}
isNoDisplay():boolean{ // formerly prototype.pn()
return ((this.attributes.classicBits & FieldConstants.FIELD_ATTRIBUTE_DISPLAY_MASK) ==
FieldConstants.FIELD_ATTRIBUTE_NO_DISPLAY_NOT_DETECTABLE);
}
setModified():void{ // minified as "prototype.Es()"
this.attributes.classicBits |= 1;
}
clearModified():void{ // minified as "prototype.ms()"
this.attributes.classicBits &= 254;
}
isModified():boolean{ // minified as "prototype.Hl()"
return (this.attributes.classicBits & 1) != 0;
}
ks():boolean{ // looks like it isProtectedNumeric, which is weird
return (this.attributes.classicBits & 0x30) == 0x30;
}
isDisplayNotDetectable():boolean { // minified as "prottype.Ss()"
return ((this.attributes.classicBits & FieldConstants.FIELD_ATTRIBUTE_DISPLAY_MASK) ==
FieldConstants.FIELD_ATTRIBUTE_DISPLAY_NOT_DETECTABLE);
}
isEditable():boolean{ // minified as "prototype.dn"
return (this.attributes.classicBits & FieldConstants.FIELD_ATTRIBUTE_PROTECTED) == 0;
}
}
class Field { // minified as Fo
fieldData:FieldData3270;
start:number;
end:number;
Ie?:number; // poorly understood see note in method contains()
constructor(fieldData:FieldData3270, start:number, end:number){
this.fieldData = fieldData; // was this.zl
this.start = start;
this.end = end;
}
size(screenSize:number):number{ // minified as I(t)
if (this.end > this.start) { // non-wrapping
return this.end - this.start;
} else {
return this.end + (screenSize - this.start);
}
}
/* this is terribly weird method with "this.Ie" coming out of nowhere
But it doesn't appear to be called, which is good.
*/
contains(position:number):boolean{ // (Fo.prototype.contains = function (t) {
if (!this.Ie){
throw "Illegal State this.Ie is not set";
}
return this.Ie >= this.start && this.Ie < this.end;
}
toString():string{
return "<Field " + this.fieldData + " from " + this.start + " to " + this.end + ">";
}
}
/* This stupid thing is not always built in every conversaion and is shitty in general
and its parts are specifically shitty.
*/
class TN3270Capabilities { // Zo = function (t, l, n, i, e, s, u) {
$e:any;
ts:any;
ls:any;
ns:any;
es:any;
ss:any;
us:any;
constructor(t:any,l:any,n:any,i:any,e:any,s:any,u:any){
this.$e = t;
this.ts = l;
this.ls = n;
this.ns = i;
this.es = e;
this.ss = s;
this.us = u;
}
}
export class DeviceType3270 {
constructor(){
}
static rs = { type: 1, string: "IBM-3278-2", height: 24, width: 80 };
static as = { type: 2, string: "IBM-3278-2-E", isExtended: !0, height: 24, width: 80 };
static deviceType1E = DeviceType3270.as;
static os = { type: 3, string: "IBM-3278-3", height: 32, width: 80 };
static cs = { type: 4, string: "IBM-3278-3-E", isExtended: !0, height: 32, width: 80 };
static deviceType2E = DeviceType3270.cs;
static fs = { type: 5, string: "IBM-3278-4", height: 43, width: 80 };
static ds = { type: 6, string: "IBM-3278-4-E", isExtended: !0, height: 43, width: 80 };
static deviceType3E = DeviceType3270.ds;
static ws = { type: 7, string: "IBM-3278-5", height: 27, width: 132 };
static vs = { type: 8, string: "IBM-3278-5-E", isExtended: !0, height: 27, width: 132 };
static deviceType4E = DeviceType3270.vs;
static ps = { type: 9, string: "IBM-DYNAMIC", isExtended: !0 };
}
export class TN3270EParser{ // minified as ic
screen:VirtualScreen3270;
messageName:string;
state:number;
previousByte:number;
subData:any[];
messageData:any[];
outerMessagePos:number;
responseBuffer:any[];
tn3270EMode:boolean;
printableChars:any[];
sequenceNumber:number;
capabilitiesToOffer:number[];
atEndOfHostMessage:boolean;
// these fields are a duplicate of fields in VirtualScreen3270
// and there is no reason for this duplication. It's probably
// a vestige of an ancient factoring that missed some details
usingAlternateSize:boolean;
currentPartitionID:number = 0; // JOE - I think this is OK for initial state
partitionState:number;
partitionInfoMap:any;
// poorly understood fields
Bu:boolean;
sh:boolean;
aa:boolean;
qh:number;
Jh:number;
lastHeader:any;
xu:any; // horrible thing that only seems to be used w/o being set
constructor(virtualScreen:VirtualScreen3270,
messageName:string) { // seen messageName of "3270_CLIENT_MESSAGE"
this.messageName = messageName; // don't really like instance var name, was this.ri
this.screen = virtualScreen;
this.state = 0; // indexes telnetStateNames [0 to 3]
this.previousByte = 0; // minimized as this.ui
this.subData = []; // minimized as this.hi = [] - only holds data for TELENT/TN3270E sub negotiation
this.messageData = []; // this.sa = []; message data as opposed to subData
this.outerMessagePos = 0; //this.ua = 0; this syncs 0 to the 5-byte header
this.responseBuffer = []; // minified as this.si
this.tn3270EMode = false; // this.Zh = false; because we handle NVT, too
this.printableChars = []; // this.ha = []; used when reading orders out of WRITE_COMMAND_xxx
this.sequenceNumber= 0;
// note that Rs and TS are "globals"
this.capabilitiesToOffer = (virtualScreen.useBetterCapabilities ? // was this.ra
TN3270EParser.betterCapabilities :
TN3270EParser.regularCapabilities);
this.atEndOfHostMessage = false; // this.Yh = false; - long-winded name, but
this.usingAlternateSize = virtualScreen.usingAlternateSize;
this.partitionState = virtualScreen.partitionState; // this.Os
this.partitionInfoMap = virtualScreen.partitionInfoMap;
this.Bu = true; // something about echoing, but used as both capability and state it seems
this.sh = false
this.aa = false; // this is managed by telnet negotiation, but not used meaningfully
/* These are bit fields with the 1,2,4,8 set in in protocol negotiation
- when all four bits are set, the hh/process loop chooses NVT or TN3270E convo types
bit 1
bit 2
bit 4
bit 8
*/
this.qh = 0;
this.Jh = 0;
// JOE found and brought these properties to the constructor
this.lastHeader = null; // minified this.va = null;
}
static regularCapabilities = [3, 7, 0, 2, 4]; // minified as Ts
static betterCapabilities = [3, 7, 0, 2, 4, 5, 7]; // minified as Rs
static failureExplanations:any = {
"CONN-PARTNER": "The requested LU Name is associated with another terminal.",
"DEVICE-IN-USE": "The requested LU Name is already in use with another session.",
"INV-ASSOCIATE": "The requested Device Type is not a printer or the associated LU Name is not a terminal.",
"INV-NAME": "The LU Name is not known to the server.",
"INV-DEVICE-TYPE": "The server does not support the requested Device Type.",
"TYPE-NAME-ERROR": "The requested LU Name is incompatible with the requested Device Type.",
"UNKNOWN-ERROR": "The server rejected the connection but did not give a specific reason.",
"UNSUPPORTED-REQ": "The server is unable to satisfy a client request.",
UNKNOWN: "Unknown error."
}
static WCC_ALARM = 0x04;
static WCC_KEYBOARD_RESTORE = 0x02;
static WCC_MDT_RESET = 0x01;
static COMMAND_WRITE = 0xF1; // 241
static COMMAND_WRITE_LOCAL = 0x01;
static COMMAND_WRITE_ASCII = 0x31; // 49
static COMMAND_ERASE_WRITE = 0xF5; // 245
static COMMAND_ERASE_WRITE_LOCAL = 0x05; // 5
static COMMAND_ERASE_WRITE_ASCII = 0x35; // 53
static COMMAND_ERASE_WRITE_ALTERNATE = 0x7E; // 126
static COMMAND_ERASE_WRITE_ALTERNATE_LOCAL = 0x0D; // 13
static COMMAND_ERASE_WRITE_ALTERNATE_ASCII = 0x3D; // 61
static COMMAND_ERASE_ALL_UNPROTECTED = 0x6F; // 111
static COMMAND_ERASE_ALL_UNPROTECTED_LOCAL = 0x0F; //15
static COMMAND_ERASE_ALL_UNPROTECTED_ASCII = 0x3F; // 63
static COMMAND_WRITE_STRUCTURED_FIELD = 0xF3; // 243
static COMMAND_WRITE_STRUCTURED_FIELD_LOCAL = 0x11; // 17
static COMMAND_READ_BUFFER = 0xF2; // 242
static COMMAND_READ_BUFFER_LOCAL = 0x02;
static COMMAND_READ_BUFFER_ASCII = 0x32;
static COMMAND_READ_MODIFIED = 0xF6; // 246
static COMMAND_READ_MODIFIED_LOCAL = 0x06;
static COMMAND_READ_MODIFIED_ASCII = 0x36;
static COMMAND_READ_MODIFIED_ALL = 0x6E; // 110
static COMMAND_READ_MODIFIED_ALL_LOCAL = 0x0e;
static COMMAND_READ_MODIFIED_ALL_ASCII = 0x3D;
// Orders are the sub-messages of write commands
static ORDER_START_FIELD = 0x1D; // 29
static ORDER_START_FIELD_EXTENDED = 0x29; // 41
static ORDER_SET_BUFFER_ADDRESS = 0x11; // 17
static ORDER_SET_ATTRIBUTE = 0x28;
static ORDER_INSERT_CURSOR = 0x13;
static ORDER_MODIFY_FIELD = 0x2C;
static ORDER_PROGRAM_TAB = 0x05;
static ORDER_REPEAT_TO_ADDRESS = 0x3C;
static ORDER_ERASE_UNPROTECTED_TO_ADDRESS = 0x12;
static ORDER_GRAPHIC_ESCAPE = 0x08;
// Structured Fields are the submessages of COMMAND_WRITE_STRUCTURED_FIELD
static STRFLD_RESET_PARTN = 0x00;
static STRFLD_READ_PARTN = 0x01;
static STRFLD_ERASE_RESET = 0x03;
static STRFLD_LOAD_PROGRAMMED_SYMBOLS = 0x06;
static STRFLD_SET_REPLY_MODE = 0x09;
static STRFLD_SET_WINDOW_ORIGIN = 0x0B;
static STRFLD_CREATE_PARTN = 0x0C;
static STRFLD_DESTROY_PARTN = 0x0D;
static STRFLD_ACTIVATE_PARTN = 0x0E;
static STRFLD_UNKNOWN_000F = 0x0F;
static STRFLD_UNKNOWN_0010 = 0x10;
static STRFLD_OUTBOUND_3270_DATA_STREAM = 0x40;
static STRFLD_SCS_DATA = 0x41;
static STRFLD_SELECT_FORMAT_GROUP = 0x4A;
static STRFLD_PRESENT_ABSOLUTE_FORMAT = 0x4B;
static STRFLD_PRESENT_RELATIVE_FORMAT = 0x4C;
static STRFLD_INBOUND_3270_DATA_STREAM= 0x80;
static STRFLD_QUERY_REPLY = 0x81; // 129
static STRFLD_READ_PARTN_QUERY = 0x0102;
static STRFLD_READ_PARTN_QUERY_LIST = 0x0103;
static STRFLD_READ_PARTN_MODIFIED_ALL = 0x016E;
static STRFLD_READ_PARTN_BUFFER = 0x01F2;
static STRFLD_READ_PARTN_MODIFIED = 0x01F6;
static STRFLD_SET_MSR_CONTROL = 0x0F01; // 3841
static STRFLD_DESTINATION_ORIGIN = 0x0F02; // 3842
static STRFLD_SELECT_COLOR_TABLE = 0x0F04;
static STRFLD_LOAD_COLOR_TABLE = 0x0F05;
static STRFLD_LOAD_LINE_TYPE = 0x0F07;
static STRFLD_SET_PARTN_CHARACTERISTICS = 0x0F08;
static STRFLD_MODIFY_PARTN = 0x0F0A;
static STRFLD_OBJECT_DATA = 0x0F0F; // 3855
static STRFLD_OBJECT_PICTURE = 0x0F10; // 3856
static STRFLD_OBJECT_CONTROL = 0x0F11; // 3857
static STRFLD_OEM_DATA = 0x0F1F;
static STRFLD_DATA_CHAIN = 0x0F21;
static STRFLD_EXCEPTION_STATUS = 0x0F22;
static STRFLD_LOAD_FORMAT_STORAGE = 0x0F24;
static STRFLD_SELECT_IPDS_MODE = 0x0F83;
static STRFLD_SET_PRINTER_CHARACTERISTICS = 0x0F84;
static STRFLD_BEGIN_END_FILE = 0x0F85;
static STRFLD_INBOUND_TEXT_HEADER = 0x0FB1;
static STRFLD_TYPE1_TEXT_OUTBOUND = 0x0FC1;
// http://bitsavers.org/pdf/ibm/3270/GA23-0059-07_3270_Data_Stream_Programmers_Reference_199206.pdf
static STRFLD_PCLK_PROTOCOL = 0x1013; // even wireshark doesn't know what this is!
static STRFLD_REQUEST_RECOVERY_DATA = 0x1030;
static STRFLD_RECOVERY_DATA = 0x1031;
static STRFLD_SET_CHECKPOINT_INTERVAL = 0x1032;
static STRFLD_RESTART = 0x1033;
static STRFLD_SAVE_RESTORE_PANEL = 0x1034;
// PF1 is F1
// PF9 is F9
// PF10 is 7A
// PF11 is 7B
// PF12 is 7C
// PF13 is C1
// PF21 is C9
// PF22 is 4A
// PF23 is 4B
// PF24 is 4C
static AID_NO_AID = 0x60; // 96
static AID_STRUCTURED_FIELD = 0x88; // 136
static AID_READ_PARTITION = 0x61; // 97
static AID_TRIGGER_ACTION = 0x7f; // 127
static AID_CLEAR_PARTITION_KEY = 0x6a; // 106
static AID_PA3 = 0x6b; // 107
static AID_PA1 = 0x6c; // 108
static AID_CLEAR_KEY = 0x6d; // 109
static AID_PA2 = 0x6e; // 110
static AID_ENTER_KEY = 0x7d; // 125
static AID_SELECTOR_PEN_MOUSE = 0x7e; // 126
// sysreq 0xF0 - 240
static IAC = 0xFF; // 255
static DONT = 0xFE; // 254
static DO = 0xFD; // 253
static WONT = 0xFC; // 252
static WILL = 0xFB; // 251
static SB = 0xFA; // 250
static AO = 0xF5; // 245 - abort output
static IP = 0xF4; // 244 - interrupt process
static BREAK = 0xF3; // 243 - Break (see RFC)
static DM = 0xF2; // 242 - Data Mark
static NOP = 0xF1; // 241
static SE = 0xF0; // 240
static EOR = 0xEF; // 239
static OPTION_BINARY_XMIT = 0;
static OPTION_ECHO = 1;
static OPTION_SUPPRESS_GO_AHEAD = 3;
static OPTION_TTYPE = 0x18; // 24 - will occur in SB/SE sequences
static OPTION_EOR = 0x19; // 25 - end of record
static OPTION_TN3270E = 0x28; // 40
// from RFC2355
static DATA_TYPE_3270 = 0;
static DATA_TYPE_SCS = 1;
static DATA_TYPE_RESPONSE = 2;
static DATA_TYPE_BIND_IMAGE = 3;
static DATA_TYPE_UNBIND = 4;
static DATA_TYPE_NVT = 5;
static DATA_TYPE_REQUEST = 6;
static DATA_TYPE_SSCPLU = 7;
static DATA_TYPE_PRINT_EOJ = 8;
static DATA_TYPE_9 = 9; // this is a bit mysterious
static PARSE_STATE_NONE = 0;
static PARSE_STATE_OPTION = 1;
static PARSE_STATE_SUB = 2;
static PARSE_STATE_VERB = 3;
// TN3270E response Flags see RFC 2355
static NO_RESPONSE = 0;
static ERROR_RESPONSE = 1;
static ALWAYS_RESPONSE = 2;
static telnetStateNames = ["TELNET_NO_STATE", "PARSER_TELNET_OPTION",
"PARSER_TELNET_SUB", "PARSER_TELNET_VERB"];
// NVT is network virtual terminal
addTelnetResponse(b1:number, b2:number){ // ic.prototype.ea = function(byte, inputByte){
// this thing accumulates a response byte
this.responseBuffer.push(255);
this.responseBuffer.push(b1);
if (Number(b2) >= 0){
this.responseBuffer.push(b2);
}
}
handleTelnetNegotiation(b:number){ // t is the first negotiation byte (ic.prototype.wa = function (t) {
let logger = Utils.telnetLogger;
logger.debug("Handling telnet option");
logger.debug("-- b=0x" + Utils.hexString(b));
switch (this.previousByte) {
case TN3270EParser.DO:
logger.debug("-- Verb=DO");
switch (b) {
case TN3270EParser.OPTION_TN3270E:
if (this.screen.enableTN3270E){
this.addTelnetResponse(TN3270EParser.WILL, b);
this.screen.convoType = VirtualScreen3270.convoTypes.LULU;
console.log("JOE postload going TN3270E");
this.screen.inTN3270EMode = true;
this.tn3270EMode = true;
} else {
this.addTelnetResponse(TN3270EParser.WONT, b);
}
break;
case 24:
this.aa = !0;
this.addTelnetResponse(TN3270EParser.WILL, b);
break;
case 25:
this.Jh |= 1;
if (0 == (8 & this.Jh)){
this.Jh |= 8;
}
this.addTelnetResponse(TN3270EParser.WILL, b);
break;
case 0:
this.qh |= 1;
if (0 == (8 & this.qh)){
this.qh |= 8;
}
this.addTelnetResponse(TN3270EParser.WILL, b);
break;
case 1:
if (this.aa){
this.Bu = !1;
this.addTelnetResponse(TN3270EParser.WONT, b);
} else {
this.Bu = !0;
this.addTelnetResponse(TN3270EParser.WILL, b);
}
break;
case 3:
this.sh = !1;
this.addTelnetResponse(TN3270EParser.WILL, b);
break;
case 5:
case 31:
case 32:
case 39:
default:
logger.warn("Defaulted on DO, sending WONT for b=0x" + Utils.hexString(b));
this.addTelnetResponse(TN3270EParser.WONT, b);
}
break;
case TN3270EParser.DONT:
logger.debug("-- Verb=DONT");
switch (b) {
case TN3270EParser.OPTION_TN3270E:
this.screen.inTN3270EMode = false;
this.tn3270EMode = false;
this.addTelnetResponse(TN3270EParser.WONT, b);
break;
case 1:
(this.Bu = !1);
this.addTelnetResponse(TN3270EParser.WONT, b);
break;
case 25:
(this.Jh = 0);
this.addTelnetResponse(TN3270EParser.WONT, b);
break;
case 0:
(this.qh = 0);
this.addTelnetResponse(TN3270EParser.WONT, b);
break;
case 3:
case 31:
default:
this.addTelnetResponse(TN3270EParser.WONT, b);
logger.warn("Defaulted on DONT, sending WONT for b=0x" + Utils.hexString(b));
}
break;
case TN3270EParser.WONT:
logger.debug("-- Verb=WONT");
switch (b) {
case TN3270EParser.OPTION_TN3270E:
logger.warn("Server responded to TN3270 option with WONT, closing connection");
this.screen.closeConnection(4e3, "Terminal Closed"); // JOE maybe something more specific
break;
case 6:
case 1:
break;
case 0:
this.qh = 0;
case 3:
default:
this.addTelnetResponse(TN3270EParser.DONT, b);
logger.warn("Defaulted on WONT, sending DONT for b=0x" + Utils.hexString(b));
}
break;
case TN3270EParser.WILL:
logger.debug("-- Verb=WILL");
switch (b) {
case 0:
this.qh |= 2;
if (0 == (4 & this.qh)){
this.qh |= 4;
}
this.addTelnetResponse(TN3270EParser.DO, b);
break;
case 25:
this.Jh |= 2;
if (0 == (4 & this.Jh)){
this.Jh |= 4;
}
this.addTelnetResponse(TN3270EParser.DO, b);
break;
case 1:
if (this.aa){
this.Bu = !1;
this.addTelnetResponse(TN3270EParser.DONT, b);
} else {
this.Bu = !0;
this.addTelnetResponse(TN3270EParser.DO, b);
}
break;
case 3:
this.sh = !1;
this.addTelnetResponse(TN3270EParser.DO, b);
break;
case TN3270EParser.OPTION_TN3270E:
if (this.screen.enableTN3270E){ // JOE originally said this.enableTN3270E which is nuts
this.screen.convoType = VirtualScreen3270.convoTypes.LULU;
console.log("JOE postload going TN3270E");
this.screen.inTN3270EMode = true;
this.tn3270EMode = true;
this.addTelnetResponse(TN3270EParser.DO, b);
} else {
this.addTelnetResponse(TN3270EParser.DONT, b);
}
break;
case 29:
case 5:
case 38:
default:
this.addTelnetResponse(TN3270EParser.DONT, b);
logger.warn("Ignoring WILL for b=0x" + Utils.hexString(b));
}
}
}
/*
handleSub cannot be understood w/o RFC's
*/
handleSub() { // (ic.prototype.ca = function () {
var screen = this.screen; // was t
var l = this.subData.length;
let nextState = 0; // was n
let logger = Utils.telnetLogger;
var i = 0;
if (screen.deviceType){
i = screen.deviceType.string.length;
}