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

Annotation of OpenXM/src/kan96xx/Doc/httpd-rpc.sm1, Revision 1.11

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

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