diff --git a/CMakeLists.txt b/CMakeLists.txt index cbd3c6db4f0..919ff1c598c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,45 +3,40 @@ ## ## !!!-> IT WILL NOT BUILD TRAFFIC SERVER <-!!! ## -## This file can be tweaked to keep editors happy. In general all projects -## should be defined here so there is only one instance of this file, not one -## per directory. This has been done only to the extent that someone using -## such an editor needed it, so much work is left to be done. +## This file can be tweaked to keep editors happy. In general all projects should be defined here so +## there is only one instance of this file, not one per directory. This has been done only to the +## extent that someone using such an editor needed it, so much work is left to be done. ####################### # -# 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 +# 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. +# 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. # ####################### cmake_minimum_required(VERSION 3.7) project(ats) -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) -include_directories(lib +include_directories( include + tests/include + lib proxy proxy/hdrs proxy/http proxy/http/remap proxy/shared - lib/records - include/wccp - lib/yamlcpp/include iocore/eventsystem iocore/net iocore/dns @@ -55,1149 +50,63 @@ include_directories(lib mgmt/api/include proxy/api) -add_executable(traffic_crashlog - src/traffic_crashlog/procinfo.cc - src/traffic_crashlog/traffic_crashlog.cc - src/traffic_crashlog/traffic_crashlog.h -) - -add_executable(traffic_ctl - src/traffic_ctl/alarm.cc - src/traffic_ctl/config.cc - src/traffic_ctl/plugin.cc - src/traffic_ctl/server.cc - src/traffic_ctl/storage.cc - src/traffic_ctl/traffic_ctl.cc - src/traffic_ctl/traffic_ctl.h - src/traffic_layout/engine.cc -) - -add_executable(traffic_layout - src/traffic_layout/engine.h - src/traffic_layout/file_system.cc - src/traffic_layout/file_system.h - src/traffic_layout/info.cc - src/traffic_layout/info.h - src/traffic_layout/traffic_layout.cc -) - -add_executable(traffic_logcat - src/traffic_logcat/logcat.cc -) - -add_executable(traffic_logstats - src/traffic_logstats/logstats.cc -) - -add_executable(traffic_manager - src/traffic_manager/AddConfigFilesHere.cc - src/traffic_manager/traffic_manager.cc -) - -add_executable(traffic_server - src/traffic_server/CoreUtils.cc - src/traffic_server/CoreUtils.h - src/traffic_server/Crash.cc - src/traffic_server/EventName.cc - src/traffic_server/EventName.h - src/traffic_server/FetchSM.cc - src/traffic_server/FetchSM.h - src/traffic_server/HostStatus.cc - src/traffic_server/InkAPI.cc - src/traffic_server/InkAPITest.cc - src/traffic_server/InkIOCoreAPI.cc - src/traffic_server/SocksProxy.cc - src/traffic_server/traffic_server.cc -) - -add_executable(ats - src/traffic_via/traffic_via.cc - src/traffic_wccp/wccp_client.cc - example/add_header/add_header.c - example/append_transform/append_transform.c - example/basic_auth/basic_auth.c - example/blacklist_0/blacklist_0.c - example/blacklist_1/blacklist_1.c - example/bnull_transform/bnull_transform.c - example/cache_scan/cache_scan.cc - example/cppapi/async_http_fetch/AsyncHttpFetch.cc - example/cppapi/async_http_fetch_streaming/AsyncHttpFetchStreaming.cc - example/cppapi/async_timer/AsyncTimer.cc - example/cppapi/boom/boom.cc - example/cppapi/clientredirect/ClientRedirect.cc - example/cppapi/clientrequest/ClientRequest.cc - example/cppapi/custom_error_remap_plugin/CustomErrorRemapPlugin.cc - example/cppapi/customresponse/CustomResponse.cc - example/cppapi/delay_transformation_plugin/DelayTransformationPlugin.cc - example/cppapi/globalhook/GlobalHookPlugin.cc - example/cppapi/gzip_transformation/GzipTransformationPlugin.cc - example/cppapi/helloworld/HelloWorldPlugin.cc - example/cppapi/intercept/intercept.cc - example/cppapi/internal_transaction_handling/InternalTransactionHandling.cc - example/cppapi/logger_example/LoggerExample.cc - example/cppapi/multiple_transaction_hooks/MultipleTransactionHookPlugins.cc - example/cppapi/null_transformation_plugin/NullTransformationPlugin.cc - example/cppapi/post_buffer/PostBuffer.cc - example/cppapi/remap_plugin/RemapPlugin.cc - example/cppapi/serverresponse/ServerResponse.cc - example/cppapi/stat_example/StatExample.cc - example/cppapi/timeout_example/TimeoutExamplePlugin.cc - example/cppapi/transactionhook/TransactionHookPlugin.cc - example/cppapi/websocket/WebSocket.cc - example/cppapi/websocket/WebSocket.h - example/cppapi/websocket/WSBuffer.cc - example/cppapi/websocket/WSBuffer.h - example/disable_http2/disable_http2.cc - example/file_1/file_1.c - example/hello/hello.c - example/intercept/intercept.cc - example/lifecycle_plugin/lifecycle_plugin.c - example/null_transform/null_transform.c - example/output_header/output_header.c - example/passthru/passthru.cc - example/protocol/Protocol.c - example/protocol/Protocol.h - example/protocol/TxnSM.c - example/protocol/TxnSM.h - example/protocol_stack/protocol_stack.cc - example/query_remap/query_remap.c - example/redirect_1/redirect_1.c - example/remap/remap.cc - example/remap_header_add/remap_header_add.cc - example/replace_header/replace_header.c - example/response_header_1/response_header_1.c - example/secure_link/secure_link.c - example/server_push/server_push.c - example/server_transform/server_transform.c - example/session_hooks/session_hooks.c - example/ssl_preaccept/ssl_preaccept.cc - example/ssl_sni/ssl_sni.cc - example/ssl_sni_whitelist/ssl_sni_whitelist.cc - example/statistic/statistic.cc - example/thread_1/thread_1.c - example/thread_pool/include/gen.c - example/thread_pool/psi.c - example/thread_pool/thread.c - example/thread_pool/thread.h - example/txn_data_sink/txn_data_sink.c - example/version/version.c - iocore/aio/AIO.cc - iocore/aio/I_AIO.h - iocore/aio/Inline.cc - iocore/aio/P_AIO.h - iocore/aio/test_AIO.cc - iocore/dns/DNS.cc - iocore/dns/DNSConnection.cc - iocore/dns/I_DNS.h - iocore/dns/I_DNSProcessor.h - iocore/dns/I_SplitDNS.h - iocore/dns/I_SplitDNSProcessor.h - iocore/dns/Inline.cc - iocore/dns/P_DNS.h - iocore/dns/P_DNSConnection.h - iocore/dns/P_DNSProcessor.h - iocore/dns/P_SplitDNS.h - iocore/dns/P_SplitDNSProcessor.h - iocore/dns/SplitDNS.cc - iocore/dns/SRV.h - iocore/dns/test_I_DNS.cc - iocore/dns/test_P_DNS.cc - iocore/eventsystem/unit_tests/test_MIOBufferWriter.cc - iocore/eventsystem/EventSystem.cc - iocore/eventsystem/I_Action.h - iocore/eventsystem/I_Continuation.h - iocore/eventsystem/I_EThread.h - iocore/eventsystem/I_Event.h - iocore/eventsystem/I_EventProcessor.h - iocore/eventsystem/I_EventSystem.h - iocore/eventsystem/I_IOBuffer.h - iocore/eventsystem/I_Lock.h - iocore/eventsystem/I_MIOBufferWriter.h - iocore/eventsystem/I_PriorityEventQueue.h - iocore/eventsystem/I_Processor.h - iocore/eventsystem/I_ProtectedQueue.h - iocore/eventsystem/I_ProxyAllocator.h - iocore/eventsystem/I_SocketManager.h - iocore/eventsystem/I_Tasks.h - iocore/eventsystem/I_Thread.h - iocore/eventsystem/I_VConnection.h - iocore/eventsystem/I_VIO.h - iocore/eventsystem/Inline.cc - iocore/eventsystem/IOBuffer.cc - iocore/eventsystem/Lock.cc - iocore/eventsystem/P_EventSystem.h - iocore/eventsystem/P_Freer.h - iocore/eventsystem/P_IOBuffer.h - iocore/eventsystem/P_ProtectedQueue.h - iocore/eventsystem/P_Thread.h - iocore/eventsystem/P_UnixEThread.h - iocore/eventsystem/P_UnixEvent.h - iocore/eventsystem/P_UnixEventProcessor.h - iocore/eventsystem/P_UnixSocketManager.h - iocore/eventsystem/P_VConnection.h - iocore/eventsystem/P_VIO.h - iocore/eventsystem/PQ-List.cc - iocore/eventsystem/Processor.cc - iocore/eventsystem/ProtectedQueue.cc - iocore/eventsystem/ProxyAllocator.cc - iocore/eventsystem/SocketManager.cc - iocore/eventsystem/Tasks.cc - iocore/eventsystem/test_Buffer.cc - iocore/eventsystem/test_Event.cc - iocore/eventsystem/test_I_Buffer.cc - iocore/eventsystem/test_I_Event.cc - iocore/eventsystem/test_P_Buffer.cc - iocore/eventsystem/test_P_Event.cc - iocore/eventsystem/Thread.cc - iocore/eventsystem/UnixEThread.cc - iocore/eventsystem/UnixEvent.cc - iocore/eventsystem/UnixEventProcessor.cc - iocore/hostdb/HostDB.cc - iocore/hostdb/I_HostDB.h - iocore/hostdb/I_HostDBProcessor.h - iocore/hostdb/Inline.cc - iocore/hostdb/P_HostDB.h - iocore/hostdb/P_HostDBProcessor.h - iocore/hostdb/P_RefCountCache.h - iocore/hostdb/P_RefCountCacheSerializer.h - iocore/hostdb/RefCountCache.cc - iocore/hostdb/test_I_HostDB.cc - iocore/hostdb/test_P_HostDB.cc - iocore/hostdb/test_RefCountCache.cc - iocore/net/BIO_fastopen.cc - iocore/net/BIO_fastopen.h - iocore/net/Connection.cc - iocore/net/I_Net.h - iocore/net/I_NetProcessor.h - iocore/net/I_NetVConnection.h - iocore/net/I_SessionAccept.h - iocore/net/I_Socks.h - iocore/net/I_UDPConnection.h - iocore/net/I_UDPNet.h - iocore/net/I_UDPPacket.h - iocore/net/Inline.cc - iocore/net/YamlSNIConfig.cc - iocore/net/YamlSNIConfig.h - iocore/net/Net.cc - iocore/net/NetVConnection.cc - iocore/net/NetVCTest.cc - iocore/net/OCSPStapling.cc - iocore/net/P_CompletionUtil.h - iocore/net/P_Connection.h - iocore/net/P_InkBulkIO.h - iocore/net/P_LibBulkIO.h - iocore/net/P_Net.h - iocore/net/P_NetAccept.h - iocore/net/P_NetVConnection.h - iocore/net/P_NetVCTest.h - iocore/net/P_OCSPStapling.h - iocore/net/P_SNIActionPerformer.h - iocore/net/P_Socks.h - iocore/net/P_SSLCertLookup.h - iocore/net/P_SSLClientUtils.h - iocore/net/P_SSLConfig.h - iocore/net/P_SSLNetAccept.h - iocore/net/P_SSLNetProcessor.h - iocore/net/P_SSLNetVConnection.h - iocore/net/P_SSLNextProtocolAccept.h - iocore/net/P_SSLNextProtocolSet.h - iocore/net/P_SSLSNI.h - iocore/net/P_SSLUtils.h - iocore/net/P_UDPConnection.h - iocore/net/P_UDPIOEvent.h - iocore/net/P_UDPNet.h - iocore/net/P_UDPPacket.h - iocore/net/P_UnixCompletionUtil.h - iocore/net/P_UnixNet.h - iocore/net/P_UnixNetProcessor.h - iocore/net/P_UnixNetState.h - iocore/net/P_UnixNetVConnection.h - iocore/net/P_UnixPollDescriptor.h - iocore/net/P_UnixUDPConnection.h - iocore/net/SNIActionPerformer.cc - iocore/net/Socks.cc - iocore/net/SSLCertLookup.cc - iocore/net/SSLClientUtils.cc - iocore/net/SSLConfig.cc - iocore/net/SSLDynlock.cc - iocore/net/SSLDynlock.h - iocore/net/SSLInternal.cc - iocore/net/SSLNetAccept.cc - iocore/net/SSLNetProcessor.cc - iocore/net/SSLNetVConnection.cc - iocore/net/SSLNextProtocolAccept.cc - iocore/net/SSLNextProtocolSet.cc - iocore/net/SSLSessionCache.cc - iocore/net/SSLSessionCache.h - iocore/net/SSLSNIConfig.cc - iocore/net/SSLUtils.cc - iocore/net/test_certlookup.cc - iocore/net/test_I_Net.cc - iocore/net/test_I_UDPNet.cc - iocore/net/test_P_Net.cc - iocore/net/UDPIOEvent.cc - iocore/net/UnixConnection.cc - iocore/net/UnixNet.cc - iocore/net/UnixNetAccept.cc - iocore/net/UnixNetPages.cc - iocore/net/UnixNetProcessor.cc - iocore/net/UnixNetVConnection.cc - iocore/net/UnixUDPConnection.cc - iocore/net/UnixUDPNet.cc - iocore/utils/diags.i - iocore/utils/I_Machine.h - iocore/utils/I_OneWayMultiTunnel.h - iocore/utils/I_OneWayTunnel.h - iocore/utils/Machine.cc - iocore/utils/OneWayMultiTunnel.cc - iocore/utils/OneWayTunnel.cc - lib/records/I_RecAlarms.h - lib/records/I_RecCore.h - lib/records/I_RecDefs.h - lib/records/I_RecEvents.h - lib/records/I_RecHttp.h - lib/records/I_RecLocal.h - lib/records/I_RecMutex.h - lib/records/I_RecProcess.h - lib/records/I_RecSignals.h - lib/records/P_RecCore.cc - lib/records/P_RecCore.h - lib/records/P_RecDefs.h - lib/records/P_RecFile.h - lib/records/P_RecLocal.h - lib/records/P_RecMessage.h - lib/records/P_RecProcess.h - lib/records/P_RecUtils.h - lib/records/RecConfigParse.cc - lib/records/RecCore.cc - lib/records/RecDebug.cc - lib/records/RecFile.cc - lib/records/RecHttp.cc - lib/records/RecLocal.cc - lib/records/RecMessage.cc - lib/records/RecMutex.cc - lib/records/RecProcess.cc - lib/records/RecRawStats.cc - lib/records/RecUtils.cc - lib/records/test_I_RecLocal.cc - lib/records/test_I_RecProcess.cc - lib/records/test_P_RecProcess.cc - lib/records/test_RecordsConfig.cc - lib/records/test_RecordsConfig.h - lib/records/test_RecProcess.i - lib/records/test_RecTree.cc - src/wccp/wccp-test-router.cc - include/wccp/Wccp.h - src/wccp/WccpConfig.cc - src/wccp/WccpEndPoint.cc - src/wccp/WccpLocal.h - src/wccp/WccpMeta.h - src/wccp/WccpMsg.cc - src/wccp/WccpStatic.cc - src/wccp/WccpUtil.h - lib/ink_autoconf.h - mgmt/api/include/mgmtapi.h - mgmt/api/APITestCliRemote.cc - mgmt/api/CoreAPI.cc - mgmt/api/CoreAPI.h - mgmt/api/CoreAPIRemote.cc - mgmt/api/CoreAPIShared.cc - mgmt/api/CoreAPIShared.h - mgmt/api/EventCallback.cc - mgmt/api/EventCallback.h - mgmt/api/EventControlMain.cc - mgmt/api/EventControlMain.h - mgmt/api/INKMgmtAPI.cc - mgmt/api/NetworkMessage.cc - mgmt/api/NetworkMessage.h - mgmt/api/NetworkUtilsLocal.cc - mgmt/api/NetworkUtilsLocal.h - mgmt/api/NetworkUtilsRemote.cc - mgmt/api/NetworkUtilsRemote.h - mgmt/api/TSControlMain.cc - mgmt/api/TSControlMain.h - mgmt/utils/ExpandingArray.cc - mgmt/utils/ExpandingArray.h - mgmt/utils/MgmtHashTable.h - mgmt/utils/MgmtLocalCleanup.cc - mgmt/utils/MgmtMarshall.cc - mgmt/utils/MgmtMarshall.h - mgmt/utils/MgmtProcessCleanup.cc - mgmt/utils/MgmtSocket.cc - mgmt/utils/MgmtSocket.h - mgmt/utils/MgmtUtils.cc - mgmt/utils/MgmtUtils.h - mgmt/utils/test_marshall.cc - mgmt/Alarms.cc - mgmt/Alarms.h - mgmt/BaseManager.cc - mgmt/BaseManager.h - mgmt/FileManager.cc - mgmt/FileManager.h - mgmt/LocalManager.cc - mgmt/LocalManager.h - mgmt/MgmtDefs.h - mgmt/ProcessManager.cc - mgmt/ProcessManager.h - mgmt/ProxyConfig.cc - mgmt/ProxyConfig.h - mgmt/RecordsConfig.cc - mgmt/RecordsConfig.h - mgmt/RecordsConfigUtils.cc - mgmt/Rollback.cc - mgmt/Rollback.h - mgmt/WebMgmtUtils.cc - mgmt/WebMgmtUtils.h - plugins/authproxy/authproxy.cc - plugins/authproxy/utils.cc - plugins/authproxy/utils.h - plugins/background_fetch/background_fetch.cc - plugins/background_fetch/configs.cc - plugins/background_fetch/configs.h - plugins/background_fetch/headers.cc - plugins/background_fetch/headers.h - plugins/background_fetch/rules.cc - plugins/background_fetch/rules.h - plugins/cache_promote/cache_promote.cc - plugins/conf_remap/conf_remap.cc - plugins/esi/fetcher/FetchedDataProcessor.h - plugins/esi/fetcher/HttpDataFetcher.h - plugins/esi/fetcher/HttpDataFetcherImpl.cc - plugins/esi/fetcher/HttpDataFetcherImpl.h - plugins/esi/lib/Attribute.h - plugins/esi/lib/ComponentBase.h - plugins/esi/lib/DocNode.cc - plugins/esi/lib/DocNode.h - plugins/esi/lib/EsiGunzip.cc - plugins/esi/lib/EsiGunzip.h - plugins/esi/lib/EsiGzip.cc - plugins/esi/lib/EsiGzip.h - plugins/esi/lib/EsiParser.cc - plugins/esi/lib/EsiParser.h - plugins/esi/lib/EsiProcessor.cc - plugins/esi/lib/EsiProcessor.h - plugins/esi/lib/Expression.cc - plugins/esi/lib/Expression.h - plugins/esi/lib/FailureInfo.cc - plugins/esi/lib/FailureInfo.h - plugins/esi/lib/gzip.cc - plugins/esi/lib/gzip.h - plugins/esi/lib/HandlerManager.cc - plugins/esi/lib/HandlerManager.h - plugins/esi/lib/HttpHeader.h - plugins/esi/lib/IncludeHandlerFactory.h - plugins/esi/lib/SpecialIncludeHandler.h - plugins/esi/lib/Stats.cc - plugins/esi/lib/Stats.h - plugins/esi/lib/StringHash.h - plugins/esi/lib/Utils.cc - plugins/esi/lib/Utils.h - plugins/esi/lib/Variables.cc - plugins/esi/lib/Variables.h - plugins/esi/test/docnode_test.cc - plugins/esi/test/gzip_test.cc - plugins/esi/test/HandlerMap.cc - plugins/esi/test/HandlerMap.h - plugins/esi/test/parser_test.cc - plugins/esi/test/print_funcs.cc - plugins/esi/test/print_funcs.h - plugins/esi/test/processor_test.cc - plugins/esi/test/sampleProb.cc - plugins/esi/test/StubIncludeHandler.cc - plugins/esi/test/StubIncludeHandler.h - plugins/esi/test/TestHandlerManager.cc - plugins/esi/test/TestHttpDataFetcher.h - plugins/esi/test/utils_test.cc - plugins/esi/test/vars_test.cc - plugins/esi/combo_handler.cc - plugins/esi/esi.cc - plugins/esi/serverIntercept.cc - plugins/esi/serverIntercept.h - plugins/experimental/acme/acme.c - plugins/experimental/balancer/balancer.cc - plugins/experimental/balancer/balancer.h - plugins/experimental/balancer/hash.cc - plugins/experimental/balancer/roundrobin.cc - plugins/experimental/buffer_upload/buffer_upload.cc - plugins/experimental/cache_key_genid/cache_key_genid.c - plugins/experimental/cache_range_requests/cache_range_requests.cc - plugins/experimental/collapsed_forwarding/collapsed_forwarding.cc - plugins/experimental/custom_redirect/custom_redirect.cc - plugins/experimental/geoip_acl/acl.cc - plugins/experimental/geoip_acl/acl.h - plugins/experimental/geoip_acl/geoip_acl.cc - plugins/experimental/geoip_acl/lulu.h - plugins/experimental/header_freq/header_freq.cc - plugins/experimental/header_normalize/header_normalize.cc - plugins/experimental/hipes/gen_escape.c - plugins/experimental/hipes/hipes.cc - plugins/experimental/hook-trace/hook-trace.cc - plugins/experimental/inliner/ats-inliner.cc - plugins/experimental/inliner/cache-handler.h - plugins/experimental/inliner/cache.cc - plugins/experimental/inliner/cache.h - plugins/experimental/inliner/chunk-decoder.cc - plugins/experimental/inliner/chunk-decoder.h - plugins/experimental/inliner/fetcher.cc - plugins/experimental/inliner/fetcher.h - plugins/experimental/inliner/gif.h - plugins/experimental/inliner/html-parser.cc - plugins/experimental/inliner/html-parser.h - plugins/experimental/inliner/inliner-handler.cc - plugins/experimental/inliner/inliner-handler.h - plugins/experimental/inliner/jpeg.h - plugins/experimental/inliner/png.h - plugins/experimental/inliner/ts.cc - plugins/experimental/inliner/ts.h - plugins/experimental/inliner/util.h - plugins/experimental/inliner/vconnection.h - plugins/experimental/memcache/protocol_binary.h - plugins/experimental/memcache/tsmemcache.cc - plugins/experimental/memcache/tsmemcache.h - plugins/experimental/memcached_remap/memcached_remap.cc - plugins/experimental/metalink/metalink.cc - plugins/experimental/money_trace/money_trace.cc - plugins/experimental/money_trace/money_trace.h - plugins/experimental/mp4/mp4.cc - plugins/experimental/mp4/mp4_common.h - plugins/experimental/mp4/mp4_meta.cc - plugins/experimental/mp4/mp4_meta.h - plugins/experimental/multiplexer/ats-multiplexer.cc - plugins/experimental/multiplexer/chunk-decoder.cc - plugins/experimental/multiplexer/chunk-decoder.h - plugins/experimental/multiplexer/dispatch.cc - plugins/experimental/multiplexer/dispatch.h - plugins/experimental/multiplexer/fetcher.cc - plugins/experimental/multiplexer/fetcher.h - plugins/experimental/multiplexer/original-request.cc - plugins/experimental/multiplexer/original-request.h - plugins/experimental/multiplexer/post.cc - plugins/experimental/multiplexer/post.h - plugins/experimental/multiplexer/ts.cc - plugins/experimental/multiplexer/ts.h - plugins/experimental/mysql_remap/lib/dictionary.c - plugins/experimental/mysql_remap/lib/dictionary.h - plugins/experimental/mysql_remap/lib/iniparser.c - plugins/experimental/mysql_remap/lib/iniparser.h - plugins/experimental/mysql_remap/default.h - plugins/experimental/mysql_remap/mysql_remap.cc - plugins/experimental/remap_purge/remap_purge.c - plugins/experimental/remap_stats/remap_stats.c - plugins/experimental/server_push_preload/server_push_preload.cc - plugins/experimental/sslheaders/expand.cc - plugins/experimental/sslheaders/sslheaders.cc - plugins/experimental/sslheaders/sslheaders.h - plugins/experimental/sslheaders/test_sslheaders.cc - plugins/experimental/sslheaders/util.cc - plugins/experimental/stale_while_revalidate/stale_while_revalidate.c - plugins/experimental/stream_editor/stream_editor.cc - plugins/experimental/system_stats/system_stats.c - plugins/experimental/tls_bridge/regex.cc - plugins/experimental/tls_bridge/regex.h - plugins/experimental/tls_bridge/tls_bridge.cc - plugins/experimental/uri_signing/config.c - plugins/experimental/uri_signing/config.h - plugins/experimental/uri_signing/cookie.c - plugins/experimental/uri_signing/cookie.h - plugins/experimental/uri_signing/jwt.c - plugins/experimental/uri_signing/jwt.h - plugins/experimental/uri_signing/match.c - plugins/experimental/uri_signing/match.h - plugins/experimental/uri_signing/parse.c - plugins/experimental/uri_signing/parse.h - plugins/experimental/uri_signing/timing.c - plugins/experimental/uri_signing/timing.h - plugins/experimental/uri_signing/uri_signing.c - plugins/experimental/uri_signing/uri_signing.h - plugins/experimental/url_sig/url_sig.c - plugins/experimental/url_sig/url_sig.h - plugins/experimental/webp_transform/ImageTransform.cc - plugins/generator/generator.cc - plugins/header_rewrite/condition.cc - plugins/header_rewrite/condition.h - plugins/header_rewrite/conditions.cc - plugins/header_rewrite/conditions.h - plugins/header_rewrite/expander.cc - plugins/header_rewrite/expander.h - plugins/header_rewrite/factory.cc - plugins/header_rewrite/factory.h - plugins/header_rewrite/header_rewrite.cc - plugins/header_rewrite/header_rewrite_test.cc - plugins/header_rewrite/lulu.cc - plugins/header_rewrite/lulu.h - plugins/header_rewrite/matcher.h - plugins/header_rewrite/operator.cc - plugins/header_rewrite/operator.h - plugins/header_rewrite/operators.cc - plugins/header_rewrite/operators.h - plugins/header_rewrite/parser.cc - plugins/header_rewrite/parser.h - plugins/header_rewrite/regex_helper.cc - plugins/header_rewrite/regex_helper.h - plugins/header_rewrite/resources.cc - plugins/header_rewrite/resources.h - plugins/header_rewrite/ruleset.cc - plugins/header_rewrite/ruleset.h - plugins/header_rewrite/statement.cc - plugins/header_rewrite/statement.h - plugins/header_rewrite/value.h - plugins/healthchecks/healthchecks.c - plugins/libloader/libloader.c - plugins/lua/ts_lua.c - plugins/lua/ts_lua_cached_response.c - plugins/lua/ts_lua_cached_response.h - plugins/lua/ts_lua_client_request.c - plugins/lua/ts_lua_client_request.h - plugins/lua/ts_lua_client_response.c - plugins/lua/ts_lua_client_response.h - plugins/lua/ts_lua_common.h - plugins/lua/ts_lua_constant.c - plugins/lua/ts_lua_constant.h - plugins/lua/ts_lua_context.c - plugins/lua/ts_lua_context.h - plugins/lua/ts_lua_coroutine.c - plugins/lua/ts_lua_coroutine.h - plugins/lua/ts_lua_crypto.c - plugins/lua/ts_lua_crypto.h - plugins/lua/ts_lua_fetch.c - plugins/lua/ts_lua_fetch.h - plugins/lua/ts_lua_hook.c - plugins/lua/ts_lua_hook.h - plugins/lua/ts_lua_http.c - plugins/lua/ts_lua_http.h - plugins/lua/ts_lua_http_cntl.c - plugins/lua/ts_lua_http_cntl.h - plugins/lua/ts_lua_http_config.c - plugins/lua/ts_lua_http_config.h - plugins/lua/ts_lua_http_intercept.c - plugins/lua/ts_lua_http_intercept.h - plugins/lua/ts_lua_http_milestone.c - plugins/lua/ts_lua_http_milestone.h - plugins/lua/ts_lua_io.c - plugins/lua/ts_lua_io.h - plugins/lua/ts_lua_log.c - plugins/lua/ts_lua_log.h - plugins/lua/ts_lua_mgmt.c - plugins/lua/ts_lua_mgmt.h - plugins/lua/ts_lua_misc.c - plugins/lua/ts_lua_misc.h - plugins/lua/ts_lua_package.c - plugins/lua/ts_lua_package.h - plugins/lua/ts_lua_remap.c - plugins/lua/ts_lua_remap.h - plugins/lua/ts_lua_server_request.c - plugins/lua/ts_lua_server_request.h - plugins/lua/ts_lua_server_response.c - plugins/lua/ts_lua_server_response.h - plugins/lua/ts_lua_stat.c - plugins/lua/ts_lua_stat.h - plugins/lua/ts_lua_string.c - plugins/lua/ts_lua_string.h - plugins/lua/ts_lua_transform.c - plugins/lua/ts_lua_transform.h - plugins/lua/ts_lua_util.c - plugins/lua/ts_lua_util.h - plugins/regex_remap/regex_remap.cc - plugins/regex_revalidate/regex_revalidate.c - plugins/s3_auth/unit_tests/test_aws_auth_v4.cc - plugins/s3_auth/unit_tests/test_aws_auth_v4.h - plugins/s3_auth/aws_auth_v4.cc - plugins/s3_auth/aws_auth_v4.h - plugins/s3_auth/aws_auth_v4_wrap.h - plugins/s3_auth/s3_auth.cc - plugins/stats_over_http/stats_over_http.c - plugins/tcpinfo/tcpinfo.cc - plugins/xdebug/xdebug.cc - include/ts/experimental.h - include/ts/InkAPIPrivateIOCore.h - include/ts/remap.h - include/ts/ts.h - include/ts/TsException.h - proxy/hdrs/HdrHeap.cc - proxy/hdrs/HdrHeap.h - proxy/hdrs/HdrTest.cc - proxy/hdrs/HdrTest.h - proxy/hdrs/HdrToken.cc - proxy/hdrs/HdrToken.h - proxy/hdrs/HdrTSOnly.cc - proxy/hdrs/HdrUtils.cc - proxy/hdrs/HdrUtils.h - proxy/hdrs/HTTP.cc - proxy/hdrs/HTTP.h - proxy/hdrs/HttpCompat.cc - proxy/hdrs/HttpCompat.h - proxy/hdrs/load_http_hdr.cc - proxy/hdrs/MIME.cc - proxy/hdrs/MIME.h - proxy/hdrs/test_mime.cc - proxy/hdrs/test_urlhash.cc - proxy/hdrs/URL.cc - proxy/hdrs/URL.h - proxy/http/remap/AclFiltering.cc - proxy/http/remap/AclFiltering.h - proxy/http/remap/RemapConfig.cc - proxy/http/remap/RemapConfig.h - proxy/http/remap/RemapPluginInfo.cc - proxy/http/remap/RemapPluginInfo.h - proxy/http/remap/RemapPlugins.cc - proxy/http/remap/RemapPlugins.h - proxy/http/remap/RemapProcessor.cc - proxy/http/remap/RemapProcessor.h - proxy/http/remap/UrlMapping.cc - proxy/http/remap/UrlMapping.h - proxy/http/remap/UrlMappingPathIndex.cc - proxy/http/remap/UrlMappingPathIndex.h - proxy/http/remap/UrlRewrite.cc - proxy/http/remap/UrlRewrite.h - proxy/http/unit_tests/test_ForwardedConfig.cc - proxy/http/unit_tests/test_ForwardedConfig_mocks.cc - proxy/http/ForwardedConfig.cc - proxy/http/Http1ClientSession.cc - proxy/http/Http1ClientSession.h - proxy/http/Http1ClientTransaction.cc - proxy/http/Http1ClientTransaction.h - proxy/http/HttpBodyFactory.cc - proxy/http/HttpBodyFactory.h - proxy/http/HttpCacheSM.cc - proxy/http/HttpCacheSM.h - proxy/http/HttpConfig.cc - proxy/http/HttpConfig.h - proxy/http/HttpConnectionCount.cc - proxy/http/HttpConnectionCount.h - proxy/http/HttpDebugNames.cc - proxy/http/HttpDebugNames.h - proxy/http/HttpPages.cc - proxy/http/HttpPages.h - proxy/http/HttpProxyAPIEnums.h - proxy/http/HttpProxyServerMain.cc - proxy/http/HttpProxyServerMain.h - proxy/http/HttpServerSession.cc - proxy/http/HttpServerSession.h - proxy/http/HttpSessionAccept.cc - proxy/http/HttpSessionAccept.h - proxy/http/HttpSessionManager.cc - proxy/http/HttpSessionManager.h - proxy/http/HttpSM.cc - proxy/http/HttpSM.h - proxy/http/HttpTransact.cc - proxy/http/HttpTransact.h - proxy/http/HttpTransactCache.cc - proxy/http/HttpTransactCache.h - proxy/http/HttpTransactHeaders.cc - proxy/http/HttpTransactHeaders.h - proxy/http/HttpTunnel.cc - proxy/http/HttpTunnel.h - proxy/http/HttpUpdateSM.cc - proxy/http/HttpUpdateSM.h - proxy/http/HttpUpdateTester.cc - proxy/http/RegressionHttpTransact.cc - proxy/http/test_socket_close.cc - proxy/http/testheaders.cc - proxy/http/TestUrl.cc - proxy/http2/HPACK.cc - proxy/http2/HPACK.h - proxy/http2/HTTP2.cc - proxy/http2/HTTP2.h - proxy/http2/Http2ClientSession.cc - proxy/http2/Http2ClientSession.h - proxy/http2/Http2ConnectionState.cc - proxy/http2/Http2ConnectionState.h - proxy/http2/Http2DebugNames.cc - proxy/http2/Http2DebugNames.h - proxy/http2/Http2DependencyTree.h - proxy/http2/Http2SessionAccept.cc - proxy/http2/Http2SessionAccept.h - proxy/http2/Http2Stream.cc - proxy/http2/Http2Stream.h - proxy/http2/HuffmanCodec.cc - proxy/http2/HuffmanCodec.h - proxy/http2/RegressionHPACK.cc - proxy/http2/test_HPACK.cc - proxy/http2/test_Http2DependencyTree.cc - proxy/http2/test_Huffmancode.cc - proxy/logging/Log.cc - proxy/logging/Log.h - proxy/logging/LogAccess.cc - proxy/logging/LogAccess.h - proxy/logging/LogAccessTest.cc - proxy/logging/LogAccessTest.h - proxy/logging/LogBuffer.cc - proxy/logging/LogBuffer.h - proxy/logging/LogBufferSink.h - proxy/logging/LogCollationAccept.cc - proxy/logging/LogCollationAccept.h - proxy/logging/LogCollationBase.h - proxy/logging/LogCollationClientSM.cc - proxy/logging/LogCollationClientSM.h - proxy/logging/LogCollationHostSM.cc - proxy/logging/LogCollationHostSM.h - proxy/logging/LogConfig.cc - proxy/logging/LogConfig.h - proxy/logging/LogField.cc - proxy/logging/LogField.h - proxy/logging/LogFieldAliasMap.cc - proxy/logging/LogFieldAliasMap.h - proxy/logging/LogFile.cc - proxy/logging/LogFile.h - proxy/logging/LogFilter.cc - proxy/logging/LogFilter.h - proxy/logging/LogFormat.cc - proxy/logging/LogFormat.h - proxy/logging/LogHost.cc - proxy/logging/LogHost.h - proxy/logging/LogLimits.h - proxy/logging/LogObject.cc - proxy/logging/LogObject.h - proxy/logging/LogSock.cc - proxy/logging/LogSock.h - proxy/logging/LogStandalone.cc - proxy/logging/LogUtils.cc - proxy/logging/LogUtils.h - proxy/logging/test_LogUtils.cc - proxy/shared/DiagsConfig.cc - proxy/shared/DiagsConfig.h - proxy/shared/UglyLogStubs.cc - proxy/CacheControl.cc - proxy/CacheControl.h - proxy/ControlBase.cc - proxy/ControlBase.h - proxy/ControlMatcher.cc - proxy/ControlMatcher.h - proxy/InkAPIInternal.h - proxy/IPAllow.cc - proxy/IPAllow.h - proxy/Main.h - proxy/Milestones.h - proxy/ParentConsistentHash.cc - proxy/ParentConsistentHash.h - proxy/ParentRoundRobin.cc - proxy/ParentRoundRobin.h - proxy/ParentSelection.cc - proxy/ParentSelection.h - proxy/ParentSelectionStrategy.cc - proxy/Plugin.cc - proxy/Plugin.h - proxy/PluginVC.cc - proxy/PluginVC.h - proxy/ProtocolProbeSessionAccept.cc - proxy/ProtocolProbeSessionAccept.h - proxy/ProxyClientSession.cc - proxy/ProxyClientSession.h - proxy/ProxyClientTransaction.cc - proxy/ProxyClientTransaction.h - proxy/RegressionSM.cc - proxy/RegressionSM.h - proxy/ReverseProxy.cc - proxy/ReverseProxy.h - proxy/Show.h - proxy/StatPages.cc - proxy/StatPages.h - proxy/TimeTrace.h - proxy/Transform.cc - proxy/Transform.h - proxy/TransformInternal.h - tests/gold_tests/tls/ssl-post.c - tests/include/catch.hpp - tests/tools/plugins/continuations_verify.cc - tests/tools/plugins/custom204plugin.cc - tests/tools/plugins/null_transform.c - tests/tools/plugins/ssl_hook_test.cc - tests/tools/plugins/ssntxnorder_verify.cc - tools/http_load/http_load.c - tools/http_load/port.h - tools/http_load/timers.c - tools/http_load/timers.h - tools/jtest/jtest.cc) - -add_library(libtscore SHARED - include/tscore/Allocator.h - src/tscore/Arena.cc - include/tscore/Arena.h - src/tscore/BaseLogFile.cc - include/tscore/BaseLogFile.h - src/tscore/Bitops.cc - include/tscore/Bitops.h - include/tscore/bwf_std_format.h - include/tscore/BufferWriter.h - include/tscore/BufferWriterForward.h - src/tscore/BufferWriterFormat.cc - src/tscore/CompileParseRules.cc - src/tscore/ConsistentHash.cc - include/tscore/ConsistentHash.h - src/tscore/ContFlags.cc - include/tscore/ContFlags.h - src/tscore/CryptoHash.cc - include/tscore/CryptoHash.h - include/tscore/defalloc.h - src/tscore/Diags.cc - include/tscore/Diags.h - include/tscore/DynArray.h - src/tscore/EventNotify.cc - include/tscore/EventNotify.h - src/tscore/fastlz.c - include/tscore/fastlz.h - src/tscore/Hash.cc - include/tscore/Hash.h - src/tscore/HashFNV.cc - include/tscore/HashFNV.h - src/tscore/HashMD5.cc - include/tscore/HashMD5.h - src/tscore/HashSip.cc - include/tscore/HashSip.h - include/tscore/History.h - src/tscore/HostLookup.cc - include/tscore/HostLookup.h - src/tscore/hugepages.cc - include/tscore/hugepages.h - include/tscore/I_Layout.h - include/tscore/I_Version.h - include/tscore/ink_aiocb.h - include/tscore/ink_align.h - src/tscore/ink_args.cc - include/tscore/ink_args.h - src/tscore/ink_assert.cc - include/tscore/ink_assert.h - include/tscore/ink_atomic.h - src/tscore/ink_base64.cc - include/tscore/ink_base64.h - src/tscore/ink_cap.cc - include/tscore/ink_cap.h - src/tscore/ink_code.cc - include/tscore/ink_code.h - include/tscore/ink_config.h - src/tscore/ink_defs.cc - include/tscore/ink_defs.h - src/tscore/ink_error.cc - include/tscore/ink_error.h - include/tscore/ink_exception.h - src/tscore/ink_file.cc - include/tscore/ink_file.h - src/tscore/ink_hash_table.cc - include/tscore/ink_hash_table.h - src/tscore/ink_hrtime.cc - include/tscore/ink_hrtime.h - src/tscore/ink_inet.cc - include/tscore/ink_inet.h - include/tscore/ink_inout.h - include/tscore/ink_llqueue.h - include/tscore/ink_lockfile.h - include/tscore/INK_MD5.h - src/tscore/ink_memory.cc - include/tscore/ink_memory.h - src/tscore/ink_mutex.cc - include/tscore/ink_mutex.h - include/tscore/ink_platform.h - src/tscore/ink_queue.cc - include/tscore/ink_queue.h - src/tscore/ink_queue_utils.cc - src/tscore/ink_rand.cc - include/tscore/ink_rand.h - src/tscore/ink_res_init.cc - src/tscore/ink_res_mkquery.cc - include/tscore/ink_resolver.h - src/tscore/ink_resource.cc - include/tscore/ink_resource.h - src/tscore/ink_rwlock.cc - include/tscore/ink_rwlock.h - src/tscore/ink_sock.cc - include/tscore/ink_sock.h - src/tscore/ink_sprintf.cc - include/tscore/ink_sprintf.h - src/tscore/ink_stack_trace.cc - include/tscore/ink_stack_trace.h - src/tscore/ink_string++.cc - include/tscore/ink_string++.h - src/tscore/ink_string.cc - include/tscore/ink_string.h - src/tscore/ink_sys_control.cc - include/tscore/ink_sys_control.h - src/tscore/ink_syslog.cc - include/tscore/ink_syslog.h - src/tscore/ink_thread.cc - include/tscore/ink_thread.h - src/tscore/ink_time.cc - include/tscore/ink_time.h - src/tscore/ink_uuid.cc - include/tscore/ink_uuid.h - src/tscore/InkErrno.cc - include/tscore/InkErrno.h - include/tscore/IntrusiveDList.h - include/tscore/IntrusiveHashMap.h - src/tscore/IntrusivePtrTest.cc - src/tscore/IpMap.cc - include/tscore/IpMap.h - src/tscore/IpMapConf.cc - include/tscore/IpMapConf.h - src/tscore/Layout.cc - include/tscore/List.h - src/tscore/llqueue.cc - src/tscore/load_http_hdr.cc - src/tscore/lockfile.cc - include/tscore/Map.h - src/tscore/MatcherUtils.cc - include/tscore/MatcherUtils.h - include/tscore/MemArena.h - src/tscore/MemArena.cc - include/tscore/MemSpan.h - src/tscore/mkdfa.c - src/tscore/MMH.cc - include/tscore/MMH.h - include/tscore/MT_hashtable.h - src/tscore/ParseRules.cc - include/tscore/ParseRules.h - include/tscore/PriorityQueue.h - include/tscore/Ptr.h - src/tscore/RawHashTable.cc - include/tscore/RawHashTable.h - src/tscore/RbTree.cc - include/tscore/RbTree.h - src/tscore/Regex.cc - include/tscore/Regex.h - src/tscore/Regression.cc - include/tscore/Regression.h - include/tscore/Result.h - src/tscore/runroot.cc - include/tscore/runroot.h - include/tscore/Scalar.h - include/tscore/SHA256.h - src/tscore/signals.cc - include/tscore/signals.h - include/tscore/SimpleTokenizer.h - src/tscore/SourceLocation.cc - include/tscore/SourceLocation.h - src/tscore/test_arena.cc - src/tscore/test_atomic.cc - src/tscore/test_freelist.cc - src/tscore/test_geometry.cc - src/tscore/test_List.cc - src/tscore/test_Map.cc - src/tscore/test_PriorityQueue.cc - src/tscore/test_Vec.cc - src/tscore/test_X509HostnameValidator.cc - include/tscore/TestBox.h - src/tscore/TestHttpHeader.cc - src/tscore/tests.cc - src/tscore/TextBuffer.cc - include/tscore/TextBuffer.h - include/tscpp/util/TextView.h - src/tscore/Tokenizer.cc - include/tscore/Tokenizer.h - include/tscore/Trie.h - include/tscore/TsBuffer.h - src/tscore/Version.cc - src/tscore/X509HostnameValidator.cc - include/tscore/X509HostnameValidator.h -) - -add_executable(test_tscore - src/tscore/unit_tests/unit_test_main.cc - src/tscore/unit_tests/test_BufferWriter.cc - src/tscore/unit_tests/test_BufferWriterFormat.cc - src/tscore/unit_tests/test_History.cc - src/tscore/unit_tests/test_ink_inet.cc - src/tscore/unit_tests/test_IntrusiveDList.cc - src/tscore/unit_tests/test_IntrusiveHashMap.cc - src/tscore/unit_tests/test_IntrusivePtr.cc - src/tscore/unit_tests/test_IpMap.cc - src/tscore/unit_tests/test_layout.cc - src/tscore/unit_tests/test_MemArena.cc - src/tscore/unit_tests/test_MemSpan.cc - src/tscore/unit_tests/test_MT_hashtable.cc - src/tscore/unit_tests/test_Ptr.cc - src/tscore/unit_tests/test_Regex.cc - src/tscore/unit_tests/test_Scalar.cc - src/tscore/unit_tests/test_scoped_resource.cc -) - -# iocore/cache -add_library(libcache SHARED - iocore/cache/Cache.cc - iocore/cache/CacheDir.cc - iocore/cache/CacheDisk.cc - iocore/cache/CacheHosting.cc - iocore/cache/CacheHttp.cc - iocore/cache/CacheLink.cc - iocore/cache/CachePages.cc - iocore/cache/CachePagesInternal.cc - iocore/cache/CacheRead.cc - iocore/cache/CacheTest.cc - iocore/cache/CacheVol.cc - iocore/cache/CacheWrite.cc - iocore/cache/I_Cache.h - iocore/cache/I_CacheDefs.h - iocore/cache/I_Store.h - iocore/cache/Inline.cc - iocore/cache/P_Cache.h - iocore/cache/P_CacheArray.h - iocore/cache/P_CacheBC.h - iocore/cache/P_CacheDir.h - iocore/cache/P_CacheDisk.h - iocore/cache/P_CacheHosting.h - iocore/cache/P_CacheHttp.h - iocore/cache/P_CacheInternal.h - iocore/cache/P_CacheTest.h - iocore/cache/P_CacheVol.h - iocore/cache/P_RamCache.h - iocore/cache/RamCacheCLFUS.cc - iocore/cache/RamCacheLRU.cc - iocore/cache/Store.cc -) - -add_library(libtsconfig SHARED - lib/tsconfig/Errata.cc - lib/tsconfig/Errata.h - lib/tsconfig/IntrusivePtr.h - lib/tsconfig/NumericType.h - lib/tsconfig/test-tsconfig.cc - lib/tsconfig/TsBuilder.cc - lib/tsconfig/TsBuilder.h - lib/tsconfig/TsConfigGrammar.c - lib/tsconfig/TsConfigGrammar.h - lib/tsconfig/TsConfigLexer.h - lib/tsconfig/TsConfigParseEvents.h - lib/tsconfig/TsConfigSyntax.c - lib/tsconfig/TsConfigTypes.h - lib/tsconfig/TsErrataUtil.cc - lib/tsconfig/TsErrataUtil.h - lib/tsconfig/TsValue.cc - lib/tsconfig/TsValue.h -) - -# Plugins -add_library(plugin_compress SHARED - plugins/compress/configuration.cc - plugins/compress/configuration.h - plugins/compress/debug_macros.h - plugins/compress/compress.cc - plugins/compress/misc.cc - plugins/compress/misc.h -) - -add_library(plugin_cachekey SHARED - plugins/cachekey/tests/pattern_test.cc - plugins/cachekey/cachekey.cc - plugins/cachekey/cachekey.h - plugins/cachekey/common.cc - plugins/cachekey/common.h - plugins/cachekey/configs.cc - plugins/cachekey/configs.h - plugins/cachekey/pattern.cc - plugins/cachekey/pattern.h - plugins/cachekey/plugin.cc - ) - -add_library(plugin_escalate SHARED - plugins/escalate/escalate.cc +macro(CC_EXEC exec path) + file(GLOB cc_exec_files ${path}/*.cc ${path}/*.h) + add_executable(${exec} ${cc_exec_files}) +endmacro(CC_EXEC) + +macro(CPP_LIB name src_path inc_path) + file(GLOB cc_lib_files ${inc_path}/*.h ${src_path}/*.cc ${src_path}/*.h ${src_path}/unit_tests/*.cc) + add_library(${name} SHARED ${cc_lib_files}) +endmacro(CPP_LIB) + +macro(CPP_ADD_SOURCES target path) + file(GLOB cpp_add_src_files ${path}/*.h ${path}/*.cc) + target_sources(${target} PUBLIC ${cpp_add_src_files}) +endmacro(CPP_ADD_SOURCES) + +CC_EXEC(traffic_crashlog src/traffic_crashlog) +CC_EXEC(traffic_server src/traffic_server) +CC_EXEC(traffic_manager src/traffic_manager) +CC_EXEC(traffic_cache_tool src/traffic_cache_tool) +CC_EXEC(traffic_ctl src/traffic_ctl) + +CPP_LIB(tscore src/tscore include/tscore) +CPP_LIB(tscpputil src/tscpp/util include/tscpp/util) +CPP_LIB(tscppapi src/tscpp/api include/tscpp/api) + +CPP_LIB(proxy proxy proxy) +CPP_ADD_SOURCES(proxy proxy/http) +CPP_ADD_SOURCES(proxy proxy/http2) +CPP_ADD_SOURCES(proxy proxy/http/remap) +CPP_ADD_SOURCES(proxy proxy/hdrs) + +CPP_LIB(iocore iocore iocore) +CPP_ADD_SOURCES(iocore iocore/eventsystem) +CPP_ADD_SOURCES(iocore iocore/net) +CPP_ADD_SOURCES(iocore iocore/cache) +CPP_ADD_SOURCES(iocore iocore/aio) +CPP_ADD_SOURCES(iocore iocore/dns) +CPP_ADD_SOURCES(iocore iocore/hostdb) +CPP_ADD_SOURCES(iocore iocore/utils) + +CPP_LIB(mgmt mgmt mgmt) +CPP_ADD_SOURCES(mgmt mgmt/api) +CPP_ADD_SOURCES(mgmt mgmt/utils) + +CPP_LIB(tsconfig lib/tsconfig lib/tsconfig) +CPP_LIB(wccp src/wccp include/wccp) + +file(GLOB plugin_files + plugins/*/*.h + plugins/*/*.c + plugins/*/*.cc + plugins/experimental/*.h + plugins/experimental/*.c + plugins/experimental/*.cc + example/*/*.h + example/*/*.c + example/*/*.cc ) +add_library(plugins SHARED ${plugin_files}) -# CacheTool -add_executable(traffic_cache_tool - src/traffic_cache_tool/CacheStore.h - src/traffic_cache_tool/CacheDefs.h - src/traffic_cache_tool/CacheDefs.cc - src/traffic_cache_tool/CacheTool.cc - src/traffic_cache_tool/Command.h - src/traffic_cache_tool/Command.cc - src/traffic_cache_tool/File.h - src/traffic_cache_tool/File.cc -) diff --git a/doc/developer-guide/internal-libraries/Lexicon.en.rst b/doc/developer-guide/internal-libraries/Lexicon.en.rst new file mode 100644 index 00000000000..f96b19a2f49 --- /dev/null +++ b/doc/developer-guide/internal-libraries/Lexicon.en.rst @@ -0,0 +1,160 @@ +.. 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:: ../../common.defs + +.. default-domain:: cpp + +Lexicon +******* + +Synopsis +======== + +:code:`#include ` + +:class:`Lexicon` is a template class designed to facilitate conversions between enumerations and +strings. Each enumeration can have a **primary** name and an arbitrary number of **secondary** +names. Enumerations convert to the primary name, and all the names convert to the enumeration. +Defaults can also be set such that a conversion for a name or enumeration that isn't defined yields +the default. All comparisons are case insensitive. + +Description +=========== + +A :class:`Lexicon` is a template class with a single type, which should be a numeric type, usually +an enumeration. An instance contains a set of **definitions**, each of which is an association +between a value, a primary name, and secondary names, the last of which is optional. All names and +values must be unique across the :class:`Lexicon`. The array operator is used to do the conversions. +When indexed by a value, the primary name for that value is returned. When indexed by a name, the +primary name or any secondary name will yield the same value. + +Defaults can be set so that any name or value that does not match a definition yields the default. A +default can set for names or values independently. A default can be explicit or it can be a function +which is called when the :class:`Lexicon` is indexed by a non-matching index. The handler function +must return a default of the appropriate type. It acts as an internal catch for undefined +conversions and is generally used to log the failure while returning a default. It could be used to +compute a default but in the case of names, this is problematic due to memory ownership and thread +safety issues. Because the return type of a name is :code:`std::string_view` there is no signal to +cleanup any allocated memory, and storing the name in the :class:`Lexicon` instance makes it +non-thread safe on read access [#]_. + +Definitions can be added by the :func:`Lexicon::define` method. Usually a :class:`Lexicon` will be +constructed with the definitions. Two types of such construction are supported, both of them taking +an initializer list of definitions. The definitions may be a pair of enumeration and primary name, +or the definitions may be an enumeration and an initializer list of names, the first of which is the +primary name. Because initializer lists must be homogenous, all definitions must be of the same +type. + +When initialized and defaults set, a :class:`Lexicon` makes it very easy to convert between +enumeration values and strings for debugging and configuration handling, particularly if the +enumeration has a value for invalid. Checking input strings is then simply indexing the +:class:`Lexicon` with the string - if it's valid the appropriate enumeration value is returned, +otherwise the invalid value is returned as the default. + +Construction is normally done by initializer lists, as these are easier to work with. There are +two forms, either pairs of value, name or pairs of value, list-of-names. The former is simpler +and sufficient if only primary names are to be defined, but the latter is required if secondary +names are present. In addition similar construction using :code:`std::array` is provided. This +is a bit clunkier, but does enable compile time verification that all values are defined. + +Examples +======== + +Assume the enumeration is + +.. literalinclude:: ../../../lib/ts/unit-tests/test_Lexicon.cc + :lines: 30 + +A :class:`Lexicon` for this could be defined as + +.. literalinclude:: ../../../lib/ts/unit-tests/test_Lexicon.cc + :lines: 32 + +An instance could be constructed, with primary and secondary names, as + +.. literalinclude:: ../../../lib/ts/unit-tests/test_Lexicon.cc + :lines: 36-40 + +Note there are no secondary names for ``INVALID`` but the list form must be used. If no secondary +names are needed, it could be done this way + +.. literalinclude:: ../../../lib/ts/unit-tests/test_Lexicon.cc + :lines: 42-46 + +Assuming the first case with secondary names is used, it would be helpful to set defaults so that +undefined names or values map to the invalid case. + +.. literalinclude:: ../../../lib/ts/unit-tests/test_Lexicon.cc + :lines: 48 + +With this initialization, these checks all succeed + +.. literalinclude:: ../../../lib/ts/unit-tests/test_Lexicon.cc + :lines: 50-59 + +A bit more complex initialization can be used in cases where verifying all of the values in an +enumeration are covered by the :class:`Lexicon`. There is a special constructor for this that +takes an extra argument, :code:`Require<>`. The API is designed with the presumption there is a "LAST_VALUE" +in the enumeration which can be used for size. For example, something like + +.. literalinclude:: ../../../lib/ts/unit-tests/test_Lexicon.cc + :lines: 62 + +with the :class:`Lexicon` specialization as + +.. literalinclude:: ../../../lib/ts/unit-tests/test_Lexicon.cc + :lines: 63 + +To cover everything (except the last value, which would normally be handled by the default), the +initialization would be + +.. literalinclude:: ../../../lib/ts/unit-tests/test_Lexicon.cc + :lines: 64-68 + +If there is am missing value, this fails to compile with a "ts::Lexicon::Definition::value’ +is uninitialized reference". + +Reference +========= + +.. class:: template < typename T > Lexicon + + A bidirectional converter between enumerations of :code:`T` and strings. + + .. function:: T operator [] (std::string_view name) + + Return the enumeration associated with :arg:`name`. If :arg:`name` is not in a definition and + no default has been set, :code:`std::domain_error` is thrown. + + .. function:: std::string_view operator [] (T value) + + Return the primary name associated with :arg:`value`. If :arg:`value` is not in a definition + and no default has been set, :code:`std::domain_error` is thrown. + + .. function:: Lexicon & define(T value, std::string_view primary, ... ) + + Add a definition. The :arg:`value` is associated with the :arg:`primary` name. An arbitrary + number of additional secondary names may be provided. + +Appendix +======== + +.. rubric:: Footnotes + +.. [#] + + The original implementation predated `std::string_view` and so returned `std::string`. While this + generation of names for unmatched values easy, it did have a performance cost. In this version I + chose to use :code:`std::string_view` which makes the default handler functions not as useful, + but still, in my view, sufficiently useful (for logging at least) to be worth supporting. diff --git a/doc/developer-guide/internal-libraries/index.en.rst b/doc/developer-guide/internal-libraries/index.en.rst index 0800562e04a..803153d9d40 100644 --- a/doc/developer-guide/internal-libraries/index.en.rst +++ b/doc/developer-guide/internal-libraries/index.en.rst @@ -34,6 +34,7 @@ development team. buffer-writer.en intrusive-list.en intrusive-hash-map.en + Lexicon.en MemArena.en AcidPtr.en Extendible.en diff --git a/include/tscore/Hash.h b/include/tscore/Hash.h index 68879a93951..d54682e9598 100644 --- a/include/tscore/Hash.h +++ b/include/tscore/Hash.h @@ -57,9 +57,30 @@ struct ATSHash : ATSHashBase { struct ATSHash32 : ATSHashBase { virtual uint32_t get(void) const = 0; virtual bool operator==(const ATSHash32 &) const; + uint32_t hash_immediate(void *data, size_t len); }; struct ATSHash64 : ATSHashBase { virtual uint64_t get(void) const = 0; virtual bool operator==(const ATSHash64 &) const; + uint64_t hash_immediate(void *data, size_t len); }; + +// ---- +// Implementation + +inline uint32_t +ATSHash32::hash_immediate(void *data, size_t len) +{ + this->update(data, len); + this->final(); + return this->get(); +} + +inline uint64_t +ATSHash64::hash_immediate(void *data, size_t len) +{ + this->update(data, len); + this->final(); + return this->get(); +} diff --git a/include/tscore/HashFNV.h b/include/tscore/HashFNV.h index e113d0cd012..d09c219a4ef 100644 --- a/include/tscore/HashFNV.h +++ b/include/tscore/HashFNV.h @@ -5,7 +5,7 @@ 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 + regarding copyright ownership. The ASF licenses this fileN 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 @@ -31,63 +31,88 @@ #include struct ATSHash32FNV1a : ATSHash32 { +protected: + using super_type = ATSHash32; + using nullxfrm = ATSHash::nullxfrm; + +public: ATSHash32FNV1a(void); - template void update(const void *data, size_t len, Transform xfrm); - void - update(const void *data, size_t len) override - { - update(data, len, ATSHash::nullxfrm()); - } + template void update(const void *data, size_t len, const Transform &xf); + + void update(const void *data, size_t len) override; void final(void) override; uint32_t get(void) const override; void clear(void) override; + template uint32_t hash_immediate(const void *data, size_t len, const Transform &xf); + private: uint32_t hval; }; -template -void -ATSHash32FNV1a::update(const void *data, size_t len, Transform xfrm) -{ - uint8_t *bp = (uint8_t *)data; - uint8_t *be = bp + len; - - for (; bp < be; ++bp) { - hval ^= (uint32_t)xfrm(*bp); - hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24); - } -} - struct ATSHash64FNV1a : ATSHash64 { ATSHash64FNV1a(void); template void update(const void *data, size_t len, Transform xfrm); - void - update(const void *data, size_t len) override - { - update(data, len, ATSHash::nullxfrm()); - } + void update(const void *data, size_t len) override; void final(void) override; uint64_t get(void) const override; void clear(void) override; + template uint64_t hash_immediate(const void *data, size_t len, const Transform &xf); + private: uint64_t hval; }; +// ---------- +// Implementation + +inline void +ATSHash32FNV1a::update(const void *data, size_t len) +{ + return this->update(data, len, ATSHash::nullxfrm()); +} +inline void +ATSHash64FNV1a::update(const void *data, size_t len) +{ + return this->update(data, len, ATSHash::nullxfrm()); +} + +template +uint32_t +ATSHash32FNV1a::hash_immediate(const void *data, size_t len, const Transform &xf) +{ + this->update(data, len, xf); + this->final(); + return this->get(); +} + +template +void +ATSHash32FNV1a::update(const void *data, size_t len, const Transform &xf) +{ + const uint8_t *bp = static_cast(data); + const uint8_t *be = bp + len; + + for (; bp < be; ++bp) { + hval ^= static_cast(xf(*bp)); + hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24); + } +} + template void -ATSHash64FNV1a::update(const void *data, size_t len, Transform xfrm) +ATSHash64FNV1a::update(const void *data, size_t len, Transform xf) { - uint8_t *bp = (uint8_t *)data; - uint8_t *be = bp + len; + const uint8_t *bp = static_cast(data); + const uint8_t *be = bp + len; for (; bp < be; ++bp) { - hval ^= (uint64_t)xfrm(*bp); + hval ^= static_cast(xf(*bp)); hval += (hval << 1) + (hval << 4) + (hval << 5) + (hval << 7) + (hval << 8) + (hval << 40); } } diff --git a/include/tscore/Lexicon.h b/include/tscore/Lexicon.h new file mode 100644 index 00000000000..aafbd6fe247 --- /dev/null +++ b/include/tscore/Lexicon.h @@ -0,0 +1,575 @@ +/** @file + + Assistant class for translating strings to and from enumeration values. + + @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 +#include +#include +#include +#include +#include +#include +#include +#include + +namespace ts +{ +/** A bidirectional mapping between names and enumeration values. + + This is intended to be a support class to make interacting with enumerations easier for + configuration and logging. Names and enumerations can then be easily and reliably interchanged. + The names are case insensitive but preserving. + + Each enumeration has a @a primary name and an arbitrary number of @a secondary names. When + converting from an enumeration, the primary name is used. However, any of the names will be + converted to the enumeration. For instance, a @c Lexicon for a boolean might have the primary + name of @c TRUE be "true" with the secondary names "1", "yes", "enable". In that case converting + @c TRUE would always be "true", while converting any of "true", "1", "yes", or "enable" would + yield @c TRUE. This is convenient for parsing configurations to be more tolerant of input. + + @note All names and value must be unique across the Lexicon. All name comparisons are case + insensitive. + */ +template class Lexicon +{ + using self_type = Lexicon; ///< Self reference type. +public: + /// Used for initializer lists that have just a primary value. + using Pair = std::tuple; + /// A function to be called if a value is not found. + using UnknownValueHandler = std::function; + /// A function to be called if a name is not found. + using UnknownNameHandler = std::function; + + /// Element of an initializer list that contains secondary names. + struct Definition { + const E &value; ///< Value for definition. + const std::initializer_list &names; ///< Primary then secondary names. + }; + + /// Template argument carrying struct. + /// @note Needed to pass a compile time constant to a constructor as compile time constant. + template struct Require { + }; + + /// Construct empty instance. + Lexicon(); + /// Construct with secondary names. + Lexicon(const std::initializer_list &items); + /// Construct with primary names only. + Lexicon(const std::initializer_list &items); + /// Construct and verify the number of definitions. + template Lexicon(const Require &, const std::array(e)> &defines); + /// Construct and verify the number of pairs. + template Lexicon(const Require &, const std::array(e)> &defines); + + /// Convert a value to a name + std::string_view operator[](E value); + + /// Convert a name to a value + E operator[](std::string_view name); + + /// Define the @a names for a @a value. + /// The first name is the primary name. All @a names must be convertible to @c std::string_view. + /// lexicon.define(Value, primary, [secondary, ... ]); + template self_type &define(E value, Args &&... names); + // These are really for consistency with constructors, they're not expected to be commonly used. + /// Define a value and names. + /// lexicon.define(Value, { primary, [secondary, ...] }); + self_type &define(E value, const std::initializer_list &names); + self_type &define(const Pair &pair); + self_type &define(const Definition &init); + + /** Set a default @a value. + * + * @param value Value to return if a name is not found. + * @return @c *this + */ + self_type &set_default(E value); + + /** Set a default @a name. + * + * @param name Name to return if a value is not found. + * @return @c *this + * + * @note The @a name is copied to local storage. + */ + self_type &set_default(std::string_view name); + + /** Set a default @a handler for names that are not found. + * + * @param handler Function to call with a name that was not found. + * @return @c this + * + * @a handler is passed the name that was not found as a @c std::string_view and must return a + * value which is then returned to the caller. + */ + self_type &set_default(const UnknownNameHandler &handler); + + /** Set a default @a handler for values that are not found. + * + * @param handler Function to call with a value that was not found. + * @return @c *this + * + * @a handler is passed the value that was not found and must return a name as a @c std::string_view. + * Caution must be used because the returned name must not leak and must be thread safe. The most + * common use would be for logging bad values. + */ + self_type &set_default(const UnknownValueHandler &handler); + + /// Get the number of values with definitions. + size_t count() const; + +protected: + // Because std::variant is broken up through clang 6, we have to do something uglier. + // using NameDefault = std::variant; + // using ValueDefault = std::variant; + + enum class Content { + NIL, ///< Nothing, not set. + SCALAR, ///< A specific value/name. + HANDLER ///< A function + }; + + struct NilValue { + }; + + struct NameDefault { + using self_type = NameDefault; + + NameDefault() = default; + ~NameDefault(); + + self_type &operator=(std::string_view name); + self_type &operator=(const UnknownValueHandler &handler); + + std::string_view operator()(E value); + + self_type &destroy(); + + Content _content{Content::NIL}; + static constexpr size_t N = std::max(sizeof(std::string_view), sizeof(UnknownValueHandler)); + char _store[N]; + }; + + struct ValueDefault { + using self_type = ValueDefault; + + ValueDefault() = default; + ~ValueDefault(); + + self_type &operator=(E value); + self_type &operator=(const UnknownNameHandler &handler); + + E operator()(std::string_view name); + + self_type &destroy(); + + Content _content{Content::NIL}; + static constexpr size_t N = std::max(sizeof(E), sizeof(UnknownNameHandler)); + char _store[N]; + }; + + /// Each unique pair of value and name is stored as an instance of this class. + /// The primary is stored first and is therefore found by normal lookup. + struct Item { + Item(E, std::string_view); + + E _value; ///< Definition value. + std::string_view _name; ///< Definition name + + /// Intrusive linkage for name lookup. + struct NameLinkage { + Item *_next{nullptr}; + Item *_prev{nullptr}; + + static Item *&next_ptr(Item *); + + static Item *&prev_ptr(Item *); + + static std::string_view key_of(Item *); + + static uint32_t hash_of(std::string_view s); + + static bool equal(std::string_view const &lhs, std::string_view const &rhs); + } _name_link; + + /// Intrusive linkage for value lookup. + struct ValueLinkage { + Item *_next{nullptr}; + Item *_prev{nullptr}; + + static Item *&next_ptr(Item *); + + static Item *&prev_ptr(Item *); + + static E key_of(Item *); + + static uintmax_t hash_of(E); + + static bool equal(E lhs, E rhs); + } _value_link; + }; + + /// Copy @a name in to local storage. + std::string_view localize(std::string_view name); + + /// Storage for names. + MemArena _arena{1024}; + /// Access by name. + IntrusiveHashMap _by_name; + /// Access by value. + IntrusiveHashMap _by_value; + NameDefault _name_default; + ValueDefault _value_default; +}; + +// ============== +// Implementation + +// ---- +// Item + +template Lexicon::Item::Item(E value, std::string_view name) : _value(value), _name(name) {} + +template +auto +Lexicon::Item::NameLinkage::next_ptr(Item *item) -> Item *& +{ + return item->_name_link._next; +} + +template +auto +Lexicon::Item::NameLinkage::prev_ptr(Item *item) -> Item *& +{ + return item->_name_link._prev; +} + +template +auto +Lexicon::Item::ValueLinkage::next_ptr(Item *item) -> Item *& +{ + return item->_value_link._next; +} + +template +auto +Lexicon::Item::ValueLinkage::prev_ptr(Item *item) -> Item *& +{ + return item->_value_link._prev; +} + +template +std::string_view +Lexicon::Item::NameLinkage::key_of(Item *item) +{ + return item->_name; +} + +template +E +Lexicon::Item::ValueLinkage::key_of(Item *item) +{ + return item->_value; +} + +template +uint32_t +Lexicon::Item::NameLinkage::hash_of(std::string_view s) +{ + return ATSHash32FNV1a().hash_immediate(s.data(), s.size(), ATSHash::nocase()); +} + +template +uintmax_t +Lexicon::Item::ValueLinkage::hash_of(E value) +{ + // In almost all cases, the values will be (roughly) sequential, so an identity hash works well. + return static_cast(value); +} + +template +bool +Lexicon::Item::NameLinkage::equal(std::string_view const &lhs, std::string_view const &rhs) +{ + return 0 == strcasecmp(lhs, rhs); +} + +template +bool +Lexicon::Item::ValueLinkage::equal(E lhs, E rhs) +{ + return lhs == rhs; +} + +// ------- + +template +auto +Lexicon::NameDefault::destroy() -> self_type & +{ + if (_content == Content::HANDLER) { + reinterpret_cast(_store)->~UnknownValueHandler(); + } + _content = Content::NIL; + return *this; +} + +template Lexicon::NameDefault::~NameDefault() +{ + this->destroy(); +} + +template +auto +Lexicon::NameDefault::operator=(std::string_view name) -> self_type & +{ + this->destroy(); + new (_store) std::string_view(name); + _content = Content::SCALAR; + return *this; +} + +template +auto +Lexicon::NameDefault::operator=(const UnknownValueHandler &handler) -> self_type & +{ + this->destroy(); + new (_store) UnknownValueHandler(handler); + _content = Content::HANDLER; + return *this; +} + +template +std::string_view +Lexicon::NameDefault::operator()(E value) +{ + switch (_content) { + case Content::SCALAR: + return *reinterpret_cast(_store); + break; + case Content::HANDLER: + return (*(reinterpret_cast(_store)))(value); + break; + default: + throw std::domain_error( + ts::LocalBufferWriter<128>().print("Lexicon: unknown enumeration '{}'\0", static_cast(value)).data()); + break; + } +} + +// ------- + +template +auto +Lexicon::ValueDefault::destroy() -> self_type & +{ + if (_content == Content::HANDLER) { + reinterpret_cast(_store)->~UnknownNameHandler(); + } + _content = Content::NIL; + return *this; +} + +template Lexicon::ValueDefault::~ValueDefault() +{ + this->destroy(); +} + +template +auto +Lexicon::ValueDefault::operator=(E value) -> self_type & +{ + this->destroy(); + *(reinterpret_cast(_store)) = value; + _content = Content::SCALAR; + return *this; +} + +template +auto +Lexicon::ValueDefault::operator=(const UnknownNameHandler &handler) -> self_type & +{ + this->destroy(); + new (_store) UnknownNameHandler(handler); + _content = Content::HANDLER; + return *this; +} + +template +E +Lexicon::ValueDefault::operator()(std::string_view name) +{ + switch (_content) { + case Content::SCALAR: + return *(reinterpret_cast(_store)); + break; + case Content::HANDLER: + return (*(reinterpret_cast(_store)))(name); + break; + default: + throw std::domain_error(ts::LocalBufferWriter<128>().print("Lexicon: unknown name '{}'\0", name).data()); + break; + } +} +// ------- +// Lexicon + +template Lexicon::Lexicon() {} + +template Lexicon::Lexicon(const std::initializer_list &items) +{ + for (auto item : items) { + this->define(item.value, item.names); + } +} + +template Lexicon::Lexicon(const std::initializer_list &items) +{ + for (auto item : items) { + this->define(item); + } +} + +template +template +Lexicon::Lexicon(const Require &, const std::array(e)> &defines) +{ + for (auto &def : defines) { + this->define(def); + } +} + +template +template +Lexicon::Lexicon(const Require &, const std::array(e)> &defines) +{ + for (auto &def : defines) { + this->define(def); + } +} + +template +std::string_view +Lexicon::localize(std::string_view name) +{ + auto span = _arena.alloc(name.size()); + memcpy(span.data(), name.data(), name.size()); + return span.view(); +} + +template std::string_view Lexicon::Lexicon::operator[](E value) +{ + auto spot = _by_value.find(value); + if (spot != _by_value.end()) { + return spot->_name; + } + return _name_default(value); +} + +template E Lexicon::Lexicon::operator[](std::string_view name) +{ + auto spot = _by_name.find(name); + if (spot != _by_name.end()) { + return spot->_value; + } + return _value_default(name); +} + +template +template +auto +Lexicon::Lexicon::define(E value, Args &&... names) -> self_type & +{ + static_assert(sizeof...(Args) > 0, "A defined value must have at least a priamry name"); + return this->define(value, {std::forward(names)...}); +} + +template +auto +Lexicon::Lexicon::define(E value, const std::initializer_list &names) -> self_type & +{ + if (names.size() < 1) { + throw std::invalid_argument("A defined value must have at least a primary name"); + } + for (auto name : names) { + auto i = new Item(value, this->localize(name)); + _by_name.insert(i); + _by_value.insert(i); + } + return *this; +} + +template +auto +Lexicon::Lexicon::define(const Pair &pair) -> self_type & +{ + return this->define(std::get<0>(pair), {std::get<1>(pair)}); +} + +template +auto +Lexicon::Lexicon::define(const Definition &init) -> self_type & +{ + return this->define(init.value, init.names); +} + +template +auto +Lexicon::Lexicon::set_default(std::string_view name) -> self_type & +{ + _name_default = this->localize(name); + return *this; +} + +template +auto +Lexicon::Lexicon::set_default(E value) -> self_type & +{ + _value_default = value; + return *this; +} + +template +auto +Lexicon::Lexicon::set_default(const UnknownValueHandler &handler) -> self_type & +{ + _name_default = handler; + return *this; +} + +template +auto +Lexicon::Lexicon::set_default(const UnknownNameHandler &handler) -> self_type & +{ + _value_default = handler; + return *this; +} + +template +size_t +Lexicon::Lexicon::count() const +{ + return _by_value.count(); +} + +} // namespace ts diff --git a/src/tscore/Makefile.am b/src/tscore/Makefile.am index 0a4157b9d37..41414508e46 100644 --- a/src/tscore/Makefile.am +++ b/src/tscore/Makefile.am @@ -169,6 +169,7 @@ libtscore_la_SOURCES = \ JeAllocator.h \ JeAllocator.cc \ Layout.cc \ + Lexicon.h \ List.h \ llqueue.cc \ lockfile.cc \ @@ -273,6 +274,7 @@ test_tscore_SOURCES = \ unit_tests/test_IntrusivePtr.cc \ unit_tests/test_IpMap.cc \ unit_tests/test_layout.cc \ + unit_tests/test_Lexicon.cc \ unit_tests/test_MemSpan.cc \ unit_tests/test_MemArena.cc \ unit_tests/test_MT_hashtable.cc \ diff --git a/src/tscore/unit_tests/test_Lexicon.cc b/src/tscore/unit_tests/test_Lexicon.cc new file mode 100644 index 00000000000..1b1a5b579cb --- /dev/null +++ b/src/tscore/unit_tests/test_Lexicon.cc @@ -0,0 +1,140 @@ +/** @file + + Lexicon unit tests. + + @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 +#include "../../../tests/include/catch.hpp" + +// Example code for documentatoin +// --- + +enum class Example { INVALID, Value_0, Value_1, Value_2, Value_3 }; + +using ExampleNames = ts::Lexicon; + +TEST_CASE("Lexicon Example", "[libts][Lexicon]") +{ + ExampleNames exnames{{Example::Value_0, {"zero", "0"}}, + {Example::Value_1, {"one", "1"}}, + {Example::Value_2, {"two", "2"}}, + {Example::Value_3, {"three", "3"}}, + {Example::INVALID, {"INVALID"}}}; + + ExampleNames exnames2{{Example::Value_0, "zero"}, + {Example::Value_1, "one"}, + {Example::Value_2, "two"}, + {Example::Value_3, "three"}, + {Example::INVALID, "INVALID"}}; + + exnames.set_default(Example::INVALID).set_default("INVALID"); + + REQUIRE(exnames[Example::INVALID] == "INVALID"); + REQUIRE(exnames[Example::Value_0] == "zero"); + REQUIRE(exnames["zero"] == Example::Value_0); + REQUIRE(exnames["Zero"] == Example::Value_0); + REQUIRE(exnames["ZERO"] == Example::Value_0); + REQUIRE(exnames["one"] == Example::Value_1); + REQUIRE(exnames["1"] == Example::Value_1); + REQUIRE(exnames["Evil Dave"] == Example::INVALID); + REQUIRE(exnames[static_cast(0xBADD00D)] == "INVALID"); + REQUIRE(exnames[exnames[static_cast(0xBADD00D)]] == Example::INVALID); + + // Case of an enumeration with a "LAST_VALUE". + enum class Radio { INVALID, ALPHA, BRAVO, CHARLIE, DELTA, LAST_VALUE }; + using Lex = ts::Lexicon; + Lex lex(Lex::Require(), {{{Radio::INVALID, {"Invalid"}}, + {Radio::ALPHA, {"Alpha"}}, + {Radio::BRAVO, {"Bravo", "Beta"}}, + {Radio::CHARLIE, {"Charlie"}}, + {Radio::DELTA, {"Delta"}}}}); +}; + +// --- +// End example code. + +enum Values { NoValue, LowValue, HighValue, Priceless }; +enum Hex { A, B, C, D, E, F, INVALID }; + +using ValueLexicon = ts::Lexicon; + +TEST_CASE("Lexicon Constructor", "[libts][Lexicon]") +{ + // Construct with a secondary name for NoValue + ValueLexicon vl{{NoValue, {"NoValue", "garbage"}}, {LowValue, {"LowValue"}}}; + + REQUIRE("LowValue" == vl[LowValue]); // Primary name + REQUIRE(NoValue == vl["NoValue"]); // Primary name + REQUIRE(NoValue == vl["garbage"]); // Secondary name + REQUIRE_THROWS_AS(vl["monkeys"], std::domain_error); // No default, so throw. + vl.set_default(NoValue); // Put in a default. + REQUIRE(NoValue == vl["monkeys"]); // Returns default instead of throw + REQUIRE(LowValue == vl["lowVALUE"]); // Check case insensitivity. + + REQUIRE(NoValue == vl["HighValue"]); // Not defined yet. + vl.define(HighValue, {"HighValue", "High_Value"}); // Add it. + REQUIRE(HighValue == vl["HighValue"]); // Verify it's there and is case insensitive. + REQUIRE(HighValue == vl["highVALUE"]); + REQUIRE(HighValue == vl["HIGH_VALUE"]); + REQUIRE("HighValue" == vl[HighValue]); // Verify value -> primary name. + + // A few more checks on primary/secondary. + REQUIRE(NoValue == vl["Priceless"]); + REQUIRE(NoValue == vl["unique"]); + vl.define(Priceless, "Priceless", "Unique"); + REQUIRE("Priceless" == vl[Priceless]); + REQUIRE(Priceless == vl["unique"]); + + // Check default handlers. + using LL = ts::Lexicon; + bool bad_value_p = false; + LL ll_1({{A, "A"}, {B, "B"}, {C, "C"}, {E, "E"}}); + ll_1.set_default([&bad_value_p](std::string_view name) mutable -> Hex { + bad_value_p = true; + return INVALID; + }); + ll_1.set_default([&bad_value_p](Hex value) mutable -> std::string_view { + bad_value_p = true; + return "INVALID"; + }); + REQUIRE(bad_value_p == false); + REQUIRE(INVALID == ll_1["F"]); + REQUIRE(bad_value_p == true); + bad_value_p = false; + REQUIRE("INVALID" == ll_1[F]); + REQUIRE(bad_value_p == true); + bad_value_p = false; + // Verify that INVALID / "INVALID" are equal because of the default handlers. + REQUIRE("INVALID" == ll_1[INVALID]); + REQUIRE(INVALID == ll_1["INVALID"]); + REQUIRE(bad_value_p == true); + // Define the value/name, verify the handlers are *not* invoked. + ll_1.define(INVALID, "INVALID"); + bad_value_p = false; + REQUIRE("INVALID" == ll_1[INVALID]); + REQUIRE(INVALID == ll_1["INVALID"]); + REQUIRE(bad_value_p == false); + + ll_1.define({D, "D"}); // Pair style + ll_1.define({F, {"F", "0xf"}}); // Definition style + REQUIRE(ll_1[D] == "D"); + REQUIRE(ll_1["0XF"] == F); +};