source: BMXNET_RPMS_dotNET_UTILITIES-BMX/trunk/m/XWBTCPM.m@ 1589

Last change on this file since 1589 was 645, checked in by Sam Habiel, 15 years ago

Initial Import of BMX.net code

File size: 7.6 KB
Line 
1XWBTCPM ;ISF/RWF - BROKER TCP/IP PROCESS HANDLER ;8/29/07 22:11
2 ;;1.1;RPC BROKER;**35,43,49**;Mar 28, 1997;Build 6
3 ;Based on: XWBTCPC & XWBTCPL, Modified by ISF/RWF
4 ;Changed to be started by UCX or %ZISTCPS
5 ;
6DSM ;DSM called from ucx, % passed in with device.
7 D ESET
8 ;Open the device
9 S XWBTDEV=% X "O XWBTDEV:(TCPDEV):60" ;Special UCX/DSM open
10 ;Go find the connection type
11 U XWBTDEV
12 G CONNTYPE
13 ;
14CACHEVMS ;Cache'/VMS tcpip entry point, called from XWBTCP_START.COM file
15 D ESET
16 S XWBTDEV="SYS$NET"
17 ; **Cache'/VMS specific code**
18 O XWBTDEV::5
19 X "U XWBTDEV:(::""-M"")" ;Packet mode like DSM
20 G CONNTYPE
21 ;
22NT ;entry from ZISTCPS
23 ;JOB LISTEN^%ZISTCPS("port","NT^XWBTCPM","stop code")
24 D ESET
25 S XWBTDEV=IO
26 G CONNTYPE
27 ;
28GTMUCX(%) ;From ucx ZFOO
29 ;If called from LISTEN^%ZISTCP(PORT,"GTM^XWBTCPM") S XWBTDEV=IO
30 D ESET
31 ;GTM specific code
32 S @("$ZINTERRUPT=""I $$JOBEXAM^ZU($ZPOSITION)""")
33 S XWBTDEV=% X "O %:(RECORDSIZE=512)"
34 G CONNTYPE
35 ;
36GTMLNX ;From Linux xinetd script
37 D ESET
38 ;GTM specific code
39 S @("$ZINTERRUPT=""I $$JOBEXAM^ZU($ZPOSITION)""")
40 S XWBTDEV=$P X "U XWBTDEV:(nowrap:nodelimiter:ioerror=""TRAP"")"
41 S %="",@("%=$ZTRNLNM(""REMOTE_HOST"")") S:$L(%) IO("GTM-IP")=%
42 I %["::ffff:" S IO("GTM-IP")=$P(%,"::ffff:",2) ; ipv6 support
43 G CONNTYPE
44 ;
45ESET ;Set inital error trap
46 S U="^",$ETRAP="D ^%ZTER H" ;Set up the error trap
47 S X="",@^%ZOSF("TRAP") ;Clear old trap
48 Q
49 ;Find the type of connection and jump to the processing routine.
50CONNTYPE ;
51 N XWBDEBUG,XWBAPVER,XWBCLMAN,XWBENVL,XWBLOG,XWBOS,XWBPTYPE
52 N XWBTBUF,XWBTIP,XWBTSKT,XWBVER,XWBWRAP,XWBSHARE,XWBT
53 N SOCK,TYPE
54 D INIT
55 S XWB=$$BREAD^XWBRW(5,XWBTIME)
56 D LOG("MSG format is "_XWB_" type "_$S(XWB="[XWB]":"NEW",XWB="{XWB}":"OLD",XWB="<?xml":"M2M",XWB="{BMX}":"BMX",1:"Unk"))
57 I XWB["[XWB]" G NEW
58 I XWB["{XWB}" G OLD^XWBTCPM1
59 I XWB["<?xml" G M2M
60 I XWB["{BMX}" G GTMLNX^BMXMON
61 I $L($T(OTH^XWBTCPM2)) D OTH^XWBTCPM2 ;See if a special code.
62 D LOG("Prefix not known: "_XWB)
63 Q
64 ;
65NEWJOB() ;Check if OK to start a new job, Return 1 if OK, 0 if not OK.
66 N X,Y,J,XWBVOL
67 D GETENV^%ZOSV S XWBVOL=$P(Y,"^",2)
68 S X=$O(^XTV(8989.3,1,4,"B",XWBVOL,0)),J=$S(X>0:^XTV(8989.3,1,4,X,0),1:"ROU^y^1")
69 I $G(^%ZIS(14.5,"LOGON",XWBVOL)) Q 0 ;Check INHIBIT LOGONS?
70 I $D(^%ZOSF("ACTJ")) X ^("ACTJ") I $P(J,U,3),($P(J,U,3)'>Y) Q 0
71 Q 1
72 ;
73M2M ;M2M Broker
74 S XWBRBUF=XWB_XWBRBUF,(IO,IO(0))=XWBTDEV G SPAWN^XWBVLL
75 Q
76 ;
77NEW ;New broker
78 S U="^",DUZ=0,DUZ(0)="",XWBVER=1.108
79 D SETTIME(1) ;Setup for sign-on timeout
80 U XWBTDEV D
81 . N XWB,ERR,NATIP,I
82 . S ERR=$$PRSP^XWBPRS
83 . S ERR=$$PRSM^XWBPRS
84 . S MSG=$G(XWB(4,"CMD")) ;Build connect msg.
85 . S I="" F S I=$O(XWB(5,"P",I)) Q:I="" S MSG=MSG_U_XWB(5,"P",I)
86 . ;Get the peer and save that IP.
87 . S NATIP=$$GETPEER^%ZOSV S:'$L(NATIP) NATIP=$P(MSG,"^",2)
88 . I NATIP'=$P(MSG,"^",2) S $P(MSG,"^",2)=NATIP
89 . Q
90 S X=$$NEWJOB() D:'X LOG("No New Connects")
91 I ($P(MSG,U)'="TCPConnect")!('X) D QSND^XWBRW("reject"),LOG("reject: "_MSG) Q
92 D QSND^XWBRW("accept"),LOG("accept") ;Ack
93 S IO("IP")=$P(MSG,U,2),XWBTSKT=$P(MSG,U,3),XWBCLMAN=$P(MSG,U,4)
94 S XWBTIP=$G(IO("IP"))
95 ;start RUM for Broker Handler XWB*1.1*5
96 D LOGRSRC^%ZOSV("$BROKER HANDLER$",2,1)
97 ;GTM
98 I $G(XWBT("PCNT")) D
99 . S X=$NA(^XUTL("XUSYS",$J,1)) L +@X:0
100 . D COUNT^XUSCNT(1),SETLOCK^XUSCNT(X)
101 ;We don't use a callback
102 K XWB,CON,LEN,MSG ;Clean up
103 ;Attempt to share license, Must have TCP port open first.
104 U XWBTDEV ;D SHARELIC^%ZOSV(1)
105 ;setup null device "NULL"
106 S %ZIS="0H",IOP="NULL" D ^%ZIS S XWBNULL=IO I POP S XWBERROR="No NULL device" D ^%ZTER,EXIT Q
107 D SAVDEV^%ZISUTL("XWBNULL")
108 ;change process name
109 D CHPRN("ip"_$P(XWBTIP,".",3,4)_":"_XWBTDEV)
110 ;
111RESTART ;The error trap returns to here
112 N $ESTACK S $ETRAP="D ETRAP^XWBTCPM"
113 S DT=$$DT^XLFDT,DTIME=30
114 U XWBTDEV D MAIN
115 D LOG("Exit: "_XWBTBUF)
116 ;Turn off the error trap for the exit
117 S $ETRAP=""
118 D EXIT ;Logout
119 K XWBR,XWBARY
120 ;stop RUM for handler XWB*1.1*5
121 D LOGRSRC^%ZOSV("$BROKER HANDLER$",2,2)
122 D USE^%ZISUTL("XWBNULL"),CLOSE^%ZISUTL("XWBNULL")
123 ;Close in the calling script
124 K SOCK,TYPE,XWBSND,XWBTYPE,XWBRBUF
125 Q
126 ;
127MAIN ; -- main message processing loop. debug at MAIN+1
128 F D Q:XWBTBUF="#BYE#"
129 . ;Setup
130 . S XWBAPVER=0,XWBTBUF="",XWBTCMD="",XWBRBUF=""
131 . K XWBR,XWBARY,XWBPRT
132 . ; -- read client request
133 . S XR=$$BREAD^XWBRW(1,XWBTIME,1)
134 . I '$L(XR) D LOG("Timeout: "_XWBTIME) S XWBTBUF="#BYE#" Q
135 . S XR=XR_$$BREAD^XWBRW(4)
136 . I XR="#BYE#" D Q ;Check for exit
137 . . D QSND^XWBRW("#BYE#"),LOG("BYE CMD") S XWBTBUF="#BYE#"
138 . . Q
139 . S TYPE=(XR="[XWB]") ;check HDR
140 . I 'TYPE D LOG("Bad Header: "_XR) Q
141 . D CALLP^XWBPRS(.XWBR,$G(XWBDEBUG)) ;Read the NEW Msg parameters and call RPC
142 . IF XWBTCMD="#BYE#" D Q
143 . . D QSND^XWBRW("#BYE#"),LOG("BYE CMD") S XWBTBUF=XWBTCMD
144 . . Q
145 . U XWBTDEV
146 . S XWBPTYPE=$S('$D(XWBPTYPE):1,XWBPTYPE<1:1,XWBPTYPE>6:1,1:XWBPTYPE)
147 . ;I $G(XWBPRT) D RETURN^XWBPRS2 Q ;New msg return
148 . I '$G(XWBPRT) D SND^XWBRW ;Return data,flush buffer
149 Q ;End Of Main
150 ;
151 ;
152ETRAP ; -- on trapped error, send error info to client
153 N XWBERC,XWBERR
154 ;Change trapping during trap.
155 S $ETRAP="D ^%ZTER,EXIT^XWBTCPM HALT"
156 S XWBERC=$E($$EC^%ZOSV,1,200),XWBERR="M ERROR="_XWBERC_$C(13,10)_"LAST REF="_$$LGR^%ZOSV
157 I $EC["U411" S XWBERROR="U411",XWBSEC="",XWBERR="Data Transfer Error to Server"
158 D ^%ZTER ;%ZTER clears $ZE and $ZCODE
159 D LOG("In ETRAP: "_XWBERC) ;Log
160 I (XWBERC["READ")!(XWBERC["WRITE")!(XWBERC["SYSTEM-F")!(XWBERC["IOEOF") D EXIT HALT
161 U XWBTDEV
162 I $G(XWBT("PCNT")) L ^XUTL("XUSYS",$J,0)
163 E L ;Clear Locks
164 ;I XWBOS'="DSM" D
165 S XWBPTYPE=1 ;So SNDERR won't check XWBR
166 ;D SNDERR^XWBRW,WRITE^XWBRW($C(24)_XWBERR_$C(4))
167 D ESND^XWBRW($C(24)_XWBERR_$C(4))
168 S $ETRAP="Q:($ESTACK&'$QUIT) Q:$ESTACK -9 S $ECODE="""" D CLEANP^XWBTCPM G RESTART^XWBTCPM",$ECODE=",U99,"
169 Q
170 ;
171CLEANP ;Clean up the partion
172 N XWBTDEV,XWBNULL D KILL^XUSCLEAN
173 Q
174 ;
175STYPE(X,WRAP) ;For backward compatability only
176 I $D(WRAP) Q $$RTRNFMT^XWBLIB($G(X),WRAP)
177 Q $$RTRNFMT^XWBLIB(X)
178 ;
179BREAD(L,T) ;read tcp buffer, L is length
180 Q $$BREAD^XWBRW(L,$G(T))
181 ;
182CHPRN(N) ;change process name
183 ;Change process name to N
184 D SETNM^%ZOSV($E(N,1,15))
185 Q
186 ;
187SETTIME(%) ;Set the Read timeout 0=RPC, 1=sign-on
188 S XWBTIME=$S($G(%):90,$G(XWBVER)>1.105:$$BAT^XUPARAM,1:36000),XWBTIME(1)=2
189 I $G(%) S XWBTIME=$S($G(XWBVER)>1.1:90,1:36000)
190 Q
191TIMEOUT ;Do this on MAIN loop timeout
192 I $G(DUZ)>0 D QSND^XWBRW("#BYE#") Q
193 ;Sign-on timeout
194 S XWBR(0)=0,XWBR(1)=1,XWBR(2)="",XWBR(3)="TIME-OUT",XWBPTYPE=2
195 D SND^XWBRW
196 Q
197 ;
198OS() ;Return the OS
199 ; Q $S(^%ZOSF("OS")["DSM":"DSM",^("OS")["UNIX":"UNIX",^("OS")["OpenM":"OpenM",1:"MSM") //SMH
200 Q $S(^%ZOSF("OS")["DSM":"DSM",^("OS")["GT.M":"GT.M",^("OS")["OpenM":"OpenM",1:"MSM")
201 ;
202INIT ;Setup
203 S U="^",XWBTIME=10,XWBOS=$$OS,XWBDEBUG=0,XWBRBUF=""
204 S XWBDEBUG=$$GET^XPAR("SYS","XWBDEBUG")
205 S XWBT("BF")=$S(XWBOS="GT.M":"#",1:"!")
206 S XWBT("PCNT")=0 I XWBOS="GT.M",$L($T(^XUSCNT)) S XWBT("PCNT")=1
207 D LOGSTART^XWBDLOG("XWBTCPM")
208 Q
209 ;
210DEBUG ;Entry point for debug, Build a server to get the connect
211 ;DSM sample;ZDEBUG ON S $ZB(1)="SERV+1^XWBTCPM:1",$ZB="ETRAP+1^XWBTCPM:1"
212 W !,"Before running this entry point set your debugger to stop at"
213 W !,"the place you want to debug. Some spots to use:"
214 W !,"'SERV+1^XWBTCPM', 'MAIN+1^XWBTCPM' or 'CAPI+1^XWBPRS.'",!
215 W !,"or location of your choice.",!
216 W !,"IP Socket to Listen on: " R SOCK:300 Q:'$T!(SOCK["^")
217 ;Use %ZISTCP to do a single server
218 D LISTEN^%ZISTCP(SOCK,"SERV^XWBTCPM")
219 U $P W !,"Done"
220 Q
221SERV ;Callback from the server
222 S XWBTDEV=IO,XWBTIME(1)=3600 D INIT
223 S XWBDEBUG=1,MSG=$$BREAD^XWBRW(5,60) ;R MSG#5
224 D NEW
225 S IO("C")=1 ;Cause the Listenr to stop
226 Q
227 ;
228EXIT ;Close out
229 I $G(DUZ) D LOGOUT^XUSRB
230 I $G(XWBT("PCNT")) D COUNT^XUSCNT(-1)
231 Q
232 ;
233LOG(MSG) ;Record Debug Info
234 D:$G(XWBDEBUG) LOG^XWBDLOG(MSG)
235 Q
236 ;
Note: See TracBrowser for help on using the repository browser.