Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:12

0001 /*
0002  * This File is part of Davix, The IO library for HTTP based protocols
0003  * Copyright (C) CERN 2013
0004  * Author: Adrien Devresse <adrien.devresse@cern.ch>
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Lesser General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2.1 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Lesser General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Lesser General Public
0017  * License along with this library; if not, write to the Free Software
0018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0019  *
0020 */
0021 
0022 #ifndef DAVFILE_HPP
0023 #define DAVFILE_HPP
0024 
0025 #include <memory>
0026 #include <istream>
0027 #include <ostream>
0028 #include <davixcontext.hpp>
0029 #include <params/davixrequestparams.hpp>
0030 #include <file/davix_file_info.hpp>
0031 #include <compat/deprecated.hpp>
0032 
0033 
0034 
0035 #ifndef __DAVIX_INSIDE__
0036 #error "Only davix.h or davix.hpp should be included."
0037 #endif
0038 
0039 
0040 ///
0041 /// @file davfile.hpp
0042 /// @author Devresse Adrien
0043 ///
0044 ///  File API of Davix
0045 
0046 
0047 namespace Davix{
0048 
0049 
0050 struct StatInfo;
0051 
0052 ///
0053 /// @class DavFile
0054 /// @brief Davix File Interface
0055 ///
0056 /// Davix File interface
0057 class DAVIX_EXPORT DavFile
0058 {
0059 public:
0060     struct DavFileInternal;
0061 
0062     class Iterator{
0063         friend struct DavFileInternal;
0064         public:
0065             Iterator() : d_ptr() {}
0066             Iterator(const Iterator & orig) : d_ptr(orig.d_ptr){}
0067 
0068             bool next();
0069 
0070             const std::string & name();
0071             const StatInfo & info();
0072         private:
0073            struct Internal;
0074 
0075            std::shared_ptr<Internal> d_ptr;
0076     };
0077 
0078     ///
0079     /// \brief default constructor
0080     /// \param c context
0081     /// \param url remote file URL
0082     ///
0083     DavFile(Context & c, const Uri & url);
0084     DavFile(Context &c, const RequestParams & params, const Uri &url);
0085     DavFile(const DavFile & orig);
0086     ///
0087     /// \brief destructor
0088     ///
0089     virtual ~DavFile();
0090 
0091     /// @brief return Uri of the current file
0092     ///
0093     const Uri & getUri() const;
0094 
0095     ///
0096     /// @brief return all replicas associated to this file
0097     ///
0098     /// Replicas are found using a corresponding The MetaLink standard ( rfc5854, rfc6249 )
0099     ///
0100     /// @param params  Davix Request parameters
0101     /// @param err  Davix error report
0102     /// @return  Replica vector, if error is found return empty vector and set err properly
0103     ///
0104     /// @snippet example_code_snippets.cpp getReplicas
0105     std::vector<DavFile> getReplicas(const RequestParams* params, DavixError** err) throw();
0106 
0107     ///
0108     ///  @brief Vector read operation
0109     ///        Able to do several read on several data chunk in one single operation.
0110     ///        Uses Http multi-part when supported by the server,
0111     ///        simulate a vector read operation otherwise.
0112     ///
0113     ///        NOTE: The return code is the number of data bytes received from the
0114     ///              server, not the total number of bytes written into the buffers.
0115     ///              The two might not be equal if range coalescing is performed.
0116     ///              Check diov_size of the output vector to make sure the buffers
0117     ///              contain the expected number of bytes.
0118     ///
0119     ///  @param params Davix request Parameters
0120     ///  @param input_vec input vectors, parameters
0121     ///  @param ioutput_vec  output vectors, results
0122     ///  @param count_vec  number of vector
0123     ///  @param err Davix error report
0124     ///  @return total number of bytes read, or -1 if error occures
0125     ///
0126     ///  @snippet example_code_snippets.cpp readPartialBufferVec
0127     dav_ssize_t readPartialBufferVec(const RequestParams* params,
0128                           const DavIOVecInput * input_vec,
0129                           DavIOVecOuput * ioutput_vec,
0130                           const dav_size_t count_vec,
0131                           DavixError** err) throw();
0132 
0133     ///
0134     ///  @brief Partial position independant read.
0135     ///
0136     ///
0137     ///         Use ranged request when supported by the server,
0138     ///         simulate a ranged request when not supported
0139     ///
0140     ///  @param params Davix request Parameters
0141     ///  @param buff  buffer
0142     ///  @param count  maximum read size
0143     ///  @param offset  starting offset for the read operation
0144     ///  @param err Davix error report
0145     ///  @return total number of bytes read, or -1 if error occures
0146     ///
0147     ///  @snippet example_code_snippets.cpp readPartial
0148     dav_ssize_t readPartial(const RequestParams* params,
0149                             void* buff,
0150                             dav_size_t count,
0151                             dav_off_t offset,
0152                             DavixError** err) throw();
0153 
0154 
0155     ///
0156     ///  @brief Get the full file content and write it to file descriptor
0157     ///
0158     ///  @param params Davix request Parameters
0159     ///  @param fd  file descriptor for write operation
0160     ///  @param err Davix error report
0161     ///  @return total number of bytes read, or -1 if error occures
0162     ///
0163     ///  @snippet example_code_snippets.cpp getToFd
0164     dav_ssize_t getToFd(const RequestParams* params,
0165                             int fd,
0166                             DavixError** err) throw();
0167 
0168     ///
0169     ///  @brief Get the first 'size_read' bytes of the file and write it to file descriptor
0170     ///
0171     ///  @param params Davix request Parameters
0172     ///  @param fd file descriptor for write operation
0173     ///  @param size_read number of bytes to read
0174     ///  @param err Davix error report
0175     ///  @return total number of bytes read, or -1 if error occures
0176     ///
0177     ///  @snippet example_code_snippets.cpp getToFd sized
0178     dav_ssize_t getToFd(const RequestParams* params,
0179                             int fd,
0180                             dav_size_t size_read,
0181                             DavixError** err) throw();
0182 
0183     ///
0184     ///  @brief Get the full file content in a dynamically allocated buffer
0185     ///
0186     ///  @param params Davix request Parameters
0187     ///  @param buffer reference to a vector for the result
0188     ///  @param err Davix error report
0189     ///  @return total number of bytes read, or -1 if error occures
0190     ///
0191     ///  @snippet example_code_snippets.cpp getFull
0192     dav_ssize_t getFull(const RequestParams* params,
0193                             std::vector<char> & buffer,
0194                             DavixError** err) throw();
0195 
0196 
0197     ///
0198     ///  @brief Get the full file content to buffer
0199     ///
0200     ///  @param params Davix request Parameters
0201     ///  @param buffer reference to a vector for storing the result
0202     ///  @return total number of bytes read, or -1 if error occures
0203     ///
0204     /// Get the file content in a dynamically allocated buffer
0205     ///
0206     ///  WARNING: this operation is without size limit for the content
0207     ///
0208     ///  @snippet example_code_snippets.cpp get
0209     dav_ssize_t get(const RequestParams* params,
0210                     std::vector<char> & buffer);
0211 
0212 
0213 
0214     ///
0215     ///  @brief Create/Replace file content
0216     ///
0217     ///  @param params Davix request Parameters
0218     ///  @param fd file descriptor
0219     ///  @param size_write number of bytes to write
0220     ///  @throw throw @ref DavixException if an error occurs
0221     ///
0222     ///  Create / Replace the file.
0223     ///  Read the new content from the file descriptor fd for a maximum of size_write bytes.
0224     ///
0225     ///  @snippet example_code_snippets.cpp put fd
0226     void put(const RequestParams* params, int fd, dav_size_t size_write);
0227 
0228 
0229     ///
0230     ///  @brief Create/Replace file content
0231     ///
0232     ///  @param params Davix request Parameters
0233     ///  @param buffer buffer with data to write
0234     ///  @param size_write number of bytes to write
0235     ///  @throw throw @ref DavixException if an error occurs
0236     ///
0237     ///  Set a new content for the file.
0238     ///  The new content comes from buffer.
0239     ///
0240     ///  @snippet example_code_snippets.cpp put buffer
0241     void put(const RequestParams* params, const char* buffer, dav_size_t size_write);
0242 
0243 #ifdef __DAVIX_HAS_STD_FUNCTION
0244 
0245     ///
0246     ///  @brief Create/Replace file content
0247     ///
0248     ///  @param params Davix request Parameters
0249     ///  @param callback data provider callback
0250     ///  @param size Total size of the data to write
0251     ///  @throw throw @ref DavixException if an error occurs
0252     ///
0253     ///  Set a new content for the file.
0254     ///  The new content comes from a data provider callback.
0255     ///
0256     ///  @snippet example_code_snippets.cpp put callback
0257     void put(const RequestParams* params, const DataProviderFun & callback, dav_size_t size);
0258 
0259 #endif
0260 
0261     ///
0262     /// @brief move
0263     /// @param params Davix request Parameters
0264     /// @param destination destination resource
0265     ///
0266     /// Move the current resource to Destination.
0267     ///
0268     /// The result of the operation depend of the protocol used.
0269     ///
0270     /// Protocol supported currently: WebDav, S3
0271     ///
0272     /// @snippet example_code_snippets.cpp move
0273     void move(const RequestParams* params, DavFile & destination);
0274 
0275 
0276     ///
0277     ///  @brief Suppress the current entity or collection.
0278     ///
0279     ///  @param params Davix request Parameters
0280     ///  @throw  throw @ref DavixException if error occurs
0281     ///
0282     ///  @snippet example_code_snippets.cpp delete
0283     void deletion(const RequestParams* params = NULL);
0284 
0285     ///
0286     ///  @brief Suppress the current entity or collection.
0287     ///
0288     ///  Exception safe version of @ref deletion(const RequestParams* params = NULL)
0289     ///
0290     ///  @snippet example_code_snippets.cpp delete no throw
0291     int deletion(const RequestParams* params,
0292                  DavixError** err) throw();
0293 
0294 
0295     ///
0296     ///  @brief create a collection (directory or bucket) at the current url
0297     ///
0298     ///  @param params Davix request Parameters
0299     ///  @throw  throw @ref DavixException if error occurs
0300     ///
0301     ///  @snippet example_code_snippets.cpp makeCollection
0302     void makeCollection(const RequestParams *params = NULL);
0303 
0304     ///
0305     ///  @brief create a collection (directory or bucket) at the current url
0306     ///
0307     ///  Exception safe version of @ref makeCollection(const RequestParams *params = NULL)
0308     ///
0309     ///  @snippet example_code_snippets.cpp makeCollection no throw
0310     int makeCollection(const RequestParams* params,
0311                        DavixError** err) throw();
0312 
0313     ///
0314     ///  @brief execute a file meta-data query
0315     ///
0316     ///  @param params Davix request Parameters
0317     ///  @param info stat struct
0318     ///  @return 0 if success, or -1 if error occures
0319     ///
0320     ///  @snippet example_code_snippets.cpp statInfo
0321     StatInfo & statInfo(const RequestParams* params, StatInfo & info);
0322 
0323     ///
0324     ///  @brief execute a POSIX-like stat() query
0325     ///
0326     ///  @param params Davix request parameters
0327     ///  @param st stat struct
0328     ///  @param err Davix error report
0329     ///  @return 0 if success, or -1 if error occures
0330     ///
0331     ///  @snippet example_code_snippets.cpp stat
0332     int stat(const RequestParams* params, struct stat * st, DavixError** err) throw();
0333 
0334     ///
0335     ///  @brief Collection listing
0336     ///
0337     ///  @param params Davix request parameters
0338     ///  @return Iterator to the collection
0339     ///
0340     ///  @snippet example_code_snippets.cpp listCollection
0341     Iterator  listCollection(const RequestParams* params);
0342 
0343 
0344     ///
0345     ///  @brief compute checksum of the file
0346     ///
0347     ///  with the given algorithm (MD5, CRC32, ADLER32)
0348     ///
0349     ///  server implementation dependend
0350     ///
0351     ///  Davix::checksum support LCGDM-DAV, dCache Jetty and Aws S3 checksum support
0352     ///
0353     ///  @param params request parameters
0354     ///  @param checksm checksum buffer
0355     ///  @param chk_algo string of the algorithm (eg: "MD5"  )
0356     ///  @return reference to checksm
0357     ///  @throw  throw @ref DavixException if error occurs
0358     ///
0359     ///  @snippet example_code_snippets.cpp checksum
0360     std::string & checksum(const RequestParams *params, std::string &checksm, const std::string &chk_algo);
0361 
0362     ///
0363     ///  @brief compute checksum of the file with the given algorithm (MD5, CRC32, ADLER32)
0364     ///
0365     ///  Exception safe version of @ref checksum
0366     ///
0367     ///  @snippet example_code_snippets.cpp checksum no throw
0368     int checksum(const RequestParams *params, std::string & checksm, const std::string & chk_algo, DavixError **err) throw();
0369 
0370 
0371     ///
0372     /// @brief provide information on the next file operation
0373     ///
0374     /// provide information on the next file operations for optimizations and prefetching
0375     ///
0376     /// @param offset
0377     /// @param size_read
0378     /// @param adv
0379     ///
0380     void prefetchInfo(off_t offset, dav_size_t size_read, advise_t adv);
0381 
0382     ///
0383     /// @brief retrieve quota information
0384     ///
0385     /// retrieve quota information about a directory
0386     ///
0387     /// @param params
0388     /// @param info
0389     ///
0390     QuotaInfo & quotaInfo(const RequestParams* params, QuotaInfo & info);
0391 
0392 private:
0393     DavFileInternal* d_ptr;
0394 
0395 public:
0396     /// @deprecated deprecated, will be removed in 2.0
0397     DEPRECATED(dav_ssize_t getAllReplicas(const RequestParams* params,
0398                                     ReplicaVec & vec, DavixError** err));
0399 
0400     ///
0401     ///  @deprecated please use put() as the replacement, will be removed in 2.0
0402     ///
0403     DEPRECATED(int putFromFd(const RequestParams* params,
0404                   int fd,
0405                   dav_size_t size_write,
0406                   DavixError** err) throw());
0407 };
0408 
0409 typedef DavFile File;
0410 
0411 
0412 } // Davix
0413 
0414 
0415 // provide stream operator for Davix::File
0416 std::ostream & operator<<(std::ostream & out, Davix::DavFile & file);
0417 std::istream & operator>>(std::istream & in, Davix::DavFile & file);
0418 
0419 #endif // DAVFILE_HPP