XRootD
Loading...
Searching...
No Matches
XrdTpcTPC.cc
Go to the documentation of this file.
4#include "XrdOuc/XrdOucEnv.hh"
8#include "XrdSys/XrdSysFD.hh"
9#include "XrdVersion.hh"
10
13#include "XrdTpc/XrdTpcUtils.hh"
14
15#include <curl/curl.h>
16
17#include <dlfcn.h>
18#include <fcntl.h>
19
20#include <algorithm>
21#include <memory>
22#include <sstream>
23#include <stdexcept>
24#include <thread>
25#include <iostream> // Delete later!!!
26
27#include "XrdTpcState.hh"
28#include "XrdTpcStream.hh"
29#include "XrdTpcTPC.hh"
30#include "XrdTpcCurlMulti.hh"
31#include <fstream>
32
33using namespace TPC;
34
35XrdXrootdTpcMon* TPCHandler::TPCLogRecord::tpcMonitor = 0;
36
37uint64_t TPCHandler::m_monid{0};
38int TPCHandler::m_marker_period = 5;
39size_t TPCHandler::m_block_size = 16*1024*1024;
40size_t TPCHandler::m_small_block_size = 1*1024*1024;
41XrdSysMutex TPCHandler::m_monid_mutex;
42
44
45/******************************************************************************/
46/* T P C H a n d l e r : : T P C L o g R e c o r d D e s t r u c t o r */
47/******************************************************************************/
48
49TPCHandler::TPCLogRecord::~TPCLogRecord()
50{
51// Record monitoring data is enabled
52//
53 if (tpcMonitor)
55
56 monInfo.clID = clID.c_str();
57 monInfo.begT = begT;
58 gettimeofday(&monInfo.endT, 0);
59
60 if (mTpcType == TpcType::Pull)
61 {monInfo.dstURL = local.c_str();
62 monInfo.srcURL = remote.c_str();
63 } else {
64 monInfo.dstURL = remote.c_str();
65 monInfo.srcURL = local.c_str();
67 }
68
69 if (!status) monInfo.endRC = 0;
70 else if (tpc_status > 0) monInfo.endRC = tpc_status;
71 else monInfo.endRC = 1;
72 monInfo.strm = static_cast<unsigned char>(streams);
73 monInfo.fSize = (bytes_transferred < 0 ? 0 : bytes_transferred);
74 if (!isIPv6) monInfo.opts |= XrdXrootdTpcMon::TpcInfo::isIPv4;
75
76 tpcMonitor->Report(monInfo);
77 }
78}
79
80/******************************************************************************/
81/* C u r l D e l e t e r : : o p e r a t o r ( ) */
82/******************************************************************************/
83
85{
86 if (curl) curl_easy_cleanup(curl);
87}
88
89/******************************************************************************/
90/* s o c k o p t _ s e t c l o e x e c _ c a l l b a c k */
91/******************************************************************************/
92
101int TPCHandler::sockopt_callback(void *clientp, curl_socket_t curlfd, curlsocktype purpose) {
102 TPCLogRecord * rec = (TPCLogRecord *)clientp;
103 if (purpose == CURLSOCKTYPE_IPCXN && rec && rec->pmarkManager.isEnabled()) {
104 // We will not reach this callback if the corresponding socket could not have been connected
105 // the socket is already connected only if the packet marking is enabled
106 return CURL_SOCKOPT_ALREADY_CONNECTED;
107 }
108 return CURL_SOCKOPT_OK;
109}
110
111/******************************************************************************/
112/* o p e n s o c k e t _ c a l l b a c k */
113/******************************************************************************/
114
115
120int TPCHandler::opensocket_callback(void *clientp,
121 curlsocktype purpose,
122 struct curl_sockaddr *aInfo)
123{
124 //Return a socket file descriptor (note the clo_exec flag will be set).
125 int fd = XrdSysFD_Socket(aInfo->family, aInfo->socktype, aInfo->protocol);
126 // See what kind of address will be used to connect
127 //
128 if(fd < 0) {
129 return CURL_SOCKET_BAD;
130 }
131 TPCLogRecord * rec = (TPCLogRecord *)clientp;
132 if (purpose == CURLSOCKTYPE_IPCXN && clientp)
133 {XrdNetAddr thePeer(&(aInfo->addr));
134 rec->isIPv6 = (thePeer.isIPType(XrdNetAddrInfo::IPv6)
135 && !thePeer.isMapped());
136 std::stringstream connectErrMsg;
137
138 if(!rec->pmarkManager.connect(fd, &(aInfo->addr), aInfo->addrlen, CONNECT_TIMEOUT, connectErrMsg)) {
139 rec->m_log->Emsg(rec->log_prefix.c_str(),"Unable to connect socket:", connectErrMsg.str().c_str());
140 return CURL_SOCKET_BAD;
141 }
142 }
143
144 return fd;
145}
146
147int TPCHandler::closesocket_callback(void *clientp, curl_socket_t fd) {
148 TPCLogRecord * rec = (TPCLogRecord *)clientp;
149
150 // Destroy the PMark handle associated to the file descriptor before closing it.
151 // Otherwise, we would lose the socket usage information if the socket is closed before
152 // the PMark handle is closed.
153 rec->pmarkManager.endPmark(fd);
154
155 return close(fd);
156}
157
158/******************************************************************************/
159/* p r e p a r e U R L */
160/******************************************************************************/
161
162// See XrdTpcUtils::prepareOpenURL() documentation
163std::string TPCHandler::prepareURL(XrdHttpExtReq &req) {
164 return XrdTpcUtils::prepareOpenURL(req.resource, req.headers,hdr2cgimap);
165}
166
167/******************************************************************************/
168/* e n c o d e _ x r o o t d _ o p a q u e _ t o _ u r i */
169/******************************************************************************/
170
171// When processing a redirection from the filesystem layer, it is permitted to return
172// some xrootd opaque data. The quoting rules for xrootd opaque data are significantly
173// more permissive than a URI (basically, only '&' and '=' are disallowed while some
174// URI parsers may dislike characters like '"'). This function takes an opaque string
175// (e.g., foo=1&bar=2&baz=") and makes it safe for all URI parsers.
176std::string encode_xrootd_opaque_to_uri(CURL *curl, const std::string &opaque)
177{
178 std::stringstream parser(opaque);
179 std::string sequence;
180 std::stringstream output;
181 bool first = true;
182 while (getline(parser, sequence, '&')) {
183 if (sequence.empty()) {continue;}
184 size_t equal_pos = sequence.find('=');
185 char *val = NULL;
186 if (equal_pos != std::string::npos)
187 val = curl_easy_escape(curl, sequence.c_str() + equal_pos + 1, sequence.size() - equal_pos - 1);
188 // Do not emit parameter if value exists and escaping failed.
189 if (!val && equal_pos != std::string::npos) {continue;}
190
191 if (!first) output << "&";
192 first = false;
193 output << sequence.substr(0, equal_pos);
194 if (val) {
195 output << "=" << val;
196 curl_free(val);
197 }
198 }
199 return output.str();
200}
201
202/******************************************************************************/
203/* T P C H a n d l e r : : C o n f i g u r e C u r l C A */
204/******************************************************************************/
205
206void
207TPCHandler::ConfigureCurlCA(CURL *curl)
208{
209 auto ca_filename = m_ca_file ? m_ca_file->CAFilename() : "";
210 auto crl_filename = m_ca_file ? m_ca_file->CRLFilename() : "";
211 if (!ca_filename.empty() && !crl_filename.empty()) {
212 curl_easy_setopt(curl, CURLOPT_CAINFO, ca_filename.c_str());
213 //Check that the CRL file contains at least one entry before setting this option to curl
214 //Indeed, an empty CRL file will make curl unhappy and therefore will fail
215 //all HTTP TPC transfers (https://github.com/xrootd/xrootd/issues/1543)
216 std::ifstream in(crl_filename, std::ifstream::ate | std::ifstream::binary);
217 if(in.tellg() > 0 && m_ca_file->atLeastOneValidCRLFound()){
218 curl_easy_setopt(curl, CURLOPT_CRLFILE, crl_filename.c_str());
219 } else {
220 std::ostringstream oss;
221 oss << "No valid CRL file has been found in the file " << crl_filename << ". Disabling CRL checking.";
222 m_log.Log(Warning,"TpcHandler",oss.str().c_str());
223 }
224 }
225 else if (!m_cadir.empty()) {
226 curl_easy_setopt(curl, CURLOPT_CAPATH, m_cadir.c_str());
227 }
228 if (!m_cafile.empty()) {
229 curl_easy_setopt(curl, CURLOPT_CAINFO, m_cafile.c_str());
230 }
231}
232
233
234bool TPCHandler::MatchesPath(const char *verb, const char *path) {
235 return !strcmp(verb, "COPY") || !strcmp(verb, "OPTIONS");
236}
237
238/******************************************************************************/
239/* P r e p a r e U R L */
240/******************************************************************************/
241
242static std::string PrepareURL(const std::string &input) {
243 if (!strncmp(input.c_str(), "davs://", 7)) {
244 return "https://" + input.substr(7);
245 }
246 return input;
247}
248
249/******************************************************************************/
250/* T P C H a n d l e r : : P r o c e s s R e q */
251/******************************************************************************/
252
254 if (req.verb == "OPTIONS") {
255 return ProcessOptionsReq(req);
256 }
257 auto header = XrdOucTUtils::caseInsensitiveFind(req.headers,"credential");
258 if (header != req.headers.end()) {
259 if (header->second != "none") {
260 m_log.Emsg("ProcessReq", "COPY requested an unsupported credential type: ", header->second.c_str());
261 return req.SendSimpleResp(400, NULL, NULL, "COPY requestd an unsupported Credential type", 0);
262 }
263 }
264 header = XrdOucTUtils::caseInsensitiveFind(req.headers,"source");
265 if (header != req.headers.end()) {
266 std::string src = PrepareURL(header->second);
267 return ProcessPullReq(src, req);
268 }
269 header = XrdOucTUtils::caseInsensitiveFind(req.headers,"destination");
270 if (header != req.headers.end()) {
271 return ProcessPushReq(header->second, req);
272 }
273 m_log.Emsg("ProcessReq", "COPY verb requested but no source or destination specified.");
274 return req.SendSimpleResp(400, NULL, NULL, "No Source or Destination specified", 0);
275}
276
277/******************************************************************************/
278/* T P C H a n d l e r D e s t r u c t o r */
279/******************************************************************************/
280
282 m_sfs = NULL;
283}
284
285/******************************************************************************/
286/* T P C H a n d l e r C o n s t r u c t o r */
287/******************************************************************************/
288
289TPCHandler::TPCHandler(XrdSysError *log, const char *config, XrdOucEnv *myEnv) :
290 m_desthttps(false),
291 m_fixed_route(false),
292 m_timeout(60),
293 m_first_timeout(120),
294 m_log(log->logger(), "TPC_"),
295 m_sfs(NULL)
296{
297 if (!Configure(config, myEnv)) {
298 throw std::runtime_error("Failed to configure the HTTP third-party-copy handler.");
299 }
300
301// Extract out the TPC monitoring object (we share it with xrootd).
302//
303 XrdXrootdGStream *gs = (XrdXrootdGStream*)myEnv->GetPtr("Tpc.gStream*");
304 if (gs)
305 TPCLogRecord::tpcMonitor = new XrdXrootdTpcMon("http",log->logger(),*gs);
306}
307
308/******************************************************************************/
309/* T P C H a n d l e r : : P r o c e s s O p t i o n s R e q */
310/******************************************************************************/
311
315int TPCHandler::ProcessOptionsReq(XrdHttpExtReq &req) {
316 return req.SendSimpleResp(200, NULL, (char *) "DAV: 1\r\nDAV: <http://apache.org/dav/propset/fs/1>\r\nAllow: HEAD,GET,PUT,PROPFIND,DELETE,OPTIONS,COPY", NULL, 0);
317}
318
319/******************************************************************************/
320/* T P C H a n d l e r : : G e t A u t h z */
321/******************************************************************************/
322
323std::string TPCHandler::GetAuthz(XrdHttpExtReq &req) {
324 std::string authz;
325 auto authz_header = XrdOucTUtils::caseInsensitiveFind(req.headers,"authorization");
326 if (authz_header != req.headers.end()) {
327 char * quoted_url = quote(authz_header->second.c_str());
328 std::stringstream ss;
329 ss << "authz=" << quoted_url;
330 free(quoted_url);
331 authz = ss.str();
332 }
333 return authz;
334}
335
336/******************************************************************************/
337/* T P C H a n d l e r : : R e d i r e c t T r a n s f e r */
338/******************************************************************************/
339
340int TPCHandler::RedirectTransfer(CURL *curl, const std::string &redirect_resource,
341 XrdHttpExtReq &req, XrdOucErrInfo &error, TPCLogRecord &rec)
342{
343 int port;
344 const char *ptr = error.getErrText(port);
345 if ((ptr == NULL) || (*ptr == '\0') || (port == 0)) {
346 rec.status = 500;
347 std::stringstream ss;
348 ss << "Internal error: redirect without hostname";
349 logTransferEvent(LogMask::Error, rec, "REDIRECT_INTERNAL_ERROR", ss.str());
350 return req.SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
351 }
352
353 // Construct redirection URL taking into consideration any opaque info
354 std::string rdr_info = ptr;
355 std::string host, opaque;
356 size_t pos = rdr_info.find('?');
357 host = rdr_info.substr(0, pos);
358
359 if (pos != std::string::npos) {
360 opaque = rdr_info.substr(pos + 1);
361 }
362
363 std::stringstream ss;
364 ss << "Location: http" << (m_desthttps ? "s" : "") << "://" << host << ":" << port << "/" << redirect_resource;
365
366 if (!opaque.empty()) {
367 ss << "?" << encode_xrootd_opaque_to_uri(curl, opaque);
368 }
369
370 rec.status = 307;
371 logTransferEvent(LogMask::Info, rec, "REDIRECT", ss.str());
372 return req.SendSimpleResp(rec.status, NULL, const_cast<char *>(ss.str().c_str()),
373 NULL, 0);
374}
375
376/******************************************************************************/
377/* T P C H a n d l e r : : O p e n W a i t S t a l l */
378/******************************************************************************/
379
380int TPCHandler::OpenWaitStall(XrdSfsFile &fh, const std::string &resource,
381 int mode, int openMode, const XrdSecEntity &sec,
382 const std::string &authz)
383{
384 int open_result;
385 while (1) {
386 int orig_ucap = fh.error.getUCap();
387 fh.error.setUCap(orig_ucap | XrdOucEI::uIPv64);
388 std::string opaque;
389 size_t pos = resource.find('?');
390 // Extract the path and opaque info from the resource
391 std::string path = resource.substr(0, pos);
392
393 if (pos != std::string::npos) {
394 opaque = resource.substr(pos + 1);
395 }
396
397 // Append the authz information if there are some
398 if(!authz.empty()) {
399 opaque += (opaque.empty() ? "" : "&");
400 opaque += authz;
401 }
402 open_result = fh.open(path.c_str(), mode, openMode, &sec, opaque.c_str());
403
404 if ((open_result == SFS_STALL) || (open_result == SFS_STARTED)) {
405 int secs_to_stall = fh.error.getErrInfo();
406 if (open_result == SFS_STARTED) {secs_to_stall = secs_to_stall/2 + 5;}
407 std::this_thread::sleep_for (std::chrono::seconds(secs_to_stall));
408 }
409 break;
410 }
411 return open_result;
412}
413
414/******************************************************************************/
415/* T P C H a n d l e r : : D e t e r m i n e X f e r S i z e */
416/******************************************************************************/
417
418
419
423int TPCHandler::DetermineXferSize(CURL *curl, XrdHttpExtReq &req, State &state,
424 bool &success, TPCLogRecord &rec, bool shouldReturnErrorToClient) {
425 success = false;
426 curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
427 // Set a custom timeout of 60 seconds (= CONNECT_TIMEOUT for convenience) for the HEAD request
428 curl_easy_setopt(curl, CURLOPT_TIMEOUT, CONNECT_TIMEOUT);
429 CURLcode res;
430 res = curl_easy_perform(curl);
431 //Immediately set the CURLOPT_NOBODY flag to 0 as we anyway
432 //don't want the next curl call to do be a HEAD request
433 curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
434 // Reset the CURLOPT_TIMEOUT to no timeout (default)
435 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 0L);
436 if (res == CURLE_HTTP_RETURNED_ERROR) {
437 std::stringstream ss;
438 ss << "Remote server failed request while fetching remote size";
439 std::stringstream ss2;
440 ss2 << ss.str() << ": " << curl_easy_strerror(res);
441 rec.status = 500;
442 logTransferEvent(LogMask::Error, rec, "SIZE_FAIL", ss2.str());
443 return shouldReturnErrorToClient ? req.SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec, res).c_str(), 0) : -1;
444 } else if (state.GetStatusCode() >= 400) {
445 std::stringstream ss;
446 ss << "Remote side " << req.clienthost << " failed with status code " << state.GetStatusCode() << " while fetching remote size";
447 rec.status = 500;
448 logTransferEvent(LogMask::Error, rec, "SIZE_FAIL", ss.str());
449 return shouldReturnErrorToClient ? req.SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0) : -1;
450 } else if (res) {
451 std::stringstream ss;
452 ss << "Internal transfer failure while fetching remote size";
453 std::stringstream ss2;
454 ss2 << ss.str() << " - HTTP library failed: " << curl_easy_strerror(res);
455 rec.status = 500;
456 logTransferEvent(LogMask::Error, rec, "SIZE_FAIL", ss2.str());
457 return shouldReturnErrorToClient ? req.SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec, res).c_str(), 0) : -1;
458 }
459 std::stringstream ss;
460 ss << "Successfully determined remote size for pull request: "
461 << state.GetContentLength();
462 logTransferEvent(LogMask::Debug, rec, "SIZE_SUCCESS", ss.str());
463 success = true;
464 return 0;
465}
466
467int TPCHandler::GetContentLengthTPCPull(CURL *curl, XrdHttpExtReq &req, uint64_t &contentLength, bool & success, TPCLogRecord &rec) {
468 State state(curl,req.tpcForwardCreds);
469 //Don't forget to copy the headers of the client's request before doing the HEAD call. Otherwise, if there is a need for authentication,
470 //it will fail
471 state.SetupHeaders(req);
472 int result;
473 //In case we cannot get the content length, we return the error to the client
474 if ((result = DetermineXferSize(curl, req, state, success, rec)) || !success) {
475 return result;
476 }
477 contentLength = state.GetContentLength();
478 return result;
479}
480
481/******************************************************************************/
482/* T P C H a n d l e r : : S e n d P e r f M a r k e r */
483/******************************************************************************/
484
485int TPCHandler::SendPerfMarker(XrdHttpExtReq &req, TPCLogRecord &rec, TPC::State &state) {
486 std::stringstream ss;
487 const std::string crlf = "\n";
488 ss << "Perf Marker" << crlf;
489 ss << "Timestamp: " << time(NULL) << crlf;
490 ss << "Stripe Index: 0" << crlf;
491 ss << "Stripe Bytes Transferred: " << state.BytesTransferred() << crlf;
492 ss << "Total Stripe Count: 1" << crlf;
493 // Include the TCP connection associated with this transfer; used by
494 // the TPC client for monitoring purposes.
495 std::string desc = state.GetConnectionDescription();
496 if (!desc.empty())
497 ss << "RemoteConnections: " << desc << crlf;
498 ss << "End" << crlf;
499 rec.bytes_transferred = state.BytesTransferred();
500 logTransferEvent(LogMask::Debug, rec, "PERF_MARKER");
501
502 return req.ChunkResp(ss.str().c_str(), 0);
503}
504
505/******************************************************************************/
506/* T P C H a n d l e r : : S e n d P e r f M a r k e r */
507/******************************************************************************/
508
509int TPCHandler::SendPerfMarker(XrdHttpExtReq &req, TPCLogRecord &rec, std::vector<State*> &state,
510 off_t bytes_transferred)
511{
512 // The 'performance marker' format is largely derived from how GridFTP works
513 // (e.g., the concept of `Stripe` is not quite so relevant here). See:
514 // https://twiki.cern.ch/twiki/bin/view/LCG/HttpTpcTechnical
515 // Example marker:
516 // Perf Marker\n
517 // Timestamp: 1537788010\n
518 // Stripe Index: 0\n
519 // Stripe Bytes Transferred: 238745\n
520 // Total Stripe Count: 1\n
521 // RemoteConnections: tcp:129.93.3.4:1234,tcp:[2600:900:6:1301:268a:7ff:fef6:a590]:2345\n
522 // End\n
523 //
524 std::stringstream ss;
525 const std::string crlf = "\n";
526 ss << "Perf Marker" << crlf;
527 ss << "Timestamp: " << time(NULL) << crlf;
528 ss << "Stripe Index: 0" << crlf;
529 ss << "Stripe Bytes Transferred: " << bytes_transferred << crlf;
530 ss << "Total Stripe Count: 1" << crlf;
531 // Build a list of TCP connections associated with this transfer; used by
532 // the TPC client for monitoring purposes.
533 bool first = true;
534 std::stringstream ss2;
535 for (std::vector<State*>::const_iterator iter = state.begin();
536 iter != state.end(); iter++)
537 {
538 std::string desc = (*iter)->GetConnectionDescription();
539 if (!desc.empty()) {
540 ss2 << (first ? "" : ",") << desc;
541 first = false;
542 }
543 }
544 if (!first)
545 ss << "RemoteConnections: " << ss2.str() << crlf;
546 ss << "End" << crlf;
547 rec.bytes_transferred = bytes_transferred;
548 logTransferEvent(LogMask::Debug, rec, "PERF_MARKER");
549
550 return req.ChunkResp(ss.str().c_str(), 0);
551}
552
553/******************************************************************************/
554/* T P C H a n d l e r : : R u n C u r l W i t h U p d a t e s */
555/******************************************************************************/
556
557int TPCHandler::RunCurlWithUpdates(CURL *curl, XrdHttpExtReq &req, State &state,
558 TPCLogRecord &rec)
559{
560 // Create the multi-handle and add in the current transfer to it.
561 CURLM *multi_handle = curl_multi_init();
562 if (!multi_handle) {
563 rec.status = 500;
564 logTransferEvent(LogMask::Error, rec, "CURL_INIT_FAIL",
565 "Failed to initialize a libcurl multi-handle");
566 std::stringstream ss;
567 ss << "Failed to initialize internal server memory";
568 return req.SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
569 }
570
571 //curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 128*1024);
572
573 CURLMcode mres;
574 mres = curl_multi_add_handle(multi_handle, curl);
575 if (mres) {
576 rec.status = 500;
577 std::stringstream ss;
578 ss << "Failed to add transfer to libcurl multi-handle: HTTP library failure=" << curl_multi_strerror(mres);
579 logTransferEvent(LogMask::Error, rec, "CURL_INIT_FAIL", ss.str());
580 curl_multi_cleanup(multi_handle);
581 return req.SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
582 }
583
584 // Start response to client prior to the first call to curl_multi_perform
585 int retval = req.StartChunkedResp(201, "Created", "Content-Type: text/plain");
586 if (retval) {
587 curl_multi_cleanup(multi_handle);
588 logTransferEvent(LogMask::Error, rec, "RESPONSE_FAIL",
589 "Failed to send the initial response to the TPC client");
590 return retval;
591 } else {
592 logTransferEvent(LogMask::Debug, rec, "RESPONSE_START",
593 "Initial transfer response sent to the TPC client");
594 }
595
596 // Transfer loop: use curl to actually run the transfer, but periodically
597 // interrupt things to send back performance updates to the client.
598 int running_handles = 1;
599 time_t last_marker = 0;
600 // Track how long it's been since the last time we recorded more bytes being transferred.
601 off_t last_advance_bytes = 0;
602 time_t last_advance_time = time(NULL);
603 time_t transfer_start = last_advance_time;
604 CURLcode res = static_cast<CURLcode>(-1);
605 do {
606 time_t now = time(NULL);
607 time_t next_marker = last_marker + m_marker_period;
608 if (now >= next_marker) {
609 off_t bytes_xfer = state.BytesTransferred();
610 if (bytes_xfer > last_advance_bytes) {
611 last_advance_bytes = bytes_xfer;
612 last_advance_time = now;
613 }
614 if (SendPerfMarker(req, rec, state)) {
615 curl_multi_remove_handle(multi_handle, curl);
616 curl_multi_cleanup(multi_handle);
617 logTransferEvent(LogMask::Error, rec, "PERFMARKER_FAIL",
618 "Failed to send a perf marker to the TPC client");
619 return -1;
620 }
621 int timeout = (transfer_start == last_advance_time) ? m_first_timeout : m_timeout;
622 if (now > last_advance_time + timeout) {
623 const char *log_prefix = rec.log_prefix.c_str();
624 bool tpc_pull = strncmp("Pull", log_prefix, 4) == 0;
625
626 state.SetErrorCode(10);
627 std::stringstream ss;
628 ss << "Transfer failed because no bytes have been "
629 << (tpc_pull ? "received from the source (pull mode) in "
630 : "transmitted to the destination (push mode) in ") << timeout << " seconds.";
631 state.SetErrorMessage(ss.str());
632 curl_multi_remove_handle(multi_handle, curl);
633 curl_multi_cleanup(multi_handle);
634 break;
635 }
636 last_marker = now;
637 }
638 // The transfer will start after this point, notify the packet marking manager
639 rec.pmarkManager.startTransfer();
640 mres = curl_multi_perform(multi_handle, &running_handles);
641 if (mres == CURLM_CALL_MULTI_PERFORM) {
642 // curl_multi_perform should be called again immediately. On newer
643 // versions of curl, this is no longer used.
644 continue;
645 } else if (mres != CURLM_OK) {
646 break;
647 } else if (running_handles == 0) {
648 break;
649 }
650
651 rec.pmarkManager.beginPMarks();
652 //printf("There are %d running handles\n", running_handles);
653
654 // Harvest any messages, looking for CURLMSG_DONE.
655 CURLMsg *msg;
656 do {
657 int msgq = 0;
658 msg = curl_multi_info_read(multi_handle, &msgq);
659 if (msg && (msg->msg == CURLMSG_DONE)) {
660 CURL *easy_handle = msg->easy_handle;
661 res = msg->data.result;
662 curl_multi_remove_handle(multi_handle, easy_handle);
663 }
664 } while (msg);
665
666 int64_t max_sleep_time = next_marker - time(NULL);
667 if (max_sleep_time <= 0) {
668 continue;
669 }
670 int fd_count;
671#ifdef HAVE_CURL_MULTI_WAIT
672 mres = curl_multi_wait(multi_handle, NULL, 0, max_sleep_time*1000, &fd_count);
673#else
674 mres = curl_multi_wait_impl(multi_handle, max_sleep_time*1000, &fd_count);
675#endif
676 if (mres != CURLM_OK) {
677 break;
678 }
679 } while (running_handles);
680
681 if (mres != CURLM_OK) {
682 std::stringstream ss;
683 ss << "Internal libcurl multi-handle error: HTTP library failure=" << curl_multi_strerror(mres);
684 logTransferEvent(LogMask::Error, rec, "TRANSFER_CURL_ERROR", ss.str());
685
686 curl_multi_remove_handle(multi_handle, curl);
687 curl_multi_cleanup(multi_handle);
688
689 if ((retval = req.ChunkResp(generateClientErr(ss, rec).c_str(), 0))) {
690 logTransferEvent(LogMask::Error, rec, "RESPONSE_FAIL",
691 "Failed to send error message to the TPC client");
692 return retval;
693 }
694 return req.ChunkResp(NULL, 0);
695 }
696
697 // Harvest any messages, looking for CURLMSG_DONE.
698 CURLMsg *msg;
699 do {
700 int msgq = 0;
701 msg = curl_multi_info_read(multi_handle, &msgq);
702 if (msg && (msg->msg == CURLMSG_DONE)) {
703 CURL *easy_handle = msg->easy_handle;
704 res = msg->data.result;
705 curl_multi_remove_handle(multi_handle, easy_handle);
706 }
707 } while (msg);
708
709 if (!state.GetErrorCode() && res == static_cast<CURLcode>(-1)) { // No transfers returned?!?
710 curl_multi_remove_handle(multi_handle, curl);
711 curl_multi_cleanup(multi_handle);
712 std::stringstream ss;
713 ss << "Internal state error in libcurl";
714 logTransferEvent(LogMask::Error, rec, "TRANSFER_CURL_ERROR", ss.str());
715
716 if ((retval = req.ChunkResp(generateClientErr(ss, rec).c_str(), 0))) {
717 logTransferEvent(LogMask::Error, rec, "RESPONSE_FAIL",
718 "Failed to send error message to the TPC client");
719 return retval;
720 }
721 return req.ChunkResp(NULL, 0);
722 }
723 curl_multi_cleanup(multi_handle);
724
725 state.Flush();
726
727 rec.bytes_transferred = state.BytesTransferred();
728 rec.tpc_status = state.GetStatusCode();
729
730 // Explicitly finalize the stream (which will close the underlying file
731 // handle) before the response is sent. In some cases, subsequent HTTP
732 // requests can occur before the filesystem is done closing the handle -
733 // and those requests may occur against partial data.
734 state.Finalize();
735
736 // Generate the final response back to the client.
737 std::stringstream ss;
738 bool success = false;
739 if (state.GetStatusCode() >= 400) {
740 std::string err = state.GetErrorMessage();
741 std::stringstream ss2;
742 ss2 << "Remote side failed with status code " << state.GetStatusCode();
743 if (!err.empty()) {
744 std::replace(err.begin(), err.end(), '\n', ' ');
745 ss2 << "; error message: \"" << err << "\"";
746 }
747 logTransferEvent(LogMask::Error, rec, "TRANSFER_FAIL", ss2.str());
748 ss << generateClientErr(ss2, rec);
749 } else if (state.GetErrorCode()) {
750 std::string err = state.GetErrorMessage();
751 if (err.empty()) {err = "(no error message provided)";}
752 else {std::replace(err.begin(), err.end(), '\n', ' ');}
753 std::stringstream ss2;
754 ss2 << "Error when interacting with local filesystem: " << err;
755 logTransferEvent(LogMask::Error, rec, "TRANSFER_FAIL", ss2.str());
756 ss << generateClientErr(ss2, rec);
757 } else if (res != CURLE_OK) {
758 std::stringstream ss2;
759 ss2 << "Internal transfer failure";
760 std::stringstream ss3;
761 ss3 << ss2.str() << ": " << curl_easy_strerror(res);
762 logTransferEvent(LogMask::Error, rec, "TRANSFER_FAIL", ss3.str());
763 ss << generateClientErr(ss2, rec, res);
764 } else {
765 ss << "success: Created";
766 success = true;
767 }
768
769 if ((retval = req.ChunkResp(ss.str().c_str(), 0))) {
770 logTransferEvent(LogMask::Error, rec, "TRANSFER_ERROR",
771 "Failed to send last update to remote client");
772 return retval;
773 } else if (success) {
774 logTransferEvent(LogMask::Info, rec, "TRANSFER_SUCCESS");
775 rec.status = 0;
776 }
777 return req.ChunkResp(NULL, 0);
778}
779
780/******************************************************************************/
781/* T P C H a n d l e r : : P r o c e s s P u s h R e q */
782/******************************************************************************/
783
784int TPCHandler::ProcessPushReq(const std::string & resource, XrdHttpExtReq &req) {
785 TPCLogRecord rec(req, TpcType::Push);
786 rec.log_prefix = "PushRequest";
787 rec.local = req.resource;
788 rec.remote = resource;
789 rec.m_log = &m_log;
790 char *name = req.GetSecEntity().name;
791 req.GetClientID(rec.clID);
792 if (name) rec.name = name;
793 logTransferEvent(LogMask::Info, rec, "PUSH_START", "Starting a push request");
794
795 ManagedCurlHandle curlPtr(curl_easy_init());
796 auto curl = curlPtr.get();
797 if (!curl) {
798 std::stringstream ss;
799 ss << "Failed to initialize internal transfer resources";
800 rec.status = 500;
801 logTransferEvent(LogMask::Error, rec, "PUSH_FAIL", ss.str());
802 return req.SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
803 }
804 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
805 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (long) CURL_HTTP_VERSION_1_1);
806// curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_setcloexec_callback);
807
808 curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket_callback);
809 curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &rec);
810 curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket_callback);
811 curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
812 curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &rec);
813 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, CONNECT_TIMEOUT);
814 auto query_header = XrdOucTUtils::caseInsensitiveFind(req.headers,"xrd-http-fullresource");
815 std::string redirect_resource = req.resource;
816 if (query_header != req.headers.end()) {
817 redirect_resource = query_header->second;
818 }
819
820 AtomicBeg(m_monid_mutex);
821 uint64_t file_monid = AtomicInc(m_monid);
822 AtomicEnd(m_monid_mutex);
823 std::unique_ptr<XrdSfsFile> fh(m_sfs->newFile(name, file_monid));
824 if (!fh.get()) {
825 rec.status = 500;
826 std::stringstream ss;
827 ss << "Failed to initialize internal transfer file handle";
828 logTransferEvent(LogMask::Error, rec, "OPEN_FAIL",
829 ss.str());
830 return req.SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
831 }
832 std::string full_url = prepareURL(req);
833
834 std::string authz = GetAuthz(req);
835
836 int open_results = OpenWaitStall(*fh, full_url, SFS_O_RDONLY, 0644,
837 req.GetSecEntity(), authz);
838 if (SFS_REDIRECT == open_results) {
839 int result = RedirectTransfer(curl, redirect_resource, req, fh->error, rec);
840 return result;
841 } else if (SFS_OK != open_results) {
842 int code;
843 std::stringstream ss;
844 const char *msg = fh->error.getErrText(code);
845 if (msg == NULL) ss << "Failed to open local resource";
846 else ss << msg;
847 rec.status = 400;
848 if (code == EACCES) rec.status = 401;
849 else if (code == EEXIST) rec.status = 412;
850 logTransferEvent(LogMask::Error, rec, "OPEN_FAIL", msg);
851 int resp_result = req.SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
852 fh->close();
853 return resp_result;
854 }
855 ConfigureCurlCA(curl);
856 curl_easy_setopt(curl, CURLOPT_URL, resource.c_str());
857
858 Stream stream(std::move(fh), 0, 0, m_log);
859 State state(0, stream, curl, true, req.tpcForwardCreds);
860 state.SetupHeaders(req);
861
862 return RunCurlWithUpdates(curl, req, state, rec);
863}
864
865/******************************************************************************/
866/* T P C H a n d l e r : : P r o c e s s P u l l R e q */
867/******************************************************************************/
868
869int TPCHandler::ProcessPullReq(const std::string &resource, XrdHttpExtReq &req) {
870 TPCLogRecord rec(req,TpcType::Pull);
871 rec.log_prefix = "PullRequest";
872 rec.local = req.resource;
873 rec.remote = resource;
874 rec.m_log = &m_log;
875 char *name = req.GetSecEntity().name;
876 req.GetClientID(rec.clID);
877 if (name) rec.name = name;
878 logTransferEvent(LogMask::Info, rec, "PULL_START", "Starting a pull request");
879
880 ManagedCurlHandle curlPtr(curl_easy_init());
881 auto curl = curlPtr.get();
882 if (!curl) {
883 std::stringstream ss;
884 ss << "Failed to initialize internal transfer resources";
885 rec.status = 500;
886 logTransferEvent(LogMask::Error, rec, "PULL_FAIL", ss.str());
887 return req.SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
888 }
889 // ddavila 2023-01-05:
890 // The following change was required by the Rucio/SENSE project where
891 // multiple IP addresses, each from a different subnet, are assigned to a
892 // single server and routed differently by SENSE.
893 // The above requires the server to utilize the same IP, that was used to
894 // start the TPC, for the resolution of the given TPC instead of
895 // using any of the IPs available.
896 if (m_fixed_route){
897 XrdNetAddr *nP;
898 int numIP = 0;
899 char buff[1024];
900 char * ip;
901
902 // Get the hostname used to contact the server from the http header
903 auto host_header = XrdOucTUtils::caseInsensitiveFind(req.headers,"host");
904 std::string host_used;
905 if (host_header != req.headers.end()) {
906 host_used = host_header->second;
907 }
908
909 // Get the IP addresses associated with the above hostname
910 XrdNetUtils::GetAddrs(host_used.c_str(), &nP, numIP, XrdNetUtils::prefAuto, 0);
911 int ip_size = nP[0].Format(buff, 1024, XrdNetAddrInfo::fmtAddr,XrdNetAddrInfo::noPort);
912 ip = (char *)malloc(ip_size-1);
913
914 // Substring to get only the address, remove brackets and garbage
915 memcpy(ip, buff+1, ip_size-2);
916 ip[ip_size-2]='\0';
917 logTransferEvent(LogMask::Info, rec, "LOCAL IP", ip);
918
919 curl_easy_setopt(curl, CURLOPT_INTERFACE, ip);
920 }
921 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
922 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (long) CURL_HTTP_VERSION_1_1);
923// curl_easy_setopt(curl,CURLOPT_SOCKOPTFUNCTION,sockopt_setcloexec_callback);
924 curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket_callback);
925 curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &rec);
926 curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
927 curl_easy_setopt(curl, CURLOPT_SOCKOPTDATA , &rec);
928 curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket_callback);
929 curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &rec);
930 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, CONNECT_TIMEOUT);
931 std::unique_ptr<XrdSfsFile> fh(m_sfs->newFile(name, m_monid++));
932 if (!fh.get()) {
933 std::stringstream ss;
934 ss << "Failed to initialize internal transfer file handle";
935 rec.status = 500;
936 logTransferEvent(LogMask::Error, rec, "PULL_FAIL", ss.str());
937 return req.SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
938 }
939 auto query_header = XrdOucTUtils::caseInsensitiveFind(req.headers,"xrd-http-fullresource");
940 std::string redirect_resource = req.resource;
941 if (query_header != req.headers.end()) {
942 redirect_resource = query_header->second;
943 }
945 auto overwrite_header = XrdOucTUtils::caseInsensitiveFind(req.headers,"overwrite");
946 if ((overwrite_header == req.headers.end()) || (overwrite_header->second == "T")) {
947 if (! usingEC) mode = SFS_O_TRUNC;
948 }
949 int streams = 1;
950 {
951 auto streams_header = XrdOucTUtils::caseInsensitiveFind(req.headers,"x-number-of-streams");
952 if (streams_header != req.headers.end()) {
953 int stream_req = -1;
954 try {
955 stream_req = std::stol(streams_header->second);
956 } catch (...) { // Handled below
957 }
958 if (stream_req < 0 || stream_req > 100) {
959 std::stringstream ss;
960 ss << "Invalid request for number of streams";
961 rec.status = 400;
962 logTransferEvent(LogMask::Info, rec, "INVALID_REQUEST", ss.str());
963 return req.SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
964 }
965 streams = stream_req == 0 ? 1 : stream_req;
966 }
967 }
968 rec.streams = streams;
969 std::string full_url = prepareURL(req);
970 std::string authz = GetAuthz(req);
971 curl_easy_setopt(curl, CURLOPT_URL, resource.c_str());
972 ConfigureCurlCA(curl);
973 uint64_t sourceFileContentLength = 0;
974 {
975 //Get the content-length of the source file and pass it to the OSS layer
976 //during the open
977 bool success;
978 GetContentLengthTPCPull(curl, req, sourceFileContentLength, success, rec);
979 if(success) {
980 //In the case we cannot get the information from the source server (offline or other error)
981 //we just don't add the size information to the opaque of the local file to open
982 full_url += "&oss.asize=" + std::to_string(sourceFileContentLength);
983 } else {
984 // In the case the GetContentLength is not successful, an error will be returned to the client
985 // just exit here so we don't open the file!
986 return 0;
987 }
988 }
989 int open_result = OpenWaitStall(*fh, full_url, mode|SFS_O_WRONLY,
990 0644 | SFS_O_MKPTH,
991 req.GetSecEntity(), authz);
992 if (SFS_REDIRECT == open_result) {
993 int result = RedirectTransfer(curl, redirect_resource, req, fh->error, rec);
994 return result;
995 } else if (SFS_OK != open_result) {
996 int code;
997 std::stringstream ss;
998 const char *msg = fh->error.getErrText(code);
999 if ((msg == NULL) || (*msg == '\0')) ss << "Failed to open local resource";
1000 else ss << msg;
1001 rec.status = 400;
1002 if (code == EACCES) rec.status = 401;
1003 else if (code == EEXIST) rec.status = 412;
1004 logTransferEvent(LogMask::Error, rec, "OPEN_FAIL", ss.str());
1005 int resp_result = req.SendSimpleResp(rec.status, NULL, NULL,
1006 generateClientErr(ss, rec).c_str(), 0);
1007 fh->close();
1008 return resp_result;
1009 }
1010 Stream stream(std::move(fh), streams * m_pipelining_multiplier, streams > 1 ? m_block_size : m_small_block_size, m_log);
1011 State state(0, stream, curl, false, req.tpcForwardCreds);
1012 state.SetupHeaders(req);
1013 state.SetContentLength(sourceFileContentLength);
1014
1015 if (streams > 1) {
1016 return RunCurlWithStreams(req, state, streams, rec);
1017 } else {
1018 return RunCurlWithUpdates(curl, req, state, rec);
1019 }
1020}
1021
1022/******************************************************************************/
1023/* T P C H a n d l e r : : l o g T r a n s f e r E v e n t */
1024/******************************************************************************/
1025
1026void TPCHandler::logTransferEvent(LogMask mask, const TPCLogRecord &rec,
1027 const std::string &event, const std::string &message)
1028{
1029 if (!(m_log.getMsgMask() & mask)) {return;}
1030
1031 std::stringstream ss;
1032 ss << "event=" << event << ", local=" << rec.local << ", remote=" << rec.remote;
1033 if (rec.name.empty())
1034 ss << ", user=(anonymous)";
1035 else
1036 ss << ", user=" << rec.name;
1037 if (rec.streams != 1)
1038 ss << ", streams=" << rec.streams;
1039 if (rec.bytes_transferred >= 0)
1040 ss << ", bytes_transferred=" << rec.bytes_transferred;
1041 if (rec.status >= 0)
1042 ss << ", status=" << rec.status;
1043 if (rec.tpc_status >= 0)
1044 ss << ", tpc_status=" << rec.tpc_status;
1045 if (!message.empty())
1046 ss << "; " << message;
1047 m_log.Log(mask, rec.log_prefix.c_str(), ss.str().c_str());
1048}
1049
1050std::string TPCHandler::generateClientErr(std::stringstream &err_ss, const TPCLogRecord &rec, CURLcode cCode) {
1051 std::stringstream ssret;
1052 ssret << "failure: " << err_ss.str() << ", local=" << rec.local <<", remote=" << rec.remote;
1053 if(cCode != CURLcode::CURLE_OK) {
1054 ssret << ", HTTP library failure=" << curl_easy_strerror(cCode);
1055 }
1056 return ssret.str();
1057}
1058/******************************************************************************/
1059/* X r d H t t p G e t E x t H a n d l e r */
1060/******************************************************************************/
1061
1062extern "C" {
1063
1064XrdHttpExtHandler *XrdHttpGetExtHandler(XrdSysError *log, const char * config, const char * /*parms*/, XrdOucEnv *myEnv) {
1065 if (curl_global_init(CURL_GLOBAL_DEFAULT)) {
1066 log->Emsg("TPCInitialize", "libcurl failed to initialize");
1067 return NULL;
1068 }
1069
1070 TPCHandler *retval{NULL};
1071 if (!config) {
1072 log->Emsg("TPCInitialize", "TPC handler requires a config filename in order to load");
1073 return NULL;
1074 }
1075 try {
1076 log->Emsg("TPCInitialize", "Will load configuration for the TPC handler from", config);
1077 retval = new TPCHandler(log, config, myEnv);
1078 } catch (std::runtime_error &re) {
1079 log->Emsg("TPCInitialize", "Encountered a runtime failure when loading ", re.what());
1080 //printf("Provided env vars: %p, XrdInet*: %p\n", myEnv, myEnv->GetPtr("XrdInet*"));
1081 }
1082 return retval;
1083}
1084
1085}
XrdHttpExtHandler * XrdHttpGetExtHandler(XrdHttpExtHandlerArgs)
char * quote(const char *str)
#define close(a)
Definition XrdPosix.hh:48
void getline(uchar *buff, int blen)
#define SFS_REDIRECT
#define SFS_O_MKPTH
#define SFS_STALL
#define SFS_O_RDONLY
#define SFS_STARTED
#define SFS_O_WRONLY
#define SFS_O_CREAT
int XrdSfsFileOpenMode
#define SFS_OK
#define SFS_O_TRUNC
#define AtomicInc(x)
#define AtomicBeg(Mtx)
#define AtomicEnd(Mtx)
CURLMcode curl_multi_wait_impl(CURLM *multi_handle, int timeout_ms, int *numfds)
void CURL
static std::string PrepareURL(const std::string &input)
Definition XrdTpcTPC.cc:242
XrdVERSIONINFO(XrdHttpGetExtHandler, HttpTPC)
std::string encode_xrootd_opaque_to_uri(CURL *curl, const std::string &opaque)
Definition XrdTpcTPC.cc:176
XrdHttpExtHandler * XrdHttpGetExtHandler(XrdSysError *log, const char *config, const char *, XrdOucEnv *myEnv)
int GetStatusCode() const
off_t BytesTransferred() const
void SetErrorMessage(const std::string &error_msg)
int GetErrorCode() const
std::string GetErrorMessage() const
std::string GetConnectionDescription()
void SetupHeaders(XrdHttpExtReq &req)
void SetContentLength(const off_t content_length)
off_t GetContentLength() const
void SetErrorCode(int error_code)
bool Finalize()
TPCHandler(XrdSysError *log, const char *config, XrdOucEnv *myEnv)
Definition XrdTpcTPC.cc:289
virtual int ProcessReq(XrdHttpExtReq &req)
Definition XrdTpcTPC.cc:253
virtual ~TPCHandler()
Definition XrdTpcTPC.cc:281
virtual bool MatchesPath(const char *verb, const char *path)
Tells if the incoming path is recognized as one of the paths that have to be processed.
Definition XrdTpcTPC.cc:234
std::string clienthost
int ChunkResp(const char *body, long long bodylen)
Send a (potentially partial) body in a chunked response; invoking with NULL body.
void GetClientID(std::string &clid)
std::map< std::string, std::string > & headers
std::string resource
int StartChunkedResp(int code, const char *desc, const char *header_to_add)
Starts a chunked response; body of request is sent over multiple parts using the SendChunkResp.
const XrdSecEntity & GetSecEntity() const
int SendSimpleResp(int code, const char *desc, const char *header_to_add, const char *body, long long bodylen)
Sends a basic response. If the length is < 0 then it is calculated internally.
static const int noPort
Do not add port number.
int Format(char *bAddr, int bLen, fmtUse fmtType=fmtAuto, int fmtOpts=0)
@ fmtAddr
Address using suitable ipv4 or ipv6 format.
static const char * GetAddrs(const char *hSpec, XrdNetAddr *aListP[], int &aListN, AddrOpts opts=allIPMap, int pNum=PortInSpec)
void * GetPtr(const char *varname)
Definition XrdOucEnv.cc:263
const char * getErrText()
void setUCap(int ucval)
Set user capabilties.
static std::map< std::string, T >::const_iterator caseInsensitiveFind(const std::map< std::string, T > &m, const std::string &lowerCaseSearchKey)
char * name
Entity's name.
virtual XrdSfsFile * newFile(char *user=0, int MonID=0)=0
XrdOucErrInfo & error
virtual int open(const char *fileName, XrdSfsFileOpenMode openMode, mode_t createMode, const XrdSecEntity *client=0, const char *opaque=0)=0
virtual int close()=0
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
XrdSysLogger * logger(XrdSysLogger *lp=0)
void Log(int mask, const char *esfx, const char *text1, const char *text2=0, const char *text3=0)
bool atLeastOneValidCRLFound() const
std::string CAFilename() const
std::string CRLFilename() const
static std::string prepareOpenURL(const std::string &reqResource, std::map< std::string, std::string > &reqHeaders, const std::map< std::string, std::string > &hdr2cgimap)
void Report(TpcInfo &info)
std::unique_ptr< CURL, CurlDeleter > ManagedCurlHandle
Definition XrdTpcTPC.hh:43
LogMask
Definition XrdTpcTPC.hh:27
@ Info
Definition XrdTpcTPC.hh:29
@ Error
Definition XrdTpcTPC.hh:31
@ Debug
Definition XrdTpcTPC.hh:28
@ Warning
Definition XrdTpcTPC.hh:30
void operator()(CURL *curl)
Definition XrdTpcTPC.cc:84
static const int uIPv64
ucap: Supports only IPv4 info