Coverage Report

Created: 2025-07-11 06:28

/src/opensips/cmds.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2019 OpenSIPS Solutions
3
 *
4
 * This file is part of opensips, a free SIP server.
5
 *
6
 * opensips is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version
10
 *
11
 * opensips is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19
 *
20
 */
21
22
#include "cmds.h"
23
24
const cmd_export_t* find_cmd_export_t(const char* name, int flags)
25
0
{
26
0
  const cmd_export_t* cmd;
27
28
0
  cmd = find_core_cmd_export_t(name, flags);
29
0
  if (!cmd)
30
0
    cmd = find_mod_cmd_export_t(name, flags);
31
32
0
  return cmd;
33
0
}
34
35
/* Checks if the module function is called with the right number of parameters
36
 * and all mandatory parameters are given
37
 * Return:
38
 *  0 - correct call
39
 * -1 - too few parameters
40
 * -2 - too many parameters
41
 * -3 - mandatory parameter omitted
42
 */
43
int check_cmd_call_params(const cmd_export_t *cmd, action_elem_t *elems, int no_params)
44
0
{
45
0
  const struct cmd_param *param;
46
0
  int n=0, m=0, i;
47
48
0
  for (param=cmd->params; param->flags; param++, n++)
49
0
    if (!(param->flags & CMD_PARAM_OPT))
50
0
      m = n+1;
51
52
0
  if (no_params < m)  /* check the minimum number of arguments for the call,
53
             * including optional params that must be explicitly omitted */
54
0
    return -1;
55
0
  else if (no_params > n)
56
0
    return -2;
57
58
0
  for (i=1, param=cmd->params; i<=no_params; i++, param++)
59
0
    if (!(param->flags & CMD_PARAM_OPT) && elems[i].type == NULLV_ST)
60
0
      return -3;
61
62
0
  return 0;
63
0
}
64
65
/* simillar function to check_cmd_call_params but for async cmds */
66
int check_acmd_call_params(const acmd_export_t *acmd, action_elem_t *elems, int no_params)
67
0
{
68
0
  const struct cmd_param *param;
69
0
  int n=0, m=0, i;
70
71
0
  for (param=acmd->params; param->flags; param++, n++)
72
0
    if (!(param->flags & CMD_PARAM_OPT))
73
0
      m = n+1;
74
75
0
  if (no_params < m)  /* check the minimum number of arguments for the call,
76
             * including optional params that must be explicitly omitted */
77
0
    return -1;
78
0
  else if (no_params > n)
79
0
    return -2;
80
81
0
  for (i=1, param=acmd->params; i<=no_params; i++, param++)
82
0
    if (!(param->flags & CMD_PARAM_OPT) && elems[i].type == NULLV_ST)
83
0
      return -3;
84
85
0
  return 0;
86
0
}