2014-05-07 22:27:00 +00:00
|
|
|
/*
|
2018-04-11 14:24:29 +00:00
|
|
|
Copyright (c) 2009-2018 Roger Light <roger@atchoo.org>
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2018-04-12 10:09:02 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2014-05-07 22:27:00 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-07-08 09:10:04 +00:00
|
|
|
#include "mosquitto_broker_internal.h"
|
2015-04-29 20:37:47 +00:00
|
|
|
#include "mqtt3_protocol.h"
|
|
|
|
#include "memory_mosq.h"
|
|
|
|
#include "packet_mosq.h"
|
|
|
|
#include "read_handle.h"
|
|
|
|
#include "send_mosq.h"
|
2015-05-16 11:25:35 +00:00
|
|
|
#include "sys_tree.h"
|
2015-04-29 20:37:47 +00:00
|
|
|
#include "util_mosq.h"
|
2014-05-07 22:27:00 +00:00
|
|
|
|
2016-03-06 22:30:17 +00:00
|
|
|
|
2015-05-18 08:29:22 +00:00
|
|
|
int handle__packet(struct mosquitto_db *db, struct mosquitto *context)
|
2014-05-07 22:27:00 +00:00
|
|
|
{
|
|
|
|
if(!context) return MOSQ_ERR_INVAL;
|
|
|
|
|
|
|
|
switch((context->in_packet.command)&0xF0){
|
|
|
|
case PINGREQ:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__pingreq(context);
|
2014-05-07 22:27:00 +00:00
|
|
|
case PINGRESP:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__pingresp(context);
|
2014-05-07 22:27:00 +00:00
|
|
|
case PUBACK:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__pubackcomp(db, context, "PUBACK");
|
2014-05-07 22:27:00 +00:00
|
|
|
case PUBCOMP:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__pubackcomp(db, context, "PUBCOMP");
|
2014-05-07 22:27:00 +00:00
|
|
|
case PUBLISH:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__publish(db, context);
|
2014-05-07 22:27:00 +00:00
|
|
|
case PUBREC:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__pubrec(context);
|
2014-05-07 22:27:00 +00:00
|
|
|
case PUBREL:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__pubrel(db, context);
|
2014-05-07 22:27:00 +00:00
|
|
|
case CONNECT:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__connect(db, context);
|
2014-05-07 22:27:00 +00:00
|
|
|
case DISCONNECT:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__disconnect(db, context);
|
2014-05-07 22:27:00 +00:00
|
|
|
case SUBSCRIBE:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__subscribe(db, context);
|
2014-05-07 22:27:00 +00:00
|
|
|
case UNSUBSCRIBE:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__unsubscribe(db, context);
|
2014-05-07 22:27:00 +00:00
|
|
|
#ifdef WITH_BRIDGE
|
|
|
|
case CONNACK:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__connack(db, context);
|
2014-05-07 22:27:00 +00:00
|
|
|
case SUBACK:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__suback(context);
|
2014-05-07 22:27:00 +00:00
|
|
|
case UNSUBACK:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__unsuback(context);
|
2014-05-07 22:27:00 +00:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
/* If we don't recognise the command, return an error straight away. */
|
|
|
|
return MOSQ_ERR_PROTOCOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|