DISPATCH-990: Add c code to support tree hostname 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/e1ae8d30
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/e1ae8d30
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/e1ae8d30

Branch: refs/heads/master
Commit: e1ae8d3022d680775a5f441ea677b1498453ee15
Parents: 10ad8cf
Author: Chuck Rolke <[email protected]>
Authored: Thu May 10 15:41:21 2018 -0400
Committer: Chuck Rolke <[email protected]>
Committed: Thu May 10 15:41:21 2018 -0400

----------------------------------------------------------------------
 src/policy.c | 38 ++++++++++++++++++++++++++++++++++++++
 src/policy.h | 19 +++++++++++++++++++
 2 files changed, 57 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/e1ae8d30/src/policy.c
----------------------------------------------------------------------
diff --git a/src/policy.c b/src/policy.c
index e982077..c545f46 100644
--- a/src/policy.c
+++ b/src/policy.c
@@ -831,3 +831,41 @@ bool qd_policy_approve_link_name(const char *username,
     }
     return false;
 }
+
+
+// Add a hostname to the lookup parse_tree
+void qd_policy_host_pattern_add(qd_policy_t *policy, const char *hostPattern)
+{
+    sys_mutex_lock(policy->tree_lock);
+    void *oldp = qd_parse_tree_add_pattern_str(policy->hostname_tree, 
hostPattern, (void*)hostPattern);
+    sys_mutex_unlock(policy->tree_lock);
+    if (oldp) {
+        qd_log(policy->log_source, QD_LOG_INFO, "vhost hostname pattern '%s' 
replaced existing pattern", hostPattern);
+    }
+}
+
+
+// Remove a hostname from the lookup parse_tree
+void qd_policy_host_pattern_remove(qd_policy_t *policy, const char 
*hostPattern)
+{
+    sys_mutex_lock(policy->tree_lock);
+    void *oldp = qd_parse_tree_remove_pattern_str(policy->hostname_tree, 
hostPattern);
+    sys_mutex_unlock(policy->tree_lock);
+    if (!oldp) {
+        qd_log(policy->log_source, QD_LOG_INFO, "vhost hostname pattern '%s' 
for removal not found", hostPattern);
+    }
+}
+
+
+// Look up a hostname in the lookup parse_tree
+const char *qd_policy_host_pattern_lookup(qd_policy_t *policy, const char 
*hostPattern)
+{
+    void *payload = 0;
+    sys_mutex_lock(policy->tree_lock);
+    bool matched = qd_parse_tree_retrieve_match_str(policy->hostname_tree, 
hostPattern, &payload);
+    sys_mutex_unlock(policy->tree_lock);
+    if (!matched) payload = 0;
+    qd_log(policy->log_source, QD_LOG_TRACE, "vhost hostname pattern '%s' 
lookup returned '%s'", 
+           hostPattern, (payload ? (char *)payload : "null"));
+    return (const char *)payload;
+}

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/e1ae8d30/src/policy.h
----------------------------------------------------------------------
diff --git a/src/policy.h b/src/policy.h
index 9bddd28..66f7ac1 100644
--- a/src/policy.h
+++ b/src/policy.h
@@ -177,4 +177,23 @@ bool qd_policy_approve_link_name(const char *username,
                                   const char *proposed,
                                   bool isReceiver
                                 );
+
+/** Add a hostname to the lookup parse_tree
+ * @param[in] policy qd_policy_t
+ * @param[in] hostPattern the hostname pattern with possible parse_tree 
wildcards
+ */
+void qd_policy_host_pattern_add(qd_policy_t *policy, const char *hostPattern);
+
+/** Remove a hostname from the lookup parse_tree
+ * @param[in] policy qd_policy_t
+ * @param[in] hostPattern the hostname pattern with possible parse_tree 
wildcards
+ */
+void qd_policy_host_pattern_remove(qd_policy_t *policy, const char 
*hostPattern);
+
+/** Look up a hostname in the lookup parse_tree
+ * @param[in] policy qd_policy_t
+ * @param[in] hostname a concrete vhost name
+ * @return the name of the ruleset whose hostname pattern matched this actual 
hostname
+ */
+const char *qd_policy_host_pattern_lookup(qd_policy_t *policy, const char 
*hostPattern);
 #endif


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to