• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright (c) 2009, 2018 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 v1.0
6  * and Eclipse Distribution License v1.0 which accompany this distribution.
7  *
8  * The Eclipse Public License is available at
9  *    http://www.eclipse.org/legal/epl-v10.html
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 async client message queue */
49 #define PERSISTENCE_QUEUE_KEY "q-"
50 /** Stem of the key for an MQTT V5 message queue */
51 #define PERSISTENCE_V5_QUEUE_KEY "q5-"
52 #define PERSISTENCE_MAX_KEY_LENGTH 8
53 
54 int MQTTPersistence_create(MQTTClient_persistence** per, int type, void* pcontext);
55 int MQTTPersistence_initialize(Clients* c, const char* serverURI);
56 int MQTTPersistence_close(Clients* c);
57 int MQTTPersistence_clear(Clients* c);
58 int MQTTPersistence_restore(Clients* c);
59 void* MQTTPersistence_restorePacket(int MQTTVersion, char* buffer, size_t buflen);
60 void MQTTPersistence_insertInOrder(List* list, void* content, size_t size);
61 int MQTTPersistence_put(int socket, char* buf0, size_t buf0len, int count,
62 						char** buffers, size_t* buflens, int htype, int msgId, int scr, int MQTTVersion);
63 int MQTTPersistence_remove(Clients* c, char* type, int qos, int msgId);
64 void MQTTPersistence_wrapMsgID(Clients *c);
65 
66 typedef struct
67 {
68 	char struct_id[4];
69 	int struct_version;
70 	int payloadlen;
71 	void* payload;
72 	int qos;
73 	int retained;
74 	int dup;
75 	int msgid;
76 	MQTTProperties properties;
77 } MQTTPersistence_message;
78 
79 typedef struct
80 {
81 	MQTTPersistence_message* msg;
82 	char* topicName;
83 	int topicLen;
84 	unsigned int seqno; /* only used on restore */
85 } MQTTPersistence_qEntry;
86 
87 int MQTTPersistence_unpersistQueueEntry(Clients* client, MQTTPersistence_qEntry* qe);
88 int MQTTPersistence_persistQueueEntry(Clients* aclient, MQTTPersistence_qEntry* qe);
89 int MQTTPersistence_restoreMessageQueue(Clients* c);
90 #ifdef __cplusplus
91      }
92 #endif
93 
94 #endif
95