| /** @file | |
| A brief file description | |
| @par License | |
| Licensed to the Apache Software Foundation (ASF) under one | |
| or more contributor license agreements. See the NOTICE file | |
| distributed with this work for additional information | |
| regarding copyright ownership. The ASF licenses this file | |
| to you under the Apache License, Version 2.0 (the | |
| "License"); you may not use this file except in compliance | |
| with the License. You may obtain a copy of the License at | |
| http://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, software | |
| distributed under the License is distributed on an "AS IS" BASIS, | |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| See the License for the specific language governing permissions and | |
| limitations under the License. | |
| */ | |
| #pragma once | |
| #include <atomic> | |
| #include <string> | |
| #include <vector> | |
| #include "tscore/ink_config.h" | |
| #include "tsutil/Regex.h" | |
| #include "proxy/http/remap/AclFiltering.h" | |
| #include "proxy/hdrs/URL.h" | |
| #include "proxy/http/remap/RemapPluginInfo.h" | |
| #include "proxy/http/remap/PluginFactory.h" | |
| #include "tsutil/Regex.h" | |
| #include "tscore/List.h" | |
| class NextHopSelectionStrategy; | |
| class NextHopStrategyFactory; | |
| struct CacheHostRecord; | |
| /** | |
| * Used to store http referrer strings (and/or regexp) | |
| **/ | |
| class referer_info | |
| { | |
| public: | |
| referer_info(const char *_ref, bool *error_flag, char *errmsgbuf = nullptr, int errmsgbuf_size = 0); | |
| ~referer_info(); | |
| referer_info *next = nullptr; | |
| char *referer = nullptr; | |
| int referer_size = 0; | |
| bool any = false; /* any flag '*' */ | |
| bool negative = false; /* negative referer '~' */ | |
| bool regex_valid = false; | |
| Regex regex; | |
| }; | |
| /** | |
| * | |
| **/ | |
| class redirect_tag_str | |
| { | |
| public: | |
| redirect_tag_str() {} | |
| ~redirect_tag_str() | |
| { | |
| type = 0; | |
| ats_free(chunk_str); | |
| chunk_str = nullptr; | |
| } | |
| redirect_tag_str *next = nullptr; | |
| char *chunk_str = nullptr; | |
| char type = 0; /* s - string, r - referer, t - url_to, f - url_from, o - origin url */ | |
| static redirect_tag_str *parse_format_redirect_url(char *url); | |
| }; | |
| /** | |
| * Used to store the mapping for class UrlRewrite | |
| **/ | |
| class url_mapping | |
| { | |
| public: | |
| ~url_mapping(); | |
| bool add_plugin_instance(RemapPluginInst *i); | |
| RemapPluginInst *get_plugin_instance(std::size_t) const; | |
| std::size_t | |
| plugin_instance_count() const | |
| { | |
| return _plugin_inst_list.size(); | |
| } | |
| void Print() const; | |
| int from_path_len = 0; | |
| URL fromURL; | |
| URL toURL; // Default TO-URL (from remap.config) | |
| bool homePageRedirect = false; | |
| bool unique = false; // INKqa11970 - unique mapping | |
| bool default_redirect_url = false; | |
| bool optional_referer = false; | |
| bool negative_referer = false; | |
| bool wildcard_from_scheme = false; // from url is '/foo', only http or https for now | |
| char *tag = nullptr; // tag | |
| char *filter_redirect_url = nullptr; // redirect url when referer filtering enabled | |
| unsigned int map_id = 0; | |
| referer_info *referer_list = nullptr; | |
| redirect_tag_str *redir_chunk_list = nullptr; | |
| bool ip_allow_check_enabled_p = false; | |
| acl_filter_rule *filter = nullptr; // acl filtering (linked list of rules) | |
| LINK(url_mapping, link); // For use with the main Queue linked list holding all the mapping | |
| NextHopSelectionStrategy *strategy = nullptr; | |
| NextHopStrategyFactory *strategyFactory = nullptr; // not owned, belongs to the UrlRewrite holding this rule | |
| std::atomic<CacheHostRecord *> volume_host_rec = nullptr; | |
| // The rule whose plugins are loading on this thread. Accessors rather than a | |
| // thread_local member so libtsapi never references TLS across the library boundary. | |
| static url_mapping *loading_instance(); | |
| static void set_loading_instance(url_mapping *um); | |
| CacheHostRecord * | |
| getVolumeHostRec() const | |
| { | |
| return volume_host_rec.load(std::memory_order_acquire); | |
| } | |
| void | |
| setVolume(const char *str) | |
| { | |
| if (str && *str) { | |
| _volume_str = str; | |
| } | |
| } | |
| const std::string & | |
| getVolume() const | |
| { | |
| return _volume_str; | |
| } | |
| int | |
| getRank() const | |
| { | |
| return _rank; | |
| } | |
| void | |
| setRank(int rank) | |
| { | |
| _rank = rank; | |
| } | |
| bool initVolumeHostRec(char *errbuf, size_t errbufsize); | |
| private: | |
| std::vector<RemapPluginInst *> _plugin_inst_list; | |
| int _rank = 0; | |
| std::string _volume_str; | |
| }; | |
| /** | |
| * Installs @a um as the thread's loading url_mapping, restoring the previous value on scope exit. | |
| **/ | |
| class UrlMappingInstanceScope | |
| { | |
| url_mapping *_prev; | |
| public: | |
| explicit UrlMappingInstanceScope(url_mapping *um) : _prev(url_mapping::loading_instance()) | |
| { | |
| url_mapping::set_loading_instance(um); | |
| } | |
| ~UrlMappingInstanceScope() { url_mapping::set_loading_instance(_prev); } | |
| UrlMappingInstanceScope(UrlMappingInstanceScope const &) = delete; | |
| UrlMappingInstanceScope &operator=(UrlMappingInstanceScope const &) = delete; | |
| }; | |
| /** | |
| * UrlMappingContainer wraps a url_mapping object and allows a caller to rewrite the target URL. | |
| * This is used while evaluating remap rules. | |
| **/ | |
| class UrlMappingContainer | |
| { | |
| public: | |
| UrlMappingContainer() {} | |
| explicit UrlMappingContainer(HdrHeap *heap) : _heap(heap) {} | |
| ~UrlMappingContainer() { deleteToURL(); } | |
| URL * | |
| getToURL() const | |
| { | |
| return _toURLPtr; | |
| }; | |
| URL * | |
| getFromURL() const | |
| { | |
| return _mapping ? &(_mapping->fromURL) : nullptr; | |
| }; | |
| url_mapping * | |
| getMapping() const | |
| { | |
| return _mapping; | |
| }; | |
| void | |
| set(url_mapping *m) | |
| { | |
| deleteToURL(); | |
| _mapping = m; | |
| _toURLPtr = m ? &(m->toURL) : nullptr; | |
| } | |
| void | |
| set(HdrHeap *heap) | |
| { | |
| _heap = heap; | |
| } | |
| URL * | |
| createNewToURL() | |
| { | |
| ink_assert(_heap != nullptr); | |
| deleteToURL(); | |
| _toURL.create(_heap); | |
| _toURLPtr = &_toURL; | |
| return _toURLPtr; | |
| } | |
| void | |
| deleteToURL() | |
| { | |
| if (_toURLPtr == &_toURL) { | |
| _toURL.clear(); | |
| } | |
| } | |
| void | |
| clear() | |
| { | |
| deleteToURL(); | |
| _mapping = nullptr; | |
| _toURLPtr = nullptr; | |
| _heap = nullptr; | |
| } | |
| // noncopyable, non-assignable | |
| UrlMappingContainer(const UrlMappingContainer &orig) = delete; | |
| UrlMappingContainer &operator=(const UrlMappingContainer &rhs) = delete; | |
| private: | |
| url_mapping *_mapping = nullptr; | |
| URL *_toURLPtr = nullptr; | |
| URL _toURL; | |
| HdrHeap *_heap = nullptr; | |
| }; |