24 posix_flags |= O_CREAT | O_EXCL;
27 posix_flags |= O_CREAT | O_TRUNC;
30 posix_flags |= O_RDONLY;
33 posix_flags |= O_WRONLY;
36 posix_flags |= O_RDWR;
59 std::string origin = getenv(
"XRDXROOTD_PROXY")? getenv(
"XRDXROOTD_PROXY") :
"";
60 if ( origin.empty() || origin.find(
"=") == 0) {
61 davix_context_ =
new Davix::Context();
62 davix_client_ =
new Davix::DavPosix(davix_context_);
78 delete davix_context_;
90 if (
XrdCl::URL(url).GetProtocol().find(
"https") == 0)
91 isChannelEncrypted =
true;
93 isChannelEncrypted =
false;
101 if (search != CGIs.end())
105 Davix::RequestParams params;
107 struct timespec ts = {timeout, 0};
108 params.setOperationTimeout(&ts);
113 auto pos = full_path.find_last_of(
'/');
115 pos != std::string::npos ? full_path.substr(0, pos) : full_path;
119 if (mkdir_status.IsError()) {
121 "Could not create parent directories when opening: %s",
130 auto status =
Posix::Stat(*davix_client_, url, timeout, stat_info);
132 auto unlink_status =
Posix::Unlink(*davix_client_, url, timeout);
133 if (unlink_status.IsError()) {
136 "Could not delete existing destination file: %s. Error: %s",
137 url.c_str(), unlink_status.GetErrorMessage().c_str());
138 return unlink_status;
145 auto status =
Posix::Stat(*davix_client_, url, timeout, stat_info);
147 filesize = stat_info->GetSize();
152 auto posix_open_flags = MakePosixOpenFlags(flags);
155 "Open: URL: %s, XRootD flags: %d, POSIX flags: %d",
156 url.c_str(), flags, posix_open_flags);
159 auto res =
Posix::Open(*davix_client_, url, posix_open_flags, timeout);
162 res.second.ToStr().c_str());
166 davix_fd_ = res.first;
183 "Cannot close. URL hasn't been previously opened");
190 if (status.IsError()) {
192 davix_fd_, status.ToStr().c_str());
208 "Cannot stat. URL hasn't been previously opened");
213 auto status =
Posix::Stat(*davix_client_, url_, timeout, stat_info);
217 if (status.IsError() && status.code == 400 && status.errNo == 3011) {
218 std::ostringstream data;
219 data << 140737018595560 <<
" " << filesize <<
" " << 33261 <<
" " << time(NULL);
220 stat_info->ParseServerResponse(data.str().c_str());
222 else if (status.IsError()) {
242 "Cannot read. URL hasn't previously been opened");
247 size = (offset + size > filesize)? filesize - offset : size;
248 std::pair<int, XRootDStatus> res;
249 if (! avoid_pread_) {
250 res =
Posix::PRead(*davix_client_, davix_fd_, buffer, size, offset);
253 offset_locker.lock();
254 if (offset == curr_offset) {
255 res =
Posix::Read(*davix_client_, davix_fd_, buffer, size);
258 res =
Posix::PRead(*davix_client_, davix_fd_, buffer, size, offset);
262 if (res.second.IsError()) {
264 url_.c_str(), res.second.ToStr().c_str());
265 if (avoid_pread_) offset_locker.unlock();
269 int num_bytes_read = res.first;
270 curr_offset = offset + num_bytes_read;
271 if (avoid_pread_) offset_locker.unlock();
274 num_bytes_read, offset, url_.c_str());
277 auto chunk_info =
new ChunkInfo(offset, num_bytes_read, buffer);
279 obj->Set(chunk_info);
288 bool isChannelEncrypted;
292 bool isHttps) : realHandler(a), isChannelEncrypted(isHttps) {}
298 if( !status->
IsOK() )
310 std::vector<uint32_t> cksums;
311 if( isChannelEncrypted )
316 cksums.reserve( nbpages );
318 size_t size = chunk->
length;
319 char *buffer =
reinterpret_cast<char*
>( chunk->
buffer );
321 for(
size_t pg = 0; pg < nbpages; ++pg )
324 if( pgsize > size ) pgsize = size;
326 cksums.push_back( crcval );
335 response->
Set( pages );
355 "Cannot write. URL hasn't previously been opened");
361 Posix::PWrite(*davix_client_, davix_fd_, offset, size, buffer, timeout);
362 if (res.second.IsError()) {
364 url_.c_str(), res.second.ToStr().c_str());
368 filesize += res.first;
371 res.first, offset, url_.c_str());
384 std::vector<uint32_t> &cksums,
388 return Write(offset, size, buffer, handler, timeout);
406 "Cannot read. URL hasn't previously been opened");
410 const auto num_chunks = chunks.size();
411 std::vector<Davix::DavIOVecInput> input_vector(num_chunks);
412 std::vector<Davix::DavIOVecOuput> output_vector(num_chunks);
414 for (
size_t i = 0; i < num_chunks; ++i) {
415 input_vector[i].diov_offset = chunks[i].offset;
416 input_vector[i].diov_size = chunks[i].length;
417 input_vector[i].diov_buffer = chunks[i].buffer;
422 if (res.second.IsError()) {
424 url_.c_str(), res.second.ToStr().c_str());
428 int num_bytes_read = res.first;
431 num_bytes_read, url_.c_str());
433 char *output =
static_cast<char *
>(buffer);
434 for (
size_t i = 0; i < num_chunks; ++i) {
435 std::memcpy(output + input_vector[i].diov_offset,
436 output_vector[i].diov_buffer, output_vector[i].diov_size);
441 read_info->SetSize(num_bytes_read);
442 read_info->GetChunks() = chunks;
453 const std::string &value) {
454 properties_[name] = value;
459 std::string &value)
const {
460 const auto p = properties_.find(name);
461 if (p == std::end(properties_)) {
#define HTTP_FILE_PLUG_IN_AVOIDRANGE_ENV
#define HTTP_FILE_PLUG_IN_AVOIDRANGE_CGI
void Set(Type object, bool own=true)
void Get(Type &object)
Retrieve the object being held.
virtual XRootDStatus PgRead(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout) override
virtual XRootDStatus PgWrite(uint64_t offset, uint32_t size, const void *buffer, std::vector< uint32_t > &cksums, ResponseHandler *handler, uint16_t timeout) override
virtual XRootDStatus Sync(ResponseHandler *handler, uint16_t timeout) override
virtual XRootDStatus Stat(bool force, ResponseHandler *handler, uint16_t timeout) override
virtual XRootDStatus Write(uint64_t offset, uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout) override
virtual XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout) override
virtual XRootDStatus VectorRead(const ChunkList &chunks, void *buffer, XrdCl::ResponseHandler *handler, uint16_t timeout) override
virtual ~HttpFilePlugIn() noexcept
virtual XRootDStatus Open(const std::string &url, OpenFlags::Flags flags, Access::Mode mode, ResponseHandler *handler, uint16_t timeout) override
virtual bool GetProperty(const std::string &name, std::string &value) const override
virtual XRootDStatus Close(ResponseHandler *handler, uint16_t timeout) override
virtual bool SetProperty(const std::string &name, const std::string &value) override
virtual bool IsOpen() const override
void Error(uint64_t topic, const char *format,...)
Report an error.
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
void HandleResponse(XrdCl::XRootDStatus *status, XrdCl::AnyObject *rdresp)
PgReadSubstitutionHandler(XrdCl::ResponseHandler *a, bool isHttps)
Handle an async response.
virtual void HandleResponse(XRootDStatus *status, AnyObject *response)
std::map< std::string, std::string > ParamsMap
std::string GetLocation() const
Get location (protocol://host:port/path)
const ParamsMap & GetParams() const
Get the URL params.
static uint32_t Calc32C(const void *data, size_t count, uint32_t prevcs=0)
std::pair< int, XrdCl::XRootDStatus > PReadVec(Davix::DavPosix &davix_client, DAVIX_FD *fd, const XrdCl::ChunkList &chunks, void *buffer)
std::pair< int, XRootDStatus > Read(Davix::DavPosix &davix_client, DAVIX_FD *fd, void *buffer, uint32_t size)
std::pair< int, XrdCl::XRootDStatus > PWrite(Davix::DavPosix &davix_client, DAVIX_FD *fd, uint64_t offset, uint32_t size, const void *buffer, uint16_t timeout)
std::pair< DAVIX_FD *, XRootDStatus > Open(Davix::DavPosix &davix_client, const std::string &url, int flags, uint16_t timeout)
std::pair< int, XRootDStatus > PRead(Davix::DavPosix &davix_client, DAVIX_FD *fd, void *buffer, uint32_t size, uint64_t offset)
XRootDStatus Close(Davix::DavPosix &davix_client, DAVIX_FD *fd)
XRootDStatus Unlink(Davix::DavPosix &davix_client, const std::string &url, uint16_t timeout)
XRootDStatus MkDir(Davix::DavPosix &davix_client, const std::string &path, XrdCl::MkDirFlags::Flags flags, XrdCl::Access::Mode, uint16_t timeout)
XRootDStatus Stat(Davix::DavPosix &davix_client, const std::string &url, uint16_t timeout, StatInfo *stat_info)
const uint16_t stError
An error occurred that could potentially be retried.
const uint16_t errInvalidOp
Davix::Context * root_davix_context_
std::vector< ChunkInfo > ChunkList
List of chunks.
Davix::DavPosix * root_davix_client_file_
void SetUpLogging(Log *logger)
static const uint64_t kLogXrdClHttp
static const int PageSize
Describe a data chunk for vector read.
void * buffer
length of the chunk
uint32_t length
offset in the file
@ MakePath
create the entire directory tree if it doesn't exist
Flags
Open flags, may be or'd when appropriate.
@ Read
Open only for reading.
@ Write
Open only for writing.
@ Update
Open for reading and writing.
bool IsOK() const
We're fine.