[17] Sort include_dir files before loading them.
Bug: https://github.com/eclipse/mosquitto/issues/17
This commit is contained in:
parent
93464179f1
commit
f72d9b3a34
@ -36,6 +36,8 @@ Broker:
|
|||||||
- queue_qos0_messages was not observing max_queued_** limits
|
- queue_qos0_messages was not observing max_queued_** limits
|
||||||
- Add support bridges to be configured to only send notifications to the local
|
- Add support bridges to be configured to only send notifications to the local
|
||||||
broker.
|
broker.
|
||||||
|
- When using the include_dir configuration option sort the files
|
||||||
|
alphabetically before loading them. Closes #17.
|
||||||
|
|
||||||
Client library:
|
Client library:
|
||||||
- Outgoing messages with QoS>1 are no longer retried after a timeout period.
|
- Outgoing messages with QoS>1 are no longer retried after a timeout period.
|
||||||
|
@ -4,6 +4,7 @@ include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/src
|
|||||||
|
|
||||||
set (MOSQ_SRCS
|
set (MOSQ_SRCS
|
||||||
conf.c
|
conf.c
|
||||||
|
conf_includedir.c
|
||||||
context.c
|
context.c
|
||||||
database.c
|
database.c
|
||||||
handle_connack.c
|
handle_connack.c
|
||||||
|
12
src/Makefile
12
src/Makefile
@ -11,6 +11,7 @@ endif
|
|||||||
OBJS= mosquitto.o \
|
OBJS= mosquitto.o \
|
||||||
bridge.o \
|
bridge.o \
|
||||||
conf.o \
|
conf.o \
|
||||||
|
conf_includedir.o \
|
||||||
context.o \
|
context.o \
|
||||||
database.o \
|
database.o \
|
||||||
handle_connack.o \
|
handle_connack.o \
|
||||||
@ -62,10 +63,13 @@ mosquitto.o : mosquitto.c mosquitto_broker_internal.h
|
|||||||
|
|
||||||
bridge.o : bridge.c mosquitto_broker_internal.h
|
bridge.o : bridge.c mosquitto_broker_internal.h
|
||||||
${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@
|
${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
conf.o : conf.c mosquitto_broker_internal.h
|
conf.o : conf.c mosquitto_broker_internal.h
|
||||||
${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@
|
${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
|
context.o : context.c mosquitto_broker_internal.h
|
||||||
${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@
|
${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
|
net_mosq.o : ../lib/net_mosq.c ../lib/net_mosq.h
|
||||||
${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@
|
${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
persist.o : persist.c persist.h mosquitto_broker_internal.h
|
persist.o : persist.c persist.h mosquitto_broker_internal.h
|
||||||
${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@
|
${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
packet_mosq.o : ../lib/packet_mosq.c ../lib/packet_mosq.h
|
packet_mosq.o : ../lib/packet_mosq.c ../lib/packet_mosq.h
|
||||||
${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@
|
${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
167
src/conf_includedir.c
Normal file
167
src/conf_includedir.c
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2009-2016 Roger Light <roger@atchoo.org>
|
||||||
|
|
||||||
|
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 <config.h>
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#else
|
||||||
|
# include <dirent.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
# include <netdb.h>
|
||||||
|
# include <sys/socket.h>
|
||||||
|
#else
|
||||||
|
# include <winsock2.h>
|
||||||
|
# include <ws2tcpip.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(WIN32) && !defined(__CYGWIN__)
|
||||||
|
# include <sys/syslog.h>
|
||||||
|
#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; i<l_file_count-1; i++){
|
||||||
|
mosquitto__free(l_files[i]);
|
||||||
|
}
|
||||||
|
mosquitto__free(l_files);
|
||||||
|
closedir(dh);
|
||||||
|
return MOSQ_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
l_files = files_tmp;
|
||||||
|
|
||||||
|
l_files[l_file_count-1] = mosquitto__malloc(len+1);
|
||||||
|
if(!l_files[l_file_count-1]){
|
||||||
|
for(i=0; i<l_file_count-1; i++){
|
||||||
|
mosquitto__free(l_files[i]);
|
||||||
|
}
|
||||||
|
mosquitto__free(l_files);
|
||||||
|
closedir(dh);
|
||||||
|
return MOSQ_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
snprintf(l_files[l_file_count-1], len, "%s/%s", include_dir, find_data.cFileName);
|
||||||
|
l_files[l_file_count-1][len] = '\0';
|
||||||
|
}while(FindNextFile(fh, &find_data));
|
||||||
|
|
||||||
|
FindClose(fh);
|
||||||
|
|
||||||
|
*files = l_files;
|
||||||
|
*file_count = l_file_count;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef 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;
|
||||||
|
int len;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
DIR *dh;
|
||||||
|
struct dirent *de;
|
||||||
|
|
||||||
|
dh = opendir(include_dir);
|
||||||
|
if(!dh){
|
||||||
|
log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to open include_dir '%s'.", include_dir);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
while((de = readdir(dh)) != NULL){
|
||||||
|
if(strlen(de->d_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; i<l_file_count-1; i++){
|
||||||
|
mosquitto__free(l_files[i]);
|
||||||
|
}
|
||||||
|
mosquitto__free(l_files);
|
||||||
|
closedir(dh);
|
||||||
|
return MOSQ_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
l_files = files_tmp;
|
||||||
|
|
||||||
|
l_files[l_file_count-1] = mosquitto__malloc(len+1);
|
||||||
|
if(!l_files[l_file_count-1]){
|
||||||
|
for(i=0; i<l_file_count-1; i++){
|
||||||
|
mosquitto__free(l_files[i]);
|
||||||
|
}
|
||||||
|
mosquitto__free(l_files);
|
||||||
|
closedir(dh);
|
||||||
|
return MOSQ_ERR_NOMEM;
|
||||||
|
}
|
||||||
|
snprintf(l_files[l_file_count-1], len, "%s/%s", include_dir, de->d_name);
|
||||||
|
l_files[l_file_count-1][len] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(dh);
|
||||||
|
|
||||||
|
*files = l_files;
|
||||||
|
*file_count = l_file_count;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
@ -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);
|
int config__read(struct mosquitto__config *config, bool reload);
|
||||||
/* Free all config data. */
|
/* Free all config data. */
|
||||||
void config__cleanup(struct mosquitto__config *config);
|
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 drop_privileges(struct mosquitto__config *config, bool temporary);
|
||||||
int restore_privileges(void);
|
int restore_privileges(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user