diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 202a7da1..65125308 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,6 +8,7 @@ set (MOSQ_SRCS conf.c conf_includedir.c context.c + control.c database.c handle_auth.c handle_connack.c diff --git a/src/Makefile b/src/Makefile index f5433ac7..393b1dc5 100644 --- a/src/Makefile +++ b/src/Makefile @@ -15,6 +15,7 @@ OBJS= mosquitto.o \ conf.o \ conf_includedir.o \ context.o \ + control.o \ database.o \ handle_auth.o \ handle_connack.o \ @@ -102,6 +103,9 @@ conf_includedir.o : conf_includedir.c mosquitto_broker_internal.h context.o : context.c mosquitto_broker_internal.h ${CROSS_COMPILE}${CC} $(BROKER_CPPFLAGS) $(BROKER_CFLAGS) -c $< -o $@ +control.o : control.c mosquitto_broker_internal.h + ${CROSS_COMPILE}${CC} $(BROKER_CPPFLAGS) $(BROKER_CFLAGS) -c $< -o $@ + database.o : database.c mosquitto_broker_internal.h ${CROSS_COMPILE}${CC} $(BROKER_CPPFLAGS) $(BROKER_CFLAGS) -c $< -o $@ diff --git a/src/control.c b/src/control.c new file mode 100644 index 00000000..069ad653 --- /dev/null +++ b/src/control.c @@ -0,0 +1,29 @@ +/* +Copyright (c) 2020 Roger Light + +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License v1.0 +and Eclipse Distribution License v1.0 which accompany this distribution. + +The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html +and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + +Contributors: + Roger Light - initial implementation and documentation. +*/ + +#include "config.h" + +#include + +#include "mqtt_protocol.h" +#include "mosquitto_broker_internal.h" + +/* Process messages coming in on $CONTROL/. These messages aren't + * passed on to other clients. */ +int control__process(struct mosquitto_db *db, struct mosquitto *context, struct mosquitto_msg_store *stored) +{ + return MOSQ_ERR_SUCCESS; +} diff --git a/src/handle_publish.c b/src/handle_publish.c index ec7b3ead..f5d98df3 100644 --- a/src/handle_publish.c +++ b/src/handle_publish.c @@ -248,6 +248,13 @@ int handle__publish(struct mosquitto_db *db, struct mosquitto *context) } log__printf(NULL, MOSQ_LOG_DEBUG, "Received PUBLISH from %s (d%d, q%d, r%d, m%d, '%s', ... (%ld bytes))", context->id, dup, msg->qos, msg->retain, msg->source_mid, msg->topic, (long)msg->payloadlen); + + if(!strncmp(msg->topic, "$CONTROL/", 9)){ + rc = control__process(db, context, msg); + db__msg_store_free(msg); + return rc; + } + if(msg->qos > 0){ db__message_store_find(context, msg->source_mid, &stored); } diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index d8950b29..a6344a51 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -697,6 +697,13 @@ void context__remove_from_by_id(struct mosquitto_db *db, struct mosquitto *conte int connect__on_authorised(struct mosquitto_db *db, struct mosquitto *context, void *auth_data_out, uint16_t auth_data_out_len); + +/* ============================================================ + * Control functions + * ============================================================ */ +int control__process(struct mosquitto_db *db, struct mosquitto *context, struct mosquitto_msg_store *stored); + + /* ============================================================ * Logging functions * ============================================================ */