XRootD
XrdClHttpOpMkcol.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* Copyright (C) 2025, Pelican Project, Morgridge Institute for Research */
3 /* */
4 /* This file is part of the XrdClHttp client plugin for XRootD. */
5 /* */
6 /* XRootD is free software: you can redistribute it and/or modify it under */
7 /* the terms of the GNU Lesser General Public License as published by the */
8 /* Free Software Foundation, either version 3 of the License, or (at your */
9 /* option) any later version. */
10 /* */
11 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
12 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
13 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
14 /* License for more details. */
15 /* */
16 /* The copyright holder's institutional names and contributor's names may not */
17 /* be used to endorse or promote products derived from this software without */
18 /* specific prior written permission of the institution or contributor. */
19 /******************************************************************************/
20 
21 #include "XrdClHttpOps.hh"
22 #include "XrdClHttpResponses.hh"
23 
24 #include <XrdCl/XrdClLog.hh>
25 
26 using namespace XrdClHttp;
27 
28 CurlMkcolOp::CurlMkcolOp(XrdCl::ResponseHandler *handler, const std::string &url,
29  struct timespec timeout, XrdCl::Log *logger,
30  bool response_info, CreateConnCalloutType callout,
31  HeaderCallout *header_callout)
32  : CurlOperation(handler, url, timeout, logger, callout, header_callout)
33 {}
34 
36 
37 void
38 CurlMkcolOp::Fail(uint16_t errCode, uint32_t errNum, const std::string &msg)
39 {
40  // Note: the generic status code handler maps HTTP status "405 Method Not Allowed"
41  // to kXR_InvalidRequest.
42  //
43  // However, for the MKCOL operation, 405 maps better to kXR_ItExists
44  if (errCode == XrdCl::errErrorResponse && errNum == kXR_InvalidRequest && GetStatusCode() == 405) {
45  m_logger->Debug(kLogXrdClHttp, "MKCOL was performed on a directory that exists");
46  errNum = kXR_ItExists;
47  }
48  CurlOperation::Fail(errCode, errNum, msg);
49 }
50 
51 void
53  if (m_curl == nullptr) return;
54  curl_easy_setopt(m_curl.get(), CURLOPT_CUSTOMREQUEST, nullptr);
56 }
57 
58 bool
60  if (!CurlOperation::Setup(curl, worker)) return false;
61  curl_easy_setopt(m_curl.get(), CURLOPT_CUSTOMREQUEST, "MKCOL");
62 
63  return true;
64 }
65 
66 void
68  SetDone(false);
69  m_logger->Debug(kLogXrdClHttp, "CurlMkcolOp::Success");
70  if (m_handler == nullptr) {return;}
71 
72  XrdCl::AnyObject *obj{nullptr};
73  if (m_response_info) {
74  auto info = new XrdClHttp::MkdirResponseInfo();
75  info->SetResponseInfo(MoveResponseInfo());
76  obj = new XrdCl::AnyObject();
77  obj->Set(info);
78  }
79 
80  auto handle = m_handler;
81  m_handler = nullptr;
82  handle->HandleResponse(new XrdCl::XRootDStatus(), obj);
83 }
@ kXR_InvalidRequest
Definition: XProtocol.hh:1038
@ kXR_ItExists
Definition: XProtocol.hh:1050
void CURL
void Fail(uint16_t errCode, uint32_t errNum, const std::string &msg) override
bool Setup(CURL *curl, CurlWorker &) override
void ReleaseHandle() override
CurlMkcolOp(XrdCl::ResponseHandler *handler, const std::string &url, struct timespec timeout, XrdCl::Log *logger, bool response_info, CreateConnCalloutType callout, HeaderCallout *header_callout)
void SetDone(bool has_failed)
std::unique_ptr< CURL, void(*)(CURL *)> m_curl
virtual void Fail(uint16_t errCode, uint32_t errNum, const std::string &)
virtual void ReleaseHandle()
XrdCl::ResponseHandler * m_handler
std::unique_ptr< ResponseInfo > MoveResponseInfo()
virtual bool Setup(CURL *curl, CurlWorker &)
Handle diagnostics.
Definition: XrdClLog.hh:101
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
Definition: XrdClLog.cc:282
Handle an async response.
virtual void HandleResponse(XRootDStatus *status, AnyObject *response)
const uint16_t errErrorResponse
Definition: XrdClStatus.hh:105
ConnectionCallout *(*)(const std::string &, const ResponseInfo &) CreateConnCalloutType
const uint64_t kLogXrdClHttp