#include <XrdXrootdRedirHelper.hh>
Public Types | |
| enum class | Outcome { Unchanged , Replaced , Error } |
Static Public Member Functions | |
| static void | Init (XrdXrootdRedirPI *pi, XrdSysError *eDest, int ipHold) |
| static bool | IsActive () |
| static bool | ParseURL (const char *url, std::string &urlHead, std::string &host, std::string &port, std::string &urlTail) |
| static Outcome | Redirect (const char *trg, int &port, XrdNetAddrInfo &clientAddr, std::string &outTarget, std::string &errMsg) |
| static void | SetClockForTesting (std::function< time_t()> nowFn) |
Process-wide adapter around the redirect plugin (XrdXrootdRedirPI) so the plugin can be invoked uniformly from the XRootD protocol and from any other subsystem that produces redirect targets (e.g. the HTTP TPC handler addressed by issue #2767).
Responsibilities centralised here so they do not need to be reproduced at every call site:
The class is non-instantiable; it is initialised once by Init() (called from XrdXrootdConfig.cc after the redirect plugin has been loaded) and its Redirect() static method is then invoked concurrently from any number of worker threads. When no plugin is configured IsActive() returns false and Redirect() is an inexpensive no-op.
Definition at line 59 of file XrdXrootdRedirHelper.hh.
|
strong |
Tri-state outcome returned by Redirect().
Mirrors the three cases of the plugin's return-string contract:
| Enumerator | |
|---|---|
| Unchanged | |
| Replaced | |
| Error | |
Definition at line 73 of file XrdXrootdRedirHelper.hh.
|
static |
Initialise the helper. Must be called exactly once, after the redirect plugin has been loaded and before any worker thread invokes Redirect(). Calling Init(nullptr, ...) is a valid no-op that simply disarms the helper.
| pi | pointer to the loaded redirect plugin, or nullptr if no plugin was loaded. When nullptr, IsActive() returns false and Redirect() always returns Unchanged. |
| eDest | logger used to report cache-population failures. Must not be nullptr when pi is non-null. |
| ipHold | number of seconds for which a successfully-resolved target XrdNetAddrInfo is reused before being refreshed. Mirrors XrdXrootdProtocol::redirIPHold. |
Definition at line 164 of file XrdXrootdRedirHelper.cc.
References eDest.
Referenced by XrdXrootdProtocol::Configure().
|
static |
Definition at line 176 of file XrdXrootdRedirHelper.cc.
|
static |
Parse a scheme://host[:port][/tail] redirect URL into its components.
Exposed as a static method, rather than kept private to the .cc, so the URL grammar Redirect() relies on for URL-form targets can be unit-tested directly without a plugin, the netaddr cache or DNS. Redirect() is its only production caller.
| url | URL to parse. Must not be nullptr. |
| urlHead | output: scheme prefix up to and including "://". |
| host | output: host name, with any ":port" suffix removed. |
| port | output: port string, or "" when no port is present. |
| urlTail | output: path/query tail including the leading '/', or "" when the URL has no path. |
url is not a parseable scheme://host[:port][/tail] URL; the output parameters are then left in an unspecified state. Definition at line 275 of file XrdXrootdRedirHelper.cc.
Referenced by Redirect().
|
static |
Run a redirect target through the redirect plugin.
Single entry point for both redirect forms; port selects which one, mirroring the calling convention of XrdXrootdProtocol::fsRedirPI():
port >= 0 : trg is a host[?cgi] target and port is its numeric port. The target is split internally (via splitHostCgi) and the plugin's Redirect() entry point is invoked; port is rewritten in place when the plugin asks for a different port.port < 0 : trg is a full scheme://host[:port][/tail] URL. It is parsed internally (via ParseURL) and the plugin's RedirectURL() entry point is invoked. Here port doubles as the plugin's rdrOpts argument; because it is also the protocol's URL marker it is passed to the plugin but left unmodified on return. A URL that cannot be parsed is logged and yields Outcome::Unchanged without invoking the plugin.Used by the XRootD protocol (fsRedirPI) for both forms and by the HTTP TPC handler (issue #2767), which only ever passes the host[?cgi] form.
| trg | redirect target: host[?cgi] when port >= 0, or a scheme://host[:port][/tail] URL when port < 0. A nullptr is tolerated defensively and yields Outcome::Unchanged without invoking the plugin. |
| port | in/out, doubling as the host-vs-URL selector; see the per-form description above. |
| clientAddr | network info of the client being redirected. |
| outTarget | output: when Replaced, holds the new redirect target. Untouched otherwise. |
| errMsg | output: when Error, holds the plugin's error message with the contract's leading '!' already stripped. Untouched otherwise. |
Definition at line 199 of file XrdXrootdRedirHelper.cc.
References XrdSysError::Emsg(), Error, ParseURL(), XrdXrootdRedirPI::Redirect(), XrdXrootdRedirPI::RedirectURL(), Replaced, splitHostCgi(), and Unchanged.
|
static |
====================== ONLY FOR TESTING, DO NOT USE ======================
Override the clock function used by the internal target-netaddr cache so unit tests can fast-forward past the ipHold expiry and exercise the refresh path of LookupTarget. Pass nullptr to restore the default clock (time(nullptr)).
| nowFn | function returning a time_t to be used in place of time(nullptr). Pass an empty function to restore the default. |
Definition at line 189 of file XrdXrootdRedirHelper.cc.