Annotation of OpenXM/src/kan96xx/Doc/httpd-rpc.sm1, Revision 1.10
1.10 ! takayama 1: %% $OpenXM: OpenXM/src/kan96xx/Doc/httpd-rpc.sm1,v 1.9 2002/10/29 10:54:17 takayama Exp $
1.1 takayama 2: %% http server by sm1. Used for RPC. Generic example.
3:
4: [(parse) (httpd.sm1) pushfile] extension pop
1.10 ! takayama 5: %% keyword for rpc
1.1 takayama 6: /httpd.textarea.name (rpc) def
7: /httpd.textarea.name.aaa
8: [(GET /?) httpd.textarea.name] cat (array) dc
9: def
1.10 ! takayama 10:
! 11: [(getenv) (OXWEB_PORT)] extension tag 0 eq {
! 12: (Default httpd port : ) messagen
! 13: /httpd.port 8090 def
! 14: } {
! 15: /httpd.port [(getenv) (OXWEB_PORT)] extension .. (integer) dc def
! 16: } ifelse
! 17: (httpd.port = ) messagen httpd.port message
! 18:
1.1 takayama 19: /httpd.serial 0 def
20:
1.7 takayama 21: /httpd.oxasir.timer 1 def %% 1 to use timer, but it accepts only one command
22: %% 0 not to use timer. It accepts programs.
23:
1.2 takayama 24: %%******* Put initialization codes for ox_asir here.
25: /httpd.initialization
1.8 takayama 26: [(if(1){)
1.2 takayama 27: (XM_debug=0; ctrl("debug_window",0); Xm_noX=1;)
28: ("Asirweb version 0.80. "+
29: " Risa/Asir oxasir version "+rtostr(version());)
1.8 takayama 30: (};)
1.2 takayama 31: ] cat
32: def
1.1 takayama 33:
1.7 takayama 34: /httpd.asirman
35: ("http://www.math.sci.kobe-u.ac.jp/OpenXM/1.2.1/doc/asir2000/html-eg/man_toc.html")
36: def
37: /httpd.asirman.ja
38: ("http://www.math.sci.kobe-u.ac.jp/OpenXM/1.2.1/doc/asir2000/html-jp/man_toc.html")
39: def
1.1 takayama 40:
41: [(parse) (oxasir.sm1) pushfile] extension
42: oxNoX
43: (oxasir.started) boundp {
44: } {
45: %% Initialize oxasir.
46: [(x^2-1) (x)] fctr pop
47: oxasir.ccc oxmathcap
48: oxasir.ccc oxsetmathcap
1.2 takayama 49: oxasir.ccc httpd.initialization oxexecutestring ;
50: (Initialization returns ...: ) messagen
51: oxasir.ccc oxpopcmo message ;
1.1 takayama 52: } ifelse
53:
54: /webrpc {
55: [/rrr ] pushVariables
56: [
57: [(oxGenPass)] extension . (integer) dc /rrr set
58:
59: [(ostype)] extension 0 get
60: (windows) eq {
61: %% On windows.
62: [(forkExec)
63: [
64: ox.win.start.0 aload pop
65: (iexplore) %% Starting internet explorer (TM).
1.3 takayama 66: [(http://) [(sm1.socket) (gethostname) []] extension
67: (:) httpd.port toString] cat
1.1 takayama 68: ]
69: [ ]
70: 3] extension
71: }{
72: %% On unix.
1.3 takayama 73: [(sleep 3 ; netscape http://)
74: [(sm1.socket) (gethostname) []] extension
75: (:) httpd.port toString ( & ) ] cat
1.1 takayama 76: system
77: } ifelse
78:
79: httpd ;
80: ] pop
81: popVariables
82: } def
83:
84:
85: /httpd_action {
86: [/in-httpd /ff /httpd.com /httpd.result /sss
87: /sss.engine /sss.web /err
1.4 takayama 88: /oxserver.vname /scheck
1.1 takayama 89: ] pushVariables
90: [
91: {
92: [(sm1.socket) (select) [httpd.server.fd 0 get -1]] extension
93: %% wait for ever
94: [(sm1.socket) (readHTTP) [httpd.server.fd 0 get ]] extension /ff set
1.2 takayama 95: ff tag 0 eq {
96: (connection is closed.) message exit
1.1 takayama 97: }
98: {
99: (------------ start ----------------------) message
100: ff message
101: (-----------------------------------------) message
102: ff removeGET webstringToAscii /httpd.com set
103: [(httpd.com=) httpd.com] cat message
104: (------------ end ----------------------) message
105: ( ) message
1.2 takayama 106:
1.1 takayama 107: httpd.com metaCommand {
108: httpd.textarea.valid {
109:
1.4 takayama 110: %%% Security check
111: [(regionMatches) httpd.com
112: httpd.refusedCommands] extension /scheck set
113: scheck 0 get -1 eq {
114: }{
115: httpd.refusedCommands scheck 2 get get message
116: (Command is refused.) message
117: [
118: httpd.refusedCommands scheck 2 get get
119: httpd.com
120: ]
121: send-page-refused exit
122: } ifelse
123:
1.1 takayama 124: %%% Executing command, here.
125: oxasir.ccc
126: httpd.com cookedCommand
127: oxexecutestring ;
128:
129: }{
130: send-page-usage exit
131: } ifelse
132:
133: [(oxReq) oxasir.ccc SM_dupErrors ] extension pop
134:
135: [(oxReq) oxasir.ccc SM_popCMO ] extension pop
136: [(oxReq) oxasir.ccc SM_popString ] extension pop
137:
138: [(flush)] extension pop
139: %% Select inputs for interruption.
140: %% Wait by the spin lock.
141: {
142: [(oxMultiSelect) [oxasir.ccc] 1] extension 1 get 0 get
143: /sss.engine set
144: [(sm1.socket) (mselect)
145: [[httpd.server.fd 0 get] 1]
146: ] extension 0 get /sss.web set
147: /sss [sss.engine sss.web] def
148: sss.engine { exit } { } ifelse
149: sss.web { exit } { } ifelse
150: } loop
151: sss message
152:
153: sss 0 get {
154: [(oxGet) oxasir.ccc] extension /err set
155: [(oxGet) oxasir.ccc] extension /httpd.result set
156: } {
157: oxasir.ccc oxreset
158: oxasir.ccc ("computation is interrupted.";) oxexecutestring ;
159: oxasir.ccc oxpopstring
160: /httpd.result set
161: exit
162: } ifelse
163: (------------- result -------------) message
164: httpd.result message
165: (----------------------------------) message
166: ( ) message
1.2 takayama 167:
168: (----------- error -------------) message
1.1 takayama 169: err message
1.2 takayama 170: (-------------------------------) message
1.1 takayama 171: err [ ] eq {
172: } {
173: oxasir.ccc cleanErrors
174: [httpd.result 10 (string) dc err toString] cat
175: /httpd.result set
176: } ifelse
177:
178: httpd.result send-page-result exit %% exit the loop LOOP-A
179: } { exit } ifelse %% metaCommand
180: } ifelse
181: } loop %% LOOP-A
182: ] pop
183: popVariables
184: } def
185:
186:
187:
188:
189: /metaCommand {
190: /arg1 set
191: [/in-metaCommand /msg /result /msg2 /nn
192: /err /fn
193: ] pushVariables
194: [
195: /msg arg1 def
196: /result 1 def
197: msg (httpdAsirMeta quit) eq {
198: oxasir.ccc oxshutdown
199: send-page-bye
200: quit
201: /result 0 def
202: } { } ifelse
203: msg (httpdAsirMeta interrupt) eq {
204: oxasir.ccc oxreset
205: (Interrupted! <br>) send-page-3
206: /result 0 def
207: } { } ifelse
208: /arg1 result def
209: ] pop
210: popVariables
211: arg1
212: } def
213:
214: /send-page-usage {
215: [/in-send-page-usage ] pushVariables
216: [
217: (HTTP/0.9 200 OK) sendln
218: (Connection: close) sendln
219: (Content-Type: text/html) sendln
220: 0 sendln
221:
1.7 takayama 222: (<H1><font color="green">OpenXM/Risa/Asir Online</font></H2><br>) sendln
1.1 takayama 223: [(getenv) (OXWEB_POST)] extension tag 0 eq {
224: (<FORM NAME="myFORM">) sendln % use get
225: }{
226: (<FORM NAME="myFORM" METHOD="POST">) sendln
227: } ifelse
228: (<INPUT TYPE=submit VALUE="submit">) sendln
229: [(<textarea name=) httpd.textarea.name
1.8 takayama 230: ( rows=7 cols="80" wrap="soft"></textarea>)] cat sendln
1.1 takayama 231: (</FORM>) sendln
1.7 takayama 232:
233: (Input example---factorization:<font color="blue"> fctr(x^3-1)</font>) sendln
234: (<br>) sendln
235: [(<font color="blue">
236: <a href=) httpd.asirman ( > AsirManual (En) </a> </font>, )] cat sendln
237: [(<font color="blue">
238: <a href=) httpd.asirman.ja ( > AsirManual (Ja) </a> </font>)] cat sendln
239: httpd.oxasir.timer {
240: (<br> It accepts only one command. The limit of CPU time is 30 seconds.
241: <font color="red"> Do not put <font color="blue"> ; </font>
242: (semi-colon) after the command.
243: </font>) sendln
244: }{ } ifelse
245: (<br>) sendln
246: [(You can also retrieve the result by GET /?) httpd.textarea.name (=) ( encoded_codes HTTP/1.0)] cat
247: sendln
248: (<br>) sendln
1.9 takayama 249: [$<a href="http://$ [(sm1.socket) (gethostname) []] extension
250: $:$ httpd.port toString
1.7 takayama 251: $/?msg=httpdAsirMeta+quit"> Shutdown the oxserver (and restart it). </a>$
1.1 takayama 252: ] cat sendln
1.7 takayama 253: (<h3 align="right"><font color="gree">Powered by OpenXM and httpd on Kan/sm1 </font> </h3>_) sendln
1.1 takayama 254: 0 sendln
255: [(flush)] extension
256: ] pop
257: popVariables
258: } def
259:
260:
261:
262: /send-page-result {
263: /arg1 set
264: [/in-send-page-result /result] pushVariables
265: [
266: /result arg1 def
267: (HTTP/0.9 200 OK) sendln
268: (Connection: close) sendln
1.3 takayama 269: [(Content-length: ) result length toString ] cat sendln
270: (Content-Type: text/plain) sendln
1.1 takayama 271: 0 sendln
272:
273: result sendln
274: 0 sendln
275: [(flush)] extension
276: ] pop
277: popVariables
278: } def
279:
1.4 takayama 280: /send-page-refused {
281: /arg1 set
282: [/in-send-page-refused /reason] pushVariables
283: [
284: /reason arg1 def
285: (HTTP/0.9 200 OK) sendln
286: (Connection: close) sendln
287: (Content-Type: text/html) sendln
288: 0 sendln
289:
290: (<H2> Your request is refused. </H2> <br> ) sendln
291: (Because your input contains the key word <font color="red">) sendln
292: reason 0 get sendln
293: ( </font> ) sendln
294: (<br> <br>) sendln
295: (Your input is <br> ) sendln
296: (<pre> ) sendln
297: reason 1 get sendln
298: (</pre> ) sendln
299:
300: 0 sendln
301: [(flush)] extension
302: ] pop
303: popVariables
304: } def
305:
1.2 takayama 306: %% **** Overwrites the definition in httpd.sm1
307: /httpd_startserver {
308: (httpd server accessible outside localhost.) message
309: %% get the hostname of this machine.
310: [(sm1.socket) (open) [httpd.port
311: [(sm1.socket) (gethostname) [ ] ]extension ] ]
312: extension
313: /httpd.server.fdAndPort set
314: (sm1.socket.open returns ) messagen httpd.server.fdAndPort message
315: [(sm1.socket) (accept) [httpd.server.fdAndPort 0 get]] extension
316: /httpd.server.fd set
317: (connected.) message
318: (sm1.socket.accept returns <httpd.server.fd> ) messagen
319: httpd.server.fd message
320:
321: } def
1.1 takayama 322:
323: %% ******* sample of cooked command
1.7 takayama 324: /cookedCommand.simplest {
1.1 takayama 325: /arg1 set
326: [/in-cookedCommand /httpd.com] pushVariables
327: [
328: /httpd.com arg1 def
329: [(if (1) {) httpd.com (; };)] cat
330: /arg1 set
1.7 takayama 331: ] pop
332: popVariables
333: arg1
334: } def
335: /cookedCommand {
336: /arg1 set
337: [/in-cookedCommand /httpd.com /fff] pushVariables
338: [
339: /httpd.com arg1 def
340: httpd.oxasir.timer not {
341: [(if (1) {) httpd.com (; };)] cat
342: /fff set
343: }{
344: %% It does not work.
345: %% [$timer(30,eval_str("$
346: %% (if (1) {) httpd.com (; };)
347: %% $"),"Computation is aborted with the resource limit ( 30 seconds)");$
348: %% ] cat
349: [$timer(30,$ httpd.com
350: $,"Computation is aborted with the resource limit ( 30 seconds) or there was a syntax error.");$
351: ] cat
352: /fff set
353: } ifelse
354: (cooked command is ) messagen fff message
355: /arg1 fff def
1.1 takayama 356: ] pop
357: popVariables
358: arg1
359: } def
1.4 takayama 360: /httpd.refusedCommands
1.8 takayama 361: [(shell) (eval_str) (ox_) (sm1_)
362: (m_start) (m_N_) (m_Inverse) (m_TexForm) %(m_)
1.5 takayama 363: (connect) (load) (bload) (bsave)
364: (end) (quit) (output) (bload27) (open)
365: (plot) (ctrl) (debug) (error) (port) (bind) (accept)
1.6 takayama 366: (draw) (peek) (poke)
1.4 takayama 367: ]
368: def
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>