Skip to content

Commit

Permalink
Build and conversion fixes for build variants.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Nov 5, 2020
1 parent 4d9afc8 commit 4d6384c
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 27 deletions.
8 changes: 8 additions & 0 deletions apps/mosquitto_ctrl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,18 @@ EXAMPLE_OBJS= example.o

ifeq ($(WITH_TLS),yes)
ifeq ($(WITH_CJSON),yes)

ifeq ($(WITH_SHARED_LIBRARIES),yes)
TARGET:=mosquitto_ctrl mosquitto_ctrl_example.so
else
ifeq ($(WITH_STATIC_LIBRARIES),yes)
TARGET:=mosquitto_ctrl mosquitto_ctrl_example.so
endif
endif

endif
endif

all : $(TARGET)

mosquitto_ctrl : ${OBJS}
Expand Down
6 changes: 5 additions & 1 deletion lib/srv_mosq.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ int mosquitto_connect_srv(struct mosquitto *mosq, const char *host, int keepaliv
int rc;
if(!mosq) return MOSQ_ERR_INVAL;

if(keepalive < 0 || keepalive > UINT16_MAX){
return MOSQ_ERR_INVAL;
}

rc = ares_init(&mosq->achan);
if(rc != ARES_SUCCESS){
return MOSQ_ERR_UNKNOWN;
Expand Down Expand Up @@ -94,7 +98,7 @@ int mosquitto_connect_srv(struct mosquitto *mosq, const char *host, int keepaliv

mosquitto__set_state(mosq, mosq_cs_connect_srv);

mosq->keepalive = keepalive;
mosq->keepalive = (uint16_t)keepalive;

return MOSQ_ERR_SUCCESS;

Expand Down
6 changes: 3 additions & 3 deletions plugins/payload-modification/mosquitto_payload_modification.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ static int callback_message(int event, void *event_data, void *userdata)
{
struct mosquitto_evt_message *ed = event_data;
char *new_payload;
int new_payloadlen;
uint32_t new_payloadlen;

/* This simply adds "hello " to the front of every payload. You can of
* course do much more complicated message processing if needed. */

/* Calculate the length of our new payload */
new_payloadlen = ed->payloadlen + strlen("hello ")+1;
new_payloadlen = ed->payloadlen + (uint32_t)strlen("hello ")+1;

/* Allocate some memory - use
* mosquitto_calloc/mosquitto_malloc/mosquitto_strdup when allocating, to
Expand All @@ -64,7 +64,7 @@ static int callback_message(int event, void *event_data, void *userdata)

/* Print "hello " to the payload */
snprintf(new_payload, new_payloadlen, "hello ");
memcpy(new_payload+strlen("hello "), ed->payload, ed->payloadlen);
memcpy(new_payload+(uint32_t)strlen("hello "), ed->payload, ed->payloadlen);

/* Assign the new payload and payloadlen to the event data structure. You
* must *not* free the original payload, it will be handled by the
Expand Down
2 changes: 1 addition & 1 deletion src/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int bridge__connect_step1(struct mosquitto_db *db, struct mosquitto *context)
{
int rc;
char *notification_topic;
int notification_topic_len;
size_t notification_topic_len;
uint8_t notification_payload;
int i;

Expand Down
7 changes: 6 additions & 1 deletion src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2151,7 +2151,12 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
}else if(!strcmp(token, "websockets_headers_size")){
#ifdef WITH_WEBSOCKETS
# if defined(LWS_LIBRARY_VERSION_NUMBER) && LWS_LIBRARY_VERSION_NUMBER>=1007000
if(conf__parse_int(&token, "websockets_headers_size", &config->websockets_headers_size, saveptr)) return MOSQ_ERR_INVAL;
if(conf__parse_int(&token, "websockets_headers_size", &tmp_int, saveptr)) return MOSQ_ERR_INVAL;
if(tmp_int < 0 || tmp_int > UINT16_MAX){
log__printf(NULL, MOSQ_LOG_WARNING, "Error: Websockets headers size must be between 0 and 65535 inclusive.");
return MOSQ_ERR_INVAL;
}
config->websockets_headers_size = (uint16_t)tmp_int;
# else
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Websockets headers size require libwebsocket 1.7+");
# endif
Expand Down
6 changes: 3 additions & 3 deletions src/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ int log__vprintf(unsigned int priority, const char *fmt, va_list va)
int syslog_priority;
time_t now = time(NULL);
char log_line[1000];
int log_line_pos;
size_t log_line_pos;
#ifdef WIN32
char *sp;
#endif
Expand Down Expand Up @@ -303,10 +303,10 @@ int log__vprintf(unsigned int priority, const char *fmt, va_list va)
get_time(&ti);
log_line_pos = strftime(log_line, sizeof(log_line), log_timestamp_format, ti);
if(log_line_pos == 0){
log_line_pos = snprintf(log_line, sizeof(log_line), "Time error");
log_line_pos = (size_t)snprintf(log_line, sizeof(log_line), "Time error");
}
}else{
log_line_pos = snprintf(log_line, sizeof(log_line), "%d", (int)now);
log_line_pos = (size_t)snprintf(log_line, sizeof(log_line), "%d", (int)now);
}
if(log_line_pos < sizeof(log_line)-3){
log_line[log_line_pos] = ':';
Expand Down
4 changes: 4 additions & 0 deletions src/mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ void listener__set_defaults(struct mosquitto__listener *listener)

void listeners__reload_all_certificates(struct mosquitto_db *db)
{
#ifdef WITH_TLS
int i;
int rc;
struct mosquitto__listener *listener;
Expand All @@ -233,6 +234,7 @@ void listeners__reload_all_certificates(struct mosquitto_db *db)
}
}
}
#endif
}


Expand Down Expand Up @@ -435,7 +437,9 @@ int main(int argc, char *argv[])
mosq_sock_t *listensock = NULL;
int listensock_count = 0;
struct mosquitto__config config;
#ifdef WITH_BRIDGE
int i;
#endif
int rc;
#ifdef WIN32
SYSTEMTIME st;
Expand Down
2 changes: 1 addition & 1 deletion src/mosquitto_broker_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ struct mosquitto__config {
char *user;
#ifdef WITH_WEBSOCKETS
int websockets_log_level;
int websockets_headers_size;
uint16_t websockets_headers_size;
bool have_websockets_listener;
#endif
#ifdef WITH_BRIDGE
Expand Down
4 changes: 2 additions & 2 deletions src/mux_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ static void loop_handle_reads_writes(struct mosquitto_db *db, mosq_sock_t sock,
if(context->wsi){
struct lws_pollfd wspoll;
wspoll.fd = context->sock;
wspoll.events = context->events;
wspoll.revents = events;
wspoll.events = (int16_t)context->events;
wspoll.revents = (int16_t)events;
#ifdef LWS_LIBRARY_VERSION_NUMBER
lws_service_fd(lws_get_context(context->wsi), &wspoll);
#else
Expand Down
6 changes: 3 additions & 3 deletions src/mux_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ and the Eclipse Distribution License is available at
static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pollfds);

static struct pollfd *pollfds = NULL;
static int pollfd_max;
static size_t pollfd_max;
#ifndef WIN32
static sigset_t my_sigblock;
#endif
Expand All @@ -78,9 +78,9 @@ int mux_poll__init(struct mosquitto_db *db, mosq_sock_t *listensock, int listens
#endif

#ifdef WIN32
pollfd_max = _getmaxstdio();
pollfd_max = (size_t)_getmaxstdio();
#else
pollfd_max = sysconf(_SC_OPEN_MAX);
pollfd_max = (size_t)sysconf(_SC_OPEN_MAX);
#endif

pollfds = mosquitto__malloc(sizeof(struct pollfd)*pollfd_max);
Expand Down
2 changes: 2 additions & 0 deletions src/security_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,9 @@ void unpwd__free_item(struct mosquitto__unpwd **unpwd, struct mosquitto__unpwd *
{
mosquitto__free(item->username);
mosquitto__free(item->password);
#ifdef WITH_TLS
mosquitto__free(item->salt);
#endif
HASH_DEL(*unpwd, item);
mosquitto__free(item);
}
Expand Down
1 change: 1 addition & 0 deletions src/sys_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and the Eclipse Distribution License is available at

#include <math.h>
#include <stdio.h>
#include <limits.h>

#include "mosquitto_broker_internal.h"
#include "memory_mosq.h"
Expand Down
31 changes: 19 additions & 12 deletions src/websockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ static int callback_mqtt(struct libwebsocket_context *context,
struct mosquitto__packet *packet;
size_t txlen;
int count;
unsigned int ucount;
const struct libwebsocket_protocols *p;
struct libws_mqtt_data *u = (struct libws_mqtt_data *)user;
size_t pos;
Expand Down Expand Up @@ -315,11 +316,12 @@ static int callback_mqtt(struct libwebsocket_context *context,
}
return 0;
}
ucount = (unsigned int)count;
#ifdef WITH_SYS_TREE
g_bytes_sent += count;
g_bytes_sent += ucount;
#endif
packet->to_process -= count;
packet->pos += count;
packet->to_process -= ucount;
packet->pos += ucount;
if(packet->to_process > 0){
if (mosq->state == mosq_cs_disconnect_ws
|| mosq->state == mosq_cs_disconnecting
Expand Down Expand Up @@ -398,7 +400,7 @@ static int callback_mqtt(struct libwebsocket_context *context,
mosq->in_packet.remaining_length += (byte & 127) * mosq->in_packet.remaining_mult;
mosq->in_packet.remaining_mult *= 128;
}while((byte & 128) != 0);
mosq->in_packet.remaining_count *= -1;
mosq->in_packet.remaining_count = (int8_t)(mosq->in_packet.remaining_count -1);

if(mosq->in_packet.remaining_length > 0){
mosq->in_packet.payload = mosquitto__malloc(mosq->in_packet.remaining_length*sizeof(uint8_t));
Expand All @@ -409,15 +411,15 @@ static int callback_mqtt(struct libwebsocket_context *context,
}
}
if(mosq->in_packet.to_process>0){
if(len - pos >= mosq->in_packet.to_process){
if((uint32_t)len - pos >= mosq->in_packet.to_process){
memcpy(&mosq->in_packet.payload[mosq->in_packet.pos], &buf[pos], mosq->in_packet.to_process);
mosq->in_packet.pos += mosq->in_packet.to_process;
pos += mosq->in_packet.to_process;
mosq->in_packet.to_process = 0;
}else{
memcpy(&mosq->in_packet.payload[mosq->in_packet.pos], &buf[pos], len-pos);
mosq->in_packet.pos += len-pos;
mosq->in_packet.to_process -= len-pos;
mosq->in_packet.pos += (uint32_t)(len-pos);
mosq->in_packet.to_process -= (uint32_t)(len-pos);
return 0;
}
}
Expand Down Expand Up @@ -537,6 +539,7 @@ static int callback_http(struct libwebsocket_context *context,
char *http_dir;
size_t buflen;
size_t wlen;
int rc;
char *filename_canonical;
unsigned char buf[4096];
struct stat filestat;
Expand Down Expand Up @@ -601,7 +604,7 @@ static int callback_http(struct libwebsocket_context *context,
free(filename_canonical);

/* FIXME - use header functions from lws 2.x */
buflen = snprintf((char *)buf, 4096, "HTTP/1.0 302 OK\r\n"
buflen = (size_t)snprintf((char *)buf, 4096, "HTTP/1.0 302 OK\r\n"
"Location: %s/\r\n\r\n",
(char *)in);
return libwebsocket_write(wsi, buf, buflen, LWS_WRITE_HTTP);
Expand All @@ -618,7 +621,7 @@ static int callback_http(struct libwebsocket_context *context,
log__printf(NULL, MOSQ_LOG_DEBUG, "http serving file \"%s\".", filename_canonical);
free(filename_canonical);
/* FIXME - use header functions from lws 2.x */
buflen = snprintf((char *)buf, 4096, "HTTP/1.0 200 OK\r\n"
buflen = (size_t)snprintf((char *)buf, 4096, "HTTP/1.0 200 OK\r\n"
"Server: mosquitto\r\n"
"Content-Length: %u\r\n\r\n",
(unsigned int)filestat.st_size);
Expand Down Expand Up @@ -652,9 +655,13 @@ static int callback_http(struct libwebsocket_context *context,
u->fptr = NULL;
return -1;
}
wlen = libwebsocket_write(wsi, buf, buflen, LWS_WRITE_HTTP);
rc = libwebsocket_write(wsi, buf, buflen, LWS_WRITE_HTTP);
if(rc < 0){
return -1;
}
wlen = (size_t)rc;
if(wlen < buflen){
if(fseek(u->fptr, buflen-wlen, SEEK_CUR) < 0){
if(fseek(u->fptr, (long)(buflen-wlen), SEEK_CUR) < 0){
fclose(u->fptr);
u->fptr = NULL;
return -1;
Expand Down Expand Up @@ -721,7 +728,7 @@ struct libwebsocket_context *mosq_websockets_init(struct mosquitto__listener *li
{
struct lws_context_creation_info info;
struct libwebsocket_protocols *p;
int protocol_count;
size_t protocol_count;
int i;
struct libws_mqtt_hack *user;

Expand Down

0 comments on commit 4d6384c

Please sign in to comment.