📄 mod_autoindex.c
字号:
} emit_link(r, "Name", K_NAME, keyid, direction, colargs, static_columns); ap_rputs(pad_scratch + 4, r); /* * Emit the guaranteed-at-least-one-space-between-columns byte. */ ap_rputs(" ", r); if (!(autoindex_opts & SUPPRESS_LAST_MOD)) { emit_link(r, "Last modified", K_LAST_MOD, keyid, direction, colargs, static_columns); ap_rputs(" ", r); } if (!(autoindex_opts & SUPPRESS_SIZE)) { emit_link(r, "Size", K_SIZE, keyid, direction, colargs, static_columns); ap_rputs(" ", r); } if (!(autoindex_opts & SUPPRESS_DESC)) { emit_link(r, "Description", K_DESC, keyid, direction, colargs, static_columns); } if (!(autoindex_opts & SUPPRESS_RULES)) { ap_rputs("<hr", r); if (autoindex_opts & EMIT_XHTML) { ap_rputs(" /", r); } ap_rputs(">", r); } else { ap_rputc('\n', r); } } else { ap_rputs("<ul>", r); } for (x = 0; x < n; x++) { char *anchor, *t, *t2; int nwidth; apr_pool_clear(scratch); t = ar[x]->name; anchor = ap_escape_html(scratch, ap_os_escape_path(scratch, t, 0)); if (!x && t[0] == '/') { t2 = "Parent Directory"; } else { t2 = t; } if (autoindex_opts & TABLE_INDEXING) { ap_rputs("<tr>", r); if (!(autoindex_opts & SUPPRESS_ICON)) { ap_rputs("<td valign=\"top\">", r); if (autoindex_opts & ICONS_ARE_LINKS) { ap_rvputs(r, "<a href=\"", anchor, "\">", NULL); } if ((ar[x]->icon) || d->default_icon) { ap_rvputs(r, "<img src=\"", ap_escape_html(scratch, ar[x]->icon ? ar[x]->icon : d->default_icon), "\" alt=\"[", (ar[x]->alt ? ar[x]->alt : " "), "]\"", NULL); if (d->icon_width) { ap_rprintf(r, " width=\"%d\"", d->icon_width); } if (d->icon_height) { ap_rprintf(r, " height=\"%d\"", d->icon_height); } if (autoindex_opts & EMIT_XHTML) { ap_rputs(" /", r); } ap_rputs(">", r); } else { ap_rputs(" ", r); } if (autoindex_opts & ICONS_ARE_LINKS) { ap_rputs("</a></td>", r); } else { ap_rputs("</td>", r); } } if (d->name_adjust == K_ADJUST) { ap_rvputs(r, "<td><a href=\"", anchor, "\">", ap_escape_html(scratch, t2), "</a>", NULL); } else { nwidth = strlen(t2); if (nwidth > name_width) { memcpy(name_scratch, t2, name_width - 3); name_scratch[name_width - 3] = '.'; name_scratch[name_width - 2] = '.'; name_scratch[name_width - 1] = '>'; name_scratch[name_width] = 0; t2 = name_scratch; nwidth = name_width; } ap_rvputs(r, "<td><a href=\"", anchor, "\">", ap_escape_html(scratch, t2), "</a>", pad_scratch + nwidth, NULL); } if (!(autoindex_opts & SUPPRESS_LAST_MOD)) { if (ar[x]->lm != -1) { char time_str[MAX_STRING_LEN]; apr_time_exp_t ts; apr_time_exp_lt(&ts, ar[x]->lm); apr_strftime(time_str, &rv, MAX_STRING_LEN, "</td><td align=\"right\">%d-%b-%Y %H:%M ", &ts); ap_rputs(time_str, r); } else { ap_rputs("</td><td> ", r); } } if (!(autoindex_opts & SUPPRESS_SIZE)) { char buf[5]; ap_rvputs(r, "</td><td align=\"right\">", apr_strfsize(ar[x]->size, buf), NULL); } if (!(autoindex_opts & SUPPRESS_DESC)) { if (ar[x]->desc) { if (d->desc_adjust == K_ADJUST) { ap_rvputs(r, "</td><td>", ar[x]->desc, NULL); } else { ap_rvputs(r, "</td><td>", terminate_description(d, ar[x]->desc, autoindex_opts, desc_width), NULL); } } } else { ap_rputs("</td><td> ", r); } ap_rputs("</td></tr>\n", r); } else if (autoindex_opts & FANCY_INDEXING) { if (!(autoindex_opts & SUPPRESS_ICON)) { if (autoindex_opts & ICONS_ARE_LINKS) { ap_rvputs(r, "<a href=\"", anchor, "\">", NULL); } if ((ar[x]->icon) || d->default_icon) { ap_rvputs(r, "<img src=\"", ap_escape_html(scratch, ar[x]->icon ? ar[x]->icon : d->default_icon), "\" alt=\"[", (ar[x]->alt ? ar[x]->alt : " "), "]\"", NULL); if (d->icon_width) { ap_rprintf(r, " width=\"%d\"", d->icon_width); } if (d->icon_height) { ap_rprintf(r, " height=\"%d\"", d->icon_height); } if (autoindex_opts & EMIT_XHTML) { ap_rputs(" /", r); } ap_rputs(">", r); } else { ap_rputs(" ", r); } if (autoindex_opts & ICONS_ARE_LINKS) { ap_rputs("</a> ", r); } else { ap_rputc(' ', r); } } nwidth = strlen(t2); if (nwidth > name_width) { memcpy(name_scratch, t2, name_width - 3); name_scratch[name_width - 3] = '.'; name_scratch[name_width - 2] = '.'; name_scratch[name_width - 1] = '>'; name_scratch[name_width] = 0; t2 = name_scratch; nwidth = name_width; } ap_rvputs(r, "<a href=\"", anchor, "\">", ap_escape_html(scratch, t2), "</a>", pad_scratch + nwidth, NULL); /* * The blank before the storm.. er, before the next field. */ ap_rputs(" ", r); if (!(autoindex_opts & SUPPRESS_LAST_MOD)) { if (ar[x]->lm != -1) { char time_str[MAX_STRING_LEN]; apr_time_exp_t ts; apr_time_exp_lt(&ts, ar[x]->lm); apr_strftime(time_str, &rv, MAX_STRING_LEN, "%d-%b-%Y %H:%M ", &ts); ap_rputs(time_str, r); } else { /*Length="22-Feb-1998 23:42 " (see 4 lines above) */ ap_rputs(" ", r); } } if (!(autoindex_opts & SUPPRESS_SIZE)) { char buf[5]; ap_rputs(apr_strfsize(ar[x]->size, buf), r); ap_rputs(" ", r); } if (!(autoindex_opts & SUPPRESS_DESC)) { if (ar[x]->desc) { ap_rputs(terminate_description(d, ar[x]->desc, autoindex_opts, desc_width), r); } } ap_rputc('\n', r); } else { ap_rvputs(r, "<li><a href=\"", anchor, "\"> ", t2, "</a></li>\n", NULL); } } if (autoindex_opts & TABLE_INDEXING) { ap_rvputs(r, breakrow, "</table>\n", NULL); } else if (autoindex_opts & FANCY_INDEXING) { if (!(autoindex_opts & SUPPRESS_RULES)) { ap_rputs("<hr", r); if (autoindex_opts & EMIT_XHTML) { ap_rputs(" /", r); } ap_rputs("></pre>\n", r); } else { ap_rputs("</pre>\n", r); } } else { ap_rputs("</ul>\n", r); }}/* * Compare two file entries according to the sort criteria. The return * is essentially a signum function value. */static int dsortf(struct ent **e1, struct ent **e2){ struct ent *c1; struct ent *c2; int result = 0; /* * First, see if either of the entries is for the parent directory. * If so, that *always* sorts lower than anything else. */ if ((*e1)->name[0] == '/') { return -1; } if ((*e2)->name[0] == '/') { return 1; } /* * Now see if one's a directory and one isn't, if we're set * isdir for FOLDERS_FIRST. */ if ((*e1)->isdir != (*e2)->isdir) { return (*e1)->isdir ? -1 : 1; } /* * All of our comparisons will be of the c1 entry against the c2 one, * so assign them appropriately to take care of the ordering. */ if ((*e1)->ascending) { c1 = *e1; c2 = *e2; } else { c1 = *e2; c2 = *e1; } switch (c1->key) { case K_LAST_MOD: if (c1->lm > c2->lm) { return 1; } else if (c1->lm < c2->lm) { return -1; } break; case K_SIZE: if (c1->size > c2->size) { return 1; } else if (c1->size < c2->size) { return -1; } break; case K_DESC: if (c1->version_sort) { result = apr_strnatcmp(c1->desc ? c1->desc : "", c2->desc ? c2->desc : ""); } else { result = strcmp(c1->desc ? c1->desc : "", c2->desc ? c2->desc : ""); } if (result) { return result; } break; } /* names may identical when treated case-insensitively, * so always fall back on strcmp() flavors to put entries * in deterministic order. This means that 'ABC' and 'abc' * will always appear in the same order, rather than * variably between 'ABC abc' and 'abc ABC' order. */ if (c1->version_sort) { if (c1->ignore_case) { result = apr_strnatcasecmp (c1->name, c2->name); } if (!result) { result = apr_strnatcmp(c1->name, c2->name); } } /* The names may be identical in respects other other than * filename case when strnatcmp is used above, so fall back * to strcmp on conflicts so that fn1.01.zzz and fn1.1.zzz * are also sorted in a deterministic order. */ if (!result && c1->ignore_case) { result = strcasecmp (c1->name, c2->name); } if (!result) { result = strcmp (c1->name, c2->name); } return result;}static int index_directory(request_rec *r, autoindex_config_rec *autoindex_conf){ char *title_name = ap_escape_html(r->pool, r->uri); char *title_endp; char *name = r->filename; char *pstring = NULL; apr_finfo_t dirent; apr_dir_t *thedir; apr_status_t status; int num_ent = 0, x; struct ent *head, *p; struct ent **ar = NULL; const char *qstring; apr_int32_t autoindex_opts = autoindex_conf->opts; char keyid; char direction; char *colargs; char *fullpath; apr_size_t dirpathlen; if ((status = apr_dir_open(&thedir, name, r->pool)) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, "Can't open directory for index: %s", r->filename); return HTTP_FORBIDDEN; }#if APR_HAS_UNICODE_FS ap_set_content_type(r, "text/html;charset=utf-8");#else ap_set_content_type(r, "text/html");#endif if (autoindex_opts & TRACK_MODIFIED) { ap_update_mtime(r, r->finfo.mtime); ap_set_last_modified(r); ap_set_etag(r); } if (r->header_only) { apr_dir_close(thedir)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -