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