Split plugin code to separate files.
parent
06dc2f41f8
commit
a199878fb3
@ -0,0 +1,48 @@
|
||||
/*
|
||||
Copyright (c) 2016-2021 Roger Light <roger@atchoo.org>
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License 2.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
https://www.eclipse.org/legal/epl-2.0/
|
||||
and the Eclipse Distribution License is available at
|
||||
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
|
||||
Contributors:
|
||||
Roger Light - initial implementation and documentation.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "mosquitto_broker_internal.h"
|
||||
#include "mosquitto_internal.h"
|
||||
#include "utlist.h"
|
||||
|
||||
|
||||
static void plugin__handle_connect_single(struct mosquitto__security_options *opts, struct mosquitto *context)
|
||||
{
|
||||
struct mosquitto_evt_connect event_data;
|
||||
struct mosquitto__callback *cb_base;
|
||||
|
||||
memset(&event_data, 0, sizeof(event_data));
|
||||
event_data.client = context;
|
||||
DL_FOREACH(opts->plugin_callbacks.connect, cb_base){
|
||||
cb_base->cb(MOSQ_EVT_CONNECT, &event_data, cb_base->userdata);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void plugin__handle_connect(struct mosquitto *context)
|
||||
{
|
||||
/* Global plugins */
|
||||
plugin__handle_connect_single(&db.config->security_options, context);
|
||||
|
||||
/* Per listener plugins */
|
||||
if(db.config->per_listener_settings && context->listener){
|
||||
plugin__handle_connect_single(&context->listener->security_options, context);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
Copyright (c) 2016-2021 Roger Light <roger@atchoo.org>
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License 2.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
https://www.eclipse.org/legal/epl-2.0/
|
||||
and the Eclipse Distribution License is available at
|
||||
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
|
||||
Contributors:
|
||||
Roger Light - initial implementation and documentation.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "mosquitto_broker_internal.h"
|
||||
#include "utlist.h"
|
||||
|
||||
|
||||
static void plugin__handle_disconnect_single(struct mosquitto__security_options *opts, struct mosquitto *context, int reason)
|
||||
{
|
||||
struct mosquitto_evt_disconnect event_data;
|
||||
struct mosquitto__callback *cb_base;
|
||||
|
||||
if(context->id == NULL) return;
|
||||
|
||||
memset(&event_data, 0, sizeof(event_data));
|
||||
event_data.client = context;
|
||||
event_data.reason = reason;
|
||||
DL_FOREACH(opts->plugin_callbacks.disconnect, cb_base){
|
||||
cb_base->cb(MOSQ_EVT_DISCONNECT, &event_data, cb_base->userdata);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void plugin__handle_disconnect(struct mosquitto *context, int reason)
|
||||
{
|
||||
/* Global plugins */
|
||||
plugin__handle_disconnect_single(&db.config->security_options, context, reason);
|
||||
|
||||
/* Per listener plugins */
|
||||
if(db.config->per_listener_settings && context->listener){
|
||||
plugin__handle_disconnect_single(&context->listener->security_options, context, reason);
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
Copyright (c) 2016-2021 Roger Light <roger@atchoo.org>
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License 2.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
https://www.eclipse.org/legal/epl-2.0/
|
||||
and the Eclipse Distribution License is available at
|
||||
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
|
||||
Contributors:
|
||||
Roger Light - initial implementation and documentation.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "mosquitto_broker_internal.h"
|
||||
#include "memory_mosq.h"
|
||||
#include "utlist.h"
|
||||
|
||||
|
||||
static int plugin__handle_message_single(struct mosquitto__security_options *opts, struct mosquitto *context, struct mosquitto_msg_store *stored)
|
||||
{
|
||||
struct mosquitto_evt_message event_data;
|
||||
struct mosquitto__callback *cb_base;
|
||||
int rc = MOSQ_ERR_SUCCESS;
|
||||
|
||||
memset(&event_data, 0, sizeof(event_data));
|
||||
event_data.client = context;
|
||||
event_data.topic = stored->topic;
|
||||
event_data.payloadlen = stored->payloadlen;
|
||||
event_data.payload = stored->payload;
|
||||
event_data.qos = stored->qos;
|
||||
event_data.retain = stored->retain;
|
||||
event_data.properties = stored->properties;
|
||||
|
||||
DL_FOREACH(opts->plugin_callbacks.message, cb_base){
|
||||
rc = cb_base->cb(MOSQ_EVT_MESSAGE, &event_data, cb_base->userdata);
|
||||
if(rc != MOSQ_ERR_SUCCESS){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
stored->topic = event_data.topic;
|
||||
if(stored->payload != event_data.payload){
|
||||
mosquitto__free(stored->payload);
|
||||
stored->payload = event_data.payload;
|
||||
stored->payloadlen = event_data.payloadlen;
|
||||
}
|
||||
stored->retain = event_data.retain;
|
||||
stored->properties = event_data.properties;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int plugin__handle_message(struct mosquitto *context, struct mosquitto_msg_store *stored)
|
||||
{
|
||||
int rc = MOSQ_ERR_SUCCESS;
|
||||
|
||||
/* Global plugins */
|
||||
rc = plugin__handle_message_single(&db.config->security_options,
|
||||
context, stored);
|
||||
if(rc) return rc;
|
||||
|
||||
if(db.config->per_listener_settings && context->listener){
|
||||
rc = plugin__handle_message_single(&context->listener->security_options,
|
||||
context, stored);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
Copyright (c) 2016-2021 Roger Light <roger@atchoo.org>
|
||||
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the Eclipse Public License 2.0
|
||||
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
|
||||
The Eclipse Public License is available at
|
||||
https://www.eclipse.org/legal/epl-2.0/
|
||||
and the Eclipse Distribution License is available at
|
||||
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
|
||||
|
||||
Contributors:
|
||||
Roger Light - initial implementation and documentation.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "mosquitto_broker_internal.h"
|
||||
#include "mosquitto_broker.h"
|
||||
#include "time_mosq.h"
|
||||
#include "utlist.h"
|
||||
|
||||
|
||||
static void plugin__handle_tick_single(struct mosquitto__security_options *opts)
|
||||
{
|
||||
struct mosquitto_evt_tick event_data;
|
||||
struct mosquitto__callback *cb_base;
|
||||
|
||||
memset(&event_data, 0, sizeof(event_data));
|
||||
|
||||
DL_FOREACH(opts->plugin_callbacks.tick, cb_base){
|
||||
mosquitto_time_ns(&event_data.now_s, &event_data.now_ns);
|
||||
event_data.next_s = 0;
|
||||
event_data.next_ms = 0;
|
||||
cb_base->cb(MOSQ_EVT_TICK, &event_data, cb_base->userdata);
|
||||
loop__update_next_event(event_data.next_s * 1000 + event_data.next_ms);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void plugin__handle_tick(void)
|
||||
{
|
||||
struct mosquitto__security_options *opts;
|
||||
int i;
|
||||
|
||||
/* FIXME - set now_s and now_ns to avoid need for multiple time lookups */
|
||||
if(db.config->per_listener_settings){
|
||||
for(i=0; i<db.config->listener_count; i++){
|
||||
opts = &db.config->listeners[i].security_options;
|
||||
if(opts && opts->plugin_callbacks.tick){
|
||||
plugin__handle_tick_single(opts);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
plugin__handle_tick_single(&db.config->security_options);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue