Module: kamailio
Branch: master
Commit: 8f796ab6f5b1edb0c4b9a7d4e3251a026dd0bb1a
URL:
https://github.com/kamailio/kamailio/commit/8f796ab6f5b1edb0c4b9a7d4e3251a0…
Author: Ovidiu Sas <osas(a)voipembedded.com>
Committer: Ovidiu Sas <osas(a)voipembedded.com>
Date: 2019-04-04T10:46:33-04:00
lcr: enhance RPC command lcr.dump_rules with filetring params
---
Modified: src/modules/lcr/doc/lcr.xml
Modified: src/modules/lcr/doc/lcr_admin.xml
Modified: src/modules/lcr/lcr_rpc.c
---
Diff:
https://github.com/kamailio/kamailio/commit/8f796ab6f5b1edb0c4b9a7d4e3251a0…
Patch:
https://github.com/kamailio/kamailio/commit/8f796ab6f5b1edb0c4b9a7d4e3251a0…
---
diff --git a/src/modules/lcr/doc/lcr.xml b/src/modules/lcr/doc/lcr.xml
index 720528d713..a328860214 100644
--- a/src/modules/lcr/doc/lcr.xml
+++ b/src/modules/lcr/doc/lcr.xml
@@ -22,6 +22,11 @@
<surname>Heinanen</surname>
<email>jh(a)tutpro.com</email>
</editor>
+ <editor>
+ <firstname>Ovidiu</firstname>
+ <surname>Sas</surname>
+ <email>osas(a)voipembedded.com</email>
+ </editor>
</authorgroup>
<copyright>
<year>2005-2014</year>
diff --git a/src/modules/lcr/doc/lcr_admin.xml b/src/modules/lcr/doc/lcr_admin.xml
index e0e8755322..47bed3ee9f 100644
--- a/src/modules/lcr/doc/lcr_admin.xml
+++ b/src/modules/lcr/doc/lcr_admin.xml
@@ -1641,8 +1641,20 @@ if (to_any_gw("192.55.66.2", 1)) {
<para>
Causes lcr module to dump the contents of its
in-memory lcr_rule and lcr_rule_target tables.
+ Rules can be filetered by lcr_id or lcr_id and prefix.
+ The filters are passed as optional parameters.
</para>
- <para>Parameters: <emphasis>none</emphasis></para>
+ <para>Parameters:</para>
+ <itemizedlist>
+ <listitem><para>
+ <emphasis>lcr_id</emphasis> filter rules based on lcr_id.
+ </para></listitem>
+ <listitem><para>
+ <emphasis>prefix</emphasis> filter rules based on prefix
+ (prefixes shorter or equal to the give prefix) in addition
+ to the previous lcr_id parameter.
+ </para></listitem>
+ </itemizedlist>
<example>
<title><function>lcr.dump_rules</function> RPC example</title>
<programlisting format="linespecific">
diff --git a/src/modules/lcr/lcr_rpc.c b/src/modules/lcr/lcr_rpc.c
index baf657ad0c..ec10653a32 100644
--- a/src/modules/lcr/lcr_rpc.c
+++ b/src/modules/lcr/lcr_rpc.c
@@ -126,18 +126,36 @@ static const char *dump_rules_doc[2] = {
static void dump_rules(rpc_t *rpc, void *c)
{
int i, j;
+ int _filter_by_prefix = 0;
+ int _lcr_id = 0;
+ str _prefix = {NULL,0};
struct rule_info **rules, *rule;
struct target *t;
void *st;
str prefix, from_uri, request_uri;
+ if (rpc->scan(c, "d", &_lcr_id)>0) {
+ if (rpc->scan(c, ".S", &_prefix)>0) {
+ _filter_by_prefix = 1;
+ }
+ }
+
for(j = 1; j <= lcr_count_param; j++) {
+ if (_lcr_id && _lcr_id!=j) continue;
+
rules = rule_pt[j];
for(i = 0; i < lcr_rule_hash_size_param; i++) {
rule = rules[i];
while(rule) {
+ if (_filter_by_prefix && _prefix.len && _prefix.s) {
+ if (_prefix.len < rule->prefix_len ||
+ strncmp(_prefix.s, rule->prefix, rule->prefix_len)!=0) {
+ rule = rule->next;
+ continue;
+ }
+ }
if(rpc->add(c, "{", &st) < 0)
return;
prefix.s = rule->prefix;
@@ -160,6 +178,8 @@ static void dump_rules(rpc_t *rpc, void *c)
rule = rule->next;
}
}
+ if (_filter_by_prefix)
+ continue;
rule = rules[lcr_rule_hash_size_param];
while(rule) {
rpc->add(c, "d", rule->prefix_len);
@@ -243,4 +263,4 @@ rpc_export_t lcr_rpc[] = {
{"lcr.load_gws", load_gws, load_gws_doc, 0},
{0, 0, 0, 0}
};
-/* clang-format on */
\ No newline at end of file
+/* clang-format on */