You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2017/02/21 03:38:00 UTC
[trafficserver] 04/04: Replace config_parse_error with Result.
This is an automated email from the ASF dual-hosted git repository.
jpeach pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git
commit 39f8e5c057386bffd51f5ba2284d2e715543e100
Author: James Peach <jp...@apache.org>
AuthorDate: Sat Feb 18 14:41:53 2017 -0800
Replace config_parse_error with Result.
---
iocore/dns/P_SplitDNSProcessor.h | 2 +-
iocore/dns/SplitDNS.cc | 18 ++++++-------
lib/ts/MatcherUtils.cc | 16 ------------
lib/ts/MatcherUtils.h | 43 +------------------------------
proxy/CacheControl.cc | 16 ++++++------
proxy/CacheControl.h | 4 +--
proxy/ControlMatcher.cc | 55 ++++++++++++++++++++--------------------
proxy/ControlMatcher.h | 9 ++++---
proxy/ParentSelection.cc | 12 ++++-----
proxy/ParentSelection.h | 2 +-
proxy/congest/Congestion.cc | 31 +++++++++++-----------
proxy/congest/Congestion.h | 5 ++--
12 files changed, 79 insertions(+), 134 deletions(-)
diff --git a/iocore/dns/P_SplitDNSProcessor.h b/iocore/dns/P_SplitDNSProcessor.h
index 33e9947..16481b4 100644
--- a/iocore/dns/P_SplitDNSProcessor.h
+++ b/iocore/dns/P_SplitDNSProcessor.h
@@ -196,7 +196,7 @@ public:
SplitDNSRecord();
~SplitDNSRecord();
- config_parse_error Init(matcher_line *line_info);
+ Result Init(matcher_line *line_info);
const char *ProcessDNSHosts(char *val);
const char *ProcessDomainSrchList(char *val);
diff --git a/iocore/dns/SplitDNS.cc b/iocore/dns/SplitDNS.cc
index 4a043d0..9bd69f0 100644
--- a/iocore/dns/SplitDNS.cc
+++ b/iocore/dns/SplitDNS.cc
@@ -428,7 +428,7 @@ SplitDNSRecord::ProcessDomainSrchList(char *val)
matcher_line* line_info - contains parsed label/value pairs
of the current split.config line
-------------------------------------------------------------- */
-config_parse_error
+Result
SplitDNSRecord::Init(matcher_line *line_info)
{
const char *errPtr = nullptr;
@@ -447,7 +447,7 @@ SplitDNSRecord::Init(matcher_line *line_info)
if (strcasecmp(label, "def_domain") == 0) {
if (nullptr != (errPtr = ProcessDefDomain(val))) {
- return config_parse_error("%s %s at line %d", modulePrefix, errPtr, line_num);
+ return Result::failure("%s %s at line %d", modulePrefix, errPtr, line_num);
}
line_info->line[0][i] = nullptr;
line_info->num_el--;
@@ -456,7 +456,7 @@ SplitDNSRecord::Init(matcher_line *line_info)
if (strcasecmp(label, "search_list") == 0) {
if (nullptr != (errPtr = ProcessDomainSrchList(val))) {
- return config_parse_error("%s %s at line %d", modulePrefix, errPtr, line_num);
+ return Result::failure("%s %s at line %d", modulePrefix, errPtr, line_num);
}
line_info->line[0][i] = nullptr;
line_info->num_el--;
@@ -465,7 +465,7 @@ SplitDNSRecord::Init(matcher_line *line_info)
if (strcasecmp(label, "named") == 0) {
if (nullptr != (errPtr = ProcessDNSHosts(val))) {
- return config_parse_error("%s %s at line %d", modulePrefix, errPtr, line_num);
+ return Result::failure("%s %s at line %d", modulePrefix, errPtr, line_num);
}
line_info->line[0][i] = nullptr;
line_info->num_el--;
@@ -474,7 +474,7 @@ SplitDNSRecord::Init(matcher_line *line_info)
}
if (!ats_is_ip(&m_servers.x_server_ip[0].sa)) {
- return config_parse_error("%s No server specified in splitdns.config at line %d", modulePrefix, line_num);
+ return Result::failure("%s No server specified in splitdns.config at line %d", modulePrefix, line_num);
}
DNSHandler *dnsH = new DNSHandler;
@@ -484,8 +484,8 @@ SplitDNSRecord::Init(matcher_line *line_info)
if ((-1 == ink_res_init(res, m_servers.x_server_ip, m_dnsSrvr_cnt, dns_search, m_servers.x_def_domain,
m_servers.x_domain_srch_list, nullptr))) {
char ab[INET6_ADDRPORTSTRLEN];
- return config_parse_error("Failed to build res record for the servers %s ...",
- ats_ip_ntop(&m_servers.x_server_ip[0].sa, ab, sizeof ab));
+ return Result::failure("Failed to build res record for the servers %s ...",
+ ats_ip_ntop(&m_servers.x_server_ip[0].sa, ab, sizeof ab));
}
dnsH->m_res = res;
@@ -503,11 +503,11 @@ SplitDNSRecord::Init(matcher_line *line_info)
if (line_info->num_el > 0) {
tmp = ProcessModifiers(line_info);
if (tmp != nullptr) {
- return config_parse_error("%s %s at line %d in splitdns.config", modulePrefix, tmp, line_num);
+ return Result::failure("%s %s at line %d in splitdns.config", modulePrefix, tmp, line_num);
}
}
- return config_parse_error::ok();
+ return Result::ok();
}
/* --------------------------------------------------------------
diff --git a/lib/ts/MatcherUtils.cc b/lib/ts/MatcherUtils.cc
index 5c5f32f..6e155a6 100644
--- a/lib/ts/MatcherUtils.cc
+++ b/lib/ts/MatcherUtils.cc
@@ -37,22 +37,6 @@
#include "ts/MatcherUtils.h"
#include "ts/Tokenizer.h"
-config_parse_error::config_parse_error(const char *fmt, ...)
-{
- va_list ap;
- int num;
-
- va_start(ap, fmt);
- num = vsnprintf(nullptr, 0, fmt, ap);
- va_end(ap);
-
- this->msg = (char *)ats_malloc(num + 1);
-
- va_start(ap, fmt);
- vsnprintf(&this->msg[0], num + 1, fmt, ap);
- va_end(ap);
-}
-
// char* readIntoBuffer(const char* file_path, const char* module_name,
// int* read_size_ptr)
//
diff --git a/lib/ts/MatcherUtils.h b/lib/ts/MatcherUtils.h
index 4893234..1cbe7b0 100644
--- a/lib/ts/MatcherUtils.h
+++ b/lib/ts/MatcherUtils.h
@@ -33,6 +33,7 @@
#define _MATCHER_UTILS_H_
#include "ts/ParseRules.h"
+#include "ts/Result.h"
#include "ts/ink_inet.h"
// Look in MatcherUtils.cc for comments on function usage
@@ -114,48 +115,6 @@ extern const matcher_tags socks_server_tags;
const char *parseConfigLine(char *line, matcher_line *p_line, const matcher_tags *tags);
-struct config_parse_error {
- // Wrapper to make a syntactically nice success value.
- static config_parse_error
- ok()
- {
- return config_parse_error();
- }
-
- config_parse_error(const config_parse_error &rhs)
- {
- if (rhs.msg.get()) {
- this->msg = ats_strdup(rhs.msg.get());
- }
- }
-
- explicit config_parse_error(const char *fmt, ...) TS_NONNULL(2) TS_PRINTFLIKE(2, 3);
-
- config_parse_error &
- operator=(const config_parse_error &rhs)
- {
- if (rhs.msg.get()) {
- this->msg = ats_strdup(rhs.msg.get());
- } else {
- this->msg = (char *)nullptr;
- }
-
- return *this;
- }
-
- const char *
- get() const
- {
- return msg.get();
- }
-
- // A config error object evaluates to true if there is an error message.
- operator bool() const { return msg.get() != nullptr; }
-private:
- config_parse_error() {}
- ats_scoped_str msg;
-};
-
// inline void LowerCaseStr(char* str)
//
// Modifies str so all characters are lower
diff --git a/proxy/CacheControl.cc b/proxy/CacheControl.cc
index 947aabb..d945b67 100644
--- a/proxy/CacheControl.cc
+++ b/proxy/CacheControl.cc
@@ -239,7 +239,7 @@ CacheControlRecord::Print()
ControlBase::Print();
}
-// config_parse_error CacheControlRecord::Init(matcher_line* line_info)
+// Result CacheControlRecord::Init(matcher_line* line_info)
//
// matcher_line* line_info - contains parsed label/value
// pairs of the current cache.config line
@@ -248,7 +248,7 @@ CacheControlRecord::Print()
// Otherwise, returns an error string that the caller MUST
// DEALLOCATE with free()
//
-config_parse_error
+Result
CacheControlRecord::Init(matcher_line *line_info)
{
int time_in;
@@ -272,7 +272,7 @@ CacheControlRecord::Init(matcher_line *line_info)
char *ptr = nullptr;
int v = strtol(val, &ptr, 0);
if (!ptr || v < 0 || v > 4) {
- return config_parse_error("Value for " TWEAK_CACHE_RESPONSES_TO_COOKIES " must be an integer in the range 0..4");
+ return Result::failure("Value for " TWEAK_CACHE_RESPONSES_TO_COOKIES " must be an integer in the range 0..4");
} else {
cache_responses_to_cookies = v;
}
@@ -316,7 +316,7 @@ CacheControlRecord::Init(matcher_line *line_info)
directive = CC_IGNORE_SERVER_NO_CACHE;
d_found = true;
} else {
- return config_parse_error("%s Invalid action at line %d in cache.config", modulePrefix, line_num);
+ return Result::failure("%s Invalid action at line %d in cache.config", modulePrefix, line_num);
}
} else {
if (strcasecmp(label, "revalidate") == 0) {
@@ -336,7 +336,7 @@ CacheControlRecord::Init(matcher_line *line_info)
this->time_arg = time_in;
} else {
- return config_parse_error("%s %s at line %d in cache.config", modulePrefix, tmp, line_num);
+ return Result::failure("%s %s at line %d in cache.config", modulePrefix, tmp, line_num);
}
}
}
@@ -350,18 +350,18 @@ CacheControlRecord::Init(matcher_line *line_info)
}
if (d_found == false) {
- return config_parse_error("%s No directive in cache.config at line %d", modulePrefix, line_num);
+ return Result::failure("%s No directive in cache.config at line %d", modulePrefix, line_num);
}
// Process any modifiers to the directive, if they exist
if (line_info->num_el > 0) {
tmp = ProcessModifiers(line_info);
if (tmp != nullptr) {
- return config_parse_error("%s %s at line %d in cache.config", modulePrefix, tmp, line_num);
+ return Result::failure("%s %s at line %d in cache.config", modulePrefix, tmp, line_num);
}
}
- return config_parse_error::ok();
+ return Result::ok();
}
// void CacheControlRecord::UpdateMatch(CacheControlResult* result, RequestData* rdata)
diff --git a/proxy/CacheControl.h b/proxy/CacheControl.h
index 259eea5..6d598e1 100644
--- a/proxy/CacheControl.h
+++ b/proxy/CacheControl.h
@@ -34,7 +34,7 @@
#include "Main.h"
#include "P_EventSystem.h"
#include "ControlBase.h"
-#include "ts/MatcherUtils.h"
+#include "ts/Result.h"
struct RequestData;
@@ -126,7 +126,7 @@ public:
CacheControlType directive;
int time_arg;
int cache_responses_to_cookies;
- config_parse_error Init(matcher_line *line_info);
+ Result Init(matcher_line *line_info);
inkcoreapi void UpdateMatch(CacheControlResult *result, RequestData *rdata);
void Print();
};
diff --git a/proxy/ControlMatcher.cc b/proxy/ControlMatcher.cc
index 13cb1a7..a49f854 100644
--- a/proxy/ControlMatcher.cc
+++ b/proxy/ControlMatcher.cc
@@ -180,7 +180,7 @@ HostMatcher<Data, MatchResult>::Match(RequestData *rdata, MatchResult *result)
}
//
-// config_parse_error HostMatcher<Data,MatchResult>::NewEntry(bool domain_record,
+// Result HostMatcher<Data,MatchResult>::NewEntry(bool domain_record,
// char* match_data, char* match_info, int line_num)
//
// Creates a new host/domain record
@@ -190,11 +190,11 @@ HostMatcher<Data, MatchResult>::Match(RequestData *rdata, MatchResult *result)
// that the caller MUST DEALLOCATE
//
template <class Data, class MatchResult>
-config_parse_error
+Result
HostMatcher<Data, MatchResult>::NewEntry(matcher_line *line_info)
{
Data *cur_d;
- config_parse_error error = config_parse_error::ok();
+ Result error = Result::ok();
char *match_data;
// Make sure space has been allocated
@@ -217,7 +217,7 @@ HostMatcher<Data, MatchResult>::NewEntry(matcher_line *line_info)
// Fill in the parameter info
cur_d = data_array + num_el;
error = cur_d->Init(line_info);
- if (error) {
+ if (error.failed()) {
// There was a problem so undo the effects this function
memset(cur_d, 0, sizeof(Data));
} else {
@@ -299,16 +299,16 @@ UrlMatcher<Data, MatchResult>::AllocateSpace(int num_entries)
}
//
-// config_parse_error UrlMatcher<Data,MatchResult>::NewEntry(matcher_line* line_info)
+// Result UrlMatcher<Data,MatchResult>::NewEntry(matcher_line* line_info)
//
template <class Data, class MatchResult>
-config_parse_error
+Result
UrlMatcher<Data, MatchResult>::NewEntry(matcher_line *line_info)
{
Data *cur_d;
char *pattern;
int *value;
- config_parse_error error = config_parse_error::ok();
+ Result error = Result::ok();
// Make sure space has been allocated
ink_assert(num_el >= 0);
@@ -323,7 +323,7 @@ UrlMatcher<Data, MatchResult>::NewEntry(matcher_line *line_info)
ink_assert(pattern != nullptr);
if (ink_hash_table_lookup(url_ht, pattern, (void **)&value)) {
- return config_parse_error("%s url expression error (have exist) at line %d position", matcher_name, line_info->line_num);
+ return Result::failure("%s url expression error (have exist) at line %d position", matcher_name, line_info->line_num);
}
// Remove our consumed label from the parsed line
@@ -333,7 +333,7 @@ UrlMatcher<Data, MatchResult>::NewEntry(matcher_line *line_info)
// Fill in the parameter info
cur_d = data_array + num_el;
error = cur_d->Init(line_info);
- if (error) {
+ if (error.failed()) {
url_str[num_el] = ats_strdup(pattern);
url_value[num_el] = num_el;
ink_hash_table_insert(url_ht, url_str[num_el], (void *)&url_value[num_el]);
@@ -440,17 +440,17 @@ RegexMatcher<Data, MatchResult>::AllocateSpace(int num_entries)
}
//
-// config_parse_error RegexMatcher<Data,MatchResult>::NewEntry(matcher_line* line_info)
+// Result RegexMatcher<Data,MatchResult>::NewEntry(matcher_line* line_info)
//
template <class Data, class MatchResult>
-config_parse_error
+Result
RegexMatcher<Data, MatchResult>::NewEntry(matcher_line *line_info)
{
Data *cur_d;
char *pattern;
const char *errptr;
int erroffset;
- config_parse_error error = config_parse_error::ok();
+ Result error = Result::ok();
// Make sure space has been allocated
ink_assert(num_el >= 0);
@@ -467,8 +467,8 @@ RegexMatcher<Data, MatchResult>::NewEntry(matcher_line *line_info)
// Create the compiled regular expression
re_array[num_el] = pcre_compile(pattern, 0, &errptr, &erroffset, nullptr);
if (!re_array[num_el]) {
- return config_parse_error("%s regular expression error at line %d position %d : %s", matcher_name, line_info->line_num,
- erroffset, errptr);
+ return Result::failure("%s regular expression error at line %d position %d : %s", matcher_name, line_info->line_num, erroffset,
+ errptr);
}
re_str[num_el] = ats_strdup(pattern);
@@ -480,7 +480,7 @@ RegexMatcher<Data, MatchResult>::NewEntry(matcher_line *line_info)
cur_d = data_array + num_el;
error = cur_d->Init(line_info);
- if (error) {
+ if (error.failed()) {
// There was a problem so undo the effects this function
ats_free(re_str[num_el]);
re_str[num_el] = nullptr;
@@ -619,7 +619,7 @@ IpMatcher<Data, MatchResult>::AllocateSpace(int num_entries)
}
//
-// config_parse_error IpMatcher<Data,MatchResult>::NewEntry(matcher_line* line_info)
+// Result IpMatcher<Data,MatchResult>::NewEntry(matcher_line* line_info)
//
// Inserts a range the ip lookup table.
// Creates new table levels as needed
@@ -629,14 +629,14 @@ IpMatcher<Data, MatchResult>::AllocateSpace(int num_entries)
// for deallocating
//
template <class Data, class MatchResult>
-config_parse_error
+Result
IpMatcher<Data, MatchResult>::NewEntry(matcher_line *line_info)
{
Data *cur_d;
const char *errptr;
char *match_data;
IpEndpoint addr1, addr2;
- config_parse_error error = config_parse_error::ok();
+ Result error = Result::ok();
// Make sure space has been allocated
ink_assert(num_el >= 0);
@@ -654,7 +654,7 @@ IpMatcher<Data, MatchResult>::NewEntry(matcher_line *line_info)
// Extract the IP range
errptr = ExtractIpRange(match_data, &addr1.sa, &addr2.sa);
if (errptr != nullptr) {
- return config_parse_error("%s %s at %s line %d", matcher_name, errptr, file_name, line_info->line_num);
+ return Result::failure("%s %s at %s line %d", matcher_name, errptr, file_name, line_info->line_num);
}
// Remove our consumed label from the parsed line
@@ -664,7 +664,7 @@ IpMatcher<Data, MatchResult>::NewEntry(matcher_line *line_info)
// Fill in the parameter info
cur_d = data_array + num_el;
error = cur_d->Init(line_info);
- if (!error) {
+ if (!error.failed()) {
ip_map.mark(&addr1.sa, &addr2.sa, cur_d);
++num_el;
}
@@ -842,8 +842,9 @@ ControlMatcher<Data, MatchResult>::BuildTableFromString(char *file_buf)
if (errptr != nullptr) {
if (config_tags != &socks_server_tags) {
- config_parse_error error("%s discarding %s entry at line %d : %s", matcher_name, config_file_path, line_num, errptr);
- SignalError(error.get(), alarmAlready);
+ Result error =
+ Result::failure("%s discarding %s entry at line %d : %s", matcher_name, config_file_path, line_num, errptr);
+ SignalError(error.message(), alarmAlready);
}
ats_free(current);
} else {
@@ -919,7 +920,7 @@ ControlMatcher<Data, MatchResult>::BuildTableFromString(char *file_buf)
// Traverse the list and build the records table
current = first;
while (current != nullptr) {
- config_parse_error error = config_parse_error::ok();
+ Result error = Result::ok();
second_pass++;
if ((flags & ALLOW_HOST_TABLE) && current->type == MATCH_DOMAIN) {
@@ -935,14 +936,14 @@ ControlMatcher<Data, MatchResult>::BuildTableFromString(char *file_buf)
} else if ((flags & ALLOW_HOST_REGEX_TABLE) && current->type == MATCH_HOST_REGEX) {
error = hrMatch->NewEntry(current);
} else {
- error = config_parse_error("%s discarding %s entry with unknown type at line %d", matcher_name, config_file_path,
- current->line_num);
+ error =
+ Result::failure("%s discarding %s entry with unknown type at line %d", matcher_name, config_file_path, current->line_num);
}
// Check to see if there was an error in creating
// the NewEntry
- if (error) {
- SignalError(error.get(), alarmAlready);
+ if (error.failed()) {
+ SignalError(error.message(), alarmAlready);
}
// Deallocate the parsing structure
diff --git a/proxy/ControlMatcher.h b/proxy/ControlMatcher.h
index 0501dbb..b3f0f0d 100644
--- a/proxy/ControlMatcher.h
+++ b/proxy/ControlMatcher.h
@@ -90,6 +90,7 @@
#include "ts/DynArray.h"
#include "ts/ink_hash_table.h"
#include "ts/IpMap.h"
+#include "ts/Result.h"
#include "ts/MatcherUtils.h"
#include "ts/ink_apidefs.h"
@@ -172,7 +173,7 @@ public:
~UrlMatcher();
void Match(RequestData *rdata, MatchResult *result);
void AllocateSpace(int num_entries);
- config_parse_error NewEntry(matcher_line *line_info);
+ Result NewEntry(matcher_line *line_info);
void Print();
int
@@ -204,7 +205,7 @@ public:
~RegexMatcher();
void Match(RequestData *rdata, MatchResult *result);
void AllocateSpace(int num_entries);
- config_parse_error NewEntry(matcher_line *line_info);
+ Result NewEntry(matcher_line *line_info);
void Print();
int
@@ -242,7 +243,7 @@ public:
~HostMatcher();
void Match(RequestData *rdata, MatchResult *result);
void AllocateSpace(int num_entries);
- config_parse_error NewEntry(matcher_line *line_info);
+ Result NewEntry(matcher_line *line_info);
void Print();
int
@@ -278,7 +279,7 @@ public:
~IpMatcher();
void Match(sockaddr const *ip_addr, RequestData *rdata, MatchResult *result);
void AllocateSpace(int num_entries);
- config_parse_error NewEntry(matcher_line *line_info);
+ Result NewEntry(matcher_line *line_info);
void Print();
int
diff --git a/proxy/ParentSelection.cc b/proxy/ParentSelection.cc
index 3b08812..6659f9d 100644
--- a/proxy/ParentSelection.cc
+++ b/proxy/ParentSelection.cc
@@ -505,7 +505,7 @@ ParentRecord::DefaultInit(char *val)
}
}
-// config_parse_error ParentRecord::Init(matcher_line* line_info)
+// Result ParentRecord::Init(matcher_line* line_info)
//
// matcher_line* line_info - contains parsed label/value
// pairs of the current cache.config line
@@ -514,7 +514,7 @@ ParentRecord::DefaultInit(char *val)
// Otherwise, returns an error string that the caller MUST
// DEALLOCATE with ats_free()
//
-config_parse_error
+Result
ParentRecord::Init(matcher_line *line_info)
{
const char *errPtr = nullptr;
@@ -622,7 +622,7 @@ ParentRecord::Init(matcher_line *line_info)
}
// Report errors generated by ProcessParents();
if (errPtr != nullptr) {
- return config_parse_error("%s %s at line %d", modulePrefix, errPtr, line_num);
+ return Result::failure("%s %s at line %d", modulePrefix, errPtr, line_num);
}
if (used == true) {
@@ -657,14 +657,14 @@ ParentRecord::Init(matcher_line *line_info)
}
if (this->parents == nullptr && go_direct == false) {
- return config_parse_error("%s No parent specified in parent.config at line %d", modulePrefix, line_num);
+ return Result::failure("%s No parent specified in parent.config at line %d", modulePrefix, line_num);
}
// Process any modifiers to the directive, if they exist
if (line_info->num_el > 0) {
tmp = ProcessModifiers(line_info);
if (tmp != nullptr) {
- return config_parse_error("%s %s at line %d in parent.config", modulePrefix, tmp, line_num);
+ return Result::failure("%s %s at line %d in parent.config", modulePrefix, tmp, line_num);
}
// record SCHEME modifier if present.
// NULL if not present
@@ -698,7 +698,7 @@ ParentRecord::Init(matcher_line *line_info)
ink_release_assert(0);
}
- return config_parse_error::ok();
+ return Result::ok();
}
// void ParentRecord::UpdateMatch(ParentResult* result, RequestData* rdata);
diff --git a/proxy/ParentSelection.h b/proxy/ParentSelection.h
index 78c0942..10686a8 100644
--- a/proxy/ParentSelection.h
+++ b/proxy/ParentSelection.h
@@ -133,7 +133,7 @@ public:
~ParentRecord();
- config_parse_error Init(matcher_line *line_info);
+ Result Init(matcher_line *line_info);
bool DefaultInit(char *val);
void UpdateMatch(ParentResult *result, RequestData *rdata);
void Print();
diff --git a/proxy/congest/Congestion.cc b/proxy/congest/Congestion.cc
index bf33cfa..e2bfdfd 100644
--- a/proxy/congest/Congestion.cc
+++ b/proxy/congest/Congestion.cc
@@ -125,14 +125,13 @@ CongestionControlRecord::setdefault()
max_connection = DEFAULT_max_connection;
}
-config_parse_error
+Result
CongestionControlRecord::validate()
{
-#define IsGt0(var) \
- if (var < 1) { \
- config_parse_error error("line %d: invalid %s = %d, %s must > 0", line_num, #var, var, #var); \
- cleanup(); \
- return error; \
+#define IsGt0(var) \
+ if (var < 1) { \
+ cleanup(); \
+ return Result::failure("line %d: invalid %s = %d, %s must > 0", line_num, #var, var, #var); \
}
if (error_page == NULL) {
@@ -140,10 +139,9 @@ CongestionControlRecord::validate()
}
if (max_connection_failures >= CONG_RULE_MAX_max_connection_failures ||
(max_connection_failures <= 0 && max_connection_failures != CONG_RULE_ULIMITED_max_connection_failures)) {
- config_parse_error error("line %d: invalid %s = %d not in [1, %d) range", line_num, "max_connection_failures",
- max_connection_failures, CONG_RULE_MAX_max_connection_failures);
cleanup();
- return error;
+ return Result::failure("line %d: invalid %s = %d not in [1, %d) range", line_num, "max_connection_failures",
+ max_connection_failures, CONG_RULE_MAX_max_connection_failures);
}
IsGt0(fail_window);
@@ -160,10 +158,10 @@ CongestionControlRecord::validate()
// max_connection == 0, no connection allow to the origin server for the rule
#undef IsGt0
- return config_parse_error::ok();
+ return Result::ok();
}
-config_parse_error
+Result
CongestionControlRecord::Init(matcher_line *line_info)
{
const char *tmp;
@@ -233,16 +231,17 @@ CongestionControlRecord::Init(matcher_line *line_info)
tmp = ProcessModifiers(line_info);
if (tmp != NULL) {
- return config_parse_error("%s %s at line %d in congestion.config", congestPrefix, tmp, line_num);
+ return Result::failure("%s %s at line %d in congestion.config", congestPrefix, tmp, line_num);
}
}
- config_parse_error error = validate();
- if (!error) {
- pRecord = new CongestionControlRecord(*this);
+ Result result = validate();
+ if (result.failed()) {
+ return result;
}
- return error;
+ pRecord = new CongestionControlRecord(*this);
+ return Result::ok();
}
void
diff --git a/proxy/congest/Congestion.h b/proxy/congest/Congestion.h
index 3507d10..4c4dd86 100644
--- a/proxy/congest/Congestion.h
+++ b/proxy/congest/Congestion.h
@@ -32,6 +32,7 @@
#define CONGESTION_H_
#include "ts/ink_platform.h"
+#include "ts/Result.h"
#include "P_EventSystem.h"
#include "ControlBase.h"
#include "ControlMatcher.h"
@@ -65,13 +66,13 @@ public:
CongestionControlRecord();
CongestionControlRecord(const CongestionControlRecord &rec);
~CongestionControlRecord();
- config_parse_error Init(matcher_line *line_info);
+ Result Init(matcher_line *line_info);
void UpdateMatch(CongestionControlRule *pRule, RequestData *rdata);
void Print();
void cleanup();
void setdefault();
- config_parse_error validate();
+ Result validate();
int rank; // matching preference
/*
--
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.