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 <[email protected]>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 > >
