[BACK]Return to cgi.sm1 CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / Doc

Diff for /OpenXM/src/kan96xx/Doc/cgi.sm1 between version 1.2 and 1.3

version 1.2, 2004/09/24 13:15:27 version 1.3, 2004/09/27 01:20:46
Line 1 
Line 1 
 % $OpenXM: OpenXM/src/kan96xx/Doc/cgi.sm1,v 1.1 2004/09/24 08:35:47 takayama Exp $  % $OpenXM: OpenXM/src/kan96xx/Doc/cgi.sm1,v 1.2 2004/09/24 13:15:27 takayama Exp $
   %  OpenXM/src/polymake/cgi/cgi-polymake.sh
   %   is a shell script to call sm1/polymake as a CGI script.
   %  Override as /doPolymake {doPolymake.OoHG} def if you need.
   
   [(plugin-cgi)
   [(Key words: )
    ( cgiUrlEncodingToKeyValuePair)
    ( cgiKeyValuePairToHttpString)
    ( cgiKeyValuePairToUrlEncodingString)
    ( cgiStringToUrlEncoding)
    ( cgiUrlEncodedStringToObj)
    ( cgiHttpToKeyValuePair)
   ]] putUsages
   
 % A sample code  % A sample code
 % (OpenXM) cgiQueryGoogle  --> it does not work well.  % (OpenXM) cgiQueryGoogle  --> it does not work well.
 /cgiQueryGoogle {  /cgiQueryGoogle {
Line 37 
Line 50 
    [(cgiHttpToKeyValuePair) pp] extension /pp2 set     [(cgiHttpToKeyValuePair) pp] extension /pp2 set
 } def  } def
   
   [(readHTTP0)
   [(fd readHTTP0 result-str)
    (Read data from fd until the connection is closed.)
    (Example:)
    $[(sm1.socket) (connect) [80 (www.math.kobe-u.ac.jp)]] extension $
    $ 0 get /goo set $
    $goo readHTTP0 /pp set pp message$
    $[(sm1.socket) (close) [goo]] extension $
   ]] putUsages
 /readHTTP0 {  /readHTTP0 {
   /arg1 set    /arg1 set
   [/fd /sss /pp /pp2 /nn] pushVariables    [/fd /sss /pp /pp2 /nn] pushVariables
Line 57 
Line 79 
   arg1    arg1
 } def  } def
   
 % oxMessageBody=FACET input-data  % -----------------------  server side -----------------------
   %  command filename action
   /cgiPolymake.polymakeName (polymake) def
   %/cgiPolymake.polymakeName (polymake_dummy) def
   %/cgiPolymake.polymakeName (hoge) def
   
   [(cgiPolymake)
   [(Make sm1 to a polymake server based on CGI/OoHG)
    $ sm1 -q -s "[(parse) (cgi.sm1) pushfile] extension cgiPolymake quit " $
   ]] putUsages
   % Server-side-script
   % oxMessageBody=action input-data-for-polymake
   % sm1 -q -s "[(parse) (cgi.sm1) pushfile] extension cgiPolymake quit "
   % env QUERY_STRING="t?oxMessageBody=FACETS+POINTS+1+0+0%0A" sm1 -q -s "[(parse) (cgi.sm1) pushfile] extension cgiPolymake quit "
 /cgiPolymake {  /cgiPolymake {
   [(getenv) (QUERY_STRING)] extension cgiPolymake.0    {
      [(getenv) (QUERY_STRING)] extension /cgi.query_string set
      cgi.query_string isString { }
      {
        cgiPolymake.errorMessage message  exit
      } ifelse
      cgi.body.http0 message
      cgi.query_string cgiPolymake.0
      cgi.body cgiReplyInHttp0 /cgi.body.http set
      cgi.body.http message
      exit
     } loop
 } def  } def
   /cgiPolymake.errorMessage
     [ (Content-Type: text/html) nl
       nl
       (<html><body>) nl
       (Input <br> action polymake-data <br> ) nl
       (Example: <pre> ) nl
       (FACETS  POINTS) nl
       (1 0 0 ) nl
       (1 1 0 ) nl
       (1 0 1 ) nl
       (</pre>) nl
       (<form>) nl
       (<input type=submit>) nl
       (<textarea name="oxMesassageBody") nl
       ( rows=10 cols="80" wrap="soft"></textarea>) nl
       (</form>) nl
       (</body></html>) nl
     ] cat
   def
   
   /cgi.body.http0
     (Content-Type: text/plain)
   def
 /cgiPolymake.0 {  /cgiPolymake.0 {
   /arg1 set    /arg1 set
   [/sss /kv /comm /i /acti0 /pError] pushVariables    [/sss /kv /comm /i /acti0 /pError] pushVariables
   [    [
     /sss arg1 def      /sss arg1 def
   % Step 1.  analyze the query string in URL encoding.
     [(cgiUrlEncodingToKeyValuePair) sss] extension /kv set      [(cgiUrlEncodingToKeyValuePair) sss] extension /kv set
     kv (oxMessageBody) getNode /comm set      kv (oxMessageBody) getNode /comm set
   % Step 2. Extract action part and file part for polymake.
     comm (array) dc /comm set      comm (array) dc /comm set
     /i 0 def      /i 0 def
     [      [
Line 86 
Line 157 
     } for      } for
     cgi.body { (string) dc } map cat /cgi.body set      cgi.body { (string) dc } map cat /cgi.body set
   
   % Step 3. Calling polymake
 % acti0  cgi.body  % acti0  cgi.body
     /pError [ ] def      /pError [ ] def
 % bug: cgi.body --> oxsVarToFile(), value is not a string object ...  %  cgi.body --> oxsVarToFile(), value is not a string object ...
 %    [(polymake) (stringInOut://cgi.body) acti0] addStdoutStderr  %    [(polymake) (stringInOut://cgi.body) acti0] addStdoutStderr
     /aaa cgi.body def  %  It is not a bug; .body is removed from the variable name.
     [(polymake) (stringInOut://aaa) acti0] addStdoutStderr      /cgi_body cgi.body def
       [cgiPolymake.polymakeName (stringInOut://cgi_body.poly) acti0] addStdoutStderr
     oxshell pop      oxshell pop
     pError [@@@stdout @@@stderr] append /pError set      pError [@@@stdout @@@stderr] append /pError set
       /cgi.body cgi_body def
   ] pop    ] pop
   popVariables    popVariables
 } def  } def
Line 112 
Line 186 
    ff1 message     ff1 message
    ff1 cgiPolymake.0     ff1 cgiPolymake.0
    cgi.body message     cgi.body message
 } def  
   
   } def
   
   /cgiReplyInHttp0 {
     /arg1 set
     [/ss /sskv] pushVariables
     [
       /ss arg1 def
       [[(Content-Body) ss]
   %     [(Content-Type) (text/plain)]
        [(oxshell-stdout) @@@stdout]
        [(oxshell-stderr) @@@stderr]
       ] /sskv set
       [(cgiKeyValuePairToHttpString) sskv] extension /arg1 set
     ] pop
     arg1
   } def
   
   % ------------  client side script ---------------
   /cgiQueryPolymake.hostname (polymake.math.kobe-u.ac.jp) def
   /cgiQueryPolymake.cginame (cgi-bin/cgi-polymake.sh) def
   /cgiQueryPolymake {
     /arg2 set /arg1 set
     [/saction /sfile /ff /ff1 /sss2 /goo /pp /pp2] pushVariables
     [
       /saction arg1 def /sfile arg2 def
   % step1. Generate query in URL encoding.
       [[(URL) cgiQueryPolymake.cginame]
        [(oxMessageBody)
        [saction ( )
         sfile nl ] cat
        ]] /ff set
        [(cgiKeyValuePairToUrlEncodingString) ff] extension /ff1 set
        [(GET ) , ff1 , ( HTTP/0.9) , nl , nl ] cat /sss2 set
   % step 2. Call the server and get the response in pp
        [(sm1.socket) (connect)
           [80 cgiQueryPolymake.hostname]] extension 0 get /goo set
        [(sm1.socket) (write) [goo sss2]]  extension
        goo readHTTP0 /pp set
        pp message
        [(sm1.socket) (close) [goo]] extension
        [(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
   
   % Overrides doPolymake
   %/doPolymake { doPolymake.OoHG } def
   
   [(doPolymake.OoHG)
   [(It first looks for local polymake. If there is, it calls the local polymake.)
    (If not, it calls http://polymake.math.kobe-u.ac.jp/cgi-bin/cgi-polymake.sh)
    (to make a computation in polymake.)
    (See doPolymake for the syntax. doPolymake.OoHG may overrides doPolymake.)
   ]] putUsages
   /doPolymake.OoHG  {
     /arg1 set
     [/in-doPolymake.OoHG  /pAction /pData /pNative /ptree
      /pResult  /pError
     ] pushVariables
     [
       arg1 0 get /pAction set
       arg1 1 get /pData set
       polymake.start
   
       /pError [ ] def
   %% step 1:  polymake tfb ===> polymake native data
       @@@polymake.k0.ccc ( polymake=Object; ) oxexecutestring
       @@@polymake.k0.ccc ( QuoteMode(1); ) oxexecutestring
       @@@polymake.k0.ccc [pData ( ;)] cat oxexecutestring
       @@@polymake.k0.ccc oxpopcmo /ptree set
       @@@polymake.k0.ccc ( QuoteMode(0); ) oxexecutestring
       [(treeToPolymake) ptree] extension /pNative set
   %% step 2: calling the polymake
       [(which) (polymake)] oxshell tag 0 eq
       {
   % cgi-polymake
          (Trying web service.) message
          pAction pNative  cgiQueryPolymake /doPolymake.OoHG.result set
   
         doPolymake.OoHG.result 0 get /pNative set
         pError doPolymake.OoHG.result rest append /pError set
       } {
   % local polymake
         [(polymake) (stringInOut://pNative.poly) pAction] addStdoutStderr
         oxshell pop
         pError [@@@stdout @@@stderr] append /pError set
       } ifelse
   %% step 3: polymake native data to polymake tfb
       [(polymake2tfb) (<) (stringIn://pNative) (>) (stringOut://pResult)
        (2>) (stringOut://@@@stderr)] oxshell pop
       pError [@@@stderr] append /pError set
   %% step 4: get also tree style data.
       @@@polymake.k0.ccc ( polymake=Object; ) oxexecutestring
       @@@polymake.k0.ccc ( QuoteMode(1); ) oxexecutestring
       @@@polymake.k0.ccc [pResult ( ;)] cat oxexecutestring
       @@@polymake.k0.ccc oxpopcmo /ptree set
       @@@polymake.k0.ccc ( QuoteMode(0); ) oxexecutestring
       [pResult ptree pError] /arg1 set
     ] pop
     popVariables
     arg1
   } def
   
   
   
   

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>