[prev in list] [next in list] [prev in thread] [next in thread]
List: subversion-commits
Subject: svn commit: r1614622 - in /subversion/branches/authzperf: BRANCH-README subversion/libsvn_repos/auth
From: stefan2 () apache ! org
Date: 2014-07-30 11:50:37
Message-ID: 20140730115037.C2EF22388EF1 () eris ! apache ! org
[Download RAW message or body]
Author: stefan2
Date: Wed Jul 30 11:50:37 2014
New Revision: 1614622
URL: http://svn.apache.org/r1614622
Log:
On the authzperf branch: Add support for suffix segment patterns ("*foo").
Suffix rules are basically reversed prefix rules. So, we reverse the
rules and match against reversed segment names using the existing prefix
matching code.
* BRANCH-README
(TODO, DONE): Another wildcard pattern is now supported.
* subversion/libsvn_repos/authz.c
(reverse_string): New utility for reversing segments and patterns.
(node_pattern_t): Add yet another sub-node container.
(is_suffix_segment): New segment pattern classification utility.
(insert_path): Detect and handle suffix pattern rules.
(finalize_tree): Include traversal of the new sub-node array.
(lookup): Include scanning the new sub-node array.
Modified:
subversion/branches/authzperf/BRANCH-README
subversion/branches/authzperf/subversion/libsvn_repos/authz.c
Modified: subversion/branches/authzperf/BRANCH-README
URL: http://svn.apache.org/viewvc/subversion/branches/authzperf/BRANCH-README?rev=1614622&r1=1614621&r2=1614622&view=diff
==============================================================================
--- subversion/branches/authzperf/BRANCH-README (original)
+++ subversion/branches/authzperf/BRANCH-README Wed Jul 30 11:50:37 2014
@@ -9,7 +9,6 @@ TODO:
* implement an authz-specific constructor for the config parser
* implement precedence rules
-* add support for suffix segment patterns ("/*foo/")
* add support for arbitrary patterns ("/foo*bar*baz/" etc.)
* implement value-expansion mode in the config parser
@@ -24,3 +23,4 @@ DONE:
* add support for full-segment wildcards ("/*/")
* add support for variable length full-segment wildcards ("/**/")
* add support for prefix segment patterns ("/foo*/")
+* add support for suffix segment patterns ("/*foo/")
Modified: subversion/branches/authzperf/subversion/libsvn_repos/authz.c
URL: http://svn.apache.org/viewvc/subversion/branches/authzperf/subversion/libsvn_repos/authz.c?rev=1614622&r1=1614621&r2=1614622&view=diff
==============================================================================
--- subversion/branches/authzperf/subversion/libsvn_repos/authz.c (original)
+++ subversion/branches/authzperf/subversion/libsvn_repos/authz.c Wed Jul 30 11:50:37 \
2014 @@ -53,6 +53,22 @@ set_add_string(apr_hash_t *set,
apr_hash_set(set, key, strlen(key), "");
}
+/* In situ reversal of the first LEN chars in S.
+ * S must be at least LEN characters long.
+ */
+static void
+reverse_string(char *s,
+ apr_size_t len)
+{
+ char *lhs, *rhs;
+ for (lhs = s, rhs = s + len - 1; lhs < rhs; ++lhs, --rhs)
+ {
+ char c = *lhs;
+ *lhs = *rhs;
+ *rhs = c;
+ }
+}
+
/*** Users, aliases and groups. ***/
@@ -304,6 +320,11 @@ typedef struct node_pattern_t
* part of "prefix*" patterns. Sorted by segment prefix. */
apr_array_header_t *prefixes;
+ /* If not NULL, the segments of all nodes_t* in this array are the
+ * reversed suffix part of "*suffix" patterns. Sorted by reversed
+ * segment suffix. */
+ apr_array_header_t *suffixes;
+
/* This node itself is a "**" segment and must therefore itself be added
* to the matching node list for the next level. */
svn_boolean_t repeat;
@@ -435,6 +456,14 @@ is_prefix_segment(const char *segment)
return wildcard_pos && wildcard_pos[1] == 0;
}
+/* Return TRUE, if SEGMENT is a suffix pattern, i.e. contains exactly one
+ * '*' and that is at the beginning of the string. */
+static svn_boolean_t
+is_suffix_segment(const char *segment)
+{
+ return segment[0] == '*' && !strchr(segment + 1, '*');
+}
+
/* Constructor utility: Create a new tree node for SEGMENT.
*/
static node_t *
@@ -579,6 +608,15 @@ insert_path(node_t *node,
segment, result_pool);
}
+ /* A single wildcard at the start of segments? */
+ else if (is_suffix_segment(segment))
+ {
+ char *reversed = apr_pstrdup(scratch_pool, segment + 1);
+ reverse_string(reversed, strlen(reversed));
+ sub_node = ensure_node_in_array(&node->pattern_sub_nodes->suffixes,
+ reversed, result_pool);
+ }
+
/* More cases to be added here later.
* There will be no error condition to be checked for. */
}
@@ -747,6 +785,8 @@ finalize_tree(node_t *parent,
finalize_subnode_array(node, access, node->pattern_sub_nodes->prefixes,
scratch_pool);
+ finalize_subnode_array(node, access, node->pattern_sub_nodes->suffixes,
+ scratch_pool);
}
/* Add our min / max info to the parent's info.
@@ -1088,6 +1128,16 @@ lookup(lookup_state_t *state,
if (node->pattern_sub_nodes->prefixes)
add_prefix_matches(state, segment,
node->pattern_sub_nodes->prefixes);
+
+ /* Find all suffux pattern matches.
+ * This must be the last check as it destroys SEGMENT. */
+ if (node->pattern_sub_nodes->suffixes)
+ {
+ /* Suffixes behave like reversed prefixes. */
+ reverse_string(segment->data, segment->len);
+ add_prefix_matches(state, segment,
+ node->pattern_sub_nodes->suffixes);
+ }
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic