[BACK]Return to httpd.sm1 CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / Doc

Diff for /OpenXM/src/kan96xx/Doc/httpd.sm1 between version 1.13 and 1.21

version 1.13, 2002/11/03 12:43:03 version 1.21, 2012/12/23 01:27:54
Line 1 
Line 1 
 %% $OpenXM: OpenXM/src/kan96xx/Doc/httpd.sm1,v 1.12 2002/10/30 13:23:06 takayama Exp $  %% $OpenXM: OpenXM/src/kan96xx/Doc/httpd.sm1,v 1.20 2010/02/08 01:08:39 takayama Exp $
 %% common modules for httpd on sm1.  %% common modules for httpd on sm1.
   % [(Strict) 1] system_variable  % for debugging.
 /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
   
   /httpd_sm1.cookie
    [(oxGenPass)] extension
   def
   /httpd.set-cookie {
     [(Set-Cookie: httpd_sm1=) httpd_sm1.cookie] cat
   } def
   
   
 [(getenv) (OXWEB_DEBUG)] extension tag 0 eq {  [(getenv) (OXWEB_DEBUG)] extension tag 0 eq {
    /httpd.debug 0 def     /httpd.debug 0 def
 } {  } {
Line 82  def
Line 91  def
   /httpd.serial 0 def    /httpd.serial 0 def
   /httpd.history [ ] def    /httpd.history [ ] def
   /httpd.result.history [ 0 ] def    /httpd.result.history [ 0 ] def
     [(nobody)] extension pop
   {    {
     httpd_startserver ;      httpd_startserver ;
     httpd_action ;      httpd_action ;
Line 133  def
Line 143  def
    (HTTP/0.9 200 OK) sendln     (HTTP/0.9 200 OK) sendln
    (Connection: close) sendln     (Connection: close) sendln
    (Content-Type: text/html) sendln     (Content-Type: text/html) sendln
      httpd.set-cookie sendln
    0 sendln     0 sendln
 %%   (<FORM NAME="myFORM" METHOD="POST">) sendln  %%   (<FORM NAME="myFORM" METHOD="POST">) sendln
    result sendln     result sendln
Line 286  def
Line 297  def
  } ifelse   } ifelse
   
   
 %% Decompose into tokens separated by a space.  
 %% (GET /hoge.jpeg ???) ---> [(GET) (/hoge.jpeg) (???)]  
 /toTokensBySpace {  
   /arg1 set  
   [/in-toTokesBySpace /ss /ss2 /i] pushVariables  
   [  
     /ss arg1 def  
     ss 1 copy /ss set  
     ss (array) dc /ss2 set  
     0 1 ss2 length 1 sub {  
       /i set  
       ss2 i get 32 eq { %% equal to space  
         ss i (,) put  
       } {  } ifelse  
     } for  
     httpd.debug { ss message } {  } ifelse  
     [ ss to_records pop] /arg1 set  
   ] pop  
   popVariables  
   arg1  
 } def  
   
 /askToSendFile {  /askToSendFile {
   /arg1 set    /arg1 set
Line 453  def
Line 443  def
   [/in-preformatHTML /sss /c] pushVariables    [/in-preformatHTML /sss /c] pushVariables
   [    [
      /sss arg1 def       /sss arg1 def
        sss toString /sss set
      sss (array) dc /sss set       sss (array) dc /sss set
      sss {       sss {
        /c set         /c set
Line 629  def
Line 620  def
        tname s i0 get append /tname set         tname s i0 get append /tname set
      } for       } for
   
        %% Remove space and cr/lf from the key word.
        [
          0 1 tname length 1 sub {
            /j set
            tname j get 36 le {
            } {
              tname j get
            } ifelse
         } for
        ] /tname set
   
      /j 0 def       /j 0 def
      i0 1 s length 1 sub {       i0 1 s length 1 sub {
        /i set         /i set
Line 642  def
Line 644  def
      /ans set       /ans set
   
      /httpd.exit       /httpd.exit
        ans length 1 lt {
          /ans [(Unknown)] def
        } {  } ifelse
      /arg1 ans def       /arg1 ans def
  ] pop   ] pop
  popVariables   popVariables
  arg1   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=) messagen fname (array) dc message
              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 {
                /fname (index.html) (array) dc def
              } {  } 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
          fname httpd.check_name {
            [(MSG) (Warning:  invalid file name.)] httpd_sendfile
            /httpd_sendfile.L1 /httpd_sendfile.L1 goto
          } {  } ifelse
          [(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 getFileType /ftype set
   
       /ans (text/plain) def  % .txt, .jar,
       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 (wav) eq {
         /ans (audio/x-wav) def
       } { } ifelse
       ftype (class) eq {
         /ans (application/octet-stream) def
       } { } ifelse
       /arg1 ans def
     ] pop
     popVariables
     arg1
   } def
   
   /httpd.check_name {
    /arg1 set
    [/in-httpd.check_name /fname /invalid] pushVariables
    [
      /fname arg1 def
      /invalid 0 def
      [(regionMatches) fname [(..) (/.)]] extension 0 get -1 eq
      {
      } {
        (The file name contains .. or /. ) message
        /invalid 1 def /httpd.check_name.L1 /httpd.check_name.L1  goto
      } ifelse
      fname length 0 eq {
        (Warning: empty file name.)
        /invalid 1 def /httpd.check_name.L1 /httpd.check_name.L1  goto
      }{ } ifelse
      fname (array) dc 0 get 47 eq {
      }{
        (Warning: The first letter is not /) message
        /invalid 1 def /httpd.check_name.L1 /httpd.check_name.L1  goto
      } ifelse
      /httpd.check_name.L1
      /arg1 invalid def
    ] pop
    popVariables
    arg1
   } def
   
   /httpd.startBrowserUnix {
     /arg1 set
     [/portnum /browser /cmd /fd /msg /htmlfn] pushVariables
     [
        arg1 /portnum set
        portnum toString /portnum set
        [(getenv) (OX_BROWSER)]  extension /browser set
        {
         browser tag 0 eq {
           [(ostype)] extension 1 get (mac) eq {
             [(sleep 3 ; open http://localhost:) portnum ( & ) ] cat
             /cmd set cmd message
           }{
             [(sleep 3 ; firefox http://localhost:) portnum ( & ) ] cat
             /cmd set cmd message
           }ifelse
           cmd system
           exit
          }{ } ifelse
          browser (mac) eq, browser (MAC) eq, or {
            (.sm1.httpd.startBrowserUnix.html) /htmlfn set
            htmlfn (w) file /fd set
            fd tag 0 eq { (httpd.startBrowserUnix fails to open a file.) error }
            { } ifelse
            [(<html><body>) nl
             (<a href="http://localhost:) portnum (">)
             (Click here to connect to the ox server)
             (</a>) nl
             (</body></html>) nl
            ] cat /msg set
            fd msg writestring  fd closefile
            [(sleep 3 ; open ) htmlfn ( &) ] cat
            /cmd set cmd message
            cmd system
            exit
          }{ } ifelse
          [(sleep 3 ; ) browser ( http://localhost:) portnum ( & ) ] cat
          /cmd set cmd message
          cmd system
          exit
        } loop
     ] pop
     popVariables
 } def  } def
   

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.21

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