2020-09-10 14:32:47 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <mqtt_protocol.h>
|
|
|
|
#include <mosquitto.h>
|
|
|
|
#include <mosquitto_broker.h>
|
|
|
|
#include <mosquitto_plugin.h>
|
|
|
|
|
2020-09-22 10:19:05 +00:00
|
|
|
static mosquitto_plugin_id_t *plg_id = NULL;
|
|
|
|
|
|
|
|
int control_callback(int event, void *event_data, void *userdata)
|
2020-09-10 14:32:47 +00:00
|
|
|
{
|
2020-09-22 10:19:05 +00:00
|
|
|
struct mosquitto_evt_control *ed = event_data;
|
|
|
|
|
|
|
|
mosquitto_broker_publish_copy(NULL, ed->topic, ed->payloadlen, ed->payload, 0, 0, NULL);
|
2020-09-10 14:32:47 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-22 10:19:05 +00:00
|
|
|
int mosquitto_plugin_version(void)
|
2020-09-10 14:32:47 +00:00
|
|
|
{
|
2020-09-22 10:19:05 +00:00
|
|
|
return MOSQ_PLUGIN_VERSION;
|
2020-09-10 14:32:47 +00:00
|
|
|
}
|
|
|
|
|
2020-09-22 10:19:05 +00:00
|
|
|
int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, void **user_data, struct mosquitto_opt *auth_opts, int auth_opt_count)
|
2020-09-10 14:32:47 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char buf[100];
|
|
|
|
|
2020-09-22 10:19:05 +00:00
|
|
|
plg_id = identifier;
|
|
|
|
|
2020-09-10 14:32:47 +00:00
|
|
|
for(i=0; i<100; i++){
|
|
|
|
snprintf(buf, sizeof(buf), "$CONTROL/user-management/v%d", i);
|
2020-09-22 10:19:05 +00:00
|
|
|
mosquitto_callback_register(plg_id, MOSQ_EVT_CONTROL, control_callback, "$CONTROL/user-management/v1", NULL);
|
2020-09-10 14:32:47 +00:00
|
|
|
}
|
|
|
|
return MOSQ_ERR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-09-22 10:19:05 +00:00
|
|
|
int mosquitto_plugin_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count)
|
2020-09-10 14:32:47 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char buf[100];
|
|
|
|
|
|
|
|
for(i=0; i<100; i++){
|
|
|
|
snprintf(buf, sizeof(buf), "$CONTROL/user-management/v%d", i);
|
2020-09-22 10:19:05 +00:00
|
|
|
mosquitto_callback_unregister(plg_id, MOSQ_EVT_CONTROL, control_callback, "$CONTROL/user-management/v1");
|
2020-09-10 14:32:47 +00:00
|
|
|
}
|
|
|
|
return MOSQ_ERR_SUCCESS;
|
|
|
|
}
|