Add read support for AUTH packets.

pull/1022/head
Roger A. Light 7 years ago
parent ca40255720
commit 8077376a79

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

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

@ -0,0 +1,49 @@
/*
Copyright (c) 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 "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;
}

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

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

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

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

@ -0,0 +1,48 @@
/*
Copyright (c) 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 "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;
}

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

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

Loading…
Cancel
Save