Skip to content

Commit

Permalink
[mi_fifo] added blacklists and whitelists for traced mi commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ionutrazvanionita authored and razvancrainea committed Jan 27, 2017
1 parent e5604b0 commit b0bf8a3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
24 changes: 15 additions & 9 deletions modules/mi_fifo/fifo_fnc.c
Expand Up @@ -61,6 +61,7 @@ static str backend = str_init("fifo");
static int volatile mi_reload_fifo = 0;

str correlation_value;
extern int mi_trace_mod_id;

FILE* mi_create_fifo(void)
{
Expand Down Expand Up @@ -435,7 +436,7 @@ static void fifo_close_async( struct mi_root *mi_rpl, struct mi_handler *hdl,
}

if (mi_rpl!=0) {
mi_write_tree( reply_stream, mi_rpl);
mi_write_tree( reply_stream, mi_rpl, 0);
free_mi_tree( mi_rpl );
} else {
mi_fifo_reply( reply_stream, "%d %.*s\n", code, reason.len, reason.s);
Expand Down Expand Up @@ -501,11 +502,12 @@ static inline struct mi_handler* build_async_handler( char *name, int len)
} \
} while(0);

#define mi_throw_error( _stream, _buf, _code, _err, ...) \
#define mi_throw_error( f, _stream, _buf, _code, _err, ...) \
do { \
mi_write_err2buf( _buf, _code, _err, __VA_ARGS__); \
mi_fifo_reply(_stream, "%d %.*s\n", _code, _buf.len, _buf.s); \
mi_trace_reply( 0, 0, _code, &_buf, 0, t_dst); \
if ( f && is_mi_cmd_traced( mi_trace_mod_id, f) ) \
mi_trace_reply( 0, 0, _code, &_buf, 0, t_dst); \
} while(0);


Expand Down Expand Up @@ -582,7 +584,7 @@ void mi_fifo_server(FILE *fifo_stream)
LM_ERR("command %s is not available\n", command);
mi_open_reply( file, reply_stream, consume1);

mi_throw_error( reply_stream, err_reason, INTERNAL_ERR_CODE,
mi_throw_error( 0, reply_stream, err_reason, INTERNAL_ERR_CODE,
consume2, "command '%s' not available", command);

goto consume2;
Expand All @@ -595,7 +597,7 @@ void mi_fifo_server(FILE *fifo_stream)
LM_ERR("failed to build async handler\n");
mi_open_reply( file, reply_stream, consume1);

mi_throw_error( reply_stream, err_reason, INTERNAL_ERR_CODE,
mi_throw_error( f, reply_stream, err_reason, INTERNAL_ERR_CODE,
consume2, "Internal server error");

goto consume2;
Expand All @@ -615,7 +617,7 @@ void mi_fifo_server(FILE *fifo_stream)
if (!reply_stream)
mi_open_reply( file, reply_stream, consume3);

mi_throw_error( reply_stream, err_reason, PARSE_ERR_CODE,
mi_throw_error( f, reply_stream, err_reason, PARSE_ERR_CODE,
consume3, "Parse error in command '%s'", command);
goto consume3;
}
Expand All @@ -624,19 +626,23 @@ void mi_fifo_server(FILE *fifo_stream)

LM_DBG("done parsing the mi tree\n");

mi_trace_request( 0, 0, command, file_sep - command, mi_cmd, &backend, t_dst);
if ( (is_mi_cmd_traced(mi_trace_mod_id, f)) ) {
mi_trace_request( 0, 0, command, file_sep - command,
mi_cmd, &backend, t_dst);
}

if ( (mi_rpl=run_mi_cmd(f, mi_cmd,
(mi_flush_f *)mi_flush_tree, reply_stream))==0 ) {
if (!reply_stream)
mi_open_reply( file, reply_stream, failure);

mi_throw_error( reply_stream, err_reason, INTERNAL_ERR_CODE,
mi_throw_error( f, reply_stream, err_reason, INTERNAL_ERR_CODE,
consume3, "command '%s' failed", command);
} else if (mi_rpl!=MI_ROOT_ASYNC_RPL) {
if (!reply_stream)
mi_open_reply( file, reply_stream, failure);
mi_write_tree( reply_stream, mi_rpl);
mi_write_tree( reply_stream, mi_rpl,
( f && is_mi_cmd_traced( mi_trace_mod_id, f) ) );

free_mi_tree( mi_rpl );
} else {
Expand Down
14 changes: 14 additions & 0 deletions modules/mi_fifo/mi_fifo.c
Expand Up @@ -66,6 +66,9 @@ static int read_buf_size = MAX_MI_FIFO_READ;
static str trace_destination_name = {NULL, 0};
trace_dest t_dst;

int mi_trace_mod_id;
char* mi_trace_bwlist_s;


static param_export_t mi_params[] = {
{"fifo_name", STR_PARAM, &mi_fifo},
Expand All @@ -77,6 +80,7 @@ static param_export_t mi_params[] = {
{"reply_dir", STR_PARAM, &mi_fifo_reply_dir},
{"reply_indent", STR_PARAM, &mi_reply_indent},
{"trace_destination", STR_PARAM, &trace_destination_name.s},
{"trace_bwlist", STR_PARAM, &mi_trace_bwlist_s },
{0,0,0}
};

Expand Down Expand Up @@ -175,6 +179,8 @@ static int mi_mod_init(void)
if (mi_trace_api && mi_trace_api->get_trace_dest_by_name) {
t_dst = mi_trace_api->get_trace_dest_by_name(&trace_destination_name);
}

mi_trace_mod_id = register_mi_trace_mod();
}

return 0;
Expand Down Expand Up @@ -228,6 +234,14 @@ static void fifo_process(int rank)
LM_ERR("can't find correlation id params!\n");
exit(-1);
}

if ( mi_trace_api && mi_trace_bwlist_s ) {
if ( parse_mi_cmd_bwlist( mi_trace_mod_id,
mi_trace_bwlist_s, strlen(mi_trace_bwlist_s) ) < 0 ) {
LM_ERR("invalid bwlist <%s>!\n", mi_trace_bwlist_s);
exit(-1);
}
}
}

mi_fifo_server( fifo_stream );
Expand Down
4 changes: 2 additions & 2 deletions modules/mi_fifo/mi_writer.c
Expand Up @@ -172,7 +172,7 @@ static int recur_write_tree(FILE *stream, struct mi_node *tree, str *buf,



int mi_write_tree(FILE *stream, struct mi_root *tree)
int mi_write_tree(FILE *stream, struct mi_root *tree, int cmd_is_traced)
{
str buf;
str code;
Expand Down Expand Up @@ -209,7 +209,7 @@ int mi_write_tree(FILE *stream, struct mi_root *tree)
*(buf.s++)='\n';
buf.len--;

if ( t_dst ) {
if ( cmd_is_traced && t_dst ) {
rpl_msg.s = mi_write_buffer;
rpl_msg.len = buf.s - mi_write_buffer;
mi_trace_reply( 0, 0, tree->code, &tree->reason, &rpl_msg, t_dst);
Expand Down
2 changes: 1 addition & 1 deletion modules/mi_fifo/mi_writer.h
Expand Up @@ -32,7 +32,7 @@
int mi_writer_init( unsigned int size, char *ident);
void mi_writer_destroy(void);

int mi_write_tree( FILE *stream, struct mi_root *tree);
int mi_write_tree( FILE *stream, struct mi_root *tree, int cmd_is_traced);
int mi_flush_tree(FILE *stream, struct mi_root *tree);

#endif /* _MI_WRITER_H_ */
Expand Down

0 comments on commit b0bf8a3

Please sign in to comment.