]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
main/format_cap: Parse capabilities generated by ast_format_cap_get_names 76/876/1
authorMatt Jordan <mjordan@digium.com>
Wed, 8 Jul 2015 21:21:09 +0000 (16:21 -0500)
committerMatt Jordan <mjordan@digium.com>
Sat, 11 Jul 2015 21:06:13 +0000 (16:06 -0500)
We have a strange relationship between the parsing of format
capabilities from a string and their representation as a string. We
expect the format capabilities to be expressed as a string in the
following format:

allow = !all,ulaw,alaw
disallow = g722

While we would generate the string representation of those formats as:

allow = (ulaw|alaw)
disallow = (ulaw|alaw|g729...)

When the configuration framework needs to store values as a string, it
generates the format capabilities using the second representation; this
representation however cannot be parsed when the entry is rehydrated.
This patch fixes that by updating
ast_format_cap_update_by_allow_disallow to parse an entry as if it were
in the generated format if it has a leading '(' and a trailing ')'.

ASTERISK-25238

Change-Id: I904d43caf4cf45af06f6aee0c9e58556eb91d6ca

main/format_cap.c

index 52262579cf0fa98e3e194b56432dba7ec121a3ce..224fe331fb4c7d5d8acf6fef56de3d89232bd616 100644 (file)
@@ -293,7 +293,24 @@ int ast_format_cap_update_by_allow_disallow(struct ast_format_cap *cap, const ch
        }
 
        parse = ast_strdupa(list);
-       while ((this = strsep(&parse, ","))) {
+
+       /* If the list is being fed to us as a result of ast_format_cap_get_names,
+        * strip off the paranthesis and immediately apply the inverse of the
+        * allowing option
+        */
+       if (parse[0] == '(' && parse[strlen(parse) - 1] == ')') {
+               parse++;
+               parse[strlen(parse) - 1] = '\0';
+
+               if (allowing) {
+                       ast_format_cap_remove_by_type(cap, AST_MEDIA_TYPE_UNKNOWN);
+               } else {
+                       ast_format_cap_append_by_type(cap, AST_MEDIA_TYPE_UNKNOWN);
+               }
+       }
+
+
+       while ((this = strsep(&parse, ",|"))) {
                int framems = 0;
                struct ast_format *format = NULL;