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
79 enum mosquitto_msg_state
82 mosq_ms_publish_qos0 = 1,
83 mosq_ms_publish_qos1 = 2,
84 mosq_ms_wait_for_puback = 3,
85 mosq_ms_publish_qos2 = 4,
86 mosq_ms_wait_for_pubrec = 5,
87 mosq_ms_resend_pubrel = 6,
88 mosq_ms_wait_for_pubrel = 7,
89 mosq_ms_resend_pubcomp = 8,
90 mosq_ms_wait_for_pubcomp = 9,
91 mosq_ms_send_pubrec = 10,
95 enum mosquitto_client_state
98 mosq_cs_connected = 1,
99 mosq_cs_disconnecting = 2,
100 mosq_cs_connect_async = 3,
101 mosq_cs_connect_pending = 4,
102 mosq_cs_connect_srv = 5
105 enum _mosquitto_protocol
113 enum _mosquitto_transport
121 struct _mosquitto_packet
124 uint8_t have_remaining;
125 uint8_t remaining_count;
127 uint32_t remaining_mult;
128 uint32_t remaining_length;
129 uint32_t packet_length;
133 struct _mosquitto_packet *next;
136 struct mosquitto_message_all
138 struct mosquitto_message_all *next;
140 //enum mosquitto_msg_direction direction;
141 enum mosquitto_msg_state state;
143 struct mosquitto_message msg;
151 int sockpairR, sockpairW;
156 SOCKET sockpairR, sockpairW;
159 enum _mosquitto_protocol protocol;
166 enum mosquitto_client_state state;
171 struct _mosquitto_packet in_packet;
172 struct _mosquitto_packet *current_out_packet;
173 struct _mosquitto_packet *out_packet;
174 struct mosquitto_message *will;
182 int (*tls_pw_callback)(char *buf, int size, int rwflag, void *userdata);
187 char *tls_psk_identity;
191 #if defined(WITH_THREADING) && !defined(WITH_BROKER)
192 pthread_mutex_t callback_mutex;
193 pthread_mutex_t log_callback_mutex;
194 pthread_mutex_t msgtime_mutex;
195 pthread_mutex_t out_packet_mutex;
196 pthread_mutex_t current_out_packet_mutex;
197 pthread_mutex_t state_mutex;
198 pthread_mutex_t in_message_mutex;
199 pthread_mutex_t out_message_mutex;
204 struct _mqtt3_bridge *bridge;
205 struct mosquitto_client_msg *msgs;
206 struct mosquitto_client_msg *last_msg;
209 struct _mosquitto_acl_user *acl_list;
210 struct _mqtt3_listener *listener;
214 struct _mosquitto_packet *out_packet_last;
219 unsigned int message_retry;
220 time_t last_retry_check;
221 struct mosquitto_message_all *in_messages;
222 struct mosquitto_message_all *in_messages_last;
223 struct mosquitto_message_all *out_messages;
224 struct mosquitto_message_all *out_messages_last;
225 void (*on_connect)(struct mosquitto *, void *userdata, int rc);
226 void (*on_disconnect)(struct mosquitto *, void *userdata, int rc);
227 void (*on_publish)(struct mosquitto *, void *userdata, int mid);
228 void (*on_message)(struct mosquitto *, void *userdata, const struct mosquitto_message *message);
229 void (*on_subscribe)(struct mosquitto *, void *userdata, int mid, int qos_count,
230 const int *granted_qos);
231 void (*on_unsubscribe)(struct mosquitto *, void *userdata, int mid);
232 void (*on_log)(struct mosquitto *, void *userdata, int level, const char *str);
233 //void (*on_error)();
239 unsigned int reconnect_delay;
240 unsigned int reconnect_delay_max;
241 bool reconnect_exponential_backoff;
243 struct _mosquitto_packet *out_packet_last;
244 int inflight_messages;
245 int max_inflight_messages;