Fix some build variants

This commit is contained in:
Roger A. Light
2025-07-10 16:08:49 +01:00
parent fa1d85ebdb
commit 43dda2ae20
16 changed files with 64 additions and 50 deletions
+1 -2
View File
@@ -6,7 +6,7 @@ include ${R}/config.mk
LOCAL_CFLAGS+=
LOCAL_CPPFLAGS+=-I${R}/lib -I${R}/apps/mosquitto_passwd -I${R}/plugins/dynamic-security -I${R}/common
LOCAL_LDFLAGS+=
LOCAL_LDADD+=-lcjson -ldl ${LIBMOSQ} ${LIBMOSQ_COMMON}
LOCAL_LDADD+=-lcjson -ldl ${LIBMOSQ} ${LIBMOSQ_COMMON} -lcrypto -lssl
# ------------------------------------------
# Compile time options
@@ -18,7 +18,6 @@ endif
ifeq ($(WITH_THREADING),yes)
LOCAL_LDFLAGS+=-pthread
LOCAL_LDADD+=-lssl -lcrypto
endif
ifeq ($(WITH_EDITLINE),yes)
+2 -2
View File
@@ -154,10 +154,10 @@ int mosquitto_publish_v5(struct mosquitto *mosq, int *mid, const char *topic, in
message->dup = false;
message->properties = properties_copy;
pthread_mutex_lock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_lock(&mosq->msgs_out.mutex);
message->state = mosq_ms_invalid;
rc = message__queue(mosq, message, mosq_md_out);
pthread_mutex_unlock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgs_out.mutex);
return rc;
}
}
+4 -4
View File
@@ -138,9 +138,9 @@ void mosquitto_log_callback_set(struct mosquitto *mosq, LIBMOSQ_CB_log on_log)
void mosquitto_ext_auth_callback_set(struct mosquitto *mosq, LIBMOSQ_CB_ext_auth on_ext_auth)
{
pthread_mutex_lock(&mosq->callback_mutex);
COMPAT_pthread_mutex_lock(&mosq->callback_mutex);
mosq->on_ext_auth = on_ext_auth;
pthread_mutex_unlock(&mosq->callback_mutex);
COMPAT_pthread_mutex_unlock(&mosq->callback_mutex);
}
@@ -300,9 +300,9 @@ int callback__on_ext_auth(struct mosquitto *mosq, const char *auth_method, uint1
int rc = MOSQ_ERR_AUTH;
LIBMOSQ_CB_ext_auth on_ext_auth;
pthread_mutex_lock(&mosq->callback_mutex);
COMPAT_pthread_mutex_lock(&mosq->callback_mutex);
on_ext_auth = mosq->on_ext_auth;
pthread_mutex_unlock(&mosq->callback_mutex);
COMPAT_pthread_mutex_unlock(&mosq->callback_mutex);
mosq->callback_depth++;
if(on_ext_auth){
+4 -4
View File
@@ -214,10 +214,10 @@ static int mosquitto__reconnect(struct mosquitto *mosq, bool blocking)
if(rc) return rc;
}
pthread_mutex_lock(&mosq->msgtime_mutex);
COMPAT_pthread_mutex_lock(&mosq->msgtime_mutex);
mosq->last_msg_in = mosquitto_time();
mosq->next_msg_out = mosq->last_msg_in + mosq->keepalive;
pthread_mutex_unlock(&mosq->msgtime_mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgtime_mutex);
mosq->ping_t = 0;
@@ -319,9 +319,9 @@ void do_client_disconnect(struct mosquitto *mosq, int reason_code, const mosquit
/* Free data and reset values */
packet__cleanup_all(mosq);
pthread_mutex_lock(&mosq->msgtime_mutex);
COMPAT_pthread_mutex_lock(&mosq->msgtime_mutex);
mosq->next_msg_out = mosquitto_time() + mosq->keepalive;
pthread_mutex_unlock(&mosq->msgtime_mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgtime_mutex);
callback__on_disconnect(mosq, reason_code, properties);
}
+2 -2
View File
@@ -114,11 +114,11 @@ int handle__connack(struct mosquitto *mosq)
switch(reason_code){
case 0:
pthread_mutex_lock(&mosq->state_mutex);
COMPAT_pthread_mutex_lock(&mosq->state_mutex);
if(mosq->state != mosq_cs_disconnecting){
mosq->state = mosq_cs_active;
}
pthread_mutex_unlock(&mosq->state_mutex);
COMPAT_pthread_mutex_unlock(&mosq->state_mutex);
message__retry_check(mosq);
return MOSQ_ERR_SUCCESS;
case 1:
+2 -2
View File
@@ -147,9 +147,9 @@ int handle__pubackcomp(struct mosquitto *mosq, const char *type)
}
}
pthread_mutex_lock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_lock(&mosq->msgs_out.mutex);
message__release_to_inflight(mosq, mosq_md_out);
pthread_mutex_unlock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgs_out.mutex);
return MOSQ_ERR_SUCCESS;
#endif
+2 -2
View File
@@ -163,10 +163,10 @@ int handle__publish(struct mosquitto *mosq)
message->properties = properties;
util__decrement_receive_quota(mosq);
rc = send__pubrec(mosq, mid, 0, NULL);
pthread_mutex_lock(&mosq->msgs_in.mutex);
COMPAT_pthread_mutex_lock(&mosq->msgs_in.mutex);
message->state = mosq_ms_wait_for_pubrel;
message__queue(mosq, message, mosq_md_in);
pthread_mutex_unlock(&mosq->msgs_in.mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgs_in.mutex);
return rc;
default:
message__cleanup(&message);
+2 -2
View File
@@ -110,9 +110,9 @@ int handle__pubrec(struct mosquitto *mosq)
callback__on_publish(mosq, mid, reason_code, properties);
}
util__increment_send_quota(mosq);
pthread_mutex_lock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_lock(&mosq->msgs_out.mutex);
message__release_to_inflight(mosq, mosq_md_out);
pthread_mutex_unlock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgs_out.mutex);
return MOSQ_ERR_SUCCESS;
}
#endif
+3 -3
View File
@@ -36,12 +36,12 @@ int log__printf(struct mosquitto *mosq, unsigned int priority, const char *fmt,
assert(mosq);
assert(fmt);
pthread_mutex_lock(&mosq->log_callback_mutex);
COMPAT_pthread_mutex_lock(&mosq->log_callback_mutex);
if(mosq->on_log){
len = strlen(fmt) + 500;
s = mosquitto_malloc(len*sizeof(char));
if(!s){
pthread_mutex_unlock(&mosq->log_callback_mutex);
COMPAT_pthread_mutex_unlock(&mosq->log_callback_mutex);
return MOSQ_ERR_NOMEM;
}
@@ -54,7 +54,7 @@ int log__printf(struct mosquitto *mosq, unsigned int priority, const char *fmt,
mosquitto_FREE(s);
}
pthread_mutex_unlock(&mosq->log_callback_mutex);
COMPAT_pthread_mutex_unlock(&mosq->log_callback_mutex);
return MOSQ_ERR_SUCCESS;
}
+10 -10
View File
@@ -72,11 +72,11 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets)
if(mosq->ssl == NULL || SSL_is_init_finished(mosq->ssl))
#endif
{
pthread_mutex_lock(&mosq->out_packet_mutex);
COMPAT_pthread_mutex_lock(&mosq->out_packet_mutex);
if(mosq->out_packet){
FD_SET(mosq->sock, &writefds);
}
pthread_mutex_unlock(&mosq->out_packet_mutex);
COMPAT_pthread_mutex_unlock(&mosq->out_packet_mutex);
}
}
}else{
@@ -110,11 +110,11 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets)
}
now = mosquitto_time();
pthread_mutex_lock(&mosq->msgtime_mutex);
COMPAT_pthread_mutex_lock(&mosq->msgtime_mutex);
if(mosq->next_msg_out && now + timeout_ms/1000 > mosq->next_msg_out){
timeout_ms = (mosq->next_msg_out - now)*1000;
}
pthread_mutex_unlock(&mosq->msgtime_mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgtime_mutex);
if(timeout_ms < 0){
/* There has been a delay somewhere which means we should have already
@@ -253,7 +253,7 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
while(run){
do{
#ifdef HAVE_PTHREAD_CANCEL
pthread_testcancel();
COMPAT_pthread_testcancel();
#endif
rc = mosquitto_loop(mosq, timeout, max_packets);
}while(run && rc == MOSQ_ERR_SUCCESS);
@@ -280,7 +280,7 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
}
do{
#ifdef HAVE_PTHREAD_CANCEL
pthread_testcancel();
COMPAT_pthread_testcancel();
#endif
rc = MOSQ_ERR_SUCCESS;
if(mosquitto__get_request_disconnect(mosq)){
@@ -348,13 +348,13 @@ int mosquitto_loop_read(struct mosquitto *mosq, int max_packets)
int i;
if(max_packets < 1) return MOSQ_ERR_INVAL;
pthread_mutex_lock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_lock(&mosq->msgs_out.mutex);
max_packets = mosq->msgs_out.queue_len;
pthread_mutex_unlock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgs_out.mutex);
pthread_mutex_lock(&mosq->msgs_in.mutex);
COMPAT_pthread_mutex_lock(&mosq->msgs_in.mutex);
max_packets += mosq->msgs_in.queue_len;
pthread_mutex_unlock(&mosq->msgs_in.mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgs_in.mutex);
if(max_packets < 1) max_packets = 1;
/* Queue len here tells us how many messages are awaiting processing and
+16 -16
View File
@@ -140,7 +140,7 @@ void message__reconnect_reset(struct mosquitto *mosq, bool update_quota_only)
struct mosquitto_message_all *message, *tmp;
assert(mosq);
pthread_mutex_lock(&mosq->msgs_in.mutex);
COMPAT_pthread_mutex_lock(&mosq->msgs_in.mutex);
mosq->msgs_in.inflight_quota = mosq->msgs_in.inflight_maximum;
mosq->msgs_in.queue_len = 0;
DL_FOREACH_SAFE(mosq->msgs_in.inflight, message, tmp){
@@ -154,10 +154,10 @@ void message__reconnect_reset(struct mosquitto *mosq, bool update_quota_only)
util__decrement_receive_quota(mosq);
}
}
pthread_mutex_unlock(&mosq->msgs_in.mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgs_in.mutex);
pthread_mutex_lock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_lock(&mosq->msgs_out.mutex);
mosq->msgs_out.inflight_quota = mosq->msgs_out.inflight_maximum;
mosq->msgs_out.queue_len = 0;
DL_FOREACH_SAFE(mosq->msgs_out.inflight, message, tmp){
@@ -181,7 +181,7 @@ void message__reconnect_reset(struct mosquitto *mosq, bool update_quota_only)
message->state = mosq_ms_invalid;
}
}
pthread_mutex_unlock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgs_out.mutex);
}
@@ -224,12 +224,12 @@ int message__remove(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_dir
assert(message);
if(dir == mosq_md_out){
pthread_mutex_lock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_lock(&mosq->msgs_out.mutex);
DL_FOREACH_SAFE(mosq->msgs_out.inflight, cur, tmp){
if(found == false && cur->msg.mid == mid){
if(cur->msg.qos != qos){
pthread_mutex_unlock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgs_out.mutex);
return MOSQ_ERR_PROTOCOL;
}
DL_DELETE(mosq->msgs_out.inflight, cur);
@@ -240,18 +240,18 @@ int message__remove(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_dir
break;
}
}
pthread_mutex_unlock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgs_out.mutex);
if(found){
return MOSQ_ERR_SUCCESS;
}else{
return MOSQ_ERR_NOT_FOUND;
}
}else{
pthread_mutex_lock(&mosq->msgs_in.mutex);
COMPAT_pthread_mutex_lock(&mosq->msgs_in.mutex);
DL_FOREACH_SAFE(mosq->msgs_in.inflight, cur, tmp){
if(cur->msg.mid == mid){
if(cur->msg.qos != qos){
pthread_mutex_unlock(&mosq->msgs_in.mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgs_in.mutex);
return MOSQ_ERR_PROTOCOL;
}
DL_DELETE(mosq->msgs_in.inflight, cur);
@@ -262,7 +262,7 @@ int message__remove(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_dir
}
}
pthread_mutex_unlock(&mosq->msgs_in.mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgs_in.mutex);
if(found){
return MOSQ_ERR_SUCCESS;
}else{
@@ -277,7 +277,7 @@ void message__retry_check(struct mosquitto *mosq)
assert(mosq);
#ifdef WITH_THREADING
pthread_mutex_lock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_lock(&mosq->msgs_out.mutex);
#endif
DL_FOREACH(mosq->msgs_out.inflight, msg){
@@ -301,7 +301,7 @@ void message__retry_check(struct mosquitto *mosq)
}
}
#ifdef WITH_THREADING
pthread_mutex_unlock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgs_out.mutex);
#endif
}
@@ -317,19 +317,19 @@ int message__out_update(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg
struct mosquitto_message_all *message, *tmp;
assert(mosq);
pthread_mutex_lock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_lock(&mosq->msgs_out.mutex);
DL_FOREACH_SAFE(mosq->msgs_out.inflight, message, tmp){
if(message->msg.mid == mid){
if(message->msg.qos != qos){
pthread_mutex_unlock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgs_out.mutex);
return MOSQ_ERR_PROTOCOL;
}
message->state = state;
pthread_mutex_unlock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgs_out.mutex);
return MOSQ_ERR_SUCCESS;
}
}
pthread_mutex_unlock(&mosq->msgs_out.mutex);
COMPAT_pthread_mutex_unlock(&mosq->msgs_out.mutex);
return MOSQ_ERR_NOT_FOUND;
}
+1
View File
@@ -17,6 +17,7 @@ Contributors:
*/
#include "config.h"
#include <stdlib.h> /* Keep this here to allow glibc detection */
#ifdef WIN32
# include <winsock2.h>
+9 -1
View File
@@ -40,7 +40,11 @@ struct metric{
time_t broker_uptime(void);
struct MHD_Daemon *mhd = NULL;
#ifdef WITH_SYS_TREE
extern struct metric metrics[mosq_metric_max];
#endif
#define HTTP_RESPONSE_BUFLEN 10000
#ifdef WIN32
@@ -199,8 +203,9 @@ static enum MHD_Result http_api__process_listeners(struct MHD_Connection *connec
static enum MHD_Result http_api__process_systree(struct MHD_Connection *connection)
{
char *buf;
enum MHD_Result ret;
#ifdef WITH_SYS_TREE
char *buf;
cJSON *j_tree = cJSON_CreateObject();
for(int i=0; i<mosq_metric_max; i++){
@@ -219,6 +224,9 @@ static enum MHD_Result http_api__process_systree(struct MHD_Connection *connecti
}else{
ret = http_api__send_error_response(connection, "Internal server error.\n", MHD_HTTP_INTERNAL_SERVER_ERROR);
}
#else
ret = http_api__send_error_response(connection, "Not found.\n", 404);
#endif
return ret;
}
+2
View File
@@ -198,6 +198,7 @@ int sub__messages_queue(const char *source_id, const char *topic, uint8_t qos, i
*base_msg = NULL;
return 0;
}
#ifdef WITH_SYS_TREE
void metrics__int_inc(enum mosq_metric_type m, int64_t value)
{
UNUSED(m); UNUSED(value);
@@ -206,6 +207,7 @@ void metrics__int_dec(enum mosq_metric_type m, int64_t value)
{
UNUSED(m); UNUSED(value);
}
#endif
int send__publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, uint8_t qos, bool retain, bool dup, uint32_t subscription_identifier, const mosquitto_property *store_props, uint32_t expiry_interval)
{
UNUSED(mosq);
+2
View File
@@ -279,6 +279,7 @@ int send__disconnect(struct mosquitto *mosq, uint8_t reason_code, const mosquitt
return 0;
}
#ifdef WITH_SYS_TREE
void metrics__int_inc(enum mosq_metric_type m, int64_t value)
{
UNUSED(m); UNUSED(value);
@@ -287,3 +288,4 @@ void metrics__int_dec(enum mosq_metric_type m, int64_t value)
{
UNUSED(m); UNUSED(value);
}
#endif
+2
View File
@@ -210,6 +210,7 @@ int session_expiry__add_from_persistence(struct mosquitto *context, time_t expir
return 0;
}
#ifdef WITH_SYS_TREE
void metrics__int_inc(enum mosq_metric_type m, int64_t value)
{
UNUSED(m); UNUSED(value);
@@ -218,3 +219,4 @@ void metrics__int_dec(enum mosq_metric_type m, int64_t value)
{
UNUSED(m); UNUSED(value);
}
#endif