Module: sip-router
Branch: vseva/acc_pvar DELETED
Commit: 7c83177a07037a80160eb5a89828a3d3874a9e62
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=7c83177…
Author: Victor Seva <linuxmaniac(a)torreviejawireless.org>
Committer: Victor Seva <linuxmaniac(a)torreviejawireless.org>
Date: Thu Dec 12 17:35:16 2013 +0100
acc: allow pvar as first parameter for functions. WIP.
---
modules/acc/acc_api.h | 1 +
modules/acc/acc_logic.c | 50 ++++++++++++++++++++++++++++++++++++++++++----
modules/acc/acc_mod.c | 17 +++++++--------
3 files changed, 54 insertions(+), 14 deletions(-)
diff --git a/modules/acc/acc_api.h b/modules/acc/acc_api.h
index aa51380..0660797 100644
--- a/modules/acc/acc_api.h
+++ b/modules/acc/acc_api.h
@@ -48,6 +48,7 @@ typedef struct acc_param {
int code;
str code_s;
str reason;
+ pv_spec_t *spec;
} acc_param_t;
/* various acc variables */
diff --git a/modules/acc/acc_logic.c b/modules/acc/acc_logic.c
index 50278fb..e7c754f 100644
--- a/modules/acc/acc_logic.c
+++ b/modules/acc/acc_logic.c
@@ -166,14 +166,45 @@ static inline int acc_preparse_req(struct sip_msg *req)
return 0;
}
-
+int acc_get_param_value(struct sip_msg *rq, struct acc_param *param)
+{
+ pv_value_t xvalue;
+ char *p;
+ if(param->spec!=NULL) {
+ if(pv_get_spec_value(rq, param->spec, &xvalue)==-1) {
+ LM_ERR("Can't get value for %.*s\n", param->reason.len,
param->reason.s);
+ return -1;
+ }
+ if(!(xvalue.flags&(PV_VAL_STR))) {
+ LM_ERR("pvar %.*s is not a string", param->reason.len,
param->reason.s);
+ return -1;
+ }
+ param->reason.s = xvalue.rs.s;
+ param->reason.len = xvalue.rs.len;
+ }
+ p = param->reason.s;
+ /* any code? */
+ if (param->reason.len>=3 && isdigit((int)p[0])
+ && isdigit((int)p[1]) && isdigit((int)p[2]) ) {
+ param->code = (p[0]-'0')*100 + (p[1]-'0')*10 + (p[2]-'0');
+ param->code_s.s = p;
+ param->code_s.len = 3;
+ param->reason.s += 3;
+ for( ; isspace((int)param->reason.s[0]) ; param->reason.s++ );
+ param->reason.len = strlen(param->reason.s);
+ }
+ return 0;
+}
int w_acc_log_request(struct sip_msg *rq, char *comment, char *foo)
{
+ struct acc_param *param = (struct acc_param*)comment;
if (acc_preparse_req(rq)<0)
return -1;
+ if(acc_get_param_value(rq, param)<0)
+ return -1;
env_set_to( rq->to );
- env_set_comment((struct acc_param*)comment);
+ env_set_comment(param);
env_set_text( ACC_REQUEST, ACC_REQUEST_LEN);
return acc_log_request(rq);
}
@@ -212,6 +243,7 @@ int acc_db_set_table_name(struct sip_msg *msg, void *param, str
*table)
int w_acc_db_request(struct sip_msg *rq, char *comment, char *table)
{
+ struct acc_param *param = (struct acc_param*)comment;
if (!table) {
LM_ERR("db support not configured\n");
return -1;
@@ -222,8 +254,10 @@ int w_acc_db_request(struct sip_msg *rq, char *comment, char *table)
LM_ERR("cannot set table name\n");
return -1;
}
+ if(acc_get_param_value(rq, param)<0)
+ return -1;
env_set_to( rq->to );
- env_set_comment((struct acc_param*)comment);
+ env_set_comment(param);
return acc_db_request(rq);
}
#endif
@@ -232,10 +266,13 @@ int w_acc_db_request(struct sip_msg *rq, char *comment, char
*table)
#ifdef RAD_ACC
int w_acc_rad_request(struct sip_msg *rq, char *comment, char *foo)
{
+ struct acc_param *param = (struct acc_param*)comment;
if (acc_preparse_req(rq)<0)
return -1;
+ if(acc_get_param_value(rq, param)<0)
+ return -1;
env_set_to( rq->to );
- env_set_comment((struct acc_param*)comment);
+ env_set_comment(param);
return acc_rad_request(rq);
}
#endif
@@ -244,10 +281,13 @@ int w_acc_rad_request(struct sip_msg *rq, char *comment, char *foo)
#ifdef DIAM_ACC
int w_acc_diam_request(struct sip_msg *rq, char *comment, char *foo)
{
+ struct acc_param *param = (struct acc_param*)comment;
if (acc_preparse_req(rq)<0)
return -1;
+ if(acc_get_param_value(rq, param)<0)
+ return -1;
env_set_to( rq->to );
- env_set_comment((struct acc_param*)comment);
+ env_set_comment(param);
return acc_diam_request(rq);
}
#endif
diff --git a/modules/acc/acc_mod.c b/modules/acc/acc_mod.c
index 2fb9258..9d9b583 100644
--- a/modules/acc/acc_mod.c
+++ b/modules/acc/acc_mod.c
@@ -355,15 +355,14 @@ static int acc_fixup(void** param, int param_no)
memset( accp, 0, sizeof(struct acc_param));
accp->reason.s = p;
accp->reason.len = strlen(p);
- /* any code? */
- if (accp->reason.len>=3 && isdigit((int)p[0])
- && isdigit((int)p[1]) && isdigit((int)p[2]) ) {
- accp->code = (p[0]-'0')*100 + (p[1]-'0')*10 + (p[2]-'0');
- accp->code_s.s = p;
- accp->code_s.len = 3;
- accp->reason.s += 3;
- for( ; isspace((int)accp->reason.s[0]) ; accp->reason.s++ );
- accp->reason.len = strlen(accp->reason.s);
+ if (p[0]=='$') { /* is a variable $xxxxx */
+ accp->spec = pv_cache_get(&accp->reason);
+ if (accp->spec==0 || accp->spec->type==PVT_NULL ||
accp->spec->type==PVT_EMPTY)
+ {
+ LM_ERR("bad param 1; "
+ "expected : $pseudo-variable or str value\n");
+ return E_UNSPEC;
+ }
}
*param = (void*)accp;
#ifdef SQL_ACC