-
Notifications
You must be signed in to change notification settings - Fork 565
/
speeddial.c
192 lines (160 loc) · 4.78 KB
/
speeddial.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* Copyright (C) 2004-2006 Voice Sistem SRL
*
* This file is part of Open SIP Server (opensips).
*
* opensips is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* opensips is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* History:
* ---------
*
*/
#include <stdio.h>
#include <string.h>
#include "../../sr_module.h"
#include "../../db/db.h"
#include "../../dprint.h"
#include "../../error.h"
#include "../../mem/mem.h"
#include "../../mod_fix.h"
#include "sdlookup.h"
/* Module destroy function prototype */
static void destroy(void);
/* Module child-init function prototype */
static int child_init(int rank);
/* Module initialization function prototype */
static int mod_init(void);
/* Module parameter variables */
static str db_url = {NULL,0};
str user_column = str_init("username");
str domain_column = str_init("domain");
str sd_user_column = str_init("sd_username");
str sd_domain_column = str_init("sd_domain");
str new_uri_column = str_init("new_uri");
int use_domain = 0;
static str domain_prefix = {NULL, 0};
str dstrip_s = {NULL, 0};
db_func_t db_funcs; /* Database functions */
db_con_t* db_handle=0; /* Database connection handle */
/* Exported functions */
// static cmd_export_t cmds[] = {
// {"sd_lookup", (cmd_function)sd_lookup, 1, fixup_spve_null, 0,
// REQUEST_ROUTE},
// {"sd_lookup", (cmd_function)sd_lookup, 2, fixup_spve_spve, 0,
// REQUEST_ROUTE},
// {0, 0, 0, 0, 0, 0}
// };
static cmd_export_t cmds[] = {
{"sd_lookup", (cmd_function)sd_lookup, {
{CMD_PARAM_STR,0,0},
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0}, {0,0,0}},
REQUEST_ROUTE},
{0,0,{{0,0,0}},0}
};
/* Exported parameters */
static param_export_t params[] = {
{"db_url", STR_PARAM, &db_url.s },
{"user_column", STR_PARAM, &user_column.s },
{"domain_column", STR_PARAM, &domain_column.s },
{"sd_user_column", STR_PARAM, &sd_user_column.s },
{"sd_domain_column", STR_PARAM, &sd_domain_column.s },
{"new_uri_column", STR_PARAM, &new_uri_column.s },
{"use_domain", INT_PARAM, &use_domain },
{"domain_prefix", STR_PARAM, &domain_prefix.s },
{0, 0, 0}
};
static dep_export_t deps = {
{ /* OpenSIPS module dependencies */
{ MOD_TYPE_SQLDB, NULL, DEP_ABORT },
{ MOD_TYPE_NULL, NULL, 0 },
},
{ /* modparam dependencies */
{ NULL, NULL },
},
};
/* Module interface */
struct module_exports exports = {
"speeddial",
MOD_TYPE_DEFAULT,/* class of this module */
MODULE_VERSION,
DEFAULT_DLFLAGS, /* dlopen flags */
0, /* load function */
&deps, /* OpenSIPS module dependencies */
cmds, /* Exported functions */
NULL, /* Exported async functions */
params, /* Exported parameters */
0, /* exported statistics */
0, /* exported MI functions */
0, /* exported pseudo-variables */
0, /* exported transformations */
0, /* extra processes */
0, /* module pre-initialization function */
mod_init, /* module initialization function */
0, /* response function */
destroy, /* destroy function */
child_init, /* child initialization function */
0 /* reload confirm function */
};
/**
*
*/
static int child_init(int rank)
{
db_handle = db_funcs.init(&db_url);
if (!db_handle)
{
LM_ERR("failed to connect database\n");
return -1;
}
return 0;
}
/**
*
*/
static int mod_init(void)
{
LM_DBG("initializing\n");
init_db_url( db_url , 0 /*cannot be null*/);
user_column.len = strlen(user_column.s);
domain_column.len = strlen(domain_column.s);
sd_user_column.len = strlen(sd_user_column.s);
sd_domain_column.len = strlen(sd_domain_column.s);
new_uri_column.len = strlen(new_uri_column.s);
if (domain_prefix.s)
domain_prefix.len = strlen(domain_prefix.s);
/* Find a database module */
if (db_bind_mod(&db_url, &db_funcs))
{
LM_ERR("failed to bind database module\n");
return -1;
}
if (!DB_CAPABILITY(db_funcs, DB_CAP_QUERY))
{
LM_ERR("Database modules does not "
"provide all functions needed by SPEEDDIAL module\n");
return -1;
}
if (domain_prefix.s && domain_prefix.len > 0) {
dstrip_s.s = domain_prefix.s;
dstrip_s.len = domain_prefix.len;
}
return 0;
}
/**
*
*/
static void destroy(void)
{
}