[Asterisk-code-review] config: Allow filters when appending to a category (asterisk[master])
George Joseph
asteriskteam at digium.com
Sun Mar 27 23:54:26 CDT 2016
George Joseph has uploaded a new change for review.
https://gerrit.asterisk.org/2488
Change subject: config: Allow filters when appending to a category
......................................................................
config: Allow filters when appending to a category
In sorcery based config files where there are multiple categories with the same
name, you can't use the (+) operator to reliably append to a category because
config.c stops looking when it finds the first one with the same name.
Example:
[1000]
type = endpoint
[1000]
type = aor
[1000](+)
authenticate_qualify = yes
This config will fail because config.c appends authenticate_qualify to the
first category it finds, the endpoint, and that's not valid for endpoint.
Solution:
The capability to find a category that contains a certain variable already
exists so the only real change was to parse anything after the '+' that's not a
comma, as a filter string.
[1000]
type = endpoint
[1000]
type = aor
[1000](+type=aor)
authenticate_qualify = yes
This now works as expected.
Although the following example doesn't make any sense for pjsip, you can even
specify multiple filters:
[1000](+type=aor&qualify_frequency=10)
ASTERISK-25868 #close
Reported-by: Nick Repin
Change-Id: I10773da4c79db36fbf1993961992af63d3441580
---
M include/asterisk/strings.h
M main/config.c
M main/utils.c
3 files changed, 36 insertions(+), 6 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/88/2488/1
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h
index 3701b53..b5302e3 100644
--- a/include/asterisk/strings.h
+++ b/include/asterisk/strings.h
@@ -304,6 +304,24 @@
char *ast_strsep(char **s, const char sep, uint32_t flags);
/*!
+ \brief Like ast_strsep but allows multiple separators
+ \since 13.9.0
+
+ \param s Pointer to address of the the string to be processed.
+ Will be modified and can't be constant.
+ \param sep A string of delimiters
+ \param flags Controls post-processing of the result.
+ AST_STRSEP_TRIM trims all leading and trailing whitespace from the result.
+ AST_STRSEP_STRIP does a trim then strips the outermost quotes. You may want
+ to trim again after the strip. Just OR both the TRIM and STRIP flags.
+ AST_STRSEP_UNESCAPE unescapes '\' sequences.
+ AST_STRSEP_ALL does all of the above processing.
+ \return The next token or NULL if done or if there are more than 8 levels of
+ nested quotes.
+*/
+char *ast_strsep2(char **s, const char *sep, uint32_t flags);
+
+/*!
\brief Strip backslash for "escaped" semicolons,
the string to be stripped (will be modified).
\return The stripped string.
diff --git a/main/config.c b/main/config.c
index 04e9367..4fc6d65 100644
--- a/main/config.c
+++ b/main/config.c
@@ -793,7 +793,7 @@
dupmatch = ast_strdupa(match);
- while ((nvp = ast_strsep(&dupmatch, ',', AST_STRSEP_STRIP))) {
+ while ((nvp = ast_strsep2(&dupmatch, ",&", AST_STRSEP_STRIP))) {
struct ast_variable *v;
char *match_name;
char *match_value = NULL;
@@ -1687,8 +1687,12 @@
while ((cur = strsep(&c, ","))) {
if (!strcasecmp(cur, "!")) {
(*cat)->ignored = 1;
- } else if (!strcasecmp(cur, "+")) {
- *cat = ast_category_get(cfg, catname, NULL);
+ } else if (cur[0] == '+') {
+ char *filter = NULL;
+ if (cur[1] != ',') {
+ filter = &cur[1];
+ }
+ *cat = ast_category_get(cfg, catname, filter);
if (!(*cat)) {
if (newcat) {
ast_category_destroy(newcat);
diff --git a/main/utils.c b/main/utils.c
index 6a778b9..d2e3726 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -1511,7 +1511,7 @@
return s;
}
-char *ast_strsep(char **iss, const char sep, uint32_t flags)
+char *ast_strsep2(char **iss, const char *sep, uint32_t flags)
{
char *st = *iss;
char *is;
@@ -1519,7 +1519,7 @@
int found = 0;
char stack[8];
- if (iss == NULL || *iss == '\0') {
+ if (!iss || *iss == '\0' || !sep) {
return NULL;
}
@@ -1545,7 +1545,7 @@
}
}
- if (*is == sep && !inquote) {
+ if (strchr(sep, *is) && !inquote) {
*is = '\0';
found = 1;
*iss = is + 1;
@@ -1571,6 +1571,14 @@
return st;
}
+char *ast_strsep(char **iss, const char sep, uint32_t flags)
+{
+ const char string_sep[] = { sep, '\0' };
+
+ return ast_strsep2(iss, string_sep, flags);
+}
+
+
char *ast_unescape_semicolon(char *s)
{
char *e;
--
To view, visit https://gerrit.asterisk.org/2488
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I10773da4c79db36fbf1993961992af63d3441580
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: George Joseph <george.joseph at fairview5.com>
More information about the asterisk-code-review
mailing list