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