--- gforth/httpd.fs 2003/08/25 14:17:45 1.14 +++ gforth/httpd.fs 2008/04/30 08:14:15 1.25 @@ -1,12 +1,12 @@ #! /usr/local/bin/gforth -\ Copyright (C) 2000,2002,2003 Free Software Foundation, Inc. +\ Copyright (C) 2000,2002,2003,2004,2006,2007 Free Software Foundation, Inc. \ This file is part of Gforth. \ Gforth is free software; you can redistribute it and/or \ modify it under the terms of the GNU General Public License -\ as published by the Free Software Foundation; either version 2 +\ as published by the Free Software Foundation, either version 3 \ of the License, or (at your option) any later version. \ This program is distributed in the hope that it will be useful, @@ -15,15 +15,36 @@ \ GNU General Public License for more details. \ You should have received a copy of the GNU General Public License -\ along with this program; if not, write to the Free Software -\ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. +\ along with this program. If not, see http://www.gnu.org/licenses/. + +\ This relies on inetd or xinetd: + +\ To run the server on port 4444, do the following: + +\ Add the following line to /etc/services: +\ gforth 4444/tcp + +\ If you use inetd, add the following line to /etc/inetd.conf: +\ gforth stream tcp nowait.10000 wwwrun /usr/users/bernd/bin/httpd + +\ If you use xinetd, create the folliwing service in /etc/xinetd.d: +\ service gforth +\ { +\ socket_type = stream +\ protocol = tcp +\ wait = no +\ user = wwwrun +\ server = /home/bernd/bin/httpd +\ } + +\ If you want port 80, replace the service "gforth" with "http" warnings off require string.fs -Variable DocumentRoot s" /usr/local/httpd/htdocs/" DocumentRoot $! -Variable UserDir s" .html-data/" UserDir $! +Variable DocumentRoot s" /srv/www/htdocs/" DocumentRoot $! +Variable UserDir s" public_html/" UserDir $! Variable url Variable posted @@ -94,9 +115,9 @@ Variable maxnum : ?cr ( -- ) #tib @ 1 >= IF source 1- + c@ #cr = #tib +! THEN ; -: refill-loop ( -- flag ) +: refill-loop ( -- flag ) base @ >r base off BEGIN refill ?cr WHILE ['] interpret catch drop >in @ 0= UNTIL - true ELSE maxnum off false THEN ; + true ELSE maxnum off false THEN r> base ! ; : get-input ( -- flag ior ) s" /nosuchfile" url $! s" HTTP/1.0" protocol $! s" close" connection $! @@ -112,7 +133,7 @@ Variable maxnum Variable htmldir : rework-htmldir ( addr u -- addr' u' / ior ) - htmldir $! htmldir $@ compact.. htmldir $!len drop + htmldir $! htmldir $@ compact-filename htmldir $!len drop htmldir $@ s" ../" string-prefix? IF -1 EXIT THEN \ can't access below current directory htmldir $@ s" ~" string-prefix? @@ -176,12 +197,19 @@ wordlist constant mime mime set-current : shtml ( addr u -- ) lastrequest - data @ IF included ELSE 2drop THEN ; + data @ IF also forth included previous ELSE 2drop THEN ; s" application/pgp-signature" transparent: sig s" application/x-bzip2" transparent: bz2 s" application/x-gzip" transparent: gz -s" /etc/mime.types" mime-read +s" /etc/mime.types" ' mime-read catch [IF] 2drop + \ no /etc/mime.types found on this machine, + \ generating the most important types: + s" text/html" transparent: html + s" image/gif" transparent: gif + s" image/png" transparent: png + s" image/jpg" transparent: jpg +[THEN] definitions @@ -189,7 +217,7 @@ s" text/plain" transparent: txt \ http errors 26mar00py -: .server ( -- ) ." Server: Gforth httpd/0.1 (" +: .server ( -- ) ." Server: Gforth httpd/1.0 (" s" os-class" environment? IF type THEN ." )" cr ; : .ok ( -- ) ." HTTP/1.1 200 OK" cr .server ; : html-error ( n addr u -- ) @@ -200,7 +228,7 @@ s" text/plain" transparent: txt ." " cr ."

" type drop ."

" cr ; : .trailer ( -- ) - ."
Gforth httpd 0.1
" cr + ."
Gforth httpd 1.0
" cr ." " cr ; : .nok ( -- ) command? @ IF &405 s" Method Not Allowed" ELSE &400 s" Bad Request" THEN html-error @@ -228,7 +256,7 @@ Defer redirect ( addr u -- ) THEN THEN THEN THEN outfile-id flush-file throw ; : httpd ( n -- ) dup maxnum ! 0 <# #S #> Keep-Alive $! - BEGIN ['] http catch maxnum @ 0= or UNTIL ; + maxnum @ 0 DO ['] http catch maxnum @ 0= or ?LEAVE LOOP ; script? [IF] :noname &100 httpd bye ; is bootmessage [THEN]