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 
0023 #ifndef DAVIX_DAVPOSIX_HPP
0024 #define DAVIX_DAVPOSIX_HPP
0025 
0026 
0027 
0028 #include <davix_file_types.hpp>
0029 #include <davixcontext.hpp>
0030 #include <params/davixrequestparams.hpp>
0031 #include <status/davixstatusrequest.hpp>
0032 
0033 
0034 /**
0035   @file davposix.hpp
0036   @author Devresse Adrien
0037 
0038   @brief POSIX-like API of davix
0039 */
0040 
0041 #ifndef __DAVIX_INSIDE__
0042 #error "Only davix.hpp for the C++ API or davix.h for the C API should be included."
0043 #endif
0044 
0045 
0046 
0047 namespace Davix {
0048 
0049 
0050 class DavPosixInternal;
0051 
0052 
0053 ///
0054 /// @brief POSIX-like API of Davix.
0055 ///
0056 /// DavPosix offers a POSIX-like API for HTTP/WebDav file operations.
0057 ///
0058 /// POSIX API can be used for convenience when porting application.
0059 /// to a POSIX like interface.
0060 ///
0061 /// DavPosix and all associated method are Thread safe.
0062 class DAVIX_EXPORT DavPosix : NonCopyable
0063 {
0064 public:
0065     ///
0066     /// \brief default constructor
0067     /// \param handle
0068     ///
0069     ///
0070     ///  @snippet example_code_snippets.cpp DavPosix
0071     DavPosix(Context* handle);
0072     virtual ~DavPosix();
0073 
0074 
0075     /**
0076       @brief POSIX-like stat() call
0077 
0078 
0079       Behavior similar to the POSIX stat function, see man 3 stat.
0080 
0081       Supported by Webdav, Http and S3.
0082 
0083       Depending of the protocol, some struct stat field can be ignored.
0084 
0085 
0086       @param params request options, can be NULL
0087       @param str string url
0088       @param st stat struct to fill
0089       @param err Davix error report system
0090       @return 0 if success, negative value if error
0091 
0092       @snippet example_code_snippets.cpp stat
0093      */
0094     int stat(const RequestParams* params, const std::string & str, struct stat * st, DavixError** err);
0095 
0096 
0097     /**
0098       @brief 64bits version of /ref Davix::DavPosix::stat.
0099 
0100       @snippet example_code_snippets.cpp stat
0101      */
0102     int stat64(const RequestParams *params, const std::string & url, StatInfo* st, DavixError** err);
0103 
0104     /**
0105       @brief get_quota gives quota information on a directory
0106      */
0107     int get_quota(const RequestParams *params, const std::string & url, QuotaInfo* st, DavixError** err);
0108 
0109 
0110     /**
0111       @brief open a directory for listing.
0112 
0113       behavior similar to the POSIX opendir function.
0114 
0115       Supported by Webdav.
0116 
0117       @param params request options, can be NULL
0118       @param url url of the directory to list
0119       @param err Davix error report system
0120       @return DAVIX_DIR davix readdir handle, NULL if error
0121 
0122       @snippet example_code_snippets.cpp opendir
0123     */
0124     DAVIX_DIR* opendir(const RequestParams* params, const std::string & url, DavixError** err);
0125 
0126     /**
0127       @brief read an entry directory.
0128 
0129       Behavior similar to the POSIX readdir function.
0130 
0131       @param dir directory handle
0132       @param err Davix Error report
0133       @return dirent struct if success, or NULL if error
0134 
0135       @snippet example_code_snippets.cpp opendir
0136     */
0137     struct dirent* readdir(DAVIX_DIR* dir, DavixError** err);
0138     /**
0139        @brief close a directory handle
0140 
0141        @param  d directory handle to close
0142        @param err Davix error report system
0143        @return 0 if success else a negative value and err is set.
0144 
0145        @snippet example_code_snippets.cpp opendir
0146     */
0147     int closedir(DAVIX_DIR* d, DavixError** err);
0148 
0149     /**
0150       @brief open a directory for listing with per entry meta-data information.
0151 
0152       Similar to \ref Davix::DavPosix::opendir but provide stat() information for each entry
0153       Supported by Webdav.
0154 
0155       @param params request options, can be NULL
0156       @param url url of the directory to list
0157       @param err Davix error report system
0158       @return DAVIX_DIR davix readdir handle or NULL if error, in this case err is set.
0159 
0160       @snippet example_code_snippets.cpp opendirpp
0161     */
0162     DAVIX_DIR* opendirpp(const RequestParams* params, const std::string & url, DavixError** err);
0163 
0164 
0165 
0166     /**
0167       @brief execute an readdirpp function
0168 
0169       Similar to \ref Davix::DavPosix::readdir but provide stat() information for each entry.
0170 
0171       Supported by Webdav.
0172 
0173       @param dir directory handle
0174       @param st struct to fill
0175       @param err Davix Error report
0176       @return dirent struct if success, or NULL if error
0177 
0178       @snippet example_code_snippets.cpp opendirpp
0179     */
0180     struct dirent* readdirpp(DAVIX_DIR* dir, struct stat * st, DavixError** err );
0181 
0182     /**
0183        @brief close a directory handle
0184 
0185        @param  d directory handle to close
0186        @param err Davix error report system
0187        @return 0 if success else a negative value and err is set.
0188 
0189        @snippet example_code_snippets.cpp opendirpp
0190     */
0191     int closedirpp(DAVIX_DIR* d, DavixError** err );
0192 
0193     /**
0194       @brief execute a mkdir function with Webdav.
0195 
0196       Behavior similar to the POSIX mkdir function.
0197 
0198       @warning dependening of the server, implementation, mode_t parameter can be ignored
0199 
0200       @param params request options, can be NULL
0201       @param url url of the directory to create
0202       @param right default mode of the directory ( ignored for now )
0203       @param err Davix error report system
0204       @return 0 if success else a negative value and err is set.
0205 
0206       @snippet example_code_snippets.cpp mkdir
0207     */
0208     int mkdir(const RequestParams* params, const std::string& url, mode_t right, DavixError** err);
0209 
0210     /**
0211       @brief rename a target file or collection.
0212 
0213       Behavior similar to the POSIX rename function.
0214 
0215       @param params request options, can be NULL
0216       @param source_url old url of the resource
0217       @param target_url new url of the resource
0218       @param err Davix error report system
0219       @return 0 if success else a negative value and err is set.
0220 
0221       @snippet example_code_snippets.cpp rename
0222     */
0223     int rename(const RequestParams* params, const std::string& source_url, const std::string& target_url, DavixError** err);
0224 
0225 
0226 
0227     /**
0228       @brief execute a remove file operation.
0229 
0230       Behavior similar to the POSIX unlink function.
0231 
0232       @param params request options, can be NULL
0233       @param url file to delete
0234       @param err Davix error report system
0235       @return 0 if success else a negative value and err is set.
0236 
0237       @snippet example_code_snippets.cpp unlink
0238     */
0239     int unlink(const RequestParams* params, const std::string& url, DavixError** err);
0240 
0241     /**
0242       @brief execute a remove directory operation.
0243 
0244       Behavior similar to the POSIX rmdir function
0245 
0246       @param params request options, can be NULL
0247       @param url directory to delete
0248       @param err Davix error report system
0249       @return 0 if success else a negative value and err is set.
0250 
0251       @snippet example_code_snippets.cpp rmdir
0252     */
0253     int rmdir(const RequestParams* params, const std::string& url, DavixError** err);
0254 
0255 
0256     /**
0257       @brief open a file for read/write operation in a POSIX-like approach.
0258 
0259       Behavior similar to the POSIX open function
0260 
0261       This operation is supported on plain HTTP servers.
0262 
0263       @param params request options, can be NULL
0264       @param url url of the HTTP file to open
0265       @param flags open flags, similar to the POSIX function open
0266       @param err Davix Error report
0267       @return Davix file descriptor in case of success, or NULL if an error occures.
0268 
0269       @snippet example_code_snippets.cpp open
0270      */
0271     DAVIX_FD* open(const RequestParams* params, const std::string & url, int flags, DavixError** err);
0272 
0273 
0274     /**
0275       @brief read a file in a POSIX-like approach with HTTP(S).
0276 
0277       Behavior similar to the POSIX read function
0278 
0279       @param fd davix file descriptor
0280       @param buffer buffer to fill
0281       @param count maximum number of bytes to read
0282       @param err Davix Error report
0283       @return the size of data or a negative value if an error occurred
0284 
0285       @snippet example_code_snippets.cpp read
0286      */
0287     ssize_t read(DAVIX_FD* fd, void* buffer, size_t count, DavixError** err);
0288 
0289 
0290     /**
0291       @brief do a partial read of a file in a POSIX-like approach with HTTP(S).
0292 
0293       Behavior similar to the POSIX pread function.
0294 
0295       @param fd davix file descriptor
0296       @param buffer buffer to fill
0297       @param count maximum number of bytes to read
0298       @param offset  offset to use
0299       @param err Davix Error report
0300       @return the size of data or a negative value if an error occurred
0301 
0302       @snippet example_code_snippets.cpp pread
0303      */
0304     ssize_t pread(DAVIX_FD* fd, void* buffer, size_t count, off_t offset, DavixError** err);
0305 
0306     /**
0307       @brief 64bits version of /ref Davix::DavPosix::pread
0308      */
0309     dav_ssize_t pread64(DAVIX_FD* fd, void* buffer, dav_size_t count, dav_off_t offset, DavixError ** err);
0310 
0311     /**
0312       @brief do a partial write of a file in a POSIX-like approach with HTTP(S).
0313 
0314       Behavior similar to the POSIX pwrite function
0315 
0316       @param fd davix file descriptor
0317       @param buffer buffer to fill
0318       @param count maximum number of bytes to write
0319       @param offset  offset to use
0320       @param err Davix Error report
0321       @return the size of data written or a negative value if an error occurred
0322 
0323       @snippet example_code_snippets.cpp pwrite
0324      */
0325     ssize_t pwrite(DAVIX_FD* fd, const void* buffer, size_t count, off_t offset, DavixError** err);
0326 
0327     /**
0328       @brief 64bits version of /ref Davix::DavPosix::pwrite
0329      */
0330     dav_ssize_t pwrite64(DAVIX_FD* fd, const void* buffer, dav_size_t count, dav_off_t offset, DavixError** err);
0331 
0332     /**
0333       @brief pread_vec a file in a POSIX-like approach with HTTP(S).
0334 
0335             Vector read operation.
0336             Able to do several read operations in one single request.
0337 
0338             NOTE: The return code is the number of data bytes received from the
0339                   server, not the total number of bytes written into the buffers.
0340                   The two might not be equal if range coalescing is performed.
0341                   Check diov_size of the output vector to make sure the buffers
0342                   contain the expected number of bytes.
0343 
0344       @param fd davix file descriptor
0345       @param input_vec input vectors, parameters
0346       @param output_vec output vectors, results
0347       @param count_vec number of vector struct
0348       @param err Davix Error report
0349       @return total number of bytes read, or -1 if error occurs.
0350 
0351       @snippet example_code_snippets.cpp preadVec
0352      */
0353     dav_ssize_t preadVec(DAVIX_FD* fd, const DavIOVecInput * input_vec,
0354                           DavIOVecOuput * output_vec,
0355                           dav_size_t count_vec, DavixError** err);
0356 
0357     /**
0358       @brief write a file in a POSIX-like approach with HTTP(S).
0359 
0360       Behavior similar to the POSIX write function.
0361 
0362       @param fd davix file descriptor
0363       @param buf buffer with the write content
0364       @param count number of bytes to write
0365       @param err Davix Error report
0366       @return the size of the written data or a negative value if an error occurred
0367 
0368       @snippet example_code_snippets.cpp write
0369      */
0370     ssize_t write(DAVIX_FD* fd, const void* buf, size_t count, DavixError** err);
0371 
0372 
0373     /**
0374       @brief move the cursor a davix file with HTTP(S).
0375 
0376       Behavior similar to the POSIX lseek function.
0377 
0378       @param fd davix file descriptor
0379       @param offset offset in byte inside the file
0380       @param flags lseek flags, similar to the lseek function
0381       @param err Davix Error report
0382       @return the offset position or (off_t)-1 if error occurs
0383 
0384       @snippet example_code_snippets.cpp lseek
0385      */
0386     off_t lseek(DAVIX_FD* fd, off_t offset, int flags, DavixError** err);
0387 
0388     /**
0389       @brief 64bits versions of /ref Davix::DavixPosix::lseek
0390      */
0391     dav_off_t lseek64(DAVIX_FD* fd, dav_off_t, int flags, DavixError** err);
0392 
0393     /**
0394       @brief close a existing file descriptor.
0395 
0396       Note : all file descriptors MUST be closed before the destruction of the parent davix context
0397 
0398       @param fd davix file descriptor
0399       @param err Davix Error report
0400       @return 0 if success, negative value if error
0401 
0402       @snippet example_code_snippets.cpp close
0403      */
0404     int close(DAVIX_FD* fd, DavixError** err);
0405 
0406     /**
0407       @brief give advise about next file operation
0408 
0409       similar to posix_fadvise, allow I/O optimizations
0410       non-blocking asynchronous function
0411 
0412       @param fd Davix file descriptor
0413       @param offset offset of the next chunk to read
0414       @param len size of the next chunk to read
0415       @param advise type of pattern for I/O : sequential, random
0416     */
0417     void fadvise(DAVIX_FD* fd, dav_off_t offset, dav_size_t len, advise_t advise);
0418 
0419 private:
0420     DAVIX_DIR* internal_opendirpp(const RequestParams* params,  const char * scope, const std::string & body, const std::string & url, DavixError** err);
0421 
0422     Context* context;
0423     long _timeout;
0424     long _s_buff;
0425 
0426     DavPosixInternal* d_ptr;
0427 
0428 };
0429 
0430 
0431 } // namespace Davix
0432 
0433 #endif // DAVIX_DAVPOSIX_HPP