Skip to content

Commit

Permalink
Add read support for AUTH packets.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Oct 25, 2018
1 parent ca40255 commit 8077376
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 $@

Expand Down
49 changes: 49 additions & 0 deletions lib/handle_auth.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright (c) 2018 Roger Light <[email protected]>
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:https://www.eclipse.org/legal/epl-v10.html
and the Eclipse Distribution License is available at
http:https://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;
}
2 changes: 2 additions & 0 deletions lib/read_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lib/read_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 $@

Expand Down
48 changes: 48 additions & 0 deletions src/handle_auth.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright (c) 2018 Roger Light <[email protected]>
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:https://www.eclipse.org/legal/epl-v10.html
and the Eclipse Distribution License is available at
http:https://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;
}
1 change: 1 addition & 0 deletions src/mosquitto_broker_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/read_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8077376

Please sign in to comment.