Move handle__disconnect() to its own file.

pull/1239/head
Roger A. Light 7 years ago
parent e5f58a8ff3
commit 73cd44ac7f

@ -11,6 +11,7 @@ set (MOSQ_SRCS
handle_auth.c
handle_connack.c
handle_connect.c
handle_disconnect.c
../lib/handle_ping.c
../lib/handle_pubackcomp.c
handle_publish.c

@ -18,6 +18,7 @@ OBJS= mosquitto.o \
handle_auth.o \
handle_connack.o \
handle_connect.o \
handle_disconnect.o \
handle_ping.o \
handle_pubackcomp.o \
handle_publish.o \
@ -102,6 +103,9 @@ handle_connack.o : handle_connack.c mosquitto_broker_internal.h
handle_connect.o : handle_connect.c mosquitto_broker_internal.h
${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@
handle_disconnect.o : handle_disconnect.c mosquitto_broker_internal.h
${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@
handle_ping.o : ../lib/handle_ping.c ../lib/read_handle.h
${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@

@ -767,53 +767,3 @@ handle_connect_error:
/* We return an error here which means the client is freed later on. */
return rc;
}
int handle__disconnect(struct mosquitto_db *db, struct mosquitto *context)
{
int rc;
uint8_t reason_code = 0;
mosquitto_property *properties = NULL;
if(!context){
return MOSQ_ERR_INVAL;
}
if(context->protocol == mosq_p_mqtt5 && context->in_packet.remaining_length > 1){
/* FIXME - must handle reason code */
rc = packet__read_byte(&context->in_packet, &reason_code);
if(rc) return rc;
if(context->in_packet.remaining_length > 2){
rc = property__read_all(CMD_DISCONNECT, &context->in_packet, &properties);
if(rc) return rc;
}
}
rc = property__process_disconnect(context, properties);
if(rc){
if(rc == MOSQ_ERR_PROTOCOL){
send__disconnect(context, MQTT_RC_PROTOCOL_ERROR, NULL);
}
mosquitto_property_free_all(&properties);
return rc;
}
mosquitto_property_free_all(&properties); /* FIXME - TEMPORARY UNTIL PROPERTIES PROCESSED */
if(context->in_packet.remaining_length != 0){
return MOSQ_ERR_PROTOCOL;
}
log__printf(NULL, MOSQ_LOG_DEBUG, "Received DISCONNECT from %s", context->id);
if(context->protocol == mosq_p_mqtt311 || context->protocol == mosq_p_mqtt5){
if((context->in_packet.command&0x0F) != 0x00){
do_disconnect(db, context);
return MOSQ_ERR_PROTOCOL;
}
}
if(reason_code == MQTT_RC_DISCONNECT_WITH_WILL_MSG){
context__set_state(context, mosq_cs_disconnect_with_will);
}else{
context__set_state(context, mosq_cs_disconnecting);
}
do_disconnect(db, context);
return MOSQ_ERR_SUCCESS;
}

@ -0,0 +1,73 @@
/*
Copyright (c) 2009-2019 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 "mosquitto_broker_internal.h"
#include "mqtt_protocol.h"
#include "packet_mosq.h"
#include "property_mosq.h"
#include "send_mosq.h"
int handle__disconnect(struct mosquitto_db *db, struct mosquitto *context)
{
int rc;
uint8_t reason_code = 0;
mosquitto_property *properties = NULL;
if(!context){
return MOSQ_ERR_INVAL;
}
if(context->protocol == mosq_p_mqtt5 && context->in_packet.remaining_length > 1){
/* FIXME - must handle reason code */
rc = packet__read_byte(&context->in_packet, &reason_code);
if(rc) return rc;
if(context->in_packet.remaining_length > 2){
rc = property__read_all(CMD_DISCONNECT, &context->in_packet, &properties);
if(rc) return rc;
}
}
rc = property__process_disconnect(context, properties);
if(rc){
if(rc == MOSQ_ERR_PROTOCOL){
send__disconnect(context, MQTT_RC_PROTOCOL_ERROR, NULL);
}
mosquitto_property_free_all(&properties);
return rc;
}
mosquitto_property_free_all(&properties); /* FIXME - TEMPORARY UNTIL PROPERTIES PROCESSED */
if(context->in_packet.remaining_length != 0){
return MOSQ_ERR_PROTOCOL;
}
log__printf(NULL, MOSQ_LOG_DEBUG, "Received DISCONNECT from %s", context->id);
if(context->protocol == mosq_p_mqtt311 || context->protocol == mosq_p_mqtt5){
if((context->in_packet.command&0x0F) != 0x00){
do_disconnect(db, context);
return MOSQ_ERR_PROTOCOL;
}
}
if(reason_code == MQTT_RC_DISCONNECT_WITH_WILL_MSG){
context__set_state(context, mosq_cs_disconnect_with_will);
}else{
context__set_state(context, mosq_cs_disconnecting);
}
do_disconnect(db, context);
return MOSQ_ERR_SUCCESS;
}
Loading…
Cancel
Save