mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-08-20 21:41:40 +08:00
Strict build fixes.
This commit is contained in:
@@ -19,6 +19,7 @@ Contributors:
|
||||
#include "config.h"
|
||||
#include <pthread.h>
|
||||
|
||||
#include "callbacks.h"
|
||||
#include "mosquitto.h"
|
||||
#include "mosquitto_internal.h"
|
||||
|
||||
|
||||
@@ -49,15 +49,14 @@ static mosquitto_plugin_id_t *mosq_pid = NULL;
|
||||
static int callback_message(int event, void *event_data, void *userdata)
|
||||
{
|
||||
struct mosquitto_evt_message *ed = event_data;
|
||||
int result;
|
||||
struct timespec ts;
|
||||
char ts_buf[TS_BUF_LEN];
|
||||
|
||||
UNUSED(event);
|
||||
UNUSED(userdata);
|
||||
|
||||
int result;
|
||||
|
||||
// Add timestamp in unix epoch (ms)
|
||||
struct timespec ts;
|
||||
char ts_buf[TS_BUF_LEN];
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
snprintf(ts_buf, TS_BUF_LEN, "%li%03lu", ts.tv_sec, ts.tv_nsec / 1000 / 1000);
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ Contributors:
|
||||
#include "mosquitto.h"
|
||||
#include "mqtt_protocol.h"
|
||||
|
||||
#define UNUSED(A) (void)(A)
|
||||
|
||||
static mosquitto_plugin_id_t *mosq_pid = NULL;
|
||||
|
||||
static int connect_callback(int event, void *event_data, void *userdata)
|
||||
@@ -49,9 +51,12 @@ static int connect_callback(int event, void *event_data, void *userdata)
|
||||
char topic[1024];
|
||||
int len;
|
||||
|
||||
UNUSED(event);
|
||||
UNUSED(userdata);
|
||||
|
||||
client_id = mosquitto_client_id(ed->client);
|
||||
len = snprintf(topic, sizeof(topic), "$SYS/broker/connection/client/%s/state", client_id);
|
||||
if(len < sizeof(topic)){
|
||||
if(len < (int)sizeof(topic)){
|
||||
mosquitto_broker_publish_copy(NULL, topic, 1, "1", 0, true, NULL);
|
||||
}else{
|
||||
/* client id too large */
|
||||
@@ -69,9 +74,12 @@ static int disconnect_callback(int event, void *event_data, void *userdata)
|
||||
mosquitto_property *proplist = NULL;
|
||||
int rc;
|
||||
|
||||
UNUSED(event);
|
||||
UNUSED(userdata);
|
||||
|
||||
client_id = mosquitto_client_id(ed->client);
|
||||
len = snprintf(topic, sizeof(topic), "$SYS/broker/connection/client/%s/state", client_id);
|
||||
if(len < sizeof(topic)){
|
||||
if(len < (int)sizeof(topic)){
|
||||
/* Expire our "disconnected" message after a day. */
|
||||
mosquitto_property_add_int32(&proplist, MQTT_PROP_MESSAGE_EXPIRY_INTERVAL, 86400);
|
||||
rc = mosquitto_broker_publish_copy(NULL, topic, 1, "0", 0, true, proplist);
|
||||
@@ -102,6 +110,10 @@ int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, void **user_data, s
|
||||
{
|
||||
int rc;
|
||||
|
||||
UNUSED(user_data);
|
||||
UNUSED(opts);
|
||||
UNUSED(opt_count);
|
||||
|
||||
mosq_pid = identifier;
|
||||
|
||||
rc = mosquitto_callback_register(mosq_pid, MOSQ_EVT_CONNECT, connect_callback, NULL, NULL);
|
||||
@@ -112,6 +124,10 @@ int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, void **user_data, s
|
||||
|
||||
int mosquitto_plugin_cleanup(void *user_data, struct mosquitto_opt *opts, int opt_count)
|
||||
{
|
||||
UNUSED(user_data);
|
||||
UNUSED(opts);
|
||||
UNUSED(opt_count);
|
||||
|
||||
mosquitto_callback_unregister(mosq_pid, MOSQ_EVT_CONNECT, connect_callback, NULL);
|
||||
return mosquitto_callback_unregister(mosq_pid, MOSQ_EVT_DISCONNECT, disconnect_callback, NULL);
|
||||
}
|
||||
|
||||
+3
-5
@@ -161,18 +161,16 @@ void bridge__start_all(void)
|
||||
}
|
||||
}
|
||||
|
||||
int bridge__set_tcp_keepalive(struct mosquitto *context)
|
||||
static int bridge__set_tcp_keepalive(struct mosquitto *context)
|
||||
{
|
||||
unsigned int idle = context->bridge->tcp_keepalive_idle;
|
||||
unsigned int interval = context->bridge->tcp_keepalive_interval;
|
||||
unsigned int counter = context->bridge->tcp_keepalive_counter;
|
||||
unsigned int enabled = 1;
|
||||
bool ret;
|
||||
|
||||
if (idle == 0 || interval == 0 || counter == 0) return MOSQ_ERR_SUCCESS;
|
||||
|
||||
unsigned int enabled = 1;
|
||||
|
||||
bool ret;
|
||||
|
||||
#ifdef WIN32
|
||||
ret =
|
||||
setsockopt(context->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&enabled, sizeof(enabled)) ||
|
||||
|
||||
+21
-19
@@ -22,6 +22,7 @@ Contributors:
|
||||
#include "mosquitto_broker_internal.h"
|
||||
|
||||
static int listensock_index = 0;
|
||||
extern int g_run;
|
||||
|
||||
void listener__set_defaults(struct mosquitto__listener *listener)
|
||||
{
|
||||
@@ -64,21 +65,21 @@ static int listeners__start_single_mqtt(struct mosquitto__listener *listener)
|
||||
if(net__socket_listen(listener)){
|
||||
return 1;
|
||||
}
|
||||
listensock_count += listener->sock_count;
|
||||
listensock_new = mosquitto__realloc(listensock, sizeof(struct mosquitto__listener_sock)*(size_t)listensock_count);
|
||||
g_listensock_count += listener->sock_count;
|
||||
listensock_new = mosquitto__realloc(g_listensock, sizeof(struct mosquitto__listener_sock)*(size_t)g_listensock_count);
|
||||
if(!listensock_new){
|
||||
return 1;
|
||||
}
|
||||
listensock = listensock_new;
|
||||
g_listensock = listensock_new;
|
||||
|
||||
for(i=0; i<listener->sock_count; i++){
|
||||
if(listener->socks[i] == INVALID_SOCKET){
|
||||
return 1;
|
||||
}
|
||||
listensock[listensock_index].sock = listener->socks[i];
|
||||
listensock[listensock_index].listener = listener;
|
||||
g_listensock[listensock_index].sock = listener->socks[i];
|
||||
g_listensock[listensock_index].listener = listener;
|
||||
#if defined(WITH_EPOLL) || defined(WITH_KQUEUE)
|
||||
listensock[listensock_index].ident = id_listener;
|
||||
g_listensock[listensock_index].ident = id_listener;
|
||||
#endif
|
||||
listensock_index++;
|
||||
}
|
||||
@@ -94,7 +95,7 @@ void listeners__add_websockets(struct lws_context *ws_context, mosq_sock_t fd)
|
||||
struct mosquitto__listener_sock *listensock_new;
|
||||
|
||||
/* Don't add more listeners after we've started the main loop */
|
||||
if(run || ws_context == NULL) return;
|
||||
if(g_run || ws_context == NULL) return;
|
||||
|
||||
/* Find context */
|
||||
for(i=0; i<db.config->listener_count; i++){
|
||||
@@ -107,17 +108,17 @@ void listeners__add_websockets(struct lws_context *ws_context, mosq_sock_t fd)
|
||||
return;
|
||||
}
|
||||
|
||||
listensock_count++;
|
||||
listensock_new = mosquitto__realloc(listensock, sizeof(struct mosquitto__listener_sock)*(size_t)listensock_count);
|
||||
g_listensock_count++;
|
||||
listensock_new = mosquitto__realloc(g_listensock, sizeof(struct mosquitto__listener_sock)*(size_t)g_listensock_count);
|
||||
if(!listensock_new){
|
||||
return;
|
||||
}
|
||||
listensock = listensock_new;
|
||||
g_listensock = listensock_new;
|
||||
|
||||
listensock[listensock_index].sock = fd;
|
||||
listensock[listensock_index].listener = listener;
|
||||
g_listensock[listensock_index].sock = fd;
|
||||
g_listensock[listensock_index].listener = listener;
|
||||
#if defined(WITH_EPOLL) || defined(WITH_KQUEUE)
|
||||
listensock[listensock_index].ident = id_listener_ws;
|
||||
g_listensock[listensock_index].ident = id_listener_ws;
|
||||
#endif
|
||||
listensock_index++;
|
||||
}
|
||||
@@ -190,7 +191,7 @@ int listeners__start(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
listensock_count = 0;
|
||||
g_listensock_count = 0;
|
||||
|
||||
if(db.config->listener_count == 0){
|
||||
if(listeners__start_local_only()){
|
||||
@@ -222,7 +223,7 @@ int listeners__start(void)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if(listensock == NULL){
|
||||
if(g_listensock == NULL){
|
||||
log__printf(NULL, MOSQ_LOG_ERR, "Error: Unable to start any listening sockets, exiting.");
|
||||
return 1;
|
||||
}
|
||||
@@ -248,10 +249,11 @@ void listeners__stop(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
for(i=0; i<listensock_count; i++){
|
||||
if(listensock[i].sock != INVALID_SOCKET){
|
||||
COMPAT_CLOSE(listensock[i].sock);
|
||||
for(i=0; i<g_listensock_count; i++){
|
||||
if(g_listensock[i].sock != INVALID_SOCKET){
|
||||
COMPAT_CLOSE(g_listensock[i].sock);
|
||||
}
|
||||
}
|
||||
mosquitto__free(listensock);
|
||||
mosquitto__free(g_listensock);
|
||||
g_listensock = NULL;
|
||||
}
|
||||
|
||||
+2
-2
@@ -60,7 +60,7 @@ extern bool flag_reload;
|
||||
extern bool flag_db_backup;
|
||||
#endif
|
||||
extern bool flag_tree_print;
|
||||
extern int run;
|
||||
extern int g_run;
|
||||
|
||||
#if defined(WITH_WEBSOCKETS) && LWS_LIBRARY_VERSION_NUMBER == 3002000
|
||||
void lws__sul_callback(struct lws_sorted_usec_list *l)
|
||||
@@ -190,7 +190,7 @@ int mosquitto_main_loop(struct mosquitto__listener_sock *listensock, int listens
|
||||
if(rc) return rc;
|
||||
#endif
|
||||
|
||||
while(run){
|
||||
while(g_run){
|
||||
queue_plugin_msgs();
|
||||
context__free_disused();
|
||||
#ifdef WITH_SYS_TREE
|
||||
|
||||
+7
-7
@@ -58,15 +58,15 @@ Contributors:
|
||||
|
||||
struct mosquitto_db db;
|
||||
|
||||
struct mosquitto__listener_sock *listensock = NULL;
|
||||
int listensock_count = 0;
|
||||
struct mosquitto__listener_sock *g_listensock = NULL;
|
||||
int g_listensock_count = 0;
|
||||
|
||||
bool flag_reload = false;
|
||||
#ifdef WITH_PERSISTENCE
|
||||
bool flag_db_backup = false;
|
||||
#endif
|
||||
bool flag_tree_print = false;
|
||||
int run;
|
||||
int g_run = 0;
|
||||
#ifdef WITH_WRAP
|
||||
#include <syslog.h>
|
||||
int allow_severity = LOG_INFO;
|
||||
@@ -168,7 +168,7 @@ static void mosquitto__daemonise(void)
|
||||
}
|
||||
|
||||
|
||||
void signal__setup(void)
|
||||
static void signal__setup(void)
|
||||
{
|
||||
signal(SIGINT, handle_sigint);
|
||||
signal(SIGTERM, handle_sigint);
|
||||
@@ -204,7 +204,7 @@ static int pid__write(void)
|
||||
}
|
||||
|
||||
|
||||
void report_features(void)
|
||||
static void report_features(void)
|
||||
{
|
||||
#ifdef WITH_BRIDGE
|
||||
log__printf(NULL, MOSQ_LOG_INFO, "Bridge support available.");
|
||||
@@ -360,8 +360,8 @@ int main(int argc, char *argv[])
|
||||
sd_notify(0, "READY=1");
|
||||
#endif
|
||||
|
||||
run = 1;
|
||||
rc = mosquitto_main_loop(listensock, listensock_count);
|
||||
g_run = 1;
|
||||
rc = mosquitto_main_loop(g_listensock, g_listensock_count);
|
||||
|
||||
log__printf(NULL, MOSQ_LOG_INFO, "mosquitto version %s terminating", VERSION);
|
||||
|
||||
|
||||
@@ -765,8 +765,8 @@ int mux__cleanup(void);
|
||||
/* ============================================================
|
||||
* Listener related functions
|
||||
* ============================================================ */
|
||||
extern struct mosquitto__listener_sock *listensock;
|
||||
extern int listensock_count;
|
||||
extern struct mosquitto__listener_sock *g_listensock;
|
||||
extern int g_listensock_count;
|
||||
|
||||
void listener__set_defaults(struct mosquitto__listener *listener);
|
||||
void listeners__reload_all_certificates(void);
|
||||
|
||||
+2
-2
@@ -36,7 +36,7 @@ extern bool flag_db_backup;
|
||||
#endif
|
||||
extern bool flag_reload;
|
||||
extern bool flag_tree_print;
|
||||
extern int run;
|
||||
extern int g_run;
|
||||
|
||||
#ifdef SIGHUP
|
||||
/* Signal handler for SIGHUP - flag a config reload. */
|
||||
@@ -53,7 +53,7 @@ void handle_sigint(int signal)
|
||||
{
|
||||
UNUSED(signal);
|
||||
|
||||
run = 0;
|
||||
g_run = 0;
|
||||
}
|
||||
|
||||
/* Signal handler for SIGUSR1 - backup the db. */
|
||||
|
||||
Reference in New Issue
Block a user