version 1.1, 2002/10/23 13:38:50 |
version 1.5, 2002/10/24 07:45:03 |
|
|
%% $OpenXM$ |
%% $OpenXM: OpenXM/src/kan96xx/Doc/httpd-rpc.sm1,v 1.4 2002/10/24 05:42:00 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.port 8090 def |
/httpd.port 8090 def |
/httpd.serial 0 def |
/httpd.serial 0 def |
|
|
/httpd.image.name (kobeuniv2.jpg) def |
%%******* Put initialization codes for ox_asir here. |
|
/httpd.initialization |
|
[ |
|
(XM_debug=0; ctrl("debug_window",0); Xm_noX=1;) |
|
("Asirweb version 0.80. "+ |
|
" Risa/Asir oxasir version "+rtostr(version());) |
|
] cat |
|
def |
|
|
|
|
[(parse) (oxasir.sm1) pushfile] extension |
[(parse) (oxasir.sm1) pushfile] extension |
|
|
[(x^2-1) (x)] fctr pop |
[(x^2-1) (x)] fctr pop |
oxasir.ccc oxmathcap |
oxasir.ccc oxmathcap |
oxasir.ccc oxsetmathcap |
oxasir.ccc oxsetmathcap |
|
oxasir.ccc httpd.initialization oxexecutestring ; |
|
(Initialization returns ...: ) messagen |
|
oxasir.ccc oxpopcmo message ; |
} ifelse |
} ifelse |
|
|
/webrpc { |
/webrpc { |
|
|
[ |
[ |
ox.win.start.0 aload pop |
ox.win.start.0 aload pop |
(iexplore) %% Starting internet explorer (TM). |
(iexplore) %% Starting internet explorer (TM). |
[(http://localhost:) httpd.port toString] cat |
[(http://) [(sm1.socket) (gethostname) []] extension |
|
(:) httpd.port toString] cat |
] |
] |
[ ] |
[ ] |
3] extension |
3] extension |
}{ |
}{ |
%% On unix. |
%% On unix. |
[(sleep 3 ; netscape http://localhost:) httpd.port toString ( & ) ] cat |
[(sleep 3 ; netscape http://) |
|
[(sm1.socket) (gethostname) []] extension |
|
(:) httpd.port toString ( & ) ] cat |
system |
system |
} ifelse |
} ifelse |
|
|
|
|
/httpd_action { |
/httpd_action { |
[/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 |
/oxserver.vname /scheck |
] pushVariables |
] pushVariables |
[ |
[ |
{ |
{ |
[(sm1.socket) (select) [httpd.server.fd 0 get -1]] extension |
[(sm1.socket) (select) [httpd.server.fd 0 get -1]] extension |
%% wait for ever |
%% wait for ever |
[(sm1.socket) (readHTTP) [httpd.server.fd 0 get ]] extension /ff set |
[(sm1.socket) (readHTTP) [httpd.server.fd 0 get ]] extension /ff set |
ff length 0 eq { |
ff tag 0 eq { |
(connection is closed.) message |
(connection is closed.) message exit |
} |
} |
{ |
{ |
(------------ start ----------------------) message |
(------------ start ----------------------) message |
|
|
[(httpd.com=) httpd.com] cat message |
[(httpd.com=) httpd.com] cat message |
(------------ end ----------------------) message |
(------------ end ----------------------) message |
( ) message |
( ) message |
httpd.serial 0 eq { |
|
/httpd.com httpd.initialization def |
|
} { } ifelse |
|
httpd.com metaCommand { |
httpd.com metaCommand { |
httpd.textarea.valid { |
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. |
%%% Executing command, here. |
oxasir.ccc |
oxasir.ccc |
httpd.com cookedCommand |
httpd.com cookedCommand |
|
|
httpd.result message |
httpd.result message |
(----------------------------------) message |
(----------------------------------) message |
( ) message |
( ) message |
|
|
|
(----------- error -------------) message |
err message |
err message |
|
(-------------------------------) message |
err [ ] eq { |
err [ ] eq { |
} { |
} { |
oxasir.ccc cleanErrors |
oxasir.ccc cleanErrors |
|
|
/result arg1 def |
/result arg1 def |
(HTTP/0.9 200 OK) sendln |
(HTTP/0.9 200 OK) sendln |
(Connection: close) sendln |
(Connection: close) sendln |
(Content-Type: text/html) sendln |
[(Content-length: ) result length toString ] cat sendln |
|
(Content-Type: text/plain) sendln |
0 sendln |
0 sendln |
|
|
result sendln |
result sendln |
|
|
popVariables |
popVariables |
} def |
} def |
|
|
%%******* Put initialization codes for ox_asir here. |
/send-page-refused { |
/httpd.initialization |
/arg1 set |
[ |
[/in-send-page-refused /reason] pushVariables |
(XM_debug=0; ctrl("debug_window",0); Xm_noX=1;) |
[ |
("Asirweb version 0.80. "+ |
/reason arg1 def |
" Risa/Asir oxasir version "+rtostr(version());) |
(HTTP/0.9 200 OK) sendln |
] cat |
(Connection: close) sendln |
def |
(Content-Type: text/html) sendln |
|
0 sendln |
|
|
|
(<H2> Your request is refused. </H2> <br> ) sendln |
|
(Because your input contains the key word <font color="red">) sendln |
|
reason 0 get sendln |
|
( </font> ) sendln |
|
(<br> <br>) sendln |
|
(Your input is <br> ) sendln |
|
(<pre> ) sendln |
|
reason 1 get sendln |
|
(</pre> ) sendln |
|
|
|
0 sendln |
|
[(flush)] extension |
|
] pop |
|
popVariables |
|
} def |
|
|
|
%% **** Overwrites the definition in httpd.sm1 |
|
/httpd_startserver { |
|
(httpd server accessible outside localhost.) message |
|
%% get the hostname of this machine. |
|
[(sm1.socket) (open) [httpd.port |
|
[(sm1.socket) (gethostname) [ ] ]extension ] ] |
|
extension |
|
/httpd.server.fdAndPort set |
|
(sm1.socket.open returns ) messagen httpd.server.fdAndPort message |
|
[(sm1.socket) (accept) [httpd.server.fdAndPort 0 get]] extension |
|
/httpd.server.fd set |
|
(connected.) message |
|
(sm1.socket.accept returns <httpd.server.fd> ) messagen |
|
httpd.server.fd message |
|
|
|
} def |
|
|
%% ******* sample of cooked command |
%% ******* sample of cooked command |
/cookedCommand { |
/cookedCommand { |
/arg1 set |
/arg1 set |
|
|
popVariables |
popVariables |
arg1 |
arg1 |
} def |
} def |
|
/httpd.refusedCommands |
|
[(shell) (eval_str) (ox_) (sm1_) (m_) |
|
(connect) (load) (bload) (bsave) |
|
(end) (quit) (output) (bload27) (open) |
|
(plot) (ctrl) (debug) (error) (port) (bind) (accept) |
|
(draw) |
|
] |
|
def |