Re: [PATCH] IndexResults for mod_autoindex

2002-11-26 Thread Francis Daly
On Fri, Nov 22, 2002 at 11:52:10PM -0600, William A.  Rowe, Jr.  wrote:
> Francis, very cool patch!  I'll look at it if noone beats me to it,
> you aren't the only one who wants this feature :-)

Good to hear, thanks.

One caveat, though, that I should have noticed before posting:

A commit about a year ago (v 1.90) removed identifiers called "stat".
I very cleverly then went and added...

> >+static int show_result(autoindex_config_rec *d, int status)
> >+{
> >+char stat[4];/* HTTP codes are 3 digits long */

..an identifier called "stat".

You may want to modify that before any eventual commit, for
consistency.

All the best,

f
-- 
Francis Daly[EMAIL PROTECTED]



Re: [PATCH] IndexResults for mod_autoindex

2002-11-22 Thread William A. Rowe, Jr.
Francis, very cool patch!  I'll look at it if noone beats me to it,
you aren't the only one who wants this feature :-)

Bill

At 03:09 AM 11/21/2002, Francis Daly wrote:
>Hi there,
>
>This is a late follow-on from some posts in May.
>
>mod_autoindex in Apache/2 does not show filenames for which the requester is
>not authenticated, which is a change from the 1.3 behaviour.
>
>The first patch below introduces a per-directory directive which
>allows the administrator list which http statuses (or status groups)
>should be shown or hidden.
>
>When left unset, I found no clear performance difference in listing a
>directory where no authentication was required (as expected); and also
>found no clear performance difference in listing a directory where each
>file individually required authentication (which was a bit of a
>surprise to me).
>
>Built and tested against vanilla 2.0.43, it applies cleanly to the
>current CVS version, 1.111.
>
>The second patch below is a docs patch against mod_autoindex.xml 1.12.
>
>There are two further optional code patches to follow, which are only
>useful if something similar to these are accepted.
>
>Any comments (and further performance testing) welcome.
>
>f
>-- 
>Francis Daly[EMAIL PROTECTED]
>
>
>--- modules/generators/mod_autoindex.c  17 Oct 2002 18:09:52 -
>+++ modules/generators/mod_autoindex.c  21 Nov 2002 02:33:31 -
>@@ -154,6 +154,12 @@
> int wildcards;
> } ai_desc_t;
> 
>+/* res_info is used when merging res_list */
>+typedef struct res_info {
>+int *range;
>+apr_table_t *tab;
>+} res_info;
>+
> typedef struct autoindex_config_struct {
> 
> char *default_icon;
>@@ -175,6 +181,7 @@
> apr_array_header_t *ign_list;
> apr_array_header_t *hdr_list;
> apr_array_header_t *rdme_list;
>+apr_table_t *res_list;
> 
> } autoindex_config_rec;
> 
>@@ -320,6 +327,45 @@
> return NULL;
> }
> 
>+static const char *set_results(cmd_parms *cmd, void *d, const char *name)
>+{
>+char entry[4];
>+int showp = 1;
>+
>+if (name[0] == '-') {
>+showp = 0;
>+name++;
>+}
>+
>+/* verify that the form is valid */
>+if (name[0] == '\0' || name[1] == '\0' || name[2] == '\0' ||
>+name[3] != '\0') {
>+return "Value (after leading minus) must be three characters long";
>+}
>+
>+/* verify that the value is valid */
>+if ((name[0] < '1' || name[0] > '9')
>+|| !((isdigit(name[1]) && isdigit(name[2]))
>+|| (name[1] == 'x' && name[2] == 'x'))) {
>+return "Value must be [-]### or [-]#xx, where # is a digit";
>+}
>+
>+strcpy(entry, name);
>+if (name[1] == 'x') {
>+entry[1] = '\0';
>+}
>+
>+/* The "value" here is "a string beginning with 1" (for show) or
>+ * "a string not beginning with 1" (for hide), as per show_result() */
>+if (showp) {
>+apr_table_set(((autoindex_config_rec *) d)->res_list, entry, "1");
>+} else {
>+apr_table_set(((autoindex_config_rec *) d)->res_list, entry, "0");
>+}
>+
>+return NULL;
>+}
>+
> static const char *add_ignore(cmd_parms *cmd, void *d, const char *ext)
> {
> push_item(((autoindex_config_rec *) d)->ign_list, 0, ext, cmd->path, NULL);
>@@ -578,6 +624,8 @@
> "one or more file extensions"),
> AP_INIT_ITERATE2("AddDescription", add_desc, BY_PATH, DIR_CMD_PERMS,
>  "Descriptive text followed by one or more filenames"),
>+AP_INIT_ITERATE("IndexResults", set_results, NULL, DIR_CMD_PERMS,
>+"one or more http status codes"),
> AP_INIT_TAKE1("HeaderName", add_header, NULL, DIR_CMD_PERMS,
>   "a filename"),
> AP_INIT_TAKE1("ReadmeName", add_readme, NULL, DIR_CMD_PERMS,
>@@ -590,7 +638,7 @@
> {NULL}
> };
> 
>-static void *create_autoindex_config(apr_pool_t *p, char *dummy)
>+static void *create_autoindex_config(apr_pool_t *p, char *dir)
> {
> autoindex_config_rec *new =
> (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
>@@ -607,15 +655,47 @@
> new->ign_list = apr_array_make(p, 4, sizeof(struct item));
> new->hdr_list = apr_array_make(p, 4, sizeof(struct item));
> new->rdme_list = apr_array_make(p, 4, sizeof(struct item));
>+new->res_list = apr_table_make(p, 4);
> new->opts = 0;
> new->incremented_opts = 0;
> new->decremented_opts = 0;
> new->default_keyid = '\0';
> new->default_direction = '\0';
> 
>+/* include, effectively, a global "IndexResults 3xx" */
>+if (dir == NULL) {
>+apr_table_set(new->res_list, "3", "1");
>+}
>+
> return (void *) new;
> }
> 
>+static int res_list_ranges(int *range, const char *key, const char *dummy)
>+{
>+int ikey;
>+
>+ikey = atoi(key);
>+if (ikey < 10) {
>+range[ikey] = 1; 
>+range[0] = 1;
>+}
>+return 1;
>+}
>+
>+static int res_list_del_entries(res_info *info, const char *key, 
>+const char *dumm

Re: [PATCH] IndexResults for mod_autoindex

2002-11-21 Thread Chris Taylor
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

I'd just like to say thanks that someone finally got round to this,
it's been my only significant issue with Apache 2 since I started
using it :)

Thanks again,

Chris Taylor - The guy with the PS2 WebServer
Email: [EMAIL PROTECTED] - PGP: http://www.x-bb.org/chris.asc

- - Original Message - 
From: "Francis Daly" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, November 21, 2002 9:09 AM
Subject: [PATCH] IndexResults for mod_autoindex


> Hi there,
> 
> This is a late follow-on from some posts in May.
> 
> mod_autoindex in Apache/2 does not show filenames for which the
> requester is not authenticated, which is a change from the 1.3
> behaviour.
> 
> The first patch below introduces a per-directory directive which
> allows the administrator list which http statuses (or status
> groups) should be shown or hidden.
> 
> When left unset, I found no clear performance difference in listing
> a directory where no authentication was required (as expected); and
> also found no clear performance difference in listing a directory
> where each file individually required authentication (which was a
> bit of a
> surprise to me).
> 
> Built and tested against vanilla 2.0.43, it applies cleanly to the
> current CVS version, 1.111.
> 
> The second patch below is a docs patch against mod_autoindex.xml
> 1.12.  
> 
> There are two further optional code patches to follow, which are
> only useful if something similar to these are accepted.
> 
> Any comments (and further performance testing) welcome.
> 
> f
> -- 
> Francis Daly[EMAIL PROTECTED]
> 
> 
> --- modules/generators/mod_autoindex.c 17 Oct 2002 18:09:52 -
> +++ modules/generators/mod_autoindex.c 21 Nov 2002 02:33:31 -
> @@ -154,6 +154,12 @@
>  int wildcards;
>  } ai_desc_t;
>  
> +/* res_info is used when merging res_list */
> +typedef struct res_info {
> +int *range;
> +apr_table_t *tab;
> +} res_info;
> +
>  typedef struct autoindex_config_struct {
>  
>  char *default_icon;
> @@ -175,6 +181,7 @@
>  apr_array_header_t *ign_list;
>  apr_array_header_t *hdr_list;
>  apr_array_header_t *rdme_list;
> +apr_table_t *res_list;
>  
>  } autoindex_config_rec;
>  
> @@ -320,6 +327,45 @@
>  return NULL;
>  }
>  
> +static const char *set_results(cmd_parms *cmd, void *d, const char
> *name) +{
> +char entry[4];
> +int showp = 1;
> +
> +if (name[0] == '-') {
> +showp = 0;
> +name++;
> +}
> +
> +/* verify that the form is valid */
> +if (name[0] == '\0' || name[1] == '\0' || name[2] == '\0' ||
> +name[3] != '\0') {
> +return "Value (after leading minus) must be three
> characters long"; +}
> +
> +/* verify that the value is valid */
> +if ((name[0] < '1' || name[0] > '9')
> +|| !((isdigit(name[1]) && isdigit(name[2]))
> +|| (name[1] == 'x' && name[2] == 'x'))) {
> +return "Value must be [-]### or [-]#xx, where # is a
> digit"; +}
> +
> +strcpy(entry, name);
> +if (name[1] == 'x') {
> +entry[1] = '\0';
> +}
> +
> +/* The "value" here is "a string beginning with 1" (for show)
> or + * "a string not beginning with 1" (for hide), as per
> show_result() */ +if (showp) {
> +apr_table_set(((autoindex_config_rec *) d)->res_list,
> entry, "1"); +} else {
> +apr_table_set(((autoindex_config_rec *) d)->res_list,
> entry, "0"); +}
> +
> +return NULL;
> +}
> +
>  static const char *add_ignore(cmd_parms *cmd, void *d, const char
> *ext) 
>  {
>  push_item(((autoindex_config_rec *) d)->ign_list, 0, ext,
> cmd->path, NULL); @@ -578,6 +624,8 @@
>  "one or more file extensions"),
>  AP_INIT_ITERATE2("AddDescription", add_desc, BY_PATH,
> DIR_CMD_PERMS, 
>   "Descriptive text followed by one or more
> filenames"), +AP_INIT_ITERATE("IndexResults", set_results,
> NULL, DIR_CMD_PERMS, +"one or more http status codes"),
>  AP_INIT_TAKE1("HeaderName", add_header, NULL, DIR_CMD_PERMS,
>"a filename"),
>  AP_INIT_TAKE1("ReadmeName", add_readme, NULL, DIR_CMD_PERMS,
> @@ -590,7 +638,7 @@
>  {NULL}
>  };
>  
> -static void *create_autoindex_config(apr_pool_t *p, cha

Re: [PATCH] IndexResults for mod_autoindex

2002-11-21 Thread Francis Daly
On Thu, Nov 21, 2002 at 09:09:35AM +, Francis Daly wrote:

> There are two further optional code patches to follow, which are only
> useful if something similar to these are accepted.

Here come the patches...

The first changes the icon presented in the mod_autoindex listing (if
FancyIndexing is on) to the whatever is set for ^^UNAUTHORIZED^^ or,
failing that, the default.  (The final patch is a docs patch for that magic
string.)

The second additionally hides details like file size and modification
time from unauthorized requesters.  If they want that info, they can
HEAD the resource with credentials, or just request the directory
index with credentials.

The first patch is probably useful.  The second is possibly
unnecessary.  I like them both.  Neither are required.

All are against the as-patched-in-previous-mail versions, although
they should be trivial to modify if those patches are changed before
being accepted.

All the best,

f
-- 
Francis Daly[EMAIL PROTECTED]

--- modules/generators/mod_autoindex.c  21 Nov 2002 02:35:54 -
+++ modules/generators/mod_autoindex.c  21 Nov 2002 02:40:23 -
@@ -1468,6 +1468,11 @@
 p->ascending = (apr_toupper(direction) == D_ASCENDING);
 p->version_sort = !!(autoindex_opts & VERSION_SORT);
 
+/* Change to the "UNAUTHORIZED" icon, if appropriate */
+if (rr->status == HTTP_UNAUTHORIZED) {
+rr->filename = "^^UNAUTHORIZED^^";
+}
+
 if (autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING)) {
 p->lm = rr->finfo.mtime;
 if (dirent->filetype == APR_DIR) {

--- modules/generators//mod_autoindex.c 21 Nov 2002 02:40:23 -
+++ modules/generators//mod_autoindex.c 21 Nov 2002 02:41:24 -
@@ -1468,9 +1468,12 @@
 p->ascending = (apr_toupper(direction) == D_ASCENDING);
 p->version_sort = !!(autoindex_opts & VERSION_SORT);
 
-/* Change to the "UNAUTHORIZED" icon, if appropriate */
+/* Change to the "UNAUTHORIZED" icon, if appropriate. 
+   And conceal details which people don't need until they authenticate */
 if (rr->status == HTTP_UNAUTHORIZED) {
 rr->filename = "^^UNAUTHORIZED^^";
+rr->finfo.mtime = -1;
+rr->finfo.size = -1;
 }
 
 if (autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING)) {

--- mod_autoindex.xml.new   Thu Nov 21 09:27:14 2002
+++ mod_autoindex.xml   Thu Nov 21 09:28:10 2002
@@ -309,7 +309,9 @@
 
 Name is either ^^DIRECTORY^^ for directories,
 ^^BLANKICON^^ for blank lines (to format the list
-correctly), a file extension, a wildcard expression, a partial
+correctly), ^^UNAUTHORIZED^^ for anything for which
+the user has not provided appropriate credentials (available from
+2.0.44), a file extension, a wildcard expression, a partial
 filename or a complete filename.
 
 Examples



[PATCH] IndexResults for mod_autoindex

2002-11-21 Thread Francis Daly
Hi there,

This is a late follow-on from some posts in May.

mod_autoindex in Apache/2 does not show filenames for which the requester is
not authenticated, which is a change from the 1.3 behaviour.

The first patch below introduces a per-directory directive which
allows the administrator list which http statuses (or status groups)
should be shown or hidden.

When left unset, I found no clear performance difference in listing a
directory where no authentication was required (as expected); and also
found no clear performance difference in listing a directory where each
file individually required authentication (which was a bit of a
surprise to me).

Built and tested against vanilla 2.0.43, it applies cleanly to the
current CVS version, 1.111.

The second patch below is a docs patch against mod_autoindex.xml 1.12.

There are two further optional code patches to follow, which are only
useful if something similar to these are accepted.

Any comments (and further performance testing) welcome.

f
-- 
Francis Daly[EMAIL PROTECTED]


--- modules/generators/mod_autoindex.c  17 Oct 2002 18:09:52 -
+++ modules/generators/mod_autoindex.c  21 Nov 2002 02:33:31 -
@@ -154,6 +154,12 @@
 int wildcards;
 } ai_desc_t;
 
+/* res_info is used when merging res_list */
+typedef struct res_info {
+int *range;
+apr_table_t *tab;
+} res_info;
+
 typedef struct autoindex_config_struct {
 
 char *default_icon;
@@ -175,6 +181,7 @@
 apr_array_header_t *ign_list;
 apr_array_header_t *hdr_list;
 apr_array_header_t *rdme_list;
+apr_table_t *res_list;
 
 } autoindex_config_rec;
 
@@ -320,6 +327,45 @@
 return NULL;
 }
 
+static const char *set_results(cmd_parms *cmd, void *d, const char *name)
+{
+char entry[4];
+int showp = 1;
+
+if (name[0] == '-') {
+showp = 0;
+name++;
+}
+
+/* verify that the form is valid */
+if (name[0] == '\0' || name[1] == '\0' || name[2] == '\0' ||
+name[3] != '\0') {
+return "Value (after leading minus) must be three characters long";
+}
+
+/* verify that the value is valid */
+if ((name[0] < '1' || name[0] > '9')
+|| !((isdigit(name[1]) && isdigit(name[2]))
+|| (name[1] == 'x' && name[2] == 'x'))) {
+return "Value must be [-]### or [-]#xx, where # is a digit";
+}
+
+strcpy(entry, name);
+if (name[1] == 'x') {
+entry[1] = '\0';
+}
+
+/* The "value" here is "a string beginning with 1" (for show) or
+ * "a string not beginning with 1" (for hide), as per show_result() */
+if (showp) {
+apr_table_set(((autoindex_config_rec *) d)->res_list, entry, "1");
+} else {
+apr_table_set(((autoindex_config_rec *) d)->res_list, entry, "0");
+}
+
+return NULL;
+}
+
 static const char *add_ignore(cmd_parms *cmd, void *d, const char *ext)
 {
 push_item(((autoindex_config_rec *) d)->ign_list, 0, ext, cmd->path, NULL);
@@ -578,6 +624,8 @@
 "one or more file extensions"),
 AP_INIT_ITERATE2("AddDescription", add_desc, BY_PATH, DIR_CMD_PERMS,
  "Descriptive text followed by one or more filenames"),
+AP_INIT_ITERATE("IndexResults", set_results, NULL, DIR_CMD_PERMS,
+"one or more http status codes"),
 AP_INIT_TAKE1("HeaderName", add_header, NULL, DIR_CMD_PERMS,
   "a filename"),
 AP_INIT_TAKE1("ReadmeName", add_readme, NULL, DIR_CMD_PERMS,
@@ -590,7 +638,7 @@
 {NULL}
 };
 
-static void *create_autoindex_config(apr_pool_t *p, char *dummy)
+static void *create_autoindex_config(apr_pool_t *p, char *dir)
 {
 autoindex_config_rec *new =
 (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
@@ -607,15 +655,47 @@
 new->ign_list = apr_array_make(p, 4, sizeof(struct item));
 new->hdr_list = apr_array_make(p, 4, sizeof(struct item));
 new->rdme_list = apr_array_make(p, 4, sizeof(struct item));
+new->res_list = apr_table_make(p, 4);
 new->opts = 0;
 new->incremented_opts = 0;
 new->decremented_opts = 0;
 new->default_keyid = '\0';
 new->default_direction = '\0';
 
+/* include, effectively, a global "IndexResults 3xx" */
+if (dir == NULL) {
+apr_table_set(new->res_list, "3", "1");
+}
+
 return (void *) new;
 }
 
+static int res_list_ranges(int *range, const char *key, const char *dummy)
+{
+int ikey;
+
+ikey = atoi(key);
+if (ikey < 10) {
+range[ikey] = 1; 
+range[0] = 1;
+}
+return 1;
+}
+
+static int res_list_del_entries(res_info *info, const char *key, 
+const char *dummy)
+{
+int ikey;
+
+ikey = atoi(key);
+if (ikey >= 100) {
+if ((*info).range[ikey/100] == 1) {
+apr_table_unset((*info).tab, key);
+} 
+}
+return 1;
+}
+
 static void *merge_autoindex_configs(apr_pool_t *p, void *basev, void *addv)
 {
 autoindex_config_rec *new;
@@ -634