myserver-commit
[Top][All Lists]
Advanced

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

[myserver-commit] [2895] Added possibility to choose which columns show


From: Giuseppe Scrivano
Subject: [myserver-commit] [2895] Added possibility to choose which columns show when a directory is browsed .
Date: Mon, 20 Oct 2008 20:21:17 +0000

Revision: 2895
          http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2895
Author:   gscrivano
Date:     2008-10-20 20:21:15 +0000 (Mon, 20 Oct 2008)

Log Message:
-----------
Added possibility to choose which columns show when a directory is browsed.

Modified Paths:
--------------
    trunk/myserver/include/http_handler/http_dir/http_dir.h
    trunk/myserver/include/protocol/http/http.h
    trunk/myserver/include/protocol/http/http_thread_context.h
    trunk/myserver/src/http_handler/http_dir/http_dir.cpp
    trunk/myserver/src/protocol/http/http.cpp

Modified: trunk/myserver/include/http_handler/http_dir/http_dir.h
===================================================================
--- trunk/myserver/include/http_handler/http_dir/http_dir.h     2008-10-19 
18:50:26 UTC (rev 2894)
+++ trunk/myserver/include/http_handler/http_dir/http_dir.h     2008-10-20 
20:21:15 UTC (rev 2895)
@@ -52,6 +52,10 @@
   static bool compareFileStructByTime (HttpDir::FileStruct i, 
HttpDir::FileStruct j);
   static bool compareFileStructBySize (HttpDir::FileStruct i, 
HttpDir::FileStruct j);
   void getFormattedSize(u_long bytes, string& out);
+  
+  void generateHeader (MemBuf &out, char sortType, bool sortReverse, const 
char *formatString);
+  void generateElement (MemBuf &out, FileStruct& fs, string &linkPrefix, const 
char *formatString);
+
 };
 
 

Modified: trunk/myserver/include/protocol/http/http.h
===================================================================
--- trunk/myserver/include/protocol/http/http.h 2008-10-19 18:50:26 UTC (rev 
2894)
+++ trunk/myserver/include/protocol/http/http.h 2008-10-20 20:21:15 UTC (rev 
2895)
@@ -22,7 +22,6 @@
 #include <include/protocol/http/http_thread_context.h>
 #include <include/protocol/protocol.h>
 #include <include/protocol/http/http_headers.h>
-#include <include/conf/security/security_token.h>
 #include <include/conf/security/security_cache.h>
 #include <include/base/xml/xml_parser.h>
 #include <include/base/thread/thread.h>
@@ -188,10 +187,9 @@
 
   static HttpStaticData* getStaticData();
 
-  SecurityToken *getSecurityToken (){return &securityToken;}
+  SecurityToken *getSecurityToken (){return &(td->securityToken);}
 
 protected:
-  SecurityToken securityToken;
   HttpDataHandler* mscgi;
   HttpDataHandler* wincgi;
   HttpDataHandler* isapi;

Modified: trunk/myserver/include/protocol/http/http_thread_context.h
===================================================================
--- trunk/myserver/include/protocol/http/http_thread_context.h  2008-10-19 
18:50:26 UTC (rev 2894)
+++ trunk/myserver/include/protocol/http/http_thread_context.h  2008-10-20 
20:21:15 UTC (rev 2895)
@@ -27,6 +27,7 @@
 #include <include/base/mem_buff/mem_buff.h>
 #include <include/connection/connection.h>
 #include <include/conf/mime/mime_manager.h>
+#include <include/conf/security/security_token.h>
 
 extern "C" {
 #ifdef WIN32
@@ -83,6 +84,8 @@
        Http* http;
        MimeRecord *mime;
        int sentData;
+  SecurityToken securityToken;
+
        const char* getVhostDir();
        const char* getVhostSys();
        const char* getHashedData (const char *name);

Modified: trunk/myserver/src/http_handler/http_dir/http_dir.cpp
===================================================================
--- trunk/myserver/src/http_handler/http_dir/http_dir.cpp       2008-10-19 
18:50:26 UTC (rev 2894)
+++ trunk/myserver/src/http_handler/http_dir/http_dir.cpp       2008-10-20 
20:21:15 UTC (rev 2895)
@@ -163,6 +163,126 @@
 }
 
 /*!
+ *Generate the HTML header for the results table.
+ *\param out Buffer where write it.
+ *\param sortType How elements are sorted.
+ *\param sortReverse True if element are in reverse order.
+ *\param formatString Decide which fields show.
+ */
+void HttpDir::generateHeader (MemBuf &out, char sortType, bool sortReverse,
+                              const char* formatString)
+{
+  const char* cur = formatString;
+
+  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;
+
+    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++;
+  }
+
+  out << "</tr>\r\n";
+}
+
+/*!
+ *Generate the HTML code for an element in the result table.
+ *\param out Buffer where write the HTML.
+ *\param file Structure with information on the element.
+ *\param uriEndWithSlash Specify if the requested resource 
+ *ends with a slash.
+ *\param formatString Specify which element show.
+ */
+void HttpDir::generateElement (MemBuf &out, 
+                               FileStruct &file, 
+                               string &linkPrefix,
+                               const char *formatString)
+{
+  char fileTime[32];
+  string name;
+
+  formatHtml (file.name, name);
+
+  out << "<tr>\r\n";
+  
+  const char* cur = formatString;
+
+  for (;;)
+  {
+    while (*cur && ((*cur == '%' ) || (*cur == ' ' )))
+      cur++;
+
+    if (!(*cur))
+      break;
+
+    switch (*cur)
+    {
+    case 'f':
+      out << "<td><a href=\"";
+      out << linkPrefix << name;
+      out << "\">" ;
+      out << name;
+      out << "</a></td>\r\n";
+      break;
+
+    case 't':
+      getRFC822GMTTime(file.time_write, fileTime, 32);
+      out << "<td>";
+      out << fileTime ;
+      out << "</td>\r\n";
+      break;
+
+    case 's':
+      out << "<td>";
+      if(file.attrib & FILE_ATTRIBUTE_DIRECTORY)
+      {
+        out << "[directory]";
+      }
+      else
+      {
+        string tmp;
+        getFormattedSize(file.size, tmp);
+        out << tmp;
+      }
+      out << "</td>";
+      break;
+    }
+
+    cur++;
+  }
+  out << "</tr>\r\n";
+}
+
+
+/*!
  *Browse a directory printing its contents in an HTML file.
  *\param td The current thread context.
  *\param s The current connection structure.
@@ -182,7 +302,6 @@
   int lastSlash = 0;
   bool useChunks = false;
   u_long sentData = 0;
-  char fileTime[32];
   char* bufferloop;
   const char* browseDirCSSpath;
   bool keepalive = false;
@@ -190,6 +309,12 @@
   size_t sortIndex;
   char sortType;
   bool sortReverse = false;
+  string linkPrefix;
+  const char *formatString = td->securityToken.getHashedData 
("http.dir.format", 
+                                                              
MYSERVER_SECURITY_CONF | MYSERVER_VHOST_CONF |
+                                                              
MYSERVER_SERVER_CONF, "%f%t%s");
+
+
   HttpRequestHeader::Entry *host = td->request.other.get("Host");
 
 
@@ -330,23 +455,10 @@
    *files in the directory.
    */
   td->secondaryBuffer->setLength(0);
-  *td->secondaryBuffer << "<table width=\"100%\">\r\n<tr>\r\n" ;
+  *td->secondaryBuffer << "<table width=\"100%\">\r\n" ;
 
-  if(sortType == 'f' && !sortReverse)
-    *td->secondaryBuffer << "<th><a href=\"?sort=fI\">File</a></th>\r\n";
-  else
-    *td->secondaryBuffer << "<th><a href=\"?sort=f\">File</a></th>\r\n";
+  generateHeader (*td->secondaryBuffer, sortType, sortReverse, formatString);
 
-  if(sortType == 't' && !sortReverse)
-    *td->secondaryBuffer << "<th><a href=\"?sort=tI\">Last 
Modified</a></th>\r\n";
-  else
-    *td->secondaryBuffer << "<th><a href=\"?sort=t\">Last 
Modified</a></th>\r\n";
-
-  if(sortType == 's' && !sortReverse)
-    *td->secondaryBuffer << "<th><a 
href=\"?sort=sI\">Size</a></th>\r\n</tr>\r\n";
-  else
-    *td->secondaryBuffer << "<th><a 
href=\"?sort=s\">Size</a></th>\r\n</tr>\r\n";
-
   ret = appendDataToHTTPChannel(td, td->secondaryBuffer->getBuffer(),
                                 td->secondaryBuffer->getLength(),
                                 &(td->outputData), &chain,
@@ -366,15 +478,33 @@
 
   if(FilesUtility::getPathRecursionLevel(td->request.uri) >= 1)
   {
+    const char* cur = formatString;
     string file;
     file.assign(td->request.uri);
     file.append("/../");
     
-    *td->secondaryBuffer << "<tr>\r\n<td colspan=\"2\">"
-                 << "<a href=\""
-                 << (td->request.uriEndsWithSlash ? ".." : ".")
-           << "\">[ .. ]</a></td>\n"
-                 << "<td>[directory]</td></tr>\r\n";
+    *td->secondaryBuffer << "<tr>\r\n";
+
+    for (;;)
+    {
+      while (*cur && ((*cur == '%' ) || (*cur == ' ' )))
+        cur++;
+      
+      if (!(*cur))
+        break;
+
+      if (*cur == 'f')
+        *td->secondaryBuffer << "<td>\n"
+                             << "<a href=\""
+                             << (td->request.uriEndsWithSlash ? ".." : ".")
+                             << "\">[ .. ]</a></td>\n";
+      else
+        *td->secondaryBuffer << "<td></td>\n";
+
+      cur++;
+    }
+
+    *td->secondaryBuffer << "</tr>\r\n";
     
     ret = appendDataToHTTPChannel(td, td->secondaryBuffer->getBuffer(),
                                   td->secondaryBuffer->getLength(),
@@ -424,48 +554,25 @@
   if(sortReverse)
     reverse (files.begin(), files.end());
 
+  if(!td->request.uriEndsWithSlash)
+  {
+    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++)
   {  
-    string formattedName;
-
     FileStruct& file = *it;
 
     td->secondaryBuffer->setLength(0);
 
-    *td->secondaryBuffer << "<tr>\r\n<td><a href=\"";
-    if(!td->request.uriEndsWithSlash)
-    {
-      *td->secondaryBuffer << &td->request.uri[lastSlash];
-      *td->secondaryBuffer << "/" ;
-    }
-    formattedName.assign(file.name);
+    generateElement (*td->secondaryBuffer, file, linkPrefix, formatString);
 
-    formatHtml(file.name, formattedName);
-
-    *td->secondaryBuffer << formattedName ;
-    *td->secondaryBuffer << "\">" ;
-    *td->secondaryBuffer << formattedName;
-    *td->secondaryBuffer << "</a></td>\r\n<td>";
-  
-    getRFC822GMTTime(file.time_write, fileTime, 32);
-
-    *td->secondaryBuffer << fileTime ;
-    *td->secondaryBuffer << "</td>\r\n<td>";
-    
-    if(file.attrib & FILE_ATTRIBUTE_DIRECTORY)
-    {
-      *td->secondaryBuffer << "[directory]";
-    }
-    else
-    {
-      string out;
-      getFormattedSize(file.size, out);
-       *td->secondaryBuffer << out;
-    }
-
-    *td->secondaryBuffer << "</td>\r\n</tr>\r\n";
     ret = appendDataToHTTPChannel(td, td->secondaryBuffer->getBuffer(),
                                   td->secondaryBuffer->getLength(),
                                   &(td->outputData), &chain,

Modified: trunk/myserver/src/protocol/http/http.cpp
===================================================================
--- trunk/myserver/src/protocol/http/http.cpp   2008-10-19 18:50:26 UTC (rev 
2894)
+++ trunk/myserver/src/protocol/http/http.cpp   2008-10-20 20:21:15 UTC (rev 
2895)
@@ -197,8 +197,8 @@
  */
 bool Http::allowHTTPTRACE()
 {
-  const char *allowTrace = securityToken.getHashedData ("http.allow_trace", 
MYSERVER_VHOST_CONF |
-                                                        MYSERVER_SERVER_CONF, 
"NO");
+  const char *allowTrace = td->securityToken.getHashedData 
("http.allow_trace", MYSERVER_VHOST_CONF |
+                                                              
MYSERVER_SERVER_CONF, "NO");
 
   if (!strcmpi (allowTrace, "YES"))
     return true;
@@ -350,18 +350,18 @@
 int Http::getFilePermissions(string& filename, string& directory, string& 
file, 
                              string &filenamePath, int yetmapped, int* 
permissions)
 {
-  securityToken.setServer (Server::getInstance ());
-  securityToken.setSysDirectory 
((string*)&(td->connection->host->getSystemRoot ()));
+  td->securityToken.setServer (Server::getInstance ());
+  td->securityToken.setSysDirectory 
((string*)&(td->connection->host->getSystemRoot ()));
 
-  securityToken.setVhost (td->connection->host);
+  td->securityToken.setVhost (td->connection->host);
 
   try
   {
     FilesUtility::splitPath (filename, directory, file);
     FilesUtility::completePath (directory);
 
-    securityToken.setResource (&filenamePath);
-    securityToken.setDirectory (&directory);
+    td->securityToken.setResource (&filenamePath);
+    td->securityToken.setDirectory (&directory);
 
     /*!
      *td->filenamePath is the file system mapped path while filename
@@ -440,27 +440,27 @@
       return 500;
     }
 
-    securityToken.setUser (user);
-    securityToken.setPassword (password);
+    td->securityToken.setUser (user);
+    td->securityToken.setPassword (password);
 
-    AuthDomain auth (&securityToken);
+    AuthDomain auth (&(td->securityToken));
     HttpReqSecurityDomain httpReqSecDom (&(td->request));
 
-    string validator (securityToken.getHashedData ("sec.validator", 
MYSERVER_VHOST_CONF |
+    string validator (td->securityToken.getHashedData ("sec.validator", 
MYSERVER_VHOST_CONF |
                                                    MYSERVER_SERVER_CONF, 
"xml"));
-    string authMethod (securityToken.getHashedData ("sec.auth_method", 
MYSERVER_VHOST_CONF |
+    string authMethod (td->securityToken.getHashedData ("sec.auth_method", 
MYSERVER_VHOST_CONF |
                                                     MYSERVER_SERVER_CONF, 
"xml"));
 
 
     SecurityDomain* domains[] = {&auth, &httpReqSecDom, NULL};
 
-    Server::getInstance()->getSecurityManager ()->getPermissionMask 
(&securityToken, domains, 
+    Server::getInstance()->getSecurityManager ()->getPermissionMask 
(&(td->securityToken), domains, 
                                                                      
validator, authMethod);
 
-    const char *authType = securityToken.getHashedData ("http.auth", 
MYSERVER_SECURITY_CONF |
+    const char *authType = td->securityToken.getHashedData ("http.auth", 
MYSERVER_SECURITY_CONF |
                                                         MYSERVER_VHOST_CONF |
                                                         MYSERVER_SERVER_CONF);
-    *permissions = securityToken.getMask ();
+    *permissions = td->securityToken.getMask ();
 
     /*! Check if we have to use digest for the current directory. */
     if(authType && !strcmpi(authType, "Digest"))
@@ -476,8 +476,8 @@
 
         if(hud->digest == 1)
         {
-          td->connection->setPassword (securityToken.getNeededPassword 
().c_str ());
-          *permissions = securityToken.getProvidedMask ();
+          td->connection->setPassword (td->securityToken.getNeededPassword 
().c_str ());
+          *permissions = td->securityToken.getProvidedMask ();
         }
       }
       td->authScheme = HTTP_AUTH_SCHEME_DIGEST;
@@ -493,7 +493,7 @@
     return 500;
   }
 
-  const char *tr = securityToken.getHashedData ("connection.throttling", 
MYSERVER_SECURITY_CONF |
+  const char *tr = td->securityToken.getHashedData ("connection.throttling", 
MYSERVER_SECURITY_CONF |
                                                 MYSERVER_VHOST_CONF |
                                                 MYSERVER_SERVER_CONF);
 
@@ -681,7 +681,7 @@
   md5.init();
   td->secondaryBuffer->setLength(0);
   *td->secondaryBuffer << td->request.digestUsername << ":" << 
td->request.digestRealm
-               << ":" << securityToken.getNeededPassword();
+               << ":" << td->securityToken.getNeededPassword();
 
   md5.update((unsigned char const*)td->secondaryBuffer->getBuffer(),
              (unsigned int)td->secondaryBuffer->getLength());
@@ -1934,7 +1934,6 @@
 {
   try
   {
-    int ret = 0;
     string time;
     ostringstream errorFile;
     string errorMessage;
@@ -1974,9 +1973,9 @@
     char errorName [32];
     sprintf (errorName, "http.error.file.%i", ID);
 
-    const char *defErrorFile = securityToken.getHashedData (errorName, 
MYSERVER_SECURITY_CONF |
-                                                            
MYSERVER_VHOST_CONF |
-                                                            
MYSERVER_SERVER_CONF);
+    const char *defErrorFile = td->securityToken.getHashedData (errorName, 
MYSERVER_SECURITY_CONF |
+                                                                
MYSERVER_VHOST_CONF |
+                                                                
MYSERVER_SERVER_CONF);
 
     if (defErrorFile)
     {






reply via email to

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