9 #include "XrdVersion.hh"
15 #include <curl/curl.h>
36 uint64_t TPCHandler::m_monid{0};
37 int TPCHandler::m_marker_period = 5;
38 size_t TPCHandler::m_block_size = 16*1024*1024;
39 size_t TPCHandler::m_small_block_size = 1*1024*1024;
48 TPCHandler::TPCLogRecord::~TPCLogRecord()
55 monInfo.
clID = clID.c_str();
57 gettimeofday(&monInfo.
endT, 0);
60 {monInfo.
dstURL = local.c_str();
61 monInfo.
srcURL = remote.c_str();
63 monInfo.
dstURL = remote.c_str();
64 monInfo.
srcURL = local.c_str();
68 if (!status) monInfo.
endRC = 0;
69 else if (tpc_status > 0) monInfo.
endRC = tpc_status;
70 else monInfo.
endRC = 1;
71 monInfo.
strm =
static_cast<unsigned char>(streams);
72 monInfo.
fSize = (bytes_transferred < 0 ? 0 : bytes_transferred);
75 tpcMonitor->Report(monInfo);
85 if (curl) curl_easy_cleanup(curl);
100 int TPCHandler::sockopt_callback(
void *clientp, curl_socket_t curlfd, curlsocktype purpose) {
101 TPCLogRecord * rec = (TPCLogRecord *)clientp;
102 if (purpose == CURLSOCKTYPE_IPCXN && rec && rec->pmarkManager.isEnabled()) {
105 return CURL_SOCKOPT_ALREADY_CONNECTED;
107 return CURL_SOCKOPT_OK;
119 int TPCHandler::opensocket_callback(
void *clientp,
120 curlsocktype purpose,
121 struct curl_sockaddr *aInfo)
124 int fd = XrdSysFD_Socket(aInfo->family, aInfo->socktype, aInfo->protocol);
128 return CURL_SOCKET_BAD;
130 TPCLogRecord * rec = (TPCLogRecord *)clientp;
131 if (purpose == CURLSOCKTYPE_IPCXN && clientp)
134 && !thePeer.isMapped());
135 std::stringstream connectErrMsg;
137 if(!rec->pmarkManager.connect(fd, &(aInfo->addr), aInfo->addrlen, CONNECT_TIMEOUT, connectErrMsg)) {
138 rec->m_log->Emsg(rec->log_prefix.c_str(),
"Unable to connect socket:", connectErrMsg.str().c_str());
139 return CURL_SOCKET_BAD;
146 int TPCHandler::closesocket_callback(
void *clientp, curl_socket_t fd) {
147 TPCLogRecord * rec = (TPCLogRecord *)clientp;
152 rec->pmarkManager.endPmark(fd);
177 std::stringstream parser(opaque);
178 std::string sequence;
179 std::stringstream output;
181 while (
getline(parser, sequence,
'&')) {
182 if (sequence.empty()) {
continue;}
183 size_t equal_pos = sequence.find(
'=');
185 if (equal_pos != std::string::npos)
186 val = curl_easy_escape(curl, sequence.c_str() + equal_pos + 1, sequence.size() - equal_pos - 1);
188 if (!val && equal_pos != std::string::npos) {
continue;}
190 if (!first) output <<
"&";
192 output << sequence.substr(0, equal_pos);
194 output <<
"=" << val;
206 TPCHandler::ConfigureCurlCA(
CURL *curl)
208 auto ca_filename = m_ca_file ? m_ca_file->CAFilename() :
"";
209 auto crl_filename = m_ca_file ? m_ca_file->CRLFilename() :
"";
210 if (!ca_filename.empty() && !crl_filename.empty()) {
211 curl_easy_setopt(curl, CURLOPT_CAINFO, ca_filename.c_str());
215 std::ifstream in(crl_filename, std::ifstream::ate | std::ifstream::binary);
216 if(in.tellg() > 0 && m_ca_file->atLeastOneValidCRLFound()){
217 curl_easy_setopt(curl, CURLOPT_CRLFILE, crl_filename.c_str());
219 std::ostringstream oss;
220 oss <<
"No valid CRL file has been found in the file " << crl_filename <<
". Disabling CRL checking.";
221 m_log.
Log(
Warning,
"TpcHandler",oss.str().c_str());
224 else if (!m_cadir.empty()) {
225 curl_easy_setopt(curl, CURLOPT_CAPATH, m_cadir.c_str());
227 if (!m_cafile.empty()) {
228 curl_easy_setopt(curl, CURLOPT_CAINFO, m_cafile.c_str());
234 return !strcmp(verb,
"COPY") || !strcmp(verb,
"OPTIONS");
242 if (!strncmp(input.c_str(),
"davs://", 7)) {
243 return "https://" + input.substr(7);
253 if (req.
verb ==
"OPTIONS") {
254 return ProcessOptionsReq(req);
257 if (header != req.
headers.end()) {
258 if (header->second !=
"none") {
259 m_log.
Emsg(
"ProcessReq",
"COPY requested an unsupported credential type: ", header->second.c_str());
260 return req.
SendSimpleResp(400, NULL, NULL,
"COPY requestd an unsupported Credential type", 0);
264 if (header != req.
headers.end()) {
266 return ProcessPullReq(src, req);
269 if (header != req.
headers.end()) {
270 return ProcessPushReq(header->second, req);
272 m_log.
Emsg(
"ProcessReq",
"COPY verb requested but no source or destination specified.");
273 return req.
SendSimpleResp(400, NULL, NULL,
"No Source or Destination specified", 0);
290 m_fixed_route(false),
292 m_first_timeout(120),
293 m_log(log->logger(),
"TPC_"),
296 if (!Configure(config, myEnv)) {
297 throw std::runtime_error(
"Failed to configure the HTTP third-party-copy handler.");
315 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);
325 if (authz_header != req.
headers.end()) {
326 std::stringstream ss;
327 ss <<
"authz=" <<
encode_str(authz_header->second);
337 int TPCHandler::RedirectTransfer(
CURL *curl,
const std::string &redirect_resource,
342 if ((ptr == NULL) || (*ptr ==
'\0') || (port == 0)) {
344 std::stringstream ss;
345 ss <<
"Internal error: redirect without hostname";
346 logTransferEvent(
LogMask::Error, rec,
"REDIRECT_INTERNAL_ERROR", ss.str());
347 return req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
351 std::string rdr_info = ptr;
352 std::string host, opaque;
353 size_t pos = rdr_info.find(
'?');
354 host = rdr_info.substr(0, pos);
356 if (pos != std::string::npos) {
357 opaque = rdr_info.substr(pos + 1);
360 std::stringstream ss;
361 ss <<
"Location: http" << (m_desthttps ?
"s" :
"") <<
"://" << host <<
":" << port <<
"/" << redirect_resource;
363 if (!opaque.empty()) {
369 return req.
SendSimpleResp(rec.status, NULL,
const_cast<char *
>(ss.str().c_str()),
377 int TPCHandler::OpenWaitStall(
XrdSfsFile &fh,
const std::string &resource,
379 const std::string &authz)
386 size_t pos = resource.find(
'?');
388 std::string path = resource.substr(0, pos);
390 if (pos != std::string::npos) {
391 opaque = resource.substr(pos + 1);
396 opaque += (opaque.empty() ?
"" :
"&");
399 open_result = fh.
open(path.c_str(), mode, openMode, &sec, opaque.c_str());
403 if (open_result ==
SFS_STARTED) {secs_to_stall = secs_to_stall/2 + 5;}
404 std::this_thread::sleep_for (std::chrono::seconds(secs_to_stall));
421 bool &success, TPCLogRecord &rec,
bool shouldReturnErrorToClient) {
423 curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
425 curl_easy_setopt(curl, CURLOPT_TIMEOUT, CONNECT_TIMEOUT);
427 res = curl_easy_perform(curl);
430 curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
432 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 0L);
433 if (res == CURLE_HTTP_RETURNED_ERROR) {
434 std::stringstream ss;
435 ss <<
"Remote server failed request while fetching remote size";
436 std::stringstream ss2;
437 ss2 << ss.str() <<
": " << curl_easy_strerror(res);
440 return shouldReturnErrorToClient ? req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec, res).c_str(), 0) : -1;
442 std::stringstream ss;
443 ss <<
"Remote side " << req.
clienthost <<
" failed with status code " << state.
GetStatusCode() <<
" while fetching remote size";
446 return shouldReturnErrorToClient ? req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0) : -1;
448 std::stringstream ss;
449 ss <<
"Internal transfer failure while fetching remote size";
450 std::stringstream ss2;
451 ss2 << ss.str() <<
" - HTTP library failed: " << curl_easy_strerror(res);
454 return shouldReturnErrorToClient ? req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec, res).c_str(), 0) : -1;
456 std::stringstream ss;
457 ss <<
"Successfully determined remote size for pull request: "
464 int TPCHandler::GetContentLengthTPCPull(
CURL *curl,
XrdHttpExtReq &req, uint64_t &contentLength,
bool & success, TPCLogRecord &rec) {
471 if ((result = DetermineXferSize(curl, req, state, success, rec)) || !success) {
483 std::stringstream ss;
484 const std::string crlf =
"\n";
485 ss <<
"Perf Marker" << crlf;
486 ss <<
"Timestamp: " << time(NULL) << crlf;
487 ss <<
"Stripe Index: 0" << crlf;
489 ss <<
"Total Stripe Count: 1" << crlf;
494 ss <<
"RemoteConnections: " << desc << crlf;
499 return req.
ChunkResp(ss.str().c_str(), 0);
506 int TPCHandler::SendPerfMarker(
XrdHttpExtReq &req, TPCLogRecord &rec, std::vector<State*> &state,
507 off_t bytes_transferred)
521 std::stringstream ss;
522 const std::string crlf =
"\n";
523 ss <<
"Perf Marker" << crlf;
524 ss <<
"Timestamp: " << time(NULL) << crlf;
525 ss <<
"Stripe Index: 0" << crlf;
526 ss <<
"Stripe Bytes Transferred: " << bytes_transferred << crlf;
527 ss <<
"Total Stripe Count: 1" << crlf;
531 std::stringstream ss2;
532 for (std::vector<State*>::const_iterator iter = state.begin();
533 iter != state.end(); iter++)
535 std::string desc = (*iter)->GetConnectionDescription();
537 ss2 << (first ?
"" :
",") << desc;
542 ss <<
"RemoteConnections: " << ss2.str() << crlf;
544 rec.bytes_transferred = bytes_transferred;
547 return req.
ChunkResp(ss.str().c_str(), 0);
558 CURLM *multi_handle = curl_multi_init();
562 "Failed to initialize a libcurl multi-handle");
563 std::stringstream ss;
564 ss <<
"Failed to initialize internal server memory";
565 return req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
571 mres = curl_multi_add_handle(multi_handle, curl);
574 std::stringstream ss;
575 ss <<
"Failed to add transfer to libcurl multi-handle: HTTP library failure=" << curl_multi_strerror(mres);
576 logTransferEvent(
LogMask::Error, rec,
"CURL_INIT_FAIL", ss.str());
577 curl_multi_cleanup(multi_handle);
578 return req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
582 int retval = req.
StartChunkedResp(201,
"Created",
"Content-Type: text/plain");
584 curl_multi_cleanup(multi_handle);
586 "Failed to send the initial response to the TPC client");
590 "Initial transfer response sent to the TPC client");
595 int running_handles = 1;
596 time_t last_marker = 0;
598 off_t last_advance_bytes = 0;
599 time_t last_advance_time = time(NULL);
600 time_t transfer_start = last_advance_time;
601 CURLcode res =
static_cast<CURLcode
>(-1);
603 time_t now = time(NULL);
604 time_t next_marker = last_marker + m_marker_period;
605 if (now >= next_marker) {
607 if (bytes_xfer > last_advance_bytes) {
608 last_advance_bytes = bytes_xfer;
609 last_advance_time = now;
611 if (SendPerfMarker(req, rec, state)) {
612 curl_multi_remove_handle(multi_handle, curl);
613 curl_multi_cleanup(multi_handle);
615 "Failed to send a perf marker to the TPC client");
618 int timeout = (transfer_start == last_advance_time) ? m_first_timeout : m_timeout;
619 if (now > last_advance_time + timeout) {
620 const char *log_prefix = rec.log_prefix.c_str();
621 bool tpc_pull = strncmp(
"Pull", log_prefix, 4) == 0;
624 std::stringstream ss;
625 ss <<
"Transfer failed because no bytes have been "
626 << (tpc_pull ?
"received from the source (pull mode) in "
627 :
"transmitted to the destination (push mode) in ") << timeout <<
" seconds.";
629 curl_multi_remove_handle(multi_handle, curl);
630 curl_multi_cleanup(multi_handle);
636 rec.pmarkManager.startTransfer();
637 mres = curl_multi_perform(multi_handle, &running_handles);
638 if (mres == CURLM_CALL_MULTI_PERFORM) {
642 }
else if (mres != CURLM_OK) {
644 }
else if (running_handles == 0) {
648 rec.pmarkManager.beginPMarks();
655 msg = curl_multi_info_read(multi_handle, &msgq);
656 if (msg && (msg->msg == CURLMSG_DONE)) {
657 CURL *easy_handle = msg->easy_handle;
658 res = msg->data.result;
659 curl_multi_remove_handle(multi_handle, easy_handle);
663 int64_t max_sleep_time = next_marker - time(NULL);
664 if (max_sleep_time <= 0) {
668 mres = curl_multi_wait(multi_handle, NULL, 0, max_sleep_time*1000, &fd_count);
669 if (mres != CURLM_OK) {
672 }
while (running_handles);
674 if (mres != CURLM_OK) {
675 std::stringstream ss;
676 ss <<
"Internal libcurl multi-handle error: HTTP library failure=" << curl_multi_strerror(mres);
677 logTransferEvent(
LogMask::Error, rec,
"TRANSFER_CURL_ERROR", ss.str());
679 curl_multi_remove_handle(multi_handle, curl);
680 curl_multi_cleanup(multi_handle);
682 if ((retval = req.
ChunkResp(generateClientErr(ss, rec).c_str(), 0))) {
684 "Failed to send error message to the TPC client");
694 msg = curl_multi_info_read(multi_handle, &msgq);
695 if (msg && (msg->msg == CURLMSG_DONE)) {
696 CURL *easy_handle = msg->easy_handle;
697 res = msg->data.result;
698 curl_multi_remove_handle(multi_handle, easy_handle);
702 if (!state.
GetErrorCode() && res ==
static_cast<CURLcode
>(-1)) {
703 curl_multi_remove_handle(multi_handle, curl);
704 curl_multi_cleanup(multi_handle);
705 std::stringstream ss;
706 ss <<
"Internal state error in libcurl";
707 logTransferEvent(
LogMask::Error, rec,
"TRANSFER_CURL_ERROR", ss.str());
709 if ((retval = req.
ChunkResp(generateClientErr(ss, rec).c_str(), 0))) {
711 "Failed to send error message to the TPC client");
716 curl_multi_cleanup(multi_handle);
730 std::stringstream ss;
731 bool success =
false;
734 std::stringstream ss2;
735 ss2 <<
"Remote side failed with status code " << state.
GetStatusCode();
737 std::replace(err.begin(), err.end(),
'\n',
' ');
738 ss2 <<
"; error message: \"" << err <<
"\"";
740 logTransferEvent(
LogMask::Error, rec,
"TRANSFER_FAIL", ss2.str());
741 ss << generateClientErr(ss2, rec);
744 if (err.empty()) {err =
"(no error message provided)";}
745 else {std::replace(err.begin(), err.end(),
'\n',
' ');}
746 std::stringstream ss2;
747 ss2 <<
"Error when interacting with local filesystem: " << err;
748 logTransferEvent(
LogMask::Error, rec,
"TRANSFER_FAIL", ss2.str());
749 ss << generateClientErr(ss2, rec);
750 }
else if (res != CURLE_OK) {
751 std::stringstream ss2;
752 ss2 <<
"Internal transfer failure";
753 std::stringstream ss3;
754 ss3 << ss2.str() <<
": " << curl_easy_strerror(res);
755 logTransferEvent(
LogMask::Error, rec,
"TRANSFER_FAIL", ss3.str());
756 ss << generateClientErr(ss2, rec, res);
758 ss <<
"success: Created";
762 if ((retval = req.
ChunkResp(ss.str().c_str(), 0))) {
764 "Failed to send last update to remote client");
766 }
else if (success) {
777 int TPCHandler::ProcessPushReq(
const std::string & resource,
XrdHttpExtReq &req) {
779 rec.log_prefix =
"PushRequest";
781 rec.remote = resource;
785 if (name) rec.name = name;
786 logTransferEvent(
LogMask::Info, rec,
"PUSH_START",
"Starting a push request");
789 auto curl = curlPtr.get();
791 std::stringstream ss;
792 ss <<
"Failed to initialize internal transfer resources";
795 return req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
797 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
798 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (
long) CURL_HTTP_VERSION_1_1);
801 curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket_callback);
802 curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &rec);
803 curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket_callback);
804 curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
805 curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &rec);
806 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, CONNECT_TIMEOUT);
808 std::string redirect_resource = req.
resource;
809 if (query_header != req.
headers.end()) {
810 redirect_resource = query_header->second;
814 uint64_t file_monid =
AtomicInc(m_monid);
816 std::unique_ptr<XrdSfsFile> fh(m_sfs->
newFile(name, file_monid));
819 std::stringstream ss;
820 ss <<
"Failed to initialize internal transfer file handle";
823 return req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
825 std::string full_url = prepareURL(req);
827 std::string authz = GetAuthz(req);
829 int open_results = OpenWaitStall(*fh, full_url,
SFS_O_RDONLY, 0644,
832 int result = RedirectTransfer(curl, redirect_resource, req, fh->
error, rec);
834 }
else if (
SFS_OK != open_results) {
836 std::stringstream ss;
838 if (msg == NULL) ss <<
"Failed to open local resource";
841 if (code == EACCES) rec.status = 401;
842 else if (code == EEXIST) rec.status = 412;
844 int resp_result = req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
848 ConfigureCurlCA(curl);
849 curl_easy_setopt(curl, CURLOPT_URL, resource.c_str());
851 Stream stream(std::move(fh), 0, 0, m_log);
855 return RunCurlWithUpdates(curl, req, state, rec);
862 int TPCHandler::ProcessPullReq(
const std::string &resource,
XrdHttpExtReq &req) {
864 rec.log_prefix =
"PullRequest";
866 rec.remote = resource;
870 if (name) rec.name = name;
871 logTransferEvent(
LogMask::Info, rec,
"PULL_START",
"Starting a pull request");
874 auto curl = curlPtr.get();
876 std::stringstream ss;
877 ss <<
"Failed to initialize internal transfer resources";
880 return req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
897 std::string host_used;
898 if (host_header != req.
headers.end()) {
899 host_used = host_header->second;
905 ip = (
char *)malloc(ip_size-1);
908 memcpy(ip, buff+1, ip_size-2);
912 curl_easy_setopt(curl, CURLOPT_INTERFACE, ip);
914 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
915 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (
long) CURL_HTTP_VERSION_1_1);
917 curl_easy_setopt(curl, CURLOPT_OPENSOCKETFUNCTION, opensocket_callback);
918 curl_easy_setopt(curl, CURLOPT_OPENSOCKETDATA, &rec);
919 curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
920 curl_easy_setopt(curl, CURLOPT_SOCKOPTDATA , &rec);
921 curl_easy_setopt(curl, CURLOPT_CLOSESOCKETFUNCTION, closesocket_callback);
922 curl_easy_setopt(curl, CURLOPT_CLOSESOCKETDATA, &rec);
923 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, CONNECT_TIMEOUT);
924 std::unique_ptr<XrdSfsFile> fh(m_sfs->
newFile(name, m_monid++));
926 std::stringstream ss;
927 ss <<
"Failed to initialize internal transfer file handle";
930 return req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
933 std::string redirect_resource = req.
resource;
934 if (query_header != req.
headers.end()) {
935 redirect_resource = query_header->second;
939 if ((overwrite_header == req.
headers.end()) || (overwrite_header->second ==
"T")) {
945 if (streams_header != req.
headers.end()) {
948 stream_req = std::stol(streams_header->second);
951 if (stream_req < 0 || stream_req > 100) {
952 std::stringstream ss;
953 ss <<
"Invalid request for number of streams";
955 logTransferEvent(
LogMask::Info, rec,
"INVALID_REQUEST", ss.str());
956 return req.
SendSimpleResp(rec.status, NULL, NULL, generateClientErr(ss, rec).c_str(), 0);
958 streams = stream_req == 0 ? 1 : stream_req;
961 rec.streams = streams;
962 std::string full_url = prepareURL(req);
963 std::string authz = GetAuthz(req);
964 curl_easy_setopt(curl, CURLOPT_URL, resource.c_str());
965 ConfigureCurlCA(curl);
966 uint64_t sourceFileContentLength = 0;
971 GetContentLengthTPCPull(curl, req, sourceFileContentLength, success, rec);
975 full_url +=
"&oss.asize=" + std::to_string(sourceFileContentLength);
982 int open_result = OpenWaitStall(*fh, full_url, mode|
SFS_O_WRONLY,
986 int result = RedirectTransfer(curl, redirect_resource, req, fh->
error, rec);
988 }
else if (
SFS_OK != open_result) {
990 std::stringstream ss;
992 if ((msg == NULL) || (*msg ==
'\0')) ss <<
"Failed to open local resource";
995 if (code == EACCES) rec.status = 401;
996 else if (code == EEXIST) rec.status = 412;
999 generateClientErr(ss, rec).c_str(), 0);
1003 Stream stream(std::move(fh), streams * m_pipelining_multiplier, streams > 1 ? m_block_size : m_small_block_size, m_log);
1009 return RunCurlWithStreams(req, state, streams, rec);
1011 return RunCurlWithUpdates(curl, req, state, rec);
1019 void TPCHandler::logTransferEvent(
LogMask mask,
const TPCLogRecord &rec,
1020 const std::string &event,
const std::string &message)
1024 std::stringstream ss;
1025 ss <<
"event=" <<
event <<
", local=" << rec.local <<
", remote=" << rec.remote;
1026 if (rec.name.empty())
1027 ss <<
", user=(anonymous)";
1029 ss <<
", user=" << rec.name;
1030 if (rec.streams != 1)
1031 ss <<
", streams=" << rec.streams;
1032 if (rec.bytes_transferred >= 0)
1033 ss <<
", bytes_transferred=" << rec.bytes_transferred;
1034 if (rec.status >= 0)
1035 ss <<
", status=" << rec.status;
1036 if (rec.tpc_status >= 0)
1037 ss <<
", tpc_status=" << rec.tpc_status;
1038 if (!message.empty())
1039 ss <<
"; " << message;
1040 m_log.
Log(mask, rec.log_prefix.c_str(), ss.str().c_str());
1043 std::string TPCHandler::generateClientErr(std::stringstream &err_ss,
const TPCLogRecord &rec, CURLcode cCode) {
1044 std::stringstream ssret;
1045 ssret <<
"failure: " << err_ss.str() <<
", local=" << rec.local <<
", remote=" << rec.remote;
1046 if(cCode != CURLcode::CURLE_OK) {
1047 ssret <<
", HTTP library failure=" << curl_easy_strerror(cCode);
1058 if (curl_global_init(CURL_GLOBAL_DEFAULT)) {
1059 log->
Emsg(
"TPCInitialize",
"libcurl failed to initialize");
1065 log->
Emsg(
"TPCInitialize",
"TPC handler requires a config filename in order to load");
1069 log->
Emsg(
"TPCInitialize",
"Will load configuration for the TPC handler from", config);
1071 }
catch (std::runtime_error &re) {
1072 log->
Emsg(
"TPCInitialize",
"Encountered a runtime failure when loading ", re.what());
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)
std::string encode_str(const std::string &str)
void getline(uchar *buff, int blen)
int GetStatusCode() const
off_t BytesTransferred() const
void SetErrorMessage(const std::string &error_msg)
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)
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 std::string prepareOpenURL(const std::string &reqResource, std::map< std::string, std::string > &reqHeaders, const std::map< std::string, std::string > &hdr2cgimap)
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)
std::unique_ptr< CURL, CurlDeleter > ManagedCurlHandle
void operator()(CURL *curl)
static const int uIPv64
ucap: Supports only IPv4 info