-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
read_handle.c
108 lines (96 loc) · 2.77 KB
/
read_handle.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
Copyright (c) 2009-2020 Roger Light <[email protected]>
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
and Eclipse Distribution License v1.0 which accompany this distribution.
The Eclipse Public License is available at
https://www.eclipse.org/legal/epl-2.0/
and the Eclipse Distribution License is available at
http:https://www.eclipse.org/org/documents/edl-v10.php.
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
Contributors:
Roger Light - initial implementation and documentation.
*/
#include "config.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "mosquitto_broker_internal.h"
#include "mqtt_protocol.h"
#include "memory_mosq.h"
#include "packet_mosq.h"
#include "read_handle.h"
#include "send_mosq.h"
#include "sys_tree.h"
#include "util_mosq.h"
int handle__packet(struct mosquitto *context)
{
int rc = MOSQ_ERR_INVAL;
if(!context) return MOSQ_ERR_INVAL;
switch((context->in_packet.command)&0xF0){
case CMD_PINGREQ:
rc = handle__pingreq(context);
break;
case CMD_PINGRESP:
rc = handle__pingresp(context);
break;
case CMD_PUBACK:
rc = handle__pubackcomp(context, "PUBACK");
break;
case CMD_PUBCOMP:
rc = handle__pubackcomp(context, "PUBCOMP");
break;
case CMD_PUBLISH:
rc = handle__publish(context);
break;
case CMD_PUBREC:
rc = handle__pubrec(context);
break;
case CMD_PUBREL:
rc = handle__pubrel(context);
break;
case CMD_CONNECT:
return handle__connect(context);
case CMD_DISCONNECT:
rc = handle__disconnect(context);
break;
case CMD_SUBSCRIBE:
rc = handle__subscribe(context);
break;
case CMD_UNSUBSCRIBE:
rc = handle__unsubscribe(context);
break;
#ifdef WITH_BRIDGE
case CMD_CONNACK:
rc = handle__connack(context);
break;
case CMD_SUBACK:
rc = handle__suback(context);
break;
case CMD_UNSUBACK:
rc = handle__unsuback(context);
break;
#endif
case CMD_AUTH:
rc = handle__auth(context);
break;
default:
rc = MOSQ_ERR_PROTOCOL;
}
if(context->protocol == mosq_p_mqtt5){
if(rc == MOSQ_ERR_PROTOCOL || rc == MOSQ_ERR_DUPLICATE_PROPERTY){
send__disconnect(context, MQTT_RC_PROTOCOL_ERROR, NULL);
}else if(rc == MOSQ_ERR_MALFORMED_PACKET){
send__disconnect(context, MQTT_RC_MALFORMED_PACKET, NULL);
}else if(rc == MOSQ_ERR_QOS_NOT_SUPPORTED){
send__disconnect(context, MQTT_RC_QOS_NOT_SUPPORTED, NULL);
}else if(rc == MOSQ_ERR_RETAIN_NOT_SUPPORTED){
send__disconnect(context, MQTT_RC_RETAIN_NOT_SUPPORTED, NULL);
}else if(rc == MOSQ_ERR_TOPIC_ALIAS_INVALID){
send__disconnect(context, MQTT_RC_TOPIC_ALIAS_INVALID, NULL);
}else if(rc == MOSQ_ERR_UNKNOWN || rc == MOSQ_ERR_NOMEM){
send__disconnect(context, MQTT_RC_UNSPECIFIED, NULL);
}
}
return rc;
}