-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebTerminal-v4.2.0.xml
2141 lines (1976 loc) · 313 KB
/
WebTerminal-v4.2.0.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2017.2 (Build 543U)" ts="2017-01-26 22:23:54">
<Class name="WebTerminal.Analytics">
<Description>
This class includes methods which collect WebTerminal's analytics such as error and installation reports.</Description>
<TimeChanged>64156,2938.359142</TimeChanged>
<TimeCreated>64154,83594.957495</TimeCreated>
<Method name="ReportInstallStatus">
<Description>
This method sends a report about installation status, including error message if any errors happened.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>status:%Status=1,type:%String="Install"</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
set req = ##class(%Net.HttpRequest).%New()
set req.Server = "www.google-analytics.com"
do req.EntityBody.Write("v=1&tid=UA-83005064-2&cid="_##class(%SYS.System).InstanceGUID()
_"&ds=web&an=WebTerminal&av="_##class(WebTerminal.Installer).#VERSION
_"&t=event&aiid="_$ZCONVERT($zv, "O", "URL")_"&ec="_$ZCONVERT(type, "O", "URL")_"&ea="
_$case($$$ISOK(status), 1: "Success", : "Failure")_"&el="
_$ZCONVERT($System.Status.GetErrorText(status), "O", "URL"))
return req.Post("/collect")
]]></Implementation>
</Method>
</Class>
<Class name="WebTerminal.Autocomplete">
<Super>Common</Super>
<TimeChanged>64158,30936.478852</TimeChanged>
<TimeCreated>63906,49098.662696</TimeCreated>
<Method name="GetGlobals">
<Description>
Returns a comma-delimited string of globals names in the namespace, which begin from "beginning".</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>namespace:%String="%SYS",beginning:%String=""</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
set result = ""
set pattern = beginning _ "*"
new $Namespace
set $Namespace = namespace
set rset = ##class(%ResultSet).%New("%SYS.GlobalQuery:NameSpaceList")
do rset.Execute($Namespace, pattern, 0)
while (rset.Next()) {
set result = result _ $case(result = "", 1:"", :",") _ rset.GetData(1)
}
return result
]]></Implementation>
</Method>
<Method name="GetClass">
<Description>
Returns a comma-delimited string of class names in the namespace, which begin from "beginning".</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>namespace:%String="%SYS",beginning:%String=""</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
new $Namespace
set $Namespace = namespace
set pattern = $REPLACE(beginning, "%", "!%") _ "%"
&sql(select LIST(ID) into :ids from %Dictionary.CompiledClass where ID like :pattern ESCAPE '!' and deployed <> 2)
return ids
]]></Implementation>
</Method>
<Method name="GetPublicClassMembers">
<Description>
Returns a comma-delimited string of public class members (accessible through ##class() construction) in the class of namespace.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>namespace:%String="%SYS",className:%String="",beginning:%String=""</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
new $Namespace
set $Namespace = namespace
set pattern = $REPLACE(beginning, "%", "!%") _ "%"
&sql(select LIST(Name) into :names from %Dictionary.CompiledMethod WHERE parent=:className AND ClassMethod=1 AND Name like :pattern ESCAPE '!')
return names
]]></Implementation>
</Method>
<Method name="GetClassMembers">
<Description>
Returns a comma-delimited string of class members in the class of namespace.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>namespace:%String="%SYS",className:%String="",beginning:%String="",methodsOnly=""</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
new $Namespace
set $Namespace = namespace
if $EXTRACT(beginning, 1) = "#" {
set ps = ..GetParameters(namespace, className, $EXTRACT(beginning, 2, $LENGTH(beginning)))
return:(ps = "") ps
return "#"_$REPLACE(ps, ",", ",#")
}
set pattern = $REPLACE(beginning, "%", "!%") _ "%"
set props = ""
&sql(select LIST(Name) into :methods from %Dictionary.CompiledMethod WHERE parent=:className AND Private = 0 AND Name like :pattern ESCAPE '!')
if (methodsOnly = "") {
&sql(select LIST(Name) into :props from %Dictionary.CompiledProperty WHERE parent=:className AND Name like :pattern ESCAPE '!')
}
return $case((methods '= "") && (props '= ""), 1: methods _ "," _ props, : methods _ props)
]]></Implementation>
</Method>
<Method name="GetParameters">
<Description>
Returns a comma-delimited string of class members in the class of namespace.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>namespace:%String="%SYS",className:%String="",beginning:%String=""</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
new $Namespace
set $Namespace = namespace
set pattern = $REPLACE(beginning, "%", "!%") _ "%"
&sql(select LIST(Name) into :names from %Dictionary.CompiledParameter WHERE parent=:className AND Name like :pattern ESCAPE '!')
return names
]]></Implementation>
</Method>
<Method name="GetRoutines">
<Description>
Returns a comma-delimited string of routine names in the namespace, which begin from "beginning".</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>namespace:%String="%SYS",beginning:%String=""</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
set result = ""
set pattern = beginning _ "*.*"
new $Namespace
set $Namespace = namespace
set rset = ##class(%ResultSet).%New("%Library.Routine:RoutineList")
do rset.Execute(pattern, , , $Namespace)
while (rset.Next()) {
set result = result _ $case(result = "", 1:"", :",") _ $PIECE(rset.GetData(1), ".", 1, *-1)
}
return result
]]></Implementation>
</Method>
</Class>
<Class name="WebTerminal.Common">
<IncludeCode>%sySystem</IncludeCode>
<TimeChanged>64303,79547.197274</TimeChanged>
<TimeCreated>63906,39668.673891</TimeCreated>
<Parameter name="ChunkSize">
<Description>
Interprocess communication cannot handle big messages at once, so they need to be split.</Description>
<Default>45</Default>
</Parameter>
<Method name="SendChunk">
<Description>
Send the chunk of data to another process. The process need to receive the chunk with the
appropriate function ReceiveChunk. Consider event length less than 44 characters long.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pid:%Numeric,flag:%String,data:%String=""</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
set pos = 1
set len = $LENGTH(data) + 1 // send the last empty message if the data size = ChunkSize
for {
try {
set st = $system.Event.Signal(
pid,
$LB(flag, $EXTRACT(data, pos, pos + ..#ChunkSize - 1))
)
} catch (e) { return $$$NOTOK }
if (st '= 1) { return $$$NOTOK }
set pos = pos + ..#ChunkSize
if (pos > len) { quit }
}
return $$$OK
]]></Implementation>
</Method>
<Method name="ReceiveChunk">
<Description>
Receives the chunk of data from another process. Returns the $LISTBUILD string which contains
flag at the first position and string at the second. This method also terminates the process
if the parent process is gone.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>timeout:%Numeric=-1</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
set flag = ""
set str = ""
for {
set message = $system.Event.WaitMsg("", $Case(timeout = -1, 1: 1, :timeout))
set data = $LISTGET(message, 2)
if (data = "") && (timeout = 0) quit
set status = $LISTGET(message, 1)
if (status <= 0) {
do:'$data(^$Job($ZPARENT)) $system.Process.Terminate($JOB, 0)
if (timeout = 0) set timeout = 1
continue
}
set flag = $LISTGET(data, 1)
set m = $LISTGET(data, 2)
set str = str _ m
if (timeout = 0) set timeout = 1
quit:($LENGTH(m) '= ..#ChunkSize)
}
return $LISTBUILD(flag, str)
]]></Implementation>
</Method>
<Method name="GetJSONString">
<Description><![CDATA[
Returns the contents of the proxy object to the current device in JSON format.<br/>
This method is called when a proxy object is used in conjunction with
the <class>%ZEN.Auxiliary.jsonProvider</class> component.<br/>
<var>format</var> is a flags string to control output formatting options.<br/>
The following character option codes are supported:<br/>
1-9 : indent with this number of spaces (4 is the default with the 'i' format specifier)<br/>
a - output null arrays/objects<br/>
b - line break before opening { of objects<br/>
c - output the Caché-specific "_class" and "_id" properties (if a child property is an instance of a concrete object class)<br/>
e - output empty object properties<br/>
i - indent with 4 spaces unless 't' or 1-9<br/>
l - output empty lists<br/>
n - newline (lf)<br/>
o - output empty arrays/objects<br/>
q - output numeric values unquoted even when they come from a non-numeric property<br/>
s - use strict JSON output - <strong>NOTE:</strong> special care should be taken when sending data to a browser, as using this flag
may expose you to cross site scripting (XSS) vulnerabilities if the data is sent inside <code><script></code> tags. Zen uses
this technique extensively, so this flag should <strong>NOT</strong> be specified for jsonProviders in Zen pages.<br/>
t - indent with tab character<br/>
u - output pre-converted to UTF-8 instead of in native internal format<br/>
w - Windows-style cr/lf newline<br/>]]></Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>obj:%ZEN.proxyObject,format:%String="aeos"</FormalSpec>
<ProcedureBlock>0</ProcedureBlock>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
set tOldIORedirected = ##class(%Device).ReDirectIO()
set tOldMnemonic = ##class(%Device).GetMnemonicRoutine()
set tOldIO = $io
try {
set str = ""
use $io::("^" _ $ZNAME)
do ##class(%Device).ReDirectIO(1)
do ##class(%ZEN.Auxiliary.jsonProvider).%ObjectToJSON(obj,,,format)
} catch ex {
set str = ""
}
if (tOldMnemonic '= "") {
use tOldIO::("^" _ tOldMnemonic)
} else {
use tOldIO
}
do ##class(%Device).ReDirectIO(tOldIORedirected)
return str
rchr(c)
quit
rstr(sz,to)
quit
wchr(s)
do output($char(s))
quit
wff()
do output($char(12))
quit
wnl()
do output($char(13,10))
quit
wstr(s)
do output(s)
quit
wtab(s)
do output($char(9))
quit
output(s)
set str = str _ s
quit
]]></Implementation>
</Method>
</Class>
<Class name="WebTerminal.Core">
<Description>
Cache WEB Terminal version 4.2.0 core.
The core class which handles client requests and executes COS code.
All writes used here are used for $X and $Y compatibility, but they actually do not
write any code to the screen.</Description>
<ProcedureBlock>0</ProcedureBlock>
<Super>Common</Super>
<TimeChanged>64309,80475.865804</TimeChanged>
<TimeCreated>64075,84588.808108</TimeCreated>
<Method name="redirects">
<Description>
Write and read redirects used when redirecting i/o.
Each of the redirects signals to $ZPARENT process the $LISTBUILD string.
There is several actions defined in the WebTerminal.Engine handler class for received list.
"o" is for output. Resulting with $lb("o", {string})
"r" is for reading string. Resulting with $lb("r", {length}, {timeout})
"rc" is for reading char. Resulting with $lb("rc", {timeout})
"end" symbolizes that execution end is reached. Resulting with $lb("end", {error message})</Description>
<Private>1</Private>
<ProcedureBlock>0</ProcedureBlock>
<Implementation><![CDATA[
wstr(str)
do ##class(%Device).ReDirectIO($$$NO)
write str
do ##class(%Device).ReDirectIO($$$YES)
quit ##class(WebTerminal.Common).SendChunk($ZPARENT, "o", str)
wchr(c)
do ##class(%Device).ReDirectIO($$$NO)
write $CHAR(c)
do ##class(%Device).ReDirectIO($$$YES)
quit ##class(WebTerminal.Common).SendChunk($ZPARENT, "o", $CHAR(c))
wnl
do ##class(%Device).ReDirectIO($$$NO)
write !
do ##class(%Device).ReDirectIO($$$YES)
quit ##class(WebTerminal.Common).SendChunk($ZPARENT, "o", $CHAR(13, 10))
wff
do ##class(%Device).ReDirectIO($$$NO)
set $X = 0
set $Y = 0
do ##class(%Device).ReDirectIO($$$YES)
quit ##class(WebTerminal.Common).SendChunk($ZPARENT, "o", $CHAR(12))
wtab(s)
do ##class(%Device).ReDirectIO($$$NO)
set $x = s
do ##class(%Device).ReDirectIO($$$YES)
quit ##class(WebTerminal.Common).SendChunk($ZPARENT, "o", $CHAR(27) _ "[" _ (s + 1) _ "G")
rstr(length = 32656, timeout = 86400)
do ##class(WebTerminal.Common).SendChunk($ZPARENT, "r", $lb(length, timeout))
quit $LISTGET(##class(WebTerminal.Common).ReceiveChunk(), 2)
rchr(timeout = 86400)
do ##class(WebTerminal.Common).SendChunk($ZPARENT, "c", timeout)
quit $LISTGET(##class(WebTerminal.Common).ReceiveChunk(), 2)
erdx s $x=0 q
erdy s $y=0 q
APC ; Application program command
w $c(27)_"_"
q
BEL ; Ring the bell
w $c(7)
q
CBT(%1) ; Cursor backward tabulation %1 tab stops
s %1=+$g(%1,1) w $c(27,91)_%1_"Z" s $zt="erdx",$x=$x+7\8-%1*8
q
CCH ; Cancel character
w $c(27)_"T"
q
CHA(%1) ; Cursor horizontal absolute (move to column %1)
s %1=+$g(%1,1) w $c(27,91)_%1_"G" s $zt="erdx",$x=%1-1
q
CHT(%1) ; Cursor horizontal tabulation (forward %1 tab stops)
s %1=+$g(%1,1) w $c(27,91)_%1_"I" s $zt="erdx",$x=$x\8+%1*8
q
CNL(%1) ; Cursor next line (cursor down %1 lines)
s %1=+$g(%1,1) w $c(27,91)_%1_"E" s $zt="erdy",$y=$y+%1
q
CPL(%1) ; Cursor preceding line (cursor up %1 lines)
s %1=+$g(%1,1) w $c(27,91)_%1_"F" s $zt="erdy",$y=$y-%1
q
CPR ; Cursor position report (return in $KEY)
n %1 w $c(27,91)_"6n" r %1
q
CTC(%1,%2,%3,%4,%5,%6,%7,%8,%9) ; Cursor tabulation control
n %i,%p s %p=""
f %i=1:1:9 i $d(@("%"_%i)) s %p=%p_$e(";",%p'="")_@("%"_%i)
w $c(27,91)_%p_"W"
q
CUB(%1) ; Cursor backward %1 columns
s %1=+$g(%1,1) w $c(27,91)_%1_"D" s $zt="erdx",$x=$x-%1
q
CUD(%1) ; Cursor down %1 lines
s %1=+$g(%1,1) w $c(27,91)_%1_"B" s $zt="erdy",$y=$y+%1
q
CUF(%1) ; Cursor forward %1 columns
s %1=+$g(%1,1) w $c(27,91)_%1_"C" s $zt="erdx",$x=$x+%1
q
CUP(%2,%1) ; Cursor position (column %1, line %2)
s %1=+$g(%1,1),%2=+$g(%2,1) w $c(27,91)_%2_";"_%1_"H"
s $zt="ecup",$x=%1-1,$zt="erdy",$y=%2-1 q
ecup s $x=0,$zt="erdy",$y=%2-1
q
CUU(%1) ; Cursor up %1 lines
s %1=+$g(%1,1) w $c(27,91)_%1_"A" s $zt="erdy",$y=$y-%1
q
CVT(%1) ; Cursor vertical tabulation
w $c(27,91)_+$g(%1,1)_"Y"
q
DA ; Device attributes - return in $KEY
n %1,%2,%3 s %3="" u $i:("":"+S")
w $c(27,91)_"c" r %1 s %2=$k f r *%1 s %3=%3_$c(%1) q:%1=99
s $k=%2_%3 u $i:("":"-S")
q
DAQ(%1,%2,%3,%4,%5,%6,%7,%8,%9) ; Define area qualification
n %i,%p s %p=""
f %i=1:1:9 i $d(@("%"_%i)) s %p=%p_$e(";",%p'="")_@("%"_i)
w $c(27,91)_%p_"o"
q
DCH(%1) ; Delete %1 characters
w $c(27,91)_+$g(%1,1)_"P"
q
DCS ; Device control string
w $c(27)_"P"
q
DL(%1) ; Delete %1 lines
w $c(27,91)_+$g(%1,1)_"M"
q
DMI ; Disable manual input
q
DSR(%1) ; Device status report - type %1 - return in $KEY
n %2 w $c(27,91)_+$g(%1,5)_"n" r %2
q
EA(%1) ; Erase in area
w $c(27,91)_+$g(%1,1)_"O"
q
ECH(%1) ; Erase %1 characters
w $c(27,91)_+$g(%1,1)_"X"
q
ED(%1) ; Erase in display (%1=0 cursor-to-end,1 begin-to-cursor,2 entire scr)
w $c(27,91)_+$g(%1)_"J"
q
EF(%1) ; Erase in field
w $c(27,91)_+$g(%1,1)_"N"
q
EL(%1) ; Erase in line (%1=0 cursor-to-end, 1 begin-to-cursor, 2 entire line)
w $c(27,91)_+$g(%1)_"K"
q
EMI ; Enable manual input
q
EPA ; End of protected area
w $c(27)_"W"
q
ESA ; End of selected area
w $c(27)_"G"
q
FNT ; Font selection
q
GSM ; Graphic size modification
q
GSS ; Graphic size selection
q
HPA(%1) ; Horizontal position attribute (cursor to column %1)
s %1=+$g(%1,1) w $c(27,91)_%1_"`" s $zt="erdx",$x=%1-1
q
HPR(%1) ; Horizontal position relative (cursor forward %1 columns)
s %1=+$g(%1,1) w $c(27,91)_%1_"a" s $zt="erdx",$x=$x+%1
q
HTJ ; Horizontal tab with justify
w $c(27)_"I"
q
HTS ; Horizontal tabulation set
w $c(27)_"H"
q
HVP(%1,%2) ; Horizontal and vertical position (column %1, line %2)
s %1=+$g(%1,1),%2=+$g(%2,1) w $c(27,91)_%2_";"_%1_"f"
s $zt="ehvp",$x=%1-1,$zt="erdy",$y=%2-1 q
ehvp s $x=0,$zt="erdy",$y=%2-1
q
ICH(%1) ; Insert %1 characters
w $c(27,91)_+$g(%1,1)_"@"
q
IL(%1) ; Insert %1 lines
w $c(27,91)_+$g(%1,1),"L"
q
IND ; Index
w $c(27)_"D" s $y=$y+1
q
INT ; Interrupt
w $c(27,91)_"a"
q
JFY ; Justify
q
MC ; Media copy
w $c(27,91)_"i"
q
MW ; Message waiting
w $c(27)_"U"
q
NEL ; Next line
w $c(27)_"E" s $x=0,$y=$y+1
q
NP(%1) ; Next page (advance %1 pages of terminal display memory)
w $c(27,91)_+$g(%1,1)_"U"
q
OSC ; Operating system command
w $c(27)_"]"
q
PLD ; Partial line down
w $c(27)_"K"
q
PLU ; Partial line up
w $c(27)_"L"
q
PM ; Privacy message
w $c(27)_"^"
q
PP(%1) ; Preceding page (backup %1 pages of terminal display memory)
w $c(27,91)_+$g(%1,1)_"V"
q
PU1 ; Private use one
w $c(27)_"Q"
q
PU2 ; Private use two
w $c(27)_"R"
q
QUAD ; QUAD
q
REP ; Repeat
w $c(27,91)_"b"
q
RI ; Reverse index
w $c(27)_"M" s $zt="erdy",$y=$y-1
q
RIS ; Reset to initial state
w $c(27)_"c" s $x=0,$y=0
q
RM(%1,%2,%3,%4,%5,%6,%7,%8,%9) ; Reset mode
n %i,%p s %p=""
f %i=1:1:9 i $d(@("%"_%i)) s %p=%p_$e(";",%p'="")_@("%"_%i)
w $c(27,91)_%p_"l"
q
SEM ; Select editing extent mode
w $c(27,91)_"Q"
q
SGR(%1,%2,%3,%4,%5,%6,%7,%8,%9) ; Select graphic rendition %1 thru %9
n %i,%p s %p=""
f %i=1:1:9 i $d(@("%"_%i)) s %p=%p_$e(";",%p'="")_@("%"_%i)
w $c(27,91)_%p_"m"
q
SL ; Scroll left
q
SM(%1,%2,%3,%4,%5,%6,%7,%8,%9) ; Set mode
n %i,%p s %p=""
f %i=1:1:9 i $d(@("%"_%i)) s %p=%p_$e(";",%p'="")_@("%"_%i)
w $c(27,91)_%p_"h"
q
SPA ; Start of protected area
w $c(27)_"V"
q
SPI ; Spacing increment
q
SR ; Scroll right
q
SS2 ; Single shift two
w $c(27)_"N"
q
SS3 ; Single shift three
w $c(27)_"O"
q
SSA ; Start of selected area
w $c(27)_"F"
q
ST ; String terminator
w $c(27)_"\"
q
STS ; Set transmit state
w $c(27)_"S"
q
SU ; Scroll up
w $c(27,91)_"S"
q
TBC ; Tabulation clear
w $c(27,91)_"g"
q
TSS ; Thin space specification
q
VPA(%1) ; Vertical position attribute (move to row %1 at same column)
s %1=+$g(%1,1) w $c(27,91)_%1_"d" s $zt="erdy",$y=%1-1
q
VPR(%1) ; Vertical position relative (move down %1 lines at same column)
s %1=+$g(%1,1) w $c(27,91)_%1_"e" s $zt="erdy",$y=$y+%1
q
VTS ; Vertical tabulation sets
w $c(27)_"J"
q
]]></Implementation>
</Method>
<Method name="VarList">
<ClassMethod>1</ClassMethod>
<ProcedureBlock>1</ProcedureBlock>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
if $data(%)
new % set %=$select($test:$LISTBUILD("%"),1:"")
set:$data(%0) %=%_$LISTBUILD("%0")
new %0 set %0="%0"
for {
set %0=$ORDER(@%0)
quit:%0=""
set %=%_$LISTBUILD(%0, $IsObject(@%0), @%0)
}
return %
]]></Implementation>
</Method>
<Method name="WaitCommand">
<Description>
Retrieves a command text from the parent process.
Terminates itself if the parent process is dead.</Description>
<ClassMethod>1</ClassMethod>
<ProcedureBlock>1</ProcedureBlock>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
for {
set data = ..ReceiveChunk()
set flag = $LISTGET(data, 1)
if (flag = "m") { // message
return $LISTGET(data, 2)
} elseif (flag = "a") { // autocomplete
do ##class(WebTerminal.Common).SendChunk($ZPARENT, "a", ..VarList())
} else { // end or unexpected
do $system.Process.Terminate($JOB, 2)
return ""
}
}
]]></Implementation>
</Method>
<Method name="Loop">
<Description>
Starts new terminal loop. Must be called with JOB command.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>StartupRoutine:%String=""</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
if ($ZPARENT = 0) {
write "This method is for JOB use only."
return 0
}
open "terminal"::"^%X364"
use $io::"^" _ $ZName
if (StartupRoutine '= "") {
do $System.Util.SetInterruptEnable($$$YES)
do ##class(%Device).ReDirectIO($$$YES)
try {
do @StartupRoutine
do ##class(%Device).ReDirectIO($$$NO)
} catch {
do ##class(%Device).ReDirectIO($$$NO)
do ..SendChunk($ZPARENT, "e", $LISTBUILD($NAMESPACE, $ZERROR))
}
do ..SendChunk($ZPARENT, "e", $LISTBUILD($NAMESPACE, ""))
return $$$OK
}
kill // kill any temporary variables ProcedureBlock may have
for {
do ##class(%Device).ReDirectIO($$$YES)
do $System.Util.SetInterruptEnable($$$YES)
set $ZERROR = ""
try {
xecute ..WaitCommand()
} catch {}
do ##class(%Device).ReDirectIO($$$NO)
write !! // assume that prompt takes 2 lines
do ..SendChunk($ZPARENT, "e", $LISTBUILD($NAMESPACE, $ZERROR))
}
return $$$OK
]]></Implementation>
</Method>
</Class>
<Class name="WebTerminal.Engine">
<Description>
Cache WEB Terminal version 4.2.0 WebSocket client.
This class represents a connected client via WebSocket.</Description>
<Super>%CSP.WebSocket,Common,Trace,Autocomplete</Super>
<TimeChanged>64309,80475.893887</TimeChanged>
<TimeCreated>63891,56786.028532</TimeCreated>
<Parameter name="WSKEYEXPIRES">
<Description>
Timeout in minutes when connection key expires.</Description>
<Default>3600</Default>
</Parameter>
<Parameter name="AuthorizationTimeout">
<Description>
How long to wait for authorization key when connection established</Description>
<Default>5</Default>
</Parameter>
<Property name="CurrentNamespace">
<Type>%String</Type>
</Property>
<Property name="InitialZName">
<Type>%String</Type>
</Property>
<Property name="InitialZNamespace">
<Type>%String</Type>
</Property>
<Property name="corePID">
<Description>
The process ID of the terminal core.</Description>
<Type>%Numeric</Type>
<InitialExpression>0</InitialExpression>
</Property>
<Property name="childNamespace">
<Description>
The last known namespace in child process.</Description>
<Type>%String</Type>
</Property>
<Property name="StartupRoutine">
<Type>%String</Type>
</Property>
<Property name="echo">
<Description>
Output flag</Description>
<Type>%Boolean</Type>
<InitialExpression>1</InitialExpression>
</Property>
<Property name="handler">
<Description>
Output flag</Description>
<Type>%Boolean</Type>
<InitialExpression>0</InitialExpression>
<Private>1</Private>
</Property>
<Method name="GetMessage">
<FormalSpec>timeout:%Integer=86400</FormalSpec>
<ReturnType>%ZEN.proxyObject</ReturnType>
<Implementation><![CDATA[
#define err(%e, %s) if (%e '= $$$OK) { set obj = ##class(%ZEN.proxyObject).%New() set obj.error = %s return obj }
set data = ..Read(, .st, timeout)
return:((st = $$$CSPWebSocketTimeout) || (st = $$$CSPWebSocketClosed)) ""
$$$err(st, "%wsReadErr: "_$System.Status.GetErrorText(st))
set st = ##class(%ZEN.Auxiliary.jsonProvider).%ConvertJSONToObject(data, , .obj, 1)
$$$err(st, "%wsParseErr: "_$System.Status.GetErrorText(st))
return obj
]]></Implementation>
</Method>
<Method name="Send">
<Description>
Do not remove this method in future versions of WebTerminal, it is used by update.</Description>
<FormalSpec>handler:%String="",data=""</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
return:((handler = "o") && (..echo = 0)) $$$OK
return:(handler = "o") ..Write("o"_data) // Enables 2013.2 support (no JSON)
set obj = ##class(%ZEN.proxyObject).%New()
set obj.h = handler
if (..handler '= 0) {
set obj."_cb" = ..handler
}
set obj.d = data
return ..Write(..GetJSONString(obj))
]]></Implementation>
</Method>
<Method name="OnPreServer">
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
set ..InitialZName = $zname
set ..InitialZNamespace = $znspace
quit $$$OK
]]></Implementation>
</Method>
<Method name="OnPostServer">
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
if (..corePID '= 0) {
do ..SendChunk(..corePID, "e")
}
quit $$$OK
]]></Implementation>
</Method>
<Method name="WriteToFile">
<ClassMethod>1</ClassMethod>
<FormalSpec>filename:%String,data:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
set file=##class(%File).%New(filename)
do file.Open("WSN")
do file.WriteLine(data)
do file.Close()
]]></Implementation>
</Method>
<Method name="ExecuteSQL">
<FormalSpec>query:%String=""</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
set tStatement = ##class(%SQL.Statement).%New()
set qStatus = tStatement.%Prepare(query)
if qStatus'=1 {
write $System.Status.DisplayError(qStatus)
} else {
set rset = tStatement.%Execute()
do rset.%Display()
}
quit $$$OK
]]></Implementation>
</Method>
<Method name="RequireAuthorization">
<Description>
This method performs the authorization and login to WebTerminal.
It returns a list with data (see Router.Auth method), which is used then to set up the
initial values for the client.</Description>
<ReturnType>%List</ReturnType>
<Implementation><![CDATA[
set data = ..GetMessage(..#AuthorizationTimeout)
return:(data = "") $LB("%wsReadErr")
return:('$IsObject(data.d)) $LB($case(data.error = "", 1: "Unresolved WS message format", :data.error))
return:(data.d.key = "") $LB("Missing key")
set authKey = data.d.key
set key = $ORDER(^WebTerminal("AuthUser", ""))
set list = ""
while (key '= "") {
set lb = $GET(^WebTerminal("AuthUser", key))
if ((lb '= "") && (key = authKey)) {
set list = lb
}
set time = $LISTGET(lb, 2)
if (time '= "") && ($System.SQL.DATEDIFF("s", time, $h) > ..#WSKEYEXPIRES) {
kill ^WebTerminal("AuthUser", key)
}
set key = $ORDER(^WebTerminal("AuthUser", key))
}
if (list = "") { // not found
return $LB("Invalid key")
}
set username = $LISTGET(list, 1)
set namespace = $LISTGET(list, 3)
set ns = $Namespace
znspace "%SYS"
do ##class(Security.Users).Get(username, .userProps)
znspace ns
set namespace = $case(namespace, "":userProps("NameSpace"), :namespace)
if ($get(userProps("Routine")) '= "") {
set ..StartupRoutine = userProps("Routine")
}
if $get(userProps("Enabled")) '= 1 {
return $LB("User " _ username _ " is not enabled in the system")
}
set $LIST(list, 3) = namespace
set loginStatus = $System.Security.Login(username)
if (loginStatus '= 1) {
return $LB($System.Status.GetErrorText(loginStatus))
}
return $LB("", list)
]]></Implementation>
</Method>
<Method name="ProcessRequest">
<Description>
See WebTerminal.Handlers</Description>
<FormalSpec>handler:%String,data</FormalSpec>
<Private>1</Private>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
try {
return $CLASSMETHOD("WebTerminal.Handlers", handler, $this, data)
} catch (e) {
set ..echo = 1
return e.AsSystemError()
}
]]></Implementation>
</Method>
<Method name="ClientLoop">
<Description>
Main method for every new client.</Description>
<Private>1</Private>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
job ##class(WebTerminal.Core).Loop(..StartupRoutine):($NAMESPACE)
if ($TEST '= 1) {
do ..Send("error", "%noJob")
return $$$NOTOK
}
set ..corePID = $ZCHILD
set ..childNamespace = $NAMESPACE
if (..StartupRoutine = "") {
do ..Send("prompt", ..childNamespace)
} else {
set message = ##class(%ZEN.proxyObject).%New()
set status = $CLASSMETHOD("WebTerminal.Handlers", "Execute", $this, "", 1)
goto loopEnd
}
//try { // temp
for {
set message = ..GetMessage()
quit:(message = "") // if client is gone, finish looping
if (message.error) {
set st = ..Send("error", message.error)
quit
}
if (message."_cb" '= "") { set ..handler = message."_cb" }
set status = ..ProcessRequest(message.h, message.d)
set ..handler = 0
set ..echo = 1
if (status '= "") && (status '= $$$OK) {
set eType = $EXTRACT(status, 1, 1)
do ..Send("execError", $case(eType = 0, 1: $System.Status.GetErrorText(status), :status))
continue
}
}
loopEnd
//} catch (e) { do ..Send("o", $System.Status.GetErrorText(e)) } // temp
return $$$OK
]]></Implementation>
</Method>
<Method name="SendLoginInfo">
<Description><![CDATA[
This method sends basic login info to the user. Use this method to set client variables
during the WebTerminal initialization.
<parameter>authList</parameter> See Router.Auth method.]]></Description>
<FormalSpec>authList:%List</FormalSpec>
<Implementation><![CDATA[
set obj = ##class(%ZEN.proxyObject).%New()
set obj.username = $USERNAME
set obj.name = $get(^WebTerminal("Name"))
set obj.cleanStart = $ListGet(authList, 4)
set obj.system = $SYSTEM
set obj.firstLaunch = ($get(^WebTerminal("FirstLaunch"), 1) '= 0)
set obj.InstanceGUID = ##class(%SYS.System).InstanceGUID()
set obj.zv = $ZVersion
set ^WebTerminal("FirstLaunch") = 0
do ..Send("init", obj)
]]></Implementation>
</Method>
<Method name="Server">
<Description>
Triggered when new connection established.</Description>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
set authRes = ..RequireAuthorization()
set authMessage = $ListGet(authRes, 1)
if (authMessage = "") {
set authList = $ListGet(authRes, 2) // see Router.Auth method
set namespace = $ListGet(authList, 3)
if (namespace '= "") && (namespace '= $Namespace) {
try {
znspace namespace
} catch (e) {
do ..Send("oLocalized",
$Char(27) _ "[31m%unNS(" _ namespace _ ")"_ $Char(27) _ "[0m" _ $Char(13,10)
)
}
}
set ..CurrentNamespace = $Namespace
do ..SendLoginInfo(authList)
do ..ClientLoop()
do ..Send("oLocalized", "%wsNormalClose"_$C(13,10))
} else {
do ..Send("oLocalized", "%wsRefuse(" _ authMessage _ ")")
}
do ..EndServer()
quit $$$OK
]]></Implementation>
</Method>
</Class>
<Class name="WebTerminal.Handlers">
<Description>
Cache WEB Terminal version 4.2.0 WebSocket handlers class.
This class describes handlers for WebSocket client. Each handler method takes WS client instance
as a first argument, and a given data as second. For example, handler for "execute"
command will be names as "HandleExecute". Note that all the processing is synchronous and it
blocks the WebSocket input while processing.
This class is inherited by WebTerminal.Engine class.