2014-05-07 22:27:00 +00:00
|
|
|
/*
|
2020-02-27 23:26:58 +00:00
|
|
|
Copyright (c) 2009-2020 Roger Light <roger@atchoo.org>
|
2014-05-07 22:27:00 +00:00
|
|
|
|
|
|
|
All rights reserved. This program and the accompanying materials
|
2020-11-25 17:34:21 +00:00
|
|
|
are made available under the terms of the Eclipse Public License 2.0
|
2014-05-07 22:27:00 +00:00
|
|
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
2021-10-05 14:20:37 +00:00
|
|
|
|
2014-05-07 22:27:00 +00:00
|
|
|
The Eclipse Public License is available at
|
2020-11-25 17:34:21 +00:00
|
|
|
https://www.eclipse.org/legal/epl-2.0/
|
2014-05-07 22:27:00 +00:00
|
|
|
and the Eclipse Distribution License is available at
|
|
|
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
2021-10-05 14:20:37 +00:00
|
|
|
|
2021-01-20 11:46:18 +00:00
|
|
|
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
2020-12-01 18:21:59 +00:00
|
|
|
|
2014-05-07 22:27:00 +00:00
|
|
|
Contributors:
|
|
|
|
Roger Light - initial implementation and documentation.
|
|
|
|
*/
|
|
|
|
|
2018-08-16 10:14:51 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2014-05-07 22:27:00 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2015-04-29 20:37:47 +00:00
|
|
|
#include "mosquitto.h"
|
|
|
|
#include "logging_mosq.h"
|
|
|
|
#include "memory_mosq.h"
|
|
|
|
#include "messages_mosq.h"
|
2018-08-29 21:26:16 +00:00
|
|
|
#include "mqtt_protocol.h"
|
2015-04-29 20:37:47 +00:00
|
|
|
#include "net_mosq.h"
|
|
|
|
#include "packet_mosq.h"
|
|
|
|
#include "read_handle.h"
|
|
|
|
#include "send_mosq.h"
|
|
|
|
#include "time_mosq.h"
|
|
|
|
#include "util_mosq.h"
|
2014-05-07 22:27:00 +00:00
|
|
|
|
2015-05-18 08:29:22 +00:00
|
|
|
int handle__packet(struct mosquitto *mosq)
|
2014-05-07 22:27:00 +00:00
|
|
|
{
|
|
|
|
assert(mosq);
|
|
|
|
|
|
|
|
switch((mosq->in_packet.command)&0xF0){
|
2018-10-30 11:00:16 +00:00
|
|
|
case CMD_PINGREQ:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__pingreq(mosq);
|
2018-10-30 11:00:16 +00:00
|
|
|
case CMD_PINGRESP:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__pingresp(mosq);
|
2018-10-30 11:00:16 +00:00
|
|
|
case CMD_PUBACK:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__pubackcomp(mosq, "PUBACK");
|
2018-10-30 11:00:16 +00:00
|
|
|
case CMD_PUBCOMP:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__pubackcomp(mosq, "PUBCOMP");
|
2018-10-30 11:00:16 +00:00
|
|
|
case CMD_PUBLISH:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__publish(mosq);
|
2018-10-30 11:00:16 +00:00
|
|
|
case CMD_PUBREC:
|
2020-11-06 15:16:07 +00:00
|
|
|
return handle__pubrec(mosq);
|
2018-10-30 11:00:16 +00:00
|
|
|
case CMD_PUBREL:
|
2020-11-06 15:16:07 +00:00
|
|
|
return handle__pubrel(mosq);
|
2018-10-30 11:00:16 +00:00
|
|
|
case CMD_CONNACK:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__connack(mosq);
|
2018-10-30 11:00:16 +00:00
|
|
|
case CMD_SUBACK:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__suback(mosq);
|
2018-10-30 11:00:16 +00:00
|
|
|
case CMD_UNSUBACK:
|
2015-05-16 17:43:06 +00:00
|
|
|
return handle__unsuback(mosq);
|
2018-11-22 18:13:18 +00:00
|
|
|
case CMD_DISCONNECT:
|
|
|
|
return handle__disconnect(mosq);
|
2018-10-30 11:00:16 +00:00
|
|
|
case CMD_AUTH:
|
2018-10-25 11:44:41 +00:00
|
|
|
return handle__auth(mosq);
|
2014-05-07 22:27:00 +00:00
|
|
|
default:
|
|
|
|
/* If we don't recognise the command, return an error straight away. */
|
2015-05-18 07:53:21 +00:00
|
|
|
log__printf(mosq, MOSQ_LOG_ERR, "Error: Unrecognised command %d\n", (mosq->in_packet.command)&0xF0);
|
2014-05-07 22:27:00 +00:00
|
|
|
return MOSQ_ERR_PROTOCOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|