You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Sven Dowideit <Sv...@home.org.au> on 2013/08/05 08:26:08 UTC

mod_autoindex string pluggability

Hello Everyone,

I'm scratching an itch to make mod_autoindex output what I want, and
would love to know what, if anything would make the changes merge-able.

In its simplest form, I'd like apache to be able to give me an index in
JSON format - previously, I've parsed the html in javascript, but
somehow I think I can do better.

While I was reading the code (today) it occurred to me that there are a
lot of if statements throughout, which could be eliminated by moving
(obscuring) the output strings to a switchable container (right now I'm
using arrays of strings for my simplicity - I don't know this codebase
any better than you know me :)

so here is the kind of thing I started to do (partial diff, its all
really kind of dull - I've extracted the HTML/XHTML strings into another
similarly replaceable array):


#define STRING_INDEX_START   0
#define STRING_INDEX_END     1

const char *table_index_string[] = {
  "  <table>\n   <tr>",
  "</table>\n"
};

const char *table_index_string_stylesheet[] = {
  "  <table id=\"indexlist\">\n   <tr class=\"indexhead\">",
  "</table>\n"
};

const char *fancy_index_string[] = {
  "<pre>",
  "</pre>\n"
};

const char *default_index_string[] = {
  "<ul>",
  "</ul>\n"
};

/* set the default string set (choose alternatives based on user conf
options) */
const char **index_string = default_index_string;

@@ -1873,23 +1872,14 @@ static void output_directories(struct ent **ar,
int n,
         }
     }
     if (autoindex_opts & TABLE_INDEXING) {
-        ap_rvputs(r, breakrow, "</table>\n", NULL);
+        ap_rputs(breakrow, r);
     }
     else if (autoindex_opts & FANCY_INDEXING) {
         if (!(autoindex_opts & SUPPRESS_RULES)) {
-            ap_rputs("<hr", r);
-            if (autoindex_opts & EMIT_XHTML) {
-                ap_rputs(" /", r);
-            }
-            ap_rputs("></pre>\n", r);
-        }
-        else {
-            ap_rputs("</pre>\n", r);
+            ap_rputs(output_string[STRING_HR], r);
         }
     }
-    else {
-        ap_rputs("</ul>\n", r);
-    }
+    ap_rputs(index_string[STRING_INDEX_END], r);
 }

Cheers
Sven


Re: mod_autoindex string pluggability

Posted by Sven Dowideit <Sv...@home.org.au>.
On 07/08/13 06:55, Daniel Lescohier wrote:
> output_directories seems html-specific code. Why not implement a
> brand-new output_directories_json, and have index_directories()
> function choose which function to call based on query args?  Anyway,
> index_directories() has to change to send the correct content-type
> header, and to skip emit_head and emit_tail function calls.
>
>
Heya,

yup, output_directories seems html specific, but I /think/ I've found a
way to make it text output generic - time and tests will tell tho :)

json was just one example, I'm hoping I can provide an avenue for apache
configurators (rather than coders) to add the next hot thing too :)

Sven

Re: mod_autoindex string pluggability

Posted by Daniel Lescohier <da...@cbsi.com>.
output_directories seems html-specific code. Why not implement a brand-new
output_directories_json, and have index_directories() function choose which
function to call based on query args?  Anyway, index_directories() has to
change to send the correct content-type header, and to skip emit_head and
emit_tail function calls.


On Mon, Aug 5, 2013 at 2:26 AM, Sven Dowideit <Sv...@home.org.au>wrote:

> Hello Everyone,
>
> I'm scratching an itch to make mod_autoindex output what I want, and
> would love to know what, if anything would make the changes merge-able.
>
> In its simplest form, I'd like apache to be able to give me an index in
> JSON format - previously, I've parsed the html in javascript, but
> somehow I think I can do better.
>
> While I was reading the code (today) it occurred to me that there are a
> lot of if statements throughout, which could be eliminated by moving
> (obscuring) the output strings to a switchable container (right now I'm
> using arrays of strings for my simplicity - I don't know this codebase
> any better than you know me :)
>
> so here is the kind of thing I started to do (partial diff, its all
> really kind of dull - I've extracted the HTML/XHTML strings into another
> similarly replaceable array):
>
>
> #define STRING_INDEX_START   0
> #define STRING_INDEX_END     1
>
> const char *table_index_string[] = {
>   "  <table>\n   <tr>",
>   "</table>\n"
> };
>
> const char *table_index_string_stylesheet[] = {
>   "  <table id=\"indexlist\">\n   <tr class=\"indexhead\">",
>   "</table>\n"
> };
>
> const char *fancy_index_string[] = {
>   "<pre>",
>   "</pre>\n"
> };
>
> const char *default_index_string[] = {
>   "<ul>",
>   "</ul>\n"
> };
>
> /* set the default string set (choose alternatives based on user conf
> options) */
> const char **index_string = default_index_string;
>
> @@ -1873,23 +1872,14 @@ static void output_directories(struct ent **ar,
> int n,
>          }
>      }
>      if (autoindex_opts & TABLE_INDEXING) {
> -        ap_rvputs(r, breakrow, "</table>\n", NULL);
> +        ap_rputs(breakrow, r);
>      }
>      else if (autoindex_opts & FANCY_INDEXING) {
>          if (!(autoindex_opts & SUPPRESS_RULES)) {
> -            ap_rputs("<hr", r);
> -            if (autoindex_opts & EMIT_XHTML) {
> -                ap_rputs(" /", r);
> -            }
> -            ap_rputs("></pre>\n", r);
> -        }
> -        else {
> -            ap_rputs("</pre>\n", r);
> +            ap_rputs(output_string[STRING_HR], r);
>          }
>      }
> -    else {
> -        ap_rputs("</ul>\n", r);
> -    }
> +    ap_rputs(index_string[STRING_INDEX_END], r);
>  }
>
> Cheers
> Sven
>
>

Re: mod_autoindex string pluggability

Posted by Ben Reser <be...@reser.org>.
On Mon, Aug 5, 2013 at 5:51 AM, Tim Bannister <is...@jellybaby.net> wrote:
> How about implementing XHTML → JSON as a filter? Either with existing modules or with something dedicated to autoindex.

That sounds really ugly if you ask me.  For one thing he's trying to
avoid parsing XHMTL so now you're suggesting that he write an XHTML
parser in C.  If it was possible to generalize it so that it was
useful to other things than just mod_autoindex then that might be
different.  But I suspect it'll have to be fairly complex to achieve
this.

Re: mod_autoindex string pluggability

Posted by Sven Dowideit <Sv...@home.org.au>.
On 05/08/13 22:51, Tim Bannister wrote:
> How about implementing XHTML → JSON as a filter? Either with existing modules or with something dedicated to autoindex.
>
Heya Tim,

thankyou - I'll file that away for future thought - I don't know
anything about apache filters, so it might come in handy later :)

I /think/ I've found a way to reuse the existing code, but I have one
major reservation - it moves the html strings out of line and into
several structs.

I /think/ that in the process mod_autoindex will use less CPU, but I'll
need to prove it later. For now, I've pushed that aside to write some
httpd-test code to make sure I'm not breaking the existing output
accidentally.

Sven

Re: mod_autoindex string pluggability

Posted by Tim Bannister <is...@jellybaby.net>.
How about implementing XHTML → JSON as a filter? Either with existing modules or with something dedicated to autoindex.

TimOn 05/08/2013 7:26 Sven Dowideit wrote:
Hello Everyone,

I'm scratching an itch to make mod_autoindex output what I want, and
would love to know what, if anything would make the changes merge-able.

In its simplest form, I'd like apache to be able to give me an index in
JSON format - previously, I've parsed the html in javascript, but
somehow I think I can do better.

While I was reading the code (today) it occurred to me that there are a
lot of if statements throughout, which could be eliminated by moving
(obscuring) the output strings to a switchable container (right now I'm
using arrays of strings for my simplicity - I don't know this codebase
any better than you know me :)

so here is the kind of thing I started to do (partial diff, its all
really kind of dull - I've extracted the HTML/XHTML strings into another
similarly replaceable array):


#define STRING_INDEX_START   0
#define STRING_INDEX_END     1

const char *table_index_string[] = {
  "  <table>\n   <tr>",
  "</table>\n"
};

const char *table_index_string_stylesheet[] = {
  "  <table id=\"indexlist\">\n   <tr class=\"indexhead\">",
  "</table>\n"
};

const char *fancy_index_string[] = {
  "<pre>",
  "</pre>\n"
};

const char *default_index_string[] = {
  "<ul>",
  "</ul>\n"
};

/* set the default string set (choose alternatives based on user conf
options) */
const char **index_string = default_index_string;

@@ -1873,23 +1872,14 @@ static void output_directories(struct ent **ar,
int n,
         }
     }
     if (autoindex_opts & TABLE_INDEXING) {
-        ap_rvputs(r, breakrow, "</table>\n", NULL);
+        ap_rputs(breakrow, r);
     }
     else if (autoindex_opts & FANCY_INDEXING) {
         if (!(autoindex_opts & SUPPRESS_RULES)) {
-            ap_rputs("<hr", r);
-            if (autoindex_opts & EMIT_XHTML) {
-                ap_rputs(" /", r);
-            }
-            ap_rputs("></pre>\n", r);
-        }
-        else {
-            ap_rputs("</pre>\n", r);
+            ap_rputs(output_string[STRING_HR], r);
         }
     }
-    else {
-        ap_rputs("</ul>\n", r);
-    }
+    ap_rputs(index_string[STRING_INDEX_END], r);
 }

Cheers
Sven