|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* mod_autoindex.c: Handles the on-the-fly html index generation
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Rob McCool
|
|
Packit |
90a5c9 |
* 3/23/93
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Adapted to Apache by rst.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Version sort added by Martin Pool <mbp@humbug.org.au>.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "apr_strings.h"
|
|
Packit |
90a5c9 |
#include "apr_fnmatch.h"
|
|
Packit |
90a5c9 |
#include "apr_strings.h"
|
|
Packit |
90a5c9 |
#include "apr_lib.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define APR_WANT_STRFUNC
|
|
Packit |
90a5c9 |
#include "apr_want.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "ap_config.h"
|
|
Packit |
90a5c9 |
#include "httpd.h"
|
|
Packit |
90a5c9 |
#include "http_config.h"
|
|
Packit |
90a5c9 |
#include "http_core.h"
|
|
Packit |
90a5c9 |
#include "http_request.h"
|
|
Packit |
90a5c9 |
#include "http_protocol.h"
|
|
Packit |
90a5c9 |
#include "http_log.h"
|
|
Packit |
90a5c9 |
#include "http_main.h"
|
|
Packit |
90a5c9 |
#include "util_script.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "mod_core.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
module AP_MODULE_DECLARE_DATA autoindex_module;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/****************************************************************
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Handling configuration directives...
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define NO_OPTIONS (1 << 0) /* Indexing options */
|
|
Packit |
90a5c9 |
#define ICONS_ARE_LINKS (1 << 1)
|
|
Packit |
90a5c9 |
#define SCAN_HTML_TITLES (1 << 2)
|
|
Packit |
90a5c9 |
#define SUPPRESS_ICON (1 << 3)
|
|
Packit |
90a5c9 |
#define SUPPRESS_LAST_MOD (1 << 4)
|
|
Packit |
90a5c9 |
#define SUPPRESS_SIZE (1 << 5)
|
|
Packit |
90a5c9 |
#define SUPPRESS_DESC (1 << 6)
|
|
Packit |
90a5c9 |
#define SUPPRESS_PREAMBLE (1 << 7)
|
|
Packit |
90a5c9 |
#define SUPPRESS_COLSORT (1 << 8)
|
|
Packit |
90a5c9 |
#define SUPPRESS_RULES (1 << 9)
|
|
Packit |
90a5c9 |
#define FOLDERS_FIRST (1 << 10)
|
|
Packit |
90a5c9 |
#define VERSION_SORT (1 << 11)
|
|
Packit |
90a5c9 |
#define TRACK_MODIFIED (1 << 12)
|
|
Packit |
90a5c9 |
#define FANCY_INDEXING (1 << 13)
|
|
Packit |
90a5c9 |
#define TABLE_INDEXING (1 << 14)
|
|
Packit |
90a5c9 |
#define IGNORE_CLIENT (1 << 15)
|
|
Packit |
90a5c9 |
#define IGNORE_CASE (1 << 16)
|
|
Packit |
90a5c9 |
#define EMIT_XHTML (1 << 17)
|
|
Packit |
90a5c9 |
#define SHOW_FORBIDDEN (1 << 18)
|
|
Packit |
90a5c9 |
#define ADDALTCLASS (1 << 19)
|
|
Packit |
90a5c9 |
#define OPTION_UNSET (1 << 20)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define K_NOADJUST 0
|
|
Packit |
90a5c9 |
#define K_ADJUST 1
|
|
Packit |
90a5c9 |
#define K_UNSET 2
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Define keys for sorting.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#define K_NAME 'N' /* Sort by file name (default) */
|
|
Packit |
90a5c9 |
#define K_LAST_MOD 'M' /* Last modification date */
|
|
Packit |
90a5c9 |
#define K_SIZE 'S' /* Size (absolute, not as displayed) */
|
|
Packit |
90a5c9 |
#define K_DESC 'D' /* Description */
|
|
Packit |
90a5c9 |
#define K_VALID "NMSD" /* String containing _all_ valid K_ opts */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define D_ASCENDING 'A'
|
|
Packit |
90a5c9 |
#define D_DESCENDING 'D'
|
|
Packit |
90a5c9 |
#define D_VALID "AD" /* String containing _all_ valid D_ opts */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* These are the dimensions of the default icons supplied with Apache.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#define DEFAULT_ICON_WIDTH 20
|
|
Packit |
90a5c9 |
#define DEFAULT_ICON_HEIGHT 22
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Other default dimensions.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#define DEFAULT_NAME_WIDTH 23
|
|
Packit |
90a5c9 |
#define DEFAULT_DESC_WIDTH 23
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct item {
|
|
Packit |
90a5c9 |
char *type;
|
|
Packit |
90a5c9 |
char *apply_to;
|
|
Packit |
90a5c9 |
char *apply_path;
|
|
Packit |
90a5c9 |
char *data;
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef struct ai_desc_t {
|
|
Packit |
90a5c9 |
char *pattern;
|
|
Packit |
90a5c9 |
char *description;
|
|
Packit |
90a5c9 |
int full_path;
|
|
Packit |
90a5c9 |
int wildcards;
|
|
Packit |
90a5c9 |
} ai_desc_t;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef struct autoindex_config_struct {
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
char *default_icon;
|
|
Packit |
90a5c9 |
char *style_sheet;
|
|
Packit |
90a5c9 |
char *head_insert;
|
|
Packit |
90a5c9 |
char *header;
|
|
Packit |
90a5c9 |
char *readme;
|
|
Packit |
90a5c9 |
apr_int32_t opts;
|
|
Packit |
90a5c9 |
apr_int32_t incremented_opts;
|
|
Packit |
90a5c9 |
apr_int32_t decremented_opts;
|
|
Packit |
90a5c9 |
int name_width;
|
|
Packit |
90a5c9 |
int name_adjust;
|
|
Packit |
90a5c9 |
int desc_width;
|
|
Packit |
90a5c9 |
int desc_adjust;
|
|
Packit |
90a5c9 |
int icon_width;
|
|
Packit |
90a5c9 |
int icon_height;
|
|
Packit |
90a5c9 |
char default_keyid;
|
|
Packit |
90a5c9 |
char default_direction;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_array_header_t *icon_list;
|
|
Packit |
90a5c9 |
apr_array_header_t *alt_list;
|
|
Packit |
90a5c9 |
apr_array_header_t *desc_list;
|
|
Packit |
90a5c9 |
apr_array_header_t *ign_list;
|
|
Packit |
90a5c9 |
int ign_noinherit;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
char *ctype;
|
|
Packit |
90a5c9 |
char *charset;
|
|
Packit |
90a5c9 |
char *datetime_format;
|
|
Packit |
90a5c9 |
} autoindex_config_rec;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static char c_by_encoding, c_by_type, c_by_path;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define BY_ENCODING &c_by_encoding
|
|
Packit |
90a5c9 |
#define BY_TYPE &c_by_type
|
|
Packit |
90a5c9 |
#define BY_PATH &c_by_path
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static APR_INLINE int response_is_html(request_rec *r)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *ctype = ap_field_noparam(r->pool, r->content_type);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return !ap_cstr_casecmp(ctype, "text/html")
|
|
Packit |
90a5c9 |
|| !ap_cstr_casecmp(ctype, "application/xhtml+xml");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* This routine puts the standard HTML header at the top of the index page.
|
|
Packit |
90a5c9 |
* We include the DOCTYPE because we may be using features therefrom (i.e.,
|
|
Packit |
90a5c9 |
* HEIGHT and WIDTH attributes on the icons if we're FancyIndexing).
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static void emit_preamble(request_rec *r, int xhtml, const char *title)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
autoindex_config_rec *d;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config,
|
|
Packit |
90a5c9 |
&autoindex_module);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (xhtml) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, DOCTYPE_XHTML_1_0T,
|
|
Packit |
90a5c9 |
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
|
|
Packit |
90a5c9 |
" <head>\n <title>Index of ", title,
|
|
Packit |
90a5c9 |
"</title>\n", NULL);
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
ap_rvputs(r, DOCTYPE_HTML_3_2,
|
|
Packit |
90a5c9 |
"<html>\n <head>\n"
|
|
Packit |
90a5c9 |
" <title>Index of ", title,
|
|
Packit |
90a5c9 |
"</title>\n", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (d->style_sheet != NULL) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, " <link rel=\"stylesheet\" href=\"", d->style_sheet,
|
|
Packit |
90a5c9 |
"\" type=\"text/css\"", xhtml ? " />\n" : ">\n", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (d->head_insert != NULL) {
|
|
Packit |
90a5c9 |
ap_rputs(d->head_insert, r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs(" </head>\n <body>\n", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void push_item(apr_array_header_t *arr, char *type, const char *to,
|
|
Packit |
90a5c9 |
const char *path, const char *data)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
struct item *p = (struct item *) apr_array_push(arr);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!to) {
|
|
Packit |
90a5c9 |
to = "";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!path) {
|
|
Packit |
90a5c9 |
path = "";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
p->type = type;
|
|
Packit |
90a5c9 |
p->data = apr_pstrdup(arr->pool, data);
|
|
Packit |
90a5c9 |
p->apply_path = apr_pstrcat(arr->pool, path, "*", NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((type == BY_PATH) && (!ap_is_matchexp(to))) {
|
|
Packit |
90a5c9 |
p->apply_to = apr_pstrcat(arr->pool, "*", to, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
p->apply_to = apr_pstrdup(arr->pool, to);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *add_alt(cmd_parms *cmd, void *d, const char *alt,
|
|
Packit |
90a5c9 |
const char *to)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (cmd->info == BY_PATH) {
|
|
Packit |
90a5c9 |
if (!strcmp(to, "**DIRECTORY**")) {
|
|
Packit |
90a5c9 |
to = "^^DIRECTORY^^";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (cmd->info == BY_ENCODING) {
|
|
Packit |
90a5c9 |
char *tmp = apr_pstrdup(cmd->temp_pool, to);
|
|
Packit |
90a5c9 |
ap_str_tolower(tmp);
|
|
Packit |
90a5c9 |
to = tmp;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
push_item(((autoindex_config_rec *) d)->alt_list, cmd->info, to,
|
|
Packit |
90a5c9 |
cmd->path, alt);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *add_icon(cmd_parms *cmd, void *d, const char *icon,
|
|
Packit |
90a5c9 |
const char *to)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *iconbak = apr_pstrdup(cmd->temp_pool, icon);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (icon[0] == '(') {
|
|
Packit |
90a5c9 |
char *alt;
|
|
Packit |
90a5c9 |
char *cl = strchr(iconbak, ')');
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (cl == NULL) {
|
|
Packit |
90a5c9 |
return "missing closing paren";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
alt = ap_getword_nc(cmd->temp_pool, &iconbak, ',');
|
|
Packit |
90a5c9 |
*cl = '\0'; /* Lose closing paren */
|
|
Packit |
90a5c9 |
add_alt(cmd, d, &alt[1], to);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (cmd->info == BY_PATH) {
|
|
Packit |
90a5c9 |
if (!strcmp(to, "**DIRECTORY**")) {
|
|
Packit |
90a5c9 |
to = "^^DIRECTORY^^";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (cmd->info == BY_ENCODING) {
|
|
Packit |
90a5c9 |
char *tmp = apr_pstrdup(cmd->temp_pool, to);
|
|
Packit |
90a5c9 |
ap_str_tolower(tmp);
|
|
Packit |
90a5c9 |
to = tmp;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
push_item(((autoindex_config_rec *) d)->icon_list, cmd->info, to,
|
|
Packit |
90a5c9 |
cmd->path, iconbak);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Add description text for a filename pattern. If the pattern has
|
|
Packit |
90a5c9 |
* wildcards already (or we need to add them), add leading and
|
|
Packit |
90a5c9 |
* trailing wildcards to it to ensure substring processing. If the
|
|
Packit |
90a5c9 |
* pattern contains a '/' anywhere, force wildcard matching mode,
|
|
Packit |
90a5c9 |
* add a slash to the prefix so that "bar/bletch" won't be matched
|
|
Packit |
90a5c9 |
* by "foobar/bletch", and make a note that there's a delimiter;
|
|
Packit |
90a5c9 |
* the matching routine simplifies to just the actual filename
|
|
Packit |
90a5c9 |
* whenever it can. This allows definitions in parent directories
|
|
Packit |
90a5c9 |
* to be made for files in subordinate ones using relative paths.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Absent a strcasestr() function, we have to force wildcards on
|
|
Packit |
90a5c9 |
* systems for which "AAA" and "aaa" mean the same file.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#ifdef CASE_BLIND_FILESYSTEM
|
|
Packit |
90a5c9 |
#define WILDCARDS_REQUIRED 1
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
#define WILDCARDS_REQUIRED 0
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *add_desc(cmd_parms *cmd, void *d, const char *desc,
|
|
Packit |
90a5c9 |
const char *to)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
autoindex_config_rec *dcfg = (autoindex_config_rec *) d;
|
|
Packit |
90a5c9 |
ai_desc_t *desc_entry;
|
|
Packit |
90a5c9 |
char *prefix = "";
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
desc_entry = (ai_desc_t *) apr_array_push(dcfg->desc_list);
|
|
Packit |
90a5c9 |
desc_entry->full_path = (ap_strchr_c(to, '/') == NULL) ? 0 : 1;
|
|
Packit |
90a5c9 |
desc_entry->wildcards = (WILDCARDS_REQUIRED
|
|
Packit |
90a5c9 |
|| desc_entry->full_path
|
|
Packit |
90a5c9 |
|| apr_fnmatch_test(to));
|
|
Packit |
90a5c9 |
if (desc_entry->wildcards) {
|
|
Packit |
90a5c9 |
prefix = desc_entry->full_path ? "*/" : "*";
|
|
Packit |
90a5c9 |
desc_entry->pattern = apr_pstrcat(dcfg->desc_list->pool,
|
|
Packit |
90a5c9 |
prefix, to, "*", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
desc_entry->pattern = apr_pstrdup(dcfg->desc_list->pool, to);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
desc_entry->description = apr_pstrdup(dcfg->desc_list->pool, desc);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *add_ignore(cmd_parms *cmd, void *d, const char *ext)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
push_item(((autoindex_config_rec *) d)->ign_list, 0, ext, cmd->path, NULL);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *add_opts(cmd_parms *cmd, void *d, int argc, char *const argv[])
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
char *w;
|
|
Packit |
90a5c9 |
apr_int32_t opts;
|
|
Packit |
90a5c9 |
apr_int32_t opts_add;
|
|
Packit |
90a5c9 |
apr_int32_t opts_remove;
|
|
Packit |
90a5c9 |
char action;
|
|
Packit |
90a5c9 |
autoindex_config_rec *d_cfg = (autoindex_config_rec *) d;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
opts = d_cfg->opts;
|
|
Packit |
90a5c9 |
opts_add = d_cfg->incremented_opts;
|
|
Packit |
90a5c9 |
opts_remove = d_cfg->decremented_opts;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (i = 0; i < argc; i++) {
|
|
Packit |
90a5c9 |
int option = 0;
|
|
Packit |
90a5c9 |
w = argv[i];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((*w == '+') || (*w == '-')) {
|
|
Packit |
90a5c9 |
action = *(w++);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
action = '\0';
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!strcasecmp(w, "FancyIndexing")) {
|
|
Packit |
90a5c9 |
option = FANCY_INDEXING;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "FoldersFirst")) {
|
|
Packit |
90a5c9 |
option = FOLDERS_FIRST;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "HTMLTable")) {
|
|
Packit |
90a5c9 |
option = TABLE_INDEXING;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "IconsAreLinks")) {
|
|
Packit |
90a5c9 |
option = ICONS_ARE_LINKS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "IgnoreCase")) {
|
|
Packit |
90a5c9 |
option = IGNORE_CASE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "IgnoreClient")) {
|
|
Packit |
90a5c9 |
option = IGNORE_CLIENT;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "ScanHTMLTitles")) {
|
|
Packit |
90a5c9 |
option = SCAN_HTML_TITLES;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "SuppressColumnSorting")) {
|
|
Packit |
90a5c9 |
option = SUPPRESS_COLSORT;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "SuppressDescription")) {
|
|
Packit |
90a5c9 |
option = SUPPRESS_DESC;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "SuppressHTMLPreamble")) {
|
|
Packit |
90a5c9 |
option = SUPPRESS_PREAMBLE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "SuppressIcon")) {
|
|
Packit |
90a5c9 |
option = SUPPRESS_ICON;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "SuppressLastModified")) {
|
|
Packit |
90a5c9 |
option = SUPPRESS_LAST_MOD;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "SuppressSize")) {
|
|
Packit |
90a5c9 |
option = SUPPRESS_SIZE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "SuppressRules")) {
|
|
Packit |
90a5c9 |
option = SUPPRESS_RULES;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "TrackModified")) {
|
|
Packit |
90a5c9 |
option = TRACK_MODIFIED;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "VersionSort")) {
|
|
Packit |
90a5c9 |
option = VERSION_SORT;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "XHTML")) {
|
|
Packit |
90a5c9 |
option = EMIT_XHTML;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "ShowForbidden")) {
|
|
Packit |
90a5c9 |
option = SHOW_FORBIDDEN;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "AddAltClass")) {
|
|
Packit |
90a5c9 |
option = ADDALTCLASS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "None")) {
|
|
Packit |
90a5c9 |
if (action != '\0') {
|
|
Packit |
90a5c9 |
return "Cannot combine '+' or '-' with 'None' keyword";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
opts = NO_OPTIONS;
|
|
Packit |
90a5c9 |
opts_add = 0;
|
|
Packit |
90a5c9 |
opts_remove = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "IconWidth")) {
|
|
Packit |
90a5c9 |
if (action != '-') {
|
|
Packit |
90a5c9 |
d_cfg->icon_width = DEFAULT_ICON_WIDTH;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
d_cfg->icon_width = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strncasecmp(w, "IconWidth=", 10)) {
|
|
Packit |
90a5c9 |
if (action == '-') {
|
|
Packit |
90a5c9 |
return "Cannot combine '-' with IconWidth=n";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
d_cfg->icon_width = atoi(&w[10]);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "IconHeight")) {
|
|
Packit |
90a5c9 |
if (action != '-') {
|
|
Packit |
90a5c9 |
d_cfg->icon_height = DEFAULT_ICON_HEIGHT;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
d_cfg->icon_height = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strncasecmp(w, "IconHeight=", 11)) {
|
|
Packit |
90a5c9 |
if (action == '-') {
|
|
Packit |
90a5c9 |
return "Cannot combine '-' with IconHeight=n";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
d_cfg->icon_height = atoi(&w[11]);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "NameWidth")) {
|
|
Packit |
90a5c9 |
if (action != '-') {
|
|
Packit |
90a5c9 |
return "NameWidth with no value may only appear as "
|
|
Packit |
90a5c9 |
"'-NameWidth'";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
d_cfg->name_width = DEFAULT_NAME_WIDTH;
|
|
Packit |
90a5c9 |
d_cfg->name_adjust = K_NOADJUST;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strncasecmp(w, "NameWidth=", 10)) {
|
|
Packit |
90a5c9 |
if (action == '-') {
|
|
Packit |
90a5c9 |
return "Cannot combine '-' with NameWidth=n";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (w[10] == '*') {
|
|
Packit |
90a5c9 |
d_cfg->name_adjust = K_ADJUST;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
int width = atoi(&w[10]);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (width && (width < 5)) {
|
|
Packit |
90a5c9 |
return "NameWidth value must be greater than 5";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
d_cfg->name_width = width;
|
|
Packit |
90a5c9 |
d_cfg->name_adjust = K_NOADJUST;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "DescriptionWidth")) {
|
|
Packit |
90a5c9 |
if (action != '-') {
|
|
Packit |
90a5c9 |
return "DescriptionWidth with no value may only appear as "
|
|
Packit |
90a5c9 |
"'-DescriptionWidth'";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
d_cfg->desc_width = DEFAULT_DESC_WIDTH;
|
|
Packit |
90a5c9 |
d_cfg->desc_adjust = K_NOADJUST;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strncasecmp(w, "DescriptionWidth=", 17)) {
|
|
Packit |
90a5c9 |
if (action == '-') {
|
|
Packit |
90a5c9 |
return "Cannot combine '-' with DescriptionWidth=n";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (w[17] == '*') {
|
|
Packit |
90a5c9 |
d_cfg->desc_adjust = K_ADJUST;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
int width = atoi(&w[17]);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (width && (width < 12)) {
|
|
Packit |
90a5c9 |
return "DescriptionWidth value must be greater than 12";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
d_cfg->desc_width = width;
|
|
Packit |
90a5c9 |
d_cfg->desc_adjust = K_NOADJUST;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strncasecmp(w, "Type=", 5)) {
|
|
Packit |
90a5c9 |
d_cfg->ctype = apr_pstrdup(cmd->pool, &w[5]);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strncasecmp(w, "Charset=", 8)) {
|
|
Packit |
90a5c9 |
d_cfg->charset = apr_pstrdup(cmd->pool, &w[8]);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(w, "UseOldDateFormat")) {
|
|
Packit |
90a5c9 |
d_cfg->datetime_format = "%d-%b-%Y %H:%M";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
return "Invalid directory indexing option";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (action == '\0') {
|
|
Packit |
90a5c9 |
opts |= option;
|
|
Packit |
90a5c9 |
opts_add = 0;
|
|
Packit |
90a5c9 |
opts_remove = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (action == '+') {
|
|
Packit |
90a5c9 |
opts_add |= option;
|
|
Packit |
90a5c9 |
opts_remove &= ~option;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
opts_remove |= option;
|
|
Packit |
90a5c9 |
opts_add &= ~option;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((opts & NO_OPTIONS) && (opts & ~NO_OPTIONS)) {
|
|
Packit |
90a5c9 |
return "Cannot combine other IndexOptions keywords with 'None'";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
d_cfg->incremented_opts = opts_add;
|
|
Packit |
90a5c9 |
d_cfg->decremented_opts = opts_remove;
|
|
Packit |
90a5c9 |
d_cfg->opts = opts;
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *set_default_order(cmd_parms *cmd, void *m,
|
|
Packit |
90a5c9 |
const char *direction, const char *key)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
autoindex_config_rec *d_cfg = (autoindex_config_rec *) m;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!strcasecmp(direction, "Ascending")) {
|
|
Packit |
90a5c9 |
d_cfg->default_direction = D_ASCENDING;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(direction, "Descending")) {
|
|
Packit |
90a5c9 |
d_cfg->default_direction = D_DESCENDING;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
return "First keyword must be 'Ascending' or 'Descending'";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!strcasecmp(key, "Name")) {
|
|
Packit |
90a5c9 |
d_cfg->default_keyid = K_NAME;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(key, "Date")) {
|
|
Packit |
90a5c9 |
d_cfg->default_keyid = K_LAST_MOD;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(key, "Size")) {
|
|
Packit |
90a5c9 |
d_cfg->default_keyid = K_SIZE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strcasecmp(key, "Description")) {
|
|
Packit |
90a5c9 |
d_cfg->default_keyid = K_DESC;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
return "Second keyword must be 'Name', 'Date', 'Size', or "
|
|
Packit |
90a5c9 |
"'Description'";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define DIR_CMD_PERMS OR_INDEXES
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const command_rec autoindex_cmds[] =
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
AP_INIT_ITERATE2("AddIcon", add_icon, BY_PATH, DIR_CMD_PERMS,
|
|
Packit |
90a5c9 |
"an icon URL followed by one or more filenames"),
|
|
Packit |
90a5c9 |
AP_INIT_ITERATE2("AddIconByType", add_icon, BY_TYPE, DIR_CMD_PERMS,
|
|
Packit |
90a5c9 |
"an icon URL followed by one or more MIME types"),
|
|
Packit |
90a5c9 |
AP_INIT_ITERATE2("AddIconByEncoding", add_icon, BY_ENCODING, DIR_CMD_PERMS,
|
|
Packit |
90a5c9 |
"an icon URL followed by one or more content encodings"),
|
|
Packit |
90a5c9 |
AP_INIT_ITERATE2("AddAlt", add_alt, BY_PATH, DIR_CMD_PERMS,
|
|
Packit |
90a5c9 |
"alternate descriptive text followed by one or more "
|
|
Packit |
90a5c9 |
"filenames"),
|
|
Packit |
90a5c9 |
AP_INIT_ITERATE2("AddAltByType", add_alt, BY_TYPE, DIR_CMD_PERMS,
|
|
Packit |
90a5c9 |
"alternate descriptive text followed by one or more MIME "
|
|
Packit |
90a5c9 |
"types"),
|
|
Packit |
90a5c9 |
AP_INIT_ITERATE2("AddAltByEncoding", add_alt, BY_ENCODING, DIR_CMD_PERMS,
|
|
Packit |
90a5c9 |
"alternate descriptive text followed by one or more "
|
|
Packit |
90a5c9 |
"content encodings"),
|
|
Packit |
90a5c9 |
AP_INIT_TAKE_ARGV("IndexOptions", add_opts, NULL, DIR_CMD_PERMS,
|
|
Packit |
90a5c9 |
"one or more index options [+|-][]"),
|
|
Packit |
90a5c9 |
AP_INIT_TAKE2("IndexOrderDefault", set_default_order, NULL, DIR_CMD_PERMS,
|
|
Packit |
90a5c9 |
"{Ascending,Descending} {Name,Size,Description,Date}"),
|
|
Packit |
90a5c9 |
AP_INIT_ITERATE("IndexIgnore", add_ignore, NULL, DIR_CMD_PERMS,
|
|
Packit |
90a5c9 |
"one or more file extensions"),
|
|
Packit |
90a5c9 |
AP_INIT_FLAG("IndexIgnoreReset", ap_set_flag_slot,
|
|
Packit |
90a5c9 |
(void *)APR_OFFSETOF(autoindex_config_rec, ign_noinherit),
|
|
Packit |
90a5c9 |
DIR_CMD_PERMS,
|
|
Packit |
90a5c9 |
"Reset the inherited list of IndexIgnore filenames"),
|
|
Packit |
90a5c9 |
AP_INIT_ITERATE2("AddDescription", add_desc, BY_PATH, DIR_CMD_PERMS,
|
|
Packit |
90a5c9 |
"Descriptive text followed by one or more filenames"),
|
|
Packit |
90a5c9 |
AP_INIT_TAKE1("HeaderName", ap_set_string_slot,
|
|
Packit |
90a5c9 |
(void *)APR_OFFSETOF(autoindex_config_rec, header),
|
|
Packit |
90a5c9 |
DIR_CMD_PERMS, "a filename"),
|
|
Packit |
90a5c9 |
AP_INIT_TAKE1("ReadmeName", ap_set_string_slot,
|
|
Packit |
90a5c9 |
(void *)APR_OFFSETOF(autoindex_config_rec, readme),
|
|
Packit |
90a5c9 |
DIR_CMD_PERMS, "a filename"),
|
|
Packit |
90a5c9 |
AP_INIT_RAW_ARGS("FancyIndexing", ap_set_deprecated, NULL, OR_ALL,
|
|
Packit |
90a5c9 |
"The FancyIndexing directive is no longer supported. "
|
|
Packit |
90a5c9 |
"Use IndexOptions FancyIndexing."),
|
|
Packit |
90a5c9 |
AP_INIT_TAKE1("DefaultIcon", ap_set_string_slot,
|
|
Packit |
90a5c9 |
(void *)APR_OFFSETOF(autoindex_config_rec, default_icon),
|
|
Packit |
90a5c9 |
DIR_CMD_PERMS, "an icon URL"),
|
|
Packit |
90a5c9 |
AP_INIT_TAKE1("IndexStyleSheet", ap_set_string_slot,
|
|
Packit |
90a5c9 |
(void *)APR_OFFSETOF(autoindex_config_rec, style_sheet),
|
|
Packit |
90a5c9 |
DIR_CMD_PERMS, "URL to style sheet"),
|
|
Packit |
90a5c9 |
AP_INIT_TAKE1("IndexHeadInsert", ap_set_string_slot,
|
|
Packit |
90a5c9 |
(void *)APR_OFFSETOF(autoindex_config_rec, head_insert),
|
|
Packit |
90a5c9 |
DIR_CMD_PERMS, "String to insert in HTML HEAD section"),
|
|
Packit |
90a5c9 |
{NULL}
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void *create_autoindex_config(apr_pool_t *p, char *dummy)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
autoindex_config_rec *new =
|
|
Packit |
90a5c9 |
(autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
new->icon_width = 0;
|
|
Packit |
90a5c9 |
new->icon_height = 0;
|
|
Packit |
90a5c9 |
new->name_width = DEFAULT_NAME_WIDTH;
|
|
Packit |
90a5c9 |
new->name_adjust = K_UNSET;
|
|
Packit |
90a5c9 |
new->desc_width = DEFAULT_DESC_WIDTH;
|
|
Packit |
90a5c9 |
new->desc_adjust = K_UNSET;
|
|
Packit |
90a5c9 |
new->icon_list = apr_array_make(p, 4, sizeof(struct item));
|
|
Packit |
90a5c9 |
new->alt_list = apr_array_make(p, 4, sizeof(struct item));
|
|
Packit |
90a5c9 |
new->desc_list = apr_array_make(p, 4, sizeof(ai_desc_t));
|
|
Packit |
90a5c9 |
new->ign_list = apr_array_make(p, 4, sizeof(struct item));
|
|
Packit |
90a5c9 |
new->opts = OPTION_UNSET;
|
|
Packit |
90a5c9 |
new->incremented_opts = 0;
|
|
Packit |
90a5c9 |
new->decremented_opts = 0;
|
|
Packit |
90a5c9 |
new->default_keyid = '\0';
|
|
Packit |
90a5c9 |
new->default_direction = '\0';
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return (void *) new;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void *merge_autoindex_configs(apr_pool_t *p, void *basev, void *addv)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
autoindex_config_rec *new;
|
|
Packit |
90a5c9 |
autoindex_config_rec *base = (autoindex_config_rec *) basev;
|
|
Packit |
90a5c9 |
autoindex_config_rec *add = (autoindex_config_rec *) addv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
new = (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));
|
|
Packit |
90a5c9 |
new->default_icon = add->default_icon ? add->default_icon
|
|
Packit |
90a5c9 |
: base->default_icon;
|
|
Packit |
90a5c9 |
new->style_sheet = add->style_sheet ? add->style_sheet
|
|
Packit |
90a5c9 |
: base->style_sheet;
|
|
Packit |
90a5c9 |
new->head_insert = add->head_insert ? add->head_insert
|
|
Packit |
90a5c9 |
: base->head_insert;
|
|
Packit |
90a5c9 |
new->header = add->header ? add->header
|
|
Packit |
90a5c9 |
: base->header;
|
|
Packit |
90a5c9 |
new->readme = add->readme ? add->readme
|
|
Packit |
90a5c9 |
: base->readme;
|
|
Packit |
90a5c9 |
new->icon_height = add->icon_height ? add->icon_height : base->icon_height;
|
|
Packit |
90a5c9 |
new->icon_width = add->icon_width ? add->icon_width : base->icon_width;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
new->ctype = add->ctype ? add->ctype : base->ctype;
|
|
Packit |
90a5c9 |
new->charset = add->charset ? add->charset : base->charset;
|
|
Packit |
90a5c9 |
new->datetime_format = add->datetime_format ? add->datetime_format : base->datetime_format;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
new->alt_list = apr_array_append(p, add->alt_list, base->alt_list);
|
|
Packit |
90a5c9 |
new->desc_list = apr_array_append(p, add->desc_list, base->desc_list);
|
|
Packit |
90a5c9 |
new->icon_list = apr_array_append(p, add->icon_list, base->icon_list);
|
|
Packit |
90a5c9 |
new->ign_list = add->ign_noinherit ? add->ign_list : apr_array_append(p, add->ign_list, base->ign_list);
|
|
Packit |
90a5c9 |
if (add->opts == NO_OPTIONS) {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If the current directory explicitly says 'no options' then we also
|
|
Packit |
90a5c9 |
* clear any incremental mods from being inheritable further down.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
new->opts = NO_OPTIONS;
|
|
Packit |
90a5c9 |
new->incremented_opts = 0;
|
|
Packit |
90a5c9 |
new->decremented_opts = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If there were any nonincremental options selected for
|
|
Packit |
90a5c9 |
* this directory, they dominate and we don't inherit *anything.*
|
|
Packit |
90a5c9 |
* Contrariwise, we *do* inherit if the only settings here are
|
|
Packit |
90a5c9 |
* incremental ones.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (add->opts == OPTION_UNSET) {
|
|
Packit |
90a5c9 |
new->incremented_opts = (base->incremented_opts
|
|
Packit |
90a5c9 |
| add->incremented_opts)
|
|
Packit |
90a5c9 |
& ~add->decremented_opts;
|
|
Packit |
90a5c9 |
new->decremented_opts = (base->decremented_opts
|
|
Packit |
90a5c9 |
| add->decremented_opts);
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* We may have incremental settings, so make sure we don't
|
|
Packit |
90a5c9 |
* inadvertently inherit an IndexOptions None from above.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
new->opts = (base->opts & ~NO_OPTIONS);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* There are local nonincremental settings, which clear
|
|
Packit |
90a5c9 |
* all inheritance from above. They *are* the new base settings.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
new->opts = add->opts;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* We're guaranteed that there'll be no overlap between
|
|
Packit |
90a5c9 |
* the add-options and the remove-options.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
new->opts |= new->incremented_opts;
|
|
Packit |
90a5c9 |
new->opts &= ~new->decremented_opts;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Inherit the NameWidth settings if there aren't any specific to
|
|
Packit |
90a5c9 |
* the new location; otherwise we'll end up using the defaults set in the
|
|
Packit |
90a5c9 |
* config-rec creation routine.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (add->name_adjust == K_UNSET) {
|
|
Packit |
90a5c9 |
new->name_width = base->name_width;
|
|
Packit |
90a5c9 |
new->name_adjust = base->name_adjust;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
new->name_width = add->name_width;
|
|
Packit |
90a5c9 |
new->name_adjust = add->name_adjust;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Likewise for DescriptionWidth.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (add->desc_adjust == K_UNSET) {
|
|
Packit |
90a5c9 |
new->desc_width = base->desc_width;
|
|
Packit |
90a5c9 |
new->desc_adjust = base->desc_adjust;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
new->desc_width = add->desc_width;
|
|
Packit |
90a5c9 |
new->desc_adjust = add->desc_adjust;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
new->default_keyid = add->default_keyid ? add->default_keyid
|
|
Packit |
90a5c9 |
: base->default_keyid;
|
|
Packit |
90a5c9 |
new->default_direction = add->default_direction ? add->default_direction
|
|
Packit |
90a5c9 |
: base->default_direction;
|
|
Packit |
90a5c9 |
return new;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/****************************************************************
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Looking things up in config entries...
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Structure used to hold entries when we're actually building an index */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
struct ent {
|
|
Packit |
90a5c9 |
char *name;
|
|
Packit |
90a5c9 |
char *icon;
|
|
Packit |
90a5c9 |
char *alt;
|
|
Packit |
90a5c9 |
char *desc;
|
|
Packit |
90a5c9 |
apr_off_t size;
|
|
Packit |
90a5c9 |
apr_time_t lm;
|
|
Packit |
90a5c9 |
struct ent *next;
|
|
Packit |
90a5c9 |
int ascending, ignore_case, version_sort;
|
|
Packit |
90a5c9 |
char key;
|
|
Packit |
90a5c9 |
int isdir;
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static char *find_item(const char *content_type, const char *content_encoding,
|
|
Packit |
90a5c9 |
char *path, apr_array_header_t *list, int path_only)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
struct item *items = (struct item *) list->elts;
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (i = 0; i < list->nelts; ++i) {
|
|
Packit |
90a5c9 |
struct item *p = &items[i];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Special cased for ^^DIRECTORY^^ and ^^BLANKICON^^ */
|
|
Packit |
90a5c9 |
if ((path[0] == '^') || (!ap_strcmp_match(path, p->apply_path))) {
|
|
Packit |
90a5c9 |
if (!*(p->apply_to)) {
|
|
Packit |
90a5c9 |
return p->data;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (p->type == BY_PATH || path[0] == '^') {
|
|
Packit |
90a5c9 |
if (!ap_strcmp_match(path, p->apply_to)) {
|
|
Packit |
90a5c9 |
return p->data;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!path_only) {
|
|
Packit |
90a5c9 |
if (!content_encoding) {
|
|
Packit |
90a5c9 |
if (p->type == BY_TYPE) {
|
|
Packit |
90a5c9 |
if (content_type
|
|
Packit |
90a5c9 |
&& !ap_strcasecmp_match(content_type,
|
|
Packit |
90a5c9 |
p->apply_to)) {
|
|
Packit |
90a5c9 |
return p->data;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
if (p->type == BY_ENCODING) {
|
|
Packit |
90a5c9 |
if (!ap_strcasecmp_match(content_encoding,
|
|
Packit |
90a5c9 |
p->apply_to)) {
|
|
Packit |
90a5c9 |
return p->data;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static char *find_item_by_request(request_rec *r, apr_array_header_t *list, int path_only)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
return find_item(ap_field_noparam(r->pool, r->content_type),
|
|
Packit |
90a5c9 |
r->content_encoding, r->filename, list, path_only);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define find_icon(d,p,t) find_item_by_request(p,d->icon_list,t)
|
|
Packit |
90a5c9 |
#define find_alt(d,p,t) find_item_by_request(p,d->alt_list,t)
|
|
Packit |
90a5c9 |
#define find_default_icon(d,n) find_item(NULL, NULL, n, d->icon_list, 1)
|
|
Packit |
90a5c9 |
#define find_default_alt(d,n) find_item(NULL, NULL, n, d->alt_list, 1)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Look through the list of pattern/description pairs and return the first one
|
|
Packit |
90a5c9 |
* if any) that matches the filename in the request. If multiple patterns
|
|
Packit |
90a5c9 |
* match, only the first one is used; since the order in the array is the
|
|
Packit |
90a5c9 |
* same as the order in which directives were processed, earlier matching
|
|
Packit |
90a5c9 |
* directives will dominate.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef CASE_BLIND_FILESYSTEM
|
|
Packit |
90a5c9 |
#define MATCH_FLAGS APR_FNM_CASE_BLIND
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
#define MATCH_FLAGS 0
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static char *find_desc(autoindex_config_rec *dcfg, const char *filename_full)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
ai_desc_t *list = (ai_desc_t *) dcfg->desc_list->elts;
|
|
Packit |
90a5c9 |
const char *filename_only;
|
|
Packit |
90a5c9 |
const char *filename;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If the filename includes a path, extract just the name itself
|
|
Packit |
90a5c9 |
* for the simple matches.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((filename_only = ap_strrchr_c(filename_full, '/')) == NULL) {
|
|
Packit |
90a5c9 |
filename_only = filename_full;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
filename_only++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
for (i = 0; i < dcfg->desc_list->nelts; ++i) {
|
|
Packit |
90a5c9 |
ai_desc_t *tuple = &list[i];
|
|
Packit |
90a5c9 |
int found;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Only use the full-path filename if the pattern contains '/'s.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
filename = (tuple->full_path) ? filename_full : filename_only;
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Make the comparison using the cheapest method; only do
|
|
Packit |
90a5c9 |
* wildcard checking if we must.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (tuple->wildcards) {
|
|
Packit |
90a5c9 |
found = (apr_fnmatch(tuple->pattern, filename, MATCH_FLAGS) == 0);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
found = (ap_strstr_c(filename, tuple->pattern) != NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (found) {
|
|
Packit |
90a5c9 |
return tuple->description;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int ignore_entry(autoindex_config_rec *d, char *path)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_array_header_t *list = d->ign_list;
|
|
Packit |
90a5c9 |
struct item *items = (struct item *) list->elts;
|
|
Packit |
90a5c9 |
char *tt;
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((tt = strrchr(path, '/')) == NULL) {
|
|
Packit |
90a5c9 |
tt = path;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
tt++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (i = 0; i < list->nelts; ++i) {
|
|
Packit |
90a5c9 |
struct item *p = &items[i];
|
|
Packit |
90a5c9 |
char *ap;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((ap = strrchr(p->apply_to, '/')) == NULL) {
|
|
Packit |
90a5c9 |
ap = p->apply_to;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifndef CASE_BLIND_FILESYSTEM
|
|
Packit |
90a5c9 |
if (!ap_strcmp_match(path, p->apply_path)
|
|
Packit |
90a5c9 |
&& !ap_strcmp_match(tt, ap)) {
|
|
Packit |
90a5c9 |
return 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#else /* !CASE_BLIND_FILESYSTEM */
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* On some platforms, the match must be case-blind. This is really
|
|
Packit |
90a5c9 |
* a factor of the filesystem involved, but we can't detect that
|
|
Packit |
90a5c9 |
* reliably - so we have to granularise at the OS level.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!ap_strcasecmp_match(path, p->apply_path)
|
|
Packit |
90a5c9 |
&& !ap_strcasecmp_match(tt, ap)) {
|
|
Packit |
90a5c9 |
return 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif /* !CASE_BLIND_FILESYSTEM */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*****************************************************************
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Actually generating output
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Elements of the emitted document:
|
|
Packit |
90a5c9 |
* Preamble
|
|
Packit |
90a5c9 |
* Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
|
|
Packit |
90a5c9 |
* succeeds for the (content_type == text/html) header file.
|
|
Packit |
90a5c9 |
* Header file
|
|
Packit |
90a5c9 |
* Emitted if found (and able).
|
|
Packit |
90a5c9 |
* H1 tag line
|
|
Packit |
90a5c9 |
* Emitted if a header file is NOT emitted.
|
|
Packit |
90a5c9 |
* Directory stuff
|
|
Packit |
90a5c9 |
* Always emitted.
|
|
Packit |
90a5c9 |
* HR
|
|
Packit |
90a5c9 |
* Emitted if FANCY_INDEXING is set.
|
|
Packit |
90a5c9 |
* Readme file
|
|
Packit |
90a5c9 |
* Emitted if found (and able).
|
|
Packit |
90a5c9 |
* ServerSig
|
|
Packit |
90a5c9 |
* Emitted if ServerSignature is not Off AND a readme file
|
|
Packit |
90a5c9 |
* is NOT emitted.
|
|
Packit |
90a5c9 |
* Postamble
|
|
Packit |
90a5c9 |
* Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req
|
|
Packit |
90a5c9 |
* succeeds for the (content_type == text/html) readme file.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* emit a plain text file
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static void do_emit_plain(request_rec *r, apr_file_t *f)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char buf[AP_IOBUFSIZE + 1];
|
|
Packit |
90a5c9 |
int ch;
|
|
Packit |
90a5c9 |
apr_size_t i, c, n;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_rputs("\n", r);
|
|
Packit |
90a5c9 |
while (!apr_file_eof(f)) {
|
|
Packit |
90a5c9 |
do {
|
|
Packit |
90a5c9 |
n = sizeof(char) * AP_IOBUFSIZE;
|
|
Packit |
90a5c9 |
rv = apr_file_read(f, buf, &n);
|
|
Packit |
90a5c9 |
} while (APR_STATUS_IS_EINTR(rv));
|
|
Packit |
90a5c9 |
if (n == 0 || rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
/* ###: better error here? */
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
buf[n] = '\0';
|
|
Packit |
90a5c9 |
c = 0;
|
|
Packit |
90a5c9 |
while (c < n) {
|
|
Packit |
90a5c9 |
for (i = c; i < n; i++) {
|
|
Packit |
90a5c9 |
if (buf[i] == '<' || buf[i] == '>' || buf[i] == '&') {
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ch = buf[i];
|
|
Packit |
90a5c9 |
buf[i] = '\0';
|
|
Packit |
90a5c9 |
ap_rputs(&buf[c], r);
|
|
Packit |
90a5c9 |
if (ch == '<') {
|
|
Packit |
90a5c9 |
ap_rputs("<", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (ch == '>') {
|
|
Packit |
90a5c9 |
ap_rputs(">", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (ch == '&') {
|
|
Packit |
90a5c9 |
ap_rputs("&", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
c = i + 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs("\n", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Handle the preamble through the H1 tag line, inclusive. Locate
|
|
Packit |
90a5c9 |
* the file with a subrequests. Process text/html documents by actually
|
|
Packit |
90a5c9 |
* running the subrequest; text/xxx documents get copied verbatim,
|
|
Packit |
90a5c9 |
* and any other content type is ignored. This means that a non-text
|
|
Packit |
90a5c9 |
* document (such as HEADER.gif) might get multiviewed as the result
|
|
Packit |
90a5c9 |
* instead of a text document, meaning nothing will be displayed, but
|
|
Packit |
90a5c9 |
* oh well.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static void emit_head(request_rec *r, char *header_fname, int suppress_amble,
|
|
Packit |
90a5c9 |
int emit_xhtml, char *title)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
autoindex_config_rec *d;
|
|
Packit |
90a5c9 |
apr_table_t *hdrs = r->headers_in;
|
|
Packit |
90a5c9 |
apr_file_t *f = NULL;
|
|
Packit |
90a5c9 |
request_rec *rr = NULL;
|
|
Packit |
90a5c9 |
int emit_amble = 1;
|
|
Packit |
90a5c9 |
int emit_H1 = 1;
|
|
Packit |
90a5c9 |
const char *r_accept;
|
|
Packit |
90a5c9 |
const char *r_accept_enc;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If there's a header file, send a subrequest to look for it. If it's
|
|
Packit |
90a5c9 |
* found and html do the subrequest, otherwise handle it
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
r_accept = apr_table_get(hdrs, "Accept");
|
|
Packit |
90a5c9 |
r_accept_enc = apr_table_get(hdrs, "Accept-Encoding");
|
|
Packit |
90a5c9 |
apr_table_setn(hdrs, "Accept", "text/html, text/plain");
|
|
Packit |
90a5c9 |
apr_table_unset(hdrs, "Accept-Encoding");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((header_fname != NULL) && r->args) {
|
|
Packit |
90a5c9 |
header_fname = apr_pstrcat(r->pool, header_fname, "?", r->args, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((header_fname != NULL)
|
|
Packit |
90a5c9 |
&& (rr = ap_sub_req_lookup_uri(header_fname, r, r->output_filters))
|
|
Packit |
90a5c9 |
&& (rr->status == HTTP_OK)
|
|
Packit |
90a5c9 |
&& (rr->filename != NULL)
|
|
Packit |
90a5c9 |
&& (rr->finfo.filetype == APR_REG)) {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Check for the two specific cases we allow: text/html and
|
|
Packit |
90a5c9 |
* text/anything-else. The former is allowed to be processed for
|
|
Packit |
90a5c9 |
* SSIs.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (rr->content_type != NULL) {
|
|
Packit |
90a5c9 |
if (response_is_html(rr)) {
|
|
Packit |
90a5c9 |
ap_filter_t *f;
|
|
Packit |
90a5c9 |
/* Hope everything will work... */
|
|
Packit |
90a5c9 |
emit_amble = 0;
|
|
Packit |
90a5c9 |
emit_H1 = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (! suppress_amble) {
|
|
Packit |
90a5c9 |
emit_preamble(r, emit_xhtml, title);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* This is a hack, but I can't find any better way to do this.
|
|
Packit |
90a5c9 |
* The problem is that we have already created the sub-request,
|
|
Packit |
90a5c9 |
* but we just inserted the OLD_WRITE filter, and the
|
|
Packit |
90a5c9 |
* sub-request needs to pass its data through the OLD_WRITE
|
|
Packit |
90a5c9 |
* filter, or things go horribly wrong (missing data, data in
|
|
Packit |
90a5c9 |
* the wrong order, etc). To fix it, if you create a
|
|
Packit |
90a5c9 |
* sub-request and then insert the OLD_WRITE filter before you
|
|
Packit |
90a5c9 |
* run the request, you need to make sure that the sub-request
|
|
Packit |
90a5c9 |
* data goes through the OLD_WRITE filter. Just steal this
|
|
Packit |
90a5c9 |
* code. The long-term solution is to remove the ap_r*
|
|
Packit |
90a5c9 |
* functions.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
for (f=rr->output_filters;
|
|
Packit |
90a5c9 |
f->frec != ap_subreq_core_filter_handle; f = f->next);
|
|
Packit |
90a5c9 |
f->next = r->output_filters;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If there's a problem running the subrequest, display the
|
|
Packit |
90a5c9 |
* preamble if we didn't do it before -- the header file
|
|
Packit |
90a5c9 |
* didn't get displayed.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (ap_run_sub_req(rr) != OK) {
|
|
Packit |
90a5c9 |
/* It didn't work */
|
|
Packit |
90a5c9 |
emit_amble = suppress_amble;
|
|
Packit |
90a5c9 |
emit_H1 = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strncasecmp("text/", rr->content_type, 5)) {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If we can open the file, prefix it with the preamble
|
|
Packit |
90a5c9 |
* regardless; since we'll be sending a block around
|
|
Packit |
90a5c9 |
* the file's contents, any HTML header it had won't end up
|
|
Packit |
90a5c9 |
* where it belongs.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (apr_file_open(&f, rr->filename, APR_READ,
|
|
Packit |
90a5c9 |
APR_OS_DEFAULT, r->pool) == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
emit_preamble(r, emit_xhtml, title);
|
|
Packit |
90a5c9 |
emit_amble = 0;
|
|
Packit |
90a5c9 |
do_emit_plain(r, f);
|
|
Packit |
90a5c9 |
apr_file_close(f);
|
|
Packit |
90a5c9 |
emit_H1 = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (r_accept) {
|
|
Packit |
90a5c9 |
apr_table_setn(hdrs, "Accept", r_accept);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
apr_table_unset(hdrs, "Accept");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (r_accept_enc) {
|
|
Packit |
90a5c9 |
apr_table_setn(hdrs, "Accept-Encoding", r_accept_enc);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (emit_amble) {
|
|
Packit |
90a5c9 |
emit_preamble(r, emit_xhtml, title);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config, &autoindex_module);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (emit_H1) {
|
|
Packit |
90a5c9 |
if (d->style_sheet != NULL) {
|
|
Packit |
90a5c9 |
/* Insert style id if stylesheet used */
|
|
Packit |
90a5c9 |
ap_rvputs(r, " Index of ", title, "\n", NULL);
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "Index of ", title, "\n", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (rr != NULL) {
|
|
Packit |
90a5c9 |
ap_destroy_sub_req(rr);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Handle the Readme file through the postamble, inclusive. Locate
|
|
Packit |
90a5c9 |
* the file with a subrequests. Process text/html documents by actually
|
|
Packit |
90a5c9 |
* running the subrequest; text/xxx documents get copied verbatim,
|
|
Packit |
90a5c9 |
* and any other content type is ignored. This means that a non-text
|
|
Packit |
90a5c9 |
* document (such as FOOTER.gif) might get multiviewed as the result
|
|
Packit |
90a5c9 |
* instead of a text document, meaning nothing will be displayed, but
|
|
Packit |
90a5c9 |
* oh well.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static void emit_tail(request_rec *r, char *readme_fname, int suppress_amble)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_file_t *f = NULL;
|
|
Packit |
90a5c9 |
request_rec *rr = NULL;
|
|
Packit |
90a5c9 |
int suppress_post = 0;
|
|
Packit |
90a5c9 |
int suppress_sig = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If there's a readme file, send a subrequest to look for it. If it's
|
|
Packit |
90a5c9 |
* found and a text file, handle it -- otherwise fall through and
|
|
Packit |
90a5c9 |
* pretend there's nothing there.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((readme_fname != NULL)
|
|
Packit |
90a5c9 |
&& (rr = ap_sub_req_lookup_uri(readme_fname, r, r->output_filters))
|
|
Packit |
90a5c9 |
&& (rr->status == HTTP_OK)
|
|
Packit |
90a5c9 |
&& (rr->filename != NULL)
|
|
Packit |
90a5c9 |
&& rr->finfo.filetype == APR_REG) {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Check for the two specific cases we allow: text/html and
|
|
Packit |
90a5c9 |
* text/anything-else. The former is allowed to be processed for
|
|
Packit |
90a5c9 |
* SSIs.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (rr->content_type != NULL) {
|
|
Packit |
90a5c9 |
if (response_is_html(rr)) {
|
|
Packit |
90a5c9 |
ap_filter_t *f;
|
|
Packit |
90a5c9 |
for (f=rr->output_filters;
|
|
Packit |
90a5c9 |
f->frec != ap_subreq_core_filter_handle; f = f->next);
|
|
Packit |
90a5c9 |
f->next = r->output_filters;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (ap_run_sub_req(rr) == OK) {
|
|
Packit |
90a5c9 |
/* worked... */
|
|
Packit |
90a5c9 |
suppress_sig = 1;
|
|
Packit |
90a5c9 |
suppress_post = suppress_amble;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!strncasecmp("text/", rr->content_type, 5)) {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If we can open the file, suppress the signature.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (apr_file_open(&f, rr->filename, APR_READ,
|
|
Packit |
90a5c9 |
APR_OS_DEFAULT, r->pool) == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
do_emit_plain(r, f);
|
|
Packit |
90a5c9 |
apr_file_close(f);
|
|
Packit |
90a5c9 |
suppress_sig = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!suppress_sig) {
|
|
Packit |
90a5c9 |
ap_rputs(ap_psignature("", r), r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!suppress_post) {
|
|
Packit |
90a5c9 |
ap_rputs("</body></html>\n", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (rr != NULL) {
|
|
Packit |
90a5c9 |
ap_destroy_sub_req(rr);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static char *find_title(request_rec *r)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char titlebuf[MAX_STRING_LEN], *find = "<title>";
|
|
Packit |
90a5c9 |
apr_file_t *thefile = NULL;
|
|
Packit |
90a5c9 |
int x, y, p;
|
|
Packit |
90a5c9 |
apr_size_t n;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (r->status != HTTP_OK) {
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((r->content_type != NULL)
|
|
Packit |
90a5c9 |
&& (response_is_html(r)
|
|
Packit |
90a5c9 |
|| !strcmp(r->content_type, INCLUDES_MAGIC_TYPE))
|
|
Packit |
90a5c9 |
&& !r->content_encoding) {
|
|
Packit |
90a5c9 |
if (apr_file_open(&thefile, r->filename, APR_READ,
|
|
Packit |
90a5c9 |
APR_OS_DEFAULT, r->pool) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
n = sizeof(char) * (MAX_STRING_LEN - 1);
|
|
Packit |
90a5c9 |
apr_file_read(thefile, titlebuf, &n);
|
|
Packit |
90a5c9 |
if (n == 0) {
|
|
Packit |
90a5c9 |
apr_file_close(thefile);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
titlebuf[n] = '\0';
|
|
Packit |
90a5c9 |
for (x = 0, p = 0; titlebuf[x]; x++) {
|
|
Packit |
90a5c9 |
if (apr_tolower(titlebuf[x]) == find[p]) {
|
|
Packit |
90a5c9 |
if (!find[++p]) {
|
|
Packit |
90a5c9 |
if ((p = ap_ind(&titlebuf[++x], '<')) != -1) {
|
|
Packit |
90a5c9 |
titlebuf[x + p] = '\0';
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* Scan for line breaks for Tanmoy's secretary */
|
|
Packit |
90a5c9 |
for (y = x; titlebuf[y]; y++) {
|
|
Packit |
90a5c9 |
if ((titlebuf[y] == CR) || (titlebuf[y] == LF)) {
|
|
Packit |
90a5c9 |
if (y == x) {
|
|
Packit |
90a5c9 |
x++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
titlebuf[y] = ' ';
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
apr_file_close(thefile);
|
|
Packit |
90a5c9 |
return apr_pstrdup(r->pool, &titlebuf[x]);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
p = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
apr_file_close(thefile);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static struct ent *make_parent_entry(apr_int32_t autoindex_opts,
|
|
Packit |
90a5c9 |
autoindex_config_rec *d,
|
|
Packit |
90a5c9 |
request_rec *r, char keyid,
|
|
Packit |
90a5c9 |
char direction)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
struct ent *p = (struct ent *) apr_pcalloc(r->pool, sizeof(struct ent));
|
|
Packit |
90a5c9 |
char *testpath;
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* p->name is now the true parent URI.
|
|
Packit |
90a5c9 |
* testpath is a crafted lie, so that the syntax '/some/..'
|
|
Packit |
90a5c9 |
* (or simply '..')be used to describe 'up' from '/some/'
|
|
Packit |
90a5c9 |
* when processeing IndexIgnore, and Icon|Alt|Desc configs.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* The output has always been to the parent. Don't make ourself
|
|
Packit |
90a5c9 |
* our own parent (worthless cyclical reference).
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!(p->name = ap_make_full_path(r->pool, r->uri, "../"))) {
|
|
Packit |
90a5c9 |
return (NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_getparents(p->name);
|
|
Packit |
90a5c9 |
if (!*p->name) {
|
|
Packit |
90a5c9 |
return (NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* IndexIgnore has always compared "/thispath/.." */
|
|
Packit |
90a5c9 |
testpath = ap_make_full_path(r->pool, r->filename, "..");
|
|
Packit |
90a5c9 |
if (ignore_entry(d, testpath)) {
|
|
Packit |
90a5c9 |
return (NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
p->size = -1;
|
|
Packit |
90a5c9 |
p->lm = -1;
|
|
Packit |
90a5c9 |
p->key = apr_toupper(keyid);
|
|
Packit |
90a5c9 |
p->ascending = (apr_toupper(direction) == D_ASCENDING);
|
|
Packit |
90a5c9 |
p->version_sort = autoindex_opts & VERSION_SORT;
|
|
Packit |
90a5c9 |
if (autoindex_opts & FANCY_INDEXING) {
|
|
Packit |
90a5c9 |
if (!(p->icon = find_default_icon(d, testpath))) {
|
|
Packit |
90a5c9 |
p->icon = find_default_icon(d, "^^DIRECTORY^^");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!(p->alt = find_default_alt(d, testpath))) {
|
|
Packit |
90a5c9 |
if (!(p->alt = find_default_alt(d, "^^DIRECTORY^^"))) {
|
|
Packit |
90a5c9 |
/* Special alt text for parent dir to distinguish it from other directories
|
|
Packit |
90a5c9 |
this is essential when trying to style this dir entry via AddAltClass */
|
|
Packit |
90a5c9 |
p->alt = "PARENTDIR";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
p->desc = find_desc(d, testpath);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return p;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static struct ent *make_autoindex_entry(const apr_finfo_t *dirent,
|
|
Packit |
90a5c9 |
int autoindex_opts,
|
|
Packit |
90a5c9 |
autoindex_config_rec *d,
|
|
Packit |
90a5c9 |
request_rec *r, char keyid,
|
|
Packit |
90a5c9 |
char direction,
|
|
Packit |
90a5c9 |
const char *pattern)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
request_rec *rr;
|
|
Packit |
90a5c9 |
struct ent *p;
|
|
Packit |
90a5c9 |
int show_forbidden = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Dot is ignored, Parent is handled by make_parent_entry() */
|
|
Packit |
90a5c9 |
if ((dirent->name[0] == '.') && (!dirent->name[1]
|
|
Packit |
90a5c9 |
|| ((dirent->name[1] == '.') && !dirent->name[2])))
|
|
Packit |
90a5c9 |
return (NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* On some platforms, the match must be case-blind. This is really
|
|
Packit |
90a5c9 |
* a factor of the filesystem involved, but we can't detect that
|
|
Packit |
90a5c9 |
* reliably - so we have to granularise at the OS level.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (pattern && (apr_fnmatch(pattern, dirent->name,
|
|
Packit |
90a5c9 |
APR_FNM_NOESCAPE | APR_FNM_PERIOD
|
|
Packit |
90a5c9 |
#ifdef CASE_BLIND_FILESYSTEM
|
|
Packit |
90a5c9 |
| APR_FNM_CASE_BLIND
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
)
|
|
Packit |
90a5c9 |
!= APR_SUCCESS)) {
|
|
Packit |
90a5c9 |
return (NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (ignore_entry(d, ap_make_full_path(r->pool,
|
|
Packit |
90a5c9 |
r->filename, dirent->name))) {
|
|
Packit |
90a5c9 |
return (NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!(rr = ap_sub_req_lookup_dirent(dirent, r, AP_SUBREQ_NO_ARGS, NULL))) {
|
|
Packit |
90a5c9 |
return (NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((autoindex_opts & SHOW_FORBIDDEN)
|
|
Packit |
90a5c9 |
&& (rr->status == HTTP_UNAUTHORIZED || rr->status == HTTP_FORBIDDEN)) {
|
|
Packit |
90a5c9 |
show_forbidden = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((rr->finfo.filetype != APR_DIR && rr->finfo.filetype != APR_REG)
|
|
Packit |
90a5c9 |
|| !(rr->status == OK || ap_is_HTTP_SUCCESS(rr->status)
|
|
Packit |
90a5c9 |
|| ap_is_HTTP_REDIRECT(rr->status)
|
|
Packit |
90a5c9 |
|| show_forbidden == 1)) {
|
|
Packit |
90a5c9 |
ap_destroy_sub_req(rr);
|
|
Packit |
90a5c9 |
return (NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
p = (struct ent *) apr_pcalloc(r->pool, sizeof(struct ent));
|
|
Packit |
90a5c9 |
if (dirent->filetype == APR_DIR) {
|
|
Packit |
90a5c9 |
p->name = apr_pstrcat(r->pool, dirent->name, "/", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
p->name = apr_pstrdup(r->pool, dirent->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
p->size = -1;
|
|
Packit |
90a5c9 |
p->icon = NULL;
|
|
Packit |
90a5c9 |
p->alt = NULL;
|
|
Packit |
90a5c9 |
p->desc = NULL;
|
|
Packit |
90a5c9 |
p->lm = -1;
|
|
Packit |
90a5c9 |
p->isdir = 0;
|
|
Packit |
90a5c9 |
p->key = apr_toupper(keyid);
|
|
Packit |
90a5c9 |
p->ascending = (apr_toupper(direction) == D_ASCENDING);
|
|
Packit |
90a5c9 |
p->version_sort = !!(autoindex_opts & VERSION_SORT);
|
|
Packit |
90a5c9 |
p->ignore_case = !!(autoindex_opts & IGNORE_CASE);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING)) {
|
|
Packit |
90a5c9 |
p->lm = rr->finfo.mtime;
|
|
Packit |
90a5c9 |
if (dirent->filetype == APR_DIR) {
|
|
Packit |
90a5c9 |
if (autoindex_opts & FOLDERS_FIRST) {
|
|
Packit |
90a5c9 |
p->isdir = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
rr->filename = ap_make_dirstr_parent (rr->pool, rr->filename);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* omit the trailing slash (1.3 compat) */
|
|
Packit |
90a5c9 |
rr->filename[strlen(rr->filename) - 1] = '\0';
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!(p->icon = find_icon(d, rr, 1))) {
|
|
Packit |
90a5c9 |
p->icon = find_default_icon(d, "^^DIRECTORY^^");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!(p->alt = find_alt(d, rr, 1))) {
|
|
Packit |
90a5c9 |
if (!(p->alt = find_default_alt(d, "^^DIRECTORY^^"))) {
|
|
Packit |
90a5c9 |
p->alt = "DIR";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
p->icon = find_icon(d, rr, 0);
|
|
Packit |
90a5c9 |
p->alt = find_alt(d, rr, 0);
|
|
Packit |
90a5c9 |
p->size = rr->finfo.size;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
p->desc = find_desc(d, rr->filename);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((!p->desc) && (autoindex_opts & SCAN_HTML_TITLES)) {
|
|
Packit |
90a5c9 |
p->desc = apr_pstrdup(r->pool, find_title(rr));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_destroy_sub_req(rr);
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* We don't need to take any special action for the file size key.
|
|
Packit |
90a5c9 |
* If we did, it would go here.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (keyid == K_LAST_MOD) {
|
|
Packit |
90a5c9 |
if (p->lm < 0) {
|
|
Packit |
90a5c9 |
p->lm = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return (p);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static char *terminate_description(autoindex_config_rec *d, char *desc,
|
|
Packit |
90a5c9 |
apr_int32_t autoindex_opts, int desc_width)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int maxsize = desc_width;
|
|
Packit |
90a5c9 |
int x;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If there's no DescriptionWidth in effect, default to the old
|
|
Packit |
90a5c9 |
* behaviour of adjusting the description size depending upon
|
|
Packit |
90a5c9 |
* what else is being displayed. Otherwise, stick with the
|
|
Packit |
90a5c9 |
* setting.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (d->desc_adjust == K_UNSET) {
|
|
Packit |
90a5c9 |
if (autoindex_opts & SUPPRESS_ICON) {
|
|
Packit |
90a5c9 |
maxsize += 6;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (autoindex_opts & SUPPRESS_LAST_MOD) {
|
|
Packit |
90a5c9 |
maxsize += 19;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (autoindex_opts & SUPPRESS_SIZE) {
|
|
Packit |
90a5c9 |
maxsize += 7;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
for (x = 0; desc[x] && ((maxsize > 0) || (desc[x] == '<')); x++) {
|
|
Packit |
90a5c9 |
if (desc[x] == '<') {
|
|
Packit |
90a5c9 |
while (desc[x] != '>') {
|
|
Packit |
90a5c9 |
if (!desc[x]) {
|
|
Packit |
90a5c9 |
maxsize = 0;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
++x;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (desc[x] == '&') {
|
|
Packit |
90a5c9 |
/* entities like ä count as one character */
|
|
Packit |
90a5c9 |
--maxsize;
|
|
Packit |
90a5c9 |
for ( ; desc[x] != ';'; ++x) {
|
|
Packit |
90a5c9 |
if (desc[x] == '\0') {
|
|
Packit |
90a5c9 |
maxsize = 0;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
--maxsize;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!maxsize && desc[x] != '\0') {
|
|
Packit |
90a5c9 |
desc[x - 1] = '>'; /* Grump. */
|
|
Packit |
90a5c9 |
desc[x] = '\0'; /* Double Grump! */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return desc;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Emit the anchor for the specified field. If a field is the key for the
|
|
Packit |
90a5c9 |
* current request, the link changes its meaning to reverse the order when
|
|
Packit |
90a5c9 |
* selected again. Non-active fields always start in ascending order.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static void emit_link(request_rec *r, const char *anchor, char column,
|
|
Packit |
90a5c9 |
char curkey, char curdirection,
|
|
Packit |
90a5c9 |
const char *colargs, int nosort)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (!nosort) {
|
|
Packit |
90a5c9 |
char qvalue[9];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
qvalue[0] = '?';
|
|
Packit |
90a5c9 |
qvalue[1] = 'C';
|
|
Packit |
90a5c9 |
qvalue[2] = '=';
|
|
Packit |
90a5c9 |
qvalue[3] = column;
|
|
Packit |
90a5c9 |
qvalue[4] = ';';
|
|
Packit |
90a5c9 |
qvalue[5] = 'O';
|
|
Packit |
90a5c9 |
qvalue[6] = '=';
|
|
Packit |
90a5c9 |
/* reverse? */
|
|
Packit |
90a5c9 |
qvalue[7] = ((curkey == column) && (curdirection == D_ASCENDING))
|
|
Packit |
90a5c9 |
? D_DESCENDING : D_ASCENDING;
|
|
Packit |
90a5c9 |
qvalue[8] = '\0';
|
|
Packit |
90a5c9 |
ap_rvputs(r, "
|
|
Packit |
90a5c9 |
"\">", anchor, "", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rputs(anchor, r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void output_directories(struct ent **ar, int n,
|
|
Packit |
90a5c9 |
autoindex_config_rec *d, request_rec *r,
|
|
Packit |
90a5c9 |
apr_int32_t autoindex_opts, char keyid,
|
|
Packit |
90a5c9 |
char direction, const char *colargs)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int x;
|
|
Packit |
90a5c9 |
apr_size_t rv;
|
|
Packit |
90a5c9 |
char *tp;
|
|
Packit |
90a5c9 |
int static_columns = !!(autoindex_opts & SUPPRESS_COLSORT);
|
|
Packit |
90a5c9 |
apr_pool_t *scratch;
|
|
Packit |
90a5c9 |
int name_width;
|
|
Packit |
90a5c9 |
int desc_width;
|
|
Packit |
90a5c9 |
char *datetime_format;
|
|
Packit |
90a5c9 |
char *name_scratch;
|
|
Packit |
90a5c9 |
char *pad_scratch;
|
|
Packit |
90a5c9 |
char *breakrow = "";
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_pool_create(&scratch, r->pool);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
name_width = d->name_width;
|
|
Packit |
90a5c9 |
desc_width = d->desc_width;
|
|
Packit |
90a5c9 |
datetime_format = d->datetime_format ? d->datetime_format : "%Y-%m-%d %H:%M";
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING))
|
|
Packit |
90a5c9 |
== FANCY_INDEXING) {
|
|
Packit |
90a5c9 |
if (d->name_adjust == K_ADJUST) {
|
|
Packit |
90a5c9 |
for (x = 0; x < n; x++) {
|
|
Packit |
90a5c9 |
int t = strlen(ar[x]->name);
|
|
Packit |
90a5c9 |
if (t > name_width) {
|
|
Packit |
90a5c9 |
name_width = t;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (d->desc_adjust == K_ADJUST) {
|
|
Packit |
90a5c9 |
for (x = 0; x < n; x++) {
|
|
Packit |
90a5c9 |
if (ar[x]->desc != NULL) {
|
|
Packit |
90a5c9 |
int t = strlen(ar[x]->desc);
|
|
Packit |
90a5c9 |
if (t > desc_width) {
|
|
Packit |
90a5c9 |
desc_width = t;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
name_scratch = apr_palloc(r->pool, name_width + 1);
|
|
Packit |
90a5c9 |
pad_scratch = apr_palloc(r->pool, name_width + 1);
|
|
Packit |
90a5c9 |
memset(pad_scratch, ' ', name_width);
|
|
Packit |
90a5c9 |
pad_scratch[name_width] = '\0';
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (autoindex_opts & TABLE_INDEXING) {
|
|
Packit |
90a5c9 |
int cols = 1;
|
|
Packit |
90a5c9 |
if (d->style_sheet != NULL) {
|
|
Packit |
90a5c9 |
/* Emit table with style id */
|
|
Packit |
90a5c9 |
ap_rputs(" \n ", r);
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
ap_rputs(" \n ", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_ICON)) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "<th", (d->style_sheet != NULL) ? " class=\"indexcolicon\">" : " valign=\"top\">", NULL);
|
|
Packit |
90a5c9 |
if ((tp = find_default_icon(d, "^^BLANKICON^^"))) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "
|
|
Packit |
90a5c9 |
"\" alt=\"[ICO]\"", NULL);
|
|
Packit |
90a5c9 |
if (d->icon_width) {
|
|
Packit |
90a5c9 |
ap_rprintf(r, " width=\"%d\"", d->icon_width);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (d->icon_height) {
|
|
Packit |
90a5c9 |
ap_rprintf(r, " height=\"%d\"", d->icon_height);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (autoindex_opts & EMIT_XHTML) {
|
|
Packit |
90a5c9 |
ap_rputs(" /", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs(">", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rputs(" ", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
++cols;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rvputs(r, "<th", (d->style_sheet != NULL) ? " class=\"indexcolname\">" : ">", NULL);
|
|
Packit |
90a5c9 |
emit_link(r, "Name", K_NAME, keyid, direction,
|
|
Packit |
90a5c9 |
colargs, static_columns);
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "<th", (d->style_sheet != NULL) ? " class=\"indexcollastmod\">" : ">", NULL);
|
|
Packit |
90a5c9 |
emit_link(r, "Last modified", K_LAST_MOD, keyid, direction,
|
|
Packit |
90a5c9 |
colargs, static_columns);
|
|
Packit |
90a5c9 |
++cols;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_SIZE)) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "<th", (d->style_sheet != NULL) ? " class=\"indexcolsize\">" : ">", NULL);
|
|
Packit |
90a5c9 |
emit_link(r, "Size", K_SIZE, keyid, direction,
|
|
Packit |
90a5c9 |
colargs, static_columns);
|
|
Packit |
90a5c9 |
++cols;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_DESC)) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "<th", (d->style_sheet != NULL) ? " class=\"indexcoldesc\">" : ">", NULL);
|
|
Packit |
90a5c9 |
emit_link(r, "Description", K_DESC, keyid, direction,
|
|
Packit |
90a5c9 |
colargs, static_columns);
|
|
Packit |
90a5c9 |
++cols;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_RULES)) {
|
|
Packit |
90a5c9 |
breakrow = apr_psprintf(r->pool,
|
|
Packit |
90a5c9 |
" <tr%s>"
|
|
Packit |
90a5c9 |
"<hr%s>\n",
|
|
Packit |
90a5c9 |
(d->style_sheet != NULL) ? " class=\"indexbreakrow\"" : "",
|
|
Packit |
90a5c9 |
cols,
|
|
Packit |
90a5c9 |
(autoindex_opts & EMIT_XHTML) ? " /" : "");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rvputs(r, "\n", breakrow, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (autoindex_opts & FANCY_INDEXING) {
|
|
Packit |
90a5c9 |
ap_rputs("", r);
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_ICON)) {
|
|
Packit |
90a5c9 |
if ((tp = find_default_icon(d, "^^BLANKICON^^"))) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "
|
|
Packit |
90a5c9 |
"\" alt=\"Icon \"", NULL);
|
|
Packit |
90a5c9 |
if (d->icon_width) {
|
|
Packit |
90a5c9 |
ap_rprintf(r, " width=\"%d\"", d->icon_width);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (d->icon_height) {
|
|
Packit |
90a5c9 |
ap_rprintf(r, " height=\"%d\"", d->icon_height);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (autoindex_opts & EMIT_XHTML) {
|
|
Packit |
90a5c9 |
ap_rputs(" /", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs("> ", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rputs(" ", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
emit_link(r, "Name", K_NAME, keyid, direction,
|
|
Packit |
90a5c9 |
colargs, static_columns);
|
|
Packit |
90a5c9 |
ap_rputs(pad_scratch + 4, r);
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Emit the guaranteed-at-least-one-space-between-columns byte.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_rputs(" ", r);
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
|
|
Packit |
90a5c9 |
emit_link(r, "Last modified", K_LAST_MOD, keyid, direction,
|
|
Packit |
90a5c9 |
colargs, static_columns);
|
|
Packit |
90a5c9 |
ap_rputs(" ", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_SIZE)) {
|
|
Packit |
90a5c9 |
emit_link(r, "Size", K_SIZE, keyid, direction,
|
|
Packit |
90a5c9 |
colargs, static_columns);
|
|
Packit |
90a5c9 |
ap_rputs(" ", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_DESC)) {
|
|
Packit |
90a5c9 |
emit_link(r, "Description", K_DESC, keyid, direction,
|
|
Packit |
90a5c9 |
colargs, static_columns);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_RULES)) {
|
|
Packit |
90a5c9 |
ap_rputs("
|
|
Packit |
90a5c9 |
if (autoindex_opts & EMIT_XHTML) {
|
|
Packit |
90a5c9 |
ap_rputs(" /", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs(">", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rputc('\n', r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rputs("
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (x = 0; x < n; x++) {
|
|
Packit |
90a5c9 |
char *anchor, *t, *t2;
|
|
Packit |
90a5c9 |
int nwidth;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_pool_clear(scratch);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
t = ar[x]->name;
|
|
Packit |
90a5c9 |
anchor = ap_escape_html(scratch, ap_os_escape_path(scratch, t, 0));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!x && t[0] == '/') {
|
|
Packit |
90a5c9 |
t2 = "Parent Directory";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
t2 = t;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (autoindex_opts & TABLE_INDEXING) {
|
|
Packit |
90a5c9 |
/* Even/Odd rows for IndexStyleSheet */
|
|
Packit |
90a5c9 |
if (d->style_sheet != NULL) {
|
|
Packit |
90a5c9 |
if (ar[x]->alt && (autoindex_opts & ADDALTCLASS)) {
|
|
Packit |
90a5c9 |
/* Include alt text in class name, distinguish between odd and even rows */
|
|
Packit |
90a5c9 |
char *altclass = apr_pstrdup(scratch, ar[x]->alt);
|
|
Packit |
90a5c9 |
ap_str_tolower(altclass);
|
|
Packit |
90a5c9 |
ap_rvputs(r, " ", NULL);
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
/* Distinguish between odd and even rows */
|
|
Packit |
90a5c9 |
ap_rvputs(r, " ", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
ap_rputs("", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_ICON)) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcolicon\">" : " valign=\"top\">", NULL);
|
|
Packit |
90a5c9 |
if (autoindex_opts & ICONS_ARE_LINKS) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((ar[x]->icon) || d->default_icon) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "
|
|
Packit |
90a5c9 |
ap_escape_html(scratch,
|
|
Packit |
90a5c9 |
ar[x]->icon ? ar[x]->icon
|
|
Packit |
90a5c9 |
: d->default_icon),
|
|
Packit |
90a5c9 |
"\" alt=\"[", (ar[x]->alt ? ar[x]->alt : " "),
|
|
Packit |
90a5c9 |
"]\"", NULL);
|
|
Packit |
90a5c9 |
if (d->icon_width) {
|
|
Packit |
90a5c9 |
ap_rprintf(r, " width=\"%d\"", d->icon_width);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (d->icon_height) {
|
|
Packit |
90a5c9 |
ap_rprintf(r, " height=\"%d\"", d->icon_height);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (autoindex_opts & EMIT_XHTML) {
|
|
Packit |
90a5c9 |
ap_rputs(" /", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs(">", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rputs(" ", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (autoindex_opts & ICONS_ARE_LINKS) {
|
|
Packit |
90a5c9 |
ap_rputs("", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rputs("", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (d->name_adjust == K_ADJUST) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcolname\">" : ">", "",
|
|
Packit |
90a5c9 |
ap_escape_html(scratch, t2), "", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
nwidth = strlen(t2);
|
|
Packit |
90a5c9 |
if (nwidth > name_width) {
|
|
Packit |
90a5c9 |
memcpy(name_scratch, t2, name_width - 3);
|
|
Packit |
90a5c9 |
name_scratch[name_width - 3] = '.';
|
|
Packit |
90a5c9 |
name_scratch[name_width - 2] = '.';
|
|
Packit |
90a5c9 |
name_scratch[name_width - 1] = '>';
|
|
Packit |
90a5c9 |
name_scratch[name_width] = 0;
|
|
Packit |
90a5c9 |
t2 = name_scratch;
|
|
Packit |
90a5c9 |
nwidth = name_width;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcolname\">" : ">", "",
|
|
Packit |
90a5c9 |
ap_escape_html(scratch, t2),
|
|
Packit |
90a5c9 |
"", pad_scratch + nwidth, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
|
|
Packit |
90a5c9 |
if (ar[x]->lm != -1) {
|
|
Packit |
90a5c9 |
char time_str[32];
|
|
Packit |
90a5c9 |
apr_time_exp_t ts;
|
|
Packit |
90a5c9 |
apr_time_exp_lt(&ts, ar[x]->lm);
|
|
Packit |
90a5c9 |
apr_strftime(time_str, &rv, sizeof(time_str),
|
|
Packit |
90a5c9 |
datetime_format,
|
|
Packit |
90a5c9 |
&ts);
|
|
Packit |
90a5c9 |
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcollastmod\">" : " align=\"right\">", time_str, " ", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcollastmod\"> " : "> ", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_SIZE)) {
|
|
Packit |
90a5c9 |
char buf[5];
|
|
Packit |
90a5c9 |
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcolsize\">" : " align=\"right\">",
|
|
Packit |
90a5c9 |
apr_strfsize(ar[x]->size, buf), NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_DESC)) {
|
|
Packit |
90a5c9 |
if (ar[x]->desc) {
|
|
Packit |
90a5c9 |
if (d->desc_adjust == K_ADJUST) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcoldesc\">" : ">", ar[x]->desc, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcoldesc\">" : ">",
|
|
Packit |
90a5c9 |
terminate_description(d, ar[x]->desc,
|
|
Packit |
90a5c9 |
autoindex_opts,
|
|
Packit |
90a5c9 |
desc_width), NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "<td", (d->style_sheet != NULL) ? " class=\"indexcoldesc\">" : ">", " ", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs("\n", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (autoindex_opts & FANCY_INDEXING) {
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_ICON)) {
|
|
Packit |
90a5c9 |
if (autoindex_opts & ICONS_ARE_LINKS) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((ar[x]->icon) || d->default_icon) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, "
|
|
Packit |
90a5c9 |
ap_escape_html(scratch,
|
|
Packit |
90a5c9 |
ar[x]->icon ? ar[x]->icon
|
|
Packit |
90a5c9 |
: d->default_icon),
|
|
Packit |
90a5c9 |
"\" alt=\"[", (ar[x]->alt ? ar[x]->alt : " "),
|
|
Packit |
90a5c9 |
"]\"", NULL);
|
|
Packit |
90a5c9 |
if (d->icon_width) {
|
|
Packit |
90a5c9 |
ap_rprintf(r, " width=\"%d\"", d->icon_width);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (d->icon_height) {
|
|
Packit |
90a5c9 |
ap_rprintf(r, " height=\"%d\"", d->icon_height);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (autoindex_opts & EMIT_XHTML) {
|
|
Packit |
90a5c9 |
ap_rputs(" /", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs(">", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rputs(" ", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (autoindex_opts & ICONS_ARE_LINKS) {
|
|
Packit |
90a5c9 |
ap_rputs(" ", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rputc(' ', r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
nwidth = strlen(t2);
|
|
Packit |
90a5c9 |
if (nwidth > name_width) {
|
|
Packit |
90a5c9 |
memcpy(name_scratch, t2, name_width - 3);
|
|
Packit |
90a5c9 |
name_scratch[name_width - 3] = '.';
|
|
Packit |
90a5c9 |
name_scratch[name_width - 2] = '.';
|
|
Packit |
90a5c9 |
name_scratch[name_width - 1] = '>';
|
|
Packit |
90a5c9 |
name_scratch[name_width] = 0;
|
|
Packit |
90a5c9 |
t2 = name_scratch;
|
|
Packit |
90a5c9 |
nwidth = name_width;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rvputs(r, "",
|
|
Packit |
90a5c9 |
ap_escape_html(scratch, t2),
|
|
Packit |
90a5c9 |
"", pad_scratch + nwidth, NULL);
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* The blank before the storm.. er, before the next field.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_rputs(" ", r);
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_LAST_MOD)) {
|
|
Packit |
90a5c9 |
if (ar[x]->lm != -1) {
|
|
Packit |
90a5c9 |
char time_str[32];
|
|
Packit |
90a5c9 |
apr_time_exp_t ts;
|
|
Packit |
90a5c9 |
apr_time_exp_lt(&ts, ar[x]->lm);
|
|
Packit |
90a5c9 |
apr_strftime(time_str, &rv, sizeof(time_str),
|
|
Packit |
90a5c9 |
datetime_format,
|
|
Packit |
90a5c9 |
&ts);
|
|
Packit |
90a5c9 |
ap_rvputs(r, time_str, " ", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* Length="1975-04-07 01:23 " (default in 2.4 and later) or
|
|
Packit |
90a5c9 |
* Length="07-Apr-1975 01:24 ". (2.2 and UseOldDateFormat)
|
|
Packit |
90a5c9 |
* See 'datetime_format' above.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_rputs(" ", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_SIZE)) {
|
|
Packit |
90a5c9 |
char buf[5];
|
|
Packit |
90a5c9 |
ap_rputs(apr_strfsize(ar[x]->size, buf), r);
|
|
Packit |
90a5c9 |
ap_rputs(" ", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_DESC)) {
|
|
Packit |
90a5c9 |
if (ar[x]->desc) {
|
|
Packit |
90a5c9 |
ap_rputs(terminate_description(d, ar[x]->desc,
|
|
Packit |
90a5c9 |
autoindex_opts,
|
|
Packit |
90a5c9 |
desc_width), r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputc('\n', r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rvputs(r, " ",
|
|
Packit |
90a5c9 |
ap_escape_html(scratch, t2),
|
|
Packit |
90a5c9 |
"\n", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (autoindex_opts & TABLE_INDEXING) {
|
|
Packit |
90a5c9 |
ap_rvputs(r, breakrow, "\n", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (autoindex_opts & FANCY_INDEXING) {
|
|
Packit |
90a5c9 |
if (!(autoindex_opts & SUPPRESS_RULES)) {
|
|
Packit |
90a5c9 |
ap_rputs("
|
|
Packit |
90a5c9 |
if (autoindex_opts & EMIT_XHTML) {
|
|
Packit |
90a5c9 |
ap_rputs(" /", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_rputs(">\n", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rputs("\n", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_rputs("\n", r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Compare two file entries according to the sort criteria. The return
|
|
Packit |
90a5c9 |
* is essentially a signum function value.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int dsortf(struct ent **e1, struct ent **e2)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
struct ent *c1;
|
|
Packit |
90a5c9 |
struct ent *c2;
|
|
Packit |
90a5c9 |
int result = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* First, see if either of the entries is for the parent directory.
|
|
Packit |
90a5c9 |
* If so, that *always* sorts lower than anything else.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((*e1)->name[0] == '/') {
|
|
Packit |
90a5c9 |
return -1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((*e2)->name[0] == '/') {
|
|
Packit |
90a5c9 |
return 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Now see if one's a directory and one isn't, if we're set
|
|
Packit |
90a5c9 |
* isdir for FOLDERS_FIRST.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((*e1)->isdir != (*e2)->isdir) {
|
|
Packit |
90a5c9 |
return (*e1)->isdir ? -1 : 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* All of our comparisons will be of the c1 entry against the c2 one,
|
|
Packit |
90a5c9 |
* so assign them appropriately to take care of the ordering.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((*e1)->ascending) {
|
|
Packit |
90a5c9 |
c1 = *e1;
|
|
Packit |
90a5c9 |
c2 = *e2;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
c1 = *e2;
|
|
Packit |
90a5c9 |
c2 = *e1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
switch (c1->key) {
|
|
Packit |
90a5c9 |
case K_LAST_MOD:
|
|
Packit |
90a5c9 |
if (c1->lm > c2->lm) {
|
|
Packit |
90a5c9 |
return 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (c1->lm < c2->lm) {
|
|
Packit |
90a5c9 |
return -1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case K_SIZE:
|
|
Packit |
90a5c9 |
if (c1->size > c2->size) {
|
|
Packit |
90a5c9 |
return 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (c1->size < c2->size) {
|
|
Packit |
90a5c9 |
return -1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case K_DESC:
|
|
Packit |
90a5c9 |
if (c1->version_sort) {
|
|
Packit |
90a5c9 |
result = apr_strnatcmp(c1->desc ? c1->desc : "",
|
|
Packit |
90a5c9 |
c2->desc ? c2->desc : "");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
result = strcmp(c1->desc ? c1->desc : "",
|
|
Packit |
90a5c9 |
c2->desc ? c2->desc : "");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (result) {
|
|
Packit |
90a5c9 |
return result;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* names may identical when treated case-insensitively,
|
|
Packit |
90a5c9 |
* so always fall back on strcmp() flavors to put entries
|
|
Packit |
90a5c9 |
* in deterministic order. This means that 'ABC' and 'abc'
|
|
Packit |
90a5c9 |
* will always appear in the same order, rather than
|
|
Packit |
90a5c9 |
* variably between 'ABC abc' and 'abc ABC' order.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (c1->version_sort) {
|
|
Packit |
90a5c9 |
if (c1->ignore_case) {
|
|
Packit |
90a5c9 |
result = apr_strnatcasecmp (c1->name, c2->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!result) {
|
|
Packit |
90a5c9 |
result = apr_strnatcmp(c1->name, c2->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* The names may be identical in respects other than
|
|
Packit |
90a5c9 |
* filename case when strnatcmp is used above, so fall back
|
|
Packit |
90a5c9 |
* to strcmp on conflicts so that fn1.01.zzz and fn1.1.zzz
|
|
Packit |
90a5c9 |
* are also sorted in a deterministic order.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!result && c1->ignore_case) {
|
|
Packit |
90a5c9 |
result = strcasecmp (c1->name, c2->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!result) {
|
|
Packit |
90a5c9 |
result = strcmp (c1->name, c2->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return result;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int index_directory(request_rec *r,
|
|
Packit |
90a5c9 |
autoindex_config_rec *autoindex_conf)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *title_name = ap_escape_html(r->pool, r->uri);
|
|
Packit |
90a5c9 |
char *title_endp;
|
|
Packit |
90a5c9 |
char *name = r->filename;
|
|
Packit |
90a5c9 |
char *pstring = NULL;
|
|
Packit |
90a5c9 |
apr_finfo_t dirent;
|
|
Packit |
90a5c9 |
apr_dir_t *thedir;
|
|
Packit |
90a5c9 |
apr_status_t status;
|
|
Packit |
90a5c9 |
int num_ent = 0, x;
|
|
Packit |
90a5c9 |
struct ent *head, *p;
|
|
Packit |
90a5c9 |
struct ent **ar = NULL;
|
|
Packit |
90a5c9 |
const char *qstring;
|
|
Packit |
90a5c9 |
apr_int32_t autoindex_opts = autoindex_conf->opts;
|
|
Packit |
90a5c9 |
char keyid;
|
|
Packit |
90a5c9 |
char direction;
|
|
Packit |
90a5c9 |
char *colargs;
|
|
Packit |
90a5c9 |
char *fullpath;
|
|
Packit |
90a5c9 |
apr_size_t dirpathlen;
|
|
Packit |
90a5c9 |
char *ctype = "text/html";
|
|
Packit |
90a5c9 |
char *charset;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((status = apr_dir_open(&thedir, name, r->pool)) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(01275)
|
|
Packit |
90a5c9 |
"Can't open directory for index: %s", r->filename);
|
|
Packit |
90a5c9 |
return HTTP_FORBIDDEN;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (autoindex_conf->ctype) {
|
|
Packit |
90a5c9 |
ctype = autoindex_conf->ctype;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (autoindex_conf->charset) {
|
|
Packit |
90a5c9 |
charset = autoindex_conf->charset;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
#if APR_HAS_UNICODE_FS
|
|
Packit |
90a5c9 |
charset = "UTF-8";
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
charset = "ISO-8859-1";
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (*charset) {
|
|
Packit |
90a5c9 |
ap_set_content_type(r, apr_pstrcat(r->pool, ctype, ";charset=",
|
|
Packit |
90a5c9 |
charset, NULL));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_set_content_type(r, ctype);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (autoindex_opts & TRACK_MODIFIED) {
|
|
Packit |
90a5c9 |
ap_update_mtime(r, r->finfo.mtime);
|
|
Packit |
90a5c9 |
ap_set_last_modified(r);
|
|
Packit |
90a5c9 |
ap_set_etag(r);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (r->header_only) {
|
|
Packit |
90a5c9 |
apr_dir_close(thedir);
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If there is no specific ordering defined for this directory,
|
|
Packit |
90a5c9 |
* default to ascending by filename.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
keyid = autoindex_conf->default_keyid
|
|
Packit |
90a5c9 |
? autoindex_conf->default_keyid : K_NAME;
|
|
Packit |
90a5c9 |
direction = autoindex_conf->default_direction
|
|
Packit |
90a5c9 |
? autoindex_conf->default_direction : D_ASCENDING;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Figure out what sort of indexing (if any) we're supposed to use.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* If no QUERY_STRING was specified or client query strings have been
|
|
Packit |
90a5c9 |
* explicitly disabled.
|
|
Packit |
90a5c9 |
* If we are ignoring the client, suppress column sorting as well.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (autoindex_opts & IGNORE_CLIENT) {
|
|
Packit |
90a5c9 |
qstring = NULL;
|
|
Packit |
90a5c9 |
autoindex_opts |= SUPPRESS_COLSORT;
|
|
Packit |
90a5c9 |
colargs = "";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
char fval[5], vval[5], *ppre = "", *epattern = "";
|
|
Packit |
90a5c9 |
fval[0] = '\0'; vval[0] = '\0';
|
|
Packit |
90a5c9 |
qstring = r->args;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while (qstring && *qstring) {
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* C= First Sort key Column (N, M, S, D) */
|
|
Packit |
90a5c9 |
if ( qstring[0] == 'C' && qstring[1] == '='
|
|
Packit |
90a5c9 |
&& qstring[2] && strchr(K_VALID, qstring[2])
|
|
Packit |
90a5c9 |
&& ( qstring[3] == '&' || qstring[3] == ';'
|
|
Packit |
90a5c9 |
|| !qstring[3])) {
|
|
Packit |
90a5c9 |
keyid = qstring[2];
|
|
Packit |
90a5c9 |
qstring += qstring[3] ? 4 : 3;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* O= Sort order (A, D) */
|
|
Packit |
90a5c9 |
else if ( qstring[0] == 'O' && qstring[1] == '='
|
|
Packit |
90a5c9 |
&& ( (qstring[2] == D_ASCENDING)
|
|
Packit |
90a5c9 |
|| (qstring[2] == D_DESCENDING))
|
|
Packit |
90a5c9 |
&& ( qstring[3] == '&' || qstring[3] == ';'
|
|
Packit |
90a5c9 |
|| !qstring[3])) {
|
|
Packit |
90a5c9 |
direction = qstring[2];
|
|
Packit |
90a5c9 |
qstring += qstring[3] ? 4 : 3;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* F= Output Format (0 plain, 1 fancy (pre), 2 table) */
|
|
Packit |
90a5c9 |
else if ( qstring[0] == 'F' && qstring[1] == '='
|
|
Packit |
90a5c9 |
&& qstring[2] && strchr("012", qstring[2])
|
|
Packit |
90a5c9 |
&& ( qstring[3] == '&' || qstring[3] == ';'
|
|
Packit |
90a5c9 |
|| !qstring[3])) {
|
|
Packit |
90a5c9 |
if (qstring[2] == '0') {
|
|
Packit |
90a5c9 |
autoindex_opts &= ~(FANCY_INDEXING | TABLE_INDEXING);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (qstring[2] == '1') {
|
|
Packit |
90a5c9 |
autoindex_opts = (autoindex_opts | FANCY_INDEXING)
|
|
Packit |
90a5c9 |
& ~TABLE_INDEXING;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (qstring[2] == '2') {
|
|
Packit |
90a5c9 |
autoindex_opts |= FANCY_INDEXING | TABLE_INDEXING;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
strcpy(fval, ";F= ");
|
|
Packit |
90a5c9 |
fval[3] = qstring[2];
|
|
Packit |
90a5c9 |
qstring += qstring[3] ? 4 : 3;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* V= Version sort (0, 1) */
|
|
Packit |
90a5c9 |
else if ( qstring[0] == 'V' && qstring[1] == '='
|
|
Packit |
90a5c9 |
&& (qstring[2] == '0' || qstring[2] == '1')
|
|
Packit |
90a5c9 |
&& ( qstring[3] == '&' || qstring[3] == ';'
|
|
Packit |
90a5c9 |
|| !qstring[3])) {
|
|
Packit |
90a5c9 |
if (qstring[2] == '0') {
|
|
Packit |
90a5c9 |
autoindex_opts &= ~VERSION_SORT;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (qstring[2] == '1') {
|
|
Packit |
90a5c9 |
autoindex_opts |= VERSION_SORT;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
strcpy(vval, ";V= ");
|
|
Packit |
90a5c9 |
vval[3] = qstring[2];
|
|
Packit |
90a5c9 |
qstring += qstring[3] ? 4 : 3;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* P= wildcard pattern (*.foo) */
|
|
Packit |
90a5c9 |
else if (qstring[0] == 'P' && qstring[1] == '=') {
|
|
Packit |
90a5c9 |
const char *eos = qstring += 2; /* for efficiency */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while (*eos && *eos != '&' && *eos != ';') {
|
|
Packit |
90a5c9 |
++eos;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (eos == qstring) {
|
|
Packit |
90a5c9 |
pstring = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
pstring = apr_pstrndup(r->pool, qstring, eos - qstring);
|
|
Packit |
90a5c9 |
if (ap_unescape_url(pstring) != OK) {
|
|
Packit |
90a5c9 |
/* ignore the pattern, if it's bad. */
|
|
Packit |
90a5c9 |
pstring = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ppre = ";P=";
|
|
Packit |
90a5c9 |
/* be correct */
|
|
Packit |
90a5c9 |
epattern = ap_escape_uri(r->pool, pstring);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (*eos && *++eos) {
|
|
Packit |
90a5c9 |
qstring = eos;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
qstring = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Syntax error? Ignore the remainder! */
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
qstring = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
colargs = apr_pstrcat(r->pool, fval, vval, ppre, epattern, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Spew HTML preamble */
|
|
Packit |
90a5c9 |
title_endp = title_name + strlen(title_name) - 1;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while (title_endp > title_name && *title_endp == '/') {
|
|
Packit |
90a5c9 |
*title_endp-- = '\0';
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
emit_head(r, autoindex_conf->header,
|
|
Packit |
90a5c9 |
autoindex_opts & SUPPRESS_PREAMBLE,
|
|
Packit |
90a5c9 |
autoindex_opts & EMIT_XHTML, title_name);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Since we don't know how many dir. entries there are, put them into a
|
|
Packit |
90a5c9 |
* linked list and then arrayificate them so qsort can use them.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
head = NULL;
|
|
Packit |
90a5c9 |
p = make_parent_entry(autoindex_opts, autoindex_conf, r, keyid, direction);
|
|
Packit |
90a5c9 |
if (p != NULL) {
|
|
Packit |
90a5c9 |
p->next = head;
|
|
Packit |
90a5c9 |
head = p;
|
|
Packit |
90a5c9 |
num_ent++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
fullpath = apr_palloc(r->pool, APR_PATH_MAX);
|
|
Packit |
90a5c9 |
dirpathlen = strlen(name);
|
|
Packit |
90a5c9 |
memcpy(fullpath, name, dirpathlen);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
do {
|
|
Packit |
90a5c9 |
status = apr_dir_read(&dirent, APR_FINFO_MIN | APR_FINFO_NAME, thedir);
|
|
Packit |
90a5c9 |
if (APR_STATUS_IS_INCOMPLETE(status)) {
|
|
Packit |
90a5c9 |
continue; /* ignore un-stat()able files */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* We want to explode symlinks here. */
|
|
Packit |
90a5c9 |
if (dirent.filetype == APR_LNK) {
|
|
Packit |
90a5c9 |
const char *savename;
|
|
Packit |
90a5c9 |
apr_finfo_t fi;
|
|
Packit |
90a5c9 |
/* We *must* have FNAME. */
|
|
Packit |
90a5c9 |
savename = dirent.name;
|
|
Packit |
90a5c9 |
apr_cpystrn(fullpath + dirpathlen, dirent.name,
|
|
Packit |
90a5c9 |
APR_PATH_MAX - dirpathlen);
|
|
Packit |
90a5c9 |
status = apr_stat(&fi, fullpath,
|
|
Packit |
90a5c9 |
dirent.valid & ~(APR_FINFO_NAME), r->pool);
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
/* Something bad happened, skip this file. */
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
memcpy(&dirent, &fi, sizeof(fi));
|
|
Packit |
90a5c9 |
dirent.name = savename;
|
|
Packit |
90a5c9 |
dirent.valid |= APR_FINFO_NAME;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
p = make_autoindex_entry(&dirent, autoindex_opts, autoindex_conf, r,
|
|
Packit |
90a5c9 |
keyid, direction, pstring);
|
|
Packit |
90a5c9 |
if (p != NULL) {
|
|
Packit |
90a5c9 |
p->next = head;
|
|
Packit |
90a5c9 |
head = p;
|
|
Packit |
90a5c9 |
num_ent++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
} while (1);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (num_ent > 0) {
|
|
Packit |
90a5c9 |
ar = (struct ent **) apr_palloc(r->pool,
|
|
Packit |
90a5c9 |
num_ent * sizeof(struct ent *));
|
|
Packit |
90a5c9 |
p = head;
|
|
Packit |
90a5c9 |
x = 0;
|
|
Packit |
90a5c9 |
while (p) {
|
|
Packit |
90a5c9 |
ar[x++] = p;
|
|
Packit |
90a5c9 |
p = p->next;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
qsort((void *) ar, num_ent, sizeof(struct ent *),
|
|
Packit |
90a5c9 |
(int (*)(const void *, const void *)) dsortf);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
output_directories(ar, num_ent, autoindex_conf, r, autoindex_opts,
|
|
Packit |
90a5c9 |
keyid, direction, colargs);
|
|
Packit |
90a5c9 |
apr_dir_close(thedir);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
emit_tail(r, autoindex_conf->readme,
|
|
Packit |
90a5c9 |
autoindex_opts & SUPPRESS_PREAMBLE);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* The formal handler... */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int handle_autoindex(request_rec *r)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
autoindex_config_rec *d;
|
|
Packit |
90a5c9 |
int allow_opts;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (strcmp(r->handler,DIR_MAGIC_TYPE) && !AP_IS_DEFAULT_HANDLER_NAME(r->handler)) {
|
|
Packit |
90a5c9 |
return DECLINED;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (r->finfo.filetype != APR_DIR) {
|
|
Packit |
90a5c9 |
return DECLINED;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
allow_opts = ap_allow_options(r);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
d = (autoindex_config_rec *) ap_get_module_config(r->per_dir_config,
|
|
Packit |
90a5c9 |
&autoindex_module);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
r->allowed |= (AP_METHOD_BIT << M_GET);
|
|
Packit |
90a5c9 |
if (r->method_number != M_GET) {
|
|
Packit |
90a5c9 |
return DECLINED;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* OK, nothing easy. Trot out the heavy artillery... */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (allow_opts & OPT_INDEXES) {
|
|
Packit |
90a5c9 |
int errstatus;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((errstatus = ap_discard_request_body(r)) != OK) {
|
|
Packit |
90a5c9 |
return errstatus;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* KLUDGE --- make the sub_req lookups happen in the right directory.
|
|
Packit |
90a5c9 |
* Fixing this in the sub_req_lookup functions themselves is difficult,
|
|
Packit |
90a5c9 |
* and would probably break virtual includes...
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (r->filename[strlen(r->filename) - 1] != '/') {
|
|
Packit |
90a5c9 |
r->filename = apr_pstrcat(r->pool, r->filename, "/", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return index_directory(r, d);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
const char *index_names = apr_table_get(r->notes, "dir-index-names");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01276)
|
|
Packit |
90a5c9 |
"Cannot serve directory %s: No matching DirectoryIndex (%s) found, and "
|
|
Packit |
90a5c9 |
"server-generated directory index forbidden by "
|
|
Packit |
90a5c9 |
"Options directive",
|
|
Packit |
90a5c9 |
r->filename,
|
|
Packit |
90a5c9 |
index_names ? index_names : "none");
|
|
Packit |
90a5c9 |
return HTTP_FORBIDDEN;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void register_hooks(apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_hook_handler(handle_autoindex,NULL,NULL,APR_HOOK_MIDDLE);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE_MODULE(autoindex) =
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
STANDARD20_MODULE_STUFF,
|
|
Packit |
90a5c9 |
create_autoindex_config, /* dir config creater */
|
|
Packit |
90a5c9 |
merge_autoindex_configs, /* dir merger --- default is to override */
|
|
Packit |
90a5c9 |
NULL, /* server config */
|
|
Packit |
90a5c9 |
NULL, /* merge server config */
|
|
Packit |
90a5c9 |
autoindex_cmds, /* command apr_table_t */
|
|
Packit |
90a5c9 |
register_hooks /* register hooks */
|
|
Packit |
90a5c9 |
};
|