version 1.9, 2002/10/21 10:43:52 |
version 1.14, 2002/11/09 12:42:25 |
|
|
%% $OpenXM: OpenXM/src/kan96xx/Doc/httpd.sm1,v 1.8 2002/10/21 02:25:51 takayama Exp $ |
%% $OpenXM: OpenXM/src/kan96xx/Doc/httpd.sm1,v 1.13 2002/11/03 12:43:03 takayama Exp $ |
%% common modules for httpd on sm1. |
%% common modules for httpd on sm1. |
/Oxserver_history_variable (Oxserver_history_variable_) def |
/Oxserver_history_variable (Oxserver_history_variable_) def |
/httpd.image.type |
/httpd.image.type |
[(getenv) (OpenXM_PSTOIMG_TYPE)] extension |
[(getenv) (OpenXM_PSTOIMG_TYPE)] extension |
def |
def |
|
|
|
[(getenv) (OXWEB_DEBUG)] extension tag 0 eq { |
|
/httpd.debug 0 def |
|
} { |
|
/httpd.debug 1 def |
|
} ifelse |
|
[(getenv) (OXWEB_TAKE_LOG)] extension tag 0 eq { |
|
/httpd.take.log 0 def |
|
} { |
|
/httpd.take.log 1 def |
|
} ifelse |
|
|
|
|
/httpd_startserver { |
/httpd_startserver { |
[(sm1.socket) (open) [httpd.port (localhost)]] extension |
[(sm1.socket) (open) [httpd.port (localhost)]] extension |
/httpd.server.fdAndPort set |
/httpd.server.fdAndPort set |
|
|
|
|
/sendln { |
/sendln { |
/arg1 set |
/arg1 set |
[/in-sendln /mmm] pushVariables |
[/in-sendln /mmm /i] pushVariables |
[ arg1 /mmm set |
[ arg1 /mmm set |
mmm tag 5 eq { |
mmm tag 5 eq { |
[mmm 10 (string) dc] cat /mmm set |
[mmm 10 (string) dc] cat /mmm set |
|
|
[(sm1.socket) (select) [httpd.server.fd 0 get 0]] extension { |
[(sm1.socket) (select) [httpd.server.fd 0 get 0]] extension { |
(Warning (sendln): your peer closed the connection. Do not send the data.) message |
(Warning (sendln): your peer closed the connection. Do not send the data.) message |
} { |
} { |
[(sm1.socket) (write) [httpd.server.fd 0 get mmm]] extension message |
[(sm1.socket) (write) [httpd.server.fd 0 get mmm]] extension /i set |
|
httpd.debug { i message } { } ifelse |
} ifelse |
} ifelse |
] pop |
] pop |
popVariables |
popVariables |
|
|
httpd_startserver ; |
httpd_startserver ; |
httpd_action ; |
httpd_action ; |
httpd_stopserver ; |
httpd_stopserver ; |
|
httpd.take.log { (date) system } { } ifelse |
% (sleep 2) system |
% (sleep 2) system |
httpd.serial 1 add /httpd.serial set |
httpd.serial 1 add /httpd.serial set |
} loop |
} loop |
|
|
ss i (,) put |
ss i (,) put |
} { } ifelse |
} { } ifelse |
} for |
} for |
ss message |
httpd.debug { ss message } { } ifelse |
[ ss to_records pop] /arg1 set |
[ ss to_records pop] /arg1 set |
] pop |
] pop |
popVariables |
popVariables |
|
|
/removeGET { |
/removeGET { |
/arg1 set |
/arg1 set |
[/in-removeGET /s /s2 /i /j /i0 |
[/in-removeGET /s /s2 /i /j /i0 |
/tname /nnn |
/tname /nnn /sta |
] pushVariables |
] pushVariables |
[ |
[ |
/s arg1 def |
/s arg1 def |
/httpd.textarea.valid 1 def |
/httpd.textarea.valid 0 def |
s 1 copy /s2 set |
s 1 copy /s2 set |
s (array) dc /s set |
s (array) dc /s set |
|
|
|
/sta 0 def |
|
|
|
%% In case of POST, remove the HTTP header. cf. trouble for NS 6.0 |
|
s length 4 gt { |
|
[s 0 get s 1 get s 2 get s 3 get] (POST) (array) dc eq { |
|
0 1 s length 4 sub { |
|
/i0 set |
|
/sta i0 def |
|
[ s i0 get s i0 1 add get ] [ 10 10 ] eq |
|
[ s i0 get s i0 1 add get s i0 2 add get s i0 3 add get] |
|
[ 13 10 13 10] eq or |
|
{ exit } { } ifelse |
|
} for |
|
}{ } ifelse |
|
} { } ifelse |
|
(sta=) messagen sta message |
/nnn httpd.textarea.name.aaa length 6 sub def |
/nnn httpd.textarea.name.aaa length 6 sub def |
|
|
/tname [ ] def |
/tname [ ] def |
0 1 s length 1 sub { |
sta 1 s length 1 sub { |
/i0 set |
/i0 set |
s i0 get 61 eq { %% 61 is = |
s i0 get 61 eq { %% 61 is = |
i0 1 add /i0 set |
i0 1 add /i0 set |
|
|
] reverse /tname set |
] reverse /tname set |
(GET /?) (array) dc tname join /tname set |
(GET /?) (array) dc tname join /tname set |
|
|
httpd.textarea.name.aaa message |
httpd.debug { httpd.textarea.name.aaa message } { } ifelse |
tname httpd.textarea.name.aaa eq { |
tname httpd.textarea.name.aaa eq { |
/httpd.textarea.valid 1 def |
/httpd.textarea.valid 1 def |
} { |
} { |
/httpd.textarea.valid 0 def |
/httpd.textarea.valid 0 def |
|
tname message |
httpd.textarea.name.aaa { (string) dc } map cat message |
httpd.textarea.name.aaa { (string) dc } map cat message |
(Warning: got an invalid name for the text field.) message |
(Warning: got an invalid name for the text field.) message |
} ifelse |
} ifelse |
|
|
] pop |
] pop |
popVariables |
popVariables |
arg1 |
arg1 |
} def |
|
|
|
|
} def |
|
|
|
% This function will be written in C in a future. |
|
% [(httpd) (parseHTTP) string] extension |
|
% [(GET) key-value-pair-1 key-value-pair-2 ...] |
|
% [(POST) key-value-pair-1 key-value-pair-2 ...] |
|
% [(GET-file) file-1 file2 ...] |
|
% ex. (GET / HTT..) (GET /?rpc=1-2) |
|
/httpd.parse { |
|
/arg1 set |
|
[/in-httpd.parse /s /s2 /sta /i0 |
|
/ans /getKeyword /j /tname /tvalue |
|
] pushVariables |
|
[ |
|
/s arg1 def |
|
s 1 copy /s2 set |
|
s (array) dc /s set |
|
|
|
/sta 0 def |
|
/getKeyword 0 def |
|
|
|
s length 7 lt { |
|
/ans [(GET-file)] def |
|
/httpd.exit goto |
|
}{ } ifelse |
|
|
|
/ans [(GET)] def |
|
[s 0 get s 1 get s 2 get s 3 get s 4 get s 5 get] (GET /?) (array) dc eq { |
|
/sta 6 def |
|
/getKeyword 1 def |
|
}{ |
|
[s 0 get s 1 get s 2 get s 3 get s 4 get] (GET /) (array) dc eq { |
|
/sta 5 def |
|
}{ |
|
[s 0 get s 1 get s 2 get s 3 get] (GET ) (array) dc eq { |
|
/ans [(GET-file)] def |
|
/httpd.exit goto |
|
} { /ans [ ] def /httpd.exit.goto } ifelse |
|
} ifelse |
|
}ifelse |
|
|
|
%% In case of POST, remove the HTTP header. cf. trouble for NS 6.0 |
|
[s 0 get s 1 get s 2 get s 3 get] (POST) (array) dc eq { |
|
/ans [(POST) ] def |
|
/getKeyword 1 def |
|
0 1 s length 4 sub { |
|
/i0 set |
|
/sta i0 def |
|
[ s i0 get s i0 1 add get ] [ 10 10 ] eq |
|
[ s i0 get s i0 1 add get s i0 2 add get s i0 3 add get] |
|
[ 13 10 13 10] eq or |
|
{ exit } { } ifelse |
|
} for |
|
}{ } ifelse |
|
(sta=) messagen sta message |
|
|
|
%% get file name |
|
getKeyword not { |
|
/tname [ ] def |
|
sta 1 << s length 1 sub >> { |
|
/i0 set |
|
s i0 get 32 le { %% 32 is " " |
|
exit |
|
} { } ifelse |
|
tname s i0 get append /tname set |
|
} for |
|
httpd.debug { (Filename is ) messagen tname {(string) dc } map message} { } ifelse |
|
/ans [(GET-file) tname { (string) dc } map cat ] def |
|
/httpd.exit goto |
|
} { } ifelse |
|
|
|
/tname [ ] def |
|
sta 1 << s length 1 sub >> { |
|
/i0 set |
|
s i0 get 61 eq { %% 61 is = |
|
httpd.debug { tname message tname {(string) dc } map cat message} { } ifelse |
|
i0 1 add /i0 set |
|
exit |
|
} { } ifelse |
|
tname s i0 get append /tname set |
|
} for |
|
|
|
/j 0 def |
|
i0 1 s length 1 sub { |
|
/i set |
|
s2 j << s i get (string) dc >> put |
|
j s2 length 1 sub lt { s2 j 1 add ( ) put } { } ifelse |
|
%% might cause a BUG. It should be improved. |
|
j 1 add /j set |
|
} for |
|
ans [tname {(string) dc} map cat |
|
s2 webstringToAscii ] append |
|
/ans set |
|
|
|
/httpd.exit |
|
ans length 1 lt { |
|
/ans [(Unknown)] def |
|
} { } ifelse |
|
/arg1 ans def |
|
] pop |
|
popVariables |
|
arg1 |
|
} def |
|
|
|
/httpd.root [(getenv) (OXWEB_HTTPD_ROOT)] extension def |
|
%% /usr/local/www/data/ Assume slash!! |
|
|
|
% [(GET-file) (filename)] httpd_sendfile |
|
% [(MSG) (message)] httpd_sendfile |
|
/httpd_sendfile { |
|
/arg1 set |
|
[/in-htpd_sendfile /msg /fname /fname2 |
|
/fsize |
|
] pushVariables |
|
[ |
|
/msg arg1 def |
|
%% Send message. [(MSG) msg2 ...] httpd_sendfile |
|
msg message |
|
msg 0 get (MSG) eq { |
|
(HTTP/0.9 200 OK) sendln |
|
(Connection: close) sendln |
|
(Content-Type: text/html) sendln |
|
0 sendln |
|
msg rest { sendln } map |
|
0 sendln |
|
[(flush)] extension |
|
/httpd_sendfile.L1 goto |
|
}{ } ifelse |
|
%% Get a file message. [(GET-file) fname] httpd_sendfile |
|
msg 0 get (GET-file) eq { |
|
httpd.root tag 5 eq not { |
|
[(MSG) (<h1> File transfer is not allowed on this server. </h1>)] |
|
httpd_sendfile |
|
/httpd_sendfile.L1 /httpd_sendfile.L1 goto |
|
} { } ifelse |
|
msg length 1 eq { |
|
/fname (index.html) def |
|
}{ |
|
/fname msg 1 get def |
|
fname tag 5 eq not { |
|
[(MSG) (<h1> Invalid file name. </h1>)] |
|
httpd_sendfile |
|
/httpd_sendfile.L1 /httpd_sendfile.L1 goto |
|
} { } ifelse |
|
fname (array) dc /fname set |
|
fname length 1 lt { |
|
[(MSG) (<h1> Invalid file name. </h1>)] |
|
httpd_sendfile |
|
/httpd_sendfile.L1 /httpd_sendfile.L1 goto |
|
} { } ifelse |
|
|
|
fname [47] eq { |
|
/fname (index.html) (array) dc def |
|
}{ } ifelse |
|
|
|
fname 0 get 47 eq { %% / |
|
/fname fname rest def |
|
} { } ifelse |
|
|
|
fname { (string) dc } map cat /fname set |
|
} ifelse |
|
|
|
/fname2 fname def |
|
[httpd.root fname2] cat /fname set |
|
[(fname=) fname] cat message |
|
[(stat) fname] extension 0 get tag 0 eq { |
|
[(MSG) (Warning (sendfile): the file ) fname2 ( is not found.) ] |
|
httpd_sendfile |
|
/httpd_sendfile.L1 /httpd_sendfile.L1 goto |
|
}{ }ifelse |
|
[(stat) fname] extension 1 get 0 get toString /fsize set |
|
(HTTP/1.1 200 OK) sendln |
|
(Server: httpd_sm1) sendln |
|
%% (ETag: "2197-bf6c-3b2d6541") sendln ??? |
|
(Accept-Ranges: bytes) sendln |
|
[(Content-Length: ) fsize] cat sendln |
|
(Connection: close) sendln |
|
[(Content-Type: ) fname httpd_type] cat sendln |
|
[(flush)] extension |
|
0 sendln |
|
fname sendBinaryFile |
|
0 sendln |
|
[(flush)] extension |
|
0 sendln |
|
[(flush)] extension |
|
/httpd_sendfile.L1 goto |
|
}{ |
|
[(MSG) (Warning: unknown argument type for httpd_sendfile)] |
|
httpd_sendfile |
|
} ifelse |
|
/httpd_sendfile.L1 |
|
] pop |
|
popVariables |
|
} def |
|
|
|
/httpd_type { |
|
/arg1 set |
|
[/in-httpd_type /fname /ftype /i /ans] pushVariables |
|
[ |
|
/fname arg1 def |
|
fname (array) dc /fname set |
|
fname reverse /fname set |
|
[ |
|
0 1 fname length 1 sub { |
|
/i set |
|
fname i get 46 eq { % '.' |
|
exit |
|
} { fname i get } ifelse |
|
} for |
|
] /ftype set |
|
ftype reverse {(string) dc} map cat /ftype set |
|
/ans (text/plain) def |
|
ftype (gif) eq { |
|
/ans (image/gif) def |
|
}{ } ifelse |
|
ftype (jpeg) eq ftype (jpg) eq or { |
|
/ans (image/jpeg) def |
|
}{ } ifelse |
|
ftype (png) eq { |
|
/ans (image/png) def |
|
}{ } ifelse |
|
ftype (png) eq { |
|
/ans (image/png) def |
|
}{ } ifelse |
|
ftype (html) eq ftype (htm) eq or { |
|
/ans (text/html) def |
|
} { } ifelse |
|
ftype (txt) eq { |
|
/ans (text/html) def |
|
} { } ifelse |
|
/arg1 ans def |
|
] pop |
|
popVariables |
|
arg1 |
|
} def |