1 /******************************************************************************* 2 * Copyright (c) 2009, 2022 IBM Corp. 3 * 4 * All rights reserved. This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License v2.0 6 * and Eclipse Distribution License v1.0 which accompany this distribution. 7 * 8 * The Eclipse Public License is available at 9 * https://www.eclipse.org/legal/epl-2.0/ 10 * and the Eclipse Distribution License is available at 11 * http://www.eclipse.org/org/documents/edl-v10.php. 12 * 13 * Contributors: 14 * Ian Craggs - initial API and implementation and/or initial documentation 15 * Ian Craggs - async client updates 16 * Ian Craggs - fix for bug 432903 - queue persistence 17 * Ian Craggs - MQTT V5 updates 18 *******************************************************************************/ 19 20 #if !defined(MQTTPERSISTENCE_H) 21 #define MQTTPERSISTENCE_H 22 23 #if defined(__cplusplus) 24 extern "C" { 25 #endif 26 27 #include "Clients.h" 28 #include "MQTTProperties.h" 29 30 /** Stem of the key for a sent PUBLISH QoS1 or QoS2 */ 31 #define PERSISTENCE_PUBLISH_SENT "s-" 32 /** Stem of the key for a sent PUBREL */ 33 #define PERSISTENCE_PUBREL "sc-" 34 /** Stem of the key for a received PUBLISH QoS2 */ 35 #define PERSISTENCE_PUBLISH_RECEIVED "r-" 36 37 /** Stem of the key for a sent MQTT V5 PUBLISH QoS1 or QoS2 */ 38 #define PERSISTENCE_V5_PUBLISH_SENT "s5-" 39 /** Stem of the key for a sent MQTT V5 PUBREL */ 40 #define PERSISTENCE_V5_PUBREL "sc5-" 41 /** Stem of the key for a received MQTT V5 PUBLISH QoS2 */ 42 #define PERSISTENCE_V5_PUBLISH_RECEIVED "r5-" 43 44 /** Stem of the key for an async client command */ 45 #define PERSISTENCE_COMMAND_KEY "c-" 46 /** Stem of the key for an MQTT V5 async client command */ 47 #define PERSISTENCE_V5_COMMAND_KEY "c5-" 48 /** Stem of the key for an client incoming message queue */ 49 #define PERSISTENCE_QUEUE_KEY "q-" 50 /** Stem of the key for an MQTT V5 incoming message queue */ 51 #define PERSISTENCE_V5_QUEUE_KEY "q5-" 52 /** Maximum length of a stem for a persistence key */ 53 #define PERSISTENCE_MAX_STEM_LENGTH 4 54 /** Maximum allowed length of a persistence key */ 55 #define PERSISTENCE_MAX_KEY_LENGTH 10 56 /** Maximum size of an integer sequence number appended to a persistence key */ 57 #define PERSISTENCE_SEQNO_LIMIT 1000000 /*10^(PERSISTENCE_MAX_KEY_LENGTH - PERSISTENCE_MAX_STEM_LENGTH)*/ 58 59 int MQTTPersistence_create(MQTTClient_persistence** per, int type, void* pcontext); 60 int MQTTPersistence_initialize(Clients* c, const char* serverURI); 61 int MQTTPersistence_close(Clients* c); 62 int MQTTPersistence_clear(Clients* c); 63 int MQTTPersistence_restorePackets(Clients* c); 64 void* MQTTPersistence_restorePacket(int MQTTVersion, char* buffer, size_t buflen); 65 void MQTTPersistence_insertInOrder(List* list, void* content, size_t size); 66 int MQTTPersistence_putPacket(SOCKET socket, char* buf0, size_t buf0len, int count, 67 char** buffers, size_t* buflens, int htype, int msgId, int scr, int MQTTVersion); 68 int MQTTPersistence_remove(Clients* c, char* type, int qos, int msgId); 69 void MQTTPersistence_wrapMsgID(Clients *c); 70 71 typedef struct 72 { 73 char struct_id[4]; 74 int struct_version; 75 int payloadlen; 76 void* payload; 77 int qos; 78 int retained; 79 int dup; 80 int msgid; 81 MQTTProperties properties; 82 } MQTTPersistence_message; 83 84 typedef struct 85 { 86 MQTTPersistence_message* msg; 87 char* topicName; 88 int topicLen; 89 unsigned int seqno; /* only used on restore */ 90 } MQTTPersistence_qEntry; 91 92 int MQTTPersistence_unpersistQueueEntry(Clients* client, MQTTPersistence_qEntry* qe); 93 int MQTTPersistence_persistQueueEntry(Clients* aclient, MQTTPersistence_qEntry* qe); 94 int MQTTPersistence_restoreMessageQueue(Clients* c); 95 #ifdef __cplusplus 96 } 97 #endif 98 99 #endif 100