Make include_dir sort usefully case sensitive.

This commit is contained in:
Roger A. Light 2019-02-13 22:39:02 +00:00
parent 321e566af6
commit 8350956a08
3 changed files with 34 additions and 12 deletions

View File

@ -351,13 +351,16 @@
contain the main configuration file.</para>
<para>The configuration files in
<option>include_dir</option> are loaded in case
insensitive alphabetical order.</para>
sensitive alphabetical order, with the upper case of
each letter ordered before the lower case of the same
letter.</para>
<example title="Load Order for include_dir" label="Load Order for include_dir">
<para>Given the files
<replaceable>b.conf</replaceable>,
<replaceable>A.conf</replaceable>,
<replaceable>01.conf</replaceable>,
<replaceable>a.conf</replaceable>, and
<replaceable>a.conf</replaceable>,
<replaceable>B.conf</replaceable>, and
<replaceable>00.conf</replaceable> inside
<option>include_dir</option>, the config files
would be loaded in this order:</para>
@ -366,6 +369,7 @@
01.conf
A.conf
a.conf
B.conf
b.conf
</programlisting></example>
<para>If this option is used multiple times, then each

View File

@ -872,10 +872,10 @@
# in the main file. This option will only be processed from the main
# configuration file. The directory specified must not contain the
# main configuration file.
# Files within include_dir will be loaded sorted in case-insensitive
# alphabetical order. If this option is given multiple times, all of the files
# from the first instance will be processed before the next instance. See the
# man page for examples.
# Files within include_dir will be loaded sorted in case-sensitive
# alphabetical order, with capital letters ordered first. If this option is
# given multiple times, all of the files from the first instance will be
# processed before the next instance. See the man page for examples.
#include_dir
# =================================================================

View File

@ -16,6 +16,7 @@ Contributors:
#include "config.h"
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
@ -47,12 +48,33 @@ Contributors:
#include "mqtt3_protocol.h"
#ifdef WIN32
int scmp_p(const void *p1, const void *p2)
{
return strcasecmp(*(const char **)p1, *(const char **)p2);
const char *s1 = *(const char **)p1;
const char *s2 = *(const char **)p2;
int result;
while(s1[0] && s2[0]){
/* Sort by case insensitive part first */
result = toupper(s1[0]) - toupper(s2[0]);
if(result == 0){
/* Case insensitive part matched, now distinguish between case */
result = s1[0] - s2[0];
if(result != 0){
return result;
}
}else{
/* Return case insensitive match fail */
return result;
}
s1++;
s2++;
}
return s1[0] - s2[0];
}
#ifdef WIN32
int config__get_dir_files(const char *include_dir, char ***files, int *file_count)
{
int len;
@ -112,10 +134,6 @@ int config__get_dir_files(const char *include_dir, char ***files, int *file_coun
#ifndef WIN32
int scmp_p(const void *p1, const void *p2)
{
return strcmp(*(const char **)p1, *(const char **)p2);
}
int config__get_dir_files(const char *include_dir, char ***files, int *file_count)
{