[sr-dev] git:master: acc: option to work on a cloned sip msg request for getting acc attributes
Daniel-Constantin Mierla
miconda at gmail.com
Tue Oct 7 08:56:03 CEST 2014
Module: sip-router
Branch: master
Commit: 15fc8b9c59aaf31f005e38f54d363f1e9d0a068e
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=15fc8b9c59aaf31f005e38f54d363f1e9d0a068e
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: Tue Oct 7 08:48:31 2014 +0200
acc: option to work on a cloned sip msg request for getting acc attributes
- it applies for callback done in tm on reply received
- avoids working on the shm stored request that can be concurently
accessed and some header shortcuts can become set
- clone_msg - new parameter to control this behavior, default is 1 (use
a cloned structure)
---
modules/acc/acc_logic.c | 40 +++++++++++++++++++++++++---------------
modules/acc/acc_mod.c | 20 +++++++++++---------
2 files changed, 36 insertions(+), 24 deletions(-)
diff --git a/modules/acc/acc_logic.c b/modules/acc/acc_logic.c
index 975c0f9..bd3f1cc 100644
--- a/modules/acc/acc_logic.c
+++ b/modules/acc/acc_logic.c
@@ -482,6 +482,7 @@ static inline void on_missed(struct cell *t, struct sip_msg *req,
}
+extern int _acc_clone_msg;
/* initiate a report if we previously enabled accounting for this t */
static inline void acc_onreply( struct cell* t, struct sip_msg *req,
@@ -490,6 +491,8 @@ static inline void acc_onreply( struct cell* t, struct sip_msg *req,
str new_uri_bk;
int br = -1;
hdr_field_t *hdr;
+ sip_msg_t tmsg;
+ sip_msg_t *preq;
/* acc_onreply is bound to TMCB_REPLY which may be called
from _reply, like when FR hits; we should not miss this
@@ -500,6 +503,13 @@ static inline void acc_onreply( struct cell* t, struct sip_msg *req,
if (!should_acc_reply(req, reply, code))
return;
+ if(_acc_clone_msg==1) {
+ memcpy(&tmsg, req, sizeof(sip_msg_t));
+ preq = &tmsg;
+ } else {
+ preq = req;
+ }
+
/* get winning branch index, if set */
if (t->relayed_reply_branch>=0) {
br = t->relayed_reply_branch;
@@ -511,9 +521,9 @@ static inline void acc_onreply( struct cell* t, struct sip_msg *req,
/* for reply processing, set as new_uri the one from selected branch */
if (br>=0) {
- new_uri_bk = req->new_uri;
- req->new_uri = t->uac[br].uri;
- req->parsed_uri_ok = 0;
+ new_uri_bk = preq->new_uri;
+ preq->new_uri = t->uac[br].uri;
+ preq->parsed_uri_ok = 0;
} else {
new_uri_bk.len = -1;
new_uri_bk.s = 0;
@@ -522,31 +532,31 @@ static inline void acc_onreply( struct cell* t, struct sip_msg *req,
env_set_to( get_rpl_to(t,reply) );
env_set_code_status( code, reply);
- if ( is_log_acc_on(req) ) {
+ if ( is_log_acc_on(preq) ) {
env_set_text( ACC_ANSWERED, ACC_ANSWERED_LEN);
- acc_log_request(req);
+ acc_log_request(preq);
}
#ifdef SQL_ACC
- if (is_db_acc_on(req)) {
- if(acc_db_set_table_name(req, db_table_acc_data, &db_table_acc)<0) {
+ if (is_db_acc_on(preq)) {
+ if(acc_db_set_table_name(preq, db_table_acc_data, &db_table_acc)<0) {
LM_ERR("cannot set acc db table name\n");
} else {
- acc_db_request(req);
+ acc_db_request(preq);
}
}
#endif
#ifdef RAD_ACC
- if (is_rad_acc_on(req))
- acc_rad_request(req);
+ if (is_rad_acc_on(preq))
+ acc_rad_request(preq);
#endif
/* DIAMETER */
#ifdef DIAM_ACC
- if (is_diam_acc_on(req))
- acc_diam_request(req);
+ if (is_diam_acc_on(preq))
+ acc_diam_request(preq);
#endif
/* run extra acc engines */
- acc_run_engines(req, 0, NULL);
+ acc_run_engines(preq, 0, NULL);
if (new_uri_bk.len>=0) {
req->new_uri = new_uri_bk;
@@ -556,8 +566,8 @@ static inline void acc_onreply( struct cell* t, struct sip_msg *req,
/* free header's parsed structures that were added by resolving acc attributes */
for( hdr=req->headers ; hdr ; hdr=hdr->next ) {
if ( hdr->parsed && hdr_allocs_parse(hdr) &&
- (hdr->parsed<(void*)t->uas.request ||
- hdr->parsed>=(void*)t->uas.end_request)) {
+ (hdr->parsed<(void*)t->uas.request ||
+ hdr->parsed>=(void*)t->uas.end_request)) {
/* header parsed filed doesn't point inside uas.request memory
* chunck -> it was added by resolving acc attributes -> free it as pkg */
DBG("removing hdr->parsed %d\n", hdr->type);
diff --git a/modules/acc/acc_mod.c b/modules/acc/acc_mod.c
index 831a137..2939cd3 100644
--- a/modules/acc/acc_mod.c
+++ b/modules/acc/acc_mod.c
@@ -119,6 +119,7 @@ int reason_from_hf = 0; /*!< assign reason from reason hf if present */
int acc_time_mode = 0;
str acc_time_attr = str_init("time_attr");
str acc_time_exten = str_init("time_exten");
+int _acc_clone_msg = 1;
/*@}*/
@@ -275,14 +276,14 @@ static param_export_t params[] = {
{"cdr_extra", PARAM_STRING, &cdr_log_extra_str },
{"cdr_start_id", PARAM_STR, &cdr_start_str },
{"cdr_end_id", PARAM_STR, &cdr_end_str },
- {"cdr_duration_id", PARAM_STR, &cdr_duration_str },
+ {"cdr_duration_id", PARAM_STR, &cdr_duration_str },
{"cdr_expired_dlg_enable", INT_PARAM, &cdr_expired_dlg_enable },
#ifdef RAD_ACC
- {"radius_config", PARAM_STRING, &radius_config },
+ {"radius_config", PARAM_STRING, &radius_config },
{"radius_flag", INT_PARAM, &radius_flag },
{"radius_missed_flag", INT_PARAM, &radius_missed_flag },
{"service_type", INT_PARAM, &service_type },
- {"radius_extra", PARAM_STRING, &rad_extra_str },
+ {"radius_extra", PARAM_STRING, &rad_extra_str },
#endif
/* DIAMETER specific */
#ifdef DIAM_ACC
@@ -290,13 +291,13 @@ static param_export_t params[] = {
{"diameter_missed_flag", INT_PARAM, &diameter_missed_flag },
{"diameter_client_host", PARAM_STRING, &diameter_client_host },
{"diameter_client_port", INT_PARAM, &diameter_client_port },
- {"diameter_extra", PARAM_STRING, &dia_extra_str },
+ {"diameter_extra", PARAM_STRING, &dia_extra_str },
#endif
/* db-specific */
#ifdef SQL_ACC
- {"db_flag", INT_PARAM, &db_flag },
- {"db_missed_flag", INT_PARAM, &db_missed_flag },
- {"db_extra", PARAM_STRING, &db_extra_str },
+ {"db_flag", INT_PARAM, &db_flag },
+ {"db_missed_flag", INT_PARAM, &db_missed_flag },
+ {"db_extra", PARAM_STRING, &db_extra_str },
{"db_url", PARAM_STR, &db_url },
{"db_table_acc", PARAM_STR, &db_table_acc },
{"db_table_missed_calls",PARAM_STR, &db_table_mc },
@@ -307,14 +308,15 @@ static param_export_t params[] = {
{"acc_sip_code_column", PARAM_STR, &acc_sipcode_col },
{"acc_sip_reason_column",PARAM_STR, &acc_sipreason_col },
{"acc_time_column", PARAM_STR, &acc_time_col },
- {"db_insert_mode", INT_PARAM, &acc_db_insert_mode },
+ {"db_insert_mode", INT_PARAM, &acc_db_insert_mode },
#endif
/* time-mode-specific */
{"time_mode", INT_PARAM, &acc_time_mode },
{"time_attr", PARAM_STR, &acc_time_attr },
{"time_exten", PARAM_STR, &acc_time_exten },
{"cdrs_table", PARAM_STR, &acc_cdrs_table },
- {"time_format", PARAM_STRING, &acc_time_format },
+ {"time_format", PARAM_STRING, &acc_time_format },
+ {"clone_msg", PARAM_INT, &_acc_clone_msg },
{0,0,0}
};
More information about the sr-dev
mailing list