summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <freddy77@gmail.com>2021-06-04 12:24:54 +0100
committerFrediano Ziglio <freddy77@gmail.com>2021-06-07 13:20:21 +0100
commit8edc63e91edddd79f76ae18e1ff903fe2325e71a (patch)
tree06700d32bef6c84db1df7d2d6e525ffcb7828528
parentd8fd31872184a045bce02f694d7f44ad38d4a8af (diff)
Use strtok style separator for usbredirfilter_string_to_rules
Follow strtok way to handle tokens using all set of separators and collapsing them. The function was already using strtok but had a bug preventing to use it correctly. Update documentation to explain the change. Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
-rw-r--r--usbredirparser/usbredirfilter.c10
-rw-r--r--usbredirparser/usbredirfilter.h12
2 files changed, 12 insertions, 10 deletions
diff --git a/usbredirparser/usbredirfilter.c b/usbredirparser/usbredirfilter.c
index fe4efdb..32f05d7 100644
--- a/usbredirparser/usbredirfilter.c
+++ b/usbredirparser/usbredirfilter.c
@@ -51,11 +51,13 @@ int usbredirfilter_string_to_rules(
empty rule strings in the set. */
r = filter_str;
rules_count = 0;
- while (r) {
- r = strchr(r, rule_sep[0]);
- if (r)
- r++;
+ for (;;) {
+ r += strspn(r, rule_sep);
+ if (!*r) {
+ break;
+ }
rules_count++;
+ r += strcspn(r, rule_sep);
}
rules = calloc(rules_count, sizeof(struct usbredirfilter_rule));
diff --git a/usbredirparser/usbredirfilter.h b/usbredirparser/usbredirfilter.h
index 85dfcca..62d4386 100644
--- a/usbredirparser/usbredirfilter.h
+++ b/usbredirparser/usbredirfilter.h
@@ -40,16 +40,16 @@ struct usbredirfilter_rule {
Where each rule has the form of:
<class>,<vendor>,<product>,<version>,<allow>
- Assuming "," as the specified token_sep character.
+ Assuming "," as the specified token_sep character set.
- And the rules are themselves are separated by the rule_sep character, ie:
+ And the rules are themselves are separated by any rule_sep characters, ie:
<rule1>|<rule2>|<rule3>
- Assuming "|" as the rule_sep character. Note that with the separator used
- in this example the format matches the format as written by the RHEV-M USB
- filter editor tool.
+ Assuming "|" as the rule_sep character set. Note that with the separator
+ used in this example the format matches the format as written by the RHEV-M
+ USB filter editor tool.
- Note that the separators must be single character strings!
+ The separators are used as strtok use separators.
On success the rules get returned in rules_ret and rules_count_ret, the
returned rules array should be freed with free() when the caller is done