Coverage Report

Created: 2025-11-11 06:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mosquitto/plugins/dynamic-security/kicklist.c
Line
Count
Source
1
/*
2
Copyright (c) 2020-2021 Roger Light <roger@atchoo.org>
3
4
All rights reserved. This program and the accompanying materials
5
are made available under the terms of the Eclipse Public License 2.0
6
and Eclipse Distribution License v1.0 which accompany this distribution.
7
8
The Eclipse Public License is available at
9
   https://www.eclipse.org/legal/epl-2.0/
10
and the Eclipse Distribution License is available at
11
  http://www.eclipse.org/org/documents/edl-v10.php.
12
13
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
14
15
Contributors:
16
   Roger Light - initial implementation and documentation.
17
*/
18
19
#include "config.h"
20
21
#include <stdio.h>
22
#include <utlist.h>
23
24
#include "dynamic_security.h"
25
26
27
int dynsec_kicklist__add(struct dynsec__data *data, const char *username)
28
0
{
29
0
  struct dynsec__kicklist *kick;
30
0
  size_t slen;
31
32
0
  if(username){
33
0
    slen = strlen(username);
34
0
  }else{
35
0
    slen = 0;
36
0
  }
37
0
  kick = malloc(sizeof(struct dynsec__kicklist)+slen+1);
38
0
  if(!kick){
39
0
    return MOSQ_ERR_NOMEM;
40
0
  }
41
0
  if(username){
42
0
    strcpy(kick->username, username);
43
0
  }else{
44
0
    kick->username[0] = '\0';
45
0
  }
46
0
  DL_APPEND(data->kicklist, kick);
47
48
0
  return MOSQ_ERR_SUCCESS;
49
0
}
50
51
52
void dynsec_kicklist__kick(struct dynsec__data *data)
53
0
{
54
0
  struct dynsec__kicklist *kick, *tmp;
55
56
0
  DL_FOREACH_SAFE(data->kicklist, kick, tmp){
57
0
    DL_DELETE(data->kicklist, kick);
58
0
    if(strlen(kick->username)){
59
0
      mosquitto_kick_client_by_username(kick->username, false);
60
0
    }else{
61
0
      mosquitto_kick_client_by_username(NULL, false);
62
0
    }
63
0
    free(kick);
64
0
  }
65
0
}
66
67
68
void dynsec_kicklist__cleanup(struct dynsec__data *data)
69
5.78k
{
70
5.78k
  struct dynsec__kicklist *kick, *tmp;
71
72
5.78k
  DL_FOREACH_SAFE(data->kicklist, kick, tmp){
73
0
    DL_DELETE(data->kicklist, kick);
74
0
    free(kick);
75
0
  }
76
5.78k
}