MT#5369 allow pvars in acc functions first parameter

mr3.2.1
Victor Seva 13 years ago
parent e69d58872c
commit 549b84e305

@ -14,6 +14,8 @@ upstream/0013-snmpstats-fixe-MIB-file-definitions.patch
upstream/0014-db_flatstore-update-timestamp-for-kamailio-specific-.patch
upstream/0015-modules-pv-fixed-params-and-param-transformation.patch
upstream/0016-modules-pua-added-some-missing-lock-releases.patch
upstream/acc-allow-pseudo-variables-as-first-parameter-for-fu.patch
upstream/acc-add-documentation-note-indicating-the-use-of-pse.patch
upstream/debug/0001-modules-debugger-trace-msg-out.patch
no_lib64_on_64_bits.patch
no_INSTALL_file.patch

@ -0,0 +1,113 @@
From 1e82ef702f9a0c3dec3e24e4f91dc879d7ba5280 Mon Sep 17 00:00:00 2001
From: Victor Seva <linuxmaniac@torreviejawireless.org>
Date: Thu, 2 Jan 2014 20:39:43 +0100
Subject: [PATCH] acc: add documentation note indicating the use of
pseudo-variables
---
modules/acc/doc/acc_admin.xml | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/modules/acc/doc/acc_admin.xml b/modules/acc/doc/acc_admin.xml
index 97858be..e233cb4 100644
--- a/modules/acc/doc/acc_admin.xml
+++ b/modules/acc/doc/acc_admin.xml
@@ -1477,7 +1477,7 @@ modparam("acc", "time_format", "%Y/%m/%d %H:%M:%S")
<section>
<title>Functions</title>
- <section>
+ <section id="acc.f.acc_log_request">
<title>
<function moreinfo="none">acc_log_request(comment)</function>
</title>
@@ -1493,6 +1493,7 @@ modparam("acc", "time_format", "%Y/%m/%d %H:%M:%S")
<itemizedlist>
<listitem>
<para><emphasis>comment</emphasis> - Comment to be appended.
+ The string can contain any number of pseudo-variables.
</para>
</listitem>
</itemizedlist>
@@ -1504,11 +1505,14 @@ modparam("acc", "time_format", "%Y/%m/%d %H:%M:%S")
<programlisting format="linespecific">
...
acc_log_request("Some comment");
+$var(code) = 404;
+$avp(reason) = "Not found";
+acc_log_request("$var(code) Error: $avp(reason)");
...
</programlisting>
</example>
</section>
- <section>
+ <section id="acc.f.acc_db_request">
<title>
<function moreinfo="none">acc_db_request(comment, table)</function>
</title>
@@ -1523,7 +1527,9 @@ acc_log_request("Some comment");
</para>
<itemizedlist>
<listitem>
- <para><emphasis>comment</emphasis> - Comment to be appended.</para>
+ <para><emphasis>comment</emphasis> - Comment to be appended.
+ The string can contain any number of pseudo-variables.
+ </para>
</listitem>
<listitem>
<para><emphasis>table</emphasis> - Database table to be used. It
@@ -1539,11 +1545,12 @@ acc_log_request("Some comment");
...
acc_db_request("Some comment", "SomeTable");
acc_db_request("Some comment", "acc_$time(year)_$time(mon)");
+acc_db_request("$var(code) Error: $avp(reason)", "SomeTable");
...
</programlisting>
</example>
</section>
- <section>
+ <section id="acc.f.acc_rad_request">
<title>
<function moreinfo="none">acc_rad_request(comment)</function>
</title>
@@ -1558,6 +1565,7 @@ acc_db_request("Some comment", "acc_$time(year)_$time(mon)");
<itemizedlist>
<listitem>
<para><emphasis>comment</emphasis> - Comment to be appended.
+ The string can contain any number of pseudo-variables.
</para>
</listitem>
</itemizedlist>
@@ -1569,11 +1577,12 @@ acc_db_request("Some comment", "acc_$time(year)_$time(mon)");
<programlisting format="linespecific">
...
acc_rad_request("Some comment");
+acc_rad_request("$var(code) Error: $avp(reason)");
...
</programlisting>
</example>
</section>
- <section>
+ <section id="acc.f.acc_diam_request">
<title>
<function moreinfo="none">acc_diam_request(comment)</function>
</title>
@@ -1587,6 +1596,7 @@ acc_rad_request("Some comment");
<itemizedlist>
<listitem>
<para><emphasis>comment</emphasis> - Comment to be appended.
+ The string can contain any number of pseudo-variables.
</para>
</listitem>
</itemizedlist>
@@ -1598,6 +1608,7 @@ acc_rad_request("Some comment");
<programlisting format="linespecific">
...
acc_diam_request("Some comment");
+acc_diam_request("$var(code) Error: $avp(reason)");
...
</programlisting>
</example>
--
1.8.5.2

@ -0,0 +1,180 @@
From 81c6e0bc108b8f4211ffade6de7a7448d1ba72f9 Mon Sep 17 00:00:00 2001
From: Victor Seva <linuxmaniac@torreviejawireless.org>
Date: Thu, 2 Jan 2014 20:39:43 +0100
Subject: [PATCH] acc: allow pseudo-variables as first parameter for functions.
---
modules/acc/acc_api.h | 1 +
modules/acc/acc_logic.c | 52 +++++++++++++++++++++++++++++++++++++++++++++----
modules/acc/acc_logic.h | 2 +-
modules/acc/acc_mod.c | 24 ++++++++++++++---------
4 files changed, 65 insertions(+), 14 deletions(-)
diff --git a/modules/acc/acc_api.h b/modules/acc/acc_api.h
index aa51380..a4d8bc6 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_elem_p elem;
} acc_param_t;
/* various acc variables */
diff --git a/modules/acc/acc_logic.c b/modules/acc/acc_logic.c
index 18437fc..0641388 100644
--- a/modules/acc/acc_logic.c
+++ b/modules/acc/acc_logic.c
@@ -166,14 +166,49 @@ static inline int acc_preparse_req(struct sip_msg *req)
return 0;
}
+int acc_parse_code(char *p, struct acc_param *param)
+{
+ if (p==NULL||param==NULL)
+ return -1;
+ /* 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 acc_get_param_value(struct sip_msg *rq, struct acc_param *param)
+{
+ if(param->elem!=NULL) {
+ if(pv_printf_s(rq, param->elem, &param->reason)==-1) {
+ LM_ERR("Can't get value for %.*s\n", param->reason.len, param->reason.s);
+ return -1;
+ }
+ if(acc_parse_code(param->reason.s, param)<0)
+ {
+ LM_ERR("Can't parse code\n");
+ return -1;
+ }
+ }
+ 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 +247,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 +258,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 +270,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 +285,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_logic.h b/modules/acc/acc_logic.h
index 7348471..29ee8f7 100644
--- a/modules/acc/acc_logic.h
+++ b/modules/acc/acc_logic.h
@@ -41,7 +41,7 @@
#include "../../modules/tm/t_hooks.h"
#include "acc_api.h"
-
+int acc_parse_code(char *p, struct acc_param *param);
void acc_onreq( struct cell* t, int type, struct tmcb_params *ps );
int w_acc_log_request(struct sip_msg *rq, char *comment, char *foo);
diff --git a/modules/acc/acc_mod.c b/modules/acc/acc_mod.c
index 2fb9258..8be152a 100644
--- a/modules/acc/acc_mod.c
+++ b/modules/acc/acc_mod.c
@@ -355,15 +355,21 @@ 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 (strchr(p,PV_MARKER)!=NULL) { /* is a variable $xxxxx */
+ if (pv_parse_format(&accp->reason, &accp->elem)<0)
+ {
+ LM_ERR("bad param 1; "
+ "parse format error [%.*s]\n", accp->reason.len, accp->reason.s);
+ return E_UNSPEC;
+ }
+ }
+ else {
+ if(acc_parse_code(p,accp)<0)
+ {
+ LM_ERR("bad param 1;"
+ "parse code error\n");
+ return E_UNSPEC;
+ }
}
*param = (void*)accp;
#ifdef SQL_ACC
--
1.8.5.2
Loading…
Cancel
Save