You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2017/11/01 17:55:18 UTC
[trafficserver] 02/03: Removes the rest of the CfgContext files and
objects
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
commit 372e9dea376c3c28819b4322a37262635b4608f0
Author: Leif Hedstrom <zw...@apache.org>
AuthorDate: Thu Oct 12 19:28:34 2017 -0600
Removes the rest of the CfgContext files and objects
---
lib/perl/lib/Apache/TS/AdminClient.pm | 43 +-
mgmt/api/APITestCliRemote.cc | 394 +----
mgmt/api/CfgContextImpl.cc | 2135 -------------------------
mgmt/api/CfgContextImpl.h | 435 ------
mgmt/api/CfgContextUtils.cc | 2756 ---------------------------------
mgmt/api/CfgContextUtils.h | 194 ---
mgmt/api/CoreAPI.cc | 53 -
mgmt/api/CoreAPI.h | 11 +-
mgmt/api/CoreAPIRemote.cc | 61 +-
mgmt/api/EventControlMain.cc | 1 -
mgmt/api/INKMgmtAPI.cc | 74 +-
mgmt/api/Makefile.am | 5 -
mgmt/api/NetworkMessage.cc | 6 -
mgmt/api/NetworkMessage.h | 1 -
mgmt/api/TSControlMain.cc | 40 -
mgmt/api/include/mgmtapi.h | 27 -
16 files changed, 30 insertions(+), 6206 deletions(-)
diff --git a/lib/perl/lib/Apache/TS/AdminClient.pm b/lib/perl/lib/Apache/TS/AdminClient.pm
index b0aad94..d9c9723 100644
--- a/lib/perl/lib/Apache/TS/AdminClient.pm
+++ b/lib/perl/lib/Apache/TS/AdminClient.pm
@@ -30,28 +30,27 @@ use Apache::TS;
# Mgmt API command constants, should track ts/mgmtapi.h
use constant {
- TS_FILE_READ => 0,
- TS_RECORD_SET => 1,
- TS_RECORD_GET => 2,
- TS_PROXY_STATE_GET => 3,
- TS_PROXY_STATE_SET => 4,
- TS_RECONFIGURE => 5,
- TS_RESTART => 6,
- TS_BOUNCE => 7,
- TS_EVENT_RESOLVE => 8,
- TS_EVENT_GET_MLT => 9,
- TS_EVENT_ACTIVE => 10,
- TS_EVENT_REG_CALLBACK => 11,
- TS_EVENT_UNREG_CALLBACK => 12,
- TS_EVENT_NOTIFY => 13,
- TS_STATS_RESET_NODE => 14,
- TS_STORAGE_DEVICE_CMD_OFFLINE => 15,
- TS_RECORD_MATCH_GET => 16,
- TS_API_PING => 17,
- TS_SERVER_BACKTRACE => 18,
- TS_RECORD_DESCRIBE_CONFIG => 19,
- TS_LIFECYCLE_MESSAGE => 20,
- TS_UNDEFINED_OP => 21
+ TS_RECORD_SET => 0,
+ TS_RECORD_GET => 1,
+ TS_PROXY_STATE_GET => 2,
+ TS_PROXY_STATE_SET => 3,
+ TS_RECONFIGURE => 4,
+ TS_RESTART => 5,
+ TS_BOUNCE => 6,
+ TS_EVENT_RESOLVE => 7,
+ TS_EVENT_GET_MLT => 8,
+ TS_EVENT_ACTIVE => 9,
+ TS_EVENT_REG_CALLBACK => 10,
+ TS_EVENT_UNREG_CALLBACK => 11,
+ TS_EVENT_NOTIFY => 12,
+ TS_STATS_RESET_NODE => 13,
+ TS_STORAGE_DEVICE_CMD_OFFLINE => 14,
+ TS_RECORD_MATCH_GET => 15,
+ TS_API_PING => 16,
+ TS_SERVER_BACKTRACE => 17,
+ TS_RECORD_DESCRIBE_CONFIG => 18,
+ TS_LIFECYCLE_MESSAGE => 19,
+ TS_UNDEFINED_OP => 20
};
use constant {
diff --git a/mgmt/api/APITestCliRemote.cc b/mgmt/api/APITestCliRemote.cc
index 73a25dd..ba7bf37 100644
--- a/mgmt/api/APITestCliRemote.cc
+++ b/mgmt/api/APITestCliRemote.cc
@@ -54,14 +54,6 @@
* read_url: tests TSReadFromUrl works by retrieving two valid urls
* test_url: tests robustness of TSReadFromUrl using invalid urls
*
- * CfgContext operations:
- * ---------------------
- * cfg_get:<config-filename>: prints out the rules in confg-filename
- * cfg:<config-filename>: switches the position of first and last rule of
- * <config-filename>
- * cfg_socks: does some basic testing of socks.config (reads in file,
- * modifies it, eg. add new rules, then commits changes)
- *
* Event Operations:
* ----------------
* active_events: lists the names of all currently active events
@@ -85,6 +77,7 @@
#include "ts/ink_config.h"
#include "ts/ink_defs.h"
+#include "ts/ink_memory.h"
#include <cstdlib>
#include <cstring>
#include <cstdio>
@@ -92,7 +85,6 @@
#include "ts/ink_string.h"
#include "mgmtapi.h"
-#include "CfgContextUtils.h"
// refer to test_records() function
#define TEST_STRING 1
@@ -365,367 +357,6 @@ print_pd_sspec(TSPdSsFormat info)
return;
}
-void
-print_cache_ele(TSCacheEle *ele)
-{
- if (!ele) {
- printf("can't print ele\n");
- return;
- }
-
- char *pd_str, *time_str;
-
- char buf[MAX_BUF_SIZE];
- int buf_pos = 0;
-
- bzero(buf, MAX_BUF_SIZE);
-
- pd_str = pdest_sspec_to_string(ele->cache_info.pd_type, ele->cache_info.pd_val, &(ele->cache_info.sec_spec));
- if (!pd_str) {
- printf("pd_str is null.\n");
- return;
- }
-
- snprintf(buf, sizeof(buf), "%s ", pd_str);
- buf_pos = strlen(buf);
- ats_free(pd_str);
-
- // now format the message
- switch (ele->cfg_ele.type) {
- case TS_CACHE_NEVER:
- snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "action=never-cache");
- break;
- case TS_CACHE_IGNORE_NO_CACHE:
- snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "action=ignore-no-cache");
- break;
- case TS_CACHE_IGNORE_CLIENT_NO_CACHE:
- snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "action=ignore-server-no-cache");
- break;
- case TS_CACHE_IGNORE_SERVER_NO_CACHE:
- snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "action=ignore-client-no-cache");
- break;
- case TS_CACHE_PIN_IN_CACHE:
- time_str = hms_time_to_string(ele->time_period);
- if (!time_str) {
- return;
- }
- snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "pin-in-cache=%s", time_str);
- ats_free(time_str);
- break;
- case TS_CACHE_REVALIDATE:
- time_str = hms_time_to_string(ele->time_period);
- if (!time_str) {
- return;
- }
- snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "revalidate=%s", time_str);
- ats_free(time_str);
- break;
- default: /* invalid action directive */
- printf("hello..\n");
- return;
- }
- printf("%s\n", buf);
-
- /*
- print_pd_sspec(ele->cache_info);
- printf("Time: %d day, %d hr, %d min, %d sec\n", ele->time_period.d, ele->time_period.h,
- ele->time_period.m, ele->time_period.s);
- */
- return;
-}
-
-void
-print_hosting_ele(TSHostingEle *ele)
-{
- if (!ele) {
- printf("can't print ele\n");
- return;
- }
-
- switch (ele->pd_type) {
- case TS_PD_DOMAIN:
- printf("dest_domain=%s\n", ele->pd_val);
- break;
- case TS_PD_HOST:
- printf("dest_host=%s\n", ele->pd_val);
- break;
- case TS_PD_IP:
- printf("ip=%s\n", ele->pd_val);
- break;
- case TS_PD_URL_REGEX:
- printf("url_regex=%s\n", ele->pd_val);
- break;
- case TS_PD_URL:
- printf("url=%s\n", ele->pd_val);
- break;
- default:
- printf("INVALID Prime Dest specifier\n");
- break;
- }
-
- print_int_list(ele->volumes);
-}
-
-void
-print_ip_allow_ele(TSIpAllowEle *ele)
-{
- if (!ele) {
- printf("can't print ele\n");
- return;
- }
-
- print_ip_addr_ele(ele->src_ip_addr);
-}
-
-void
-print_parent_ele(TSParentProxyEle *ele)
-{
- if (!ele) {
- printf("can't print ele\n");
- return;
- }
-
- printf("parent rule type: %d\n", ele->cfg_ele.type);
- print_pd_sspec(ele->parent_info);
- printf("round robin? %d\n", ele->rr);
- print_domain_list(ele->proxy_list);
- printf("direct? %d\n", ele->direct);
-}
-
-void
-print_volume_ele(TSVolumeEle *ele)
-{
- if (!ele) {
- printf("can't print ele\n");
- return;
- }
-
- printf("volume #: %d\n", ele->volume_num);
- printf("scheme: %d\n", ele->scheme);
- switch (ele->size_format) {
- case TS_SIZE_FMT_ABSOLUTE:
- printf("volume_size=%d\n", ele->volume_size);
- break;
- case TS_SIZE_FMT_PERCENT:
- printf("volume_size=%% %d\n", ele->volume_size);
- break;
- default:
- // Handled here:
- // TS_SIZE_FMT_UNDEFINED
- break;
- }
-}
-
-void
-print_plugin_ele(TSPluginEle *ele)
-{
- if (!ele) {
- printf("can't print plugin ele\n");
- return;
- }
-
- printf("name: %s\t\t", ele->name);
- if (ele->args) {
- printf("args: ");
- print_string_list(ele->args);
- } else {
- printf("NO ARGS\n");
- }
-}
-
-void
-print_remap_ele(TSRemapEle *ele)
-{
- if (!ele) {
- printf("can't print ele\n");
- return;
- }
-
- char buf[MAX_BUF_SIZE];
- bzero(buf, MAX_BUF_SIZE);
-
- switch (ele->cfg_ele.type) {
- case TS_REMAP_MAP:
- ink_strlcat(buf, "map", sizeof(buf));
- break;
- case TS_REMAP_REVERSE_MAP:
- ink_strlcat(buf, "reverse_map", sizeof(buf));
- break;
- case TS_REMAP_REDIRECT:
- ink_strlcat(buf, "redirect", sizeof(buf));
- break;
- case TS_REMAP_REDIRECT_TEMP:
- ink_strlcat(buf, "redirect_temporary", sizeof(buf));
- break;
- default:
- // Handled here:
- // Lots of cases...
- break;
- }
- // space delimitor
- ink_strlcat(buf, " ", sizeof(buf));
-
- // from scheme
- switch (ele->from_scheme) {
- case TS_SCHEME_HTTP:
- ink_strlcat(buf, "http", sizeof(buf));
- break;
- case TS_SCHEME_HTTPS:
- ink_strlcat(buf, "https", sizeof(buf));
- break;
- default:
- // Handled here:
- // TS_SCHEME_NONE, TS_SCHEME_UNDEFINED, TS_SCHEME_NONE,
- // TS_SCHEME_UNDEFINED
- break;
- }
- ink_strlcat(buf, "://", sizeof(buf));
-
- // from host
- if (ele->from_host) {
- ink_strlcat(buf, ele->from_host, sizeof(buf));
- }
- // from port
- if (ele->from_port != TS_INVALID_PORT) {
- snprintf(buf, sizeof(buf), "%s:%d", buf, ele->from_port);
- }
- // from host path
- if (ele->from_path_prefix) {
- ink_strlcat(buf, "/", sizeof(buf));
- ink_strlcat(buf, ele->from_path_prefix, sizeof(buf));
- }
- // space delimitor
- ink_strlcat(buf, " ", sizeof(buf));
-
- // to scheme
- switch (ele->to_scheme) {
- case TS_SCHEME_HTTP:
- ink_strlcat(buf, "http", sizeof(buf));
- break;
- case TS_SCHEME_HTTPS:
- ink_strlcat(buf, "https", sizeof(buf));
- break;
- default:
- // Handled here:
- // TS_SCHEME_NONE, TS_SCHEME_UNDEFINED
- break;
- }
- ink_strlcat(buf, "://", sizeof(buf));
-
- // to host
- if (ele->to_host) {
- ink_strlcat(buf, ele->to_host, sizeof(buf));
- }
- // to port
- if (ele->to_port != TS_INVALID_PORT) {
- snprintf(buf, sizeof(buf), "%s:%d", buf, ele->to_port);
- }
- // to host path
- if (ele->to_path_prefix) {
- ink_strlcat(buf, "/", sizeof(buf));
- ink_strlcat(buf, ele->to_path_prefix, sizeof(buf));
- }
-
- printf("%s\n", buf);
- return;
-}
-
-void
-print_socks_ele(TSSocksEle *ele)
-{
- printf("\n");
- if (!ele) {
- printf("can't print ele\n");
- } else if (ele->ip_addrs) {
- print_ip_list(ele->ip_addrs);
- printf("\n");
- } else {
- print_ip_addr_ele(ele->dest_ip_addr);
- print_domain_list(ele->socks_servers);
- printf("round_robin=%d\n", ele->rr);
- }
-}
-
-void
-print_split_dns_ele(TSSplitDnsEle *ele)
-{
- if (!ele) {
- printf("can't print ele\n");
- return;
- }
-
- char *str;
- char buf[MAX_BUF_SIZE];
- bzero(buf, MAX_BUF_SIZE);
-
- char *pd_name = nullptr;
- switch (ele->pd_type) {
- case TS_PD_DOMAIN:
- pd_name = ats_strdup("dest_domain");
- break;
- case TS_PD_HOST:
- pd_name = ats_strdup("dest_host");
- break;
- case TS_PD_URL_REGEX:
- pd_name = ats_strdup("url_regex");
- break;
- case TS_PD_URL:
- pd_name = ats_strdup("url");
- break;
- default:
- pd_name = ats_strdup("?????");
- // Handled here:
- // TS_PD_IP, TS_PD_UNDEFINED
- break;
- }
-
- if (ele->pd_val) {
- ink_strlcat(buf, pd_name, sizeof(buf));
- ink_strlcat(buf, "=", sizeof(buf));
- ink_strlcat(buf, ele->pd_val, sizeof(buf));
- ink_strlcat(buf, " ", sizeof(buf));
- }
-
- if (ele->dns_servers_addrs) {
- ink_strlcat(buf, "named=", sizeof(buf));
- str = ip_addr_list_to_string((LLQ *)ele->dns_servers_addrs, " ");
- ink_strlcat(buf, str, sizeof(buf));
- ats_free(str);
- ink_strlcat(buf, " ", sizeof(buf));
- }
-
- if (ele->def_domain) {
- ink_strlcat(buf, "dns_server=", sizeof(buf));
- ink_strlcat(buf, ele->def_domain, sizeof(buf));
- ink_strlcat(buf, " ", sizeof(buf));
- }
-
- if (ele->search_list) {
- ink_strlcat(buf, "search_list=", sizeof(buf));
- str = domain_list_to_string(ele->search_list, " ");
- ink_strlcat(buf, str, sizeof(buf));
- ats_free(str);
- ink_strlcat(buf, " ", sizeof(buf));
- }
- printf("%s\n", buf);
- ats_free(pd_name);
-
- return;
-}
-
-void
-print_storage_ele(TSStorageEle *ele)
-{
- if (!ele) {
- printf("can't print ele\n");
- return;
- }
-
- if (ele->pathname) {
- printf("pathname=%s, size=%d\n", ele->pathname, ele->size);
- }
-}
-
/***************************************************************************
* Control Testing
***************************************************************************/
@@ -1271,27 +902,6 @@ test_read_url(bool valid)
}
}
-/* ------------------------------------------------------------------------
- * test_read_file
- * ------------------------------------------------------------------------
- * reads hosting.config file and prints it out
- */
-void
-test_read_file()
-{
- char *f_text = nullptr;
- int f_size = -1;
- int f_ver = -1;
-
- printf("\n");
- if (TSConfigFileRead(TS_FNAME_HOSTING, &f_text, &f_size, &f_ver) != TS_ERR_OKAY) {
- printf("[TSConfigFileRead] FAILED!\n");
- } else {
- printf("[TSConfigFileRead]\n\tFile Size=%d, Version=%d\n%s\n", f_size, f_ver, f_text);
- TSfree(f_text);
- }
-}
-
/***************************************************************************
* Events Testing
***************************************************************************/
@@ -1596,8 +1206,6 @@ runInteractive()
test_record_get_mlt();
} else if (strstr(buf, "set_mlt")) {
test_record_set_mlt();
- } else if (strstr(buf, "read_file")) {
- test_read_file();
} else if (strstr(buf, "proxy.")) {
test_rec_get(buf);
} else if (strstr(buf, "active_events")) {
diff --git a/mgmt/api/CfgContextImpl.cc b/mgmt/api/CfgContextImpl.cc
deleted file mode 100644
index bf88dad..0000000
--- a/mgmt/api/CfgContextImpl.cc
+++ /dev/null
@@ -1,2135 +0,0 @@
-/** @file
-
- Implementation of CfgContext class and all the CfgEleObj subclasses
-
- @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 "ts/ink_platform.h"
-#include "ts/ink_string.h"
-
-#include "CfgContextImpl.h"
-#include "CfgContextUtils.h"
-#include "mgmtapi.h"
-
-//--------------------------------------------------------------------------
-// Defines
-//--------------------------------------------------------------------------
-
-#define TIGHT_RULE_CHECK true
-
-//--------------------------------------------------------------------------
-// CommentObj
-//--------------------------------------------------------------------------
-CommentObj::CommentObj(char *comment)
-{
- m_ele = comment_ele_create(comment);
- m_valid = (comment ? true : false);
-}
-
-CommentObj::~CommentObj()
-{
- comment_ele_destroy(m_ele);
-}
-
-char *
-CommentObj::formatEleToRule()
-{
- return ats_strdup(m_ele->comment);
-}
-
-bool
-CommentObj::isValid()
-{
- return m_valid;
-}
-
-TSCfgEle *
-CommentObj::getCfgEleCopy()
-{
- return (TSCfgEle *)copy_comment_ele(m_ele);
-}
-
-//--------------------------------------------------------------------------
-// CacheObj
-//--------------------------------------------------------------------------
-CacheObj::CacheObj(TSCacheEle *ele)
-{
- m_ele = ele;
- m_valid = true;
- m_valid = isValid();
-}
-
-// assumes the specifiers are specified in specific order!!
-CacheObj::CacheObj(TokenList *tokens)
-{
- Token *tok;
- m_ele = TSCacheEleCreate(TS_TYPE_UNDEFINED);
- m_ele->cfg_ele.error = TS_ERR_OKAY;
- m_valid = true;
-
- if (!tokens) {
- goto FORMAT_ERR;
- }
-
- m_ele->cfg_ele.type = get_rule_type(tokens, TS_FNAME_CACHE_OBJ);
-
- // if any invalid values, set m_valid=false
- // convert token name and value into ele field
- tok = tokens->first();
- tok = tokens_to_pdss_format(tokens, tok, &(m_ele->cache_info));
-
- if (!tok) { // INVALID FORMAT
- goto FORMAT_ERR;
- }
-
- tok = tokens->next(tok);
- if (m_ele->cfg_ele.type == TS_CACHE_REVALIDATE || m_ele->cfg_ele.type == TS_CACHE_PIN_IN_CACHE ||
- m_ele->cfg_ele.type == TS_CACHE_TTL_IN_CACHE) {
- // must have a time specified
- if (strcmp(tok->name, "pin-in-cache") != 0 && strcmp(tok->name, "revalidate") != 0 && strcmp(tok->name, "ttl-in-cache") != 0) {
- goto FORMAT_ERR; // wrong token!!
- }
- if (string_to_hms_time(tok->value, &(m_ele->time_period)) != TS_ERR_OKAY) {
- goto FORMAT_ERR;
- }
- }
-
- return;
-
-FORMAT_ERR:
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- m_valid = false;
-}
-
-CacheObj::~CacheObj()
-{
- TSCacheEleDestroy(m_ele);
-}
-
-char *
-CacheObj::formatEleToRule()
-{
- if (!isValid()) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- return nullptr;
- }
-
- char *pd_str, *time_str;
- char buf[MAX_RULE_SIZE];
- memset(buf, 0, MAX_RULE_SIZE);
-
- pd_str = pdest_sspec_to_string(m_ele->cache_info.pd_type, m_ele->cache_info.pd_val, &(m_ele->cache_info.sec_spec));
- if (!pd_str) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- return nullptr;
- }
- ink_strlcat(buf, pd_str, sizeof(buf));
- ats_free(pd_str);
-
- switch (m_ele->cfg_ele.type) {
- case TS_CACHE_NEVER:
- ink_strlcat(buf, "action=never-cache ", sizeof(buf));
- break;
- case TS_CACHE_IGNORE_NO_CACHE:
- ink_strlcat(buf, "action=ignore-no-cache ", sizeof(buf));
- break;
- case TS_CACHE_IGNORE_CLIENT_NO_CACHE:
- ink_strlcat(buf, "action=ignore-client-no-cache ", sizeof(buf));
- break;
- case TS_CACHE_IGNORE_SERVER_NO_CACHE:
- ink_strlcat(buf, "action=ignore-server-no-cache ", sizeof(buf));
- break;
- case TS_CACHE_AUTH_CONTENT:
- ink_strlcat(buf, "action=cache-auth-content ", sizeof(buf));
- break;
- case TS_CACHE_PIN_IN_CACHE:
- ink_strlcat(buf, "pin-in-cache=", sizeof(buf));
- time_str = hms_time_to_string(m_ele->time_period);
- if (time_str) {
- ink_strlcat(buf, time_str, sizeof(buf));
- ats_free(time_str);
- }
- ink_strlcat(buf, " ", sizeof(buf));
- break;
- case TS_CACHE_REVALIDATE:
- ink_strlcat(buf, "revalidate=", sizeof(buf));
- time_str = hms_time_to_string(m_ele->time_period);
- if (time_str) {
- ink_strlcat(buf, time_str, sizeof(buf));
- ats_free(time_str);
- }
- ink_strlcat(buf, " ", sizeof(buf));
- break;
- case TS_CACHE_TTL_IN_CACHE:
- ink_strlcat(buf, "ttl-in-cache=", sizeof(buf));
- time_str = hms_time_to_string(m_ele->time_period);
- if (time_str) {
- ink_strlcat(buf, time_str, sizeof(buf));
- ats_free(time_str);
- }
- ink_strlcat(buf, " ", sizeof(buf));
- break;
- default:
- // Handled here:
- // Lots of cases...
- break;
- }
-
- return ats_strdup(buf);
-}
-
-bool
-CacheObj::isValid()
-{
- char *timeStr;
-
- if (m_ele->cfg_ele.error != TS_ERR_OKAY) {
- m_valid = false;
- }
- // all Cache Ele's should have a prim dest, sec specs are optional
- if (!ccu_checkPdSspec(m_ele->cache_info)) {
- m_valid = false;
- }
- // only pin-in-cache, ttl, and revalidate rules have time period
- switch (m_ele->cfg_ele.type) {
- case TS_CACHE_NEVER:
- case TS_CACHE_IGNORE_NO_CACHE:
- case TS_CACHE_IGNORE_CLIENT_NO_CACHE:
- case TS_CACHE_IGNORE_SERVER_NO_CACHE:
- case TS_CACHE_AUTH_CONTENT:
- break;
- case TS_CACHE_PIN_IN_CACHE:
- case TS_CACHE_REVALIDATE:
- case TS_CACHE_TTL_IN_CACHE:
- timeStr = hms_time_to_string(m_ele->time_period);
- if (!timeStr) {
- m_valid = false;
- }
- ats_free(timeStr);
- default:
- // Handled here:
- // Lots of cases ...
- break;
- }
-
- if (!m_valid) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- }
-
- return m_valid;
-}
-
-TSCfgEle *
-CacheObj::getCfgEleCopy()
-{
- return (TSCfgEle *)copy_cache_ele(m_ele);
-}
-
-//--------------------------------------------------------------------------
-// CongestionObj
-//--------------------------------------------------------------------------
-CongestionObj::CongestionObj(TSCongestionEle *ele)
-{
- m_ele = ele;
- m_valid = true;
- m_valid = isValid();
-}
-
-CongestionObj::CongestionObj(TokenList *tokens)
-{
- Token *tok;
- m_ele = TSCongestionEleCreate();
- m_ele->cfg_ele.error = TS_ERR_OKAY;
- m_valid = true;
-
- if (!tokens) {
- goto FORMAT_ERR;
- }
-
- m_ele->cfg_ele.type = get_rule_type(tokens, TS_FNAME_CONGESTION);
-
- // if any invalid values, set m_valid=false
- // convert token name and value into ele field
- tok = tokens->first();
- // tok = tokens_to_pdss_format(tokens, tok, &(m_ele->congestion_info));
-
- if (!tok) { // INVALID FORMAT
- goto FORMAT_ERR;
- }
-
- if (strcmp(tok->name, "dest_domain") == 0) {
- m_ele->pd_type = TS_PD_DOMAIN;
- } else if (strcmp(tok->name, "dest_host") == 0) {
- m_ele->pd_type = TS_PD_HOST;
- } else if (strcmp(tok->name, "dest_ip") == 0) {
- m_ele->pd_type = TS_PD_IP;
- } else if (strcmp(tok->name, "host_regex") == 0) {
- m_ele->pd_type = TS_PD_URL_REGEX;
- }
- m_ele->pd_val = ats_strdup(tok->value);
-
- // check for remaining tags
- tok = tokens->next(tok);
- while (tok) {
- if (!tok->name || !tok->value) {
- goto FORMAT_ERR;
- }
- if (strcmp(tok->name, "prefix") == 0) {
- m_ele->prefix = ats_strdup(tok->value);
- } else if (strcmp(tok->name, "port") == 0) {
- m_ele->port = ink_atoi(tok->value);
- } else if (strcmp(tok->name, "congestion_scheme") == 0) {
- if (strcmp(tok->value, "per_ip") == 0) {
- m_ele->scheme = TS_HTTP_CONGEST_PER_IP;
- } else if (strcmp(tok->value, "per_host") == 0) {
- m_ele->scheme = TS_HTTP_CONGEST_PER_HOST;
- } else {
- goto FORMAT_ERR;
- }
- } else if (strcmp(tok->name, "max_connection_failures") == 0) {
- m_ele->max_connection_failures = ink_atoi(tok->value);
- } else if (strcmp(tok->name, "fail_window") == 0) {
- m_ele->fail_window = ink_atoi(tok->value);
- } else if (strcmp(tok->name, "proxy_retry_interval") == 0) {
- m_ele->proxy_retry_interval = ink_atoi(tok->value);
- } else if (strcmp(tok->name, "client_wait_interval") == 0) {
- m_ele->client_wait_interval = ink_atoi(tok->value);
- } else if (strcmp(tok->name, "wait_interval_alpha") == 0) {
- m_ele->wait_interval_alpha = ink_atoi(tok->value);
- } else if (strcmp(tok->name, "live_os_conn_timeout") == 0) {
- m_ele->live_os_conn_timeout = ink_atoi(tok->value);
- } else if (strcmp(tok->name, "live_os_conn_retries") == 0) {
- m_ele->live_os_conn_retries = ink_atoi(tok->value);
- } else if (strcmp(tok->name, "dead_os_conn_timeout") == 0) {
- m_ele->dead_os_conn_timeout = ink_atoi(tok->value);
- } else if (strcmp(tok->name, "dead_os_conn_retries") == 0) {
- m_ele->dead_os_conn_retries = ink_atoi(tok->value);
- } else if (strcmp(tok->name, "max_connection") == 0) {
- m_ele->max_connection = ink_atoi(tok->value);
- } else if (strcmp(tok->name, "error_page_uri") == 0) {
- m_ele->error_page_uri = ats_strdup(tok->value);
- } else {
- goto FORMAT_ERR;
- }
- tok = tokens->next(tok);
- }
- return;
-
-FORMAT_ERR:
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- m_valid = false;
-}
-
-CongestionObj::~CongestionObj()
-{
- TSCongestionEleDestroy(m_ele);
-}
-
-//
-// will always print defaults in the rule
-//
-char *
-CongestionObj::formatEleToRule()
-{
- if (!isValid()) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- return nullptr;
- }
-
- char buf[MAX_BUF_SIZE];
- size_t pos = 0;
- int psize;
- memset(buf, 0, MAX_BUF_SIZE);
-
- // push in primary destination
- if (pos < sizeof(buf)) {
- switch (m_ele->pd_type) {
- case TS_PD_DOMAIN:
- psize = snprintf(buf + pos, sizeof(buf) - pos, "dest_domain=%s ", m_ele->pd_val);
- break;
- case TS_PD_HOST:
- psize = snprintf(buf + pos, sizeof(buf) - pos, "dest_host=%s ", m_ele->pd_val);
- break;
- case TS_PD_IP:
- psize = snprintf(buf + pos, sizeof(buf) - pos, "dest_ip=%s ", m_ele->pd_val);
- break;
- case TS_PD_URL_REGEX:
- psize = snprintf(buf + pos, sizeof(buf) - pos, "host_regex=%s ", m_ele->pd_val);
- break;
- default:
- psize = 0;
- // Handled here:
- // TS_PD_UNDEFINED
- break;
- }
- if (psize > 0) {
- pos += psize;
- }
- }
- // secondary specifiers
- if (m_ele->prefix) {
- if (pos < sizeof(buf) && (psize = snprintf(buf + pos, sizeof(buf) - pos, "prefix=%s ", m_ele->prefix)) > 0) {
- pos += psize;
- }
- }
- if (m_ele->port > 0) {
- if (pos < sizeof(buf) && (psize = snprintf(buf + pos, sizeof(buf) - pos, "port=%d ", m_ele->port)) > 0) {
- pos += psize;
- }
- }
-
- if (pos < sizeof(buf) &&
- (psize = snprintf(buf + pos, sizeof(buf) - pos, "max_connection_failures=%d ", m_ele->max_connection_failures)) > 0) {
- pos += psize;
- }
- if (pos < sizeof(buf) && (psize = snprintf(buf + pos, sizeof(buf) - pos, "fail_window=%d ", m_ele->fail_window)) > 0) {
- pos += psize;
- }
- if (pos < sizeof(buf) &&
- (psize = snprintf(buf + pos, sizeof(buf) - pos, "proxy_retry_interval=%d ", m_ele->proxy_retry_interval)) > 0) {
- pos += psize;
- }
- if (pos < sizeof(buf) &&
- (psize = snprintf(buf + pos, sizeof(buf) - pos, "client_wait_interval=%d ", m_ele->client_wait_interval)) > 0) {
- pos += psize;
- }
- if (pos < sizeof(buf) &&
- (psize = snprintf(buf + pos, sizeof(buf) - pos, "wait_interval_alpha=%d ", m_ele->wait_interval_alpha)) > 0) {
- pos += psize;
- }
- if (pos < sizeof(buf) &&
- (psize = snprintf(buf + pos, sizeof(buf) - pos, "live_os_conn_timeout=%d ", m_ele->live_os_conn_timeout)) > 0) {
- pos += psize;
- }
- if (pos < sizeof(buf) &&
- (psize = snprintf(buf + pos, sizeof(buf) - pos, "live_os_conn_retries=%d ", m_ele->live_os_conn_retries)) > 0) {
- pos += psize;
- }
- if (pos < sizeof(buf) &&
- (psize = snprintf(buf + pos, sizeof(buf) - pos, "dead_os_conn_timeout=%d ", m_ele->dead_os_conn_timeout)) > 0) {
- pos += psize;
- }
- if (pos < sizeof(buf) &&
- (psize = snprintf(buf + pos, sizeof(buf) - pos, "dead_os_conn_retries=%d ", m_ele->dead_os_conn_retries)) > 0) {
- pos += psize;
- }
- if (pos < sizeof(buf) && (psize = snprintf(buf + pos, sizeof(buf) - pos, "max_connection=%d ", m_ele->max_connection)) > 0) {
- pos += psize;
- }
- if (m_ele->error_page_uri) {
- if (pos < sizeof(buf) && (psize = snprintf(buf + pos, sizeof(buf) - pos, "error_page=%s ", m_ele->error_page_uri)) > 0) {
- pos += psize;
- }
- }
- switch (m_ele->scheme) {
- case TS_HTTP_CONGEST_PER_IP:
- snprintf(buf + pos, sizeof(buf) - pos, "congestion_scheme=per_ip ");
- break;
- case TS_HTTP_CONGEST_PER_HOST:
- snprintf(buf + pos, sizeof(buf) - pos, "congestion_scheme=per_host ");
- break;
- default:
- break;
- }
-
- return ats_strdup(buf);
-}
-
-bool
-CongestionObj::isValid()
-{
- if (m_ele->cfg_ele.error != TS_ERR_OKAY) {
- m_valid = false;
- }
- // all Congestion Ele's should have a prim dest, sec specs are optional
- if (!m_ele->pd_val) {
- m_valid = false;
- }
-
- if (!m_valid) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- }
- return m_valid;
-}
-
-TSCfgEle *
-CongestionObj::getCfgEleCopy()
-{
- return (TSCfgEle *)copy_congestion_ele(m_ele);
-}
-
-//--------------------------------------------------------------------------
-// HostingObj
-//--------------------------------------------------------------------------
-HostingObj::HostingObj(TSHostingEle *ele)
-{
- m_ele = ele;
- m_valid = true;
- m_valid = isValid();
-}
-
-HostingObj::HostingObj(TokenList *tokens)
-{
- Token *token;
-
- m_ele = TSHostingEleCreate();
- m_ele->cfg_ele.error = TS_ERR_OKAY;
- m_valid = true;
-
- if (!tokens || tokens->length != 2) {
- goto FORMAT_ERR;
- }
-
- m_ele->cfg_ele.type = get_rule_type(tokens, TS_FNAME_HOSTING);
- if (m_ele->cfg_ele.type == TS_TYPE_UNDEFINED) {
- goto FORMAT_ERR;
- }
- // First Token
- token = tokens->first();
- if (!token->value) {
- goto FORMAT_ERR;
- }
- if (strcmp(token->name, "hostname") == 0) {
- m_ele->pd_type = TS_PD_HOST;
- } else if (strcmp(token->name, "domain") == 0) {
- m_ele->pd_type = TS_PD_DOMAIN;
- } else {
- goto FORMAT_ERR;
- }
- m_ele->pd_val = ats_strdup(token->value);
-
- // Second Token
- token = tokens->next(token);
- if (!token->value) {
- goto FORMAT_ERR;
- }
- if (strcmp(token->name, "volume") != 0) {
- goto FORMAT_ERR;
- }
- m_ele->volumes = string_to_int_list(token->value, LIST_DELIMITER);
- return;
-
-FORMAT_ERR:
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- m_valid = false;
-}
-
-HostingObj::~HostingObj()
-{
- TSHostingEleDestroy(m_ele);
-}
-
-char *
-HostingObj::formatEleToRule()
-{
- if (!isValid()) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- return nullptr;
- }
-
- char *list_str;
- char buf[MAX_RULE_SIZE];
- memset(buf, 0, MAX_RULE_SIZE);
-
- switch (m_ele->pd_type) {
- case TS_PD_HOST:
- ink_strlcat(buf, "hostname=", sizeof(buf));
- break;
- case TS_PD_DOMAIN:
- ink_strlcat(buf, "domain=", sizeof(buf));
- break;
- default:
- // Handled here:
- // Lots of cases...
- break;
- }
-
- list_str = int_list_to_string(m_ele->volumes, ",");
- ink_strlcat(buf, m_ele->pd_val, sizeof(buf));
- ink_strlcat(buf, " volume=", sizeof(buf));
- ink_strlcat(buf, list_str, sizeof(buf));
- ats_free(list_str);
-
- return ats_strdup(buf);
-}
-
-bool
-HostingObj::isValid()
-{
- int *part;
- int len, i;
-
- if (m_ele->pd_type == TS_PD_UNDEFINED) {
- m_valid = false;
- goto Lend;
- }
-
- if (!m_ele->pd_val) {
- m_valid = false;
- goto Lend;
- }
-
- if (!m_ele->volumes || !TSIntListIsValid(m_ele->volumes, 0, 50000)) {
- m_valid = false;
- goto Lend;
- }
- // check that each volume is between 1-255
- len = TSIntListLen(m_ele->volumes);
- for (i = 0; i < len; i++) {
- part = TSIntListDequeue(m_ele->volumes);
- if (*part < 1 || *part > 255) {
- TSIntListEnqueue(m_ele->volumes, part);
- m_valid = false;
- goto Lend;
- }
- TSIntListEnqueue(m_ele->volumes, part);
- }
-
-Lend:
- if (!m_valid) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- }
- return m_valid;
-}
-
-TSCfgEle *
-HostingObj::getCfgEleCopy()
-{
- return (TSCfgEle *)copy_hosting_ele(m_ele);
-}
-
-//--------------------------------------------------------------------------
-// IpAllowObj
-//--------------------------------------------------------------------------
-IpAllowObj::IpAllowObj(TSIpAllowEle *ele)
-{
- m_ele = ele;
- m_valid = true;
- m_valid = isValid();
-}
-
-IpAllowObj::IpAllowObj(TokenList *tokens)
-{
- Token *token;
-
- m_ele = TSIpAllowEleCreate();
- m_ele->cfg_ele.error = TS_ERR_OKAY;
- m_valid = true;
-
- if (!tokens || (tokens->length != 2)) {
- goto FORMAT_ERR;
- }
-
- m_ele->cfg_ele.type = get_rule_type(tokens, TS_FNAME_IP_ALLOW);
- if (m_ele->cfg_ele.type == TS_TYPE_UNDEFINED) {
- goto FORMAT_ERR;
- }
-
- token = tokens->first();
- if (!token->name || strcmp(token->name, "src_ip")) {
- goto FORMAT_ERR;
- }
- if (!token->value) {
- goto FORMAT_ERR;
- } else {
- m_ele->src_ip_addr = string_to_ip_addr_ele(token->value);
- }
-
- token = tokens->next(token);
- if (!token->name || strcmp(token->name, "action")) {
- goto FORMAT_ERR;
- }
- if (!token->value) {
- goto FORMAT_ERR;
- } else {
- if (!strcmp(token->value, "ip_allow")) {
- m_ele->action = TS_IP_ALLOW_ALLOW;
- } else if (strcmp(token->value, "ip_deny") == 0) {
- m_ele->action = TS_IP_ALLOW_DENY;
- } else {
- m_ele->action = TS_IP_ALLOW_UNDEFINED;
- }
- }
- return;
-
-FORMAT_ERR:
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- m_valid = false;
-}
-
-IpAllowObj::~IpAllowObj()
-{
- TSIpAllowEleDestroy(m_ele);
-}
-
-char *
-IpAllowObj::formatEleToRule()
-{
- if (!isValid()) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- return nullptr;
- ;
- }
-
- char *rule;
- char buf[MAX_RULE_SIZE];
- memset(buf, 0, MAX_RULE_SIZE);
-
- ink_strlcpy(buf, "src_ip=", sizeof(buf));
- if (m_ele->src_ip_addr) {
- char *ip_str = ip_addr_ele_to_string(m_ele->src_ip_addr);
- if (ip_str) {
- ink_strlcat(buf, ip_str, sizeof(buf));
- ats_free(ip_str);
- }
- }
-
- ink_strlcat(buf, " action=", sizeof(buf));
- switch (m_ele->action) {
- case TS_IP_ALLOW_ALLOW:
- ink_strlcat(buf, "ip_allow", sizeof(buf));
- break;
- case TS_IP_ALLOW_DENY:
- ink_strlcat(buf, "ip_deny", sizeof(buf));
- break;
- default:
- // Handled here:
- // TS_IP_ALLOW_UNDEFINED
- break;
- }
-
- rule = ats_strdup(buf);
- return rule;
-}
-
-bool
-IpAllowObj::isValid()
-{
- if (m_ele->cfg_ele.error != TS_ERR_OKAY) {
- m_valid = false;
- }
-
- if (!m_ele->src_ip_addr) {
- m_valid = false;
- }
-
- switch (m_ele->action) {
- case TS_IP_ALLOW_ALLOW:
- case TS_IP_ALLOW_DENY:
- break;
- default:
- m_valid = false;
- }
-
- if (!m_valid) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- }
- return m_valid;
-}
-
-TSCfgEle *
-IpAllowObj::getCfgEleCopy()
-{
- return (TSCfgEle *)copy_ip_allow_ele(m_ele);
-}
-
-//--------------------------------------------------------------------------
-// ParentProxyObj
-//--------------------------------------------------------------------------
-ParentProxyObj::ParentProxyObj(TSParentProxyEle *ele)
-{
- m_ele = ele;
- m_valid = true;
- m_valid = isValid();
-}
-
-ParentProxyObj::ParentProxyObj(TokenList *tokens)
-{
- Token *tok;
- m_ele = TSParentProxyEleCreate(TS_TYPE_UNDEFINED);
- m_ele->cfg_ele.error = TS_ERR_OKAY;
- m_valid = true;
-
- if (!tokens || tokens->length < 1) {
- goto FORMAT_ERR;
- }
-
- m_ele->cfg_ele.type = get_rule_type(tokens, TS_FNAME_PARENT_PROXY);
- if (m_ele->cfg_ele.type == TS_TYPE_UNDEFINED) {
- goto FORMAT_ERR;
- }
-
- tok = tokens->first();
- tok = tokens_to_pdss_format(tokens, tok, &(m_ele->parent_info));
- if (tok == nullptr) {
- goto FORMAT_ERR;
- }
- // search parent and round_robin action tags
- for (tok = tokens->next(tok); tok; tok = tokens->next(tok)) {
- if (strcmp(tok->name, "round_robin") == 0) {
- // sanity check
- if (!tok->value) {
- goto FORMAT_ERR;
- }
- if (strcmp(tok->value, "true") == 0) {
- m_ele->rr = TS_RR_TRUE;
- } else if (strcmp(tok->value, "strict") == 0) {
- m_ele->rr = TS_RR_STRICT;
- } else if (strcmp(tok->value, "false") == 0) {
- m_ele->rr = TS_RR_FALSE;
- } else {
- m_ele->rr = TS_RR_NONE;
- goto FORMAT_ERR;
- }
-
- } else if (strcmp(tok->name, "parent") == 0) {
- // sanity check
- if (!tok->value) {
- goto FORMAT_ERR;
- }
- m_ele->proxy_list = string_to_domain_list(tok->value, ";");
-
- } else if (strcmp(tok->name, "go_direct") == 0) {
- // sanity check
- if (!tok->value) {
- goto FORMAT_ERR;
- }
- if (!strcmp(tok->value, "true")) {
- m_ele->direct = true;
- } else if (!strcmp(tok->value, "false")) {
- m_ele->direct = false;
- } else {
- goto FORMAT_ERR;
- }
- } else {
- goto FORMAT_ERR;
- }
- }
-
- // the rule type should tell us whether go_direct or not
- // the "go_direct" action tag recognization is done in get_rule_type
- switch (m_ele->cfg_ele.type) {
- case TS_PP_GO_DIRECT:
- m_ele->direct = true;
- break;
- case TS_PP_PARENT:
- m_ele->direct = false;
- break;
- default:
- // Handled here:
- // Lots of cases
- break;
- }
-
- return;
-
-FORMAT_ERR:
- m_valid = false;
-}
-
-ParentProxyObj::~ParentProxyObj()
-{
- TSParentProxyEleDestroy(m_ele);
-}
-
-char *
-ParentProxyObj::formatEleToRule()
-{
- if (!isValid()) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- return nullptr;
- }
-
- char *pd_str, *list_str;
- char buf[MAX_RULE_SIZE];
- memset(buf, 0, MAX_RULE_SIZE);
-
- pd_str = pdest_sspec_to_string(m_ele->parent_info.pd_type, m_ele->parent_info.pd_val, &(m_ele->parent_info.sec_spec));
- if (!pd_str) {
- return nullptr;
- }
- ink_strlcat(buf, pd_str, sizeof(buf));
- ats_free(pd_str);
-
- // round_robin
- if ((m_ele->rr != TS_RR_NONE) && (m_ele->rr != TS_RR_UNDEFINED)) {
- if (!isspace(buf[strlen(buf) - 1])) {
- ink_strlcat(buf, " ", sizeof(buf));
- }
- ink_strlcat(buf, "round_robin=", sizeof(buf));
- switch (m_ele->rr) {
- case TS_RR_TRUE:
- ink_strlcat(buf, "true", sizeof(buf));
- break;
- case TS_RR_STRICT:
- ink_strlcat(buf, "strict", sizeof(buf));
- break;
- case TS_RR_FALSE:
- ink_strlcat(buf, "false", sizeof(buf));
- break;
- default:
- // Handled here:
- // TS_RR_NONE, TS_RR_UNDEFINED
- break;
- }
- }
-
- if (m_ele->proxy_list != nullptr) {
- // include space delimiter if not already exist
- if (!isspace(buf[strlen(buf) - 1])) {
- ink_strlcat(buf, " ", sizeof(buf));
- }
- list_str = domain_list_to_string(m_ele->proxy_list, ";");
- ink_strlcat(buf, "parent=\"", sizeof(buf));
- if (list_str) {
- ink_strlcat(buf, list_str, sizeof(buf));
- ats_free(list_str);
- }
- ink_strlcat(buf, "\"", sizeof(buf));
- }
-
- if (m_ele->direct) {
- // include space delimiter if not already exist
- if (!isspace(buf[strlen(buf) - 1])) {
- ink_strlcat(buf, " ", sizeof(buf));
- }
- ink_strlcat(buf, "go_direct=true", sizeof(buf));
- } else {
- if (!isspace(buf[strlen(buf) - 1])) {
- ink_strlcat(buf, " ", sizeof(buf));
- }
- ink_strlcat(buf, "go_direct=false", sizeof(buf));
- }
-
- return ats_strdup(buf);
-}
-
-bool
-ParentProxyObj::isValid()
-{
- if (m_ele->cfg_ele.error != TS_ERR_OKAY) {
- m_valid = false;
- }
-
- if (!ccu_checkPdSspec(m_ele->parent_info)) {
- m_valid = false;
- }
-
- if (m_ele->proxy_list && !TSDomainListIsValid(m_ele->proxy_list)) {
- m_valid = false;
- }
-
- if (!m_valid) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- }
-
- return m_valid;
-}
-
-TSCfgEle *
-ParentProxyObj::getCfgEleCopy()
-{
- return (TSCfgEle *)copy_parent_proxy_ele(m_ele);
-}
-
-//--------------------------------------------------------------------------
-// VolumeObj
-//--------------------------------------------------------------------------
-VolumeObj::VolumeObj(TSVolumeEle *ele)
-{
- m_ele = ele;
- m_valid = true;
- m_valid = isValid();
-}
-
-VolumeObj::VolumeObj(TokenList *tokens)
-{
- Token *token;
-
- m_ele = TSVolumeEleCreate();
- m_ele->cfg_ele.error = TS_ERR_OKAY;
- m_valid = true;
-
- if (!tokens || tokens->length != 3) {
- goto FORMAT_ERR;
- }
-
- m_ele->cfg_ele.type = get_rule_type(tokens, TS_FNAME_VOLUME);
- if (m_ele->cfg_ele.type == TS_TYPE_UNDEFINED) {
- goto FORMAT_ERR;
- }
-
- token = tokens->first();
- if (strcmp(token->name, "volume") || !token->value) {
- goto FORMAT_ERR;
- }
- m_ele->volume_num = ink_atoi(token->value);
-
- // arguments
- token = tokens->next(token);
- while (token) {
- if (strcmp(token->name, "scheme")) {
- if (!token->value || m_ele->scheme) {
- // return a format error if the token doesn't have a
- // value or the scheme was already set with a previous
- // duplicated option.
- goto FORMAT_ERR;
- }
- if (!strcmp(token->value, "http")) {
- m_ele->scheme = TS_VOLUME_HTTP;
- } else {
- m_ele->scheme = TS_VOLUME_UNDEFINED;
- }
- }
-
- if (strcmp(token->name, "size")) {
- if (!token->value || m_ele->volume_size) {
- // return a format error if the token doesn't have a
- // value or the size was already set with a previous
- // duplicated option.
- goto FORMAT_ERR;
- }
- // CAUTION: we may need a tigher error check
- if (strstr(token->value, "%")) {
- m_ele->size_format = TS_SIZE_FMT_PERCENT;
- } else {
- m_ele->size_format = TS_SIZE_FMT_ABSOLUTE;
- }
- m_ele->volume_size = ink_atoi(token->value);
- }
-
- if (m_ele->scheme && m_ele->volume_size) {
- break; // Ignore duplicated options.
- }
-
- token = tokens->next(token);
- }
-
- return;
-
-FORMAT_ERR:
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- m_valid = false;
-}
-
-VolumeObj::~VolumeObj()
-{
- TSVolumeEleDestroy(m_ele);
-}
-
-char *
-VolumeObj::formatEleToRule()
-{
- if (!isValid()) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- return nullptr;
- }
-
- char buf[MAX_RULE_SIZE];
- memset(buf, 0, MAX_RULE_SIZE);
-
- snprintf(buf, sizeof(buf), "volume=%d scheme=", m_ele->volume_num);
-
- switch (m_ele->scheme) {
- case TS_VOLUME_HTTP:
- ink_strlcat(buf, "http", sizeof(buf));
- break;
- default:
- // Handled here:
- // TS_VOLUME_UNDEFINED, TS_SIZE_FMT_ABSOLUTE, TS_SIZE_FMT_UNDEFINED
- break;
- }
-
- size_t pos = strlen(buf);
- snprintf(buf + pos, sizeof(buf) - pos, " size=%d", m_ele->volume_size);
- switch (m_ele->size_format) {
- case TS_SIZE_FMT_PERCENT:
- ink_strlcat(buf, "%", sizeof(buf));
- break;
- default:
- // Handled here:
- // TS_SIZE_FMT_ABSOLUTE, TS_SIZE_FMT_UNDEFINED
- break;
- }
-
- return ats_strdup(buf);
-}
-
-bool
-VolumeObj::isValid()
-{
- if (m_ele->cfg_ele.error != TS_ERR_OKAY) {
- m_valid = false;
- }
- // volume nubmer must be between 1-255 inclusive
- if (m_ele->volume_num < 1 || m_ele->volume_num > 255) {
- m_valid = false;
- }
-
- switch (m_ele->scheme) {
- case TS_VOLUME_HTTP:
- break;
- default:
- m_valid = false;
- }
-
- // absolute size must be multiple of 128; percentage size <= 100
- if (m_ele->size_format == TS_SIZE_FMT_ABSOLUTE) {
- if ((m_ele->volume_size < 0) || (m_ele->volume_size % 128)) {
- m_valid = false;
- }
- } else if (m_ele->size_format == TS_SIZE_FMT_PERCENT) {
- if ((m_ele->volume_size < 0) || (m_ele->volume_size > 100)) {
- m_valid = false;
- }
- }
-
- if (!m_valid) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- }
-
- return m_valid;
-}
-
-TSCfgEle *
-VolumeObj::getCfgEleCopy()
-{
- return (TSCfgEle *)copy_volume_ele(m_ele);
-}
-
-//--------------------------------------------------------------------------
-// PluginObj
-//--------------------------------------------------------------------------
-PluginObj::PluginObj(TSPluginEle *ele)
-{
- m_ele = ele;
- m_valid = true;
- m_valid = isValid();
-}
-
-PluginObj::PluginObj(TokenList *tokens)
-{
- Token *token;
-
- m_ele = TSPluginEleCreate();
- m_ele->cfg_ele.error = TS_ERR_OKAY;
- m_valid = true;
-
- if (!tokens || tokens->length < 1) {
- goto FORMAT_ERR;
- }
-
- m_ele->cfg_ele.type = get_rule_type(tokens, TS_FNAME_PLUGIN);
- if (m_ele->cfg_ele.type == TS_TYPE_UNDEFINED) {
- goto FORMAT_ERR;
- }
- // plugin name
- token = tokens->first();
- if (strcmp(token->name, "") == 0) {
- goto FORMAT_ERR;
- }
- m_ele->name = ats_strdup(token->name);
-
- // arguments
- token = tokens->next(token);
- while (token) {
- if (m_ele->args == TS_INVALID_LIST) {
- m_ele->args = TSStringListCreate();
- }
- if (token->name) {
- TSStringListEnqueue(m_ele->args, ats_strdup(token->name));
- }
- token = tokens->next(token);
- }
-
- return;
-
-FORMAT_ERR:
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- m_valid = false;
-}
-
-PluginObj::~PluginObj()
-{
- TSPluginEleDestroy(m_ele);
-}
-
-char *
-PluginObj::formatEleToRule()
-{
- if (!isValid()) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- return nullptr;
- }
-
- char *list_str;
- char buf[MAX_RULE_SIZE];
- memset(buf, 0, MAX_RULE_SIZE);
-
- list_str = string_list_to_string(m_ele->args, " ");
- if (list_str) {
- snprintf(buf, sizeof(buf), "%s %s", m_ele->name, list_str);
- ats_free(list_str);
- } else {
- snprintf(buf, sizeof(buf), "%s", m_ele->name);
- }
-
- return ats_strdup(buf);
-}
-
-bool
-PluginObj::isValid()
-{
- if (m_ele->cfg_ele.error != TS_ERR_OKAY) {
- m_valid = false;
- }
- // check plugin name
- if (!m_ele->name || strcmp(m_ele->name, "") == 0) {
- m_valid = false;
- }
-
- return m_valid;
-}
-
-TSCfgEle *
-PluginObj::getCfgEleCopy()
-{
- return (TSCfgEle *)copy_plugin_ele(m_ele);
-}
-
-//--------------------------------------------------------------------------
-// RemapObj
-//--------------------------------------------------------------------------
-RemapObj::RemapObj(TSRemapEle *ele)
-{
- m_ele = ele;
- m_valid = true;
- m_valid = isValid();
-}
-
-RemapObj::RemapObj(TokenList *tokens)
-{
- Token *token;
- short current; // current token index
- Tokenizer fromTok(":/");
- Tokenizer toTok(":/");
- char buf[MAX_RULE_SIZE];
-
- m_ele = TSRemapEleCreate(TS_TYPE_UNDEFINED);
- m_ele->cfg_ele.error = TS_ERR_OKAY;
- m_valid = true;
-
- if (!tokens || ((tokens->length != 2) && (tokens->length != 3))) {
- goto FORMAT_ERR;
- }
-
- m_ele->cfg_ele.type = get_rule_type(tokens, TS_FNAME_REMAP);
- if (m_ele->cfg_ele.type == TS_TYPE_UNDEFINED) {
- goto FORMAT_ERR;
- }
- // The first token must either be "map, "reverse_map", "redirect", and redirect_temporary
- token = tokens->first();
-
- // target
- token = tokens->next(token);
-
- if (!ccu_checkUrl(token->name)) {
- goto FORMAT_ERR;
- }
-
- // TODO: Should we check the return value (count) here?
- fromTok.Initialize(token->name, ALLOW_EMPTY_TOKS); // allow empty token for parse sanity check
-
- if (strcmp(fromTok[0], "http") == 0) {
- m_ele->from_scheme = TS_SCHEME_HTTP;
- } else if (strcmp(fromTok[0], "https") == 0) {
- m_ele->from_scheme = TS_SCHEME_HTTPS;
- } else {
- m_ele->from_scheme = TS_SCHEME_UNDEFINED;
- goto FORMAT_ERR;
- }
-
- // from host
- m_ele->from_host = ats_strdup(fromTok[3]);
-
- current = 4;
- if (fromTok[4]) {
- // from port
- m_ele->from_port = ink_atoi(fromTok[4]);
- if (m_ele->from_port != 0) { // Does it have a port
- current++;
- } else { // No ports
- m_ele->from_port = TS_INVALID_PORT;
- }
-
- // from prefix
- if (fromTok[current]) {
- memset(buf, 0, MAX_RULE_SIZE);
-
- for (int i = current; fromTok[i]; i++) {
- ink_strlcat(buf, fromTok[i], sizeof(buf));
- ink_strlcat(buf, "/", sizeof(buf));
- }
-
- if ((token->name)[strlen(token->name) - 1] != '/') {
- buf[strlen(buf) - 1] = '\0'; // truncate the last '/'
- }
-
- m_ele->from_path_prefix = ats_strdup(buf);
- }
- } else {
- if ((token->name)[strlen(token->name) - 1] == '/') {
- memset(buf, 0, MAX_RULE_SIZE);
- ink_strlcpy(buf, m_ele->from_host, sizeof(buf));
- ats_free(m_ele->from_host);
- ink_strlcat(buf, "/", sizeof(buf));
- m_ele->from_host = ats_strdup(buf);
- }
- }
-
- if (!ccu_checkUrl(token->value)) {
- goto FORMAT_ERR;
- }
-
- // TODO: Should we check the return value (count) here?
- toTok.Initialize(token->value, ALLOW_EMPTY_TOKS); // allow empty token for parse sanity check
-
- if (strcmp(toTok[0], "http") == 0) {
- m_ele->to_scheme = TS_SCHEME_HTTP;
- } else if (strcmp(toTok[0], "https") == 0) {
- m_ele->to_scheme = TS_SCHEME_HTTPS;
- } else {
- m_ele->to_scheme = TS_SCHEME_UNDEFINED;
- goto FORMAT_ERR;
- }
-
- // to host
- m_ele->to_host = ats_strdup(toTok[3]);
-
- current = 4;
- if (toTok[4]) {
- // to port
- m_ele->to_port = ink_atoi(toTok[4]);
- if (m_ele->to_port != 0) { // Does it have a port
- current++;
- } else { // No ports
- m_ele->to_port = TS_INVALID_PORT;
- }
-
- // to prefix
- if (toTok[current]) {
- memset(buf, 0, MAX_RULE_SIZE);
-
- for (int i = current; toTok[i]; i++) {
- ink_strlcat(buf, toTok[i], sizeof(buf));
- ink_strlcat(buf, "/", sizeof(buf));
- }
-
- if ((token->name)[strlen(token->name) - 1] != '/') {
- buf[strlen(buf) - 1] = '\0'; // truncate the last '/'
- }
-
- m_ele->to_path_prefix = ats_strdup(buf);
- }
- } else {
- if ((token->value)[strlen(token->value) - 1] == '/') {
- memset(buf, 0, MAX_RULE_SIZE);
- ink_strlcpy(buf, m_ele->to_host, sizeof(buf));
- ats_free(m_ele->to_host);
- ink_strlcat(buf, "/", sizeof(buf));
- m_ele->to_host = ats_strdup(buf);
- }
- }
-
- return;
-
-FORMAT_ERR:
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- m_valid = false;
-}
-
-RemapObj::~RemapObj()
-{
- TSRemapEleDestroy(m_ele);
-}
-
-char *
-RemapObj::formatEleToRule()
-{
- if (!isValid()) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- return nullptr;
- }
-
- char buf[MAX_RULE_SIZE];
- memset(buf, 0, MAX_RULE_SIZE);
-
- switch (m_ele->cfg_ele.type) {
- case TS_REMAP_MAP:
- ink_strlcat(buf, "map", sizeof(buf));
- break;
- case TS_REMAP_REVERSE_MAP:
- ink_strlcat(buf, "reverse_map", sizeof(buf));
- break;
- case TS_REMAP_REDIRECT:
- ink_strlcat(buf, "redirect", sizeof(buf));
- break;
- case TS_REMAP_REDIRECT_TEMP:
- ink_strlcat(buf, "redirect_temporary", sizeof(buf));
- break;
- default:
- // Handled here:
- // Lots of cases...
- break;
- }
- // space delimitor
- ink_strlcat(buf, " ", sizeof(buf));
-
- // from scheme
- switch (m_ele->from_scheme) {
- case TS_SCHEME_HTTP:
- ink_strlcat(buf, "http", sizeof(buf));
- break;
- case TS_SCHEME_HTTPS:
- ink_strlcat(buf, "https", sizeof(buf));
- break;
- default:
- // Handled here:
- // TS_SCHEME_NONE, TS_SCHEME_UNDEFINED
- break;
- }
- ink_strlcat(buf, "://", sizeof(buf));
-
- // from host
- if (m_ele->from_host) {
- ink_strlcat(buf, m_ele->from_host, sizeof(buf));
- }
- // from port
- if (m_ele->from_port != TS_INVALID_PORT) {
- snprintf(buf, sizeof(buf), "%s:%d", buf, m_ele->from_port);
- }
- // from host path
- if (m_ele->from_path_prefix) {
- ink_strlcat(buf, "/", sizeof(buf));
- ink_strlcat(buf, m_ele->from_path_prefix, sizeof(buf));
- }
- // space delimitor
- ink_strlcat(buf, " ", sizeof(buf));
-
- // to scheme
- switch (m_ele->to_scheme) {
- case TS_SCHEME_HTTP:
- ink_strlcat(buf, "http", sizeof(buf));
- break;
- case TS_SCHEME_HTTPS:
- ink_strlcat(buf, "https", sizeof(buf));
- break;
- default:
- // Handled here:
- // TS_SCHEME_NONE, TS_SCHEME_UNDEFINED
- break;
- }
- ink_strlcat(buf, "://", sizeof(buf));
-
- // to host
- if (m_ele->to_host) {
- ink_strlcat(buf, m_ele->to_host, sizeof(buf));
- }
- // to port
- if (m_ele->to_port != TS_INVALID_PORT) {
- snprintf(buf, sizeof(buf), "%s:%d", buf, m_ele->to_port);
- }
- // to host path
- if (m_ele->to_path_prefix) {
- ink_strlcat(buf, "/", sizeof(buf));
- ink_strlcat(buf, m_ele->to_path_prefix, sizeof(buf));
- }
-
- return ats_strdup(buf);
-}
-
-bool
-RemapObj::isValid()
-{
- if (m_ele->cfg_ele.error != TS_ERR_OKAY) {
- m_valid = false;
- }
- // rule type
- switch (m_ele->cfg_ele.type) {
- case TS_REMAP_MAP:
- case TS_REMAP_REVERSE_MAP:
- case TS_REMAP_REDIRECT:
- case TS_REMAP_REDIRECT_TEMP:
- break;
- default:
- m_valid = false;
- }
-
- // from scheme
- switch (m_ele->from_scheme) {
- case TS_SCHEME_HTTP:
- case TS_SCHEME_HTTPS:
- break;
- default:
- m_valid = false;
- }
-
- switch (m_ele->to_scheme) {
- case TS_SCHEME_HTTP:
- case TS_SCHEME_HTTPS:
- break;
- default:
- m_valid = false;
- }
-
- // mandatory field
- if (!m_ele->from_host || strstr(m_ele->from_host, ":/")) {
- m_valid = false;
- }
- // mandatory field
- if (!m_ele->to_host || strstr(m_ele->to_host, ":/")) {
- m_valid = false;
- }
-
- if ((m_ele->from_path_prefix && strstr(m_ele->from_path_prefix, ":")) ||
- (m_ele->to_path_prefix && strstr(m_ele->to_path_prefix, ":"))) {
- m_valid = false;
- }
-
- if (!m_valid) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- }
-
- return m_valid;
-}
-
-TSCfgEle *
-RemapObj::getCfgEleCopy()
-{
- return (TSCfgEle *)copy_remap_ele(m_ele);
-}
-
-//--------------------------------------------------------------------------
-// SocksObj
-//--------------------------------------------------------------------------
-SocksObj::SocksObj(TSSocksEle *ele)
-{
- m_ele = ele;
- m_valid = true;
- m_valid = isValid();
-}
-
-SocksObj::SocksObj(TokenList *tokens)
-{
- Token *tok;
-
- m_ele = TSSocksEleCreate(TS_TYPE_UNDEFINED);
- m_ele->cfg_ele.error = TS_ERR_OKAY;
- m_valid = true;
-
- if (!tokens) {
- goto FORMAT_ERR;
- }
-
- m_ele->cfg_ele.type = get_rule_type(tokens, TS_FNAME_SOCKS);
- if (m_ele->cfg_ele.type == TS_TYPE_UNDEFINED) {
- goto FORMAT_ERR;
- }
- // Determine if it's a "no-socks" rule or a "parent socks servers" rule
- tok = tokens->first();
- if (strcmp(tok->name, "no_socks") == 0) { // no-socks rule; TS_SOCKS_BYPASS
-
- if (m_ele->ip_addrs != nullptr) {
- goto FORMAT_ERR;
- }
- m_ele->ip_addrs = string_to_ip_addr_list(tok->value, ",");
- } else if (strcmp(tok->name, "auth") == 0) { // TS_SOCKS_AUTH rule
- if (strcmp(tok->value, "u") == 0) {
- tok = tokens->next(tok);
- if (tok && tok->name) {
- m_ele->username = ats_strdup(tok->name);
- } else {
- goto FORMAT_ERR;
- }
- if (tok && tok->name) {
- tok = tokens->next(tok);
- m_ele->password = ats_strdup(tok->name);
- } else {
- goto FORMAT_ERR;
- }
- } else {
- goto FORMAT_ERR;
- }
- } else { // multiple socks servers rule; TS_SOCKS_MULTIPLE
- // should be dest_ip tag
- if (strcmp(tok->name, "dest_ip") == 0) {
- m_ele->dest_ip_addr = string_to_ip_addr_ele(tok->value);
- } else {
- goto FORMAT_ERR;
- }
-
- // search dest_ip, parent and round_robin action tags
- for (tok = tokens->next(tok); tok; tok = tokens->next(tok)) {
- if (strcmp(tok->name, "round_robin") == 0) {
- // sanity check
- if (!tok->value) {
- goto FORMAT_ERR;
- }
-
- if (strcmp(tok->value, "true") == 0) {
- m_ele->rr = TS_RR_TRUE;
- } else if (strcmp(tok->value, "strict") == 0) {
- m_ele->rr = TS_RR_STRICT;
- } else if (strcmp(tok->value, "false") == 0) {
- m_ele->rr = TS_RR_FALSE;
- } else {
- m_ele->rr = TS_RR_NONE;
- goto FORMAT_ERR; // missing value for round_robin tag
- }
-
- } else if (strcmp(tok->name, "parent") == 0) {
- // sanity check
- if (!tok->value) {
- goto FORMAT_ERR;
- }
- m_ele->socks_servers = string_to_domain_list(tok->value, ";");
- }
- } // end for loop
- }
-
- return;
-
-FORMAT_ERR:
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- m_valid = false;
-}
-
-SocksObj::~SocksObj()
-{
- TSSocksEleDestroy(m_ele);
-}
-
-char *
-SocksObj::formatEleToRule()
-{
- if (!isValid()) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- return nullptr;
- }
- char buf[MAX_RULE_SIZE];
- memset(buf, 0, MAX_RULE_SIZE);
-
- if (m_ele->ip_addrs != nullptr) { // TS_SOCKS_BYPASS rule
- char *str_list = ip_addr_list_to_string((LLQ *)m_ele->ip_addrs, ",");
- if (str_list) {
- snprintf(buf, sizeof(buf), "no_socks %s", str_list);
- ats_free(str_list);
- } else {
- return nullptr; // invalid ip_addr_list
- }
- } else if (m_ele->username != nullptr) { // TS_SOCKS_AUTH rule
- snprintf(buf, sizeof(buf), "auth u %s %s", m_ele->username, m_ele->password);
- } else { // TS_SOCKS_MULTIPLE rule
- // destination ip
- char *ip_str = ip_addr_ele_to_string((TSIpAddrEle *)m_ele->dest_ip_addr);
- if (ip_str) {
- ink_strlcat(buf, "dest_ip=", sizeof(buf));
- ink_strlcat(buf, ip_str, sizeof(buf));
- ats_free(ip_str);
- } else {
- return nullptr; // invalid IP
- }
-
- // parent server list
- if (m_ele->socks_servers != nullptr) {
- // include space delimiter if not already exist
- if (!isspace(buf[strlen(buf) - 1])) {
- ink_strlcat(buf, " ", sizeof(buf));
- }
- char *list_str = domain_list_to_string(m_ele->socks_servers, ";");
- if (list_str) {
- ink_strlcat(buf, "parent=\"", sizeof(buf));
- ink_strlcat(buf, list_str, sizeof(buf));
- ink_strlcat(buf, "\"", sizeof(buf));
- ats_free(list_str);
- } else {
- return nullptr; // invalid list
- }
- }
- // round-robin, if specified
- if ((m_ele->rr != TS_RR_NONE) && (m_ele->rr != TS_RR_UNDEFINED)) {
- if (!isspace(buf[strlen(buf) - 1])) {
- ink_strlcat(buf, " ", sizeof(buf));
- }
- ink_strlcat(buf, "round_robin=", sizeof(buf));
- switch (m_ele->rr) {
- case TS_RR_TRUE:
- ink_strlcat(buf, "true", sizeof(buf));
- break;
- case TS_RR_STRICT:
- ink_strlcat(buf, "strict", sizeof(buf));
- break;
- case TS_RR_FALSE:
- ink_strlcat(buf, "false", sizeof(buf));
- break;
- default:
- // Handled here:
- // TS_RR_NONE, TS_RR_UNDEFINED
- break;
- }
- }
- }
-
- return ats_strdup(buf);
-}
-
-// the rule must either have an ip addr list (exclusive) OR
-// the dest_ip_addr * socks_servers OR
-// the username and password
-bool
-SocksObj::isValid()
-{
- if (m_ele->cfg_ele.error != TS_ERR_OKAY) {
- m_valid = false;
- }
-
- switch (m_ele->cfg_ele.type) {
- case TS_SOCKS_BYPASS:
- if (m_ele->dest_ip_addr || m_ele->username || m_ele->password || !TSIpAddrListIsValid(m_ele->ip_addrs)) {
- m_valid = false;
- } else {
- m_valid = true;
- }
- break;
- case TS_SOCKS_AUTH:
- if (m_ele->username == nullptr || m_ele->password == nullptr || m_ele->ip_addrs || m_ele->dest_ip_addr) {
- m_valid = false;
- } else {
- m_valid = true;
- }
- break;
- case TS_SOCKS_MULTIPLE:
- if (m_ele->ip_addrs || m_ele->username || !(m_ele->dest_ip_addr && m_ele->socks_servers) ||
- !ccu_checkIpAddrEle(m_ele->dest_ip_addr) || !TSDomainListIsValid(m_ele->socks_servers)) {
- m_valid = false;
- } else {
- m_valid = true;
- }
- break;
- default:
- m_valid = false;
- break;
- }
-
- if (!m_valid) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- }
-
- return m_valid;
-}
-
-TSCfgEle *
-SocksObj::getCfgEleCopy()
-{
- return (TSCfgEle *)copy_socks_ele(m_ele);
-}
-
-//--------------------------------------------------------------------------
-// SplitDnsObj
-//--------------------------------------------------------------------------
-SplitDnsObj::SplitDnsObj(TSSplitDnsEle *ele)
-{
- m_ele = ele;
- m_valid = true;
- m_valid = isValid();
-}
-
-SplitDnsObj::SplitDnsObj(TokenList *tokens)
-{
- Token *tok;
-
- m_ele = TSSplitDnsEleCreate();
- m_ele->cfg_ele.error = TS_ERR_OKAY;
- m_valid = true;
-
- if (!tokens || (tokens->length > 6)) {
- goto FORMAT_ERR;
- }
-
- m_ele->cfg_ele.type = get_rule_type(tokens, TS_FNAME_SPLIT_DNS);
- if (m_ele->cfg_ele.type == TS_TYPE_UNDEFINED) {
- goto FORMAT_ERR;
- }
-
- tok = tokens->first();
- while (tok) {
- if (!strcmp(tok->name, "dest_domain")) {
- if ((m_ele->pd_type != TS_PD_UNDEFINED) || (m_ele->pd_val != nullptr) || (!tok->value)) {
- // fields are already defined!!
- goto FORMAT_ERR;
- }
- m_ele->pd_type = TS_PD_DOMAIN;
- m_ele->pd_val = ats_strdup(tok->value);
- } else if (strcmp(tok->name, "dest_host") == 0) {
- if ((m_ele->pd_type != TS_PD_UNDEFINED) || (m_ele->pd_val != nullptr) || (!tok->value)) {
- // fields are already defined!!
- goto FORMAT_ERR;
- }
- m_ele->pd_type = TS_PD_HOST;
- m_ele->pd_val = ats_strdup(tok->value);
- } else if (strcmp(tok->name, "url_regex") == 0) {
- if ((m_ele->pd_type != TS_PD_UNDEFINED) || (m_ele->pd_val != nullptr) || (!tok->value)) {
- // fields are already defined!!
- goto FORMAT_ERR;
- }
- m_ele->pd_type = TS_PD_URL_REGEX;
- m_ele->pd_val = ats_strdup(tok->value);
- } else if (strcmp(tok->name, "url") == 0) {
- if ((m_ele->pd_type != TS_PD_UNDEFINED) || (m_ele->pd_val != nullptr) || (!tok->value)) {
- // fields are already defined!!
- goto FORMAT_ERR;
- }
- m_ele->pd_type = TS_PD_URL;
- m_ele->pd_val = ats_strdup(tok->value);
- } else if (strcmp(tok->name, "named") == 0) {
- if ((m_ele->dns_servers_addrs != nullptr) || (!tok->value)) {
- // fields are already defined!!
- goto FORMAT_ERR;
- }
- m_ele->dns_servers_addrs = (TSDomainList)string_to_domain_list(tok->value, "; ");
- } else if (strcmp(tok->name, "def_domain") == 0) {
- if ((m_ele->def_domain != nullptr) || (!tok->value)) {
- // fields are already defined!!
- goto FORMAT_ERR;
- }
- m_ele->def_domain = ats_strdup(tok->value);
- } else if (strcmp(tok->name, "search_list") == 0) {
- if ((m_ele->search_list != nullptr) || (!tok->value)) {
- // fields are already defined!!
- goto FORMAT_ERR;
- }
- m_ele->search_list = (TSDomainList)string_to_domain_list(tok->value, "; ");
- } else {
- // Not able to recongize token name
- goto FORMAT_ERR;
- }
-
- tok = tokens->next(tok);
- }
- return;
-
-FORMAT_ERR:
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- m_valid = false;
-}
-
-SplitDnsObj::~SplitDnsObj()
-{
- TSSplitDnsEleDestroy(m_ele);
-}
-
-char *
-SplitDnsObj::formatEleToRule()
-{
- if (!isValid()) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- return nullptr;
- }
-
- char buf[MAX_RULE_SIZE];
- memset(buf, 0, MAX_RULE_SIZE);
-
- char *pd_name;
- switch (m_ele->pd_type) {
- case TS_PD_DOMAIN:
- pd_name = ats_strdup("dest_domain");
- break;
- case TS_PD_HOST:
- pd_name = ats_strdup("dest_host");
- break;
- case TS_PD_URL_REGEX:
- pd_name = ats_strdup("url_regex");
- break;
- case TS_PD_URL:
- pd_name = ats_strdup("url");
- break;
- default:
- pd_name = ats_strdup(""); // lv: just to make this junk workable
- // Handled here:
- // TS_PD_IP, TS_PD_UNDEFINED
- break;
- }
-
- if (m_ele->pd_val) {
- ink_strlcat(buf, pd_name, sizeof(buf));
- ink_strlcat(buf, "=", sizeof(buf));
- if (strstr(m_ele->pd_val, " ")) {
- ink_strlcat(buf, "\"", sizeof(buf));
- }
- ink_strlcat(buf, m_ele->pd_val, sizeof(buf));
- if (strstr(m_ele->pd_val, " ")) {
- ink_strlcat(buf, "\"", sizeof(buf));
- }
- ink_strlcat(buf, " ", sizeof(buf));
- }
-
- if (m_ele->dns_servers_addrs) {
- ink_strlcat(buf, "named=", sizeof(buf));
- char *temp = domain_list_to_string((LLQ *)m_ele->dns_servers_addrs, ";");
- if (temp) {
- if (strstr(temp, " ")) {
- ink_strlcat(buf, "\"", sizeof(buf));
- }
- ink_strlcat(buf, temp, sizeof(buf));
- if (strstr(temp, " ")) {
- ink_strlcat(buf, "\"", sizeof(buf));
- }
- ats_free(temp);
- }
- ink_strlcat(buf, " ", sizeof(buf));
- }
-
- if (m_ele->def_domain) {
- ink_strlcat(buf, "def_domain=", sizeof(buf));
- if (strstr(m_ele->def_domain, " ")) {
- ink_strlcat(buf, "\"", sizeof(buf));
- }
- ink_strlcat(buf, m_ele->def_domain, sizeof(buf));
- if (strstr(m_ele->def_domain, " ")) {
- ink_strlcat(buf, "\"", sizeof(buf));
- }
- ink_strlcat(buf, " ", sizeof(buf));
- }
-
- if (m_ele->search_list) {
- ink_strlcat(buf, "search_list=", sizeof(buf));
- char *temp = domain_list_to_string(m_ele->search_list, ";");
- if (temp) {
- if (strstr(temp, " ")) {
- ink_strlcat(buf, "\"", sizeof(buf));
- }
- ink_strlcat(buf, temp, sizeof(buf));
- if (strstr(temp, " ")) {
- ink_strlcat(buf, "\"", sizeof(buf));
- }
- ats_free(temp);
- }
- ink_strlcat(buf, " ", sizeof(buf));
- }
- // chop the last space
- while (isspace(buf[strlen(buf) - 1])) {
- buf[strlen(buf) - 1] = '\0';
- }
-
- ats_free(pd_name);
-
- return ats_strdup(buf);
-}
-
-bool
-SplitDnsObj::isValid()
-{
- if (m_ele->cfg_ele.error != TS_ERR_OKAY) {
- m_valid = false;
- }
-
- switch (m_ele->pd_type) {
- case TS_PD_DOMAIN:
- case TS_PD_HOST:
- case TS_PD_URL_REGEX:
- break;
- default:
- m_valid = false;
- }
-
- if (!m_ele->pd_val) {
- m_valid = false;
- }
-
- if (!TSDomainListIsValid(m_ele->dns_servers_addrs)) {
- m_valid = false;
- }
- // search_list is optional
- if (m_ele->search_list && !TSDomainListIsValid(m_ele->search_list)) {
- m_valid = false;
- }
-
- if (!m_valid) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- }
-
- return m_valid;
-}
-
-TSCfgEle *
-SplitDnsObj::getCfgEleCopy()
-{
- return (TSCfgEle *)copy_split_dns_ele(m_ele);
-}
-
-//--------------------------------------------------------------------------
-// StorageObj
-//--------------------------------------------------------------------------
-StorageObj::StorageObj(TSStorageEle *ele)
-{
- m_ele = ele;
- m_valid = true;
- m_valid = isValid(); // now validate
-}
-
-// must have at least 1 token (token-name = pathname, token-value = size (if any) )
-StorageObj::StorageObj(TokenList *tokens)
-{
- Token *tok;
-
- m_ele = TSStorageEleCreate();
- m_ele->cfg_ele.error = TS_ERR_OKAY;
- m_valid = true;
-
- if (!tokens || (tokens->length > 6)) {
- goto FORMAT_ERR;
- }
-
- m_ele->cfg_ele.type = get_rule_type(tokens, TS_FNAME_STORAGE);
- if (m_ele->cfg_ele.type == TS_TYPE_UNDEFINED) {
- goto FORMAT_ERR;
- }
- // check first token; must exist
- tok = tokens->first();
- if (!tok->name) {
- goto FORMAT_ERR; // no pathname specified
- } else {
- m_ele->pathname = ats_strdup(tok->name);
- }
-
- // check if size is specified
- if (tok->value) { // size is specified in second token
- m_ele->size = ink_atoi(tok->value);
- }
-
- return;
-
-FORMAT_ERR:
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- m_valid = false;
-}
-
-StorageObj::~StorageObj()
-{
- TSStorageEleDestroy(m_ele);
-}
-
-char *
-StorageObj::formatEleToRule()
-{
- if (!isValid()) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- return nullptr;
- }
-
- char buf[MAX_RULE_SIZE];
- memset(buf, 0, MAX_RULE_SIZE);
-
- if (m_ele->size < 0) { // if size < 0, then raw volume
- snprintf(buf, sizeof(buf), "%s", m_ele->pathname);
- } else {
- snprintf(buf, sizeof(buf), "%s %d", m_ele->pathname, m_ele->size);
- }
-
- return ats_strdup(buf);
-}
-
-bool
-StorageObj::isValid()
-{
- if (m_ele->cfg_ele.error != TS_ERR_OKAY) {
- m_valid = false;
- }
-
- if (!(m_ele->pathname)) {
- m_valid = false;
- }
-
- if (!m_valid) {
- m_ele->cfg_ele.error = TS_ERR_INVALID_CONFIG_RULE;
- }
-
- return m_valid;
-}
-
-TSCfgEle *
-StorageObj::getCfgEleCopy()
-{
- return (TSCfgEle *)copy_storage_ele(m_ele);
-}
-
-/*****************************************************************
- * CfgContext
- *****************************************************************/
-CfgContext::CfgContext(TSFileNameT filename)
-{
- m_file = filename;
- m_ver = -1;
-}
-
-CfgContext::~CfgContext()
-{
- CfgEleObj *ele;
- while ((ele = m_eles.dequeue())) {
- delete ele;
- }
-}
-
-TSMgmtError
-CfgContext::addEle(CfgEleObj *ele)
-{
- ink_assert(ele != nullptr);
- m_eles.enqueue(ele); // enqueue CfgEleObj at end of Queue
- return TS_ERR_OKAY;
-}
-
-TSMgmtError
-CfgContext::removeEle(CfgEleObj *ele)
-{
- ink_assert(ele != nullptr);
- m_eles.remove(ele);
- delete ele;
-
- return TS_ERR_OKAY;
-}
-
-TSMgmtError
-CfgContext::insertEle(CfgEleObj *ele, CfgEleObj *after_ele)
-{
- ink_assert(ele != nullptr && after_ele != nullptr);
- m_eles.insert(ele, after_ele);
-
- return TS_ERR_OKAY;
-}
-
-// insert Ele at front of the Queue
-TSMgmtError
-CfgContext::pushEle(CfgEleObj *ele)
-{
- ink_assert(ele != nullptr);
- m_eles.push(ele);
-
- return TS_ERR_OKAY;
-}
diff --git a/mgmt/api/CfgContextImpl.h b/mgmt/api/CfgContextImpl.h
deleted file mode 100644
index 93b1e09..0000000
--- a/mgmt/api/CfgContextImpl.h
+++ /dev/null
@@ -1,435 +0,0 @@
-/** @file
-
- A brief file description
-
- @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.
- */
-
-/***********************************************************************
- * CfgContext.h
- *
- * Describes the CfgContext class. CfgContext has file name and set of Ele's
- ***********************************************************************/
-
-#ifndef _CFG_CONTEXT_IMPL_H_
-#define _CFG_CONTEXT_IMPL_H_
-
-#include "mgmtapi.h"
-#include "CfgContextDefs.h"
-#include "GenericParser.h" /* use for TokenList */
-
-#include "ts/List.h"
-
-/**********************************************************************
- * CfgEleObj
- *
- * abstract base class; basic element in a CfgContext
- **********************************************************************/
-class CfgEleObj
-{
-public:
- /* Each subclass must provide two constructors:
- using INK<file>Ele or a TokenList */
-
- virtual ~CfgEleObj() {} // virtual destructor
- virtual char *formatEleToRule() = 0;
- virtual bool isValid() = 0;
-
- /* these are implemented as inline functons by subclasses */
- virtual TSCfgEle *getCfgEle() = 0; /* returns actual ele */
- virtual TSCfgEle *getCfgEleCopy() = 0; /* returns copy of ele */
- virtual TSRuleTypeT getRuleType() = 0;
-
- LINK(CfgEleObj, link);
-
-protected:
- bool m_valid; /* stores if Ele has valid fields; by default true */
-};
-
-/********************************************************************
- * Ele Subclasses
- ********************************************************************/
-/* Each subclass can be constructed from a TokenList (creates the Ele)
- * or from passing in the Ele itself. Typically, objects with dynamically
- * allocated memory should also have a copy constructor and an
- * overloaded assignment operator. However, sine these subclasses function
- * more as wrappers for the C based Ele structs, we only require that
- * each subclass implements a function which returns a dynamic copy of
- * its m_ele data member
- */
-
-/* CommentEle */
-class CommentObj : public CfgEleObj
-{
-public:
- CommentObj(char *comment);
- ~CommentObj();
-
- virtual char *formatEleToRule();
- virtual bool isValid();
- virtual TSCfgEle *getCfgEleCopy();
- virtual TSCfgEle *
- getCfgEle()
- {
- return (TSCfgEle *)m_ele;
- }
- virtual TSRuleTypeT
- getRuleType()
- {
- return m_ele->cfg_ele.type;
- }
-
-private:
- INKCommentEle *m_ele;
-};
-
-/* cache.config ***************************************************/
-class CacheObj : public CfgEleObj
-{
-public:
- CacheObj(TSCacheEle *ele);
- CacheObj(TokenList *tokens); // creates the ele
- ~CacheObj();
-
- virtual char *formatEleToRule();
- virtual bool isValid();
- virtual TSCfgEle *getCfgEleCopy();
- virtual TSCfgEle *
- getCfgEle()
- {
- return (TSCfgEle *)m_ele;
- }
- virtual TSRuleTypeT
- getRuleType()
- {
- return m_ele->cfg_ele.type;
- }
-
-private:
- TSCacheEle *m_ele;
-};
-
-/* congestion.config ***************************************************/
-class CongestionObj : public CfgEleObj
-{
-public:
- CongestionObj(TSCongestionEle *ele);
- CongestionObj(TokenList *tokens); // creates the ele
- ~CongestionObj();
-
- virtual char *formatEleToRule();
- virtual bool isValid();
- virtual TSCfgEle *getCfgEleCopy();
- virtual TSCfgEle *
- getCfgEle()
- {
- return (TSCfgEle *)m_ele;
- }
- virtual TSRuleTypeT
- getRuleType()
- {
- return m_ele->cfg_ele.type;
- }
-
-private:
- TSCongestionEle *m_ele;
-};
-
-/* hosting.config ************************************************/
-class HostingObj : public CfgEleObj
-{
-public:
- HostingObj(TSHostingEle *ele);
- HostingObj(TokenList *tokens); // creates the ele
- ~HostingObj();
-
- virtual char *formatEleToRule();
- virtual bool isValid();
- virtual TSCfgEle *getCfgEleCopy();
- virtual TSCfgEle *
- getCfgEle()
- {
- return (TSCfgEle *)m_ele;
- }
- virtual TSRuleTypeT
- getRuleType()
- {
- return m_ele->cfg_ele.type;
- }
-
-private:
- TSHostingEle *m_ele;
-};
-
-/* ip_allow.config *********************************************/
-class IpAllowObj : public CfgEleObj
-{
-public:
- IpAllowObj(TSIpAllowEle *ele);
- IpAllowObj(TokenList *tokens);
- ~IpAllowObj();
-
- virtual char *formatEleToRule();
- virtual bool isValid();
- virtual TSCfgEle *getCfgEleCopy();
- virtual TSCfgEle *
- getCfgEle()
- {
- return (TSCfgEle *)m_ele;
- }
- virtual TSRuleTypeT
- getRuleType()
- {
- return m_ele->cfg_ele.type;
- }
-
-private:
- TSIpAllowEle *m_ele;
-};
-
-/* parent.config *******************************************/
-class ParentProxyObj : public CfgEleObj
-{
-public:
- ParentProxyObj(TSParentProxyEle *ele);
- ParentProxyObj(TokenList *tokens);
- ~ParentProxyObj();
-
- virtual char *formatEleToRule();
- virtual bool isValid();
- virtual TSCfgEle *getCfgEleCopy();
- virtual TSCfgEle *
- getCfgEle()
- {
- return (TSCfgEle *)m_ele;
- }
- virtual TSRuleTypeT
- getRuleType()
- {
- return m_ele->cfg_ele.type;
- }
-
-private:
- TSParentProxyEle *m_ele;
-};
-
-/* volume.config *******************************************/
-class VolumeObj : public CfgEleObj
-{
-public:
- VolumeObj(TSVolumeEle *ele);
- VolumeObj(TokenList *tokens);
- ~VolumeObj();
-
- virtual char *formatEleToRule();
- virtual bool isValid();
- virtual TSCfgEle *getCfgEleCopy();
- virtual TSCfgEle *
- getCfgEle()
- {
- return (TSCfgEle *)m_ele;
- }
- virtual TSRuleTypeT
- getRuleType()
- {
- return m_ele->cfg_ele.type;
- }
-
-private:
- TSVolumeEle *m_ele;
-};
-
-/* plugin.config *******************************************/
-class PluginObj : public CfgEleObj
-{
-public:
- PluginObj(TSPluginEle *ele);
- PluginObj(TokenList *tokens);
- ~PluginObj();
-
- virtual char *formatEleToRule();
- virtual bool isValid();
- virtual TSCfgEle *getCfgEleCopy();
- virtual TSCfgEle *
- getCfgEle()
- {
- return (TSCfgEle *)m_ele;
- }
- virtual TSRuleTypeT
- getRuleType()
- {
- return m_ele->cfg_ele.type;
- }
-
-private:
- TSPluginEle *m_ele;
-};
-
-/* remap.config *******************************************/
-class RemapObj : public CfgEleObj
-{
-public:
- RemapObj(TSRemapEle *ele);
- RemapObj(TokenList *tokens);
- ~RemapObj();
-
- virtual char *formatEleToRule();
- virtual bool isValid();
- virtual TSCfgEle *getCfgEleCopy();
- virtual TSCfgEle *
- getCfgEle()
- {
- return (TSCfgEle *)m_ele;
- }
- virtual TSRuleTypeT
- getRuleType()
- {
- return m_ele->cfg_ele.type;
- }
-
-private:
- TSRemapEle *m_ele;
-};
-
-/* socks.config *******************************************/
-class SocksObj : public CfgEleObj
-{
-public:
- SocksObj(TSSocksEle *ele);
- SocksObj(TokenList *tokens);
- ~SocksObj();
-
- virtual char *formatEleToRule();
- virtual bool isValid();
- virtual TSCfgEle *getCfgEleCopy();
- virtual TSCfgEle *
- getCfgEle()
- {
- return (TSCfgEle *)m_ele;
- }
- virtual TSRuleTypeT
- getRuleType()
- {
- return m_ele->cfg_ele.type;
- }
-
-private:
- TSSocksEle *m_ele;
-};
-
-/* splitdns.config *******************************************/
-class SplitDnsObj : public CfgEleObj
-{
-public:
- SplitDnsObj(TSSplitDnsEle *ele);
- SplitDnsObj(TokenList *tokens);
- ~SplitDnsObj();
-
- virtual char *formatEleToRule();
- virtual bool isValid();
- virtual TSCfgEle *getCfgEleCopy();
- virtual TSCfgEle *
- getCfgEle()
- {
- return (TSCfgEle *)m_ele;
- }
- virtual TSRuleTypeT
- getRuleType()
- {
- return m_ele->cfg_ele.type;
- }
-
-private:
- TSSplitDnsEle *m_ele;
-};
-
-/* storage.config *******************************************/
-class StorageObj : public CfgEleObj
-{
-public:
- StorageObj(TSStorageEle *ele);
- StorageObj(TokenList *tokens);
- ~StorageObj();
-
- virtual char *formatEleToRule();
- virtual bool isValid();
- virtual TSCfgEle *getCfgEleCopy();
- virtual TSCfgEle *
- getCfgEle()
- {
- return (TSCfgEle *)m_ele;
- }
- virtual TSRuleTypeT
- getRuleType()
- {
- return m_ele->cfg_ele.type;
- }
-
-private:
- TSStorageEle *m_ele;
-};
-
-/*****************************************************************
- * CfgContext
- *****************************************************************/
-class CfgContext
-{
-public:
- CfgContext(TSFileNameT filename);
- ~CfgContext();
-
- TSFileNameT
- getFilename()
- {
- return m_file;
- }
- int
- getVersion()
- {
- return m_ver;
- }
- void
- setVersion(int ver)
- {
- m_ver = ver;
- }
-
- CfgEleObj *
- first()
- {
- return m_eles.head;
- }
- CfgEleObj *
- next(CfgEleObj *here)
- {
- return (here->link).next;
- }
-
- TSMgmtError addEle(CfgEleObj *ele); /* enqueue EleObj at end of Queue */
- TSMgmtError removeEle(CfgEleObj *ele);
- TSMgmtError insertEle(CfgEleObj *ele, CfgEleObj *after_ele);
- TSMgmtError pushEle(CfgEleObj *ele);
-
-private:
- TSFileNameT m_file;
- int m_ver; /* version of the file read */
- Queue<CfgEleObj> m_eles;
-};
-
-#endif
diff --git a/mgmt/api/CfgContextUtils.cc b/mgmt/api/CfgContextUtils.cc
deleted file mode 100644
index 54d3ca1..0000000
--- a/mgmt/api/CfgContextUtils.cc
+++ /dev/null
@@ -1,2756 +0,0 @@
-/** @file
-
- A brief file description
-
- @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 "ts/ink_platform.h"
-#include "ts/ParseRules.h"
-#include "ts/ink_string.h"
-#include "CfgContextUtils.h"
-#include "ts/Tokenizer.h"
-/***************************************************************************
- * Conversion Functions
- ***************************************************************************/
-/* ---------------------------------------------------------------------------
- * string_to_ip_addr_ele
- * ---------------------------------------------------------------------------
- * Converts ip address string format to an TSIpAddrEle.
- * Determines if single/range, cidr/not-cidr based on format of string.
- *
- * if SINGLE = ip_a/cidr_a
- * if RANGE = ip_a/cidr_a-ip_b/cidr_b (possible to have spaces next to dash)
- * Returns NULL if invalid ele (eg. if ip's are invalid)
- */
-TSIpAddrEle *
-string_to_ip_addr_ele(const char *str)
-{
- Tokenizer range_tokens(RANGE_DELIMITER_STR);
- Tokenizer cidr_tokens(CIDR_DELIMITER_STR);
- Tokenizer cidr_tokens2(CIDR_DELIMITER_STR);
- TSIpAddrEle *ele;
- const char *const_ip_a, *const_ip_b;
- char *ip_a = nullptr, *ip_b = nullptr;
- int numTokens = 0;
- char buf[MAX_BUF_SIZE];
-
- // ink_assert(str);
- if (!str) {
- return nullptr;
- }
-
- ele = TSIpAddrEleCreate();
- if (!ele) {
- return nullptr;
- }
-
- memset(buf, 0, MAX_BUF_SIZE);
- snprintf(buf, sizeof(buf), "%s", str);
-
- // determine if range or single type
- range_tokens.Initialize(buf, COPY_TOKS);
- numTokens = range_tokens.count();
- if (numTokens == 1) { // SINGLE TYPE
- ele->type = TS_IP_SINGLE;
- // determine if cidr type
- cidr_tokens.Initialize(buf, COPY_TOKS);
- numTokens = cidr_tokens.count();
- if (numTokens == 1) { // Single, NON-CIDR TYPE
- ele->ip_a = string_to_ip_addr(str);
- } else { // Single, CIDR TYPE
- if (!isNumber(cidr_tokens[1])) {
- goto Lerror;
- }
- ele->ip_a = string_to_ip_addr(cidr_tokens[0]);
- ele->cidr_a = ink_atoi(cidr_tokens[1]);
- }
- if (!ele->ip_a) { // ERROR: Invalid ip
- goto Lerror;
- }
- } else { // RANGE TYPE
- ele->type = TS_IP_RANGE;
- const_ip_a = range_tokens[0];
- const_ip_b = range_tokens[1];
- ip_a = ats_strdup(const_ip_a);
- ip_b = ats_strdup(const_ip_b);
-
- // determine if ip's are cidr type; only test if ip_a is cidr, assume both are same
- cidr_tokens.Initialize(ip_a, COPY_TOKS);
- numTokens = cidr_tokens.count();
- if (numTokens == 1) { // Range, NON-CIDR TYPE
- ele->ip_a = string_to_ip_addr(ip_a);
- ele->ip_b = string_to_ip_addr(ip_b);
- } else { // Range, CIDR TYPE */
- ele->ip_a = string_to_ip_addr(cidr_tokens[0]);
- ele->cidr_a = ink_atoi(cidr_tokens[1]);
- cidr_tokens2.Initialize(ip_b, COPY_TOKS);
- ele->ip_b = string_to_ip_addr(cidr_tokens2[0]);
- ele->cidr_b = ink_atoi(cidr_tokens2[1]);
- if (!isNumber(cidr_tokens[1]) || !isNumber(cidr_tokens2[1])) {
- goto Lerror;
- }
- }
- if (!ele->ip_a || !ele->ip_b) { // ERROR: invalid IP
- goto Lerror;
- }
- }
-
- ats_free(ip_a);
- ats_free(ip_b);
- return ele;
-
-Lerror:
- ats_free(ip_a);
- ats_free(ip_b);
- TSIpAddrEleDestroy(ele);
-
- return nullptr;
-}
-
-/* ----------------------------------------------------------------------------
- * ip_addr_ele_to_string
- * ---------------------------------------------------------------------------
- * Converts an TSIpAddrEle to following string format:
- * Output:
- * if SINGLE = ip_a/cidr_a
- * if RANGE = ip_a/cidr_a-ip_b/cidr_b
- * If there is no cidr = ip_a-ip_b
- * Returns NULL if invalid ele (needs to check that the ip's are valid too)
- */
-char *
-ip_addr_ele_to_string(TSIpAddrEle *ele)
-{
- char buf[MAX_BUF_SIZE];
- char *str, *ip_a_str = nullptr, *ip_b_str = nullptr;
-
- // ink_assert(ele);
- if (!ele) {
- goto Lerror;
- }
-
- memset(buf, 0, MAX_BUF_SIZE);
-
- if (ele->ip_a == TS_INVALID_IP_ADDR) {
- goto Lerror; // invalid ip_addr
- }
-
- if (ele->type == TS_IP_SINGLE) { // SINGLE TYPE
- ip_a_str = ip_addr_to_string(ele->ip_a);
- if (!ip_a_str) { // ERROR: invalid IP address
- goto Lerror;
- }
- if (ele->cidr_a != TS_INVALID_IP_CIDR) { // a cidr type
- snprintf(buf, sizeof(buf), "%s%c%d", ip_a_str, CIDR_DELIMITER, ele->cidr_a);
- } else { // not cidr type
- snprintf(buf, sizeof(buf), "%s", ip_a_str);
- }
-
- ats_free(ip_a_str);
- str = ats_strdup(buf);
-
- return str;
- } else if (ele->type == TS_IP_RANGE) { // RANGE TYPE
- ip_a_str = ip_addr_to_string(ele->ip_a);
- ip_b_str = ip_addr_to_string(ele->ip_b);
-
- if (!ip_a_str || !ip_b_str) {
- goto Lerror;
- }
-
- if (ele->cidr_a != TS_INVALID_IP_CIDR && ele->cidr_b != TS_INVALID_IP_CIDR) {
- // a cidr type
- snprintf(buf, sizeof(buf), "%s%c%d%c%s%c%d", ip_a_str, CIDR_DELIMITER, ele->cidr_a, RANGE_DELIMITER, ip_b_str, CIDR_DELIMITER,
- ele->cidr_b);
- } else { // not cidr type
- snprintf(buf, sizeof(buf), "%s%c%s", ip_a_str, RANGE_DELIMITER, ip_b_str);
- }
- ats_free(ip_a_str);
- ats_free(ip_b_str);
- str = ats_strdup(buf);
-
- return str;
- }
-
-Lerror:
- ats_free(ip_a_str);
- ats_free(ip_b_str);
- return nullptr;
-}
-
-/* ----------------------------------------------------------------------------
- * ip_addr_to_string
- * ---------------------------------------------------------------------------
- * Converts an TSIpAddr (char*) to dotted decimal string notation. Allocates
- * memory for the new TSIpAddr.
- * Returns NULL if invalid TSIpAddr
- */
-char *
-ip_addr_to_string(TSIpAddr ip)
-{
- // ink_assert(ip != TS_INVALID_IP_ADDR);
- if (ip == TS_INVALID_IP_ADDR) {
- return nullptr;
- }
- if (!ccu_checkIpAddr(ip)) {
- return nullptr;
- }
- return ats_strdup((char *)ip);
-}
-
-/* ----------------------------------------------------------------------------
- * string_to_ip_addr
- * ---------------------------------------------------------------------------
- * Converts an ip address in dotted-decimal string format into a string;
- * allocates memory for string. If IP is invalid, then returns TS_INVALID_IP_ADDR.
- */
-TSIpAddr
-string_to_ip_addr(const char *str)
-{
- // ink_assert(str);
- if (!ccu_checkIpAddr(str)) {
- return TS_INVALID_IP_ADDR;
- }
-
- char *copy;
- copy = ats_strdup(str);
- return (TSIpAddr)copy;
-}
-
-/* ---------------------------------------------------------------
- * ip_addr_list_to_string
- * ---------------------------------------------------------------
- * converts TSIpAddrList <==> ip_addr1<delim>ip_addr2<delim>ip_addr3, ...
- * Returns TSIpAddrList with original elements.
- * If encounters invalid TSIpAddrEle, returns NULL.
- */
-char *
-ip_addr_list_to_string(IpAddrList *list, const char *delimiter)
-{
- char buf[MAX_BUF_SIZE];
- int buf_pos = 0;
- TSIpAddrEle *ip_ele;
- char *ip_str, *new_str;
- int num, i;
-
- // ink_assert(list && delimiter);
- if (!list || !delimiter) {
- return nullptr;
- }
-
- num = queue_len((LLQ *)list);
-
- for (i = 0; i < num; i++) {
- ip_ele = (TSIpAddrEle *)dequeue((LLQ *)list); // read next ip
- ip_str = ip_addr_ele_to_string(ip_ele);
-
- if (!ip_str) {
- enqueue((LLQ *)list, ip_ele);
- return nullptr;
- }
- if (i == num - 1) {
- snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "%s", ip_str);
- } else {
- snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "%s%s", ip_str, delimiter);
- }
- buf_pos = strlen(buf);
- ats_free(ip_str);
-
- enqueue((LLQ *)list, ip_ele); // return ip to list
- }
-
- new_str = ats_strdup(buf);
-
- return new_str;
-}
-
-/* ---------------------------------------------------------------
- * string_to_ip_addr_list
- * ---------------------------------------------------------------
- * Converts ip_addr1<delim>ip_addr2<delim>ip_addr3, ...==> TSIpAddrList
- * Does checking to make sure that each ip_addr is valid; if encounter
- * an invalid ip addr, then returns TS_INVALID_LIST
- */
-TSIpAddrList
-string_to_ip_addr_list(const char *str_list, const char *delimiter)
-{
- Tokenizer tokens(delimiter);
- int numToks, i;
- TSIpAddrList ip_list;
- TSIpAddrEle *ip_ele;
-
- // ink_assert(str_list && delimiter);
- if (!str_list || !delimiter) {
- return TS_INVALID_LIST;
- }
-
- tokens.Initialize(str_list);
- numToks = tokens.count();
-
- ip_list = TSIpAddrListCreate();
-
- for (i = 0; i < numToks; i++) {
- ip_ele = string_to_ip_addr_ele(tokens[i]);
- if (ip_ele) {
- TSIpAddrListEnqueue(ip_list, ip_ele);
- } else { // Error: invalid IP
- TSIpAddrListDestroy(ip_list);
- return TS_INVALID_LIST;
- }
- }
- return ip_list;
-}
-
-/* ---------------------------------------------------------------
- * port_list_to_string (REPLACE BY sprintf_ports)
- * ---------------------------------------------------------------
- * Purpose: prints a list of ports in a PortList into string delimited format
- * Input: ports - the queue of TSPortEle *'s.
- * Output: port_0<delim>port_1<delim>...<delim>port_n
- * (each port can refer to a port range, eg 80-90)
- * Return NULL if encounter invalid port or empty port list
- */
-char *
-port_list_to_string(PortList *ports, const char *delimiter)
-{
- int num_ports;
- size_t pos = 0;
- int i, psize;
- TSPortEle *port_ele;
- char buf[MAX_BUF_SIZE];
- char *str;
-
- // ink_assert(ports && delimiter);
- if (!ports || !delimiter) {
- goto Lerror;
- }
-
- num_ports = queue_len((LLQ *)ports);
- if (num_ports <= 0) { // no ports specified
- goto Lerror;
- }
- // now list all the ports, including ranges
- for (i = 0; i < num_ports; i++) {
- port_ele = (TSPortEle *)dequeue((LLQ *)ports);
- if (!ccu_checkPortEle(port_ele)) {
- enqueue((LLQ *)ports, port_ele); // return TSPortEle to list
- goto Lerror;
- }
-
- if (pos < sizeof(buf) && (psize = snprintf(buf + pos, sizeof(buf) - pos, "%d", port_ele->port_a)) > 0) {
- pos += psize;
- }
- if (port_ele->port_b != TS_INVALID_PORT) { //. is this a range
- // add in range delimiter & end of range
- if (pos < sizeof(buf) && (psize = snprintf(buf + pos, sizeof(buf) - pos, "%c%d", RANGE_DELIMITER, port_ele->port_b)) > 0) {
- pos += psize;
- }
- }
-
- if (i != num_ports - 1) {
- if (pos < sizeof(buf) && (psize = snprintf(buf + pos, sizeof(buf) - pos, "%s", delimiter)) > 0) {
- pos += psize;
- }
- }
-
- enqueue((LLQ *)ports, port_ele); // return TSPortEle to list
- }
-
- str = ats_strdup(buf);
- return str;
-
-Lerror:
- return nullptr;
-}
-
-/* ---------------------------------------------------------------
- * string_to_port_list
- * ---------------------------------------------------------------
- * Converts port1<delim>port2<delim>port3, ...==> TSPortList
- * Does checking to make sure that each ip_addr is valid; if encounter
- * an invalid ip addr, then returns TST_INVALID_LIST
- */
-TSPortList
-string_to_port_list(const char *str_list, const char *delimiter)
-{
- Tokenizer tokens(delimiter);
- int numToks, i;
- TSPortList port_list;
- TSPortEle *port_ele;
-
- // ink_assert(str_list && delimiter);
- if (!str_list || !delimiter) {
- return TS_INVALID_LIST;
- }
-
- tokens.Initialize(str_list);
-
- numToks = tokens.count();
-
- port_list = TSPortListCreate();
-
- for (i = 0; i < numToks; i++) {
- port_ele = string_to_port_ele(tokens[i]);
- if (port_ele) {
- TSPortListEnqueue(port_list, port_ele);
- } else { // error - invalid port ele
- TSPortListDestroy(port_list);
- return TS_INVALID_LIST;
- }
- }
-
- return port_list;
-}
-
-/* ---------------------------------------------------------------------------
- * port_ele_to_string
- * ---------------------------------------------------------------------------
- * Converts a port_ele to string format: <port_a> or <port_a>-<port_b>
- * Returns NULL if invalid PortEle
- */
-char *
-port_ele_to_string(TSPortEle *ele)
-{
- char buf[MAX_BUF_SIZE];
- char *str;
-
- // ink_assert(ele);
- if (!ele || !ccu_checkPortEle(ele)) {
- return nullptr;
- }
-
- memset(buf, 0, MAX_BUF_SIZE);
-
- if (ele->port_b == TS_INVALID_PORT) { // Not a range
- snprintf(buf, sizeof(buf), "%d", ele->port_a);
- } else {
- snprintf(buf, sizeof(buf), "%d%c%d", ele->port_a, RANGE_DELIMITER, ele->port_b);
- }
-
- str = ats_strdup(buf);
- return str;
-}
-
-/*----------------------------------------------------------------------------
- * string_to_port_ele
- *---------------------------------------------------------------------------
- * Converts a string formatted port_ele into actual port_ele. Returns NULL if
- * invalid port(s). It is okay to have a single port specified.
- */
-TSPortEle *
-string_to_port_ele(const char *str)
-{
- Tokenizer tokens(RANGE_DELIMITER_STR);
- TSPortEle *ele;
- char copy[MAX_BUF_SIZE];
-
- // ink_assert(str);
- if (!str) {
- return nullptr;
- }
-
- memset(copy, 0, MAX_BUF_SIZE);
- snprintf(copy, sizeof(copy), "%s", str);
-
- ele = TSPortEleCreate();
- if (tokens.Initialize(copy, COPY_TOKS) > 2) {
- goto Lerror;
- }
- if (tokens.count() == 1) { // Not a Range of ports
- if (!isNumber(str)) {
- goto Lerror;
- }
- ele->port_a = ink_atoi(str);
- } else {
- if (!isNumber(tokens[0]) || !isNumber(tokens[1])) {
- goto Lerror;
- }
- ele->port_a = ink_atoi(tokens[0]);
- ele->port_b = ink_atoi(tokens[1]);
- }
-
- if (!ccu_checkPortEle(ele)) {
- goto Lerror;
- }
-
- return ele;
-
-Lerror:
- TSPortEleDestroy(ele);
- return nullptr;
-}
-
-/*----------------------------------------------------------------------------
- * string_list_to_string
- *----------------------------------------------------------------------------
- * Converts str list to delimited string. Does not alter the
- * StringList passed in.
- * eg. str1<delim>str2<delim>str3...
- */
-char *
-string_list_to_string(TSStringList str_list, const char *delimiter)
-{
- char buf[MAX_BUF_SIZE];
- size_t buf_pos = 0;
- int i, numElems, psize;
- char *str_ele, *list_str;
-
- // ink_assert(str_list != TS_INVALID_LIST && delimiter);
- if (str_list == TS_INVALID_LIST || !delimiter) {
- return nullptr;
- }
-
- memset(buf, 0, MAX_BUF_SIZE);
- numElems = queue_len((LLQ *)str_list);
- for (i = 0; i < numElems; i++) {
- str_ele = (char *)dequeue((LLQ *)str_list);
-
- if (i == numElems - 1) { // the last element shouldn't print comma
- if (buf_pos < sizeof(buf) && (psize = snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "%s", str_ele)) > 0) {
- buf_pos += psize;
- }
- } else {
- if (buf_pos < sizeof(buf) && (psize = snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "%s%s", str_ele, delimiter)) > 0) {
- buf_pos += psize;
- }
- }
-
- enqueue((LLQ *)str_list, str_ele);
- }
-
- list_str = ats_strdup(buf);
- return list_str;
-}
-
-/* ---------------------------------------------------------------
- * string_to_string_list
- * ---------------------------------------------------------------
- * Converts port1<delim>port2<delim>port3, ...==> TSStringList
- * Does checking to make sure that each ip_addr is valid; if encounter
- * an invalid ip addr, then returns INVALID_HANDLE
- */
-TSStringList
-string_to_string_list(const char *str, const char *delimiter)
-{
- Tokenizer tokens(delimiter);
- tokens.Initialize(str);
-
- // ink_assert(str && delimiter);
- if (!str || !delimiter) {
- return TS_INVALID_LIST;
- }
-
- TSStringList str_list = TSStringListCreate();
- for (unsigned i = 0; i < tokens.count(); i++) {
- TSStringListEnqueue(str_list, ats_strdup(tokens[i]));
- }
-
- return str_list;
-}
-
-/*----------------------------------------------------------------------------
- * int_list_to_string
- *----------------------------------------------------------------------------
- * TSList(of char*'s only)==> elem1<delimiter>elem2<delimiter>elem3<delimiter>
- * Note: the string always ends with the delimiter
- * The list and its elements are not changed in any way.
- * Returns NULL if error.
- */
-char *
-int_list_to_string(TSIntList list, const char *delimiter)
-{
- char buf[MAX_BUF_SIZE];
- size_t buf_pos = 0;
- int numElems, i, psize;
- int *elem;
-
- // ink_assert(list != TS_INVALID_LIST && delimiter);
- if (list == TS_INVALID_LIST || !delimiter) {
- return nullptr;
- }
-
- numElems = queue_len((LLQ *)list);
-
- memset(buf, 0, MAX_BUF_SIZE);
- for (i = 0; i < numElems; i++) {
- elem = (int *)dequeue((LLQ *)list);
- if (i == numElems - 1) {
- if (buf_pos < sizeof(buf) && (psize = snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "%d", *elem)) > 0) {
- buf_pos += psize;
- }
- } else {
- if (buf_pos < sizeof(buf) && (psize = snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "%d%s", *elem, delimiter)) > 0) {
- buf_pos += psize;
- }
- }
- enqueue((LLQ *)list, elem);
- }
- return ats_strdup(buf);
-}
-
-/* ---------------------------------------------------------------
- * string_to_int_list
- * ---------------------------------------------------------------
- * converts domain1<delim>domain2<delim>domain3, ... ==> TSList
- * Does checking to make sure that each integer is valid; if encounter
- * an invalid int, then returns TS_INVALID_LIST
- */
-TSIntList
-string_to_int_list(const char *str_list, const char *delimiter)
-{
- Tokenizer tokens(delimiter);
- int numToks, i;
- TSList list;
- int *ele;
-
- // ink_assert (str_list && delimiter);
- if (!str_list || !delimiter) {
- return TS_INVALID_LIST;
- }
-
- tokens.Initialize(str_list);
-
- numToks = tokens.count();
- list = TSIntListCreate();
-
- for (i = 0; i < numToks; i++) {
- if (!isNumber(tokens[i])) {
- goto Lerror;
- }
- ele = (int *)ats_malloc(sizeof(int));
- *ele = ink_atoi(tokens[i]); // What about we can't convert? ERROR?
- TSIntListEnqueue(list, ele);
- }
-
- return list;
-
-Lerror:
- TSIntListDestroy(list);
- return TS_INVALID_LIST;
-}
-
-/* ---------------------------------------------------------------
- * string_to_domain_list
- * ---------------------------------------------------------------
- * Converts domain1<delim>domain2<delim>domain3, ... ==> TSDomainList
- * Returns TS_INVALID_LIST if encounter an invalid Domain.
- */
-TSDomainList
-string_to_domain_list(const char *str_list, const char *delimiter)
-{
- Tokenizer tokens(delimiter);
- int numToks, i;
- TSDomainList list;
- TSDomain *ele;
-
- // ink_assert(str_list && delimiter);
- if (!str_list || !delimiter) {
- return TS_INVALID_LIST;
- }
-
- tokens.Initialize(str_list);
-
- numToks = tokens.count();
-
- list = TSDomainListCreate();
-
- for (i = 0; i < numToks; i++) {
- ele = string_to_domain(tokens[i]);
- if (ele) {
- TSDomainListEnqueue(list, ele);
- } else { // Error: invalid domain
- TSDomainListDestroy(list);
- return TS_INVALID_LIST;
- }
- }
-
- return list;
-}
-
-/*----------------------------------------------------------------------------
- * domain_list_to_string
- *----------------------------------------------------------------------------
- * TSList(of char*'s only)==> elem1<delimiter>elem2<delimiter>elem3<delimiter>
- * Note: the string always ends with the delimiter
- * The list and its elements are not changed in any way.
- * Returns NULL if encounter an invalid TSDomain.
- */
-char *
-domain_list_to_string(TSDomainList list, const char *delimiter)
-{
- char buf[MAX_BUF_SIZE];
- size_t buf_pos = 0;
- int numElems, i, psize;
- char *list_str, *dom_str;
- TSDomain *domain;
-
- // ink_assert(list != TS_INVALID_LIST && delimiter);
- if (list == TS_INVALID_LIST || !delimiter) {
- return nullptr;
- }
-
- numElems = queue_len((LLQ *)list);
-
- memset(buf, 0, MAX_BUF_SIZE);
-
- for (i = 0; i < numElems; i++) {
- domain = (TSDomain *)dequeue((LLQ *)list);
-
- dom_str = domain_to_string(domain);
- if (!dom_str) {
- return nullptr;
- }
- if (i == numElems - 1) { // the last element shouldn't print comma
- if (buf_pos < sizeof(buf) && (psize = snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "%s", dom_str)) > 0) {
- buf_pos += psize;
- }
- } else {
- if (buf_pos < sizeof(buf) && (psize = snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "%s%s", dom_str, delimiter)) > 0) {
- buf_pos += psize;
- }
- }
-
- ats_free(dom_str);
- enqueue((LLQ *)list, domain);
- }
-
- list_str = ats_strdup(buf);
- return list_str;
-}
-
-/*----------------------------------------------------------------------------
- * domain_to_string
- *----------------------------------------------------------------------------
- * Converts an TSDomain into string format, eg. www.host.com:8080
- * Return NULL if invalid TSDomain (eg. missing domain value).
- */
-char *
-domain_to_string(TSDomain *domain)
-{
- char buf[MAX_BUF_SIZE];
- char *dom_str;
-
- // ink_assert(domain);
- if (!domain) {
- return nullptr;
- }
-
- if (domain->domain_val) {
- if (domain->port != TS_INVALID_PORT) { // host:port
- snprintf(buf, sizeof(buf), "%s:%d", domain->domain_val, domain->port);
- } else { // host
- snprintf(buf, sizeof(buf), "%s", domain->domain_val);
- }
- } else {
- return nullptr; // invalid TSDomain
- }
-
- dom_str = ats_strdup(buf);
-
- return dom_str;
-}
-
-/*----------------------------------------------------------------------------
- * string_to_domain
- *----------------------------------------------------------------------------
- * Converts string format, eg. www.host.com:8080, into TSDomain.
- * The string can consist of just the host (which can be a name or an IP)
- * or of the host and port.
- * Return NULL if invalid TSDomain (eg. missing domain value).
- */
-TSDomain *
-string_to_domain(const char *str)
-{
- TSDomain *dom;
- char *token, *remain, *token_pos;
- char buf[MAX_BUF_SIZE];
-
- // ink_assert(str);
- if (!str) {
- return nullptr;
- }
-
- dom = TSDomainCreate();
-
- // get hostname
- ink_strlcpy(buf, str, sizeof(buf));
- token = strtok_r(buf, ":", &token_pos);
- remain = token_pos;
- if (token) {
- dom->domain_val = ats_strdup(token);
- } else {
- goto Lerror;
- }
-
- // get port, if exists
- if (remain) {
- // check if the "remain" consist of all integers
- if (!isNumber(remain)) {
- goto Lerror;
- }
- dom->port = ink_atoi(remain);
- } else {
- dom->port = TS_INVALID_PORT;
- }
-
- return dom;
-
-Lerror:
- TSDomainDestroy(dom);
- return nullptr;
-}
-
-/* ---------------------------------------------------------------
- * pdest_sspec_to_string
- * ---------------------------------------------------------------
- * Converts the TSPrimeDest, primary dest, secondary spec struct
- * into string format: <pdT>:pdst_val:sspec1:sspec2:...:
- * <pdT> - dest_domain, dest_host, dest_ip, url_regex
- * even if sspec is missing the delimter is included; so if no
- * sspecs, then : ::: ::: will appear
- */
-char *
-pdest_sspec_to_string(TSPrimeDestT pd, char *pd_val, TSSspec *sspec)
-{
- char buf[MAX_BUF_SIZE];
- size_t buf_pos = 0;
- int psize;
- char hour_a[3], hour_b[3], min_a[3], min_b[3];
- char *src_ip, *str;
-
- // ink_assert(pd != TS_PD_UNDEFINED && pd_val && sspec);
- if (pd == TS_PD_UNDEFINED || !pd_val || !sspec) {
- return nullptr;
- }
-
- memset(buf, 0, MAX_BUF_SIZE);
-
- do {
- // push in primary destination
- switch (pd) {
- case TS_PD_DOMAIN:
- psize = snprintf(buf, sizeof(buf), "dest_domain=%s ", pd_val);
- break;
- case TS_PD_HOST:
- psize = snprintf(buf, sizeof(buf), "dest_host=%s ", pd_val);
- break;
- case TS_PD_IP:
- psize = snprintf(buf, sizeof(buf), "dest_ip=%s ", pd_val);
- break;
- case TS_PD_URL_REGEX:
- psize = snprintf(buf, sizeof(buf), "url_regex=%s ", pd_val);
- break;
- case TS_PD_URL:
- psize = snprintf(buf, sizeof(buf), "url=%s ", pd_val);
- break;
- default:
- psize = 0;
- // Handled here:
- // TS_PD_UNDEFINED
- break;
- }
- if (psize > 0) {
- buf_pos += psize;
- }
- if (buf_pos + 1 >= sizeof(buf)) {
- break;
- }
-
- // if there are secondary specifiers
- if (sspec) {
- // convert the time into a string, eg. 8 to "08"
- if (sspec->time.hour_a == 0) {
- snprintf(hour_a, sizeof(hour_a), "00");
- } else {
- if (sspec->time.hour_a < 10) {
- snprintf(hour_a, sizeof(hour_a), "0%d", sspec->time.hour_a);
- } else {
- snprintf(hour_a, sizeof(hour_a), "%d", sspec->time.hour_a);
- }
- }
- if (sspec->time.min_a == 0) {
- snprintf(min_a, sizeof(min_a), "00");
- } else {
- if (sspec->time.min_a < 10) {
- snprintf(min_a, sizeof(min_a), "0%d", sspec->time.min_a);
- } else {
- snprintf(min_a, sizeof(min_a), "%d", sspec->time.min_a);
- }
- }
- if (sspec->time.hour_b == 0) {
- snprintf(hour_b, sizeof(hour_b), "00");
- } else {
- if (sspec->time.hour_b < 10) {
- snprintf(hour_b, sizeof(hour_b), "0%d", sspec->time.hour_b);
- } else {
- snprintf(hour_b, sizeof(hour_b), "%d", sspec->time.hour_b);
- }
- }
- if (sspec->time.min_b == 0) {
- snprintf(min_b, sizeof(min_b), "00");
- } else {
- if (sspec->time.min_b < 10) {
- snprintf(min_b, sizeof(min_b), "0%d", sspec->time.min_b);
- } else {
- snprintf(min_b, sizeof(min_b), "%d", sspec->time.min_b);
- }
- }
-
- if (!(sspec->time.hour_a == 0 && sspec->time.min_a == 0 && sspec->time.hour_b == 0 && sspec->time.min_b == 0)) {
- // time is specified
- if (buf_pos < sizeof(buf) &&
- (psize = snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "time=%s:%s-%s:%s ", hour_a, min_a, hour_b, min_b)) > 0) {
- buf_pos += psize;
- }
- }
- // src_ip
- if (sspec->src_ip != TS_INVALID_IP_ADDR) {
- src_ip = ip_addr_to_string(sspec->src_ip);
- if (!src_ip) {
- return nullptr;
- }
- if (buf_pos < sizeof(buf) && (psize = snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "src_ip=%s ", src_ip)) > 0) {
- buf_pos += psize;
- }
- ats_free(src_ip);
- }
- // prefix?
- if (sspec->prefix) {
- if (buf_pos < sizeof(buf) && (psize = snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "prefix=%s ", sspec->prefix)) > 0) {
- buf_pos += psize;
- }
- }
- // suffix?
- if (sspec->suffix) {
- if (buf_pos < sizeof(buf) && (psize = snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "suffix=%s ", sspec->suffix)) > 0) {
- buf_pos += psize;
- }
- }
- // port?
- if (sspec->port) {
- char *portStr = port_ele_to_string(sspec->port);
- if (portStr) {
- if (buf_pos < sizeof(buf) && (psize = snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "port=%s ", portStr)) > 0) {
- buf_pos += psize;
- }
- ats_free(portStr);
- }
- }
- // method
- if (buf_pos < sizeof(buf)) {
- switch (sspec->method) {
- case TS_METHOD_GET:
- psize = snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "method=get ");
- break;
- case TS_METHOD_POST:
- psize = snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "method=post ");
- break;
- case TS_METHOD_PUT:
- psize = snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "method=put ");
- break;
- case TS_METHOD_TRACE:
- psize = snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "method=trace ");
- break;
- case TS_METHOD_PUSH:
- psize = snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "method=PUSH ");
- break;
- default:
- psize = 0;
- break;
- }
- if (psize > 0) {
- buf_pos += psize;
- }
- } else {
- break;
- }
-
- // scheme
- if (buf_pos < sizeof(buf)) {
- switch (sspec->scheme) {
- case TS_SCHEME_NONE:
- snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "%c", DELIMITER);
- break;
- case TS_SCHEME_HTTP:
- snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "scheme=http ");
- break;
- case TS_SCHEME_HTTPS:
- snprintf(buf + buf_pos, sizeof(buf) - buf_pos, "scheme=https ");
- break;
- default:
- break;
- }
- }
- }
- } while (false);
-
- str = ats_strdup(buf);
- return str;
-}
-
-/*----------------------------------------------------------------------------
- * string_to_pdss_format
- *----------------------------------------------------------------------------
- * <pd_type>#<pd_value>#<sspecs> --> TSPdSsFormat
- * NOTE that the entire data line, including the action type is being passed in
- */
-TSMgmtError
-string_to_pdss_format(const char *str, TSPdSsFormat *pdss)
-{
- Tokenizer tokens(DELIMITER_STR);
- Tokenizer time_tokens(":-");
- char copy[MAX_BUF_SIZE];
-
- // ink_assert(str && pdss);
- if (!str || !pdss) {
- return TS_ERR_PARAMS;
- }
-
- memset(copy, 0, MAX_BUF_SIZE);
- snprintf(copy, sizeof(copy), "%s", str);
-
- tokens.Initialize(copy, ALLOW_EMPTY_TOKS);
-
- // pd type
- if (strcmp(tokens[1], "dest_domain") == 0) {
- pdss->pd_type = TS_PD_DOMAIN;
- } else if (strcmp(tokens[1], "dest_host") == 0) {
- pdss->pd_type = TS_PD_HOST;
- } else if (strcmp(tokens[1], "dest_ip") == 0) {
- pdss->pd_type = TS_PD_IP;
- } else if (strcmp(tokens[1], "url_regex") == 0) {
- pdss->pd_type = TS_PD_URL_REGEX;
- } else if (strcmp(tokens[1], "url") == 0) {
- pdss->pd_type = TS_PD_URL;
- } else {
- goto Lerror;
- }
-
- // pd_value
- if (!tokens[2]) {
- goto Lerror;
- }
- pdss->pd_val = ats_strdup(tokens[2]);
-
- // check secondary specifiers; exists only if not empty string
- // time
- if (strlen(tokens[3]) > 0) {
- if (string_to_time_struct(tokens[3], &(pdss->sec_spec)) != TS_ERR_OKAY) {
- goto Lerror;
- }
- }
- // src_ip
- if (strlen(tokens[4]) > 0) {
- pdss->sec_spec.src_ip = ats_strdup(tokens[4]);
- }
- // prefix
- if (strlen(tokens[5]) > 0) {
- pdss->sec_spec.prefix = ats_strdup(tokens[5]);
- }
- // suffix
- if (strlen(tokens[6]) > 0) {
- pdss->sec_spec.suffix = ats_strdup(tokens[6]);
- }
- // port
- if (strlen(tokens[7]) > 0) { // no port
- pdss->sec_spec.port = string_to_port_ele(tokens[7]);
- }
- // method
- if (strlen(tokens[8]) > 0) {
- pdss->sec_spec.method = string_to_method_type(tokens[8]);
- }
- // scheme
- if (strlen(tokens[9]) > 0) {
- pdss->sec_spec.scheme = string_to_scheme_type(tokens[9]);
- }
- return TS_ERR_OKAY;
-
-Lerror:
- return TS_ERR_FAIL;
-}
-
-/*----------------------------------------------------------------------------
- * hms_time_to_string
- *----------------------------------------------------------------------------
- * Converts an TSHmsTime structure to string format: eg. 5h15m20s
- */
-char *
-hms_time_to_string(TSHmsTime time)
-{
- char buf[MAX_BUF_SIZE];
- size_t s;
-
- s = snprintf(buf, sizeof(buf), "%dd%dh%dm%ds", time.d, time.h, time.m, time.s);
-
- if ((s > 0) && (s < sizeof(buf))) {
- return ats_strdup(buf);
- } else {
- return nullptr;
- }
-}
-
-/*----------------------------------------------------------------------------
- * string_to_hms_time
- *----------------------------------------------------------------------------
- * Convert ?d?h?m?s ==> TSHmsTime
- * Returns TS_ERR_FAIL if invalid hms format, eg. if there are invalid
- * characters, eg. "10xh", "10h15m30s34", or repeated values, eg. "10h15h"
- */
-TSMgmtError
-string_to_hms_time(const char *str, TSHmsTime *time)
-{
- int i, pos = 0;
- int len;
- char unit[10];
- bool valid = false;
-
- // ink_assert(str && time);
- if (!str || !time) {
- return TS_ERR_PARAMS;
- }
-
- memset(unit, 0, 10);
- len = strlen(str);
- time->d = time->h = time->m = time->s = 0;
- for (i = 0; i < len; i++) {
- valid = false;
- if ((*str) == 'd') {
- if (time->d > 0 || !isNumber(unit)) {
- goto Lerror;
- }
- time->d = ink_atoi(unit);
- memset(unit, 0, 10);
- pos = 0;
- valid = true;
- } else if ((*str) == 'h') {
- if (time->h > 0 || !isNumber(unit)) {
- goto Lerror;
- }
- time->h = ink_atoi(unit);
- memset(unit, 0, 10);
- pos = 0;
- valid = true;
- } else if ((*str) == 'm') {
- if (time->m > 0 || !isNumber(unit)) {
- goto Lerror;
- }
- time->m = ink_atoi(unit);
- memset(unit, 0, 10);
- pos = 0;
- valid = true;
- } else if ((*str) == 's') {
- if (time->s > 0 || !isNumber(unit)) {
- goto Lerror;
- }
- time->s = ink_atoi(unit);
- memset(unit, 0, 10);
- pos = 0;
- valid = true;
- } else {
- unit[pos] = *str;
- pos++;
- }
-
- ++str;
- }
-
- if (!valid) {
- goto Lerror;
- }
- return TS_ERR_OKAY;
-
-Lerror:
- return TS_ERR_FAIL;
-}
-
-/*----------------------------------------------------------------------------
- * string_to_time_struct
- *----------------------------------------------------------------------------
- * convert string "09:00-23:00" to time struct
- * struct {
- * int hour_a;
- * int min_a;
- * int hour_b;
- * int min_b;
- * } time
- * Returns TS_ERR_FAIL if invalid time string.
- */
-TSMgmtError
-string_to_time_struct(const char *str, TSSspec *sspec)
-{
- Tokenizer time_tokens(":-");
-
- if (time_tokens.Initialize(str) != 4) {
- return TS_ERR_FAIL;
- }
-
- if (strcmp(time_tokens[0], "00") == 0) {
- sspec->time.hour_a = 0;
- } else {
- if (!isNumber(time_tokens[0])) {
- goto Lerror;
- }
- sspec->time.hour_a = ink_atoi(time_tokens[0]);
- }
- if (strcmp(time_tokens[1], "00") == 0) {
- sspec->time.min_a = 0;
- } else {
- if (!isNumber(time_tokens[1])) {
- goto Lerror;
- }
- sspec->time.min_a = ink_atoi(time_tokens[1]);
- }
- if (strcmp(time_tokens[2], "00") == 0) {
- sspec->time.hour_b = 0;
- } else {
- if (!isNumber(time_tokens[2])) {
- goto Lerror;
- }
- sspec->time.hour_b = ink_atoi(time_tokens[2]);
- }
- if (strcmp(time_tokens[3], "00") == 0) {
- sspec->time.min_b = 0;
- } else {
- if (!isNumber(time_tokens[3])) {
- goto Lerror;
- }
- sspec->time.min_b = ink_atoi(time_tokens[3]);
- }
-
- // check valid time values
- if (!ccu_checkTimePeriod(sspec)) {
- goto Lerror;
- }
-
- return TS_ERR_OKAY;
-
-Lerror:
- return TS_ERR_FAIL;
-}
-
-/*----------------------------------------------------------------------------
- * string_to_header_type
- *----------------------------------------------------------------------------
- * string ==> TSHdrT
- */
-TSHdrT
-string_to_header_type(const char *str)
-{
- // ink_assert(str);
- if (!str) {
- return TS_HDR_UNDEFINED;
- }
-
- if (strcmp(str, "date") == 0) {
- return TS_HDR_DATE;
- } else if (strcmp(str, "host") == 0) {
- return TS_HDR_HOST;
- } else if (strcmp(str, "cookie") == 0) {
- return TS_HDR_COOKIE;
- } else if (strcmp(str, "client_ip") == 0) {
- return TS_HDR_CLIENT_IP;
- }
-
- return TS_HDR_UNDEFINED;
-}
-
-char *
-header_type_to_string(TSHdrT hdr)
-{
- // header type
- switch (hdr) {
- case TS_HDR_DATE:
- return ats_strdup("date");
- case TS_HDR_HOST:
- return ats_strdup("host");
- case TS_HDR_COOKIE:
- return ats_strdup("cookie");
- case TS_HDR_CLIENT_IP:
- return ats_strdup("client_ip");
- default:
- break;
- }
-
- return nullptr;
-}
-
-/*----------------------------------------------------------------------------
- * string_to_scheme_type
- *----------------------------------------------------------------------------
- * converts scheme string into a TSSchemeT type
- */
-TSSchemeT
-string_to_scheme_type(const char *scheme)
-{
- if (strcasecmp(scheme, "http") == 0) {
- return TS_SCHEME_HTTP;
- } else if (strcasecmp(scheme, "https") == 0) {
- return TS_SCHEME_HTTPS;
- }
- return TS_SCHEME_UNDEFINED;
-}
-
-char *
-scheme_type_to_string(TSSchemeT scheme)
-{
- switch (scheme) {
- case TS_SCHEME_HTTP:
- return ats_strdup("http");
- case TS_SCHEME_HTTPS:
- return ats_strdup("https");
- default:
- break;
- }
-
- return nullptr;
-}
-
-/*----------------------------------------------------------------------------
- * string_to_method_type
- *----------------------------------------------------------------------------
- * converts scheme string into a TSSchemeT type
- */
-TSMethodT
-string_to_method_type(const char *method)
-{
- if (strcasecmp(method, "get") == 0) {
- return TS_METHOD_GET;
- } else if (strcasecmp(method, "post") == 0) {
- return TS_METHOD_POST;
- } else if (strcasecmp(method, "put") == 0) {
- return TS_METHOD_PUT;
- } else if (strcasecmp(method, "trace") == 0) {
- return TS_METHOD_TRACE;
- } else if (strcasecmp(method, "push") == 0) { // could be "push" or "PUSH"
- return TS_METHOD_PUSH;
- }
-
- return TS_METHOD_UNDEFINED;
-}
-
-char *
-method_type_to_string(TSMethodT method)
-{
- switch (method) {
- case TS_METHOD_GET:
- return ats_strdup("get");
- case TS_METHOD_POST:
- return ats_strdup("post");
- case TS_METHOD_PUT:
- return ats_strdup("put");
- case TS_METHOD_TRACE:
- return ats_strdup("trace");
- case TS_METHOD_PUSH:
- return ats_strdup("push");
- default:
- break;
- }
-
- return nullptr;
-}
-
-/*----------------------------------------------------------------------------
- * connect_type_to_string
- *----------------------------------------------------------------------------
- */
-char *
-connect_type_to_string(TSConnectT conn)
-{
- switch (conn) {
- case TS_CON_UDP:
- return ats_strdup("udp");
- case TS_CON_TCP:
- return ats_strdup("tcp");
- default:
- break;
- }
- return nullptr;
-}
-
-TSConnectT
-string_to_connect_type(const char *conn)
-{
- if (strcmp(conn, "tcp") == 0) {
- return TS_CON_TCP;
- } else {
- return TS_CON_UDP;
- }
-
- return TS_CON_UNDEFINED;
-}
-
-/*----------------------------------------------------------------------------
- * multicast_type_to_string
- *----------------------------------------------------------------------------
- */
-char *
-multicast_type_to_string(TSMcTtlT mc)
-{
- switch (mc) {
- case TS_MC_TTL_SINGLE_SUBNET:
- return ats_strdup("single_subnet");
- case TS_MC_TTL_MULT_SUBNET:
- return ats_strdup("multiple_subnet");
- default:
- break;
- }
- return nullptr;
-}
-
-/* -------------------------------------------------------------------------
- * string_to_round_robin_type
- * -------------------------------------------------------------------------
- */
-TSRrT
-string_to_round_robin_type(const char *rr)
-{
- if (strcmp(rr, "true") == 0) {
- return TS_RR_TRUE;
- } else if (strcmp(rr, "false") == 0) {
- return TS_RR_FALSE;
- } else if (strcmp(rr, "strict") == 0) {
- return TS_RR_STRICT;
- }
-
- return TS_RR_UNDEFINED;
-}
-
-char *
-round_robin_type_to_string(TSRrT rr)
-{
- switch (rr) {
- case TS_RR_TRUE:
- return ats_strdup("true");
- case TS_RR_FALSE:
- return ats_strdup("false");
- case TS_RR_STRICT:
- return ats_strdup("strict");
- default:
- break;
- }
-
- return nullptr;
-}
-
-/*----------------------------------------------------------------------------
- * filename_to_string
- *----------------------------------------------------------------------------
- * TSFileNameT ==> string
- */
-const char *
-filename_to_string(TSFileNameT file)
-{
- switch (file) {
- case TS_FNAME_CACHE_OBJ:
- return "cache.config";
- case TS_FNAME_CONGESTION:
- return "congestion.config";
- case TS_FNAME_HOSTING:
- return "hosting.config";
- case TS_FNAME_IP_ALLOW:
- return "ip_allow.config";
- case TS_FNAME_PARENT_PROXY:
- return "parent.config";
- case TS_FNAME_VOLUME:
- return "volume.config";
- case TS_FNAME_PLUGIN:
- return "plugin.config";
- case TS_FNAME_REMAP:
- return "remap.config";
- case TS_FNAME_SOCKS:
- return "socks.config";
- case TS_FNAME_SPLIT_DNS:
- return "splitdns.config";
- case TS_FNAME_STORAGE:
- return "storage.config";
- default: /* no such config file */
- return nullptr;
- }
-}
-
-/* -------------------------------------------------------------------------
- * string_to_congest_scheme_type
- * -------------------------------------------------------------------------
- */
-TSCongestionSchemeT
-string_to_congest_scheme_type(const char *scheme)
-{
- if (strcmp(scheme, "per_ip") == 0) {
- return TS_HTTP_CONGEST_PER_IP;
- } else if (strcmp(scheme, "per_host") == 0) {
- return TS_HTTP_CONGEST_PER_HOST;
- }
-
- return TS_HTTP_CONGEST_UNDEFINED;
-}
-
-/* -------------------------------------------------------------------------
- * string_to_admin_acc_type
- * -------------------------------------------------------------------------
- */
-TSAccessT
-string_to_admin_acc_type(const char *access)
-{
- if (strcmp(access, "none") == 0) {
- return TS_ACCESS_NONE;
- } else if (strcmp(access, "monitor_only") == 0) {
- return TS_ACCESS_MONITOR;
- } else if (strcmp(access, "monitor_config_view") == 0) {
- return TS_ACCESS_MONITOR_VIEW;
- } else if (strcmp(access, "monitor_config_change") == 0) {
- return TS_ACCESS_MONITOR_CHANGE;
- }
-
- return TS_ACCESS_UNDEFINED;
-}
-
-char *
-admin_acc_type_to_string(TSAccessT access)
-{
- switch (access) {
- case TS_ACCESS_NONE:
- return ats_strdup("none");
- case TS_ACCESS_MONITOR:
- return ats_strdup("monitor_only");
- case TS_ACCESS_MONITOR_VIEW:
- return ats_strdup("monitor_config_view");
- case TS_ACCESS_MONITOR_CHANGE:
- return ats_strdup("monitor_config_change");
- default:
- break;
- }
-
- return nullptr;
-}
-
-/***************************************************************************
- * Tokens-to-Struct Converstion Functions
- ***************************************************************************/
-/* -------------------------------------------------------------------------
- * tokens_to_pdss_format
- * -------------------------------------------------------------------------
- * Pass in the TokenList and a pointer to first Token to start iterating from.
- * Iterates through the tokens, checking
- * for tokens that are either primary destination specifiers and secondary
- * specfiers. Returns pointer to the last valid pointer; eg. the last sec
- * spec that was in the list. If there are no primary dest or sec specs,
- * then just returns same pointer originally passed in.
- *
- * Returns NULL, if the first token IS NOT a Primary Dest Specifier
- */
-Token *
-tokens_to_pdss_format(TokenList *tokens, Token *first_tok, TSPdSsFormat *pdss)
-{
- Token *tok, *last_tok;
- int i = 0;
- const char *sspecs[NUM_SEC_SPECS] = {"time", "src_ip", "prefix", "suffix", "port", "method", "scheme", "tag"};
-
- // ink_assert(tokens && first_tok && pdss);
- if (!tokens || !first_tok || !pdss) {
- return nullptr;
- }
-
- // tokens->Print();
-
- // first token must be primary destination specifier
- if (strcmp(first_tok->name, "dest_domain") == 0) {
- pdss->pd_type = TS_PD_DOMAIN;
- } else if (strcmp(first_tok->name, "dest_host") == 0) {
- pdss->pd_type = TS_PD_HOST;
- } else if (strcmp(first_tok->name, "dest_ip") == 0) {
- pdss->pd_type = TS_PD_IP;
- } else if (strcmp(first_tok->name, "url_regex") == 0) {
- pdss->pd_type = TS_PD_URL_REGEX;
- } else if (strcmp(first_tok->name, "url") == 0) {
- pdss->pd_type = TS_PD_URL;
- } else {
- return nullptr; // INVALID primary destination specifier
- }
- pdss->pd_val = ats_strdup(first_tok->value);
-
- // iterate through tokens checking for sec specifiers
- // state determines which sec specifier being checked
- // the state is only set if there's a sec spec match
- last_tok = first_tok;
- tok = tokens->next(first_tok);
- while (tok) {
- bool matchFound = false;
- for (i = 0; i < NUM_SEC_SPECS; i++) {
- if (strcmp(tok->name, sspecs[i]) == 0) { // sec spec
- matchFound = true;
- switch (i) {
- case 0: // time
- // convert the time value
- string_to_time_struct(tok->value, &(pdss->sec_spec));
- goto next_token;
- case 1: // src_ip
- pdss->sec_spec.src_ip = ats_strdup(tok->value);
- goto next_token;
- case 2: // prefix
- pdss->sec_spec.prefix = ats_strdup(tok->value);
- goto next_token;
- case 3: // suffix
- pdss->sec_spec.suffix = ats_strdup(tok->value);
- goto next_token;
- case 4: // port
- pdss->sec_spec.port = string_to_port_ele(tok->value);
- goto next_token;
- case 5: // method
- pdss->sec_spec.method = string_to_method_type(tok->value);
- goto next_token;
- case 6: // scheme
- pdss->sec_spec.scheme = string_to_scheme_type(tok->value);
- goto next_token;
- default:
- // This should never happen
- break;
- }
- } // end if statement
- } // end for loop
-
- // No longer in the secondary specifer region,
- // return the last valid secondary specifer
- if (!matchFound) {
- return last_tok;
- }
-
- next_token: // Get the next token
- last_tok = tok;
- tok = tokens->next(tok);
-
- } // end while loop
-
- return nullptr;
-}
-
-/***************************************************************************
- * Validation Functions
- ***************************************************************************/
-
-/* -------------------------------------------------------------------------
- * isNumber
- * -------------------------------------------------------------------------
- * Returns true if the entire string is numerical
- */
-bool
-isNumber(const char *strNum)
-{
- for (int i = 0; strNum[i] != '\0'; i++) {
- if (!isdigit(strNum[i])) {
- return false;
- }
- }
-
- return true;
-}
-
-/* -------------------------------------------------------------------------
- * ccu_checkIpAddr (from WebFileEdit.cc)
- * -------------------------------------------------------------------------
- * Checks to see if the passed in string represents a valid
- * ip address in dot notation (ie 209.1.33.20)
- * If the min_addr and max_addr are specified, then it checks
- * that the ip address falls within the range; Otherwise
- * the min_addr = 0.0.0.0 and max_addr = 255.255.255.255
- *
- * Returns true if it does and false if it does not
- */
-bool
-ccu_checkIpAddr(const char *addr, const char *min_addr, const char *max_addr)
-{
- Tokenizer addrToks(".");
- Tokenizer minToks(".");
- Tokenizer maxToks(".");
- int len, addrQ, minQ, maxQ;
-
- if (!addr || !min_addr || !max_addr) {
- return false;
- }
- // BZ47440
- // truncate any leading or trailing white spaces from addr,
- // which can occur if IP is from a list of IP addresses
- char *new_addr = chopWhiteSpaces_alloc((char *)addr);
- if (new_addr == nullptr) {
- return false;
- }
-
- if ((addrToks.Initialize(new_addr, ALLOW_EMPTY_TOKS)) != 4 || (minToks.Initialize((char *)min_addr, ALLOW_EMPTY_TOKS)) != 4 ||
- (maxToks.Initialize((char *)max_addr, ALLOW_EMPTY_TOKS)) != 4) {
- ats_free(new_addr);
- return false; // Wrong number of parts
- }
- // IP can't end in a "." either
- len = strlen(new_addr);
- if (new_addr[len - 1] == '.') {
- ats_free(new_addr);
- return false;
- }
- // Check all four parts of the ip address to make
- // sure that they are valid
- for (int i = 0; i < 4; i++) {
- if (!isNumber(addrToks[i])) {
- ats_free(new_addr);
- return false;
- }
- // coverity[secure_coding]
- if (sscanf(addrToks[i], "%d", &addrQ) != 1 || sscanf(minToks[i], "%d", &minQ) != 1 || sscanf(maxToks[i], "%d", &maxQ) != 1) {
- ats_free(new_addr);
- return false;
- }
-
- if (addrQ < minQ || addrQ > maxQ) {
- ats_free(new_addr);
- return false;
- }
- }
-
- ats_free(new_addr);
- return true;
-}
-
-/* ----------------------------------------------------------------------------
- * ccu_checkIpAddrEle
- * ---------------------------------------------------------------------------
- * very similar to the ip_addr_ele_to_string function
- */
-bool
-ccu_checkIpAddrEle(TSIpAddrEle *ele)
-{
- if (!ele || ele->ip_a == TS_INVALID_IP_ADDR) {
- return false;
- }
-
- if (ele->type == TS_IP_SINGLE) { // SINGLE TYPE
- return (ccu_checkIpAddr(ele->ip_a));
- } else if (ele->type == TS_IP_RANGE) { // RANGE TYPE
- return (ccu_checkIpAddr(ele->ip_a) && ccu_checkIpAddr(ele->ip_b));
- } else {
- return false;
- }
-}
-
-bool
-ccu_checkPortNum(int port)
-{
- return ((port > 0) && (port < 65535)); // What is max. port number?
-}
-
-// port_b can be "unspecified"; however if port_b is specified, it must
-// be greater than port_a
-bool
-ccu_checkPortEle(TSPortEle *ele)
-{
- if (!ele) {
- return false;
- }
-
- if (ele->port_b == 0) { // single port
- return (ccu_checkPortNum(ele->port_a));
- } else { // range of ports
- if (ele->port_a >= ele->port_b) {
- return false;
- }
- return (ccu_checkPortNum(ele->port_a) && ccu_checkPortNum(ele->port_b));
- }
-}
-
-/* ---------------------------------------------------------------
- * checkPdSspec
- * ---------------------------------------------------------------
- * must have a prim dest value spsecified and have valid prim dest type
- */
-bool
-ccu_checkPdSspec(TSPdSsFormat pdss)
-{
- if (pdss.pd_type != TS_PD_DOMAIN && pdss.pd_type != TS_PD_HOST && pdss.pd_type != TS_PD_IP && pdss.pd_type != TS_PD_URL_REGEX) {
- goto Lerror;
- }
-
- if (!pdss.pd_val) {
- goto Lerror;
- }
- // primary destination cannot have spaces
- if (strstr(pdss.pd_val, " ")) {
- goto Lerror;
- }
- // if pdest is IP type, check if valid IP (could be single or range)
- if (pdss.pd_type == TS_PD_IP) {
- TSIpAddrEle *ip = string_to_ip_addr_ele(pdss.pd_val);
- if (!ip) {
- goto Lerror;
- } else {
- TSIpAddrEleDestroy(ip);
- }
- }
- // if src_ip specified, check if valid IP address
- if (pdss.sec_spec.src_ip) {
- if (!ccu_checkIpAddr(pdss.sec_spec.src_ip)) {
- goto Lerror;
- }
- }
-
- if (!ccu_checkTimePeriod(&(pdss.sec_spec))) {
- goto Lerror;
- }
-
- return true;
-
-Lerror:
- return false;
-}
-
-/* ---------------------------------------------------------------
- * ccu_checkUrl
- * ---------------------------------------------------------------
- * Checks that there is not more than one instance of ":/" in
- * the url.
- */
-bool
-ccu_checkUrl(char *url)
-{
- // Chop the protocol part, if it exists
- char *slashStr = strstr(url, "://");
- if (!slashStr) {
- return false; // missing protocol
- } else {
- url = slashStr + 3; // advance two positions to get rid of leading '://'
- }
-
- // check if there's a second occurrence
- slashStr = strstr(url, ":/");
- if (slashStr) {
- return false;
- }
-
- // make sure that after the first solo "/", there are no more ":"
- // to specify ports
- slashStr = strstr(url, "/"); // begin path prefix
- if (slashStr) {
- url = slashStr++;
- if (strstr(url, ":")) {
- return false; // the port must be specified before the prefix
- }
- }
-
- return true;
-}
-
-/* ---------------------------------------------------------------
- * ccu_checkTimePeriod
- * ---------------------------------------------------------------
- * Checks that the time struct used to specify the time period in the
- * TSSspec has valid time values (eg. 0-23 hr, 0-59 min) and that
- * time A <= time B
- */
-bool
-ccu_checkTimePeriod(TSSspec *sspec)
-{
- // check valid time values
- if (sspec->time.hour_a < 0 || sspec->time.hour_a > 23 || sspec->time.hour_b < 0 || sspec->time.hour_b > 23 ||
- sspec->time.min_a < 0 || sspec->time.min_a > 59 || sspec->time.min_b < 0 || sspec->time.min_b > 59) {
- return false;
- }
-
- // check time_a < time_b
- if (sspec->time.hour_a > sspec->time.hour_b) {
- return false;
- } else if (sspec->time.hour_a == sspec->time.hour_b) {
- if (sspec->time.min_a > sspec->time.min_b) {
- return false;
- }
- }
-
- return true;
-}
-
-/* ----------------------------------------------------------------------------
- * chopWhiteSpaces_alloc
- * ---------------------------------------------------------------------------
- * eliminates any leading and trailing white spaces from str; returns
- * the new allocated string
- */
-char *
-chopWhiteSpaces_alloc(char *str)
-{
- int len;
-
- if (!str) {
- return nullptr;
- }
-
- // skip any leading white spaces
- while (*str != '\0') {
- if ((*str) == ' ') {
- ++str;
- continue;
- }
- break;
- }
-
- // eliminate trailing white spaces
- len = strcspn(str, " ");
-
- return ats_strndup(str, len + 1);
-}
-
-/***************************************************************
- * General Helper Functions
- ***************************************************************/
-/*--------------------------------------------------------------
- * create_ele_obj_from_rule_node
- *--------------------------------------------------------------
- * Calls the appropriate subclasses' constructor using TokenList.
- * Returns NULL if invalid Ele.
- */
-CfgEleObj *
-create_ele_obj_from_rule_node(Rule *rule)
-{
- TSRuleTypeT rule_type;
- TokenList *token_list;
- CfgEleObj *ele = nullptr;
-
- // sanity check
- // ink_assert(rule != NULL);
- if (!rule) {
- return nullptr;
- }
-
- // first check if the rule node is a comment
- if (rule->getComment()) {
- ele = (CfgEleObj *)new CommentObj(rule->getComment());
- return ele;
- }
-
- token_list = rule->tokenList;
- // determine what rule type the TokenList refers to
- rule_type = get_rule_type(token_list, rule->getFiletype());
-
- // convert TokenList into an Ele
- // need switch statement to determine which Ele constructor to call
- switch (rule_type) {
- case TS_CACHE_NEVER: /* all cache rules use same constructor */
- case TS_CACHE_IGNORE_NO_CACHE:
- case TS_CACHE_IGNORE_CLIENT_NO_CACHE:
- case TS_CACHE_IGNORE_SERVER_NO_CACHE:
- case TS_CACHE_PIN_IN_CACHE:
- case TS_CACHE_TTL_IN_CACHE:
- case TS_CACHE_REVALIDATE:
- case TS_CACHE_AUTH_CONTENT:
- ele = (CfgEleObj *)new CacheObj(token_list);
- break;
- case TS_CONGESTION:
- ele = (CfgEleObj *)new CongestionObj(token_list);
- break;
- case TS_HOSTING: /* hosting.config */
- ele = (CfgEleObj *)new HostingObj(token_list);
- break;
- case TS_IP_ALLOW: /* ip_allow.config */
- ele = (CfgEleObj *)new IpAllowObj(token_list);
- break;
-
- case TS_PP_PARENT: /* parent.config */
- case TS_PP_GO_DIRECT:
- ele = (CfgEleObj *)new ParentProxyObj(token_list);
- break;
- case TS_VOLUME: /* volume.config */
- ele = (CfgEleObj *)new VolumeObj(token_list);
- break;
- case TS_PLUGIN:
- ele = (CfgEleObj *)new PluginObj(token_list);
- break;
- case TS_REMAP_MAP: /* remap.config */
- case TS_REMAP_REVERSE_MAP:
- case TS_REMAP_REDIRECT:
- case TS_REMAP_REDIRECT_TEMP:
- ele = (CfgEleObj *)new RemapObj(token_list);
- break;
- case TS_SOCKS_BYPASS: /* socks.config */
- case TS_SOCKS_AUTH:
- case TS_SOCKS_MULTIPLE:
- ele = (CfgEleObj *)new SocksObj(token_list);
- break;
- case TS_SPLIT_DNS: /* splitdns.config */
- ele = (CfgEleObj *)new SplitDnsObj(token_list);
- break;
- case TS_STORAGE:
- ele = (CfgEleObj *)new StorageObj(token_list);
- break;
- default:
- return nullptr; // invalid rule type
- }
- if (!ele || !ele->isValid()) {
- return nullptr;
- }
- return ele;
-}
-
-/*--------------------------------------------------------------
- * create_ele_obj_from_ele
- *--------------------------------------------------------------
- * calls the appropriate subclasses' constructor using actual TSEle
- * need to convert the ele into appropriate Ele object type
- * Note: the ele is not copied, it is actually used, so caller
- * shouldn't free it!
- */
-CfgEleObj *
-create_ele_obj_from_ele(TSCfgEle *ele)
-{
- CfgEleObj *ele_obj = nullptr;
-
- if (!ele) {
- return nullptr;
- }
-
- switch (ele->type) {
- case TS_CACHE_NEVER: /* cache.config */
- case TS_CACHE_IGNORE_NO_CACHE: // fall-through
- case TS_CACHE_IGNORE_CLIENT_NO_CACHE: // fall-through
- case TS_CACHE_IGNORE_SERVER_NO_CACHE: // fall-through
- case TS_CACHE_PIN_IN_CACHE: // fall-through
- case TS_CACHE_REVALIDATE: // fall-through
- case TS_CACHE_TTL_IN_CACHE:
- case TS_CACHE_AUTH_CONTENT:
- ele_obj = (CfgEleObj *)new CacheObj((TSCacheEle *)ele);
- break;
-
- case TS_CONGESTION:
- ele_obj = (CfgEleObj *)new CongestionObj((TSCongestionEle *)ele);
- break;
-
- case TS_HOSTING: /* hosting.config */
- ele_obj = (CfgEleObj *)new HostingObj((TSHostingEle *)ele);
- break;
-
- case TS_IP_ALLOW: /* ip_allow.config */
- ele_obj = (CfgEleObj *)new IpAllowObj((TSIpAllowEle *)ele);
- break;
-
- case TS_PP_PARENT: /* parent.config */
- case TS_PP_GO_DIRECT: // fall-through
- ele_obj = (CfgEleObj *)new ParentProxyObj((TSParentProxyEle *)ele);
- break;
-
- case TS_VOLUME: /* volume.config */
- ele_obj = (CfgEleObj *)new VolumeObj((TSVolumeEle *)ele);
- break;
-
- case TS_PLUGIN:
- ele_obj = (CfgEleObj *)new PluginObj((TSPluginEle *)ele);
- break;
-
- case TS_REMAP_MAP: /* remap.config */
- case TS_REMAP_REVERSE_MAP: // fall-through
- case TS_REMAP_REDIRECT: // fall-through
- case TS_REMAP_REDIRECT_TEMP: // fall-through
- ele_obj = (CfgEleObj *)new RemapObj((TSRemapEle *)ele);
- break;
-
- case TS_SOCKS_BYPASS: /* socks.config */
- case TS_SOCKS_AUTH:
- case TS_SOCKS_MULTIPLE:
- ele_obj = (CfgEleObj *)new SocksObj((TSSocksEle *)ele);
- break;
-
- case TS_SPLIT_DNS: /* splitdns.config */
- ele_obj = (CfgEleObj *)new SplitDnsObj((TSSplitDnsEle *)ele);
- break;
-
- case TS_STORAGE: /* storage.config */
- ele_obj = (CfgEleObj *)new StorageObj((TSStorageEle *)ele);
- break;
-
- case TS_TYPE_UNDEFINED:
- default:
- return nullptr; // error
- }
-
- return ele_obj;
-}
-
-/*--------------------------------------------------------------
- * get_rule_type
- *--------------------------------------------------------------
- * determine what rule type the TokenList refers to by examining
- * the appropriate token-value pair in the TokenList
- */
-TSRuleTypeT
-get_rule_type(TokenList *token_list, TSFileNameT file)
-{
- Token *tok;
-
- // ink_asser(ttoken_list);
- if (!token_list) {
- return TS_TYPE_UNDEFINED;
- }
-
- /* Depending on the file and rule type, need to find out which
- token specifies which type of rule it is */
- switch (file) {
- case TS_FNAME_CACHE_OBJ: /* cache.config */
- tok = token_list->first();
- while (tok != nullptr) {
- if (strcmp(tok->name, "action") == 0) {
- if (strcmp(tok->value, "never-cache") == 0) {
- return TS_CACHE_NEVER;
- } else if (strcmp(tok->value, "ignore-no-cache") == 0) {
- return TS_CACHE_IGNORE_NO_CACHE;
- } else if (strcmp(tok->value, "ignore-client-no-cache") == 0) {
- return TS_CACHE_IGNORE_CLIENT_NO_CACHE;
- } else if (strcmp(tok->value, "ignore-server-no-cache") == 0) {
- return TS_CACHE_IGNORE_SERVER_NO_CACHE;
- } else if (strcmp(tok->value, "cache-auth-content") == 0) {
- return TS_CACHE_AUTH_CONTENT;
- } else {
- return TS_TYPE_UNDEFINED;
- }
- } else if (strcmp(tok->name, "pin-in-cache") == 0) {
- return TS_CACHE_PIN_IN_CACHE;
- } else if (strcmp(tok->name, "revalidate") == 0) {
- return TS_CACHE_REVALIDATE;
- } else if (strcmp(tok->name, "ttl-in-cache") == 0) {
- return TS_CACHE_TTL_IN_CACHE;
- } else { // try next token
- tok = token_list->next(tok);
- }
- }
- // if reached this point, there is no action specified
- return TS_TYPE_UNDEFINED;
-
- case TS_FNAME_CONGESTION: /* congestion.config */
- return TS_CONGESTION;
-
- case TS_FNAME_HOSTING: /* hosting.config */
- return TS_HOSTING;
-
- case TS_FNAME_IP_ALLOW: /* ip_allow.config */
- return TS_IP_ALLOW;
-
- case TS_FNAME_PARENT_PROXY: /* parent.config */
- // search fro go_direct action name and recongize the value-> ture or false
- for (tok = token_list->first(); tok; tok = token_list->next(tok)) {
- if ((strcmp(tok->name, "go_direct") == 0) && (strcmp(tok->value, "true") == 0)) {
- return TS_PP_GO_DIRECT;
- }
- }
- return TS_PP_PARENT;
-
- case TS_FNAME_VOLUME: /* volume.config */
- return TS_VOLUME;
-
- case TS_FNAME_PLUGIN: /* plugin.config */
- return TS_PLUGIN;
-
- case TS_FNAME_REMAP: /* remap.config */
- tok = token_list->first();
- if (strcmp(tok->name, "map") == 0) {
- return TS_REMAP_MAP;
- } else if (strcmp(tok->name, "reverse_map") == 0) {
- return TS_REMAP_REVERSE_MAP;
- } else if (strcmp(tok->name, "redirect") == 0) {
- return TS_REMAP_REDIRECT;
- } else if (strcmp(tok->name, "redirect_temporary") == 0) {
- return TS_REMAP_REDIRECT_TEMP;
- } else {
- return TS_TYPE_UNDEFINED;
- }
- case TS_FNAME_SOCKS: /* socks.config */
- tok = token_list->first();
- if (strcmp(tok->name, "no_socks") == 0) {
- return TS_SOCKS_BYPASS;
- } else if (strcmp(tok->name, "auth") == 0) {
- return TS_SOCKS_AUTH;
- } else if (strcmp(tok->name, "dest_ip") == 0) {
- return TS_SOCKS_MULTIPLE;
- } else {
- return TS_TYPE_UNDEFINED;
- }
- case TS_FNAME_SPLIT_DNS: /* splitdns.config */
- return TS_SPLIT_DNS;
-
- case TS_FNAME_STORAGE: /* storage.config */
- return TS_STORAGE;
-
- case TS_FNAME_UNDEFINED:
- default:
- return TS_TYPE_UNDEFINED;
- }
-
- return TS_TYPE_UNDEFINED; // Should not reach here
-}
-
-///////////////////////////////////////////////////////////////////
-// Since we are using the ele's as C structures wrapped in C++ classes
-// we need to write copy function that "copy" the C structures
-// 1) need copy functions for each helper information struct which
-// are typically embedded in the Ele's (eg. any lists, TSSspec)
-// 2) need copy functions for each Ele; these functiosn will actually
-// be called by teh copy constructors and overloaded assignment
-// operators in each CfgEleObj subclass!!
-///////////////////////////////////////////////////////////////////
-void
-copy_cfg_ele(TSCfgEle *src_ele, TSCfgEle *dst_ele)
-{
- // ink_assert (src_ele && dst_ele);
- if (!src_ele || !dst_ele) {
- return;
- }
-
- dst_ele->type = src_ele->type;
- dst_ele->error = src_ele->error;
-}
-
-void
-copy_sspec(TSSspec *src, TSSspec *dst)
-{
- // ink_assert(src && dst);
- if (!src || !dst) {
- return;
- }
-
- dst->active = src->active;
- dst->time.hour_a = src->time.hour_a;
- dst->time.min_a = src->time.min_a;
- dst->time.hour_b = src->time.hour_b;
- dst->time.min_b = src->time.min_b;
- if (src->src_ip) {
- dst->src_ip = ats_strdup(src->src_ip);
- }
- if (src->prefix) {
- dst->prefix = ats_strdup(src->prefix);
- }
- if (src->suffix) {
- dst->suffix = ats_strdup(src->suffix);
- }
- dst->port = copy_port_ele(src->port);
- dst->method = src->method;
- dst->scheme = src->scheme;
-}
-
-void
-copy_pdss_format(TSPdSsFormat *src_pdss, TSPdSsFormat *dst_pdss)
-{
- // ink_assert (src_pdss && dst_pdss);
- if (!src_pdss || !dst_pdss) {
- return;
- }
-
- dst_pdss->pd_type = src_pdss->pd_type;
- if (src_pdss->pd_val) {
- dst_pdss->pd_val = ats_strdup(src_pdss->pd_val);
- }
- copy_sspec(&(src_pdss->sec_spec), &(dst_pdss->sec_spec));
-}
-
-void
-copy_hms_time(TSHmsTime *src, TSHmsTime *dst)
-{
- if (!src || !dst) {
- return;
- }
-
- dst->d = src->d;
- dst->h = src->h;
- dst->m = src->m;
- dst->s = src->s;
-}
-
-TSIpAddrEle *
-copy_ip_addr_ele(TSIpAddrEle *src_ele)
-{
- TSIpAddrEle *dst_ele;
-
- if (!src_ele) {
- return nullptr;
- }
-
- dst_ele = TSIpAddrEleCreate();
- dst_ele->type = src_ele->type;
- if (src_ele->ip_a) {
- dst_ele->ip_a = ats_strdup(src_ele->ip_a);
- }
- dst_ele->cidr_a = src_ele->cidr_a;
- dst_ele->port_a = src_ele->port_a;
- if (src_ele->ip_b) {
- dst_ele->ip_b = ats_strdup(src_ele->ip_b);
- }
- dst_ele->cidr_b = src_ele->cidr_b;
- dst_ele->port_b = src_ele->port_b;
-
- return dst_ele;
-}
-
-TSPortEle *
-copy_port_ele(TSPortEle *src_ele)
-{
- TSPortEle *dst_ele;
-
- if (!src_ele) {
- return nullptr;
- }
-
- dst_ele = TSPortEleCreate();
- dst_ele->port_a = src_ele->port_a;
- dst_ele->port_b = src_ele->port_b;
-
- return dst_ele;
-}
-
-TSDomain *
-copy_domain(TSDomain *src_dom)
-{
- TSDomain *dst_dom;
-
- if (!src_dom) {
- return nullptr;
- }
-
- dst_dom = TSDomainCreate();
- if (src_dom->domain_val) {
- dst_dom->domain_val = ats_strdup(src_dom->domain_val);
- }
- dst_dom->port = src_dom->port;
-
- return dst_dom;
-}
-
-TSIpAddrList
-copy_ip_addr_list(TSIpAddrList list)
-{
- TSIpAddrList nlist;
- TSIpAddrEle *ele, *nele;
- int count, i;
-
- if (list == TS_INVALID_LIST) {
- return TS_INVALID_LIST;
- }
-
- nlist = TSIpAddrListCreate();
- count = TSIpAddrListLen(list);
- for (i = 0; i < count; i++) {
- ele = TSIpAddrListDequeue(list);
- nele = copy_ip_addr_ele(ele);
- TSIpAddrListEnqueue(list, ele);
- TSIpAddrListEnqueue(nlist, nele);
- }
-
- return nlist;
-}
-
-TSPortList
-copy_port_list(TSPortList list)
-{
- TSPortList nlist;
- TSPortEle *ele, *nele;
- int count, i;
-
- if (list == TS_INVALID_LIST) {
- return TS_INVALID_LIST;
- }
-
- nlist = TSPortListCreate();
- count = TSPortListLen(list);
- for (i = 0; i < count; i++) {
- ele = TSPortListDequeue(list);
- nele = copy_port_ele(ele);
- TSPortListEnqueue(list, ele);
- TSPortListEnqueue(nlist, nele);
- }
-
- return nlist;
-}
-
-TSDomainList
-copy_domain_list(TSDomainList list)
-{
- TSDomainList nlist;
- TSDomain *ele, *nele;
- int count, i;
-
- if (list == TS_INVALID_LIST) {
- return TS_INVALID_LIST;
- }
-
- nlist = TSDomainListCreate();
- count = TSDomainListLen(list);
- for (i = 0; i < count; i++) {
- ele = TSDomainListDequeue(list);
- nele = copy_domain(ele);
- TSDomainListEnqueue(list, ele);
- TSDomainListEnqueue(nlist, nele);
- }
-
- return nlist;
-}
-
-TSStringList
-copy_string_list(TSStringList list)
-{
- TSStringList nlist;
- char *ele, *nele;
- int count, i;
-
- if (list == TS_INVALID_LIST) {
- return TS_INVALID_LIST;
- }
-
- nlist = TSStringListCreate();
- count = TSStringListLen(list);
- for (i = 0; i < count; i++) {
- ele = TSStringListDequeue(list);
- nele = ats_strdup(ele);
- TSStringListEnqueue(list, ele);
- TSStringListEnqueue(nlist, nele);
- }
-
- return nlist;
-}
-
-TSIntList
-copy_int_list(TSIntList list)
-{
- TSIntList nlist;
- int *elem, *nelem;
- int count, i;
-
- if (list == TS_INVALID_LIST) {
- return TS_INVALID_LIST;
- }
-
- nlist = TSIntListCreate();
- count = TSIntListLen(list);
- for (i = 0; i < count; i++) {
- elem = TSIntListDequeue(list);
- nelem = (int *)ats_malloc(sizeof(int));
- *nelem = *elem;
- TSIntListEnqueue(list, elem);
- TSIntListEnqueue(nlist, nelem);
- }
-
- return nlist;
-}
-
-TSCacheEle *
-copy_cache_ele(TSCacheEle *ele)
-{
- if (!ele) {
- return nullptr;
- }
-
- TSCacheEle *nele = TSCacheEleCreate(ele->cfg_ele.type);
- if (!nele) {
- return nullptr;
- }
-
- copy_cfg_ele(&(ele->cfg_ele), &(nele->cfg_ele));
- copy_pdss_format(&(ele->cache_info), &(nele->cache_info));
- copy_hms_time(&(ele->time_period), &(nele->time_period));
-
- return nele;
-}
-
-TSCongestionEle *
-copy_congestion_ele(TSCongestionEle *ele)
-{
- if (!ele) {
- return nullptr;
- }
-
- TSCongestionEle *nele = TSCongestionEleCreate();
- if (!nele) {
- return nullptr;
- }
- copy_cfg_ele(&(ele->cfg_ele), &(nele->cfg_ele));
- // copy_pdss_format(&(ele->congestion_info), &(nele->congestion_info));
- nele->pd_type = ele->pd_type;
- nele->pd_val = ats_strdup(ele->pd_val);
- if (ele->prefix) {
- nele->prefix = ats_strdup(ele->prefix);
- }
- nele->port = ele->port;
- nele->scheme = ele->scheme;
- nele->max_connection_failures = ele->max_connection_failures;
- nele->fail_window = ele->fail_window;
- nele->proxy_retry_interval = ele->proxy_retry_interval;
- nele->client_wait_interval = ele->client_wait_interval;
- nele->wait_interval_alpha = ele->wait_interval_alpha;
- nele->live_os_conn_timeout = ele->live_os_conn_timeout;
- nele->live_os_conn_retries = ele->live_os_conn_retries;
- nele->dead_os_conn_timeout = ele->dead_os_conn_timeout;
- nele->dead_os_conn_retries = ele->dead_os_conn_retries;
- nele->max_connection = ele->max_connection;
- if (ele->error_page_uri) {
- nele->error_page_uri = ats_strdup(ele->error_page_uri);
- }
-
- return nele;
-}
-
-TSHostingEle *
-copy_hosting_ele(TSHostingEle *ele)
-{
- if (!ele) {
- return nullptr;
- }
-
- TSHostingEle *nele = TSHostingEleCreate();
- if (!nele) {
- return nullptr;
- }
-
- copy_cfg_ele(&(ele->cfg_ele), &(nele->cfg_ele));
- nele->pd_type = ele->pd_type;
- if (ele->pd_val) {
- nele->pd_val = ats_strdup(ele->pd_val);
- }
- ele->volumes = copy_int_list(ele->volumes);
-
- return nele;
-}
-
-TSIpAllowEle *
-copy_ip_allow_ele(TSIpAllowEle *ele)
-{
- if (!ele) {
- return nullptr;
- }
-
- TSIpAllowEle *nele = TSIpAllowEleCreate();
- if (!nele) {
- return nullptr;
- }
- if (ele->src_ip_addr) {
- nele->src_ip_addr = copy_ip_addr_ele(ele->src_ip_addr);
- }
- nele->action = ele->action;
- return nele;
-}
-
-TSParentProxyEle *
-copy_parent_proxy_ele(TSParentProxyEle *ele)
-{
- if (!ele) {
- return nullptr;
- }
-
- TSParentProxyEle *nele = TSParentProxyEleCreate(TS_TYPE_UNDEFINED);
- if (!nele) {
- return nullptr;
- }
-
- copy_cfg_ele(&(ele->cfg_ele), &(nele->cfg_ele));
- copy_pdss_format(&(ele->parent_info), &(nele->parent_info));
- nele->rr = ele->rr;
- nele->proxy_list = copy_domain_list(ele->proxy_list);
- nele->direct = ele->direct;
-
- return nele;
-}
-
-TSVolumeEle *
-copy_volume_ele(TSVolumeEle *ele)
-{
- if (!ele) {
- return nullptr;
- }
-
- TSVolumeEle *nele = TSVolumeEleCreate();
- if (!nele) {
- return nullptr;
- }
-
- copy_cfg_ele(&(ele->cfg_ele), &(nele->cfg_ele));
- nele->volume_num = ele->volume_num;
- nele->scheme = ele->scheme;
- nele->volume_size = ele->volume_size;
- nele->size_format = ele->size_format;
-
- return nele;
-}
-
-TSPluginEle *
-copy_plugin_ele(TSPluginEle *ele)
-{
- if (!ele) {
- return nullptr;
- }
-
- TSPluginEle *nele = TSPluginEleCreate();
- if (!nele) {
- return nullptr;
- }
-
- copy_cfg_ele(&(ele->cfg_ele), &(nele->cfg_ele));
- if (ele->name) {
- nele->name = ats_strdup(ele->name);
- }
- nele->args = copy_string_list(ele->args);
-
- return nele;
-}
-
-TSRemapEle *
-copy_remap_ele(TSRemapEle *ele)
-{
- if (!ele) {
- return nullptr;
- }
-
- TSRemapEle *nele = TSRemapEleCreate(TS_TYPE_UNDEFINED);
- if (!nele) {
- return nullptr;
- }
-
- copy_cfg_ele(&(ele->cfg_ele), &(nele->cfg_ele));
- nele->map = ele->map;
- nele->from_scheme = ele->from_scheme;
- if (ele->from_host) {
- nele->from_host = ats_strdup(ele->from_host);
- }
- nele->from_port = ele->from_port;
- if (ele->from_path_prefix) {
- nele->from_path_prefix = ats_strdup(ele->from_path_prefix);
- }
- nele->to_scheme = ele->to_scheme;
- if (ele->to_host) {
- nele->to_host = ats_strdup(ele->to_host);
- }
- nele->to_port = ele->to_port;
- if (ele->to_path_prefix) {
- nele->to_path_prefix = ats_strdup(ele->to_path_prefix);
- }
-
- return nele;
-}
-
-TSSocksEle *
-copy_socks_ele(TSSocksEle *ele)
-{
- if (!ele) {
- return nullptr;
- }
-
- TSSocksEle *nele = TSSocksEleCreate(TS_TYPE_UNDEFINED);
- if (!nele) {
- return nullptr;
- }
-
- copy_cfg_ele(&(ele->cfg_ele), &(nele->cfg_ele));
- nele->ip_addrs = copy_ip_addr_list(ele->ip_addrs);
- nele->dest_ip_addr = copy_ip_addr_ele(ele->dest_ip_addr);
- nele->socks_servers = copy_domain_list(ele->socks_servers);
- nele->rr = ele->rr;
- if (ele->username) {
- nele->username = ats_strdup(ele->username);
- }
- if (ele->password) {
- nele->password = ats_strdup(ele->password);
- }
-
- return nele;
-}
-
-TSSplitDnsEle *
-copy_split_dns_ele(TSSplitDnsEle *ele)
-{
- if (!ele) {
- return nullptr;
- }
-
- TSSplitDnsEle *nele = TSSplitDnsEleCreate();
- if (!nele) {
- return nullptr;
- }
-
- copy_cfg_ele(&(ele->cfg_ele), &(nele->cfg_ele));
- nele->pd_type = ele->pd_type;
- if (ele->pd_val) {
- nele->pd_val = ats_strdup(ele->pd_val);
- }
- nele->dns_servers_addrs = copy_domain_list(ele->dns_servers_addrs);
- if (ele->def_domain) {
- nele->def_domain = ats_strdup(ele->def_domain);
- }
- nele->search_list = copy_domain_list(ele->search_list);
-
- return nele;
-}
-
-TSStorageEle *
-copy_storage_ele(TSStorageEle *ele)
-{
- if (!ele) {
- return nullptr;
- }
-
- TSStorageEle *nele = TSStorageEleCreate();
- if (!nele) {
- return nullptr;
- }
-
- copy_cfg_ele(&(ele->cfg_ele), &(nele->cfg_ele));
- if (ele->pathname) {
- nele->pathname = ats_strdup(ele->pathname);
- }
- nele->size = ele->size;
-
- return nele;
-}
-
-INKCommentEle *
-copy_comment_ele(INKCommentEle *ele)
-{
- if (!ele) {
- return nullptr;
- }
-
- INKCommentEle *nele = comment_ele_create(ele->comment);
- return nele;
-}
-
-/***************************************************************************
- * Functions needed by implementation but must be hidden from user
- ***************************************************************************/
-INKCommentEle *
-comment_ele_create(char *comment)
-{
- INKCommentEle *ele;
-
- ele = (INKCommentEle *)ats_malloc(sizeof(INKCommentEle));
-
- ele->cfg_ele.type = TS_TYPE_COMMENT;
- ele->cfg_ele.error = TS_ERR_OKAY;
- if (comment) {
- ele->comment = ats_strdup(comment);
- } else { // comment is NULL
- ele->comment = nullptr;
- }
-
- return ele;
-}
-
-void
-comment_ele_destroy(INKCommentEle *ele)
-{
- if (ele) {
- ats_free(ele->comment);
- ats_free(ele);
- }
-
- return;
-}
diff --git a/mgmt/api/CfgContextUtils.h b/mgmt/api/CfgContextUtils.h
deleted file mode 100644
index a19ca18..0000000
--- a/mgmt/api/CfgContextUtils.h
+++ /dev/null
@@ -1,194 +0,0 @@
-/** @file
-
- A brief file description
-
- @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.
- */
-
-/*****************************************************************************
- * Filename: CfgContextUtils.h (based on FileOp.h)
- * ------------------------------------------------------------------------
- * Purpose:
- * 1) Contains helper functions to convert "values" from TokenList to Ele
- * format and from Ele Format to file Rule Format
- * 2) contains helper functions to check for valid info
- *
- ***************************************************************************/
-
-#ifndef _CONTEXT_UTILS_H_
-#define _CONTEXT_UTILS_H_
-
-#include "CfgContextDefs.h"
-#include "mgmtapi.h"
-#include "GenericParser.h"
-#include "CfgContextImpl.h"
-
-/***************************************************************************
- * Conversion Functions
- ***************************************************************************/
-/* INKIpAddrEle <==> (single type) ip_a/cidr_a
- * (range type) ip_a/cidr_a-ip_b/cidr_b */
-TSIpAddrEle *string_to_ip_addr_ele(const char *str);
-char *ip_addr_ele_to_string(TSIpAddrEle *ele);
-
-/* INKIpAddr <==> ip_addr_string */
-char *ip_addr_to_string(TSIpAddr ip);
-TSIpAddr string_to_ip_addr(const char *str);
-
-/* IpAddrList <==> ip_addr1, ip_addr2, ip_addr3, ... */
-char *ip_addr_list_to_string(IpAddrList *list, const char *delimiter);
-TSIpAddrList string_to_ip_addr_list(const char *str_list, const char *delimiter);
-
-/* PortList <==> port_1<delim>port_2<delim>port_3<delim>...<delim>port_n
- * (Note: each port can be a port range */
-char *port_list_to_string(PortList *ports, const char *delimiter);
-TSPortList string_to_port_list(const char *str_list, const char *delimiter);
-
-/* TSPortEle <==> port_a / port_a#port_b */
-char *port_ele_to_string(TSPortEle *ele);
-TSPortEle *string_to_port_ele(const char *str);
-
-/* TSProxyList <==> proxy_1, proxy_2,... */
-// char* proxy_list_to_string(ProxyList *list);
-
-/* TSStringList(of char*'s)==> elem1<delimiter>elem2<delimiter>elem3 */
-char *string_list_to_string(TSStringList list, const char *delimiter);
-TSStringList string_to_string_list(const char *str, const char *delimiter);
-
-/* TSIntList(of char*'s)==> elem1<delimiter>elem2<delimiter>elem3 */
-char *int_list_to_string(TSIntList list, const char *delimiter);
-TSIntList string_to_int_list(const char *str, const char *delimiter);
-
-/* TSDomain */
-TSDomain *string_to_domain(const char *str);
-char *domain_to_string(TSDomain *domain);
-
-/* TSDomainList */
-TSDomainList string_to_domain_list(const char *str_list, const char *delimiter);
-char *domain_list_to_string(TSDomainList list, const char *delimiter);
-
-/* pd, pd_val, TSSspec ==> <pd_type>#<pd_value>#<sspecs> */
-char *pdest_sspec_to_string(TSPrimeDestT pd, char *prim_dest_val, TSSspec *sspec);
-/* <pd_type>#<pd_value>#<sspecs> ==> TSPdSsFormat */
-TSMgmtError string_to_pdss_format(const char *str, TSPdSsFormat *pdss);
-
-/* ?h?m?s <==> TSHmsTime */
-char *hms_time_to_string(TSHmsTime time);
-TSMgmtError string_to_hms_time(const char *str, TSHmsTime *time);
-
-/* string ==> time struct */
-TSMgmtError string_to_time_struct(const char *str, TSSspec *sspec);
-
-/* string ==> TSHdrT */
-TSHdrT string_to_header_type(const char *str);
-char *header_type_to_string(TSHdrT hdr);
-
-/* TSSchemeT <==> string */
-TSSchemeT string_to_scheme_type(const char *scheme);
-char *scheme_type_to_string(TSSchemeT scheme);
-
-/* TSMethodT <==> string */
-TSMethodT string_to_method_type(const char *method);
-char *method_type_to_string(TSMethodT method);
-
-/* TSConnectT <==> string */
-char *connect_type_to_string(TSConnectT conn);
-TSConnectT string_to_connect_type(const char *conn);
-
-/* TSMcTtlt <==> string */
-char *multicast_type_to_string(TSMcTtlT mc);
-
-/* TSRrT <==> string */
-TSRrT string_to_round_robin_type(const char *rr);
-char *round_robin_type_to_string(TSRrT rr);
-
-/* TSFileNameT <==> string */
-const char *filename_to_string(TSFileNameT file);
-
-TSCongestionSchemeT string_to_congest_scheme_type(const char *scheme);
-
-TSAccessT string_to_admin_acc_type(const char *access);
-char *admin_acc_type_to_string(TSAccessT access);
-
-/***************************************************************************
- * Tokens-to-Struct Conversion Functions
- ***************************************************************************/
-Token *tokens_to_pdss_format(TokenList *tokens, Token *first_tok, TSPdSsFormat *pdss);
-
-/***************************************************************************
- * Validation Functions
- ***************************************************************************/
-bool isNumber(const char *strNum);
-bool ccu_checkIpAddr(const char *addr, const char *min_addr = "0.0.0.0", const char *max_addr = "255.255.255.255");
-bool ccu_checkIpAddrEle(TSIpAddrEle *ele);
-bool ccu_checkPortNum(int port);
-bool ccu_checkPortEle(TSPortEle *ele);
-bool ccu_checkPdSspec(TSPdSsFormat pdss);
-bool ccu_checkUrl(char *url);
-bool ccu_checkTimePeriod(TSSspec *sspec);
-
-char *chopWhiteSpaces_alloc(char *str);
-
-/***************************************************************************
- * General Helper Functions
- ***************************************************************************/
-CfgEleObj *create_ele_obj_from_rule_node(Rule *rule);
-CfgEleObj *create_ele_obj_from_ele(TSCfgEle *ele);
-TSRuleTypeT get_rule_type(TokenList *token_list, TSFileNameT file);
-
-/***************************************************************************
- * Copy Helper Functions
- ***************************************************************************/
-// these are mainly used by the C++ CfgEleObj subclasses when they need
-// to make copies of their m_ele data class member
-
-void copy_cfg_ele(TSCfgEle *src_ele, TSCfgEle *dst_ele);
-void copy_sspec(TSSspec *src, TSSspec *dst);
-void copy_pdss_format(TSPdSsFormat *src_pdss, TSPdSsFormat *dst_pdss);
-void copy_hms_time(TSHmsTime *src, TSHmsTime *dst);
-TSIpAddrEle *copy_ip_addr_ele(TSIpAddrEle *src_ele);
-TSPortEle *copy_port_ele(TSPortEle *src_ele);
-TSDomain *copy_domain(TSDomain *src_dom);
-
-TSIpAddrList copy_ip_addr_list(TSIpAddrList list);
-TSPortList copy_port_list(TSPortList list);
-TSDomainList copy_domain_list(TSDomainList list);
-TSStringList copy_string_list(TSStringList list);
-TSIntList copy_int_list(TSIntList list);
-
-TSCacheEle *copy_cache_ele(TSCacheEle *ele);
-TSCongestionEle *copy_congestion_ele(TSCongestionEle *ele);
-TSHostingEle *copy_hosting_ele(TSHostingEle *ele);
-TSIpAllowEle *copy_ip_allow_ele(TSIpAllowEle *ele);
-TSParentProxyEle *copy_parent_proxy_ele(TSParentProxyEle *ele);
-TSVolumeEle *copy_volume_ele(TSVolumeEle *ele);
-TSPluginEle *copy_plugin_ele(TSPluginEle *ele);
-TSRemapEle *copy_remap_ele(TSRemapEle *ele);
-TSSocksEle *copy_socks_ele(TSSocksEle *ele);
-TSSplitDnsEle *copy_split_dns_ele(TSSplitDnsEle *ele);
-TSStorageEle *copy_storage_ele(TSStorageEle *ele);
-INKCommentEle *copy_comment_ele(INKCommentEle *ele);
-
-/***************************************************************************
- * Functions needed by implementation but must be hidden from user
- ***************************************************************************/
-INKCommentEle *comment_ele_create(char *comment);
-void comment_ele_destroy(INKCommentEle *ele);
-
-#endif
diff --git a/mgmt/api/CoreAPI.cc b/mgmt/api/CoreAPI.cc
index a76c9d6..868898c 100644
--- a/mgmt/api/CoreAPI.cc
+++ b/mgmt/api/CoreAPI.cc
@@ -44,7 +44,6 @@
#include "CoreAPI.h"
#include "CoreAPIShared.h"
-#include "CfgContextUtils.h"
#include "EventCallback.h"
#include "ts/I_Layout.h"
#include "ts/ink_cap.h"
@@ -695,58 +694,6 @@ MgmtRecordSetString(const char *rec_name, const char *string_val, TSActionNeedT
}
/**************************************************************************
- * FILE OPERATIONS
- *************************************************************************/
-
-/*-------------------------------------------------------------------------
- * ReadFile (MgmtAPILocal::get_lines_from_file)
- *-------------------------------------------------------------------------
- * Purpose: returns copy of the most recent version of the file
- * Input: file - the config file to read
- * text - a buffer is allocated on the text char* pointer
- * size - the size of the buffer is returned
- * ver - the version number of file being read
- * Note: CALLEE must DEALLOCATE text memory returned
- */
-TSMgmtError
-ReadFile(TSFileNameT file, char **text, int *size, int *version)
-{
- const char *fname;
- Rollback *file_rb;
- int ret, old_file_len;
- TextBuffer *old_file_content;
- char *old_file_lines;
- version_t ver;
-
- Debug("FileOp", "[get_lines_from_file] START");
-
- fname = filename_to_string(file);
- if (!fname) {
- return TS_ERR_READ_FILE;
- }
-
- ret = configFiles->getRollbackObj(fname, &file_rb);
- if (ret != true) {
- Debug("FileOp", "[get_lines_from_file] Can't get Rollback for file: %s", fname);
- return TS_ERR_READ_FILE;
- }
- ver = file_rb->getCurrentVersion();
- file_rb->getVersion(ver, &old_file_content);
- *version = ver;
-
- // don't need to allocate memory b/c "getVersion" allocates memory
- old_file_lines = old_file_content->bufPtr();
- old_file_len = strlen(old_file_lines);
-
- *text = ats_strdup(old_file_lines); // make copy before deleting TextBuffer
- *size = old_file_len;
-
- delete old_file_content; // delete TextBuffer
-
- return TS_ERR_OKAY;
-}
-
-/**************************************************************************
* EVENTS
*************************************************************************/
/*-------------------------------------------------------------------------
diff --git a/mgmt/api/CoreAPI.h b/mgmt/api/CoreAPI.h
index 9e19b11..7a20b10 100644
--- a/mgmt/api/CoreAPI.h
+++ b/mgmt/api/CoreAPI.h
@@ -30,9 +30,13 @@
#include "MgmtDefs.h" // MgmtInt, MgmtFloat, etc
#include "mgmtapi.h"
-#include "CfgContextDefs.h"
#include "ts/Tokenizer.h"
+// for buffer used temporarily to parse incoming commands.
+#ifndef MAX_BUF_SIZE
+#define MAX_BUF_SIZE 4098
+#endif
+
TSMgmtError Init(const char *socket_path = NULL, TSInitOptionT options = TS_MGMT_OPT_DEFAULTS);
TSMgmtError Terminate();
@@ -67,11 +71,6 @@ TSMgmtError MgmtConfigRecordDescribe(const char *rec_name, unsigned flags, TSCon
TSMgmtError MgmtConfigRecordDescribeMatching(const char *regex, unsigned flags, TSList rec_vals);
/***************************************************************************
- * File Operations
- ***************************************************************************/
-TSMgmtError ReadFile(TSFileNameT file, char **text, int *size, int *version);
-
-/***************************************************************************
* Events
***************************************************************************/
diff --git a/mgmt/api/CoreAPIRemote.cc b/mgmt/api/CoreAPIRemote.cc
index 962b02c..fb3d540 100644
--- a/mgmt/api/CoreAPIRemote.cc
+++ b/mgmt/api/CoreAPIRemote.cc
@@ -42,10 +42,11 @@
#include "ts/ink_string.h"
#include "ts/I_Layout.h"
#include "ts/ParseRules.h"
+#include "ts/ink_memory.h"
#include "CoreAPI.h"
#include "CoreAPIShared.h"
-#include "CfgContextUtils.h"
#include "NetworkUtilsRemote.h"
+
#include "EventCallback.h"
#include "MgmtMarshall.h"
@@ -814,64 +815,6 @@ MgmtRecordSetString(const char *rec_name, const char *string_val, TSActionNeedT
}
/***************************************************************************
- * File Operations
- ***************************************************************************/
-/*-------------------------------------------------------------------------
- * ReadFile
- *-------------------------------------------------------------------------
- * Purpose: returns copy of the most recent version of the file
- * Input: file - the config file to read
- * text - a buffer is allocated on the text char* pointer
- * size - the size of the buffer is returned
- * Output:
- *
- * Marshals a read file request that can be sent over the unix domain socket.
- * Connects to the socket and sends request over. Parses the response from
- * Traffic Manager.
- */
-TSMgmtError
-ReadFile(TSFileNameT file, char **text, int *size, int *version)
-{
- TSMgmtError ret;
- OpType optype = OpType::FILE_READ;
- MgmtMarshallInt fid = file;
-
- MgmtMarshallData reply = {nullptr, 0};
- MgmtMarshallInt err;
- MgmtMarshallInt vers;
- MgmtMarshallData data = {nullptr, 0};
-
- *text = nullptr;
- *size = *version = 0;
-
- ret = MGMTAPI_SEND_MESSAGE(main_socket_fd, OpType::FILE_READ, &optype, &fid);
- if (ret != TS_ERR_OKAY) {
- return ret;
- }
-
- ret = recv_mgmt_message(main_socket_fd, reply);
- if (ret != TS_ERR_OKAY) {
- return ret;
- }
-
- ret = recv_mgmt_response(reply.ptr, reply.len, OpType::FILE_READ, &err, &vers, &data);
- ats_free(reply.ptr);
-
- if (ret != TS_ERR_OKAY) {
- return ret;
- }
-
- if (err != TS_ERR_OKAY) {
- return (TSMgmtError)err;
- }
-
- *version = vers;
- *text = (char *)data.ptr;
- *size = (int)data.len;
- return TS_ERR_OKAY;
-}
-
-/***************************************************************************
* Events
***************************************************************************/
/*-------------------------------------------------------------------------
diff --git a/mgmt/api/EventControlMain.cc b/mgmt/api/EventControlMain.cc
index ccf2bcc..ba76d10 100644
--- a/mgmt/api/EventControlMain.cc
+++ b/mgmt/api/EventControlMain.cc
@@ -519,7 +519,6 @@ done:
using event_message_handler = TSMgmtError (*)(EventClientT *, void *, size_t);
static const event_message_handler handlers[] = {
- nullptr, // FILE_READ
nullptr, // RECORD_SET
nullptr, // RECORD_GET
nullptr, // PROXY_STATE_GET
diff --git a/mgmt/api/INKMgmtAPI.cc b/mgmt/api/INKMgmtAPI.cc
index d044dac..50ab43b 100644
--- a/mgmt/api/INKMgmtAPI.cc
+++ b/mgmt/api/INKMgmtAPI.cc
@@ -31,13 +31,12 @@
***************************************************************************/
#include "ts/ink_platform.h"
#include "ts/ink_code.h"
+#include "ts/ink_memory.h"
#include "ts/ParseRules.h"
#include <climits>
#include "ts/I_Layout.h"
#include "mgmtapi.h"
-#include "CfgContextImpl.h"
-#include "CfgContextUtils.h"
#include "CoreAPI.h"
#include "CoreAPIShared.h"
@@ -254,31 +253,6 @@ TSIpAddrListIsEmpty(TSIpAddrList ip_addrl)
return queue_is_empty((LLQ *)ip_addrl);
}
-// returns false if any of the IpAddrEle is not an valid IP address by making
-// use of ccu_checkIpAddrEle; if return false, the ip's may be reordered
-// from the original list
-tsapi bool
-TSIpAddrListIsValid(TSIpAddrList ip_addrl)
-{
- int i, len;
- TSIpAddrEle *ele;
-
- if (!ip_addrl) {
- return false;
- }
-
- len = queue_len((LLQ *)ip_addrl);
- for (i = 0; i < len; i++) {
- ele = (TSIpAddrEle *)dequeue((LLQ *)ip_addrl);
- if (!ccu_checkIpAddrEle(ele)) {
- enqueue((LLQ *)ip_addrl, ele);
- return false;
- }
- enqueue((LLQ *)ip_addrl, ele);
- }
- return true;
-}
-
/*--- TSPortList operations ----------------------------------------------*/
tsapi TSPortList
TSPortListCreate()
@@ -361,31 +335,6 @@ TSPortListIsEmpty(TSPortList portl)
return queue_is_empty((LLQ *)portl);
}
-// returns false if any of the PortEle's has a port_a <= 0;
-// if returns false, then will return the entire port list
-// intact, although the ports may not be ordered in the same way
-tsapi bool
-TSPortListIsValid(TSPortList portl)
-{
- int i, len;
- TSPortEle *ele;
-
- if (!portl) {
- return false;
- }
-
- len = queue_len((LLQ *)portl);
- for (i = 0; i < len; i++) {
- ele = (TSPortEle *)dequeue((LLQ *)portl);
- if (!ccu_checkPortEle(ele)) {
- enqueue((LLQ *)portl, ele);
- return false;
- }
- enqueue((LLQ *)portl, ele);
- }
- return true;
-}
-
/*--- TSDomainList operations -----------------------------------------*/
tsapi TSDomainList
TSDomainListCreate()
@@ -1747,13 +1696,6 @@ TSGetErrorMessage(TSMgmtError err_id)
return err_msg;
}
-/*--- direct file operations ----------------------------------------------*/
-tsapi TSMgmtError
-TSConfigFileRead(TSFileNameT file, char **text, int *size, int *version)
-{
- return ReadFile(file, text, size, version);
-}
-
/* ReadFromUrl: reads a remotely located config file into a buffer
* Input: url - remote location of the file
* header - a buffer is allocated on the header char* pointer
@@ -2115,20 +2057,6 @@ TSEventSignalCbUnregister(char *event_name, TSEventSignalFunc func)
return EventSignalCbUnregister(event_name, func);
}
-/* checks if the fields in the ele are all valid */
-bool
-TSIsValid(TSCfgEle *ele)
-{
- CfgEleObj *ele_obj;
-
- if (!ele) {
- return false;
- }
-
- ele_obj = create_ele_obj_from_ele(ele);
- return (ele_obj->isValid());
-}
-
TSConfigRecordDescription *
TSConfigRecordDescriptionCreate(void)
{
diff --git a/mgmt/api/Makefile.am b/mgmt/api/Makefile.am
index d5385e5..e9c8357 100644
--- a/mgmt/api/Makefile.am
+++ b/mgmt/api/Makefile.am
@@ -34,10 +34,6 @@ noinst_LTLIBRARIES = libmgmtapilocal.la libmgmtapi.la
lib_LTLIBRARIES = libtsmgmt.la
libmgmtapi_la_SOURCES = \
- CfgContextImpl.cc \
- CfgContextImpl.h \
- CfgContextUtils.cc \
- CfgContextUtils.h \
CoreAPI.h \
CoreAPIShared.cc \
CoreAPIShared.h \
@@ -55,7 +51,6 @@ if BUILD_TESTS
endif
libmgmtapilocal_la_SOURCES = \
- CfgContextDefs.h \
CoreAPI.cc \
EventControlMain.cc \
EventControlMain.h \
diff --git a/mgmt/api/NetworkMessage.cc b/mgmt/api/NetworkMessage.cc
index 808e9ed..c7b244b 100644
--- a/mgmt/api/NetworkMessage.cc
+++ b/mgmt/api/NetworkMessage.cc
@@ -38,7 +38,6 @@ struct NetCmdOperation {
// Requests always begin with a OpType, followed by aditional fields.
static const struct NetCmdOperation requests[] = {
- /* FILE_READ */ {2, {MGMT_MARSHALL_INT, MGMT_MARSHALL_INT}},
/* RECORD_SET */ {3, {MGMT_MARSHALL_INT, MGMT_MARSHALL_STRING, MGMT_MARSHALL_STRING}},
/* RECORD_GET */ {2, {MGMT_MARSHALL_INT, MGMT_MARSHALL_STRING}},
/* PROXY_STATE_GET */ {1, {MGMT_MARSHALL_INT}},
@@ -64,7 +63,6 @@ static const struct NetCmdOperation requests[] = {
// Responses always begin with a TSMgmtError code, followed by additional fields.
static const struct NetCmdOperation responses[] = {
- /* FILE_READ */ {3, {MGMT_MARSHALL_INT, MGMT_MARSHALL_INT, MGMT_MARSHALL_DATA}},
/* RECORD_SET */ {2, {MGMT_MARSHALL_INT, MGMT_MARSHALL_INT}},
/* RECORD_GET */
{5, {MGMT_MARSHALL_INT, MGMT_MARSHALL_INT, MGMT_MARSHALL_INT, MGMT_MARSHALL_STRING, MGMT_MARSHALL_DATA}},
@@ -213,10 +211,6 @@ send_mgmt_error(int fd, OpType optype, TSMgmtError error)
ink_release_assert(responses[static_cast<unsigned>(optype)].nfields == 2);
return send_mgmt_response(fd, optype, &ecode, &strval);
- case OpType::FILE_READ:
- ink_release_assert(responses[static_cast<unsigned>(optype)].nfields == 3);
- return send_mgmt_response(fd, optype, &ecode, &intval, &dataval);
-
case OpType::RECORD_GET:
case OpType::RECORD_MATCH_GET:
ink_release_assert(responses[static_cast<unsigned>(optype)].nfields == 5);
diff --git a/mgmt/api/NetworkMessage.h b/mgmt/api/NetworkMessage.h
index a133882..45b5213 100644
--- a/mgmt/api/NetworkMessage.h
+++ b/mgmt/api/NetworkMessage.h
@@ -33,7 +33,6 @@
// the possible operations or msg types sent from remote client to TM
enum class OpType : MgmtMarshallInt {
- FILE_READ,
RECORD_SET,
RECORD_GET,
PROXY_STATE_GET,
diff --git a/mgmt/api/TSControlMain.cc b/mgmt/api/TSControlMain.cc
index a499ad8..841947d 100644
--- a/mgmt/api/TSControlMain.cc
+++ b/mgmt/api/TSControlMain.cc
@@ -500,45 +500,6 @@ fail:
}
/**************************************************************************
- * handle_file_read
- *
- * purpose: handles request to read a file
- * output: SUCC or ERR
- * note: None
- *************************************************************************/
-static TSMgmtError
-handle_file_read(int fd, void *req, size_t reqlen)
-{
- int size, version;
- char *text;
-
- MgmtMarshallInt optype;
- MgmtMarshallInt fid;
-
- MgmtMarshallInt err;
- MgmtMarshallInt vers = 0;
- MgmtMarshallData data = {nullptr, 0};
-
- err = recv_mgmt_request(req, reqlen, OpType::FILE_READ, &optype, &fid);
- if (err != TS_ERR_OKAY) {
- return (TSMgmtError)err;
- }
-
- // make CoreAPI call on Traffic Manager side
- err = ReadFile((TSFileNameT)fid, &text, &size, &version);
- if (err == TS_ERR_OKAY) {
- vers = version;
- data.ptr = text;
- data.len = size;
- }
-
- err = send_mgmt_response(fd, OpType::FILE_READ, &err, &vers, &data);
-
- ats_free(text); // free memory allocated by ReadFile
- return (TSMgmtError)err;
-}
-
-/**************************************************************************
* handle_proxy_state_get
*
* purpose: handles request to get the state of the proxy (TS)
@@ -988,7 +949,6 @@ struct control_message_handler {
};
static const control_message_handler handlers[] = {
- /* FILE_READ */ {MGMT_API_PRIVILEGED, handle_file_read},
/* RECORD_SET */ {MGMT_API_PRIVILEGED, handle_record_set},
/* RECORD_GET */ {0, handle_record_get},
/* PROXY_STATE_GET */ {0, handle_proxy_state_get},
diff --git a/mgmt/api/include/mgmtapi.h b/mgmt/api/include/mgmtapi.h
index f3b7f1c..6dbea26 100644
--- a/mgmt/api/include/mgmtapi.h
+++ b/mgmt/api/include/mgmtapi.h
@@ -124,9 +124,6 @@ typedef TSHandle TSDomainList; /* contains TSDomain *'s */
typedef TSHandle TSStringList; /* contains char* 's */
typedef TSHandle TSIntList; /* contains int* 's */
-typedef TSHandle TSCfgContext;
-typedef TSHandle TSCfgIterState;
-
/*--- basic control operations --------------------------------------------*/
typedef enum {
@@ -641,7 +638,6 @@ tsapi TSIpAddrEle *TSIpAddrListDequeue(TSIpAddrList ip_addrl);
tsapi int TSIpAddrListLen(TSIpAddrList ip_addrl);
tsapi bool TSIpAddrListIsEmpty(TSIpAddrList ip_addrl);
tsapi int TSIpAddrListLen(TSIpAddrList ip_addrl);
-tsapi bool TSIpAddrListIsValid(TSIpAddrList ip_addrl);
/*--- TSPortList operations ----------------------------------------------*/
tsapi TSPortList TSPortListCreate();
@@ -650,7 +646,6 @@ tsapi TSMgmtError TSPortListEnqueue(TSPortList portl, TSPortEle *port);
tsapi TSPortEle *TSPortListDequeue(TSPortList portl);
tsapi bool TSPortListIsEmpty(TSPortList portl);
tsapi int TSPortListLen(TSPortList portl);
-tsapi bool TSPortListIsValid(TSPortList portl);
/*--- TSStringList operations --------------------------------------------*/
tsapi TSStringList TSStringListCreate();
@@ -735,13 +730,6 @@ tsapi TSSplitDnsEle *TSSplitDnsEleCreate();
tsapi void TSSplitDnsEleDestroy(TSSplitDnsEle *ele);
tsapi TSStorageEle *TSStorageEleCreate();
tsapi void TSStorageEleDestroy(TSStorageEle *ele);
-/*--- Ele helper operations -------------------------------------*/
-
-/* TSIsValid: checks if the fields in the ele are all valid
- * Input: ele - the ele to check (typecast any of the TSxxxEle's to an TSCfgEle)
- * Output: true if ele has valid fields for its rule type, false otherwise
- */
-bool TSIsValid(TSCfgEle *ele);
/***************************************************************************
* API Core
@@ -847,15 +835,6 @@ tsapi TSMgmtError TSLifecycleMessage(const char *tag, void const *data, size_t d
*/
char *TSGetErrorMessage(TSMgmtError error_id);
-/*--- direct file operations ----------------------------------------------*/
-/* TSConfigFileRead: reads a config file into a buffer
- * Input: file - the config file to read
- * text - a buffer is allocated on the text char* pointer
- * size - the size of the buffer is returned
- * Output: TSMgmtError
- */
-tsapi TSMgmtError TSConfigFileRead(TSFileNameT file, char **text, int *size, int *version);
-
/* TSReadFromUrl: reads a remotely located config file into a buffer
* Input: url - remote location of the file
* header - a buffer is allocated on the header char* pointer
@@ -1022,12 +1001,6 @@ tsapi TSMgmtError TSEventSignalCbRegister(char *event_name, TSEventSignalFunc fu
*/
tsapi TSMgmtError TSEventSignalCbUnregister(char *event_name, TSEventSignalFunc func);
-/*--- TSCfgContext Operations --------------------------------------------*/
-/*
- * These operations are used to manipulate the opaque TSCfgContext type,
- * eg. when want to modify a file
- */
-
/*--- TS Cache Inspector Operations --------------------------------------------*/
/* TSLookupFromCacheUrl
--
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.