2 Copyright (c) 2010-2014 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 This product includes software developed by the OpenSSL Project for use in the
31 OpenSSL Toolkit. (http://www.openssl.org/)
32 This product includes cryptographic software written by Eric Young
34 This product includes software written by Tim Hudson (tjh@cryptsoft.com)
44 #if defined(WIN32) && !defined(WITH_BROKER)
45 # ifdef libmosquitto_EXPORTS
46 # define libmosq_EXPORT __declspec(dllexport)
48 # define libmosq_EXPORT __declspec(dllimport)
51 # define libmosq_EXPORT
66 #define LIBMOSQUITTO_MAJOR 1
67 #define LIBMOSQUITTO_MINOR 3
68 #define LIBMOSQUITTO_REVISION 1
69 /* LIBMOSQUITTO_VERSION_NUMBER looks like 1002001 for e.g. version 1.2.1. */
70 #define LIBMOSQUITTO_VERSION_NUMBER (LIBMOSQUITTO_MAJOR*1000000+LIBMOSQUITTO_MINOR*1000+LIBMOSQUITTO_REVISION)
73 #define MOSQ_LOG_NONE 0x00
74 #define MOSQ_LOG_INFO 0x01
75 #define MOSQ_LOG_NOTICE 0x02
76 #define MOSQ_LOG_WARNING 0x04
77 #define MOSQ_LOG_ERR 0x08
78 #define MOSQ_LOG_DEBUG 0x10
79 #define MOSQ_LOG_SUBSCRIBE 0x20
80 #define MOSQ_LOG_UNSUBSCRIBE 0x40
81 #define MOSQ_LOG_ALL 0xFFFF
85 MOSQ_ERR_CONN_PENDING = -1,
88 MOSQ_ERR_PROTOCOL = 2,
91 MOSQ_ERR_CONN_REFUSED = 5,
92 MOSQ_ERR_NOT_FOUND = 6,
93 MOSQ_ERR_CONN_LOST = 7,
95 MOSQ_ERR_PAYLOAD_SIZE = 9,
96 MOSQ_ERR_NOT_SUPPORTED = 10,
98 MOSQ_ERR_ACL_DENIED = 12,
99 MOSQ_ERR_UNKNOWN = 13,
104 /* MQTT specification restricts client ids to a maximum of 23 characters */
105 #define MOSQ_MQTT_ID_MAX_LENGTH 23
107 struct mosquitto_message{
120 * libmosquitto provides thread safe operation, with the exception of
121 * <mosquitto_lib_init> which is not thread safe.
123 /***************************************************
126 * The following functions that deal with network operations will return
127 * MOSQ_ERR_SUCCESS on success, but this does not mean that the operation has
128 * taken place. An attempt will be made to write the network data, but if the
129 * socket is not available for writing at that time then the packet will not be
130 * sent. To ensure the packet is sent, call mosquitto_loop() (which must also
131 * be called to process incoming network data).
132 * This is especially important when disconnecting a client that has a will. If
133 * the broker does not receive the DISCONNECT command, it will assume that the
134 * client has disconnected unexpectedly and send the will.
136 * mosquitto_connect()
137 * mosquitto_disconnect()
138 * mosquitto_subscribe()
139 * mosquitto_unsubscribe()
140 * mosquitto_publish()
141 ***************************************************/
144 * Function: mosquitto_lib_version
146 * Can be used to obtain version information for the mosquitto library.
147 * This allows the application to compare the library version against the
148 * version it was compiled against by using the LIBMOSQUITTO_MAJOR,
149 * LIBMOSQUITTO_MINOR and LIBMOSQUITTO_REVISION defines.
152 * major - an integer pointer. If not NULL, the major version of the
153 * library will be returned in this variable.
154 * minor - an integer pointer. If not NULL, the minor version of the
155 * library will be returned in this variable.
156 * revision - an integer pointer. If not NULL, the revision of the library will
157 * be returned in this variable.
160 * LIBMOSQUITTO_VERSION_NUMBER, which is a unique number based on the major,
161 * minor and revision values.
163 * <mosquitto_lib_cleanup>, <mosquitto_lib_init>
165 libmosq_EXPORT int mosquitto_lib_version(int *major, int *minor, int *revision);
168 * Function: mosquitto_lib_init
170 * Must be called before any other mosquitto functions.
172 * This function is *not* thread safe.
175 * MOSQ_ERR_SUCCESS - always
178 * <mosquitto_lib_cleanup>, <mosquitto_lib_version>
180 libmosq_EXPORT int mosquitto_lib_init(void);
183 * Function: mosquitto_lib_cleanup
185 * Call to free resources associated with the library.
188 * MOSQ_ERR_SUCCESS - always
191 * <mosquitto_lib_init>, <mosquitto_lib_version>
193 libmosq_EXPORT int mosquitto_lib_cleanup(void);
196 * Function: mosquitto_new
198 * Create a new mosquitto client instance.
201 * id - String to use as the client id. If NULL, a random client id
202 * will be generated. If id is NULL, clean_session must be true.
203 * clean_session - set to true to instruct the broker to clean all messages
204 * and subscriptions on disconnect, false to instruct it to
205 * keep them. See the man page mqtt(7) for more details.
206 * Note that a client will never discard its own outgoing
207 * messages on disconnect. Calling <mosquitto_connect> or
208 * <mosquitto_reconnect> will cause the messages to be resent.
209 * Use <mosquitto_reinitialise> to reset a client to its
211 * Must be set to true if the id parameter is NULL.
212 * obj - A user pointer that will be passed as an argument to any
213 * callbacks that are specified.
216 * Pointer to a struct mosquitto on success.
217 * NULL on failure. Interrogate errno to determine the cause for the failure:
218 * - ENOMEM on out of memory.
219 * - EINVAL on invalid input parameters.
222 * <mosquitto_reinitialise>, <mosquitto_destroy>, <mosquitto_user_data_set>
224 libmosq_EXPORT struct mosquitto *mosquitto_new(const char *id, bool clean_session, void *obj);
227 * Function: mosquitto_destroy
229 * Use to free memory associated with a mosquitto client instance.
232 * mosq - a struct mosquitto pointer to free.
235 * <mosquitto_new>, <mosquitto_reinitialise>
237 libmosq_EXPORT void mosquitto_destroy(struct mosquitto *mosq);
240 * Function: mosquitto_reinitialise
242 * This function allows an existing mosquitto client to be reused. Call on a
243 * mosquitto instance to close any open network connections, free memory
244 * and reinitialise the client with the new parameters. The end result is the
245 * same as the output of <mosquitto_new>.
248 * mosq - a valid mosquitto instance.
249 * id - string to use as the client id. If NULL, a random client id
250 * will be generated. If id is NULL, clean_session must be true.
251 * clean_session - set to true to instruct the broker to clean all messages
252 * and subscriptions on disconnect, false to instruct it to
253 * keep them. See the man page mqtt(7) for more details.
254 * Must be set to true if the id parameter is NULL.
255 * obj - A user pointer that will be passed as an argument to any
256 * callbacks that are specified.
259 * MOSQ_ERR_SUCCESS - on success.
260 * MOSQ_ERR_INVAL - if the input parameters were invalid.
261 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
264 * <mosquitto_new>, <mosquitto_destroy>
266 libmosq_EXPORT int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_session, void *obj);
269 * Function: mosquitto_will_set
271 * Configure will information for a mosquitto instance. By default, clients do
272 * not have a will. This must be called before calling <mosquitto_connect>.
275 * mosq - a valid mosquitto instance.
276 * topic - the topic on which to publish the will.
277 * payloadlen - the size of the payload (bytes). Valid values are between 0 and
279 * payload - pointer to the data to send. If payloadlen > 0 this must be a
280 * valid memory location.
281 * qos - integer value 0, 1 or 2 indicating the Quality of Service to be
283 * retain - set to true to make the will a retained message.
286 * MOSQ_ERR_SUCCESS - on success.
287 * MOSQ_ERR_INVAL - if the input parameters were invalid.
288 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
289 * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large.
291 libmosq_EXPORT int mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain);
294 * Function: mosquitto_will_clear
296 * Remove a previously configured will. This must be called before calling
297 * <mosquitto_connect>.
300 * mosq - a valid mosquitto instance.
303 * MOSQ_ERR_SUCCESS - on success.
304 * MOSQ_ERR_INVAL - if the input parameters were invalid.
306 libmosq_EXPORT int mosquitto_will_clear(struct mosquitto *mosq);
309 * Function: mosquitto_username_pw_set
311 * Configure username and password for a mosquitton instance. This is only
312 * supported by brokers that implement the MQTT spec v3.1. By default, no
313 * username or password will be sent.
314 * If username is NULL, the password argument is ignored.
315 * This must be called before calling mosquitto_connect().
317 * This is must be called before calling <mosquitto_connect>.
320 * mosq - a valid mosquitto instance.
321 * username - the username to send as a string, or NULL to disable
323 * password - the password to send as a string. Set to NULL when username is
324 * valid in order to send just a username.
327 * MOSQ_ERR_SUCCESS - on success.
328 * MOSQ_ERR_INVAL - if the input parameters were invalid.
329 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
331 libmosq_EXPORT int mosquitto_username_pw_set(struct mosquitto *mosq, const char *username, const char *password);
334 * Function: mosquitto_connect
336 * Connect to an MQTT broker.
339 * mosq - a valid mosquitto instance.
340 * host - the hostname or ip address of the broker to connect to.
341 * port - the network port to connect to. Usually 1883.
342 * keepalive - the number of seconds after which the broker should send a PING
343 * message to the client if no other messages have been exchanged
347 * MOSQ_ERR_SUCCESS - on success.
348 * MOSQ_ERR_INVAL - if the input parameters were invalid.
349 * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
350 * contains the error code, even on Windows.
351 * Use strerror_r() where available or FormatMessage() on
355 * <mosquitto_connect_bind>, <mosquitto_connect_async>, <mosquitto_reconnect>, <mosquitto_disconnect>, <mosquitto_tls_set>
357 libmosq_EXPORT int mosquitto_connect(struct mosquitto *mosq, const char *host, int port, int keepalive);
360 * Function: mosquitto_connect_bind
362 * Connect to an MQTT broker. This extends the functionality of
363 * <mosquitto_connect> by adding the bind_address parameter. Use this function
364 * if you need to restrict network communication over a particular interface.
367 * mosq - a valid mosquitto instance.
368 * host - the hostname or ip address of the broker to connect to.
369 * port - the network port to connect to. Usually 1883.
370 * keepalive - the number of seconds after which the broker should send a PING
371 * message to the client if no other messages have been exchanged
373 * bind_address - the hostname or ip address of the local network interface to
377 * MOSQ_ERR_SUCCESS - on success.
378 * MOSQ_ERR_INVAL - if the input parameters were invalid.
379 * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
380 * contains the error code, even on Windows.
381 * Use strerror_r() where available or FormatMessage() on
385 * <mosquitto_connect>, <mosquitto_connect_async>, <mosquitto_connect_bind_async>
387 libmosq_EXPORT int mosquitto_connect_bind(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address);
390 * Function: mosquitto_connect_async
392 * Connect to an MQTT broker. This is a non-blocking call. If you use
393 * <mosquitto_connect_async> your client must use the threaded interface
394 * <mosquitto_loop_start>. If you need to use <mosquitto_loop>, you must use
395 * <mosquitto_connect> to connect the client.
397 * May be called before or after <mosquitto_loop_start>.
400 * mosq - a valid mosquitto instance.
401 * host - the hostname or ip address of the broker to connect to.
402 * port - the network port to connect to. Usually 1883.
403 * keepalive - the number of seconds after which the broker should send a PING
404 * message to the client if no other messages have been exchanged
408 * MOSQ_ERR_SUCCESS - on success.
409 * MOSQ_ERR_INVAL - if the input parameters were invalid.
410 * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
411 * contains the error code, even on Windows.
412 * Use strerror_r() where available or FormatMessage() on
416 * <mosquitto_connect_bind_async>, <mosquitto_connect>, <mosquitto_reconnect>, <mosquitto_disconnect>, <mosquitto_tls_set>
418 libmosq_EXPORT int mosquitto_connect_async(struct mosquitto *mosq, const char *host, int port, int keepalive);
421 * Function: mosquitto_connect_async
423 * Connect to an MQTT broker. This is a non-blocking call. If you use
424 * <mosquitto_connect_async> your client must use the threaded interface
425 * <mosquitto_loop_start>. If you need to use <mosquitto_loop>, you must use
426 * <mosquitto_connect> to connect the client.
428 * This extends the functionality of <mosquitto_connect_async> by adding the
429 * bind_address parameter. Use this function if you need to restrict network
430 * communication over a particular interface.
432 * May be called before or after <mosquitto_loop_start>.
435 * mosq - a valid mosquitto instance.
436 * host - the hostname or ip address of the broker to connect to.
437 * port - the network port to connect to. Usually 1883.
438 * keepalive - the number of seconds after which the broker should send a PING
439 * message to the client if no other messages have been exchanged
441 * bind_address - the hostname or ip address of the local network interface to
445 * MOSQ_ERR_SUCCESS - on success.
446 * MOSQ_ERR_INVAL - if the input parameters were invalid.
447 * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
448 * contains the error code, even on Windows.
449 * Use strerror_r() where available or FormatMessage() on
453 * <mosquitto_connect_async>, <mosquitto_connect>, <mosquitto_connect_bind>
455 libmosq_EXPORT int mosquitto_connect_bind_async(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address);
458 * Function: mosquitto_connect_srv
460 * Connect to an MQTT broker. This is a non-blocking call. If you use
461 * <mosquitto_connect_async> your client must use the threaded interface
462 * <mosquitto_loop_start>. If you need to use <mosquitto_loop>, you must use
463 * <mosquitto_connect> to connect the client.
465 * This extends the functionality of <mosquitto_connect_async> by adding the
466 * bind_address parameter. Use this function if you need to restrict network
467 * communication over a particular interface.
469 * May be called before or after <mosquitto_loop_start>.
472 * mosq - a valid mosquitto instance.
473 * host - the hostname or ip address of the broker to connect to.
474 * keepalive - the number of seconds after which the broker should send a PING
475 * message to the client if no other messages have been exchanged
477 * bind_address - the hostname or ip address of the local network interface to
481 * MOSQ_ERR_SUCCESS - on success.
482 * MOSQ_ERR_INVAL - if the input parameters were invalid.
483 * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
484 * contains the error code, even on Windows.
485 * Use strerror_r() where available or FormatMessage() on
489 * <mosquitto_connect_async>, <mosquitto_connect>, <mosquitto_connect_bind>
491 libmosq_EXPORT int mosquitto_connect_srv(struct mosquitto *mosq, const char *host, int keepalive, const char *bind_address);
494 * Function: mosquitto_reconnect
496 * Reconnect to a broker.
498 * This function provides an easy way of reconnecting to a broker after a
499 * connection has been lost. It uses the values that were provided in the
500 * <mosquitto_connect> call. It must not be called before
501 * <mosquitto_connect>.
504 * mosq - a valid mosquitto instance.
507 * MOSQ_ERR_SUCCESS - on success.
508 * MOSQ_ERR_INVAL - if the input parameters were invalid.
509 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
512 * MOSQ_ERR_SUCCESS - on success.
513 * MOSQ_ERR_INVAL - if the input parameters were invalid.
514 * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
515 * contains the error code, even on Windows.
516 * Use strerror_r() where available or FormatMessage() on
520 * <mosquitto_connect>, <mosquitto_disconnect>, <mosquitto_reconnect_async>
522 libmosq_EXPORT int mosquitto_reconnect(struct mosquitto *mosq);
525 * Function: mosquitto_reconnect_async
527 * Reconnect to a broker. Non blocking version of <mosquitto_reconnect>.
529 * This function provides an easy way of reconnecting to a broker after a
530 * connection has been lost. It uses the values that were provided in the
531 * <mosquitto_connect> or <mosquitto_connect_async> calls. It must not be
532 * called before <mosquitto_connect>.
535 * mosq - a valid mosquitto instance.
538 * MOSQ_ERR_SUCCESS - on success.
539 * MOSQ_ERR_INVAL - if the input parameters were invalid.
540 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
543 * MOSQ_ERR_SUCCESS - on success.
544 * MOSQ_ERR_INVAL - if the input parameters were invalid.
545 * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
546 * contains the error code, even on Windows.
547 * Use strerror_r() where available or FormatMessage() on
551 * <mosquitto_connect>, <mosquitto_disconnect>
553 libmosq_EXPORT int mosquitto_reconnect_async(struct mosquitto *mosq);
556 * Function: mosquitto_disconnect
558 * Disconnect from the broker.
561 * mosq - a valid mosquitto instance.
564 * MOSQ_ERR_SUCCESS - on success.
565 * MOSQ_ERR_INVAL - if the input parameters were invalid.
566 * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
568 libmosq_EXPORT int mosquitto_disconnect(struct mosquitto *mosq);
571 * Function: mosquitto_publish
573 * Publish a message on a given topic.
576 * mosq - a valid mosquitto instance.
577 * mid - pointer to an int. If not NULL, the function will set this
578 * to the message id of this particular message. This can be then
579 * used with the publish callback to determine when the message
581 * Note that although the MQTT protocol doesn't use message ids
582 * for messages with QoS=0, libmosquitto assigns them message ids
583 * so they can be tracked with this parameter.
584 * payloadlen - the size of the payload (bytes). Valid values are between 0 and
586 * payload - pointer to the data to send. If payloadlen > 0 this must be a
587 * valid memory location.
588 * qos - integer value 0, 1 or 2 indicating the Quality of Service to be
589 * used for the message.
590 * retain - set to true to make the message retained.
593 * MOSQ_ERR_SUCCESS - on success.
594 * MOSQ_ERR_INVAL - if the input parameters were invalid.
595 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
596 * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
597 * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
599 * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large.
602 * <mosquitto_max_inflight_messages_set>
604 libmosq_EXPORT int mosquitto_publish(struct mosquitto *mosq, int *mid, const char *topic, int payloadlen, const void *payload, int qos, bool retain);
607 * Function: mosquitto_subscribe
609 * Subscribe to a topic.
612 * mosq - a valid mosquitto instance.
613 * mid - a pointer to an int. If not NULL, the function will set this to
614 * the message id of this particular message. This can be then used
615 * with the subscribe callback to determine when the message has been
617 * sub - the subscription pattern.
618 * qos - the requested Quality of Service for this subscription.
621 * MOSQ_ERR_SUCCESS - on success.
622 * MOSQ_ERR_INVAL - if the input parameters were invalid.
623 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
624 * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
626 libmosq_EXPORT int mosquitto_subscribe(struct mosquitto *mosq, int *mid, const char *sub, int qos);
629 * Function: mosquitto_unsubscribe
631 * Unsubscribe from a topic.
634 * mosq - a valid mosquitto instance.
635 * mid - a pointer to an int. If not NULL, the function will set this to
636 * the message id of this particular message. This can be then used
637 * with the unsubscribe callback to determine when the message has been
639 * sub - the unsubscription pattern.
642 * MOSQ_ERR_SUCCESS - on success.
643 * MOSQ_ERR_INVAL - if the input parameters were invalid.
644 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
645 * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
647 libmosq_EXPORT int mosquitto_unsubscribe(struct mosquitto *mosq, int *mid, const char *sub);
650 * Function: mosquitto_message_copy
652 * Copy the contents of a mosquitto message to another message.
653 * Useful for preserving a message received in the on_message() callback.
656 * dst - a pointer to a valid mosquitto_message struct to copy to.
657 * src - a pointer to a valid mosquitto_message struct to copy from.
660 * MOSQ_ERR_SUCCESS - on success.
661 * MOSQ_ERR_INVAL - if the input parameters were invalid.
662 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
665 * <mosquitto_message_free>
667 libmosq_EXPORT int mosquitto_message_copy(struct mosquitto_message *dst, const struct mosquitto_message *src);
670 * Function: mosquitto_message_free
672 * Completely free a mosquitto_message struct.
675 * message - pointer to a mosquitto_message pointer to free.
678 * <mosquitto_message_copy>
680 libmosq_EXPORT void mosquitto_message_free(struct mosquitto_message **message);
683 * Function: mosquitto_loop
685 * The main network loop for the client. You must call this frequently in order
686 * to keep communications between the client and broker working. If incoming
687 * data is present it will then be processed. Outgoing commands, from e.g.
688 * <mosquitto_publish>, are normally sent immediately that their function is
689 * called, but this is not always possible. <mosquitto_loop> will also attempt
690 * to send any remaining outgoing messages, which also includes commands that
691 * are part of the flow for messages with QoS>0.
693 * An alternative approach is to use <mosquitto_loop_start> to run the client
694 * loop in its own thread.
696 * This calls select() to monitor the client network socket. If you want to
697 * integrate mosquitto client operation with your own select() call, use
698 * <mosquitto_socket>, <mosquitto_loop_read>, <mosquitto_loop_write> and
699 * <mosquitto_loop_misc>.
704 * mosq - a valid mosquitto instance.
705 * timeout - Maximum number of milliseconds to wait for network activity
706 * in the select() call before timing out. Set to 0 for instant
707 * return. Set negative to use the default of 1000ms.
708 * max_packets - this parameter is currently unused and should be set to 1 for
709 * future compatibility.
712 * MOSQ_ERR_SUCCESS - on success.
713 * MOSQ_ERR_INVAL - if the input parameters were invalid.
714 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
715 * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
716 * MOSQ_ERR_CONN_LOST - if the connection to the broker was lost.
717 * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
719 * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
720 * contains the error code, even on Windows.
721 * Use strerror_r() where available or FormatMessage() on
724 * <mosquitto_loop_forever>, <mosquitto_loop_start>, <mosquitto_loop_stop>
726 libmosq_EXPORT int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets);
729 * Function: mosquitto_loop_forever
731 * This function call loop() for you in an infinite blocking loop. It is useful
732 * for the case where you only want to run the MQTT client loop in your
735 * It handles reconnecting in case server connection is lost. If you call
736 * mosquitto_disconnect() in a callback it will return.
739 * mosq - a valid mosquitto instance.
740 * timeout - Maximum number of milliseconds to wait for network activity
741 * in the select() call before timing out. Set to 0 for instant
742 * return. Set negative to use the default of 1000ms.
743 * max_packets - this parameter is currently unused and should be set to 1 for
744 * future compatibility.
747 * MOSQ_ERR_SUCCESS - on success.
748 * MOSQ_ERR_INVAL - if the input parameters were invalid.
749 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
750 * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
751 * MOSQ_ERR_CONN_LOST - if the connection to the broker was lost.
752 * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
754 * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
755 * contains the error code, even on Windows.
756 * Use strerror_r() where available or FormatMessage() on
760 * <mosquitto_loop>, <mosquitto_loop_start>
762 libmosq_EXPORT int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets);
765 * Function: mosquitto_loop_start
767 * This is part of the threaded client interface. Call this once to start a new
768 * thread to process network traffic. This provides an alternative to
769 * repeatedly calling <mosquitto_loop> yourself.
772 * mosq - a valid mosquitto instance.
775 * MOSQ_ERR_SUCCESS - on success.
776 * MOSQ_ERR_INVAL - if the input parameters were invalid.
777 * MOSQ_ERR_NOT_SUPPORTED - if thread support is not available.
780 * <mosquitto_connect_async>, <mosquitto_loop>, <mosquitto_loop_forever>, <mosquitto_loop_stop>
782 libmosq_EXPORT int mosquitto_loop_start(struct mosquitto *mosq);
785 * Function: mosquitto_loop_stop
787 * This is part of the threaded client interface. Call this once to stop the
788 * network thread previously created with <mosquitto_loop_start>. This call
789 * will block until the network thread finishes. For the network thread to end,
790 * you must have previously called <mosquitto_disconnect> or have set the force
794 * mosq - a valid mosquitto instance.
795 * force - set to true to force thread cancellation. If false,
796 * <mosquitto_disconnect> must have already been called.
799 * MOSQ_ERR_SUCCESS - on success.
800 * MOSQ_ERR_INVAL - if the input parameters were invalid.
801 * MOSQ_ERR_NOT_SUPPORTED - if thread support is not available.
804 * <mosquitto_loop>, <mosquitto_loop_start>
806 libmosq_EXPORT int mosquitto_loop_stop(struct mosquitto *mosq, bool force);
809 * Function: mosquitto_socket
811 * Return the socket handle for a mosquitto instance. Useful if you want to
812 * include a mosquitto client in your own select() calls.
815 * mosq - a valid mosquitto instance.
818 * The socket for the mosquitto client or -1 on failure.
820 libmosq_EXPORT int mosquitto_socket(struct mosquitto *mosq);
823 * Function: mosquitto_loop_read
825 * Carry out network read operations.
826 * This should only be used if you are not using mosquitto_loop() and are
827 * monitoring the client network socket for activity yourself.
830 * mosq - a valid mosquitto instance.
831 * max_packets - this parameter is currently unused and should be set to 1 for
832 * future compatibility.
835 * MOSQ_ERR_SUCCESS - on success.
836 * MOSQ_ERR_INVAL - if the input parameters were invalid.
837 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
838 * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
839 * MOSQ_ERR_CONN_LOST - if the connection to the broker was lost.
840 * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
842 * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
843 * contains the error code, even on Windows.
844 * Use strerror_r() where available or FormatMessage() on
848 * <mosquitto_socket>, <mosquitto_loop_write>, <mosquitto_loop_misc>
850 libmosq_EXPORT int mosquitto_loop_read(struct mosquitto *mosq, int max_packets);
853 * Function: mosquitto_loop_write
855 * Carry out network write operations.
856 * This should only be used if you are not using mosquitto_loop() and are
857 * monitoring the client network socket for activity yourself.
860 * mosq - a valid mosquitto instance.
861 * max_packets - this parameter is currently unused and should be set to 1 for
862 * future compatibility.
865 * MOSQ_ERR_SUCCESS - on success.
866 * MOSQ_ERR_INVAL - if the input parameters were invalid.
867 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
868 * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
869 * MOSQ_ERR_CONN_LOST - if the connection to the broker was lost.
870 * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
872 * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
873 * contains the error code, even on Windows.
874 * Use strerror_r() where available or FormatMessage() on
878 * <mosquitto_socket>, <mosquitto_loop_read>, <mosquitto_loop_misc>, <mosquitto_want_write>
880 libmosq_EXPORT int mosquitto_loop_write(struct mosquitto *mosq, int max_packets);
883 * Function: mosquitto_loop_misc
885 * Carry out miscellaneous operations required as part of the network loop.
886 * This should only be used if you are not using mosquitto_loop() and are
887 * monitoring the client network socket for activity yourself.
889 * This function deals with handling PINGs and checking whether messages need
890 * to be retried, so should be called fairly frequently.
893 * mosq - a valid mosquitto instance.
896 * MOSQ_ERR_SUCCESS - on success.
897 * MOSQ_ERR_INVAL - if the input parameters were invalid.
898 * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
901 * <mosquitto_socket>, <mosquitto_loop_read>, <mosquitto_loop_write>
903 libmosq_EXPORT int mosquitto_loop_misc(struct mosquitto *mosq);
906 * Function: mosquitto_want_write
908 * Returns true if there is data ready to be written on the socket.
911 * mosq - a valid mosquitto instance.
914 * <mosquitto_socket>, <mosquitto_loop_read>, <mosquitto_loop_write>
916 libmosq_EXPORT bool mosquitto_want_write(struct mosquitto *mosq);
919 * Function: mosquitto_tls_set
921 * Configure the client for certificate based SSL/TLS support. Must be called
922 * before <mosquitto_connect>.
924 * Cannot be used in conjunction with <mosquitto_tls_psk_set>.
926 * Define the Certificate Authority certificates to be trusted (ie. the server
927 * certificate must be signed with one of these certificates) using cafile.
929 * If the server you are connecting to requires clients to provide a
930 * certificate, define certfile and keyfile with your client certificate and
931 * private key. If your private key is encrypted, provide a password callback
932 * function or you will have to enter the password at the command line.
935 * mosq - a valid mosquitto instance.
936 * cafile - path to a file containing the PEM encoded trusted CA
937 * certificate files. Either cafile or capath must not be NULL.
938 * capath - path to a directory containing the PEM encoded trusted CA
939 * certificate files. See mosquitto.conf for more details on
940 * configuring this directory. Either cafile or capath must not
942 * certfile - path to a file containing the PEM encoded certificate file
943 * for this client. If NULL, keyfile must also be NULL and no
944 * client certificate will be used.
945 * keyfile - path to a file containing the PEM encoded private key for
946 * this client. If NULL, certfile must also be NULL and no
947 * client certificate will be used.
948 * pw_callback - if keyfile is encrypted, set pw_callback to allow your client
949 * to pass the correct password for decryption. If set to NULL,
950 * the password must be entered on the command line.
951 * Your callback must write the password into "buf", which is
952 * "size" bytes long. The return value must be the length of the
953 * password. "userdata" will be set to the calling mosquitto
957 * MOSQ_ERR_SUCCESS - on success.
958 * MOSQ_ERR_INVAL - if the input parameters were invalid.
959 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
962 * <mosquitto_tls_opts_set>, <mosquitto_tls_psk_set>, <mosquitto_tls_insecure_set>
964 libmosq_EXPORT int mosquitto_tls_set(struct mosquitto *mosq,
965 const char *cafile, const char *capath,
966 const char *certfile, const char *keyfile,
967 int (*pw_callback)(char *buf, int size, int rwflag, void *userdata));
970 * Function: mosquitto_tls_insecure_set
972 * Configure verification of the server hostname in the server certificate. If
973 * value is set to true, it is impossible to guarantee that the host you are
974 * connecting to is not impersonating your server. This can be useful in
975 * initial server testing, but makes it possible for a malicious third party to
976 * impersonate your server through DNS spoofing, for example.
977 * Do not use this function in a real system. Setting value to true makes the
978 * connection encryption pointless.
979 * Must be called before <mosquitto_connect>.
982 * mosq - a valid mosquitto instance.
983 * value - if set to false, the default, certificate hostname checking is
984 * performed. If set to true, no hostname checking is performed and
985 * the connection is insecure.
988 * MOSQ_ERR_SUCCESS - on success.
989 * MOSQ_ERR_INVAL - if the input parameters were invalid.
992 * <mosquitto_tls_set>
994 libmosq_EXPORT int mosquitto_tls_insecure_set(struct mosquitto *mosq, bool value);
997 * Function: mosquitto_tls_opts_set
999 * Set advanced SSL/TLS options. Must be called before <mosquitto_connect>.
1002 * mosq - a valid mosquitto instance.
1003 * cert_reqs - an integer defining the verification requirements the client
1004 * will impose on the server. This can be one of:
1005 * * SSL_VERIFY_NONE (0): the server will not be verified in any way.
1006 * * SSL_VERIFY_PEER (1): the server certificate will be verified
1007 * and the connection aborted if the verification fails.
1008 * The default and recommended value is SSL_VERIFY_PEER. Using
1009 * SSL_VERIFY_NONE provides no security.
1010 * tls_version - the version of the SSL/TLS protocol to use as a string. If NULL,
1011 * the default value is used. The default value and the
1012 * available values depend on the version of openssl that the
1013 * library was compiled against. For openssl >= 1.0.1, the
1014 * available options are tlsv1.2, tlsv1.1 and tlsv1, with tlv1.2
1015 * as the default. For openssl < 1.0.1, only tlsv1 is available.
1016 * ciphers - a string describing the ciphers available for use. See the
1017 * "openssl ciphers" tool for more information. If NULL, the
1018 * default ciphers will be used.
1021 * MOSQ_ERR_SUCCESS - on success.
1022 * MOSQ_ERR_INVAL - if the input parameters were invalid.
1023 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
1026 * <mosquitto_tls_set>
1028 libmosq_EXPORT int mosquitto_tls_opts_set(struct mosquitto *mosq, int cert_reqs, const char *tls_version, const char *ciphers);
1031 * Function: mosquitto_tls_psk_set
1033 * Configure the client for pre-shared-key based TLS support. Must be called
1034 * before <mosquitto_connect>.
1036 * Cannot be used in conjunction with <mosquitto_tls_set>.
1039 * mosq - a valid mosquitto instance.
1040 * psk - the pre-shared-key in hex format with no leading "0x".
1041 * identity - the identity of this client. May be used as the username
1042 * depending on the server settings.
1043 * ciphers - a string describing the PSK ciphers available for use. See the
1044 * "openssl ciphers" tool for more information. If NULL, the
1045 * default ciphers will be used.
1048 * MOSQ_ERR_SUCCESS - on success.
1049 * MOSQ_ERR_INVAL - if the input parameters were invalid.
1050 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
1053 * <mosquitto_tls_set>
1055 libmosq_EXPORT int mosquitto_tls_psk_set(struct mosquitto *mosq, const char *psk, const char *identity, const char *ciphers);
1058 * Function: mosquitto_connect_callback_set
1060 * Set the connect callback. This is called when the broker sends a CONNACK
1061 * message in response to a connection.
1064 * mosq - a valid mosquitto instance.
1065 * on_connect - a callback function in the following form:
1066 * void callback(struct mosquitto *mosq, void *obj, int rc)
1068 * Callback Parameters:
1069 * mosq - the mosquitto instance making the callback.
1070 * obj - the user data provided in <mosquitto_new>
1071 * rc - the return code of the connection response, one of:
1074 * * 1 - connection refused (unacceptable protocol version)
1075 * * 2 - connection refused (identifier rejected)
1076 * * 3 - connection refused (broker unavailable)
1077 * * 4-255 - reserved for future use
1079 libmosq_EXPORT void mosquitto_connect_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int));
1082 * Function: mosquitto_disconnect_callback_set
1084 * Set the disconnect callback. This is called when the broker has received the
1085 * DISCONNECT command and has disconnected the client.
1088 * mosq - a valid mosquitto instance.
1089 * on_disconnect - a callback function in the following form:
1090 * void callback(struct mosquitto *mosq, void *obj)
1092 * Callback Parameters:
1093 * mosq - the mosquitto instance making the callback.
1094 * obj - the user data provided in <mosquitto_new>
1095 * rc - integer value indicating the reason for the disconnect. A value of 0
1096 * means the client has called <mosquitto_disconnect>. Any other value
1097 * indicates that the disconnect is unexpected.
1099 libmosq_EXPORT void mosquitto_disconnect_callback_set(struct mosquitto *mosq, void (*on_disconnect)(struct mosquitto *, void *, int));
1102 * Function: mosquitto_publish_callback_set
1104 * Set the publish callback. This is called when a message initiated with
1105 * <mosquitto_publish> has been sent to the broker successfully.
1108 * mosq - a valid mosquitto instance.
1109 * on_publish - a callback function in the following form:
1110 * void callback(struct mosquitto *mosq, void *obj, int mid)
1112 * Callback Parameters:
1113 * mosq - the mosquitto instance making the callback.
1114 * obj - the user data provided in <mosquitto_new>
1115 * mid - the message id of the sent message.
1117 libmosq_EXPORT void mosquitto_publish_callback_set(struct mosquitto *mosq, void (*on_publish)(struct mosquitto *, void *, int));
1120 * Function: mosquitto_message_callback_set
1122 * Set the message callback. This is called when a message is received from the
1126 * mosq - a valid mosquitto instance.
1127 * on_message - a callback function in the following form:
1128 * void callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message)
1130 * Callback Parameters:
1131 * mosq - the mosquitto instance making the callback.
1132 * obj - the user data provided in <mosquitto_new>
1133 * message - the message data. This variable and associated memory will be
1134 * freed by the library after the callback completes. The client
1135 * should make copies of any of the data it requires.
1138 * <mosquitto_message_copy>
1140 libmosq_EXPORT void mosquitto_message_callback_set(struct mosquitto *mosq, void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *));
1143 * Function: mosquitto_subscribe_callback_set
1145 * Set the subscribe callback. This is called when the broker responds to a
1146 * subscription request.
1149 * mosq - a valid mosquitto instance.
1150 * on_subscribe - a callback function in the following form:
1151 * void callback(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos)
1153 * Callback Parameters:
1154 * mosq - the mosquitto instance making the callback.
1155 * obj - the user data provided in <mosquitto_new>
1156 * mid - the message id of the subscribe message.
1157 * qos_count - the number of granted subscriptions (size of granted_qos).
1158 * granted_qos - an array of integers indicating the granted QoS for each of
1159 * the subscriptions.
1161 libmosq_EXPORT void mosquitto_subscribe_callback_set(struct mosquitto *mosq, void (*on_subscribe)(struct mosquitto *, void *, int, int, const int *));
1164 * Function: mosquitto_unsubscribe_callback_set
1166 * Set the unsubscribe callback. This is called when the broker responds to a
1167 * unsubscription request.
1170 * mosq - a valid mosquitto instance.
1171 * on_unsubscribe - a callback function in the following form:
1172 * void callback(struct mosquitto *mosq, void *obj, int mid)
1174 * Callback Parameters:
1175 * mosq - the mosquitto instance making the callback.
1176 * obj - the user data provided in <mosquitto_new>
1177 * mid - the message id of the unsubscribe message.
1179 libmosq_EXPORT void mosquitto_unsubscribe_callback_set(struct mosquitto *mosq, void (*on_unsubscribe)(struct mosquitto *, void *, int));
1182 * Function: mosquitto_log_callback_set
1184 * Set the logging callback. This should be used if you want event logging
1185 * information from the client library.
1187 * mosq - a valid mosquitto instance.
1188 * on_log - a callback function in the following form:
1189 * void callback(struct mosquitto *mosq, void *obj, int level, const char *str)
1191 * Callback Parameters:
1192 * mosq - the mosquitto instance making the callback.
1193 * obj - the user data provided in <mosquitto_new>
1194 * level - the log message level from the values:
1200 * str - the message string.
1202 libmosq_EXPORT void mosquitto_log_callback_set(struct mosquitto *mosq, void (*on_log)(struct mosquitto *, void *, int, const char *));
1205 * Function: mosquitto_reconnect_delay_set
1207 * Control the behaviour of the client when it has unexpectedly disconnected in
1208 * <mosquitto_loop_forever> or after <mosquitto_loop_start>. The default
1209 * behaviour if this function is not used is to repeatedly attempt to reconnect
1210 * with a delay of 1 second until the connection succeeds.
1212 * Use reconnect_delay parameter to change the delay between successive
1213 * reconnection attempts. You may also enable exponential backoff of the time
1214 * between reconnections by setting reconnect_exponential_backoff to true and
1215 * set an upper bound on the delay with reconnect_delay_max.
1218 * delay=2, delay_max=10, exponential_backoff=False
1219 * Delays would be: 2, 4, 6, 8, 10, 10, ...
1222 * delay=3, delay_max=30, exponential_backoff=True
1223 * Delays would be: 3, 6, 12, 24, 30, 30, ...
1226 * mosq - a valid mosquitto instance.
1227 * reconnect_delay - the number of seconds to wait between
1229 * reconnect_delay_max - the maximum number of seconds to wait
1230 * between reconnects.
1231 * reconnect_exponential_backoff - use exponential backoff between
1232 * reconnect attempts. Set to true to enable
1233 * exponential backoff.
1236 * MOSQ_ERR_SUCCESS - on success.
1237 * MOSQ_ERR_INVAL - if the input parameters were invalid.
1239 libmosq_EXPORT int mosquitto_reconnect_delay_set(struct mosquitto *mosq, unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff);
1242 * Function: mosquitto_max_inflight_messages_set
1244 * Set the number of QoS 1 and 2 messages that can be "in flight" at one time.
1245 * An in flight message is part way through its delivery flow. Attempts to send
1246 * further messages with <mosquitto_publish> will result in the messages being
1247 * queued until the number of in flight messages reduces.
1249 * A higher number here results in greater message throughput, but if set
1250 * higher than the maximum in flight messages on the broker may lead to
1251 * delays in the messages being acknowledged.
1253 * Set to 0 for no maximum.
1256 * mosq - a valid mosquitto instance.
1257 * max_inflight_messages - the maximum number of inflight messages. Defaults
1261 * MOSQ_ERR_SUCCESS - on success.
1262 * MOSQ_ERR_INVAL - if the input parameters were invalid.
1264 libmosq_EXPORT int mosquitto_max_inflight_messages_set(struct mosquitto *mosq, unsigned int max_inflight_messages);
1267 * Function: mosquitto_message_retry_set
1269 * Set the number of seconds to wait before retrying messages. This applies to
1270 * publish messages with QoS>0. May be called at any time.
1273 * mosq - a valid mosquitto instance.
1274 * message_retry - the number of seconds to wait for a response before
1275 * retrying. Defaults to 20.
1277 libmosq_EXPORT void mosquitto_message_retry_set(struct mosquitto *mosq, unsigned int message_retry);
1280 * Function: mosquitto_user_data_set
1282 * When <mosquitto_new> is called, the pointer given as the "obj" parameter
1283 * will be passed to the callbacks as user data. The <mosquitto_user_data_set>
1284 * function allows this obj parameter to be updated at any time. This function
1285 * will not modify the memory pointed to by the current user data pointer. If
1286 * it is dynamically allocated memory you must free it yourself.
1289 * mosq - a valid mosquitto instance.
1290 * obj - A user pointer that will be passed as an argument to any callbacks
1291 * that are specified.
1293 libmosq_EXPORT void mosquitto_user_data_set(struct mosquitto *mosq, void *obj);
1296 /* =============================================================================
1298 * Section: Utility functions
1300 * =============================================================================
1304 * Function: mosquitto_strerror
1306 * Call to obtain a const string description of a mosquitto error number.
1309 * mosq_errno - a mosquitto error number.
1312 * A constant string describing the error.
1314 libmosq_EXPORT const char *mosquitto_strerror(int mosq_errno);
1317 * Function: mosquitto_connack_string
1319 * Call to obtain a const string description of an MQTT connection result.
1322 * connack_code - an MQTT connection result.
1325 * A constant string describing the result.
1327 libmosq_EXPORT const char *mosquitto_connack_string(int connack_code);
1330 * Function: mosquitto_sub_topic_tokenise
1332 * Tokenise a topic or subscription string into an array of strings
1333 * representing the topic hierarchy.
1337 * subtopic: "a/deep/topic/hierarchy"
1342 * topics[1] = "deep"
1343 * topics[2] = "topic"
1344 * topics[3] = "hierarchy"
1348 * subtopic: "/a/deep/topic/hierarchy/"
1354 * topics[2] = "deep"
1355 * topics[3] = "topic"
1356 * topics[4] = "hierarchy"
1359 * subtopic - the subscription/topic to tokenise
1360 * topics - a pointer to store the array of strings
1361 * count - an int pointer to store the number of items in the topics array.
1364 * MOSQ_ERR_SUCCESS - on success
1365 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
1370 * > int topic_count;
1373 * > mosquitto_sub_topic_tokenise("$SYS/broker/uptime", &topics, &topic_count);
1375 * > for(i=0; i<token_count; i++){
1376 * > printf("%d: %s\n", i, topics[i]);
1380 * <mosquitto_sub_topic_tokens_free>
1382 libmosq_EXPORT int mosquitto_sub_topic_tokenise(const char *subtopic, char ***topics, int *count);
1385 * Function: mosquitto_sub_topic_tokens_free
1387 * Free memory that was allocated in <mosquitto_sub_topic_tokenise>.
1390 * topics - pointer to string array.
1391 * count - count of items in string array.
1394 * MOSQ_ERR_SUCCESS - on success
1395 * MOSQ_ERR_INVAL - if the input parameters were invalid.
1398 * <mosquitto_sub_topic_tokenise>
1400 libmosq_EXPORT int mosquitto_sub_topic_tokens_free(char ***topics, int count);
1403 * Function: mosquitto_topic_matches_sub
1405 * Check whether a topic matches a subscription.
1409 * foo/bar would match the subscription foo/# or +/bar
1410 * non/matching would not match the subscription non/+/+
1413 * sub - subscription string to check topic against.
1414 * topic - topic to check.
1415 * result - bool pointer to hold result. Will be set to true if the topic
1416 * matches the subscription.
1419 * MOSQ_ERR_SUCCESS - on success
1420 * MOSQ_ERR_INVAL - if the input parameters were invalid.
1421 * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
1423 libmosq_EXPORT int mosquitto_topic_matches_sub(const char *sub, const char *topic, bool *result);