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

Annotation of OpenXM/src/kan96xx/Doc/httpd-asir2.sm1, Revision 1.2

1.2     ! takayama    1: %% $OpenXM: OpenXM/src/kan96xx/Doc/httpd-asir2.sm1,v 1.1 2014/08/30 11:29:12 takayama Exp $
1.1       takayama    2: %% Asir server to be called from a cgi program.
                      3:
                      4: [(parse) (httpd-asir.sm1) pushfile] extension pop
                      5:
1.2     ! takayama    6: %% Default value of timer. Todo, not implemented.
        !             7: %% /webasir.tlimit (120) def
        !             8:
        !             9: %% export CGI_ASIR_ALLOW="[(fctr) (quit)]"
        !            10: %% export WEBASIR_TYPE="fctr"
        !            11: %% Start sm1 and webasir2, connect by asir-port/cgi/webasir2.c
1.1       takayama   12: %% Top level script
                     13: %% GET /?key=1%2B3%3B  [two nl]
                     14: %% GET /?msg=httpdAsirMeta+quit  HTTP/1.1 [two nl]
                     15: /httpd-asir2.quit 0 def
                     16: /webasir2 {
                     17:  [/rrr /cmd /mypid /lockname /mytype] pushVariables
                     18:  [
                     19:   %% This procedure to generate port number might fail.
                     20:   [(oxGenPass)] extension . (integer) dc  /rrr set
                     21:   rrr << rrr 20000 idiv 20000 mul >> sub /rrr set
                     22:   /httpd.port 1200 rrr add def
                     23:   httpd.port message
                     24:
1.2     ! takayama   25:   [(getenv) (CGI_ASIR_ALLOW)] extension tag 0 eq { /mytype (all) def }
        !            26:   {oxasirSetSecureFlagFromEnv} ifelse
        !            27:   [(getenv) (WEBASIR_TYPE)] extension isString {
        !            28:     /mytype [(getenv) (WEBASIR_Type)] extension def
        !            29:   } { /mytype (none) def } ifelse
1.1       takayama   30:   [(getpid)] extension (dollar) dc /mypid set
                     31:   [(/tmp/webasir-) mytype (-) mypid (.txt)] cat /lockname set
                     32:   [(PrintDollar) 0] system_variable
                     33:   [(outputObjectToFile) lockname
                     34:     [httpd.port nl httpd.textarea.name nl ] cat
                     35:   ] extension
                     36:   lockname message
                     37:   [(cat ) lockname] cat (system) nl message
                     38:   /httpd-asir2.quit 0 def
                     39:   httpd ;
                     40:   [(rm -f ) lockname] cat system
                     41:  ] pop
                     42:  popVariables
                     43: } def
                     44:
                     45: %% override httpd_action in httpd-asir.sm1
                     46: /httpd_action {
                     47:   [/in-httpd /ff /httpd.com /httpd.result /sss
                     48:    /sss.engine /sss.web /err
                     49:    /oxserver.vname
                     50:   ] pushVariables
                     51:   [
                     52:   {
                     53:        [(sm1.socket) (select) [httpd.server.fd 0 get -1]] extension
                     54:        %%     wait for ever
                     55:         [(sm1.socket) (readHTTP) [httpd.server.fd 0 get ]] extension /ff set
                     56:         ff tag 0 eq {
                     57:            (connection is closed.) message exit
                     58:         }
                     59:         {
                     60:           (------------  start ----------------------) message
                     61:              ff message
                     62:              /httpd.sendFile null def
                     63:           (-----------------------------------------) message
                     64:              ff removeGET webstringToAscii /httpd.com set
                     65:              [(httpd.com=) httpd.com] cat message
                     66:              (httpd.sendFile=) messagen httpd.sendFile message
                     67:           (------------  end ----------------------) message
                     68:           (   ) message
                     69:           httpd.serial 0 eq {
                     70:             /httpd.com  httpd.initialization def
                     71:             /httpd.textarea.valid 1 def
                     72:           } { } ifelse
                     73:           httpd.com metaCommand {
                     74:             httpd.textarea.valid {
                     75:               /oxserver.vname
                     76:                  [Oxserver_history_variable httpd.serial toString] cat
                     77:               def
                     78:               oxasir.ccc
                     79:               [(if (1) {)  httpd.com  (; };)] cat
                     80:               oxexecutestring ;
                     81:             }{
                     82:               send-page-warning  exit
                     83:             } ifelse
                     84:             [(oxReq) oxasir.ccc SM_dupErrors ] extension pop
                     85:
                     86:             [(oxReq) oxasir.ccc SM_popCMO ] extension pop
                     87:
                     88:             [(oxReq) oxasir.ccc SM_setName oxserver.vname] extension pop
                     89:             oxasir.ccc [oxserver.vname (;)] cat oxexecutestring
                     90:
                     91:             [(oxReq) oxasir.ccc SM_popString ] extension pop
                     92:             [(flush)] extension pop
                     93:             %% Select inputs for interruption.
                     94:             %% Wait by the spin lock.
                     95:             {
                     96:               [(oxMultiSelect) [oxasir.ccc] 1] extension 1 get 0 get
                     97:               /sss.engine set
                     98:               [(sm1.socket) (mselect)
                     99:                 [[httpd.server.fd 0 get] 1]
                    100:               ] extension 0 get /sss.web set
                    101:               /sss [sss.engine sss.web] def
                    102:               sss.engine { exit } { } ifelse
                    103:               sss.web    { exit } { } ifelse
                    104:             } loop
                    105:             sss message
                    106:
                    107:             sss 0 get {
                    108:                 [(oxGet) oxasir.ccc] extension  /err          set
                    109:                 [(oxGet) oxasir.ccc] extension  /httpd.result set
                    110:                 %% oxasir.ccc oxpopstring /httpd.result set
                    111:             } {
                    112:                 oxasir.ccc oxreset
                    113:                 oxasir.ccc ("computation is interrupted.";) oxexecutestring ;
                    114:                 oxasir.ccc oxpopstring
                    115:                 /httpd.result set
                    116:                 exit
                    117:             } ifelse
                    118:             (------------- result -------------) message
                    119:             httpd.result message
                    120:             (----------------------------------) message
                    121:             (  ) message
                    122:
                    123:             err message
                    124:             err [ ] eq  {
                    125:               /httpd.history
                    126:                 httpd.history
                    127:                 [10 (string) dc
                    128:                  (/**** ) httpd.serial toString ( ****/)
                    129:                  10 (string) dc
                    130:                   httpd.com
                    131:                  (;)  %% add extra ;
                    132:                  ] cat
                    133:                 append
                    134:               def
                    135:             } {
                    136:               oxasir.ccc cleanErrors
                    137:               [httpd.result 10 (string) dc err toString] cat
                    138:               /httpd.result set
                    139:             } ifelse
                    140:
                    141:             httpd.result
                    142:             sendln  exit  %% exit the loop LOOP-A
                    143:           } { exit } ifelse  %% metaCommand
                    144:         } ifelse
                    145:   } loop  %% LOOP-A
                    146:   ] pop
                    147:   popVariables
                    148: } def
                    149:
                    150: %%overrides metaCommand in httpd-asir.sm1
                    151: /metaCommand {
                    152:   /arg1 set
                    153:   [/in-metaCommand /msg /result /msg2 /nn
                    154:    /err /fn
                    155:   ] pushVariables
                    156:   [
                    157:     /msg arg1 def
                    158:     /result 1 def
                    159:     msg 1 copy toTokensBySpace /msg2 set
                    160:     msg (httpdAsirMeta quit) eq {
                    161:        oxasir.ccc oxshutdown
                    162:        (byebye) sendln
                    163:        /httpd-asir2.quit 1 def
                    164:        /result 0 def
                    165:     } { } ifelse
                    166:     msg (httpdAsirMeta save) eq {
                    167:        send-page-save
                    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: %%override httpd in httpd.sm1
                    182: /httpd {
                    183:   /httpd.serial 1 def
                    184:   /httpd.history [ ] def
                    185:   /httpd.result.history [ 0 ] def
                    186:   [(nobody)] extension pop
                    187:   {
                    188:     httpd_startserver ;
                    189:     httpd_action ;
                    190:     httpd_stopserver ;
                    191:     httpd.take.log { (date) system  } { } ifelse
                    192: %    (sleep 2) system
                    193:     httpd.serial 1 add /httpd.serial set
                    194:     httpd-asir2.quit { exit } { } ifelse
                    195:   } loop
                    196: } def
1.2     ! takayama  197:
        !           198: % overrides or new for cgiasir.sm1
        !           199: /oxasirSetSecureMode {
        !           200:   oxasir.ccc [ ] eq { ox_asirConnectMethod } { } ifelse
        !           201:   oxasir.ccc $ctrl("error_in_timer",1);$ oxsubmit
        !           202:   oxasir.ccc $set_secure_mode(1);$ oxsubmit
        !           203: } def
        !           204:
        !           205: /oxasirSetSecureFlag {
        !           206:   /arg1 set
        !           207:   [/fff ] pushVariables
        !           208:   [
        !           209:     /fff arg1 def
        !           210:     oxasir.ccc [ ] eq { ox_asirConnectMethod } { } ifelse
        !           211:     oxasir.ccc [$set_secure_flag("$ fff toString $",1);$] cat oxsubmit
        !           212:     oxasir.ccc oxpopcmo
        !           213:   ] pop
        !           214:   popVariables
        !           215: } def
        !           216:
        !           217: %%%
        !           218: /oxasirSetSecureFlagFromEnv {
        !           219:      [(getenv) (CGI_ASIR_ALLOW)] extension isString {
        !           220:         [(getenv) (CGI_ASIR_ALLOW)] extension  /cgiAsirAllow.s set
        !           221:         [(parse) cgiAsirAllow.s] extension pop /cgiAsirAllow.p set
        !           222:         cgiAsirAllow.p isArray {
        !           223:            cgiAsirAllow.p /cgiAsirAllow  set
        !           224:         } {  } ifelse
        !           225:      } {  } ifelse
        !           226:      cgiAsirAllow {oxasirSetSecureFlag} map
        !           227:      oxasirSetSecureMode
        !           228: } def
        !           229:

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