mosquitto/lib/read_handle.c

73 lines
1.9 KiB
C
Raw Normal View History

2014-05-07 22:27:00 +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.
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.
2020-12-01 18:21:59 +00:00
SPDX-License-Identifier: EPL-2.0 OR EDL-1.0
2014-05-07 22:27:00 +00:00
Contributors:
Roger Light - initial implementation and documentation.
*/
#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"
#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){
case CMD_PINGREQ:
2015-05-16 17:43:06 +00:00
return handle__pingreq(mosq);
case CMD_PINGRESP:
2015-05-16 17:43:06 +00:00
return handle__pingresp(mosq);
case CMD_PUBACK:
2015-05-16 17:43:06 +00:00
return handle__pubackcomp(mosq, "PUBACK");
case CMD_PUBCOMP:
2015-05-16 17:43:06 +00:00
return handle__pubackcomp(mosq, "PUBCOMP");
case CMD_PUBLISH:
2015-05-16 17:43:06 +00:00
return handle__publish(mosq);
case CMD_PUBREC:
return handle__pubrec(mosq);
case CMD_PUBREL:
return handle__pubrel(mosq);
case CMD_CONNACK:
2015-05-16 17:43:06 +00:00
return handle__connack(mosq);
case CMD_SUBACK:
2015-05-16 17:43:06 +00:00
return handle__suback(mosq);
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);
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;
}
}