diff --git a/lib/Makefile b/lib/Makefile index 9dc330c4..8e310e61 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -8,6 +8,7 @@ MOSQ_OBJS=mosquitto.o \ connect.o \ handle_auth.o \ handle_connack.o \ + handle_disconnect.o \ handle_ping.o \ handle_pubackcomp.o \ handle_publish.o \ @@ -101,6 +102,9 @@ handle_auth.o : handle_auth.c read_handle.h handle_connack.o : handle_connack.c read_handle.h ${CROSS_COMPILE}$(CC) $(LIB_CFLAGS) -c $< -o $@ +handle_disconnect.o : handle_disconnect.c read_handle.h + ${CROSS_COMPILE}$(CC) $(LIB_CFLAGS) -c $< -o $@ + handle_publish.o : handle_publish.c read_handle.h ${CROSS_COMPILE}$(CC) $(LIB_CFLAGS) -c $< -o $@ diff --git a/lib/handle_disconnect.c b/lib/handle_disconnect.c new file mode 100644 index 00000000..2f3bb58a --- /dev/null +++ b/lib/handle_disconnect.c @@ -0,0 +1,58 @@ +/* +Copyright (c) 2009-2018 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 + +#include "logging_mosq.h" +#include "mqtt_protocol.h" +#include "memory_mosq.h" +#include "net_mosq.h" +#include "packet_mosq.h" +#include "property_mosq.h" +#include "send_mosq.h" +#include "util_mosq.h" + +int handle__disconnect(struct mosquitto *mosq) +{ + int rc; + uint8_t reason_code; + mosquitto_property *properties = NULL; + + if(!mosq){ + return MOSQ_ERR_INVAL; + } + + rc = packet__read_byte(&mosq->in_packet, &reason_code); + if(rc) return rc; + + if(mosq->protocol == mosq_p_mqtt5){ + rc = property__read_all(CMD_DISCONNECT, &mosq->in_packet, &properties); + if(rc) return rc; + mosquitto_property_free_all(&properties); + } + + log__printf(mosq, MOSQ_LOG_DEBUG, "Received DISCONNECT (%d)", reason_code); + + do_client_disconnect(mosq, reason_code, properties); + + mosquitto_property_free_all(&properties); + + return MOSQ_ERR_SUCCESS; +} + diff --git a/lib/read_handle.c b/lib/read_handle.c index 1da41aa7..991a7dbc 100644 --- a/lib/read_handle.c +++ b/lib/read_handle.c @@ -57,6 +57,8 @@ int handle__packet(struct mosquitto *mosq) return handle__suback(mosq); case CMD_UNSUBACK: return handle__unsuback(mosq); + case CMD_DISCONNECT: + return handle__disconnect(mosq); case CMD_AUTH: return handle__auth(mosq); default: diff --git a/lib/read_handle.h b/lib/read_handle.h index 8bf20b5f..e0e17c94 100644 --- a/lib/read_handle.h +++ b/lib/read_handle.h @@ -26,6 +26,7 @@ int handle__pubackcomp(struct mosquitto_db *db, struct mosquitto *mosq, const ch #else int handle__packet(struct mosquitto *mosq); int handle__connack(struct mosquitto *mosq); +int handle__disconnect(struct mosquitto *mosq); int handle__pubackcomp(struct mosquitto *mosq, const char *type); int handle__publish(struct mosquitto *mosq); int handle__auth(struct mosquitto *mosq);