|
|
|
@ -4,12 +4,12 @@ Copyright (c) 2010-2014 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.
|
|
|
|
|
*/
|
|
|
|
@ -43,6 +43,8 @@ extern "C" {
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
|
|
#define LIBMOSQUITTO_MAJOR 1
|
|
|
|
|
#define LIBMOSQUITTO_MINOR 4
|
|
|
|
|
#define LIBMOSQUITTO_REVISION 90
|
|
|
|
@ -119,7 +121,7 @@ struct mosquitto;
|
|
|
|
|
*/
|
|
|
|
|
/***************************************************
|
|
|
|
|
* 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
|
|
|
|
@ -220,7 +222,7 @@ libmosq_EXPORT int mosquitto_lib_cleanup(void);
|
|
|
|
|
*/
|
|
|
|
|
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.
|
|
|
|
@ -262,7 +264,7 @@ libmosq_EXPORT void mosquitto_destroy(struct mosquitto *mosq);
|
|
|
|
|
*/
|
|
|
|
|
libmosq_EXPORT int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_session, void *obj);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
/*
|
|
|
|
|
* Function: mosquitto_will_set
|
|
|
|
|
*
|
|
|
|
|
* Configure will information for a mosquitto instance. By default, clients do
|
|
|
|
@ -288,7 +290,7 @@ libmosq_EXPORT int mosquitto_reinitialise(struct mosquitto *mosq, const char *id
|
|
|
|
|
*/
|
|
|
|
|
libmosq_EXPORT int mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
/*
|
|
|
|
|
* Function: mosquitto_will_clear
|
|
|
|
|
*
|
|
|
|
|
* Remove a previously configured will. This must be called before calling
|
|
|
|
@ -359,7 +361,7 @@ libmosq_EXPORT int mosquitto_connect(struct mosquitto *mosq, const char *host, i
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
* if you need to restrict network communication over a particular interface.
|
|
|
|
|
*
|
|
|
|
|
* Parameters:
|
|
|
|
|
* mosq - a valid mosquitto instance.
|
|
|
|
@ -425,7 +427,7 @@ libmosq_EXPORT int mosquitto_connect_async(struct mosquitto *mosq, const char *h
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
* communication over a particular interface.
|
|
|
|
|
*
|
|
|
|
|
* May be called before or after <mosquitto_loop_start>.
|
|
|
|
|
*
|
|
|
|
@ -462,7 +464,7 @@ libmosq_EXPORT int mosquitto_connect_bind_async(struct mosquitto *mosq, const ch
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
* communication over a particular interface.
|
|
|
|
|
*
|
|
|
|
|
* May be called before or after <mosquitto_loop_start>.
|
|
|
|
|
*
|
|
|
|
@ -497,7 +499,7 @@ libmosq_EXPORT int mosquitto_connect_srv(struct mosquitto *mosq, const char *hos
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
@ -528,7 +530,7 @@ libmosq_EXPORT int mosquitto_reconnect(struct mosquitto *mosq);
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
@ -565,11 +567,11 @@ libmosq_EXPORT int mosquitto_reconnect_async(struct mosquitto *mosq);
|
|
|
|
|
*/
|
|
|
|
|
libmosq_EXPORT int mosquitto_disconnect(struct mosquitto *mosq);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
/*
|
|
|
|
|
* 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
|
|
|
|
@ -598,7 +600,7 @@ libmosq_EXPORT int mosquitto_disconnect(struct mosquitto *mosq);
|
|
|
|
|
* MOSQ_ERR_PAYLOAD_SIZE - if payloadlen is too large.
|
|
|
|
|
* MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8
|
|
|
|
|
*
|
|
|
|
|
* See Also:
|
|
|
|
|
* 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);
|
|
|
|
@ -670,7 +672,7 @@ libmosq_EXPORT int mosquitto_message_copy(struct mosquitto_message *dst, const s
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Function: mosquitto_message_free
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Completely free a mosquitto_message struct.
|
|
|
|
|
*
|
|
|
|
|
* Parameters:
|
|
|
|
@ -714,7 +716,7 @@ libmosq_EXPORT void mosquitto_message_free_contents(struct mosquitto_message *me
|
|
|
|
|
* <mosquitto_loop_misc>.
|
|
|
|
|
*
|
|
|
|
|
* Threads:
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Parameters:
|
|
|
|
|
* mosq - a valid mosquitto instance.
|
|
|
|
|
* timeout - Maximum number of milliseconds to wait for network activity
|
|
|
|
@ -722,7 +724,7 @@ libmosq_EXPORT void mosquitto_message_free_contents(struct mosquitto_message *me
|
|
|
|
|
* 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.
|
|
|
|
@ -1107,7 +1109,7 @@ libmosq_EXPORT int mosquitto_tls_opts_set(struct mosquitto *mosq, int cert_reqs,
|
|
|
|
|
*/
|
|
|
|
|
libmosq_EXPORT int mosquitto_tls_psk_set(struct mosquitto *mosq, const char *psk, const char *identity, const char *ciphers);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
/*
|
|
|
|
|
* Function: mosquitto_connect_callback_set
|
|
|
|
|
*
|
|
|
|
|
* Set the connect callback. This is called when the broker sends a CONNACK
|
|
|
|
@ -1130,13 +1132,13 @@ libmosq_EXPORT int mosquitto_tls_psk_set(struct mosquitto *mosq, const char *psk
|
|
|
|
|
* * 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_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:
|
|
|
|
@ -1150,13 +1152,13 @@ libmosq_EXPORT void mosquitto_connect_callback_set(struct mosquitto *mosq, void
|
|
|
|
|
* 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_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:
|
|
|
|
@ -1174,7 +1176,7 @@ libmosq_EXPORT void mosquitto_publish_callback_set(struct mosquitto *mosq, void
|
|
|
|
|
*
|
|
|
|
|
* 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:
|
|
|
|
@ -1197,7 +1199,7 @@ libmosq_EXPORT void mosquitto_message_callback_set(struct mosquitto *mosq, void
|
|
|
|
|
*
|
|
|
|
|
* 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:
|
|
|
|
@ -1218,7 +1220,7 @@ libmosq_EXPORT void mosquitto_subscribe_callback_set(struct mosquitto *mosq, voi
|
|
|
|
|
*
|
|
|
|
|
* 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:
|
|
|
|
@ -1440,7 +1442,7 @@ libmosq_EXPORT const char *mosquitto_connack_string(int connack_code);
|
|
|
|
|
* > char **topics;
|
|
|
|
|
* > int topic_count;
|
|
|
|
|
* > int i;
|
|
|
|
|
* >
|
|
|
|
|
* >
|
|
|
|
|
* > mosquitto_sub_topic_tokenise("$SYS/broker/uptime", &topics, &topic_count);
|
|
|
|
|
* >
|
|
|
|
|
* > for(i=0; i<token_count; i++){
|
|
|
|
@ -1641,7 +1643,7 @@ libmosq_EXPORT int mosquitto_subscribe_simple(
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
* disconnects cleanly and returns.
|
|
|
|
|
*
|
|
|
|
|
* Parameters:
|
|
|
|
|
* callback - a callback function in the following form:
|
|
|
|
|