This is an automated email from the ASF dual-hosted git repository.
zwoop 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 02fc306613 Restructure the Config objects (#11478)
02fc306613 is described below
commit 02fc306613842aaf11beaa99057a192994105ef1
Author: Leif Hedstrom <[email protected]>
AuthorDate: Thu Jun 27 13:43:54 2024 -0600
Restructure the Config objects (#11478)
* Restructure the Config objects
* Adds a small cache for the static Records
* Fixes an unecessary copy
* Better error handling for bad Records
---
example/cripts/example1.cc | 1 +
include/cripts/Bundles/Common.hpp | 6 +-
include/cripts/Configs.hpp | 238 ++++++++++++++++++++------------------
include/cripts/ConfigsBase.hpp | 135 ++++++++++++++++-----
include/cripts/Context.hpp | 7 --
include/cripts/Epilogue.hpp | 2 +-
include/cripts/Headers.hpp | 5 +-
include/cripts/Instance.hpp | 2 +-
include/cripts/Lulu.hpp | 10 ++
include/cripts/Matcher.hpp | 3 +-
include/cripts/Metrics.hpp | 8 +-
src/cripts/Bundles/Common.cc | 24 ++--
src/cripts/Bundles/HRWBridge.cc | 16 +--
src/cripts/Bundles/Headers.cc | 4 +-
src/cripts/Configs.cc | 128 +++++++++++---------
src/cripts/Connections.cc | 2 +-
src/cripts/Crypto.cc | 4 +-
src/cripts/Headers.cc | 22 ++--
src/cripts/Matcher.cc | 8 +-
src/cripts/Urls.cc | 20 ++--
tools/cripts/genconfig.py | 12 +-
21 files changed, 386 insertions(+), 271 deletions(-)
diff --git a/example/cripts/example1.cc b/example/cripts/example1.cc
index 971a10b599..a8a5c82539 100644
--- a/example/cripts/example1.cc
+++ b/example/cripts/example1.cc
@@ -150,6 +150,7 @@ do_remap()
CDebug("Int config cache.http = {}", proxy.config.http.cache.http.get());
CDebug("Float config cache.heuristic_lm_factor = {}",
proxy.config.http.cache.heuristic_lm_factor.get());
+ CDebug("String config http.response_server_str = {}",
proxy.config.http.response_server_str.getSV(context));
CDebug("X-Miles = {}", req["X-Miles"]);
CDebug("random(1000) = {}", Cript::random(1000));
diff --git a/include/cripts/Bundles/Common.hpp
b/include/cripts/Bundles/Common.hpp
index fdbd1f79eb..b5ee8674d6 100644
--- a/include/cripts/Bundles/Common.hpp
+++ b/include/cripts/Bundles/Common.hpp
@@ -34,7 +34,7 @@ class Common : public Cript::Bundle::Base
using super_type = Cript::Bundle::Base;
using self_type = Common;
- using RecordsList = std::vector<std::pair<Cript::Records, const
Cript::Records::ValueType>>;
+ using RecordsList = std::vector<std::pair<const Cript::Records *, const
Cript::Records::ValueType>>;
public:
using super_type::Base;
@@ -68,8 +68,8 @@ public:
}
self_type &via_header(const Cript::string_view &destination, const
Cript::string_view &value);
- self_type &set_config(const Cript::string_view name, const
Cript::Records::ValueType value);
- self_type &set_config(std::vector<std::pair<const Cript::string_view, const
Cript::Records::ValueType>> configs);
+ self_type &set_config(const Cript::string_view name, const
Cript::Records::ValueType &value);
+ self_type &set_config(const std::vector<std::pair<const Cript::string_view,
const Cript::Records::ValueType>> &configs);
void doRemap(Cript::Context *context) override;
diff --git a/include/cripts/Configs.hpp b/include/cripts/Configs.hpp
index 5d70fae07e..e76d55e105 100644
--- a/include/cripts/Configs.hpp
+++ b/include/cripts/Configs.hpp
@@ -38,7 +38,8 @@ private:
class Body_Factory
{
public:
- Cript::IntConfig
response_suppression_mode{TS_CONFIG_BODY_FACTORY_RESPONSE_SUPPRESSION_MODE};
+ Cript::IntConfig
response_suppression_mode{"proxy.config.body_factory.response_suppression_mode"};
+ Cript::StringConfig
template_base{"proxy.config.body_factory.template_base"};
}; // End class Body_Factory
public:
@@ -48,6 +49,7 @@ private:
class Hostdb
{
public:
+ Cript::StringConfig ip_resolve{"proxy.config.hostdb.ip_resolve"};
}; // End class Hostdb
public:
@@ -57,61 +59,61 @@ private:
class Http
{
public:
- Cript::IntConfig allow_half_open{TS_CONFIG_HTTP_ALLOW_HALF_OPEN};
- Cript::IntConfig allow_multi_range{TS_CONFIG_HTTP_ALLOW_MULTI_RANGE};
- Cript::IntConfig
anonymize_remove_client_ip{TS_CONFIG_HTTP_ANONYMIZE_REMOVE_CLIENT_IP};
- Cript::IntConfig
anonymize_remove_cookie{TS_CONFIG_HTTP_ANONYMIZE_REMOVE_COOKIE};
- Cript::IntConfig
anonymize_remove_from{TS_CONFIG_HTTP_ANONYMIZE_REMOVE_FROM};
- Cript::IntConfig
anonymize_remove_referer{TS_CONFIG_HTTP_ANONYMIZE_REMOVE_REFERER};
- Cript::IntConfig
anonymize_remove_user_agent{TS_CONFIG_HTTP_ANONYMIZE_REMOVE_USER_AGENT};
- Cript::IntConfig
attach_server_session_to_client{TS_CONFIG_HTTP_ATTACH_SERVER_SESSION_TO_CLIENT};
- Cript::IntConfig
auth_server_session_private{TS_CONFIG_HTTP_AUTH_SERVER_SESSION_PRIVATE};
- Cript::IntConfig
background_fill_active_timeout{TS_CONFIG_HTTP_BACKGROUND_FILL_ACTIVE_TIMEOUT};
- Cript::FloatConfig
background_fill_completed_threshold{TS_CONFIG_HTTP_BACKGROUND_FILL_COMPLETED_THRESHOLD};
+ Cript::IntConfig allow_half_open{"proxy.config.http.allow_half_open"};
+ Cript::IntConfig
allow_multi_range{"proxy.config.http.allow_multi_range"};
+ Cript::IntConfig
anonymize_remove_client_ip{"proxy.config.http.anonymize_remove_client_ip"};
+ Cript::IntConfig
anonymize_remove_cookie{"proxy.config.http.anonymize_remove_cookie"};
+ Cript::IntConfig
anonymize_remove_from{"proxy.config.http.anonymize_remove_from"};
+ Cript::IntConfig
anonymize_remove_referer{"proxy.config.http.anonymize_remove_referer"};
+ Cript::IntConfig
anonymize_remove_user_agent{"proxy.config.http.anonymize_remove_user_agent"};
+ Cript::IntConfig
attach_server_session_to_client{"proxy.config.http.attach_server_session_to_client"};
+ Cript::IntConfig
auth_server_session_private{"proxy.config.http.auth_server_session_private"};
+ Cript::IntConfig
background_fill_active_timeout{"proxy.config.http.background_fill_active_timeout"};
+ Cript::FloatConfig
background_fill_completed_threshold{"proxy.config.http.background_fill_completed_threshold"};
private:
class Cache
{
public:
- Cript::IntConfig
cache_responses_to_cookies{TS_CONFIG_HTTP_CACHE_CACHE_RESPONSES_TO_COOKIES};
- Cript::IntConfig
cache_urls_that_look_dynamic{TS_CONFIG_HTTP_CACHE_CACHE_URLS_THAT_LOOK_DYNAMIC};
- Cript::IntConfig generation{TS_CONFIG_HTTP_CACHE_GENERATION};
- Cript::IntConfig
guaranteed_max_lifetime{TS_CONFIG_HTTP_CACHE_GUARANTEED_MAX_LIFETIME};
- Cript::IntConfig
guaranteed_min_lifetime{TS_CONFIG_HTTP_CACHE_GUARANTEED_MIN_LIFETIME};
- Cript::FloatConfig
heuristic_lm_factor{TS_CONFIG_HTTP_CACHE_HEURISTIC_LM_FACTOR};
- Cript::IntConfig
heuristic_max_lifetime{TS_CONFIG_HTTP_CACHE_HEURISTIC_MAX_LIFETIME};
- Cript::IntConfig
heuristic_min_lifetime{TS_CONFIG_HTTP_CACHE_HEURISTIC_MIN_LIFETIME};
- Cript::IntConfig http{TS_CONFIG_HTTP_CACHE_HTTP};
- Cript::IntConfig
ignore_accept_charset_mismatch{TS_CONFIG_HTTP_CACHE_IGNORE_ACCEPT_CHARSET_MISMATCH};
- Cript::IntConfig
ignore_accept_encoding_mismatch{TS_CONFIG_HTTP_CACHE_IGNORE_ACCEPT_ENCODING_MISMATCH};
- Cript::IntConfig
ignore_accept_language_mismatch{TS_CONFIG_HTTP_CACHE_IGNORE_ACCEPT_LANGUAGE_MISMATCH};
- Cript::IntConfig
ignore_accept_mismatch{TS_CONFIG_HTTP_CACHE_IGNORE_ACCEPT_MISMATCH};
- Cript::IntConfig
ignore_authentication{TS_CONFIG_HTTP_CACHE_IGNORE_AUTHENTICATION};
- Cript::IntConfig
ignore_client_cc_max_age{TS_CONFIG_HTTP_CACHE_IGNORE_CLIENT_CC_MAX_AGE};
- Cript::IntConfig
ignore_client_no_cache{TS_CONFIG_HTTP_CACHE_IGNORE_CLIENT_NO_CACHE};
- Cript::IntConfig ignore_query{TS_CONFIG_HTTP_CACHE_IGNORE_QUERY};
- Cript::IntConfig
ignore_server_no_cache{TS_CONFIG_HTTP_CACHE_IGNORE_SERVER_NO_CACHE};
- Cript::IntConfig
ims_on_client_no_cache{TS_CONFIG_HTTP_CACHE_IMS_ON_CLIENT_NO_CACHE};
- Cript::IntConfig
max_open_read_retries{TS_CONFIG_HTTP_CACHE_MAX_OPEN_READ_RETRIES};
- Cript::IntConfig
max_open_write_retries{TS_CONFIG_HTTP_CACHE_MAX_OPEN_WRITE_RETRIES};
- Cript::IntConfig
max_open_write_retry_timeout{TS_CONFIG_HTTP_CACHE_MAX_OPEN_WRITE_RETRY_TIMEOUT};
- Cript::IntConfig max_stale_age{TS_CONFIG_HTTP_CACHE_MAX_STALE_AGE};
- Cript::IntConfig
open_read_retry_time{TS_CONFIG_HTTP_CACHE_OPEN_READ_RETRY_TIME};
- Cript::IntConfig
open_write_fail_action{TS_CONFIG_HTTP_CACHE_OPEN_WRITE_FAIL_ACTION};
+ Cript::IntConfig
cache_responses_to_cookies{"proxy.config.http.cache.cache_responses_to_cookies"};
+ Cript::IntConfig
cache_urls_that_look_dynamic{"proxy.config.http.cache.cache_urls_that_look_dynamic"};
+ Cript::IntConfig generation{"proxy.config.http.cache.generation"};
+ Cript::IntConfig
guaranteed_max_lifetime{"proxy.config.http.cache.guaranteed_max_lifetime"};
+ Cript::IntConfig
guaranteed_min_lifetime{"proxy.config.http.cache.guaranteed_min_lifetime"};
+ Cript::FloatConfig
heuristic_lm_factor{"proxy.config.http.cache.heuristic_lm_factor"};
+ Cript::IntConfig
heuristic_max_lifetime{"proxy.config.http.cache.heuristic_max_lifetime"};
+ Cript::IntConfig
heuristic_min_lifetime{"proxy.config.http.cache.heuristic_min_lifetime"};
+ Cript::IntConfig http{"proxy.config.http.cache.http"};
+ Cript::IntConfig
ignore_accept_charset_mismatch{"proxy.config.http.cache.ignore_accept_charset_mismatch"};
+ Cript::IntConfig
ignore_accept_encoding_mismatch{"proxy.config.http.cache.ignore_accept_encoding_mismatch"};
+ Cript::IntConfig
ignore_accept_language_mismatch{"proxy.config.http.cache.ignore_accept_language_mismatch"};
+ Cript::IntConfig
ignore_accept_mismatch{"proxy.config.http.cache.ignore_accept_mismatch"};
+ Cript::IntConfig
ignore_authentication{"proxy.config.http.cache.ignore_authentication"};
+ Cript::IntConfig
ignore_client_cc_max_age{"proxy.config.http.cache.ignore_client_cc_max_age"};
+ Cript::IntConfig
ignore_client_no_cache{"proxy.config.http.cache.ignore_client_no_cache"};
+ Cript::IntConfig
ignore_query{"proxy.config.http.cache.ignore_query"};
+ Cript::IntConfig
ignore_server_no_cache{"proxy.config.http.cache.ignore_server_no_cache"};
+ Cript::IntConfig
ims_on_client_no_cache{"proxy.config.http.cache.ims_on_client_no_cache"};
+ Cript::IntConfig
max_open_read_retries{"proxy.config.http.cache.max_open_read_retries"};
+ Cript::IntConfig
max_open_write_retries{"proxy.config.http.cache.max_open_write_retries"};
+ Cript::IntConfig
max_open_write_retry_timeout{"proxy.config.http.cache.max_open_write_retry_timeout"};
+ Cript::IntConfig
max_stale_age{"proxy.config.http.cache.max_stale_age"};
+ Cript::IntConfig
open_read_retry_time{"proxy.config.http.cache.open_read_retry_time"};
+ Cript::IntConfig
open_write_fail_action{"proxy.config.http.cache.open_write_fail_action"};
private:
class Range
{
public:
- Cript::IntConfig lookup{TS_CONFIG_HTTP_CACHE_RANGE_LOOKUP};
- Cript::IntConfig write{TS_CONFIG_HTTP_CACHE_RANGE_WRITE};
+ Cript::IntConfig lookup{"proxy.config.http.cache.range.lookup"};
+ Cript::IntConfig write{"proxy.config.http.cache.range.write"};
}; // End class Range
public:
Range range;
- Cript::IntConfig
required_headers{TS_CONFIG_HTTP_CACHE_REQUIRED_HEADERS};
- Cript::IntConfig
when_to_revalidate{TS_CONFIG_HTTP_CACHE_WHEN_TO_REVALIDATE};
+ Cript::IntConfig
required_headers{"proxy.config.http.cache.required_headers"};
+ Cript::IntConfig
when_to_revalidate{"proxy.config.http.cache.when_to_revalidate"};
}; // End class Cache
public:
@@ -121,13 +123,13 @@ private:
class Chunking
{
public:
- Cript::IntConfig size{TS_CONFIG_HTTP_CHUNKING_SIZE};
+ Cript::IntConfig size{"proxy.config.http.chunking.size"};
}; // End class Chunking
public:
Chunking chunking;
- Cript::IntConfig chunking_enabled{TS_CONFIG_HTTP_CHUNKING_ENABLED};
+ Cript::IntConfig chunking_enabled{"proxy.config.http.chunking_enabled"};
private:
class Connect
@@ -136,7 +138,7 @@ private:
class Down
{
public:
- Cript::IntConfig policy{TS_CONFIG_HTTP_CONNECT_DOWN_POLICY};
+ Cript::IntConfig policy{"proxy.config.http.connect.down.policy"};
}; // End class Down
public:
@@ -147,19 +149,19 @@ private:
public:
Connect connect;
- Cript::IntConfig
connect_attempts_max_retries{TS_CONFIG_HTTP_CONNECT_ATTEMPTS_MAX_RETRIES};
- Cript::IntConfig
connect_attempts_max_retries_down_server{TS_CONFIG_HTTP_CONNECT_ATTEMPTS_MAX_RETRIES_DOWN_SERVER};
- Cript::IntConfig
connect_attempts_rr_retries{TS_CONFIG_HTTP_CONNECT_ATTEMPTS_RR_RETRIES};
- Cript::IntConfig
connect_attempts_timeout{TS_CONFIG_HTTP_CONNECT_ATTEMPTS_TIMEOUT};
- Cript::IntConfig default_buffer_size{TS_CONFIG_HTTP_DEFAULT_BUFFER_SIZE};
- Cript::IntConfig
default_buffer_water_mark{TS_CONFIG_HTTP_DEFAULT_BUFFER_WATER_MARK};
- Cript::IntConfig
doc_in_cache_skip_dns{TS_CONFIG_HTTP_DOC_IN_CACHE_SKIP_DNS};
+ Cript::IntConfig
connect_attempts_max_retries{"proxy.config.http.connect_attempts_max_retries"};
+ Cript::IntConfig
connect_attempts_max_retries_down_server{"proxy.config.http.connect_attempts_max_retries_down_server"};
+ Cript::IntConfig
connect_attempts_rr_retries{"proxy.config.http.connect_attempts_rr_retries"};
+ Cript::IntConfig
connect_attempts_timeout{"proxy.config.http.connect_attempts_timeout"};
+ Cript::IntConfig
default_buffer_size{"proxy.config.http.default_buffer_size"};
+ Cript::IntConfig
default_buffer_water_mark{"proxy.config.http.default_buffer_water_mark"};
+ Cript::IntConfig
doc_in_cache_skip_dns{"proxy.config.http.doc_in_cache_skip_dns"};
private:
class Down_Server
{
public:
- Cript::IntConfig cache_time{TS_CONFIG_HTTP_DOWN_SERVER_CACHE_TIME};
+ Cript::IntConfig
cache_time{"proxy.config.http.down_server.cache_time"};
}; // End class Down_Server
public:
@@ -169,9 +171,9 @@ private:
class Flow_Control
{
public:
- Cript::IntConfig enabled{TS_CONFIG_HTTP_FLOW_CONTROL_ENABLED};
- Cript::IntConfig
high_water{TS_CONFIG_HTTP_FLOW_CONTROL_HIGH_WATER_MARK};
- Cript::IntConfig low_water{TS_CONFIG_HTTP_FLOW_CONTROL_LOW_WATER_MARK};
+ Cript::IntConfig enabled{"proxy.config.http.flow_control.enabled"};
+ Cript::IntConfig
high_water{"proxy.config.http.flow_control.high_water"};
+ Cript::IntConfig low_water{"proxy.config.http.flow_control.low_water"};
}; // End class Flow_Control
public:
@@ -181,43 +183,45 @@ private:
class Forward
{
public:
- Cript::IntConfig
proxy_auth_to_parent{TS_CONFIG_HTTP_FORWARD_PROXY_AUTH_TO_PARENT};
+ Cript::IntConfig
proxy_auth_to_parent{"proxy.config.http.forward.proxy_auth_to_parent"};
}; // End class Forward
public:
Forward forward;
- Cript::IntConfig
forward_connect_method{TS_CONFIG_HTTP_FORWARD_CONNECT_METHOD};
- Cript::IntConfig
insert_age_in_response{TS_CONFIG_HTTP_INSERT_AGE_IN_RESPONSE};
- Cript::IntConfig
insert_client_ip{TS_CONFIG_HTTP_ANONYMIZE_INSERT_CLIENT_IP};
- Cript::IntConfig
insert_request_via_str{TS_CONFIG_HTTP_INSERT_REQUEST_VIA_STR};
- Cript::IntConfig
insert_response_via_str{TS_CONFIG_HTTP_INSERT_RESPONSE_VIA_STR};
- Cript::IntConfig
insert_squid_x_forwarded_for{TS_CONFIG_HTTP_INSERT_SQUID_X_FORWARDED_FOR};
- Cript::IntConfig
keep_alive_enabled_in{TS_CONFIG_HTTP_KEEP_ALIVE_ENABLED_IN};
- Cript::IntConfig
keep_alive_enabled_out{TS_CONFIG_HTTP_KEEP_ALIVE_ENABLED_OUT};
- Cript::IntConfig
keep_alive_no_activity_timeout_in{TS_CONFIG_HTTP_KEEP_ALIVE_NO_ACTIVITY_TIMEOUT_IN};
- Cript::IntConfig
keep_alive_no_activity_timeout_out{TS_CONFIG_HTTP_KEEP_ALIVE_NO_ACTIVITY_TIMEOUT_OUT};
- Cript::IntConfig keep_alive_post_out{TS_CONFIG_HTTP_KEEP_ALIVE_POST_OUT};
- Cript::IntConfig max_proxy_cycles{TS_CONFIG_HTTP_MAX_PROXY_CYCLES};
- Cript::IntConfig
negative_caching_enabled{TS_CONFIG_HTTP_NEGATIVE_CACHING_ENABLED};
- Cript::IntConfig
negative_caching_lifetime{TS_CONFIG_HTTP_NEGATIVE_CACHING_LIFETIME};
- Cript::IntConfig
negative_revalidating_enabled{TS_CONFIG_HTTP_NEGATIVE_REVALIDATING_ENABLED};
- Cript::IntConfig
negative_revalidating_lifetime{TS_CONFIG_HTTP_NEGATIVE_REVALIDATING_LIFETIME};
- Cript::IntConfig
no_dns_just_forward_to_parent{TS_CONFIG_HTTP_NO_DNS_JUST_FORWARD_TO_PARENT};
- Cript::IntConfig normalize_ae{TS_CONFIG_HTTP_NORMALIZE_AE};
- Cript::IntConfig
number_of_redirections{TS_CONFIG_HTTP_NUMBER_OF_REDIRECTIONS};
+ Cript::IntConfig
forward_connect_method{"proxy.config.http.forward_connect_method"};
+ Cript::StringConfig
global_user_agent_header{"proxy.config.http.global_user_agent_header"};
+ Cript::IntConfig
insert_age_in_response{"proxy.config.http.insert_age_in_response"};
+ Cript::IntConfig
insert_client_ip{"proxy.config.http.insert_client_ip"};
+ Cript::StringConfig
insert_forwarded{"proxy.config.http.insert_forwarded"};
+ Cript::IntConfig
insert_request_via_str{"proxy.config.http.insert_request_via_str"};
+ Cript::IntConfig
insert_response_via_str{"proxy.config.http.insert_response_via_str"};
+ Cript::IntConfig
insert_squid_x_forwarded_for{"proxy.config.http.insert_squid_x_forwarded_for"};
+ Cript::IntConfig
keep_alive_enabled_in{"proxy.config.http.keep_alive_enabled_in"};
+ Cript::IntConfig
keep_alive_enabled_out{"proxy.config.http.keep_alive_enabled_out"};
+ Cript::IntConfig
keep_alive_no_activity_timeout_in{"proxy.config.http.keep_alive_no_activity_timeout_in"};
+ Cript::IntConfig
keep_alive_no_activity_timeout_out{"proxy.config.http.keep_alive_no_activity_timeout_out"};
+ Cript::IntConfig
keep_alive_post_out{"proxy.config.http.keep_alive_post_out"};
+ Cript::IntConfig
max_proxy_cycles{"proxy.config.http.max_proxy_cycles"};
+ Cript::IntConfig
negative_caching_enabled{"proxy.config.http.negative_caching_enabled"};
+ Cript::IntConfig
negative_caching_lifetime{"proxy.config.http.negative_caching_lifetime"};
+ Cript::IntConfig
negative_revalidating_enabled{"proxy.config.http.negative_revalidating_enabled"};
+ Cript::IntConfig
negative_revalidating_lifetime{"proxy.config.http.negative_revalidating_lifetime"};
+ Cript::IntConfig
no_dns_just_forward_to_parent{"proxy.config.http.no_dns_just_forward_to_parent"};
+ Cript::IntConfig normalize_ae{"proxy.config.http.normalize_ae"};
+ Cript::IntConfig
number_of_redirections{"proxy.config.http.number_of_redirections"};
private:
class Parent_Proxy
{
public:
- Cript::IntConfig
disable_parent_markdowns{TS_CONFIG_HTTP_DISABLE_PARENT_MARKDOWNS};
- Cript::IntConfig
enable_parent_timeout_markdowns{TS_CONFIG_HTTP_ENABLE_PARENT_TIMEOUT_MARKDOWNS};
- Cript::IntConfig
fail_threshold{TS_CONFIG_HTTP_PARENT_PROXY_FAIL_THRESHOLD};
- Cript::IntConfig
mark_down_hostdb{TS_CONFIG_PARENT_FAILURES_UPDATE_HOSTDB};
- Cript::IntConfig
per_parent_connect_attempts{TS_CONFIG_HTTP_PER_PARENT_CONNECT_ATTEMPTS};
- Cript::IntConfig retry_time{TS_CONFIG_HTTP_PARENT_PROXY_RETRY_TIME};
- Cript::IntConfig
total_connect_attempts{TS_CONFIG_HTTP_PARENT_PROXY_TOTAL_CONNECT_ATTEMPTS};
+ Cript::IntConfig
disable_parent_markdowns{"proxy.config.http.parent_proxy.disable_parent_markdowns"};
+ Cript::IntConfig
enable_parent_timeout_markdowns{"proxy.config.http.parent_proxy.enable_parent_timeout_markdowns"};
+ Cript::IntConfig
fail_threshold{"proxy.config.http.parent_proxy.fail_threshold"};
+ Cript::IntConfig
mark_down_hostdb{"proxy.config.http.parent_proxy.mark_down_hostdb"};
+ Cript::IntConfig
per_parent_connect_attempts{"proxy.config.http.parent_proxy.per_parent_connect_attempts"};
+ Cript::IntConfig
retry_time{"proxy.config.http.parent_proxy.retry_time"};
+ Cript::IntConfig
total_connect_attempts{"proxy.config.http.parent_proxy.total_connect_attempts"};
}; // End class Parent_Proxy
public:
@@ -233,7 +237,7 @@ private:
class Content_Length
{
public:
- Cript::IntConfig
enabled{TS_CONFIG_HTTP_POST_CHECK_CONTENT_LENGTH_ENABLED};
+ Cript::IntConfig
enabled{"proxy.config.http.post.check.content_length.enabled"};
}; // End class Content_Length
public:
@@ -249,18 +253,20 @@ private:
public:
Post post;
- Cript::IntConfig proxy_protocol_out{TS_CONFIG_HTTP_PROXY_PROTOCOL_OUT};
- Cript::IntConfig
redirect_use_orig_cache_key{TS_CONFIG_HTTP_REDIRECT_USE_ORIG_CACHE_KEY};
- Cript::IntConfig
request_buffer_enabled{TS_CONFIG_HTTP_REQUEST_BUFFER_ENABLED};
- Cript::IntConfig
request_header_max_size{TS_CONFIG_HTTP_REQUEST_HEADER_MAX_SIZE};
- Cript::IntConfig
response_header_max_size{TS_CONFIG_HTTP_RESPONSE_HEADER_MAX_SIZE};
- Cript::IntConfig
response_server_enabled{TS_CONFIG_HTTP_RESPONSE_SERVER_ENABLED};
- Cript::IntConfig
send_http11_requests{TS_CONFIG_HTTP_SEND_HTTP11_REQUESTS};
+ Cript::IntConfig
proxy_protocol_out{"proxy.config.http.proxy_protocol_out"};
+ Cript::IntConfig
redirect_use_orig_cache_key{"proxy.config.http.redirect_use_orig_cache_key"};
+ Cript::IntConfig
request_buffer_enabled{"proxy.config.http.request_buffer_enabled"};
+ Cript::IntConfig
request_header_max_size{"proxy.config.http.request_header_max_size"};
+ Cript::IntConfig
response_header_max_size{"proxy.config.http.response_header_max_size"};
+ Cript::IntConfig
response_server_enabled{"proxy.config.http.response_server_enabled"};
+ Cript::StringConfig
response_server_str{"proxy.config.http.response_server_str"};
+ Cript::IntConfig
send_http11_requests{"proxy.config.http.send_http11_requests"};
private:
class Server_Session_Sharing
{
public:
+ Cript::StringConfig
match{"proxy.config.http.server_session_sharing.match"};
}; // End class Server_Session_Sharing
public:
@@ -273,7 +279,7 @@ private:
class Log
{
public:
- Cript::IntConfig threshold{TS_CONFIG_HTTP_SLOW_LOG_THRESHOLD};
+ Cript::IntConfig threshold{"proxy.config.http.slow.log.threshold"};
}; // End class Log
public:
@@ -284,11 +290,11 @@ private:
public:
Slow slow;
- Cript::IntConfig
transaction_active_timeout_in{TS_CONFIG_HTTP_TRANSACTION_ACTIVE_TIMEOUT_IN};
- Cript::IntConfig
transaction_active_timeout_out{TS_CONFIG_HTTP_TRANSACTION_ACTIVE_TIMEOUT_OUT};
- Cript::IntConfig
transaction_no_activity_timeout_in{TS_CONFIG_HTTP_TRANSACTION_NO_ACTIVITY_TIMEOUT_IN};
- Cript::IntConfig
transaction_no_activity_timeout_out{TS_CONFIG_HTTP_TRANSACTION_NO_ACTIVITY_TIMEOUT_OUT};
- Cript::IntConfig
uncacheable_requests_bypass_parent{TS_CONFIG_HTTP_UNCACHEABLE_REQUESTS_BYPASS_PARENT};
+ Cript::IntConfig
transaction_active_timeout_in{"proxy.config.http.transaction_active_timeout_in"};
+ Cript::IntConfig
transaction_active_timeout_out{"proxy.config.http.transaction_active_timeout_out"};
+ Cript::IntConfig
transaction_no_activity_timeout_in{"proxy.config.http.transaction_no_activity_timeout_in"};
+ Cript::IntConfig
transaction_no_activity_timeout_out{"proxy.config.http.transaction_no_activity_timeout_out"};
+ Cript::IntConfig
uncacheable_requests_bypass_parent{"proxy.config.http.uncacheable_requests_bypass_parent"};
}; // End class Http
public:
@@ -298,13 +304,13 @@ private:
class Net
{
public:
- Cript::IntConfig
default_inactivity_timeout{TS_CONFIG_NET_DEFAULT_INACTIVITY_TIMEOUT};
- Cript::IntConfig sock_notsent_lowat{TS_CONFIG_NET_SOCK_NOTSENT_LOWAT};
- Cript::IntConfig
sock_option_flag_out{TS_CONFIG_NET_SOCK_OPTION_FLAG_OUT};
- Cript::IntConfig
sock_packet_mark_out{TS_CONFIG_NET_SOCK_PACKET_MARK_OUT};
- Cript::IntConfig sock_packet_tos_out{TS_CONFIG_NET_SOCK_PACKET_TOS_OUT};
- Cript::IntConfig
sock_recv_buffer_size_out{TS_CONFIG_NET_SOCK_RECV_BUFFER_SIZE_OUT};
- Cript::IntConfig
sock_send_buffer_size_out{TS_CONFIG_NET_SOCK_SEND_BUFFER_SIZE_OUT};
+ Cript::IntConfig
default_inactivity_timeout{"proxy.config.net.default_inactivity_timeout"};
+ Cript::IntConfig
sock_notsent_lowat{"proxy.config.net.sock_notsent_lowat"};
+ Cript::IntConfig
sock_option_flag_out{"proxy.config.net.sock_option_flag_out"};
+ Cript::IntConfig
sock_packet_mark_out{"proxy.config.net.sock_packet_mark_out"};
+ Cript::IntConfig
sock_packet_tos_out{"proxy.config.net.sock_packet_tos_out"};
+ Cript::IntConfig
sock_recv_buffer_size_out{"proxy.config.net.sock_recv_buffer_size_out"};
+ Cript::IntConfig
sock_send_buffer_size_out{"proxy.config.net.sock_send_buffer_size_out"};
}; // End class Net
public:
@@ -317,8 +323,8 @@ private:
class Vc
{
public:
- Cript::IntConfig
default_buffer_index{TS_CONFIG_PLUGIN_VC_DEFAULT_BUFFER_INDEX};
- Cript::IntConfig
default_buffer_water_mark{TS_CONFIG_PLUGIN_VC_DEFAULT_BUFFER_WATER_MARK};
+ Cript::IntConfig
default_buffer_index{"proxy.config.plugin.vc.default_buffer_index"};
+ Cript::IntConfig
default_buffer_water_mark{"proxy.config.plugin.vc.default_buffer_water_mark"};
}; // End class Vc
public:
@@ -330,7 +336,7 @@ private:
Plugin plugin;
public:
- Cript::IntConfig srv_enabled{TS_CONFIG_SRV_ENABLED};
+ Cript::IntConfig srv_enabled{"proxy.config.srv_enabled"};
private:
class Ssl
@@ -345,6 +351,7 @@ private:
class Cert
{
public:
+ Cript::StringConfig
filename{"proxy.config.ssl.client.CA.cert.filename"};
}; // End class Cert
public:
@@ -356,10 +363,14 @@ private:
Ca CA;
public:
+ Cript::StringConfig
alpn_protocols{"proxy.config.ssl.client.alpn_protocols"};
+
private:
class Cert
{
public:
+ Cript::StringConfig
filename{"proxy.config.ssl.client.cert.filename"};
+ Cript::StringConfig path{"proxy.config.ssl.client.cert.path"};
}; // End class Cert
public:
@@ -369,11 +380,14 @@ private:
class Private_Key
{
public:
+ Cript::StringConfig
filename{"proxy.config.ssl.client.private_key.filename"};
}; // End class Private_Key
public:
Private_Key private_key;
+ Cript::StringConfig sni_policy{"proxy.config.ssl.client.sni_policy"};
+
private:
class Verify
{
@@ -381,6 +395,8 @@ private:
class Server
{
public:
+ Cript::StringConfig
policy{"proxy.config.ssl.client.verify.server.policy"};
+ Cript::StringConfig
properties{"proxy.config.ssl.client.verify.server.properties"};
}; // End class Server
public:
@@ -397,8 +413,8 @@ private:
Client client;
public:
- Cript::IntConfig
hsts_include_subdomains{TS_CONFIG_SSL_HSTS_INCLUDE_SUBDOMAINS};
- Cript::IntConfig hsts_max_age{TS_CONFIG_SSL_HSTS_MAX_AGE};
+ Cript::IntConfig
hsts_include_subdomains{"proxy.config.ssl.hsts_include_subdomains"};
+ Cript::IntConfig hsts_max_age{"proxy.config.ssl.hsts_max_age"};
}; // End class Ssl
public:
@@ -408,7 +424,7 @@ private:
class Url_Remap
{
public:
- Cript::IntConfig
pristine_host_hdr{TS_CONFIG_URL_REMAP_PRISTINE_HOST_HDR};
+ Cript::IntConfig
pristine_host_hdr{"proxy.config.url_remap.pristine_host_hdr"};
}; // End class Url_Remap
public:
@@ -418,8 +434,8 @@ private:
class Websocket
{
public:
- Cript::IntConfig active_timeout{TS_CONFIG_WEBSOCKET_ACTIVE_TIMEOUT};
- Cript::IntConfig
no_activity_timeout{TS_CONFIG_WEBSOCKET_NO_ACTIVITY_TIMEOUT};
+ Cript::IntConfig active_timeout{"proxy.config.websocket.active_timeout"};
+ Cript::IntConfig
no_activity_timeout{"proxy.config.websocket.no_activity_timeout"};
}; // End class Websocket
public:
diff --git a/include/cripts/ConfigsBase.hpp b/include/cripts/ConfigsBase.hpp
index 4ceb27fcfa..e1348bebac 100644
--- a/include/cripts/ConfigsBase.hpp
+++ b/include/cripts/ConfigsBase.hpp
@@ -19,40 +19,14 @@
#pragma once
-#include "ts/ts.h"
+#include <unordered_map>
+#include "ts/ts.h"
#include "cripts/Lulu.hpp"
#include "cripts/Context.hpp"
namespace Cript
{
-class IntConfig
-{
-public:
- IntConfig() = delete;
- explicit IntConfig(TSOverridableConfigKey key) : _key(key) {}
-
- // Implemented later in Configs.cc
- integer _get(Cript::Context *context) const;
- void _set(Cript::Context *context, integer value);
-
-private:
- const TSOverridableConfigKey _key;
-}; // namespace Criptclass IntConfig
-
-class FloatConfig
-{
-public:
- FloatConfig() = delete;
- explicit FloatConfig(TSOverridableConfigKey key) : _key(key) {}
-
- // Implemented later in Configs.cc
- float _get(Cript::Context *context) const;
- void _set(Cript::Context *context, float value);
-
-private:
- const TSOverridableConfigKey _key;
-};
class Records
{
@@ -70,7 +44,12 @@ public:
explicit Records(const Cript::string_view name);
ValueType _get(const Cript::Context *context) const;
- bool _set(const Cript::Context *context, const ValueType value);
+ bool _set(const Cript::Context *context, const ValueType &value) const;
+
+ // Optimizations, we can't use string_view in the ValueType since we need
persistent storage.
+ // Be careful with the setSV() and make sure there's underlying storage!
+ const Cript::string_view getSV(const Cript::Context *context) const;
+ bool setSV(const Cript::Context *context, const
Cript::string_view value) const;
[[nodiscard]] TSOverridableConfigKey
key() const
@@ -96,9 +75,105 @@ public:
return (_key != TS_CONFIG_NULL && _type != TS_RECORDDATATYPE_NULL);
}
+ [[nodiscard]] bool
+ isInteger() const
+ {
+ return _type == TS_RECORDDATATYPE_INT;
+ }
+
+ [[nodiscard]] bool
+ isFloat() const
+ {
+ return _type == TS_RECORDDATATYPE_FLOAT;
+ }
+
+ [[nodiscard]] bool
+ isString() const
+ {
+ return _type == TS_RECORDDATATYPE_STRING;
+ }
+
+ static void add(const Records *rec);
+ static const Records *lookup(const Cript::string_view name);
+
private:
Cript::string _name;
TSOverridableConfigKey _key = TS_CONFIG_NULL;
TSRecordDataType _type = TS_RECORDDATATYPE_NULL;
-};
+
+ static std::unordered_map<Cript::string_view, const Records *> _gRecords;
+}; // class Records
+
+class IntConfig
+{
+public:
+ IntConfig() = delete;
+ explicit IntConfig(const Cript::string_view name) : _record(name) {
Records::add(&_record); }
+
+ float
+ _get(Cript::Context *context) const
+ {
+ return std::get<TSMgmtInt>(_record._get(context));
+ }
+
+ void
+ _set(Cript::Context *context, integer value)
+ {
+ _record._set(context, value);
+ }
+
+private:
+ const Records _record;
+}; // class IntConfig
+
+class FloatConfig
+{
+public:
+ FloatConfig() = delete;
+ explicit FloatConfig(const Cript::string_view name) : _record(name) {
Records::add(&_record); }
+
+ float
+ _get(Cript::Context *context) const
+ {
+ return std::get<TSMgmtFloat>(_record._get(context));
+ }
+
+ void
+ _set(Cript::Context *context, float value)
+ {
+ _record._set(context, value);
+ }
+
+private:
+ const Records _record;
+}; // class FloatConfig
+
+class StringConfig
+{
+public:
+ StringConfig() = delete;
+ explicit StringConfig(const Cript::string_view name) : _record(name) {
Records::add(&_record); }
+
+ std::string
+ _get(Cript::Context *context) const
+ {
+ return std::get<std::string>(_record._get(context));
+ }
+
+ void
+ _set(Cript::Context *context, std::string &value)
+ {
+ _record.setSV(context, value);
+ }
+
+ const std::string_view
+ getSV(Cript::Context *context) const
+ {
+ return _record.getSV(context);
+ }
+
+private:
+ const Records _record;
+}; // class StringConfig
+
} // namespace Cript
diff --git a/include/cripts/Context.hpp b/include/cripts/Context.hpp
index d6eedc24a3..128b537fd9 100644
--- a/include/cripts/Context.hpp
+++ b/include/cripts/Context.hpp
@@ -108,13 +108,6 @@ private:
#define transaction context->state
#define txn_data context->data
#define instance context->p_instance
-#define borrow auto &
#define CDebug(...) context->p_instance.debug(__VA_ARGS__)
#define CDebugOn() context->p_instance.debugOn()
-#define CAssert(...) TSReleaseAssert(__VA_ARGS__)
#define DisableCallback(cb) context->state.disableCallback(cb)
-#define AsBoolean(arg) std::get<boolean>(arg)
-#define AsString(arg) std::get<Cript::string>(arg)
-#define AsInteger(arg) std::get<integer>(arg)
-#define AsFloat(arg) std::get<double>(arg)
-#define AsPointer(arg) std::get<void *>(arg)
diff --git a/include/cripts/Epilogue.hpp b/include/cripts/Epilogue.hpp
index 6b26d62a1a..96b7b712c4 100644
--- a/include/cripts/Epilogue.hpp
+++ b/include/cripts/Epilogue.hpp
@@ -348,7 +348,7 @@ default_cont(TSCont contp, TSEvent event, void *edata)
break;
// This is for cleanup, and should always be called / wrapped
default:
- TSReleaseAssert(!"Unknown event to Cript plugin!");
+ CFatal("Cripts continuation: Unknown event %d", event);
break;
}
diff --git a/include/cripts/Headers.hpp b/include/cripts/Headers.hpp
index 22ec36d088..b0b30a053f 100644
--- a/include/cripts/Headers.hpp
+++ b/include/cripts/Headers.hpp
@@ -24,6 +24,7 @@
#include "ts/ts.h"
#include "cripts/Transaction.hpp"
+#include "cripts/Lulu.hpp"
class Header
{
@@ -123,7 +124,7 @@ public:
[[nodiscard]] Cript::string_view::const_pointer
data() const
{
- TSReleaseAssert(_method.size() > 0);
+ CAssert(_method.size() > 0);
return _method.data();
}
@@ -319,7 +320,7 @@ public:
operator++()
{
if (_tag != END_TAG) {
- TSReleaseAssert(_tag == _owner->_iterator_tag);
+ CAssert(_tag == _owner->_iterator_tag);
_view = _owner->iterate();
if (_view.empty()) {
diff --git a/include/cripts/Instance.hpp b/include/cripts/Instance.hpp
index a3b4742e2d..5866fe1604 100644
--- a/include/cripts/Instance.hpp
+++ b/include/cripts/Instance.hpp
@@ -63,7 +63,7 @@ public:
{
for (auto &it : bundles) {
if (it->name() == bundle->name()) {
- TSReleaseAssert(!"Duplicate bundle");
+ CFatal("[Instance]: Duplicate bundle %s", bundle->name().c_str());
}
}
diff --git a/include/cripts/Lulu.hpp b/include/cripts/Lulu.hpp
index e32dbc05b8..7108c4b109 100644
--- a/include/cripts/Lulu.hpp
+++ b/include/cripts/Lulu.hpp
@@ -42,6 +42,16 @@ namespace CFS = std::filesystem; // Simplify the
usage of std::filesys
integer integer_helper(std::string_view sv);
+// Some convenience macros
+#define borrow auto &
+#define CAssert(...) TSReleaseAssert(__VA_ARGS__)
+#define CFatal(...) TSFatal(__VA_ARGS__)
+#define AsBoolean(arg) std::get<boolean>(arg)
+#define AsString(arg) std::get<Cript::string>(arg)
+#define AsInteger(arg) std::get<integer>(arg)
+#define AsFloat(arg) std::get<double>(arg)
+#define AsPointer(arg) std::get<void *>(arg)
+
namespace Cript
{
// Use Cript::string_view consistently, so that it's a one-stop shop for all
string_view needs.
diff --git a/include/cripts/Matcher.hpp b/include/cripts/Matcher.hpp
index b7110147d5..24e48a75cf 100644
--- a/include/cripts/Matcher.hpp
+++ b/include/cripts/Matcher.hpp
@@ -27,6 +27,7 @@
#include <tuple>
#include "ts/ts.h"
+#include "cripts/Lulu.hpp"
namespace Matcher
{
@@ -84,7 +85,7 @@ namespace Range
if (swoc::IPRange r; r.load(str)) {
mark(r);
} else {
- TSReleaseAssert("Bad IP range");
+ CFatal("[Matcher::Range::IP] Invalid IP range: %.*s",
static_cast<int>(str.size()), str.data());
}
}
diff --git a/include/cripts/Metrics.hpp b/include/cripts/Metrics.hpp
index 5b653dcc31..e70ea33dd5 100644
--- a/include/cripts/Metrics.hpp
+++ b/include/cripts/Metrics.hpp
@@ -59,7 +59,7 @@ public:
void
increment(int64_t inc) const
{
- TSReleaseAssert(_id != ts::Metrics::NOT_FOUND);
+ CAssert(_id != ts::Metrics::NOT_FOUND);
_metric->increment(inc);
}
@@ -72,7 +72,7 @@ public:
void
decrement(int64_t dec) const
{
- TSReleaseAssert(_id != ts::Metrics::NOT_FOUND);
+ CAssert(_id != ts::Metrics::NOT_FOUND);
_metric->decrement(dec);
}
@@ -85,14 +85,14 @@ public:
[[nodiscard]] int64_t
get() const
{
- TSReleaseAssert(_id != TS_ERROR);
+ CAssert(_id != TS_ERROR);
return _metric->load();
}
void
set(int64_t val)
{
- TSReleaseAssert(_id != TS_ERROR);
+ CAssert(_id != TS_ERROR);
_metric->store(val);
}
diff --git a/src/cripts/Bundles/Common.cc b/src/cripts/Bundles/Common.cc
index 2956c35bfd..f5b7e2e608 100644
--- a/src/cripts/Bundles/Common.cc
+++ b/src/cripts/Bundles/Common.cc
@@ -42,28 +42,28 @@ Common::validate(std::vector<Cript::Bundle::Error> &errors)
const
// Make sure all configurations are of the correct type
for (auto &[rec, value] : _configs) {
- switch (rec.type()) {
+ switch (rec->type()) {
case TS_RECORDDATATYPE_INT:
if (!std::holds_alternative<TSMgmtInt>(value)) {
- errors.emplace_back("Invalid value for config, expecting an integer",
name(), rec.name());
+ errors.emplace_back("Invalid value for config, expecting an integer",
name(), rec->name());
good = false;
}
break;
case TS_RECORDDATATYPE_FLOAT:
if (!std::holds_alternative<TSMgmtFloat>(value)) {
- errors.emplace_back("Invalid value for config, expecting a float",
name(), rec.name());
+ errors.emplace_back("Invalid value for config, expecting a float",
name(), rec->name());
good = false;
}
break;
case TS_RECORDDATATYPE_STRING:
if (!std::holds_alternative<std::string>(value)) {
- errors.emplace_back("Invalid value for config, expecting an integer",
name(), rec.name());
+ errors.emplace_back("Invalid value for config, expecting an integer",
name(), rec->name());
good = false;
}
break;
default:
- errors.emplace_back("Invalid configuration type", name(), rec.name());
+ errors.emplace_back("Invalid configuration type", name(), rec->name());
good = false;
break;
}
@@ -105,20 +105,22 @@ Common::via_header(const Cript::string_view &destination,
const Cript::string_vi
}
Common &
-Common::set_config(const Cript::string_view name, const
Cript::Records::ValueType value)
+Common::set_config(const Cript::string_view name, const
Cript::Records::ValueType &value)
{
- Cript::Records rec(name);
+ auto rec = Cript::Records::lookup(name); // These should be loaded at startup
- if (rec.loaded()) {
+ if (rec) {
needCallback(Cript::Callbacks::DO_REMAP);
- _configs.emplace_back(std::move(rec), value);
+ _configs.emplace_back(rec, value);
+ } else {
+ CFatal("[Common::set_config]: Unknown configuration '%.*s'",
static_cast<int>(name.size()), name.data());
}
return *this;
}
Common &
-Common::set_config(std::vector<std::pair<const Cript::string_view, const
Cript::Records::ValueType>> configs)
+Common::set_config(const std::vector<std::pair<const Cript::string_view, const
Cript::Records::ValueType>> &configs)
{
for (auto &[name, value] : configs) {
set_config(name, value);
@@ -150,7 +152,7 @@ Common::doRemap(Cript::Context *context)
// .set_config()
for (auto &[rec, value] : _configs) {
- rec._set(context, value);
+ rec->_set(context, value);
}
}
diff --git a/src/cripts/Bundles/HRWBridge.cc b/src/cripts/Bundles/HRWBridge.cc
index bba4727bb6..09eb6d6e4a 100644
--- a/src/cripts/Bundles/HRWBridge.cc
+++ b/src/cripts/Bundles/HRWBridge.cc
@@ -54,7 +54,7 @@ ID::ID(const Cript::string_view &id) : super_type(id)
} else if (id == "UNIQUE") {
_type = Type::UNIQUE;
} else {
- TSReleaseAssert(!"Invalid ID type in HRWBridge");
+ CFatal("[Cripts::Headers] Unknown HRWBridge ID type: %s.", id.data());
}
}
@@ -112,7 +112,7 @@ IP::IP(const Cript::string_view &type) : super_type(type)
} else if (type == "OUTBOUND") {
_type = Type::INBOUND;
} else {
- TSReleaseAssert(!"Invalid TYPE IP in HRWBridge");
+ CFatal("[Cripts::Headers] Unknown HRWBridge IP type: %s.", type.data());
}
}
@@ -169,17 +169,17 @@ CIDR::CIDR(Cript::string_view &cidr) : super_type(cidr)
{
auto ipv4 = cidr.split_prefix_at(',');
- TSReleaseAssert(ipv4 != cidr); // No ' found
+ CAssert(ipv4 != cidr); // No ' found
auto result = std::from_chars(ipv4.data(), ipv4.data() + ipv4.size(),
_ipv4_cidr);
if (result.ec != std::errc()) {
- TSReleaseAssert(!"Invalid CIDR parameters in HRWBridge");
+ CFatal("[Cripts::Headers] Invalid IPv4 CIDR parameters: %s.", cidr.data());
}
result = std::from_chars(cidr.data(), cidr.data() + cidr.size(), _ipv6_cidr);
if (result.ec != std::errc()) {
- TSReleaseAssert(!"Invalid CIDR parameters in HRWBridge");
+ CFatal("[Cripts::Headers] Invalid IPv6 CIDR parameters: %s.", cidr.data());
}
}
@@ -251,7 +251,7 @@ URL::_getComponent(Cript::Url &url)
break;
default:
- TSReleaseAssert(!"Invalid URL component in HRWBridge");
+ CFatal("[Cripts::Headers] Invalid URL component in HRWBridge.");
break;
}
@@ -275,7 +275,7 @@ URL::URL(Type utype, const Cript::string_view &comp) :
super_type("")
} else if (comp == "URL") {
_comp = Component::URL;
} else {
- TSReleaseAssert(!"Invalid URL component in HRWBridge");
+ CFatal("[Cripts::Headers] Invalid URL component in HRWBridge.");
}
}
@@ -320,7 +320,7 @@ URL::value(Cript::Context *context)
} break;
default:
- TSReleaseAssert(!"Invalid URL type in HRWBridge");
+ CFatal("[Cripts::Headers] Invalid URL type in HRWBridge.");
break;
}
diff --git a/src/cripts/Bundles/Headers.cc b/src/cripts/Bundles/Headers.cc
index ddd3ec4d50..c068cd6469 100644
--- a/src/cripts/Bundles/Headers.cc
+++ b/src/cripts/Bundles/Headers.cc
@@ -73,7 +73,7 @@ Headers::rm_headers(const Cript::string_view target, const
HeaderList &headers)
needCallback(Cript::Callbacks::DO_READ_RESPONSE);
break;
default:
- TSReleaseAssert(!"Invalid target for rm_headers()");
+ CFatal("[Cripts::Headers] Unknown header target: %s.", target.data());
}
return *this;
@@ -102,7 +102,7 @@ Headers::set_headers(const Cript::string_view target, const
HeaderValueList &hea
needCallback(Cript::Callbacks::DO_READ_RESPONSE);
break;
default:
- TSReleaseAssert(!"Invalid target for set_headers()");
+ CFatal("[Cripts::Headers] Unknown header target: %s.", target.data());
}
hdrs->reserve(headers.size());
diff --git a/src/cripts/Configs.cc b/src/cripts/Configs.cc
index 0c6dfca2f8..226b1b2f4c 100644
--- a/src/cripts/Configs.cc
+++ b/src/cripts/Configs.cc
@@ -21,68 +21,28 @@
namespace Cript
{
-integer
-IntConfig::_get(Cript::Context *context) const
-{
- integer value = -1;
-
- TSAssert(context->state.txnp);
- if (TSHttpTxnConfigIntGet(context->state.txnp, _key, &value) != TS_SUCCESS) {
- context->state.error.fail();
- }
-
- return value;
-}
-
-void
-IntConfig::_set(Cript::Context *context, integer value)
-{
- TSAssert(context->state.txnp);
- if (TSHttpTxnConfigIntSet(context->state.txnp, _key,
static_cast<TSMgmtInt>(value)) != TS_SUCCESS) {
- context->state.error.fail();
- }
-}
-
-float
-FloatConfig::_get(Cript::Context *context) const
-{
- float value = -1;
- TSAssert(context->state.txnp);
- if (TSHttpTxnConfigFloatGet(context->state.txnp, _key, &value) !=
TS_SUCCESS) {
- context->state.error.fail();
- }
-
- return value;
-}
-
-void
-FloatConfig::_set(Cript::Context *context, float value)
-{
- TSAssert(context->state.txnp);
- if (TSHttpTxnConfigFloatSet(context->state.txnp, _key,
static_cast<TSMgmtFloat>(value)) != TS_SUCCESS) {
- context->state.error.fail();
- }
-}
+std::unordered_map<Cript::string_view, const Records *> Records::_gRecords;
Records::Records(const Cript::string_view name)
{
TSOverridableConfigKey key;
TSRecordDataType type;
- if (TSHttpTxnConfigFind(name.data(), name.size(), &key, &type) !=
TS_SUCCESS) {
- TSError("Invalid configuration variable '%.*s'",
static_cast<int>(name.size()), name.data());
- TSReleaseAssert(!"Invalid configuration variable");
- } else {
+ if (TSHttpTxnConfigFind(name.data(), name.size(), &key, &type) ==
TS_SUCCESS) {
_name = name;
_key = key;
_type = type;
+ } else {
+ CFatal("[Records]: Invalid configuration variable '%.*s'",
static_cast<int>(name.size()), name.data());
}
}
Records::ValueType
Records::_get(const Cript::Context *context) const
{
+ TSAssert(context->state.txnp);
+
switch (_type) {
case TS_RECORDDATATYPE_INT: {
TSMgmtInt i;
@@ -98,25 +58,44 @@ Records::_get(const Cript::Context *context) const
return f;
}
} break;
+ case TS_RECORDDATATYPE_STRING: {
+ return std::string{getSV(context)};
+ } break;
+ default:
+ CFatal("[Records]: Invalid configuration type");
+ return 0;
+ }
+
+ return 0;
+}
+
+const Cript::string_view
+Records::getSV(const Cript::Context *context) const
+{
+ TSAssert(context->state.txnp);
+
+ switch (_type) {
case TS_RECORDDATATYPE_STRING: {
const char *s = nullptr;
int len = 0;
if (TSHttpTxnConfigStringGet(context->state.txnp, _key, &s, &len) ==
TS_SUCCESS) {
- return std::string(s, len);
+ return {s, len};
}
} break;
default:
- TSReleaseAssert(!"Invalid configuration type");
- return 0;
+ CFatal("[Records]: Invalid configuration type for getSV()");
+ break;
}
- return 0;
+ return {};
}
bool
-Records::_set(const Cript::Context *context, const ValueType value)
+Records::_set(const Cript::Context *context, const ValueType &value) const
{
+ TSAssert(context->state.txnp);
+
switch (_type) {
case TS_RECORDDATATYPE_INT: {
TSMgmtInt i = std::get<TSMgmtInt>(value);
@@ -139,18 +118,59 @@ Records::_set(const Cript::Context *context, const
ValueType value)
case TS_RECORDDATATYPE_STRING: {
auto &str = std::get<std::string>(value);
- if (TSHttpTxnConfigStringSet(context->state.txnp, _key, str.c_str(),
str.size()) != TS_SUCCESS) {
+ setSV(context, {str.data(), str.size()});
+ } break;
+ default:
+ CFatal("[Records]: Invalid configuration type");
+ return false;
+ }
+
+ return true; // Success
+}
+
+bool
+Records::setSV(const Cript::Context *context, const Cript::string_view value)
const
+{
+ TSAssert(context->state.txnp);
+
+ switch (_type) {
+ case TS_RECORDDATATYPE_STRING: {
+ if (TSHttpTxnConfigStringSet(context->state.txnp, _key, value.data(),
value.size()) != TS_SUCCESS) {
TSError("Failed to set string configuration '%s'", _name.c_str());
return false;
}
- CDebug("Set string configuration '{}' to '{}'", _name.c_str(),
str.c_str());
+ CDebug("Set string configuration '{}' to '{}'", _name.c_str(), value);
} break;
default:
- TSReleaseAssert(!"Invalid configuration type");
+ CFatal("[Records]: Invalid configuration type for setSV()");
return false;
}
return true; // Success
}
+// Static members for the records "cache"
+void
+Records::add(const Records *rec)
+{
+ CAssert(rec->loaded());
+ auto it = _gRecords.find(rec->name());
+
+ CAssert(it == _gRecords.end());
+ _gRecords[rec->name()] = rec;
+}
+
+const Records *
+Records::lookup(const Cript::string_view name)
+{
+ auto it = _gRecords.find(name);
+
+ if (it != _gRecords.end()) {
+ CAssert(it->second->loaded());
+ return it->second;
+ }
+
+ return nullptr;
+}
+
} // namespace Cript
diff --git a/src/cripts/Connections.cc b/src/cripts/Connections.cc
index 8b7bbd735a..931af5b40c 100644
--- a/src/cripts/Connections.cc
+++ b/src/cripts/Connections.cc
@@ -96,7 +96,7 @@ Cript::IP::hasher(unsigned ipv4_cidr, unsigned ipv6_cidr)
bool
Cript::IP::sample(double rate, uint32_t seed, unsigned ipv4_cidr, unsigned
ipv6_cidr)
{
- TSReleaseAssert(rate >= 0.0 && rate <= 1.0); // For detecting bugs in a
Cript, 0.0 and 1.0 are valid though
+ CAssert(rate >= 0.0 && rate <= 1.0); // For detecting bugs in a Cript, 0.0
and 1.0 are valid though
if (_sampler == 0) {
// This only works until 2038
diff --git a/src/cripts/Crypto.cc b/src/cripts/Crypto.cc
index 8bf36080c2..bf1ef1895f 100644
--- a/src/cripts/Crypto.cc
+++ b/src/cripts/Crypto.cc
@@ -152,8 +152,8 @@ Crypto::detail::Cipher::_initialize()
unsigned char iv[EVP_MAX_IV_LENGTH];
TSAssert(_ctx == nullptr);
- TSReleaseAssert(_cipher != nullptr);
- TSReleaseAssert(_key_len ==
static_cast<int>(EVP_CIPHER_key_length(_cipher))); // Make sure the crypto key
was correct size
+ CAssert(_cipher != nullptr);
+ CAssert(_key_len == static_cast<int>(EVP_CIPHER_key_length(_cipher))); //
Make sure the crypto key was correct size
memset(iv, 0, sizeof(iv)); // The IV is always '0x0'
_ctx = EVP_CIPHER_CTX_new();
diff --git a/src/cripts/Headers.cc b/src/cripts/Headers.cc
index 6f5b5509f8..88b6e77753 100644
--- a/src/cripts/Headers.cc
+++ b/src/cripts/Headers.cc
@@ -318,9 +318,9 @@ Header::iterate()
Client::Response &
Client::Response::_get(Cript::Context *context)
{
- TSReleaseAssert(context->state.hook != TS_HTTP_READ_REQUEST_HDR_HOOK);
- TSReleaseAssert(context->state.hook != TS_HTTP_POST_REMAP_HOOK);
- TSReleaseAssert(context->state.hook != TS_HTTP_SEND_REQUEST_HDR_HOOK);
+ CAssert(context->state.hook != TS_HTTP_READ_REQUEST_HDR_HOOK);
+ CAssert(context->state.hook != TS_HTTP_POST_REMAP_HOOK);
+ CAssert(context->state.hook != TS_HTTP_SEND_REQUEST_HDR_HOOK);
Client::Response *response = &context->_client_resp_header;
@@ -339,10 +339,10 @@ Client::Response::_get(Cript::Context *context)
Server::Request &
Server::Request::_get(Cript::Context *context)
{
- TSReleaseAssert(context->state.hook != TS_HTTP_READ_REQUEST_HDR_HOOK);
- TSReleaseAssert(context->state.hook != TS_HTTP_POST_REMAP_HOOK);
- TSReleaseAssert(context->state.hook != TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK);
- TSReleaseAssert(context->state.hook != TS_HTTP_READ_RESPONSE_HDR_HOOK);
+ CAssert(context->state.hook != TS_HTTP_READ_REQUEST_HDR_HOOK);
+ CAssert(context->state.hook != TS_HTTP_POST_REMAP_HOOK);
+ CAssert(context->state.hook != TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK);
+ CAssert(context->state.hook != TS_HTTP_READ_RESPONSE_HDR_HOOK);
Server::Request *request = &context->_server_req_header;
@@ -361,10 +361,10 @@ Server::Request::_get(Cript::Context *context)
Server::Response &
Server::Response::_get(Cript::Context *context)
{
- TSReleaseAssert(context->state.hook != TS_HTTP_READ_REQUEST_HDR_HOOK);
- TSReleaseAssert(context->state.hook != TS_HTTP_POST_REMAP_HOOK);
- TSReleaseAssert(context->state.hook != TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK);
- TSReleaseAssert(context->state.hook != TS_HTTP_SEND_REQUEST_HDR_HOOK);
+ CAssert(context->state.hook != TS_HTTP_READ_REQUEST_HDR_HOOK);
+ CAssert(context->state.hook != TS_HTTP_POST_REMAP_HOOK);
+ CAssert(context->state.hook != TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK);
+ CAssert(context->state.hook != TS_HTTP_SEND_REQUEST_HDR_HOOK);
Server::Response *response = &context->_server_resp_header;
diff --git a/src/cripts/Matcher.cc b/src/cripts/Matcher.cc
index 77e6246d1f..67ec165f61 100644
--- a/src/cripts/Matcher.cc
+++ b/src/cripts/Matcher.cc
@@ -34,7 +34,7 @@ Matcher::PCRE::Result::malloc(PCRE2_SIZE size, void *context)
auto *result = static_cast<Result *>(context);
std::byte *ret = result->_ctx_data + result->_ctx_ix;
- TSReleaseAssert(size < (sizeof(result->_ctx_data) - result->_ctx_ix));
+ CAssert(size < (sizeof(result->_ctx_data) - result->_ctx_ix));
result->_ctx_ix += size;
return ret;
@@ -52,13 +52,11 @@ Matcher::PCRE::add(Cript::string_view regex, uint32_t
options, bool jit)
PCRE2_UCHAR error[256];
pcre2_get_error_message(errorcode, error, sizeof(error));
- TSError("PCRE compile error `%s': %.*s", error,
static_cast<int>(regex.length()), regex.data());
- TSReleaseAssert(!"Failed to compile regex");
+ CFatal("[Matcher::PCRE]: PCRE compile error `%s': %.*s", error,
static_cast<int>(regex.length()), regex.data());
} else {
if (jit) {
if (0 != pcre2_jit_compile(re, PCRE2_JIT_COMPLETE)) {
- TSError("PCRE JIT compile error: %.*s",
static_cast<int>(regex.length()), regex.data());
- TSReleaseAssert(!"Failed to JIT compile regex");
+ CFatal("[Matcher::PCRE]: PCRE JIT compile error: %.*s",
static_cast<int>(regex.length()), regex.data());
}
}
_regexes.emplace_back(regex, re);
diff --git a/src/cripts/Urls.cc b/src/cripts/Urls.cc
index bbe25f10ec..d9108c9d36 100644
--- a/src/cripts/Urls.cc
+++ b/src/cripts/Urls.cc
@@ -43,7 +43,7 @@ Cript::Url::Scheme::getSV()
Cript::Url::Scheme
Cript::Url::Scheme::operator=(Cript::string_view scheme)
{
- TSReleaseAssert(!_owner->readOnly()); // This can not be a read-only URL
+ CAssert(!_owner->readOnly()); // This can not be a read-only URL
TSUrlSchemeSet(_owner->_bufp, _owner->_urlp, scheme.data(), scheme.size());
_owner->_modified = true;
reset();
@@ -70,7 +70,7 @@ Cript::Url::Host::getSV()
Cript::Url::Host
Cript::Url::Host::operator=(Cript::string_view host)
{
- TSReleaseAssert(!_owner->readOnly()); // This can not be a read-only URL
+ CAssert(!_owner->readOnly()); // This can not be a read-only URL
TSUrlHostSet(_owner->_bufp, _owner->_urlp, host.data(), host.size());
_owner->_modified = true;
reset();
@@ -91,7 +91,7 @@ Cript::Url::Port::operator integer() // This should not be
explicit
Cript::Url::Port
Cript::Url::Port::operator=(int port)
{
- TSReleaseAssert(!_owner->readOnly()); // This can not be a read-only URL
+ CAssert(!_owner->readOnly()); // This can not be a read-only URL
TSUrlPortSet(_owner->_bufp, _owner->_urlp, port);
_owner->_modified = true;
reset();
@@ -142,7 +142,7 @@ Cript::Url::Path::operator[](Segments::size_type ix)
Cript::Url::Path
Cript::Url::Path::operator=(Cript::string_view path)
{
- TSReleaseAssert(!_owner->readOnly()); // This can not be a read-only URL
+ CAssert(!_owner->readOnly()); // This can not be a read-only URL
TSUrlPathSet(_owner->_bufp, _owner->_urlp, path.data(), path.size());
_owner->_modified = true;
reset();
@@ -168,7 +168,7 @@ Cript::Url::Path::operator+=(Cript::string_view add)
Cript::Url::Path::String &
Cript::Url::Path::String::operator=(const Cript::string_view str)
{
- TSReleaseAssert(!_owner->_owner->readOnly()); // This can not be a read-only
URL
+ CAssert(!_owner->_owner->readOnly()); // This can not be a read-only URL
_owner->_size -= _owner->_segments[_ix].size();
_owner->_segments[_ix] = str;
_owner->_size += str.size();
@@ -215,7 +215,7 @@ Cript::Url::Path::_parser()
Cript::Url::Query::Parameter &
Cript::Url::Query::Parameter::operator=(const Cript::string_view str)
{
- TSReleaseAssert(!_owner->_owner->readOnly()); // This can not be a read-only
URL
+ CAssert(!_owner->_owner->readOnly()); // This can not be a read-only URL
auto iter = _owner->_hashed.find(_name);
if (iter != _owner->_hashed.end()) {
@@ -275,7 +275,7 @@ Cript::Url::Query::getSV()
Cript::Url::Query
Cript::Url::Query::operator=(Cript::string_view query)
{
- TSReleaseAssert(!_owner->readOnly()); // This can not be a read-only URL
+ CAssert(!_owner->readOnly()); // This can not be a read-only URL
TSUrlHttpQuerySet(_owner->_bufp, _owner->_urlp, query.data(), query.size());
_owner->_modified = true;
reset();
@@ -329,7 +329,7 @@ Cript::Url::Query::erase(Cript::string_view param)
_size -= iter->second.size(); // Size of the erased value
_hashed.erase(iter);
- TSReleaseAssert(viter != _ordered.end());
+ CAssert(viter != _ordered.end());
_size -= viter->size(); // Length of the erased key
_ordered.erase(viter);
@@ -351,7 +351,7 @@
Cript::Url::Query::erase(std::initializer_list<Cript::string_view> list, bool ke
if (list.end() == std::find(list.begin(), list.end(), *viter)) {
auto iter = _hashed.find(*viter);
- TSReleaseAssert(iter != _hashed.end());
+ CAssert(iter != _hashed.end());
_size -= iter->second.size(); // Size of the erased value
_size -= viter->size(); // Length of the erased key
_hashed.erase(iter);
@@ -420,7 +420,7 @@ Cript::Url::Matrix::getSV()
Cript::Url::Matrix
Cript::Url::Matrix::operator=(Cript::string_view matrix)
{
- TSReleaseAssert(!_owner->readOnly()); // This can not be a read-only URL
+ CAssert(!_owner->readOnly()); // This can not be a read-only URL
TSUrlHttpParamsSet(_owner->_bufp, _owner->_urlp, matrix.data(),
matrix.size());
_owner->_modified = true;
reset();
diff --git a/tools/cripts/genconfig.py b/tools/cripts/genconfig.py
index 34bb4b2031..579867f676 100755
--- a/tools/cripts/genconfig.py
+++ b/tools/cripts/genconfig.py
@@ -79,13 +79,11 @@ def print_class(tree, cur="", indent=0):
indentp("public:", indent - 1)
firstInstance = False
if tree[k][1] == "TS_RECORDDATATYPE_INT":
- indentp("Cript::IntConfig {}{{{}}};".format(k, tree[k][0]),
indent)
+ indentp("Cript::IntConfig {}{{\"{}\"}};".format(k,
tree[k][2]), indent)
elif tree[k][1] == "TS_RECORDDATATYPE_FLOAT":
- indentp("Cript::FloatConfig {}{{{}}};".format(k, tree[k][0]),
indent)
+ indentp("Cript::FloatConfig {}{{\"{}\"}};".format(k,
tree[k][2]), indent)
elif tree[k][1] == "TS_RECORDDATATYPE_STRING":
- pass
- # ToDo: Support strings somehow??
- # indentp("StringConfig {}{{{}}};".format(k, tree[k][0]),
indent + 1)
+ indentp("Cript::StringConfig {}{{\"{}\"}};".format(k,
tree[k][2]), indent)
else:
print("The source file has a bad configuration data type:
{}".format(tree[k][1]))
if cur:
@@ -112,7 +110,6 @@ while i < len(lines):
conf = conf.strip(" {\"").rstrip("\" ")
enum = enum.strip(" {")
type = type.strip(" ").rstrip(",}); ")
- # parts = conf.split(".")
elements.append((conf, enum, type))
i += 1
@@ -120,13 +117,14 @@ tree = {}
elements.sort()
for elem in elements:
cur = tree
+ name = elem[0]
parts = elem[0].split(".")
size = len(parts) - 1
for ix, part in enumerate(parts):
sub = cur.get(part)
if sub is None:
if ix == size:
- cur[part] = (elem[1], elem[2])
+ cur[part] = (elem[1], elem[2], name)
else:
cur[part] = {}
cur = cur[part]