/
fraud_detection.c
174 lines (148 loc) · 5.12 KB
/
fraud_detection.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "../../ut.h"
#include "../../db/db.h"
#include "../../time_rec.h"
#include "../drouting/dr_api.h"
#include "frd_stats.h"
#include "frd_load.h"
extern str db_url;
extern str table_name;
extern str rid_col;
extern str pid_col;
extern str prefix_col;
extern str start_h_col;
extern str end_h_col;
extern str days_col;
extern str cpm_thresh_warn_col;
extern str cpm_thresh_crit_col;
extern str calldur_thresh_warn_col;
extern str calldur_thresh_crit_col;
extern str totalc_thresh_warn_col;
extern str totalc_thresh_crit_col;
extern str concalls_thresh_warn_col;
extern str concalls_thresh_crit_col;
extern str seqcalls_thresh_warn_col;
extern str seqcalls_thresh_crit_col;
dr_head_p dr_head;
struct dr_binds drb;
rw_lock_t *frd_data_lock;
static int mod_init(void);
static int child_init(int);
static void destroy(void);
static cmd_export_t cmds[]={
/* {"get_mapping",(cmd_function)get_mapping,1,fixup_pvar_null,
0, REQUEST_ROUTE|ONREPLY_ROUTE},
{"get_mapping",(cmd_function)get_mapping0,0,0,
0, REQUEST_ROUTE|ONREPLY_ROUTE},*/
{0,0,0,0,0,0}
};
static param_export_t params[]={
{"db_url", STR_PARAM, &db_url.s},
{"table_name", STR_PARAM, &table_name.s},
{"rid_col", STR_PARAM, &rid_col.s},
{"pid_col", STR_PARAM, &pid_col.s},
{"prefix_col", STR_PARAM, &prefix_col.s},
{"start_h_col", STR_PARAM, &start_h_col.s},
{"end_h_col", STR_PARAM, &end_h_col.s},
{"days_col", STR_PARAM, &days_col.s},
{"cpm_thresh_warn_col", STR_PARAM, &cpm_thresh_warn_col.s},
{"cpm_thresh_crit_col", STR_PARAM, &cpm_thresh_crit_col.s},
{"calldur_thresh_warn_col", STR_PARAM, &calldur_thresh_warn_col.s},
{"calldur_thresh_crit_col", STR_PARAM, &calldur_thresh_crit_col.s},
{"totalc_thresh_warn_col", STR_PARAM, &totalc_thresh_warn_col.s},
{"totalc_thresh_crit_col", STR_PARAM, &totalc_thresh_crit_col.s},
{"concalls_thresh_warn_col", STR_PARAM, &concalls_thresh_warn_col.s},
{"concalls_thresh_crit_col", STR_PARAM, &concalls_thresh_crit_col.s},
{"seqcalls_thresh_warn_col", STR_PARAM, &seqcalls_thresh_warn_col.s},
{"seqcalls_thresh_crit_col", STR_PARAM, &seqcalls_thresh_crit_col.s},
{0,0,0}
};
static mi_export_t mi_cmds[] = {
//{ "get_maps","return all mappings",mi_get_maps,MI_NO_INPUT_FLAG,0,0},
{0,0,0,0,0,0}
};
static dep_export_t deps = {
{
{MOD_TYPE_SQLDB, NULL, DEP_ABORT},
{MOD_TYPE_DEFAULT, "drouting", DEP_ABORT},
{MOD_TYPE_NULL, NULL, 0},
},
{
{NULL, NULL},
},
};
/** module exports */
struct module_exports exports= {
"fraud_detection", /* module name */
MOD_TYPE_DEFAULT,
MODULE_VERSION,
DEFAULT_DLFLAGS, /* dlopen flags */
&deps,
cmds, /* exported functions */
params, /* exported parameters */
0, /* exported statistics */
mi_cmds, /* exported MI functions */
0, /* exported pseudo-variables */
0, /* extra processes */
mod_init, /* module initialization function */
(response_function) 0, /* response handling function */
(destroy_function)destroy, /* destroy function */
child_init /* per-child init function */
};
static void set_lengths(void)
{
db_url.len = strlen(db_url.s);
table_name.len = strlen(table_name.s);
rid_col.len = strlen(rid_col.s);
pid_col.len = strlen(pid_col.s);
prefix_col.len = strlen(prefix_col.s);
start_h_col.len = strlen(start_h_col.s);
end_h_col.len = strlen(end_h_col.s);
days_col.len = strlen(days_col.s);
cpm_thresh_warn_col.len = strlen(cpm_thresh_warn_col.s);
cpm_thresh_crit_col.len = strlen(cpm_thresh_crit_col.s);
calldur_thresh_warn_col.len = strlen(calldur_thresh_warn_col.s);
calldur_thresh_crit_col.len = strlen(calldur_thresh_crit_col.s);
totalc_thresh_warn_col.len = strlen(totalc_thresh_warn_col.s);
totalc_thresh_crit_col.len = strlen(totalc_thresh_crit_col.s);
concalls_thresh_warn_col.len = strlen(concalls_thresh_warn_col.s);
concalls_thresh_crit_col.len = strlen(concalls_thresh_crit_col.s);
seqcalls_thresh_warn_col.len = strlen(seqcalls_thresh_warn_col.s);
seqcalls_thresh_crit_col.len = strlen(seqcalls_thresh_crit_col.s);
}
static int mod_init(void)
{
LM_INFO("Initializing module\n");
if ((frd_data_lock = lock_init_rw()) == NULL) {
LM_CRIT("failed to init reader/writer lock\n");
return -1;
}
set_lengths();
if (load_dr_api(&drb) != 0) {
LM_ERR("Cannot load dr_api\n");
return -1;
}
frd_init_db();
frd_reload_data();
str number = str_init("0754565");
rt_info_t *test = drb.match_number(dr_head, 1, &number);
if (test) {
frd_thresholds_t *thr = (frd_thresholds_t*)test->attrs.s;
LM_INFO("xxx - <%u> matched: %d %d %d %d %d\n", test->id, thr->cpm_thr.warning,
thr->call_duration_thr.critical, thr->total_calls_thr.warning,
thr->concurrent_calls_thr.critical, thr->seq_calls_thr.warning);
}
else
LM_INFO("no match\n");
return 0;
}
static int child_init(int rank)
{
return 0;
}
/*
* destroy function
*/
static void destroy(void)
{
LM_INFO("Destroying module\n");
}