2 Copyright (c) 2010,2011,2013 Roger Light <roger@atchoo.org>
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. Neither the name of mosquitto nor the names of its
14 contributors may be used to endorse or promote products derived from
15 this software without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE.
30 #ifndef _MOSQUITTO_INTERNAL_H_
31 #define _MOSQUITTO_INTERNAL_H_
36 # include <winsock2.h>
40 #include <openssl/ssl.h>
44 #if defined(WITH_THREADING) && !defined(WITH_BROKER)
47 # include <dummypthread.h>
56 typedef unsigned char uint8_t;
57 typedef unsigned short uint16_t;
58 typedef unsigned int uint32_t;
59 typedef unsigned long long uint64_t;
67 #include "mosquitto.h"
68 #include "time_mosq.h"
70 struct mosquitto_client_msg;
73 enum mosquitto_msg_direction {
78 enum mosquitto_msg_state {
80 mosq_ms_publish_qos0 = 1,
81 mosq_ms_publish_qos1 = 2,
82 mosq_ms_wait_for_puback = 3,
83 mosq_ms_publish_qos2 = 4,
84 mosq_ms_wait_for_pubrec = 5,
85 mosq_ms_resend_pubrel = 6,
86 mosq_ms_wait_for_pubrel = 7,
87 mosq_ms_resend_pubcomp = 8,
88 mosq_ms_wait_for_pubcomp = 9,
89 mosq_ms_send_pubrec = 10,
93 enum mosquitto_client_state {
95 mosq_cs_connected = 1,
96 mosq_cs_disconnecting = 2,
97 mosq_cs_connect_async = 3,
98 mosq_cs_connect_pending = 4,
99 mosq_cs_connect_srv = 5
102 enum _mosquitto_protocol {
109 enum _mosquitto_transport {
116 struct _mosquitto_packet{
118 uint8_t have_remaining;
119 uint8_t remaining_count;
121 uint32_t remaining_mult;
122 uint32_t remaining_length;
123 uint32_t packet_length;
127 struct _mosquitto_packet *next;
130 struct mosquitto_message_all{
131 struct mosquitto_message_all *next;
133 //enum mosquitto_msg_direction direction;
134 enum mosquitto_msg_state state;
136 struct mosquitto_message msg;
143 int sockpairR, sockpairW;
148 SOCKET sockpairR, sockpairW;
151 enum _mosquitto_protocol protocol;
158 enum mosquitto_client_state state;
163 struct _mosquitto_packet in_packet;
164 struct _mosquitto_packet *current_out_packet;
165 struct _mosquitto_packet *out_packet;
166 struct mosquitto_message *will;
174 int (*tls_pw_callback)(char *buf, int size, int rwflag, void *userdata);
179 char *tls_psk_identity;
183 #if defined(WITH_THREADING) && !defined(WITH_BROKER)
184 pthread_mutex_t callback_mutex;
185 pthread_mutex_t log_callback_mutex;
186 pthread_mutex_t msgtime_mutex;
187 pthread_mutex_t out_packet_mutex;
188 pthread_mutex_t current_out_packet_mutex;
189 pthread_mutex_t state_mutex;
190 pthread_mutex_t in_message_mutex;
191 pthread_mutex_t out_message_mutex;
196 struct _mqtt3_bridge *bridge;
197 struct mosquitto_client_msg *msgs;
198 struct mosquitto_client_msg *last_msg;
201 struct _mosquitto_acl_user *acl_list;
202 struct _mqtt3_listener *listener;
206 struct _mosquitto_packet *out_packet_last;
211 unsigned int message_retry;
212 time_t last_retry_check;
213 struct mosquitto_message_all *in_messages;
214 struct mosquitto_message_all *in_messages_last;
215 struct mosquitto_message_all *out_messages;
216 struct mosquitto_message_all *out_messages_last;
217 void (*on_connect)(struct mosquitto *, void *userdata, int rc);
218 void (*on_disconnect)(struct mosquitto *, void *userdata, int rc);
219 void (*on_publish)(struct mosquitto *, void *userdata, int mid);
220 void (*on_message)(struct mosquitto *, void *userdata, const struct mosquitto_message *message);
221 void (*on_subscribe)(struct mosquitto *, void *userdata, int mid, int qos_count, const int *granted_qos);
222 void (*on_unsubscribe)(struct mosquitto *, void *userdata, int mid);
223 void (*on_log)(struct mosquitto *, void *userdata, int level, const char *str);
224 //void (*on_error)();
230 unsigned int reconnect_delay;
231 unsigned int reconnect_delay_max;
232 bool reconnect_exponential_backoff;
234 struct _mosquitto_packet *out_packet_last;
235 int inflight_messages;
236 int max_inflight_messages;