- you can include variables in table name and will be evaluated at
runtime:
modparam("acc", "db_table_acc", "acc_$time(year)_$time(mon)")
will write now to table acc_2010_10
- same can be done for missed_calls table name
- second parameter of acc_db_request() supports as well config variables
... | ... |
@@ -39,6 +39,7 @@ |
39 | 39 |
#include <string.h> |
40 | 40 |
|
41 | 41 |
#include "../../dprint.h" |
42 |
+#include "../../sr_module.h" |
|
42 | 43 |
#include "../../parser/parse_from.h" |
43 | 44 |
#include "../../parser/parse_content.h" |
44 | 45 |
#include "../../modules/tm/tm_load.h" |
... | ... |
@@ -101,8 +102,6 @@ struct acc_enviroment acc_env; |
101 | 102 |
(((_rq)->REQ_METHOD==METHOD_CANCEL) && report_cancels==0) |
102 | 103 |
|
103 | 104 |
|
104 |
- |
|
105 |
- |
|
106 | 105 |
static void tmcb_func( struct cell* t, int type, struct tmcb_params *ps ); |
107 | 106 |
|
108 | 107 |
|
... | ... |
@@ -180,6 +179,35 @@ int w_acc_log_request(struct sip_msg *rq, char *comment, char *foo) |
180 | 179 |
|
181 | 180 |
|
182 | 181 |
#ifdef SQL_ACC |
182 |
+int acc_db_set_table_name(struct sip_msg *msg, void *param, str *table) |
|
183 |
+{ |
|
184 |
+#define DB_TABLE_NAME_SIZE 64 |
|
185 |
+ static char db_table_name_buf[DB_TABLE_NAME_SIZE]; |
|
186 |
+ str dbtable; |
|
187 |
+ |
|
188 |
+ if(param!=NULL) { |
|
189 |
+ if(get_str_fparam(&dbtable, msg, (fparam_t*)param)<0) { |
|
190 |
+ LM_ERR("cannot get acc db table name\n"); |
|
191 |
+ return -1; |
|
192 |
+ } |
|
193 |
+ if(dbtable.len>=DB_TABLE_NAME_SIZE) { |
|
194 |
+ LM_ERR("acc db table name too big [%.*s] max %d\n", |
|
195 |
+ dbtable.len, dbtable.s, DB_TABLE_NAME_SIZE); |
|
196 |
+ return -1; |
|
197 |
+ } |
|
198 |
+ strncpy(db_table_name_buf, dbtable.s, dbtable.len); |
|
199 |
+ env_set_text(db_table_name_buf, dbtable.len); |
|
200 |
+ } else { |
|
201 |
+ if(table==NULL) { |
|
202 |
+ LM_ERR("no acc table name\n"); |
|
203 |
+ return -1; |
|
204 |
+ } |
|
205 |
+ env_set_text(table->s, table->len); |
|
206 |
+ } |
|
207 |
+ return 0; |
|
208 |
+} |
|
209 |
+ |
|
210 |
+ |
|
183 | 211 |
int w_acc_db_request(struct sip_msg *rq, char *comment, char *table) |
184 | 212 |
{ |
185 | 213 |
if (!table) { |
... | ... |
@@ -188,9 +216,12 @@ int w_acc_db_request(struct sip_msg *rq, char *comment, char *table) |
188 | 216 |
} |
189 | 217 |
if (acc_preparse_req(rq)<0) |
190 | 218 |
return -1; |
219 |
+ if(acc_db_set_table_name(rq, (void*)table, NULL)<0) { |
|
220 |
+ LM_ERR("cannot set table name\n"); |
|
221 |
+ return -1; |
|
222 |
+ } |
|
191 | 223 |
env_set_to( rq->to ); |
192 | 224 |
env_set_comment((struct acc_param*)comment); |
193 |
- env_set_text(table, strlen(table)); |
|
194 | 225 |
return acc_db_request(rq); |
195 | 226 |
} |
196 | 227 |
#endif |
... | ... |
@@ -318,7 +349,10 @@ static inline void on_missed(struct cell *t, struct sip_msg *req, |
318 | 349 |
} |
319 | 350 |
#ifdef SQL_ACC |
320 | 351 |
if (is_db_mc_on(req)) { |
321 |
- env_set_text(db_table_mc.s, db_table_mc.len); |
|
352 |
+ if(acc_db_set_table_name(req, db_table_mc_data, &db_table_mc)<0) { |
|
353 |
+ LM_ERR("cannot set missed call db table name\n"); |
|
354 |
+ return; |
|
355 |
+ } |
|
322 | 356 |
acc_db_request( req ); |
323 | 357 |
flags_to_reset |= db_missed_flag; |
324 | 358 |
} |
... | ... |
@@ -386,7 +420,10 @@ static inline void acc_onreply( struct cell* t, struct sip_msg *req, |
386 | 420 |
} |
387 | 421 |
#ifdef SQL_ACC |
388 | 422 |
if (is_db_acc_on(req)) { |
389 |
- env_set_text( db_table_acc.s, db_table_acc.len); |
|
423 |
+ if(acc_db_set_table_name(req, db_table_acc_data, &db_table_acc)<0) { |
|
424 |
+ LM_ERR("cannot set acc db table name\n"); |
|
425 |
+ return; |
|
426 |
+ } |
|
390 | 427 |
acc_db_request(req); |
391 | 428 |
} |
392 | 429 |
#endif |
... | ... |
@@ -427,7 +464,10 @@ static inline void acc_onack( struct cell* t, struct sip_msg *req, |
427 | 464 |
} |
428 | 465 |
#ifdef SQL_ACC |
429 | 466 |
if (is_db_acc_on(req)) { |
430 |
- env_set_text( db_table_acc.s, db_table_acc.len); |
|
467 |
+ if(acc_db_set_table_name(ack, db_table_acc_data, &db_table_acc)<0) { |
|
468 |
+ LM_ERR("cannot set acc db table name\n"); |
|
469 |
+ return; |
|
470 |
+ } |
|
431 | 471 |
acc_db_request( ack ); |
432 | 472 |
} |
433 | 473 |
#endif |
... | ... |
@@ -164,7 +164,9 @@ static char *db_extra_str = 0; /*!< db extra variables */ |
164 | 164 |
struct acc_extra *db_extra = 0; |
165 | 165 |
static str db_url = {NULL, 0}; /*!< Database url */ |
166 | 166 |
str db_table_acc = str_init("acc"); /*!< name of database tables */ |
167 |
+void *db_table_acc_data = NULL; |
|
167 | 168 |
str db_table_mc = str_init("missed_calls"); |
169 |
+void *db_table_mc_data = NULL; |
|
168 | 170 |
/* names of columns in tables acc/missed calls*/ |
169 | 171 |
str acc_method_col = str_init("method"); |
170 | 172 |
str acc_fromtag_col = str_init("from_tag"); |
... | ... |
@@ -318,6 +320,8 @@ static int acc_fixup(void** param, int param_no) |
318 | 320 |
if (db_url.s==0) { |
319 | 321 |
pkg_free(p); |
320 | 322 |
*param = 0; |
323 |
+ } else { |
|
324 |
+ return fixup_var_pve_str_12(param, 2); |
|
321 | 325 |
} |
322 | 326 |
#endif |
323 | 327 |
} |
... | ... |
@@ -363,7 +367,27 @@ static int mod_init( void ) |
363 | 367 |
if (db_url.s) |
364 | 368 |
db_url.len = strlen(db_url.s); |
365 | 369 |
db_table_acc.len = strlen(db_table_acc.s); |
370 |
+ if(db_table_acc.len!=3 || strncmp(db_table_acc.s, "acc", 3)!=0) |
|
371 |
+ { |
|
372 |
+ db_table_acc_data = db_table_acc.s; |
|
373 |
+ if(fixup_var_pve_str_12(&db_table_acc_data, 1)<0) |
|
374 |
+ { |
|
375 |
+ LM_ERR("unable to parse acc table name [%.*s]\n", |
|
376 |
+ db_table_acc.len, db_table_acc.s); |
|
377 |
+ return -1; |
|
378 |
+ } |
|
379 |
+ } |
|
366 | 380 |
db_table_mc.len = strlen(db_table_mc.s); |
381 |
+ if(db_table_mc.len!=12 || strncmp(db_table_mc.s, "missed_calls", 12)!=0) |
|
382 |
+ { |
|
383 |
+ db_table_mc_data = db_table_mc.s; |
|
384 |
+ if(fixup_var_pve_str_12(&db_table_mc_data, 1)<0) |
|
385 |
+ { |
|
386 |
+ LM_ERR("unable to parse mc table name [%.*s]\n", |
|
387 |
+ db_table_mc.len, db_table_mc.s); |
|
388 |
+ return -1; |
|
389 |
+ } |
|
390 |
+ } |
|
367 | 391 |
acc_method_col.len = strlen(acc_method_col.s); |
368 | 392 |
acc_fromtag_col.len = strlen(acc_fromtag_col.s); |
369 | 393 |
acc_totag_col.len = strlen(acc_totag_col.s); |