diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index cae15b03..dbbf2ca6 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -35,6 +35,7 @@ set(C_SRC actions.c callbacks.c connect.c + handle_auth.c handle_connack.c handle_ping.c handle_pubackcomp.c diff --git a/lib/Makefile b/lib/Makefile index 52d04714..9dc330c4 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -6,6 +6,7 @@ MOSQ_OBJS=mosquitto.o \ actions.o \ callbacks.o \ connect.o \ + handle_auth.o \ handle_connack.o \ handle_ping.o \ handle_pubackcomp.o \ @@ -94,6 +95,9 @@ callbacks.o : callbacks.c mosquitto.h mosquitto_internal.h connect.o : connect.c mosquitto.h mosquitto_internal.h ${CROSS_COMPILE}$(CC) $(LIB_CFLAGS) -c $< -o $@ +handle_auth.o : handle_auth.c read_handle.h + ${CROSS_COMPILE}$(CC) $(LIB_CFLAGS) -c $< -o $@ + handle_connack.o : handle_connack.c read_handle.h ${CROSS_COMPILE}$(CC) $(LIB_CFLAGS) -c $< -o $@ diff --git a/lib/handle_auth.c b/lib/handle_auth.c new file mode 100644 index 00000000..ef2b1f83 --- /dev/null +++ b/lib/handle_auth.c @@ -0,0 +1,49 @@ +/* +Copyright (c) 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 "mosquitto_internal.h" +#include "mqtt_protocol.h" +#include "packet_mosq.h" +#include "property_mosq.h" + + +int handle__auth(struct mosquitto *mosq) +{ + int rc = 0; + uint8_t reason_code; + struct mqtt5__property *properties = NULL; + + if(!mosq) return MOSQ_ERR_INVAL; + log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received AUTH", mosq->id); + + if(mosq->protocol != mosq_p_mqtt5){ + return MOSQ_ERR_PROTOCOL; + } + + if(packet__read_byte(&mosq->in_packet, &reason_code)) return 1; + + rc = property__read_all(AUTH, &mosq->in_packet, &properties); + if(rc) return rc; + property__free_all(&properties); /* FIXME - TEMPORARY UNTIL PROPERTIES PROCESSED */ + + return MOSQ_ERR_SUCCESS; +} diff --git a/lib/read_handle.c b/lib/read_handle.c index fab8b7dd..011c083c 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 UNSUBACK: return handle__unsuback(mosq); + case AUTH: + return handle__auth(mosq); default: /* If we don't recognise the command, return an error straight away. */ log__printf(mosq, MOSQ_LOG_ERR, "Error: Unrecognised command %d\n", (mosq->in_packet.command)&0xF0); diff --git a/lib/read_handle.h b/lib/read_handle.h index 887746de..8bf20b5f 100644 --- a/lib/read_handle.h +++ b/lib/read_handle.h @@ -28,6 +28,7 @@ int handle__packet(struct mosquitto *mosq); int handle__connack(struct mosquitto *mosq); int handle__pubackcomp(struct mosquitto *mosq, const char *type); int handle__publish(struct mosquitto *mosq); +int handle__auth(struct mosquitto *mosq); #endif int handle__pubrec(struct mosquitto *mosq); int handle__pubrel(struct mosquitto_db *db, struct mosquitto *mosq); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ba503f60..97f1d3b4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,7 @@ set (MOSQ_SRCS conf_includedir.c context.c database.c + handle_auth.c handle_connack.c handle_connect.c ../lib/handle_ping.c diff --git a/src/Makefile b/src/Makefile index 16191e20..93b2ea4a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -14,6 +14,7 @@ OBJS= mosquitto.o \ conf_includedir.o \ context.o \ database.o \ + handle_auth.o \ handle_connack.o \ handle_connect.o \ handle_ping.o \ @@ -79,6 +80,9 @@ context.o : context.c mosquitto_broker_internal.h database.o : database.c mosquitto_broker_internal.h ${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@ +handle_auth.o : handle_auth.c mosquitto_broker_internal.h + ${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@ + handle_connack.o : handle_connack.c mosquitto_broker_internal.h ${CROSS_COMPILE}${CC} $(BROKER_CFLAGS) -c $< -o $@ diff --git a/src/handle_auth.c b/src/handle_auth.c new file mode 100644 index 00000000..1941fb95 --- /dev/null +++ b/src/handle_auth.c @@ -0,0 +1,48 @@ +/* +Copyright (c) 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 "mosquitto_broker_internal.h" +#include "mqtt_protocol.h" +#include "packet_mosq.h" +#include "property_mosq.h" + + +int handle__auth(struct mosquitto_db *db, struct mosquitto *context) +{ + int rc = 0; + uint8_t reason_code; + struct mqtt5__property *properties = NULL; + + if(!context) return MOSQ_ERR_INVAL; + log__printf(NULL, MOSQ_LOG_DEBUG, "Received AUTH from %s", context->id); + + if(context->protocol != mosq_p_mqtt5){ + return MOSQ_ERR_PROTOCOL; + } + + if(packet__read_byte(&context->in_packet, &reason_code)) return 1; + + rc = property__read_all(AUTH, &context->in_packet, &properties); + if(rc) return rc; + property__free_all(&properties); /* FIXME - TEMPORARY UNTIL PROPERTIES PROCESSED */ + + return MOSQ_ERR_SUCCESS; +} diff --git a/src/mosquitto_broker_internal.h b/src/mosquitto_broker_internal.h index de4cb121..f9970a78 100644 --- a/src/mosquitto_broker_internal.h +++ b/src/mosquitto_broker_internal.h @@ -532,6 +532,7 @@ int handle__disconnect(struct mosquitto_db *db, struct mosquitto *context); int handle__publish(struct mosquitto_db *db, struct mosquitto *context); int handle__subscribe(struct mosquitto_db *db, struct mosquitto *context); int handle__unsubscribe(struct mosquitto_db *db, struct mosquitto *context); +int handle__auth(struct mosquitto_db *db, struct mosquitto *context); /* ============================================================ * Database handling diff --git a/src/read_handle.c b/src/read_handle.c index 9d032ed2..a283ca0e 100644 --- a/src/read_handle.c +++ b/src/read_handle.c @@ -65,6 +65,8 @@ int handle__packet(struct mosquitto_db *db, struct mosquitto *context) case UNSUBACK: return handle__unsuback(context); #endif + case AUTH: + return handle__auth(db, context); default: /* If we don't recognise the command, return an error straight away. */ return MOSQ_ERR_PROTOCOL;