From 9c6a5f3cf0ff6d70f3579257620ce8ace5d1eba6 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sat, 6 Jan 2018 22:42:13 +0000 Subject: [PATCH] [656] Fix building on Windows. Thanks to Arun Kirthi Cherian. Bug: https://github.com/eclipse/mosquitto/issues/656 --- client/client_shared.c | 1 + lib/CMakeLists.txt | 21 ++++++++++----------- lib/cpp/CMakeLists.txt | 27 +++++++++++---------------- lib/mosquitto.h | 2 +- src/conf_includedir.c | 6 ++++-- src/handle_connect.c | 2 +- src/mosquitto_broker_internal.h | 4 +++- src/mosquitto_passwd.c | 15 +++++++++++---- src/signals.c | 21 +++++++++++---------- src/sys_tree.h | 8 ++++---- 10 files changed, 57 insertions(+), 50 deletions(-) diff --git a/client/client_shared.c b/client/client_shared.c index 4d1882c5..b8c8bdfc 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -26,6 +26,7 @@ Contributors: #include #include #define snprintf sprintf_s +#define strncasecmp _strnicmp #endif #include diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index abb1fcc5..7cb06035 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,5 +1,5 @@ -option(WITH_STATIC_LIBRARIES "Build the static libraries?" ON) -option(WITH_PIC "Build the static library with PIC(Position Independent Code) enabled archives?" OFF) +option(WITH_STATIC_LIBRARIES "Build static versions of the libmosquitto/pp libraries?" OFF) +option(WITH_PIC "Build the static library with PIC (Position Independent Code) enabled archives?" OFF) add_subdirectory(cpp) option(WITH_THREADING "Include client library threading support?" ON) @@ -90,13 +90,11 @@ if (${WITH_SRV} STREQUAL ON) endif (ARES_HEADER) endif (${WITH_SRV} STREQUAL ON) -add_library(libmosquitto_obj OBJECT ${C_SRC}) -set_target_properties(libmosquitto_obj PROPERTIES +add_library(libmosquitto SHARED ${C_SRC}) +set_target_properties(libmosquitto PROPERTIES POSITION_INDEPENDENT_CODE 1 ) -add_library(libmosquitto SHARED $) - target_link_libraries(libmosquitto ${LIBRARIES}) set_target_properties(libmosquitto PROPERTIES @@ -108,11 +106,12 @@ set_target_properties(libmosquitto PROPERTIES install(TARGETS libmosquitto RUNTIME DESTINATION "${BINDIR}" LIBRARY DESTINATION "${LIBDIR}") if (${WITH_STATIC_LIBRARIES} STREQUAL ON) - if (${WITH_PIC} STREQUAL OFF) - add_library(libmosquitto_static STATIC ${C_SRC}) - else (${WITH_PIC} STREQUAL OFF) - add_library(libmosquitto_static STATIC $) - endif (${WITH_PIC} STREQUAL OFF) + add_library(libmosquitto_static STATIC ${C_SRC}) + if (${WITH_PIC} STREQUAL ON) + set_target_properties(libmosquitto_static PROPERTIES + POSITION_INDEPENDENT_CODE 1 + ) + endif (${WITH_PIC} STREQUAL ON) target_link_libraries(libmosquitto_static ${LIBRARIES}) diff --git a/lib/cpp/CMakeLists.txt b/lib/cpp/CMakeLists.txt index 8eb19bfc..5e4f08ea 100644 --- a/lib/cpp/CMakeLists.txt +++ b/lib/cpp/CMakeLists.txt @@ -2,15 +2,12 @@ include_directories(${mosquitto_SOURCE_DIR}/lib ${mosquitto_SOURCE_DIR}/lib/cpp ${STDBOOL_H_PATH} ${STDINT_H_PATH}) link_directories(${mosquitto_BINARY_DIR}/lib) -set(C_SRC mosquittopp.cpp mosquittopp.h) +set(CPP_SRC mosquittopp.cpp mosquittopp.h) -add_library(mosquittopp_obj OBJECT ${C_SRC}) -set_target_properties(mosquittopp_obj PROPERTIES +add_library(mosquittopp SHARED ${CPP_SRC}) +set_target_properties(mosquittopp PROPERTIES POSITION_INDEPENDENT_CODE 1 ) - -add_library(mosquittopp SHARED $) - target_link_libraries(mosquittopp libmosquitto) set_target_properties(mosquittopp PROPERTIES VERSION ${VERSION} @@ -19,17 +16,15 @@ set_target_properties(mosquittopp PROPERTIES install(TARGETS mosquittopp RUNTIME DESTINATION "${BINDIR}" LIBRARY DESTINATION "${LIBDIR}") if (${WITH_STATIC_LIBRARIES} STREQUAL ON) - if (${WITH_PIC} STREQUAL OFF) - add_library(mosquittopp_static STATIC - $ - ${C_SRC} + add_library(mosquittopp_static STATIC + ${C_SRC} + ${CPP_SRC} + ) + if (${WITH_PIC} STREQUAL ON) + set_target_properties(mosquittopp_static PROPERTIES + POSITION_INDEPENDENT_CODE 1 ) - else (${WITH_PIC} STREQUAL OFF) - add_library(mosquittopp_static STATIC - $ - $ - ) - endif (${WITH_PIC} STREQUAL OFF) + endif (${WITH_PIC} STREQUAL ON) target_link_libraries(mosquittopp_static ${LIBRARIES}) diff --git a/lib/mosquitto.h b/lib/mosquitto.h index 0f8154aa..dcae11d0 100644 --- a/lib/mosquitto.h +++ b/lib/mosquitto.h @@ -31,7 +31,7 @@ extern "C" { # define libmosq_EXPORT #endif -#ifdef WIN32 +#if defined(_MSC_VER) && _MSC_VER < 1900 # ifndef __cplusplus # define bool char # define true 1 diff --git a/src/conf_includedir.c b/src/conf_includedir.c index 73614f79..4a528d52 100644 --- a/src/conf_includedir.c +++ b/src/conf_includedir.c @@ -54,6 +54,8 @@ int strcasecmp_p(const void *p1, const void *p2) #ifdef WIN32 int config__get_dir_files(const char *include_dir, char ***files, int *file_count) { + int len; + int i; char **l_files = NULL; int l_file_count = 0; char **files_tmp; @@ -79,7 +81,7 @@ int config__get_dir_files(const char *include_dir, char ***files, int *file_coun mosquitto__free(l_files[i]); } mosquitto__free(l_files); - closedir(dh); + FindClose(fh); return MOSQ_ERR_NOMEM; } l_files = files_tmp; @@ -90,7 +92,7 @@ int config__get_dir_files(const char *include_dir, char ***files, int *file_coun mosquitto__free(l_files[i]); } mosquitto__free(l_files); - closedir(dh); + FindClose(fh); return MOSQ_ERR_NOMEM; } snprintf(l_files[l_file_count-1], len, "%s/%s", include_dir, find_data.cFileName); diff --git a/src/handle_connect.c b/src/handle_connect.c index 6100ccf6..b9c755a9 100644 --- a/src/handle_connect.c +++ b/src/handle_connect.c @@ -407,7 +407,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context) } name_entry = X509_NAME_get_entry(name, i); if(name_entry){ - context->username = mosquitto__strdup((char *)ASN1_STRING_data(name_entry->value)); + context->username = mosquitto__strdup((char *)X509_NAME_ENTRY_get_data(name_entry)); } } else { // use_subject_as_username BIO *subject_bio = BIO_new(BIO_s_mem()); diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index 3508c555..77a10fa4 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -603,12 +603,14 @@ int mosquitto_unpwd_check_default(struct mosquitto_db *db, const char *username, int mosquitto_psk_key_get_default(struct mosquitto_db *db, const char *hint, const char *identity, char *key, int max_key_len); /* ============================================================ - * Window service related functions + * Window service and signal related functions * ============================================================ */ #if defined(WIN32) || defined(__CYGWIN__) void service_install(void); void service_uninstall(void); void service_run(void); + +DWORD WINAPI SigThreadProc(void* data); #endif /* ============================================================ diff --git a/src/mosquitto_passwd.c b/src/mosquitto_passwd.c index aef8cd05..7ce18820 100644 --- a/src/mosquitto_passwd.c +++ b/src/mosquitto_passwd.c @@ -23,15 +23,22 @@ Contributors: #include #include #include + + #ifdef WIN32 -# include +# include # ifndef __cplusplus -# define bool char -# define true 1 -# define false 0 +# if defined(_MSC_VER) && _MSC_VER < 1900 +# define bool char +# define true 1 +# define false 0 +# else +# include +# endif # endif # define snprintf sprintf_s # include +# include #else # include # include diff --git a/src/signals.c b/src/signals.c index a4154c7d..a068b159 100644 --- a/src/signals.c +++ b/src/signals.c @@ -120,16 +120,17 @@ DWORD WINAPI SigThreadProc(void* data) while (true) { int wr = WaitForMultipleObjects(sizeof(evt) / sizeof(HANDLE), evt, FALSE, INFINITE); switch (wr) { - case WAIT_OBJECT_0 + 0: - handle_sigint(SIGINT); - break; - case WAIT_OBJECT_0 + 1: - flag_reload = true; - continue; - case WAIT_OBJECT_0 + 2: - handle_sigusr1(0); - continue; - break; + case WAIT_OBJECT_0 + 0: + handle_sigint(SIGINT); + break; + case WAIT_OBJECT_0 + 1: + flag_reload = true; + continue; + case WAIT_OBJECT_0 + 2: + handle_sigusr1(0); + continue; + break; + } } CloseHandle(evt[0]); CloseHandle(evt[1]); diff --git a/src/sys_tree.h b/src/sys_tree.h index 97331265..077e6a1c 100644 --- a/src/sys_tree.h +++ b/src/sys_tree.h @@ -39,10 +39,10 @@ extern unsigned int g_connection_count; #define G_MSGS_SENT_INC(A) (g_msgs_sent+=(A)) #define G_PUB_MSGS_RECEIVED_INC(A) (g_pub_msgs_received+=(A)) #define G_PUB_MSGS_SENT_INC(A) (g_pub_msgs_sent+=(A)) -#define G_MSGS_DROPPED_INC(A) (g_msgs_dropped++) -#define G_CLIENTS_EXPIRED_INC(A) (g_clients_expired++) -#define G_SOCKET_CONNECTIONS_INC(A) (g_socket_connections++) -#define G_CONNECTION_COUNT_INC(A) (g_connection_count++) +#define G_MSGS_DROPPED_INC() (g_msgs_dropped++) +#define G_CLIENTS_EXPIRED_INC() (g_clients_expired++) +#define G_SOCKET_CONNECTIONS_INC() (g_socket_connections++) +#define G_CONNECTION_COUNT_INC() (g_connection_count++) #else