qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tr...@apache.org
Subject qpid-dispatch git commit: DISPATCH-286 - Add delimiter support for slash and backslash in hash-prefix lookups.
Date Wed, 20 Apr 2016 16:34:17 GMT
Repository: qpid-dispatch
Updated Branches:
  refs/heads/master b99acb85b -> 7eea3ff37


DISPATCH-286 - Add delimiter support for slash and backslash in hash-prefix lookups.


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/7eea3ff3
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/7eea3ff3
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/7eea3ff3

Branch: refs/heads/master
Commit: 7eea3ff37e250eefe5cc29cf69137427f310c9f7
Parents: b99acb8
Author: Ted Ross <tross@redhat.com>
Authored: Wed Apr 20 10:38:02 2016 -0400
Committer: Ted Ross <tross@redhat.com>
Committed: Wed Apr 20 12:29:45 2016 -0400

----------------------------------------------------------------------
 src/iterator.c     | 23 +++++++---------
 tests/field_test.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/7eea3ff3/src/iterator.c
----------------------------------------------------------------------
diff --git a/src/iterator.c b/src/iterator.c
index 45a3234..4af832a 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    = '.';
+const char *SEPARATORS  = "./\\";
 
 const uint32_t HASH_INIT = 5381;
 
@@ -166,24 +166,20 @@ static void parse_node_view(qd_field_iterator_t *iter)
 }
 
 
-static void qd_address_iterator_check_trailing_octet(qd_field_iterator_t *iter, char octet)
+static void qd_address_iterator_remove_trailing_separator(qd_field_iterator_t *iter)
 {
     // Save the iterator's pointer so we can apply it back before returning from this function.
     pointer_t save_pointer = iter->pointer;
 
     char current_octet = 0;
-    while(!qd_field_iterator_end(iter)) {
+    while (!qd_field_iterator_end(iter)) {
         current_octet = qd_field_iterator_octet(iter);
     }
 
     // We have the last octet in current_octet
-    if (current_octet == octet) {
-        iter->pointer = save_pointer;
-        iter->pointer.length-- ;
-    }
-    else {
-        iter->pointer = save_pointer;
-    }
+    iter->pointer = save_pointer;
+    if (current_octet && strrchr(SEPARATORS, (int) current_octet))
+        iter->pointer.length--;
 }
 
 
@@ -283,7 +279,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);
+        qd_address_iterator_remove_trailing_separator(iter);
         parse_address_view(iter);
         return;
     }
@@ -725,14 +721,15 @@ void qd_iterator_hash_segments(qd_field_iterator_t *iter)
         octet = qd_field_iterator_octet(iter);
         segment_length += 1;
 
-        if (octet == SEPARATOR) {
+        if (strrchr(SEPARATORS, (int) octet)) {
             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
+    // Segments should never end with a separator. see view_initialize which in turn calls
+    // qd_address_iterator_remove_trailing_separator
     // Insert the last segment which was not inserted in the previous while loop
     qd_insert_hash_segment(iter, &hash, segment_length);
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/7eea3ff3/tests/field_test.c
----------------------------------------------------------------------
diff --git a/tests/field_test.c b/tests/field_test.c
index d320b60..af08fd7 100644
--- a/tests/field_test.c
+++ b/tests/field_test.c
@@ -648,6 +648,77 @@ static char *test_qd_hash_retrieve_prefix_separator_exact_match_dot_at_end_1(voi
 }
 
 
+static char *test_prefix_hash(void *context)
+{
+    static char error[200];
+    char *entries[] = {"an_entry_with_no_separators",   //  0
+                       "dot.separated.pattern.one",     //  1
+                       "dot.separated.pattern.two",     //  2
+                       "dot.separated.",                //  3
+                       "dot",                           //  4
+                       "slash",                         //  5
+                       "slash/delimited",               //  6
+                       "slash/delimited/first",         //  7
+                       "slash/delimited/second",        //  8
+                       "mixed.set/of/delimiters.one",   //  9
+                       "mixed.set/of/delimiters.two",   // 10
+                       "mixed.set/of/delimiters/three", // 11
+                       "mixed.set",                     // 12
+                       "backslash\\windows",            // 13
+                       0};
+    struct { char* pattern; int entry; } patterns[] = {{"an_entry_with_no_separators", 0},
+                                                       {"dot.separated.pattern.one", 1},
+                                                       {"dot.separated.pattern.two", 2},
+                                                       {"dot.separated.pattern.three", 3},
+                                                       {"dot.separated.other.pattern", 3},
+                                                       {"dot.differentiated/other", 4},
+                                                       {"slash/other", 5},
+                                                       {"slash/delimited/first", 7},
+                                                       {"slash/delimited/second", 8},
+                                                       {"slash/delimited/third", 6},
+                                                       {"mixed.other", -1},
+                                                       {"mixed.set/other", 12},
+                                                       {"mixed.set/of/delimiters.one/queue",
9},
+                                                       {"mixed.set/of/delimiters.one.queue",
9},
+                                                       {"mixed.set.of/delimiters.one.queue",
12},
+                                                       {"other.thing.entirely", -1},
+                                                       {"backslash\\windows\\test", 13},
+                                                       {0, 0}};
+
+    qd_hash_t *hash = qd_hash(10, 32, 0);
+    long idx = 0;
+
+    //
+    // Insert the entries into the hash table
+    //
+    while (entries[idx]) {
+        qd_field_iterator_t *iter = qd_address_iterator_string(entries[idx], ITER_VIEW_ADDRESS_HASH);
+        qd_hash_insert(hash, iter, (void*) (idx + 1), 0);
+        qd_field_iterator_free(iter);
+        idx++;
+    }
+
+    //
+    // Test the patterns
+    //
+    idx = 0;
+    while (patterns[idx].pattern) {
+        qd_field_iterator_t *iter = qd_address_iterator_string(patterns[idx].pattern, ITER_VIEW_ADDRESS_HASH);
+        int position;
+        qd_hash_retrieve_prefix(hash, iter, (void*) &position);
+        position--;
+        if (position != patterns[idx].entry) {
+            snprintf(error, 200, "Pattern: '%s', expected %d, got %d",
+                     patterns[idx].pattern, patterns[idx].entry, position);
+            return error;
+        }
+        idx++;
+    }
+
+    return 0;
+}
+
+
 int field_tests(void)
 {
     int result = 0;
@@ -672,6 +743,7 @@ int field_tests(void)
     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);
+    TEST_CASE(test_prefix_hash, 0);
 
     return result;
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message