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