Add case insensitive name sorting support
Add the fancyindex_case_sensitive option which consider the case when sorting by name if it is on (default option to keep current behavior) and does an case insensitive name sorting if it is offpull/124/head
parent
566ad22a61
commit
19491a6a84
|
@ -142,6 +142,15 @@ fancyindex_default_sort
|
|||
:Description:
|
||||
Defines sorting criterion by default.
|
||||
|
||||
fancyindex_case_sensitive
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
:Syntax: *fancyindex_case_sensitive* [*on* | *off*]
|
||||
:Default: fancyindex_case_sensitive on
|
||||
:Context: http, server, location
|
||||
:Description:
|
||||
If enabled (default setting), sorting by name will be case sensitive.
|
||||
If disabled, case will be ignored when applying a sort by name.
|
||||
|
||||
fancyindex_directories_first
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
:Syntax: *fancyindex_directories_first* [*on* | *off*]
|
||||
|
|
|
@ -152,6 +152,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
ngx_flag_t enable; /**< Module is enabled. */
|
||||
ngx_uint_t default_sort; /**< Default sort criterion. */
|
||||
ngx_flag_t case_sensitive; /**< Case sensitive name sorting */
|
||||
ngx_flag_t dirs_first; /**< Group directories together first when sorting */
|
||||
ngx_flag_t localtime; /**< File mtime dates are sent in local time. */
|
||||
ngx_flag_t exact_size; /**< Sizes are sent always in bytes. */
|
||||
|
@ -187,6 +188,8 @@ static ngx_conf_enum_t ngx_http_fancyindex_sort_criteria[] = {
|
|||
{ ngx_null_string, 0 }
|
||||
};
|
||||
|
||||
ngx_flag_t case_sensitive = 1;
|
||||
|
||||
enum {
|
||||
NGX_HTTP_FANCYINDEX_HEADERFOOTER_SUBREQUEST,
|
||||
NGX_HTTP_FANCYINDEX_HEADERFOOTER_LOCAL,
|
||||
|
@ -391,6 +394,13 @@ static ngx_command_t ngx_http_fancyindex_commands[] = {
|
|||
offsetof(ngx_http_fancyindex_loc_conf_t, default_sort),
|
||||
&ngx_http_fancyindex_sort_criteria },
|
||||
|
||||
{ ngx_string("fancyindex_case_sensitive"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
||||
ngx_conf_set_flag_slot,
|
||||
NGX_HTTP_LOC_CONF_OFFSET,
|
||||
offsetof(ngx_http_fancyindex_loc_conf_t, case_sensitive),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("fancyindex_directories_first"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
||||
ngx_conf_set_flag_slot,
|
||||
|
@ -1193,6 +1203,8 @@ ngx_http_fancyindex_handler(ngx_http_request_t *r)
|
|||
return NGX_DECLINED;
|
||||
}
|
||||
|
||||
case_sensitive = alcf->case_sensitive;
|
||||
|
||||
if ((rc = make_content_buf(r, &out[0].buf, alcf)) != NGX_OK)
|
||||
return rc;
|
||||
|
||||
|
@ -1360,7 +1372,11 @@ ngx_http_fancyindex_cmp_entries_name_desc(const void *one, const void *two)
|
|||
ngx_http_fancyindex_entry_t *first = (ngx_http_fancyindex_entry_t *) one;
|
||||
ngx_http_fancyindex_entry_t *second = (ngx_http_fancyindex_entry_t *) two;
|
||||
|
||||
return (int) ngx_strcmp(second->name.data, first->name.data);
|
||||
if(case_sensitive) {
|
||||
return (int) ngx_strcmp(second->name.data, first->name.data);
|
||||
} else {
|
||||
return (int) ngx_strcasecmp(second->name.data, first->name.data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1390,7 +1406,11 @@ ngx_http_fancyindex_cmp_entries_name_asc(const void *one, const void *two)
|
|||
ngx_http_fancyindex_entry_t *first = (ngx_http_fancyindex_entry_t *) one;
|
||||
ngx_http_fancyindex_entry_t *second = (ngx_http_fancyindex_entry_t *) two;
|
||||
|
||||
return (int) ngx_strcmp(first->name.data, second->name.data);
|
||||
if(case_sensitive) {
|
||||
return (int) ngx_strcmp(first->name.data, second->name.data);
|
||||
} else {
|
||||
return (int) ngx_strcasecmp(first->name.data, second->name.data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1449,6 +1469,7 @@ ngx_http_fancyindex_create_loc_conf(ngx_conf_t *cf)
|
|||
*/
|
||||
conf->enable = NGX_CONF_UNSET;
|
||||
conf->default_sort = NGX_CONF_UNSET_UINT;
|
||||
conf->case_sensitive = NGX_CONF_UNSET;
|
||||
conf->dirs_first = NGX_CONF_UNSET;
|
||||
conf->localtime = NGX_CONF_UNSET;
|
||||
conf->name_length = NGX_CONF_UNSET_UINT;
|
||||
|
@ -1473,6 +1494,7 @@ ngx_http_fancyindex_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||
|
||||
ngx_conf_merge_value(conf->enable, prev->enable, 0);
|
||||
ngx_conf_merge_uint_value(conf->default_sort, prev->default_sort, NGX_HTTP_FANCYINDEX_SORT_CRITERION_NAME);
|
||||
ngx_conf_merge_value(conf->case_sensitive, prev->case_sensitive, 1);
|
||||
ngx_conf_merge_value(conf->dirs_first, prev->dirs_first, 1);
|
||||
ngx_conf_merge_value(conf->localtime, prev->localtime, 0);
|
||||
ngx_conf_merge_value(conf->exact_size, prev->exact_size, 1);
|
||||
|
|
Loading…
Reference in New Issue