[sr-dev] git:master:35508d1d: pipelimit: added pl_active() - return true if pipe is active
Daniel-Constantin Mierla
miconda at gmail.com
Tue Mar 2 09:15:57 CET 2021
Module: kamailio
Branch: master
Commit: 35508d1dde810d422a6cf12631015a34a72bc039
URL: https://github.com/kamailio/kamailio/commit/35508d1dde810d422a6cf12631015a34a72bc039
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-03-02T09:10:34+01:00
pipelimit: added pl_active() - return true if pipe is active
---
Modified: src/modules/pipelimit/pipelimit.c
Modified: src/modules/pipelimit/pl_ht.c
---
Diff: https://github.com/kamailio/kamailio/commit/35508d1dde810d422a6cf12631015a34a72bc039.diff
Patch: https://github.com/kamailio/kamailio/commit/35508d1dde810d422a6cf12631015a34a72bc039.patch
---
diff --git a/src/modules/pipelimit/pipelimit.c b/src/modules/pipelimit/pipelimit.c
index faacd086df..d7b4f129c8 100644
--- a/src/modules/pipelimit/pipelimit.c
+++ b/src/modules/pipelimit/pipelimit.c
@@ -122,6 +122,7 @@ static ticks_t pl_timer_handle(ticks_t, struct timer_ln*, void*);
static void pl_timer_exec(unsigned int ticks, void *param);
static int w_pl_check(struct sip_msg*, char *, char *);
static int w_pl_check3(struct sip_msg*, char *, char *, char *);
+static int w_pl_active(sip_msg_t *, char *, char *);
static int w_pl_drop_default(struct sip_msg*, char *, char *);
static int w_pl_drop_forced(struct sip_msg*, char *, char *);
static int w_pl_drop(struct sip_msg*, char *, char *);
@@ -133,6 +134,8 @@ static cmd_export_t cmds[]={
0, ANY_ROUTE},
{"pl_check", (cmd_function)w_pl_check3, 3, fixup_pl_check3,
0, ANY_ROUTE},
+ {"pl_active", (cmd_function)w_pl_active, 1, fixup_spve_null,
+ 0, ANY_ROUTE},
{"pl_drop", (cmd_function)w_pl_drop_default, 0, 0,
0, REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|ONSEND_ROUTE},
{"pl_drop", (cmd_function)w_pl_drop_forced, 1, fixup_uint_null,
@@ -729,6 +732,36 @@ static int fixup_pl_check3(void** param, int param_no)
return 0;
}
+static int pl_active(sip_msg_t *msg, str *pipeid)
+{
+ pl_pipe_t *pipe = NULL;
+
+ pipe = pl_pipe_get(pipeid, 0);
+ if(pipe==NULL) {
+ LM_ERR("pipe does not exist [%.*s]\n", pipeid->len, pipeid->s);
+ return -1;
+ }
+
+ return 1;
+}
+
+/**
+ * checking if pipe is active
+ */
+static int w_pl_active(sip_msg_t* msg, char *p1, char *p2)
+{
+ str pipeid = {0, 0};
+
+ if(fixup_get_svalue(msg, (gparam_p)p1, &pipeid)!=0
+ || pipeid.s == 0)
+ {
+ LM_ERR("invalid pipeid parameter");
+ return -1;
+ }
+
+ return pl_active(msg, &pipeid);
+}
+
static void pl_timer_refresh(void)
{
if(pl_load_fetch!=0) {
@@ -873,6 +906,11 @@ static sr_kemi_t sr_kemi_pipelimit_exports[] = {
{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_INT,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
+ { str_init("pipelimit"), str_init("pl_active"),
+ SR_KEMIP_INT, pl_active,
+ { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
{ str_init("pipelimit"), str_init("pl_drop"),
SR_KEMIP_INT, ki_pl_drop,
{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
diff --git a/src/modules/pipelimit/pl_ht.c b/src/modules/pipelimit/pl_ht.c
index 1f666b89f3..38434068b4 100644
--- a/src/modules/pipelimit/pl_ht.c
+++ b/src/modules/pipelimit/pl_ht.c
@@ -221,7 +221,7 @@ pl_pipe_t* pl_pipe_get(str *pipeid, int mode)
unsigned int cellid;
unsigned int idx;
pl_pipe_t *it;
-
+
if(_pl_pipes_ht==NULL)
return NULL;
@@ -236,7 +236,7 @@ pl_pipe_t* pl_pipe_get(str *pipeid, int mode)
}
while(it!=NULL && it->cellid == cellid)
{
- if(pipeid->len==it->name.len
+ if(pipeid->len==it->name.len
&& strncmp(pipeid->s, it->name.s, pipeid->len)==0)
{
if(mode==0) lock_release(&_pl_pipes_ht->slots[idx].lock);
More information about the sr-dev
mailing list