*** empty log message ***
authorMatthew Mondor <mmondor@pulsar-zone.net>
Sat, 9 Jul 2005 06:33:19 +0000 (06:33 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Sat, 9 Jul 2005 06:33:19 +0000 (06:33 +0000)
tests/js-test/js/httpd/httpd.js

index 9a1bf2a..09baa8e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: httpd.js,v 1.33 2005/07/09 05:44:53 mmondor Exp $ */
+/* $Id: httpd.js,v 1.34 2005/07/09 06:33:19 mmondor Exp $ */
 
 /*
  * Copyright (c) 2005, Matthew Mondor
@@ -119,7 +119,7 @@ eval(file_read('root.js'));         /* Root object for virtual chroot(2) */
  * Server identification
  */
 SERVER_VERSION                 = 'mmondor_js_httpd/0.0.1 (NetBSD)';
-SERVER_CVSID   = '$Id: httpd.js,v 1.33 2005/07/09 05:44:53 mmondor Exp $';
+SERVER_CVSID   = '$Id: httpd.js,v 1.34 2005/07/09 06:33:19 mmondor Exp $';
 
 
 
@@ -813,49 +813,63 @@ FD.prototype.parsePost = function(time)
 
 FD.prototype.httpRespond = function(time)
 {
-       var path, fd, st, res, ext, mimetype, i, index, sess;
+       var path, fd, st, res, ext, mimetype, i, sess;
        var cookie = undefined;
 
-       index = false;
-       for (;;) {
-               path = this.http_vhost.htdocs_root.valid_virtual(
-                   this.http_path);
-               if (!path) {
-                       http_error(this, 403, 'Permission Denied',
-                          'You do not have the permission to access this ' +
-                          'resource.');
-                       return true;
-               }
+       /*
+        * Attempt to find requested file.
+        * If it consists of a directory, attempt to first find index.html in
+        * it, then index.jso in it, fail with error 403 if none can be found.
+        * Otherwise, continue forward keeping the descriptor open, and the
+        * stat information already filled in.
+        */
+
+       path = this.http_vhost.htdocs_root.valid_virtual(this.http_path);
+       if (!path) {
+               http_error(this, 403, 'Permission Denied',
+                   'You do not have the permission to access this ' +
+                   'resource.');
+               return true;
+       }
+
+       fd = new FD();
+
+       try {
+               fd.open(path.real, FD.O_RDONLY);
+               st = fd.fstat();
+       } catch (x) {
+               http_error(this, 404, 'Not Found',
+                   path.virtual + ' could not be found.');
+               return true;
+       }
+
+       if ((st.st_mode & FD.S_IFDIR) != 0) {
+               var error = false;
 
-               fd = new FD();
+               fd.close();
                try {
-                       fd.open(path.real, FD.O_RDONLY);
+                       fd.open(path.real + '/index.html', FD.O_RDONLY);
                        st = fd.fstat();
+                       path.real += '/index.html';
+                       path.virtual += '/index.html';
                } catch (x) {
-                       if (index) {
-                               http_error(this, 403, 'Permission Denied',
-                                   'You do not have the permission to ' +
-                                   'access this resource.');
-                               return true;
-                       } else {
-                               http_error(this, 404, 'Not Found',
-                                   path.virtual + ' could not be found.');
-                               return true;
+                       err.put(x + "\n");
+                       try {
+                               fd.open(path.real + '/index.jso',
+                                   FD.O_RDONLY);
+                               st = fd.fstat();
+                               path.real += '/index.jso';
+                               path.virtual += '/index.jso';
+                       } catch (x) {
+                               error = true;
                        }
                }
-
-               /*
-                * Is file a directory?  If so, attempt to fallback to
-                * index.html inside it.
-                */
-               if ((st.st_mode & FD.S_IFDIR) != 0) {
-                       fd.close();
-                       this.http_path += '/index.html';
-                       index = true;
-                       continue;
+               if (error) {
+                       http_error(this, 403, 'Permission Denied',
+                           'You do not have the permission to access the ' +
+                           'resource ' + path.virtual);
+                       return true;
                }
-
-               break;
        }
 
        /*
@@ -864,7 +878,8 @@ FD.prototype.httpRespond = function(time)
        if ((st.st_mode & FD.S_IFREG) == 0) {
                fd.close();
                http_error(this, 403, 'Permission Denied',
-                   'You do not have the permission to access this resource.');
+                   'You do not have the permission to access the resource ' +
+                   path.virtual);
                return true;
        }
 
@@ -960,6 +975,7 @@ FD.prototype.httpRespond = function(time)
                            'Please try again later.');
                }
 
+               delete obj;
                return true;
        }