- basic DB operations should work, but no extensive load testing has yet be done,
as some work still remains:
- remove dead code and superflous comments in postgres driver
- clean up memory management, at the moment there exists two flavors: don't
copy that much (mysql, unixodbc), don't trust the driver, copy everything
(postgres, db_berkeley)
- after this is unified, then only one implementation for the memory
management of the db API could be used for all modules
- Foundations of this change have been created from Frederick Bullik,
Frederick.Bullik at 1und1 dot de
- Please review and test.
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@3563 689a6050-402a-0410-94f2-e92a70836424
... | ... |
@@ -276,22 +276,22 @@ static void acc_db_init_keys(void) |
276 | 276 |
/* init the static db keys */ |
277 | 277 |
n = 0; |
278 | 278 |
/* caution: keys need to be aligned to core format */ |
279 |
- db_keys[n++] = acc_method_col; |
|
280 |
- db_keys[n++] = acc_fromtag_col; |
|
281 |
- db_keys[n++] = acc_totag_col; |
|
282 |
- db_keys[n++] = acc_callid_col; |
|
283 |
- db_keys[n++] = acc_sipcode_col; |
|
284 |
- db_keys[n++] = acc_sipreason_col; |
|
285 |
- db_keys[n++] = acc_time_col; |
|
279 |
+ db_keys[n++] = &acc_method_col; |
|
280 |
+ db_keys[n++] = &acc_fromtag_col; |
|
281 |
+ db_keys[n++] = &acc_totag_col; |
|
282 |
+ db_keys[n++] = &acc_callid_col; |
|
283 |
+ db_keys[n++] = &acc_sipcode_col; |
|
284 |
+ db_keys[n++] = &acc_sipreason_col; |
|
285 |
+ db_keys[n++] = &acc_time_col; |
|
286 | 286 |
time_idx = n-1; |
287 | 287 |
|
288 | 288 |
/* init the extra db keys */ |
289 | 289 |
for(extra=db_extra; extra ; extra=extra->next) |
290 |
- db_keys[n++] = extra->name.s; |
|
290 |
+ db_keys[n++] = &extra->name; |
|
291 | 291 |
|
292 | 292 |
/* multi leg call columns */ |
293 | 293 |
for( extra=leg_info ; extra ; extra=extra->next) |
294 |
- db_keys[n++] = extra->name.s; |
|
294 |
+ db_keys[n++] = &extra->name; |
|
295 | 295 |
|
296 | 296 |
/* init the values */ |
297 | 297 |
for(i=0; i<n; i++) { |
... | ... |
@@ -304,9 +304,9 @@ static void acc_db_init_keys(void) |
304 | 304 |
|
305 | 305 |
/* binds to the corresponding database module |
306 | 306 |
* returns 0 on success, -1 on error */ |
307 |
-int acc_db_init(char* db_url) |
|
307 |
+int acc_db_init(const str* db_url) |
|
308 | 308 |
{ |
309 |
- if (bind_dbmod(db_url, &acc_dbf)<0){ |
|
309 |
+ if (db_bind_mod(db_url, &acc_dbf)<0){ |
|
310 | 310 |
LM_ERR("bind_db failed\n"); |
311 | 311 |
return -1; |
312 | 312 |
} |
... | ... |
@@ -325,7 +325,7 @@ int acc_db_init(char* db_url) |
325 | 325 |
|
326 | 326 |
/* initialize the database connection |
327 | 327 |
* returns 0 on success, -1 on error */ |
328 |
-int acc_db_init_child(char *db_url) |
|
328 |
+int acc_db_init_child(const str *db_url) |
|
329 | 329 |
{ |
330 | 330 |
db_handle=acc_dbf.init(db_url); |
331 | 331 |
if (db_handle==0){ |
... | ... |
@@ -364,7 +364,7 @@ int acc_db_request( struct sip_msg *rq) |
364 | 364 |
for( i++ ; i<m; i++) |
365 | 365 |
VAL_STR(db_vals+i) = val_arr[i]; |
366 | 366 |
|
367 |
- if (acc_dbf.use_table(db_handle, acc_env.text.s/*table*/) < 0) { |
|
367 |
+ if (acc_dbf.use_table(db_handle, &acc_env.text/*table*/) < 0) { |
|
368 | 368 |
LM_ERR("error in use_table\n"); |
369 | 369 |
return -1; |
370 | 370 |
} |
... | ... |
@@ -69,8 +69,8 @@ void acc_log_init(); |
69 | 69 |
int acc_log_request( struct sip_msg *req); |
70 | 70 |
|
71 | 71 |
#ifdef SQL_ACC |
72 |
-int acc_db_init(char* db_url); |
|
73 |
-int acc_db_init_child(char* db_url); |
|
72 |
+int acc_db_init(const str* db_url); |
|
73 |
+int acc_db_init_child(const str* db_url); |
|
74 | 74 |
void acc_db_close(); |
75 | 75 |
int acc_db_request( struct sip_msg *req); |
76 | 76 |
#endif |
... | ... |
@@ -306,7 +306,7 @@ static inline void on_missed(struct cell *t, struct sip_msg *req, |
306 | 306 |
} |
307 | 307 |
#ifdef SQL_ACC |
308 | 308 |
if (is_db_mc_on(req)) { |
309 |
- env_set_text( db_table_mc, 0); |
|
309 |
+ env_set_text(db_table_mc.s, 0); |
|
310 | 310 |
acc_db_request( req ); |
311 | 311 |
flags_to_reset |= db_missed_flag; |
312 | 312 |
} |
... | ... |
@@ -371,7 +371,7 @@ static inline void acc_onreply( struct cell* t, struct sip_msg *req, |
371 | 371 |
} |
372 | 372 |
#ifdef SQL_ACC |
373 | 373 |
if (is_db_acc_on(req)) { |
374 |
- env_set_text( db_table_acc, 0); |
|
374 |
+ env_set_text( db_table_acc.s, 0); |
|
375 | 375 |
acc_db_request(req); |
376 | 376 |
} |
377 | 377 |
#endif |
... | ... |
@@ -409,7 +409,7 @@ static inline void acc_onack( struct cell* t, struct sip_msg *req, |
409 | 409 |
} |
410 | 410 |
#ifdef SQL_ACC |
411 | 411 |
if (is_db_acc_on(req)) { |
412 |
- env_set_text( db_table_acc, 0); |
|
412 |
+ env_set_text( db_table_acc.s, 0); |
|
413 | 413 |
acc_db_request( ack ); |
414 | 414 |
} |
415 | 415 |
#endif |
... | ... |
@@ -71,7 +71,7 @@ MODULE_VERSION |
71 | 71 |
struct tm_binds tmb; |
72 | 72 |
struct rr_binds rrb; |
73 | 73 |
|
74 |
-static int mod_init( void ); |
|
74 |
+static int mod_init(void); |
|
75 | 75 |
static void destroy(void); |
76 | 76 |
static int child_init(int rank); |
77 | 77 |
|
... | ... |
@@ -143,18 +143,18 @@ int db_missed_flag = -1; |
143 | 143 |
static char *db_extra_str = 0; |
144 | 144 |
struct acc_extra *db_extra = 0; |
145 | 145 |
/* Database url */ |
146 |
-static char *db_url = 0; |
|
146 |
+static str db_url = {NULL, 0}; |
|
147 | 147 |
/* name of database tables */ |
148 |
-char *db_table_acc = "acc"; |
|
149 |
-char *db_table_mc = "missed_calls"; |
|
148 |
+str db_table_acc = str_init("acc"); |
|
149 |
+str db_table_mc = str_init("missed_calls"); |
|
150 | 150 |
/* names of columns in tables acc/missed calls*/ |
151 |
-char* acc_method_col = "method"; |
|
152 |
-char* acc_fromtag_col = "from_tag"; |
|
153 |
-char* acc_totag_col = "to_tag"; |
|
154 |
-char* acc_callid_col = "callid"; |
|
155 |
-char* acc_sipcode_col = "sip_code"; |
|
156 |
-char* acc_sipreason_col = "sip_reason"; |
|
157 |
-char* acc_time_col = "time"; |
|
151 |
+str acc_method_col = str_init("method"); |
|
152 |
+str acc_fromtag_col = str_init("from_tag"); |
|
153 |
+str acc_totag_col = str_init("to_tag"); |
|
154 |
+str acc_callid_col = str_init("callid"); |
|
155 |
+str acc_sipcode_col = str_init("sip_code"); |
|
156 |
+str acc_sipreason_col = str_init("sip_reason"); |
|
157 |
+str acc_time_col = str_init("time"); |
|
158 | 158 |
#endif |
159 | 159 |
|
160 | 160 |
/* ------------- fixup function --------------- */ |
... | ... |
@@ -214,16 +214,16 @@ static param_export_t params[] = { |
214 | 214 |
{"db_flag", INT_PARAM, &db_flag }, |
215 | 215 |
{"db_missed_flag", INT_PARAM, &db_missed_flag }, |
216 | 216 |
{"db_extra", STR_PARAM, &db_extra_str }, |
217 |
- {"db_url", STR_PARAM, &db_url }, |
|
218 |
- {"db_table_acc", STR_PARAM, &db_table_acc }, |
|
219 |
- {"db_table_missed_calls",STR_PARAM, &db_table_mc }, |
|
220 |
- {"acc_method_column", STR_PARAM, &acc_method_col }, |
|
221 |
- {"acc_from_tag_column", STR_PARAM, &acc_fromtag_col }, |
|
222 |
- {"acc_to_tag_column", STR_PARAM, &acc_totag_col }, |
|
223 |
- {"acc_callid_column", STR_PARAM, &acc_callid_col }, |
|
224 |
- {"acc_sip_code_column", STR_PARAM, &acc_sipcode_col }, |
|
225 |
- {"acc_sip_reason_column",STR_PARAM, &acc_sipreason_col }, |
|
226 |
- {"acc_time_column", STR_PARAM, &acc_time_col }, |
|
217 |
+ {"db_url", STR_PARAM, &db_url.s }, |
|
218 |
+ {"db_table_acc", STR_PARAM, &db_table_acc.s }, |
|
219 |
+ {"db_table_missed_calls",STR_PARAM, &db_table_mc.s }, |
|
220 |
+ {"acc_method_column", STR_PARAM, &acc_method_col.s }, |
|
221 |
+ {"acc_from_tag_column", STR_PARAM, &acc_fromtag_col.s }, |
|
222 |
+ {"acc_to_tag_column", STR_PARAM, &acc_totag_col.s }, |
|
223 |
+ {"acc_callid_column", STR_PARAM, &acc_callid_col.s }, |
|
224 |
+ {"acc_sip_code_column", STR_PARAM, &acc_sipcode_col.s }, |
|
225 |
+ {"acc_sip_reason_column",STR_PARAM, &acc_sipreason_col.s }, |
|
226 |
+ {"acc_time_column", STR_PARAM, &acc_time_col.s }, |
|
227 | 227 |
#endif |
228 | 228 |
{0,0,0} |
229 | 229 |
}; |
... | ... |
@@ -283,7 +283,7 @@ static int acc_fixup(void** param, int param_no) |
283 | 283 |
#ifdef SQL_ACC |
284 | 284 |
} else if (param_no == 2) { |
285 | 285 |
/* only for db acc - the table name */ |
286 |
- if (db_url==0) { |
|
286 |
+ if (db_url.s==0) { |
|
287 | 287 |
pkg_free(p); |
288 | 288 |
*param = 0; |
289 | 289 |
} |
... | ... |
@@ -310,6 +310,18 @@ static int mod_init( void ) |
310 | 310 |
{ |
311 | 311 |
LM_INFO("initializing...\n"); |
312 | 312 |
|
313 |
+ if (db_url.s) |
|
314 |
+ db_url.len = strlen(db_url.s); |
|
315 |
+ db_table_acc.len = strlen(db_table_acc.s); |
|
316 |
+ db_table_mc.len = strlen(db_table_mc.s); |
|
317 |
+ acc_method_col.len = strlen(acc_method_col.s); |
|
318 |
+ acc_fromtag_col.len = strlen(acc_fromtag_col.s); |
|
319 |
+ acc_totag_col.len = strlen(acc_totag_col.s); |
|
320 |
+ acc_callid_col.len = strlen(acc_callid_col.s); |
|
321 |
+ acc_sipcode_col.len = strlen(acc_sipcode_col.s); |
|
322 |
+ acc_sipreason_col.len = strlen(acc_sipreason_col.s); |
|
323 |
+ acc_time_col.len = strlen(acc_time_col.s); |
|
324 |
+ |
|
313 | 325 |
/* ----------- GENERIC INIT SECTION ----------- */ |
314 | 326 |
|
315 | 327 |
if (flag_idx2mask(&failed_transaction_flag)<0) |
... | ... |
@@ -369,13 +381,13 @@ static int mod_init( void ) |
369 | 381 |
/* ------------ SQL INIT SECTION ----------- */ |
370 | 382 |
|
371 | 383 |
#ifdef SQL_ACC |
372 |
- if (db_url && db_url[0]) { |
|
384 |
+ if (db_url.s && db_url.len > 0) { |
|
373 | 385 |
/* parse the extra string, if any */ |
374 | 386 |
if (db_extra_str && (db_extra=parse_acc_extra(db_extra_str))==0 ) { |
375 | 387 |
LM_ERR("failed to parse db_extra param\n"); |
376 | 388 |
return -1; |
377 | 389 |
} |
378 |
- if (acc_db_init(db_url)<0){ |
|
390 |
+ if (acc_db_init(&db_url)<0){ |
|
379 | 391 |
LM_ERR("failed...did you load a database module?\n"); |
380 | 392 |
return -1; |
381 | 393 |
} |
... | ... |
@@ -385,7 +397,6 @@ static int mod_init( void ) |
385 | 397 |
if (flag_idx2mask(&db_missed_flag)<0) |
386 | 398 |
return -1; |
387 | 399 |
} else { |
388 |
- db_url = 0; |
|
389 | 400 |
db_flag = 0; |
390 | 401 |
db_missed_flag = 0; |
391 | 402 |
} |
... | ... |
@@ -445,8 +456,11 @@ static int mod_init( void ) |
445 | 456 |
static int child_init(int rank) |
446 | 457 |
{ |
447 | 458 |
#ifdef SQL_ACC |
448 |
- if (db_url && acc_db_init_child(db_url)<0) |
|
459 |
+ if(db_url.s && acc_db_init_child(&db_url)<0) { |
|
460 |
+ LM_ERR("could not open database connection"); |
|
449 | 461 |
return -1; |
462 |
+ } |
|
463 |
+ |
|
450 | 464 |
#endif |
451 | 465 |
|
452 | 466 |
/* DIAMETER */ |
... | ... |
@@ -64,19 +64,19 @@ extern int diameter_missed_flag; |
64 | 64 |
extern int db_flag; |
65 | 65 |
extern int db_missed_flag; |
66 | 66 |
|
67 |
-extern char *db_table_acc; |
|
68 |
-extern char *db_table_mc; |
|
67 |
+extern str db_table_acc; |
|
68 |
+extern str db_table_mc; |
|
69 | 69 |
|
70 |
-extern char* acc_method_col; |
|
71 |
-extern char* acc_fromuri_col; |
|
72 |
-extern char* acc_fromtag_col; |
|
73 |
-extern char* acc_touri_col; |
|
74 |
-extern char* acc_totag_col; |
|
75 |
-extern char* acc_callid_col; |
|
76 |
-extern char* acc_cseqno_col; |
|
77 |
-extern char* acc_sipcode_col; |
|
78 |
-extern char* acc_sipreason_col; |
|
79 |
-extern char* acc_time_col; |
|
70 |
+extern str acc_method_col; |
|
71 |
+extern str acc_fromuri_col; |
|
72 |
+extern str acc_fromtag_col; |
|
73 |
+extern str acc_touri_col; |
|
74 |
+extern str acc_totag_col; |
|
75 |
+extern str acc_callid_col; |
|
76 |
+extern str acc_cseqno_col; |
|
77 |
+extern str acc_sipcode_col; |
|
78 |
+extern str acc_sipreason_col; |
|
79 |
+extern str acc_time_col; |
|
80 | 80 |
#endif /* SQL_ACC */ |
81 | 81 |
|
82 | 82 |
|
... | ... |
@@ -34,6 +34,7 @@ |
34 | 34 |
#include "../../dprint.h" |
35 | 35 |
#include "../../error.h" |
36 | 36 |
#include "../../mem/mem.h" |
37 |
+#include "../../ut.h" |
|
37 | 38 |
|
38 | 39 |
#include "alookup.h" |
39 | 40 |
|
... | ... |
@@ -53,16 +54,13 @@ static int mod_init(void); |
53 | 54 |
|
54 | 55 |
|
55 | 56 |
/* Module parameter variables */ |
56 |
-char* db_url = DEFAULT_RODB_URL; |
|
57 |
-char* user_column = "username"; |
|
58 |
-char* domain_column = "domain"; |
|
59 |
-char* alias_user_column = "alias_username"; |
|
60 |
-char* alias_domain_column = "alias_domain"; |
|
61 |
-int use_domain = 0; |
|
62 |
-char* domain_prefix = NULL; |
|
63 |
- |
|
64 |
-str dstrip_s; |
|
65 |
- |
|
57 |
+static str db_url = str_init(DEFAULT_RODB_URL); |
|
58 |
+str user_column = str_init("username"); |
|
59 |
+str domain_column = str_init("domain"); |
|
60 |
+str alias_user_column = str_init("alias_username"); |
|
61 |
+str alias_domain_column = str_init("alias_domain"); |
|
62 |
+str domain_prefix = {NULL, 0}; |
|
63 |
+int use_domain = 0; |
|
66 | 64 |
|
67 | 65 |
db_con_t* db_handle; /* Database connection handle */ |
68 | 66 |
db_func_t adbf; /* DB functions */ |
... | ... |
@@ -77,20 +75,20 @@ static cmd_export_t cmds[] = { |
77 | 75 |
|
78 | 76 |
/* Exported parameters */ |
79 | 77 |
static param_export_t params[] = { |
80 |
- {"db_url", STR_PARAM, &db_url }, |
|
81 |
- {"user_column", STR_PARAM, &user_column }, |
|
82 |
- {"domain_column", STR_PARAM, &domain_column }, |
|
83 |
- {"alias_user_column", STR_PARAM, &alias_user_column }, |
|
84 |
- {"alias_domain_column", STR_PARAM, &alias_domain_column }, |
|
78 |
+ {"db_url", STR_PARAM, &db_url.s }, |
|
79 |
+ {"user_column", STR_PARAM, &user_column.s }, |
|
80 |
+ {"domain_column", STR_PARAM, &domain_column.s }, |
|
81 |
+ {"alias_user_column", STR_PARAM, &alias_user_column.s }, |
|
82 |
+ {"alias_domain_column", STR_PARAM, &alias_domain_column.s }, |
|
85 | 83 |
{"use_domain", INT_PARAM, &use_domain }, |
86 |
- {"domain_prefix", STR_PARAM, &domain_prefix }, |
|
84 |
+ {"domain_prefix", STR_PARAM, &domain_prefix.s }, |
|
87 | 85 |
{0, 0, 0} |
88 | 86 |
}; |
89 | 87 |
|
90 | 88 |
|
91 | 89 |
/* Module interface */ |
92 | 90 |
struct module_exports exports = { |
93 |
- "alias_db", |
|
91 |
+ "alias_db", |
|
94 | 92 |
DEFAULT_DLFLAGS, /* dlopen flags */ |
95 | 93 |
cmds, /* Exported functions */ |
96 | 94 |
params, /* Exported parameters */ |
... | ... |
@@ -110,7 +108,7 @@ struct module_exports exports = { |
110 | 108 |
*/ |
111 | 109 |
static int child_init(int rank) |
112 | 110 |
{ |
113 |
- db_handle = adbf.init(db_url); |
|
111 |
+ db_handle = adbf.init(&db_url); |
|
114 | 112 |
if (!db_handle) |
115 | 113 |
{ |
116 | 114 |
LM_ERR("unable to connect database\n"); |
... | ... |
@@ -127,31 +125,26 @@ static int child_init(int rank) |
127 | 125 |
static int mod_init(void) |
128 | 126 |
{ |
129 | 127 |
LM_INFO("initializing...\n"); |
128 |
+ db_url.len = strlen(db_url.s); |
|
129 |
+ user_column.len = strlen(user_column.s); |
|
130 |
+ domain_column.len = strlen(domain_column.s); |
|
131 |
+ alias_domain_column.len = strlen(domain_column.s); |
|
132 |
+ alias_user_column.len = strlen(alias_user_column.s); |
|
133 |
+ if (domain_prefix.s) |
|
134 |
+ domain_prefix.len = strlen(domain_prefix.s); |
|
130 | 135 |
|
131 | 136 |
/* Find a database module */ |
132 |
- if (bind_dbmod(db_url, &adbf)) |
|
137 |
+ if (db_bind_mod(&db_url, &adbf)) |
|
133 | 138 |
{ |
134 | 139 |
LM_ERR("unable to bind database module\n"); |
135 | 140 |
return -1; |
136 | 141 |
} |
137 |
- if (!DB_CAPABILITY( adbf, DB_CAP_QUERY)) |
|
142 |
+ if (!DB_CAPABILITY(adbf, DB_CAP_QUERY)) |
|
138 | 143 |
{ |
139 | 144 |
LM_CRIT("database modules does not " |
140 | 145 |
"provide all functions needed by avpops module\n"); |
141 | 146 |
return -1; |
142 | 147 |
} |
143 |
- |
|
144 |
- |
|
145 |
- if(domain_prefix==NULL || strlen(domain_prefix)==0) |
|
146 |
- { |
|
147 |
- dstrip_s.s = 0; |
|
148 |
- dstrip_s.len = 0; |
|
149 |
- } |
|
150 |
- else |
|
151 |
- { |
|
152 |
- dstrip_s.s = domain_prefix; |
|
153 |
- dstrip_s.len = strlen(domain_prefix); |
|
154 |
- } |
|
155 | 148 |
|
156 | 149 |
return 0; |
157 | 150 |
} |
... | ... |
@@ -36,12 +36,12 @@ |
36 | 36 |
|
37 | 37 |
/* Module parameters variables */ |
38 | 38 |
|
39 |
-extern char* user_column; /* 'username' column name */ |
|
40 |
-extern char* domain_column; /* 'domain' column name */ |
|
41 |
-extern char* alias_user_column; /* 'alias_username' column name */ |
|
42 |
-extern char* alias_domain_column; /* 'alias_domain' column name */ |
|
43 |
-extern int use_domain; /* use or not the domain for alias lookup */ |
|
44 |
-extern str dstrip_s; |
|
39 |
+extern str user_column; /* 'username' column name */ |
|
40 |
+extern str domain_column; /* 'domain' column name */ |
|
41 |
+extern str alias_user_column; /* 'alias_username' column name */ |
|
42 |
+extern str alias_domain_column; /* 'alias_domain' column name */ |
|
43 |
+extern str domain_prefix; |
|
44 |
+extern int use_domain; /* use or not the domain for alias lookup */ |
|
45 | 45 |
|
46 | 46 |
extern db_con_t* db_handle; /* Database connection handle */ |
47 | 47 |
|
... | ... |
@@ -69,12 +69,19 @@ static inline int rewrite_ruri(struct sip_msg* _m, char* _s) |
69 | 69 |
*/ |
70 | 70 |
int alias_db_lookup(struct sip_msg* _msg, char* _table, char* _str2) |
71 | 71 |
{ |
72 |
- str user_s; |
|
73 |
- db_key_t db_keys[2] = { alias_user_column, alias_domain_column }; |
|
72 |
+ str user_s, table_s; |
|
73 |
+ db_key_t db_keys[2] = {&alias_user_column, &alias_domain_column}; |
|
74 | 74 |
db_val_t db_vals[2]; |
75 |
- db_key_t db_cols[] = { user_column, domain_column }; |
|
75 |
+ db_key_t db_cols[] = {&user_column, &domain_column}; |
|
76 | 76 |
db_res_t* db_res = NULL; |
77 | 77 |
|
78 |
+ if(!_table) { |
|
79 |
+ LM_ERR("invalid parameter"); |
|
80 |
+ return -1; |
|
81 |
+ } |
|
82 |
+ table_s.s = _table; |
|
83 |
+ table_s.len = strlen(_table); |
|
84 |
+ |
|
78 | 85 |
if (parse_sip_msg_uri(_msg) < 0) |
79 | 86 |
return -1; |
80 | 87 |
|
... | ... |
@@ -90,16 +97,16 @@ int alias_db_lookup(struct sip_msg* _msg, char* _table, char* _str2) |
90 | 97 |
db_vals[1].val.str_val.s = _msg->parsed_uri.host.s; |
91 | 98 |
db_vals[1].val.str_val.len = _msg->parsed_uri.host.len; |
92 | 99 |
|
93 |
- if (dstrip_s.s!=NULL && dstrip_s.len>0 |
|
94 |
- && dstrip_s.len<_msg->parsed_uri.host.len |
|
95 |
- && strncasecmp(_msg->parsed_uri.host.s,dstrip_s.s,dstrip_s.len)==0) |
|
100 |
+ if (domain_prefix.s && domain_prefix.len>0 |
|
101 |
+ && domain_prefix.len<_msg->parsed_uri.host.len |
|
102 |
+ && strncasecmp(_msg->parsed_uri.host.s,domain_prefix.s,domain_prefix.len)==0) |
|
96 | 103 |
{ |
97 |
- db_vals[1].val.str_val.s += dstrip_s.len; |
|
98 |
- db_vals[1].val.str_val.len -= dstrip_s.len; |
|
104 |
+ db_vals[1].val.str_val.s += domain_prefix.len; |
|
105 |
+ db_vals[1].val.str_val.len -= domain_prefix.len; |
|
99 | 106 |
} |
100 | 107 |
} |
101 | 108 |
|
102 |
- adbf.use_table(db_handle, _table); |
|
109 |
+ adbf.use_table(db_handle, &table_s); |
|
103 | 110 |
if(adbf.query(db_handle, db_keys, NULL, db_vals, db_cols, |
104 | 111 |
(use_domain)?2:1 /*no keys*/, 2 /*no cols*/, NULL, &db_res)!=0) |
105 | 112 |
{ |
... | ... |
@@ -200,4 +207,3 @@ int alias_db_lookup(struct sip_msg* _msg, char* _table, char* _str2) |
200 | 207 |
err_server: |
201 | 208 |
return -1; |
202 | 209 |
} |
203 |
- |
... | ... |
@@ -91,7 +91,7 @@ struct sl_binds slb; |
91 | 91 |
/* |
92 | 92 |
* Module parameter variables |
93 | 93 |
*/ |
94 |
-static char* db_url = DEFAULT_RODB_URL; |
|
94 |
+static str db_url = {DEFAULT_RODB_URL, DEFAULT_RODB_URL_LEN}; |
|
95 | 95 |
str user_column = {USER_COL, USER_COL_LEN}; |
96 | 96 |
str domain_column = {DOMAIN_COL, DOMAIN_COL_LEN}; |
97 | 97 |
str pass_column = {PASS_COL, PASS_COL_LEN}; |
... | ... |
@@ -123,7 +123,7 @@ static cmd_export_t cmds[] = { |
123 | 123 |
* Exported parameters |
124 | 124 |
*/ |
125 | 125 |
static param_export_t params[] = { |
126 |
- {"db_url", STR_PARAM, &db_url }, |
|
126 |
+ {"db_url", STR_PARAM, &db_url.s }, |
|
127 | 127 |
{"user_column", STR_PARAM, &user_column.s }, |
128 | 128 |
{"domain_column", STR_PARAM, &domain_column.s }, |
129 | 129 |
{"password_column", STR_PARAM, &pass_column.s }, |
... | ... |
@@ -156,7 +156,7 @@ struct module_exports exports = { |
156 | 156 |
|
157 | 157 |
static int child_init(int rank) |
158 | 158 |
{ |
159 |
- auth_db_handle = auth_dbf.init(db_url); |
|
159 |
+ auth_db_handle = auth_dbf.init(&db_url); |
|
160 | 160 |
if (auth_db_handle == 0){ |
161 | 161 |
LM_ERR("unable to connect to the database\n"); |
162 | 162 |
return -1; |
... | ... |
@@ -172,13 +172,14 @@ static int mod_init(void) |
172 | 172 |
|
173 | 173 |
LM_INFO("initializing...\n"); |
174 | 174 |
|
175 |
+ db_url.len = strlen(db_url.s); |
|
175 | 176 |
user_column.len = strlen(user_column.s); |
176 | 177 |
domain_column.len = strlen(domain_column.s); |
177 | 178 |
pass_column.len = strlen(pass_column.s); |
178 | 179 |
pass_column_2.len = strlen(pass_column.s); |
179 | 180 |
|
180 | 181 |
/* Find a database module */ |
181 |
- if (bind_dbmod(db_url, &auth_dbf) < 0){ |
|
182 |
+ if (db_bind_mod(&db_url, &auth_dbf) < 0){ |
|
182 | 183 |
LM_ERR("unable to bind to a database driver\n"); |
183 | 184 |
return -1; |
184 | 185 |
} |
... | ... |
@@ -252,12 +253,12 @@ static int auth_fixup(void** param, int param_no) |
252 | 253 |
name.s = (char*)*param; |
253 | 254 |
name.len = strlen(name.s); |
254 | 255 |
|
255 |
- dbh = auth_dbf.init(db_url); |
|
256 |
+ dbh = auth_dbf.init(&db_url); |
|
256 | 257 |
if (!dbh) { |
257 | 258 |
LM_ERR("unable to open database connection\n"); |
258 | 259 |
return -1; |
259 | 260 |
} |
260 |
- ver = table_version(&auth_dbf, dbh, &name); |
|
261 |
+ ver = db_table_version(&auth_dbf, dbh, &name); |
|
261 | 262 |
auth_dbf.close(dbh); |
262 | 263 |
if (ver < 0) { |
263 | 264 |
LM_ERR("failed to query table version\n"); |
... | ... |
@@ -52,13 +52,14 @@ static str auth_500_err = str_init("Server Internal Error"); |
52 | 52 |
|
53 | 53 |
|
54 | 54 |
static inline int get_ha1(struct username* _username, str* _domain, |
55 |
- char* _table, char* _ha1, db_res_t** res) |
|
55 |
+ const str* _table, char* _ha1, db_res_t** res) |
|
56 | 56 |
{ |
57 | 57 |
struct aaa_avp *cred; |
58 | 58 |
db_key_t keys[2]; |
59 | 59 |
db_val_t vals[2]; |
60 | 60 |
db_key_t *col; |
61 | 61 |
str result; |
62 |
+ |
|
62 | 63 |
int n, nc; |
63 | 64 |
|
64 | 65 |
col = pkg_malloc(sizeof(*col) * (credentials_n + 1)); |
... | ... |
@@ -67,14 +68,14 @@ static inline int get_ha1(struct username* _username, str* _domain, |
67 | 68 |
return -1; |
68 | 69 |
} |
69 | 70 |
|
70 |
- keys[0] = user_column.s; |
|
71 |
- keys[1] = domain_column.s; |
|
71 |
+ keys[0] = &user_column; |
|
72 |
+ keys[1] = &domain_column; |
|
72 | 73 |
/* should we calculate the HA1, and is it calculated with domain? */ |
73 | 74 |
col[0] = (_username->domain.len && !calc_ha1) ? |
74 |
- (pass_column_2.s) : (pass_column.s); |
|
75 |
+ (&pass_column_2) : (&pass_column); |
|
75 | 76 |
|
76 | 77 |
for (n = 0, cred=credentials; cred ; n++, cred=cred->next) { |
77 |
- col[1 + n] = cred->attr_name.s; |
|
78 |
+ col[1 + n] = &cred->attr_name; |
|
78 | 79 |
} |
79 | 80 |
|
80 | 81 |
VAL_TYPE(vals) = VAL_TYPE(vals + 1) = DB_STR; |
... | ... |
@@ -191,9 +192,9 @@ static int generate_avps(db_res_t* result) |
191 | 192 |
ivalue.n); |
192 | 193 |
break; |
193 | 194 |
default: |
194 |
- LM_ERR("subscriber table column `%s' has unsuported type. " |
|
195 |
+ LM_ERR("subscriber table column `%.*s' has unsuported type. " |
|
195 | 196 |
"Only string/str or int columns are supported by" |
196 |
- "load_credentials.\n", result->col.names[i]); |
|
197 |
+ "load_credentials.\n", result->col.names[i]->len, result->col.names[i]->s); |
|
197 | 198 |
break; |
198 | 199 |
} |
199 | 200 |
} |
... | ... |
@@ -206,16 +207,24 @@ static int generate_avps(db_res_t* result) |
206 | 207 |
* Authorize digest credentials |
207 | 208 |
*/ |
208 | 209 |
static inline int authorize(struct sip_msg* _m, pv_elem_t* _realm, |
209 |
- char* _table, hdr_types_t _hftype) |
|
210 |
+ char* _table, hdr_types_t _hftype) |
|
210 | 211 |
{ |
211 | 212 |
char ha1[256]; |
212 | 213 |
int res; |
213 | 214 |
struct hdr_field* h; |
214 | 215 |
auth_body_t* cred; |
215 | 216 |
auth_result_t ret; |
216 |
- str domain; |
|
217 |
+ str domain, table; |
|
217 | 218 |
db_res_t* result = NULL; |
218 | 219 |
|
220 |
+ if(!_table) { |
|
221 |
+ LM_ERR("invalid parameter"); |
|
222 |
+ return -1; |
|
223 |
+ } |
|
224 |
+ |
|
225 |
+ table.s = _table; |
|
226 |
+ table.len = strlen(_table); |
|
227 |
+ |
|
219 | 228 |
if (_realm) { |
220 | 229 |
if (pv_printf_s(_m, _realm, &domain)!=0) { |
221 | 230 |
LM_ERR("pv_printf_s failed\n"); |
... | ... |
@@ -233,7 +242,7 @@ static inline int authorize(struct sip_msg* _m, pv_elem_t* _realm, |
233 | 242 |
|
234 | 243 |
cred = (auth_body_t*)h->parsed; |
235 | 244 |
|
236 |
- res = get_ha1(&cred->digest.username, &domain, _table, ha1, &result); |
|
245 |
+ res = get_ha1(&cred->digest.username, &domain, &table, ha1, &result); |
|
237 | 246 |
if (res < 0) { |
238 | 247 |
/* Error while accessing the database */ |
239 | 248 |
if (slb.reply(_m, 500, &auth_500_err) == -1) { |
... | ... |
@@ -51,11 +51,16 @@ |
51 | 51 |
MODULE_VERSION |
52 | 52 |
|
53 | 53 |
/* modules param variables */ |
54 |
-static char *DB_URL = 0; /* database url */ |
|
55 |
-static char *DB_TABLE = 0; /* table */ |
|
56 |
-static int use_domain = 0; /* if domain should be use for avp matching */ |
|
57 |
-static char *db_columns[6] = {"uuid","attribute","value", |
|
58 |
- "type","username","domain"}; |
|
54 |
+static str db_url = {NULL, 0}; /* database url */ |
|
55 |
+static str db_table = {NULL, 0}; /* table */ |
|
56 |
+static int use_domain = 0; /* if domain should be use for avp matching */ |
|
57 |
+static str uuid_col = str_init("uuid"); |
|
58 |
+static str attribute_col = str_init("attribute"); |
|
59 |
+static str value_col = str_init("value"); |
|
60 |
+static str type_col = str_init("type"); |
|
61 |
+static str username_col = str_init("username"); |
|
62 |
+static str domain_col = str_init("domain"); |
|
63 |
+static str* db_columns[6] = {&uuid_col, &attribute_col, &value_col, &type_col, &username_col, &domain_col}; |
|
59 | 64 |
|
60 | 65 |
|
61 | 66 |
static int avpops_init(void); |
... | ... |
@@ -125,16 +130,16 @@ static cmd_export_t cmds[] = { |
125 | 130 |
* Exported parameters |
126 | 131 |
*/ |
127 | 132 |
static param_export_t params[] = { |
128 |
- {"db_url", STR_PARAM, &DB_URL }, |
|
129 |
- {"avp_url", STR_PARAM, &DB_URL }, |
|
130 |
- {"avp_table", STR_PARAM, &DB_TABLE }, |
|
131 |
- {"use_domain", INT_PARAM, &use_domain }, |
|
132 |
- {"uuid_column", STR_PARAM, &db_columns[0] }, |
|
133 |
- {"attribute_column", STR_PARAM, &db_columns[1] }, |
|
134 |
- {"value_column", STR_PARAM, &db_columns[2] }, |
|
135 |
- {"type_column", STR_PARAM, &db_columns[3] }, |
|
136 |
- {"username_column", STR_PARAM, &db_columns[4] }, |
|
137 |
- {"domain_column", STR_PARAM, &db_columns[5] }, |
|
133 |
+ {"db_url", STR_PARAM, &db_url.s }, |
|
134 |
+ {"avp_url", STR_PARAM, &db_url.s }, |
|
135 |
+ {"avp_table", STR_PARAM, &db_table.s }, |
|
136 |
+ {"use_domain", INT_PARAM, &use_domain }, |
|
137 |
+ {"uuid_column", STR_PARAM, &uuid_col.s }, |
|
138 |
+ {"attribute_column", STR_PARAM, &attribute_col.s }, |
|
139 |
+ {"value_column", STR_PARAM, &value_col.s }, |
|
140 |
+ {"type_column", STR_PARAM, &type_col.s }, |
|
141 |
+ {"username_column", STR_PARAM, &username_col.s }, |
|
142 |
+ {"domain_column", STR_PARAM, &domain_col.s }, |
|
138 | 143 |
{"db_scheme", STR_PARAM|USE_FUNC_PARAM, (void*)avp_add_db_scheme }, |
139 | 144 |
{0, 0, 0} |
140 | 145 |
}; |
... | ... |
@@ -160,21 +165,32 @@ static int avpops_init(void) |
160 | 165 |
{ |
161 | 166 |
LM_INFO("initializing...\n"); |
162 | 167 |
|
168 |
+ if (db_url.s) |
|
169 |
+ db_url.len = strlen(db_url.s); |
|
170 |
+ if (db_table.s) |
|
171 |
+ db_table.len = strlen(db_table.s); |
|
172 |
+ uuid_col.len = strlen(uuid_col.s); |
|
173 |
+ attribute_col.len = strlen(attribute_col.s); |
|
174 |
+ value_col.len = strlen(value_col.s); |
|
175 |
+ type_col.len = strlen(type_col.s); |
|
176 |
+ username_col.len = strlen(username_col.s); |
|
177 |
+ domain_col.len = strlen(domain_col.s); |
|
178 |
+ |
|
163 | 179 |
/* if DB_URL defined -> bind to a DB module */ |
164 |
- if (DB_URL!=0) |
|
180 |
+ if (db_url.s!=0) |
|
165 | 181 |
{ |
166 | 182 |
/* check AVP_TABLE param */ |
167 |
- if (DB_TABLE==0) |
|
183 |
+ if (db_table.s==0) |
|
168 | 184 |
{ |
169 | 185 |
LM_CRIT("\"AVP_DB\" present but \"AVP_TABLE\" found empty\n"); |
170 | 186 |
goto error; |
171 | 187 |
} |
172 | 188 |
/* bind to the DB module */ |
173 |
- if (avpops_db_bind(DB_URL)<0) |
|
189 |
+ if (avpops_db_bind(&db_url)<0) |
|
174 | 190 |
goto error; |
175 | 191 |
} |
176 | 192 |
|
177 |
- init_store_avps( db_columns ); |
|
193 |
+ init_store_avps(db_columns); |
|
178 | 194 |
|
179 | 195 |
return 0; |
180 | 196 |
error: |
... | ... |
@@ -185,13 +201,13 @@ error: |
185 | 201 |
static int avpops_child_init(int rank) |
186 | 202 |
{ |
187 | 203 |
/* init DB only if enabled */ |
188 |
- if (DB_URL==0) |
|
204 |
+ if (db_url.s==0) |
|
189 | 205 |
return 0; |
190 | 206 |
/* skip main process and TCP manager process */ |
191 | 207 |
if (rank==PROC_MAIN || rank==PROC_TCP_MAIN) |
192 | 208 |
return 0; |
193 | 209 |
/* init DB connection */ |
194 |
- return avpops_db_init(DB_URL, DB_TABLE, db_columns); |
|
210 |
+ return avpops_db_init(&db_url, &db_table, db_columns); |
|
195 | 211 |
} |
196 | 212 |
|
197 | 213 |
|
... | ... |
@@ -206,7 +222,7 @@ static int fixup_db_avp(void** param, int param_no, int allow_scheme) |
206 | 222 |
|
207 | 223 |
flags=0; |
208 | 224 |
flags0=0; |
209 |
- if (DB_URL==0) |
|
225 |
+ if (db_url.s==0) |
|
210 | 226 |
{ |
211 | 227 |
LM_ERR("you have to config a db url for using avp_db_xxx functions\n"); |
212 | 228 |
return E_UNSPEC; |
... | ... |
@@ -315,7 +331,7 @@ static int fixup_db_query_avp(void** param, int param_no) |
315 | 331 |
pvname_list_t *anlist = NULL; |
316 | 332 |
str s; |
317 | 333 |
|
318 |
- if (DB_URL==0) |
|
334 |
+ if (db_url.s==0) |
|
319 | 335 |
{ |
320 | 336 |
LM_ERR("you have to config a db url for using avp_db_query function\n"); |
321 | 337 |
return E_UNSPEC; |
... | ... |
@@ -39,8 +39,8 @@ |
39 | 39 |
|
40 | 40 |
static db_con_t *db_hdl=0; /* DB handler */ |
41 | 41 |
static db_func_t avpops_dbf; /* DB functions */ |
42 |
-static char *def_table; /* default DB table */ |
|
43 |
-static char **db_columns; /* array with names of DB columns */ |
|
42 |
+static str def_table; /* default DB table */ |
|
43 |
+static str **db_columns; /* array with names of DB columns */ |
|
44 | 44 |
|
45 | 45 |
static db_key_t keys_cmp[3]; /* array of keys and values used in selection */ |
46 | 46 |
static db_val_t vals_cmp[3]; /* statement as in "select" and "delete" */ |
... | ... |
@@ -49,9 +49,9 @@ static db_val_t vals_cmp[3]; /* statement as in "select" and "delete" */ |
49 | 49 |
static struct db_scheme *db_scheme_list=0; |
50 | 50 |
|
51 | 51 |
|
52 |
-int avpops_db_bind(char* db_url) |
|
52 |
+int avpops_db_bind(const str* db_url) |
|
53 | 53 |
{ |
54 |
- if (bind_dbmod(db_url, &avpops_dbf )) |
|
54 |
+ if (db_bind_mod(db_url, &avpops_dbf )) |
|
55 | 55 |
{ |
56 | 56 |
LM_CRIT("cannot bind to database module! " |
57 | 57 |
"Did you load a database module ?\n"); |
... | ... |
@@ -70,8 +70,9 @@ int avpops_db_bind(char* db_url) |
70 | 70 |
} |
71 | 71 |
|
72 | 72 |
|
73 |
-int avpops_db_init(char* db_url, char* db_table, char **db_cols) |
|
73 |
+int avpops_db_init(const str* db_url, const str* db_table, str** db_cols) |
|
74 | 74 |
{ |
75 |
+ |
|
75 | 76 |
db_hdl = avpops_dbf.init(db_url); |
76 | 77 |
if (db_hdl==0) |
77 | 78 |
{ |
... | ... |
@@ -80,10 +81,11 @@ int avpops_db_init(char* db_url, char* db_table, char **db_cols) |
80 | 81 |
} |
81 | 82 |
if (avpops_dbf.use_table(db_hdl, db_table)<0) |
82 | 83 |
{ |
83 |
- LM_ERR("cannot select table \"%s\"\n", db_table); |
|
84 |
+ LM_ERR("cannot select table \"%.*s\"\n", db_table->len, db_table->s); |
|
84 | 85 |
goto error; |
85 | 86 |
} |
86 |
- def_table = db_table; |
|
87 |
+ def_table.s = db_table->s; |
|
88 |
+ def_table.len = db_table->len; |
|
87 | 89 |
db_columns = db_cols; |
88 | 90 |
|
89 | 91 |
return 0; |
... | ... |
@@ -125,13 +127,14 @@ int avp_add_db_scheme( modparam_t type, void* val) |
125 | 127 |
|
126 | 128 |
/* print scheme */ |
127 | 129 |
LM_DBG("new scheme <%s> added\n" |
128 |
- "\t\tuuid_col=<%s>\n\t\tusername_col=<%s>\n" |
|
129 |
- "\t\tdomain_col=<%s>\n\t\tvalue_col=<%s>\n" |
|
130 |
- "\t\tdb_flags=%d\n\t\ttable=<%s>\n", |
|
130 |
+ "\t\tuuid_col=<%.*s>\n\t\tusername_col=<%.*s>\n" |
|
131 |
+ "\t\tdomain_col=<%.*s>\n\t\tvalue_col=<%.*s>\n" |
|
132 |
+ "\t\tdb_flags=%d\n\t\ttable=<%.*s>\n", |
|
131 | 133 |
scheme->name, |
132 |
- scheme->uuid_col, scheme->username_col, |
|
133 |
- scheme->domain_col, scheme->value_col, |
|
134 |
- scheme->db_flags, scheme->table ); |
|
134 |
+ scheme->uuid_col->len, scheme->uuid_col->s, scheme->username_col->len, |
|
135 |
+ scheme->username_col->s, scheme->domain_col->len, scheme->domain_col->s, |
|
136 |
+ scheme->value_col->len, scheme->value_col->s, scheme->db_flags, |
|
137 |
+ scheme->table->len, scheme->table->s); |
|
135 | 138 |
|
136 | 139 |
scheme->next = db_scheme_list; |
137 | 140 |
db_scheme_list = scheme; |
... | ... |
@@ -153,22 +156,21 @@ struct db_scheme *avp_get_db_scheme (char *name) |
153 | 156 |
} |
154 | 157 |
|
155 | 158 |
|
156 |
-static inline int set_table( char *table, char *func) |
|
159 |
+static inline int set_table( const str *table, char *func) |
|
157 | 160 |
{ |
158 | 161 |
static int default_set = 1; |
159 |
- |
|
160 |
- if (table) |
|
162 |
+ if (table->s) |
|
161 | 163 |
{ |
162 | 164 |
if ( avpops_dbf.use_table( db_hdl, table)<0 ) |
163 | 165 |
{ |
164 |
- LM_ERR("db-%s: cannot set table \"%s\"\n", func, table); |
|
166 |
+ LM_ERR("db-%s: cannot set table \"%.*s\"\n", func, table->len, table->s); |
|
165 | 167 |
return -1; |
166 | 168 |
} |
167 | 169 |
default_set = 0; |
168 | 170 |
} else if (!default_set){ |
169 |
- if ( avpops_dbf.use_table( db_hdl, def_table)<0 ) |
|
171 |
+ if ( avpops_dbf.use_table( db_hdl, &def_table)<0 ) |
|
170 | 172 |
{ |
171 |
- LM_ERR("db-%s: cannot set table \"%s\"\n", func, def_table); |
|
173 |
+ LM_ERR("db-%s: cannot set table \"%.*s\"\n", func, def_table.len, def_table.s); |
|
172 | 174 |
return -1; |
173 | 175 |
} |
174 | 176 |
default_set = 1; |
... | ... |
@@ -229,7 +231,7 @@ static inline int prepare_selection( str *uuid, str *username, str *domain, |
229 | 231 |
|
230 | 232 |
|
231 | 233 |
db_res_t *db_load_avp( str *uuid, str *username, str *domain, |
232 |
- char *attr, char *table, struct db_scheme *scheme) |
|
234 |
+ char *attr, const str *table, struct db_scheme *scheme) |
|
233 | 235 |
{ |
234 | 236 |
static db_key_t keys_ret[3]; |
235 | 237 |
unsigned int nr_keys_cmp; |
... | ... |
@@ -272,10 +274,9 @@ void db_close_query( db_res_t *res ) |
272 | 274 |
} |
273 | 275 |
|
274 | 276 |
|
275 |
-int db_store_avp( db_key_t *keys, db_val_t *vals, int n, char *table) |
|
277 |
+int db_store_avp( db_key_t *keys, db_val_t *vals, int n, const str *table) |
|
276 | 278 |
{ |
277 | 279 |
int r; |
278 |
- |
|
279 | 280 |
if (set_table( table ,"store")!=0) |
280 | 281 |
return -1; |
281 | 282 |
|
... | ... |
@@ -291,7 +292,7 @@ int db_store_avp( db_key_t *keys, db_val_t *vals, int n, char *table) |
291 | 292 |
|
292 | 293 |
|
293 | 294 |
int db_delete_avp( str *uuid, str *username, str *domain, char *attr, |
294 |
- char *table) |
|
295 |
+ const str *table) |
|
295 | 296 |
{ |
296 | 297 |
unsigned int nr_keys_cmp; |
297 | 298 |
|
... | ... |
@@ -317,6 +318,7 @@ int db_query_avp(struct sip_msg *msg, char *query, pvname_list_t* dest) |
317 | 318 |
db_res_t* db_res = NULL; |
318 | 319 |
int i, j; |
319 | 320 |
pvname_list_t* crt; |
321 |
+ static str query_str; |
|
320 | 322 |
|
321 | 323 |
if(query==NULL) |
322 | 324 |
{ |
... | ... |
@@ -324,7 +326,10 @@ int db_query_avp(struct sip_msg *msg, char *query, pvname_list_t* dest) |
324 | 326 |
return -1; |
325 | 327 |
} |
326 | 328 |
|
327 |
- if(avpops_dbf.raw_query(db_hdl, query, &db_res)!=0) |
|
329 |
+ query_str.s = query; |
|
330 |
+ query_str.len = strlen(query); |
|
331 |
+ |
|
332 |
+ if(avpops_dbf.raw_query(db_hdl, &query_str, &db_res)!=0) |
|
328 | 333 |
{ |
329 | 334 |
LM_ERR("cannot do the query\n"); |
330 | 335 |
return -1; |
... | ... |
@@ -41,29 +41,29 @@ |
41 | 41 |
struct db_scheme |
42 | 42 |
{ |
43 | 43 |
char *name; |
44 |
- char *uuid_col; |
|
45 |
- char *username_col; |
|
46 |
- char *domain_col; |
|
47 |
- char *value_col; |
|
48 |
- char *table; |
|
44 |
+ str *uuid_col; |
|
45 |
+ str *username_col; |
|
46 |
+ str *domain_col; |
|
47 |
+ str *value_col; |
|
48 |
+ str *table; |
|
49 | 49 |
int db_flags; |
50 | 50 |
struct db_scheme *next; |
51 | 51 |
}; |
52 | 52 |
|
53 | 53 |
|
54 |
-int avpops_db_bind(char* db_url); |
|
54 |
+int avpops_db_bind(const str* db_url); |
|
55 | 55 |
|
56 |
-int avpops_db_init(char* db_url, char* db_table, char **db_columns); |
|
56 |
+int avpops_db_init(const str* db_url, const str* db_table, str **db_columns); |
|
57 | 57 |
|
58 | 58 |
db_res_t *db_load_avp( str *uuid, str *username, str *domain, |
59 |
- char *attr, char *table, struct db_scheme *scheme); |
|
59 |
+ char *attr, const str *table, struct db_scheme *scheme); |
|
60 | 60 |
|
61 | 61 |
void db_close_query( db_res_t *res ); |
62 | 62 |
|
63 |
-int db_store_avp( db_key_t *keys, db_val_t *vals, int n, char *table); |
|
63 |
+int db_store_avp( db_key_t *keys, db_val_t *vals, int n, const str *table); |
|
64 | 64 |
|
65 | 65 |
int db_delete_avp( str *uuid, str *username, str *domain, |
66 |
- char *attr, char *table); |
|
66 |
+ char *attr, const str *table); |
|
67 | 67 |
|
68 | 68 |
int db_query_avp(struct sip_msg* msg, char *query, pvname_list_t* dest); |
69 | 69 |
|
... | ... |
@@ -66,7 +66,7 @@ static str empty={"",0}; |
66 | 66 |
#define AVP_PRINTBUF_SIZE 1024 |
67 | 67 |
static char printbuf[AVP_PRINTBUF_SIZE]; |
68 | 68 |
|
69 |
-void init_store_avps( char **db_columns) |
|
69 |
+void init_store_avps(str **db_columns) |
|
70 | 70 |
{ |
71 | 71 |
/* unique user id */ |
72 | 72 |
store_keys[0] = db_columns[0]; /*uuid*/ |
... | ... |
@@ -114,11 +114,11 @@ struct db_param |
114 | 114 |
{ |
115 | 115 |
struct fis_param a; /* attribute */ |
116 | 116 |
str sa; /* attribute as str (for db queries) */ |
117 |
- char *table; /* DB table/scheme name */ |
|
117 |
+ str *table; /* DB table/scheme name */ |
|
118 | 118 |
struct db_scheme *scheme; /* DB scheme */ |
119 | 119 |
}; |
120 | 120 |
|
121 |
-void init_store_avps(char **db_columns); |
|
121 |
+void init_store_avps(str **db_columns); |
|
122 | 122 |
|
123 | 123 |
int ops_dbload_avps (struct sip_msg* msg, struct fis_param *sp, |
124 | 124 |
struct db_param *dbp, int use_domain); |
... | ... |
@@ -287,15 +287,8 @@ int parse_avp_db(char *s, struct db_param *dbp, int allow_scheme) |
287 | 287 |
/* update scheme flags with AVP name type*/ |
288 | 288 |
dbp->scheme->db_flags|=dbp->a.opd&AVPOPS_VAL_STR?AVP_NAME_STR:0; |
289 | 289 |
} else { |
290 |
- /* duplicate table as str NULL terminated */ |
|
291 |
- dbp->table = (char*)pkg_malloc( tmp.len + 1 ); |
|
292 |
- if (dbp->table==0) |
|
293 |
- { |
|
294 |
- LM_ERR("no more pkg mem\n"); |
|
295 |
- goto error;; |
|
296 |
- } |
|
297 |
- memcpy( dbp->table, tmp.s, tmp.len); |
|
298 |
- dbp->table[tmp.len] = 0; |
|
290 |
+ /* duplicate table as str */ |
|
291 |
+ pkg_str_dup(dbp->table, &tmp); |
|
299 | 292 |
} |
300 | 293 |
} |
301 | 294 |
|
... | ... |
@@ -471,27 +464,27 @@ int parse_avp_db_scheme( char *s, struct db_scheme *scheme) |
471 | 464 |
if ( foo.len==SCHEME_UUID_COL_LEN && |
472 | 465 |
!strncasecmp( foo.s, SCHEME_UUID_COL, foo.len) ) |
473 | 466 |
{ |
474 |
- duplicate_str( scheme->uuid_col, bar, error); |
|
467 |
+ duplicate_str( scheme->uuid_col->s, bar, error); |
|
475 | 468 |
} else |
476 | 469 |
if ( foo.len==SCHEME_USERNAME_COL_LEN && |
477 | 470 |
!strncasecmp( foo.s, SCHEME_USERNAME_COL, foo.len) ) |
478 | 471 |
{ |
479 |
- duplicate_str( scheme->username_col, bar, error); |
|
472 |
+ duplicate_str( scheme->username_col->s, bar, error); |
|
480 | 473 |
} else |
481 | 474 |
if ( foo.len==SCHEME_DOMAIN_COL_LEN && |
482 | 475 |
!strncasecmp( foo.s, SCHEME_DOMAIN_COL, foo.len) ) |
483 | 476 |
{ |
484 |
- duplicate_str( scheme->domain_col, bar, error); |
|
477 |
+ duplicate_str( scheme->domain_col->s, bar, error); |
|
485 | 478 |
} else |
486 | 479 |
if ( foo.len==SCHEME_VALUE_COL_LEN && |
487 | 480 |
!strncasecmp( foo.s, SCHEME_VALUE_COL, foo.len) ) |
488 | 481 |
{ |
489 |
- duplicate_str( scheme->value_col, bar, error); |
|
482 |
+ duplicate_str( scheme->value_col->s, bar, error); |
|
490 | 483 |
} else |
491 | 484 |
if ( foo.len==SCHEME_TABLE_LEN && |
492 | 485 |
!strncasecmp( foo.s, SCHEME_TABLE, foo.len) ) |
493 | 486 |
{ |
494 |
- duplicate_str( scheme->table, bar, error); |
|
487 |
+ duplicate_str( scheme->table->s, bar, error); |
|
495 | 488 |
} else |
496 | 489 |
if ( foo.len==SCHEME_VAL_TYPE_LEN && |
497 | 490 |
!strncasecmp( foo.s, SCHEME_VAL_TYPE, foo.len) ) |
... | ... |
@@ -52,33 +52,51 @@ |
52 | 52 |
|
53 | 53 |
MODULE_VERSION |
54 | 54 |
|
55 |
-char* db_url = DEFAULT_RODB_URL; |
|
56 |
-char * db_table = "carrierroute"; |
|
57 |
-char * subscriber_table = "subscriber"; |
|
58 |
-char * carrier_table = "route_tree"; |
|
59 |
- |
|
60 |
-char * columns[COLUMN_NUM] = { |
|
61 |
- "id", |
|
62 |
- "carrier", |
|
63 |
- "scan_prefix", |
|
64 |
- "domain", |
|
65 |
- "prob", |
|
66 |
- "rewrite_host", |
|
67 |
- "strip", |
|
68 |
- "rewrite_prefix", |
|
69 |
- "rewrite_suffix", |
|
70 |
- "comment" |
|
55 |
+str db_url = str_init(DEFAULT_RODB_URL); |
|
56 |
+str db_table = str_init("carrierroute"); |
|
57 |
+str subscriber_table = str_init("subscriber"); |
|
58 |
+str carrier_table = str_init("route_tree"); |
|
59 |
+ |
|
60 |
+static str id_col = str_init("id"); |
|
61 |
+static str carrier_col = str_init("carrier"); |
|
62 |
+static str scan_prefix_col = str_init("scan_prefix"); |
|
63 |
+static str domain_col = str_init("domain"); |
|
64 |
+static str prob_col = str_init("prob"); |
|
65 |
+static str rewrite_host_col = str_init("rewrite_host"); |
|
66 |
+static str strip_col = str_init("strip"); |
|
67 |
+static str rewrite_prefix_col = str_init("rewrite_prefix"); |
|
68 |
+static str rewrite_suffix_col = str_init("rewrite_suffix"); |
|
69 |
+static str comment_col = str_init("comment"); |
|
70 |
+static str username_col = str_init("username"); |
|
71 |
+static str cr_preferred_carrier_col = str_init("cr_preferred_carrier"); |
|
72 |
+static str subscriber_domain_col = str_init("domain"); |
|
73 |
+static str carrier_id_col = str_init("id"); |
|
74 |
+static str carrier_name_col = str_init("carrier"); |
|
75 |
+ |
|
76 |
+ |
|
77 |
+ |
|
78 |
+str * columns[COLUMN_NUM] = { |
|
79 |
+ &id_col, |
|
80 |
+ &carrier_col, |
|
81 |
+ &scan_prefix_col, |
|
82 |
+ &domain_col, |
|
83 |
+ &prob_col, |
|
84 |
+ &rewrite_host_col, |
|
85 |
+ &strip_col, |
|
86 |
+ &rewrite_prefix_col, |
|
87 |
+ &rewrite_suffix_col, |
|
88 |
+ &comment_col, |
|
71 | 89 |
}; |
72 | 90 |
|
73 |
-char * subscriber_columns[SUBSCRIBER_COLUMN_NUM] = { |
|
74 |
- "username", |
|
75 |
- "domain", |
|
76 |
- "cr_preferred_carrier" |
|
91 |
+str * subscriber_columns[SUBSCRIBER_COLUMN_NUM] = { |
|
92 |
+ &username_col, |
|
93 |
+ &domain_col, |
|
94 |
+ &cr_preferred_carrier_col, |
|
77 | 95 |
}; |
78 | 96 |
|
79 |
-char * carrier_columns[CARRIER_COLUMN_NUM] = { |
|
80 |
- "id", |
|
81 |
- "carrier" |
|
97 |
+str * carrier_columns[CARRIER_COLUMN_NUM] = { |
|
98 |
+ &id_col, |
|
99 |
+ &carrier_col, |
|
82 | 100 |
}; |
83 | 101 |
|
84 | 102 |
char * config_source = "file"; |
... | ... |
@@ -117,25 +135,25 @@ static cmd_export_t cmds[]={ |
117 | 135 |
}; |
118 | 136 |
|
119 | 137 |
static param_export_t params[]= { |
120 |
- {"db_url", STR_PARAM, &db_url }, |
|
121 |
- {"db_table", STR_PARAM, &db_table }, |
|
122 |
- {"carrier_table", STR_PARAM, &carrier_table }, |
|
123 |
- {"subscriber_table", STR_PARAM, &subscriber_table }, |
|
124 |
- {"id_column", STR_PARAM, &columns[COL_ID] }, |
|
125 |
- {"carrier_column", STR_PARAM, &columns[COL_CARRIER] }, |
|
126 |
- {"scan_prefix_column", STR_PARAM, &columns[COL_SCAN_PREFIX] }, |
|
127 |
- {"domain_column", STR_PARAM, &columns[COL_DOMAIN] }, |
|
128 |
- {"prob_column", STR_PARAM, &columns[COL_PROB] }, |
|
129 |
- {"rewrite_host_column", STR_PARAM, &columns[COL_REWRITE_HOST] }, |
|
130 |
- {"strip_column", STR_PARAM, &columns[COL_STRIP] }, |
|
131 |
- {"rewrite_prefix_column", STR_PARAM, &columns[COL_REWRITE_PREFIX] }, |
|
132 |
- {"rewrite_suffix_column", STR_PARAM, &columns[COL_REWRITE_SUFFIX] }, |
|
133 |
- {"comment_column", STR_PARAM, &columns[COL_COMMENT] }, |
|
134 |
- {"subscriber_user_col", STR_PARAM, &subscriber_columns[SUBSCRIBER_USERNAME_COL] }, |
|
135 |
- {"subscriber_domain_col", STR_PARAM, &subscriber_columns[SUBSCRIBER_DOMAIN_COL] }, |
|
136 |
- {"subscriber_carrier_col", STR_PARAM, &subscriber_columns[SUBSCRIBER_CARRIER_COL] }, |
|
137 |
- {"carrier_id_col", STR_PARAM, &carrier_columns[CARRIER_ID_COL] }, |
|
138 |
- {"carrier_name_col", STR_PARAM, &carrier_columns[CARRIER_NAME_COL] }, |
|
138 |
+ {"db_url", STR_PARAM, &db_url.s }, |
|
139 |
+ {"db_table", STR_PARAM, &db_table.s }, |
|
140 |
+ {"carrier_table", STR_PARAM, &carrier_table.s }, |
|
141 |
+ {"subscriber_table", STR_PARAM, &subscriber_table.s }, |
|
142 |
+ {"id_column", STR_PARAM, &id_col.s }, |
|
143 |
+ {"carrier_column", STR_PARAM, &carrier_col.s }, |
|
144 |
+ {"scan_prefix_column", STR_PARAM, &scan_prefix_col.s }, |
|
145 |
+ {"domain_column", STR_PARAM, &domain_col.s }, |
|
146 |
+ {"prob_column", STR_PARAM, &prob_col.s }, |
|
147 |
+ {"rewrite_host_column", STR_PARAM, &rewrite_host_col.s }, |
|
148 |
+ {"strip_column", STR_PARAM, &strip_col.s }, |
|
149 |
+ {"rewrite_prefix_column", STR_PARAM, &rewrite_prefix_col.s }, |
|
150 |
+ {"rewrite_suffix_column", STR_PARAM, &rewrite_suffix_col.s }, |
|
151 |
+ {"comment_column", STR_PARAM, &comment_col.s }, |
|
152 |
+ {"subscriber_user_col", STR_PARAM, &username_col.s }, |
|
153 |
+ {"subscriber_domain_col", STR_PARAM, &subscriber_domain_col.s }, |
|
154 |
+ {"subscriber_carrier_col", STR_PARAM, &cr_preferred_carrier_col.s }, |
|
155 |
+ {"carrier_id_col", STR_PARAM, &carrier_id_col.s }, |
|
156 |
+ {"carrier_name_col", STR_PARAM, &carrier_name_col.s }, |
|
139 | 157 |
{"config_source", STR_PARAM, &config_source }, |
140 | 158 |
{"default_tree", STR_PARAM, &default_tree }, |
141 | 159 |
{"config_file", STR_PARAM, &config_file }, |
... | ... |
@@ -178,6 +196,27 @@ struct module_exports exports = { |
178 | 196 |
* @return 0 on success, -1 on failure |
179 | 197 |
*/ |
180 | 198 |
static int mod_init(void) { |
199 |
+ |
|
200 |
+ db_url.len = strlen(db_url.s); |
|
201 |
+ db_table.len = strlen(db_table.s); |
|
202 |
+ carrier_table.len = strlen(carrier_table.s); |
|
203 |
+ subscriber_table.len = strlen(subscriber_table.s); |
|
204 |
+ id_col.len = strlen(id_col.s); |
|
205 |
+ carrier_col.len = strlen(carrier_col.s); |
|
206 |
+ scan_prefix_col.len = strlen(scan_prefix_col.s); |
|
207 |
+ domain_col.len = strlen(domain_col.s); |
|
208 |
+ prob_col.len = strlen(prob_col.s); |
|
209 |
+ rewrite_host_col.len = strlen(rewrite_host_col.s); |
|
210 |
+ strip_col.len = strlen(strip_col.s); |
|
211 |
+ rewrite_prefix_col.len = strlen(rewrite_prefix_col.s); |
|
212 |
+ rewrite_suffix_col.len = strlen(rewrite_suffix_col.s); |
|
213 |
+ comment_col.len = strlen(comment_col.s); |
|
214 |
+ username_col.len = strlen(username_col.s); |
|
215 |
+ subscriber_domain_col.len = strlen(subscriber_domain_col.s); |
|
216 |
+ cr_preferred_carrier_col.len = strlen(cr_preferred_carrier_col.s); |
|
217 |
+ carrier_id_col.len = strlen(carrier_id_col.s); |
|
218 |
+ carrier_name_col.len = strlen(carrier_name_col.s); |
|
219 |
+ |
|
181 | 220 |
if (init_route_data(config_source) < 0) { |
182 | 221 |
LM_ERR("could not init route data\n"); |
183 | 222 |
return -1; |
... | ... |
@@ -79,13 +79,13 @@ |
79 | 79 |
#define ROUTE_TABLE_VER 1 |
80 | 80 |
#define CARRIER_TABLE_VER 1 |
81 | 81 |
|
82 |
-extern char * db_url; |
|
83 |
-extern char * db_table; |
|
84 |
-extern char * carrier_table; |
|
85 |
-extern char * subscriber_table; |
|
86 |
-extern char * subscriber_columns[]; |
|
87 |
-extern char * carrier_columns[]; |
|
88 |
-extern char * columns[]; |
|
82 |
+extern str db_url; |
|
83 |
+extern str db_table; |
|
84 |
+extern str carrier_table; |
|
85 |
+extern str subscriber_table; |
|
86 |
+extern str * subscriber_columns[]; |
|
87 |
+extern str * carrier_columns[]; |
|
88 |
+extern str * columns[]; |
|
89 | 89 |
extern char * config_source; |
90 | 90 |
extern char * config_file; |
91 | 91 |
extern char * default_tree; |
... | ... |
@@ -67,17 +67,14 @@ db_con_t * dbh = NULL; |
67 | 67 |
* |
68 | 68 |
* @return 0 means ok, -1 means an error occured |
69 | 69 |
*/ |
70 |
-int check_table_version(db_func_t* dbf, db_con_t* dbh, char* table, const int version) { |
|
71 |
- str tmp; |
|
72 |
- tmp.s = table; |
|
73 |
- tmp.len = strlen(table); |
|
70 |
+static int check_table_version(db_func_t* dbf, db_con_t* dbh, const str* table, const int version) { |
|
74 | 71 |
|
75 |
- int ver = table_version(dbf, dbh, &tmp); |
|
72 |
+ int ver = db_table_version(dbf, dbh, table); |
|
76 | 73 |
if (ver < 0) { |
77 |
- LM_ERR("Error while querying version for table %.*s\n", tmp.len, tmp.s); |
|
74 |
+ LM_ERR("Error while querying version for table %.*s\n", table->len, table->s); |
|
78 | 75 |
return -1; |
79 | 76 |
} else if (ver < version) { |
80 |
- LM_ERR("Invalid version for table %.*s found\n", tmp.len, tmp.s); |
|
77 |
+ LM_ERR("Invalid version for table %.*s found\n", table->len, table->s); |
|
81 | 78 |
return -1; |
82 | 79 |
} |
83 | 80 |
return 0; |
... | ... |
@@ -89,20 +86,20 @@ int check_table_version(db_func_t* dbf, db_con_t* dbh, char* table, const int ve |
89 | 86 |
* @return 0 means ok, -1 means an error occured. |
90 | 87 |
*/ |
91 | 88 |
int db_init(void) { |
92 |
- if (db_url == NULL) { |
|
89 |
+ if (!db_url.s) { |
|
93 | 90 |
LM_ERR("You have to set the db_url module parameter.\n"); |
94 | 91 |
return -1; |
95 | 92 |
} |
96 |
- if (bind_dbmod(db_url, &dbf) < 0) { |
|
93 |
+ if (db_bind_mod(&db_url, &dbf) < 0) { |
|
97 | 94 |
LM_ERR("Can't bind database module.\n"); |
98 | 95 |
return -1; |
99 | 96 |
} |
100 |
- if((dbh = dbf.init(db_url)) == NULL){ |
|
97 |
+ if((dbh = dbf.init(&db_url)) == NULL){ |
|
101 | 98 |
LM_ERR("Can't connect to database.\n"); |
102 | 99 |
return -1; |
103 | 100 |
} |
104 |
- if ( (check_table_version(&dbf, dbh, db_table, ROUTE_TABLE_VER) < 0) || |
|
105 |
- (check_table_version(&dbf, dbh, carrier_table, CARRIER_TABLE_VER) < 0) ) { |
|
101 |
+ if ( (check_table_version(&dbf, dbh, &db_table, ROUTE_TABLE_VER) < 0) || |
|
102 |
+ (check_table_version(&dbf, dbh, &carrier_table, CARRIER_TABLE_VER) < 0) ) { |
|
106 | 103 |
LM_ERR("Error during table version check.\n"); |
107 | 104 |
return -1; |
108 | 105 |
} |
... | ... |
@@ -118,7 +115,7 @@ int db_child_init(void) { |
118 | 115 |
if(dbh){ |
119 | 116 |
dbf.close(dbh); |
120 | 117 |
} |
121 |
- if((dbh = dbf.init(db_url)) == NULL){ |
|
118 |
+ if((dbh = dbf.init(&db_url)) == NULL){ |
|
122 | 119 |
LM_ERR("Can't connect to database.\n"); |
123 | 120 |
return -1; |
124 | 121 |
} |
... | ... |
@@ -158,7 +155,7 @@ int load_user_carrier(str * user, str * domain) { |
158 | 155 |
vals[1].nul = 0; |
159 | 156 |
vals[1].val.str_val = *domain; |
160 | 157 |
|
161 |
- if (dbf.use_table(dbh, subscriber_table) < 0) { |
|
158 |
+ if (dbf.use_table(dbh, &subscriber_table) < 0) { |
|
162 | 159 |
LM_ERR("can't use table\n"); |
163 | 160 |
} |
164 | 161 |
|
... | ... |
@@ -190,14 +187,15 @@ int load_user_carrier(str * user, str * domain) { |
190 | 187 |
int load_route_data(struct rewrite_data * rd) { |
191 | 188 |
db_res_t * res = NULL; |
192 | 189 |
db_row_t * row = NULL; |
193 |
- int i; |
|
190 |
+ int i, ret; |
|
194 | 191 |
int carrier_count = 0; |
195 | 192 |
struct carrier * carriers = NULL, * tmp = NULL; |
193 |
+ static str query_str; |
|
196 | 194 |
|
197 | 195 |
if ((strlen("SELECT DISTINCT FROM WHERE = ") |
198 |
- + strlen(db_table) |
|
199 |
- + strlen(columns[COL_DOMAIN]) |
|
200 |
- + strlen(columns[COL_CARRIER]) |
|
196 |
+ + db_table.len |
|
197 |
+ + columns[COL_DOMAIN]->len |
|
198 |
+ + columns[COL_CARRIER]->len |
|
201 | 199 |
+ 20) > QUERY_LEN) { |
202 | 200 |
LM_ERR("query too long\n"); |
203 | 201 |
return -1; |
... | ... |
@@ -215,16 +213,24 @@ int load_route_data(struct rewrite_data * rd) { |
215 | 213 |
memset(rd->carriers, 0, sizeof(struct carrier_tree *) * carrier_count); |
216 | 214 |
rd->tree_num = carrier_count; |
217 | 215 |
|
218 |
- |
|
219 | 216 |
tmp = carriers; |
220 | 217 |
for (i=0; i<carrier_count; i++) { |
221 | 218 |
memset(query, 0, QUERY_LEN); |
222 |
- snprintf(query, QUERY_LEN, "SELECT DISTINCT %s FROM %s WHERE %s=%i", columns[COL_DOMAIN], db_table, columns[COL_CARRIER], tmp->id); |
|
223 |
- if (dbf.raw_query(dbh, query, &res) < 0) { |
|
219 |
+ ret = snprintf(query, QUERY_LEN, "SELECT DISTINCT %.*s FROM %.*s WHERE %.*s=%i", |
|
220 |
+ columns[COL_DOMAIN]->len, columns[COL_DOMAIN]->s, db_table.len, db_table.s, |
|
221 |
+ columns[COL_CARRIER]->len, columns[COL_CARRIER]->s, tmp->id); |
|
222 |
+ if (ret < 0) { |
|
223 |
+ LM_ERR("error in snprintf"); |
|
224 |
+ goto errout; |
|
225 |
+ } |
|
226 |
+ query_str.s = query; |
|
227 |
+ query_str.len = ret; |
|
228 |
+ |
|
229 |
+ if (dbf.raw_query(dbh, &query_str, &res) < 0) { |
|
224 | 230 |
LM_ERR("Failed to query database.\n"); |
225 | 231 |
goto errout; |
226 | 232 |
} |
227 |
- LM_INFO("add_carrier: name %s, id %i, trees: %i\n", tmp->name, tmp->id, RES_ROW_N(res)); |
|
233 |
+ LM_INFO("add_carrier: name %s, id %i, trees: %i\n", tmp->name, tmp->id, RES_ROW_N(res)); |
|
228 | 234 |
if (add_carrier_tree(tmp->name, tmp->id, rd, RES_ROW_N(res)) == NULL) { |
229 | 235 |
LM_ERR("cant add carrier %s\n", tmp->name); |
230 | 236 |
goto errout; |
... | ... |
@@ -234,13 +240,12 @@ int load_route_data(struct rewrite_data * rd) { |
234 | 240 |
res = NULL; |
235 | 241 |
} |
236 | 242 |
|
237 |
- if (dbf.use_table(dbh, db_table) < 0) { |
|
238 |
- LM_ERR("Cannot set database table '%s'.\n", |
|
239 |
- db_table); |
|
243 |
+ if (dbf.use_table(dbh, &db_table) < 0) { |
|
244 |
+ LM_ERR("Cannot set database table '%.*s'.\n", db_table.len, db_table.s); |
|
240 | 245 |
return -1; |
241 | 246 |
} |
242 | 247 |
|
243 |
- if (dbf.query(dbh, NULL, NULL, NULL, (const char **)columns, 0, |
|
248 |
+ if (dbf.query(dbh, NULL, NULL, NULL, (db_key_t *)columns, 0, |
|
244 | 249 |
COLUMN_NUM, NULL, &res) < 0) { |
245 | 250 |
LM_ERR("Failed to query database.\n"); |
246 | 251 |
return -1; |
... | ... |
@@ -286,12 +291,12 @@ static int store_carriers(struct carrier ** start){ |
286 | 291 |
LM_ERR("invalid parameter\n"); |
287 | 292 |
return -1; |
288 | 293 |
} |
289 |
- if (dbf.use_table(dbh, carrier_table) < 0) { |
|
294 |
+ if (dbf.use_table(dbh, &carrier_table) < 0) { |
|
290 | 295 |
LM_ERR("couldn't use table\n"); |
291 | 296 |
return -1; |
292 | 297 |
} |
293 | 298 |
|
294 |
- if (dbf.query(dbh, 0, 0, 0, (const char **)carrier_columns, 0, CARRIER_COLUMN_NUM, 0, &res) < 0) { |
|
299 |
+ if (dbf.query(dbh, 0, 0, 0, (db_key_t *)carrier_columns, 0, CARRIER_COLUMN_NUM, 0, &res) < 0) { |
|
295 | 300 |
LM_ERR("couldn't query table\n"); |
296 | 301 |
return -1; |
297 | 302 |
} |
... | ... |
@@ -71,11 +71,11 @@ |
71 | 71 |
|
72 | 72 |
|
73 | 73 |
/* modules param variables */ |
74 |
-static char *DB_URL = 0; /* database url */ |
|
75 |
-static char *DB_TABLE = 0; /* */ |
|
74 |
+static str db_url = {NULL, 0}; /* database url */ |
|
75 |
+static str db_table = {NULL, 0}; /* database table */ |
|
76 | 76 |
static char *dtd_file = 0; /* name of the DTD file for CPL parser */ |
77 | 77 |
static char *lookup_domain = 0; |
78 |
-static char *timer_avp = 0; /* name of variable timer AVP */ |
|
78 |
+static str timer_avp = {NULL, 0}; /* name of variable timer AVP */ |
|
79 | 79 |
|
80 | 80 |
|
81 | 81 |
struct cpl_enviroment cpl_env = { |
... | ... |
@@ -139,8 +139,8 @@ static cmd_export_t cmds[] = { |
139 | 139 |
* Exported parameters |
140 | 140 |
*/ |
141 | 141 |
static param_export_t params[] = { |
142 |
- {"db_url", STR_PARAM, &DB_URL }, |
|
143 |
- {"cpl_table", STR_PARAM, &DB_TABLE }, |
|
142 |
+ {"db_url", STR_PARAM, &db_url.s }, |
|
143 |
+ {"cpl_table", STR_PARAM, &db_table.s }, |
|
144 | 144 |
{"cpl_dtd_file", STR_PARAM, &dtd_file }, |
145 | 145 |
{"proxy_recurse", INT_PARAM, &cpl_env.proxy_recurse }, |
146 | 146 |
{"proxy_route", INT_PARAM, &cpl_env.proxy_route }, |
... | ... |
@@ -149,7 +149,7 @@ static param_export_t params[] = { |
149 | 149 |
{"realm_prefix", STR_PARAM, &cpl_env.realm_prefix.s }, |
150 | 150 |
{"lookup_domain", STR_PARAM, &lookup_domain }, |
151 | 151 |
{"lookup_append_branches", INT_PARAM, &cpl_env.lu_append_branches}, |
152 |
- {"timer_avp", STR_PARAM, &timer_avp }, |
|
152 |
+ {"timer_avp", STR_PARAM, &timer_avp.s }, |
|
153 | 153 |
{"username_column",STR_PARAM, &cpl_username_col }, |
154 | 154 |
{"domain_column", STR_PARAM, &cpl_domain_col }, |
155 | 155 |
{"cpl_xml_column", STR_PARAM, &cpl_xml_col }, |
... | ... |
@@ -232,17 +232,20 @@ static int cpl_init(void) |
232 | 232 |
int val; |
233 | 233 |
pv_spec_t avp_spec; |
234 | 234 |
unsigned short avp_type; |
235 |
- str stmp; |
|
235 |
+ |
|
236 |
+ if (db_url.s) db_url.len = strlen(db_url.s); |
|
237 |
+ if (db_table.s) db_table.len = strlen(db_table.s); |
|
238 |
+ if (timer_avp.s) timer_avp.len = strlen(timer_avp.s); |
|
236 | 239 |
|
237 | 240 |
LM_INFO("initializing...\n"); |
238 | 241 |
|
239 | 242 |
/* check the module params */ |
240 |
- if (DB_URL==0) { |
|
243 |
+ if (!db_url.s) { |
|
241 | 244 |
LM_CRIT("mandatory parameter \"DB_URL\" found empty\n"); |
242 | 245 |
goto error; |
243 | 246 |
} |
244 | 247 |
|
245 |
- if (DB_TABLE==0) { |
|
248 |
+ if (!db_table.s) { |
|
246 | 249 |
LM_CRIT("mandatory parameter \"DB_TABLE\" found empty\n"); |
247 | 250 |
goto error; |
248 | 251 |
} |
... | ... |
@@ -255,18 +258,17 @@ static int cpl_init(void) |
255 | 258 |
} |
256 | 259 |
|
257 | 260 |
/* fix the timer_avp name */ |
258 |
- if (timer_avp && *timer_avp) { |
|
259 |
- stmp.s = timer_avp; stmp.len = strlen(stmp.s); |
|
260 |
- if (pv_parse_spec(&stmp, &avp_spec)==0 |
|
261 |
+ if (timer_avp.s && timer_avp.len > 0) { |
|
262 |
+ if (pv_parse_spec(&timer_avp, &avp_spec)==0 |
|
261 | 263 |
|| avp_spec.type!=PVT_AVP) { |
262 |
- LM_ERR("malformed or non AVP %s AVP definition\n", timer_avp); |
|
264 |
+ LM_ERR("malformed or non AVP %.*s AVP definition\n", timer_avp.len, timer_avp.s); |
|
263 | 265 |
return -1; |
264 | 266 |
} |
265 | 267 |
|
266 | 268 |
if(pv_get_avp_name(0, &(avp_spec.pvp), &cpl_env.timer_avp, |
267 | 269 |
&avp_type)!=0) |
268 | 270 |
{ |
269 |
- LM_ERR("[%s]- invalid AVP definition\n", timer_avp); |
|
271 |
+ LM_ERR("[%.*s]- invalid AVP definition\n", timer_avp.len, timer_avp.s); |
|
270 | 272 |
return -1; |
271 | 273 |
} |
272 | 274 |
cpl_env.timer_avp_type = avp_type; |
... | ... |
@@ -318,7 +320,7 @@ static int cpl_init(void) |
318 | 320 |
} |
319 | 321 |
|
320 | 322 |
/* bind to the mysql module */ |
321 |
- if (cpl_db_bind(DB_URL,DB_TABLE)<0) goto error; |
|
323 |
+ if (cpl_db_bind(&db_url, &db_table)<0) goto error; |
|
322 | 324 |
|
323 | 325 |
/* load TM API */ |
324 | 326 |
if (load_tm_api(&cpl_fct.tmb)!=0) { |
... | ... |
@@ -403,13 +405,13 @@ error: |
403 | 405 |
|
404 | 406 |
static int cpl_child_init(int rank) |
405 | 407 |
{ |
406 |
- return cpl_db_init(DB_URL, DB_TABLE); |
|
408 |
+ return cpl_db_init(&db_url, &db_table); |
|
407 | 409 |
} |
408 | 410 |
|
409 | 411 |
|
410 | 412 |
static int mi_child_init(void) |
411 | 413 |
{ |
412 |
- return cpl_db_init(DB_URL, DB_TABLE); |
|
414 |
+ return cpl_db_init(&db_url, &db_table); |
|
413 | 415 |
} |
414 |