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/details.c
Line
Count
Source
1
/*
2
Copyright (c) 2025 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 <cjson/cJSON.h>
22
#include <stdio.h>
23
#include <uthash.h>
24
25
#include "dynamic_security.h"
26
#include "json_help.h"
27
28
29
int dynsec_details__process_get(struct dynsec__data *data, struct mosquitto_control_cmd *cmd)
30
0
{
31
0
  cJSON *tree, *j_data;
32
0
  const char *admin_clientid, *admin_username;
33
34
0
  tree = cJSON_CreateObject();
35
0
  if(tree == NULL
36
0
      || cJSON_AddStringToObject(tree, "command", "getDetails") == NULL
37
0
      || (j_data = cJSON_AddObjectToObject(tree, "data")) == NULL
38
0
      || (cmd->correlation_data && cJSON_AddStringToObject(tree, "correlationData", cmd->correlation_data) == NULL)
39
0
      || cJSON_AddIntToObject(j_data, "clientCount", (int)HASH_CNT(hh, data->clients)) == NULL
40
0
      || cJSON_AddIntToObject(j_data, "groupCount", (int)HASH_CNT(hh, data->groups)) == NULL
41
0
      || cJSON_AddIntToObject(j_data, "roleCount", (int)HASH_CNT(hh, data->roles)) == NULL
42
0
      || cJSON_AddIntToObject(j_data, "changeIndex", data->changeindex) == NULL
43
0
      ){
44
45
0
    cJSON_Delete(tree);
46
0
    mosquitto_control_command_reply(cmd, "Internal error");
47
0
    return MOSQ_ERR_NOMEM;
48
0
  }
49
0
  cJSON_AddItemToArray(cmd->j_responses, tree);
50
51
0
  admin_clientid = mosquitto_client_id(cmd->client);
52
0
  admin_username = mosquitto_client_username(cmd->client);
53
0
  mosquitto_log_printf(MOSQ_LOG_INFO, "dynsec: %s/%s | getDetails",
54
0
      admin_clientid, admin_username);
55
56
0
  return MOSQ_ERR_SUCCESS;
57
0
}