9 #include "XrdVersion.hh"
15 #include <curl/curl.h>
37 uint64_t TPCHandler::m_monid{0};
38 int TPCHandler::m_marker_period = 5;
39 size_t TPCHandler::m_block_size = 16*1024*1024;
40 size_t TPCHandler::m_small_block_size = 1*1024*1024;
49 TPCHandler::TPCLogRecord::~TPCLogRecord()
56 monInfo.
clID = clID.c_str();
58 gettimeofday(&monInfo.
endT, 0);
61 {monInfo.
dstURL = local.c_str();
62 monInfo.
srcURL = remote.c_str();
64 monInfo.
dstURL = remote.c_str();
65 monInfo.
srcURL = local.c_str();
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);
76 tpcMonitor->Report(monInfo);
86 if (curl) curl_easy_cleanup(curl);
101 int 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()) {
106 return CURL_SOCKOPT_ALREADY_CONNECTED;
108 return CURL_SOCKOPT_OK;
120 int TPCHandler::opensocket_callback(
void *clientp,
121 curlsocktype purpose,
122 struct curl_sockaddr *aInfo)
125 int fd = XrdSysFD_Socket(aInfo->family, aInfo->socktype, aInfo->protocol);
129 return CURL_SOCKET_BAD;
131 TPCLogRecord * rec = (TPCLogRecord *)clientp;
132 if (purpose == CURLSOCKTYPE_IPCXN && clientp)
135 && !thePeer.isMapped());
136 std::stringstream connectErrMsg;
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;
147 int TPCHandler::closesocket_callback(
void *clientp, curl_socket_t fd) {
148 TPCLogRecord * rec = (TPCLogRecord *)clientp;
153 rec->pmarkManager.endPmark(fd);
178 std::stringstream parser(opaque);
179 std::string sequence;
180 std::stringstream output;
182 while (
getline(parser, sequence,
'&')) {
183 if (sequence.empty()) {
continue;}
184 size_t equal_pos = sequence.find(
'=');
186 if (equal_pos != std::string::npos)
187 val = curl_easy_escape(curl, sequence.c_str() + equal_pos + 1, sequence.size() - equal_pos - 1);
189 if (!val && equal_pos != std::string::npos) {
continue;}
191 if (!first) output <<
"&";
193 output << sequence.substr(0, equal_pos);
195 output <<
"=" << val;
207 TPCHandler::ConfigureCurlCA(
CURL *curl)
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());
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());
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());
225 else if (!m_cadir.empty()) {
226 curl_easy_setopt(curl, CURLOPT_CAPATH, m_cadir.c_str());
228 if (!m_cafile.empty()) {
229 curl_easy_setopt(curl, CURLOPT_CAINFO, m_cafile.c_str());
235 return !strcmp(verb,
"COPY") || !strcmp(verb,
"OPTIONS");
243 if (!strncmp(input.c_str(),
"davs://", 7)) {
244 return "https://" + input.substr(7);
254 if (req.
verb ==
"OPTIONS") {
255 return ProcessOptionsReq(req);
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);
265 if (header != req.
headers.end()) {
267 return ProcessPullReq(src, req);
270 if (header != req.
headers.end()) {
271 return ProcessPushReq(header->second, req);
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);
291 m_fixed_route(false),
293 m_first_timeout(120),
294 m_log(log->logger(),
"TPC_"),
297 if (!Configure(config, myEnv)) {
298 throw std::runtime_error(
"Failed to configure the HTTP third-party-copy handler.");
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);
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;
340 int TPCHandler::RedirectTransfer(
CURL *curl,
const std::string &redirect_resource,
345 if ((ptr == NULL) || (*ptr ==
'\0') || (port == 0)) {
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);
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);
359 if (pos != std::string::npos) {
360 opaque = rdr_info.substr(pos + 1);
363 std::stringstream ss;
364 ss <<
"Location: http" << (m_desthttps ?
"s" :
"") <<
"://" << host <<
":" << port <<
"/" << redirect_resource;
366 if (!opaque.empty()) {
372 return req.
SendSimpleResp(rec.status, NULL,
const_cast<char *
>(ss.str().c_str()),
380 int TPCHandler::OpenWaitStall(
XrdSfsFile &fh,
const std::string &resource,
382 const std::string &authz)
389 size_t pos = resource.find(
'?');
391 std::string path = resource.substr(0, pos);
393 if (pos != std::string::npos) {
394 opaque = resource.substr(pos + 1);
399 opaque += (opaque.empty() ?
"" :
"&");
402 open_result = fh.
open(path.c_str(), mode, openMode, &sec, opaque.c_str());
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));
424 bool &success, TPCLogRecord &rec,
bool shouldReturnErrorToClient) {
426 curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
428 curl_easy_setopt(curl, CURLOPT_TIMEOUT, CONNECT_TIMEOUT);
430 res = curl_easy_perform(curl);
433 curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
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);
443 return shouldReturnErrorToClient ? req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec, res).c_str(), 0) : -1;
445 std::stringstream ss;
446 ss <<
"Remote side " << req.
clienthost <<
" failed with status code " << state.
GetStatusCode() <<
" while fetching remote size";
449 return shouldReturnErrorToClient ? req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0) : -1;
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);
457 return shouldReturnErrorToClient ? req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec, res).c_str(), 0) : -1;
459 std::stringstream ss;
460 ss <<
"Successfully determined remote size for pull request: "
467 int TPCHandler::GetContentLengthTPCPull(
CURL *curl,
XrdHttpExtReq &req, uint64_t &contentLength,
bool & success, TPCLogRecord &rec) {
474 if ((result = DetermineXferSize(curl, req, state, success, rec)) || !success) {
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;
492 ss <<
"Total Stripe Count: 1" << crlf;
497 ss <<
"RemoteConnections: " << desc << crlf;
502 return req.
ChunkResp(ss.str().c_str(), 0);
509 int TPCHandler::SendPerfMarker(
XrdHttpExtReq &req, TPCLogRecord &rec, std::vector<State*> &state,
510 off_t bytes_transferred)
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;
534 std::stringstream ss2;
535 for (std::vector<State*>::const_iterator iter = state.begin();
536 iter != state.end(); iter++)
538 std::string desc = (*iter)->GetConnectionDescription();
540 ss2 << (first ?
"" :
",") << desc;
545 ss <<
"RemoteConnections: " << ss2.str() << crlf;
547 rec.bytes_transferred = bytes_transferred;
550 return req.
ChunkResp(ss.str().c_str(), 0);
561 CURLM *multi_handle = curl_multi_init();
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);
574 mres = curl_multi_add_handle(multi_handle, curl);
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);
585 int retval = req.
StartChunkedResp(201,
"Created",
"Content-Type: text/plain");
587 curl_multi_cleanup(multi_handle);
589 "Failed to send the initial response to the TPC client");
593 "Initial transfer response sent to the TPC client");
598 int running_handles = 1;
599 time_t last_marker = 0;
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);
606 time_t now = time(NULL);
607 time_t next_marker = last_marker + m_marker_period;
608 if (now >= next_marker) {
610 if (bytes_xfer > last_advance_bytes) {
611 last_advance_bytes = bytes_xfer;
612 last_advance_time = now;
614 if (SendPerfMarker(req, rec, state)) {
615 curl_multi_remove_handle(multi_handle, curl);
616 curl_multi_cleanup(multi_handle);
618 "Failed to send a perf marker to the TPC client");
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;
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.";
632 curl_multi_remove_handle(multi_handle, curl);
633 curl_multi_cleanup(multi_handle);
639 rec.pmarkManager.startTransfer();
640 mres = curl_multi_perform(multi_handle, &running_handles);
641 if (mres == CURLM_CALL_MULTI_PERFORM) {
645 }
else if (mres != CURLM_OK) {
647 }
else if (running_handles == 0) {
651 rec.pmarkManager.beginPMarks();
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);
666 int64_t max_sleep_time = next_marker - time(NULL);
667 if (max_sleep_time <= 0) {
671 #ifdef HAVE_CURL_MULTI_WAIT
672 mres = curl_multi_wait(multi_handle, NULL, 0, max_sleep_time*1000, &fd_count);
676 if (mres != CURLM_OK) {
679 }
while (running_handles);
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());
686 curl_multi_remove_handle(multi_handle, curl);
687 curl_multi_cleanup(multi_handle);
689 if ((retval = req.
ChunkResp(generateClientErr(ss, rec).c_str(), 0))) {
691 "Failed to send error message to the TPC client");
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);
709 if (!state.
GetErrorCode() && res ==
static_cast<CURLcode
>(-1)) {
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());
716 if ((retval = req.
ChunkResp(generateClientErr(ss, rec).c_str(), 0))) {
718 "Failed to send error message to the TPC client");
723 curl_multi_cleanup(multi_handle);
737 std::stringstream ss;
738 bool success =
false;
741 std::stringstream ss2;
742 ss2 <<
"Remote side failed with status code " << state.
GetStatusCode();
744 std::replace(err.begin(), err.end(),
'\n',
' ');
745 ss2 <<
"; error message: \"" << err <<
"\"";
747 logTransferEvent(
LogMask::Error, rec,
"TRANSFER_FAIL", ss2.str());
748 ss << generateClientErr(ss2, rec);
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);
765 ss <<
"success: Created";
769 if ((retval = req.
ChunkResp(ss.str().c_str(), 0))) {
771 "Failed to send last update to remote client");
773 }
else if (success) {
784 int TPCHandler::ProcessPushReq(
const std::string & resource,
XrdHttpExtReq &req) {
786 rec.log_prefix =
"PushRequest";
788 rec.remote = resource;
792 if (name) rec.name = name;
793 logTransferEvent(
LogMask::Info, rec,
"PUSH_START",
"Starting a push request");
796 auto curl = curlPtr.get();
798 std::stringstream ss;
799 ss <<
"Failed to initialize internal transfer resources";
802 return req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
804 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
805 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (
long) CURL_HTTP_VERSION_1_1);
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);
815 std::string redirect_resource = req.
resource;
816 if (query_header != req.
headers.end()) {
817 redirect_resource = query_header->second;
821 uint64_t file_monid =
AtomicInc(m_monid);
823 std::unique_ptr<XrdSfsFile> fh(m_sfs->
newFile(name, file_monid));
826 std::stringstream ss;
827 ss <<
"Failed to initialize internal transfer file handle";
830 return req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
832 std::string full_url = prepareURL(req);
834 std::string authz = GetAuthz(req);
836 int open_results = OpenWaitStall(*fh, full_url,
SFS_O_RDONLY, 0644,
839 int result = RedirectTransfer(curl, redirect_resource, req, fh->
error, rec);
841 }
else if (
SFS_OK != open_results) {
843 std::stringstream ss;
845 if (msg == NULL) ss <<
"Failed to open local resource";
848 if (code == EACCES) rec.status = 401;
849 else if (code == EEXIST) rec.status = 412;
851 int resp_result = req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
855 ConfigureCurlCA(curl);
856 curl_easy_setopt(curl, CURLOPT_URL, resource.c_str());
858 Stream stream(std::move(fh), 0, 0, m_log);
862 return RunCurlWithUpdates(curl, req, state, rec);
869 int TPCHandler::ProcessPullReq(
const std::string &resource,
XrdHttpExtReq &req) {
871 rec.log_prefix =
"PullRequest";
873 rec.remote = resource;
877 if (name) rec.name = name;
878 logTransferEvent(
LogMask::Info, rec,
"PULL_START",
"Starting a pull request");
881 auto curl = curlPtr.get();
883 std::stringstream ss;
884 ss <<
"Failed to initialize internal transfer resources";
887 return req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
904 std::string host_used;
905 if (host_header != req.
headers.end()) {
906 host_used = host_header->second;
912 ip = (
char *)malloc(ip_size-1);
915 memcpy(ip, buff+1, ip_size-2);
919 curl_easy_setopt(curl, CURLOPT_INTERFACE, ip);
921 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
922 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (
long) CURL_HTTP_VERSION_1_1);
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++));
933 std::stringstream ss;
934 ss <<
"Failed to initialize internal transfer file handle";
937 return req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
940 std::string redirect_resource = req.
resource;
941 if (query_header != req.
headers.end()) {
942 redirect_resource = query_header->second;
946 if ((overwrite_header == req.
headers.end()) || (overwrite_header->second ==
"T")) {
952 if (streams_header != req.
headers.end()) {
955 stream_req = std::stol(streams_header->second);
958 if (stream_req < 0 || stream_req > 100) {
959 std::stringstream ss;
960 ss <<
"Invalid request for number of streams";
962 logTransferEvent(
LogMask::Info, rec,
"INVALID_REQUEST", ss.str());
963 return req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
965 streams = stream_req == 0 ? 1 : stream_req;
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;
978 GetContentLengthTPCPull(curl, req, sourceFileContentLength, success, rec);
982 full_url +=
"&oss.asize=" + std::to_string(sourceFileContentLength);
989 int open_result = OpenWaitStall(*fh, full_url, mode|
SFS_O_WRONLY,
993 int result = RedirectTransfer(curl, redirect_resource, req, fh->
error, rec);
995 }
else if (
SFS_OK != open_result) {
997 std::stringstream ss;
999 if ((msg == NULL) || (*msg ==
'\0')) ss <<
"Failed to open local resource";
1002 if (code == EACCES) rec.status = 401;
1003 else if (code == EEXIST) rec.status = 412;
1006 generateClientErr(ss, rec).c_str(), 0);
1010 Stream stream(std::move(fh), streams * m_pipelining_multiplier, streams > 1 ? m_block_size : m_small_block_size, m_log);
1016 return RunCurlWithStreams(req, state, streams, rec);
1018 return RunCurlWithUpdates(curl, req, state, rec);
1026 void TPCHandler::logTransferEvent(
LogMask mask,
const TPCLogRecord &rec,
1027 const std::string &event,
const std::string &message)
1031 std::stringstream ss;
1032 ss <<
"event=" <<
event <<
", local=" << rec.local <<
", remote=" << rec.remote;
1033 if (rec.name.empty())
1034 ss <<
", user=(anonymous)";
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());
1050 std::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);
1065 if (curl_global_init(CURL_GLOBAL_DEFAULT)) {
1066 log->
Emsg(
"TPCInitialize",
"libcurl failed to initialize");
1072 log->
Emsg(
"TPCInitialize",
"TPC handler requires a config filename in order to load");
1076 log->
Emsg(
"TPCInitialize",
"Will load configuration for the TPC handler from", config);
1078 }
catch (std::runtime_error &re) {
1079 log->
Emsg(
"TPCInitialize",
"Encountered a runtime failure when loading ", re.what());
char * quote(const char *str)
void getline(uchar *buff, int blen)
CURLMcode curl_multi_wait_impl(CURLM *multi_handle, int timeout_ms, int *numfds)
static std::string PrepareURL(const std::string &input)
XrdVERSIONINFO(XrdHttpGetExtHandler, HttpTPC)
XrdHttpExtHandler * XrdHttpGetExtHandler(XrdSysError *log, const char *config, const char *, XrdOucEnv *myEnv)
std::string encode_xrootd_opaque_to_uri(CURL *curl, const std::string &opaque)
int GetStatusCode() const
off_t BytesTransferred() const
void CopyHeaders(XrdHttpExtReq &req)
void SetErrorMessage(const std::string &error_msg)
std::string GetErrorMessage() const
std::string GetConnectionDescription()
void SetContentLength(const off_t content_length)
off_t GetContentLength() const
void SetErrorCode(int error_code)
TPCHandler(XrdSysError *log, const char *config, XrdOucEnv *myEnv)
virtual int ProcessReq(XrdHttpExtReq &req)
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.
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
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)
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
virtual int open(const char *fileName, XrdSfsFileOpenMode openMode, mode_t createMode, const XrdSecEntity *client=0, const char *opaque=0)=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)
std::unique_ptr< CURL, CurlDeleter > ManagedCurlHandle
void operator()(CURL *curl)
static const int uIPv64
ucap: Supports only IPv4 info