From: Stefan Fritsch Date: Fri, 30 Dec 2011 11:03:17 +0000 (+0000) Subject: merge r1225796: X-Git-Tag: 2.4.0~30 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=441458cecefd1da05c050bfd30e21266d2289839;p=apache merge r1225796: Sort list of modules git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1225801 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/generators/mod_info.c b/modules/generators/mod_info.c index 85d0819f93..360290c7bb 100644 --- a/modules/generators/mod_info.c +++ b/modules/generators/mod_info.c @@ -63,6 +63,7 @@ #include "ap_mpm.h" #include "mpm_common.h" #include +#include typedef struct { @@ -687,11 +688,32 @@ static int show_active_hooks(request_rec * r) return 0; } +static int cmp_module_name(const void *a_, const void *b_) +{ + const module * const *a = a_; + const module * const *b = b_; + return strcmp((*a)->name, (*b)->name); +} + +static apr_array_header_t *get_sorted_modules(apr_pool_t *p) +{ + apr_array_header_t *arr = apr_array_make(p, 64, sizeof(module *)); + module *modp, **entry; + for (modp = ap_top_module; modp; modp = modp->next) { + entry = &APR_ARRAY_PUSH(arr, module *); + *entry = modp; + } + qsort(arr->elts, arr->nelts, sizeof(module *), cmp_module_name); + return arr; +} + static int display_info(request_rec * r) { - module *modp; + module *modp = NULL; const char *more_info; const command_rec *cmd; + apr_array_header_t *modules = NULL; + int i; if (strcmp(r->handler, "server-info")) { return DECLINED; @@ -730,11 +752,12 @@ static int display_info(request_rec * r) ap_rputs("

Loaded Modules

" "
", r); - /* TODO: Sort by Alpha */ - for (modp = ap_top_module; modp; modp = modp->next) { + modules = get_sorted_modules(r->pool); + for (i = 0; i < modules->nelts; i++) { + modp = APR_ARRAY_IDX(modules, i, module *); ap_rprintf(r, "%s", modp->name, modp->name); - if (modp->next) { + if (i < modules->nelts) { ap_rputs(", ", r); } } @@ -756,7 +779,10 @@ static int display_info(request_rec * r) } else { int comma = 0; - for (modp = ap_top_module; modp; modp = modp->next) { + if (!modules) + modules = get_sorted_modules(r->pool); + for (i = 0; i < modules->nelts; i++) { + modp = APR_ARRAY_IDX(modules, i, module *); if (!r->args || !strcasecmp(modp->name, r->args)) { ap_rprintf(r, "
Module Name: " @@ -862,7 +888,9 @@ static int display_info(request_rec * r) } else { ap_rputs("
Server Module List
", r); - for (modp = ap_top_module; modp; modp = modp->next) { + modules = get_sorted_modules(r->pool); + for (i = 0; i < modules->nelts; i++) { + modp = APR_ARRAY_IDX(modules, i, module *); ap_rputs("
", r); ap_rputs(modp->name, r); ap_rputs("
", r);