auth_plugin_publish.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <mqtt_protocol.h>
  4. #include <mosquitto.h>
  5. #include <mosquitto_broker.h>
  6. #include <mosquitto_plugin.h>
  7. int mosquitto_auth_plugin_version(void)
  8. {
  9. return 4;
  10. }
  11. int mosquitto_auth_plugin_init(void **user_data, struct mosquitto_opt *auth_opts, int auth_opt_count)
  12. {
  13. return MOSQ_ERR_SUCCESS;
  14. }
  15. int mosquitto_auth_plugin_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count)
  16. {
  17. return MOSQ_ERR_SUCCESS;
  18. }
  19. int mosquitto_auth_security_init(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload)
  20. {
  21. return MOSQ_ERR_SUCCESS;
  22. }
  23. int mosquitto_auth_security_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count, bool reload)
  24. {
  25. return MOSQ_ERR_SUCCESS;
  26. }
  27. int mosquitto_auth_acl_check(void *user_data, int access, struct mosquitto *client, const struct mosquitto_acl_msg *msg)
  28. {
  29. static int count = 0;
  30. mosquitto_property *props = NULL;
  31. if(access == MOSQ_ACL_WRITE){
  32. if(count == 0){
  33. /* "missing-client" isn't connected, so we can check memory usage properly. */
  34. mosquitto_broker_publish_copy("missing-client", "topic/2", strlen("test-message-2"), "test-message-2", 2, true, NULL);
  35. mosquitto_broker_publish_copy("test-client", "topic/0", strlen("test-message-0"), "test-message-0", 0, true, NULL);
  36. mosquitto_broker_publish_copy("missing-client", "topic/2", strlen("test-message-2"), "test-message-2", 2, true, NULL);
  37. mosquitto_broker_publish_copy("test-client", "topic/1", strlen("test-message-1"), "test-message-1", 1, true, NULL);
  38. mosquitto_broker_publish_copy("missing-client", "topic/2", strlen("test-message-2"), "test-message-2", 2, true, NULL);
  39. mosquitto_broker_publish_copy("test-client", "topic/2", strlen("test-message-2"), "test-message-2", 2, true, NULL);
  40. count = 1;
  41. }else{
  42. mosquitto_property_add_byte(&props, MQTT_PROP_PAYLOAD_FORMAT_INDICATOR, 1);
  43. mosquitto_broker_publish_copy("test-client", "topic/0", strlen("test-message-0"), "test-message-0", 0, true, props);
  44. props = NULL;
  45. mosquitto_property_add_byte(&props, MQTT_PROP_PAYLOAD_FORMAT_INDICATOR, 1);
  46. mosquitto_broker_publish_copy("test-client", "topic/1", strlen("test-message-1"), "test-message-1", 1, true, props);
  47. props = NULL;
  48. mosquitto_property_add_byte(&props, MQTT_PROP_PAYLOAD_FORMAT_INDICATOR, 1);
  49. mosquitto_broker_publish_copy("test-client", "topic/2", strlen("test-message-2"), "test-message-2", 2, true, props);
  50. }
  51. }
  52. return MOSQ_ERR_SUCCESS;
  53. }
  54. int mosquitto_auth_unpwd_check(void *user_data, struct mosquitto *client, const char *username, const char *password)
  55. {
  56. return MOSQ_ERR_SUCCESS;
  57. }
  58. int mosquitto_auth_psk_key_get(void *user_data, struct mosquitto *client, const char *hint, const char *identity, char *key, int max_key_len)
  59. {
  60. return MOSQ_ERR_AUTH;
  61. }