version 1.11, 2002/11/04 05:40:40 |
version 1.17, 2013/03/07 02:10:32 |
|
|
%% $OpenXM: OpenXM/src/kan96xx/Doc/httpd-rpc.sm1,v 1.10 2002/11/03 12:43:03 takayama Exp $ |
%% $OpenXM: OpenXM/src/kan96xx/Doc/httpd-rpc.sm1,v 1.16 2012/12/23 02:33:16 takayama Exp $ |
%% http server by sm1. Used for RPC. Generic example. |
%% http server by sm1. Used for RPC. Generic example. |
|
|
[(parse) (httpd.sm1) pushfile] extension pop |
[(parse) (httpd.sm1) pushfile] extension pop |
|
/httpd.textmode 1 def %% It does not work on some browsers. |
|
|
|
/httpd_action { |
|
httpd_action_allow_file_transfer |
|
%% If OXWEB_HTTPD_ROOT is set, file transfer will be allowed. |
|
%% Example: export OXWEB_HTTPD_ROOT=/usr/local/www/data/ |
|
%% Do not forget the last / |
|
% httpd_action_rpc_only %% old |
|
} def |
%% keyword for rpc |
%% keyword for rpc |
/httpd.textarea.name (rpc) def |
/httpd.textarea.name (rpc) def |
/httpd.textarea.name.aaa |
/httpd.textarea.name.aaa |
|
|
def |
def |
|
|
/httpd.asirman |
/httpd.asirman |
("http://www.math.sci.kobe-u.ac.jp/OpenXM/1.2.1/doc/asir2000/html-eg/man_toc.html") |
("http://www.math.sci.kobe-u.ac.jp/OpenXM/1.2.1/doc/asir2000/html-en/man_toc.html") |
def |
def |
/httpd.asirman.ja |
/httpd.asirman.ja |
("http://www.math.sci.kobe-u.ac.jp/OpenXM/1.2.1/doc/asir2000/html-jp/man_toc.html") |
("http://www.math.sci.kobe-u.ac.jp/OpenXM/1.2.1/doc/asir2000/html-ja/man_toc.html") |
def |
def |
|
|
[(parse) (oxasir.sm1) pushfile] extension |
[(parse) (oxasir.sm1) pushfile] extension |
|
|
3] extension |
3] extension |
}{ |
}{ |
%% On unix. |
%% On unix. |
[(sleep 3 ; netscape http://) |
[(ostype)] extension 1 get (mac) eq { |
|
/webrpc.browser (open) def |
|
} { /webrpc.browser (firefox) def } ifelse |
|
[(sleep 3 ; ) webrpc.browser ( http://) |
[(sm1.socket) (gethostname) []] extension |
[(sm1.socket) (gethostname) []] extension |
(:) httpd.port toString ( & ) ] cat |
(:) httpd.port toString ( & ) ] cat |
system |
system |
|
|
} def |
} def |
|
|
|
|
/httpd_action { |
/httpd_action_rpc_only { |
[/in-httpd /ff /httpd.com /httpd.result /sss |
[/in-httpd /ff /httpd.com /httpd.result /sss |
/sss.engine /sss.web /err |
/sss.engine /sss.web /err |
/oxserver.vname /scheck |
/oxserver.vname /scheck |
|
|
} def |
} def |
|
|
|
|
|
/httpd_action_allow_file_transfer { |
|
[/in-httpd /ff /httpd.com /httpd.result /sss |
|
/sss.engine /sss.web /err |
|
/oxserver.vname /scheck /ff2 |
|
] pushVariables |
|
[ |
|
(httpd_action_allow_file_transfer: ) message |
|
{ |
|
[(sm1.socket) (select) [httpd.server.fd 0 get -1]] extension |
|
%% wait for ever |
|
[(sm1.socket) (readHTTP) [httpd.server.fd 0 get ]] extension /ff set |
|
ff tag 0 eq { |
|
(connection is closed.) message exit |
|
} |
|
{ |
|
(------------ start ----------------------) message |
|
ff message |
|
(-----------------------------------------) message |
|
ff httpd.parse /ff2 set |
|
ff2 message |
|
/httpd.textarea.valid 0 def /httpd.com ( ) def |
|
ff2 0 get (GET-file) eq { |
|
ff2 length 1 eq httpd.root tag 0 eq { |
|
send-page-usage |
|
exit |
|
} { } ifelse |
|
ff2 httpd_sendfile exit |
|
} { } ifelse |
|
ff2 0 get (GET) eq ff2 0 get (POST) eq or { |
|
ff2 1 get tag 6 eq |
|
ff2 1 get length 2 eq and |
|
{ % list |
|
ff2 1 get 0 get httpd.textarea.name eq { |
|
/httpd.textarea.valid 1 def |
|
/httpd.com ff2 1 get 1 get def |
|
}{ } ifelse |
|
ff2 1 get 0 get (msg) eq { %% meta command |
|
/httpd.textarea.valid 0 def |
|
/httpd.com ff2 1 get 1 get def |
|
}{ } ifelse |
|
} { } ifelse |
|
}{ } ifelse |
|
%% ff removeGET webstringToAscii /httpd.com set |
|
[(httpd.com=) httpd.com] cat message |
|
(------------ end ----------------------) message |
|
( ) message |
|
|
|
httpd.com metaCommand { |
|
httpd.textarea.valid { |
|
|
|
%%% Security check |
|
[(regionMatches) httpd.com |
|
httpd.refusedCommands] extension /scheck set |
|
scheck 0 get -1 eq { |
|
}{ |
|
httpd.refusedCommands scheck 2 get get message |
|
(Command is refused.) message |
|
[ |
|
httpd.refusedCommands scheck 2 get get |
|
httpd.com |
|
] |
|
send-page-refused exit |
|
} ifelse |
|
|
|
%%% Executing command, here. |
|
oxasir.ccc |
|
httpd.com cookedCommand |
|
oxexecutestring ; |
|
|
|
}{ |
|
send-page-usage exit |
|
} ifelse |
|
|
|
[(oxReq) oxasir.ccc SM_dupErrors ] extension pop |
|
|
|
[(oxReq) oxasir.ccc SM_popCMO ] extension pop |
|
[(oxReq) oxasir.ccc SM_popString ] extension pop |
|
|
|
[(flush)] extension pop |
|
%% Select inputs for interruption. |
|
%% Wait by the spin lock. |
|
{ |
|
[(oxMultiSelect) [oxasir.ccc] 1] extension 1 get 0 get |
|
/sss.engine set |
|
[(sm1.socket) (mselect) |
|
[[httpd.server.fd 0 get] 1] |
|
] extension 0 get /sss.web set |
|
/sss [sss.engine sss.web] def |
|
sss.engine { exit } { } ifelse |
|
sss.web { exit } { } ifelse |
|
} loop |
|
sss message |
|
|
|
sss 0 get { |
|
[(oxGet) oxasir.ccc] extension /err set |
|
[(oxGet) oxasir.ccc] extension /httpd.result set |
|
} { |
|
oxasir.ccc oxreset |
|
oxasir.ccc ("computation is interrupted.";) oxexecutestring ; |
|
oxasir.ccc oxpopstring |
|
/httpd.result set |
|
exit |
|
} ifelse |
|
(------------- result -------------) message |
|
httpd.result message |
|
(----------------------------------) message |
|
( ) message |
|
|
|
(----------- error -------------) message |
|
err message |
|
(-------------------------------) message |
|
err [ ] eq { |
|
} { |
|
oxasir.ccc cleanErrors |
|
[httpd.result 10 (string) dc err toString] cat |
|
/httpd.result set |
|
} ifelse |
|
|
|
httpd.result send-page-result exit %% exit the loop LOOP-A |
|
} { exit } ifelse %% metaCommand |
|
} ifelse |
|
} loop %% LOOP-A |
|
] pop |
|
popVariables |
|
} def |
|
|
|
|
/metaCommand { |
/metaCommand { |
/arg1 set |
/arg1 set |
[/in-metaCommand /msg /result /msg2 /nn |
[/in-metaCommand /msg /result /msg2 /nn |
|
|
|
|
/send-page-result { |
/send-page-result { |
/arg1 set |
/arg1 set |
[/in-send-page-result /result] pushVariables |
[/in-send-page-result /result /hlen /msg1 /msg2] pushVariables |
[ |
[ |
/result arg1 def |
/result arg1 def |
|
/msg1 (<html> <body> <pre>) def |
|
/msg2 (</pre> </body> </html>) def |
|
httpd.textmode { 0 /hlen set } |
|
{ msg1 length msg2 length add 3 add /hlen set } ifelse |
(HTTP/0.9 200 OK) sendln |
(HTTP/0.9 200 OK) sendln |
(Connection: close) sendln |
(Connection: close) sendln |
[(Content-length: ) result length toString ] cat sendln |
[(Content-length: ) result length hlen add toString ] cat sendln |
(Content-Type: text/html) sendln |
httpd.textmode |
%(Content-Type: text/plain) sendln % It does not work on some browsers. |
{ (Content-Type: text/plain) sendln } % It does not work on some browsers. |
|
{ (Content-Type: text/html) sendln } ifelse |
0 sendln |
0 sendln |
|
|
(<html> <body> <pre>) sendln |
httpd.textmode { } { msg1 sendln } ifelse |
result sendln |
result sendln |
(</pre> </body> </html>) sendln |
httpd.textmode { } { msg2 sendln } ifelse |
0 sendln |
0 sendln |
[(flush)] extension |
[(flush)] extension |
] pop |
] pop |
|
|
(end) (quit) (output) (bload27) (open) |
(end) (quit) (output) (bload27) (open) |
(plot) (ctrl) (debug) (error) (port) (bind) (accept) |
(plot) (ctrl) (debug) (error) (port) (bind) (accept) |
(draw) (peek) (poke) |
(draw) (peek) (poke) |
|
(write_string_to_a_file) (_filter) |
] |
] |
def |
def |