[sr-dev] git:master:ce00265d: lcr: implemented structured output for lcr.dump_rules rpc command
Ovidiu Sas
osas at voipembedded.com
Mon Apr 8 21:01:50 CEST 2019
Module: kamailio
Branch: master
Commit: ce00265d25741657f255bd35403ba9d6cce297fc
URL: https://github.com/kamailio/kamailio/commit/ce00265d25741657f255bd35403ba9d6cce297fc
Author: Ovidiu Sas <osas at voipembedded.com>
Committer: Ovidiu Sas <osas at voipembedded.com>
Date: 2019-04-08T15:00:06-04:00
lcr: implemented structured output for lcr.dump_rules rpc command
---
Modified: src/modules/lcr/lcr_rpc.c
---
Diff: https://github.com/kamailio/kamailio/commit/ce00265d25741657f255bd35403ba9d6cce297fc.diff
Patch: https://github.com/kamailio/kamailio/commit/ce00265d25741657f255bd35403ba9d6cce297fc.patch
---
diff --git a/src/modules/lcr/lcr_rpc.c b/src/modules/lcr/lcr_rpc.c
index ec10653a32..ef5b351e6c 100644
--- a/src/modules/lcr/lcr_rpc.c
+++ b/src/modules/lcr/lcr_rpc.c
@@ -131,7 +131,9 @@ static void dump_rules(rpc_t *rpc, void *c)
str _prefix = {NULL,0};
struct rule_info **rules, *rule;
struct target *t;
- void *st;
+ void *rec = NULL;
+ void *srec = NULL;
+ void *st, *sst, *ssst;
str prefix, from_uri, request_uri;
if (rpc->scan(c, "d", &_lcr_id)>0) {
@@ -156,7 +158,14 @@ static void dump_rules(rpc_t *rpc, void *c)
continue;
}
}
- if(rpc->add(c, "{", &st) < 0)
+ if (srec==NULL) {
+ /* We create one array per lcr_id */
+ if(rpc->add(c, "{", &rec) < 0)
+ return;
+ if(rpc->struct_add(rec, "[", "rule", &srec) < 0)
+ return;
+ }
+ if(rpc->array_add(srec, "{", &st) < 0)
return;
prefix.s = rule->prefix;
prefix.len = rule->prefix_len;
@@ -168,24 +177,37 @@ static void dump_rules(rpc_t *rpc, void *c)
rule->rule_id, "prefix", &prefix, "from_uri", &from_uri,
"request_uri", &request_uri, "stopper", rule->stopper);
t = rule->targets;
- while(t) {
- if(rpc->add(c, "{", &st) < 0)
+ if (t) {
+ if (rpc->struct_add(st, "[", "gw", &sst) < 0)
return;
- rpc->struct_add(st, "ddd", "gw_index", t->gw_index,
- "priority", t->priority, "weight", t->weight);
- t = t->next;
+ while(t) {
+ if (rpc->array_add(sst, "{", &ssst) < 0)
+ return;
+ rpc->struct_add(ssst, "ddd", "gw_index", t->gw_index,
+ "priority", t->priority, "weight", t->weight);
+ t = t->next;
+ }
}
rule = rule->next;
}
}
+
+ /* Mark the end of rule array */
+ srec = NULL;
+
if (_filter_by_prefix)
continue;
rule = rules[lcr_rule_hash_size_param];
- while(rule) {
- rpc->add(c, "d", rule->prefix_len);
- rule = rule->next;
+ if (rule) {
+ if(rpc->struct_add(rec, "[", "prefix_len", &st) < 0)
+ return;
+ while(rule) {
+ rpc->array_add(st, "d", rule->prefix_len);
+ rule = rule->next;
+ }
}
}
+ if (rec==NULL) rpc->fault(c, 404, "Empty reply");
}
More information about the sr-dev
mailing list