Coverage Report

Created: 2025-09-04 06:10

/src/mosquitto/src/plugin_subscribe.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
Copyright (c) 2016-2022 Roger Light <roger@atchoo.org>
3
Copyright (c) 2022 Cedalo GmbH
4
5
All rights reserved. This program and the accompanying materials
6
are made available under the terms of the Eclipse Public License 2.0
7
and Eclipse Distribution License v1.0 which accompany this distribution.
8
9
The Eclipse Public License is available at
10
   https://www.eclipse.org/legal/epl-2.0/
11
and the Eclipse Distribution License is available at
12
  http://www.eclipse.org/org/documents/edl-v10.php.
13
14
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
15
16
Contributors:
17
   Roger Light - initial implementation and documentation.
18
*/
19
20
#include "config.h"
21
22
#include "mosquitto_broker_internal.h"
23
#include "utlist.h"
24
25
26
static int plugin__handle_subscribe_single(struct mosquitto__security_options *opts, struct mosquitto *context, struct mosquitto_subscription *sub)
27
0
{
28
0
  struct mosquitto_evt_subscribe event_data;
29
0
  struct mosquitto__callback *cb_base, *cb_next;
30
0
  int rc = MOSQ_ERR_SUCCESS;
31
32
0
  memset(&event_data, 0, sizeof(event_data));
33
0
  event_data.client = context;
34
0
  event_data.data.topic_filter = sub->topic_filter;
35
0
  event_data.data.options = sub->options;
36
0
  event_data.data.identifier = sub->identifier;
37
0
  event_data.data.properties = sub->properties;
38
39
0
  DL_FOREACH_SAFE(opts->plugin_callbacks.subscribe, cb_base, cb_next){
40
0
    rc = cb_base->cb(MOSQ_EVT_SUBSCRIBE, &event_data, cb_base->userdata);
41
0
    if(rc != MOSQ_ERR_SUCCESS){
42
0
      break;
43
0
    }
44
45
0
    if(sub->topic_filter != event_data.data.topic_filter){
46
0
      mosquitto_free(sub->topic_filter);
47
0
      sub->topic_filter = event_data.data.topic_filter;
48
0
    }
49
0
  }
50
0
  sub->options = event_data.data.options;
51
52
0
  return rc;
53
0
}
54
55
56
int plugin__handle_subscribe(struct mosquitto *context, struct mosquitto_subscription *sub)
57
0
{
58
0
  int rc = MOSQ_ERR_SUCCESS;
59
60
  /* Global plugins */
61
0
  rc = plugin__handle_subscribe_single(&db.config->security_options, context, sub);
62
0
  if(rc) return rc;
63
64
0
  if(db.config->per_listener_settings && context->listener){
65
0
    rc = plugin__handle_subscribe_single(context->listener->security_options, context, sub);
66
0
  }
67
68
0
  return rc;
69
0
}