You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2019/04/12 19:54:17 UTC
[trafficserver] branch 8.1.x updated: TCL: Remove TCL depedency
from mgmt
This is an automated email from the ASF dual-hosted git repository.
bcall pushed a commit to branch 8.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/8.1.x by this push:
new 074bf8e TCL: Remove TCL depedency from mgmt
074bf8e is described below
commit 074bf8e09e2c3b2636310e7413ceb8f3325b28e9
Author: Xavier Chi <ch...@gmail.com>
AuthorDate: Mon Oct 15 16:17:21 2018 -0500
TCL: Remove TCL depedency from mgmt
(cherry picked from commit eddd3cbade8042fbe47c2d931664771c0d4c3227)
Conflicts:
mgmt/BaseManager.h
mgmt/FileManager.h
mgmt/WebMgmtUtils.h
---
iocore/net/P_SSLCertLookup.h | 2 +
mgmt/BaseManager.cc | 23 +++------
mgmt/BaseManager.h | 11 +----
mgmt/FileManager.cc | 55 ++++++---------------
mgmt/FileManager.h | 16 ++----
mgmt/WebMgmtUtils.cc | 114 -------------------------------------------
mgmt/WebMgmtUtils.h | 19 --------
7 files changed, 33 insertions(+), 207 deletions(-)
diff --git a/iocore/net/P_SSLCertLookup.h b/iocore/net/P_SSLCertLookup.h
index 65d278a..c52a7fc 100644
--- a/iocore/net/P_SSLCertLookup.h
+++ b/iocore/net/P_SSLCertLookup.h
@@ -26,6 +26,8 @@
#include "ProxyConfig.h"
#include "P_SSLUtils.h"
+#include <tscore/ink_hash_table.h>
+
struct SSLConfigParams;
struct SSLContextStorage;
diff --git a/mgmt/BaseManager.cc b/mgmt/BaseManager.cc
index 2a8c030..54f46bf 100644
--- a/mgmt/BaseManager.cc
+++ b/mgmt/BaseManager.cc
@@ -39,25 +39,20 @@
BaseManager::BaseManager()
{
/* Setup the event queue and callback tables */
- mgmt_event_queue = create_queue();
- mgmt_callback_table = ink_hash_table_create(InkHashTableKeyType_Word);
+ mgmt_event_queue = create_queue();
} /* End BaseManager::BaseManager */
BaseManager::~BaseManager()
{
- InkHashTableEntry *entry;
- InkHashTableIteratorState iterator_state;
-
while (!queue_is_empty(mgmt_event_queue)) {
MgmtMessageHdr *mh = (MgmtMessageHdr *)dequeue(mgmt_event_queue);
ats_free(mh);
}
ats_free(mgmt_event_queue);
- for (entry = ink_hash_table_iterator_first(mgmt_callback_table, &iterator_state); entry != nullptr;
- entry = ink_hash_table_iterator_next(mgmt_callback_table, &iterator_state)) {
- MgmtCallbackList *tmp, *cb_list = (MgmtCallbackList *)entry;
+ for (auto &&it : mgmt_callback_table) {
+ MgmtCallbackList *tmp, *cb_list = it.second;
for (tmp = cb_list->next; tmp; tmp = cb_list->next) {
ats_free(cb_list);
@@ -85,10 +80,9 @@ int
BaseManager::registerMgmtCallback(int msg_id, MgmtCallback cb, void *opaque_cb_data)
{
MgmtCallbackList *cb_list;
- InkHashTableValue hash_value;
- if (ink_hash_table_lookup(mgmt_callback_table, (InkHashTableKey)(intptr_t)msg_id, &hash_value) != 0) {
- cb_list = (MgmtCallbackList *)hash_value;
+ if (auto it = mgmt_callback_table.find(msg_id); it != mgmt_callback_table.end()) {
+ cb_list = it->second;
} else {
cb_list = nullptr;
}
@@ -108,7 +102,7 @@ BaseManager::registerMgmtCallback(int msg_id, MgmtCallback cb, void *opaque_cb_d
cb_list->func = cb;
cb_list->opaque_data = opaque_cb_data;
cb_list->next = nullptr;
- ink_hash_table_insert(mgmt_callback_table, (InkHashTableKey)(intptr_t)msg_id, cb_list);
+ mgmt_callback_table.emplace(msg_id, cb_list);
}
return msg_id;
} /* End BaseManager::registerMgmtCallback */
@@ -116,9 +110,8 @@ BaseManager::registerMgmtCallback(int msg_id, MgmtCallback cb, void *opaque_cb_d
void
BaseManager::executeMgmtCallback(int msg_id, char *data_raw, int data_len)
{
- InkHashTableValue hash_value;
- if (ink_hash_table_lookup(mgmt_callback_table, (InkHashTableKey)(intptr_t)msg_id, &hash_value) != 0) {
- for (MgmtCallbackList *cb_list = (MgmtCallbackList *)hash_value; cb_list; cb_list = cb_list->next) {
+ if (auto it = mgmt_callback_table.find(msg_id); it != mgmt_callback_table.end()) {
+ for (MgmtCallbackList *cb_list = it->second; cb_list; cb_list = cb_list->next) {
(*((MgmtCallback)(cb_list->func)))(cb_list->opaque_data, data_raw, data_len);
}
}
diff --git a/mgmt/BaseManager.h b/mgmt/BaseManager.h
index 79bf60c..b20d997 100644
--- a/mgmt/BaseManager.h
+++ b/mgmt/BaseManager.h
@@ -36,18 +36,11 @@
#include "tscore/ink_thread.h"
#include "tscore/ink_mutex.h"
#include "tscore/ink_llqueue.h"
-#include "tscore/ink_hash_table.h"
#include "MgmtDefs.h"
#include "MgmtMarshall.h"
-/*******************************************
- * used by LocalManager and in Proxy Main. *
- */
-#define MAX_OPTION_SIZE 2048
-#define MAX_PROXY_SERVER_PORTS 2048
-#define MAX_ATTR_LEN 5
-/*******************************************/
+#include <unordered_map>
/*
* MgmtEvent defines.
@@ -124,7 +117,7 @@ public:
int registerMgmtCallback(int msg_id, MgmtCallback func, void *opaque_callback_data = nullptr);
LLQ *mgmt_event_queue;
- InkHashTable *mgmt_callback_table;
+ std::unordered_map<int, MgmtCallbackList *> mgmt_callback_table;
protected:
void executeMgmtCallback(int msg_id, char *data_raw, int data_len);
diff --git a/mgmt/FileManager.cc b/mgmt/FileManager.cc
index 90dd69a..171cfdd 100644
--- a/mgmt/FileManager.cc
+++ b/mgmt/FileManager.cc
@@ -40,9 +40,6 @@
FileManager::FileManager()
{
- bindings = ink_hash_table_create(InkHashTableKeyType_String);
- ink_assert(bindings != nullptr);
-
ink_mutex_init(&accessLock);
ink_mutex_init(&cbListLock);
}
@@ -56,9 +53,6 @@ FileManager::FileManager()
FileManager::~FileManager()
{
callbackListable *cb;
- Rollback *rb;
- InkHashTableEntry *entry;
- InkHashTableIteratorState iterator_state;
// Let other operations finish and do not start any new ones
ink_mutex_acquire(&accessLock);
@@ -66,16 +60,10 @@ FileManager::~FileManager()
for (cb = cblist.pop(); cb != nullptr; cb = cblist.pop()) {
delete cb;
}
-
- for (entry = ink_hash_table_iterator_first(bindings, &iterator_state); entry != nullptr;
- entry = ink_hash_table_iterator_next(bindings, &iterator_state)) {
- rb = (Rollback *)ink_hash_table_entry_value(bindings, entry);
-
- delete rb;
+ for (auto &&it : bindings) {
+ delete it.second;
}
- ink_hash_table_destroy(bindings);
-
ink_mutex_release(&accessLock);
ink_mutex_destroy(&accessLock);
ink_mutex_destroy(&cbListLock);
@@ -130,7 +118,7 @@ FileManager::addFileHelper(const char *fileName, const char *configName, bool ro
Rollback *rb = new Rollback(fileName, configName, root_access_needed, parentRollback, flags);
rb->configFiles = this;
- ink_hash_table_insert(bindings, fileName, rb);
+ bindings.emplace(fileName, rb);
}
// bool FileManager::getRollbackObj(char* fileName, Rollback** rbPtr)
@@ -143,15 +131,13 @@ FileManager::addFileHelper(const char *fileName, const char *configName, bool ro
bool
FileManager::getRollbackObj(const char *fileName, Rollback **rbPtr)
{
- InkHashTableValue lookup = nullptr;
- int found;
-
ink_mutex_acquire(&accessLock);
- found = ink_hash_table_lookup(bindings, fileName, &lookup);
+ auto it = bindings.find(fileName);
+ bool found = it != bindings.end();
ink_mutex_release(&accessLock);
- *rbPtr = (Rollback *)lookup;
- return (found == 0) ? false : true;
+ *rbPtr = found ? it->second : nullptr;
+ return found;
}
// bool FileManager::fileChanged(const char* fileName)
@@ -192,16 +178,13 @@ void
FileManager::rereadConfig()
{
Rollback *rb;
- InkHashTableEntry *entry;
- InkHashTableIteratorState iterator_state;
std::vector<Rollback *> changedFiles;
std::vector<Rollback *> parentFileNeedChange;
size_t n;
ink_mutex_acquire(&accessLock);
- for (entry = ink_hash_table_iterator_first(bindings, &iterator_state); entry != nullptr;
- entry = ink_hash_table_iterator_next(bindings, &iterator_state)) {
- rb = (Rollback *)ink_hash_table_entry_value(bindings, entry);
+ for (auto &&it : bindings) {
+ rb = it.second;
if (rb->checkForUserUpdate(rb->isVersioned() ? ROLLBACK_CHECK_AND_UPDATE : ROLLBACK_CHECK_ONLY)) {
changedFiles.push_back(rb);
if (rb->isChildRollback()) {
@@ -220,9 +203,8 @@ FileManager::rereadConfig()
continue;
}
// for each parent file, if it is changed, then delete all its children
- for (entry = ink_hash_table_iterator_first(bindings, &iterator_state); entry != nullptr;
- entry = ink_hash_table_iterator_next(bindings, &iterator_state)) {
- rb = (Rollback *)ink_hash_table_entry_value(bindings, entry);
+ for (auto &&it : bindings) {
+ rb = it.second;
if (rb->getParentRollback() == changedFiles[i]) {
if (std::find(childFileNeedDelete.begin(), childFileNeedDelete.end(), rb) == childFileNeedDelete.end()) {
childFileNeedDelete.push_back(rb);
@@ -232,7 +214,7 @@ FileManager::rereadConfig()
}
n = childFileNeedDelete.size();
for (size_t i = 0; i < n; i++) {
- ink_hash_table_delete(bindings, childFileNeedDelete[i]->getFileName());
+ bindings.erase(childFileNeedDelete[i]->getFileName());
delete childFileNeedDelete[i];
}
ink_mutex_release(&accessLock);
@@ -257,14 +239,11 @@ bool
FileManager::isConfigStale()
{
Rollback *rb;
- InkHashTableEntry *entry;
- InkHashTableIteratorState iterator_state;
bool stale = false;
ink_mutex_acquire(&accessLock);
- for (entry = ink_hash_table_iterator_first(bindings, &iterator_state); entry != nullptr;
- entry = ink_hash_table_iterator_next(bindings, &iterator_state)) {
- rb = (Rollback *)ink_hash_table_entry_value(bindings, entry);
+ for (auto &&it : bindings) {
+ rb = it.second;
if (rb->checkForUserUpdate(ROLLBACK_CHECK_ONLY)) {
stale = true;
break;
@@ -281,12 +260,10 @@ FileManager::isConfigStale()
void
FileManager::configFileChild(const char *parent, const char *child, unsigned flags)
{
- InkHashTableValue lookup;
Rollback *parentRollback = nullptr;
ink_mutex_acquire(&accessLock);
- int htfound = ink_hash_table_lookup(bindings, parent, &lookup);
- if (htfound) {
- parentRollback = (Rollback *)lookup;
+ if (auto it = bindings.find(parent); it != bindings.end()) {
+ parentRollback = it->second;
addFileHelper(child, "", parentRollback->rootAccessNeeded(), parentRollback, flags);
}
ink_mutex_release(&accessLock);
diff --git a/mgmt/FileManager.h b/mgmt/FileManager.h
index b8784ba..7d118d4 100644
--- a/mgmt/FileManager.h
+++ b/mgmt/FileManager.h
@@ -23,19 +23,13 @@
#pragma once
-/****************************************************************************
- *
- * FileManager.h - Interface for class to manage configuration updates
- *
- *
- ****************************************************************************/
-
-#include <cstdio>
-
-#include "tscore/ink_hash_table.h"
+#include "tscore/ink_mutex.h"
#include "tscore/List.h"
#include "Rollback.h"
+#include <unordered_map>
+
+class ExpandingArray;
class Rollback;
typedef void (*FileCallbackFunc)(char *, char *, bool);
@@ -101,7 +95,7 @@ private:
ink_mutex accessLock; // Protects bindings hashtable
ink_mutex cbListLock; // Protects the CallBack List
DLL<callbackListable> cblist;
- InkHashTable *bindings;
+ std::unordered_map<std::string_view, Rollback *> bindings;
void addFileHelper(const char *fileName, const char *configName, bool root_access_needed, Rollback *parentRollback,
unsigned flags = 0);
};
diff --git a/mgmt/WebMgmtUtils.cc b/mgmt/WebMgmtUtils.cc
index 9784eb5..d892e16 100644
--- a/mgmt/WebMgmtUtils.cc
+++ b/mgmt/WebMgmtUtils.cc
@@ -801,120 +801,6 @@ varType(const char *varName)
return data_type;
}
-// InkHashTable* processFormSubmission(char* submission)
-//
-// A generic way to handle a HTML form submission.
-// Creates a hash table with name value pairs
-//
-// CALLEE must deallocate the returned hash table with
-// ink_hash_table_destroy_and_free_values(InkHashTable *ht_ptr)
-//
-
-InkHashTable *
-processFormSubmission(char *submission)
-{
- InkHashTable *nameVal = ink_hash_table_create(InkHashTableKeyType_String);
- Tokenizer updates("&\n\r");
- Tokenizer pair("=");
- int numUpdates;
- char *name;
- char *value;
- char *submission_copy;
- int pairNum;
-
- if (submission == nullptr) {
- ink_hash_table_destroy(nameVal);
- return nullptr;
- }
-
- submission_copy = ats_strdup(submission);
- numUpdates = updates.Initialize(submission_copy, SHARE_TOKS);
-
- for (int i = 0; i < numUpdates; i++) {
- pairNum = pair.Initialize(updates[i]);
-
- // We should have gotten either either 1 or 2 tokens
- // One token indicates an variable being set to
- // blank. Two indicates the variable being set to
- // a value. If the submission is invalid, just forget
- // about it.
- if (pairNum == 1 || pairNum == 2) {
- name = ats_strdup(pair[0]);
- substituteUnsafeChars(name);
-
- // If the value is blank, store it as a null
- if (pairNum == 1) {
- value = nullptr;
- } else {
- value = ats_strdup(pair[1]);
- substituteUnsafeChars(value);
- }
-
- ink_hash_table_insert(nameVal, name, value);
- ats_free(name);
- }
- }
- ats_free(submission_copy);
-
- return nameVal;
-}
-
-// InkHashTable* processFormSubmission_noSubstitute(char* submission)
-//
-// A generic way to handle a HTML form submission.
-// Creates a hash table with name value pairs
-//
-// CALLEE must deallocate the returned hash table with
-// ink_hash_table_destroy_and_free_values(InkHashTable *ht_ptr)
-//
-// Note: This function will _not_ substituteUnsafeChars()
-InkHashTable *
-processFormSubmission_noSubstitute(char *submission)
-{
- InkHashTable *nameVal = ink_hash_table_create(InkHashTableKeyType_String);
- Tokenizer updates("&\n\r");
- Tokenizer pair("=");
- int numUpdates;
- char *name;
- char *value;
- char *submission_copy;
- int pairNum;
-
- if (submission == nullptr) {
- ink_hash_table_destroy(nameVal);
- return nullptr;
- }
-
- submission_copy = ats_strdup(submission);
- numUpdates = updates.Initialize(submission_copy, SHARE_TOKS);
-
- for (int i = 0; i < numUpdates; i++) {
- pairNum = pair.Initialize(updates[i]);
-
- // We should have gotten either either 1 or 2 tokens
- // One token indicates an variable being set to
- // blank. Two indicates the variable being set to
- // a value. If the submission is invalid, just forget
- // about it.
- if (pairNum == 1 || pairNum == 2) {
- name = ats_strdup(pair[0]);
-
- // If the value is blank, store it as a null
- if (pairNum == 1) {
- value = nullptr;
- } else {
- value = ats_strdup(pair[1]);
- }
-
- ink_hash_table_insert(nameVal, name, value);
- ats_free(name);
- }
- }
- ats_free(submission_copy);
-
- return nameVal;
-}
-
//
// Removes any cr/lf line breaks from the text data
//
diff --git a/mgmt/WebMgmtUtils.h b/mgmt/WebMgmtUtils.h
index 517c6aa..f18a6fe 100644
--- a/mgmt/WebMgmtUtils.h
+++ b/mgmt/WebMgmtUtils.h
@@ -25,19 +25,6 @@
#define _WEB_MGMT_UTILS_
#include "MgmtDefs.h"
-
-/****************************************************************************
- *
- * WebMgmtUtils.h - Functions for interfacing to management records
- *
- *
- *
- ****************************************************************************/
-
-#include "tscore/ink_hash_table.h"
-#include "tscore/TextBuffer.h"
-#include "ExpandingArray.h"
-
#include "records/P_RecCore.h"
// class MgmtData - stores information from local manager
@@ -92,12 +79,6 @@ int convertHtmlToUnix(char *buffer);
int substituteUnsafeChars(char *buffer);
char *substituteForHTMLChars(const char *buffer);
-// Produce a hash table based on a HTML form submission
-//
-// CALLEE deallocates hashtable
-InkHashTable *processFormSubmission(char *submission);
-InkHashTable *processFormSubmission_noSubstitute(char *submission);
-
int setHostnameVar();
void appendDefaultDomain(char *hostname, int bufLength);