Coverage Report

Created: 2025-08-29 06:53

/src/opensips/mi/mi_trace.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2016 - 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 *
20
 *
21
 * History:
22
 * -------
23
 *  2016-09-19  first version (Ionut Ionita)
24
 */
25
#ifndef _mi_trace_h
26
#define _mi_trace_h
27
28
#include "../trace_api.h"
29
30
extern trace_proto_t* mi_trace_api;
31
extern int correlation_id, correlation_vendor;
32
extern str correlation_value;
33
34
#define MAX_TRACE_FIELD (1 << 7)
35
36
struct mi_trace_req {
37
  str cmd;
38
  str backend;
39
  char params[MAX_TRACE_FIELD];
40
};
41
42
extern str mi_trpl;
43
44
enum mi_trace_type { MI_TRACE_REQ, MI_TRACE_RPL};
45
46
struct mi_trace_param {
47
  enum mi_trace_type type;
48
  union {
49
    struct mi_trace_req* req;
50
    str *rpl;
51
  } d;
52
};
53
54
extern struct mi_trace_param mi_tparam;
55
56
void try_load_trace_api(void);
57
58
int trace_mi_message(const union sockaddr_union* src, const union sockaddr_union* dst,
59
  struct mi_trace_param* pld_param, str* correlation_value, trace_dest trace_dst);
60
61
struct mi_trace_req* build_mi_trace_request(str *cmd, mi_item_t *params,
62
                    str* backend);
63
64
str *build_mi_trace_reply(str *rpl_msg);
65
char* generate_correlation_id(int* len);;
66
int load_correlation_id(void);
67
68
static inline void mi_trace_reply( const union sockaddr_union* src, const union sockaddr_union* dst,
69
    str* message, trace_dest t_dst)
70
0
{
71
0
  /* trace disabled */
72
0
  if ( !t_dst )
73
0
    return;
74
0
75
0
  if (!message) {
76
0
    LM_ERR("Empty MI reply!\n");
77
0
    return;
78
0
  }
79
0
80
0
  mi_tparam.d.rpl = build_mi_trace_reply(message);
81
0
  mi_tparam.type = MI_TRACE_RPL;
82
0
83
0
  if ( !correlation_value.s ) {
84
0
    LM_ERR("can't find correlation id generated by the request!\n");
85
0
    return;
86
0
  }
87
0
88
0
  if (trace_mi_message( src, dst, &mi_tparam, &correlation_value, t_dst) < 0) {
89
0
    LM_ERR("failed to trace mi command reply!\n");
90
0
  }
91
0
}
92
93
94
static inline void mi_trace_request( const union sockaddr_union* src, const union sockaddr_union* dst,
95
    char* command, int len, mi_item_t *params, str* backend, trace_dest t_dst )
96
0
{
97
0
  str comm_s = { command, len };
98
0
99
0
  if ( !t_dst || !backend )
100
0
    return;
101
0
102
0
  mi_tparam.d.req = build_mi_trace_request( &comm_s, params, backend);
103
0
  if (!mi_tparam.d.req) {
104
0
    LM_ERR("Failed to prepare payload for tracing request\n");
105
0
    return;
106
0
  }
107
0
  mi_tparam.type = MI_TRACE_REQ;
108
0
109
0
  correlation_value.s = generate_correlation_id(&correlation_value.len);
110
0
111
0
  if ( !correlation_value.s ) {
112
0
    LM_ERR("failed to generate correlation id!\n");
113
0
    return;
114
0
  }
115
0
116
0
  if (trace_mi_message( src, dst, &mi_tparam, &correlation_value, t_dst) < 0) {
117
0
    LM_ERR("failed to trace mi command request!\n");
118
0
  }
119
0
}
120
121
int register_mi_trace_mod(void);
122
int init_mod_trace_cmds(int id, int white);
123
124
int block_mi_cmd_trace(int id, char* name, int len);
125
int allow_mi_cmd_trace(int id, char* name, int len);
126
unsigned char is_mi_cmd_traced(int id, struct mi_cmd* cmd);
127
int parse_mi_cmd_bwlist(int id, char* bw_string, int len);
128
129
130
131
#endif