MQTTPersistence.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #if !defined(MQTTPERSISTENCE_H)
  20. #define MQTTPERSISTENCE_H
  21. #if defined(__cplusplus)
  22. extern "C" {
  23. #endif
  24. #include "Clients.h"
  25. #include "MQTTProperties.h"
  26. /** Stem of the key for a sent PUBLISH QoS1 or QoS2 */
  27. #define PERSISTENCE_PUBLISH_SENT "s-"
  28. /** Stem of the key for a sent PUBREL */
  29. #define PERSISTENCE_PUBREL "sc-"
  30. /** Stem of the key for a received PUBLISH QoS2 */
  31. #define PERSISTENCE_PUBLISH_RECEIVED "r-"
  32. /** Stem of the key for a sent MQTT V5 PUBLISH QoS1 or QoS2 */
  33. #define PERSISTENCE_V5_PUBLISH_SENT "s5-"
  34. /** Stem of the key for a sent MQTT V5 PUBREL */
  35. #define PERSISTENCE_V5_PUBREL "sc5-"
  36. /** Stem of the key for a received MQTT V5 PUBLISH QoS2 */
  37. #define PERSISTENCE_V5_PUBLISH_RECEIVED "r5-"
  38. /** Stem of the key for an async client command */
  39. #define PERSISTENCE_COMMAND_KEY "c-"
  40. /** Stem of the key for an MQTT V5 async client command */
  41. #define PERSISTENCE_V5_COMMAND_KEY "c5-"
  42. /** Stem of the key for an client incoming message queue */
  43. #define PERSISTENCE_QUEUE_KEY "q-"
  44. /** Stem of the key for an MQTT V5 incoming message queue */
  45. #define PERSISTENCE_V5_QUEUE_KEY "q5-"
  46. /** Maximum length of a stem for a persistence key */
  47. #define PERSISTENCE_MAX_STEM_LENGTH 4
  48. /** Maximum allowed length of a persistence key */
  49. #define PERSISTENCE_MAX_KEY_LENGTH 10
  50. /** Maximum size of an integer sequence number appended to a persistence key */
  51. #define PERSISTENCE_SEQNO_LIMIT 1000000 /*10^(PERSISTENCE_MAX_KEY_LENGTH - PERSISTENCE_MAX_STEM_LENGTH)*/
  52. int MQTTPersistence_create(MQTTClient_persistence** per, int type, void* pcontext);
  53. int MQTTPersistence_initialize(Clients* c, const char* serverURI);
  54. int MQTTPersistence_close(Clients* c);
  55. int MQTTPersistence_clear(Clients* c);
  56. int MQTTPersistence_restorePackets(Clients* c);
  57. void* MQTTPersistence_restorePacket(int MQTTVersion, char* buffer, size_t buflen);
  58. void MQTTPersistence_insertInOrder(List* list, void* content, size_t size);
  59. int MQTTPersistence_putPacket(SOCKET socket, char* buf0, size_t buf0len, int count,
  60. char** buffers, size_t* buflens, int htype, int msgId, int scr, int MQTTVersion);
  61. int MQTTPersistence_remove(Clients* c, char* type, int qos, int msgId);
  62. void MQTTPersistence_wrapMsgID(Clients *c);
  63. typedef struct
  64. {
  65. char struct_id[4];
  66. int struct_version;
  67. int payloadlen;
  68. void* payload;
  69. int qos;
  70. int retained;
  71. int dup;
  72. int msgid;
  73. MQTTProperties properties;
  74. } MQTTPersistence_message;
  75. typedef struct
  76. {
  77. MQTTPersistence_message* msg;
  78. char* topicName;
  79. int topicLen;
  80. unsigned int seqno; /* only used on restore */
  81. } MQTTPersistence_qEntry;
  82. int MQTTPersistence_unpersistQueueEntry(Clients* client, MQTTPersistence_qEntry* qe);
  83. int MQTTPersistence_persistQueueEntry(Clients* aclient, MQTTPersistence_qEntry* qe);
  84. int MQTTPersistence_restoreMessageQueue(Clients* c);
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88. #endif