diff --git a/ChangeLog.txt b/ChangeLog.txt index ef0e1a10..abb98349 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -36,6 +36,8 @@ Broker: - queue_qos0_messages was not observing max_queued_** limits - Add support bridges to be configured to only send notifications to the local broker. +- When using the include_dir configuration option sort the files + alphabetically before loading them. Closes #17. Client library: - Outgoing messages with QoS>1 are no longer retried after a timeout period. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e1916077..4173eabc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,6 +4,7 @@ include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/src set (MOSQ_SRCS conf.c + conf_includedir.c context.c database.c handle_connack.c diff --git a/src/Makefile b/src/Makefile index 8be0277f..af8e4661 100644 --- a/src/Makefile +++ b/src/Makefile @@ -11,6 +11,7 @@ endif OBJS= mosquitto.o \ bridge.o \ conf.o \ + conf_includedir.o \ context.o \ database.o \ handle_connack.o \ @@ -62,10 +63,13 @@ mosquitto.o : mosquitto.c mosquitto_broker_internal.h bridge.o : bridge.c mosquitto_broker_internal.h ${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@ - + conf.o : conf.c mosquitto_broker_internal.h ${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@ - + +conf_includedir.o : conf_includedir.c mosquitto_broker_internal.h + ${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@ + context.o : context.c mosquitto_broker_internal.h ${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@ @@ -119,10 +123,10 @@ net.o : net.c mosquitto_broker_internal.h net_mosq.o : ../lib/net_mosq.c ../lib/net_mosq.h ${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@ - + persist.o : persist.c persist.h mosquitto_broker_internal.h ${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@ - + packet_mosq.o : ../lib/packet_mosq.c ../lib/packet_mosq.h ${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@ diff --git a/src/conf_includedir.c b/src/conf_includedir.c new file mode 100644 index 00000000..73614f79 --- /dev/null +++ b/src/conf_includedir.c @@ -0,0 +1,167 @@ +/* +Copyright (c) 2009-2016 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License v1.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#include + +#include +#include +#include +#include +#include + +#ifdef WIN32 +#else +# include +#endif + +#ifndef WIN32 +# include +# include +#else +# include +# include +#endif + +#if !defined(WIN32) && !defined(__CYGWIN__) +# include +#endif + +#include "mosquitto_broker_internal.h" +#include "memory_mosq.h" +#include "tls_mosq.h" +#include "util_mosq.h" +#include "mqtt3_protocol.h" + +int strcasecmp_p(const void *p1, const void *p2) +{ + return strcasecmp(*(const char **)p1, *(const char **)p2); +} + + +#ifdef WIN32 +int config__get_dir_files(const char *include_dir, char ***files, int *file_count) +{ + char **l_files = NULL; + int l_file_count = 0; + char **files_tmp; + + HANDLE fh; + char dirpath[MAX_PATH]; + WIN32_FIND_DATA find_data; + + snprintf(dirpath, MAX_PATH, "%s\\*.conf", include_dir); + fh = FindFirstFile(dirpath, &find_data); + if(fh == INVALID_HANDLE_VALUE){ + log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to open include_dir '%s'.", include_dir); + return 1; + } + + do{ + len = strlen(include_dir)+1+strlen(find_data.cFileName)+1; + + l_file_count++; + files_tmp = mosquitto__realloc(l_files, l_file_count*sizeof(char *)); + if(!files_tmp){ + for(i=0; id_name) > 5){ + if(!strcmp(&de->d_name[strlen(de->d_name)-5], ".conf")){ + len = strlen(include_dir)+1+strlen(de->d_name)+1; + + l_file_count++; + files_tmp = mosquitto__realloc(l_files, l_file_count*sizeof(char *)); + if(!files_tmp){ + for(i=0; id_name); + l_files[l_file_count-1][len] = '\0'; + } + } + } + closedir(dh); + + *files = l_files; + *file_count = l_file_count; + + return 0; +} +#endif + + diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index 32563425..3256e89e 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -477,6 +477,7 @@ int config__parse_args(struct mosquitto__config *config, int argc, char *argv[]) int config__read(struct mosquitto__config *config, bool reload); /* Free all config data. */ void config__cleanup(struct mosquitto__config *config); +int config__get_dir_files(const char *include_dir, char ***files, int *file_count); int drop_privileges(struct mosquitto__config *config, bool temporary); int restore_privileges(void);