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/01/23 21:17:08 UTC

svn commit: r1654360 - in /qpid/dispatch/trunk: include/qpid/dispatch/iterator.h src/iterator.c tests/field_test.c

Author: tross
Date: Fri Jan 23 20:17:08 2015
New Revision: 1654360

URL: http://svn.apache.org/r1654360
Log:
DISPATCH-6 - Added a hash-prefix override to allow custom hash-spaces in the
             field/address iterator's address-hash view.

Modified:
    qpid/dispatch/trunk/include/qpid/dispatch/iterator.h
    qpid/dispatch/trunk/src/iterator.c
    qpid/dispatch/trunk/tests/field_test.c

Modified: qpid/dispatch/trunk/include/qpid/dispatch/iterator.h
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/include/qpid/dispatch/iterator.h?rev=1654360&r1=1654359&r2=1654360&view=diff
==============================================================================
--- qpid/dispatch/trunk/include/qpid/dispatch/iterator.h (original)
+++ qpid/dispatch/trunk/include/qpid/dispatch/iterator.h Fri Jan 23 20:17:08 2015
@@ -158,6 +158,11 @@ void qd_field_iterator_reset_view(qd_fie
 void qd_field_iterator_set_phase(qd_field_iterator_t *iter, char phase);
 
 /**
+ * Override the hash-prefix with a custom character.
+ */
+void qd_field_iterator_override_prefix(qd_field_iterator_t *iter, char prefix);
+
+/**
  * Return the current octet in the iterator's view and step to the next.
  */
 unsigned char qd_field_iterator_octet(qd_field_iterator_t *iter);

Modified: qpid/dispatch/trunk/src/iterator.c
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/iterator.c?rev=1654360&r1=1654359&r2=1654360&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/iterator.c (original)
+++ qpid/dispatch/trunk/src/iterator.c Fri Jan 23 20:17:08 2015
@@ -53,6 +53,7 @@ struct qd_field_iterator_t {
     addr_state_t        state;
     bool                view_prefix;
     unsigned char       prefix;
+    unsigned char       prefix_override;
     unsigned char       phase;
 };
 
@@ -83,7 +84,7 @@ static void parse_address_view(qd_field_
     // to aid the router in looking up addresses.
     //
 
-    if (qd_field_iterator_prefix(iter, "_")) {
+    if (iter->prefix_override == '\0' && qd_field_iterator_prefix(iter, "_")) {
         if (qd_field_iterator_prefix(iter, "local/")) {
             iter->prefix      = 'L';
             iter->state       = STATE_AT_PREFIX;
@@ -115,7 +116,7 @@ static void parse_address_view(qd_field_
         }
     }
 
-    iter->prefix      = 'M';
+    iter->prefix      = iter->prefix_override ? iter->prefix_override : 'M';
     iter->state       = STATE_AT_PREFIX;
     iter->view_prefix = true;
 }
@@ -280,6 +281,7 @@ qd_field_iterator_t* qd_field_iterator_s
     iter->start_pointer.cursor = (unsigned char*) text;
     iter->start_pointer.length = strlen(text);
     iter->phase                = '0';
+    iter->prefix_override      = '\0';
 
     qd_field_iterator_reset_view(iter, view);
 
@@ -297,6 +299,7 @@ qd_field_iterator_t* qd_field_iterator_b
     iter->start_pointer.cursor = (unsigned char*) text;
     iter->start_pointer.length = length;
     iter->phase                = '0';
+    iter->prefix_override      = '\0';
 
     qd_field_iterator_reset_view(iter, view);
 
@@ -314,6 +317,7 @@ qd_field_iterator_t *qd_field_iterator_b
     iter->start_pointer.cursor = qd_buffer_base(buffer) + offset;
     iter->start_pointer.length = length;
     iter->phase                = '0';
+    iter->prefix_override      = '\0';
 
     qd_field_iterator_reset_view(iter, view);
 
@@ -352,6 +356,13 @@ void qd_field_iterator_set_phase(qd_fiel
 }
 
 
+void qd_field_iterator_override_prefix(qd_field_iterator_t *iter, char prefix)
+{
+    iter->prefix_override = prefix;
+    qd_field_iterator_reset_view(iter, iter->view);
+}
+
+
 unsigned char qd_field_iterator_octet(qd_field_iterator_t *iter)
 {
     if (iter->state == STATE_AT_PREFIX) {
@@ -410,6 +421,7 @@ qd_field_iterator_t *qd_field_iterator_s
     sub->mode                 = iter->mode;
     sub->state                = STATE_IN_ADDRESS;
     sub->view_prefix          = false;
+    sub->prefix_override      = '\0';
     sub->phase                = '0';
 
     return sub;

Modified: qpid/dispatch/trunk/tests/field_test.c
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/field_test.c?rev=1654360&r1=1654359&r2=1654360&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/field_test.c (original)
+++ qpid/dispatch/trunk/tests/field_test.c Fri Jan 23 20:17:08 2015
@@ -139,6 +139,30 @@ static char* test_view_address_hash(void
 }
 
 
+static char* test_view_address_hash_override(void *context)
+{
+    struct {const char *addr; const char *view;} cases[] = {
+    {"amqp:/link-target",        "Clink-target"},
+    {"amqp:/domain/link-target", "Cdomain/link-target"},
+    {0, 0}
+    };
+    int idx;
+
+    for (idx = 0; cases[idx].addr; idx++) {
+        qd_field_iterator_t *iter = qd_field_iterator_string(cases[idx].addr, ITER_VIEW_ADDRESS_HASH);
+        qd_field_iterator_override_prefix(iter, 'C');
+        if (!qd_field_iterator_equal(iter, (unsigned char*) cases[idx].view)) {
+            char *got = (char*) qd_field_iterator_copy(iter);
+            snprintf(fail_text, FAIL_TEXT_SIZE, "Addr '%s' failed.  Expected '%s', got '%s'",
+                     cases[idx].addr, cases[idx].view, got);
+            return fail_text;
+        }
+    }
+
+    return 0;
+}
+
+
 static char* test_view_node_hash(void *context)
 {
     struct {const char *addr; const char *view;} cases[] = {
@@ -173,6 +197,7 @@ int field_tests(void)
     TEST_CASE(test_view_global_non_dns, 0);
     TEST_CASE(test_view_global_no_host, 0);
     TEST_CASE(test_view_address_hash, 0);
+    TEST_CASE(test_view_address_hash_override, 0);
     TEST_CASE(test_view_node_hash, 0);
 
     return result;



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