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

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

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