Module: kamailio
Branch: master
Commit: c218e3597e734bfe4308ce1911437080637107bd
URL:
https://github.com/kamailio/kamailio/commit/c218e3597e734bfe4308ce191143708…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2017-05-27T21:48:52+02:00
pipelimit: exported functions to kemi framework
---
Modified: src/modules/pipelimit/pipelimit.c
---
Diff:
https://github.com/kamailio/kamailio/commit/c218e3597e734bfe4308ce191143708…
Patch:
https://github.com/kamailio/kamailio/commit/c218e3597e734bfe4308ce191143708…
---
diff --git a/src/modules/pipelimit/pipelimit.c b/src/modules/pipelimit/pipelimit.c
index 32dec4a55f..702d22f879 100644
--- a/src/modules/pipelimit/pipelimit.c
+++ b/src/modules/pipelimit/pipelimit.c
@@ -53,6 +53,7 @@
#include "../../core/rpc.h"
#include "../../core/rpc_lookup.h"
#include "../../core/rand/kam_rand.h"
+#include "../../core/kemi.h"
#include "pl_statistics.h"
#include "pl_ht.h"
@@ -643,13 +644,42 @@ static int w_pl_check(struct sip_msg* msg, char *p1, char *p2)
/**
* limit checking with creation of pipe if it doesn't exist
*/
+static int pl_check_limit(sip_msg_t* msg, str *pipeid, str *alg, int limit)
+{
+ pl_pipe_t *pipe = NULL;
+
+ pipe = pl_pipe_get(pipeid, 1);
+ if(pipe==NULL) {
+ LM_DBG("pipe not found [%.*s] - trying to add it\n",
+ pipeid->len, pipeid->s);
+ if(pl_pipe_add(pipeid, alg, limit)<0) {
+ LM_ERR("failed to add pipe [%.*s]\n",
+ pipeid->len, pipeid->s);
+ return -2;
+ }
+ pipe = pl_pipe_get(pipeid, 0);
+ if(pipe==NULL) {
+ LM_ERR("failed to retrieve pipe [%.*s]\n",
+ pipeid->len, pipeid->s);
+ return -2;
+ }
+ } else {
+ if(limit>0) pipe->limit = limit;
+ pl_pipe_release(&pipe->name);
+ }
+
+ return pl_check(msg, pipeid);
+}
+
+/**
+ * limit checking with creation of pipe if it doesn't exist
+ */
static int w_pl_check3(struct sip_msg* msg, char *p1pipe, char *p2alg,
char *p3limit)
{
int limit;
str pipeid = {0, 0};
str alg = {0, 0};
- pl_pipe_t *pipe = NULL;
if(msg==NULL)
return -1;
@@ -674,30 +704,7 @@ static int w_pl_check3(struct sip_msg* msg, char *p1pipe, char
*p2alg,
return -1;
}
- pipe = pl_pipe_get(&pipeid, 1);
- if(pipe==NULL)
- {
- LM_DBG("pipe not found [%.*s] - trying to add it\n",
- pipeid.len, pipeid.s);
- if(pl_pipe_add(&pipeid, &alg, limit)<0)
- {
- LM_ERR("failed to add pipe [%.*s]\n",
- pipeid.len, pipeid.s);
- return -2;
- }
- pipe = pl_pipe_get(&pipeid, 0);
- if(pipe==NULL)
- {
- LM_ERR("failed to retrieve pipe [%.*s]\n",
- pipeid.len, pipeid.s);
- return -2;
- }
- } else {
- if(limit>0) pipe->limit = limit;
- pl_pipe_release(&pipe->name);
- }
-
- return pl_check(msg, &pipeid);
+ return pl_check_limit(msg, &pipeid, &alg, limit);
}
static int fixup_pl_check3(void** param, int param_no)
@@ -805,3 +812,61 @@ static rpc_export_t rpc_methods[] = {
{0, 0, 0, 0}
};
+static int ki_pl_drop(sip_msg_t* msg)
+{
+ return pl_drop(msg, 0, 0);
+}
+
+static int ki_pl_drop_retry(sip_msg_t* msg, int rafter)
+{
+ return pl_drop(msg, rafter, rafter);
+}
+
+static int ki_pl_drop_range(sip_msg_t* msg, int rmin, int rmax)
+{
+ return pl_drop(msg, rmin, rmax);
+}
+
+/**
+ *
+ */
+/* clang-format off */
+static sr_kemi_t sr_kemi_pipelimit_exports[] = {
+ { str_init("pipelimit"), str_init("pl_check"),
+ SR_KEMIP_INT, pl_check,
+ { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init("pipelimit"), str_init("pl_check_limit"),
+ SR_KEMIP_INT, pl_check_limit,
+ { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_INT,
+ 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,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init("pipelimit"), str_init("pl_drop_retry"),
+ SR_KEMIP_INT, ki_pl_drop_retry,
+ { SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init("pipelimit"), str_init("pl_drop_range"),
+ SR_KEMIP_INT, ki_pl_drop_range,
+ { SR_KEMIP_INT, SR_KEMIP_INT, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+
+ { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
+};
+/* clang-format on */
+
+/**
+ *
+ */
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
+{
+ sr_kemi_modules_add(sr_kemi_pipelimit_exports);
+ return 0;
+}
\ No newline at end of file