From 37a90d6ee628cebc9c750637ff4d9a284be3c2b7 Mon Sep 17 00:00:00 2001 From: Ovidiu Sas Date: Wed, 3 Apr 2019 13:37:37 -0500 Subject: [PATCH] lcr: enhance the lcr.dump_rules with filtering params: - lcr_id [optional] - prefix [optional] If lcr_id param is provided, then only the rules belonging to the given lcr_id will be dumped. If the lcr_id and prefix param is provided, then only the rules belonging to the given lcr_id and prefixes that equal or longer to the given prefix will be dumped. --- src/modules/lcr/lcr_rpc.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/modules/lcr/lcr_rpc.c b/src/modules/lcr/lcr_rpc.c index baf657ad0c9..af4a205d35e 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, _prefix.len)!=0) { + rule = rule->next; + continue; + } + } if(rpc->add(c, "{", &st) < 0) return; prefix.s = rule->prefix; @@ -243,4 +261,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 */