mirror of
https://github.com/eclipse/mosquitto.git
synced 2025-05-09 01:01:11 +08:00
Build and conversion fixes for build variants.
This commit is contained in:
parent
4d9afc835b
commit
4d6384c758
@ -26,7 +26,15 @@ 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
|
||||
|
||||
|
@ -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;
|
||||
@ -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;
|
||||
|
||||
|
@ -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
|
||||
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -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] = ':';
|
||||
|
@ -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;
|
||||
@ -233,6 +234,7 @@ void listeners__reload_all_certificates(struct mosquitto_db *db)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -58,7 +58,7 @@ Contributors:
|
||||
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
|
||||
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ Contributors:
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "mosquitto_broker_internal.h"
|
||||
#include "memory_mosq.h"
|
||||
|
@ -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;
|
||||
@ -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
|
||||
@ -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));
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
@ -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);
|
||||
@ -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);
|
||||
@ -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;
|
||||
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user