32 #include <sys/socket.h>
73 std::string open_url = ConstructFinalUrl(url);
74 st = pFile->
Open(open_url, flags, mode, handler, timeout);
87 ProxyPrefixFile::GetPrefixUrl()
const
89 std::string url_prefix = (getenv(
"XROOT_PROXY") ? getenv(
"XROOT_PROXY") :
"");
92 if (url_prefix.empty()) {
93 url_prefix = (getenv(
"xroot_proxy") ? getenv(
"xroot_proxy") :
"");
103 ProxyPrefixFile::trim(
const std::string& in)
const
105 std::string::const_iterator wsfront, wsback;
106 std::string::const_reverse_iterator rwsback;
107 wsfront = in.begin();
108 rwsback = in.rbegin();
110 while (*wsfront ==
' ') {
114 while (*rwsback ==
' ') {
118 wsback = rwsback.base();
119 return (wsback <= wsfront ? std::string() : std::string(wsfront, wsback));
132 std::list<std::string>
133 ProxyPrefixFile::GetExclDomains()
const
135 std::string excl_domains = (getenv(
"XROOT_PROXY_EXCL_DOMAINS") ?
136 getenv(
"XROOT_PROXY_EXCL_DOMAINS") :
"");
138 if (excl_domains.empty()) {
139 return std::list<std::string>();
144 std::list<std::string> lst;
145 std::stringstream ss(excl_domains);
147 while (
getline(ss, item, delim)) {
148 lst.push_back(trim(item));
158 ProxyPrefixFile::ConstructFinalUrl(
const std::string& orig_surl)
const
160 std::string final_surl = orig_surl;
161 std::string url_prefix = GetPrefixUrl();
163 log->
Debug(1,
"url=%s, prefix_url=%s", orig_surl.c_str(), url_prefix.c_str());
165 if (!url_prefix.empty()) {
166 bool exclude =
false;
167 std::list<std::string> lst_excl = GetExclDomains();
169 std::string orig_host = orig_url.GetHostId();
171 size_t pos = orig_host.find(
':');
173 if (pos != std::string::npos) {
174 orig_host = orig_host.substr(0, pos);
177 orig_host = GetFqdn(orig_host);
179 for (std::list<std::string>::iterator it_excl = lst_excl.begin();
180 it_excl != lst_excl.end(); ++it_excl) {
181 if (url_prefix.size() < it_excl->size()) {
185 if (std::equal(it_excl->rbegin(), it_excl->rend(), orig_host.rbegin())) {
192 final_surl.insert(0, url_prefix);
196 log->
Debug(1,
"final_url=%s", final_surl.c_str());
204 ProxyPrefixFile::GetFqdn(
const std::string& hostname)
const
207 std::string fqdn = hostname;
208 struct addrinfo hints, *info;
210 memset(&hints, 0,
sizeof hints);
211 hints.ai_family = AF_UNSPEC;
212 hints.ai_socktype = SOCK_STREAM;
213 hints.ai_flags = AI_CANONNAME;
215 if ((gai_result = getaddrinfo(hostname.c_str(), NULL, &hints, &info)) != 0) {
216 log->
Error(1,
"getaddrinfo: %s", gai_strerror(gai_result));
221 fqdn = info->ai_canonname;
void getline(uchar *buff, int blen)
XRootDStatus Open(const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
void Error(uint64_t topic, const char *format,...)
Report an error.
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
Handle an async response.
ProxyPrefixFile()
Constructor.
virtual XRootDStatus Open(const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, uint16_t timeout) override
Open.
virtual ~ProxyPrefixFile() override
Destructor.
const uint16_t stError
An error occurred that could potentially be retried.
const uint16_t errInvalidOp
Flags
Open flags, may be or'd when appropriate.
bool IsOK() const
We're fine.