Merge remote-tracking branch 'origin/fixes' into develop

This commit is contained in:
Roger A. Light
2020-09-24 17:03:14 +01:00
172 changed files with 2587 additions and 775 deletions

View File

@@ -1,8 +1,18 @@
Thank you for contributing your time to the Mosquitto project!
Before you go any further, please note that we cannot accept contributions if
you haven't signed the [Eclipse Contributor Agreement](https://www.eclipse.org/legal/ECA.php).
If you aren't able to do that, or just don't want to, please describe your bug
fix/feature change in an issue. For simple bug fixes it is can be just as easy
for us to be told about the problem and then go fix it directly.
Then please check the following list of things we ask for in your pull request:
- [ ] Have you signed the [Eclipse Contributor Agreement](https://www.eclipse.org/legal/ECA.php), using the same email address as you used in your commits?
- [ ] Do each of your commits have a "Signed-off-by" line, with the correct email address? Use "git commit -s" to generate this line for you.
- [ ] If you are contributing a new feature, is your work based off the develop branch?
- [ ] If you are contributing a bugfix, is your work based off the fixes branch?
- [ ] Have you added an explanation of what your changes do and why you'd like us to include them?
- [ ] Have you successfully run `make test` with your changes locally?
- [ ] Have you signed the [Eclipse Contributor Agreement](https://www.eclipse.org/legal/ECA.php), using the same email address as you used in your commits?
- [ ] Do each of your commits have a "Signed-off-by" line, with the correct email address? Use "git commit -s" to generate this line for you.
-----

19
.github/workflows/covsync.yml vendored Normal file
View File

@@ -0,0 +1,19 @@
name: "Synchronise Coverity Scan branches on a weekly basis"
on:
workflow_dispatch:
schedule:
- cron: "7 3 * * 0"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- run: |
git checkout -b coverity-fixes origin/fixes
git push origin coverity-fixes
git checkout -b coverity-develop origin/develop
git push origin coverity-develop

View File

@@ -11,7 +11,7 @@ project(mosquitto)
cmake_minimum_required(VERSION 2.8)
# Only for version 3 and up. cmake_policy(SET CMP0042 NEW)
set (VERSION 1.6.9)
set (VERSION 1.6.12)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
@@ -24,6 +24,7 @@ endif (WIN32)
include(GNUInstallDirs)
option(WITH_BUNDLED_DEPS "Build with bundled dependencies?" ON)
option(WITH_TLS
"Include SSL/TLS support?" ON)
option(WITH_TLS_PSK

View File

@@ -67,6 +67,9 @@ Client library:
sockets. Closes #1526.
- Add `mosquitto_ssl_get()` to allow clients to access their SSL structure and
perform additional verification.
- Fix send quota being incorrecly reset on reconnect. Closes #1822.
- Don't use logging until log mutex is initialised. Closes #1819.
- Fix missing mach/mach_time.h header on OS X. Closes #1831.
Clients:
- Add timeout return code (27) for `mosquitto_sub -W <secs>` and
@@ -94,6 +97,105 @@ Clients:
- Add `--version` for all clients.
1.6.12 - 2020-08-19
===================
Security:
- In some circumstances, Mosquitto could leak memory when handling PUBLISH
messages. This is limited to incoming QoS 2 messages, and is related
to the combination of the broker having persistence enabled, a clean
session=false client, which was connected prior to the broker restarting,
then has reconnected and has now sent messages at a sufficiently high rate
that the incoming queue at the broker has filled up and hence messages are
being dropped. This is more likely to have an effect where
max_queued_messages is a small value. This has now been fixed. Closes #1793.
Broker:
- Build warning fixes when building with WITH_BRIDGE=no and WITH_TLS=no.
Clients:
- All clients exit with an error exit code on CONNACK failure. Closes #1778.
- Don't busy loop with `mosquitto_pub -l` on a slow connection.
1.6.11 - 2020-08-11
===================
Security:
- On Windows the Mosquitto service was being installed without appropriate
path quoting, this has been fixed.
Broker:
- Fix usage message only mentioning v3.1.1. Closes #1713.
- Fix broker refusing to start if only websockets listeners were defined.
Closes #1740.
- Change systemd unit files to create /var/log/mosquitto before starting.
Closes #821.
- Don't quit with an error if opening the log file isn't possible.
Closes #821.
- Fix bridge topic remapping when using "" as the topic. Closes #1749.
- Fix messages being queued for disconnected bridges when clean start was
set to true. Closes #1729.
- Fix `autosave_interval` not being triggered by messages being delivered.
Closes #1726.
- Fix websockets clients sometimes not being disconnected promptly.
Closes #1718.
- Fix "slow" file based logging by switching to line based buffering.
Closes #1689. Closes #1741.
- Log protocol error message where appropriate from a bad UNSUBSCRIBE, rather
than the generic "socket error".
- Don't try to start DLT logging if DLT unavailable, to avoid a long delay
when shutting down the broker. Closes #1735.
- Fix potential memory leaks. Closes #1773. Closes #1774.
- Fix clients not receiving messages after a previous client with the same
client ID and positive will delay interval quit. Closes #1752.
- Fix overly broad HAVE_PTHREAD_CANCEL compile guard. Closes #1547.
Client library:
- Improved documentation around connect callback return codes. Close #1730.
- Fix `mosquitto_publish*()` no longer returning `MOSQ_ERR_NO_CONN` when not
connected. Closes #1725.
- `mosquitto_loop_start()` now sets a thread name on Linux, FreeBSD, NetBSD,
and OpenBSD. Closes #1777.
- Fix `mosquitto_loop_stop()` not stopping on Windows. Closes #1748. Closes #117.
1.6.10 - 2020-05-25
===================
Broker:
- Report invalid bridge prefix+pattern combinations at config parsing time
rather than letting the bridge fail later. Issue #1635.
- Fix `mosquitto_passwd -b` not updating passwords for existing users
correctly. Creating a new user with `-b` worked without problem.
Closes #1664.
- Fix memory leak when connecting clients rejected.
- Don't disconnect clients that are already disconnected. This prevents the
session expiry being extended on SIGHUP. Closes #1521.
- Fix support for openssl 3.0.
- Fix check when loading persistence file of a different version than the
native version. Closes #1684.
- Fix possible assert crash associated with bridge reconnecting when compiled
without epoll support. Closes #1700.
Client library:
- Don't treat an unexpected PUBACK, PUBREL, or PUBCOMP as a fatal error.
Issue #1629.
- Fix support for openssl 3.0.
- Fix memory leaks from multiple calls to
`mosquitto_lib_init()`/`mosquitto_lib_cleanup()`. Closes #1691.
- Fix documentation on return code of `mosquitto_lib_init()` for Windows.
Closes #1690.
Clients:
- Fix mosquitto_sub %j or %J not working on Windows. Closes #1674.
Build:
- Various fixes for building with <C99 support. Closes #1622.
- Fix use of sed on BSD. Closes #1614.
>>>>>>> fixes
1.6.9 - 20200227
================

View File

@@ -110,7 +110,6 @@ sign : dist
copy : sign
cd dist; scp mosquitto-${VERSION}.tar.gz mosquitto-${VERSION}.tar.gz.asc mosquitto:site/mosquitto.org/files/source/
cd dist; scp *.html mosquitto:site/mosquitto.org/man/
scp ChangeLog.txt mosquitto:site/mosquitto.org/
coverage :

View File

@@ -65,6 +65,8 @@ int cfg_parse_property(struct mosq_config *cfg, int argc, char *argv[], int *idx
int cmd, identifier, type;
mosquitto_property **proplist;
int rc;
long tmpl;
size_t szt;
/* idx now points to "command" */
if((*idx)+2 > argc-1){
@@ -161,19 +163,44 @@ int cfg_parse_property(struct mosq_config *cfg, int argc, char *argv[], int *idx
switch(type){
case MQTT_PROP_TYPE_BYTE:
rc = mosquitto_property_add_byte(proplist, identifier, atoi(value));
tmpl = atol(value);
if(tmpl < 0 || tmpl > UINT8_MAX){
fprintf(stderr, "Error: Property value (%ld) out of range for property %s.\n\n", tmpl, propname);
return MOSQ_ERR_INVAL;
}
rc = mosquitto_property_add_byte(proplist, identifier, (uint8_t )tmpl);
break;
case MQTT_PROP_TYPE_INT16:
rc = mosquitto_property_add_int16(proplist, identifier, atoi(value));
tmpl = atol(value);
if(tmpl < 0 || tmpl > UINT16_MAX){
fprintf(stderr, "Error: Property value (%ld) out of range for property %s.\n\n", tmpl, propname);
return MOSQ_ERR_INVAL;
}
rc = mosquitto_property_add_int16(proplist, identifier, (uint16_t )tmpl);
break;
case MQTT_PROP_TYPE_INT32:
rc = mosquitto_property_add_int32(proplist, identifier, atoi(value));
tmpl = atol(value);
if(tmpl < 0 || tmpl > UINT32_MAX){
fprintf(stderr, "Error: Property value (%ld) out of range for property %s.\n\n", tmpl, propname);
return MOSQ_ERR_INVAL;
}
rc = mosquitto_property_add_int32(proplist, identifier, (uint32_t )tmpl);
break;
case MQTT_PROP_TYPE_VARINT:
rc = mosquitto_property_add_varint(proplist, identifier, atoi(value));
tmpl = atol(value);
if(tmpl < 0 || tmpl > UINT32_MAX){
fprintf(stderr, "Error: Property value (%ld) out of range for property %s.\n\n", tmpl, propname);
return MOSQ_ERR_INVAL;
}
rc = mosquitto_property_add_varint(proplist, identifier, (uint32_t )tmpl);
break;
case MQTT_PROP_TYPE_BINARY:
rc = mosquitto_property_add_binary(proplist, identifier, value, strlen(value));
szt = strlen(value);
if(szt > UINT16_MAX){
fprintf(stderr, "Error: Property value too long for property %s.\n\n", propname);
return MOSQ_ERR_INVAL;
}
rc = mosquitto_property_add_binary(proplist, identifier, value, (uint16_t )szt);
break;
case MQTT_PROP_TYPE_STRING:
rc = mosquitto_property_add_string(proplist, identifier, value);

View File

@@ -45,7 +45,7 @@ static int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int
static int check_format(const char *str)
{
int i;
int len;
size_t len;
len = strlen(str);
for(i=0; i<len; i++){
@@ -268,7 +268,7 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
char line[1024];
int count;
char *loc = NULL;
int len;
size_t len;
char *args[3];
#ifndef WIN32
@@ -418,7 +418,7 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
fprintf(stderr, "Error: You must provide a client id if you are using an infinite session expiry interval.\n");
return 1;
}
rc = mosquitto_property_add_int32(&cfg->connect_props, MQTT_PROP_SESSION_EXPIRY_INTERVAL, cfg->session_expiry_interval);
rc = mosquitto_property_add_int32(&cfg->connect_props, MQTT_PROP_SESSION_EXPIRY_INTERVAL, (uint32_t )cfg->session_expiry_interval);
if(rc){
fprintf(stderr, "Error adding property session-expiry-interval\n");
}
@@ -481,7 +481,7 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
int cfg_add_topic(struct mosq_config *cfg, int type, char *topic, const char *arg)
{
if(mosquitto_validate_utf8(topic, strlen(topic))){
if(mosquitto_validate_utf8(topic, (int )strlen(topic))){
fprintf(stderr, "Error: Malformed UTF-8 in %s argument.\n\n", arg);
return 1;
}
@@ -503,7 +503,7 @@ int cfg_add_topic(struct mosq_config *cfg, int type, char *topic, const char *ar
return 1;
}
cfg->topic_count++;
cfg->topics = realloc(cfg->topics, cfg->topic_count*sizeof(char *));
cfg->topics = realloc(cfg->topics, (size_t )cfg->topic_count*sizeof(char *));
if(!cfg->topics){
err_printf(cfg, "Error: Out of memory.\n");
return 1;
@@ -517,7 +517,9 @@ int cfg_add_topic(struct mosq_config *cfg, int type, char *topic, const char *ar
int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, char *argv[])
{
int i;
int tmpi;
float f;
size_t szt;
for(i=1; i<argc; i++){
if(!strcmp(argv[i], "-A")){
@@ -784,7 +786,16 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
return 1;
}else{
cfg->message = strdup(argv[i+1]);
cfg->msglen = strlen(cfg->message);
if(cfg->message == NULL){
fprintf(stderr, "Error: Out of memory.\n\n");
return 1;
}
szt = strlen(cfg->message);
if(szt > MQTT_MAX_PAYLOAD){
fprintf(stderr, "Error: Message length must be less than %u bytes.\n\n", MQTT_MAX_PAYLOAD);
return 1;
}
cfg->msglen = (int )szt;
cfg->pub_mode = MSGMODE_CMD;
}
i++;
@@ -793,7 +804,12 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
fprintf(stderr, "Error: -M argument given but max_inflight not specified.\n\n");
return 1;
}else{
cfg->max_inflight = atoi(argv[i+1]);
tmpi = atoi(argv[i+1]);
if(tmpi < 1){
fprintf(stderr, "Error: Maximum inflight messages must be greater than 0.\n\n");
return 1;
}
cfg->max_inflight = (unsigned int )tmpi;
}
i++;
}else if(!strcmp(argv[i], "--nodelay")){
@@ -936,13 +952,13 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
fprintf(stderr, "Error: --repeat-delay argument given but no time specified.\n\n");
return 1;
}else{
f = atof(argv[i+1]);
f = (float )atof(argv[i+1]);
if(f < 0.0f){
fprintf(stderr, "Error: --repeat-delay argument must be >=0.0.\n\n");
return 1;
}
f *= 1.0e6;
cfg->repeat_delay.tv_sec = (int)f/1e6;
f *= 1.0e6f;
cfg->repeat_delay.tv_sec = (int)f/1000000;
cfg->repeat_delay.tv_usec = (int)f%1000000;
}
i++;
@@ -987,7 +1003,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
fprintf(stderr, "Error: -T argument given but no topic filter specified.\n\n");
return 1;
}else{
if(mosquitto_validate_utf8(argv[i+1], strlen(argv[i+1]))){
if(mosquitto_validate_utf8(argv[i+1], (int )strlen(argv[i+1]))){
fprintf(stderr, "Error: Malformed UTF-8 in -T argument.\n\n");
return 1;
}
@@ -996,7 +1012,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
return 1;
}
cfg->filter_out_count++;
cfg->filter_outs = realloc(cfg->filter_outs, cfg->filter_out_count*sizeof(char *));
cfg->filter_outs = realloc(cfg->filter_outs, (size_t )cfg->filter_out_count*sizeof(char *));
if(!cfg->filter_outs){
fprintf(stderr, "Error: Out of memory.\n");
return 1;
@@ -1046,7 +1062,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
fprintf(stderr, "Error: -U argument given but no unsubscribe topic specified.\n\n");
return 1;
}else{
if(mosquitto_validate_utf8(argv[i+1], strlen(argv[i+1]))){
if(mosquitto_validate_utf8(argv[i+1], (int )strlen(argv[i+1]))){
fprintf(stderr, "Error: Malformed UTF-8 in -U argument.\n\n");
return 1;
}
@@ -1055,7 +1071,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
return 1;
}
cfg->unsub_topic_count++;
cfg->unsub_topics = realloc(cfg->unsub_topics, cfg->unsub_topic_count*sizeof(char *));
cfg->unsub_topics = realloc(cfg->unsub_topics, (size_t )cfg->unsub_topic_count*sizeof(char *));
if(!cfg->unsub_topics){
fprintf(stderr, "Error: Out of memory.\n");
return 1;
@@ -1112,11 +1128,12 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
fprintf(stderr, "Error: -W argument given but no timeout specified.\n\n");
return 1;
}else{
cfg->timeout = atoi(argv[i+1]);
if(cfg->timeout < 1){
fprintf(stderr, "Error: Invalid timeout \"%d\".\n\n", cfg->msg_count);
tmpi = atoi(argv[i+1]);
if(tmpi < 1){
fprintf(stderr, "Error: Invalid timeout \"%d\".\n\n", tmpi);
return 1;
}
cfg->timeout = (unsigned int )tmpi;
}
i++;
}
@@ -1126,7 +1143,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
return 1;
}else{
cfg->will_payload = strdup(argv[i+1]);
cfg->will_payloadlen = strlen(cfg->will_payload);
cfg->will_payloadlen = (int )strlen(cfg->will_payload);
}
i++;
}else if(!strcmp(argv[i], "--will-qos")){
@@ -1148,7 +1165,7 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
fprintf(stderr, "Error: --will-topic argument given but no will topic specified.\n\n");
return 1;
}else{
if(mosquitto_validate_utf8(argv[i+1], strlen(argv[i+1]))){
if(mosquitto_validate_utf8(argv[i+1], (int )strlen(argv[i+1]))){
fprintf(stderr, "Error: Malformed UTF-8 in --will-topic argument.\n\n");
return 1;
}
@@ -1359,7 +1376,7 @@ int client_connect(struct mosquitto *mosq, struct mosq_config *cfg)
static int mosquitto__urldecode(char *str)
{
int i, j;
int len;
size_t len;
if(!str) return 0;
if(!strchr(str, '%')) return 0;

View File

@@ -53,7 +53,7 @@ struct mosq_config {
int pub_mode; /* pub, rr */
char *file_input; /* pub, rr */
char *message; /* pub, rr */
long msglen; /* pub, rr */
int msglen; /* pub, rr */
char *topic; /* pub, rr */
char *bind_address;
int repeat_count; /* pub */
@@ -68,7 +68,7 @@ struct mosq_config {
char *password;
char *will_topic;
char *will_payload;
long will_payloadlen;
int will_payloadlen;
int will_qos;
bool will_retain;
#ifdef WITH_TLS
@@ -104,7 +104,7 @@ struct mosq_config {
int msg_count; /* sub */
char *format; /* sub, rr */
bool pretty; /* sub, rr */
int timeout; /* sub */
unsigned int timeout; /* sub */
int sub_opts; /* sub */
long session_expiry_interval;
int random_filter; /* sub */

View File

@@ -46,6 +46,7 @@ static bool disconnect_sent = false;
static int publish_count = 0;
static bool ready_for_repeat = false;
static volatile int status = STATUS_CONNECTING;
static int connack_result = 0;
#ifdef WIN32
static uint64_t next_publish_tv;
@@ -76,7 +77,7 @@ static void set_repeat_time(void)
next_publish_tv.tv_sec += cfg.repeat_delay.tv_sec;
next_publish_tv.tv_usec += cfg.repeat_delay.tv_usec;
next_publish_tv.tv_sec += next_publish_tv.tv_usec/1e6;
next_publish_tv.tv_sec += next_publish_tv.tv_usec/1000000;
next_publish_tv.tv_usec = next_publish_tv.tv_usec%1000000;
}
@@ -129,6 +130,8 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flag
UNUSED(flags);
UNUSED(properties);
connack_result = result;
if(!result){
switch(cfg.pub_mode){
case MSGMODE_CMD:
@@ -217,7 +220,7 @@ void my_publish_callback(struct mosquitto *mosq, void *obj, int mid, int reason_
int pub_shared_init(void)
{
line_buf = malloc(line_buf_len);
line_buf = malloc((size_t )line_buf_len);
if(!line_buf){
err_printf(&cfg, "Error: Out of memory.\n");
return 1;
@@ -238,11 +241,22 @@ int pub_stdin_line_loop(struct mosquitto *mosq)
mosquitto_loop_start(mosq);
stdin_finished = false;
do{
if(status == STATUS_CONNECTING){
#ifdef WIN32
Sleep(100);
#else
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 100000000;
nanosleep(&ts, NULL);
#endif
}
if(status == STATUS_CONNACK_RECVD){
pos = 0;
read_len = line_buf_len;
while(status == STATUS_CONNACK_RECVD && fgets(&line_buf[pos], read_len, stdin)){
buf_len_actual = strlen(line_buf);
buf_len_actual = (int )strlen(line_buf);
if(line_buf[buf_len_actual-1] == '\n'){
line_buf[buf_len_actual-1] = '\0';
rc = my_publish(mosq, &mid_sent, cfg.topic, buf_len_actual-1, line_buf, cfg.qos, cfg.retain);
@@ -256,7 +270,7 @@ int pub_stdin_line_loop(struct mosquitto *mosq)
line_buf_len += 1024;
pos += 1023;
read_len = 1024;
buf2 = realloc(line_buf, line_buf_len);
buf2 = realloc(line_buf, (size_t )line_buf_len);
if(!buf2){
err_printf(&cfg, "Error: Out of memory.\n");
return MOSQ_ERR_NOMEM;
@@ -319,7 +333,7 @@ int pub_other_loop(struct mosquitto *mosq)
int loop_delay = 1000;
if(cfg.repeat_count > 1 && (cfg.repeat_delay.tv_sec == 0 || cfg.repeat_delay.tv_usec != 0)){
loop_delay = cfg.repeat_delay.tv_usec / 2000;
loop_delay = (int )cfg.repeat_delay.tv_usec / 2000;
}
do{
@@ -584,7 +598,11 @@ int main(int argc, char *argv[])
if(rc){
err_printf(&cfg, "Error: %s\n", mosquitto_strerror(rc));
}
return rc;
if(connack_result){
return connack_result;
}else{
return rc;
}
cleanup:
mosquitto_lib_cleanup();

View File

@@ -50,7 +50,7 @@ void my_log_callback(struct mosquitto *mosq, void *obj, int level, const char *s
int load_stdin(void)
{
long pos = 0, rlen;
size_t pos = 0, rlen;
char buf[1024];
char *aux_message = NULL;
@@ -70,7 +70,12 @@ int load_stdin(void)
memcpy(&(cfg.message[pos]), buf, rlen);
pos += rlen;
}
cfg.msglen = pos;
if(pos > MQTT_MAX_PAYLOAD){
err_printf(&cfg, "Error: Message length must be less than %u bytes.\n\n", MQTT_MAX_PAYLOAD);
free(cfg.message);
return 1;
}
cfg.msglen = (int )pos;
if(!cfg.msglen){
err_printf(&cfg, "Error: Zero length input.\n");
@@ -82,8 +87,9 @@ int load_stdin(void)
int load_file(const char *filename)
{
long pos, rlen;
size_t pos, rlen;
FILE *fptr = NULL;
long flen;
fptr = fopen(filename, "rb");
if(!fptr){
@@ -92,12 +98,13 @@ int load_file(const char *filename)
}
cfg.pub_mode = MSGMODE_FILE;
fseek(fptr, 0, SEEK_END);
cfg.msglen = ftell(fptr);
if(cfg.msglen > 268435455){
flen = ftell(fptr);
if(flen > MQTT_MAX_PAYLOAD){
fclose(fptr);
err_printf(&cfg, "Error: File \"%s\" is too large (>268,435,455 bytes).\n", filename);
err_printf(&cfg, "Error: File must be less than %u bytes.\n\n", MQTT_MAX_PAYLOAD);
free(cfg.message);
return 1;
}else if(cfg.msglen == 0){
}else if(flen == 0){
fclose(fptr);
cfg.message = NULL;
cfg.msglen = 0;
@@ -107,8 +114,9 @@ int load_file(const char *filename)
err_printf(&cfg, "Error: Unable to determine size of file \"%s\".\n", filename);
return 1;
}
cfg.msglen = (int )flen;
fseek(fptr, 0, SEEK_SET);
cfg.message = malloc(cfg.msglen);
cfg.message = malloc((size_t )cfg.msglen);
if(!cfg.message){
fclose(fptr);
err_printf(&cfg, "Error: Out of memory.\n");
@@ -116,7 +124,7 @@ int load_file(const char *filename)
}
pos = 0;
while(pos < cfg.msglen){
rlen = fread(&(cfg.message[pos]), sizeof(char), cfg.msglen-pos, fptr);
rlen = fread(&(cfg.message[pos]), sizeof(char), (size_t )cfg.msglen-pos, fptr);
pos += rlen;
}
fclose(fptr);

View File

@@ -54,6 +54,7 @@ bool process_messages = true;
int msg_count = 0;
struct mosquitto *mosq = NULL;
static bool timed_out = false;
static int connack_result = 0;
#ifndef WIN32
void my_signal_handler(int signum)
@@ -118,6 +119,7 @@ void my_message_callback(struct mosquitto *mosq, void *obj, const struct mosquit
void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flags, const mosquitto_property *properties)
{
connack_result = result;
if(!result){
client_state = rr_s_connected;
mosquitto_subscribe_v5(mosq, NULL, cfg.response_topic, cfg.qos, 0, cfg.subscribe_props);
@@ -392,7 +394,11 @@ int main(int argc, char *argv[])
}else if(rc){
err_printf(&cfg, "Error: %s\n", mosquitto_strerror(rc));
}
return rc;
if(connack_result){
return connack_result;
}else{
return rc;
}
cleanup:
mosquitto_lib_cleanup();

View File

@@ -42,6 +42,7 @@ int msg_count = 0;
struct mosquitto *mosq = NULL;
int last_mid = 0;
static bool timed_out = false;
static int connack_result = 0;
#ifndef WIN32
void my_signal_handler(int signum)
@@ -120,6 +121,7 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flag
UNUSED(flags);
UNUSED(properties);
connack_result = result;
if(!result){
mosquitto_subscribe_multiple(mosq, NULL, cfg.topic_count, cfg.topics, cfg.qos, cfg.sub_opts, cfg.subscribe_props);
@@ -412,7 +414,11 @@ int main(int argc, char *argv[])
}else if(rc){
err_printf(&cfg, "Error: %s\n", mosquitto_strerror(rc));
}
return rc;
if(connack_result){
return connack_result;
}else{
return rc;
}
cleanup:
mosquitto_destroy(mosq);

View File

@@ -110,7 +110,7 @@ static void write_payload(const unsigned char *payload, int payloadlen, int hex,
}
if(hex == 0){
(void)fwrite(payload, 1, payloadlen, stdout);
(void)fwrite(payload, 1, (size_t )payloadlen, stdout);
}else if(hex == 1){
for(i=0; i<payloadlen; i++){
fprintf(stdout, "%02x", payload[i]);

View File

@@ -118,7 +118,7 @@ WITH_CONTROL:=yes
# Also bump lib/mosquitto.h, CMakeLists.txt,
# installer/mosquitto.nsi, installer/mosquitto64.nsi
VERSION=1.6.9
VERSION=1.6.12
# Client library SO version. Bump if incompatible API/ABI changes are made.
SOVERSION=1
@@ -167,8 +167,10 @@ PASSWD_LDADD:=
ifneq ($(or $(findstring $(UNAME),FreeBSD), $(findstring $(UNAME),OpenBSD), $(findstring $(UNAME),NetBSD)),)
BROKER_LDADD:=$(BROKER_LDADD) -lm
SEDINPLACE:=-i ""
else
BROKER_LDADD:=$(BROKER_LDADD) -ldl -lm
SEDINPLACE:=-i
endif
ifeq ($(UNAME),Linux)

View File

@@ -1,14 +0,0 @@
FROM alpine:3.6
MAINTAINER David Audet <david.audet@ca.com>
LABEL Description="Eclipse Mosquitto MQTT Broker"
RUN apk --no-cache add mosquitto=1.4.12-r0 ca-certificates && \
mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \
cp /etc/mosquitto/mosquitto.conf /mosquitto/config && \
chown -R mosquitto:mosquitto /mosquitto
COPY docker-entrypoint.sh /
EXPOSE 1883
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["/usr/sbin/mosquitto", "-c", "/mosquitto/config/mosquitto.conf"]

View File

@@ -1,49 +0,0 @@
#Eclipse Mosquitto v1.4.12 Docker Image
##Mount Points
Three mount points have been created in the image to be used for configuration, persistent storage and logs.
```
/mosquitto/config
/mosquitto/data
/mosquitto/log
```
##Configuration
When running the image, the default configuration values are used.
To use a custom configuration file, mount a **local** configuration file to `/mosquitto/config/mosquitto.conf`
```
docker run -it -p 1883:1883 -p 9001:9001 -v <path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:1.4.12
```
Configuration can be changed to:
* persist data to `/mosquitto/data`
* log to `/mosquitto/log/mosquitto.log`
i.e. add the following to `mosquitto.conf`:
```
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
```
**Note**: If a volume is used, the data will persist between containers.
##Build
Build the image:
```
docker build -t eclipse-mosquitto:1.4.12 .
```
##Run
Run a container using the new image:
```
docker run -it -p 1883:1883 -p 9001:9001 -v <path-to-configuration-file>:/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log eclipse-mosquitto:1.4.12
```
:boom: if the mosquitto configuration (mosquitto.conf) was modified
to use non-default ports, the docker run command will need to be updated
to expose the ports that have been configured.

View File

@@ -1,5 +0,0 @@
#!/bin/ash
set -e
exec "$@"

View File

@@ -0,0 +1,90 @@
FROM alpine:3.12
LABEL maintainer="Roger Light <roger@atchoo.org>" \
description="Eclipse Mosquitto MQTT Broker"
ENV VERSION=1.5.9 \
DOWNLOAD_SHA256=d7b62aa0ca680b0d869d6883373903362f98326a6465fc6cd01a0b9e0e8f0333 \
GPG_KEYS=A0D6EEA1DCAE49A635A3B2F0779B22DFB3E717B7 \
LWS_VERSION=2.4.2
RUN set -x && \
apk --no-cache add --virtual build-deps \
build-base \
cmake \
gnupg \
openssl-dev \
util-linux-dev && \
wget https://github.com/warmcat/libwebsockets/archive/v${LWS_VERSION}.tar.gz -O /tmp/lws.tar.gz && \
mkdir -p /build/lws && \
tar --strip=1 -xf /tmp/lws.tar.gz -C /build/lws && \
rm /tmp/lws.tar.gz && \
cd /build/lws && \
cmake . \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DCMAKE_INSTALL_PREFIX=/usr \
-DLWS_IPV6=ON \
-DLWS_WITHOUT_BUILTIN_GETIFADDRS=ON \
-DLWS_WITHOUT_CLIENT=ON \
-DLWS_WITHOUT_EXTENSIONS=ON \
-DLWS_WITHOUT_TESTAPPS=ON \
-DLWS_WITH_SHARED=OFF \
-DLWS_WITH_ZIP_FOPS=OFF \
-DLWS_WITH_ZLIB=OFF && \
make -j "$(nproc)" && \
rm -rf /root/.cmake && \
wget https://mosquitto.org/files/source/mosquitto-${VERSION}.tar.gz -O /tmp/mosq.tar.gz && \
echo "$DOWNLOAD_SHA256 /tmp/mosq.tar.gz" | sha256sum -c - && \
wget https://mosquitto.org/files/source/mosquitto-${VERSION}.tar.gz.asc -O /tmp/mosq.tar.gz.asc && \
export GNUPGHOME="$(mktemp -d)" && \
found=''; \
for server in \
ha.pool.sks-keyservers.net \
hkp://keyserver.ubuntu.com:80 \
hkp://p80.pool.sks-keyservers.net:80 \
pgp.mit.edu \
; do \
echo "Fetching GPG key $GPG_KEYS from $server"; \
gpg --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$GPG_KEYS" && found=yes && break; \
done; \
test -z "$found" && echo >&2 "error: failed to fetch GPG key $GPG_KEYS" && exit 1; \
gpg --batch --verify /tmp/mosq.tar.gz.asc /tmp/mosq.tar.gz && \
gpgconf --kill all && \
rm -rf "$GNUPGHOME" /tmp/mosq.tar.gz.asc && \
mkdir -p /build/mosq && \
tar --strip=1 -xf /tmp/mosq.tar.gz -C /build/mosq && \
rm /tmp/mosq.tar.gz && \
make -C /build/mosq -j "$(nproc)" \
CFLAGS="-Wall -O2 -I/build/lws/include -flto" \
LDFLAGS="-L/build/lws/lib -flto" \
WITH_ADNS=no \
WITH_DOCS=no \
WITH_SHARED_LIBRARIES=yes \
WITH_SRV=no \
WITH_STRIP=yes \
WITH_WEBSOCKETS=yes \
prefix=/usr \
binary && \
addgroup -S -g 1883 mosquitto 2>/dev/null && \
adduser -S -u 1883 -D -H -h /var/empty -s /sbin/nologin -G mosquitto -g mosquitto mosquitto 2>/dev/null && \
mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \
install -d /usr/sbin/ && \
install -s -m755 /build/mosq/client/mosquitto_pub /usr/bin/mosquitto_pub && \
install -s -m755 /build/mosq/client/mosquitto_sub /usr/bin/mosquitto_sub && \
install -s -m644 /build/mosq/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1 && \
install -s -m755 /build/mosq/src/mosquitto /usr/sbin/mosquitto && \
install -s -m755 /build/mosq/src/mosquitto_passwd /usr/bin/mosquitto_passwd && \
install -m644 /build/mosq/mosquitto.conf /mosquitto/config/mosquitto.conf && \
chown -R mosquitto:mosquitto /mosquitto && \
apk --no-cache add \
ca-certificates libuuid && \
apk del build-deps && \
rm -rf /build
VOLUME ["/mosquitto/data", "/mosquitto/log"]
# Set up the entry point script and default command
COPY docker-entrypoint.sh /
EXPOSE 1883
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["/usr/sbin/mosquitto", "-c", "/mosquitto/config/mosquitto.conf"]

View File

@@ -0,0 +1,49 @@
# Eclipse Mosquitto Docker Image
Containers built with this Dockerfile build as source from published tarballs.
## Mount Points
A docker mount point has been created in the image to be used for configuration.
```
/mosquitto/config
```
Two docker volumes have been created in the image to be used for persistent storage and logs.
```
/mosquitto/data
/mosquitto/log
```
## User/Group
The image runs mosquitto under the mosquitto user and group, which are created
with a uid and gid of 1883.
## Configuration
When creating a container from the image, the default configuration values are used.
To use a custom configuration file, mount a **local** configuration file to `/mosquitto/config/mosquitto.conf`
```
docker run -it -p 1883:1883 -v <absolute-path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:<version>
```
:boom: if the mosquitto configuration (mosquitto.conf) was modified
to use non-default ports, the docker run command will need to be updated
to expose the ports that have been configured, for example:
```
docker run -it -p 1883:1883 -p 8080:8080 -v <absolute-path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:<version>
```
Configuration can be changed to:
* persist data to `/mosquitto/data`
* log to `/mosquitto/log/mosquitto.log`
i.e. add the following to `mosquitto.conf`:
```
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
```
**Note**: For any volume used, the data will be persistent between containers.

View File

@@ -0,0 +1,10 @@
#!/bin/ash
set -e
# Set permissions
user="$(id -u)"
if [ "$user" = '0' ]; then
[ -d "/mosquitto" ] && chown -R mosquitto:mosquitto /mosquitto || true
fi
exec "$@"

View File

@@ -1,4 +1,4 @@
FROM alpine:3.8
FROM alpine:3.12
LABEL maintainer="Roger Light <roger@atchoo.org>" \
description="Eclipse Mosquitto MQTT Broker"
@@ -62,7 +62,7 @@ RUN set -x && \
WITH_SHARED_LIBRARIES=yes \
WITH_SRV=no \
WITH_STRIP=yes \
WITH_TLS_PSK=no \
WITH_TLS_PSK=no \
WITH_WEBSOCKETS=yes \
prefix=/usr \
binary && \
@@ -78,7 +78,9 @@ RUN set -x && \
install -m644 /build/mosq/mosquitto.conf /mosquitto/config/mosquitto.conf && \
chown -R mosquitto:mosquitto /mosquitto && \
apk --no-cache add \
ca-certificates libuuid && \
ca-certificates \
libressl \
libuuid && \
apk del build-deps && \
rm -rf /build

View File

@@ -30,7 +30,7 @@ to use non-default ports, the docker run command will need to be updated
to expose the ports that have been configured, for example:
```
docker run -it -p 1883:1883 -p 9001:9001 -v <absolute-path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:<version>
docker run -it -p 1883:1883 -p 8080:8080 -v <absolute-path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:<version>
```
Configuration can be changed to:

View File

@@ -1,4 +1,10 @@
#!/bin/ash
set -e
# Set permissions
user="$(id -u)"
if [ "$user" = '0' ]; then
[ -d "/mosquitto" ] && chown -R mosquitto:mosquitto /mosquitto || true
fi
exec "$@"

View File

@@ -0,0 +1,91 @@
FROM alpine:3.12
LABEL maintainer="Roger Light <roger@atchoo.org>" \
description="Eclipse Mosquitto MQTT Broker"
ENV VERSION=1.6.11 \
DOWNLOAD_SHA256=b02d8f1368c40d5779ee125c37daf9003608eb47d7fbb04c5b938c76c1230a1f \
GPG_KEYS=A0D6EEA1DCAE49A635A3B2F0779B22DFB3E717B7 \
LWS_VERSION=2.4.2
RUN set -x && \
apk --no-cache add --virtual build-deps \
build-base \
cmake \
gnupg \
openssl-dev \
util-linux-dev && \
wget https://github.com/warmcat/libwebsockets/archive/v${LWS_VERSION}.tar.gz -O /tmp/lws.tar.gz && \
mkdir -p /build/lws && \
tar --strip=1 -xf /tmp/lws.tar.gz -C /build/lws && \
rm /tmp/lws.tar.gz && \
cd /build/lws && \
cmake . \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DCMAKE_INSTALL_PREFIX=/usr \
-DLWS_IPV6=ON \
-DLWS_WITHOUT_BUILTIN_GETIFADDRS=ON \
-DLWS_WITHOUT_CLIENT=ON \
-DLWS_WITHOUT_EXTENSIONS=ON \
-DLWS_WITHOUT_TESTAPPS=ON \
-DLWS_WITH_SHARED=OFF \
-DLWS_WITH_ZIP_FOPS=OFF \
-DLWS_WITH_ZLIB=OFF && \
make -j "$(nproc)" && \
rm -rf /root/.cmake && \
wget https://mosquitto.org/files/source/mosquitto-${VERSION}.tar.gz -O /tmp/mosq.tar.gz && \
echo "$DOWNLOAD_SHA256 /tmp/mosq.tar.gz" | sha256sum -c - && \
wget https://mosquitto.org/files/source/mosquitto-${VERSION}.tar.gz.asc -O /tmp/mosq.tar.gz.asc && \
export GNUPGHOME="$(mktemp -d)" && \
found=''; \
for server in \
ha.pool.sks-keyservers.net \
hkp://keyserver.ubuntu.com:80 \
hkp://p80.pool.sks-keyservers.net:80 \
pgp.mit.edu \
; do \
echo "Fetching GPG key $GPG_KEYS from $server"; \
gpg --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$GPG_KEYS" && found=yes && break; \
done; \
test -z "$found" && echo >&2 "error: failed to fetch GPG key $GPG_KEYS" && exit 1; \
gpg --batch --verify /tmp/mosq.tar.gz.asc /tmp/mosq.tar.gz && \
gpgconf --kill all && \
rm -rf "$GNUPGHOME" /tmp/mosq.tar.gz.asc && \
mkdir -p /build/mosq && \
tar --strip=1 -xf /tmp/mosq.tar.gz -C /build/mosq && \
rm /tmp/mosq.tar.gz && \
make -C /build/mosq -j "$(nproc)" \
CFLAGS="-Wall -O2 -I/build/lws/include" \
LDFLAGS="-L/build/lws/lib" \
WITH_ADNS=no \
WITH_DOCS=no \
WITH_SHARED_LIBRARIES=yes \
WITH_SRV=no \
WITH_STRIP=yes \
WITH_WEBSOCKETS=yes \
prefix=/usr \
binary && \
addgroup -S -g 1883 mosquitto 2>/dev/null && \
adduser -S -u 1883 -D -H -h /var/empty -s /sbin/nologin -G mosquitto -g mosquitto mosquitto 2>/dev/null && \
mkdir -p /mosquitto/config /mosquitto/data /mosquitto/log && \
install -d /usr/sbin/ && \
install -s -m755 /build/mosq/client/mosquitto_pub /usr/bin/mosquitto_pub && \
install -s -m755 /build/mosq/client/mosquitto_rr /usr/bin/mosquitto_rr && \
install -s -m755 /build/mosq/client/mosquitto_sub /usr/bin/mosquitto_sub && \
install -s -m644 /build/mosq/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1 && \
install -s -m755 /build/mosq/src/mosquitto /usr/sbin/mosquitto && \
install -s -m755 /build/mosq/src/mosquitto_passwd /usr/bin/mosquitto_passwd && \
install -m644 /build/mosq/mosquitto.conf /mosquitto/config/mosquitto.conf && \
chown -R mosquitto:mosquitto /mosquitto && \
apk --no-cache add \
ca-certificates && \
apk del build-deps && \
rm -rf /build
VOLUME ["/mosquitto/data", "/mosquitto/log"]
# Set up the entry point script and default command
COPY docker-entrypoint.sh /
EXPOSE 1883
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["/usr/sbin/mosquitto", "-c", "/mosquitto/config/mosquitto.conf"]

View File

@@ -0,0 +1,49 @@
# Eclipse Mosquitto Docker Image
Containers built with this Dockerfile build as source from published tarballs.
## Mount Points
A docker mount point has been created in the image to be used for configuration.
```
/mosquitto/config
```
Two docker volumes have been created in the image to be used for persistent storage and logs.
```
/mosquitto/data
/mosquitto/log
```
## User/Group
The image runs mosquitto under the mosquitto user and group, which are created
with a uid and gid of 1883.
## Configuration
When creating a container from the image, the default configuration values are used.
To use a custom configuration file, mount a **local** configuration file to `/mosquitto/config/mosquitto.conf`
```
docker run -it -p 1883:1883 -v <absolute-path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:<version>
```
:boom: if the mosquitto configuration (mosquitto.conf) was modified
to use non-default ports, the docker run command will need to be updated
to expose the ports that have been configured, for example:
```
docker run -it -p 1883:1883 -p 8080:8080 -v <absolute-path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:<version>
```
Configuration can be changed to:
* persist data to `/mosquitto/data`
* log to `/mosquitto/log/mosquitto.log`
i.e. add the following to `mosquitto.conf`:
```
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
```
**Note**: For any volume used, the data will be persistent between containers.

View File

@@ -0,0 +1,10 @@
#!/bin/ash
set -e
# Set permissions
user="$(id -u)"
if [ "$user" = '0' ]; then
[ -d "/mosquitto" ] && chown -R mosquitto:mosquitto /mosquitto || true
fi
exec "$@"

View File

@@ -1,10 +1,10 @@
FROM alpine:3.8
FROM alpine:3.12
LABEL maintainer="Roger Light <roger@atchoo.org>" \
description="Eclipse Mosquitto MQTT Broker"
ENV VERSION=1.6.8 \
DOWNLOAD_SHA256=7df23c81ca37f0e070574fe74414403cf25183016433d07add6134366fb45df6 \
ENV VERSION=1.6.11 \
DOWNLOAD_SHA256=b02d8f1368c40d5779ee125c37daf9003608eb47d7fbb04c5b938c76c1230a1f \
GPG_KEYS=A0D6EEA1DCAE49A635A3B2F0779B22DFB3E717B7 \
LWS_VERSION=2.4.2
@@ -79,7 +79,8 @@ RUN set -x && \
install -m644 /build/mosq/mosquitto.conf /mosquitto/config/mosquitto.conf && \
chown -R mosquitto:mosquitto /mosquitto && \
apk --no-cache add \
ca-certificates && \
ca-certificates \
libressl && \
apk del build-deps && \
rm -rf /build

View File

@@ -30,7 +30,7 @@ to use non-default ports, the docker run command will need to be updated
to expose the ports that have been configured, for example:
```
docker run -it -p 1883:1883 -p 9001:9001 -v <absolute-path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:<version>
docker run -it -p 1883:1883 -p 8080:8080 -v <absolute-path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:<version>
```
Configuration can be changed to:

View File

@@ -1,4 +1,10 @@
#!/bin/ash
set -e
# Set permissions
user="$(id -u)"
if [ "$user" = '0' ]; then
[ -d "/mosquitto" ] && chown -R mosquitto:mosquitto /mosquitto || true
fi
exec "$@"

View File

@@ -2,11 +2,14 @@
This directory contains Docker files for Mosquitto.
The `1.5` directory contains the latest version of Mosquitto for
that series, and provide the basis of the official image.
The `1.6` directory contains the latest version of Mosquitto for
that series, and provide the basis of the official image. It uses libressl. The
`1.6-openssl` directory is identical except that it uses openssl instead of
libressl, and enables TLS-PSK support.
`1.4.12` is the version using Alpine packaged Mosquitto, which will be removed
at the next minor release.
The `1.5` directory contains the version of Mosquitto based on the 1.5 branch.
It uses libressl. The `1.5-openssl` directory is identical except that it uses
openssl instead of libressl, and enables TLS-PSK support.
The `generic` directory contains a generic Dockerfile that can be used to build
arbitrary versions of Mosquitto based on the released tarballs as follows:

View File

@@ -6,7 +6,7 @@ RUN test -n "${VERSION}"
RUN apk --no-cache add \
build-base \
libressl-dev \
openssl-dev \
c-ares-dev \
curl \
util-linux-dev \
@@ -48,8 +48,7 @@ LABEL maintainer="Jonathan Hanson <jonathan@jonathan-hanson.org>" \
RUN apk --no-cache add \
busybox \
ca-certificates \
libcrypto1.0 \
libssl1.0 \
openssl \
libuuid \
libwebsockets \
musl

View File

@@ -13,7 +13,7 @@ Three docker volumes have been created in the image to be used for configuration
When creating a container from the image, the default configuration values are used.
To use a custom configuration file, mount a **local** configuration file to `/mosquitto/config/mosquitto.conf`
```
docker run -it -p 1883:1883 -p 9001:9001 -v <absolute-path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:<version>
docker run -it -p 1883:1883 -v <absolute-path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:<version>
```
Configuration can be changed to:
@@ -40,7 +40,7 @@ docker build -t eclipse-mosquitto:<version> --build-arg VERSION="<version>" .
## Run
Run a container using the new image:
```
docker run -it -p 1883:1883 -p 9001:9001 -v <path-to-configuration-file>:/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log eclipse-mosquitto:<version>
docker run -it -p 1883:1883 -v <path-to-configuration-file>:/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log eclipse-mosquitto:<version>
```
:boom: if the mosquitto configuration (mosquitto.conf) was modified
to use non-default ports, the docker run command will need to be updated

View File

@@ -1,4 +1,10 @@
#!/bin/ash
set -e
# Set permissions
user="$(id -u)"
if [ "$user" = '0' ]; then
[ -d "/mosquitto" ] && chown -R mosquitto:mosquitto /mosquitto || true
fi
exec "$@"

View File

@@ -1,4 +1,4 @@
FROM alpine:3.8
FROM alpine:3.12
LABEL maintainer="Roger Light <roger@atchoo.org>" \
description="Eclipse Mosquitto MQTT Broker"
@@ -12,7 +12,7 @@ RUN set -x && \
build-base \
cmake \
gnupg \
libressl-dev \
openssl-dev \
util-linux-dev && \
wget https://github.com/warmcat/libwebsockets/archive/v${LWS_VERSION}.tar.gz -O /tmp/lws.tar.gz && \
mkdir -p /build/lws && \
@@ -43,7 +43,6 @@ RUN set -x && \
WITH_SHARED_LIBRARIES=yes \
WITH_SRV=no \
WITH_STRIP=yes \
WITH_TLS_PSK=no \
WITH_WEBSOCKETS=yes \
prefix=/usr \
binary && \

View File

@@ -29,10 +29,11 @@ docker run -it -p 1883:1883 -v <absolute-path-to-configuration-file>:/mosquitto/
:boom: if the mosquitto configuration (mosquitto.conf) was modified
to use non-default ports, the docker run command will need to be updated
to expose the ports that have been configured, for example:
to expose the ports that have been configured, for example if you use port 8080
for websockets as well as port 1883:
```
docker run -it -p 1883:1883 -p 9001:9001 -v <absolute-path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:<version>
docker run -it -p 1883:1883 -p 8080:8080 -v <absolute-path-to-configuration-file>:/mosquitto/config/mosquitto.conf eclipse-mosquitto:<version>
```
Configuration can be changed to:

View File

@@ -1,4 +1,10 @@
#!/bin/ash
set -e
# Set permissions
user="$(id -u)"
if [ "$user" = '0' ]; then
[ -d "/mosquitto" ] && chown -R mosquitto:mosquitto /mosquitto || true
fi
exec "$@"

View File

@@ -2,5 +2,5 @@ This is a simple example of the C++ library mosquittopp.
It is a client that subscribes to the topic temperature/celsius which should
have temperature data in text form being published to it. It reads this data as
a Celsius temperature, converts to Farenheit and republishes on
temperature/farenheit.
a Celsius temperature, converts to Fahrenheit and republishes on
temperature/fahrenheit.

View File

@@ -28,7 +28,7 @@ void mqtt_tempconv::on_connect(int rc)
void mqtt_tempconv::on_message(const struct mosquitto_message *message)
{
double temp_celsius, temp_farenheit;
double temp_celsius, temp_fahrenheit;
char buf[51];
if(!strcmp(message->topic, "temperature/celsius")){
@@ -36,9 +36,9 @@ void mqtt_tempconv::on_message(const struct mosquitto_message *message)
/* Copy N-1 bytes to ensure always 0 terminated. */
memcpy(buf, message->payload, 50*sizeof(char));
temp_celsius = atof(buf);
temp_farenheit = temp_celsius*9.0/5.0 + 32.0;
snprintf(buf, 50, "%f", temp_farenheit);
publish(NULL, "temperature/farenheit", strlen(buf), buf);
temp_fahrenheit = temp_celsius*9.0/5.0 + 32.0;
snprintf(buf, 50, "%f", temp_fahrenheit);
publish(NULL, "temperature/fahrenheit", strlen(buf), buf);
}
}

View File

@@ -9,7 +9,7 @@
!define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
Name "Eclipse Mosquitto"
!define VERSION 1.6.9
!define VERSION 1.6.12
OutFile "mosquitto-${VERSION}-install-windows-x86.exe"
InstallDir "$PROGRAMFILES\mosquitto"

View File

@@ -9,7 +9,7 @@
!define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
Name "Eclipse Mosquitto"
!define VERSION 1.6.9
!define VERSION 1.6.12
OutFile "mosquitto-${VERSION}-install-windows-x64.exe"
!include "x64.nsh"

View File

@@ -74,7 +74,7 @@ endif
$(INSTALL) mqtt_protocol.h "${DESTDIR}${incdir}/mqtt_protocol.h"
$(INSTALL) -d "${DESTDIR}${libdir}/pkgconfig"
$(INSTALL) -m644 ../libmosquitto.pc.in "${DESTDIR}${libdir}/pkgconfig/libmosquitto.pc"
sed -i -e "s#@CMAKE_INSTALL_PREFIX@#${prefix}#" -e "s#@VERSION@#${VERSION}#" "${DESTDIR}${libdir}/pkgconfig/libmosquitto.pc"
sed ${SEDINPLACE} -e "s#@CMAKE_INSTALL_PREFIX@#${prefix}#" -e "s#@VERSION@#${VERSION}#" "${DESTDIR}${libdir}/pkgconfig/libmosquitto.pc"
ifeq ($(WITH_SHARED_LIBRARIES),yes)
$(MAKE) -C cpp install
endif

View File

@@ -155,9 +155,9 @@ int mosquitto_publish_v5(struct mosquitto *mosq, int *mid, const char *topic, in
pthread_mutex_lock(&mosq->msgs_out.mutex);
message->state = mosq_ms_invalid;
message__queue(mosq, message, mosq_md_out);
rc = message__queue(mosq, message, mosq_md_out);
pthread_mutex_unlock(&mosq->msgs_out.mutex);
return MOSQ_ERR_SUCCESS;
return rc;
}
}

View File

@@ -81,20 +81,6 @@ static int mosquitto__connect_init(struct mosquitto *mosq, const char *host, int
mosq->msgs_out.inflight_quota = mosq->msgs_out.inflight_maximum;
mosq->retain_available = 1;
if(mosq->sockpairR != INVALID_SOCKET){
COMPAT_CLOSE(mosq->sockpairR);
mosq->sockpairR = INVALID_SOCKET;
}
if(mosq->sockpairW != INVALID_SOCKET){
COMPAT_CLOSE(mosq->sockpairW);
mosq->sockpairW = INVALID_SOCKET;
}
if(net__socketpair(&mosq->sockpairR, &mosq->sockpairW)){
log__printf(mosq, MOSQ_LOG_WARNING,
"Warning: Unable to open socket pair, outgoing publish commands may be delayed.");
}
return MOSQ_ERR_SUCCESS;
}

View File

@@ -26,7 +26,7 @@ endif
$(INSTALL) mosquittopp.h "${DESTDIR}${incdir}/mosquittopp.h"
$(INSTALL) -d "${DESTDIR}${libdir}/pkgconfig/"
$(INSTALL) -m644 ../../libmosquittopp.pc.in "${DESTDIR}${libdir}/pkgconfig/libmosquittopp.pc"
sed -i -e "s#@CMAKE_INSTALL_PREFIX@#${prefix}#" -e "s#@VERSION@#${VERSION}#" "${DESTDIR}${libdir}/pkgconfig/libmosquittopp.pc"
sed ${SEDINPLACE} -e "s#@CMAKE_INSTALL_PREFIX@#${prefix}#" -e "s#@VERSION@#${VERSION}#" "${DESTDIR}${libdir}/pkgconfig/libmosquittopp.pc"
uninstall :
-rm -f "${DESTDIR}${libdir}/libmosquittopp.so.${SOVERSION}"

View File

@@ -4,6 +4,7 @@
#define pthread_create(A, B, C, D)
#define pthread_join(A, B)
#define pthread_cancel(A)
#define pthread_testcancel()
#define pthread_mutex_init(A, B)
#define pthread_mutex_destroy(A)

View File

@@ -104,6 +104,7 @@ int handle__connack(struct mosquitto *mosq)
mosquitto_property_read_int32(properties, MQTT_PROP_MAXIMUM_PACKET_SIZE, &mosq->maximum_packet_size, false);
mosq->msgs_out.inflight_quota = mosq->msgs_out.inflight_maximum;
message__reconnect_reset(mosq);
connack_callback(mosq, reason_code, connect_flags, properties);
mosquitto_property_free_all(&properties);

View File

@@ -92,9 +92,7 @@ int handle__pubackcomp(struct mosquitto *mosq, const char *type)
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received %s (Mid: %d, RC:%d)", mosq->id, type, mid, reason_code);
rc = message__delete(mosq, mid, mosq_md_out, qos);
if(rc){
return rc;
}else{
if(rc == MOSQ_ERR_SUCCESS){
/* Only inform the client the message has been sent once. */
pthread_mutex_lock(&mosq->callback_mutex);
if(mosq->on_publish){
@@ -109,6 +107,8 @@ int handle__pubackcomp(struct mosquitto *mosq, const char *type)
}
pthread_mutex_unlock(&mosq->callback_mutex);
mosquitto_property_free_all(&properties);
}else if(rc != MOSQ_ERR_NOT_FOUND){
return rc;
}
pthread_mutex_lock(&mosq->msgs_out.mutex);
message__release_to_inflight(mosq, mosq_md_out);

View File

@@ -101,9 +101,7 @@ int handle__pubrel(struct mosquitto_db *db, struct mosquitto *mosq)
}
rc = message__remove(mosq, mid, mosq_md_in, &message, 2);
if(rc){
return rc;
}else{
if(rc == MOSQ_ERR_SUCCESS){
/* Only pass the message on if we have removed it from the queue - this
* prevents multiple callbacks for the same message. */
pthread_mutex_lock(&mosq->callback_mutex);
@@ -120,6 +118,10 @@ int handle__pubrel(struct mosquitto_db *db, struct mosquitto *mosq)
pthread_mutex_unlock(&mosq->callback_mutex);
mosquitto_property_free_all(&properties);
message__cleanup(&message);
}else if(rc == MOSQ_ERR_NOT_FOUND){
return MOSQ_ERR_SUCCESS;
}else{
return rc;
}
#endif

View File

@@ -109,6 +109,7 @@ MOSQ_1.6 {
mosquitto_property_add_varint;
mosquitto_property_check_all;
mosquitto_property_check_command;
mosquitto_property_copy_all;
mosquitto_property_free_all;
mosquitto_property_read_binary;
mosquitto_property_read_byte;

View File

@@ -191,14 +191,63 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets)
}
static int interruptible_sleep(struct mosquitto *mosq, unsigned long reconnect_delay)
{
#ifdef HAVE_PSELECT
struct timespec local_timeout;
#else
struct timeval local_timeout;
#endif
fd_set readfds;
int fdcount;
char pairbuf;
int maxfd = 0;
local_timeout.tv_sec = reconnect_delay;
#ifdef HAVE_PSELECT
local_timeout.tv_nsec = 0;
#else
local_timeout.tv_usec = 0;
#endif
FD_ZERO(&readfds);
maxfd = 0;
if(mosq->sockpairR != INVALID_SOCKET){
/* sockpairR is used to break out of select() before the
* timeout, when mosquitto_loop_stop() is called */
FD_SET(mosq->sockpairR, &readfds);
maxfd = mosq->sockpairR;
}
#ifdef HAVE_PSELECT
fdcount = pselect(maxfd+1, &readfds, NULL, NULL, &local_timeout, NULL);
#else
fdcount = select(maxfd+1, &readfds, NULL, NULL, &local_timeout);
#endif
if(fdcount == -1){
#ifdef WIN32
errno = WSAGetLastError();
#endif
if(errno == EINTR){
return MOSQ_ERR_SUCCESS;
}else{
return MOSQ_ERR_ERRNO;
}
}else if(mosq->sockpairR != INVALID_SOCKET && FD_ISSET(mosq->sockpairR, &readfds)){
#ifndef WIN32
if(read(mosq->sockpairR, &pairbuf, 1) == 0){
}
#else
recv(mosq->sockpairR, &pairbuf, 1, 0);
#endif
}
return MOSQ_ERR_SUCCESS;
}
int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
{
int run = 1;
int rc;
unsigned long reconnect_delay;
#ifndef WIN32
struct timespec req, rem;
#endif
int state;
if(!mosq) return MOSQ_ERR_INVAL;
@@ -207,6 +256,9 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
while(run){
do{
#ifdef HAVE_PTHREAD_CANCEL
pthread_testcancel();
#endif
rc = mosquitto_loop(mosq, timeout, max_packets);
}while(run && rc == MOSQ_ERR_SUCCESS);
/* Quit after fatal errors. */
@@ -231,6 +283,9 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
return rc;
}
do{
#ifdef HAVE_PTHREAD_CANCEL
pthread_testcancel();
#endif
rc = MOSQ_ERR_SUCCESS;
state = mosquitto__get_state(mosq);
if(state == mosq_cs_disconnecting || state == mosq_cs_disconnected){
@@ -252,15 +307,8 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
mosq->reconnects++;
}
#ifdef WIN32
Sleep(reconnect_delay*1000);
#else
req.tv_sec = reconnect_delay;
req.tv_nsec = 0;
while(nanosleep(&req, &rem) == -1 && errno == EINTR){
req = rem;
}
#endif
rc = interruptible_sleep(mosq, reconnect_delay);
if(rc) return rc;
state = mosquitto__get_state(mosq);
if(state == mosq_cs_disconnecting || state == mosq_cs_disconnected){

Some files were not shown because too many files have changed in this diff Show More