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

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

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