Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Jun 21, 2016
2 parents 63e3926 + d813e11 commit 1c3988a
Show file tree
Hide file tree
Showing 155 changed files with 2,017 additions and 628 deletions.
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ if (WIN32)
else (WIN32)
set (BINDIR bin)
set (SBINDIR sbin)
if (${CMAKE_INSTALL_PREFIX} STREQUAL /usr)
if ("${CMAKE_INSTALL_PREFIX}" STREQUAL /usr)
set (SYSCONFDIR /etc/mosquitto)
else (${CMAKE_INSTALL_PREFIX} STREQUAL /usr)
else ("${CMAKE_INSTALL_PREFIX}" STREQUAL /usr)
set (SYSCONFDIR etc/mosquitto)
endif (${CMAKE_INSTALL_PREFIX} STREQUAL /usr)
endif ("${CMAKE_INSTALL_PREFIX}" STREQUAL /usr)

set (LIBDIR lib${LIB_SUFFIX})
set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBDIR}")
set (INCLUDEDIR include)
set (DATAROOTDIR share)
set (MANDIR ${DATAROOTDIR}/man)
set (SHAREDIR ${DATAROOTDIR}/mosquitto)
set (MANDIR "${DATAROOTDIR}/man")
set (SHAREDIR "${DATAROOTDIR}/mosquitto")
endif (WIN32)

option(WITH_TLS
Expand Down Expand Up @@ -96,7 +96,7 @@ endif (${DOCUMENTATION} STREQUAL ON)
# Install config file
# ========================================

install(FILES mosquitto.conf aclfile.example pskfile.example pwfile.example DESTINATION ${SYSCONFDIR})
install(FILES mosquitto.conf aclfile.example pskfile.example pwfile.example DESTINATION "${SYSCONFDIR}")

# ========================================
# Testing
Expand Down
68 changes: 67 additions & 1 deletion ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,73 @@ Build:
- Add WITH_STRIP option (defaulting to "no") that when set to "yes" will strip
executables and shared libraries when installing.
- Add WITH_STATIC_LIBRARIES (defaulting to "no") that when set to "yes" will
buld and install static versions of the client libraries.
build and install static versions of the client libraries.


1.4.9 - 20160603
================

Broker:
- Ensure websockets clients that previously connected with clean session set
to false have their queued messages delivered immediately on reconnecting.
Closes #476314.
- Reconnecting client with clean session set to false doesn't start with mid=1
again.
- Will topic isn't truncated by one byte when using a mount_point any more.
- Network errors are printed correctly on Windows.
- Fix incorrect $SYS heap memory reporting when using ACLs.
- Bridge config parameters couldn't contain a space, this has been fixed.
Closes #150.
- Fix saving of persistence messages that start with a '/'. Closes #151.
- Fix reconnecting for bridges that use TLS on Windows. Closes #154.
- Broker and bridges can now cope with unknown incoming PUBACK, PUBREC,
PUBREL, PUBCOMP without disconnecting. Closes #57.
- Fix websockets listeners not being able to bind to an IP address. Closes
#170.
- mosquitto_passwd utility now correctly deals with unknown command line
arguments in all cases. Closes #169.
- Fix publishing of $SYS/broker/clients/maximum
- Fix order of #includes in lib/send_mosq.c to ensure struct mosquitto doesn't
differ between source files when websockets is being used. Closes #180.
- Fix possible rare crash when writing out persistence file and a client has
incomplete messages inflight that it has been denied the right to publish.

Client library:
- Fix the case where a message received just before the keepalive timer
expired would cause the client to miss the keepalive timer.
- Return value of pthread_create is now checked.
- _mosquitto_destroy should not cancel threads that weren't created by
libmosquitto. Closes #166.
- Clients can now cope with unknown incoming PUBACK, PUBREC, PUBREL, PUBCOMP
without disconnecting. Closes #57.
- Fix mosquitto_topic_matches_sub() reporting matches on some invalid
subscriptions.

Clients:
- Handle some unchecked malloc() calls. Closes #1.

Build:
- Fix string quoting in CMakeLists.txt. Closes #4.
- Fix building on Visual Studio 2015. Closes #136.


1.4.8 - 20160214
================

Broker:
- Wills published by clients connected to a listener with mount_point defined
now correctly obey the mount point. This was a potential security risk
because it allowed clients to publish messages outside of their restricted
mount point. This is only affects brokers where the mount_point option is in
use. Closes #487178.
- Fix detection of broken connections on Windows. Closes #485143.
- Close stdin etc. when daemonised. Closes #485589.
- Fix incorrect detection of FreeBSD and OpenBSD. Closes #485131.

Client library:
- mosq->want_write should be cleared immediately before a call to SSL_write,
to allow clients using mosquitto_want_write() to get accurate results.


1.4.7 - 20151221
================
Expand Down
28 changes: 28 additions & 0 deletions Mosquitto.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Pod::Spec.new do |s|
s.name = "Mosquitto"
s.version = "1.4.8"
s.summary = "Eclipse Mosquitto is an open source implementation of a server for version 3.1 and 3.1.1 of the MQTT protocol."
s.description = "Eclipse Mosquitto is an open source implementation of a server for version 3.1 and 3.1.1 of the MQTT protocol."
s.homepage = "https://github.com/eclipse/mosquitto"
s.license = 'This project is dual licensed under the Eclipse Public License 1.0 and the Eclipse Distribution License 1.0 as described in the epl-v10 and edl-v10 files.'
s.author = { "Eclipse Foundation" => "[email protected]" }
s.source = { :git => "https://github.com/eclipse/mosquitto.git", :tag => "v1.4.8" }

s.ios.deployment_target = '6.0'
s.xcconfig = { 'HEADER_SEARCH_PATHS' => '${PODS_ROOT}/**',
'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES',
'GCC_PREPROCESSOR_DEFINITIONS' => 'WITH_THREADING=1'
}
s.source_files = ['lib/*.{c,h}', '*.h']

s.subspec 'WithoutTLS' do |sp|
sp.source_files = ['lib/*.{c,h}', '*.h']
end

s.subspec 'TLS' do |sp|
sp.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => 'WITH_TLS=1' }
sp.source_files = ['lib/*.{c,h}', '*.h']
sp.dependency 'OpenSSL-Universal', '~> 1.0.1.19'
end

end
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
os: Visual Studio 2013

environment:
CMAKE_ARGS: -DCMAKE_BUILD_TYPE=Release
NSIS_ROOT: C:\nsis
Expand Down
4 changes: 2 additions & 2 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ add_executable(mosquitto_sub sub_client.c ${shared_src})
target_link_libraries(mosquitto_pub libmosquitto)
target_link_libraries(mosquitto_sub libmosquitto)

install(TARGETS mosquitto_pub RUNTIME DESTINATION ${BINDIR} LIBRARY DESTINATION ${LIBDIR})
install(TARGETS mosquitto_sub RUNTIME DESTINATION ${BINDIR} LIBRARY DESTINATION ${LIBDIR})
install(TARGETS mosquitto_pub RUNTIME DESTINATION "${BINDIR}" LIBRARY DESTINATION "${LIBDIR}")
install(TARGETS mosquitto_sub RUNTIME DESTINATION "${BINDIR}" LIBRARY DESTINATION "${LIBDIR}")
12 changes: 12 additions & 0 deletions client/client_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
if(env){
len = strlen(env) + strlen("/mosquitto_pub") + 1;
loc = malloc(len);
if(!loc){
fprintf(stderr, "Error: Out of memory.\n");
return 1;
}
if(pub_or_sub == CLIENT_PUB){
snprintf(loc, len, "%s/mosquitto_pub", env);
}else{
Expand All @@ -132,6 +136,10 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
if(env){
len = strlen(env) + strlen("/.config/mosquitto_pub") + 1;
loc = malloc(len);
if(!loc){
fprintf(stderr, "Error: Out of memory.\n");
return 1;
}
if(pub_or_sub == CLIENT_PUB){
snprintf(loc, len, "%s/.config/mosquitto_pub", env);
}else{
Expand All @@ -148,6 +156,10 @@ int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *
if(rc > 0 && rc < 1024){
len = strlen(env) + strlen("\\mosquitto_pub.conf") + 1;
loc = malloc(len);
if(!loc){
fprintf(stderr, "Error: Out of memory.\n");
return 1;
}
if(pub_or_sub == CLIENT_PUB){
snprintf(loc, len, "%s\\mosquitto_pub.conf", env);
}else{
Expand Down
5 changes: 4 additions & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
*
* Generally for Windows native support.
* ============================================================ */
#if defined(_MSC_VER) && _MSC_VER < 1900
# define snprintf sprintf_s
#endif

#ifdef WIN32
#define snprintf sprintf_s
# ifndef strcasecmp
# define strcasecmp strcmpi
# endif
Expand Down
2 changes: 1 addition & 1 deletion config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ LIB_LDFLAGS:=${LDFLAGS}
BROKER_CFLAGS:=${LIB_CFLAGS} ${CPPFLAGS} -DVERSION="\"${VERSION}\"" -DTIMESTAMP="\"${TIMESTAMP}\"" -DWITH_BROKER
CLIENT_CFLAGS:=${CFLAGS} ${CPPFLAGS} -I../lib -DVERSION="\"${VERSION}\""

ifneq ($(or $(find $(UNAME),FreeBSD), $(find $(UNAME),OpenBSD)),)
ifneq ($(or $(findstring $(UNAME),FreeBSD), $(findstring $(UNAME),OpenBSD)),)
BROKER_LIBS:=-lm
else
BROKER_LIBS:=-ldl -lm
Expand Down
6 changes: 3 additions & 3 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ set_target_properties(libmosquitto PROPERTIES
SOVERSION 1
)

install(TARGETS libmosquitto RUNTIME DESTINATION ${BINDIR} LIBRARY DESTINATION ${LIBDIR})
install(TARGETS libmosquitto RUNTIME DESTINATION "${BINDIR}" LIBRARY DESTINATION "${LIBDIR}")

if (${WITH_STATIC_LIBRARIES} STREQUAL ON)
if (${WITH_PIC} STREQUAL OFF)
Expand All @@ -114,10 +114,10 @@ if (${WITH_STATIC_LIBRARIES} STREQUAL ON)
)

target_compile_definitions(libmosquitto_static PUBLIC "LIBMOSQUITTO_STATIC")
install(TARGETS libmosquitto_static RUNTIME DESTINATION ${BINDIR} ARCHIVE DESTINATION ${LIBDIR})
install(TARGETS libmosquitto_static RUNTIME DESTINATION "${BINDIR}" ARCHIVE DESTINATION "${LIBDIR}")
endif (${WITH_STATIC_LIBRARIES} STREQUAL ON)

install(FILES mosquitto.h DESTINATION ${INCLUDEDIR})
install(FILES mosquitto.h DESTINATION "${INCLUDEDIR}")

if (UNIX AND NOT APPLE)
install(CODE "EXEC_PROGRAM(/sbin/ldconfig)")
Expand Down
6 changes: 3 additions & 3 deletions lib/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set_target_properties(mosquittopp PROPERTIES
VERSION ${VERSION}
SOVERSION 1
)
install(TARGETS mosquittopp RUNTIME DESTINATION ${BINDIR} LIBRARY DESTINATION ${LIBDIR})
install(TARGETS mosquittopp RUNTIME DESTINATION "${BINDIR}" LIBRARY DESTINATION "${LIBDIR}")

if (${WITH_STATIC_LIBRARIES} STREQUAL ON)
if (${WITH_PIC} STREQUAL OFF)
Expand All @@ -39,10 +39,10 @@ if (${WITH_STATIC_LIBRARIES} STREQUAL ON)
)

target_compile_definitions(mosquittopp_static PUBLIC "LIBMOSQUITTO_STATIC")
install(TARGETS mosquittopp_static RUNTIME DESTINATION ${BINDIR} ARCHIVE DESTINATION ${LIBDIR})
install(TARGETS mosquittopp_static RUNTIME DESTINATION "${BINDIR}" ARCHIVE DESTINATION "${LIBDIR}")
endif (${WITH_STATIC_LIBRARIES} STREQUAL ON)

install(FILES mosquittopp.h DESTINATION ${INCLUDEDIR})
install(FILES mosquittopp.h DESTINATION "${INCLUDEDIR}")

if (UNIX AND NOT APPLE)
install(CODE "EXEC_PROGRAM(/sbin/ldconfig)")
Expand Down
7 changes: 6 additions & 1 deletion lib/handle_pubackcomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ int handle__pubackcomp(struct mosquitto *mosq, const char *type)

if(mid){
rc = db__message_delete(db, mosq, mid, mosq_md_out);
if(rc) return rc;
if(rc == MOSQ_ERR_NOT_FOUND){
log__printf(mosq, MOSQ_LOG_WARNING, "Warning: Received %s from %s for an unknown packet identifier %d.", type, mosq->id, mid);
return MOSQ_ERR_SUCCESS;
}else{
return rc;
}
}
#else
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received %s (Mid: %d)", mosq->id, type, mid);
Expand Down
6 changes: 5 additions & 1 deletion lib/handle_pubrec.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ int handle__pubrec(struct mosquitto *mosq)

rc = message__out_update(mosq, mid, mosq_ms_wait_for_pubcomp);
#endif
if(rc) return rc;
if(rc == MOSQ_ERR_NOT_FOUND){
log__printf(mosq, MOSQ_LOG_WARNING, "Warning: Received PUBREC from %s for an unknown packet identifier %d.", mosq->id, mid);
}else if(rc != MOSQ_ERR_SUCCESS){
return rc;
}
rc = send__pubrel(mosq, mid);
if(rc) return rc;

Expand Down
1 change: 1 addition & 0 deletions lib/handle_pubrel.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ int handle__pubrel(struct mosquitto_db *db, struct mosquitto *mosq)
if(db__message_release(db, mosq, mid, mosq_md_in)){
/* Message not found. Still send a PUBCOMP anyway because this could be
* due to a repeated PUBREL after a client has reconnected. */
log__printf(mosq, MOSQ_LOG_WARNING, "Warning: Received PUBREL from %s for an unknown packet identifier %d.", mosq->id, mid);
}
#else
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received PUBREL (Mid: %d)", mosq->id, mid);
Expand Down
38 changes: 19 additions & 19 deletions lib/mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_se
mosq->out_packet = NULL;
mosq->current_out_packet = NULL;
mosq->last_msg_in = mosquitto_time();
mosq->last_msg_out = mosquitto_time();
mosq->next_msg_out = mosquitto_time() + mosq->keepalive;
mosq->ping_t = 0;
mosq->last_mid = 0;
mosq->state = mosq_cs_new;
Expand All @@ -194,7 +194,7 @@ int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_se
mosq->reconnect_delay = 1;
mosq->reconnect_delay_max = 1;
mosq->reconnect_exponential_backoff = false;
mosq->threaded = false;
mosq->threaded = mosq_ts_none;
#ifdef WITH_TLS
mosq->ssl = NULL;
mosq->tls_cert_reqs = SSL_VERIFY_PEER;
Expand Down Expand Up @@ -272,10 +272,10 @@ void mosquitto__destroy(struct mosquitto *mosq)
if(!mosq) return;

#ifdef WITH_THREADING
if(mosq->threaded && !pthread_equal(mosq->thread_id, pthread_self())){
if(mosq->threaded == mosq_ts_self && !pthread_equal(mosq->thread_id, pthread_self())){
pthread_cancel(mosq->thread_id);
pthread_join(mosq->thread_id, NULL);
mosq->threaded = false;
mosq->threaded = mosq_ts_none;
}

if(mosq->id){
Expand Down Expand Up @@ -476,7 +476,7 @@ static int mosquitto__reconnect(struct mosquitto *mosq, bool blocking)

pthread_mutex_lock(&mosq->msgtime_mutex);
mosq->last_msg_in = mosquitto_time();
mosq->last_msg_out = mosquitto_time();
mosq->next_msg_out = mosq->last_msg_in + mosq->keepalive;
pthread_mutex_unlock(&mosq->msgtime_mutex);

mosq->ping_t = 0;
Expand Down Expand Up @@ -549,7 +549,7 @@ int mosquitto_publish(struct mosquitto *mosq, int *mid, const char *topic, int p

if(!mosq || !topic || qos<0 || qos>2) return MOSQ_ERR_INVAL;
if(STREMPTY(topic)) return MOSQ_ERR_INVAL;
if(!mosquitto_validate_utf8(topic, strlen(topic))) return MOSQ_ERR_MALFORMED_UTF8;
if(mosquitto_validate_utf8(topic, strlen(topic))) return MOSQ_ERR_MALFORMED_UTF8;
if(payloadlen < 0 || payloadlen > MQTT_MAX_PAYLOAD) return MOSQ_ERR_PAYLOAD_SIZE;

if(mosquitto_pub_topic_check(topic) != MOSQ_ERR_SUCCESS){
Expand Down Expand Up @@ -820,6 +820,7 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets)
int rc;
char pairbuf;
int maxfd = 0;
time_t now;

if(!mosq || max_packets < 1) return MOSQ_ERR_INVAL;
#ifndef WIN32
Expand All @@ -842,7 +843,6 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets)
if(mosq->ssl){
if(mosq->want_write){
FD_SET(mosq->sock, &writefds);
mosq->want_write = false;
}else if(mosq->want_connect){
/* Remove possible FD_SET from above, we don't want to check
* for writing if we are still connecting, unless want_write is
Expand Down Expand Up @@ -882,21 +882,21 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets)
}
}

if(timeout >= 0){
local_timeout.tv_sec = timeout/1000;
#ifdef HAVE_PSELECT
local_timeout.tv_nsec = (timeout-local_timeout.tv_sec*1000)*1e6;
#else
local_timeout.tv_usec = (timeout-local_timeout.tv_sec*1000)*1000;
#endif
}else{
local_timeout.tv_sec = 1;
if(timeout < 0){
timeout = 1000;
}

now = mosquitto_time();
if(mosq->next_msg_out && now + timeout/1000 > mosq->next_msg_out){
timeout = (mosq->next_msg_out - now)*1000;
}

local_timeout.tv_sec = timeout/1000;
#ifdef HAVE_PSELECT
local_timeout.tv_nsec = 0;
local_timeout.tv_nsec = (timeout-local_timeout.tv_sec*1000)*1e6;
#else
local_timeout.tv_usec = 0;
local_timeout.tv_usec = (timeout-local_timeout.tv_sec*1000)*1000;
#endif
}

#ifdef HAVE_PSELECT
fdcount = pselect(maxfd+1, &readfds, &writefds, NULL, &local_timeout, NULL);
Expand Down
Loading

0 comments on commit 1c3988a

Please sign in to comment.