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

1.2     ! takayama    1: %% $OpenXM: OpenXM/src/kan96xx/Doc/httpd-rpc.sm1,v 1.1 2002/10/23 13:38:50 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.2     ! takayama   12: %%******* Put initialization codes for ox_asir here.
        !            13: /httpd.initialization
        !            14:  [
        !            15:   (XM_debug=0; ctrl("debug_window",0); Xm_noX=1;)
        !            16:   ("Asirweb version 0.80. "+
        !            17:    " Risa/Asir oxasir version "+rtostr(version());)
        !            18:  ] cat
        !            19: def
1.1       takayama   20:
                     21:
                     22: [(parse) (oxasir.sm1) pushfile] extension
                     23: oxNoX
                     24: (oxasir.started) boundp {
                     25: } {
                     26:   %% Initialize oxasir.
                     27:   [(x^2-1) (x)] fctr pop
                     28:   oxasir.ccc oxmathcap
                     29:   oxasir.ccc oxsetmathcap
1.2     ! takayama   30:   oxasir.ccc httpd.initialization oxexecutestring ;
        !            31:   (Initialization returns ...: ) messagen
        !            32:   oxasir.ccc oxpopcmo message ;
1.1       takayama   33: } ifelse
                     34:
                     35: /webrpc  {
                     36:  [/rrr ] pushVariables
                     37:  [
                     38:   [(oxGenPass)] extension . (integer) dc  /rrr set
                     39:
                     40:   [(ostype)] extension 0 get
                     41:    (windows) eq {
                     42:      %% On windows.
                     43:       [(forkExec)
                     44:        [
                     45:          ox.win.start.0 aload pop
                     46:          (iexplore)   %% Starting internet explorer (TM).
                     47:          [(http://localhost:) httpd.port toString] cat
                     48:        ]
                     49:        [  ]
                     50:       3] extension
                     51:    }{
                     52:       %% On unix.
                     53:       [(sleep 3 ; netscape http://localhost:) httpd.port toString ( & ) ] cat
                     54:       system
                     55:    } ifelse
                     56:
                     57:    httpd ;
                     58:   ] pop
                     59:   popVariables
                     60: } def
                     61:
                     62:
                     63: /httpd_action {
                     64:   [/in-httpd /ff /httpd.com /httpd.result /sss
                     65:    /sss.engine /sss.web /err
                     66:    /oxserver.vname
                     67:   ] pushVariables
                     68:   [
                     69:   {
                     70:        [(sm1.socket) (select) [httpd.server.fd 0 get -1]] extension
                     71:        %%     wait for ever
                     72:         [(sm1.socket) (readHTTP) [httpd.server.fd 0 get ]] extension /ff set
1.2     ! takayama   73:         ff tag 0 eq {
        !            74:            (connection is closed.) message exit
1.1       takayama   75:         }
                     76:         {
                     77:           (------------  start ----------------------) message
                     78:              ff message
                     79:           (-----------------------------------------) message
                     80:              ff removeGET webstringToAscii /httpd.com set
                     81:              [(httpd.com=) httpd.com] cat message
                     82:           (------------  end ----------------------) message
                     83:           (   ) message
1.2     ! takayama   84:
1.1       takayama   85:           httpd.com metaCommand {
                     86:             httpd.textarea.valid {
                     87:
                     88:               %%%  Executing command, here.
                     89:               oxasir.ccc
                     90:               httpd.com cookedCommand
                     91:               oxexecutestring ;
                     92:
                     93:             }{
                     94:               send-page-usage  exit
                     95:             } ifelse
                     96:
                     97:             [(oxReq) oxasir.ccc SM_dupErrors ] extension pop
                     98:
                     99:             [(oxReq) oxasir.ccc SM_popCMO ] extension pop
                    100:             [(oxReq) oxasir.ccc SM_popString ] extension pop
                    101:
                    102:             [(flush)] extension pop
                    103:             %% Select inputs for interruption.
                    104:             %% Wait by the spin lock.
                    105:             {
                    106:               [(oxMultiSelect) [oxasir.ccc] 1] extension 1 get 0 get
                    107:               /sss.engine set
                    108:               [(sm1.socket) (mselect)
                    109:                 [[httpd.server.fd 0 get] 1]
                    110:               ] extension 0 get /sss.web set
                    111:               /sss [sss.engine sss.web] def
                    112:               sss.engine { exit } { } ifelse
                    113:               sss.web    { exit } { } ifelse
                    114:             } loop
                    115:             sss message
                    116:
                    117:             sss 0 get {
                    118:                 [(oxGet) oxasir.ccc] extension  /err          set
                    119:                 [(oxGet) oxasir.ccc] extension  /httpd.result set
                    120:             } {
                    121:                 oxasir.ccc oxreset
                    122:                 oxasir.ccc ("computation is interrupted.";) oxexecutestring ;
                    123:                 oxasir.ccc oxpopstring
                    124:                 /httpd.result set
                    125:                 exit
                    126:             } ifelse
                    127:             (------------- result -------------) message
                    128:             httpd.result message
                    129:             (----------------------------------) message
                    130:             (  ) message
1.2     ! takayama  131:
        !           132:             (----------- error -------------) message
1.1       takayama  133:             err message
1.2     ! takayama  134:             (-------------------------------) message
1.1       takayama  135:             err [ ] eq  {
                    136:             } {
                    137:               oxasir.ccc cleanErrors
                    138:               [httpd.result 10 (string) dc err toString] cat
                    139:               /httpd.result set
                    140:             } ifelse
                    141:
                    142:             httpd.result send-page-result  exit  %% exit the loop LOOP-A
                    143:           } { exit } ifelse  %% metaCommand
                    144:         } ifelse
                    145:   } loop  %% LOOP-A
                    146:   ] pop
                    147:   popVariables
                    148: } def
                    149:
                    150:
                    151:
                    152:
                    153: /metaCommand {
                    154:   /arg1 set
                    155:   [/in-metaCommand /msg /result /msg2 /nn
                    156:    /err /fn
                    157:   ] pushVariables
                    158:   [
                    159:     /msg arg1 def
                    160:     /result 1 def
                    161:     msg (httpdAsirMeta quit) eq {
                    162:        oxasir.ccc oxshutdown
                    163:        send-page-bye
                    164:        quit
                    165:        /result 0 def
                    166:     } { } ifelse
                    167:     msg (httpdAsirMeta interrupt) eq {
                    168:        oxasir.ccc oxreset
                    169:        (Interrupted! <br>) send-page-3
                    170:        /result 0 def
                    171:     } { } ifelse
                    172:     /arg1 result def
                    173:   ] pop
                    174:   popVariables
                    175:   arg1
                    176: } def
                    177:
                    178: /send-page-usage {
                    179:   [/in-send-page-usage ] pushVariables
                    180:   [
                    181:    (HTTP/0.9 200 OK) sendln
                    182:    (Connection: close) sendln
                    183:    (Content-Type: text/html) sendln
                    184:    0 sendln
                    185:
                    186:   (<H1> Usage </H2> <br> ) sendln
                    187:   [(Ask by GET /?) httpd.textarea.name (=) ( encoded_codes  HTTP/1.0)] cat
                    188:   sendln
                    189:   (<br>) sendln
                    190:   [(getenv) (OXWEB_POST)] extension tag 0 eq {
                    191:     (<FORM NAME="myFORM">) sendln  % use get
                    192:   }{
                    193:     (<FORM NAME="myFORM" METHOD="POST">) sendln
                    194:   } ifelse
                    195:    (<INPUT TYPE=submit VALUE="submit">) sendln
                    196:    [(<textarea name=) httpd.textarea.name
                    197:     ( rows=10 cols="80" wrap="soft"></textarea>)] cat sendln
                    198:    (</FORM>) sendln
                    199:    [$<a href="http://localhost:$ httpd.port toString
                    200:     $/?msg=httpdAsirMeta+quit"> Shutdown the server. </a>, $
                    201:    ] cat sendln
                    202:
                    203:    0 sendln
                    204:    [(flush)] extension
                    205:   ] pop
                    206:   popVariables
                    207: } def
                    208:
                    209:
                    210:
                    211: /send-page-result {
                    212:   /arg1 set
                    213:   [/in-send-page-result /result] pushVariables
                    214:   [
                    215:    /result arg1 def
                    216:    (HTTP/0.9 200 OK) sendln
                    217:    (Connection: close) sendln
                    218:    (Content-Type: text/html) sendln
                    219:    0 sendln
                    220:
                    221:    result sendln
                    222:    0 sendln
                    223:    [(flush)] extension
                    224:   ] pop
                    225:   popVariables
                    226: } def
                    227:
1.2     ! takayama  228: %% **** Overwrites the definition in httpd.sm1
        !           229: /httpd_startserver {
        !           230:    (httpd server accessible outside localhost.) message
        !           231:    %%  get the hostname of this machine.
        !           232:    [(sm1.socket) (open) [httpd.port
        !           233:                          [(sm1.socket) (gethostname) [ ] ]extension ] ]
        !           234:     extension
        !           235:    /httpd.server.fdAndPort set
        !           236:    (sm1.socket.open returns  ) messagen httpd.server.fdAndPort message
        !           237:    [(sm1.socket) (accept) [httpd.server.fdAndPort 0 get]] extension
        !           238:    /httpd.server.fd set
        !           239:    (connected.) message
        !           240:    (sm1.socket.accept returns <httpd.server.fd> ) messagen
        !           241:    httpd.server.fd message
        !           242:
        !           243: } def
1.1       takayama  244:
                    245: %% ******* sample of cooked command
                    246: /cookedCommand {
                    247:   /arg1 set
                    248:   [/in-cookedCommand /httpd.com] pushVariables
                    249:   [
                    250:     /httpd.com arg1 def
                    251:     [(if (1) {)  httpd.com  (; };)] cat
                    252:     /arg1 set
                    253:   ] pop
                    254:   popVariables
                    255:   arg1
                    256: } def

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