1 #ifndef AWS_MQTT_MQTT_H
2 #define AWS_MQTT_MQTT_H
3 
4 /**
5  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6  * SPDX-License-Identifier: Apache-2.0.
7  */
8 
9 #include <aws/common/byte_buf.h>
10 #include <aws/common/logging.h>
11 
12 #include <aws/mqtt/exports.h>
13 
14 #define AWS_C_MQTT_PACKAGE_ID 5
15 
16 /* Quality of Service associated with a publish action or subscription [MQTT-4.3]. */
17 enum aws_mqtt_qos {
18     AWS_MQTT_QOS_AT_MOST_ONCE = 0x0,
19     AWS_MQTT_QOS_AT_LEAST_ONCE = 0x1,
20     AWS_MQTT_QOS_EXACTLY_ONCE = 0x2,
21     /* reserved = 3 */
22     AWS_MQTT_QOS_FAILURE = 0x80, /* Only used in SUBACK packets */
23 };
24 
25 /* Result of a connect request [MQTT-3.2.2.3]. */
26 enum aws_mqtt_connect_return_code {
27     AWS_MQTT_CONNECT_ACCEPTED,
28     AWS_MQTT_CONNECT_UNACCEPTABLE_PROTOCOL_VERSION,
29     AWS_MQTT_CONNECT_IDENTIFIER_REJECTED,
30     AWS_MQTT_CONNECT_SERVER_UNAVAILABLE,
31     AWS_MQTT_CONNECT_BAD_USERNAME_OR_PASSWORD,
32     AWS_MQTT_CONNECT_NOT_AUTHORIZED,
33     /* reserved = 6 - 255 */
34 };
35 
36 enum aws_mqtt_error {
37     AWS_ERROR_MQTT_INVALID_RESERVED_BITS = AWS_ERROR_ENUM_BEGIN_RANGE(AWS_C_MQTT_PACKAGE_ID),
38     AWS_ERROR_MQTT_BUFFER_TOO_BIG,
39     AWS_ERROR_MQTT_INVALID_REMAINING_LENGTH,
40     AWS_ERROR_MQTT_UNSUPPORTED_PROTOCOL_NAME,
41     AWS_ERROR_MQTT_UNSUPPORTED_PROTOCOL_LEVEL,
42     AWS_ERROR_MQTT_INVALID_CREDENTIALS,
43     AWS_ERROR_MQTT_INVALID_QOS,
44     AWS_ERROR_MQTT_INVALID_PACKET_TYPE,
45     AWS_ERROR_MQTT_INVALID_TOPIC,
46     AWS_ERROR_MQTT_TIMEOUT,
47     AWS_ERROR_MQTT_PROTOCOL_ERROR,
48     AWS_ERROR_MQTT_NOT_CONNECTED,
49     AWS_ERROR_MQTT_ALREADY_CONNECTED,
50     AWS_ERROR_MQTT_BUILT_WITHOUT_WEBSOCKETS,
51     AWS_ERROR_MQTT_UNEXPECTED_HANGUP,
52     AWS_ERROR_MQTT_CONNECTION_SHUTDOWN,
53     AWS_ERROR_MQTT_CONNECTION_DESTROYED,
54     AWS_ERROR_MQTT_CONNECTION_DISCONNECTING,
55     AWS_ERROR_MQTT_CANCELLED_FOR_CLEAN_SESSION,
56     AWS_ERROR_MQTT_QUEUE_FULL,
57 
58     AWS_ERROR_END_MQTT_RANGE = AWS_ERROR_ENUM_END_RANGE(AWS_C_MQTT_PACKAGE_ID),
59 };
60 
61 enum aws_mqtt_log_subject {
62     AWS_LS_MQTT_GENERAL = AWS_LOG_SUBJECT_BEGIN_RANGE(AWS_C_MQTT_PACKAGE_ID),
63     AWS_LS_MQTT_CLIENT,
64     AWS_LS_MQTT_TOPIC_TREE,
65 };
66 
67 /** Function called on cleanup of a userdata. */
68 typedef void(aws_mqtt_userdata_cleanup_fn)(void *userdata);
69 
70 AWS_EXTERN_C_BEGIN
71 
72 AWS_MQTT_API
73 bool aws_mqtt_is_valid_topic(const struct aws_byte_cursor *topic);
74 AWS_MQTT_API
75 bool aws_mqtt_is_valid_topic_filter(const struct aws_byte_cursor *topic_filter);
76 
77 /**
78  * Initializes internal datastructures used by aws-c-mqtt.
79  * Must be called before using any functionality in aws-c-mqtt.
80  */
81 AWS_MQTT_API
82 void aws_mqtt_library_init(struct aws_allocator *allocator);
83 
84 /**
85  * Shuts down the internal datastructures used by aws-c-mqtt.
86  */
87 AWS_MQTT_API
88 void aws_mqtt_library_clean_up(void);
89 
90 AWS_MQTT_API
91 void aws_mqtt_fatal_assert_library_initialized(void);
92 
93 AWS_EXTERN_C_END
94 
95 #endif /* AWS_MQTT_MQTT_H */
96