You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by tr...@apache.org on 2015/10/01 15:46:05 UTC
[1/2] qpid-dispatch git commit: DISPATCH-159 - Additional fix for
exact matching. Also added backward compatibility by letting a dot (.) be at
the end of the linkRoutePattern property. Added additional tests for exact
matching and dot-at-end matching
Repository: qpid-dispatch
Updated Branches:
refs/heads/master 6406f040b -> 96affd96b
DISPATCH-159 - Additional fix for exact matching. Also added backward compatibility by letting a dot (.) be at the end of the linkRoutePattern property. Added additional tests for exact matching and dot-at-end matching
Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/839cc0e7
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/839cc0e7
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/839cc0e7
Branch: refs/heads/master
Commit: 839cc0e70ffe461765916da8ab28590fd0838f14
Parents: 6406f04
Author: ganeshmurthy <gm...@redhat.com>
Authored: Thu Oct 1 09:23:29 2015 -0400
Committer: ganeshmurthy <gm...@redhat.com>
Committed: Thu Oct 1 09:23:29 2015 -0400
----------------------------------------------------------------------
src/iterator.c | 18 +++--
tests/field_test.c | 205 +++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 195 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/839cc0e7/src/iterator.c
----------------------------------------------------------------------
diff --git a/src/iterator.c b/src/iterator.c
index 39cb96e..43efb8d 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -87,7 +87,7 @@ typedef enum {
static char *my_area = "";
static char *my_router = "";
-const char SEPARATOR_SLASH = '/';
+const char SEPARATOR_DOT = '.';
const uint32_t HASH_INIT = 5381;
@@ -275,7 +275,7 @@ static void view_initialize(qd_field_iterator_t *iter)
if (iter->view == ITER_VIEW_ADDRESS_HASH) {
iter->mode = MODE_TO_END;
- qd_address_iterator_check_trailing_octet(iter, '/');
+ qd_address_iterator_check_trailing_octet(iter, SEPARATOR_DOT);
parse_address_view(iter);
return;
}
@@ -521,7 +521,7 @@ int qd_field_iterator_equal(qd_field_iterator_t *iter, const unsigned char *stri
qd_field_iterator_reset(iter);
while (!qd_field_iterator_end(iter) && *string) {
- if (*string != qd_field_iterator_octet(iter))
+ if (*string != qd_field_iterator_octet(iter))
break;
string++;
}
@@ -680,7 +680,8 @@ static void qd_insert_hash_segment(qd_field_iterator_t *iter, uint32_t *hash, in
// While storing the segment, don't include the hash of the separator in the segment but do include it in the overall hash.
hash_segment->hash = *hash;
- hash_segment->segment_length = segment_length - 1;
+
+ hash_segment->segment_length = segment_length;
DEQ_INSERT_TAIL(iter->hash_segments, hash_segment);
}
@@ -692,23 +693,24 @@ void qd_iterator_hash_segments(qd_field_iterator_t *iter)
uint32_t hash = HASH_INIT;
char octet;
int segment_length=0;
+
while (!qd_field_iterator_end(iter)) {
// Get the octet at which the iterator is currently pointing to.
octet = qd_field_iterator_octet(iter);
segment_length += 1;
- if (octet == SEPARATOR_SLASH) {
- qd_insert_hash_segment(iter, &hash, segment_length);
+ if (octet == SEPARATOR_DOT) {
+ qd_insert_hash_segment(iter, &hash, segment_length-1);
}
hash = ((hash << 5) + hash) + octet; /* hash * 33 + c */
}
// Segments should never end with a separator. see view_initialize which in turn calls qd_address_iterator_check_trailing_octet
- // Insert the last segment
+ // Insert the last segment which was not inserted in the previous while loop
qd_insert_hash_segment(iter, &hash, segment_length);
- // Return the pointers in the iterator back to the original state.
+ // Return the pointers in the iterator back to the original state before returning from this function.
qd_field_iterator_reset(iter);
}
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/839cc0e7/tests/field_test.c
----------------------------------------------------------------------
diff --git a/tests/field_test.c b/tests/field_test.c
index 5430bd5..a093505 100644
--- a/tests/field_test.c
+++ b/tests/field_test.c
@@ -168,20 +168,20 @@ static char* test_view_address_hash(void *context)
{"_topo/my-area/router", "Rrouter"},
{"amqp:/mobile", "M1mobile"},
- // Re-run the above tests to make sure trailing slashes are ignored.
- {"amqp:/_local/my-addr/sub/", "Lmy-addr/sub"},
- {"amqp:/_local/my-addr/", "Lmy-addr"},
- {"amqp:/_topo/area/router/local/sub/", "Aarea"},
- {"amqp:/_topo/my-area/router/local/sub/", "Rrouter"},
- {"amqp:/_topo/my-area/my-router/local/sub/", "Llocal/sub"},
- {"amqp:/_topo/area/all/local/sub/", "Aarea"},
- {"amqp:/_topo/my-area/all/local/sub/", "Llocal/sub"},
- {"amqp:/_topo/all/all/local/sub/", "Llocal/sub"},
- {"amqp://host:port/_local/my-addr/", "Lmy-addr"},
- {"_topo/area/router/my-addr/", "Aarea"},
- {"_topo/my-area/router/my-addr/", "Rrouter"},
- {"_topo/my-area/my-router/my-addr/", "Lmy-addr"},
- {"_topo/my-area/router/", "Rrouter"},
+ // Re-run the above tests to make sure trailing dots are ignored.
+ {"amqp:/_local/my-addr/sub.", "Lmy-addr/sub"},
+ {"amqp:/_local/my-addr.", "Lmy-addr"},
+ {"amqp:/_topo/area/router/local/sub.", "Aarea"},
+ {"amqp:/_topo/my-area/router/local/sub.", "Rrouter"},
+ {"amqp:/_topo/my-area/my-router/local/sub.", "Llocal/sub"},
+ {"amqp:/_topo/area/all/local/sub.", "Aarea"},
+ {"amqp:/_topo/my-area/all/local/sub.", "Llocal/sub"},
+ {"amqp:/_topo/all/all/local/sub.", "Llocal/sub"},
+ {"amqp://host:port/_local/my-addr.", "Lmy-addr"},
+ {"_topo/area/router/my-addr.", "Aarea"},
+ {"_topo/my-area/router/my-addr.", "Rrouter"},
+ {"_topo/my-area/my-router/my-addr.", "Lmy-addr"},
+ {"_topo/my-area/router.", "Rrouter"},
{"_topo/my-area/router:", "Rrouter:"},
{0, 0}
@@ -327,7 +327,7 @@ static char* test_field_advance_buffer(void *context)
static char *test_qd_hash_retrieve_prefix_separator(void *context)
{
qd_hash_t *hash = qd_hash(10, 32, 0);
- qd_field_iterator_t *iter = qd_address_iterator_string("policy/org/apache", ITER_VIEW_ADDRESS_HASH);
+ qd_field_iterator_t *iter = qd_address_iterator_string("policy.org.apache", ITER_VIEW_ADDRESS_HASH);
qd_address_iterator_override_prefix(iter, 'C');
// Insert that hash
@@ -337,7 +337,7 @@ static char *test_qd_hash_retrieve_prefix_separator(void *context)
if (error != QD_ERROR_NONE)
return "qd_hash_insert failed";
- const char *taddr = "policy/org/apache/dev";
+ const char *taddr = "policy.org.apache.dev";
qd_field_iterator_t *address_iter = qd_address_iterator_string(taddr, ITER_VIEW_ADDRESS_HASH);
qd_address_iterator_override_prefix(address_iter, 'C');
@@ -370,7 +370,7 @@ static char *test_qd_hash_retrieve_prefix(void *context)
if (error != QD_ERROR_NONE)
return "qd_hash_insert failed";
- const char *taddr = "policy/org/apache/dev";
+ const char *taddr = "policy.org.apache.dev";
qd_field_iterator_t *address_iter = qd_address_iterator_string(taddr, ITER_VIEW_ADDRESS_HASH);
qd_address_iterator_override_prefix(address_iter, 'C');
@@ -404,7 +404,7 @@ static char *test_qd_hash_retrieve_prefix_no_match(void *context)
if (error != QD_ERROR_NONE)
return "qd_hash_insert failed";
- const char *taddr = "policy/org/apache/dev";
+ const char *taddr = "policy.org.apache.dev";
qd_field_iterator_t *address_iter = qd_address_iterator_string(taddr, ITER_VIEW_ADDRESS_HASH);
qd_address_iterator_override_prefix(address_iter, 'C');
@@ -428,7 +428,7 @@ static char *test_qd_hash_retrieve_prefix_no_match_separator(void *context)
qd_hash_t *hash = qd_hash(10, 32, 0);
// No 'y' in policy. There should be no match.
- qd_field_iterator_t *iter = qd_address_iterator_string("policy/org/apach", ITER_VIEW_ADDRESS_HASH);
+ qd_field_iterator_t *iter = qd_address_iterator_string("policy.org.apach", ITER_VIEW_ADDRESS_HASH);
qd_address_iterator_override_prefix(iter, 'C');
// Insert that hash
@@ -438,7 +438,7 @@ static char *test_qd_hash_retrieve_prefix_no_match_separator(void *context)
if (error != QD_ERROR_NONE)
return "qd_hash_insert failed";
- const char *taddr = "policy/org/apache/dev";
+ const char *taddr = "policy.org.apache.dev";
qd_field_iterator_t *address_iter = qd_address_iterator_string(taddr, ITER_VIEW_ADDRESS_HASH);
qd_address_iterator_override_prefix(address_iter, 'C');
@@ -456,6 +456,166 @@ static char *test_qd_hash_retrieve_prefix_no_match_separator(void *context)
return 0;
}
+static char *test_qd_hash_retrieve_prefix_separator_exact_match(void *context)
+{
+ qd_hash_t *hash = qd_hash(10, 32, 0);
+ qd_field_iterator_t *iter = qd_address_iterator_string("policy", ITER_VIEW_ADDRESS_HASH);
+ qd_address_iterator_override_prefix(iter, 'C');
+
+ // Insert that hash
+ qd_error_t error = qd_hash_insert(hash, iter, "TEST", 0);
+
+ // There should be no error on the insert hash
+ if (error != QD_ERROR_NONE)
+ return "qd_hash_insert failed";
+
+ const char *taddr = "policy";
+
+ qd_field_iterator_t *address_iter = qd_address_iterator_string(taddr, ITER_VIEW_ADDRESS_HASH);
+ qd_address_iterator_override_prefix(address_iter, 'C');
+
+ qd_address_t *addr;
+
+ qd_hash_retrieve_prefix(hash, address_iter, (void*) &addr);
+
+ qd_field_iterator_free(iter);
+ qd_field_iterator_free(address_iter);
+
+ if(addr)
+ return 0;
+
+ return "test_qd_hash_retrieve_prefix_separator_exact_match() failed";
+}
+
+static char *test_qd_hash_retrieve_prefix_separator_exact_match_1(void *context)
+{
+ qd_hash_t *hash = qd_hash(10, 32, 0);
+ qd_field_iterator_t *iter = qd_address_iterator_string("policy.apache.org", ITER_VIEW_ADDRESS_HASH);
+ qd_address_iterator_override_prefix(iter, 'C');
+
+ // Insert that hash
+ qd_error_t error = qd_hash_insert(hash, iter, "TEST", 0);
+
+ // There should be no error on the insert hash
+ if (error != QD_ERROR_NONE)
+ return "qd_hash_insert failed";
+
+ const char *taddr = "policy.apache.org";
+
+ qd_field_iterator_t *address_iter = qd_address_iterator_string(taddr, ITER_VIEW_ADDRESS_HASH);
+ qd_address_iterator_override_prefix(address_iter, 'C');
+
+ qd_address_t *addr;
+
+ qd_hash_retrieve_prefix(hash, address_iter, (void*) &addr);
+
+ qd_field_iterator_free(iter);
+ qd_field_iterator_free(address_iter);
+
+ if(addr)
+ return 0;
+
+ return "test_qd_hash_retrieve_prefix_separator_exact_match_1() failed";
+}
+
+
+static char *test_qd_hash_retrieve_prefix_separator_exact_match_slashes(void *context)
+{
+ qd_hash_t *hash = qd_hash(10, 32, 0);
+
+ // Use slashes. slashes are not treated as separators, they are just part of the literal string.
+ qd_field_iterator_t *iter = qd_address_iterator_string("policy/apache/org", ITER_VIEW_ADDRESS_HASH);
+ qd_address_iterator_override_prefix(iter, 'C');
+
+ // Insert that hash
+ qd_error_t error = qd_hash_insert(hash, iter, "TEST", 0);
+
+ // There should be no error on the insert hash
+ if (error != QD_ERROR_NONE)
+ return "qd_hash_insert failed";
+
+ const char *taddr = "policy/apache/org";
+
+ qd_field_iterator_t *address_iter = qd_address_iterator_string(taddr, ITER_VIEW_ADDRESS_HASH);
+ qd_address_iterator_override_prefix(address_iter, 'C');
+
+ qd_address_t *addr;
+
+ qd_hash_retrieve_prefix(hash, address_iter, (void*) &addr);
+
+ qd_field_iterator_free(iter);
+ qd_field_iterator_free(address_iter);
+
+ if(addr)
+ return 0;
+
+ return "test_qd_hash_retrieve_prefix_separator_exact_match_slashes() failed";
+}
+
+
+static char *test_qd_hash_retrieve_prefix_separator_exact_match_dot_at_end(void *context)
+{
+ qd_hash_t *hash = qd_hash(10, 32, 0);
+ qd_field_iterator_t *iter = qd_address_iterator_string("policy", ITER_VIEW_ADDRESS_HASH);
+ qd_address_iterator_override_prefix(iter, 'C');
+
+ // Insert that hash
+ qd_error_t error = qd_hash_insert(hash, iter, "TEST", 0);
+
+ // There should be no error on the insert hash
+ if (error != QD_ERROR_NONE)
+ return "qd_hash_insert failed";
+
+ const char *taddr = "policy.";
+
+ qd_field_iterator_t *address_iter = qd_address_iterator_string(taddr, ITER_VIEW_ADDRESS_HASH);
+ qd_address_iterator_override_prefix(address_iter, 'C');
+
+ qd_address_t *addr;
+
+ qd_hash_retrieve_prefix(hash, address_iter, (void*) &addr);
+
+ qd_field_iterator_free(iter);
+ qd_field_iterator_free(address_iter);
+
+ if(addr)
+ return 0;
+
+ return "test_qd_hash_retrieve_prefix_separator_exact_match_dot_at_end() failed";
+}
+
+
+static char *test_qd_hash_retrieve_prefix_separator_exact_match_dot_at_end_1(void *context)
+{
+ qd_hash_t *hash = qd_hash(10, 32, 0);
+ qd_field_iterator_t *iter = qd_address_iterator_string("policy.apache", ITER_VIEW_ADDRESS_HASH);
+ qd_address_iterator_override_prefix(iter, 'C');
+
+ // Insert that hash
+ qd_error_t error = qd_hash_insert(hash, iter, "TEST", 0);
+
+ // There should be no error on the insert hash
+ if (error != QD_ERROR_NONE)
+ return "qd_hash_insert failed";
+
+ const char *taddr = "policy.apache.";
+
+ qd_field_iterator_t *address_iter = qd_address_iterator_string(taddr, ITER_VIEW_ADDRESS_HASH);
+ qd_address_iterator_override_prefix(address_iter, 'C');
+
+ qd_address_t *addr;
+
+ qd_hash_retrieve_prefix(hash, address_iter, (void*) &addr);
+
+ qd_field_iterator_free(iter);
+ qd_field_iterator_free(address_iter);
+
+ if(addr)
+ return 0;
+
+ return "test_qd_hash_retrieve_prefix_separator_exact_match_dot_at_end_1() failed";
+}
+
int field_tests(void)
{
@@ -475,6 +635,11 @@ int field_tests(void)
TEST_CASE(test_qd_hash_retrieve_prefix, 0);
TEST_CASE(test_qd_hash_retrieve_prefix_no_match, 0);
TEST_CASE(test_qd_hash_retrieve_prefix_no_match_separator, 0);
+ TEST_CASE(test_qd_hash_retrieve_prefix_separator_exact_match, 0);
+ TEST_CASE(test_qd_hash_retrieve_prefix_separator_exact_match_1, 0);
+ TEST_CASE(test_qd_hash_retrieve_prefix_separator_exact_match_slashes, 0);
+ TEST_CASE(test_qd_hash_retrieve_prefix_separator_exact_match_dot_at_end, 0);
+ TEST_CASE(test_qd_hash_retrieve_prefix_separator_exact_match_dot_at_end_1, 0);
return result;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[2/2] qpid-dispatch git commit: DISPATCH-159 - Remove the name of the
separator from the separator constant.
Posted by tr...@apache.org.
DISPATCH-159 - Remove the name of the separator from the separator constant.
Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/96affd96
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/96affd96
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/96affd96
Branch: refs/heads/master
Commit: 96affd96b2837fb7ab90eeeba6e14ca7897c4b7d
Parents: 839cc0e
Author: Ted Ross <tr...@redhat.com>
Authored: Thu Oct 1 09:44:52 2015 -0400
Committer: Ted Ross <tr...@redhat.com>
Committed: Thu Oct 1 09:44:52 2015 -0400
----------------------------------------------------------------------
src/iterator.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/96affd96/src/iterator.c
----------------------------------------------------------------------
diff --git a/src/iterator.c b/src/iterator.c
index 43efb8d..da12347 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -87,7 +87,7 @@ typedef enum {
static char *my_area = "";
static char *my_router = "";
-const char SEPARATOR_DOT = '.';
+const char SEPARATOR = '.';
const uint32_t HASH_INIT = 5381;
@@ -275,7 +275,7 @@ static void view_initialize(qd_field_iterator_t *iter)
if (iter->view == ITER_VIEW_ADDRESS_HASH) {
iter->mode = MODE_TO_END;
- qd_address_iterator_check_trailing_octet(iter, SEPARATOR_DOT);
+ qd_address_iterator_check_trailing_octet(iter, SEPARATOR);
parse_address_view(iter);
return;
}
@@ -699,7 +699,7 @@ void qd_iterator_hash_segments(qd_field_iterator_t *iter)
octet = qd_field_iterator_octet(iter);
segment_length += 1;
- if (octet == SEPARATOR_DOT) {
+ if (octet == SEPARATOR) {
qd_insert_hash_segment(iter, &hash, segment_length-1);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org