Annotation of OpenXM/src/kan96xx/Doc/httpd-asir2.sm1, Revision 1.1
1.1 ! takayama 1: %% $OpenXM$
! 2: %% Asir server to be called from a cgi program.
! 3:
! 4: [(parse) (httpd-asir.sm1) pushfile] extension pop
! 5:
! 6: %% Top level script
! 7: %% GET /?key=1%2B3%3B [two nl]
! 8: %% GET /?msg=httpdAsirMeta+quit HTTP/1.1 [two nl]
! 9: /httpd-asir2.quit 0 def
! 10: /webasir2 {
! 11: [/rrr /cmd /mypid /lockname /mytype] pushVariables
! 12: [
! 13: %% This procedure to generate port number might fail.
! 14: [(oxGenPass)] extension . (integer) dc /rrr set
! 15: rrr << rrr 20000 idiv 20000 mul >> sub /rrr set
! 16: /httpd.port 1200 rrr add def
! 17: httpd.port message
! 18:
! 19: [(getenv) (ASIR_TYPE)] extension isString {
! 20: /mytype [(getenv) (ASIR_Type)] extension def
! 21: } { /mytype (all) def } ifelse
! 22: [(getpid)] extension (dollar) dc /mypid set
! 23: [(/tmp/webasir-) mytype (-) mypid (.txt)] cat /lockname set
! 24: [(PrintDollar) 0] system_variable
! 25: [(outputObjectToFile) lockname
! 26: [httpd.port nl httpd.textarea.name nl ] cat
! 27: ] extension
! 28: lockname message
! 29: [(cat ) lockname] cat (system) nl message
! 30: /httpd-asir2.quit 0 def
! 31: httpd ;
! 32: [(rm -f ) lockname] cat system
! 33: ] pop
! 34: popVariables
! 35: } def
! 36:
! 37: %% override httpd_action in httpd-asir.sm1
! 38: /httpd_action {
! 39: [/in-httpd /ff /httpd.com /httpd.result /sss
! 40: /sss.engine /sss.web /err
! 41: /oxserver.vname
! 42: ] pushVariables
! 43: [
! 44: {
! 45: [(sm1.socket) (select) [httpd.server.fd 0 get -1]] extension
! 46: %% wait for ever
! 47: [(sm1.socket) (readHTTP) [httpd.server.fd 0 get ]] extension /ff set
! 48: ff tag 0 eq {
! 49: (connection is closed.) message exit
! 50: }
! 51: {
! 52: (------------ start ----------------------) message
! 53: ff message
! 54: /httpd.sendFile null def
! 55: (-----------------------------------------) message
! 56: ff removeGET webstringToAscii /httpd.com set
! 57: [(httpd.com=) httpd.com] cat message
! 58: (httpd.sendFile=) messagen httpd.sendFile message
! 59: (------------ end ----------------------) message
! 60: ( ) message
! 61: httpd.serial 0 eq {
! 62: /httpd.com httpd.initialization def
! 63: /httpd.textarea.valid 1 def
! 64: } { } ifelse
! 65: httpd.com metaCommand {
! 66: httpd.textarea.valid {
! 67: /oxserver.vname
! 68: [Oxserver_history_variable httpd.serial toString] cat
! 69: def
! 70: oxasir.ccc
! 71: [(if (1) {) httpd.com (; };)] cat
! 72: oxexecutestring ;
! 73: }{
! 74: send-page-warning exit
! 75: } ifelse
! 76: [(oxReq) oxasir.ccc SM_dupErrors ] extension pop
! 77:
! 78: [(oxReq) oxasir.ccc SM_popCMO ] extension pop
! 79:
! 80: [(oxReq) oxasir.ccc SM_setName oxserver.vname] extension pop
! 81: oxasir.ccc [oxserver.vname (;)] cat oxexecutestring
! 82:
! 83: [(oxReq) oxasir.ccc SM_popString ] extension pop
! 84: [(flush)] extension pop
! 85: %% Select inputs for interruption.
! 86: %% Wait by the spin lock.
! 87: {
! 88: [(oxMultiSelect) [oxasir.ccc] 1] extension 1 get 0 get
! 89: /sss.engine set
! 90: [(sm1.socket) (mselect)
! 91: [[httpd.server.fd 0 get] 1]
! 92: ] extension 0 get /sss.web set
! 93: /sss [sss.engine sss.web] def
! 94: sss.engine { exit } { } ifelse
! 95: sss.web { exit } { } ifelse
! 96: } loop
! 97: sss message
! 98:
! 99: sss 0 get {
! 100: [(oxGet) oxasir.ccc] extension /err set
! 101: [(oxGet) oxasir.ccc] extension /httpd.result set
! 102: %% oxasir.ccc oxpopstring /httpd.result set
! 103: } {
! 104: oxasir.ccc oxreset
! 105: oxasir.ccc ("computation is interrupted.";) oxexecutestring ;
! 106: oxasir.ccc oxpopstring
! 107: /httpd.result set
! 108: exit
! 109: } ifelse
! 110: (------------- result -------------) message
! 111: httpd.result message
! 112: (----------------------------------) message
! 113: ( ) message
! 114:
! 115: err message
! 116: err [ ] eq {
! 117: /httpd.history
! 118: httpd.history
! 119: [10 (string) dc
! 120: (/**** ) httpd.serial toString ( ****/)
! 121: 10 (string) dc
! 122: httpd.com
! 123: (;) %% add extra ;
! 124: ] cat
! 125: append
! 126: def
! 127: } {
! 128: oxasir.ccc cleanErrors
! 129: [httpd.result 10 (string) dc err toString] cat
! 130: /httpd.result set
! 131: } ifelse
! 132:
! 133: httpd.result
! 134: sendln exit %% exit the loop LOOP-A
! 135: } { exit } ifelse %% metaCommand
! 136: } ifelse
! 137: } loop %% LOOP-A
! 138: ] pop
! 139: popVariables
! 140: } def
! 141:
! 142: %%overrides metaCommand in httpd-asir.sm1
! 143: /metaCommand {
! 144: /arg1 set
! 145: [/in-metaCommand /msg /result /msg2 /nn
! 146: /err /fn
! 147: ] pushVariables
! 148: [
! 149: /msg arg1 def
! 150: /result 1 def
! 151: msg 1 copy toTokensBySpace /msg2 set
! 152: msg (httpdAsirMeta quit) eq {
! 153: oxasir.ccc oxshutdown
! 154: (byebye) sendln
! 155: /httpd-asir2.quit 1 def
! 156: /result 0 def
! 157: } { } ifelse
! 158: msg (httpdAsirMeta save) eq {
! 159: send-page-save
! 160: /result 0 def
! 161: } { } ifelse
! 162: msg (httpdAsirMeta interrupt) eq {
! 163: oxasir.ccc oxreset
! 164: (Interrupted! <br>) send-page-3
! 165: /result 0 def
! 166: } { } ifelse
! 167: /arg1 result def
! 168: ] pop
! 169: popVariables
! 170: arg1
! 171: } def
! 172:
! 173: %%override httpd in httpd.sm1
! 174: /httpd {
! 175: /httpd.serial 1 def
! 176: /httpd.history [ ] def
! 177: /httpd.result.history [ 0 ] def
! 178: [(nobody)] extension pop
! 179: {
! 180: httpd_startserver ;
! 181: httpd_action ;
! 182: httpd_stopserver ;
! 183: httpd.take.log { (date) system } { } ifelse
! 184: % (sleep 2) system
! 185: httpd.serial 1 add /httpd.serial set
! 186: httpd-asir2.quit { exit } { } ifelse
! 187: } loop
! 188: } def
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>