persist_read_stubs.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #include <time.h>
  2. #define WITH_BROKER
  3. #include <logging_mosq.h>
  4. #include <memory_mosq.h>
  5. #include <mosquitto_broker_internal.h>
  6. #include <net_mosq.h>
  7. #include <send_mosq.h>
  8. #include <time_mosq.h>
  9. extern char *last_sub;
  10. extern int last_qos;
  11. extern uint32_t last_identifier;
  12. extern struct mosquitto_db db;
  13. struct mosquitto *context__init(mosq_sock_t sock)
  14. {
  15. struct mosquitto *m;
  16. UNUSED(sock);
  17. m = mosquitto__calloc(1, sizeof(struct mosquitto));
  18. if(m){
  19. m->msgs_in.inflight_maximum = 20;
  20. m->msgs_out.inflight_maximum = 20;
  21. m->msgs_in.inflight_quota = 20;
  22. m->msgs_out.inflight_quota = 20;
  23. }
  24. return m;
  25. }
  26. void db__msg_store_free(struct mosquitto_msg_store *store)
  27. {
  28. int i;
  29. mosquitto__free(store->source_id);
  30. mosquitto__free(store->source_username);
  31. if(store->dest_ids){
  32. for(i=0; i<store->dest_id_count; i++){
  33. mosquitto__free(store->dest_ids[i]);
  34. }
  35. mosquitto__free(store->dest_ids);
  36. }
  37. mosquitto__free(store->topic);
  38. mosquitto_property_free_all(&store->properties);
  39. mosquitto__free(store->payload);
  40. mosquitto__free(store);
  41. }
  42. int db__message_store(const struct mosquitto *source, struct mosquitto_msg_store *stored, uint32_t message_expiry_interval, dbid_t store_id, enum mosquitto_msg_origin origin)
  43. {
  44. int rc = MOSQ_ERR_SUCCESS;
  45. UNUSED(origin);
  46. if(source && source->id){
  47. stored->source_id = mosquitto__strdup(source->id);
  48. }else{
  49. stored->source_id = mosquitto__strdup("");
  50. }
  51. if(!stored->source_id){
  52. rc = MOSQ_ERR_NOMEM;
  53. goto error;
  54. }
  55. if(source && source->username){
  56. stored->source_username = mosquitto__strdup(source->username);
  57. if(!stored->source_username){
  58. rc = MOSQ_ERR_NOMEM;
  59. goto error;
  60. }
  61. }
  62. if(source){
  63. stored->source_listener = source->listener;
  64. }
  65. stored->mid = 0;
  66. if(message_expiry_interval > 0){
  67. stored->message_expiry_time = time(NULL) + message_expiry_interval;
  68. }else{
  69. stored->message_expiry_time = 0;
  70. }
  71. stored->dest_ids = NULL;
  72. stored->dest_id_count = 0;
  73. db.msg_store_count++;
  74. db.msg_store_bytes += stored->payloadlen;
  75. if(!store_id){
  76. stored->db_id = ++db.last_db_id;
  77. }else{
  78. stored->db_id = store_id;
  79. }
  80. db.msg_store = stored;
  81. return MOSQ_ERR_SUCCESS;
  82. error:
  83. db__msg_store_free(stored);
  84. return rc;
  85. }
  86. int log__printf(struct mosquitto *mosq, unsigned int priority, const char *fmt, ...)
  87. {
  88. UNUSED(mosq);
  89. UNUSED(priority);
  90. UNUSED(fmt);
  91. return 0;
  92. }
  93. time_t mosquitto_time(void)
  94. {
  95. return 123;
  96. }
  97. int net__socket_close(struct mosquitto *mosq)
  98. {
  99. UNUSED(mosq);
  100. return MOSQ_ERR_SUCCESS;
  101. }
  102. int send__pingreq(struct mosquitto *mosq)
  103. {
  104. UNUSED(mosq);
  105. return MOSQ_ERR_SUCCESS;
  106. }
  107. int mosquitto_acl_check(struct mosquitto *context, const char *topic, uint32_t payloadlen, void* payload, uint8_t qos, bool retain, int access)
  108. {
  109. UNUSED(context);
  110. UNUSED(topic);
  111. UNUSED(payloadlen);
  112. UNUSED(payload);
  113. UNUSED(qos);
  114. UNUSED(retain);
  115. UNUSED(access);
  116. return MOSQ_ERR_SUCCESS;
  117. }
  118. int acl__find_acls(struct mosquitto *context)
  119. {
  120. UNUSED(context);
  121. return MOSQ_ERR_SUCCESS;
  122. }
  123. int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t identifier, int options, struct mosquitto__subhier **root)
  124. {
  125. UNUSED(context);
  126. UNUSED(options);
  127. UNUSED(root);
  128. last_sub = strdup(sub);
  129. last_qos = qos;
  130. last_identifier = identifier;
  131. return MOSQ_ERR_SUCCESS;
  132. }
  133. int db__message_insert(struct mosquitto *context, uint16_t mid, enum mosquitto_msg_direction dir, uint8_t qos, bool retain, struct mosquitto_msg_store *stored, mosquitto_property *properties, bool update)
  134. {
  135. UNUSED(context);
  136. UNUSED(mid);
  137. UNUSED(dir);
  138. UNUSED(qos);
  139. UNUSED(retain);
  140. UNUSED(stored);
  141. UNUSED(properties);
  142. UNUSED(update);
  143. return MOSQ_ERR_SUCCESS;
  144. }
  145. void db__msg_store_ref_dec(struct mosquitto_msg_store **store)
  146. {
  147. UNUSED(store);
  148. }
  149. void db__msg_store_ref_inc(struct mosquitto_msg_store *store)
  150. {
  151. store->ref_count++;
  152. }
  153. void db__msg_add_to_inflight_stats(struct mosquitto_msg_data *msg_data, struct mosquitto_client_msg *msg)
  154. {
  155. UNUSED(msg_data);
  156. UNUSED(msg);
  157. }
  158. void db__msg_add_to_queued_stats(struct mosquitto_msg_data *msg_data, struct mosquitto_client_msg *msg)
  159. {
  160. UNUSED(msg_data);
  161. UNUSED(msg);
  162. }