This is an automated email from the ASF dual-hosted git repository. amc pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push: new eddd3cb TCL: Remove TCL depedency from mgmt eddd3cb is described below commit eddd3cbade8042fbe47c2d931664771c0d4c3227 Author: Xavier Chi <chitianha...@gmail.com> AuthorDate: Mon Oct 15 16:17:21 2018 -0500 TCL: Remove TCL depedency from mgmt --- mgmt/BaseManager.cc | 23 ++++------- mgmt/BaseManager.h | 5 ++- mgmt/FileManager.cc | 55 ++++++++----------------- mgmt/FileManager.h | 5 ++- mgmt/WebMgmtUtils.cc | 114 --------------------------------------------------- mgmt/WebMgmtUtils.h | 7 ---- 6 files changed, 30 insertions(+), 179 deletions(-) diff --git a/mgmt/BaseManager.cc b/mgmt/BaseManager.cc index e41b09d..abd99ce 100644 --- a/mgmt/BaseManager.cc +++ b/mgmt/BaseManager.cc @@ -27,25 +27,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); @@ -73,10 +68,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; } @@ -96,7 +90,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 */ @@ -104,9 +98,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 c76a719..a254a72 100644 --- a/mgmt/BaseManager.h +++ b/mgmt/BaseManager.h @@ -26,11 +26,12 @@ #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" +#include <unordered_map> + /* * MgmtEvent defines. */ @@ -107,7 +108,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 c9e8783..fed3aeb 100644 --- a/mgmt/FileManager.cc +++ b/mgmt/FileManager.cc @@ -32,9 +32,6 @@ FileManager::FileManager() { - bindings = ink_hash_table_create(InkHashTableKeyType_String); - ink_assert(bindings != nullptr); - ink_mutex_init(&accessLock); ink_mutex_init(&cbListLock); } @@ -48,9 +45,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); @@ -58,16 +52,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); @@ -122,7 +110,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) @@ -135,15 +123,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) @@ -184,16 +170,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()) { @@ -212,9 +195,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); @@ -224,7 +206,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); @@ -249,14 +231,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; @@ -273,12 +252,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 9bd77cb..94cc7cc 100644 --- a/mgmt/FileManager.h +++ b/mgmt/FileManager.h @@ -23,10 +23,11 @@ #pragma once -#include "tscore/ink_hash_table.h" #include "tscore/ink_mutex.h" #include "tscore/List.h" +#include <unordered_map> + class ExpandingArray; class Rollback; @@ -92,7 +93,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 603fb10..474114c 100644 --- a/mgmt/WebMgmtUtils.cc +++ b/mgmt/WebMgmtUtils.cc @@ -790,120 +790,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 f34b59f..9112785 100644 --- a/mgmt/WebMgmtUtils.h +++ b/mgmt/WebMgmtUtils.h @@ -24,7 +24,6 @@ #pragma once #include "MgmtDefs.h" -#include "tscore/ink_hash_table.h" #include "records/P_RecCore.h" // class MgmtData - stores information from local manager @@ -78,12 +77,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);