This is an automated email from the ASF dual-hosted git repository. bcall pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push: new a89fb08 allow regex_revalidate per remap rule, remove direct ink includes a89fb08 is described below commit a89fb08794d0ffa00cf07e0825e55dcb9616bb22 Author: Brian Olsen <brian_ols...@comcast.com> AuthorDate: Mon Oct 22 19:49:32 2018 +0000 allow regex_revalidate per remap rule, remove direct ink includes --- doc/admin-guide/plugins/regex_revalidate.en.rst | 5 +- plugins/regex_revalidate/regex_revalidate.c | 167 ++++++++++++++++++------ 2 files changed, 129 insertions(+), 43 deletions(-) diff --git a/doc/admin-guide/plugins/regex_revalidate.en.rst b/doc/admin-guide/plugins/regex_revalidate.en.rst index a24fbee..5074882 100644 --- a/doc/admin-guide/plugins/regex_revalidate.en.rst +++ b/doc/admin-guide/plugins/regex_revalidate.en.rst @@ -24,7 +24,8 @@ Regex Revalidate Plugin This plugin allows for the creation of rules which match regular expressions against mapped URLs to determine if and when a cache object revalidation should -be forced. +be forced. This plugin can be used both globally and for individual remap +rules. Purpose ======= @@ -60,7 +61,7 @@ The rule configuration file format is described below in `Revalidation Rules`_. By default The plugin regularly (every 60 seconds) checks its rules configuration file for changes and it will also check for changes when ``traffic_ctl config reload`` -is run. If the file has been modified since its last scan, the contents +is run. If the file has been modified since its last scan, the contents are read and the in-memory rules list is updated. Thus, new rules may be added and existing ones modified without requiring a service restart. diff --git a/plugins/regex_revalidate/regex_revalidate.c b/plugins/regex_revalidate/regex_revalidate.c index 4b009df..56713ea 100644 --- a/plugins/regex_revalidate/regex_revalidate.c +++ b/plugins/regex_revalidate/regex_revalidate.c @@ -19,8 +19,8 @@ limitations under the License. */ -#include "tscore/ink_defs.h" -#include "tscore/ink_platform.h" +#include "ts/ts.h" +#include "ts/remap.h" #include <stdlib.h> #include <stdio.h> @@ -59,6 +59,13 @@ ts_free(void *s) return TSfree(s); } +static void +setup_memory_allocation() +{ + pcre_malloc = &ts_malloc; + pcre_free = &ts_free; +} + typedef struct invalidate_t { const char *regex_text; pcre *regex; @@ -331,7 +338,7 @@ list_config(plugin_state_t *pstate, invalidate_t *i) } static int -free_handler(TSCont cont, TSEvent event ATS_UNUSED, void *edata ATS_UNUSED) +free_handler(TSCont cont, TSEvent event, void *edata) { invalidate_t *iptr; @@ -343,7 +350,7 @@ free_handler(TSCont cont, TSEvent event ATS_UNUSED, void *edata ATS_UNUSED) } static int -config_handler(TSCont cont, TSEvent event ATS_UNUSED, void *edata ATS_UNUSED) +config_handler(TSCont cont, TSEvent event, void *edata) { plugin_state_t *pstate; invalidate_t *i, *iptr; @@ -453,44 +460,23 @@ main_handler(TSCont cont, TSEvent event, void *edata) return 0; } -static bool -check_ts_version() +TSRemapStatus +TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) { - const char *ts_version = TSTrafficServerVersionGet(); + TSCont main_cont = NULL; - if (ts_version) { - int major_ts_version = 0; - int minor_ts_version = 0; - int micro_ts_version = 0; - - if (sscanf(ts_version, "%d.%d.%d", &major_ts_version, &minor_ts_version, µ_ts_version) != 3) { - return false; - } - - if ((TS_VERSION_MAJOR == major_ts_version) && (TS_VERSION_MINOR == minor_ts_version) && - (TS_VERSION_MICRO == micro_ts_version)) { - return true; - } - } + main_cont = TSContCreate(main_handler, NULL); + TSContDataSet(main_cont, ih); + TSHttpTxnHookAdd(txnp, TS_HTTP_SEND_REQUEST_HDR_HOOK, main_cont); - return false; + return TSREMAP_NO_REMAP; } -void -TSPluginInit(int argc, const char *argv[]) +static bool +configure_plugin_state(plugin_state_t *pstate, int argc, const char **argv, bool *const disable_timed_reload) { - TSPluginRegistrationInfo info; - TSCont main_cont, config_cont; - plugin_state_t *pstate; - invalidate_t *iptr = NULL; - bool disable_timed_reload = false; - - TSDebug(LOG_PREFIX, "Starting plugin init"); - - pstate = (plugin_state_t *)TSmalloc(sizeof(plugin_state_t)); - init_plugin_state_t(pstate); - int c; + invalidate_t *iptr = NULL; static const struct option longopts[] = {{"config", required_argument, NULL, 'c'}, {"log", required_argument, NULL, 'l'}, {"disable-timed-reload", no_argument, NULL, 'd'}, @@ -500,16 +486,19 @@ TSPluginInit(int argc, const char *argv[]) switch (c) { case 'c': pstate->config_file = TSstrdup(optarg); + TSDebug(LOG_PREFIX, "Config File: %s", pstate->config_file); break; case 'l': if (TS_SUCCESS == TSTextLogObjectCreate(optarg, TS_LOG_MODE_ADD_TIMESTAMP, &pstate->log)) { TSTextLogObjectRollingEnabledSet(pstate->log, 1); TSTextLogObjectRollingIntervalSecSet(pstate->log, LOG_ROLL_INTERVAL); TSTextLogObjectRollingOffsetHrSet(pstate->log, LOG_ROLL_OFFSET); + TSDebug(LOG_PREFIX, "Logging Mode enabled"); } break; case 'd': - disable_timed_reload = true; + *disable_timed_reload = true; + TSDebug(LOG_PREFIX, "Timed reload disabled (disable-timed-reload)"); break; default: break; @@ -518,8 +507,7 @@ TSPluginInit(int argc, const char *argv[]) if (!pstate->config_file) { TSError("[regex_revalidate] Plugin requires a --config option along with a config file name"); - free_plugin_state_t(pstate); - return; + return false; } if (!load_config(pstate, &iptr)) { @@ -529,6 +517,104 @@ TSPluginInit(int argc, const char *argv[]) list_config(pstate, iptr); } + return true; +} + +TSReturnCode +TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int errbuf_size) +{ + TSCont config_cont = NULL; + plugin_state_t *pstate = NULL; + bool disable_timed_reload = false; + + TSDebug(LOG_PREFIX, "Starting remap init"); + pstate = (plugin_state_t *)TSmalloc(sizeof(plugin_state_t)); + init_plugin_state_t(pstate); + + if (!configure_plugin_state(pstate, argc - 1, (const char **)(argv + 1), &disable_timed_reload)) { + free_plugin_state_t(pstate); + TSError("[regex_revalidate] Remap plugin registration failed"); + return TS_ERROR; + } + + *ih = (void *)pstate; + + config_cont = TSContCreate(config_handler, TSMutexCreate()); + TSContDataSet(config_cont, (void *)pstate); + + TSMgmtUpdateRegister(config_cont, LOG_PREFIX); + + if (!disable_timed_reload) { + TSContSchedule(config_cont, CONFIG_TMOUT, TS_THREAD_POOL_TASK); + } + + TSDebug(LOG_PREFIX, "Remap plugin registration succeeded"); + + return TS_SUCCESS; +} + +void +TSRemapDeleteInstance(void *ih) +{ + if (NULL != ih) { + plugin_state_t *const pstate = (plugin_state_t *)ih; + free_plugin_state_t(pstate); + } +} + +static bool +check_ts_version() +{ + const char *ts_version = TSTrafficServerVersionGet(); + + if (ts_version) { + int major_ts_version = 0; + int minor_ts_version = 0; + int micro_ts_version = 0; + + if (sscanf(ts_version, "%d.%d.%d", &major_ts_version, &minor_ts_version, µ_ts_version) != 3) { + return false; + } + + if ((TS_VERSION_MAJOR == major_ts_version)) { + return true; + } + } + + return false; +} + +TSReturnCode +TSRemapInit(TSRemapInterface *api_info, char *errbug, int errbuf_size) +{ + setup_memory_allocation(); + + if (!check_ts_version()) { + TSError("[regex_revalidate] Plugin requires Traffic Server %d", TS_VERSION_MAJOR); + return TS_ERROR; + } + + return TS_SUCCESS; +} + +void +TSPluginInit(int argc, const char *argv[]) +{ + TSPluginRegistrationInfo info; + TSCont main_cont, config_cont; + plugin_state_t *pstate = NULL; + bool disable_timed_reload = false; + + TSDebug(LOG_PREFIX, "Starting plugin init"); + + pstate = (plugin_state_t *)TSmalloc(sizeof(plugin_state_t)); + init_plugin_state_t(pstate); + + if (!configure_plugin_state(pstate, argc, argv, &disable_timed_reload)) { + free_plugin_state_t(pstate); + return; + } + info.plugin_name = LOG_PREFIX; info.vendor_name = "Apache Software Foundation"; info.support_email = "d...@trafficserver.apache.org"; @@ -543,13 +629,12 @@ TSPluginInit(int argc, const char *argv[]) } if (!check_ts_version()) { - TSError("[regex_revalidate] Plugin requires Traffic Server %d.%d.%d", TS_VERSION_MAJOR, TS_VERSION_MINOR, TS_VERSION_MICRO); + TSError("[regex_revalidate] Plugin requires Traffic Server %d", TS_VERSION_MAJOR); free_plugin_state_t(pstate); return; } - pcre_malloc = &ts_malloc; - pcre_free = &ts_free; + setup_memory_allocation(); main_cont = TSContCreate(main_handler, NULL); TSContDataSet(main_cont, (void *)pstate);