Skip to content

Commit

Permalink
[fraud_detection] Mi reload command fully working
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-datcu committed Sep 24, 2014
1 parent 751aa72 commit 57740d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 14 additions & 1 deletion modules/fraud_detection/fraud_detection.c
Expand Up @@ -53,6 +53,7 @@ static void destroy(void);
static int check_fraud(struct sip_msg *msg, char *user, char *number, char *pid);
static int fixup_check_fraud(void **param, int param_no);
static struct mi_root* mi_show_stats(struct mi_root *cmd_tree, void *param);
static struct mi_root* mi_reload(struct mi_root *cmd_tree, void *param);

static cmd_export_t cmds[]={
{"check_fraud", (cmd_function)check_fraud, 3, fixup_check_fraud, 0,
Expand Down Expand Up @@ -86,6 +87,7 @@ static mi_export_t mi_cmds[] = {
//{ "get_maps","return all mappings",mi_get_maps,MI_NO_INPUT_FLAG,0,0},
{"show_fraud_stats", "print current stats for a particular user",
mi_show_stats, 0, 0, 0},
{"fraud_reload", "reload fraud profiles from db", mi_reload, 0, 0, 0},
{0,0,0,0,0,0}
};

Expand Down Expand Up @@ -458,7 +460,6 @@ static struct mi_root* mi_show_stats(struct mi_root *cmd_tree, void *param)
#define ADD_STAT_CHILD(pname, pval) do {\
int val_len;\
char *cval = int2str(pval, &val_len);\
LM_INFO("xxx - %u <%.*s>\n", pval, val_len,cval);\
if (add_mi_node_child(&rpl_tree->node, MI_DUP_VALUE,\
pname ## _name.s, pname ## _name.len, cval, val_len) == 0)\
goto add_error;\
Expand All @@ -480,3 +481,15 @@ static struct mi_root* mi_show_stats(struct mi_root *cmd_tree, void *param)
free_mi_tree(rpl_tree);
return 0;
}

static struct mi_root* mi_reload(struct mi_root *cmd_tree, void *param)
{
if (frd_connect_db() != 0 || frd_reload_data() != 0) {
LM_ERR ("cannot load data from db\n");
return init_mi_tree(500, MI_INTERNAL_ERR_S, MI_INTERNAL_ERR_LEN);
}
else {
frd_disconnect_db();
return init_mi_tree(200, MI_OK_S, MI_OK_LEN);
}
}
1 change: 0 additions & 1 deletion modules/fraud_detection/frd_load.c
Expand Up @@ -414,7 +414,6 @@ static void frd_destroy_data_unsafe(dr_head_p dr_head, free_list_t *fl)

void frd_destroy_data(void)
{
LM_INFO("xxx-deleting <%p>\n", *dr_head);
frd_destroy_data_unsafe(*dr_head, free_list);
}

Expand Down

0 comments on commit 57740d7

Please sign in to comment.