version 1.9, 2004/11/23 01:37:47 |
version 1.14, 2013/09/22 05:17:17 |
|
|
% $OpenXM: OpenXM/src/kan96xx/Doc/cgi.sm1,v 1.8 2004/11/22 12:30:32 takayama Exp $ |
% $OpenXM: OpenXM/src/kan96xx/Doc/cgi.sm1,v 1.13 2013/09/22 01:07:38 takayama Exp $ |
% OpenXM/src/polymake/cgi/cgi-polymake.sh |
% OpenXM/src/polymake/cgi/cgi-polymake.sh |
% is a shell script to call sm1/polymake as a CGI script. |
% is a shell script to call sm1/polymake as a CGI script. |
% Override as /doPolymake {doPolymake.OoHG} def if you need. |
% Override as /doPolymake {doPolymake.OoHG} def if you need. |
|
|
[[(URL),(/index.html)] |
[[(URL),(/index.html)] |
] /kv set |
] /kv set |
[(cgiKeyValuePairToUrlEncodingString) kv] extension /sss set |
[(cgiKeyValuePairToUrlEncodingString) kv] extension /sss set |
[(GET ) , sss , ( HTTP/0.9) , nl , nl ] cat /sss2 set |
% [(GET ) , sss , ( HTTP/0.9) , nl , nl ] cat /sss2 set |
|
[(GET ) , sss , ( HTTP/0.9) , nl , |
|
(HOST: ) , url , nl |
|
nl ] cat /sss2 set |
|
|
sss2 message |
sss2 message |
[(sm1.socket) (connect) [80 url]] extension 0 get /goo set |
[(sm1.socket) (connect) [80 url]] extension 0 get /goo set |
|
|
/cgiPolymake.polymakeName (polymake) def |
/cgiPolymake.polymakeName (polymake) def |
%/cgiPolymake.polymakeName (polymake_dummy) def |
%/cgiPolymake.polymakeName (polymake_dummy) def |
%/cgiPolymake.polymakeName (hoge) def |
%/cgiPolymake.polymakeName (hoge) def |
|
/cgiPolymake.log 1 def |
|
|
[(cgiPolymake) |
[(cgiPolymake) |
[(Make sm1 to a polymake server based on CGI/OoHG) |
[(Make sm1 to a polymake server based on CGI/OoHG) |
|
|
/cgiPolymake { |
/cgiPolymake { |
{ |
{ |
[(getenv) (CONTENT_LENGTH)] extension /cgi.content_length set |
[(getenv) (CONTENT_LENGTH)] extension /cgi.content_length set |
|
cgi.content_length isString { |
|
} { |
|
cgiPolymake.errorMessage message exit |
|
} ifelse |
cgi.content_length .. (integer) dc /cgi.content_length set |
cgi.content_length .. (integer) dc /cgi.content_length set |
|
cgi.content_length 1 lt { |
|
cgiPolymake.errorMessage message exit |
|
} { } ifelse |
[(read) 0 cgi.content_length] extension /cgi.query_string set |
[(read) 0 cgi.content_length] extension /cgi.query_string set |
|
cgiPolymake.log { |
|
cgi.query_string (string) dc sm1log |
|
} { } ifelse |
cgi.query_string isString { |
cgi.query_string isString { |
cgi.query_string length 0 eq { |
cgi.query_string length 0 eq { |
cgiPolymake.errorMessage message exit |
cgiPolymake.errorMessage message exit |
|
|
% ------------ client side script --------------- |
% ------------ client side script --------------- |
/cgiQueryPolymake.hostname (polymake.math.kobe-u.ac.jp) def |
/cgiQueryPolymake.hostname (polymake.math.kobe-u.ac.jp) def |
/cgiQueryPolymake.cginame (/cgi-bin/cgi-polymake.sh) def |
/cgiQueryPolymake.cginame (/cgi-bin/cgi-polymake.sh) def |
/cgiQueryPolymake { |
%/cgiQueryPolymake { cgiQueryPolymake.curl } def |
|
/cgiQueryPolymake { cgiQueryPolymake.native } def |
|
/cgiQueryPolymake.curl { |
/arg2 set /arg1 set |
/arg2 set /arg1 set |
|
[/saction /sfile /ff /ff1 /sss2 /goo /pp /pp2 /key /body /fd] pushVariables |
|
[ |
|
/saction arg1 def /sfile arg2 def |
|
% step1. Generate query in URL encoding. |
|
[(http://) cgiQueryPolymake.hostname cgiQueryPolymake.cginame] cat |
|
/ff1 set |
|
% full URL necessary for virtual host of apache. |
|
[[(oxMessageBody) |
|
[saction ( ) |
|
sfile nl ] cat |
|
] |
|
] /ff set |
|
|
|
ff 0 get 0 get /key set |
|
ff 0 get 1 get /body set |
|
% step 2. Call the server and get the response in pp |
|
/cgi.verbose 1 def |
|
(/tmp/sm1-q-cgi.txt) (w) file /fd set |
|
fd body writestring |
|
fd closefile |
|
[(curl) (--form) [key (=@/tmp/sm1-q-cgi.txt)] cat ff1] /ff set |
|
ff message |
|
ff |
|
addStdoutStderr oxshell |
|
@@@stdout /pp set |
|
pp message |
|
@@2stderr message |
|
(-----) message |
|
% For the case of error. |
|
[(regexec) (200 OK) [pp]] extension length 0 eq { |
|
(sss2=) message |
|
sss2 message |
|
(pp=) message |
|
pp message |
|
(cgi.sm1: there seems to be an error in the HTTP connection.) |
|
} { } ifelse |
|
|
|
cgi.verbose { pp message } { } ifelse |
|
[(cgiHttpToKeyValuePair) pp] extension /pp2 set |
|
|
|
% step 3. Analyze the response. |
|
[pp2 (Content-Body) getNode |
|
pp2 (oxshell-stdout) getNode |
|
pp2 (oxshell-stderr) getNode |
|
] /arg1 set |
|
] pop |
|
popVariables |
|
arg1 |
|
} def |
|
|
|
/cgiQueryPolymake.native { |
|
/arg2 set /arg1 set |
[/saction /sfile /ff /ff1 /sss2 /goo /pp /pp2] pushVariables |
[/saction /sfile /ff /ff1 /sss2 /goo /pp /pp2] pushVariables |
[ |
[ |
/saction arg1 def /sfile arg2 def |
/saction arg1 def /sfile arg2 def |
|
|
] /ff set |
] /ff set |
[(cgiKeyValuePairToUrlEncodingString) ff] extension /ff set |
[(cgiKeyValuePairToUrlEncodingString) ff] extension /ff set |
[(POST ) , ff1 , ( HTTP/0.9) , nl , |
[(POST ) , ff1 , ( HTTP/0.9) , nl , |
(Connection: Keep-Alive) , nl , |
% (Connection: Keep-Alive) , nl , |
(Content-length: ) , ff length (string) dc , nl , |
(HOST: ) cgiQueryPolymake.hostname , nl , |
ff ] cat /sss2 set |
(Content-length: ) , ff length (dollar) dc , nl , nl |
|
ff nl] cat /sss2 set |
% step 2. Call the server and get the response in pp |
% step 2. Call the server and get the response in pp |
[(sm1.socket) (connect) |
[(sm1.socket) (connect) |
[80 cgiQueryPolymake.hostname]] extension 0 get /goo set |
[80 cgiQueryPolymake.hostname]] extension 0 get /goo set |
|
|
arg1 |
arg1 |
} def |
} def |
|
|
|
/cgi.test1 { |
|
(FACETS) |
|
[(POINTS) nl |
|
(1 0 0 ) nl |
|
(1 1 0 ) nl |
|
(1 0 1 ) nl |
|
] cat |
|
cgiQueryPolymake message |
|
} def |
% Overrides doPolymake |
% Overrides doPolymake |
%/doPolymake { doPolymake.OoHG } def |
%/doPolymake { doPolymake.OoHG } def |
%/polymake.start { polymake.start.OoHG } def |
%/polymake.start { polymake.start.OoHG } def |
|
|
[ |
[ |
arg1 0 get /pAction set |
arg1 0 get /pAction set |
arg1 1 get /pData set |
arg1 1 get /pData set |
polymake.start |
polymake.start.OoHG |
|
|
/pError [ ] def |
/pError [ ] def |
%% step 1: polymake tfb ===> polymake native data |
%% step 1: polymake tfb ===> polymake native data |