-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
strings_mosq.c
235 lines (222 loc) · 6.94 KB
/
strings_mosq.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
Copyright (c) 2010-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
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 <errno.h>
#include <string.h>
#include "mosquitto.h"
#include "mqtt_protocol.h"
const char *mosquitto_strerror(int mosq_errno)
{
switch(mosq_errno){
case MOSQ_ERR_AUTH_CONTINUE:
return "Continue with authentication.";
case MOSQ_ERR_NO_SUBSCRIBERS:
return "No subscribers.";
case MOSQ_ERR_SUB_EXISTS:
return "Subscription already exists.";
case MOSQ_ERR_CONN_PENDING:
return "Connection pending.";
case MOSQ_ERR_SUCCESS:
return "No error.";
case MOSQ_ERR_NOMEM:
return "Out of memory.";
case MOSQ_ERR_PROTOCOL:
return "A network protocol error occurred when communicating with the broker.";
case MOSQ_ERR_INVAL:
return "Invalid arguments provided.";
case MOSQ_ERR_NO_CONN:
return "The client is not currently connected.";
case MOSQ_ERR_CONN_REFUSED:
return "The connection was refused.";
case MOSQ_ERR_NOT_FOUND:
return "Message not found (internal error).";
case MOSQ_ERR_CONN_LOST:
return "The connection was lost.";
case MOSQ_ERR_TLS:
return "A TLS error occurred.";
case MOSQ_ERR_PAYLOAD_SIZE:
return "Payload too large.";
case MOSQ_ERR_NOT_SUPPORTED:
return "This feature is not supported.";
case MOSQ_ERR_AUTH:
return "Authorisation failed.";
case MOSQ_ERR_ACL_DENIED:
return "Access denied by ACL.";
case MOSQ_ERR_UNKNOWN:
return "Unknown error.";
case MOSQ_ERR_ERRNO:
return strerror(errno);
case MOSQ_ERR_EAI:
return "Lookup error.";
case MOSQ_ERR_PROXY:
return "Proxy error.";
case MOSQ_ERR_MALFORMED_UTF8:
return "Malformed UTF-8";
case MOSQ_ERR_DUPLICATE_PROPERTY:
return "Duplicate property in property list";
case MOSQ_ERR_TLS_HANDSHAKE:
return "TLS handshake failed.";
case MOSQ_ERR_QOS_NOT_SUPPORTED:
return "Requested QoS not supported on server.";
case MOSQ_ERR_OVERSIZE_PACKET:
return "Packet larger than supported by the server.";
case MOSQ_ERR_OCSP:
return "OCSP error.";
default:
return "Unknown error.";
}
}
const char *mosquitto_connack_string(int connack_code)
{
switch(connack_code){
case 0:
return "Connection Accepted.";
case 1:
return "Connection Refused: unacceptable protocol version.";
case 2:
return "Connection Refused: identifier rejected.";
case 3:
return "Connection Refused: broker unavailable.";
case 4:
return "Connection Refused: bad user name or password.";
case 5:
return "Connection Refused: not authorised.";
default:
return "Connection Refused: unknown reason.";
}
}
const char *mosquitto_reason_string(int reason_code)
{
switch(reason_code){
case MQTT_RC_SUCCESS:
return "Success";
case MQTT_RC_GRANTED_QOS1:
return "Granted QoS 1";
case MQTT_RC_GRANTED_QOS2:
return "Granted QoS 2";
case MQTT_RC_DISCONNECT_WITH_WILL_MSG:
return "Disconnect with Will Message";
case MQTT_RC_NO_MATCHING_SUBSCRIBERS:
return "No matching subscribers";
case MQTT_RC_NO_SUBSCRIPTION_EXISTED:
return "No subscription existed";
case MQTT_RC_CONTINUE_AUTHENTICATION:
return "Continue authentication";
case MQTT_RC_REAUTHENTICATE:
return "Re-authenticate";
case MQTT_RC_UNSPECIFIED:
return "Unspecified error";
case MQTT_RC_MALFORMED_PACKET:
return "Malformed Packet";
case MQTT_RC_PROTOCOL_ERROR:
return "Protocol Error";
case MQTT_RC_IMPLEMENTATION_SPECIFIC:
return "Implementation specific error";
case MQTT_RC_UNSUPPORTED_PROTOCOL_VERSION:
return "Unsupported Protocol Version";
case MQTT_RC_CLIENTID_NOT_VALID:
return "Client Identifier not valid";
case MQTT_RC_BAD_USERNAME_OR_PASSWORD:
return "Bad User Name or Password";
case MQTT_RC_NOT_AUTHORIZED:
return "Not authorized";
case MQTT_RC_SERVER_UNAVAILABLE:
return "Server unavailable";
case MQTT_RC_SERVER_BUSY:
return "Server busy";
case MQTT_RC_BANNED:
return "Banned";
case MQTT_RC_SERVER_SHUTTING_DOWN:
return "Server shutting down";
case MQTT_RC_BAD_AUTHENTICATION_METHOD:
return "Bad authentication method";
case MQTT_RC_KEEP_ALIVE_TIMEOUT:
return "Keep Alive timeout";
case MQTT_RC_SESSION_TAKEN_OVER:
return "Session taken over";
case MQTT_RC_TOPIC_FILTER_INVALID:
return "Topic Filter invalid";
case MQTT_RC_TOPIC_NAME_INVALID:
return "Topic Name invalid";
case MQTT_RC_PACKET_ID_IN_USE:
return "Packet Identifier in use";
case MQTT_RC_PACKET_ID_NOT_FOUND:
return "Packet Identifier not found";
case MQTT_RC_RECEIVE_MAXIMUM_EXCEEDED:
return "Receive Maximum exceeded";
case MQTT_RC_TOPIC_ALIAS_INVALID:
return "Topic Alias invalid";
case MQTT_RC_PACKET_TOO_LARGE:
return "Packet too large";
case MQTT_RC_MESSAGE_RATE_TOO_HIGH:
return "Message rate too high";
case MQTT_RC_QUOTA_EXCEEDED:
return "Quota exceeded";
case MQTT_RC_ADMINISTRATIVE_ACTION:
return "Administrative action";
case MQTT_RC_PAYLOAD_FORMAT_INVALID:
return "Payload format invalid";
case MQTT_RC_RETAIN_NOT_SUPPORTED:
return "Retain not supported";
case MQTT_RC_QOS_NOT_SUPPORTED:
return "QoS not supported";
case MQTT_RC_USE_ANOTHER_SERVER:
return "Use another server";
case MQTT_RC_SERVER_MOVED:
return "Server moved";
case MQTT_RC_SHARED_SUBS_NOT_SUPPORTED:
return "Shared Subscriptions not supported";
case MQTT_RC_CONNECTION_RATE_EXCEEDED:
return "Connection rate exceeded";
case MQTT_RC_MAXIMUM_CONNECT_TIME:
return "Maximum connect time";
case MQTT_RC_SUBSCRIPTION_IDS_NOT_SUPPORTED:
return "Subscription identifiers not supported";
case MQTT_RC_WILDCARD_SUBS_NOT_SUPPORTED:
return "Wildcard Subscriptions not supported";
default:
return "Unknown reason";
}
}
int mosquitto_string_to_command(const char *str, int *cmd)
{
if(!strcasecmp(str, "connect")){
*cmd = CMD_CONNECT;
}else if(!strcasecmp(str, "connack")){
*cmd = CMD_CONNACK;
}else if(!strcasecmp(str, "publish")){
*cmd = CMD_PUBLISH;
}else if(!strcasecmp(str, "puback")){
*cmd = CMD_PUBACK;
}else if(!strcasecmp(str, "pubrec")){
*cmd = CMD_PUBREC;
}else if(!strcasecmp(str, "pubrel")){
*cmd = CMD_PUBREL;
}else if(!strcasecmp(str, "pubcomp")){
*cmd = CMD_PUBCOMP;
}else if(!strcasecmp(str, "subscribe")){
*cmd = CMD_SUBSCRIBE;
}else if(!strcasecmp(str, "unsubscribe")){
*cmd = CMD_UNSUBSCRIBE;
}else if(!strcasecmp(str, "disconnect")){
*cmd = CMD_DISCONNECT;
}else if(!strcasecmp(str, "auth")){
*cmd = CMD_AUTH;
}else if(!strcasecmp(str, "will")){
*cmd = CMD_WILL;
}else{
return MOSQ_ERR_INVAL;
}
return MOSQ_ERR_SUCCESS;
}