Add DISCONNECT handling to library.

This commit is contained in:
Roger Light 2018-11-22 18:13:18 +00:00
parent 236e967161
commit f809ecbcbe
4 changed files with 65 additions and 0 deletions

View File

@ -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 $@

58
lib/handle_disconnect.c Normal file
View File

@ -0,0 +1,58 @@
/*
Copyright (c) 2009-2018 Roger Light <roger@atchoo.org>
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 <stdio.h>
#include <string.h>
#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;
}

View File

@ -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:

View File

@ -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);