MQTTPersistence.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #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 async client message queue */
  43. #define PERSISTENCE_QUEUE_KEY "q-"
  44. /** Stem of the key for an MQTT V5 message queue */
  45. #define PERSISTENCE_V5_QUEUE_KEY "q5-"
  46. #define PERSISTENCE_MAX_KEY_LENGTH 8
  47. int MQTTPersistence_create(MQTTClient_persistence** per, int type, void* pcontext);
  48. int MQTTPersistence_initialize(Clients* c, const char* serverURI);
  49. int MQTTPersistence_close(Clients* c);
  50. int MQTTPersistence_clear(Clients* c);
  51. int MQTTPersistence_restore(Clients* c);
  52. void* MQTTPersistence_restorePacket(int MQTTVersion, char* buffer, size_t buflen);
  53. void MQTTPersistence_insertInOrder(List* list, void* content, size_t size);
  54. int MQTTPersistence_put(int socket, char* buf0, size_t buf0len, int count,
  55. char** buffers, size_t* buflens, int htype, int msgId, int scr, int MQTTVersion);
  56. int MQTTPersistence_remove(Clients* c, char* type, int qos, int msgId);
  57. void MQTTPersistence_wrapMsgID(Clients *c);
  58. typedef struct
  59. {
  60. char struct_id[4];
  61. int struct_version;
  62. int payloadlen;
  63. void* payload;
  64. int qos;
  65. int retained;
  66. int dup;
  67. int msgid;
  68. MQTTProperties properties;
  69. } MQTTPersistence_message;
  70. typedef struct
  71. {
  72. MQTTPersistence_message* msg;
  73. char* topicName;
  74. int topicLen;
  75. unsigned int seqno; /* only used on restore */
  76. } MQTTPersistence_qEntry;
  77. int MQTTPersistence_unpersistQueueEntry(Clients* client, MQTTPersistence_qEntry* qe);
  78. int MQTTPersistence_persistQueueEntry(Clients* aclient, MQTTPersistence_qEntry* qe);
  79. int MQTTPersistence_restoreMessageQueue(Clients* c);
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. #endif