Allow plugins to call mosquitto_log_printf() (Linux only at the moment).

pull/211/merge
Roger A. Light 11 years ago
parent fc1e514ad4
commit 00d951e6d6

@ -120,7 +120,7 @@ LIB_LIBS:=
PASSWD_LIBS:=
ifeq ($(UNAME),Linux)
BROKER_LIBS:=$(BROKER_LIBS) -lrt
BROKER_LIBS:=$(BROKER_LIBS) -lrt -Wl,--dynamic-list=linker.syms
LIB_LIBS:=$(LIB_LIBS) -lrt
endif

@ -2,6 +2,16 @@ include_directories(${mosquitto_SOURCE_DIR} ${mosquitto_SOURCE_DIR}/src
${mosquitto_SOURCE_DIR}/lib ${OPENSSL_INCLUDE_DIR}
${STDBOOL_H_PATH} ${STDINT_H_PATH})
if (UNIX)
set (CMAKE_EXE_LINKER_FLAGS "-Wl,--dynamic-list=${mosquitto_SOURCE_DIR}/src/linker.syms")
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
endif (UNIX)
# FIXME - something else needs fixing before this will work.
#if (APPLE)
# set (CMAKE_EXE_LINKER_FLAGS "-Wl,-exported_symbols_list -Wl,${mosquitto_SOURCE_DIR}/src/linker-macosx.syms")
#endif (APPLE)
set (MOSQ_SRCS
conf.c
context.c

@ -81,9 +81,8 @@ int mqtt3_log_close(void)
return MOSQ_ERR_SUCCESS;
}
int _mosquitto_log_printf(struct mosquitto *mosq, int priority, const char *fmt, ...)
int _mosquitto_log_vprintf(struct mosquitto *mosq, int priority, const char *fmt, va_list va)
{
va_list va;
char *s;
char *st;
int len;
@ -164,9 +163,7 @@ int _mosquitto_log_printf(struct mosquitto *mosq, int priority, const char *fmt,
s = _mosquitto_malloc(len*sizeof(char));
if(!s) return MOSQ_ERR_NOMEM;
va_start(va, fmt);
vsnprintf(s, len, fmt, va);
va_end(va);
s[len-1] = '\0'; /* Ensure string is null terminated. */
if(log_destinations & MQTT3_LOG_STDOUT){
@ -221,3 +218,24 @@ int _mosquitto_log_printf(struct mosquitto *mosq, int priority, const char *fmt,
return MOSQ_ERR_SUCCESS;
}
int _mosquitto_log_printf(struct mosquitto *mosq, int priority, const char *fmt, ...)
{
va_list va;
int rc;
va_start(va, fmt);
rc = _mosquitto_log_vprintf(mosq, priority, fmt, va);
va_end(va);
return rc;
}
void mosquitto_log_printf(int level, const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
_mosquitto_log_vprintf(NULL, level, fmt, va);
va_end(va);
}

@ -36,6 +36,48 @@ struct mosquitto_auth_opt {
* gcc -I<path to mosquitto_plugin.h> -fPIC -shared plugin.c -o plugin.so
*/
/* =========================================================================
*
* Utility Functions
*
* Use these functions from within your plugin.
*
* There are also very useful functions in libmosquitto.
*
* ========================================================================= */
/*
* Function: mosquitto_log_printf
*
* Write a log message using the broker configured logging.
*
* Parameters:
* level - Log message priority. Can currently be one of:
*
* MOSQ_LOG_INFO
* MOSQ_LOG_NOTICE
* MOSQ_LOG_WARNING
* MOSQ_LOG_ERR
* MOSQ_LOG_DEBUG
* MOSQ_LOG_SUBSCRIBE (not recommended for use by plugins)
* MOSQ_LOG_UNSUBSCRIBE (not recommended for use by plugins)
*
* These values are defined in mosquitto.h.
*
* fmt, ... - printf style format and arguments.
*/
void mosquitto_log_printf(int level, const char *fmt, ...);
/* =========================================================================
*
* Plugin Functions
*
* You must implement these functions in your plugin.
*
* ========================================================================= */
/*
* Function: mosquitto_auth_plugin_version
*

Loading…
Cancel
Save