Module: sip-router
Branch: 3.2
Commit: fec398c8d6f2cd2e038b19aceedfa2e50a3c57e0
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=fec398c…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Tue Oct 12 14:52:07 2010 +0200
acc(k): table name for db acc can be dynamic
- 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
(cherry picked from commit e8f6a95d43b6a4340cf7e97213af5c71fa2a69e9)
---
modules_k/acc/acc_logic.c | 52 +++++++++++++++++++++++++++++++++++++++-----
modules_k/acc/acc_mod.c | 24 ++++++++++++++++++++
modules_k/acc/acc_mod.h | 2 +
3 files changed, 72 insertions(+), 6 deletions(-)
diff --git a/modules_k/acc/acc_logic.c b/modules_k/acc/acc_logic.c
index e5033ea..e1c49a9 100644
--- a/modules_k/acc/acc_logic.c
+++ b/modules_k/acc/acc_logic.c
@@ -39,6 +39,7 @@
#include <string.h>
#include "../../dprint.h"
+#include "../../sr_module.h"
#include "../../parser/parse_from.h"
#include "../../parser/parse_content.h"
#include "../../modules/tm/tm_load.h"
@@ -103,8 +104,6 @@ struct acc_enviroment acc_env;
#define is_acc_prepare_on(_rq) \
(is_acc_flag_set(_rq,acc_prepare_flag))
-
-
static void tmcb_func( struct cell* t, int type, struct tmcb_params *ps );
@@ -182,6 +181,35 @@ int w_acc_log_request(struct sip_msg *rq, char *comment, char *foo)
#ifdef SQL_ACC
+int acc_db_set_table_name(struct sip_msg *msg, void *param, str *table)
+{
+#define DB_TABLE_NAME_SIZE 64
+ static char db_table_name_buf[DB_TABLE_NAME_SIZE];
+ str dbtable;
+
+ if(param!=NULL) {
+ if(get_str_fparam(&dbtable, msg, (fparam_t*)param)<0) {
+ LM_ERR("cannot get acc db table name\n");
+ return -1;
+ }
+ if(dbtable.len>=DB_TABLE_NAME_SIZE) {
+ LM_ERR("acc db table name too big [%.*s] max %d\n",
+ dbtable.len, dbtable.s, DB_TABLE_NAME_SIZE);
+ return -1;
+ }
+ strncpy(db_table_name_buf, dbtable.s, dbtable.len);
+ env_set_text(db_table_name_buf, dbtable.len);
+ } else {
+ if(table==NULL) {
+ LM_ERR("no acc table name\n");
+ return -1;
+ }
+ env_set_text(table->s, table->len);
+ }
+ return 0;
+}
+
+
int w_acc_db_request(struct sip_msg *rq, char *comment, char *table)
{
if (!table) {
@@ -190,9 +218,12 @@ int w_acc_db_request(struct sip_msg *rq, char *comment, char *table)
}
if (acc_preparse_req(rq)<0)
return -1;
+ if(acc_db_set_table_name(rq, (void*)table, NULL)<0) {
+ LM_ERR("cannot set table name\n");
+ return -1;
+ }
env_set_to( rq->to );
env_set_comment((struct acc_param*)comment);
- env_set_text(table, strlen(table));
return acc_db_request(rq);
}
#endif
@@ -340,7 +371,10 @@ static inline void on_missed(struct cell *t, struct sip_msg *req,
}
#ifdef SQL_ACC
if (is_db_mc_on(req)) {
- env_set_text(db_table_mc.s, db_table_mc.len);
+ if(acc_db_set_table_name(req, db_table_mc_data, &db_table_mc)<0) {
+ LM_ERR("cannot set missed call db table name\n");
+ return;
+ }
acc_db_request( req );
flags_to_reset |= db_missed_flag;
}
@@ -411,7 +445,10 @@ static inline void acc_onreply( struct cell* t, struct sip_msg *req,
}
#ifdef SQL_ACC
if (is_db_acc_on(req)) {
- env_set_text( db_table_acc.s, db_table_acc.len);
+ if(acc_db_set_table_name(req, db_table_acc_data, &db_table_acc)<0) {
+ LM_ERR("cannot set acc db table name\n");
+ return;
+ }
acc_db_request(req);
}
#endif
@@ -452,7 +489,10 @@ static inline void acc_onack( struct cell* t, struct sip_msg *req,
}
#ifdef SQL_ACC
if (is_db_acc_on(req)) {
- env_set_text( db_table_acc.s, db_table_acc.len);
+ if(acc_db_set_table_name(ack, db_table_acc_data, &db_table_acc)<0) {
+ LM_ERR("cannot set acc db table name\n");
+ return;
+ }
acc_db_request( ack );
}
#endif
diff --git a/modules_k/acc/acc_mod.c b/modules_k/acc/acc_mod.c
index c913eba..c301937 100644
--- a/modules_k/acc/acc_mod.c
+++ b/modules_k/acc/acc_mod.c
@@ -179,7 +179,9 @@ static char *db_extra_str = 0; /*!< db extra variables */
struct acc_extra *db_extra = 0;
static str db_url = {NULL, 0}; /*!< Database url */
str db_table_acc = str_init("acc"); /*!< name of database tables */
+void *db_table_acc_data = NULL;
str db_table_mc = str_init("missed_calls");
+void *db_table_mc_data = NULL;
/* names of columns in tables acc/missed calls*/
str acc_method_col = str_init("method");
str acc_fromtag_col = str_init("from_tag");
@@ -342,6 +344,8 @@ static int acc_fixup(void** param, int param_no)
if (db_url.s==0) {
pkg_free(p);
*param = 0;
+ } else {
+ return fixup_var_pve_str_12(param, 2);
}
#endif
}
@@ -431,7 +435,27 @@ static int mod_init( void )
}
}
db_table_acc.len = strlen(db_table_acc.s);
+ if(db_table_acc.len!=3 || strncmp(db_table_acc.s, "acc", 3)!=0)
+ {
+ db_table_acc_data = db_table_acc.s;
+ if(fixup_var_pve_str_12(&db_table_acc_data, 1)<0)
+ {
+ LM_ERR("unable to parse acc table name [%.*s]\n",
+ db_table_acc.len, db_table_acc.s);
+ return -1;
+ }
+ }
db_table_mc.len = strlen(db_table_mc.s);
+ if(db_table_mc.len!=12 || strncmp(db_table_mc.s, "missed_calls", 12)!=0)
+ {
+ db_table_mc_data = db_table_mc.s;
+ if(fixup_var_pve_str_12(&db_table_mc_data, 1)<0)
+ {
+ LM_ERR("unable to parse mc table name [%.*s]\n",
+ db_table_mc.len, db_table_mc.s);
+ return -1;
+ }
+ }
acc_method_col.len = strlen(acc_method_col.s);
acc_fromtag_col.len = strlen(acc_fromtag_col.s);
acc_totag_col.len = strlen(acc_totag_col.s);
diff --git a/modules_k/acc/acc_mod.h b/modules_k/acc/acc_mod.h
index ca76eff..5e7792a 100644
--- a/modules_k/acc/acc_mod.h
+++ b/modules_k/acc/acc_mod.h
@@ -78,7 +78,9 @@ extern int db_flag;
extern int db_missed_flag;
extern str db_table_acc;
+extern void *db_table_acc_data;
extern str db_table_mc;
+extern void *db_table_mc_data;
extern str acc_method_col;
extern str acc_fromuri_col;