Diff for /gforth/httpd.fs between versions 1.15 and 1.21

version 1.15, 2004/04/10 00:16:55 version 1.21, 2006/10/07 21:51:28
Line 1 Line 1
 #! /usr/local/bin/gforth  #! /usr/local/bin/gforth
   
 \ Copyright (C) 2000,2002,2003 Free Software Foundation, Inc.  \ Copyright (C) 2000,2002,2003,2004 Free Software Foundation, Inc.
   
 \ This file is part of Gforth.  \ This file is part of Gforth.
   
Line 18 Line 18
 \ along with this program; if not, write to the Free Software  \ along with this program; if not, write to the Free Software
 \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.  \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
   
   \ 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  warnings off
   
 require string.fs  require string.fs
   
 Variable DocumentRoot  s" /usr/local/httpd/htdocs/" DocumentRoot $!  Variable DocumentRoot  s" /srv/www/htdocs/" DocumentRoot $!
 Variable UserDir       s" .html-data/"              UserDir      $!  Variable UserDir       s" public_html/"     UserDir      $!
   
 Variable url  Variable url
 Variable posted  Variable posted
Line 94  Variable maxnum Line 116  Variable maxnum
   
 : ?cr ( -- )  : ?cr ( -- )
   #tib @ 1 >= IF  source 1- + c@ #cr = #tib +!  THEN ;    #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    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 )  : get-input ( -- flag ior )
   s" /nosuchfile" url $!  s" HTTP/1.0" protocol $!    s" /nosuchfile" url $!  s" HTTP/1.0" protocol $!
   s" close" connection $!    s" close" connection $!
Line 112  Variable maxnum Line 134  Variable maxnum
 Variable htmldir  Variable htmldir
   
 : rework-htmldir ( addr u -- addr' u' / ior )  : rework-htmldir ( addr u -- addr' u' / ior )
   htmldir $! htmldir $@ compact.. htmldir $!len drop    htmldir $! htmldir $@ compact-filename htmldir $!len drop
   htmldir $@ s" ../" string-prefix?    htmldir $@ s" ../" string-prefix?
   IF    -1 EXIT  THEN  \ can't access below current directory    IF    -1 EXIT  THEN  \ can't access below current directory
   htmldir $@ s" ~" string-prefix?    htmldir $@ s" ~" string-prefix?
Line 181  mime set-current Line 203  mime set-current
 s" application/pgp-signature" transparent: sig  s" application/pgp-signature" transparent: sig
 s" application/x-bzip2" transparent: bz2  s" application/x-bzip2" transparent: bz2
 s" application/x-gzip" transparent: gz  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  definitions
   
Line 189  s" text/plain" transparent: txt Line 218  s" text/plain" transparent: txt
   
 \ http errors                                          26mar00py  \ http errors                                          26mar00py
   
 : .server ( -- )  ." Server: Gforth httpd/0.1 ("  : .server ( -- )  ." Server: Gforth httpd/1.0 ("
     s" os-class" environment? IF  type  THEN  ." )" cr ;      s" os-class" environment? IF  type  THEN  ." )" cr ;
 : .ok  ( -- ) ." HTTP/1.1 200 OK" cr .server ;  : .ok  ( -- ) ." HTTP/1.1 200 OK" cr .server ;
 : html-error ( n addr u -- )  : html-error ( n addr u -- )
Line 200  s" text/plain" transparent: txt Line 229  s" text/plain" transparent: txt
     ." </TITLE></HEAD>" cr      ." </TITLE></HEAD>" cr
     ." <BODY><H1>" type drop ." </H1>" cr ;      ." <BODY><H1>" type drop ." </H1>" cr ;
 : .trailer ( -- )  : .trailer ( -- )
     ." <HR><ADDRESS>Gforth httpd 0.1</ADDRESS>" cr      ." <HR><ADDRESS>Gforth httpd 1.0</ADDRESS>" cr
     ." </BODY></HTML>" cr ;      ." </BODY></HTML>" cr ;
 : .nok ( -- ) command? @ IF  &405 s" Method Not Allowed"  : .nok ( -- ) command? @ IF  &405 s" Method Not Allowed"
     ELSE  &400 s" Bad Request"  THEN  html-error      ELSE  &400 s" Bad Request"  THEN  html-error

Removed from v.1.15  
changed lines
  Added in v.1.21


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