Module: kamailio
Branch: master
Commit: d5b6568529a26fb21b0aef9634354ade63aee802
URL:
https://github.com/kamailio/kamailio/commit/d5b6568529a26fb21b0aef9634354ad…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-07-25T14:48:29+02:00
pipelimit: added rpc command pl.list
- get the details of one or all pipes in json format
- old pl.stats and pl.get_pipes print details in a string
---
Modified: src/modules/pipelimit/pipelimit.c
Modified: src/modules/pipelimit/pl_ht.c
---
Diff:
https://github.com/kamailio/kamailio/commit/d5b6568529a26fb21b0aef9634354ad…
Patch:
https://github.com/kamailio/kamailio/commit/d5b6568529a26fb21b0aef9634354ad…
---
diff --git a/src/modules/pipelimit/pipelimit.c b/src/modules/pipelimit/pipelimit.c
index da30bcbd31..ce7935afb0 100644
--- a/src/modules/pipelimit/pipelimit.c
+++ b/src/modules/pipelimit/pipelimit.c
@@ -734,15 +734,19 @@ static ticks_t pl_timer_handle(ticks_t ticks, struct timer_ln* tl,
void* data)
/* rpc function documentation */
const char *rpc_pl_stats_doc[2] = {
- "Print pipelimit statistics: \
+ "Print pipelimit statistics (string output): \
<id> <load> <counter>", 0
};
const char *rpc_pl_get_pipes_doc[2] = {
- "Print pipes info: \
+ "Print pipes info (string output): \
<id> <algorithm> <limit> <counter>", 0
};
+const char *rpc_pl_list_doc[2] = {
+ "List details for one or all pipes", 0
+};
+
const char *rpc_pl_set_pipe_doc[2] = {
"Sets a pipe params: <pipe_id> <pipe_algorithm>
<pipe_limit>", 0
};
@@ -764,6 +768,7 @@ const char *rpc_pl_push_load_doc[2] = {
/* rpc function implementations */
void rpc_pl_stats(rpc_t *rpc, void *c);
+void rpc_pl_list(rpc_t *rpc, void *c);
void rpc_pl_get_pipes(rpc_t *rpc, void *c);
void rpc_pl_set_pipe(rpc_t *rpc, void *c);
@@ -804,6 +809,7 @@ void rpc_pl_push_load(rpc_t *rpc, void *c) {
static rpc_export_t rpc_methods[] = {
{"pl.stats", rpc_pl_stats, rpc_pl_stats_doc, RET_ARRAY},
+ {"pl.list", rpc_pl_list, rpc_pl_list_doc, RET_ARRAY},
{"pl.get_pipes", rpc_pl_get_pipes, rpc_pl_get_pipes_doc, RET_ARRAY},
{"pl.set_pipe", rpc_pl_set_pipe, rpc_pl_set_pipe_doc, 0},
{"pl.get_pid", rpc_pl_get_pid, rpc_pl_get_pid_doc, 0},
diff --git a/src/modules/pipelimit/pl_ht.c b/src/modules/pipelimit/pl_ht.c
index f23414c29a..07f69f666d 100644
--- a/src/modules/pipelimit/pl_ht.c
+++ b/src/modules/pipelimit/pl_ht.c
@@ -444,6 +444,76 @@ void rpc_pl_get_pipes(rpc_t *rpc, void *c)
}
}
+int rpc_pl_list_pipe(rpc_t *rpc, void *c, pl_pipe_t *it)
+{
+ str algo;
+ void* th;
+
+ if (it->algo == PIPE_ALGO_NOP) {
+ return 0;
+ }
+
+ if (str_map_int(algo_names, it->algo, &algo)) {
+ return -1;
+ }
+ /* add structure node */
+ if (rpc->add(c, "{", &th) < 0) {
+ rpc->fault(c, 500, "Internal pipe structure");
+ return -1;
+ }
+ if(rpc->struct_add(th, "ssdd",
+ "name", it->name.s,
+ "algorithm", algo.s,
+ "limit", it->limit,
+ "counter", it->counter)<0) {
+ rpc->fault(c, 500, "Internal error address list structure");
+ return -1;
+ }
+ return 0;
+}
+
+void rpc_pl_list(rpc_t *rpc, void *c)
+{
+ int i;
+ pl_pipe_t *it;
+ str pipeid = STR_NULL;
+ int ret;
+
+ if (rpc->scan(c, "*S", &pipeid) < 1) {
+ pipeid.s = NULL;
+ pipeid.len = 0;
+ }
+
+ if(pipeid.len>0) {
+ it = pl_pipe_get(&pipeid, 1);
+ if (it==NULL) {
+ LM_ERR("no pipe: %.*s\n", pipeid.len, pipeid.s);
+ rpc->fault(c, 400, "Unknown pipe id %.*s", pipeid.len, pipeid.s);
+ return;
+ }
+ if(rpc_pl_list_pipe(rpc, c, it)<0) {
+ LM_DBG("failed to list pipe: %.*s\n", it->name.len, it->name.s);
+ }
+ pl_pipe_release(&pipeid);
+ return;
+ }
+
+ for(i=0; i<_pl_pipes_ht->htsize; i++)
+ {
+ lock_get(&_pl_pipes_ht->slots[i].lock);
+ it = _pl_pipes_ht->slots[i].first;
+ while(it) {
+ if(rpc_pl_list_pipe(rpc, c, it)<0) {
+ LM_DBG("failed to list pipe: %.*s\n", it->name.len, it->name.s);
+ lock_release(&_pl_pipes_ht->slots[i].lock);
+ return;
+ }
+ it = it->next;
+ }
+ lock_release(&_pl_pipes_ht->slots[i].lock);
+ }
+}
+
void rpc_pl_set_pipe(rpc_t *rpc, void *c)
{
unsigned int algo_id, limit = 0;