Skip to content

Commit

Permalink
Make include_dir sort usefully case sensitive.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Feb 13, 2019
1 parent 321e566 commit 8350956
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
8 changes: 6 additions & 2 deletions man/mosquitto.conf.5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions mosquitto.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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

# =================================================================
Expand Down
30 changes: 24 additions & 6 deletions src/conf_includedir.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and the Eclipse Distribution License is available at

#include "config.h"

#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -47,12 +48,33 @@ and the Eclipse Distribution License is available at
#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;
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 8350956

Please sign in to comment.