XRootD
Loading...
Searching...
No Matches
XrdClHttp::CurlStatOp Class Reference

#include <XrdClHttpOps.hh>

+ Inheritance diagram for XrdClHttp::CurlStatOp:
+ Collaboration diagram for XrdClHttp::CurlStatOp:

Public Member Functions

 CurlStatOp (XrdCl::ResponseHandler *handler, const std::string &url, struct timespec timeout, XrdCl::Log *log, bool response_info, CreateConnCalloutType callout, HeaderCallout *header_callout)
 
virtual ~CurlStatOp ()
 
std::pair< int64_t, bool > GetStatInfo ()
 
virtual HttpVerb GetVerb () const override
 
virtual void OptionsDone () override
 
RedirectAction Redirect (std::string &target) override
 
void ReleaseHandle () override
 
virtual bool RequiresOptions () const override
 
bool Setup (CURL *curl, CurlWorker &) override
 
void Success () override
 
- Public Member Functions inherited from XrdClHttp::CurlOperation
 CurlOperation (const CurlOperation &)=delete
 
 CurlOperation (XrdCl::ResponseHandler *handler, const std::string &url, std::chrono::steady_clock::time_point expiry, XrdCl::Log *log, CreateConnCalloutType, HeaderCallout *header_callout)
 
 CurlOperation (XrdCl::ResponseHandler *handler, const std::string &url, struct timespec timeout, XrdCl::Log *log, CreateConnCalloutType, HeaderCallout *header_callout)
 
virtual ~CurlOperation ()
 
virtual bool ContinueHandle ()
 
void ExtendDeadline (struct timespec timeout)
 
virtual void Fail (uint16_t errCode, uint32_t errNum, const std::string &)
 
bool FinishSetup (CURL *curl)
 
std::pair< XErrorCode, std::string > GetCallbackError () const
 
CreateConnCalloutType GetConnCalloutFunc () const
 
std::string GetCurlErrorMessage () const
 
CURL * GetCurlHandle () const
 
OpError GetError () const
 
std::chrono::steady_clock::time_point GetHeaderExpiry () const
 
std::chrono::steady_clock::time_point GetOperationExpiry ()
 
std::unique_ptr< ResponseInfo > GetResponseInfo ()
 
int GetStatusCode () const
 
std::string GetStatusMessage () const
 
bool GetTriedBoker () const
 
const std::string & GetUrl () const
 
bool HasFailed () const
 
bool HeaderTimeoutExpired (const std::chrono::steady_clock::time_point &now)
 
bool IsDone () const
 
bool IsPaused () const
 
bool IsRedirect () const
 
std::unique_ptr< ResponseInfo > MoveResponseInfo ()
 
bool OperationTimeoutExpired (const std::chrono::steady_clock::time_point &now)
 
virtual void SetContinueQueue (std::shared_ptr< XrdClHttp::HandlerQueue > queue)
 
void SetTriedBoker ()
 
bool StartConnectionCallout (std::string &err)
 
std::tuple< uint64_t, std::chrono::steady_clock::duration, std::chrono::steady_clock::duration, std::chrono::steady_clock::duration > StatisticsReset ()
 
bool TransferStalled (uint64_t xfer_bytes, const std::chrono::steady_clock::time_point &now)
 
bool UseConnectionCallout ()
 
virtual int WaitSocket ()
 
virtual int WaitSocketCallback (std::string &err)
 

Protected Member Functions

void SuccessImpl (bool returnObj)
 
- Protected Member Functions inherited from XrdClHttp::CurlOperation
int FailCallback (XErrorCode ecode, const std::string &emsg)
 
void SetDone (bool has_failed)
 
void SetPaused (bool paused)
 
bool SetupNextRequest (const std::string &url, CurlWorker &worker)
 
void UpdateBytes (uint64_t bytes)
 

Additional Inherited Members

- Public Types inherited from XrdClHttp::CurlOperation
using HeaderList = std::vector<std::pair<std::string, std::string>>
 
using HttpVerb = XrdClHttp::HttpVerb
 
enum  OpError {
  ErrNone ,
  ErrHeaderTimeout ,
  ErrCallback ,
  ErrOperationTimeout ,
  ErrTransferClientStall ,
  ErrTransferStall ,
  ErrTransferSlow
}
 
enum class  RedirectAction {
  Fail ,
  Reinvoke ,
  ReinvokeAfterAllow
}
 
- Static Public Member Functions inherited from XrdClHttp::CurlOperation
static void CleanupDnsCache ()
 
static int GetDefaultSlowRateBytesSec ()
 
static int GetDefaultStallTimeout ()
 
static const std::string GetVerbString (HttpVerb)
 
static void SetSlowRateBytesSec (int rate)
 
static void SetStallTimeout (const std::chrono::steady_clock::duration &stall_interval)
 
static void SetStallTimeout (int stall_interval)
 
- Protected Attributes inherited from XrdClHttp::CurlOperation
std::unique_ptr< CURL, void(*)(CURL *)> m_curl
 
XrdCl::ResponseHandler * m_handler {nullptr}
 
HeaderCallout * m_header_callout
 
std::atomic< std::chrono::steady_clock::time_point > m_header_expiry
 
HeaderParser m_headers
 
std::vector< std::pair< std::string, std::string > > m_headers_list
 
XrdCl::Log * m_logger
 
int m_minimum_rate {m_minimum_transfer_rate}
 
std::chrono::steady_clock::time_point m_operation_expiry
 
std::string m_request_url
 
const std::string m_url
 
- Static Protected Attributes inherited from XrdClHttp::CurlOperation
static constexpr int m_default_minimum_rate {1024 * 256}
 
static int m_minimum_transfer_rate {CurlOperation::m_default_minimum_rate}
 

Detailed Description

Definition at line 466 of file XrdClHttpOps.hh.

Constructor & Destructor Documentation

◆ CurlStatOp()

XrdClHttp::CurlStatOp::CurlStatOp ( XrdCl::ResponseHandler * handler,
const std::string & url,
struct timespec timeout,
XrdCl::Log * log,
bool response_info,
CreateConnCalloutType callout,
HeaderCallout * header_callout )
inline

Definition at line 468 of file XrdClHttpOps.hh.

469 :
470 CurlOperation(handler, url, timeout, log, callout, header_callout),
471 m_response_info(response_info)
472 {
474 }
std::chrono::steady_clock::time_point GetHeaderExpiry() const
std::chrono::steady_clock::time_point m_operation_expiry
CurlOperation(XrdCl::ResponseHandler *handler, const std::string &url, struct timespec timeout, XrdCl::Log *log, CreateConnCalloutType, HeaderCallout *header_callout)

References XrdClHttp::CurlOperation::CurlOperation(), XrdClHttp::CurlOperation::GetHeaderExpiry(), and XrdClHttp::CurlOperation::m_operation_expiry.

Referenced by XrdClHttp::CurlChecksumOp::CurlChecksumOp(), XrdClHttp::CurlOpenOp::CurlOpenOp(), and XrdClHttp::CurlQueryOp::CurlQueryOp().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ~CurlStatOp()

virtual XrdClHttp::CurlStatOp::~CurlStatOp ( )
inlinevirtual

Definition at line 476 of file XrdClHttpOps.hh.

476{}

Member Function Documentation

◆ GetStatInfo()

std::pair< int64_t, bool > CurlStatOp::GetStatInfo ( )

Definition at line 158 of file XrdClHttpOpStat.cc.

158 {
159 if (!m_is_propfind) {
160 m_length = m_headers.GetContentLength();
161 return {m_length, false};
162 }
163 if (m_length >= 0) {
164 return {m_length, m_is_dir};
165 }
166
167 TiXmlDocument doc;
168 doc.Parse(m_response.c_str());
169 if (doc.Error()) {
170 m_logger->Error(kLogXrdClHttp, "Failed to parse XML response: %s", m_response.substr(0, 1024).c_str());
171 return {-1, false};
172 }
173
174 auto elem = doc.RootElement();
175 if (strcasecmp(elem->Value(), "D:multistatus")) {
176 m_logger->Error(kLogXrdClHttp, "Unexpected XML response: %s", m_response.substr(0, 1024).c_str());
177 return {-1, false};
178 }
179 auto found_response = false;
180 for (auto response = elem->FirstChildElement(); response != nullptr; response = response->NextSiblingElement()) {
181 if (!strcasecmp(response->Value(), "D:response")) {
182 found_response = true;
183 elem = response;
184 break;
185 }
186 }
187 if (!found_response) {
188 m_logger->Error(kLogXrdClHttp, "Failed to find response element in XML response: %s", m_response.substr(0, 1024).c_str());
189 return {-1, false};
190 }
191 for (auto child = elem->FirstChildElement(); child != nullptr; child = child->NextSiblingElement()) {
192 if (strcasecmp(child->Value(), "D:propstat")) {
193 continue;
194 }
195 for (auto prop = child->FirstChildElement(); prop != nullptr; prop = prop->NextSiblingElement()) {
196 if (!strcasecmp(prop->Value(), "D:prop")) {
197 return ParseProp(prop);
198 }
199 }
200 }
201 m_logger->Error(kLogXrdClHttp, "Failed to find properties in XML response: %s", m_response.substr(0, 1024).c_str());
202 return {-1, false};
203}
static void child()
const uint64_t kLogXrdClHttp

References child(), XrdClHttp::kLogXrdClHttp, XrdClHttp::CurlOperation::m_headers, and XrdClHttp::CurlOperation::m_logger.

Referenced by XrdClHttp::CurlOpenOp::Success(), and SuccessImpl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetVerb()

virtual HttpVerb XrdClHttp::CurlStatOp::GetVerb ( ) const
inlineoverridevirtual

Implements XrdClHttp::CurlOperation.

Reimplemented in XrdClHttp::CurlChecksumOp.

Definition at line 488 of file XrdClHttpOps.hh.

References XrdClHttp::HEAD, and XrdClHttp::PROPFIND.

◆ OptionsDone()

void CurlStatOp::OptionsDone ( )
overridevirtual

Reimplemented from XrdClHttp::CurlOperation.

Reimplemented in XrdClHttp::CurlChecksumOp.

Definition at line 36 of file XrdClHttpOpStat.cc.

37{
38 auto &instance = VerbsCache::Instance();
39 auto target = m_headers.GetLocation();
40 auto verbs = instance.Get(target.empty() ? m_url : target);
41 if (verbs.IsSet(VerbsCache::HttpVerb::kPROPFIND)) {
42 curl_easy_setopt(m_curl.get(), CURLOPT_CUSTOMREQUEST, "PROPFIND");
43 m_headers_list.emplace_back("Depth", "0");
44 curl_easy_setopt(m_curl.get(), CURLOPT_NOBODY, 0L);
45 m_is_propfind = true;
46 } else {
47 m_is_propfind = false;
48 curl_easy_setopt(m_curl.get(), CURLOPT_NOBODY, 1L);
49 }
50}
const std::string m_url
std::unique_ptr< CURL, void(*)(CURL *)> m_curl
std::vector< std::pair< std::string, std::string > > m_headers_list
static VerbsCache & Instance()

References XrdClHttp::VerbsCache::Instance(), XrdClHttp::VerbsCache::kPROPFIND, XrdClHttp::CurlOperation::m_curl, XrdClHttp::CurlOperation::m_headers, XrdClHttp::CurlOperation::m_headers_list, and XrdClHttp::CurlOperation::m_url.

+ Here is the call graph for this function:

◆ Redirect()

CurlOperation::RedirectAction CurlStatOp::Redirect ( std::string & target)
overridevirtual

Reimplemented from XrdClHttp::CurlOperation.

Definition at line 53 of file XrdClHttpOpStat.cc.

54{
55 auto headers = m_headers;
56 auto result = CurlOperation::Redirect(target);
58 return result;
59 }
60 auto &instance = VerbsCache::Instance();
61 auto verbs = instance.Get(target);
62 if (verbs.IsSet(VerbsCache::HttpVerb::kUnset)) {
63 m_headers = std::move(headers);
65 }
66
67 if (verbs.IsSet(VerbsCache::HttpVerb::kPROPFIND)) {
68 curl_easy_setopt(m_curl.get(), CURLOPT_CUSTOMREQUEST, "PROPFIND");
69 m_headers_list.emplace_back("Depth", "0");
70 curl_easy_setopt(m_curl.get(), CURLOPT_NOBODY, 0L);
71 m_is_propfind = true;
72 } else {
73 m_is_propfind = false;
74 curl_easy_setopt(m_curl.get(), CURLOPT_NOBODY, 1L);
75 }
77}
virtual RedirectAction Redirect(std::string &target)

References XrdClHttp::CurlOperation::Fail, XrdClHttp::VerbsCache::Instance(), XrdClHttp::VerbsCache::kPROPFIND, XrdClHttp::VerbsCache::kUnset, XrdClHttp::CurlOperation::m_curl, XrdClHttp::CurlOperation::m_headers, XrdClHttp::CurlOperation::m_headers_list, XrdClHttp::CurlOperation::Redirect(), XrdClHttp::CurlOperation::Reinvoke, and XrdClHttp::CurlOperation::ReinvokeAfterAllow.

+ Here is the call graph for this function:

◆ ReleaseHandle()

void CurlStatOp::ReleaseHandle ( )
overridevirtual

Reimplemented from XrdClHttp::CurlOperation.

Definition at line 100 of file XrdClHttpOpStat.cc.

101{
102 if (m_curl == nullptr) return;
103 curl_easy_setopt(m_curl.get(), CURLOPT_NOBODY, 0L);
104 if (m_is_propfind) {
105 curl_easy_setopt(m_curl.get(), CURLOPT_CUSTOMREQUEST, nullptr);
106 }
107 curl_easy_setopt(m_curl.get(), CURLOPT_WRITEFUNCTION, nullptr);
108 curl_easy_setopt(m_curl.get(), CURLOPT_WRITEDATA, nullptr);
110}
virtual void ReleaseHandle()

References XrdClHttp::CurlOperation::m_curl, and XrdClHttp::CurlOperation::ReleaseHandle().

Referenced by XrdClHttp::CurlChecksumOp::ReleaseHandle(), and XrdClHttp::CurlOpenOp::ReleaseHandle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RequiresOptions()

bool CurlStatOp::RequiresOptions ( ) const
overridevirtual

Reimplemented from XrdClHttp::CurlOperation.

Definition at line 205 of file XrdClHttpOpStat.cc.

206{
207 auto &instance = VerbsCache::Instance();
208 auto verbs = instance.Get(m_url);
209 return verbs.IsSet(VerbsCache::HttpVerb::kUnset);
210}

References XrdClHttp::VerbsCache::Instance(), XrdClHttp::VerbsCache::kUnset, and XrdClHttp::CurlOperation::m_url.

+ Here is the call graph for this function:

◆ Setup()

bool CurlStatOp::Setup ( CURL * curl,
CurlWorker & worker )
overridevirtual

Reimplemented from XrdClHttp::CurlOperation.

Definition at line 80 of file XrdClHttpOpStat.cc.

81{
82 if (!CurlOperation::Setup(curl, worker)) return false;
83 curl_easy_setopt(m_curl.get(), CURLOPT_WRITEFUNCTION, CurlStatOp::WriteCallback);
84 curl_easy_setopt(m_curl.get(), CURLOPT_WRITEDATA, this);
85
86 auto &instance = VerbsCache::Instance();
87 auto verbs = instance.Get(m_url);
88 if (verbs.IsSet(VerbsCache::HttpVerb::kPROPFIND)) {
89 curl_easy_setopt(m_curl.get(), CURLOPT_CUSTOMREQUEST, "PROPFIND");
90 m_headers_list.emplace_back("Depth", "0");
91 curl_easy_setopt(m_curl.get(), CURLOPT_NOBODY, 0L);
92 m_is_propfind = true;
93 } else {
94 curl_easy_setopt(m_curl.get(), CURLOPT_NOBODY, 1L);
95 }
96 return true;
97}
virtual bool Setup(CURL *curl, CurlWorker &)

References XrdClHttp::VerbsCache::Instance(), XrdClHttp::VerbsCache::kPROPFIND, XrdClHttp::CurlOperation::m_curl, XrdClHttp::CurlOperation::m_headers_list, XrdClHttp::CurlOperation::m_url, and XrdClHttp::CurlOperation::Setup().

Referenced by XrdClHttp::CurlChecksumOp::Setup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Success()

void CurlStatOp::Success ( )
overridevirtual

Implements XrdClHttp::CurlOperation.

Definition at line 212 of file XrdClHttpOpStat.cc.

213{
214 SuccessImpl(true);
215}
void SuccessImpl(bool returnObj)

References SuccessImpl().

+ Here is the call graph for this function:

◆ SuccessImpl()

void CurlStatOp::SuccessImpl ( bool returnObj)
protected

Definition at line 218 of file XrdClHttpOpStat.cc.

219{
220 SetDone(false);
221 m_logger->Debug(kLogXrdClHttp, "CurlStatOp::Success");
222 if (m_handler == nullptr) {return;}
223 XrdCl::AnyObject *obj = nullptr;
224 if (returnObj) {
225 auto [size, isdir] = GetStatInfo();
226 if (size < 0) {
227 m_logger->Error(kLogXrdClHttp, "Failed to get stat info for %s", m_url.c_str());
228 Fail(XrdCl::errErrorResponse, kXR_FSError, "Server responded without object size");
229 return;
230 }
231 if (m_is_propfind) {
232 m_logger->Debug(kLogXrdClHttp, "Successful propfind operation on %s (size %lld, isdir %d)", m_url.c_str(), static_cast<long long>(size), isdir);
233 } else {
234 m_logger->Debug(kLogXrdClHttp, "Successful stat operation on %s (size %lld)", m_url.c_str(), static_cast<long long>(size));
235 }
236
237 time_t mtime = m_is_propfind ? m_modtime : m_headers.GetModTime();
238 if (mtime < 0) {
239 mtime = time(NULL);
240 }
241 XrdCl::StatInfo *stat_info;
242 if (m_response_info){
243 auto info = new XrdClHttp::StatResponse("nobody", size,
245 info->SetResponseInfo(MoveResponseInfo());
246 stat_info = info;
247 } else {
248 stat_info = new XrdCl::StatInfo("nobody", size,
250 }
251 obj = new XrdCl::AnyObject();
252 obj->Set(stat_info);
253 } else if (m_response_info) {
254 auto info = new XrdClHttp::OpenResponseInfo();
255 info->SetResponseInfo(MoveResponseInfo());
256 obj = new XrdCl::AnyObject();
257 obj->Set(info);
258 }
259
260 auto handle = m_handler;
261 m_handler = nullptr;
262 handle->HandleResponse(new XrdCl::XRootDStatus(), obj);
263}
@ kXR_FSError
void SetDone(bool has_failed)
std::unique_ptr< ResponseInfo > MoveResponseInfo()
XrdCl::ResponseHandler * m_handler
std::pair< int64_t, bool > GetStatInfo()
void Set(Type object, bool own=true)
@ IsReadable
Read access is allowed.
@ IsDir
This is a directory.
const uint16_t errErrorResponse

References XrdCl::errErrorResponse, XrdClHttp::CurlOperation::Fail, GetStatInfo(), XrdCl::StatInfo::IsDir, XrdCl::StatInfo::IsReadable, XrdClHttp::kLogXrdClHttp, kXR_FSError, XrdClHttp::CurlOperation::m_handler, XrdClHttp::CurlOperation::m_headers, XrdClHttp::CurlOperation::m_logger, XrdClHttp::CurlOperation::m_url, XrdClHttp::CurlOperation::MoveResponseInfo(), XrdCl::AnyObject::Set(), and XrdClHttp::CurlOperation::SetDone().

Referenced by XrdClHttp::CurlOpenOp::Fail(), XrdClHttp::CurlOpenOp::Success(), and Success().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: