00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00103
00105
00106 #if defined(__cplusplus)
00107 extern "C" {
00108 #endif
00109 #if !defined(MQTTCLIENT_H)
00110 #define MQTTCLIENT_H
00111
00112 #if defined(WIN32) || defined(WIN64)
00113 #define DLLImport __declspec(dllimport)
00114 #define DLLExport __declspec(dllexport)
00115 #else
00116 #define DLLImport extern
00117 #define DLLExport __attribute__ ((visibility ("default")))
00118 #endif
00119
00120 #include <stdio.h>
00121
00123
00124
00125 #if !defined(NO_PERSISTENCE)
00126 #include "MQTTClientPersistence.h"
00127 #endif
00128
00133 #define MQTTCLIENT_SUCCESS 0
00134
00138 #define MQTTCLIENT_FAILURE -1
00139
00140
00141
00145 #define MQTTCLIENT_DISCONNECTED -3
00146
00150 #define MQTTCLIENT_MAX_MESSAGES_INFLIGHT -4
00151
00154 #define MQTTCLIENT_BAD_UTF8_STRING -5
00155
00158 #define MQTTCLIENT_NULL_PARAMETER -6
00159
00164 #define MQTTCLIENT_TOPICNAME_TRUNCATED -7
00165
00169 #define MQTTCLIENT_BAD_STRUCTURE -8
00170
00173 #define MQTTCLIENT_BAD_QOS -9
00174
00177 #define MQTTCLIENT_SSL_NOT_SUPPORTED -10
00178
00181 #define MQTTCLIENT_BAD_PROTOCOL -14
00182
00186 #define MQTTVERSION_DEFAULT 0
00187
00190 #define MQTTVERSION_3_1 3
00191
00194 #define MQTTVERSION_3_1_1 4
00195
00198 #define MQTT_BAD_SUBSCRIBE 0x80
00199
00203 typedef struct
00204 {
00206 char struct_id[4];
00208 int struct_version;
00210 int do_openssl_init;
00211 } MQTTClient_init_options;
00212
00213 #define MQTTClient_init_options_initializer { {'M', 'Q', 'T', 'G'}, 0, 0 }
00214
00219 DLLExport void MQTTClient_global_init(MQTTClient_init_options* inits);
00220
00225 typedef void* MQTTClient;
00236 typedef int MQTTClient_deliveryToken;
00237 typedef int MQTTClient_token;
00238
00245 typedef struct
00246 {
00248 char struct_id[4];
00250 int struct_version;
00252 int payloadlen;
00254 void* payload;
00268 int qos;
00287 int retained;
00294 int dup;
00298 int msgid;
00299 } MQTTClient_message;
00300
00301 #define MQTTClient_message_initializer { {'M', 'Q', 'T', 'M'}, 0, 0, NULL, 0, 0, 0, 0 }
00302
00329 typedef int MQTTClient_messageArrived(void* context, char* topicName, int topicLen, MQTTClient_message* message);
00330
00351 typedef void MQTTClient_deliveryComplete(void* context, MQTTClient_deliveryToken dt);
00352
00368 typedef void MQTTClient_connectionLost(void* context, char* cause);
00369
00397 DLLExport int MQTTClient_setCallbacks(MQTTClient handle, void* context, MQTTClient_connectionLost* cl,
00398 MQTTClient_messageArrived* ma, MQTTClient_deliveryComplete* dc);
00399
00400
00443 DLLExport int MQTTClient_create(MQTTClient* handle, const char* serverURI, const char* clientId,
00444 int persistence_type, void* persistence_context);
00445
00458 typedef struct
00459 {
00461 char struct_id[4];
00465 int struct_version;
00467 const char* topicName;
00469 const char* message;
00473 int retained;
00478 int qos;
00480 struct
00481 {
00482 int len;
00483 const void* data;
00484 } payload;
00485 } MQTTClient_willOptions;
00486
00487 #define MQTTClient_willOptions_initializer { {'M', 'Q', 'T', 'W'}, 1, NULL, NULL, 0, 0, {0, NULL} }
00488
00489 #define MQTT_SSL_VERSION_DEFAULT 0
00490 #define MQTT_SSL_VERSION_TLS_1_0 1
00491 #define MQTT_SSL_VERSION_TLS_1_1 2
00492 #define MQTT_SSL_VERSION_TLS_1_2 3
00493
00506 typedef struct
00507 {
00509 char struct_id[4];
00511 int struct_version;
00512
00514 const char* trustStore;
00515
00519 const char* keyStore;
00520
00524 const char* privateKey;
00526 const char* privateKeyPassword;
00527
00536 const char* enabledCipherSuites;
00537
00539 int enableServerCertAuth;
00540
00545 int sslVersion;
00546
00552 int verify;
00553
00559 const char* CApath;
00560
00561 } MQTTClient_SSLOptions;
00562
00563 #define MQTTClient_SSLOptions_initializer { {'M', 'Q', 'T', 'S'}, 2, NULL, NULL, NULL, NULL, NULL, 1, MQTT_SSL_VERSION_DEFAULT, 0, NULL }
00564
00579 typedef struct
00580 {
00582 char struct_id[4];
00590 int struct_version;
00600 int keepAliveInterval;
00622 int cleansession;
00632 int reliable;
00638 MQTTClient_willOptions* will;
00644 const char* username;
00650 const char* password;
00654 int connectTimeout;
00658 int retryInterval;
00663 MQTTClient_SSLOptions* ssl;
00667 int serverURIcount;
00678 char* const* serverURIs;
00685 int MQTTVersion;
00689 struct
00690 {
00691 const char* serverURI;
00692 int MQTTVersion;
00693 int sessionPresent;
00694 } returned;
00698 struct {
00699 int len;
00700 const void* data;
00701 } binarypwd;
00702 } MQTTClient_connectOptions;
00703
00704 #define MQTTClient_connectOptions_initializer { {'M', 'Q', 'T', 'C'}, 5, 60, 1, 1, NULL, NULL, NULL, 30, 20, NULL, 0, NULL, 0, {NULL, 0, 0}, {0, NULL} }
00705
00713 typedef struct
00714 {
00715 const char* name;
00716 const char* value;
00717 } MQTTClient_nameValue;
00718
00724 DLLExport MQTTClient_nameValue* MQTTClient_getVersionInfo(void);
00725
00746 DLLExport int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options);
00747
00766 DLLExport int MQTTClient_disconnect(MQTTClient handle, int timeout);
00767
00775 DLLExport int MQTTClient_isConnected(MQTTClient handle);
00776
00777
00778
00779
00780
00794 DLLExport int MQTTClient_subscribe(MQTTClient handle, const char* topic, int qos);
00795
00812 DLLExport int MQTTClient_subscribeMany(MQTTClient handle, int count, char* const* topic, int* qos);
00813
00825 DLLExport int MQTTClient_unsubscribe(MQTTClient handle, const char* topic);
00826
00838 DLLExport int MQTTClient_unsubscribeMany(MQTTClient handle, int count, char* const* topic);
00839
00861 DLLExport int MQTTClient_publish(MQTTClient handle, const char* topicName, int payloadlen, void* payload, int qos, int retained,
00862 MQTTClient_deliveryToken* dt);
00882 DLLExport int MQTTClient_publishMessage(MQTTClient handle, const char* topicName, MQTTClient_message* msg, MQTTClient_deliveryToken* dt);
00883
00884
00900 DLLExport int MQTTClient_waitForCompletion(MQTTClient handle, MQTTClient_deliveryToken dt, unsigned long timeout);
00901
00902
00921 DLLExport int MQTTClient_getPendingDeliveryTokens(MQTTClient handle, MQTTClient_deliveryToken **tokens);
00922
00929 DLLExport void MQTTClient_yield(void);
00930
00962 DLLExport int MQTTClient_receive(MQTTClient handle, char** topicName, int* topicLen, MQTTClient_message** message,
00963 unsigned long timeout);
00964
00975 DLLExport void MQTTClient_freeMessage(MQTTClient_message** msg);
00976
00985 DLLExport void MQTTClient_free(void* ptr);
00986
00994 DLLExport void MQTTClient_destroy(MQTTClient* handle);
00995
00996 #endif
00997 #ifdef __cplusplus
00998 }
00999 #endif
01000