summaryrefslogtreecommitdiff
path: root/libs/libmosquitto/include
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-10-09 11:20:33 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-10-09 11:20:39 +0300
commit8b6123bb83988d80cafc113a45bb4fabe38ffefa (patch)
tree94f7f1a190795a7a1f70ff9fd0d4b7a919efe3cc /libs/libmosquitto/include
parentbe76bd932b0a8dada123311ab9a056a31fe8140f (diff)
fixes #2587 (remove rest of old OpenSSL)
Diffstat (limited to 'libs/libmosquitto/include')
-rw-r--r--libs/libmosquitto/include/config.h69
-rw-r--r--libs/libmosquitto/include/mosquitto.h2993
-rw-r--r--libs/libmosquitto/include/uthash.h948
-rw-r--r--libs/libmosquitto/include/utlist.h1073
4 files changed, 0 insertions, 5083 deletions
diff --git a/libs/libmosquitto/include/config.h b/libs/libmosquitto/include/config.h
deleted file mode 100644
index f717d00c8a..0000000000
--- a/libs/libmosquitto/include/config.h
+++ /dev/null
@@ -1,69 +0,0 @@
-#ifndef CONFIG_H
-#define CONFIG_H
-/* ============================================================
- * Platform options
- * ============================================================ */
-
-#ifdef __APPLE__
-# define __DARWIN_C_SOURCE
-#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__SYMBIAN32__) || defined(__QNX__)
-# define _XOPEN_SOURCE 700
-# define __BSD_VISIBLE 1
-# define HAVE_NETINET_IN_H
-#else
-# define _XOPEN_SOURCE 700
-# define _DEFAULT_SOURCE 1
-# define _POSIX_C_SOURCE 200809L
-#endif
-
-#define _GNU_SOURCE
-
-#define OPENSSL_LOAD_CONF
-
-/* ============================================================
- * Compatibility defines
- * ============================================================ */
-#if defined(_MSC_VER) && _MSC_VER < 1900
-# define snprintf sprintf_s
-# define EPROTO ECONNABORTED
-#endif
-
-#ifdef WIN32
-# ifndef strcasecmp
-# define strcasecmp strcmpi
-# endif
-# define strtok_r strtok_s
-# define strerror_r(e, b, l) strerror_s(b, l, e)
-#endif
-
-
-#define uthash_malloc(sz) mosquitto__malloc(sz)
-#define uthash_free(ptr,sz) mosquitto__free(ptr)
-
-
-#ifdef WITH_TLS
-# include <openssl/opensslconf.h>
-# if defined(WITH_TLS_PSK) && !defined(OPENSSL_NO_PSK)
-# define FINAL_WITH_TLS_PSK
-# endif
-#endif
-
-
-#ifdef __COVERITY__
-# include <stdint.h>
-/* These are "wrong", but we don't use them so it doesn't matter */
-# define _Float32 uint32_t
-# define _Float32x uint32_t
-# define _Float64 uint64_t
-# define _Float64x uint64_t
-# define _Float128 uint64_t
-#endif
-
-#define UNUSED(A) (void)(A)
-
-/* Android Bionic libpthread implementation doesn't have pthread_cancel */
-#ifndef ANDROID
-# define HAVE_PTHREAD_CANCEL
-#endif
-
-#endif
diff --git a/libs/libmosquitto/include/mosquitto.h b/libs/libmosquitto/include/mosquitto.h
deleted file mode 100644
index 09bba66e08..0000000000
--- a/libs/libmosquitto/include/mosquitto.h
+++ /dev/null
@@ -1,2993 +0,0 @@
-/*
-Copyright (c) 2010-2019 Roger Light <roger@atchoo.org>
-
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-and Eclipse Distribution License v1.0 which accompany this distribution.
-
-The Eclipse Public License is available at
- http://www.eclipse.org/legal/epl-v10.html
-and the Eclipse Distribution License is available at
- http://www.eclipse.org/org/documents/edl-v10.php.
-
-Contributors:
- Roger Light - initial implementation and documentation.
-*/
-
-#ifndef MOSQUITTO_H
-#define MOSQUITTO_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if defined(WIN32) && !defined(WITH_BROKER) && !defined(LIBMOSQUITTO_STATIC)
-# ifdef libmosquitto_EXPORTS
-# define libmosq_EXPORT __declspec(dllexport)
-# else
-# define libmosq_EXPORT __declspec(dllimport)
-# endif
-#else
-# define libmosq_EXPORT
-#endif
-
-#if defined(_MSC_VER) && _MSC_VER < 1900
-# ifndef __cplusplus
-# define bool char
-# define true 1
-# define false 0
-# endif
-#else
-# ifndef __cplusplus
-# include <stdbool.h>
-# endif
-#endif
-
-#include <stddef.h>
-#include <stdint.h>
-
-#define LIBMOSQUITTO_MAJOR 1
-#define LIBMOSQUITTO_MINOR 6
-#define LIBMOSQUITTO_REVISION 3
-/* LIBMOSQUITTO_VERSION_NUMBER looks like 1002001 for e.g. version 1.2.1. */
-#define LIBMOSQUITTO_VERSION_NUMBER (LIBMOSQUITTO_MAJOR*1000000+LIBMOSQUITTO_MINOR*1000+LIBMOSQUITTO_REVISION)
-
-/* Log types */
-#define MOSQ_LOG_NONE 0
-#define MOSQ_LOG_INFO (1<<0)
-#define MOSQ_LOG_NOTICE (1<<1)
-#define MOSQ_LOG_WARNING (1<<2)
-#define MOSQ_LOG_ERR (1<<3)
-#define MOSQ_LOG_DEBUG (1<<4)
-#define MOSQ_LOG_SUBSCRIBE (1<<5)
-#define MOSQ_LOG_UNSUBSCRIBE (1<<6)
-#define MOSQ_LOG_WEBSOCKETS (1<<7)
-#define MOSQ_LOG_INTERNAL 0x80000000
-#define MOSQ_LOG_ALL 0x7FFFFFFF
-
-/* Error values */
-enum mosq_err_t {
- MOSQ_ERR_AUTH_CONTINUE = -4,
- MOSQ_ERR_NO_SUBSCRIBERS = -3,
- MOSQ_ERR_SUB_EXISTS = -2,
- MOSQ_ERR_CONN_PENDING = -1,
- MOSQ_ERR_SUCCESS = 0,
- MOSQ_ERR_NOMEM = 1,
- MOSQ_ERR_PROTOCOL = 2,
- MOSQ_ERR_INVAL = 3,
- MOSQ_ERR_NO_CONN = 4,
- MOSQ_ERR_CONN_REFUSED = 5,
- MOSQ_ERR_NOT_FOUND = 6,
- MOSQ_ERR_CONN_LOST = 7,
- MOSQ_ERR_TLS = 8,
- MOSQ_ERR_PAYLOAD_SIZE = 9,
- MOSQ_ERR_NOT_SUPPORTED = 10,
- MOSQ_ERR_AUTH = 11,
- MOSQ_ERR_ACL_DENIED = 12,
- MOSQ_ERR_UNKNOWN = 13,
- MOSQ_ERR_ERRNO = 14,
- MOSQ_ERR_EAI = 15,
- MOSQ_ERR_PROXY = 16,
- MOSQ_ERR_PLUGIN_DEFER = 17,
- MOSQ_ERR_MALFORMED_UTF8 = 18,
- MOSQ_ERR_KEEPALIVE = 19,
- MOSQ_ERR_LOOKUP = 20,
- MOSQ_ERR_MALFORMED_PACKET = 21,
- MOSQ_ERR_DUPLICATE_PROPERTY = 22,
- MOSQ_ERR_TLS_HANDSHAKE = 23,
- MOSQ_ERR_QOS_NOT_SUPPORTED = 24,
- MOSQ_ERR_OVERSIZE_PACKET = 25,
- MOSQ_ERR_OCSP = 26,
-};
-
-/* Option values */
-enum mosq_opt_t {
- MOSQ_OPT_PROTOCOL_VERSION = 1,
- MOSQ_OPT_SSL_CTX = 2,
- MOSQ_OPT_SSL_CTX_WITH_DEFAULTS = 3,
- MOSQ_OPT_RECEIVE_MAXIMUM = 4,
- MOSQ_OPT_SEND_MAXIMUM = 5,
- MOSQ_OPT_TLS_KEYFORM = 6,
- MOSQ_OPT_TLS_ENGINE = 7,
- MOSQ_OPT_TLS_ENGINE_KPASS_SHA1 = 8,
- MOSQ_OPT_TLS_OCSP_REQUIRED = 9,
- MOSQ_OPT_TLS_ALPN = 10,
-};
-
-
-/* MQTT specification restricts client ids to a maximum of 23 characters */
-#define MOSQ_MQTT_ID_MAX_LENGTH 23
-
-#define MQTT_PROTOCOL_V31 3
-#define MQTT_PROTOCOL_V311 4
-#define MQTT_PROTOCOL_V5 5
-
-struct mosquitto_message{
- int mid;
- char *topic;
- void *payload;
- int payloadlen;
- int qos;
- bool retain;
-};
-
-struct mosquitto;
-typedef struct mqtt5__property mosquitto_property;
-
-/*
- * Topic: Threads
- * libmosquitto provides thread safe operation, with the exception of
- * <mosquitto_lib_init> which is not thread safe.
- *
- * If your application uses threads you must use <mosquitto_threaded_set> to
- * tell the library this is the case, otherwise it makes some optimisations
- * for the single threaded case that may result in unexpected behaviour for
- * the multi threaded case.
- */
-/***************************************************
- * Important note
- *
- * The following functions that deal with network operations will return
- * MOSQ_ERR_SUCCESS on success, but this does not mean that the operation has
- * taken place. An attempt will be made to write the network data, but if the
- * socket is not available for writing at that time then the packet will not be
- * sent. To ensure the packet is sent, call mosquitto_loop() (which must also
- * be called to process incoming network data).
- * This is especially important when disconnecting a client that has a will. If
- * the broker does not receive the DISCONNECT command, it will assume that the
- * client has disconnected unexpectedly and send the will.
- *
- * mosquitto_connect()
- * mosquitto_disconnect()
- * mosquitto_subscribe()
- * mosquitto_unsubscribe()
- * mosquitto_publish()
- ***************************************************/
-
-
-/* ======================================================================
- *
- * Section: Library version, init, and cleanup
- *
- * ====================================================================== */
-/*
- * Function: mosquitto_lib_version
- *
- * Can be used to obtain version information for the mosquitto library.
- * This allows the application to compare the library version against the
- * version it was compiled against by using the LIBMOSQUITTO_MAJOR,
- * LIBMOSQUITTO_MINOR and LIBMOSQUITTO_REVISION defines.
- *
- * Parameters:
- * major - an integer pointer. If not NULL, the major version of the
- * library will be returned in this variable.
- * minor - an integer pointer. If not NULL, the minor version of the
- * library will be returned in this variable.
- * revision - an integer pointer. If not NULL, the revision of the library will
- * be returned in this variable.
- *
- * Returns:
- * LIBMOSQUITTO_VERSION_NUMBER, which is a unique number based on the major,
- * minor and revision values.
- * See Also:
- * <mosquitto_lib_cleanup>, <mosquitto_lib_init>
- */
-libmosq_EXPORT int mosquitto_lib_version(int *major, int *minor, int *revision);
-
-/*
- * Function: mosquitto_lib_init
- *
- * Must be called before any other mosquitto functions.
- *
- * This function is *not* thread safe.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - always
- *
- * See Also:
- * <mosquitto_lib_cleanup>, <mosquitto_lib_version>
- */
-libmosq_EXPORT int mosquitto_lib_init(void);
-
-/*
- * Function: mosquitto_lib_cleanup
- *
- * Call to free resources associated with the library.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - always
- *
- * See Also:
- * <mosquitto_lib_init>, <mosquitto_lib_version>
- */
-libmosq_EXPORT int mosquitto_lib_cleanup(void);
-
-
-/* ======================================================================
- *
- * Section: Client creation, destruction, and reinitialisation
- *
- * ====================================================================== */
-/*
- * Function: mosquitto_new
- *
- * Create a new mosquitto client instance.
- *
- * Parameters:
- * id - String to use as the client id. If NULL, a random client id
- * will be generated. If id is NULL, clean_session must be true.
- * clean_session - set to true to instruct the broker to clean all messages
- * and subscriptions on disconnect, false to instruct it to
- * keep them. See the man page mqtt(7) for more details.
- * Note that a client will never discard its own outgoing
- * messages on disconnect. Calling <mosquitto_connect> or
- * <mosquitto_reconnect> will cause the messages to be resent.
- * Use <mosquitto_reinitialise> to reset a client to its
- * original state.
- * Must be set to true if the id parameter is NULL.
- * obj - A user pointer that will be passed as an argument to any
- * callbacks that are specified.
- *
- * Returns:
- * Pointer to a struct mosquitto on success.
- * NULL on failure. Interrogate errno to determine the cause for the failure:
- * - ENOMEM on out of memory.
- * - EINVAL on invalid input parameters.
- *
- * See Also:
- * <mosquitto_reinitialise>, <mosquitto_destroy>, <mosquitto_user_data_set>
- */
-libmosq_EXPORT struct mosquitto *mosquitto_new(const char *id, bool clean_session, void *obj);
-
-/*
- * Function: mosquitto_destroy
- *
- * Use to free memory associated with a mosquitto client instance.
- *
- * Parameters:
- * mosq - a struct mosquitto pointer to free.
- *
- * See Also:
- * <mosquitto_new>, <mosquitto_reinitialise>
- */
-libmosq_EXPORT void mosquitto_destroy(struct mosquitto *mosq);
-
-/*
- * Function: mosquitto_reinitialise
- *
- * This function allows an existing mosquitto client to be reused. Call on a
- * mosquitto instance to close any open network connections, free memory
- * and reinitialise the client with the new parameters. The end result is the
- * same as the output of <mosquitto_new>.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * id - string to use as the client id. If NULL, a random client id
- * will be generated. If id is NULL, clean_session must be true.
- * clean_session - set to true to instruct the broker to clean all messages
- * and subscriptions on disconnect, false to instruct it to
- * keep them. See the man page mqtt(7) for more details.
- * Must be set to true if the id parameter is NULL.
- * obj - A user pointer that will be passed as an argument to any
- * callbacks that are specified.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- *
- * See Also:
- * <mosquitto_new>, <mosquitto_destroy>
- */
-libmosq_EXPORT int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_session, void *obj);
-
-
-/* ======================================================================
- *
- * Section: Will
- *
- * ====================================================================== */
-/*
- * Function: mosquitto_will_set
- *
- * Configure will information for a mosquitto instance. By default, clients do
- * not have a will. This must be called before calling <mosquitto_connect>.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * topic - the topic on which to publish the will.
- * payloadlen - the size of the payload (bytes). Valid values are between 0 and
- * 268,435,455.
- * payload - pointer to the data to send. If payloadlen > 0 this must be a
- * valid memory location.
- * qos - integer value 0, 1 or 2 indicating the Quality of Service to be
- * used for the will.
- * retain - set to true to make the will a retained message.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large.
- * MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8.
- */
-libmosq_EXPORT int mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain);
-
-/*
- * Function: mosquitto_will_set_v5
- *
- * Configure will information for a mosquitto instance, with attached
- * properties. By default, clients do not have a will. This must be called
- * before calling <mosquitto_connect>.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * topic - the topic on which to publish the will.
- * payloadlen - the size of the payload (bytes). Valid values are between 0 and
- * 268,435,455.
- * payload - pointer to the data to send. If payloadlen > 0 this must be a
- * valid memory location.
- * qos - integer value 0, 1 or 2 indicating the Quality of Service to be
- * used for the will.
- * retain - set to true to make the will a retained message.
- * properties - list of MQTT 5 properties. Can be NULL. On success only, the
- * property list becomes the property of libmosquitto once this
- * function is called and will be freed by the library. The
- * property list must be freed by the application on error.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large.
- * MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8.
- * MOSQ_ERR_NOT_SUPPORTED - if properties is not NULL and the client is not
- * using MQTT v5
- * MOSQ_ERR_PROTOCOL - if a property is invalid for use with wills.
- * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden.
- */
-libmosq_EXPORT int mosquitto_will_set_v5(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain, mosquitto_property *properties);
-
-/*
- * Function: mosquitto_will_clear
- *
- * Remove a previously configured will. This must be called before calling
- * <mosquitto_connect>.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- */
-libmosq_EXPORT int mosquitto_will_clear(struct mosquitto *mosq);
-
-
-/* ======================================================================
- *
- * Section: Username and password
- *
- * ====================================================================== */
-/*
- * Function: mosquitto_username_pw_set
- *
- * Configure username and password for a mosquitton instance. This is only
- * supported by brokers that implement the MQTT spec v3.1. By default, no
- * username or password will be sent.
- * If username is NULL, the password argument is ignored.
- * This must be called before calling mosquitto_connect().
- *
- * This is must be called before calling <mosquitto_connect>.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * username - the username to send as a string, or NULL to disable
- * authentication.
- * password - the password to send as a string. Set to NULL when username is
- * valid in order to send just a username.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- */
-libmosq_EXPORT int mosquitto_username_pw_set(struct mosquitto *mosq, const char *username, const char *password);
-
-
-/* ======================================================================
- *
- * Section: Connecting, reconnecting, disconnecting
- *
- * ====================================================================== */
-/*
- * Function: mosquitto_connect
- *
- * Connect to an MQTT broker.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * host - the hostname or ip address of the broker to connect to.
- * port - the network port to connect to. Usually 1883.
- * keepalive - the number of seconds after which the broker should send a PING
- * message to the client if no other messages have been exchanged
- * in that time.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
- * contains the error code, even on Windows.
- * Use strerror_r() where available or FormatMessage() on
- * Windows.
- *
- * See Also:
- * <mosquitto_connect_bind>, <mosquitto_connect_async>, <mosquitto_reconnect>, <mosquitto_disconnect>, <mosquitto_tls_set>
- */
-libmosq_EXPORT int mosquitto_connect(struct mosquitto *mosq, const char *host, int port, int keepalive);
-
-/*
- * Function: mosquitto_connect_bind
- *
- * Connect to an MQTT broker. This extends the functionality of
- * <mosquitto_connect> by adding the bind_address parameter. Use this function
- * if you need to restrict network communication over a particular interface.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * host - the hostname or ip address of the broker to connect to.
- * port - the network port to connect to. Usually 1883.
- * keepalive - the number of seconds after which the broker should send a PING
- * message to the client if no other messages have been exchanged
- * in that time.
- * bind_address - the hostname or ip address of the local network interface to
- * bind to.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
- * contains the error code, even on Windows.
- * Use strerror_r() where available or FormatMessage() on
- * Windows.
- *
- * See Also:
- * <mosquitto_connect>, <mosquitto_connect_async>, <mosquitto_connect_bind_async>
- */
-libmosq_EXPORT int mosquitto_connect_bind(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address);
-
-/*
- * Function: mosquitto_connect_bind_v5
- *
- * Connect to an MQTT broker. This extends the functionality of
- * <mosquitto_connect> by adding the bind_address parameter. Use this function
- * if you need to restrict network communication over a particular interface.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * host - the hostname or ip address of the broker to connect to.
- * port - the network port to connect to. Usually 1883.
- * keepalive - the number of seconds after which the broker should send a PING
- * message to the client if no other messages have been exchanged
- * in that time.
- * bind_address - the hostname or ip address of the local network interface to
- * bind to.
- * properties - the MQTT 5 properties for the connect (not for the Will).
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
- * contains the error code, even on Windows.
- * Use strerror_r() where available or FormatMessage() on
- * Windows.
- * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden.
- * MOSQ_ERR_PROTOCOL - if any property is invalid for use with CONNECT.
- *
- * See Also:
- * <mosquitto_connect>, <mosquitto_connect_async>, <mosquitto_connect_bind_async>
- */
-libmosq_EXPORT int mosquitto_connect_bind_v5(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address, const mosquitto_property *properties);
-
-/*
- * Function: mosquitto_connect_async
- *
- * Connect to an MQTT broker. This is a non-blocking call. If you use
- * <mosquitto_connect_async> your client must use the threaded interface
- * <mosquitto_loop_start>. If you need to use <mosquitto_loop>, you must use
- * <mosquitto_connect> to connect the client.
- *
- * May be called before or after <mosquitto_loop_start>.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * host - the hostname or ip address of the broker to connect to.
- * port - the network port to connect to. Usually 1883.
- * keepalive - the number of seconds after which the broker should send a PING
- * message to the client if no other messages have been exchanged
- * in that time.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
- * contains the error code, even on Windows.
- * Use strerror_r() where available or FormatMessage() on
- * Windows.
- *
- * See Also:
- * <mosquitto_connect_bind_async>, <mosquitto_connect>, <mosquitto_reconnect>, <mosquitto_disconnect>, <mosquitto_tls_set>
- */
-libmosq_EXPORT int mosquitto_connect_async(struct mosquitto *mosq, const char *host, int port, int keepalive);
-
-/*
- * Function: mosquitto_connect_bind_async
- *
- * Connect to an MQTT broker. This is a non-blocking call. If you use
- * <mosquitto_connect_bind_async> your client must use the threaded interface
- * <mosquitto_loop_start>. If you need to use <mosquitto_loop>, you must use
- * <mosquitto_connect> to connect the client.
- *
- * This extends the functionality of <mosquitto_connect_async> by adding the
- * bind_address parameter. Use this function if you need to restrict network
- * communication over a particular interface.
- *
- * May be called before or after <mosquitto_loop_start>.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * host - the hostname or ip address of the broker to connect to.
- * port - the network port to connect to. Usually 1883.
- * keepalive - the number of seconds after which the broker should send a PING
- * message to the client if no other messages have been exchanged
- * in that time.
- * bind_address - the hostname or ip address of the local network interface to
- * bind to.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
- * contains the error code, even on Windows.
- * Use strerror_r() where available or FormatMessage() on
- * Windows.
- *
- * See Also:
- * <mosquitto_connect_async>, <mosquitto_connect>, <mosquitto_connect_bind>
- */
-libmosq_EXPORT int mosquitto_connect_bind_async(struct mosquitto *mosq, const char *host, int port, int keepalive, const char *bind_address);
-
-/*
- * Function: mosquitto_connect_srv
- *
- * Connect to an MQTT broker. This is a non-blocking call. If you use
- * <mosquitto_connect_async> your client must use the threaded interface
- * <mosquitto_loop_start>. If you need to use <mosquitto_loop>, you must use
- * <mosquitto_connect> to connect the client.
- *
- * This extends the functionality of <mosquitto_connect_async> by adding the
- * bind_address parameter. Use this function if you need to restrict network
- * communication over a particular interface.
- *
- * May be called before or after <mosquitto_loop_start>.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * host - the hostname or ip address of the broker to connect to.
- * keepalive - the number of seconds after which the broker should send a PING
- * message to the client if no other messages have been exchanged
- * in that time.
- * bind_address - the hostname or ip address of the local network interface to
- * bind to.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
- * contains the error code, even on Windows.
- * Use strerror_r() where available or FormatMessage() on
- * Windows.
- *
- * See Also:
- * <mosquitto_connect_async>, <mosquitto_connect>, <mosquitto_connect_bind>
- */
-libmosq_EXPORT int mosquitto_connect_srv(struct mosquitto *mosq, const char *host, int keepalive, const char *bind_address);
-
-/*
- * Function: mosquitto_reconnect
- *
- * Reconnect to a broker.
- *
- * This function provides an easy way of reconnecting to a broker after a
- * connection has been lost. It uses the values that were provided in the
- * <mosquitto_connect> call. It must not be called before
- * <mosquitto_connect>.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
- * contains the error code, even on Windows.
- * Use strerror_r() where available or FormatMessage() on
- * Windows.
- *
- * See Also:
- * <mosquitto_connect>, <mosquitto_disconnect>, <mosquitto_reconnect_async>
- */
-libmosq_EXPORT int mosquitto_reconnect(struct mosquitto *mosq);
-
-/*
- * Function: mosquitto_reconnect_async
- *
- * Reconnect to a broker. Non blocking version of <mosquitto_reconnect>.
- *
- * This function provides an easy way of reconnecting to a broker after a
- * connection has been lost. It uses the values that were provided in the
- * <mosquitto_connect> or <mosquitto_connect_async> calls. It must not be
- * called before <mosquitto_connect>.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
- * contains the error code, even on Windows.
- * Use strerror_r() where available or FormatMessage() on
- * Windows.
- *
- * See Also:
- * <mosquitto_connect>, <mosquitto_disconnect>
- */
-libmosq_EXPORT int mosquitto_reconnect_async(struct mosquitto *mosq);
-
-/*
- * Function: mosquitto_disconnect
- *
- * Disconnect from the broker.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
- */
-libmosq_EXPORT int mosquitto_disconnect(struct mosquitto *mosq);
-
-/*
- * Function: mosquitto_disconnect_v5
- *
- * Disconnect from the broker, with attached MQTT properties.
- *
- * Use <mosquitto_property_add_*> to create a list of properties, then attach
- * them to this publish. Properties need freeing with
- * <mosquitto_property_free_all>.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * reason_code - the disconnect reason code.
- * properties - a valid mosquitto_property list, or NULL.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
- * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden.
- * MOSQ_ERR_PROTOCOL - if any property is invalid for use with DISCONNECT.
- */
-libmosq_EXPORT int mosquitto_disconnect_v5(struct mosquitto *mosq, int reason_code, const mosquitto_property *properties);
-
-
-/* ======================================================================
- *
- * Section: Publishing, subscribing, unsubscribing
- *
- * ====================================================================== */
-/*
- * Function: mosquitto_publish
- *
- * Publish a message on a given topic.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * mid - pointer to an int. If not NULL, the function will set this
- * to the message id of this particular message. This can be then
- * used with the publish callback to determine when the message
- * has been sent.
- * Note that although the MQTT protocol doesn't use message ids
- * for messages with QoS=0, libmosquitto assigns them message ids
- * so they can be tracked with this parameter.
- * topic - null terminated string of the topic to publish to.
- * payloadlen - the size of the payload (bytes). Valid values are between 0 and
- * 268,435,455.
- * payload - pointer to the data to send. If payloadlen > 0 this must be a
- * valid memory location.
- * qos - integer value 0, 1 or 2 indicating the Quality of Service to be
- * used for the message.
- * retain - set to true to make the message retained.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
- * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
- * broker.
- * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large.
- * MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8
- * MOSQ_ERR_QOS_NOT_SUPPORTED - if the QoS is greater than that supported by
- * the broker.
- * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
- * supported by the broker.
- *
- * See Also:
- * <mosquitto_max_inflight_messages_set>
- */
-libmosq_EXPORT int mosquitto_publish(struct mosquitto *mosq, int *mid, const char *topic, int payloadlen, const void *payload, int qos, bool retain);
-
-
-/*
- * Function: mosquitto_publish_v5
- *
- * Publish a message on a given topic, with attached MQTT properties.
- *
- * Use <mosquitto_property_add_*> to create a list of properties, then attach
- * them to this publish. Properties need freeing with
- * <mosquitto_property_free_all>.
- *
- * Requires the mosquitto instance to be connected with MQTT 5.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * mid - pointer to an int. If not NULL, the function will set this
- * to the message id of this particular message. This can be then
- * used with the publish callback to determine when the message
- * has been sent.
- * Note that although the MQTT protocol doesn't use message ids
- * for messages with QoS=0, libmosquitto assigns them message ids
- * so they can be tracked with this parameter.
- * topic - null terminated string of the topic to publish to.
- * payloadlen - the size of the payload (bytes). Valid values are between 0 and
- * 268,435,455.
- * payload - pointer to the data to send. If payloadlen > 0 this must be a
- * valid memory location.
- * qos - integer value 0, 1 or 2 indicating the Quality of Service to be
- * used for the message.
- * retain - set to true to make the message retained.
- * properties - a valid mosquitto_property list, or NULL.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
- * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
- * broker.
- * MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large.
- * MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8
- * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden.
- * MOSQ_ERR_PROTOCOL - if any property is invalid for use with PUBLISH.
- * MOSQ_ERR_QOS_NOT_SUPPORTED - if the QoS is greater than that supported by
- * the broker.
- * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
- * supported by the broker.
- */
-libmosq_EXPORT int mosquitto_publish_v5(
- struct mosquitto *mosq,
- int *mid,
- const char *topic,
- int payloadlen,
- const void *payload,
- int qos,
- bool retain,
- const mosquitto_property *properties);
-
-
-/*
- * Function: mosquitto_subscribe
- *
- * Subscribe to a topic.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * mid - a pointer to an int. If not NULL, the function will set this to
- * the message id of this particular message. This can be then used
- * with the subscribe callback to determine when the message has been
- * sent.
- * sub - the subscription pattern.
- * qos - the requested Quality of Service for this subscription.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
- * MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8
- * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
- * supported by the broker.
- */
-libmosq_EXPORT int mosquitto_subscribe(struct mosquitto *mosq, int *mid, const char *sub, int qos);
-
-/*
- * Function: mosquitto_subscribe_v5
- *
- * Subscribe to a topic, with attached MQTT properties.
- *
- * Use <mosquitto_property_add_*> to create a list of properties, then attach
- * them to this subscribe. Properties need freeing with
- * <mosquitto_property_free_all>.
- *
- * Requires the mosquitto instance to be connected with MQTT 5.
- *
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * mid - a pointer to an int. If not NULL, the function will set this to
- * the message id of this particular message. This can be then used
- * with the subscribe callback to determine when the message has been
- * sent.
- * sub - the subscription pattern.
- * qos - the requested Quality of Service for this subscription.
- * options - options to apply to this subscription, OR'd together. Set to 0 to
- * use the default options, otherwise choose from the list:
- * MQTT_SUB_OPT_NO_LOCAL - with this option set, if this client
- * publishes to a topic to which it is subscribed, the
- * broker will not publish the message back to the
- * client.
- * MQTT_SUB_OPT_RETAIN_AS_PUBLISHED - with this option set, messages
- * published for this subscription will keep the
- * retain flag as was set by the publishing client.
- * The default behaviour without this option set has
- * the retain flag indicating whether a message is
- * fresh/stale.
- * MQTT_SUB_OPT_SEND_RETAIN_ALWAYS - with this option set,
- * pre-existing retained messages are sent as soon as
- * the subscription is made, even if the subscription
- * already exists. This is the default behaviour, so
- * it is not necessary to set this option.
- * MQTT_SUB_OPT_SEND_RETAIN_NEW - with this option set, pre-existing
- * retained messages for this subscription will be
- * sent when the subscription is made, but only if the
- * subscription does not already exist.
- * MQTT_SUB_OPT_SEND_RETAIN_NEVER - with this option set,
- * pre-existing retained messages will never be sent
- * for this subscription.
- * properties - a valid mosquitto_property list, or NULL.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
- * MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8
- * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden.
- * MOSQ_ERR_PROTOCOL - if any property is invalid for use with SUBSCRIBE.
- * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
- * supported by the broker.
- */
-libmosq_EXPORT int mosquitto_subscribe_v5(struct mosquitto *mosq, int *mid, const char *sub, int qos, int options, const mosquitto_property *properties);
-
-/*
- * Function: mosquitto_subscribe_multiple
- *
- * Subscribe to multiple topics.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * mid - a pointer to an int. If not NULL, the function will set this to
- * the message id of this particular message. This can be then used
- * with the subscribe callback to determine when the message has been
- * sent.
- * sub_count - the count of subscriptions to be made
- * sub - array of sub_count pointers, each pointing to a subscription string.
- * The "char *const *const" datatype ensures that neither the array of
- * pointers nor the strings that they point to are mutable. If you aren't
- * familiar with this, just think of it as a safer "char **",
- * equivalent to "const char *" for a simple string pointer.
- * qos - the requested Quality of Service for each subscription.
- * options - options to apply to this subscription, OR'd together. Set to 0 to
- * use the default options, otherwise choose from the list:
- * MQTT_SUB_OPT_NO_LOCAL - with this option set, if this client
- * publishes to a topic to which it is subscribed, the
- * broker will not publish the message back to the
- * client.
- * MQTT_SUB_OPT_RETAIN_AS_PUBLISHED - with this option set, messages
- * published for this subscription will keep the
- * retain flag as was set by the publishing client.
- * The default behaviour without this option set has
- * the retain flag indicating whether a message is
- * fresh/stale.
- * MQTT_SUB_OPT_SEND_RETAIN_ALWAYS - with this option set,
- * pre-existing retained messages are sent as soon as
- * the subscription is made, even if the subscription
- * already exists. This is the default behaviour, so
- * it is not necessary to set this option.
- * MQTT_SUB_OPT_SEND_RETAIN_NEW - with this option set, pre-existing
- * retained messages for this subscription will be
- * sent when the subscription is made, but only if the
- * subscription does not already exist.
- * MQTT_SUB_OPT_SEND_RETAIN_NEVER - with this option set,
- * pre-existing retained messages will never be sent
- * for this subscription.
- * properties - a valid mosquitto_property list, or NULL. Only used with MQTT
- * v5 clients.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
- * MOSQ_ERR_MALFORMED_UTF8 - if a topic is not valid UTF-8
- * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
- * supported by the broker.
- */
-libmosq_EXPORT int mosquitto_subscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, char *const *const sub, int qos, int options, const mosquitto_property *properties);
-
-/*
- * Function: mosquitto_unsubscribe
- *
- * Unsubscribe from a topic.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * mid - a pointer to an int. If not NULL, the function will set this to
- * the message id of this particular message. This can be then used
- * with the unsubscribe callback to determine when the message has been
- * sent.
- * sub - the unsubscription pattern.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
- * MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8
- * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
- * supported by the broker.
- */
-libmosq_EXPORT int mosquitto_unsubscribe(struct mosquitto *mosq, int *mid, const char *sub);
-
-/*
- * Function: mosquitto_unsubscribe_v5
- *
- * Unsubscribe from a topic, with attached MQTT properties.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * mid - a pointer to an int. If not NULL, the function will set this to
- * the message id of this particular message. This can be then used
- * with the unsubscribe callback to determine when the message has been
- * sent.
- * sub - the unsubscription pattern.
- * properties - a valid mosquitto_property list, or NULL. Only used with MQTT
- * v5 clients.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
- * MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8
- * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden.
- * MOSQ_ERR_PROTOCOL - if any property is invalid for use with UNSUBSCRIBE.
- * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
- * supported by the broker.
- */
-libmosq_EXPORT int mosquitto_unsubscribe_v5(struct mosquitto *mosq, int *mid, const char *sub, const mosquitto_property *properties);
-
-/*
- * Function: mosquitto_unsubscribe_multiple
- *
- * Unsubscribe from multiple topics.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * mid - a pointer to an int. If not NULL, the function will set this to
- * the message id of this particular message. This can be then used
- * with the subscribe callback to determine when the message has been
- * sent.
- * sub_count - the count of unsubscriptions to be made
- * sub - array of sub_count pointers, each pointing to an unsubscription string.
- * The "char *const *const" datatype ensures that neither the array of
- * pointers nor the strings that they point to are mutable. If you aren't
- * familiar with this, just think of it as a safer "char **",
- * equivalent to "const char *" for a simple string pointer.
- * properties - a valid mosquitto_property list, or NULL. Only used with MQTT
- * v5 clients.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
- * MOSQ_ERR_MALFORMED_UTF8 - if a topic is not valid UTF-8
- * MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
- * supported by the broker.
- */
-libmosq_EXPORT int mosquitto_unsubscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, char *const *const sub, const mosquitto_property *properties);
-
-
-/* ======================================================================
- *
- * Section: Struct mosquitto_message helper functions
- *
- * ====================================================================== */
-/*
- * Function: mosquitto_message_copy
- *
- * Copy the contents of a mosquitto message to another message.
- * Useful for preserving a message received in the on_message() callback.
- *
- * Parameters:
- * dst - a pointer to a valid mosquitto_message struct to copy to.
- * src - a pointer to a valid mosquitto_message struct to copy from.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- *
- * See Also:
- * <mosquitto_message_free>
- */
-libmosq_EXPORT int mosquitto_message_copy(struct mosquitto_message *dst, const struct mosquitto_message *src);
-
-/*
- * Function: mosquitto_message_free
- *
- * Completely free a mosquitto_message struct.
- *
- * Parameters:
- * message - pointer to a mosquitto_message pointer to free.
- *
- * See Also:
- * <mosquitto_message_copy>, <mosquitto_message_free_contents>
- */
-libmosq_EXPORT void mosquitto_message_free(struct mosquitto_message **message);
-
-/*
- * Function: mosquitto_message_free_contents
- *
- * Free a mosquitto_message struct contents, leaving the struct unaffected.
- *
- * Parameters:
- * message - pointer to a mosquitto_message struct to free its contents.
- *
- * See Also:
- * <mosquitto_message_copy>, <mosquitto_message_free>
- */
-libmosq_EXPORT void mosquitto_message_free_contents(struct mosquitto_message *message);
-
-
-/* ======================================================================
- *
- * Section: Network loop (managed by libmosquitto)
- *
- * ====================================================================== */
-/*
- * Function: mosquitto_loop
- *
- * The main network loop for the client. You must call this frequently in order
- * to keep communications between the client and broker working. If incoming
- * data is present it will then be processed. Outgoing commands, from e.g.
- * <mosquitto_publish>, are normally sent immediately that their function is
- * called, but this is not always possible. <mosquitto_loop> will also attempt
- * to send any remaining outgoing messages, which also includes commands that
- * are part of the flow for messages with QoS>0.
- *
- * An alternative approach is to use <mosquitto_loop_start> to run the client
- * loop in its own thread.
- *
- * This calls select() to monitor the client network socket. If you want to
- * integrate mosquitto client operation with your own select() call, use
- * <mosquitto_socket>, <mosquitto_loop_read>, <mosquitto_loop_write> and
- * <mosquitto_loop_misc>.
- *
- * Threads:
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * timeout - Maximum number of milliseconds to wait for network activity
- * in the select() call before timing out. Set to 0 for instant
- * return. Set negative to use the default of 1000ms.
- * max_packets - this parameter is currently unused and should be set to 1 for
- * future compatibility.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
- * MOSQ_ERR_CONN_LOST - if the connection to the broker was lost.
- * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
- * broker.
- * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
- * contains the error code, even on Windows.
- * Use strerror_r() where available or FormatMessage() on
- * Windows.
- * See Also:
- * <mosquitto_loop_forever>, <mosquitto_loop_start>, <mosquitto_loop_stop>
- */
-libmosq_EXPORT int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets);
-
-/*
- * Function: mosquitto_loop_forever
- *
- * This function call loop() for you in an infinite blocking loop. It is useful
- * for the case where you only want to run the MQTT client loop in your
- * program.
- *
- * It handles reconnecting in case server connection is lost. If you call
- * mosquitto_disconnect() in a callback it will return.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * timeout - Maximum number of milliseconds to wait for network activity
- * in the select() call before timing out. Set to 0 for instant
- * return. Set negative to use the default of 1000ms.
- * max_packets - this parameter is currently unused and should be set to 1 for
- * future compatibility.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
- * MOSQ_ERR_CONN_LOST - if the connection to the broker was lost.
- * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
- * broker.
- * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
- * contains the error code, even on Windows.
- * Use strerror_r() where available or FormatMessage() on
- * Windows.
- *
- * See Also:
- * <mosquitto_loop>, <mosquitto_loop_start>
- */
-libmosq_EXPORT int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets);
-
-/*
- * Function: mosquitto_loop_start
- *
- * This is part of the threaded client interface. Call this once to start a new
- * thread to process network traffic. This provides an alternative to
- * repeatedly calling <mosquitto_loop> yourself.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOT_SUPPORTED - if thread support is not available.
- *
- * See Also:
- * <mosquitto_connect_async>, <mosquitto_loop>, <mosquitto_loop_forever>, <mosquitto_loop_stop>
- */
-libmosq_EXPORT int mosquitto_loop_start(struct mosquitto *mosq);
-
-/*
- * Function: mosquitto_loop_stop
- *
- * This is part of the threaded client interface. Call this once to stop the
- * network thread previously created with <mosquitto_loop_start>. This call
- * will block until the network thread finishes. For the network thread to end,
- * you must have previously called <mosquitto_disconnect> or have set the force
- * parameter to true.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * force - set to true to force thread cancellation. If false,
- * <mosquitto_disconnect> must have already been called.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOT_SUPPORTED - if thread support is not available.
- *
- * See Also:
- * <mosquitto_loop>, <mosquitto_loop_start>
- */
-libmosq_EXPORT int mosquitto_loop_stop(struct mosquitto *mosq, bool force);
-
-
-/* ======================================================================
- *
- * Section: Network loop (for use in other event loops)
- *
- * ====================================================================== */
-/*
- * Function: mosquitto_loop_read
- *
- * Carry out network read operations.
- * This should only be used if you are not using mosquitto_loop() and are
- * monitoring the client network socket for activity yourself.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * max_packets - this parameter is currently unused and should be set to 1 for
- * future compatibility.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
- * MOSQ_ERR_CONN_LOST - if the connection to the broker was lost.
- * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
- * broker.
- * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
- * contains the error code, even on Windows.
- * Use strerror_r() where available or FormatMessage() on
- * Windows.
- *
- * See Also:
- * <mosquitto_socket>, <mosquitto_loop_write>, <mosquitto_loop_misc>
- */
-libmosq_EXPORT int mosquitto_loop_read(struct mosquitto *mosq, int max_packets);
-
-/*
- * Function: mosquitto_loop_write
- *
- * Carry out network write operations.
- * This should only be used if you are not using mosquitto_loop() and are
- * monitoring the client network socket for activity yourself.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * max_packets - this parameter is currently unused and should be set to 1 for
- * future compatibility.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
- * MOSQ_ERR_CONN_LOST - if the connection to the broker was lost.
- * MOSQ_ERR_PROTOCOL - if there is a protocol error communicating with the
- * broker.
- * MOSQ_ERR_ERRNO - if a system call returned an error. The variable errno
- * contains the error code, even on Windows.
- * Use strerror_r() where available or FormatMessage() on
- * Windows.
- *
- * See Also:
- * <mosquitto_socket>, <mosquitto_loop_read>, <mosquitto_loop_misc>, <mosquitto_want_write>
- */
-libmosq_EXPORT int mosquitto_loop_write(struct mosquitto *mosq, int max_packets);
-
-/*
- * Function: mosquitto_loop_misc
- *
- * Carry out miscellaneous operations required as part of the network loop.
- * This should only be used if you are not using mosquitto_loop() and are
- * monitoring the client network socket for activity yourself.
- *
- * This function deals with handling PINGs and checking whether messages need
- * to be retried, so should be called fairly frequently.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
- *
- * See Also:
- * <mosquitto_socket>, <mosquitto_loop_read>, <mosquitto_loop_write>
- */
-libmosq_EXPORT int mosquitto_loop_misc(struct mosquitto *mosq);
-
-
-/* ======================================================================
- *
- * Section: Network loop (helper functions)
- *
- * ====================================================================== */
-/*
- * Function: mosquitto_socket
- *
- * Return the socket handle for a mosquitto instance. Useful if you want to
- * include a mosquitto client in your own select() calls.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- *
- * Returns:
- * The socket for the mosquitto client or -1 on failure.
- */
-libmosq_EXPORT int mosquitto_socket(struct mosquitto *mosq);
-
-/*
- * Function: mosquitto_want_write
- *
- * Returns true if there is data ready to be written on the socket.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- *
- * See Also:
- * <mosquitto_socket>, <mosquitto_loop_read>, <mosquitto_loop_write>
- */
-libmosq_EXPORT bool mosquitto_want_write(struct mosquitto *mosq);
-
-/*
- * Function: mosquitto_threaded_set
- *
- * Used to tell the library that your application is using threads, but not
- * using <mosquitto_loop_start>. The library operates slightly differently when
- * not in threaded mode in order to simplify its operation. If you are managing
- * your own threads and do not use this function you will experience crashes
- * due to race conditions.
- *
- * When using <mosquitto_loop_start>, this is set automatically.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * threaded - true if your application is using threads, false otherwise.
- */
-libmosq_EXPORT int mosquitto_threaded_set(struct mosquitto *mosq, bool threaded);
-
-
-/* ======================================================================
- *
- * Section: Client options
- *
- * ====================================================================== */
-/*
- * Function: mosquitto_opts_set
- *
- * Used to set options for the client.
- *
- * This function is deprecated, the replacement <mosquitto_int_option> and
- * <mosquitto_void_option> functions should be used instead.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * option - the option to set.
- * value - the option specific value.
- *
- * Options:
- * MOSQ_OPT_PROTOCOL_VERSION
- * Value must be an int, set to either MQTT_PROTOCOL_V31 or
- * MQTT_PROTOCOL_V311. Must be set before the client connects.
- * Defaults to MQTT_PROTOCOL_V31.
- *
- * MOSQ_OPT_SSL_CTX
- * Pass an openssl SSL_CTX to be used when creating TLS connections
- * rather than libmosquitto creating its own. This must be called
- * before connecting to have any effect. If you use this option, the
- * onus is on you to ensure that you are using secure settings.
- * Setting to NULL means that libmosquitto will use its own SSL_CTX
- * if TLS is to be used.
- * This option is only available for openssl 1.1.0 and higher.
- *
- * MOSQ_OPT_SSL_CTX_WITH_DEFAULTS
- * Value must be an int set to 1 or 0. If set to 1, then the user
- * specified SSL_CTX passed in using MOSQ_OPT_SSL_CTX will have the
- * default options applied to it. This means that you only need to
- * change the values that are relevant to you. If you use this
- * option then you must configure the TLS options as normal, i.e.
- * you should use <mosquitto_tls_set> to configure the cafile/capath
- * as a minimum.
- * This option is only available for openssl 1.1.0 and higher.
- */
-libmosq_EXPORT int mosquitto_opts_set(struct mosquitto *mosq, enum mosq_opt_t option, void *value);
-
-/*
- * Function: mosquitto_int_option
- *
- * Used to set integer options for the client.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * option - the option to set.
- * value - the option specific value.
- *
- * Options:
- * MOSQ_OPT_PROTOCOL_VERSION
- * Value must be set to either MQTT_PROTOCOL_V31,
- * MQTT_PROTOCOL_V311, or MQTT_PROTOCOL_V5. Must be set before the
- * client connects. Defaults to MQTT_PROTOCOL_V311.
- *
- * MOSQ_OPT_RECEIVE_MAXIMUM
- * Value can be set between 1 and 65535 inclusive, and represents
- * the maximum number of incoming QoS 1 and QoS 2 messages that this
- * client wants to process at once. Defaults to 20. This option is
- * not valid for MQTT v3.1 or v3.1.1 clients.
- * Note that if the MQTT_PROP_RECEIVE_MAXIMUM property is in the
- * proplist passed to mosquitto_connect_v5(), then that property
- * will override this option. Using this option is the recommended
- * method however.
- *
- * MOSQ_OPT_SEND_MAXIMUM
- * Value can be set between 1 and 65535 inclusive, and represents
- * the maximum number of outgoing QoS 1 and QoS 2 messages that this
- * client will attempt to have "in flight" at once. Defaults to 20.
- * This option is not valid for MQTT v3.1 or v3.1.1 clients.
- * Note that if the broker being connected to sends a
- * MQTT_PROP_RECEIVE_MAXIMUM property that has a lower value than
- * this option, then the broker provided value will be used.
- *
- * MOSQ_OPT_SSL_CTX_WITH_DEFAULTS
- * If value is set to a non zero value, then the user specified
- * SSL_CTX passed in using MOSQ_OPT_SSL_CTX will have the default
- * options applied to it. This means that you only need to change
- * the values that are relevant to you. If you use this option then
- * you must configure the TLS options as normal, i.e. you should
- * use <mosquitto_tls_set> to configure the cafile/capath as a
- * minimum.
- * This option is only available for openssl 1.1.0 and higher.
- * MOSQ_OPT_TLS_OCSP_REQUIRED
- * Set whether OCSP checking on TLS connections is required. Set to
- * 1 to enable checking, or 0 (the default) for no checking.
- */
-libmosq_EXPORT int mosquitto_int_option(struct mosquitto *mosq, enum mosq_opt_t option, int value);
-
-
-/*
- * Function: mosquitto_void_option
- *
- * Used to set void* options for the client.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * option - the option to set.
- * value - the option specific value.
- *
- * Options:
- * MOSQ_OPT_SSL_CTX
- * Pass an openssl SSL_CTX to be used when creating TLS connections
- * rather than libmosquitto creating its own. This must be called
- * before connecting to have any effect. If you use this option, the
- * onus is on you to ensure that you are using secure settings.
- * Setting to NULL means that libmosquitto will use its own SSL_CTX
- * if TLS is to be used.
- * This option is only available for openssl 1.1.0 and higher.
- */
-libmosq_EXPORT int mosquitto_void_option(struct mosquitto *mosq, enum mosq_opt_t option, void *value);
-
-
-/*
- * Function: mosquitto_reconnect_delay_set
- *
- * Control the behaviour of the client when it has unexpectedly disconnected in
- * <mosquitto_loop_forever> or after <mosquitto_loop_start>. The default
- * behaviour if this function is not used is to repeatedly attempt to reconnect
- * with a delay of 1 second until the connection succeeds.
- *
- * Use reconnect_delay parameter to change the delay between successive
- * reconnection attempts. You may also enable exponential backoff of the time
- * between reconnections by setting reconnect_exponential_backoff to true and
- * set an upper bound on the delay with reconnect_delay_max.
- *
- * Example 1:
- * delay=2, delay_max=10, exponential_backoff=False
- * Delays would be: 2, 4, 6, 8, 10, 10, ...
- *
- * Example 2:
- * delay=3, delay_max=30, exponential_backoff=True
- * Delays would be: 3, 6, 12, 24, 30, 30, ...
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * reconnect_delay - the number of seconds to wait between
- * reconnects.
- * reconnect_delay_max - the maximum number of seconds to wait
- * between reconnects.
- * reconnect_exponential_backoff - use exponential backoff between
- * reconnect attempts. Set to true to enable
- * exponential backoff.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- */
-libmosq_EXPORT int mosquitto_reconnect_delay_set(struct mosquitto *mosq, unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff);
-
-/*
- * Function: mosquitto_max_inflight_messages_set
- *
- * This function is deprected. Use the <mosquitto_int_option> function with the
- * MOSQ_OPT_SEND_MAXIMUM option instead.
- *
- * Set the number of QoS 1 and 2 messages that can be "in flight" at one time.
- * An in flight message is part way through its delivery flow. Attempts to send
- * further messages with <mosquitto_publish> will result in the messages being
- * queued until the number of in flight messages reduces.
- *
- * A higher number here results in greater message throughput, but if set
- * higher than the maximum in flight messages on the broker may lead to
- * delays in the messages being acknowledged.
- *
- * Set to 0 for no maximum.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * max_inflight_messages - the maximum number of inflight messages. Defaults
- * to 20.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- */
-libmosq_EXPORT int mosquitto_max_inflight_messages_set(struct mosquitto *mosq, unsigned int max_inflight_messages);
-
-/*
- * Function: mosquitto_message_retry_set
- *
- * This function now has no effect.
- */
-libmosq_EXPORT void mosquitto_message_retry_set(struct mosquitto *mosq, unsigned int message_retry);
-
-/*
- * Function: mosquitto_user_data_set
- *
- * When <mosquitto_new> is called, the pointer given as the "obj" parameter
- * will be passed to the callbacks as user data. The <mosquitto_user_data_set>
- * function allows this obj parameter to be updated at any time. This function
- * will not modify the memory pointed to by the current user data pointer. If
- * it is dynamically allocated memory you must free it yourself.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * obj - A user pointer that will be passed as an argument to any callbacks
- * that are specified.
- */
-libmosq_EXPORT void mosquitto_user_data_set(struct mosquitto *mosq, void *obj);
-
-/* Function: mosquitto_userdata
- *
- * Retrieve the "userdata" variable for a mosquitto client.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- *
- * Returns:
- * A pointer to the userdata member variable.
- */
-libmosq_EXPORT void *mosquitto_userdata(struct mosquitto *mosq);
-
-
-/* ======================================================================
- *
- * Section: TLS support
- *
- * ====================================================================== */
-/*
- * Function: mosquitto_tls_set
- *
- * Configure the client for certificate based SSL/TLS support. Must be called
- * before <mosquitto_connect>.
- *
- * Cannot be used in conjunction with <mosquitto_tls_psk_set>.
- *
- * Define the Certificate Authority certificates to be trusted (ie. the server
- * certificate must be signed with one of these certificates) using cafile.
- *
- * If the server you are connecting to requires clients to provide a
- * certificate, define certfile and keyfile with your client certificate and
- * private key. If your private key is encrypted, provide a password callback
- * function or you will have to enter the password at the command line.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * cafile - path to a file containing the PEM encoded trusted CA
- * certificate files. Either cafile or capath must not be NULL.
- * capath - path to a directory containing the PEM encoded trusted CA
- * certificate files. See mosquitto.conf for more details on
- * configuring this directory. Either cafile or capath must not
- * be NULL.
- * certfile - path to a file containing the PEM encoded certificate file
- * for this client. If NULL, keyfile must also be NULL and no
- * client certificate will be used.
- * keyfile - path to a file containing the PEM encoded private key for
- * this client. If NULL, certfile must also be NULL and no
- * client certificate will be used.
- * pw_callback - if keyfile is encrypted, set pw_callback to allow your client
- * to pass the correct password for decryption. If set to NULL,
- * the password must be entered on the command line.
- * Your callback must write the password into "buf", which is
- * "size" bytes long. The return value must be the length of the
- * password. "userdata" will be set to the calling mosquitto
- * instance. The mosquitto userdata member variable can be
- * retrieved using <mosquitto_userdata>.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- *
- * See Also:
- * <mosquitto_tls_opts_set>, <mosquitto_tls_psk_set>,
- * <mosquitto_tls_insecure_set>, <mosquitto_userdata>
- */
-libmosq_EXPORT int mosquitto_tls_set(struct mosquitto *mosq,
- const char *cafile, const char *capath,
- const char *certfile, const char *keyfile,
- int (*pw_callback)(char *buf, int size, int rwflag, void *userdata));
-
-/*
- * Function: mosquitto_tls_insecure_set
- *
- * Configure verification of the server hostname in the server certificate. If
- * value is set to true, it is impossible to guarantee that the host you are
- * connecting to is not impersonating your server. This can be useful in
- * initial server testing, but makes it possible for a malicious third party to
- * impersonate your server through DNS spoofing, for example.
- * Do not use this function in a real system. Setting value to true makes the
- * connection encryption pointless.
- * Must be called before <mosquitto_connect>.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * value - if set to false, the default, certificate hostname checking is
- * performed. If set to true, no hostname checking is performed and
- * the connection is insecure.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- *
- * See Also:
- * <mosquitto_tls_set>
- */
-libmosq_EXPORT int mosquitto_tls_insecure_set(struct mosquitto *mosq, bool value);
-
-/*
- * Function: mosquitto_tls_opts_set
- *
- * Set advanced SSL/TLS options. Must be called before <mosquitto_connect>.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * cert_reqs - an integer defining the verification requirements the client
- * will impose on the server. This can be one of:
- * * SSL_VERIFY_NONE (0): the server will not be verified in any way.
- * * SSL_VERIFY_PEER (1): the server certificate will be verified
- * and the connection aborted if the verification fails.
- * The default and recommended value is SSL_VERIFY_PEER. Using
- * SSL_VERIFY_NONE provides no security.
- * tls_version - the version of the SSL/TLS protocol to use as a string. If NULL,
- * the default value is used. The default value and the
- * available values depend on the version of openssl that the
- * library was compiled against. For openssl >= 1.0.1, the
- * available options are tlsv1.2, tlsv1.1 and tlsv1, with tlv1.2
- * as the default. For openssl < 1.0.1, only tlsv1 is available.
- * ciphers - a string describing the ciphers available for use. See the
- * "openssl ciphers" tool for more information. If NULL, the
- * default ciphers will be used.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- *
- * See Also:
- * <mosquitto_tls_set>
- */
-libmosq_EXPORT int mosquitto_tls_opts_set(struct mosquitto *mosq, int cert_reqs, const char *tls_version, const char *ciphers);
-
-/*
- * Function: mosquitto_tls_psk_set
- *
- * Configure the client for pre-shared-key based TLS support. Must be called
- * before <mosquitto_connect>.
- *
- * Cannot be used in conjunction with <mosquitto_tls_set>.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * psk - the pre-shared-key in hex format with no leading "0x".
- * identity - the identity of this client. May be used as the username
- * depending on the server settings.
- * ciphers - a string describing the PSK ciphers available for use. See the
- * "openssl ciphers" tool for more information. If NULL, the
- * default ciphers will be used.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- *
- * See Also:
- * <mosquitto_tls_set>
- */
-libmosq_EXPORT int mosquitto_tls_psk_set(struct mosquitto *mosq, const char *psk, const char *identity, const char *ciphers);
-
-
-/* ======================================================================
- *
- * Section: Callbacks
- *
- * ====================================================================== */
-/*
- * Function: mosquitto_connect_callback_set
- *
- * Set the connect callback. This is called when the broker sends a CONNACK
- * message in response to a connection.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * on_connect - a callback function in the following form:
- * void callback(struct mosquitto *mosq, void *obj, int rc)
- *
- * Callback Parameters:
- * mosq - the mosquitto instance making the callback.
- * obj - the user data provided in <mosquitto_new>
- * rc - the return code of the connection response, one of:
- *
- * * 0 - success
- * * 1 - connection refused (unacceptable protocol version)
- * * 2 - connection refused (identifier rejected)
- * * 3 - connection refused (broker unavailable)
- * * 4-255 - reserved for future use
- */
-libmosq_EXPORT void mosquitto_connect_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int));
-
-/*
- * Function: mosquitto_connect_with_flags_callback_set
- *
- * Set the connect callback. This is called when the broker sends a CONNACK
- * message in response to a connection.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * on_connect - a callback function in the following form:
- * void callback(struct mosquitto *mosq, void *obj, int rc)
- *
- * Callback Parameters:
- * mosq - the mosquitto instance making the callback.
- * obj - the user data provided in <mosquitto_new>
- * rc - the return code of the connection response, one of:
- * flags - the connect flags.
- *
- * * 0 - success
- * * 1 - connection refused (unacceptable protocol version)
- * * 2 - connection refused (identifier rejected)
- * * 3 - connection refused (broker unavailable)
- * * 4-255 - reserved for future use
- */
-libmosq_EXPORT void mosquitto_connect_with_flags_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int, int));
-
-/*
- * Function: mosquitto_connect_v5_callback_set
- *
- * Set the connect callback. This is called when the broker sends a CONNACK
- * message in response to a connection.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * on_connect - a callback function in the following form:
- * void callback(struct mosquitto *mosq, void *obj, int rc)
- *
- * Callback Parameters:
- * mosq - the mosquitto instance making the callback.
- * obj - the user data provided in <mosquitto_new>
- * rc - the return code of the connection response, one of:
- * * 0 - success
- * * 1 - connection refused (unacceptable protocol version)
- * * 2 - connection refused (identifier rejected)
- * * 3 - connection refused (broker unavailable)
- * * 4-255 - reserved for future use
- * flags - the connect flags.
- * props - list of MQTT 5 properties, or NULL
- *
- */
-libmosq_EXPORT void mosquitto_connect_v5_callback_set(struct mosquitto *mosq, void (*on_connect)(struct mosquitto *, void *, int, int, const mosquitto_property *props));
-
-/*
- * Function: mosquitto_disconnect_callback_set
- *
- * Set the disconnect callback. This is called when the broker has received the
- * DISCONNECT command and has disconnected the client.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * on_disconnect - a callback function in the following form:
- * void callback(struct mosquitto *mosq, void *obj)
- *
- * Callback Parameters:
- * mosq - the mosquitto instance making the callback.
- * obj - the user data provided in <mosquitto_new>
- * rc - integer value indicating the reason for the disconnect. A value of 0
- * means the client has called <mosquitto_disconnect>. Any other value
- * indicates that the disconnect is unexpected.
- */
-libmosq_EXPORT void mosquitto_disconnect_callback_set(struct mosquitto *mosq, void (*on_disconnect)(struct mosquitto *, void *, int));
-
-/*
- * Function: mosquitto_disconnect_v5_callback_set
- *
- * Set the disconnect callback. This is called when the broker has received the
- * DISCONNECT command and has disconnected the client.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * on_disconnect - a callback function in the following form:
- * void callback(struct mosquitto *mosq, void *obj)
- *
- * Callback Parameters:
- * mosq - the mosquitto instance making the callback.
- * obj - the user data provided in <mosquitto_new>
- * rc - integer value indicating the reason for the disconnect. A value of 0
- * means the client has called <mosquitto_disconnect>. Any other value
- * indicates that the disconnect is unexpected.
- * props - list of MQTT 5 properties, or NULL
- */
-libmosq_EXPORT void mosquitto_disconnect_v5_callback_set(struct mosquitto *mosq, void (*on_disconnect)(struct mosquitto *, void *, int, const mosquitto_property *));
-
-/*
- * Function: mosquitto_publish_callback_set
- *
- * Set the publish callback. This is called when a message initiated with
- * <mosquitto_publish> has been sent to the broker successfully.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * on_publish - a callback function in the following form:
- * void callback(struct mosquitto *mosq, void *obj, int mid)
- *
- * Callback Parameters:
- * mosq - the mosquitto instance making the callback.
- * obj - the user data provided in <mosquitto_new>
- * mid - the message id of the sent message.
- */
-libmosq_EXPORT void mosquitto_publish_callback_set(struct mosquitto *mosq, void (*on_publish)(struct mosquitto *, void *, int));
-
-/*
- * Function: mosquitto_publish_v5_callback_set
- *
- * Set the publish callback. This is called when a message initiated with
- * <mosquitto_publish> has been sent to the broker. This callback will be
- * called both if the message is sent successfully, or if the broker responded
- * with an error, which will be reflected in the reason_code parameter.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * on_publish - a callback function in the following form:
- * void callback(struct mosquitto *mosq, void *obj, int mid)
- *
- * Callback Parameters:
- * mosq - the mosquitto instance making the callback.
- * obj - the user data provided in <mosquitto_new>
- * mid - the message id of the sent message.
- * reason_code - the MQTT 5 reason code
- * props - list of MQTT 5 properties, or NULL
- */
-libmosq_EXPORT void mosquitto_publish_v5_callback_set(struct mosquitto *mosq, void (*on_publish)(struct mosquitto *, void *, int, int, const mosquitto_property *));
-
-/*
- * Function: mosquitto_message_callback_set
- *
- * Set the message callback. This is called when a message is received from the
- * broker.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * on_message - a callback function in the following form:
- * void callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message)
- *
- * Callback Parameters:
- * mosq - the mosquitto instance making the callback.
- * obj - the user data provided in <mosquitto_new>
- * message - the message data. This variable and associated memory will be
- * freed by the library after the callback completes. The client
- * should make copies of any of the data it requires.
- *
- * See Also:
- * <mosquitto_message_copy>
- */
-libmosq_EXPORT void mosquitto_message_callback_set(struct mosquitto *mosq, void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *));
-
-/*
- * Function: mosquitto_message_v5_callback_set
- *
- * Set the message callback. This is called when a message is received from the
- * broker.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * on_message - a callback function in the following form:
- * void callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message)
- *
- * Callback Parameters:
- * mosq - the mosquitto instance making the callback.
- * obj - the user data provided in <mosquitto_new>
- * message - the message data. This variable and associated memory will be
- * freed by the library after the callback completes. The client
- * should make copies of any of the data it requires.
- * props - list of MQTT 5 properties, or NULL
- *
- * See Also:
- * <mosquitto_message_copy>
- */
-libmosq_EXPORT void mosquitto_message_v5_callback_set(struct mosquitto *mosq, void (*on_message)(struct mosquitto *, void *, const struct mosquitto_message *, const mosquitto_property *));
-
-/*
- * Function: mosquitto_subscribe_callback_set
- *
- * Set the subscribe callback. This is called when the broker responds to a
- * subscription request.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * on_subscribe - a callback function in the following form:
- * void callback(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos)
- *
- * Callback Parameters:
- * mosq - the mosquitto instance making the callback.
- * obj - the user data provided in <mosquitto_new>
- * mid - the message id of the subscribe message.
- * qos_count - the number of granted subscriptions (size of granted_qos).
- * granted_qos - an array of integers indicating the granted QoS for each of
- * the subscriptions.
- */
-libmosq_EXPORT void mosquitto_subscribe_callback_set(struct mosquitto *mosq, void (*on_subscribe)(struct mosquitto *, void *, int, int, const int *));
-
-/*
- * Function: mosquitto_subscribe_v5_callback_set
- *
- * Set the subscribe callback. This is called when the broker responds to a
- * subscription request.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * on_subscribe - a callback function in the following form:
- * void callback(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos)
- *
- * Callback Parameters:
- * mosq - the mosquitto instance making the callback.
- * obj - the user data provided in <mosquitto_new>
- * mid - the message id of the subscribe message.
- * qos_count - the number of granted subscriptions (size of granted_qos).
- * granted_qos - an array of integers indicating the granted QoS for each of
- * the subscriptions.
- * props - list of MQTT 5 properties, or NULL
- */
-libmosq_EXPORT void mosquitto_subscribe_v5_callback_set(struct mosquitto *mosq, void (*on_subscribe)(struct mosquitto *, void *, int, int, const int *, const mosquitto_property *));
-
-/*
- * Function: mosquitto_unsubscribe_callback_set
- *
- * Set the unsubscribe callback. This is called when the broker responds to a
- * unsubscription request.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * on_unsubscribe - a callback function in the following form:
- * void callback(struct mosquitto *mosq, void *obj, int mid)
- *
- * Callback Parameters:
- * mosq - the mosquitto instance making the callback.
- * obj - the user data provided in <mosquitto_new>
- * mid - the message id of the unsubscribe message.
- */
-libmosq_EXPORT void mosquitto_unsubscribe_callback_set(struct mosquitto *mosq, void (*on_unsubscribe)(struct mosquitto *, void *, int));
-
-/*
- * Function: mosquitto_unsubscribe_v5_callback_set
- *
- * Set the unsubscribe callback. This is called when the broker responds to a
- * unsubscription request.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * on_unsubscribe - a callback function in the following form:
- * void callback(struct mosquitto *mosq, void *obj, int mid)
- *
- * Callback Parameters:
- * mosq - the mosquitto instance making the callback.
- * obj - the user data provided in <mosquitto_new>
- * mid - the message id of the unsubscribe message.
- * props - list of MQTT 5 properties, or NULL
- */
-libmosq_EXPORT void mosquitto_unsubscribe_v5_callback_set(struct mosquitto *mosq, void (*on_unsubscribe)(struct mosquitto *, void *, int, const mosquitto_property *));
-
-/*
- * Function: mosquitto_log_callback_set
- *
- * Set the logging callback. This should be used if you want event logging
- * information from the client library.
- *
- * mosq - a valid mosquitto instance.
- * on_log - a callback function in the following form:
- * void callback(struct mosquitto *mosq, void *obj, int level, const char *str)
- *
- * Callback Parameters:
- * mosq - the mosquitto instance making the callback.
- * obj - the user data provided in <mosquitto_new>
- * level - the log message level from the values:
- * MOSQ_LOG_INFO
- * MOSQ_LOG_NOTICE
- * MOSQ_LOG_WARNING
- * MOSQ_LOG_ERR
- * MOSQ_LOG_DEBUG
- * str - the message string.
- */
-libmosq_EXPORT void mosquitto_log_callback_set(struct mosquitto *mosq, void (*on_log)(struct mosquitto *, void *, int, const char *));
-
-/*
- * Function: mosquitto_string_option
- *
- * Used to set const char* options for the client.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * option - the option to set.
- * value - the option specific value.
- *
- * Options:
- * MOSQ_OPT_TLS_ENGINE
- * Configure the client for TLS Engine support. Pass a TLS Engine ID
- * to be used when creating TLS connections.
- * Must be set before <mosquitto_connect>.
- * MOSQ_OPT_TLS_KEYFORM
- * Configure the client to treat the keyfile differently depending
- * on its type. Must be set before <mosquitto_connect>.
- * Set as either "pem" or "engine", to determine from where the
- * private key for a TLS connection will be obtained. Defaults to
- * "pem", a normal private key file.
- * MOSQ_OPT_TLS_KPASS_SHA1
- * Where the TLS Engine requires the use of a password to be
- * accessed, this option allows a hex encoded SHA1 hash of the
- * private key password to be passed to the engine directly.
- * Must be set before <mosquitto_connect>.
- * MOSQ_OPT_TLS_ALPN
- * If the broker being connected to has multiple services available
- * on a single TLS port, such as both MQTT and WebSockets, use this
- * option to configure the ALPN option for the connection.
- */
-libmosq_EXPORT int mosquitto_string_option(struct mosquitto *mosq, enum mosq_opt_t option, const char *value);
-
-
-/*
- * Function: mosquitto_reconnect_delay_set
- *
- * Control the behaviour of the client when it has unexpectedly disconnected in
- * <mosquitto_loop_forever> or after <mosquitto_loop_start>. The default
- * behaviour if this function is not used is to repeatedly attempt to reconnect
- * with a delay of 1 second until the connection succeeds.
- *
- * Use reconnect_delay parameter to change the delay between successive
- * reconnection attempts. You may also enable exponential backoff of the time
- * between reconnections by setting reconnect_exponential_backoff to true and
- * set an upper bound on the delay with reconnect_delay_max.
- *
- * Example 1:
- * delay=2, delay_max=10, exponential_backoff=False
- * Delays would be: 2, 4, 6, 8, 10, 10, ...
- *
- * Example 2:
- * delay=3, delay_max=30, exponential_backoff=True
- * Delays would be: 3, 6, 12, 24, 30, 30, ...
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * reconnect_delay - the number of seconds to wait between
- * reconnects.
- * reconnect_delay_max - the maximum number of seconds to wait
- * between reconnects.
- * reconnect_exponential_backoff - use exponential backoff between
- * reconnect attempts. Set to true to enable
- * exponential backoff.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success.
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- */
-libmosq_EXPORT int mosquitto_reconnect_delay_set(struct mosquitto *mosq, unsigned int reconnect_delay, unsigned int reconnect_delay_max, bool reconnect_exponential_backoff);
-
-
-/* =============================================================================
- *
- * Section: SOCKS5 proxy functions
- *
- * =============================================================================
- */
-
-/*
- * Function: mosquitto_socks5_set
- *
- * Configure the client to use a SOCKS5 proxy when connecting. Must be called
- * before connecting. "None" and "username/password" authentication is
- * supported.
- *
- * Parameters:
- * mosq - a valid mosquitto instance.
- * host - the SOCKS5 proxy host to connect to.
- * port - the SOCKS5 proxy port to use.
- * username - if not NULL, use this username when authenticating with the proxy.
- * password - if not NULL and username is not NULL, use this password when
- * authenticating with the proxy.
- */
-libmosq_EXPORT int mosquitto_socks5_set(struct mosquitto *mosq, const char *host, int port, const char *username, const char *password);
-
-
-/* =============================================================================
- *
- * Section: Utility functions
- *
- * =============================================================================
- */
-
-/*
- * Function: mosquitto_strerror
- *
- * Call to obtain a const string description of a mosquitto error number.
- *
- * Parameters:
- * mosq_errno - a mosquitto error number.
- *
- * Returns:
- * A constant string describing the error.
- */
-libmosq_EXPORT const char *mosquitto_strerror(int mosq_errno);
-
-/*
- * Function: mosquitto_connack_string
- *
- * Call to obtain a const string description of an MQTT connection result.
- *
- * Parameters:
- * connack_code - an MQTT connection result.
- *
- * Returns:
- * A constant string describing the result.
- */
-libmosq_EXPORT const char *mosquitto_connack_string(int connack_code);
-
-/*
- * Function: mosquitto_reason_string
- *
- * Call to obtain a const string description of an MQTT reason code.
- *
- * Parameters:
- * reason_code - an MQTT reason code.
- *
- * Returns:
- * A constant string describing the reason.
- */
-libmosq_EXPORT const char *mosquitto_reason_string(int reason_code);
-
-/* Function: mosquitto_string_to_command
- *
- * Take a string input representing an MQTT command and convert it to the
- * libmosquitto integer representation.
- *
- * Parameters:
- * str - the string to parse.
- * cmd - pointer to an int, for the result.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success
- * MOSQ_ERR_INVAL - on an invalid input.
- *
- * Example:
- * mosquitto_string_to_command("CONNECT", &cmd);
- * // cmd == CMD_CONNECT
- */
-libmosq_EXPORT int mosquitto_string_to_command(const char *str, int *cmd);
-
-/*
- * Function: mosquitto_sub_topic_tokenise
- *
- * Tokenise a topic or subscription string into an array of strings
- * representing the topic hierarchy.
- *
- * For example:
- *
- * subtopic: "a/deep/topic/hierarchy"
- *
- * Would result in:
- *
- * topics[0] = "a"
- * topics[1] = "deep"
- * topics[2] = "topic"
- * topics[3] = "hierarchy"
- *
- * and:
- *
- * subtopic: "/a/deep/topic/hierarchy/"
- *
- * Would result in:
- *
- * topics[0] = NULL
- * topics[1] = "a"
- * topics[2] = "deep"
- * topics[3] = "topic"
- * topics[4] = "hierarchy"
- *
- * Parameters:
- * subtopic - the subscription/topic to tokenise
- * topics - a pointer to store the array of strings
- * count - an int pointer to store the number of items in the topics array.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- * MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8
- *
- * Example:
- *
- * > char **topics;
- * > int topic_count;
- * > int i;
- * >
- * > mosquitto_sub_topic_tokenise("$SYS/broker/uptime", &topics, &topic_count);
- * >
- * > for(i=0; i<token_count; i++){
- * > printf("%d: %s\n", i, topics[i]);
- * > }
- *
- * See Also:
- * <mosquitto_sub_topic_tokens_free>
- */
-libmosq_EXPORT int mosquitto_sub_topic_tokenise(const char *subtopic, char ***topics, int *count);
-
-/*
- * Function: mosquitto_sub_topic_tokens_free
- *
- * Free memory that was allocated in <mosquitto_sub_topic_tokenise>.
- *
- * Parameters:
- * topics - pointer to string array.
- * count - count of items in string array.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- *
- * See Also:
- * <mosquitto_sub_topic_tokenise>
- */
-libmosq_EXPORT int mosquitto_sub_topic_tokens_free(char ***topics, int count);
-
-/*
- * Function: mosquitto_topic_matches_sub
- * Function: mosquitto_topic_matches_sub2
- *
- * Check whether a topic matches a subscription.
- *
- * For example:
- *
- * foo/bar would match the subscription foo/# or +/bar
- * non/matching would not match the subscription non/+/+
- *
- * Parameters:
- * sub - subscription string to check topic against.
- * sublen - length in bytes of sub string
- * topic - topic to check.
- * topiclen - length in bytes of topic string
- * result - bool pointer to hold result. Will be set to true if the topic
- * matches the subscription.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success
- * MOSQ_ERR_INVAL - if the input parameters were invalid.
- * MOSQ_ERR_NOMEM - if an out of memory condition occurred.
- */
-libmosq_EXPORT int mosquitto_topic_matches_sub(const char *sub, const char *topic, bool *result);
-libmosq_EXPORT int mosquitto_topic_matches_sub2(const char *sub, size_t sublen, const char *topic, size_t topiclen, bool *result);
-
-/*
- * Function: mosquitto_pub_topic_check
- *
- * Check whether a topic to be used for publishing is valid.
- *
- * This searches for + or # in a topic and checks its length.
- *
- * This check is already carried out in <mosquitto_publish> and
- * <mosquitto_will_set>, there is no need to call it directly before them. It
- * may be useful if you wish to check the validity of a topic in advance of
- * making a connection for example.
- *
- * Parameters:
- * topic - the topic to check
- * topiclen - length of the topic in bytes
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - for a valid topic
- * MOSQ_ERR_INVAL - if the topic contains a + or a #, or if it is too long.
- * MOSQ_ERR_MALFORMED_UTF8 - if sub or topic is not valid UTF-8
- *
- * See Also:
- * <mosquitto_sub_topic_check>
- */
-libmosq_EXPORT int mosquitto_pub_topic_check(const char *topic);
-libmosq_EXPORT int mosquitto_pub_topic_check2(const char *topic, size_t topiclen);
-
-/*
- * Function: mosquitto_sub_topic_check
- *
- * Check whether a topic to be used for subscribing is valid.
- *
- * This searches for + or # in a topic and checks that they aren't in invalid
- * positions, such as with foo/#/bar, foo/+bar or foo/bar#, and checks its
- * length.
- *
- * This check is already carried out in <mosquitto_subscribe> and
- * <mosquitto_unsubscribe>, there is no need to call it directly before them.
- * It may be useful if you wish to check the validity of a topic in advance of
- * making a connection for example.
- *
- * Parameters:
- * topic - the topic to check
- * topiclen - the length in bytes of the topic
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - for a valid topic
- * MOSQ_ERR_INVAL - if the topic contains a + or a # that is in an
- * invalid position, or if it is too long.
- * MOSQ_ERR_MALFORMED_UTF8 - if topic is not valid UTF-8
- *
- * See Also:
- * <mosquitto_sub_topic_check>
- */
-libmosq_EXPORT int mosquitto_sub_topic_check(const char *topic);
-libmosq_EXPORT int mosquitto_sub_topic_check2(const char *topic, size_t topiclen);
-
-
-struct libmosquitto_will {
- char *topic;
- void *payload;
- int payloadlen;
- int qos;
- bool retain;
-};
-
-struct libmosquitto_auth {
- char *username;
- char *password;
-};
-
-struct libmosquitto_tls {
- char *cafile;
- char *capath;
- char *certfile;
- char *keyfile;
- char *ciphers;
- char *tls_version;
- int (*pw_callback)(char *buf, int size, int rwflag, void *userdata);
- int cert_reqs;
-};
-
-/*
- * Function: mosquitto_subscribe_simple
- *
- * Helper function to make subscribing to a topic and retrieving some messages
- * very straightforward.
- *
- * This connects to a broker, subscribes to a topic, waits for msg_count
- * messages to be received, then returns after disconnecting cleanly.
- *
- * Parameters:
- * messages - pointer to a "struct mosquitto_message *". The received
- * messages will be returned here. On error, this will be set to
- * NULL.
- * msg_count - the number of messages to retrieve.
- * want_retained - if set to true, stale retained messages will be treated as
- * normal messages with regards to msg_count. If set to
- * false, they will be ignored.
- * topic - the subscription topic to use (wildcards are allowed).
- * qos - the qos to use for the subscription.
- * host - the broker to connect to.
- * port - the network port the broker is listening on.
- * client_id - the client id to use, or NULL if a random client id should be
- * generated.
- * keepalive - the MQTT keepalive value.
- * clean_session - the MQTT clean session flag.
- * username - the username string, or NULL for no username authentication.
- * password - the password string, or NULL for an empty password.
- * will - a libmosquitto_will struct containing will information, or NULL for
- * no will.
- * tls - a libmosquitto_tls struct containing TLS related parameters, or NULL
- * for no use of TLS.
- *
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success
- * >0 - on error.
- */
-libmosq_EXPORT int mosquitto_subscribe_simple(
- struct mosquitto_message **messages,
- int msg_count,
- bool want_retained,
- const char *topic,
- int qos,
- const char *host,
- int port,
- const char *client_id,
- int keepalive,
- bool clean_session,
- const char *username,
- const char *password,
- const struct libmosquitto_will *will,
- const struct libmosquitto_tls *tls);
-
-
-/*
- * Function: mosquitto_subscribe_callback
- *
- * Helper function to make subscribing to a topic and processing some messages
- * very straightforward.
- *
- * This connects to a broker, subscribes to a topic, then passes received
- * messages to a user provided callback. If the callback returns a 1, it then
- * disconnects cleanly and returns.
- *
- * Parameters:
- * callback - a callback function in the following form:
- * int callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message)
- * Note that this is the same as the normal on_message callback,
- * except that it returns an int.
- * userdata - user provided pointer that will be passed to the callback.
- * topic - the subscription topic to use (wildcards are allowed).
- * qos - the qos to use for the subscription.
- * host - the broker to connect to.
- * port - the network port the broker is listening on.
- * client_id - the client id to use, or NULL if a random client id should be
- * generated.
- * keepalive - the MQTT keepalive value.
- * clean_session - the MQTT clean session flag.
- * username - the username string, or NULL for no username authentication.
- * password - the password string, or NULL for an empty password.
- * will - a libmosquitto_will struct containing will information, or NULL for
- * no will.
- * tls - a libmosquitto_tls struct containing TLS related parameters, or NULL
- * for no use of TLS.
- *
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success
- * >0 - on error.
- */
-libmosq_EXPORT int mosquitto_subscribe_callback(
- int (*callback)(struct mosquitto *, void *, const struct mosquitto_message *),
- void *userdata,
- const char *topic,
- int qos,
- const char *host,
- int port,
- const char *client_id,
- int keepalive,
- bool clean_session,
- const char *username,
- const char *password,
- const struct libmosquitto_will *will,
- const struct libmosquitto_tls *tls);
-
-
-/*
- * Function: mosquitto_validate_utf8
- *
- * Helper function to validate whether a UTF-8 string is valid, according to
- * the UTF-8 spec and the MQTT additions.
- *
- * Parameters:
- * str - a string to check
- * len - the length of the string in bytes
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success
- * MOSQ_ERR_INVAL - if str is NULL or len<0 or len>65536
- * MOSQ_ERR_MALFORMED_UTF8 - if str is not valid UTF-8
- */
-libmosq_EXPORT int mosquitto_validate_utf8(const char *str, int len);
-
-
-/* =============================================================================
- *
- * Section: Properties
- *
- * =============================================================================
- */
-
-
-/*
- * Function: mosquitto_property_add_byte
- *
- * Add a new byte property to a property list.
- *
- * If *proplist == NULL, a new list will be created, otherwise the new property
- * will be appended to the list.
- *
- * Parameters:
- * proplist - pointer to mosquitto_property pointer, the list of properties
- * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
- * value - integer value for the new property
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success
- * MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL
- * MOSQ_ERR_NOMEM - on out of memory
- *
- * Example:
- * mosquitto_property *proplist = NULL;
- * mosquitto_property_add_byte(&proplist, MQTT_PROP_PAYLOAD_FORMAT_IDENTIFIER, 1);
- */
-libmosq_EXPORT int mosquitto_property_add_byte(mosquitto_property **proplist, int identifier, uint8_t value);
-
-/*
- * Function: mosquitto_property_add_int16
- *
- * Add a new int16 property to a property list.
- *
- * If *proplist == NULL, a new list will be created, otherwise the new property
- * will be appended to the list.
- *
- * Parameters:
- * proplist - pointer to mosquitto_property pointer, the list of properties
- * identifier - property identifier (e.g. MQTT_PROP_RECEIVE_MAXIMUM)
- * value - integer value for the new property
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success
- * MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL
- * MOSQ_ERR_NOMEM - on out of memory
- *
- * Example:
- * mosquitto_property *proplist = NULL;
- * mosquitto_property_add_int16(&proplist, MQTT_PROP_RECEIVE_MAXIMUM, 1000);
- */
-libmosq_EXPORT int mosquitto_property_add_int16(mosquitto_property **proplist, int identifier, uint16_t value);
-
-/*
- * Function: mosquitto_property_add_int32
- *
- * Add a new int32 property to a property list.
- *
- * If *proplist == NULL, a new list will be created, otherwise the new property
- * will be appended to the list.
- *
- * Parameters:
- * proplist - pointer to mosquitto_property pointer, the list of properties
- * identifier - property identifier (e.g. MQTT_PROP_MESSAGE_EXPIRY_INTERVAL)
- * value - integer value for the new property
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success
- * MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL
- * MOSQ_ERR_NOMEM - on out of memory
- *
- * Example:
- * mosquitto_property *proplist = NULL;
- * mosquitto_property_add_int32(&proplist, MQTT_PROP_MESSAGE_EXPIRY_INTERVAL, 86400);
- */
-libmosq_EXPORT int mosquitto_property_add_int32(mosquitto_property **proplist, int identifier, uint32_t value);
-
-/*
- * Function: mosquitto_property_add_varint
- *
- * Add a new varint property to a property list.
- *
- * If *proplist == NULL, a new list will be created, otherwise the new property
- * will be appended to the list.
- *
- * Parameters:
- * proplist - pointer to mosquitto_property pointer, the list of properties
- * identifier - property identifier (e.g. MQTT_PROP_SUBSCRIPTION_IDENTIFIER)
- * value - integer value for the new property
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success
- * MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL
- * MOSQ_ERR_NOMEM - on out of memory
- *
- * Example:
- * mosquitto_property *proplist = NULL;
- * mosquitto_property_add_varint(&proplist, MQTT_PROP_SUBSCRIPTION_IDENTIFIER, 1);
- */
-libmosq_EXPORT int mosquitto_property_add_varint(mosquitto_property **proplist, int identifier, uint32_t value);
-
-/*
- * Function: mosquitto_property_add_binary
- *
- * Add a new binary property to a property list.
- *
- * If *proplist == NULL, a new list will be created, otherwise the new property
- * will be appended to the list.
- *
- * Parameters:
- * proplist - pointer to mosquitto_property pointer, the list of properties
- * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
- * value - pointer to the property data
- * len - length of property data in bytes
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success
- * MOSQ_ERR_INVAL - if identifier is invalid, or if proplist is NULL
- * MOSQ_ERR_NOMEM - on out of memory
- *
- * Example:
- * mosquitto_property *proplist = NULL;
- * mosquitto_property_add_binary(&proplist, MQTT_PROP_AUTHENTICATION_DATA, auth_data, auth_data_len);
- */
-libmosq_EXPORT int mosquitto_property_add_binary(mosquitto_property **proplist, int identifier, const void *value, uint16_t len);
-
-/*
- * Function: mosquitto_property_add_string
- *
- * Add a new string property to a property list.
- *
- * If *proplist == NULL, a new list will be created, otherwise the new property
- * will be appended to the list.
- *
- * Parameters:
- * proplist - pointer to mosquitto_property pointer, the list of properties
- * identifier - property identifier (e.g. MQTT_PROP_CONTENT_TYPE)
- * value - string value for the new property, must be UTF-8 and zero terminated
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success
- * MOSQ_ERR_INVAL - if identifier is invalid, if value is NULL, or if proplist is NULL
- * MOSQ_ERR_NOMEM - on out of memory
- * MOSQ_ERR_MALFORMED_UTF8 - value is not valid UTF-8.
- *
- * Example:
- * mosquitto_property *proplist = NULL;
- * mosquitto_property_add_string(&proplist, MQTT_PROP_CONTENT_TYPE, "application/json");
- */
-libmosq_EXPORT int mosquitto_property_add_string(mosquitto_property **proplist, int identifier, const char *value);
-
-/*
- * Function: mosquitto_property_add_string_pair
- *
- * Add a new string pair property to a property list.
- *
- * If *proplist == NULL, a new list will be created, otherwise the new property
- * will be appended to the list.
- *
- * Parameters:
- * proplist - pointer to mosquitto_property pointer, the list of properties
- * identifier - property identifier (e.g. MQTT_PROP_USER_PROPERTY)
- * name - string name for the new property, must be UTF-8 and zero terminated
- * value - string value for the new property, must be UTF-8 and zero terminated
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success
- * MOSQ_ERR_INVAL - if identifier is invalid, if name or value is NULL, or if proplist is NULL
- * MOSQ_ERR_NOMEM - on out of memory
- * MOSQ_ERR_MALFORMED_UTF8 - if name or value are not valid UTF-8.
- *
- * Example:
- * mosquitto_property *proplist = NULL;
- * mosquitto_property_add_string_pair(&proplist, MQTT_PROP_USER_PROPERTY, "client", "mosquitto_pub");
- */
-libmosq_EXPORT int mosquitto_property_add_string_pair(mosquitto_property **proplist, int identifier, const char *name, const char *value);
-
-/*
- * Function: mosquitto_property_read_byte
- *
- * Attempt to read a byte property matching an identifier, from a property list
- * or single property. This function can search for multiple entries of the
- * same identifier by using the returned value and skip_first. Note however
- * that it is forbidden for most properties to be duplicated.
- *
- * If the property is not found, *value will not be modified, so it is safe to
- * pass a variable with a default value to be potentially overwritten:
- *
- * uint16_t keepalive = 60; // default value
- * // Get value from property list, or keep default if not found.
- * mosquitto_property_read_int16(proplist, MQTT_PROP_SERVER_KEEP_ALIVE, &keepalive, false);
- *
- * Parameters:
- * proplist - mosquitto_property pointer, the list of properties or single property
- * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
- * value - pointer to store the value, or NULL if the value is not required.
- * skip_first - boolean that indicates whether the first item in the list
- * should be ignored or not. Should usually be set to false.
- *
- * Returns:
- * A valid property pointer if the property is found
- * NULL, if the property is not found, or proplist is NULL.
- *
- * Example:
- * // proplist is obtained from a callback
- * mosquitto_property *prop;
- * prop = mosquitto_property_read_byte(proplist, identifier, &value, false);
- * while(prop){
- * printf("value: %s\n", value);
- * prop = mosquitto_property_read_byte(prop, identifier, &value);
- * }
- */
-libmosq_EXPORT const mosquitto_property *mosquitto_property_read_byte(
- const mosquitto_property *proplist,
- int identifier,
- uint8_t *value,
- bool skip_first);
-
-/*
- * Function: mosquitto_property_read_int16
- *
- * Read an int16 property value from a property.
- *
- * Parameters:
- * property - property to read
- * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
- * value - pointer to store the value, or NULL if the value is not required.
- * skip_first - boolean that indicates whether the first item in the list
- * should be ignored or not. Should usually be set to false.
- *
- * Returns:
- * A valid property pointer if the property is found
- * NULL, if the property is not found, or proplist is NULL.
- *
- * Example:
- * See <mosquitto_property_read_byte>
- */
-libmosq_EXPORT const mosquitto_property *mosquitto_property_read_int16(
- const mosquitto_property *proplist,
- int identifier,
- uint16_t *value,
- bool skip_first);
-
-/*
- * Function: mosquitto_property_read_int32
- *
- * Read an int32 property value from a property.
- *
- * Parameters:
- * property - pointer to mosquitto_property pointer, the list of properties
- * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
- * value - pointer to store the value, or NULL if the value is not required.
- * skip_first - boolean that indicates whether the first item in the list
- * should be ignored or not. Should usually be set to false.
- *
- * Returns:
- * A valid property pointer if the property is found
- * NULL, if the property is not found, or proplist is NULL.
- *
- * Example:
- * See <mosquitto_property_read_byte>
- */
-libmosq_EXPORT const mosquitto_property *mosquitto_property_read_int32(
- const mosquitto_property *proplist,
- int identifier,
- uint32_t *value,
- bool skip_first);
-
-/*
- * Function: mosquitto_property_read_varint
- *
- * Read a varint property value from a property.
- *
- * Parameters:
- * property - property to read
- * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
- * value - pointer to store the value, or NULL if the value is not required.
- * skip_first - boolean that indicates whether the first item in the list
- * should be ignored or not. Should usually be set to false.
- *
- * Returns:
- * A valid property pointer if the property is found
- * NULL, if the property is not found, or proplist is NULL.
- *
- * Example:
- * See <mosquitto_property_read_byte>
- */
-libmosq_EXPORT const mosquitto_property *mosquitto_property_read_varint(
- const mosquitto_property *proplist,
- int identifier,
- uint32_t *value,
- bool skip_first);
-
-/*
- * Function: mosquitto_property_read_binary
- *
- * Read a binary property value from a property.
- *
- * On success, value must be free()'d by the application.
- *
- * Parameters:
- * property - property to read
- * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
- * value - pointer to store the value, or NULL if the value is not required.
- * skip_first - boolean that indicates whether the first item in the list
- * should be ignored or not. Should usually be set to false.
- *
- * Returns:
- * A valid property pointer if the property is found
- * NULL, if the property is not found, or proplist is NULL, or if an out of memory condition occurred.
- *
- * Example:
- * See <mosquitto_property_read_byte>
- */
-libmosq_EXPORT const mosquitto_property *mosquitto_property_read_binary(
- const mosquitto_property *proplist,
- int identifier,
- void **value,
- uint16_t *len,
- bool skip_first);
-
-/*
- * Function: mosquitto_property_read_string
- *
- * Read a string property value from a property.
- *
- * On success, value must be free()'d by the application.
- *
- * Parameters:
- * property - property to read
- * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
- * value - pointer to char*, for the property data to be stored in, or NULL if
- * the value is not required.
- * skip_first - boolean that indicates whether the first item in the list
- * should be ignored or not. Should usually be set to false.
- *
- * Returns:
- * A valid property pointer if the property is found
- * NULL, if the property is not found, or proplist is NULL, or if an out of memory condition occurred.
- *
- * Example:
- * See <mosquitto_property_read_byte>
- */
-libmosq_EXPORT const mosquitto_property *mosquitto_property_read_string(
- const mosquitto_property *proplist,
- int identifier,
- char **value,
- bool skip_first);
-
-/*
- * Function: mosquitto_property_read_string_pair
- *
- * Read a string pair property value pair from a property.
- *
- * On success, name and value must be free()'d by the application.
- *
- * Parameters:
- * property - property to read
- * identifier - property identifier (e.g. MQTT_PROP_PAYLOAD_FORMAT_INDICATOR)
- * name - pointer to char* for the name property data to be stored in, or NULL
- * if the name is not required.
- * value - pointer to char*, for the property data to be stored in, or NULL if
- * the value is not required.
- * skip_first - boolean that indicates whether the first item in the list
- * should be ignored or not. Should usually be set to false.
- *
- * Returns:
- * A valid property pointer if the property is found
- * NULL, if the property is not found, or proplist is NULL, or if an out of memory condition occurred.
- *
- * Example:
- * See <mosquitto_property_read_byte>
- */
-libmosq_EXPORT const mosquitto_property *mosquitto_property_read_string_pair(
- const mosquitto_property *proplist,
- int identifier,
- char **name,
- char **value,
- bool skip_first);
-
-/*
- * Function: mosquitto_property_free_all
- *
- * Free all properties from a list of properties. Frees the list and sets *properties to NULL.
- *
- * Parameters:
- * properties - list of properties to free
- *
- * Example:
- * mosquitto_properties *properties = NULL;
- * // Add properties
- * mosquitto_property_free_all(&properties);
- */
-libmosq_EXPORT void mosquitto_property_free_all(mosquitto_property **properties);
-
-/*
- * Function: mosquitto_property_copy_all
- *
- * Parameters:
- * dest : pointer for new property list
- * src : property list
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on successful copy
- * MOSQ_ERR_INVAL - if dest is NULL
- * MOSQ_ERR_NOMEM - on out of memory (dest will be set to NULL)
- */
-libmosq_EXPORT int mosquitto_property_copy_all(mosquitto_property **dest, const mosquitto_property *src);
-
-/*
- * Function: mosquitto_property_check_command
- *
- * Check whether a property identifier is valid for the given command.
- *
- * Parameters:
- * command - MQTT command (e.g. CMD_CONNECT)
- * identifier - MQTT property (e.g. MQTT_PROP_USER_PROPERTY)
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - if the identifier is valid for command
- * MOSQ_ERR_PROTOCOL - if the identifier is not valid for use with command.
- */
-libmosq_EXPORT int mosquitto_property_check_command(int command, int identifier);
-
-
-/*
- * Function: mosquitto_property_check_all
- *
- * Check whether a list of properties are valid for a particular command,
- * whether there are duplicates, and whether the values are valid where
- * possible.
- *
- * Note that this function is used internally in the library whenever
- * properties are passed to it, so in basic use this is not needed, but should
- * be helpful to check property lists *before* the point of using them.
- *
- * Parameters:
- * command - MQTT command (e.g. CMD_CONNECT)
- * properties - list of MQTT properties to check.
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - if all properties are valid
- * MOSQ_ERR_DUPLICATE_PROPERTY - if a property is duplicated where it is forbidden.
- * MOSQ_ERR_PROTOCOL - if any property is invalid
- */
-libmosq_EXPORT int mosquitto_property_check_all(int command, const mosquitto_property *properties);
-
-/* Function: mosquitto_string_to_property_info
- *
- * Parse a property name string and convert to a property identifier and data type.
- * The property name is as defined in the MQTT specification, with - as a
- * separator, for example: payload-format-indicator.
- *
- * Parameters:
- * propname - the string to parse
- * identifier - pointer to an int to receive the property identifier
- * type - pointer to an int to receive the property type
- *
- * Returns:
- * MOSQ_ERR_SUCCESS - on success
- * MOSQ_ERR_INVAL - if the string does not match a property
- *
- * Example:
- * mosquitto_string_to_property_info("response-topic", &id, &type);
- * // id == MQTT_PROP_RESPONSE_TOPIC
- * // type == MQTT_PROP_TYPE_STRING
- */
-libmosq_EXPORT int mosquitto_string_to_property_info(const char *propname, int *identifier, int *type);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/libs/libmosquitto/include/uthash.h b/libs/libmosquitto/include/uthash.h
deleted file mode 100644
index 915a8254ee..0000000000
--- a/libs/libmosquitto/include/uthash.h
+++ /dev/null
@@ -1,948 +0,0 @@
-/*
-Copyright (c) 2003-2013, Troy D. Hanson http://troydhanson.github.com/uthash/
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
-OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef UTHASH_H
-#define UTHASH_H
-
-#include <string.h> /* memcmp,strlen */
-#include <stddef.h> /* ptrdiff_t */
-#include <stdlib.h> /* exit() */
-
-/* These macros use decltype or the earlier __typeof GNU extension.
- As decltype is only available in newer compilers (VS2010 or gcc 4.3+
- when compiling c++ source) this code uses whatever method is needed
- or, for VS2008 where neither is available, uses casting workarounds. */
-#ifdef _MSC_VER /* MS compiler */
-#if _MSC_VER >= 1600 && defined(__cplusplus) /* VS2010 or newer in C++ mode */
-#define DECLTYPE(x) (decltype(x))
-#else /* VS2008 or older (or VS2010 in C mode) */
-#define NO_DECLTYPE
-#define DECLTYPE(x)
-#endif
-#else /* GNU, Sun and other compilers */
-#define DECLTYPE(x) (__typeof(x))
-#endif
-
-#ifdef NO_DECLTYPE
-#define DECLTYPE_ASSIGN(dst,src) \
-do { \
- char **_da_dst = (char**)(&(dst)); \
- *_da_dst = (char*)(src); \
-} while(0)
-#else
-#define DECLTYPE_ASSIGN(dst,src) \
-do { \
- (dst) = DECLTYPE(dst)(src); \
-} while(0)
-#endif
-
-/* a number of the hash function use uint32_t which isn't defined on win32 */
-#ifdef _MSC_VER
-typedef unsigned int uint32_t;
-typedef unsigned char uint8_t;
-#else
-#include <inttypes.h> /* uint32_t */
-#endif
-
-#define UTHASH_VERSION 1.9.8
-
-#ifndef uthash_fatal
-#define uthash_fatal(msg) exit(-1) /* fatal error (out of memory,etc) */
-#endif
-#ifndef uthash_malloc
-#define uthash_malloc(sz) malloc(sz) /* malloc fcn */
-#endif
-#ifndef uthash_free
-#define uthash_free(ptr,sz) free(ptr) /* free fcn */
-#endif
-
-#ifndef uthash_noexpand_fyi
-#define uthash_noexpand_fyi(tbl) /* can be defined to log noexpand */
-#endif
-#ifndef uthash_expand_fyi
-#define uthash_expand_fyi(tbl) /* can be defined to log expands */
-#endif
-
-/* initial number of buckets */
-#define HASH_INITIAL_NUM_BUCKETS 32 /* initial number of buckets */
-#define HASH_INITIAL_NUM_BUCKETS_LOG2 5 /* lg2 of initial number of buckets */
-#define HASH_BKT_CAPACITY_THRESH 10 /* expand when bucket count reaches */
-
-/* calculate the element whose hash handle address is hhe */
-#define ELMT_FROM_HH(tbl,hhp) ((void*)(((char*)(hhp)) - ((tbl)->hho)))
-
-#define HASH_FIND(hh,head,keyptr,keylen,out) \
-do { \
- unsigned _hf_bkt,_hf_hashv; \
- out=NULL; \
- if (head) { \
- HASH_FCN(keyptr,keylen, (head)->hh.tbl->num_buckets, _hf_hashv, _hf_bkt); \
- if (HASH_BLOOM_TEST((head)->hh.tbl, _hf_hashv)) { \
- HASH_FIND_IN_BKT((head)->hh.tbl, hh, (head)->hh.tbl->buckets[ _hf_bkt ], \
- keyptr,keylen,out); \
- } \
- } \
-} while (0)
-
-#ifdef HASH_BLOOM
-#define HASH_BLOOM_BITLEN (1ULL << HASH_BLOOM)
-#define HASH_BLOOM_BYTELEN (HASH_BLOOM_BITLEN/8) + ((HASH_BLOOM_BITLEN%8) ? 1:0)
-#define HASH_BLOOM_MAKE(tbl) \
-do { \
- (tbl)->bloom_nbits = HASH_BLOOM; \
- (tbl)->bloom_bv = (uint8_t*)uthash_malloc(HASH_BLOOM_BYTELEN); \
- if (!((tbl)->bloom_bv)) { uthash_fatal( "out of memory"); } \
- memset((tbl)->bloom_bv, 0, HASH_BLOOM_BYTELEN); \
- (tbl)->bloom_sig = HASH_BLOOM_SIGNATURE; \
-} while (0)
-
-#define HASH_BLOOM_FREE(tbl) \
-do { \
- uthash_free((tbl)->bloom_bv, HASH_BLOOM_BYTELEN); \
-} while (0)
-
-#define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8] |= (1U << ((idx)%8)))
-#define HASH_BLOOM_BITTEST(bv,idx) (bv[(idx)/8] & (1U << ((idx)%8)))
-
-#define HASH_BLOOM_ADD(tbl,hashv) \
- HASH_BLOOM_BITSET((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1)))
-
-#define HASH_BLOOM_TEST(tbl,hashv) \
- HASH_BLOOM_BITTEST((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1)))
-
-#else
-#define HASH_BLOOM_MAKE(tbl)
-#define HASH_BLOOM_FREE(tbl)
-#define HASH_BLOOM_ADD(tbl,hashv)
-#define HASH_BLOOM_TEST(tbl,hashv) (1)
-#define HASH_BLOOM_BYTELEN 0
-#endif
-
-#define HASH_MAKE_TABLE(hh,head) \
-do { \
- (head)->hh.tbl = (UT_hash_table*)uthash_malloc( \
- sizeof(UT_hash_table)); \
- if (!((head)->hh.tbl)) { uthash_fatal( "out of memory"); } \
- memset((head)->hh.tbl, 0, sizeof(UT_hash_table)); \
- (head)->hh.tbl->tail = &((head)->hh); \
- (head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS; \
- (head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2; \
- (head)->hh.tbl->hho = (char*)(&(head)->hh) - (char*)(head); \
- (head)->hh.tbl->buckets = (UT_hash_bucket*)uthash_malloc( \
- HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \
- if (! (head)->hh.tbl->buckets) { uthash_fatal( "out of memory"); } \
- memset((head)->hh.tbl->buckets, 0, \
- HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \
- HASH_BLOOM_MAKE((head)->hh.tbl); \
- (head)->hh.tbl->signature = HASH_SIGNATURE; \
-} while(0)
-
-#define HASH_ADD(hh,head,fieldname,keylen_in,add) \
- HASH_ADD_KEYPTR(hh,head,&((add)->fieldname),keylen_in,add)
-
-#define HASH_REPLACE(hh,head,fieldname,keylen_in,add,replaced) \
-do { \
- replaced=NULL; \
- HASH_FIND(hh,head,&((add)->fieldname),keylen_in,replaced); \
- if (replaced!=NULL) { \
- HASH_DELETE(hh,head,replaced); \
- }; \
- HASH_ADD(hh,head,fieldname,keylen_in,add); \
-} while(0)
-
-#define HASH_ADD_KEYPTR(hh,head,keyptr,keylen_in,add) \
-do { \
- unsigned _ha_bkt; \
- (add)->hh.next = NULL; \
- (add)->hh.key = (char*)keyptr; \
- (add)->hh.keylen = (unsigned)keylen_in; \
- if (!(head)) { \
- head = (add); \
- (head)->hh.prev = NULL; \
- HASH_MAKE_TABLE(hh,head); \
- } else { \
- (head)->hh.tbl->tail->next = (add); \
- (add)->hh.prev = ELMT_FROM_HH((head)->hh.tbl, (head)->hh.tbl->tail); \
- (head)->hh.tbl->tail = &((add)->hh); \
- } \
- (head)->hh.tbl->num_items++; \
- (add)->hh.tbl = (head)->hh.tbl; \
- HASH_FCN(keyptr,keylen_in, (head)->hh.tbl->num_buckets, \
- (add)->hh.hashv, _ha_bkt); \
- HASH_ADD_TO_BKT((head)->hh.tbl->buckets[_ha_bkt],&(add)->hh); \
- HASH_BLOOM_ADD((head)->hh.tbl,(add)->hh.hashv); \
- HASH_EMIT_KEY(hh,head,keyptr,keylen_in); \
- HASH_FSCK(hh,head); \
-} while(0)
-
-#define HASH_TO_BKT( hashv, num_bkts, bkt ) \
-do { \
- bkt = ((hashv) & ((num_bkts) - 1)); \
-} while(0)
-
-/* delete "delptr" from the hash table.
- * "the usual" patch-up process for the app-order doubly-linked-list.
- * The use of _hd_hh_del below deserves special explanation.
- * These used to be expressed using (delptr) but that led to a bug
- * if someone used the same symbol for the head and deletee, like
- * HASH_DELETE(hh,users,users);
- * We want that to work, but by changing the head (users) below
- * we were forfeiting our ability to further refer to the deletee (users)
- * in the patch-up process. Solution: use scratch space to
- * copy the deletee pointer, then the latter references are via that
- * scratch pointer rather than through the repointed (users) symbol.
- */
-#define HASH_DELETE(hh,head,delptr) \
-do { \
- unsigned _hd_bkt; \
- struct UT_hash_handle *_hd_hh_del; \
- if ( ((delptr)->hh.prev == NULL) && ((delptr)->hh.next == NULL) ) { \
- uthash_free((head)->hh.tbl->buckets, \
- (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket) ); \
- HASH_BLOOM_FREE((head)->hh.tbl); \
- uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \
- head = NULL; \
- } else { \
- _hd_hh_del = &((delptr)->hh); \
- if ((delptr) == ELMT_FROM_HH((head)->hh.tbl,(head)->hh.tbl->tail)) { \
- (head)->hh.tbl->tail = \
- (UT_hash_handle*)((ptrdiff_t)((delptr)->hh.prev) + \
- (head)->hh.tbl->hho); \
- } \
- if ((delptr)->hh.prev) { \
- ((UT_hash_handle*)((ptrdiff_t)((delptr)->hh.prev) + \
- (head)->hh.tbl->hho))->next = (delptr)->hh.next; \
- } else { \
- DECLTYPE_ASSIGN(head,(delptr)->hh.next); \
- } \
- if (_hd_hh_del->next) { \
- ((UT_hash_handle*)((ptrdiff_t)_hd_hh_del->next + \
- (head)->hh.tbl->hho))->prev = \
- _hd_hh_del->prev; \
- } \
- HASH_TO_BKT( _hd_hh_del->hashv, (head)->hh.tbl->num_buckets, _hd_bkt); \
- HASH_DEL_IN_BKT(hh,(head)->hh.tbl->buckets[_hd_bkt], _hd_hh_del); \
- (head)->hh.tbl->num_items--; \
- } \
- HASH_FSCK(hh,head); \
-} while (0)
-
-
-/* convenience forms of HASH_FIND/HASH_ADD/HASH_DEL */
-#define HASH_FIND_STR(head,findstr,out) \
- HASH_FIND(hh,head,findstr,strlen(findstr),out)
-#define HASH_ADD_STR(head,strfield,add) \
- HASH_ADD(hh,head,strfield,strlen(add->strfield),add)
-#define HASH_REPLACE_STR(head,strfield,add,replaced) \
- HASH_REPLACE(hh,head,strfield,strlen(add->strfield),add,replaced)
-#define HASH_FIND_INT(head,findint,out) \
- HASH_FIND(hh,head,findint,sizeof(int),out)
-#define HASH_ADD_INT(head,intfield,add) \
- HASH_ADD(hh,head,intfield,sizeof(int),add)
-#define HASH_REPLACE_INT(head,intfield,add,replaced) \
- HASH_REPLACE(hh,head,intfield,sizeof(int),add,replaced)
-#define HASH_FIND_PTR(head,findptr,out) \
- HASH_FIND(hh,head,findptr,sizeof(void *),out)
-#define HASH_ADD_PTR(head,ptrfield,add) \
- HASH_ADD(hh,head,ptrfield,sizeof(void *),add)
-#define HASH_REPLACE_PTR(head,ptrfield,add) \
- HASH_REPLACE(hh,head,ptrfield,sizeof(void *),add,replaced)
-#define HASH_DEL(head,delptr) \
- HASH_DELETE(hh,head,delptr)
-
-/* HASH_FSCK checks hash integrity on every add/delete when HASH_DEBUG is defined.
- * This is for uthash developer only; it compiles away if HASH_DEBUG isn't defined.
- */
-#ifdef HASH_DEBUG
-#define HASH_OOPS(...) do { fprintf(stderr,__VA_ARGS__); exit(-1); } while (0)
-#define HASH_FSCK(hh,head) \
-do { \
- unsigned _bkt_i; \
- unsigned _count, _bkt_count; \
- char *_prev; \
- struct UT_hash_handle *_thh; \
- if (head) { \
- _count = 0; \
- for( _bkt_i = 0; _bkt_i < (head)->hh.tbl->num_buckets; _bkt_i++) { \
- _bkt_count = 0; \
- _thh = (head)->hh.tbl->buckets[_bkt_i].hh_head; \
- _prev = NULL; \
- while (_thh) { \
- if (_prev != (char*)(_thh->hh_prev)) { \
- HASH_OOPS("invalid hh_prev %p, actual %p\n", \
- _thh->hh_prev, _prev ); \
- } \
- _bkt_count++; \
- _prev = (char*)(_thh); \
- _thh = _thh->hh_next; \
- } \
- _count += _bkt_count; \
- if ((head)->hh.tbl->buckets[_bkt_i].count != _bkt_count) { \
- HASH_OOPS("invalid bucket count %d, actual %d\n", \
- (head)->hh.tbl->buckets[_bkt_i].count, _bkt_count); \
- } \
- } \
- if (_count != (head)->hh.tbl->num_items) { \
- HASH_OOPS("invalid hh item count %d, actual %d\n", \
- (head)->hh.tbl->num_items, _count ); \
- } \
- /* traverse hh in app order; check next/prev integrity, count */ \
- _count = 0; \
- _prev = NULL; \
- _thh = &(head)->hh; \
- while (_thh) { \
- _count++; \
- if (_prev !=(char*)(_thh->prev)) { \
- HASH_OOPS("invalid prev %p, actual %p\n", \
- _thh->prev, _prev ); \
- } \
- _prev = (char*)ELMT_FROM_HH((head)->hh.tbl, _thh); \
- _thh = ( _thh->next ? (UT_hash_handle*)((char*)(_thh->next) + \
- (head)->hh.tbl->hho) : NULL ); \
- } \
- if (_count != (head)->hh.tbl->num_items) { \
- HASH_OOPS("invalid app item count %d, actual %d\n", \
- (head)->hh.tbl->num_items, _count ); \
- } \
- } \
-} while (0)
-#else
-#define HASH_FSCK(hh,head)
-#endif
-
-/* When compiled with -DHASH_EMIT_KEYS, length-prefixed keys are emitted to
- * the descriptor to which this macro is defined for tuning the hash function.
- * The app can #include <unistd.h> to get the prototype for write(2). */
-#ifdef HASH_EMIT_KEYS
-#define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) \
-do { \
- unsigned _klen = fieldlen; \
- write(HASH_EMIT_KEYS, &_klen, sizeof(_klen)); \
- write(HASH_EMIT_KEYS, keyptr, fieldlen); \
-} while (0)
-#else
-#define HASH_EMIT_KEY(hh,head,keyptr,fieldlen)
-#endif
-
-/* default to Jenkin's hash unless overridden e.g. DHASH_FUNCTION=HASH_SAX */
-#ifdef HASH_FUNCTION
-#define HASH_FCN HASH_FUNCTION
-#else
-#define HASH_FCN HASH_JEN
-#endif
-
-/* The Bernstein hash function, used in Perl prior to v5.6 */
-#define HASH_BER(key,keylen,num_bkts,hashv,bkt) \
-do { \
- unsigned _hb_keylen=keylen; \
- char *_hb_key=(char*)(key); \
- (hashv) = 0; \
- while (_hb_keylen--) { (hashv) = ((hashv) * 33) + *_hb_key++; } \
- bkt = (hashv) & (num_bkts-1); \
-} while (0)
-
-
-/* SAX/FNV/OAT/JEN hash functions are macro variants of those listed at
- * http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx */
-#define HASH_SAX(key,keylen,num_bkts,hashv,bkt) \
-do { \
- unsigned _sx_i; \
- char *_hs_key=(char*)(key); \
- hashv = 0; \
- for(_sx_i=0; _sx_i < keylen; _sx_i++) \
- hashv ^= (hashv << 5) + (hashv >> 2) + _hs_key[_sx_i]; \
- bkt = hashv & (num_bkts-1); \
-} while (0)
-
-#define HASH_FNV(key,keylen,num_bkts,hashv,bkt) \
-do { \
- unsigned _fn_i; \
- char *_hf_key=(char*)(key); \
- hashv = 2166136261UL; \
- for(_fn_i=0; _fn_i < keylen; _fn_i++) \
- hashv = (hashv * 16777619) ^ _hf_key[_fn_i]; \
- bkt = hashv & (num_bkts-1); \
-} while(0)
-
-#define HASH_OAT(key,keylen,num_bkts,hashv,bkt) \
-do { \
- unsigned _ho_i; \
- char *_ho_key=(char*)(key); \
- hashv = 0; \
- for(_ho_i=0; _ho_i < keylen; _ho_i++) { \
- hashv += _ho_key[_ho_i]; \
- hashv += (hashv << 10); \
- hashv ^= (hashv >> 6); \
- } \
- hashv += (hashv << 3); \
- hashv ^= (hashv >> 11); \
- hashv += (hashv << 15); \
- bkt = hashv & (num_bkts-1); \
-} while(0)
-
-#define HASH_JEN_MIX(a,b,c) \
-do { \
- a -= b; a -= c; a ^= ( c >> 13 ); \
- b -= c; b -= a; b ^= ( a << 8 ); \
- c -= a; c -= b; c ^= ( b >> 13 ); \
- a -= b; a -= c; a ^= ( c >> 12 ); \
- b -= c; b -= a; b ^= ( a << 16 ); \
- c -= a; c -= b; c ^= ( b >> 5 ); \
- a -= b; a -= c; a ^= ( c >> 3 ); \
- b -= c; b -= a; b ^= ( a << 10 ); \
- c -= a; c -= b; c ^= ( b >> 15 ); \
-} while (0)
-
-#define HASH_JEN(key,keylen,num_bkts,hashv,bkt) \
-do { \
- unsigned _hj_i,_hj_j,_hj_k; \
- unsigned char *_hj_key=(unsigned char*)(key); \
- hashv = 0xfeedbeef; \
- _hj_i = _hj_j = 0x9e3779b9; \
- _hj_k = (unsigned)keylen; \
- while (_hj_k >= 12) { \
- _hj_i += (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 ) \
- + ( (unsigned)_hj_key[2] << 16 ) \
- + ( (unsigned)_hj_key[3] << 24 ) ); \
- _hj_j += (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 ) \
- + ( (unsigned)_hj_key[6] << 16 ) \
- + ( (unsigned)_hj_key[7] << 24 ) ); \
- hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 ) \
- + ( (unsigned)_hj_key[10] << 16 ) \
- + ( (unsigned)_hj_key[11] << 24 ) ); \
- \
- HASH_JEN_MIX(_hj_i, _hj_j, hashv); \
- \
- _hj_key += 12; \
- _hj_k -= 12; \
- } \
- hashv += keylen; \
- switch ( _hj_k ) { \
- case 11: hashv += ( (unsigned)_hj_key[10] << 24 ); \
- case 10: hashv += ( (unsigned)_hj_key[9] << 16 ); \
- case 9: hashv += ( (unsigned)_hj_key[8] << 8 ); \
- case 8: _hj_j += ( (unsigned)_hj_key[7] << 24 ); \
- case 7: _hj_j += ( (unsigned)_hj_key[6] << 16 ); \
- case 6: _hj_j += ( (unsigned)_hj_key[5] << 8 ); \
- case 5: _hj_j += _hj_key[4]; \
- case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); \
- case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); \
- case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); \
- case 1: _hj_i += _hj_key[0]; \
- } \
- HASH_JEN_MIX(_hj_i, _hj_j, hashv); \
- bkt = hashv & (num_bkts-1); \
-} while(0)
-
-/* The Paul Hsieh hash function */
-#undef get16bits
-#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
- || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
-#define get16bits(d) (*((const uint16_t *) (d)))
-#endif
-
-#if !defined (get16bits)
-#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8) \
- +(uint32_t)(((const uint8_t *)(d))[0]) )
-#endif
-#define HASH_SFH(key,keylen,num_bkts,hashv,bkt) \
-do { \
- unsigned char *_sfh_key=(unsigned char*)(key); \
- uint32_t _sfh_tmp, _sfh_len = keylen; \
- \
- int _sfh_rem = _sfh_len & 3; \
- _sfh_len >>= 2; \
- hashv = 0xcafebabe; \
- \
- /* Main loop */ \
- for (;_sfh_len > 0; _sfh_len--) { \
- hashv += get16bits (_sfh_key); \
- _sfh_tmp = (uint32_t)(get16bits (_sfh_key+2)) << 11 ^ hashv; \
- hashv = (hashv << 16) ^ _sfh_tmp; \
- _sfh_key += 2*sizeof (uint16_t); \
- hashv += hashv >> 11; \
- } \
- \
- /* Handle end cases */ \
- switch (_sfh_rem) { \
- case 3: hashv += get16bits (_sfh_key); \
- hashv ^= hashv << 16; \
- hashv ^= (uint32_t)(_sfh_key[sizeof (uint16_t)] << 18); \
- hashv += hashv >> 11; \
- break; \
- case 2: hashv += get16bits (_sfh_key); \
- hashv ^= hashv << 11; \
- hashv += hashv >> 17; \
- break; \
- case 1: hashv += *_sfh_key; \
- hashv ^= hashv << 10; \
- hashv += hashv >> 1; \
- } \
- \
- /* Force "avalanching" of final 127 bits */ \
- hashv ^= hashv << 3; \
- hashv += hashv >> 5; \
- hashv ^= hashv << 4; \
- hashv += hashv >> 17; \
- hashv ^= hashv << 25; \
- hashv += hashv >> 6; \
- bkt = hashv & (num_bkts-1); \
-} while(0)
-
-#ifdef HASH_USING_NO_STRICT_ALIASING
-/* The MurmurHash exploits some CPU's (x86,x86_64) tolerance for unaligned reads.
- * For other types of CPU's (e.g. Sparc) an unaligned read causes a bus error.
- * MurmurHash uses the faster approach only on CPU's where we know it's safe.
- *
- * Note the preprocessor built-in defines can be emitted using:
- *
- * gcc -m64 -dM -E - < /dev/null (on gcc)
- * cc -## a.c (where a.c is a simple test file) (Sun Studio)
- */
-#if (defined(__i386__) || defined(__x86_64__) || defined(_M_IX86))
-#define MUR_GETBLOCK(p,i) p[i]
-#else /* non intel */
-#define MUR_PLUS0_ALIGNED(p) (((unsigned long)p & 0x3) == 0)
-#define MUR_PLUS1_ALIGNED(p) (((unsigned long)p & 0x3) == 1)
-#define MUR_PLUS2_ALIGNED(p) (((unsigned long)p & 0x3) == 2)
-#define MUR_PLUS3_ALIGNED(p) (((unsigned long)p & 0x3) == 3)
-#define WP(p) ((uint32_t*)((unsigned long)(p) & ~3UL))
-#if (defined(__BIG_ENDIAN__) || defined(SPARC) || defined(__ppc__) || defined(__ppc64__))
-#define MUR_THREE_ONE(p) ((((*WP(p))&0x00ffffff) << 8) | (((*(WP(p)+1))&0xff000000) >> 24))
-#define MUR_TWO_TWO(p) ((((*WP(p))&0x0000ffff) <<16) | (((*(WP(p)+1))&0xffff0000) >> 16))
-#define MUR_ONE_THREE(p) ((((*WP(p))&0x000000ff) <<24) | (((*(WP(p)+1))&0xffffff00) >> 8))
-#else /* assume little endian non-intel */
-#define MUR_THREE_ONE(p) ((((*WP(p))&0xffffff00) >> 8) | (((*(WP(p)+1))&0x000000ff) << 24))
-#define MUR_TWO_TWO(p) ((((*WP(p))&0xffff0000) >>16) | (((*(WP(p)+1))&0x0000ffff) << 16))
-#define MUR_ONE_THREE(p) ((((*WP(p))&0xff000000) >>24) | (((*(WP(p)+1))&0x00ffffff) << 8))
-#endif
-#define MUR_GETBLOCK(p,i) (MUR_PLUS0_ALIGNED(p) ? ((p)[i]) : \
- (MUR_PLUS1_ALIGNED(p) ? MUR_THREE_ONE(p) : \
- (MUR_PLUS2_ALIGNED(p) ? MUR_TWO_TWO(p) : \
- MUR_ONE_THREE(p))))
-#endif
-#define MUR_ROTL32(x,r) (((x) << (r)) | ((x) >> (32 - (r))))
-#define MUR_FMIX(_h) \
-do { \
- _h ^= _h >> 16; \
- _h *= 0x85ebca6b; \
- _h ^= _h >> 13; \
- _h *= 0xc2b2ae35l; \
- _h ^= _h >> 16; \
-} while(0)
-
-#define HASH_MUR(key,keylen,num_bkts,hashv,bkt) \
-do { \
- const uint8_t *_mur_data = (const uint8_t*)(key); \
- const int _mur_nblocks = (keylen) / 4; \
- uint32_t _mur_h1 = 0xf88D5353; \
- uint32_t _mur_c1 = 0xcc9e2d51; \
- uint32_t _mur_c2 = 0x1b873593; \
- uint32_t _mur_k1 = 0; \
- const uint8_t *_mur_tail; \
- const uint32_t *_mur_blocks = (const uint32_t*)(_mur_data+_mur_nblocks*4); \
- int _mur_i; \
- for(_mur_i = -_mur_nblocks; _mur_i; _mur_i++) { \
- _mur_k1 = MUR_GETBLOCK(_mur_blocks,_mur_i); \
- _mur_k1 *= _mur_c1; \
- _mur_k1 = MUR_ROTL32(_mur_k1,15); \
- _mur_k1 *= _mur_c2; \
- \
- _mur_h1 ^= _mur_k1; \
- _mur_h1 = MUR_ROTL32(_mur_h1,13); \
- _mur_h1 = _mur_h1*5+0xe6546b64; \
- } \
- _mur_tail = (const uint8_t*)(_mur_data + _mur_nblocks*4); \
- _mur_k1=0; \
- switch((keylen) & 3) { \
- case 3: _mur_k1 ^= _mur_tail[2] << 16; \
- case 2: _mur_k1 ^= _mur_tail[1] << 8; \
- case 1: _mur_k1 ^= _mur_tail[0]; \
- _mur_k1 *= _mur_c1; \
- _mur_k1 = MUR_ROTL32(_mur_k1,15); \
- _mur_k1 *= _mur_c2; \
- _mur_h1 ^= _mur_k1; \
- } \
- _mur_h1 ^= (keylen); \
- MUR_FMIX(_mur_h1); \
- hashv = _mur_h1; \
- bkt = hashv & (num_bkts-1); \
-} while(0)
-#endif /* HASH_USING_NO_STRICT_ALIASING */
-
-/* key comparison function; return 0 if keys equal */
-#define HASH_KEYCMP(a,b,len) memcmp(a,b,len)
-
-/* iterate over items in a known bucket to find desired item */
-#define HASH_FIND_IN_BKT(tbl,hh,head,keyptr,keylen_in,out) \
-do { \
- if (head.hh_head) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,head.hh_head)); \
- else out=NULL; \
- while (out) { \
- if ((out)->hh.keylen == keylen_in) { \
- if ((HASH_KEYCMP((out)->hh.key,keyptr,keylen_in)) == 0) break; \
- } \
- if ((out)->hh.hh_next) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,(out)->hh.hh_next)); \
- else out = NULL; \
- } \
-} while(0)
-
-/* add an item to a bucket */
-#define HASH_ADD_TO_BKT(head,addhh) \
-do { \
- head.count++; \
- (addhh)->hh_next = head.hh_head; \
- (addhh)->hh_prev = NULL; \
- if (head.hh_head) { (head).hh_head->hh_prev = (addhh); } \
- (head).hh_head=addhh; \
- if (head.count >= ((head.expand_mult+1) * HASH_BKT_CAPACITY_THRESH) \
- && (addhh)->tbl->noexpand != 1) { \
- HASH_EXPAND_BUCKETS((addhh)->tbl); \
- } \
-} while(0)
-
-/* remove an item from a given bucket */
-#define HASH_DEL_IN_BKT(hh,head,hh_del) \
- (head).count--; \
- if ((head).hh_head == hh_del) { \
- (head).hh_head = hh_del->hh_next; \
- } \
- if (hh_del->hh_prev) { \
- hh_del->hh_prev->hh_next = hh_del->hh_next; \
- } \
- if (hh_del->hh_next) { \
- hh_del->hh_next->hh_prev = hh_del->hh_prev; \
- }
-
-/* Bucket expansion has the effect of doubling the number of buckets
- * and redistributing the items into the new buckets. Ideally the
- * items will distribute more or less evenly into the new buckets
- * (the extent to which this is true is a measure of the quality of
- * the hash function as it applies to the key domain).
- *
- * With the items distributed into more buckets, the chain length
- * (item count) in each bucket is reduced. Thus by expanding buckets
- * the hash keeps a bound on the chain length. This bounded chain
- * length is the essence of how a hash provides constant time lookup.
- *
- * The calculation of tbl->ideal_chain_maxlen below deserves some
- * explanation. First, keep in mind that we're calculating the ideal
- * maximum chain length based on the *new* (doubled) bucket count.
- * In fractions this is just n/b (n=number of items,b=new num buckets).
- * Since the ideal chain length is an integer, we want to calculate
- * ceil(n/b). We don't depend on floating point arithmetic in this
- * hash, so to calculate ceil(n/b) with integers we could write
- *
- * ceil(n/b) = (n/b) + ((n%b)?1:0)
- *
- * and in fact a previous version of this hash did just that.
- * But now we have improved things a bit by recognizing that b is
- * always a power of two. We keep its base 2 log handy (call it lb),
- * so now we can write this with a bit shift and logical AND:
- *
- * ceil(n/b) = (n>>lb) + ( (n & (b-1)) ? 1:0)
- *
- */
-#define HASH_EXPAND_BUCKETS(tbl) \
-do { \
- unsigned _he_bkt; \
- unsigned _he_bkt_i; \
- struct UT_hash_handle *_he_thh, *_he_hh_nxt; \
- UT_hash_bucket *_he_new_buckets, *_he_newbkt; \
- _he_new_buckets = (UT_hash_bucket*)uthash_malloc( \
- 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \
- if (!_he_new_buckets) { uthash_fatal( "out of memory"); } \
- memset(_he_new_buckets, 0, \
- 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \
- tbl->ideal_chain_maxlen = \
- (tbl->num_items >> (tbl->log2_num_buckets+1)) + \
- ((tbl->num_items & ((tbl->num_buckets*2)-1)) ? 1 : 0); \
- tbl->nonideal_items = 0; \
- for(_he_bkt_i = 0; _he_bkt_i < tbl->num_buckets; _he_bkt_i++) \
- { \
- _he_thh = tbl->buckets[ _he_bkt_i ].hh_head; \
- while (_he_thh) { \
- _he_hh_nxt = _he_thh->hh_next; \
- HASH_TO_BKT( _he_thh->hashv, tbl->num_buckets*2, _he_bkt); \
- _he_newbkt = &(_he_new_buckets[ _he_bkt ]); \
- if (++(_he_newbkt->count) > tbl->ideal_chain_maxlen) { \
- tbl->nonideal_items++; \
- _he_newbkt->expand_mult = _he_newbkt->count / \
- tbl->ideal_chain_maxlen; \
- } \
- _he_thh->hh_prev = NULL; \
- _he_thh->hh_next = _he_newbkt->hh_head; \
- if (_he_newbkt->hh_head) _he_newbkt->hh_head->hh_prev = \
- _he_thh; \
- _he_newbkt->hh_head = _he_thh; \
- _he_thh = _he_hh_nxt; \
- } \
- } \
- uthash_free( tbl->buckets, tbl->num_buckets*sizeof(struct UT_hash_bucket) ); \
- tbl->num_buckets *= 2; \
- tbl->log2_num_buckets++; \
- tbl->buckets = _he_new_buckets; \
- tbl->ineff_expands = (tbl->nonideal_items > (tbl->num_items >> 1)) ? \
- (tbl->ineff_expands+1) : 0; \
- if (tbl->ineff_expands > 1) { \
- tbl->noexpand=1; \
- uthash_noexpand_fyi(tbl); \
- } \
- uthash_expand_fyi(tbl); \
-} while(0)
-
-
-/* This is an adaptation of Simon Tatham's O(n log(n)) mergesort */
-/* Note that HASH_SORT assumes the hash handle name to be hh.
- * HASH_SRT was added to allow the hash handle name to be passed in. */
-#define HASH_SORT(head,cmpfcn) HASH_SRT(hh,head,cmpfcn)
-#define HASH_SRT(hh,head,cmpfcn) \
-do { \
- unsigned _hs_i; \
- unsigned _hs_looping,_hs_nmerges,_hs_insize,_hs_psize,_hs_qsize; \
- struct UT_hash_handle *_hs_p, *_hs_q, *_hs_e, *_hs_list, *_hs_tail; \
- if (head) { \
- _hs_insize = 1; \
- _hs_looping = 1; \
- _hs_list = &((head)->hh); \
- while (_hs_looping) { \
- _hs_p = _hs_list; \
- _hs_list = NULL; \
- _hs_tail = NULL; \
- _hs_nmerges = 0; \
- while (_hs_p) { \
- _hs_nmerges++; \
- _hs_q = _hs_p; \
- _hs_psize = 0; \
- for ( _hs_i = 0; _hs_i < _hs_insize; _hs_i++ ) { \
- _hs_psize++; \
- _hs_q = (UT_hash_handle*)((_hs_q->next) ? \
- ((void*)((char*)(_hs_q->next) + \
- (head)->hh.tbl->hho)) : NULL); \
- if (! (_hs_q) ) break; \
- } \
- _hs_qsize = _hs_insize; \
- while ((_hs_psize > 0) || ((_hs_qsize > 0) && _hs_q )) { \
- if (_hs_psize == 0) { \
- _hs_e = _hs_q; \
- _hs_q = (UT_hash_handle*)((_hs_q->next) ? \
- ((void*)((char*)(_hs_q->next) + \
- (head)->hh.tbl->hho)) : NULL); \
- _hs_qsize--; \
- } else if ( (_hs_qsize == 0) || !(_hs_q) ) { \
- _hs_e = _hs_p; \
- if (_hs_p){ \
- _hs_p = (UT_hash_handle*)((_hs_p->next) ? \
- ((void*)((char*)(_hs_p->next) + \
- (head)->hh.tbl->hho)) : NULL); \
- } \
- _hs_psize--; \
- } else if (( \
- cmpfcn(DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_p)), \
- DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_q))) \
- ) <= 0) { \
- _hs_e = _hs_p; \
- if (_hs_p){ \
- _hs_p = (UT_hash_handle*)((_hs_p->next) ? \
- ((void*)((char*)(_hs_p->next) + \
- (head)->hh.tbl->hho)) : NULL); \
- } \
- _hs_psize--; \
- } else { \
- _hs_e = _hs_q; \
- _hs_q = (UT_hash_handle*)((_hs_q->next) ? \
- ((void*)((char*)(_hs_q->next) + \
- (head)->hh.tbl->hho)) : NULL); \
- _hs_qsize--; \
- } \
- if ( _hs_tail ) { \
- _hs_tail->next = ((_hs_e) ? \
- ELMT_FROM_HH((head)->hh.tbl,_hs_e) : NULL); \
- } else { \
- _hs_list = _hs_e; \
- } \
- if (_hs_e) { \
- _hs_e->prev = ((_hs_tail) ? \
- ELMT_FROM_HH((head)->hh.tbl,_hs_tail) : NULL); \
- } \
- _hs_tail = _hs_e; \
- } \
- _hs_p = _hs_q; \
- } \
- if (_hs_tail){ \
- _hs_tail->next = NULL; \
- } \
- if ( _hs_nmerges <= 1 ) { \
- _hs_looping=0; \
- (head)->hh.tbl->tail = _hs_tail; \
- DECLTYPE_ASSIGN(head,ELMT_FROM_HH((head)->hh.tbl, _hs_list)); \
- } \
- _hs_insize *= 2; \
- } \
- HASH_FSCK(hh,head); \
- } \
-} while (0)
-
-/* This function selects items from one hash into another hash.
- * The end result is that the selected items have dual presence
- * in both hashes. There is no copy of the items made; rather
- * they are added into the new hash through a secondary hash
- * hash handle that must be present in the structure. */
-#define HASH_SELECT(hh_dst, dst, hh_src, src, cond) \
-do { \
- unsigned _src_bkt, _dst_bkt; \
- void *_last_elt=NULL, *_elt; \
- UT_hash_handle *_src_hh, *_dst_hh, *_last_elt_hh=NULL; \
- ptrdiff_t _dst_hho = ((char*)(&(dst)->hh_dst) - (char*)(dst)); \
- if (src) { \
- for(_src_bkt=0; _src_bkt < (src)->hh_src.tbl->num_buckets; _src_bkt++) { \
- for(_src_hh = (src)->hh_src.tbl->buckets[_src_bkt].hh_head; \
- _src_hh; \
- _src_hh = _src_hh->hh_next) { \
- _elt = ELMT_FROM_HH((src)->hh_src.tbl, _src_hh); \
- if (cond(_elt)) { \
- _dst_hh = (UT_hash_handle*)(((char*)_elt) + _dst_hho); \
- _dst_hh->key = _src_hh->key; \
- _dst_hh->keylen = _src_hh->keylen; \
- _dst_hh->hashv = _src_hh->hashv; \
- _dst_hh->prev = _last_elt; \
- _dst_hh->next = NULL; \
- if (_last_elt_hh) { _last_elt_hh->next = _elt; } \
- if (!dst) { \
- DECLTYPE_ASSIGN(dst,_elt); \
- HASH_MAKE_TABLE(hh_dst,dst); \
- } else { \
- _dst_hh->tbl = (dst)->hh_dst.tbl; \
- } \
- HASH_TO_BKT(_dst_hh->hashv, _dst_hh->tbl->num_buckets, _dst_bkt); \
- HASH_ADD_TO_BKT(_dst_hh->tbl->buckets[_dst_bkt],_dst_hh); \
- (dst)->hh_dst.tbl->num_items++; \
- _last_elt = _elt; \
- _last_elt_hh = _dst_hh; \
- } \
- } \
- } \
- } \
- HASH_FSCK(hh_dst,dst); \
-} while (0)
-
-#define HASH_CLEAR(hh,head) \
-do { \
- if (head) { \
- uthash_free((head)->hh.tbl->buckets, \
- (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket)); \
- HASH_BLOOM_FREE((head)->hh.tbl); \
- uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \
- (head)=NULL; \
- } \
-} while(0)
-
-#define HASH_OVERHEAD(hh,head) \
- (size_t)((((head)->hh.tbl->num_items * sizeof(UT_hash_handle)) + \
- ((head)->hh.tbl->num_buckets * sizeof(UT_hash_bucket)) + \
- (sizeof(UT_hash_table)) + \
- (HASH_BLOOM_BYTELEN)))
-
-#ifdef NO_DECLTYPE
-#define HASH_ITER(hh,head,el,tmp) \
-for((el)=(head), (*(char**)(&(tmp)))=(char*)((head)?(head)->hh.next:NULL); \
- el; (el)=(tmp),(*(char**)(&(tmp)))=(char*)((tmp)?(tmp)->hh.next:NULL))
-#else
-#define HASH_ITER(hh,head,el,tmp) \
-for((el)=(head),(tmp)=DECLTYPE(el)((head)?(head)->hh.next:NULL); \
- el; (el)=(tmp),(tmp)=DECLTYPE(el)((tmp)?(tmp)->hh.next:NULL))
-#endif
-
-/* obtain a count of items in the hash */
-#define HASH_COUNT(head) HASH_CNT(hh,head)
-#define HASH_CNT(hh,head) ((head)?((head)->hh.tbl->num_items):0)
-
-typedef struct UT_hash_bucket {
- struct UT_hash_handle *hh_head;
- unsigned count;
-
- /* expand_mult is normally set to 0. In this situation, the max chain length
- * threshold is enforced at its default value, HASH_BKT_CAPACITY_THRESH. (If
- * the bucket's chain exceeds this length, bucket expansion is triggered).
- * However, setting expand_mult to a non-zero value delays bucket expansion
- * (that would be triggered by additions to this particular bucket)
- * until its chain length reaches a *multiple* of HASH_BKT_CAPACITY_THRESH.
- * (The multiplier is simply expand_mult+1). The whole idea of this
- * multiplier is to reduce bucket expansions, since they are expensive, in
- * situations where we know that a particular bucket tends to be overused.
- * It is better to let its chain length grow to a longer yet-still-bounded
- * value, than to do an O(n) bucket expansion too often.
- */
- unsigned expand_mult;
-
-} UT_hash_bucket;
-
-/* random signature used only to find hash tables in external analysis */
-#define HASH_SIGNATURE 0xa0111fe1
-#define HASH_BLOOM_SIGNATURE 0xb12220f2
-
-typedef struct UT_hash_table {
- UT_hash_bucket *buckets;
- unsigned num_buckets, log2_num_buckets;
- unsigned num_items;
- struct UT_hash_handle *tail; /* tail hh in app order, for fast append */
- ptrdiff_t hho; /* hash handle offset (byte pos of hash handle in element */
-
- /* in an ideal situation (all buckets used equally), no bucket would have
- * more than ceil(#items/#buckets) items. that's the ideal chain length. */
- unsigned ideal_chain_maxlen;
-
- /* nonideal_items is the number of items in the hash whose chain position
- * exceeds the ideal chain maxlen. these items pay the penalty for an uneven
- * hash distribution; reaching them in a chain traversal takes >ideal steps */
- unsigned nonideal_items;
-
- /* ineffective expands occur when a bucket doubling was performed, but
- * afterward, more than half the items in the hash had nonideal chain
- * positions. If this happens on two consecutive expansions we inhibit any
- * further expansion, as it's not helping; this happens when the hash
- * function isn't a good fit for the key domain. When expansion is inhibited
- * the hash will still work, albeit no longer in constant time. */
- unsigned ineff_expands, noexpand;
-
- uint32_t signature; /* used only to find hash tables in external analysis */
-#ifdef HASH_BLOOM
- uint32_t bloom_sig; /* used only to test bloom exists in external analysis */
- uint8_t *bloom_bv;
- char bloom_nbits;
-#endif
-
-} UT_hash_table;
-
-typedef struct UT_hash_handle {
- struct UT_hash_table *tbl;
- void *prev; /* prev element in app order */
- void *next; /* next element in app order */
- struct UT_hash_handle *hh_prev; /* previous hh in bucket order */
- struct UT_hash_handle *hh_next; /* next hh in bucket order */
- void *key; /* ptr to enclosing struct's key */
- unsigned keylen; /* enclosing struct's key len */
- unsigned hashv; /* result of hash-fcn(key) */
-} UT_hash_handle;
-
-#endif /* UTHASH_H */
diff --git a/libs/libmosquitto/include/utlist.h b/libs/libmosquitto/include/utlist.h
deleted file mode 100644
index 5bb1ac9b72..0000000000
--- a/libs/libmosquitto/include/utlist.h
+++ /dev/null
@@ -1,1073 +0,0 @@
-/*
-Copyright (c) 2007-2018, Troy D. Hanson http://troydhanson.github.com/uthash/
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
-OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef UTLIST_H
-#define UTLIST_H
-
-#define UTLIST_VERSION 2.1.0
-
-#include <assert.h>
-
-/*
- * This file contains macros to manipulate singly and doubly-linked lists.
- *
- * 1. LL_ macros: singly-linked lists.
- * 2. DL_ macros: doubly-linked lists.
- * 3. CDL_ macros: circular doubly-linked lists.
- *
- * To use singly-linked lists, your structure must have a "next" pointer.
- * To use doubly-linked lists, your structure must "prev" and "next" pointers.
- * Either way, the pointer to the head of the list must be initialized to NULL.
- *
- * ----------------.EXAMPLE -------------------------
- * struct item {
- * int id;
- * struct item *prev, *next;
- * }
- *
- * struct item *list = NULL:
- *
- * int main() {
- * struct item *item;
- * ... allocate and populate item ...
- * DL_APPEND(list, item);
- * }
- * --------------------------------------------------
- *
- * For doubly-linked lists, the append and delete macros are O(1)
- * For singly-linked lists, append and delete are O(n) but prepend is O(1)
- * The sort macro is O(n log(n)) for all types of single/double/circular lists.
- */
-
-/* These macros use decltype or the earlier __typeof GNU extension.
- As decltype is only available in newer compilers (VS2010 or gcc 4.3+
- when compiling c++ source) this code uses whatever method is needed
- or, for VS2008 where neither is available, uses casting workarounds. */
-#if !defined(LDECLTYPE) && !defined(NO_DECLTYPE)
-#if defined(_MSC_VER) /* MS compiler */
-#if _MSC_VER >= 1600 && defined(__cplusplus) /* VS2010 or newer in C++ mode */
-#define LDECLTYPE(x) decltype(x)
-#else /* VS2008 or older (or VS2010 in C mode) */
-#define NO_DECLTYPE
-#endif
-#elif defined(__BORLANDC__) || defined(__ICCARM__) || defined(__LCC__) || defined(__WATCOMC__)
-#define NO_DECLTYPE
-#else /* GNU, Sun and other compilers */
-#define LDECLTYPE(x) __typeof(x)
-#endif
-#endif
-
-/* for VS2008 we use some workarounds to get around the lack of decltype,
- * namely, we always reassign our tmp variable to the list head if we need
- * to dereference its prev/next pointers, and save/restore the real head.*/
-#ifdef NO_DECLTYPE
-#define IF_NO_DECLTYPE(x) x
-#define LDECLTYPE(x) char*
-#define UTLIST_SV(elt,list) _tmp = (char*)(list); {char **_alias = (char**)&(list); *_alias = (elt); }
-#define UTLIST_NEXT(elt,list,next) ((char*)((list)->next))
-#define UTLIST_NEXTASGN(elt,list,to,next) { char **_alias = (char**)&((list)->next); *_alias=(char*)(to); }
-/* #define UTLIST_PREV(elt,list,prev) ((char*)((list)->prev)) */
-#define UTLIST_PREVASGN(elt,list,to,prev) { char **_alias = (char**)&((list)->prev); *_alias=(char*)(to); }
-#define UTLIST_RS(list) { char **_alias = (char**)&(list); *_alias=_tmp; }
-#define UTLIST_CASTASGN(a,b) { char **_alias = (char**)&(a); *_alias=(char*)(b); }
-#else
-#define IF_NO_DECLTYPE(x)
-#define UTLIST_SV(elt,list)
-#define UTLIST_NEXT(elt,list,next) ((elt)->next)
-#define UTLIST_NEXTASGN(elt,list,to,next) ((elt)->next)=(to)
-/* #define UTLIST_PREV(elt,list,prev) ((elt)->prev) */
-#define UTLIST_PREVASGN(elt,list,to,prev) ((elt)->prev)=(to)
-#define UTLIST_RS(list)
-#define UTLIST_CASTASGN(a,b) (a)=(b)
-#endif
-
-/******************************************************************************
- * The sort macro is an adaptation of Simon Tatham's O(n log(n)) mergesort *
- * Unwieldy variable names used here to avoid shadowing passed-in variables. *
- *****************************************************************************/
-#define LL_SORT(list, cmp) \
- LL_SORT2(list, cmp, next)
-
-#define LL_SORT2(list, cmp, next) \
-do { \
- LDECLTYPE(list) _ls_p; \
- LDECLTYPE(list) _ls_q; \
- LDECLTYPE(list) _ls_e; \
- LDECLTYPE(list) _ls_tail; \
- IF_NO_DECLTYPE(LDECLTYPE(list) _tmp;) \
- int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
- if (list) { \
- _ls_insize = 1; \
- _ls_looping = 1; \
- while (_ls_looping) { \
- UTLIST_CASTASGN(_ls_p,list); \
- (list) = NULL; \
- _ls_tail = NULL; \
- _ls_nmerges = 0; \
- while (_ls_p) { \
- _ls_nmerges++; \
- _ls_q = _ls_p; \
- _ls_psize = 0; \
- for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \
- _ls_psize++; \
- UTLIST_SV(_ls_q,list); _ls_q = UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); \
- if (!_ls_q) break; \
- } \
- _ls_qsize = _ls_insize; \
- while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \
- if (_ls_psize == 0) { \
- _ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
- UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
- } else if (_ls_qsize == 0 || !_ls_q) { \
- _ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
- UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
- } else if (cmp(_ls_p,_ls_q) <= 0) { \
- _ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
- UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
- } else { \
- _ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
- UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
- } \
- if (_ls_tail) { \
- UTLIST_SV(_ls_tail,list); UTLIST_NEXTASGN(_ls_tail,list,_ls_e,next); UTLIST_RS(list); \
- } else { \
- UTLIST_CASTASGN(list,_ls_e); \
- } \
- _ls_tail = _ls_e; \
- } \
- _ls_p = _ls_q; \
- } \
- if (_ls_tail) { \
- UTLIST_SV(_ls_tail,list); UTLIST_NEXTASGN(_ls_tail,list,NULL,next); UTLIST_RS(list); \
- } \
- if (_ls_nmerges <= 1) { \
- _ls_looping=0; \
- } \
- _ls_insize *= 2; \
- } \
- } \
-} while (0)
-
-
-#define DL_SORT(list, cmp) \
- DL_SORT2(list, cmp, prev, next)
-
-#define DL_SORT2(list, cmp, prev, next) \
-do { \
- LDECLTYPE(list) _ls_p; \
- LDECLTYPE(list) _ls_q; \
- LDECLTYPE(list) _ls_e; \
- LDECLTYPE(list) _ls_tail; \
- IF_NO_DECLTYPE(LDECLTYPE(list) _tmp;) \
- int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
- if (list) { \
- _ls_insize = 1; \
- _ls_looping = 1; \
- while (_ls_looping) { \
- UTLIST_CASTASGN(_ls_p,list); \
- (list) = NULL; \
- _ls_tail = NULL; \
- _ls_nmerges = 0; \
- while (_ls_p) { \
- _ls_nmerges++; \
- _ls_q = _ls_p; \
- _ls_psize = 0; \
- for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \
- _ls_psize++; \
- UTLIST_SV(_ls_q,list); _ls_q = UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); \
- if (!_ls_q) break; \
- } \
- _ls_qsize = _ls_insize; \
- while ((_ls_psize > 0) || ((_ls_qsize > 0) && _ls_q)) { \
- if (_ls_psize == 0) { \
- _ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
- UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
- } else if ((_ls_qsize == 0) || (!_ls_q)) { \
- _ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
- UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
- } else if (cmp(_ls_p,_ls_q) <= 0) { \
- _ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
- UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
- } else { \
- _ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
- UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
- } \
- if (_ls_tail) { \
- UTLIST_SV(_ls_tail,list); UTLIST_NEXTASGN(_ls_tail,list,_ls_e,next); UTLIST_RS(list); \
- } else { \
- UTLIST_CASTASGN(list,_ls_e); \
- } \
- UTLIST_SV(_ls_e,list); UTLIST_PREVASGN(_ls_e,list,_ls_tail,prev); UTLIST_RS(list); \
- _ls_tail = _ls_e; \
- } \
- _ls_p = _ls_q; \
- } \
- UTLIST_CASTASGN((list)->prev, _ls_tail); \
- UTLIST_SV(_ls_tail,list); UTLIST_NEXTASGN(_ls_tail,list,NULL,next); UTLIST_RS(list); \
- if (_ls_nmerges <= 1) { \
- _ls_looping=0; \
- } \
- _ls_insize *= 2; \
- } \
- } \
-} while (0)
-
-#define CDL_SORT(list, cmp) \
- CDL_SORT2(list, cmp, prev, next)
-
-#define CDL_SORT2(list, cmp, prev, next) \
-do { \
- LDECLTYPE(list) _ls_p; \
- LDECLTYPE(list) _ls_q; \
- LDECLTYPE(list) _ls_e; \
- LDECLTYPE(list) _ls_tail; \
- LDECLTYPE(list) _ls_oldhead; \
- LDECLTYPE(list) _tmp; \
- int _ls_insize, _ls_nmerges, _ls_psize, _ls_qsize, _ls_i, _ls_looping; \
- if (list) { \
- _ls_insize = 1; \
- _ls_looping = 1; \
- while (_ls_looping) { \
- UTLIST_CASTASGN(_ls_p,list); \
- UTLIST_CASTASGN(_ls_oldhead,list); \
- (list) = NULL; \
- _ls_tail = NULL; \
- _ls_nmerges = 0; \
- while (_ls_p) { \
- _ls_nmerges++; \
- _ls_q = _ls_p; \
- _ls_psize = 0; \
- for (_ls_i = 0; _ls_i < _ls_insize; _ls_i++) { \
- _ls_psize++; \
- UTLIST_SV(_ls_q,list); \
- if (UTLIST_NEXT(_ls_q,list,next) == _ls_oldhead) { \
- _ls_q = NULL; \
- } else { \
- _ls_q = UTLIST_NEXT(_ls_q,list,next); \
- } \
- UTLIST_RS(list); \
- if (!_ls_q) break; \
- } \
- _ls_qsize = _ls_insize; \
- while (_ls_psize > 0 || (_ls_qsize > 0 && _ls_q)) { \
- if (_ls_psize == 0) { \
- _ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
- UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
- if (_ls_q == _ls_oldhead) { _ls_q = NULL; } \
- } else if (_ls_qsize == 0 || !_ls_q) { \
- _ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
- UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
- if (_ls_p == _ls_oldhead) { _ls_p = NULL; } \
- } else if (cmp(_ls_p,_ls_q) <= 0) { \
- _ls_e = _ls_p; UTLIST_SV(_ls_p,list); _ls_p = \
- UTLIST_NEXT(_ls_p,list,next); UTLIST_RS(list); _ls_psize--; \
- if (_ls_p == _ls_oldhead) { _ls_p = NULL; } \
- } else { \
- _ls_e = _ls_q; UTLIST_SV(_ls_q,list); _ls_q = \
- UTLIST_NEXT(_ls_q,list,next); UTLIST_RS(list); _ls_qsize--; \
- if (_ls_q == _ls_oldhead) { _ls_q = NULL; } \
- } \
- if (_ls_tail) { \
- UTLIST_SV(_ls_tail,list); UTLIST_NEXTASGN(_ls_tail,list,_ls_e,next); UTLIST_RS(list); \
- } else { \
- UTLIST_CASTASGN(list,_ls_e); \
- } \
- UTLIST_SV(_ls_e,list); UTLIST_PREVASGN(_ls_e,list,_ls_tail,prev); UTLIST_RS(list); \
- _ls_tail = _ls_e; \
- } \
- _ls_p = _ls_q; \
- } \
- UTLIST_CASTASGN((list)->prev,_ls_tail); \
- UTLIST_CASTASGN(_tmp,list); \
- UTLIST_SV(_ls_tail,list); UTLIST_NEXTASGN(_ls_tail,list,_tmp,next); UTLIST_RS(list); \
- if (_ls_nmerges <= 1) { \
- _ls_looping=0; \
- } \
- _ls_insize *= 2; \
- } \
- } \
-} while (0)
-
-/******************************************************************************
- * singly linked list macros (non-circular) *
- *****************************************************************************/
-#define LL_PREPEND(head,add) \
- LL_PREPEND2(head,add,next)
-
-#define LL_PREPEND2(head,add,next) \
-do { \
- (add)->next = (head); \
- (head) = (add); \
-} while (0)
-
-#define LL_CONCAT(head1,head2) \
- LL_CONCAT2(head1,head2,next)
-
-#define LL_CONCAT2(head1,head2,next) \
-do { \
- LDECLTYPE(head1) _tmp; \
- if (head1) { \
- _tmp = (head1); \
- while (_tmp->next) { _tmp = _tmp->next; } \
- _tmp->next=(head2); \
- } else { \
- (head1)=(head2); \
- } \
-} while (0)
-
-#define LL_APPEND(head,add) \
- LL_APPEND2(head,add,next)
-
-#define LL_APPEND2(head,add,next) \
-do { \
- LDECLTYPE(head) _tmp; \
- (add)->next=NULL; \
- if (head) { \
- _tmp = (head); \
- while (_tmp->next) { _tmp = _tmp->next; } \
- _tmp->next=(add); \
- } else { \
- (head)=(add); \
- } \
-} while (0)
-
-#define LL_INSERT_INORDER(head,add,cmp) \
- LL_INSERT_INORDER2(head,add,cmp,next)
-
-#define LL_INSERT_INORDER2(head,add,cmp,next) \
-do { \
- LDECLTYPE(head) _tmp; \
- if (head) { \
- LL_LOWER_BOUND2(head, _tmp, add, cmp, next); \
- LL_APPEND_ELEM2(head, _tmp, add, next); \
- } else { \
- (head) = (add); \
- (head)->next = NULL; \
- } \
-} while (0)
-
-#define LL_LOWER_BOUND(head,elt,like,cmp) \
- LL_LOWER_BOUND2(head,elt,like,cmp,next)
-
-#define LL_LOWER_BOUND2(head,elt,like,cmp,next) \
- do { \
- if ((head) == NULL || (cmp(head, like)) >= 0) { \
- (elt) = NULL; \
- } else { \
- for ((elt) = (head); (elt)->next != NULL; (elt) = (elt)->next) { \
- if (cmp((elt)->next, like) >= 0) { \
- break; \
- } \
- } \
- } \
- } while (0)
-
-#define LL_DELETE(head,del) \
- LL_DELETE2(head,del,next)
-
-#define LL_DELETE2(head,del,next) \
-do { \
- LDECLTYPE(head) _tmp; \
- if ((head) == (del)) { \
- (head)=(head)->next; \
- } else { \
- _tmp = (head); \
- while (_tmp->next && (_tmp->next != (del))) { \
- _tmp = _tmp->next; \
- } \
- if (_tmp->next) { \
- _tmp->next = (del)->next; \
- } \
- } \
-} while (0)
-
-#define LL_COUNT(head,el,counter) \
- LL_COUNT2(head,el,counter,next) \
-
-#define LL_COUNT2(head,el,counter,next) \
-do { \
- (counter) = 0; \
- LL_FOREACH2(head,el,next) { ++(counter); } \
-} while (0)
-
-#define LL_FOREACH(head,el) \
- LL_FOREACH2(head,el,next)
-
-#define LL_FOREACH2(head,el,next) \
- for ((el) = (head); el; (el) = (el)->next)
-
-#define LL_FOREACH_SAFE(head,el,tmp) \
- LL_FOREACH_SAFE2(head,el,tmp,next)
-
-#define LL_FOREACH_SAFE2(head,el,tmp,next) \
- for ((el) = (head); (el) && ((tmp) = (el)->next, 1); (el) = (tmp))
-
-#define LL_SEARCH_SCALAR(head,out,field,val) \
- LL_SEARCH_SCALAR2(head,out,field,val,next)
-
-#define LL_SEARCH_SCALAR2(head,out,field,val,next) \
-do { \
- LL_FOREACH2(head,out,next) { \
- if ((out)->field == (val)) break; \
- } \
-} while (0)
-
-#define LL_SEARCH(head,out,elt,cmp) \
- LL_SEARCH2(head,out,elt,cmp,next)
-
-#define LL_SEARCH2(head,out,elt,cmp,next) \
-do { \
- LL_FOREACH2(head,out,next) { \
- if ((cmp(out,elt))==0) break; \
- } \
-} while (0)
-
-#define LL_REPLACE_ELEM2(head, el, add, next) \
-do { \
- LDECLTYPE(head) _tmp; \
- assert((head) != NULL); \
- assert((el) != NULL); \
- assert((add) != NULL); \
- (add)->next = (el)->next; \
- if ((head) == (el)) { \
- (head) = (add); \
- } else { \
- _tmp = (head); \
- while (_tmp->next && (_tmp->next != (el))) { \
- _tmp = _tmp->next; \
- } \
- if (_tmp->next) { \
- _tmp->next = (add); \
- } \
- } \
-} while (0)
-
-#define LL_REPLACE_ELEM(head, el, add) \
- LL_REPLACE_ELEM2(head, el, add, next)
-
-#define LL_PREPEND_ELEM2(head, el, add, next) \
-do { \
- if (el) { \
- LDECLTYPE(head) _tmp; \
- assert((head) != NULL); \
- assert((add) != NULL); \
- (add)->next = (el); \
- if ((head) == (el)) { \
- (head) = (add); \
- } else { \
- _tmp = (head); \
- while (_tmp->next && (_tmp->next != (el))) { \
- _tmp = _tmp->next; \
- } \
- if (_tmp->next) { \
- _tmp->next = (add); \
- } \
- } \
- } else { \
- LL_APPEND2(head, add, next); \
- } \
-} while (0) \
-
-#define LL_PREPEND_ELEM(head, el, add) \
- LL_PREPEND_ELEM2(head, el, add, next)
-
-#define LL_APPEND_ELEM2(head, el, add, next) \
-do { \
- if (el) { \
- assert((head) != NULL); \
- assert((add) != NULL); \
- (add)->next = (el)->next; \
- (el)->next = (add); \
- } else { \
- LL_PREPEND2(head, add, next); \
- } \
-} while (0) \
-
-#define LL_APPEND_ELEM(head, el, add) \
- LL_APPEND_ELEM2(head, el, add, next)
-
-#ifdef NO_DECLTYPE
-/* Here are VS2008 / NO_DECLTYPE replacements for a few functions */
-
-#undef LL_CONCAT2
-#define LL_CONCAT2(head1,head2,next) \
-do { \
- char *_tmp; \
- if (head1) { \
- _tmp = (char*)(head1); \
- while ((head1)->next) { (head1) = (head1)->next; } \
- (head1)->next = (head2); \
- UTLIST_RS(head1); \
- } else { \
- (head1)=(head2); \
- } \
-} while (0)
-
-#undef LL_APPEND2
-#define LL_APPEND2(head,add,next) \
-do { \
- if (head) { \
- (add)->next = head; /* use add->next as a temp variable */ \
- while ((add)->next->next) { (add)->next = (add)->next->next; } \
- (add)->next->next=(add); \
- } else { \
- (head)=(add); \
- } \
- (add)->next=NULL; \
-} while (0)
-
-#undef LL_INSERT_INORDER2
-#define LL_INSERT_INORDER2(head,add,cmp,next) \
-do { \
- if ((head) == NULL || (cmp(head, add)) >= 0) { \
- (add)->next = (head); \
- (head) = (add); \
- } else { \
- char *_tmp = (char*)(head); \
- while ((head)->next != NULL && (cmp((head)->next, add)) < 0) { \
- (head) = (head)->next; \
- } \
- (add)->next = (head)->next; \
- (head)->next = (add); \
- UTLIST_RS(head); \
- } \
-} while (0)
-
-#undef LL_DELETE2
-#define LL_DELETE2(head,del,next) \
-do { \
- if ((head) == (del)) { \
- (head)=(head)->next; \
- } else { \
- char *_tmp = (char*)(head); \
- while ((head)->next && ((head)->next != (del))) { \
- (head) = (head)->next; \
- } \
- if ((head)->next) { \
- (head)->next = ((del)->next); \
- } \
- UTLIST_RS(head); \
- } \
-} while (0)
-
-#undef LL_REPLACE_ELEM2
-#define LL_REPLACE_ELEM2(head, el, add, next) \
-do { \
- assert((head) != NULL); \
- assert((el) != NULL); \
- assert((add) != NULL); \
- if ((head) == (el)) { \
- (head) = (add); \
- } else { \
- (add)->next = head; \
- while ((add)->next->next && ((add)->next->next != (el))) { \
- (add)->next = (add)->next->next; \
- } \
- if ((add)->next->next) { \
- (add)->next->next = (add); \
- } \
- } \
- (add)->next = (el)->next; \
-} while (0)
-
-#undef LL_PREPEND_ELEM2
-#define LL_PREPEND_ELEM2(head, el, add, next) \
-do { \
- if (el) { \
- assert((head) != NULL); \
- assert((add) != NULL); \
- if ((head) == (el)) { \
- (head) = (add); \
- } else { \
- (add)->next = (head); \
- while ((add)->next->next && ((add)->next->next != (el))) { \
- (add)->next = (add)->next->next; \
- } \
- if ((add)->next->next) { \
- (add)->next->next = (add); \
- } \
- } \
- (add)->next = (el); \
- } else { \
- LL_APPEND2(head, add, next); \
- } \
-} while (0) \
-
-#endif /* NO_DECLTYPE */
-
-/******************************************************************************
- * doubly linked list macros (non-circular) *
- *****************************************************************************/
-#define DL_PREPEND(head,add) \
- DL_PREPEND2(head,add,prev,next)
-
-#define DL_PREPEND2(head,add,prev,next) \
-do { \
- (add)->next = (head); \
- if (head) { \
- (add)->prev = (head)->prev; \
- (head)->prev = (add); \
- } else { \
- (add)->prev = (add); \
- } \
- (head) = (add); \
-} while (0)
-
-#define DL_APPEND(head,add) \
- DL_APPEND2(head,add,prev,next)
-
-#define DL_APPEND2(head,add,prev,next) \
-do { \
- if (head) { \
- (add)->prev = (head)->prev; \
- (head)->prev->next = (add); \
- (head)->prev = (add); \
- (add)->next = NULL; \
- } else { \
- (head)=(add); \
- (head)->prev = (head); \
- (head)->next = NULL; \
- } \
-} while (0)
-
-#define DL_INSERT_INORDER(head,add,cmp) \
- DL_INSERT_INORDER2(head,add,cmp,prev,next)
-
-#define DL_INSERT_INORDER2(head,add,cmp,prev,next) \
-do { \
- LDECLTYPE(head) _tmp; \
- if (head) { \
- DL_LOWER_BOUND2(head, _tmp, add, cmp, next); \
- DL_APPEND_ELEM2(head, _tmp, add, prev, next); \
- } else { \
- (head) = (add); \
- (head)->prev = (head); \
- (head)->next = NULL; \
- } \
-} while (0)
-
-#define DL_LOWER_BOUND(head,elt,like,cmp) \
- DL_LOWER_BOUND2(head,elt,like,cmp,next)
-
-#define DL_LOWER_BOUND2(head,elt,like,cmp,next) \
-do { \
- if ((head) == NULL || (cmp(head, like)) >= 0) { \
- (elt) = NULL; \
- } else { \
- for ((elt) = (head); (elt)->next != NULL; (elt) = (elt)->next) { \
- if ((cmp((elt)->next, like)) >= 0) { \
- break; \
- } \
- } \
- } \
-} while (0)
-
-#define DL_CONCAT(head1,head2) \
- DL_CONCAT2(head1,head2,prev,next)
-
-#define DL_CONCAT2(head1,head2,prev,next) \
-do { \
- LDECLTYPE(head1) _tmp; \
- if (head2) { \
- if (head1) { \
- UTLIST_CASTASGN(_tmp, (head2)->prev); \
- (head2)->prev = (head1)->prev; \
- (head1)->prev->next = (head2); \
- UTLIST_CASTASGN((head1)->prev, _tmp); \
- } else { \
- (head1)=(head2); \
- } \
- } \
-} while (0)
-
-#define DL_DELETE(head,del) \
- DL_DELETE2(head,del,prev,next)
-
-#define DL_DELETE2(head,del,prev,next) \
-do { \
- assert((head) != NULL); \
- assert((del)->prev != NULL); \
- if ((del)->prev == (del)) { \
- (head)=NULL; \
- } else if ((del)==(head)) { \
- (del)->next->prev = (del)->prev; \
- (head) = (del)->next; \
- } else { \
- (del)->prev->next = (del)->next; \
- if ((del)->next) { \
- (del)->next->prev = (del)->prev; \
- } else { \
- (head)->prev = (del)->prev; \
- } \
- } \
-} while (0)
-
-#define DL_COUNT(head,el,counter) \
- DL_COUNT2(head,el,counter,next) \
-
-#define DL_COUNT2(head,el,counter,next) \
-do { \
- (counter) = 0; \
- DL_FOREACH2(head,el,next) { ++(counter); } \
-} while (0)
-
-#define DL_FOREACH(head,el) \
- DL_FOREACH2(head,el,next)
-
-#define DL_FOREACH2(head,el,next) \
- for ((el) = (head); el; (el) = (el)->next)
-
-/* this version is safe for deleting the elements during iteration */
-#define DL_FOREACH_SAFE(head,el,tmp) \
- DL_FOREACH_SAFE2(head,el,tmp,next)
-
-#define DL_FOREACH_SAFE2(head,el,tmp,next) \
- for ((el) = (head); (el) && ((tmp) = (el)->next, 1); (el) = (tmp))
-
-/* these are identical to their singly-linked list counterparts */
-#define DL_SEARCH_SCALAR LL_SEARCH_SCALAR
-#define DL_SEARCH LL_SEARCH
-#define DL_SEARCH_SCALAR2 LL_SEARCH_SCALAR2
-#define DL_SEARCH2 LL_SEARCH2
-
-#define DL_REPLACE_ELEM2(head, el, add, prev, next) \
-do { \
- assert((head) != NULL); \
- assert((el) != NULL); \
- assert((add) != NULL); \
- if ((head) == (el)) { \
- (head) = (add); \
- (add)->next = (el)->next; \
- if ((el)->next == NULL) { \
- (add)->prev = (add); \
- } else { \
- (add)->prev = (el)->prev; \
- (add)->next->prev = (add); \
- } \
- } else { \
- (add)->next = (el)->next; \
- (add)->prev = (el)->prev; \
- (add)->prev->next = (add); \
- if ((el)->next == NULL) { \
- (head)->prev = (add); \
- } else { \
- (add)->next->prev = (add); \
- } \
- } \
-} while (0)
-
-#define DL_REPLACE_ELEM(head, el, add) \
- DL_REPLACE_ELEM2(head, el, add, prev, next)
-
-#define DL_PREPEND_ELEM2(head, el, add, prev, next) \
-do { \
- if (el) { \
- assert((head) != NULL); \
- assert((add) != NULL); \
- (add)->next = (el); \
- (add)->prev = (el)->prev; \
- (el)->prev = (add); \
- if ((head) == (el)) { \
- (head) = (add); \
- } else { \
- (add)->prev->next = (add); \
- } \
- } else { \
- DL_APPEND2(head, add, prev, next); \
- } \
-} while (0) \
-
-#define DL_PREPEND_ELEM(head, el, add) \
- DL_PREPEND_ELEM2(head, el, add, prev, next)
-
-#define DL_APPEND_ELEM2(head, el, add, prev, next) \
-do { \
- if (el) { \
- assert((head) != NULL); \
- assert((add) != NULL); \
- (add)->next = (el)->next; \
- (add)->prev = (el); \
- (el)->next = (add); \
- if ((add)->next) { \
- (add)->next->prev = (add); \
- } else { \
- (head)->prev = (add); \
- } \
- } else { \
- DL_PREPEND2(head, add, prev, next); \
- } \
-} while (0) \
-
-#define DL_APPEND_ELEM(head, el, add) \
- DL_APPEND_ELEM2(head, el, add, prev, next)
-
-#ifdef NO_DECLTYPE
-/* Here are VS2008 / NO_DECLTYPE replacements for a few functions */
-
-#undef DL_INSERT_INORDER2
-#define DL_INSERT_INORDER2(head,add,cmp,prev,next) \
-do { \
- if ((head) == NULL) { \
- (add)->prev = (add); \
- (add)->next = NULL; \
- (head) = (add); \
- } else if ((cmp(head, add)) >= 0) { \
- (add)->prev = (head)->prev; \
- (add)->next = (head); \
- (head)->prev = (add); \
- (head) = (add); \
- } else { \
- char *_tmp = (char*)(head); \
- while ((head)->next && (cmp((head)->next, add)) < 0) { \
- (head) = (head)->next; \
- } \
- (add)->prev = (head); \
- (add)->next = (head)->next; \
- (head)->next = (add); \
- UTLIST_RS(head); \
- if ((add)->next) { \
- (add)->next->prev = (add); \
- } else { \
- (head)->prev = (add); \
- } \
- } \
-} while (0)
-#endif /* NO_DECLTYPE */
-
-/******************************************************************************
- * circular doubly linked list macros *
- *****************************************************************************/
-#define CDL_APPEND(head,add) \
- CDL_APPEND2(head,add,prev,next)
-
-#define CDL_APPEND2(head,add,prev,next) \
-do { \
- if (head) { \
- (add)->prev = (head)->prev; \
- (add)->next = (head); \
- (head)->prev = (add); \
- (add)->prev->next = (add); \
- } else { \
- (add)->prev = (add); \
- (add)->next = (add); \
- (head) = (add); \
- } \
-} while (0)
-
-#define CDL_PREPEND(head,add) \
- CDL_PREPEND2(head,add,prev,next)
-
-#define CDL_PREPEND2(head,add,prev,next) \
-do { \
- if (head) { \
- (add)->prev = (head)->prev; \
- (add)->next = (head); \
- (head)->prev = (add); \
- (add)->prev->next = (add); \
- } else { \
- (add)->prev = (add); \
- (add)->next = (add); \
- } \
- (head) = (add); \
-} while (0)
-
-#define CDL_INSERT_INORDER(head,add,cmp) \
- CDL_INSERT_INORDER2(head,add,cmp,prev,next)
-
-#define CDL_INSERT_INORDER2(head,add,cmp,prev,next) \
-do { \
- LDECLTYPE(head) _tmp; \
- if (head) { \
- CDL_LOWER_BOUND2(head, _tmp, add, cmp, next); \
- CDL_APPEND_ELEM2(head, _tmp, add, prev, next); \
- } else { \
- (head) = (add); \
- (head)->next = (head); \
- (head)->prev = (head); \
- } \
-} while (0)
-
-#define CDL_LOWER_BOUND(head,elt,like,cmp) \
- CDL_LOWER_BOUND2(head,elt,like,cmp,next)
-
-#define CDL_LOWER_BOUND2(head,elt,like,cmp,next) \
-do { \
- if ((head) == NULL || (cmp(head, like)) >= 0) { \
- (elt) = NULL; \
- } else { \
- for ((elt) = (head); (elt)->next != (head); (elt) = (elt)->next) { \
- if ((cmp((elt)->next, like)) >= 0) { \
- break; \
- } \
- } \
- } \
-} while (0)
-
-#define CDL_DELETE(head,del) \
- CDL_DELETE2(head,del,prev,next)
-
-#define CDL_DELETE2(head,del,prev,next) \
-do { \
- if (((head)==(del)) && ((head)->next == (head))) { \
- (head) = NULL; \
- } else { \
- (del)->next->prev = (del)->prev; \
- (del)->prev->next = (del)->next; \
- if ((del) == (head)) (head)=(del)->next; \
- } \
-} while (0)
-
-#define CDL_COUNT(head,el,counter) \
- CDL_COUNT2(head,el,counter,next) \
-
-#define CDL_COUNT2(head, el, counter,next) \
-do { \
- (counter) = 0; \
- CDL_FOREACH2(head,el,next) { ++(counter); } \
-} while (0)
-
-#define CDL_FOREACH(head,el) \
- CDL_FOREACH2(head,el,next)
-
-#define CDL_FOREACH2(head,el,next) \
- for ((el)=(head);el;(el)=(((el)->next==(head)) ? NULL : (el)->next))
-
-#define CDL_FOREACH_SAFE(head,el,tmp1,tmp2) \
- CDL_FOREACH_SAFE2(head,el,tmp1,tmp2,prev,next)
-
-#define CDL_FOREACH_SAFE2(head,el,tmp1,tmp2,prev,next) \
- for ((el) = (head), (tmp1) = (head) ? (head)->prev : NULL; \
- (el) && ((tmp2) = (el)->next, 1); \
- (el) = ((el) == (tmp1) ? NULL : (tmp2)))
-
-#define CDL_SEARCH_SCALAR(head,out,field,val) \
- CDL_SEARCH_SCALAR2(head,out,field,val,next)
-
-#define CDL_SEARCH_SCALAR2(head,out,field,val,next) \
-do { \
- CDL_FOREACH2(head,out,next) { \
- if ((out)->field == (val)) break; \
- } \
-} while (0)
-
-#define CDL_SEARCH(head,out,elt,cmp) \
- CDL_SEARCH2(head,out,elt,cmp,next)
-
-#define CDL_SEARCH2(head,out,elt,cmp,next) \
-do { \
- CDL_FOREACH2(head,out,next) { \
- if ((cmp(out,elt))==0) break; \
- } \
-} while (0)
-
-#define CDL_REPLACE_ELEM2(head, el, add, prev, next) \
-do { \
- assert((head) != NULL); \
- assert((el) != NULL); \
- assert((add) != NULL); \
- if ((el)->next == (el)) { \
- (add)->next = (add); \
- (add)->prev = (add); \
- (head) = (add); \
- } else { \
- (add)->next = (el)->next; \
- (add)->prev = (el)->prev; \
- (add)->next->prev = (add); \
- (add)->prev->next = (add); \
- if ((head) == (el)) { \
- (head) = (add); \
- } \
- } \
-} while (0)
-
-#define CDL_REPLACE_ELEM(head, el, add) \
- CDL_REPLACE_ELEM2(head, el, add, prev, next)
-
-#define CDL_PREPEND_ELEM2(head, el, add, prev, next) \
-do { \
- if (el) { \
- assert((head) != NULL); \
- assert((add) != NULL); \
- (add)->next = (el); \
- (add)->prev = (el)->prev; \
- (el)->prev = (add); \
- (add)->prev->next = (add); \
- if ((head) == (el)) { \
- (head) = (add); \
- } \
- } else { \
- CDL_APPEND2(head, add, prev, next); \
- } \
-} while (0)
-
-#define CDL_PREPEND_ELEM(head, el, add) \
- CDL_PREPEND_ELEM2(head, el, add, prev, next)
-
-#define CDL_APPEND_ELEM2(head, el, add, prev, next) \
-do { \
- if (el) { \
- assert((head) != NULL); \
- assert((add) != NULL); \
- (add)->next = (el)->next; \
- (add)->prev = (el); \
- (el)->next = (add); \
- (add)->next->prev = (add); \
- } else { \
- CDL_PREPEND2(head, add, prev, next); \
- } \
-} while (0)
-
-#define CDL_APPEND_ELEM(head, el, add) \
- CDL_APPEND_ELEM2(head, el, add, prev, next)
-
-#ifdef NO_DECLTYPE
-/* Here are VS2008 / NO_DECLTYPE replacements for a few functions */
-
-#undef CDL_INSERT_INORDER2
-#define CDL_INSERT_INORDER2(head,add,cmp,prev,next) \
-do { \
- if ((head) == NULL) { \
- (add)->prev = (add); \
- (add)->next = (add); \
- (head) = (add); \
- } else if ((cmp(head, add)) >= 0) { \
- (add)->prev = (head)->prev; \
- (add)->next = (head); \
- (add)->prev->next = (add); \
- (head)->prev = (add); \
- (head) = (add); \
- } else { \
- char *_tmp = (char*)(head); \
- while ((char*)(head)->next != _tmp && (cmp((head)->next, add)) < 0) { \
- (head) = (head)->next; \
- } \
- (add)->prev = (head); \
- (add)->next = (head)->next; \
- (add)->next->prev = (add); \
- (head)->next = (add); \
- UTLIST_RS(head); \
- } \
-} while (0)
-#endif /* NO_DECLTYPE */
-
-#endif /* UTLIST_H */