Skip to content

Commit

Permalink
Various Windows build fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Dec 2, 2020
1 parent 71845d2 commit 26ffe13
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 26 deletions.
2 changes: 2 additions & 0 deletions apps/mosquitto_ctrl/dynsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ SPDX-License-Identifier: EPL-2.0 OR EDL-1.0
Contributors:
Roger Light - initial implementation and documentation.
*/
#include "config.h"

#include <cJSON.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
2 changes: 2 additions & 0 deletions apps/mosquitto_ctrl/dynsec_role.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ SPDX-License-Identifier: EPL-2.0 OR EDL-1.0
Contributors:
Roger Light - initial implementation and documentation.
*/
#include "config.h"

#include <cJSON.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
1 change: 1 addition & 0 deletions apps/mosquitto_ctrl/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ static char *get_default_cfg_location(void)
char *env;
#else
char env[1024];
int rc;
#endif

#ifndef WIN32
Expand Down
2 changes: 1 addition & 1 deletion client/sub_client_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ static int json_print(const struct mosquitto_message *message, const mosquitto_p
return_parse_end = NULL;
if(message->payload){
tmp = cJSON_ParseWithOpts(message->payload, &return_parse_end, true);
if(tmp == NULL || return_parse_end != message->payload + message->payloadlen){
if(tmp == NULL || return_parse_end != (uint8_t *)message->payload + message->payloadlen){
cJSON_Delete(root);
return MOSQ_ERR_INVAL;
}
Expand Down
23 changes: 16 additions & 7 deletions include/mosquitto.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,23 @@ SPDX-License-Identifier: EPL-2.0 OR EDL-1.0
extern "C" {
#endif

#if defined(WIN32) && !defined(WITH_BROKER) && !defined(LIBMOSQUITTO_STATIC)
# ifdef libmosquitto_EXPORTS
# define libmosq_EXPORT __declspec(dllexport)
# else
# define libmosq_EXPORT __declspec(dllimport)
# endif

#ifdef WIN32
# ifdef mosquitto_EXPORTS
# define libmosq_EXPORT __declspec(dllexport)
# else
# ifndef LIBMOSQUITTO_STATIC
# ifdef libmosquitto_EXPORTS
# define libmosq_EXPORT __declspec(dllexport)
# else
# define libmosq_EXPORT __declspec(dllimport)
# endif
# else
# define libmosq_EXPORT
# endif
# endif
#else
# define libmosq_EXPORT
# define libmosq_EXPORT
#endif

#if defined(_MSC_VER) && _MSC_VER < 1900
Expand Down
30 changes: 17 additions & 13 deletions include/mosquitto_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ struct mosquitto_acl_msg {
bool retain;
};

#ifdef WIN32
# define mosq_plugin_EXPORT __declspec(dllexport)
#endif

/*
* To create an authentication plugin you must include this file then implement
* the functions listed in the "Plugin Functions" section below. The resulting
Expand Down Expand Up @@ -129,7 +133,7 @@ struct mosquitto_acl_msg {
* If the broker does not support the version that you require, return -1 to
* indicate failure.
*/
int mosquitto_plugin_version(int supported_version_count, const int *supported_versions);
mosq_plugin_EXPORT int mosquitto_plugin_version(int supported_version_count, const int *supported_versions);

/*
* Function: mosquitto_auth_plugin_init
Expand All @@ -152,7 +156,7 @@ int mosquitto_plugin_version(int supported_version_count, const int *supported_v
* Return 0 on success
* Return >0 on failure.
*/
int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, void **userdata, struct mosquitto_opt *options, int option_count);
mosq_plugin_EXPORT int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, void **userdata, struct mosquitto_opt *options, int option_count);


/*
Expand All @@ -172,7 +176,7 @@ int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, void **userdata, st
* Return 0 on success
* Return >0 on failure.
*/
int mosquitto_plugin_cleanup(void *userdata, struct mosquitto_opt *options, int option_count);
mosq_plugin_EXPORT int mosquitto_plugin_cleanup(void *userdata, struct mosquitto_opt *options, int option_count);



Expand All @@ -195,7 +199,7 @@ int mosquitto_plugin_cleanup(void *userdata, struct mosquitto_opt *options, int
* check it is a supported plugin version. Your code must simply return
* the version of the plugin interface you support, i.e. 4.
*/
int mosquitto_auth_plugin_version(void);
mosq_plugin_EXPORT int mosquitto_auth_plugin_version(void);


/*
Expand All @@ -217,7 +221,7 @@ int mosquitto_auth_plugin_version(void);
* Return 0 on success
* Return >0 on failure.
*/
int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *opts, int opt_count);
mosq_plugin_EXPORT int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *opts, int opt_count);


/*
Expand All @@ -239,7 +243,7 @@ int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *opts, int
* Return 0 on success
* Return >0 on failure.
*/
int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *opts, int opt_count);
mosq_plugin_EXPORT int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *opts, int opt_count);


/*
Expand Down Expand Up @@ -267,7 +271,7 @@ int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *opts, i
* Return 0 on success
* Return >0 on failure.
*/
int mosquitto_auth_security_init(void *user_data, struct mosquitto_opt *opts, int opt_count, bool reload);
mosq_plugin_EXPORT int mosquitto_auth_security_init(void *user_data, struct mosquitto_opt *opts, int opt_count, bool reload);


/*
Expand Down Expand Up @@ -295,7 +299,7 @@ int mosquitto_auth_security_init(void *user_data, struct mosquitto_opt *opts, in
* Return 0 on success
* Return >0 on failure.
*/
int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_opt *opts, int opt_count, bool reload);
mosq_plugin_EXPORT int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_opt *opts, int opt_count, bool reload);


/*
Expand All @@ -322,7 +326,7 @@ int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_opt *opts,
* MOSQ_ERR_UNKNOWN for an application specific error.
* MOSQ_ERR_PLUGIN_DEFER if your plugin does not wish to handle this check.
*/
int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *client, const struct mosquitto_acl_msg *msg);
mosq_plugin_EXPORT int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *client, const struct mosquitto_acl_msg *msg);


/*
Expand All @@ -339,7 +343,7 @@ int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *clie
* MOSQ_ERR_UNKNOWN for an application specific error.
* MOSQ_ERR_PLUGIN_DEFER if your plugin does not wish to handle this check.
*/
int mosquitto_auth_unpwd_check(void *user_data, struct mosquitto *client, const char *username, const char *password);
mosq_plugin_EXPORT int mosquitto_auth_unpwd_check(void *user_data, struct mosquitto *client, const char *username, const char *password);


/*
Expand Down Expand Up @@ -367,7 +371,7 @@ int mosquitto_auth_unpwd_check(void *user_data, struct mosquitto *client, const
* Return >0 on failure.
* Return MOSQ_ERR_PLUGIN_DEFER if your plugin does not wish to handle this check.
*/
int mosquitto_auth_psk_key_get(void *user_data, struct mosquitto *client, const char *hint, const char *identity, char *key, int max_key_len);
mosq_plugin_EXPORT int mosquitto_auth_psk_key_get(void *user_data, struct mosquitto *client, const char *hint, const char *identity, char *key, int max_key_len);

/*
* Function: mosquitto_auth_start
Expand All @@ -394,9 +398,9 @@ int mosquitto_auth_psk_key_get(void *user_data, struct mosquitto *client, const
* Return MOSQ_ERR_AUTH if authentication was valid but did not succeed.
* Return any other relevant positive integer MOSQ_ERR_* to produce an error.
*/
int mosquitto_auth_start(void *user_data, struct mosquitto *client, const char *method, bool reauth, const void *data_in, uint16_t data_in_len, void **data_out, uint16_t *data_out_len);
mosq_plugin_EXPORT int mosquitto_auth_start(void *user_data, struct mosquitto *client, const char *method, bool reauth, const void *data_in, uint16_t data_in_len, void **data_out, uint16_t *data_out_len);

int mosquitto_auth_continue(void *user_data, struct mosquitto *client, const char *method, const void *data_in, uint16_t data_in_len, void **data_out, uint16_t *data_out_len);
mosq_plugin_EXPORT int mosquitto_auth_continue(void *user_data, struct mosquitto *client, const char *method, const void *data_in, uint16_t data_in_len, void **data_out, uint16_t *data_out_len);


#ifdef __cplusplus
Expand Down
4 changes: 3 additions & 1 deletion plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
add_subdirectory(dynamic-security)
add_subdirectory(message-timestamp)
if(NOT WIN32)
add_subdirectory(message-timestamp)
endif(NOT WIN32)
add_subdirectory(payload-modification)
5 changes: 4 additions & 1 deletion plugins/dynamic-security/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (CJSON_FOUND AND WITH_TLS)
set( CLIENT_DIR ${mosquitto_BINARY_DIR}/lib ${CJSON_DIR})

include_directories(${CLIENT_INC})
link_directories(${CLIENT_DIR})
link_directories(${CLIENT_DIR} ${mosquitto_SOURCE_DIR})

add_library(mosquitto_dynamic_security SHARED
acl.c
Expand All @@ -33,6 +33,9 @@ if (CJSON_FOUND AND WITH_TLS)
set_target_properties(mosquitto_dynamic_security PROPERTIES PREFIX "")

target_link_libraries(mosquitto_dynamic_security ${CJSON_LIBRARIES})
if(WIN32)
target_link_libraries(mosquitto_dynamic_security mosquitto)
endif(WIN32)

install(TARGETS mosquitto_dynamic_security RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
endif()
4 changes: 4 additions & 0 deletions plugins/payload-modification/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/include
${STDBOOL_H_PATH} ${STDINT_H_PATH})
link_directories(${mosquitto_SOURCE_DIR})

add_library(mosquitto_payload_modification SHARED mosquitto_payload_modification.c)
set_target_properties(mosquitto_payload_modification PROPERTIES
POSITION_INDEPENDENT_CODE 1
)
set_target_properties(mosquitto_payload_modification PROPERTIES PREFIX "")
if(WIN32)
target_link_libraries(mosquitto_payload_modification mosquitto)
endif(WIN32)

install(TARGETS mosquitto_payload_modification RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
4 changes: 4 additions & 0 deletions src/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,11 @@ void log__internal(const char *fmt, ...)
return;
}

#ifdef WIN32
log__printf(NULL, MOSQ_LOG_INTERNAL, "%s", buf);
#else
log__printf(NULL, MOSQ_LOG_INTERNAL, "%s%s%s", "\e[32m", buf, "\e[0m");
#endif
}

int mosquitto_log_vprintf(int level, const char *fmt, va_list va)
Expand Down
1 change: 1 addition & 0 deletions src/memory_public.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ SPDX-License-Identifier: EPL-2.0 OR EDL-1.0
Roger Light - initial implementation and documentation.
*/

#include "mosquitto_broker.h"
#include "memory_mosq.h"

void *mosquitto_calloc(size_t nmemb, size_t size)
Expand Down
2 changes: 1 addition & 1 deletion src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static unsigned int psk_server_callback(SSL *ssl, const char *identity, unsigned

/* The hex to BN conversion results in the length halving, so we can pass
* max_psk_len*2 as the max hex key here. */
psk_key = mosquitto__calloc(1, max_psk_len*2 + 1);
psk_key = mosquitto__calloc(1, (size_t)max_psk_len*2 + 1);
if(!psk_key) return 0;

if(mosquitto_psk_key_get(context, psk_hint, identity, psk_key, (int)max_psk_len*2) != MOSQ_ERR_SUCCESS){
Expand Down
4 changes: 2 additions & 2 deletions src/retain.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ int retain__init(void)
{
struct mosquitto__retainhier *retainhier;

retainhier = retain__add_hier_entry(NULL, &db.retains, "", strlen(""));
retainhier = retain__add_hier_entry(NULL, &db.retains, "", (int)strlen(""));
if(!retainhier) return MOSQ_ERR_NOMEM;

retainhier = retain__add_hier_entry(NULL, &db.retains, "$SYS", strlen("$SYS"));
retainhier = retain__add_hier_entry(NULL, &db.retains, "$SYS", (int)strlen("$SYS"));
if(!retainhier) return MOSQ_ERR_NOMEM;

return MOSQ_ERR_SUCCESS;
Expand Down
7 changes: 7 additions & 0 deletions src/signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ SPDX-License-Identifier: EPL-2.0 OR EDL-1.0
Roger Light - initial implementation and documentation.
Dmitry Kaukov - windows named events implementation.
*/
#ifdef WIN32
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h>
#endif

#include "config.h"

#include <stdio.h>
#include <stdbool.h>
#include <signal.h>

Expand Down

0 comments on commit 26ffe13

Please sign in to comment.