httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rodent of Unusual Size <Ken.C...@Golux.Com>
Subject [PATCH] Add '+' and '-' to IndexOptions keywords
Date Fri, 25 Sep 1998 19:28:02 GMT
Since I've been futzing around in mod_autoindex recently,
I thought I'd submit this thing I've had banging around
for a while (updated to 1.3.3-dev).

The attached patch enhances IndexOptions to accept
incremental keywords, like 

 IndexOptions -IconsAreLinks +SuppressLastModified

in a manner similar to the Options core directive.  As
a side-effect, multiple IndexOptions directives are
combined, rather than each overriding the last, so the
above is equivalent to 

 IndexOptions -IconsAreLinks
 IndexOptions +SuppressLastModified

One other semantic diference: if a keyword appears
without a '+' or '-' prefix, it totally clears any
existing incremental changes and sets the options to
that keyword.  Subsequent keywords with prefixes
go into the add/remove buckets until the next unprefixed
keyword appears.  That is, these are equivalent:

 IndexOptions +IconsAreLinks +SuppressLastModified FancyIndexing
    and
 IndexOptions FancyIndexing

or

 IndexOptions +IconsAreLinks FancyIndexing -SuppressLastModified
    and
 IndexOptions FancyIndexing -SuppressLastModified

Comments?  This is a feature, so R-T-C applies, yes?

#ken    P-)}

Ken Coar                    <http://Web.Golux.Com/coar/>
Apache Group member         <http://www.apache.org/>
"Apache Server for Dummies" <http://Web.Golux.Com/coar/ASFD/>

Index: modules/standard/mod_autoindex.c
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_autoindex.c,v
retrieving revision 1.93
diff -u -r1.93 mod_autoindex.c
--- mod_autoindex.c     1998/09/24 15:53:40     1.93
+++ mod_autoindex.c     1998/09/25 19:16:18
@@ -131,6 +131,8 @@
 
     char *default_icon;
     int opts;
+    int incremented_opts;
+    int decremented_opts;
     int name_width;
     int name_adjust;
     int icon_width;
@@ -294,6 +296,10 @@
 
     cfg = (autoindex_config_rec *) d;
     curopts = cfg->opts;
+    if (curopts & NO_OPTIONS) {
+       return "FancyIndexing directive conflicts with existing "
+              "IndexOptions None";
+    }
     newopts = (arg ? (curopts | FANCY_INDEXING) : (curopts & ~FANCY_INDEXING));
     cfg->opts = newopts;
     return NULL;
@@ -302,51 +308,97 @@
 static const char *add_opts(cmd_parms *cmd, void *d, const char *optstr)
 {
     char *w;
-    int opts = 0;
+    int opts;
+    int opts_add;
+    int opts_remove;
+    char action;
     autoindex_config_rec *d_cfg = (autoindex_config_rec *) d;
 
+    opts = d_cfg->opts;
+    opts_add = d_cfg->incremented_opts;
+    opts_remove = d_cfg->decremented_opts;
     while (optstr[0]) {
+       int option = 0;
+
        w = ap_getword_conf(cmd->pool, &optstr);
+       if ((*w == '+') || (*w == '-')) {
+           action = *(w++);
+       }
+       else {
+           action = '\0';
+       }
        if (!strcasecmp(w, "FancyIndexing")) {
-           opts |= FANCY_INDEXING;
+           option = FANCY_INDEXING;
        }
        else if (!strcasecmp(w, "IconsAreLinks")) {
-           opts |= ICONS_ARE_LINKS;
+           option = ICONS_ARE_LINKS;
        }
        else if (!strcasecmp(w, "ScanHTMLTitles")) {
-           opts |= SCAN_HTML_TITLES;
+           option = SCAN_HTML_TITLES;
        }
        else if (!strcasecmp(w, "SuppressLastModified")) {
-           opts |= SUPPRESS_LAST_MOD;
+           option = SUPPRESS_LAST_MOD;
        }
        else if (!strcasecmp(w, "SuppressSize")) {
-           opts |= SUPPRESS_SIZE;
+           option = SUPPRESS_SIZE;
        }
        else if (!strcasecmp(w, "SuppressDescription")) {
-           opts |= SUPPRESS_DESC;
+           option = SUPPRESS_DESC;
        }
        else if (!strcasecmp(w, "SuppressHTMLPreamble")) {
-           opts |= SUPPRESS_PREAMBLE;
+           option = SUPPRESS_PREAMBLE;
        }
         else if (!strcasecmp(w, "SuppressColumnSorting")) {
-            opts |= SUPPRESS_COLSORT;
+            option = SUPPRESS_COLSORT;
        }
        else if (!strcasecmp(w, "None")) {
+           if (action != '\0') {
+               return "Cannot combine '+' or '-' with 'None' keyword";
+           }
            opts = NO_OPTIONS;
+           opts_add = 0;
+           opts_remove = 0;
        }
        else if (!strcasecmp(w, "IconWidth")) {
-           d_cfg->icon_width = DEFAULT_ICON_WIDTH;
+           if (action != '-') {
+               d_cfg->icon_width = DEFAULT_ICON_WIDTH;
+           }
+           else {
+               d_cfg->icon_width = 0;
+           }
        }
        else if (!strncasecmp(w, "IconWidth=", 10)) {
+           if (action != '\0') {
+               return "Cannot combine '+' or '-' with IconWidth=n";
+           }
            d_cfg->icon_width = atoi(&w[10]);
        }
        else if (!strcasecmp(w, "IconHeight")) {
-           d_cfg->icon_height = DEFAULT_ICON_HEIGHT;
+           if (action != '-') {
+               d_cfg->icon_height = DEFAULT_ICON_HEIGHT;
+           }
+           else {
+               d_cfg->icon_height = 0;
+           }
        }
        else if (!strncasecmp(w, "IconHeight=", 11)) {
+           if (action != '\0') {
+               return "Cannot combine '+' or '-' with IconHeight=n";
+           }
            d_cfg->icon_height = atoi(&w[11]);
        }
+       else if (!strcasecmp(w, "NameWidth")) {
+           if (action != '-') {
+               return "NameWidth with no value may only appear as "
+                      "'-NameWidth'";
+           }
+           d_cfg->name_width = DEFAULT_NAME_WIDTH;
+           d_cfg->name_adjust = 0;
+       }
        else if (!strncasecmp(w, "NameWidth=", 10)) {
+           if (action != '\0') {
+               return "Cannot combine '+' or '-' with NameWidth=n";
+           }
            if (w[10] == '*') {
                d_cfg->name_adjust = 1;
            }
@@ -362,10 +414,25 @@
        else {
            return "Invalid directory indexing option";
        }
+       if (action == '\0') {
+           opts |= option;
+           opts_add = 0;
+           opts_remove = 0;
+       }
+       else if (action == '+') {
+           opts_add |= option;
+           opts_remove &= ~option;
+       }
+       else {
+           opts_remove |= option;
+           opts_add &= ~option;
+       }
     }
     if ((opts & NO_OPTIONS) && (opts & ~NO_OPTIONS)) {
        return "Cannot combine other IndexOptions keywords with 'None'";
     }
+    d_cfg->incremented_opts = opts_add;
+    d_cfg->decremented_opts = opts_remove;
     d_cfg->opts = opts;
     return NULL;
 }
@@ -418,6 +485,8 @@
     new->hdr_list = ap_make_array(p, 4, sizeof(struct item));
     new->rdme_list = ap_make_array(p, 4, sizeof(struct item));
     new->opts = 0;
+    new->incremented_opts = 0;
+    new->decremented_opts = 0;
 
     return (void *) new;
 }
@@ -441,10 +510,31 @@
     new->icon_list = ap_append_arrays(p, add->icon_list, base->icon_list);
     new->rdme_list = ap_append_arrays(p, add->rdme_list, base->rdme_list);
     if (add->opts & NO_OPTIONS) {
+       /*
+        * If the current directory says 'no options' then we also
+        * clear any incremental mods from being inheritable.
+        */
        new->opts = NO_OPTIONS;
+       new->incremented_opts = 0;
+       new->decremented_opts = 0;
     }
     else {
-       new->opts = base->opts | add->opts;
+       new->incremented_opts = (base->incremented_opts 
+                                | add->incremented_opts)
+                               & ~add->decremented_opts;
+       new->decremented_opts = (base->decremented_opts
+                                | add->decremented_opts);
+       /*
+        * We've got some local settings, so make sure we don't inadvertently
+        * inherit an IndexOptions None from above.
+        */
+       new->opts = ((base->opts | add->opts) & ~NO_OPTIONS);
+       /*
+        * We're guaranteed that there'll be no overlap between
+        * the add-options and the remove-options.
+        */
+       new->opts |= new->incremented_opts;
+       new->opts &= ~new->decremented_opts;
     }
     new->name_width = add->name_width;
     new->name_adjust = add->name_adjust;

Mime
View raw message