myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [SCM] GNU MyServer branch, master, updated. 27a3b5c269


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 27a3b5c2698d4346f24471f96d48fe526af603e0
Date: Wed, 04 Nov 2009 14:50:25 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  27a3b5c2698d4346f24471f96d48fe526af603e0 (commit)
      from  ffcd007ec5d92f956a8fca0a1ab7a95a16ac5a4b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit 27a3b5c2698d4346f24471f96d48fe526af603e0
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Nov 4 15:50:17 2009 +0100

    The directory listing handler allows to specify an ignore pattern.

diff --git a/myserver/documentation/directory_listing.texi 
b/myserver/documentation/directory_listing.texi
index a57c6a4..de09614 100644
--- a/myserver/documentation/directory_listing.texi
+++ b/myserver/documentation/directory_listing.texi
@@ -64,7 +64,6 @@ by its size, while @code{%f%t} displays the file name and its 
last
 modified time.
 
 @subsection Directory listing layout
-
 You can change the layout of the directory browsing page. The line
 below, in @file{myserver.xml}, points to the CSS file used to
 configure the layout for the browsing directory pages:
@@ -72,3 +71,19 @@ configure the layout for the browsing directory pages:
 @example
   <DEFINE name="http.dir.css" value="/sys/css/browsestyle.css" />
 @end example
+
address@hidden Ignore entries
+It is possible to ignore some files to be listed from the final
+output.  It is done using the @code{http.dir.ignore} regular
+expression that can be specified at any level.
+
+Pay attention, this directive does not change the file visibility, so
+a direct request to the entries that are part of the mask will have
+the same effect as if this directive is not specified.
+
+In the following example, the file @file{hidden} is not included in
+the directory listing.
+
address@hidden
+  <DEFINE name="http.dir.ignore" value="hidden" />
address@hidden example
diff --git a/myserver/src/http_handler/http_dir/http_dir.cpp 
b/myserver/src/http_handler/http_dir/http_dir.cpp
index a94e903..21e3c1d 100644
--- a/myserver/src/http_handler/http_dir/http_dir.cpp
+++ b/myserver/src/http_handler/http_dir/http_dir.cpp
@@ -106,7 +106,7 @@ int HttpDir::unLoad ()
 }
 
 /*!
-  *Get a formatted dobule representation of BYTES right shifted by POWER.
+ *Get a formatted dobule representation of BYTES right shifted by POWER.
  * \param bytes Number of bytes.
  * \param power Power of 2.
  * \return the double representation for BYTES>>POWER.
@@ -176,38 +176,38 @@ void HttpDir::generateHeader (MemBuf &out, char sortType, 
bool sortReverse,
   out << "<tr>\r\n";
 
   for (;;)
-  {
-    while (*cur && ((*cur == '%' ) || (*cur == ' ' )))
-      cur++;
-
-    if (!(*cur))
-      break;
-
-    switch (*cur)
     {
-    case 'f':
-      if (sortType == 'f' && !sortReverse)
-        out << "<th><a href=\"?sort=fI\">File</a></th>\r\n";
-      else
-        out << "<th><a href=\"?sort=f\">File</a></th>\r\n";
-      break;
+      while (*cur && ((*cur == '%' ) || (*cur == ' ' )))
+        cur++;
 
-    case 't':
-      if (sortType == 't' && !sortReverse)
-        out << "<th><a href=\"?sort=tI\">Last Modified</a></th>\r\n";
-      else
-        out << "<th><a href=\"?sort=t\">Last Modified</a></th>\r\n";
-      break;
+      if (!(*cur))
+        break;
 
-    case 's':
-    if (sortType == 's' && !sortReverse)
-      out << "<th><a href=\"?sort=sI\">Size</a></th>\r\n";
-    else
-      out << "<th><a href=\"?sort=s\">Size</a></th>\r\n";
-    break;
+      switch (*cur)
+        {
+        case 'f':
+          if (sortType == 'f' && !sortReverse)
+            out << "<th><a href=\"?sort=fI\">File</a></th>\r\n";
+          else
+            out << "<th><a href=\"?sort=f\">File</a></th>\r\n";
+          break;
+
+        case 't':
+          if (sortType == 't' && !sortReverse)
+            out << "<th><a href=\"?sort=tI\">Last Modified</a></th>\r\n";
+          else
+            out << "<th><a href=\"?sort=t\">Last Modified</a></th>\r\n";
+          break;
+
+        case 's':
+          if (sortType == 's' && !sortReverse)
+            out << "<th><a href=\"?sort=sI\">Size</a></th>\r\n";
+          else
+            out << "<th><a href=\"?sort=s\">Size</a></th>\r\n";
+          break;
+        }
+      cur++;
     }
-    cur++;
-  }
 
   out << "</tr>\r\n";
 }
@@ -299,17 +299,20 @@ int HttpDir::send (HttpThreadContext* td,
   bool useChunks = false;
   u_long sentData = 0;
   char* bufferloop;
-  const char* browseDirCSSpath;
+  const char* cssFile;
   bool keepalive = false;
   vector<HttpDir::FileStruct> files;
   size_t sortIndex;
   char sortType = 0;
   bool sortReverse = false;
   string linkPrefix;
+  Regex ignRegex;
+  const char *ignPattern;
   const char *formatString = td->securityToken.getData ("http.dir.format",
-                                                              
MYSERVER_SECURITY_CONF |
-                                                              
MYSERVER_VHOST_CONF |
-                                                              
MYSERVER_SERVER_CONF, "%f%t%s");
+                                                        MYSERVER_SECURITY_CONF
+                                                        | MYSERVER_VHOST_CONF
+                                                        | MYSERVER_SERVER_CONF,
+                                                        "%f%t%s");
 
 
   HttpRequestHeader::Entry *host = td->request.other.get ("Host");
@@ -322,14 +325,16 @@ int HttpDir::send (HttpThreadContext* td,
   if ( !(td->permissions & MYSERVER_PERMISSION_BROWSE))
     return td->http->sendAuth ();
 
-  if (td->mime && Server::getInstance ()->getFiltersFactory ()->chain (&chain,
-                                                        td->mime->filters,
-                                             td->connection->socket, &nbw, 1))
-  {
-    td->connection->host->warningsLogWrite (_("HttpDir: internal error"));
-    chain.clearAllFilters ();
-    return td->http->raiseHTTPError (500);
-  }
+  if (td->mime
+      && Server::getInstance ()->getFiltersFactory ()->chain (&chain,
+                                                    td->mime->filters,
+                                                td->connection->socket,
+                                                              &nbw, 1))
+    {
+      td->connection->host->warningsLogWrite (_("HttpDir: internal error"));
+      chain.clearAllFilters ();
+      return td->http->raiseHTTPError (500);
+    }
 
   lastSlash = td->request.uri.rfind ('/') + 1;
 
@@ -337,55 +342,64 @@ int HttpDir::send (HttpThreadContext* td,
 
   td->response.setValue ("Content-type", "text/html");
 
-  if (!td->appendOutputs)
-  {
+  ignPattern = td->securityToken.getData ("http.dir.ignore",
+                                          MYSERVER_SECURITY_CONF
+                                          | MYSERVER_VHOST_CONF
+                                          | MYSERVER_SERVER_CONF, NULL);
+  if (ignPattern)
+    {
+      int ret = ignRegex.compile (ignPattern, REG_EXTENDED);
+      if (ret)
+        {
+          td->connection->host->warningsLogWrite (_("HttpDir: pattern `%s' "
+                                                  "is not valid"), ignPattern);
 
-    HttpHeaders::buildHTTPResponseHeader (td->buffer->getBuffer (),
-                                         &(td->response));
+          fd.findclose ();
+          td->outputData.close ();
+          chain.clearAllFilters ();
+          return td->http->raiseHTTPError (500);
+        }
+    }
 
-    if (td->connection->socket->send (td->buffer->getBuffer (),
-                       (u_long)strlen (td->buffer->getBuffer ()), 0)
-       == SOCKET_ERROR)
+  if (!td->appendOutputs)
     {
-      /* Remove the connection.  */
-      return 0;
+
+      HttpHeaders::buildHTTPResponseHeader (td->buffer->getBuffer (),
+                                            &(td->response));
+
+      if (td->connection->socket->send (td->buffer->getBuffer (),
+                                   strlen (td->buffer->getBuffer ()), 0) < 0)
+        return 0;
     }
-  }
 
   if (onlyHeader)
     return 1;
 
-
   sortIndex = td->request.uriOpts.find ("sort=");
 
   if (sortIndex != string::npos && sortIndex + 5 < td->request.uriOpts.length 
())
-  {
     sortType = td->request.uriOpts.at (sortIndex + 5);
-  }
 
   if (sortIndex != string::npos && sortIndex + 6 < td->request.uriOpts.length 
())
-  {
-     sortReverse = td->request.uriOpts.at (sortIndex + 6) == 'I';
-  }
+    sortReverse = td->request.uriOpts.at (sortIndex + 6) == 'I';
 
   /* Make sortType always lowercase.  */
   switch (sortType)
-  {
+    {
     case 's':
     case 'S':
       sortType = 's';
       break;
+
     case 't':
     case 'T':
       sortType = 't';
       break;
-    default:
-      sort (files.begin (), files.end (), compareFileStructByName);
-  }
+    }
 
-  browseDirCSSpath = td->securityToken.getData ("http.dir.css",
-                                                      MYSERVER_SECURITY_CONF | 
MYSERVER_VHOST_CONF |
-                                                      MYSERVER_SERVER_CONF, 
NULL);
+  cssFile = td->securityToken.getData ("http.dir.css", MYSERVER_SECURITY_CONF
+                                       | MYSERVER_VHOST_CONF
+                                       | MYSERVER_SERVER_CONF, NULL);
 
   td->secondaryBuffer->setLength (0);
   *td->secondaryBuffer << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
@@ -397,29 +411,29 @@ int HttpDir::send (HttpThreadContext* td,
   *td->secondaryBuffer << "</title>\r\n";
 
   /*
-   *If it is defined a CSS file for the graphic layout of
-   *the browse directory insert it in the page.
+   * If it is defined a CSS file for the graphic layout of
+   * the browse directory insert it in the page.
    */
-  if (browseDirCSSpath)
-  {
-    *td->secondaryBuffer << "<link rel=\"stylesheet\" href=\""
-                 << browseDirCSSpath
-                 << "\" type=\"text/css\" media=\"all\"/>\r\n";
-  }
+  if (cssFile)
+    {
+      *td->secondaryBuffer << "<link rel=\"stylesheet\" href=\""
+                           << cssFile
+                           << "\" type=\"text/css\" media=\"all\"/>\r\n";
+    }
 
   *td->secondaryBuffer << "</head>\r\n";
 
   ret = appendDataToHTTPChannel (td, td->secondaryBuffer->getBuffer (),
-                                td->secondaryBuffer->getLength (),
-                                &(td->outputData), &chain,
-                                td->appendOutputs, useChunks);
+                                 td->secondaryBuffer->getLength (),
+                                 &(td->outputData), &chain,
+                                 td->appendOutputs, useChunks);
   if (ret)
-  {
-    /* Return an internal server error. */
-    td->outputData.close ();
-    chain.clearAllFilters ();
-    return td->http->raiseHTTPError (500);
-  }
+    {
+      /* Return an internal server error. */
+      td->outputData.close ();
+      chain.clearAllFilters ();
+      return td->http->raiseHTTPError (500);
+    }
 
   sentData = td->secondaryBuffer->getLength ();
 
@@ -430,25 +444,25 @@ int HttpDir::send (HttpThreadContext* td,
   *td->secondaryBuffer << "</h1>\r\n<hr />\r\n";
 
   ret = appendDataToHTTPChannel (td, td->secondaryBuffer->getBuffer (),
-                                td->secondaryBuffer->getLength (),
-                                &(td->outputData), &chain,
-                                td->appendOutputs, useChunks);
+                                 td->secondaryBuffer->getLength (),
+                                 &(td->outputData), &chain,
+                                 td->appendOutputs, useChunks);
 
   if (ret)
-  {
-    td->outputData.close ();
-    /* Return an internal server error.  */
-    return td->http->raiseHTTPError (500);
-  }
+    {
+      td->outputData.close ();
+      /* Return an internal server error.  */
+      return td->http->raiseHTTPError (500);
+    }
   sentData += td->secondaryBuffer->getLength ();
 
   ret = fd.findfirst (filename.c_str ());
 
   if (ret == -1)
-  {
-    chain.clearAllFilters ();
-    return td->http->raiseHTTPError (404);
-  }
+    {
+      chain.clearAllFilters ();
+      return td->http->raiseHTTPError (404);
+    }
 
   /*
    * With the current code we build the HTML TABLE to indicize the
@@ -460,87 +474,94 @@ int HttpDir::send (HttpThreadContext* td,
   generateHeader (*td->secondaryBuffer, sortType, sortReverse, formatString);
 
   ret = appendDataToHTTPChannel (td, td->secondaryBuffer->getBuffer (),
-                                td->secondaryBuffer->getLength (),
-                                &(td->outputData), &chain,
-                                td->appendOutputs, useChunks);
+                                 td->secondaryBuffer->getLength (),
+                                 &(td->outputData), &chain,
+                                 td->appendOutputs, useChunks);
 
   if (ret)
-  {
-    td->outputData.close ();
-    chain.clearAllFilters ();
-    /* Return an internal server error.  */
-    return td->http->raiseHTTPError (500);
-  }
+    {
+      td->outputData.close ();
+      chain.clearAllFilters ();
+      /* Return an internal server error.  */
+      return td->http->raiseHTTPError (500);
+    }
 
   sentData += td->secondaryBuffer->getLength ();
 
   td->secondaryBuffer->setLength (0);
 
   if (FilesUtility::getPathRecursionLevel (td->request.uri) >= 1)
-  {
-    const char* cur = formatString;
-    string file;
-    file.assign (td->request.uri);
-    file.append ("/../");
+    {
+      const char* cur = formatString;
+      string file;
+      file.assign (td->request.uri);
+      file.append ("/../");
 
-    *td->secondaryBuffer << "<tr>\r\n";
+      *td->secondaryBuffer << "<tr>\r\n";
 
-    for (;;)
-    {
-      while (*cur && ((*cur == '%' ) || (*cur == ' ' )))
-        cur++;
+      for (;;)
+        {
+          while (*cur && ((*cur == '%' ) || (*cur == ' ' )))
+            cur++;
 
-      if (!(*cur))
-        break;
+          if (!(*cur))
+            break;
 
-      if (*cur == 'f')
-        *td->secondaryBuffer << "<td>\n"
-                             << "<a href=\""
-                             << (td->request.uriEndsWithSlash ? ".." : ".")
-                             << "\">[ .. ]</a></td>\n";
-      else
-        *td->secondaryBuffer << "<td></td>\n";
+          if (*cur == 'f')
+            *td->secondaryBuffer << "<td>\n"
+                                 << "<a href=\""
+                                 << (td->request.uriEndsWithSlash ? ".." : ".")
+                                 << "\">[ .. ]</a></td>\n";
+          else
+            *td->secondaryBuffer << "<td></td>\n";
 
-      cur++;
-    }
+          cur++;
+        }
 
-    *td->secondaryBuffer << "</tr>\r\n";
+      *td->secondaryBuffer << "</tr>\r\n";
 
-    ret = appendDataToHTTPChannel (td, td->secondaryBuffer->getBuffer (),
-                                  td->secondaryBuffer->getLength (),
-                                  &(td->outputData), &chain,
-                                  td->appendOutputs, useChunks);
-    if (ret)
-    {
-      fd.findclose ();
-      td->outputData.close ();
-      chain.clearAllFilters ();
-      /* Return an internal server error.  */
-      return td->http->raiseHTTPError (500);
+      ret = appendDataToHTTPChannel (td, td->secondaryBuffer->getBuffer (),
+                                     td->secondaryBuffer->getLength (),
+                                     &(td->outputData), &chain,
+                                     td->appendOutputs, useChunks);
+      if (ret)
+        {
+          fd.findclose ();
+          td->outputData.close ();
+          chain.clearAllFilters ();
+          /* Return an internal server error.  */
+          return td->http->raiseHTTPError (500);
+        }
+      sentData += td->secondaryBuffer->getLength ();
     }
-    sentData += td->secondaryBuffer->getLength ();
-  }
 
   /* Put all files in a vector.  */
   do
-  {
-    if (fd.name[0] == '.')
-      continue;
-
-    FileStruct file;
-    file.name = fd.name;
-    file.time_write = fd.time_write;
-    file.attrib = fd.attrib;
-    file.size = fd.size;
-    files.push_back (file);
-  }
+    {
+      if (fd.name[0] == '.')
+        continue;
+
+      if (ignPattern)
+        {
+          regmatch_t pm[1];
+          if (! ignRegex.exec (fd.name, 1, pm, 0))
+            continue;
+        }
+
+      FileStruct file;
+      file.name = fd.name;
+      file.time_write = fd.time_write;
+      file.attrib = fd.attrib;
+      file.size = fd.size;
+      files.push_back (file);
+    }
   while (!fd.findnext ());
 
   fd.findclose ();
 
   /* Sort the vector.  */
   switch (sortType)
-  {
+    {
     case 's':
       sort (files.begin (), files.end (), compareFileStructBySize);
       break;
@@ -549,76 +570,76 @@ int HttpDir::send (HttpThreadContext* td,
       break;
     case 'f':
       sort (files.begin (), files.end (), compareFileStructByName);
-  }
+    }
 
   if (sortReverse)
     reverse (files.begin (), files.end ());
 
   if (!td->request.uriEndsWithSlash)
-  {
-    linkPrefix.assign (&td->request.uri[lastSlash]);
-    linkPrefix.append ("/");
-  }
+    {
+      linkPrefix.assign (&td->request.uri[lastSlash]);
+      linkPrefix.append ("/");
+    }
   else
     linkPrefix.assign ("");
 
 
   /* Build the files table and send it.  */
   for (vector<FileStruct>::iterator it = files.begin ();
-      it != files.end (); it++)
-  {
-    FileStruct& file = *it;
+       it != files.end (); it++)
+    {
+      FileStruct& file = *it;
 
-    td->secondaryBuffer->setLength (0);
+      td->secondaryBuffer->setLength (0);
 
-    generateElement (*td->secondaryBuffer, file, linkPrefix, formatString);
+      generateElement (*td->secondaryBuffer, file, linkPrefix, formatString);
 
-    ret = appendDataToHTTPChannel (td, td->secondaryBuffer->getBuffer (),
-                                  td->secondaryBuffer->getLength (),
-                                  &(td->outputData), &chain,
-                                  td->appendOutputs, useChunks);
-    if (ret)
-    {
-      td->outputData.close ();
-      chain.clearAllFilters ();
-      /* Return an internal server error.  */
-      return td->http->raiseHTTPError (500);
-    }
+      ret = appendDataToHTTPChannel (td, td->secondaryBuffer->getBuffer (),
+                                     td->secondaryBuffer->getLength (),
+                                     &(td->outputData), &chain,
+                                     td->appendOutputs, useChunks);
+      if (ret)
+        {
+          td->outputData.close ();
+          chain.clearAllFilters ();
+          /* Return an internal server error.  */
+          return td->http->raiseHTTPError (500);
+        }
 
-    sentData += td->secondaryBuffer->getLength ();
+      sentData += td->secondaryBuffer->getLength ();
 
-  }
+    }
 
   td->secondaryBuffer->setLength (0);
   *td->secondaryBuffer << "</table>\r\n<hr />\r\n<address>"
-               << MYSERVER_VERSION;
+                       << MYSERVER_VERSION;
 
   if (host && host->value->length ())
-  {
-    ostringstream portBuff;
-    size_t portSeparator = host->value->find (':');
-    *td->secondaryBuffer << " on ";
-    if (portSeparator != string::npos)
-      *td->secondaryBuffer << host->value->substr (0, portSeparator).c_str () ;
-    else
-      *td->secondaryBuffer << host->value->c_str () ;
-
-    *td->secondaryBuffer << " Port ";
-    portBuff << td->connection->getLocalPort ();
-    *td->secondaryBuffer << portBuff.str ();
-  }
+    {
+      ostringstream portBuff;
+      size_t portSeparator = host->value->find (':');
+      *td->secondaryBuffer << " on ";
+      if (portSeparator != string::npos)
+        *td->secondaryBuffer << host->value->substr (0, portSeparator).c_str 
() ;
+      else
+        *td->secondaryBuffer << host->value->c_str () ;
+
+      *td->secondaryBuffer << " Port ";
+      portBuff << td->connection->getLocalPort ();
+      *td->secondaryBuffer << portBuff.str ();
+    }
   *td->secondaryBuffer << "</address>\r\n</body>\r\n</html>\r\n";
   ret = appendDataToHTTPChannel (td, td->secondaryBuffer->getBuffer (),
-                                td->secondaryBuffer->getLength (),
-                                &(td->outputData), &chain,
-                                td->appendOutputs, useChunks);
+                                 td->secondaryBuffer->getLength (),
+                                 &(td->outputData), &chain,
+                                 td->appendOutputs, useChunks);
 
   if (ret)
-  {
-    td->outputData.close ();
-    /* Return an internal server error.  */
-    return td->http->raiseHTTPError (500);
-  }
+    {
+      td->outputData.close ();
+      /* Return an internal server error.  */
+      return td->http->raiseHTTPError (500);
+    }
   sentData += td->secondaryBuffer->getLength ();
 
   *td->secondaryBuffer << end_str;
@@ -628,11 +649,9 @@ int HttpDir::send (HttpThreadContext* td,
     if (*bufferloop == '\\')
       *bufferloop = '/';
 
-  if (!td->appendOutputs && useChunks)
-  {
-    if (chain.getStream ()->write ("0\r\n\r\n", 5, &nbw))
-      return 1;
-  }
+  if (!td->appendOutputs && useChunks
+      && chain.getStream ()->write ("0\r\n\r\n", 5, &nbw))
+    return 1;
 
   /* For logging activity.  */
   td->sentData += sentData;
@@ -656,20 +675,20 @@ void HttpDir::formatHtml (string& in, string& out)
    * with "&#CODE;".
    */
   for (pos = 0; out[pos] != '\0'; pos++)
-  {
-    if (((u_char)out[pos] >= 32 &&
-        (u_char)out[pos] <= 65)   ||
-       ((u_char)out[pos] >= 91 &&
-        (u_char)out[pos] <= 96)   ||
-       ((u_char)out[pos] >= 123 &&
-        (u_char)out[pos] <= 126) ||
-       ((u_char)out[pos] >= 160 &&
-        (u_char)out[pos] < 255))
     {
-      ostringstream os;
-      os << "&#" << (int)((unsigned char)out[pos]) << ";";
-      out.replace (pos, 1, os.str ());
-      pos += os.str ().length () - 1;
+      if (((u_char)out[pos] >= 32 &&
+           (u_char)out[pos] <= 65)   ||
+          ((u_char)out[pos] >= 91 &&
+           (u_char)out[pos] <= 96)   ||
+          ((u_char)out[pos] >= 123 &&
+           (u_char)out[pos] <= 126) ||
+          ((u_char)out[pos] >= 160 &&
+           (u_char)out[pos] < 255))
+        {
+          ostringstream os;
+          os << "&#" << (int)((unsigned char)out[pos]) << ";";
+          out.replace (pos, 1, os.str ());
+          pos += os.str ().length () - 1;
+        }
     }
-  }
 }

-----------------------------------------------------------------------

Summary of changes:
 myserver/documentation/directory_listing.texi   |   17 +-
 myserver/src/http_handler/http_dir/http_dir.cpp |  445 ++++++++++++-----------
 2 files changed, 248 insertions(+), 214 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

[Prev in Thread] Current Thread [Next in Thread]