[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.7

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

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