httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francis Daly <d...@daoine.org>
Subject [PATCH] Case-insensitive listing in mod_autoindex
Date Wed, 27 Nov 2002 13:38:20 GMT
Hi there,

Apache/1.3.24+ had the option to sort the file list generated by
mod_autoindex in a case-insensitive fashion, by using "IndexOptions
+IgnoreCase".

This functionality has not been carried over to Apache/2.

There is an open bug report on the issue -- 
http://nagoya.apache.org/bugzilla/show_bug.cgi?14276

I'm not sure if there was a deliberate decision taken to remove this
functionality from Apache/2, or if it's just that no-one has yet gotten
around to putting it back in.

On the off-chance that it is the latter, I offer the following patch 
which provides a similar function, but uses a different directive.  It
adds "NameNoCase" as a possible second argument of IndexOrderDefault.
It also adds "(case)" to the output list heading as a link to the
case-insensitively-sorted list, if the client is able to choose that.

Note that this is not equivalent to the old IgnoreCase; if identical
functionality is wanted, then a different patch will be needed.

Built and tested against 2.0.43, it was adjusted to apply cleanly to
the current cvs version of mod_autoindex.c, 1.112.

The second patch should apply cleanly to version 1.12 of
mod_autoindex.xml.  It contains the usual amount of presumption; a true
compatibility note can be added depending on when and if the patch
is accepted.

Any comments welcome,

	f
-- 
Francis Daly        deva@daoine.org

--- mod_autoindex.c-1.112	Wed Nov 27 12:53:44 2002
+++ mod_autoindex.c	Wed Nov 27 13:25:04 2002
@@ -119,10 +119,11 @@
  * Define keys for sorting.
  */
 #define K_NAME 'N'              /* Sort by file name (default) */
+#define K_NO_CASE 'C'           /* Case-insensitive name */
 #define K_LAST_MOD 'M'          /* Last modification date */
 #define K_SIZE 'S'              /* Size (absolute, not as displayed) */
 #define K_DESC 'D'              /* Description */
-#define K_VALID "NMSD"          /* String containing _all_ valid K_ opts */
+#define K_VALID "NCMSD"         /* String containing _all_ valid K_ opts */
 
 #define D_ASCENDING 'A'
 #define D_DESCENDING 'D'
@@ -537,6 +538,9 @@
     if (!strcasecmp(key, "Name")) {
         d_cfg->default_keyid = K_NAME;
     }
+    else if (!strcasecmp(key, "NameNoCase")) {
+        d_cfg->default_keyid = K_NO_CASE;
+    }
     else if (!strcasecmp(key, "Date")) {
         d_cfg->default_keyid = K_LAST_MOD;
     }
@@ -547,8 +551,8 @@
         d_cfg->default_keyid = K_DESC;
     }
     else {
-        return "Second keyword must be 'Name', 'Date', 'Size', or "
-               "'Description'";
+        return "Second keyword must be 'Name', 'NameNoCase', 'Date', "
+               "'Size', or 'Description'";
     }
 
     return NULL;
@@ -573,7 +577,7 @@
     AP_INIT_RAW_ARGS("IndexOptions", add_opts, NULL, DIR_CMD_PERMS,
                      "one or more index options [+|-][]"),
     AP_INIT_TAKE2("IndexOrderDefault", set_default_order, NULL, DIR_CMD_PERMS,
-                  "{Ascending,Descending} {Name,Size,Description,Date}"),
+                  "{Ascending,Descending} {Name,NameNoCase,Size,Description,Date}"),
     AP_INIT_ITERATE("IndexIgnore", add_ignore, NULL, DIR_CMD_PERMS,
                     "one or more file extensions"),
     AP_INIT_ITERATE2("AddDescription", add_desc, BY_PATH, DIR_CMD_PERMS,
@@ -1552,6 +1556,10 @@
         ap_rputs("<th>", r);
         emit_link(r, "Name", K_NAME, keyid, direction, 
                   colargs, static_columns);
+        if (!static_columns) {
+            emit_link(r, " (case)", K_NO_CASE, keyid, direction, 
+                      colargs, static_columns);
+        }
         if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
             ap_rputs("</th><th>", r);
             emit_link(r, "Last modified", K_LAST_MOD, keyid, direction, 
@@ -1597,7 +1605,13 @@
         }
         emit_link(r, "Name", K_NAME, keyid, direction, 
                   colargs, static_columns);
-        ap_rputs(pad_scratch + 4, r);
+        if (!static_columns) {
+            emit_link(r, " (case)", K_NO_CASE, keyid, direction, 
+                      colargs, static_columns);
+            ap_rputs(pad_scratch + 4 + 7, r);
+        } else {
+            ap_rputs(pad_scratch + 4, r);
+        }
         /*
          * Emit the guaranteed-at-least-one-space-between-columns byte.
          */
@@ -1891,6 +1905,17 @@
         else {
             result = strcmp(c1->desc ? c1->desc : "",
                             c2->desc ? c2->desc : "");
+        }
+        if (result) {
+            return result;
+        }
+        break;
+    case K_NO_CASE:
+        if (c1->version_sort) {
+            result = apr_strnatcasecmp(c1->name, c2->name);
+        } 
+        else {
+            result = strcasecmp(c1->name, c2->name);
         }
         if (result) {
             return result;

--- mod_autoindex.xml-1.12	Wed Nov 27 13:04:42 2002
+++ mod_autoindex.xml	Wed Nov 27 13:07:49 2002
@@ -813,7 +813,7 @@
 <name>IndexOrderDefault</name>
 <description>Sets the default ordering of the directory index</description>
 <syntax>IndexOrderDefault Ascending|Descending
-Name|Date|Size|Description</syntax>
+Name|NameNoCase|Date|Size|Description</syntax>
 <default>IndexOrderDefault Ascending Name</default>
 <contextlist><context>server config</context><context>virtual host</context>
 <context>directory</context><context>.htaccess</context>
@@ -832,9 +832,9 @@
     arguments. The first must be either <code>Ascending</code> or
     <code>Descending</code>, indicating the direction of the sort.
     The second argument must be one of the keywords <code>Name</code>,
-    <code>Date</code>, <code>Size</code>, or <code>Description</code>,
-    and identifies the primary key. The secondary key is
-    <em>always</em> the ascending filename.</p>
+    <code>NameNoCase</code>, <code>Date</code>, <code>Size</code>,
or 
+    <code>Description</code>, and identifies the primary key. The 
+    secondary key is <em>always</em> the ascending filename.</p>
 
     <p>You can force a directory listing to only be displayed in a
     particular order by combining this directive with the <code><a
@@ -842,6 +842,8 @@
     >SuppressColumnSorting</a></code> index option; this will prevent
     the client from requesting the directory listing in a different
     order.</p>
+
+    <note>NameNoCase is available after 2.0.44</note>
 </usage>
 </directivesynopsis>
 

Mime
View raw message