⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod_autoindex.c

📁 linux网络服务器工具
💻 C
📖 第 1 页 / 共 5 页
字号:
        else if (!strcasecmp(w, "XHTML")) {            option = EMIT_XHTML;        }        else if (!strcasecmp(w, "ShowForbidden")) {            option = SHOW_FORBIDDEN;        }        else if (!strcasecmp(w, "None")) {            if (action != '\0') {                return "Cannot combine '+' or '-' with 'None' keyword";            }            opts = NO_OPTIONS;            opts_add = 0;            opts_remove = 0;        }        else if (!strcasecmp(w, "IconWidth")) {            if (action != '-') {                d_cfg->icon_width = DEFAULT_ICON_WIDTH;            }            else {                d_cfg->icon_width = 0;            }        }        else if (!strncasecmp(w, "IconWidth=", 10)) {            if (action == '-') {                return "Cannot combine '-' with IconWidth=n";            }            d_cfg->icon_width = atoi(&w[10]);        }        else if (!strcasecmp(w, "IconHeight")) {            if (action != '-') {                d_cfg->icon_height = DEFAULT_ICON_HEIGHT;            }            else {                d_cfg->icon_height = 0;            }        }        else if (!strncasecmp(w, "IconHeight=", 11)) {            if (action == '-') {                return "Cannot combine '-' with IconHeight=n";            }            d_cfg->icon_height = atoi(&w[11]);        }        else if (!strcasecmp(w, "NameWidth")) {            if (action != '-') {                return "NameWidth with no value may only appear as "                       "'-NameWidth'";            }            d_cfg->name_width = DEFAULT_NAME_WIDTH;            d_cfg->name_adjust = K_NOADJUST;        }        else if (!strncasecmp(w, "NameWidth=", 10)) {            if (action == '-') {                return "Cannot combine '-' with NameWidth=n";            }            if (w[10] == '*') {                d_cfg->name_adjust = K_ADJUST;            }            else {                int width = atoi(&w[10]);                if (width && (width < 5)) {                    return "NameWidth value must be greater than 5";                }                d_cfg->name_width = width;                d_cfg->name_adjust = K_NOADJUST;            }        }        else if (!strcasecmp(w, "DescriptionWidth")) {            if (action != '-') {                return "DescriptionWidth with no value may only appear as "                       "'-DescriptionWidth'";            }            d_cfg->desc_width = DEFAULT_DESC_WIDTH;            d_cfg->desc_adjust = K_NOADJUST;        }        else if (!strncasecmp(w, "DescriptionWidth=", 17)) {            if (action == '-') {                return "Cannot combine '-' with DescriptionWidth=n";            }            if (w[17] == '*') {                d_cfg->desc_adjust = K_ADJUST;            }            else {                int width = atoi(&w[17]);                if (width && (width < 12)) {                    return "DescriptionWidth value must be greater than 12";                }                d_cfg->desc_width = width;                d_cfg->desc_adjust = K_NOADJUST;            }        }        else if (!strncasecmp(w, "Type=", 5)) {            d_cfg->ctype = apr_pstrdup(cmd->pool, &w[5]);        }        else if (!strncasecmp(w, "Charset=", 8)) {            d_cfg->charset = apr_pstrdup(cmd->pool, &w[8]);        }        else {            return "Invalid directory indexing option";        }        if (action == '\0') {            opts |= option;            opts_add = 0;            opts_remove = 0;        }        else if (action == '+') {            opts_add |= option;            opts_remove &= ~option;        }        else {            opts_remove |= option;            opts_add &= ~option;        }    }    if ((opts & NO_OPTIONS) && (opts & ~NO_OPTIONS)) {        return "Cannot combine other IndexOptions keywords with 'None'";    }    d_cfg->incremented_opts = opts_add;    d_cfg->decremented_opts = opts_remove;    d_cfg->opts = opts;    return NULL;}static const char *set_default_order(cmd_parms *cmd, void *m,                                     const char *direction, const char *key){    autoindex_config_rec *d_cfg = (autoindex_config_rec *) m;    if (!strcasecmp(direction, "Ascending")) {        d_cfg->default_direction = D_ASCENDING;    }    else if (!strcasecmp(direction, "Descending")) {        d_cfg->default_direction = D_DESCENDING;    }    else {        return "First keyword must be 'Ascending' or 'Descending'";    }    if (!strcasecmp(key, "Name")) {        d_cfg->default_keyid = K_NAME;    }    else if (!strcasecmp(key, "Date")) {        d_cfg->default_keyid = K_LAST_MOD;    }    else if (!strcasecmp(key, "Size")) {        d_cfg->default_keyid = K_SIZE;    }    else if (!strcasecmp(key, "Description")) {        d_cfg->default_keyid = K_DESC;    }    else {        return "Second keyword must be 'Name', 'Date', 'Size', or "               "'Description'";    }    return NULL;}#define DIR_CMD_PERMS OR_INDEXESstatic const command_rec autoindex_cmds[] ={    AP_INIT_ITERATE2("AddIcon", add_icon, BY_PATH, DIR_CMD_PERMS,                     "an icon URL followed by one or more filenames"),    AP_INIT_ITERATE2("AddIconByType", add_icon, BY_TYPE, DIR_CMD_PERMS,                     "an icon URL followed by one or more MIME types"),    AP_INIT_ITERATE2("AddIconByEncoding", add_icon, BY_ENCODING, DIR_CMD_PERMS,                     "an icon URL followed by one or more content encodings"),    AP_INIT_ITERATE2("AddAlt", add_alt, BY_PATH, DIR_CMD_PERMS,                     "alternate descriptive text followed by one or more "                     "filenames"),    AP_INIT_ITERATE2("AddAltByType", add_alt, BY_TYPE, DIR_CMD_PERMS,                     "alternate descriptive text followed by one or more MIME "                     "types"),    AP_INIT_ITERATE2("AddAltByEncoding", add_alt, BY_ENCODING, DIR_CMD_PERMS,                     "alternate descriptive text followed by one or more "                     "content encodings"),    AP_INIT_TAKE_ARGV("IndexOptions", add_opts, NULL, DIR_CMD_PERMS,                      "one or more index options [+|-][]"),    AP_INIT_TAKE2("IndexOrderDefault", set_default_order, NULL, DIR_CMD_PERMS,                  "{Ascending,Descending} {Name,Size,Description,Date}"),    AP_INIT_ITERATE("IndexIgnore", add_ignore, NULL, DIR_CMD_PERMS,                    "one or more file extensions"),    AP_INIT_ITERATE2("AddDescription", add_desc, BY_PATH, DIR_CMD_PERMS,                     "Descriptive text followed by one or more filenames"),    AP_INIT_TAKE1("HeaderName", add_header, NULL, DIR_CMD_PERMS,                  "a filename"),    AP_INIT_TAKE1("ReadmeName", add_readme, NULL, DIR_CMD_PERMS,                  "a filename"),    AP_INIT_RAW_ARGS("FancyIndexing", ap_set_deprecated, NULL, OR_ALL,                     "The FancyIndexing directive is no longer supported. "                     "Use IndexOptions FancyIndexing."),    AP_INIT_TAKE1("DefaultIcon", ap_set_string_slot,                  (void *)APR_OFFSETOF(autoindex_config_rec, default_icon),                  DIR_CMD_PERMS, "an icon URL"),    AP_INIT_TAKE1("IndexStyleSheet", ap_set_string_slot,                  (void *)APR_OFFSETOF(autoindex_config_rec, style_sheet),                  DIR_CMD_PERMS, "URL to style sheet"),    {NULL}};static void *create_autoindex_config(apr_pool_t *p, char *dummy){    autoindex_config_rec *new =    (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));    new->icon_width = 0;    new->icon_height = 0;    new->name_width = DEFAULT_NAME_WIDTH;    new->name_adjust = K_UNSET;    new->desc_width = DEFAULT_DESC_WIDTH;    new->desc_adjust = K_UNSET;    new->icon_list = apr_array_make(p, 4, sizeof(struct item));    new->alt_list = apr_array_make(p, 4, sizeof(struct item));    new->desc_list = apr_array_make(p, 4, sizeof(ai_desc_t));    new->ign_list = apr_array_make(p, 4, sizeof(struct item));    new->hdr_list = apr_array_make(p, 4, sizeof(struct item));    new->rdme_list = apr_array_make(p, 4, sizeof(struct item));    new->opts = 0;    new->incremented_opts = 0;    new->decremented_opts = 0;    new->default_keyid = '\0';    new->default_direction = '\0';    return (void *) new;}static void *merge_autoindex_configs(apr_pool_t *p, void *basev, void *addv){    autoindex_config_rec *new;    autoindex_config_rec *base = (autoindex_config_rec *) basev;    autoindex_config_rec *add = (autoindex_config_rec *) addv;    new = (autoindex_config_rec *) apr_pcalloc(p, sizeof(autoindex_config_rec));    new->default_icon = add->default_icon ? add->default_icon                                          : base->default_icon;    new->style_sheet = add->style_sheet ? add->style_sheet                                          : base->style_sheet;    new->icon_height = add->icon_height ? add->icon_height : base->icon_height;    new->icon_width = add->icon_width ? add->icon_width : base->icon_width;    new->ctype = add->ctype ? add->ctype : base->ctype;    new->charset = add->charset ? add->charset : base->charset;    new->alt_list = apr_array_append(p, add->alt_list, base->alt_list);    new->ign_list = apr_array_append(p, add->ign_list, base->ign_list);    new->hdr_list = apr_array_append(p, add->hdr_list, base->hdr_list);    new->desc_list = apr_array_append(p, add->desc_list, base->desc_list);    new->icon_list = apr_array_append(p, add->icon_list, base->icon_list);    new->rdme_list = apr_array_append(p, add->rdme_list, base->rdme_list);    if (add->opts & NO_OPTIONS) {        /*         * If the current directory says 'no options' then we also         * clear any incremental mods from being inheritable further down.         */        new->opts = NO_OPTIONS;        new->incremented_opts = 0;        new->decremented_opts = 0;    }    else {        /*         * If there were any nonincremental options selected for         * this directory, they dominate and we don't inherit *anything.*         * Contrariwise, we *do* inherit if the only settings here are         * incremental ones.         */        if (add->opts == 0) {            new->incremented_opts = (base->incremented_opts                                     | add->incremented_opts)                                    & ~add->decremented_opts;            new->decremented_opts = (base->decremented_opts                                     | add->decremented_opts);            /*             * We may have incremental settings, so make sure we don't             * inadvertently inherit an IndexOptions None from above.             */            new->opts = (base->opts & ~NO_OPTIONS);        }        else {            /*             * There are local nonincremental settings, which clear             * all inheritance from above.  They *are* the new base settings.             */            new->opts = add->opts;;        }        /*         * We're guaranteed that there'll be no overlap between         * the add-options and the remove-options.         */        new->opts |= new->incremented_opts;        new->opts &= ~new->decremented_opts;    }    /*     * Inherit the NameWidth settings if there aren't any specific to     * the new location; otherwise we'll end up using the defaults set in the     * config-rec creation routine.     */    if (add->name_adjust == K_UNSET) {        new->name_width = base->name_width;        new->name_adjust = base->name_adjust;    }    else {        new->name_width = add->name_width;        new->name_adjust = add->name_adjust;    }    /*     * Likewise for DescriptionWidth.     */    if (add->desc_adjust == K_UNSET) {        new->desc_width = base->desc_width;        new->desc_adjust = base->desc_adjust;    }    else {        new->desc_width = add->desc_width;        new->desc_adjust = add->desc_adjust;    }    new->default_keyid = add->default_keyid ? add->default_keyid                                            : base->default_keyid;    new->default_direction = add->default_direction ? add->default_direction                                                    : base->default_direction;    return new;}/**************************************************************** * * Looking things up in config entries... *//* Structure used to hold entries when we're actually building an index */struct ent {    char *name;    char *icon;    char *alt;    char *desc;    apr_off_t size;    apr_time_t lm;    struct ent *next;    int ascending, ignore_case, version_sort;    char key;    int isdir;};static char *find_item(request_rec *r, apr_array_header_t *list, int path_only){    const char *content_type = ap_field_noparam(r->pool, r->content_type);    const char *content_encoding = r->content_encoding;    char *path = r->filename;    struct item *items = (struct item *) list->elts;    int i;    for (i = 0; i < list->nelts; ++i) {        struct item *p = &items[i];        /* Special cased for ^^DIRECTORY^^ and ^^BLANKICON^^ */        if ((path[0] == '^') || (!ap_strcmp_match(path, p->apply_path))) {            if (!*(p->apply_to)) {                return p->data;            }            else if (p->type == BY_PATH || path[0] == '^') {                if (!ap_strcmp_match(path, p->apply_to)) {                    return p->data;                }            }            else if (!path_only) {                if (!content_encoding) {                    if (p->type == BY_TYPE) {                        if (content_type                            && !ap_strcasecmp_match(content_type,                                                    p->apply_to)) {                            return p->data;                        }                    }                }                else {                    if (p->type == BY_ENCODING) {                        if (!ap_strcasecmp_match(content_encoding,                                                 p->apply_to)) {                            return p->data;                        }                    }                }            }        }    }    return NULL;}#define find_icon(d,p,t) find_item(p,d->icon_list,t)#define find_alt(d,p,t) find_item(p,d->alt_list,t)#define find_header(d,p) find_item(p,d->hdr_list,0)#define find_readme(d,p) find_item(p,d->rdme_list,0)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -