This is an automated email from the ASF dual-hosted git repository.
cmcfarlen 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 1ecdebb4d4 Move APIHook classes to tsapicore (#10148)
1ecdebb4d4 is described below
commit 1ecdebb4d45490cc8c7c4a9f654b024803ea2d90
Author: JosiahWI <[email protected]>
AuthorDate: Wed Oct 11 09:32:00 2023 -0500
Move APIHook classes to tsapicore (#10148)
* Move APIHook classes to tsapi
This moves APIHook, APIHooks, and FeatureAPIHooks to tsapi. It also
moves the global ssl hooks to inknet, and the global http tooks to
proxy. This removes the definitions of all those classes from the
various stubs (in inknet, inkcache, and http_remap).
* Clean up after rebase
* Stub the tsapi C interface used by FetchSM
* Add missing inkdns dep to inkhostdb
* Add missing deps to inknet and proxy
* Move lifecycle_hooks to g_lifecycle_hooks
* Fix logcat dependencies
---
include/api/APIHook.h | 45 +++++
include/api/APIHooks.h | 52 ++++++
include/api/FeatureAPIHooks.h | 154 ++++++++++++++++
include/api/InkAPIInternal.h | 212 +---------------------
include/api/LifecycleAPIHooks.h | 35 ++++
iocore/cache/CMakeLists.txt | 2 +
iocore/cache/test/main.cc | 6 +
iocore/cache/test/stub.cc | 91 +++-------
iocore/hostdb/CMakeLists.txt | 1 +
iocore/net/CMakeLists.txt | 2 +
iocore/net/Makefile.am | 2 +
iocore/net/Net.cc | 2 +
iocore/net/SSLAPIHooks.cc | 32 ++++
iocore/net/SSLAPIHooks.h | 60 ++++++
iocore/net/SSLNetVConnection.cc | 19 +-
iocore/net/SSLSecret.cc | 5 +-
iocore/net/SSLUtils.cc | 5 +-
iocore/net/TLSSessionResumptionSupport.cc | 3 +-
iocore/net/libinknet_stub.cc | 37 ----
iocore/net/unit_tests/unit_test_main.cc | 2 +
mgmt/rpc/CMakeLists.txt | 1 +
mgmt/rpc/handlers/plugins/Plugins.cc | 6 +-
proxy/CMakeLists.txt | 5 +-
proxy/HttpAPIHooks.cc | 32 ++++
proxy/HttpAPIHooks.h | 37 ++++
proxy/Makefile.am | 2 +
proxy/http/CMakeLists.txt | 3 +
proxy/http/HttpProxyServerMain.cc | 3 +-
proxy/http/remap/CMakeLists.txt | 5 +-
proxy/http/remap/unit-tests/nexthop_test_stubs.cc | 4 -
src/api/APIHook.cc | 76 ++++++++
src/api/APIHooks.cc | 58 ++++++
src/api/CMakeLists.txt | 3 +
src/api/InkAPI.cc | 83 +--------
src/api/LifecycleAPIHooks.cc | 32 ++++
src/api/Makefile.am | 14 +-
src/tests/CMakeLists.txt | 3 +-
src/traffic_logcat/CMakeLists.txt | 18 +-
src/traffic_server/traffic_server.cc | 11 +-
39 files changed, 744 insertions(+), 419 deletions(-)
diff --git a/include/api/APIHook.h b/include/api/APIHook.h
new file mode 100644
index 0000000000..caec587892
--- /dev/null
+++ b/include/api/APIHook.h
@@ -0,0 +1,45 @@
+/** @file
+
+ Internal SDK stuff
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#pragma once
+
+#include "ts/InkAPIPrivateIOCore.h"
+
+#include "tscore/List.h"
+
+/// A single API hook that can be invoked.
+class APIHook
+{
+public:
+ INKContInternal *m_cont;
+ int invoke(int event, void *edata) const;
+ APIHook *next() const;
+ APIHook *prev() const;
+ LINK(APIHook, m_link);
+
+ // This is like invoke(), but allows for blocking on continuation mutexes.
It is a hack, calling it can block
+ // the calling thread. Hooks that require this should be reimplemented,
modeled on the hook handling in HttpSM.cc .
+ // That is, try to lock the mutex, and reschedule the continuation if the
mutex cannot be locked.
+ //
+ int blocking_invoke(int event, void *edata) const;
+};
diff --git a/include/api/APIHooks.h b/include/api/APIHooks.h
new file mode 100644
index 0000000000..e1e379769e
--- /dev/null
+++ b/include/api/APIHooks.h
@@ -0,0 +1,52 @@
+/** @file
+
+ Internal SDK stuff
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#pragma once
+
+#include "APIHook.h"
+
+#include "ts/InkAPIPrivateIOCore.h"
+
+#include "tscore/List.h"
+
+/// A collection of API hooks.
+class APIHooks
+{
+public:
+ void append(INKContInternal *cont);
+ /// Get the first hook.
+ APIHook *head() const;
+ /// Remove all hooks.
+ void clear();
+ /// Check if there are no hooks.
+ bool is_empty() const;
+
+private:
+ Que(APIHook, m_link) m_hooks;
+};
+
+inline bool
+APIHooks::is_empty() const
+{
+ return nullptr == m_hooks.head;
+}
diff --git a/include/api/FeatureAPIHooks.h b/include/api/FeatureAPIHooks.h
new file mode 100644
index 0000000000..1d62cfc7c6
--- /dev/null
+++ b/include/api/FeatureAPIHooks.h
@@ -0,0 +1,154 @@
+/** @file
+
+ Internal SDK stuff
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#pragma once
+
+#include "APIHook.h"
+#include "APIHooks.h"
+
+#include "ts/InkAPIPrivateIOCore.h"
+
+#include "tscore/ink_apidefs.h"
+
+/** Container for API hooks for a specific feature.
+
+ This is an array of hook lists, each identified by a numeric identifier
(id). Each array element is a list of all
+ hooks for that ID. Adding a hook means adding to the list in the
corresponding array element. There is no provision
+ for removing a hook.
+
+ @note The minimum value for a hook ID is zero. Therefore the template
parameter @a N_ID should be one more than the
+ maximum hook ID so the valid ids are 0..(N-1) in the standard C array
style.
+ */
+template <typename ID, ///< Type of hook ID
+ int N ///< Number of hooks
+ >
+class FeatureAPIHooks
+{
+public:
+ FeatureAPIHooks(); ///< Constructor (empty container).
+ ~FeatureAPIHooks(); ///< Destructor.
+
+ /// Remove all hooks.
+ void clear();
+ /// Add the hook @a cont to the end of the hooks for @a id.
+ void append(ID id, INKContInternal *cont);
+ /// Get the list of hooks for @a id.
+ APIHook *get(ID id) const;
+ /// @return @c true if @a id is a valid id, @c false otherwise.
+ static bool is_valid(ID id);
+
+ /// Invoke the callbacks for the hook @a id.
+ void invoke(ID id, int event, void *data);
+
+ /// Fast check for any hooks in this container.
+ ///
+ /// @return @c true if any list has at least one hook, @c false if
+ /// all lists have no hooks.
+ bool has_hooks() const;
+
+ /// Check for existence of hooks of a specific @a id.
+ /// @return @c true if any hooks of type @a id are present.
+ bool has_hooks_for(ID id) const;
+
+ /// Get a pointer to the set of hooks for a specific hook @id
+ APIHooks const *operator[](ID id) const;
+
+private:
+ bool m_hooks_p = false; ///< Flag for (not) empty container.
+ /// The array of hooks lists.
+ APIHooks m_hooks[N];
+};
+
+template <typename ID, int N> FeatureAPIHooks<ID, N>::FeatureAPIHooks() {}
+
+template <typename ID, int N> FeatureAPIHooks<ID, N>::~FeatureAPIHooks()
+{
+ this->clear();
+}
+
+// The APIHooks::clear() method can't be inlined (easily), and we end up
calling
+// clear() very frequently (it's used in a number of features). A rough
estimate
+// is that we may call APIHooks::clear() as much as 230x per transaction
(there's
+// 180 additional APIHooks that should be eliminated in a different PR). This
+// code at least avoids calling this function for a majority of the cases.
+// Before this code, APIHooks::clear() would show up as top 5 in perf top.
+template <typename ID, int N>
+void
+FeatureAPIHooks<ID, N>::clear()
+{
+ if (m_hooks_p) {
+ for (auto &h : m_hooks) {
+ if (!h.is_empty()) {
+ h.clear();
+ }
+ }
+ m_hooks_p = false;
+ }
+}
+
+template <typename ID, int N>
+void
+FeatureAPIHooks<ID, N>::append(ID id, INKContInternal *cont)
+{
+ if (is_valid(id)) {
+ m_hooks_p = true;
+ m_hooks[id].append(cont);
+ }
+}
+
+template <typename ID, int N>
+APIHook *
+FeatureAPIHooks<ID, N>::get(ID id) const
+{
+ return likely(is_valid(id)) ? m_hooks[id].head() : nullptr;
+}
+
+template <typename ID, int N>
+APIHooks const *
+FeatureAPIHooks<ID, N>::operator[](ID id) const
+{
+ return likely(is_valid(id)) ? &(m_hooks[id]) : nullptr;
+}
+
+template <typename ID, int N>
+void
+FeatureAPIHooks<ID, N>::invoke(ID id, int event, void *data)
+{
+ if (likely(is_valid(id))) {
+ m_hooks[id].invoke(event, data);
+ }
+}
+
+template <typename ID, int N>
+bool
+FeatureAPIHooks<ID, N>::has_hooks() const
+{
+ return m_hooks_p;
+}
+
+template <typename ID, int N>
+bool
+FeatureAPIHooks<ID, N>::is_valid(ID id)
+{
+ return 0 <= id && id < N;
+}
diff --git a/include/api/InkAPIInternal.h b/include/api/InkAPIInternal.h
index 6b47bd8d13..4d2f31695d 100644
--- a/include/api/InkAPIInternal.h
+++ b/include/api/InkAPIInternal.h
@@ -33,6 +33,10 @@
#include "I_Tasks.h"
#include "Plugin.h"
+#include "api/APIHook.h"
+#include "api/APIHooks.h"
+#include "api/FeatureAPIHooks.h"
+
#include "ts/InkAPIPrivateIOCore.h"
#include "ts/experimental.h"
@@ -102,209 +106,6 @@ struct HttpAltInfo {
float m_qvalue;
};
-enum APIHookScope {
- API_HOOK_SCOPE_NONE,
- API_HOOK_SCOPE_GLOBAL,
- API_HOOK_SCOPE_LOCAL,
-};
-
-/// A single API hook that can be invoked.
-class APIHook
-{
-public:
- INKContInternal *m_cont;
- int invoke(int event, void *edata) const;
- APIHook *next() const;
- APIHook *prev() const;
- LINK(APIHook, m_link);
-
- // This is like invoke(), but allows for blocking on continuation mutexes.
It is a hack, calling it can block
- // the calling thread. Hooks that require this should be reimplemented,
modeled on the hook handling in HttpSM.cc .
- // That is, try to lock the mutex, and reschedule the continuation if the
mutex cannot be locked.
- //
- int blocking_invoke(int event, void *edata) const;
-};
-
-/// A collection of API hooks.
-class APIHooks
-{
-public:
- void append(INKContInternal *cont);
- /// Get the first hook.
- APIHook *head() const;
- /// Remove all hooks.
- void clear();
- /// Check if there are no hooks.
- bool is_empty() const;
-
-private:
- Que(APIHook, m_link) m_hooks;
-};
-
-inline bool
-APIHooks::is_empty() const
-{
- return nullptr == m_hooks.head;
-}
-
-/** Container for API hooks for a specific feature.
-
- This is an array of hook lists, each identified by a numeric identifier
(id). Each array element is a list of all
- hooks for that ID. Adding a hook means adding to the list in the
corresponding array element. There is no provision
- for removing a hook.
-
- @note The minimum value for a hook ID is zero. Therefore the template
parameter @a N_ID should be one more than the
- maximum hook ID so the valid ids are 0..(N-1) in the standard C array
style.
- */
-template <typename ID, ///< Type of hook ID
- int N ///< Number of hooks
- >
-class FeatureAPIHooks
-{
-public:
- FeatureAPIHooks(); ///< Constructor (empty container).
- ~FeatureAPIHooks(); ///< Destructor.
-
- /// Remove all hooks.
- void clear();
- /// Add the hook @a cont to the end of the hooks for @a id.
- void append(ID id, INKContInternal *cont);
- /// Get the list of hooks for @a id.
- APIHook *get(ID id) const;
- /// @return @c true if @a id is a valid id, @c false otherwise.
- static bool is_valid(ID id);
-
- /// Invoke the callbacks for the hook @a id.
- void invoke(ID id, int event, void *data);
-
- /// Fast check for any hooks in this container.
- ///
- /// @return @c true if any list has at least one hook, @c false if
- /// all lists have no hooks.
- bool has_hooks() const;
-
- /// Check for existence of hooks of a specific @a id.
- /// @return @c true if any hooks of type @a id are present.
- bool has_hooks_for(ID id) const;
-
- /// Get a pointer to the set of hooks for a specific hook @id
- APIHooks const *operator[](ID id) const;
-
-private:
- bool m_hooks_p = false; ///< Flag for (not) empty container.
- /// The array of hooks lists.
- APIHooks m_hooks[N];
-};
-
-template <typename ID, int N> FeatureAPIHooks<ID, N>::FeatureAPIHooks() {}
-
-template <typename ID, int N> FeatureAPIHooks<ID, N>::~FeatureAPIHooks()
-{
- this->clear();
-}
-
-// The APIHooks::clear() method can't be inlined (easily), and we end up
calling
-// clear() very frequently (it's used in a number of features). A rough
estimate
-// is that we may call APIHooks::clear() as much as 230x per transaction
(there's
-// 180 additional APIHooks that should be eliminated in a different PR). This
-// code at least avoids calling this function for a majority of the cases.
-// Before this code, APIHooks::clear() would show up as top 5 in perf top.
-template <typename ID, int N>
-void
-FeatureAPIHooks<ID, N>::clear()
-{
- if (m_hooks_p) {
- for (auto &h : m_hooks) {
- if (!h.is_empty()) {
- h.clear();
- }
- }
- m_hooks_p = false;
- }
-}
-
-template <typename ID, int N>
-void
-FeatureAPIHooks<ID, N>::append(ID id, INKContInternal *cont)
-{
- if (is_valid(id)) {
- m_hooks_p = true;
- m_hooks[id].append(cont);
- }
-}
-
-template <typename ID, int N>
-APIHook *
-FeatureAPIHooks<ID, N>::get(ID id) const
-{
- return likely(is_valid(id)) ? m_hooks[id].head() : nullptr;
-}
-
-template <typename ID, int N>
-APIHooks const *
-FeatureAPIHooks<ID, N>::operator[](ID id) const
-{
- return likely(is_valid(id)) ? &(m_hooks[id]) : nullptr;
-}
-
-template <typename ID, int N>
-void
-FeatureAPIHooks<ID, N>::invoke(ID id, int event, void *data)
-{
- if (likely(is_valid(id))) {
- m_hooks[id].invoke(event, data);
- }
-}
-
-template <typename ID, int N>
-bool
-FeatureAPIHooks<ID, N>::has_hooks() const
-{
- return m_hooks_p;
-}
-
-template <typename ID, int N>
-bool
-FeatureAPIHooks<ID, N>::is_valid(ID id)
-{
- return 0 <= id && id < N;
-}
-
-class HttpAPIHooks : public FeatureAPIHooks<TSHttpHookID, TS_HTTP_LAST_HOOK>
-{
-};
-
-class TSSslHookInternalID
-{
-public:
- explicit constexpr TSSslHookInternalID(TSHttpHookID id) : _id(id -
TS_SSL_FIRST_HOOK) {}
-
- constexpr
- operator int() const
- {
- return _id;
- }
-
- static const int NUM = TS_SSL_LAST_HOOK - TS_SSL_FIRST_HOOK + 1;
-
- constexpr bool
- is_in_bounds() const
- {
- return (_id >= 0) && (_id < NUM);
- }
-
-private:
- const int _id;
-};
-
-class SslAPIHooks : public FeatureAPIHooks<TSSslHookInternalID,
TSSslHookInternalID::NUM>
-{
-};
-
-class LifecycleAPIHooks : public FeatureAPIHooks<TSLifecycleHookID,
TS_LIFECYCLE_LAST_HOOK>
-{
-};
-
class ConfigUpdateCallback : public Continuation
{
public:
@@ -350,6 +151,8 @@ private:
std::unordered_map<std::string, INKContInternal *> cb_table;
};
+#include "HttpAPIHooks.h"
+
class HttpHookState
{
public:
@@ -403,7 +206,4 @@ HttpHookState::id() const
void api_init();
-extern HttpAPIHooks *http_global_hooks;
-extern LifecycleAPIHooks *lifecycle_hooks;
-extern SslAPIHooks *ssl_hooks;
extern ConfigUpdateCbTable *global_config_cbs;
diff --git a/include/api/LifecycleAPIHooks.h b/include/api/LifecycleAPIHooks.h
new file mode 100644
index 0000000000..50178be8a7
--- /dev/null
+++ b/include/api/LifecycleAPIHooks.h
@@ -0,0 +1,35 @@
+/** @file
+
+ Internal SDK stuff
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#include "FeatureAPIHooks.h"
+
+#include "ts/apidefs.h"
+
+class LifecycleAPIHooks : public FeatureAPIHooks<TSLifecycleHookID,
TS_LIFECYCLE_LAST_HOOK>
+{
+};
+
+// there is no corresponding deinit; we leak the resource on shutdown
+void init_global_lifecycle_hooks();
+
+extern LifecycleAPIHooks *g_lifecycle_hooks;
diff --git a/iocore/cache/CMakeLists.txt b/iocore/cache/CMakeLists.txt
index 8065146b12..c283b90ff6 100644
--- a/iocore/cache/CMakeLists.txt
+++ b/iocore/cache/CMakeLists.txt
@@ -55,6 +55,8 @@ target_include_directories(inkcache
target_link_libraries(inkcache
PUBLIC
ts::aio
+ ts::hdrs
+ ts::http
ts::inkevent
ts::tscore
PRIVATE
diff --git a/iocore/cache/test/main.cc b/iocore/cache/test/main.cc
index 58e1ccffac..cf8c70d168 100644
--- a/iocore/cache/test/main.cc
+++ b/iocore/cache/test/main.cc
@@ -23,6 +23,9 @@
#include "tscore/ink_config.h"
#include <string_view>
+#include "HttpAPIHooks.h"
+#include "SSLAPIHooks.h"
+
#define CATCH_CONFIG_MAIN
#include "main.h"
@@ -137,6 +140,9 @@ struct EventProcessorListener :
Catch::TestEventListenerBase {
ink_net_init(ts::ModuleVersion(1, 0, ts::ModuleVersion::PRIVATE));
ink_assert(GLOBAL_DATA != nullptr);
+ init_global_http_hooks();
+ init_global_ssl_hooks();
+
statPagesManager.init(); // mutex needs to be initialized before calling
netProcessor.init
netProcessor.init();
eventProcessor.start(THREADS);
diff --git a/iocore/cache/test/stub.cc b/iocore/cache/test/stub.cc
index eee82395e4..a0c00ff8a8 100644
--- a/iocore/cache/test/stub.cc
+++ b/iocore/cache/test/stub.cc
@@ -21,47 +21,15 @@
limitations under the License.
*/
-#include "tscore/I_Version.h"
-
-AppVersionInfo appVersionInfo;
+#include "SSLAPIHooks.h"
#include "api/InkAPIInternal.h"
-void
-APIHooks::append(INKContInternal *cont)
-{
-}
-
-int
-APIHook::invoke(int, void *) const
-{
- ink_assert(false);
- return 0;
-}
-
-int
-APIHook::blocking_invoke(int, void *) const
-{
- ink_assert(false);
- return 0;
-}
-APIHook *
-APIHook::next() const
-{
- ink_assert(false);
- return nullptr;
-}
+#include "HttpAPIHooks.h"
-APIHook *
-APIHooks::head() const
-{
- return nullptr;
-}
+#include "tscore/I_Version.h"
-void
-APIHooks::clear()
-{
-}
+AppVersionInfo appVersionInfo;
void
HttpHookState::init(TSHttpHookID id, HttpAPIHooks const *global, HttpAPIHooks
const *ssn, HttpAPIHooks const *txn)
@@ -79,44 +47,37 @@ HttpHookState::getNext()
return nullptr;
}
-HttpAPIHooks *http_global_hooks = nullptr;
-SslAPIHooks *ssl_hooks = nullptr;
-LifecycleAPIHooks *lifecycle_hooks = nullptr;
-ConfigUpdateCbTable *global_config_cbs = nullptr;
-
-#include "api/FetchSM.h"
-ClassAllocator<FetchSM> FetchSMAllocator("unusedFetchSMAllocator");
-void
-FetchSM::ext_launch()
-{
-}
-void
-FetchSM::ext_destroy()
-{
-}
-ssize_t
-FetchSM::ext_read_data(char *, unsigned long)
+namespace tsapi::c
{
- return 0;
-}
-void
-FetchSM::ext_add_header(char const *, int, char const *, int)
+TSVConn
+TSHttpConnectWithPluginId(sockaddr const *addr, const char *tag, int64_t id)
{
+ return TSVConn{};
}
-void
-FetchSM::ext_write_data(void const *, unsigned long)
+
+int TS_MIME_LEN_CONTENT_LENGTH = 0;
+const char *TS_MIME_FIELD_CONTENT_LENGTH = "";
+
+TSIOBufferBlock
+TSIOBufferReaderStart(TSIOBufferReader readerp)
{
+ return TSIOBufferBlock{};
}
-void *
-FetchSM::ext_get_user_data()
+
+TSIOBufferBlock
+TSIOBufferBlockNext(TSIOBufferBlock blockp)
{
- return nullptr;
+ return TSIOBufferBlock{};
}
-void
-FetchSM::ext_set_user_data(void *)
+
+const char *
+TSIOBufferBlockReadStart(TSIOBufferBlock blockp, TSIOBufferReader readerp,
int64_t *avail)
{
+ return "";
}
+
void
-FetchSM::ext_init(Continuation *, char const *, char const *, char const *,
sockaddr const *, int)
+TSIOBufferReaderConsume(TSIOBufferReader readerp, int64_t nbytes)
{
}
+} // namespace tsapi::c
diff --git a/iocore/hostdb/CMakeLists.txt b/iocore/hostdb/CMakeLists.txt
index 6597637b52..678ebfc852 100644
--- a/iocore/hostdb/CMakeLists.txt
+++ b/iocore/hostdb/CMakeLists.txt
@@ -39,6 +39,7 @@ target_include_directories(inkhostdb
target_link_libraries(inkhostdb
PUBLIC
ts::inkcache
+ ts::inkdns
ts::inkevent
ts::tscore
PRIVATE
diff --git a/iocore/net/CMakeLists.txt b/iocore/net/CMakeLists.txt
index 7ca11f85d9..893ac0988d 100644
--- a/iocore/net/CMakeLists.txt
+++ b/iocore/net/CMakeLists.txt
@@ -35,6 +35,7 @@ add_library(inknet STATIC
ProxyProtocol.cc
ReadWriteEventIO.cc
Socks.cc
+ SSLAPIHooks.cc
SSLCertLookup.cc
SSLClientCoordinator.cc
SSLClientUtils.cc
@@ -126,6 +127,7 @@ target_link_libraries(inknet
OpenSSL::Crypto
OpenSSL::SSL
PRIVATE
+ ts::tsapicore
yaml-cpp::yaml-cpp
)
diff --git a/iocore/net/Makefile.am b/iocore/net/Makefile.am
index e9ec2270d9..ae46160436 100644
--- a/iocore/net/Makefile.am
+++ b/iocore/net/Makefile.am
@@ -208,6 +208,8 @@ libinknet_a_SOURCES = \
ReadWriteEventIO.h \
ReadWriteEventIO.cc \
Socks.cc \
+ SSLAPIHooks.h \
+ SSLAPIHooks.cc \
SSLCertLookup.cc \
SSLClientCoordinator.cc \
SSLClientUtils.cc \
diff --git a/iocore/net/Net.cc b/iocore/net/Net.cc
index 0550566e5c..05438e5dd2 100644
--- a/iocore/net/Net.cc
+++ b/iocore/net/Net.cc
@@ -28,6 +28,7 @@
************************************************************************/
+#include "SSLAPIHooks.h"
#include "P_Net.h"
#include <utility>
@@ -120,6 +121,7 @@ ink_net_init(ts::ModuleVersion version)
if (!init_called) {
configure_net();
register_net_stats();
+ init_global_ssl_hooks();
}
init_called = 1;
diff --git a/iocore/net/SSLAPIHooks.cc b/iocore/net/SSLAPIHooks.cc
new file mode 100644
index 0000000000..0dc718b881
--- /dev/null
+++ b/iocore/net/SSLAPIHooks.cc
@@ -0,0 +1,32 @@
+/** @file
+
+ Internal SDK stuff
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#include "SSLAPIHooks.h"
+
+SSLAPIHooks *g_ssl_hooks = nullptr;
+
+void
+init_global_ssl_hooks()
+{
+ g_ssl_hooks = new SSLAPIHooks;
+}
diff --git a/iocore/net/SSLAPIHooks.h b/iocore/net/SSLAPIHooks.h
new file mode 100644
index 0000000000..4c4bbe76f1
--- /dev/null
+++ b/iocore/net/SSLAPIHooks.h
@@ -0,0 +1,60 @@
+/** @file
+
+ Internal SDK stuff
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#pragma once
+
+#include "api/FeatureAPIHooks.h"
+
+#include "ts/apidefs.h"
+
+class TSSslHookInternalID
+{
+public:
+ explicit constexpr TSSslHookInternalID(TSHttpHookID id) : _id(id -
TS_SSL_FIRST_HOOK) {}
+
+ constexpr
+ operator int() const
+ {
+ return _id;
+ }
+
+ static const int NUM = TS_SSL_LAST_HOOK - TS_SSL_FIRST_HOOK + 1;
+
+ constexpr bool
+ is_in_bounds() const
+ {
+ return (_id >= 0) && (_id < NUM);
+ }
+
+private:
+ const int _id;
+};
+
+class SSLAPIHooks : public FeatureAPIHooks<TSSslHookInternalID,
TSSslHookInternalID::NUM>
+{
+};
+
+// there is no corresponding deinit; we leak the resource on shutdown
+void init_global_ssl_hooks();
+
+extern SSLAPIHooks *g_ssl_hooks;
diff --git a/iocore/net/SSLNetVConnection.cc b/iocore/net/SSLNetVConnection.cc
index 19c4da1274..717d0021a0 100644
--- a/iocore/net/SSLNetVConnection.cc
+++ b/iocore/net/SSLNetVConnection.cc
@@ -39,6 +39,7 @@
#include "P_SSLClientUtils.h"
#include "P_SSLNetVConnection.h"
#include "BIO_fastopen.h"
+#include "SSLAPIHooks.h"
#include "SSLStats.h"
#include "P_ALPNSupport.h"
@@ -1265,7 +1266,7 @@ SSLNetVConnection::sslServerHandShakeEvent(int &err)
Metrics::increment(ssl_rsb.total_attempts_handshake_count_in);
if (!curHook) {
Dbg(dbg_ctl_ssl, "Initialize preaccept curHook from NULL");
- curHook = ssl_hooks->get(TSSslHookInternalID(TS_VCONN_START_HOOK));
+ curHook = g_ssl_hooks->get(TSSslHookInternalID(TS_VCONN_START_HOOK));
} else {
curHook = curHook->next();
}
@@ -1567,7 +1568,7 @@ SSLNetVConnection::sslClientHandShakeEvent(int &err)
Metrics::increment(ssl_rsb.total_attempts_handshake_count_out);
if (!curHook) {
Dbg(dbg_ctl_ssl, "Initialize outbound connect curHook from NULL");
- curHook =
ssl_hooks->get(TSSslHookInternalID(TS_VCONN_OUTBOUND_START_HOOK));
+ curHook =
g_ssl_hooks->get(TSSslHookInternalID(TS_VCONN_OUTBOUND_START_HOOK));
} else {
curHook = curHook->next();
}
@@ -1842,7 +1843,7 @@ SSLNetVConnection::callHooks(TSEvent eventId)
case HANDSHAKE_HOOKS_CLIENT_HELLO:
case HANDSHAKE_HOOKS_CLIENT_HELLO_INVOKE:
if (!curHook) {
- curHook = ssl_hooks->get(TSSslHookInternalID(TS_SSL_CLIENT_HELLO_HOOK));
+ curHook =
g_ssl_hooks->get(TSSslHookInternalID(TS_SSL_CLIENT_HELLO_HOOK));
} else {
curHook = curHook->next();
}
@@ -1856,14 +1857,14 @@ SSLNetVConnection::callHooks(TSEvent eventId)
// The server verify event addresses ATS to origin handshake
// All the other events are for client to ATS
if (!curHook) {
- curHook = ssl_hooks->get(TSSslHookInternalID(TS_SSL_VERIFY_SERVER_HOOK));
+ curHook =
g_ssl_hooks->get(TSSslHookInternalID(TS_SSL_VERIFY_SERVER_HOOK));
} else {
curHook = curHook->next();
}
break;
case HANDSHAKE_HOOKS_SNI:
if (!curHook) {
- curHook = ssl_hooks->get(TSSslHookInternalID(TS_SSL_SERVERNAME_HOOK));
+ curHook = g_ssl_hooks->get(TSSslHookInternalID(TS_SSL_SERVERNAME_HOOK));
} else {
curHook = curHook->next();
}
@@ -1874,7 +1875,7 @@ SSLNetVConnection::callHooks(TSEvent eventId)
case HANDSHAKE_HOOKS_CERT:
case HANDSHAKE_HOOKS_CERT_INVOKE:
if (!curHook) {
- curHook = ssl_hooks->get(TSSslHookInternalID(TS_SSL_CERT_HOOK));
+ curHook = g_ssl_hooks->get(TSSslHookInternalID(TS_SSL_CERT_HOOK));
} else {
curHook = curHook->next();
}
@@ -1887,7 +1888,7 @@ SSLNetVConnection::callHooks(TSEvent eventId)
case HANDSHAKE_HOOKS_CLIENT_CERT:
case HANDSHAKE_HOOKS_CLIENT_CERT_INVOKE:
if (!curHook) {
- curHook = ssl_hooks->get(TSSslHookInternalID(TS_SSL_VERIFY_CLIENT_HOOK));
+ curHook =
g_ssl_hooks->get(TSSslHookInternalID(TS_SSL_VERIFY_CLIENT_HOOK));
} else {
curHook = curHook->next();
}
@@ -1897,14 +1898,14 @@ SSLNetVConnection::callHooks(TSEvent eventId)
if (eventId == TS_EVENT_VCONN_CLOSE) {
sslHandshakeHookState = HANDSHAKE_HOOKS_DONE;
if (curHook == nullptr) {
- curHook = ssl_hooks->get(TSSslHookInternalID(TS_VCONN_CLOSE_HOOK));
+ curHook = g_ssl_hooks->get(TSSslHookInternalID(TS_VCONN_CLOSE_HOOK));
} else {
curHook = curHook->next();
}
} else if (eventId == TS_EVENT_VCONN_OUTBOUND_CLOSE) {
sslHandshakeHookState = HANDSHAKE_HOOKS_DONE;
if (curHook == nullptr) {
- curHook =
ssl_hooks->get(TSSslHookInternalID(TS_VCONN_OUTBOUND_CLOSE_HOOK));
+ curHook =
g_ssl_hooks->get(TSSslHookInternalID(TS_VCONN_OUTBOUND_CLOSE_HOOK));
} else {
curHook = curHook->next();
}
diff --git a/iocore/net/SSLSecret.cc b/iocore/net/SSLSecret.cc
index e0bb8e502c..03f285ca6b 100644
--- a/iocore/net/SSLSecret.cc
+++ b/iocore/net/SSLSecret.cc
@@ -21,7 +21,8 @@
#include "swoc/swoc_file.h"
-#include "api/InkAPIInternal.h" // Added to include the ssl_hook and
lifestyle_hook definitions
+#include "api/LifecycleAPIHooks.h"
+
#include "P_SSLConfig.h"
#include <utility>
@@ -44,7 +45,7 @@ SSLSecret::loadSecret(const std::string &name1, const
std::string &name2, std::s
{
// Call the load secret hooks
//
- class APIHook *curHook = lifecycle_hooks->get(TS_LIFECYCLE_SSL_SECRET_HOOK);
+ class APIHook *curHook =
g_lifecycle_hooks->get(TS_LIFECYCLE_SSL_SECRET_HOOK);
TSSecretID secret_name;
secret_name.cert_name = name1.data();
secret_name.cert_name_len = name1.size();
diff --git a/iocore/net/SSLUtils.cc b/iocore/net/SSLUtils.cc
index a70ea4f9a6..fb6e9c7005 100644
--- a/iocore/net/SSLUtils.cc
+++ b/iocore/net/SSLUtils.cc
@@ -42,6 +42,7 @@
#include "P_TLSKeyLogger.h"
#include "BoringSSLUtils.h"
#include "ProxyProtocol.h"
+#include "SSLAPIHooks.h"
#include "SSLSessionCache.h"
#include "SSLSessionTicket.h"
#include "SSLDynlock.h"
@@ -228,7 +229,7 @@ ssl_new_cached_session(SSL *ssl, SSL_SESSION *sess)
session_cache->insertSession(sid, sess, ssl);
// Call hook after new session is created
- APIHook *hook = ssl_hooks->get(TSSslHookInternalID(TS_SSL_SESSION_HOOK));
+ APIHook *hook = g_ssl_hooks->get(TSSslHookInternalID(TS_SSL_SESSION_HOOK));
while (hook) {
hook->invoke(TS_EVENT_SSL_SESSION_NEW, &sid);
hook = hook->m_link.next;
@@ -251,7 +252,7 @@ ssl_rm_cached_session(SSL_CTX *ctx, SSL_SESSION *sess)
SSLSessionID sid(id, len);
// Call hook before session is removed
- APIHook *hook = ssl_hooks->get(TSSslHookInternalID(TS_SSL_SESSION_HOOK));
+ APIHook *hook = g_ssl_hooks->get(TSSslHookInternalID(TS_SSL_SESSION_HOOK));
while (hook) {
hook->invoke(TS_EVENT_SSL_SESSION_REMOVE, &sid);
hook = hook->m_link.next;
diff --git a/iocore/net/TLSSessionResumptionSupport.cc
b/iocore/net/TLSSessionResumptionSupport.cc
index e1da969892..5085a9e7b7 100644
--- a/iocore/net/TLSSessionResumptionSupport.cc
+++ b/iocore/net/TLSSessionResumptionSupport.cc
@@ -25,6 +25,7 @@
// Check if the ticket_key callback #define is available, and if so, enable
session tickets.
#include "TLSSessionResumptionSupport.h"
+#include "SSLAPIHooks.h"
#include "P_SSLConfig.h"
#include "SSLStats.h"
@@ -150,7 +151,7 @@ TLSSessionResumptionSupport::getSession(SSL *ssl, const
unsigned char *id, int l
}
}
- APIHook *hook = ssl_hooks->get(TSSslHookInternalID(TS_SSL_SESSION_HOOK));
+ APIHook *hook = g_ssl_hooks->get(TSSslHookInternalID(TS_SSL_SESSION_HOOK));
while (hook) {
hook->invoke(TS_EVENT_SSL_SESSION_GET, &sid);
hook = hook->m_link.next;
diff --git a/iocore/net/libinknet_stub.cc b/iocore/net/libinknet_stub.cc
index 1147395251..b5bf8cec33 100644
--- a/iocore/net/libinknet_stub.cc
+++ b/iocore/net/libinknet_stub.cc
@@ -68,41 +68,6 @@ ParentConfigParams::nextParent(HttpRequestData *,
ParentResult *, unsigned int,
}
#include "api/InkAPIInternal.h"
-int
-APIHook::invoke(int, void *) const
-{
- ink_assert(false);
- return 0;
-}
-
-int
-APIHook::blocking_invoke(int, void *) const
-{
- ink_assert(false);
- return 0;
-}
-
-APIHook *
-APIHook::next() const
-{
- ink_assert(false);
- return nullptr;
-}
-
-APIHook *
-APIHook::prev() const
-{
- ink_assert(false);
- return nullptr;
-}
-
-APIHook *
-APIHooks::head() const
-{
- ink_assert(false);
- return nullptr;
-}
-
#include "ControlMatcher.h"
char *
HttpRequestData::get_string()
@@ -132,8 +97,6 @@ HttpRequestData::get_client_ip()
return nullptr;
}
-SslAPIHooks *ssl_hooks = nullptr;
-LifecycleAPIHooks *lifecycle_hooks = nullptr;
StatPagesManager statPagesManager;
#include "PreWarmManager.h"
diff --git a/iocore/net/unit_tests/unit_test_main.cc
b/iocore/net/unit_tests/unit_test_main.cc
index 42ec30bc89..1fd4e1ec84 100644
--- a/iocore/net/unit_tests/unit_test_main.cc
+++ b/iocore/net/unit_tests/unit_test_main.cc
@@ -26,6 +26,7 @@
#include "I_Thread.h"
#include "P_SSLConfig.h"
#include "records/I_RecordsConfig.h"
+#include "SSLAPIHooks.h"
#include "tscore/BaseLogFile.h"
#include "tscore/Diags.h"
#include "tscore/I_Layout.h"
@@ -61,6 +62,7 @@ public:
main_thread->set_specific();
SSLConfig::startup();
+ init_global_ssl_hooks();
}
void
diff --git a/mgmt/rpc/CMakeLists.txt b/mgmt/rpc/CMakeLists.txt
index ae20a7d076..45c2d2fc5d 100644
--- a/mgmt/rpc/CMakeLists.txt
+++ b/mgmt/rpc/CMakeLists.txt
@@ -69,6 +69,7 @@ target_link_libraries(rpcpublichandlers
PRIVATE
ts::inkcache
ts::proxy
+ ts::tsapicore
)
if(BUILD_TESTING)
diff --git a/mgmt/rpc/handlers/plugins/Plugins.cc
b/mgmt/rpc/handlers/plugins/Plugins.cc
index 7d83570f8a..ae41038fbb 100644
--- a/mgmt/rpc/handlers/plugins/Plugins.cc
+++ b/mgmt/rpc/handlers/plugins/Plugins.cc
@@ -21,7 +21,7 @@
#include "Plugins.h"
#include "rpc/handlers/common/ErrorUtils.h"
-#include "api/InkAPIInternal.h"
+#include "api/LifecycleAPIHooks.h"
namespace
{
@@ -61,7 +61,7 @@ plugin_send_basic_msg(std::string_view const &id, YAML::Node
const ¶ms)
{
// The rpc could be ready before plugins are initialized.
// We make sure it is ready.
- if (!lifecycle_hooks) {
+ if (!g_lifecycle_hooks) {
return err::make_errata(err::Codes::PLUGIN, "Plugin is not yet ready to
handle any messages.");
}
@@ -75,7 +75,7 @@ plugin_send_basic_msg(std::string_view const &id, YAML::Node
const ¶ms)
msg.data = info.data.data();
msg.data_size = info.data.size();
- APIHook *hook = lifecycle_hooks->get(TS_LIFECYCLE_MSG_HOOK);
+ APIHook *hook = g_lifecycle_hooks->get(TS_LIFECYCLE_MSG_HOOK);
while (hook) {
TSPluginMsg tmp(msg); // Just to make sure plugins don't mess this up
for others.
diff --git a/proxy/CMakeLists.txt b/proxy/CMakeLists.txt
index 7c8164c78b..97534809fb 100644
--- a/proxy/CMakeLists.txt
+++ b/proxy/CMakeLists.txt
@@ -21,7 +21,8 @@ add_library(proxy STATIC
CacheControl.cc
ControlBase.cc
ControlMatcher.cc
- HostStatus.cc
+ HostStatus.cc
+ HttpAPIHooks.cc
IPAllow.cc
ParentConsistentHash.cc
ParentRoundRobin.cc
@@ -63,8 +64,10 @@ target_link_libraries(proxy
PUBLIC
ts::inkcache
ts::inkevent
+ ts::tsapicore
ts::tscore
PRIVATE
+ ts::jsonrpc_protocol
ts::inkutils
)
diff --git a/proxy/HttpAPIHooks.cc b/proxy/HttpAPIHooks.cc
new file mode 100644
index 0000000000..699984c769
--- /dev/null
+++ b/proxy/HttpAPIHooks.cc
@@ -0,0 +1,32 @@
+/** @file
+
+ Internal SDK stuff
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#include "HttpAPIHooks.h"
+
+HttpAPIHooks *http_global_hooks = nullptr;
+
+void
+init_global_http_hooks()
+{
+ http_global_hooks = new HttpAPIHooks;
+}
diff --git a/proxy/HttpAPIHooks.h b/proxy/HttpAPIHooks.h
new file mode 100644
index 0000000000..a983d0c121
--- /dev/null
+++ b/proxy/HttpAPIHooks.h
@@ -0,0 +1,37 @@
+/** @file
+
+ Internal SDK stuff
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#pragma once
+
+#include "api/FeatureAPIHooks.h"
+
+#include "ts/apidefs.h"
+
+class HttpAPIHooks : public FeatureAPIHooks<TSHttpHookID, TS_HTTP_LAST_HOOK>
+{
+};
+
+// there is no corresponding deinit; we leak the resource on shutdown
+void init_global_http_hooks();
+
+extern HttpAPIHooks *http_global_hooks;
diff --git a/proxy/Makefile.am b/proxy/Makefile.am
index 42132ceebe..d7b919e490 100644
--- a/proxy/Makefile.am
+++ b/proxy/Makefile.am
@@ -55,6 +55,8 @@ libproxy_a_SOURCES = \
ControlMatcher.h \
HostStatus.cc \
HostStatus.h \
+ HttpAPIHooks.cc \
+ HttpAPIHooks.h \
IPAllow.cc \
IPAllow.h \
ParentConsistentHash.cc \
diff --git a/proxy/http/CMakeLists.txt b/proxy/http/CMakeLists.txt
index 06e2398b27..2619865120 100644
--- a/proxy/http/CMakeLists.txt
+++ b/proxy/http/CMakeLists.txt
@@ -61,8 +61,11 @@ target_link_libraries(http
ts::inkevent
ts::inkhostdb
ts::proxy
+ ts::tsapicore
ts::tscore
PRIVATE
+ ts::http2
+ ts::http_remap
ts::inkcache
ts::inkutils
)
diff --git a/proxy/http/HttpProxyServerMain.cc
b/proxy/http/HttpProxyServerMain.cc
index e85ff1233c..a16c061c70 100644
--- a/proxy/http/HttpProxyServerMain.cc
+++ b/proxy/http/HttpProxyServerMain.cc
@@ -21,6 +21,7 @@
limitations under the License.
*/
+#include "api/LifecycleAPIHooks.h"
#include "tscore/ink_config.h"
#include "P_Net.h"
#include "HttpConfig.h"
@@ -366,7 +367,7 @@ start_HttpProxyServer()
statPagesManager.register_http("remap_hits", register_ShowRemapHitCount);
// Alert plugins that connections will be accepted.
- APIHook *hook = lifecycle_hooks->get(TS_LIFECYCLE_PORTS_READY_HOOK);
+ APIHook *hook = g_lifecycle_hooks->get(TS_LIFECYCLE_PORTS_READY_HOOK);
while (hook) {
hook->invoke(TS_EVENT_LIFECYCLE_PORTS_READY, nullptr);
hook = hook->next();
diff --git a/proxy/http/remap/CMakeLists.txt b/proxy/http/remap/CMakeLists.txt
index f0bb9ff372..4d5133dbea 100644
--- a/proxy/http/remap/CMakeLists.txt
+++ b/proxy/http/remap/CMakeLists.txt
@@ -36,7 +36,10 @@ add_library(http_remap STATIC
)
add_library(ts::http_remap ALIAS http_remap)
-target_include_directories(http_remap PRIVATE
+target_include_directories(http_remap
+ PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ PRIVATE
${IOCORE_INCLUDE_DIRS}
${PROXY_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/src/records
diff --git a/proxy/http/remap/unit-tests/nexthop_test_stubs.cc
b/proxy/http/remap/unit-tests/nexthop_test_stubs.cc
index 5ab1523300..71ef6fc3a3 100644
--- a/proxy/http/remap/unit-tests/nexthop_test_stubs.cc
+++ b/proxy/http/remap/unit-tests/nexthop_test_stubs.cc
@@ -60,10 +60,6 @@ HttpCacheAction::cancel(Continuation *c)
{
}
PostDataBuffers::~PostDataBuffers() {}
-void
-APIHooks::clear()
-{
-}
HttpTunnel::HttpTunnel() {}
HttpCacheSM::HttpCacheSM() {}
diff --git a/src/api/APIHook.cc b/src/api/APIHook.cc
new file mode 100644
index 0000000000..eae867cc4f
--- /dev/null
+++ b/src/api/APIHook.cc
@@ -0,0 +1,76 @@
+/** @file
+
+ Internal SDK stuff
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#include "api/APIHook.h"
+
+#include "ts/apidefs.h"
+
+#include "tscore/ink_assert.h"
+#include "tscore/ink_atomic.h"
+
+// inkevent
+#include "I_Event.h"
+#include "I_Lock.h"
+
+APIHook *
+APIHook::next() const
+{
+ return m_link.next;
+}
+
+APIHook *
+APIHook::prev() const
+{
+ return m_link.prev;
+}
+
+int
+APIHook::invoke(int event, void *edata) const
+{
+ if (event == EVENT_IMMEDIATE || event == EVENT_INTERVAL || event ==
TS_EVENT_HTTP_TXN_CLOSE) {
+ if (ink_atomic_increment((int *)&m_cont->m_event_count, 1) < 0) {
+ ink_assert(!"not reached");
+ }
+ }
+ WEAK_MUTEX_TRY_LOCK(lock, m_cont->mutex, this_ethread());
+ if (!lock.is_locked()) {
+ // If we cannot get the lock, the caller needs to restructure to handle
rescheduling
+ ink_release_assert(0);
+ }
+ return m_cont->handleEvent(event, edata);
+ return 0;
+}
+
+int
+APIHook::blocking_invoke(int event, void *edata) const
+{
+ if (event == EVENT_IMMEDIATE || event == EVENT_INTERVAL || event ==
TS_EVENT_HTTP_TXN_CLOSE) {
+ if (ink_atomic_increment((int *)&m_cont->m_event_count, 1) < 0) {
+ ink_assert(!"not reached");
+ }
+ }
+
+ WEAK_SCOPED_MUTEX_LOCK(lock, m_cont->mutex, this_ethread());
+
+ return m_cont->handleEvent(event, edata);
+}
diff --git a/src/api/APIHooks.cc b/src/api/APIHooks.cc
new file mode 100644
index 0000000000..0b1f6737c7
--- /dev/null
+++ b/src/api/APIHooks.cc
@@ -0,0 +1,58 @@
+/** @file
+
+ Internal SDK stuff
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#include "api/APIHooks.h"
+
+#include "tscore/Allocator.h"
+
+// inkevent
+#include "I_ProxyAllocator.h"
+#include "I_Thread.h"
+
+static ClassAllocator<APIHook> apiHookAllocator("apiHookAllocator");
+
+APIHook *
+APIHooks::head() const
+{
+ return m_hooks.head;
+}
+
+void
+APIHooks::append(INKContInternal *cont)
+{
+ APIHook *api_hook;
+
+ api_hook = THREAD_ALLOC(apiHookAllocator, this_thread());
+ api_hook->m_cont = cont;
+
+ m_hooks.enqueue(api_hook);
+}
+
+void
+APIHooks::clear()
+{
+ APIHook *hook;
+ while (nullptr != (hook = m_hooks.pop())) {
+ THREAD_FREE(hook, apiHookAllocator, this_thread());
+ }
+}
diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt
index a373cac198..0b081ed929 100644
--- a/src/api/CMakeLists.txt
+++ b/src/api/CMakeLists.txt
@@ -23,11 +23,14 @@ add_library(ts::tsapi ALIAS tsapi)
target_link_libraries(tsapi PRIVATE ts::tscore)
add_library(tsapicore STATIC
+ APIHook.cc
+ APIHooks.cc
Metrics.cc
ConfigUpdateCbTable.cc
InkContInternal.cc
InkVConnInternal.cc
FetchSM.cc
+ LifecycleAPIHooks.cc
)
add_library(ts::tsapicore ALIAS tsapicore)
target_link_libraries(tsapicore PRIVATE ts::tscore)
diff --git a/src/api/InkAPI.cc b/src/api/InkAPI.cc
index ac02a509b9..80260e158d 100644
--- a/src/api/InkAPI.cc
+++ b/src/api/InkAPI.cc
@@ -44,6 +44,7 @@
#include "ProxySession.h"
#include "Http2ClientSession.h"
#include "PoolableSession.h"
+#include "HttpAPIHooks.h"
#include "HttpSM.h"
#include "HttpConfig.h"
#include "P_Net.h"
@@ -55,6 +56,7 @@
#include "records/I_RecCore.h"
#include "P_SSLConfig.h"
#include "P_SSLClientUtils.h"
+#include "SSLAPIHooks.h"
#include "SSLDiags.h"
#include "SSLInternal.h"
#include "TLSBasicSupport.h"
@@ -66,6 +68,7 @@
#include "HttpSessionAccept.h"
#include "PluginVC.h"
#include "api/FetchSM.h"
+#include "api/LifecycleAPIHooks.h"
#include "HttpDebugNames.h"
#include "I_AIO.h"
#include "I_Tasks.h"
@@ -391,9 +394,6 @@ namespace c
} // end namespace c
} // end namespace tsapi
-HttpAPIHooks *http_global_hooks = nullptr;
-SslAPIHooks *ssl_hooks = nullptr;
-LifecycleAPIHooks *lifecycle_hooks = nullptr;
ConfigUpdateCbTable *global_config_cbs = nullptr;
static ts::Metrics &global_api_metrics = ts::Metrics::getInstance();
@@ -1047,73 +1047,6 @@ FileImpl::fgets(char *buf, size_t length)
// APIHook, APIHooks, HttpAPIHooks, HttpHookState
//
////////////////////////////////////////////////////////////////////
-APIHook *
-APIHook::next() const
-{
- return m_link.next;
-}
-
-APIHook *
-APIHook::prev() const
-{
- return m_link.prev;
-}
-
-int
-APIHook::invoke(int event, void *edata) const
-{
- if (event == EVENT_IMMEDIATE || event == EVENT_INTERVAL || event ==
TS_EVENT_HTTP_TXN_CLOSE) {
- if (ink_atomic_increment((int *)&m_cont->m_event_count, 1) < 0) {
- ink_assert(!"not reached");
- }
- }
- WEAK_MUTEX_TRY_LOCK(lock, m_cont->mutex, this_ethread());
- if (!lock.is_locked()) {
- // If we cannot get the lock, the caller needs to restructure to handle
rescheduling
- ink_release_assert(0);
- }
- return m_cont->handleEvent(event, edata);
-}
-
-int
-APIHook::blocking_invoke(int event, void *edata) const
-{
- if (event == EVENT_IMMEDIATE || event == EVENT_INTERVAL || event ==
TS_EVENT_HTTP_TXN_CLOSE) {
- if (ink_atomic_increment((int *)&m_cont->m_event_count, 1) < 0) {
- ink_assert(!"not reached");
- }
- }
-
- WEAK_SCOPED_MUTEX_LOCK(lock, m_cont->mutex, this_ethread());
-
- return m_cont->handleEvent(event, edata);
-}
-
-APIHook *
-APIHooks::head() const
-{
- return m_hooks.head;
-}
-
-void
-APIHooks::append(INKContInternal *cont)
-{
- APIHook *api_hook;
-
- api_hook = THREAD_ALLOC(apiHookAllocator, this_thread());
- api_hook->m_cont = cont;
-
- m_hooks.enqueue(api_hook);
-}
-
-void
-APIHooks::clear()
-{
- APIHook *hook;
- while (nullptr != (hook = m_hooks.pop())) {
- THREAD_FREE(hook, apiHookAllocator, this_thread());
- }
-}
void
HttpHookState::init(TSHttpHookID id, HttpAPIHooks const *global, HttpAPIHooks
const *ssn, HttpAPIHooks const *txn)
@@ -1458,9 +1391,9 @@ api_init()
TS_HTTP_LEN_PUBLIC = HTTP_LEN_PUBLIC;
TS_HTTP_LEN_S_MAXAGE = HTTP_LEN_S_MAXAGE;
- http_global_hooks = new HttpAPIHooks;
- ssl_hooks = new SslAPIHooks;
- lifecycle_hooks = new LifecycleAPIHooks;
+ init_global_http_hooks();
+ init_global_ssl_hooks();
+ init_global_lifecycle_hooks();
global_config_cbs = new ConfigUpdateCbTable;
// Setup the version string for returning to plugins
@@ -4551,7 +4484,7 @@ tsapi::c::TSHttpHookAdd(TSHttpHookID id, TSCont contp)
TSSslHookInternalID internalId{id};
if (internalId.is_in_bounds()) {
- ssl_hooks->append(internalId, icontp);
+ g_ssl_hooks->append(internalId, icontp);
} else { // Follow through the regular HTTP hook framework
http_global_hooks->append(id, icontp);
}
@@ -4563,7 +4496,7 @@ tsapi::c::TSLifecycleHookAdd(TSLifecycleHookID id, TSCont
contp)
sdk_assert(sdk_sanity_check_continuation(contp) == TS_SUCCESS);
sdk_assert(sdk_sanity_check_lifecycle_hook_id(id) == TS_SUCCESS);
- lifecycle_hooks->append(id, (INKContInternal *)contp);
+ g_lifecycle_hooks->append(id, (INKContInternal *)contp);
}
/* HTTP sessions */
diff --git a/src/api/LifecycleAPIHooks.cc b/src/api/LifecycleAPIHooks.cc
new file mode 100644
index 0000000000..6b1af76f6c
--- /dev/null
+++ b/src/api/LifecycleAPIHooks.cc
@@ -0,0 +1,32 @@
+/** @file
+
+ Internal SDK stuff
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#include "api/LifecycleAPIHooks.h"
+
+LifecycleAPIHooks *g_lifecycle_hooks = nullptr;
+
+void
+init_global_lifecycle_hooks()
+{
+ g_lifecycle_hooks = new LifecycleAPIHooks;
+}
diff --git a/src/api/Makefile.am b/src/api/Makefile.am
index f165c6024e..778919466b 100644
--- a/src/api/Makefile.am
+++ b/src/api/Makefile.am
@@ -35,8 +35,13 @@ AM_CPPFLAGS += \
-I$(abs_top_srcdir)/proxy/http2 \
-I$(abs_top_srcdir)/proxy/http/remap \
-I$(abs_top_srcdir)/proxy/logging \
- -I$(abs_top_srcdir)/mgmt/rpc \
- -I$(abs_top_srcdir)/mgmt/ \
+ -I$(abs_top_srcdir)/mgmt/rpc \
+ -I$(abs_top_srcdir)/mgmt/ \
+ -I$(abs_top_srcdir)/iocore/eventsystem \
+ -I$(abs_top_srcdir)/iocore/cache \
+ -I$(abs_top_srcdir)/iocore/aio \
+ -I$(abs_top_srcdir)/iocore/net \
+ -I$(abs_top_srcdir)/iocore/dns \
@SWOC_INCLUDES@ \
@YAMLCPP_INCLUDES@ \
$(TS_INCLUDES)
@@ -59,11 +64,14 @@ endif
# libtsapicore.a
libtsapicore_a_SOURCES = \
+ APIHook.cc \
+ APIHooks.cc \
Metrics.cc \
ConfigUpdateCbTable.cc \
InkContInternal.cc \
InkVConnInternal.cc \
- FetchSM.cc
+ FetchSM.cc \
+ LifecycleAPIHooks.cc
test_Metrics_SOURCES = test_Metrics.cc
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 3c0c4d16fc..2775dd5605 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -67,7 +67,7 @@ macro(add_cache_test name)
${CMAKE_SOURCE_DIR}/iocore/cache/test/stub.cc
${CMAKE_SOURCE_DIR}/iocore/cache/test/CacheTestHandler.cc
${ARGN})
- target_link_libraries(${name} PRIVATE ts::proxy)
+ target_link_libraries(${name} PRIVATE ts::inknet ts::proxy ts::tsapicore)
add_test(NAME test_cache_${name} COMMAND $<TARGET_FILE:${name}>)
endmacro()
@@ -75,7 +75,6 @@ macro(add_net_test name)
add_executable(${name}
${CMAKE_SOURCE_DIR}/iocore/net/libinknet_stub.cc
${ARGN})
- target_link_libraries(${name} PRIVATE ts::proxy)
add_test(NAME test_cache_${name} COMMAND $<TARGET_FILE:${name}>)
endmacro()
diff --git a/src/traffic_logcat/CMakeLists.txt
b/src/traffic_logcat/CMakeLists.txt
index e702c553e3..281df58142 100644
--- a/src/traffic_logcat/CMakeLists.txt
+++ b/src/traffic_logcat/CMakeLists.txt
@@ -15,6 +15,20 @@
#
#######################
-add_executable(traffic_logcat logcat.cc)
-target_link_libraries(traffic_logcat PRIVATE ts::tscore ts::proxy ts::logging
ts::hdrs ts::tsapicore ts::diagsconfig libswoc)
+add_executable(traffic_logcat
+ ${PROJECT_SOURCE_DIR}/src/shared/overridable_txn_vars.cc
+ logcat.cc
+)
+target_link_libraries(traffic_logcat
+ PRIVATE
+ ts::tsapi
+ ts::proxy
+ ts::inknet
+ ts::logging
+ ts::hdrs
+ ts::tsapicore
+ ts::diagsconfig
+ ts::configmanager
+ libswoc
+)
install(TARGETS traffic_logcat)
diff --git a/src/traffic_server/traffic_server.cc
b/src/traffic_server/traffic_server.cc
index 96d0a11f7c..103828676a 100644
--- a/src/traffic_server/traffic_server.cc
+++ b/src/traffic_server/traffic_server.cc
@@ -99,6 +99,7 @@ extern "C" int plock(int);
#include "RemapProcessor.h"
#include "I_Tasks.h"
#include "api/InkAPIInternal.h"
+#include "api/LifecycleAPIHooks.h"
#include "HTTP2.h"
#include "tscore/ink_config.h"
#include "P_SSLClientUtils.h"
@@ -241,7 +242,7 @@ struct AutoStopCont : public Continuation {
{
TSSystemState::stop_ssl_handshaking();
- APIHook *hook = lifecycle_hooks->get(TS_LIFECYCLE_SHUTDOWN_HOOK);
+ APIHook *hook = g_lifecycle_hooks->get(TS_LIFECYCLE_SHUTDOWN_HOOK);
while (hook) {
WEAK_SCOPED_MUTEX_LOCK(lock, hook->m_cont->mutex, this_ethread());
hook->invoke(TS_EVENT_LIFECYCLE_SHUTDOWN, nullptr);
@@ -810,7 +811,7 @@ CB_After_Cache_Init()
intm[id].store(time(nullptr));
// Alert the plugins the cache is initialized.
- hook = lifecycle_hooks->get(TS_LIFECYCLE_CACHE_READY_HOOK);
+ hook = g_lifecycle_hooks->get(TS_LIFECYCLE_CACHE_READY_HOOK);
while (hook) {
hook->invoke(TS_EVENT_LIFECYCLE_CACHE_READY, nullptr);
hook = hook->next();
@@ -2229,7 +2230,7 @@ main(int /* argc ATS_UNUSED */, const char **argv)
if (http_enabled) {
// call the ready hooks before we start accepting connections.
- APIHook *hook =
lifecycle_hooks->get(TS_LIFECYCLE_PORTS_INITIALIZED_HOOK);
+ APIHook *hook =
g_lifecycle_hooks->get(TS_LIFECYCLE_PORTS_INITIALIZED_HOOK);
while (hook) {
hook->invoke(TS_EVENT_LIFECYCLE_PORTS_INITIALIZED, nullptr);
hook = hook->next();
@@ -2319,7 +2320,7 @@ init_ssl_ctx_callback(void *ctx, bool server)
{
TSEvent event = server ? TS_EVENT_LIFECYCLE_SERVER_SSL_CTX_INITIALIZED :
TS_EVENT_LIFECYCLE_CLIENT_SSL_CTX_INITIALIZED;
APIHook *hook =
- lifecycle_hooks->get(server ? TS_LIFECYCLE_SERVER_SSL_CTX_INITIALIZED_HOOK
: TS_LIFECYCLE_CLIENT_SSL_CTX_INITIALIZED_HOOK);
+ g_lifecycle_hooks->get(server ?
TS_LIFECYCLE_SERVER_SSL_CTX_INITIALIZED_HOOK :
TS_LIFECYCLE_CLIENT_SSL_CTX_INITIALIZED_HOOK);
while (hook) {
hook->invoke(event, ctx);
@@ -2341,7 +2342,7 @@ task_threads_started_callback()
pluginInitCheck.wait(lock, [] { return plugin_init_done; });
}
- APIHook *hook = lifecycle_hooks->get(TS_LIFECYCLE_TASK_THREADS_READY_HOOK);
+ APIHook *hook = g_lifecycle_hooks->get(TS_LIFECYCLE_TASK_THREADS_READY_HOOK);
while (hook) {
WEAK_SCOPED_MUTEX_LOCK(lock, hook->m_cont->mutex, this_ethread());
hook->invoke(TS_EVENT_LIFECYCLE_TASK_THREADS_READY, nullptr);