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