Module: sip-router
Branch: master
Commit: 3f8d1e2bdba6650d2541261a2184a0bef5b88b07
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=3f8d1e2…
Author: Ovidiu Sas <osas(a)voipembedded.com>
Committer: Ovidiu Sas <osas(a)voipembedded.com>
Date: Tue Jan 8 14:21:46 2013 -0500
pipelimit: enhance return codes for pl_check() function
---
modules/pipelimit/README | 29 ++++++++++++++++++++++++--
modules/pipelimit/doc/pipelimit_admin.xml | 31 ++++++++++++++++++++++++++--
modules/pipelimit/pipelimit.c | 4 +-
3 files changed, 56 insertions(+), 8 deletions(-)
diff --git a/modules/pipelimit/README b/modules/pipelimit/README
index 4f5c890..8d32766 100644
--- a/modules/pipelimit/README
+++ b/modules/pipelimit/README
@@ -278,8 +278,11 @@ kamcmd cfg.set_now_string pipelimit reply_reason
"Limiting"
Check the current request against the 'name' pipe. The pipe name can be
provided via a pseudo variabile.
- The method will return an error code if the limit for the matched
- algorithm is reached.
+ The method will return:
+ * -2 if no pipe was found
+ * -1 if pipe limit was reached
+ * 1 if pipe limit was NOT reached
+ * 2 if pipe has NOP algorithm
Meaning of the parameters is as follows:
* name - the pseudovariable holding the pipe name.
@@ -296,7 +299,27 @@ kamcmd cfg.set_now_string pipelimit reply_reason
"Limiting"
...
# use pipe 'one' for the current method via PV
$var(p) = "one";
- if (!pl_check("$var(p)")) {
+ $var(check_result) = pl_check("$var(p)");
+ switch($var(check_result)) {
+ case -2:
+ xlog("L_ALERT","pl_check(\"$var(p)\") drop -pipe
NOT found\n");
+ pl_drop();
+ exit;
+ break;
+ case -1:
+ xlog("L_ALERT","pl_check(\"$var(p)\")
drop\n");
+ pl_drop();
+ exit;
+ break;
+ case 1:
+ xlog("L_INFO", "pl_check(\"$var(p)\")
pass\n");
+ break;
+ case 2:
+ xlog("L_ALERT","pl_check(\"$var(p)\") pass -NOP
algorithm\n");
+ break;
+ default:
+ xlog("L_ERR","pl_check(\"$var(p)\") droping \
+with unexpected retcode=$var(check_result)\n");
pl_drop();
exit;
}
diff --git a/modules/pipelimit/doc/pipelimit_admin.xml
b/modules/pipelimit/doc/pipelimit_admin.xml
index ffc4b30..290b51c 100644
--- a/modules/pipelimit/doc/pipelimit_admin.xml
+++ b/modules/pipelimit/doc/pipelimit_admin.xml
@@ -262,8 +262,13 @@ modparam("pipelimit", "reply_reason",
"Limiting")
Check the current request against the 'name' pipe.
The pipe name can be provided via a pseudo variabile.
</para>
- <para>The method will return an error code if the limit for the matched
- algorithm is reached.
+ <para>The method will return:
+ <itemizedlist>
+ <listitem><para><emphasis>-2</emphasis> if no pipe was
found</para></listitem>
+ <listitem><para><emphasis>-1</emphasis> if pipe limit was
reached</para></listitem>
+ <listitem><para><emphasis>1</emphasis> if pipe limit was NOT
reached</para></listitem>
+ <listitem><para><emphasis>2</emphasis> if pipe has NOP
algorithm</para></listitem>
+ </itemizedlist>
</para>
<para>Meaning of the parameters is as follows:</para>
<itemizedlist>
@@ -286,7 +291,27 @@ modparam("pipelimit", "reply_reason",
"Limiting")
...
# use pipe 'one' for the current method via PV
$var(p) = "one";
- if (!pl_check("$var(p)")) {
+ $var(check_result) = pl_check("$var(p)");
+ switch($var(check_result)) {
+ case -2:
+ xlog("L_ALERT","pl_check(\"$var(p)\") drop -pipe NOT
found\n");
+ pl_drop();
+ exit;
+ break;
+ case -1:
+ xlog("L_ALERT","pl_check(\"$var(p)\") drop\n");
+ pl_drop();
+ exit;
+ break;
+ case 1:
+ xlog("L_INFO", "pl_check(\"$var(p)\") pass\n");
+ break;
+ case 2:
+ xlog("L_ALERT","pl_check(\"$var(p)\") pass -NOP
algorithm\n");
+ break;
+ default:
+ xlog("L_ERR","pl_check(\"$var(p)\") droping \
+with unexpected retcode=$var(check_result)\n");
pl_drop();
exit;
}
diff --git a/modules/pipelimit/pipelimit.c b/modules/pipelimit/pipelimit.c
index 9ee28b3..b183e33 100644
--- a/modules/pipelimit/pipelimit.c
+++ b/modules/pipelimit/pipelimit.c
@@ -522,7 +522,7 @@ static int pipe_push(struct sip_msg * msg, str *pipeid)
if(pipe==NULL)
{
LM_ERR("pipe not found [%.*s]\n", pipeid->len, pipeid->s);
- return -1;
+ return -2;
}
pipe->counter++;
@@ -531,7 +531,7 @@ static int pipe_push(struct sip_msg * msg, str *pipeid)
case PIPE_ALGO_NOP:
LM_ERR("no algorithm defined for pipe %.*s\n",
pipeid->len, pipeid->s);
- ret = 1;
+ ret = 2;
break;
case PIPE_ALGO_TAILDROP:
ret = (pipe->counter <= pipe->limit * timer_interval) ? 1 : -1;