TS-2598 Expose HttpDebugNames to public plugin APIs
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/d3fd1e67 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/d3fd1e67 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/d3fd1e67 Branch: refs/heads/lua_config Commit: d3fd1e674b0e6d51fd3e8f4c49ed7d5d9eeb56a3 Parents: ce6b5c7 Author: Leif Hedstrom <[email protected]> Authored: Sat Mar 15 12:30:58 2014 -0600 Committer: Leif Hedstrom <[email protected]> Committed: Sat Mar 15 12:30:58 2014 -0600 ---------------------------------------------------------------------- CHANGES | 2 ++ doc/reference/api/TSDebug.en.rst | 12 ++++++++ proxy/InkAPI.cc | 30 +++++++++++++++---- proxy/InkAPITest.cc | 56 +++++++++++++++++++++++++++++++++++ proxy/api/ts/ts.h | 26 ++++++++++++++++ 5 files changed, 120 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/d3fd1e67/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index b68e5c3..3b64258 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ -*- coding: utf-8 -*- Changes with Apache Traffic Server 5.0.0 + *) [TS-2598] Expose HttpDebugNames to public plugin APIs. + *) [TS-2639] Release HttpClientSession objects back to the proxy allocator. *) [TS-2637] Add traffic_line records match option. http://git-wip-us.apache.org/repos/asf/trafficserver/blob/d3fd1e67/doc/reference/api/TSDebug.en.rst ---------------------------------------------------------------------- diff --git a/doc/reference/api/TSDebug.en.rst b/doc/reference/api/TSDebug.en.rst index 430617c..7fc21db 100644 --- a/doc/reference/api/TSDebug.en.rst +++ b/doc/reference/api/TSDebug.en.rst @@ -32,6 +32,9 @@ Synopsis .. function:: void TSHttpSsnDebugSet(TSHttpSsn ssn, int on) .. function:: int TSHttpTxnDebugGet(TSHttpTxn txnp) .. function:: int TSHttpSsnDebugGet(TSHttpSsn ssn) +.. function:: const char* TSHttpServerStateNameLookup(TSServerState state) +.. function:: const char* TSHttpHookNameLookup(TSHttpHookID hook) +.. function:: const char* TSHttpEventNameLookup(TSEvent event) .. macro:: void TSAssert(expression) .. macro:: void TSReleaseAssert(expression) @@ -61,6 +64,11 @@ in conjunction with :func:`TSHttpTxnDebugSet`, :func:`TSHttpSsnDebugSet`, :func:`TSHttpTxnDebugGet` and :func:`TSHttpSsnDebugGet` to enable debugging on specific session and transaction objects. +:func:`TSHttpServerStateNameLookup`, :func:`TSHttpHookNameLookup` and +:func:`TSHttpEventNameLookup` converts the respective internal state to a +string representation. This can be useful in debugging (:func:`TSDebug`), +logging and other types notifications. + Examples ======== @@ -69,6 +77,10 @@ debugging flag is enabled:: #include <ts/ts.h> + // Produce information about a hook receiving an event + TSDebug(PLUGIN_NAME, "Entering hook=%s, event=%s", + TSHttpHookNameLookup(hook), TSHttpEventNameLookup(event)); + // Emit debug message if "tag" is enabled or the txn debug // flag is set. TSDebugSpecifc(TSHttpTxnDebugGet(txn), "tag" , http://git-wip-us.apache.org/repos/asf/trafficserver/blob/d3fd1e67/proxy/InkAPI.cc ---------------------------------------------------------------------- diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc index 2a2270a..00a78e1 100644 --- a/proxy/InkAPI.cc +++ b/proxy/InkAPI.cc @@ -21,9 +21,6 @@ limitations under the License. */ -// Avoid complaining about the deprecated APIs. -// #define TS_DEPRECATED - #include <stdio.h> #include "libts.h" @@ -418,12 +415,14 @@ int _TSAssert(const char *text, const char *file, int line) { _ink_assert(text, file, line); + return 0; +} #else _TSAssert(const char *, const char *, int) { -#endif - return 0; + return 0; } +#endif // This assert is for internal API use only. #if TS_USE_FAST_SDK @@ -433,7 +432,6 @@ _TSAssert(const char *, const char *, int) ( (void)((EX) ? (void)0 : _TSReleaseAssert(#EX, __FILE__, __LINE__)) ) #endif - //////////////////////////////////////////////////////////////////// // // SDK Interoperability Support @@ -8494,3 +8492,23 @@ TSHttpTxnIsCacheable(TSHttpTxn txnp, TSMBuffer request, TSMBuffer response) // Make sure these are valid response / requests, then verify if it's cacheable. return (req->valid() && resp->valid() && HttpTransact::is_response_cacheable(&(sm->t_state), req, resp)) ? 1: 0; } + + +// Lookup various debug names for common HTTP types. +const char* +TSHttpServerStateNameLookup(TSServerState state) +{ + return HttpDebugNames::get_server_state_name(static_cast<HttpTransact::ServerState_t>(state)); +} + +const char* +TSHttpHookNameLookup(TSHttpHookID hook) +{ + return HttpDebugNames::get_api_hook_name(static_cast<TSHttpHookID>(hook)); +} + +const char* +TSHttpEventNameLookup(TSEvent event) +{ + return HttpDebugNames::get_event_name(static_cast<int>(event)); +} http://git-wip-us.apache.org/repos/asf/trafficserver/blob/d3fd1e67/proxy/InkAPITest.cc ---------------------------------------------------------------------- diff --git a/proxy/InkAPITest.cc b/proxy/InkAPITest.cc index f558eb0..f380eb5 100644 --- a/proxy/InkAPITest.cc +++ b/proxy/InkAPITest.cc @@ -7608,3 +7608,59 @@ REGRESSION_TEST(SDK_API_ENCODING) (RegressionTest * test, int /* atype ATS_UNUSE return; } + + + +//////////////////////////////////////////////// +// SDK_API_DEBUG_NAME_LOOKUPS +// +// Unit Test for API: TSHttpServerStateNameLookup +// TSHttpHookNameLookup +// TSHttpEventNameLookup +//////////////////////////////////////////////// + +REGRESSION_TEST(SDK_API_DEBUG_NAME_LOOKUPS) (RegressionTest * test, int /* atype ATS_UNUSED */, int *pstatus) +{ + bool success = true; + const char state_name[] = "INACTIVE_TIMEOUT"; + const char hook_name[] = "TS_HTTP_READ_RESPONSE_HDR_HOOK"; + const char event_name[] = "VC_EVENT_IMMEDIATE"; + const char* str; + + *pstatus = REGRESSION_TEST_INPROGRESS; + + str = TSHttpServerStateNameLookup(TS_SRVSTATE_INACTIVE_TIMEOUT); + if ((strlen(str) != strlen(state_name) || strcmp(str, state_name))) { + SDK_RPRINT(test, "TSHttpServerStateNameLookup", "TestCase1", TC_FAIL, "Failed on %d, expected %s, got %s", + TS_SRVSTATE_INACTIVE_TIMEOUT, state_name, str); + success = false; + } else { + SDK_RPRINT(test, "TSHttpServerStateNameLookup", "TestCase1", TC_PASS, "ok"); + } + + + str = TSHttpHookNameLookup(TS_HTTP_READ_RESPONSE_HDR_HOOK); + if ((strlen(str) != strlen(hook_name) || strcmp(str, hook_name))) { + SDK_RPRINT(test, "TSHttpHookNameLookup", "TestCase1", TC_FAIL, "Failed on %d, expected %s, got %s", + TS_HTTP_READ_RESPONSE_HDR_HOOK, hook_name, str); + success = false; + } else { + SDK_RPRINT(test, "TSHttpHookNameLookup", "TestCase1", TC_PASS, "ok"); + } + + + str = TSHttpEventNameLookup(TS_EVENT_IMMEDIATE); + if ((strlen(str) != strlen(event_name) || strcmp(str, event_name))) { + SDK_RPRINT(test, "TSHttpEventNameLookup", "TestCase1", TC_FAIL, "Failed on %d, expected %s, got %s", + TS_EVENT_IMMEDIATE, hook_name, str); + success = false; + } else { + SDK_RPRINT(test, "TSHttpEventNameLookup", "TestCase1", TC_PASS, "ok"); + } + + + *pstatus = success ? REGRESSION_TEST_PASSED : REGRESSION_TEST_FAILED; + + return; +} + http://git-wip-us.apache.org/repos/asf/trafficserver/blob/d3fd1e67/proxy/api/ts/ts.h ---------------------------------------------------------------------- diff --git a/proxy/api/ts/ts.h b/proxy/api/ts/ts.h index b864624..02f4bf0 100644 --- a/proxy/api/ts/ts.h +++ b/proxy/api/ts/ts.h @@ -2270,6 +2270,32 @@ extern "C" */ tsapi int TSHttpTxnIsCacheable(TSHttpTxn txnp, TSMBuffer request, TSMBuffer response); + /** + Return a string respresentation for a TSServerState value. This is useful for plugin debugging. + + @param state the value of this TSServerState + + @return the string representation of the state + */ + tsapi const char* TSHttpServerStateNameLookup(TSServerState state); + + /** + Return a string respresentation for a TSHttpHookID value. This is useful for plugin debugging. + + @param hook the value of this TSHttpHookID + + @return the string representation of the hook ID + */ + tsapi const char* TSHttpHookNameLookup(TSHttpHookID hook); + + /** + Return a string respresentation for a TSEvent value. This is useful for plugin debugging. + + @param event the value of this TSHttpHookID + + @return the string representation of the event + */ + tsapi const char* TSHttpEventNameLookup(TSEvent event); #ifdef __cplusplus }
