Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:04: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 DAVIX_REQUESTPARAMS_HPP
0023 #define DAVIX_REQUESTPARAMS_HPP
0024 
0025 #include <vector>
0026 #include <string>
0027 #include <map>
0028 
0029 #include "davix_request_params_types.hpp"
0030 #include "../auth/davixauth.hpp"
0031 
0032 
0033 /**
0034   @file davixrequestparams.hpp
0035   @author Devresse Adrien
0036 
0037   @brief C++ Davix configuration API
0038 */
0039 
0040 #ifndef __DAVIX_INSIDE__
0041 #error "Only davix.h or davix.hpp should be included."
0042 #endif
0043 
0044 
0045 namespace Davix {
0046 
0047 namespace gcloud {
0048     class Credentials;
0049 }
0050 
0051 struct RequestParamsInternal;
0052 
0053 
0054 
0055 ///
0056 /// @class RequestParams
0057 /// @brief Main container for Davix request options
0058 ///
0059 /// RequestParams hold the davix request options :
0060 /// authentication parameters, timeouts, user-agents,...
0061 /// A Requestparams object can be shared between several Request
0062 class DAVIX_EXPORT RequestParams
0063 {
0064 public:
0065     ///
0066     /// \brief default constructor
0067     ///
0068     RequestParams();
0069     ///
0070     /// \brief copy constructor
0071     /// \param params
0072     ///
0073     RequestParams(const RequestParams & params);
0074     ///
0075     /// \brief conveniencecopy constructor with NULL check
0076     /// \param params
0077     RequestParams(const RequestParams* params);
0078     /// \brief assignment operator
0079     RequestParams & operator=(const RequestParams & _p);
0080 
0081     virtual ~RequestParams();
0082 
0083 
0084     ///  disable the certificate authority validity check for the https request
0085     void setSSLCAcheck(bool chk);
0086 
0087     /// return the SSL Certificate authority validity check
0088     bool getSSLCACheck() const;
0089 
0090     /// set a X509 credential for a simple client authentication
0091     /// this function overwrite \ref setClientCertCallbackX509
0092     void setClientCertX509(const X509Credential & cli_cert);
0093 
0094     /// get the current client side credential
0095     const X509Credential &  getClientCertX509() const;
0096 
0097     /// set login/password for HTTP Authentication
0098     void setClientLoginPassword(const std::string & login, const std::string & password);
0099 
0100     /// get login/password for HTTP Authentication
0101     const std::pair<std::string,std::string> & getClientLoginPassword() const;
0102 
0103 
0104 #ifdef __DAVIX_HAS_STD_FUNCTION
0105     /// set a function for or X509 client side dynamic authentication
0106     /// this function overwrite \ref setClientCertCallbackX509
0107     void setClientCertFunctionX509(const authFunctionClientCertX509 & callback);
0108 
0109     /// return the function
0110     const authFunctionClientCertX509 & getClientCertFunctionX509() const;
0111 #endif
0112 
0113     /// set a callback for X509 client side dynamic authentication
0114     /// this function overwrite \ref setClientCertX509
0115     void setClientCertCallbackX509(authCallbackClientCertX509 callback, void* userdata);
0116 
0117     /// return the current client side callback for authentication with the associated user data
0118     std::pair<authCallbackClientCertX509,void*> getClientCertCallbackX509() const;
0119 
0120     /// set a callback for basic login/password http authentication
0121     /// this function overwrite \ref setClientLoginPassword
0122     void setClientLoginPasswordCallback(authCallbackLoginPasswordBasic callback, void* userdata);
0123 
0124     /// return the current login/password callback and the associated user data
0125     std::pair<authCallbackLoginPasswordBasic,void*> getClientLoginPasswordCallback() const;
0126 
0127     ///
0128     /// \brief define a Amazon S3 private key and public key
0129     /// \param secret_key secret key
0130     /// \param access_key public key
0131     ///
0132     void setAwsAuthorizationKeys(const AwsSecretKey & secret_key, const AwsAccessKey & access_key);
0133 
0134     ///
0135     /// \brief get Amazon S3 authentication tokens
0136     /// \return pair of secret key and public key
0137     ///
0138     const std::pair<AwsSecretKey, AwsAccessKey> & getAwsAutorizationKeys() const;
0139 
0140     ///
0141     /// \brief define a Amazon S3 bucket region
0142     /// \param region the region
0143     ///
0144     void setAwsRegion(const AwsRegion & region);
0145 
0146     ///
0147     /// \brief get Amazon S3 bucket region
0148     /// \return the bucket region
0149     ///
0150     const AwsRegion & getAwsRegion() const;
0151 
0152     ///
0153     /// \brief define an Amazon S3 security token
0154     /// \param token the security token
0155     ///
0156     void setAwsToken(const AwsToken & token);
0157 
0158     ///
0159     /// \brief get Amazon S3 security token
0160     /// \return the security token
0161     ///
0162     const AwsToken & getAwsToken() const;
0163 
0164     ///
0165     /// \brief set whether we're using an S3 path-based url
0166     /// \param alternate whether using an S3 path-based url
0167     ///
0168     void setAwsAlternate(const bool & alternate);
0169 
0170     ///
0171     /// \brief get whether we're using an S3 path-based url
0172     /// \return whether we're using an S3 path-based url
0173     ///
0174     const bool & getAwsAlternate() const;
0175 
0176     ///
0177     /// \brief set the secret key for Azure authentication
0178     /// \param key the secret key
0179     ///
0180     void setAzureKey(const AzureSecretKey & key);
0181 
0182     ///
0183     /// \brief get the secret key used for Azure authentication
0184     /// \return the secret key
0185     ///
0186     const AzureSecretKey & getAzureKey() const;
0187 
0188     ///
0189     /// \brief set the secret key for Azure authentication
0190     /// \param creds the secret key
0191     ///
0192     void setGcloudCredentials(const Davix::gcloud::Credentials & creds);
0193 
0194     ///
0195     /// \brief get the secret key used for Azure authentication
0196     /// \return the secret key
0197     ///
0198     const Davix::gcloud::Credentials & getGcloudCredentials() const;
0199 
0200     ///
0201     /// \brief set the OS token used for Swift authentication
0202     /// \param token the OS token
0203     ///
0204     void setOSToken(const OSToken & token);
0205 
0206     ///
0207     /// \brief get the OS token used for Swift authentication
0208     /// \return the OS token
0209     ///
0210     const OSToken & getOSToken() const;
0211 
0212     ///
0213     /// \brief set the OS project id used for Swift authentication
0214     /// \param id the project id
0215     ///
0216     void setOSProjectID(const OSProjectID & id);
0217 
0218     ///
0219     /// \brief get the OS project id used for Swift authentication
0220     /// \return the project id
0221     ///
0222     const OSProjectID & getOSProjectID() const;
0223 
0224     ///
0225     /// \brief set the Swift account used for Swift authentication
0226     /// \param account the Swift account
0227     ///
0228     void setSwiftAccount(const SwiftAccount & account);
0229 
0230     ///
0231     /// \brief get the Swift account used for Swift authentication
0232     /// \return the Swift account
0233     ///
0234     const SwiftAccount & getSwiftAccount() const;
0235 
0236     /// set listing mode flag for S3 bucket
0237     void setS3ListingMode(const S3ListingMode::S3ListingMode s3_listing_mode);
0238 
0239     /// get listing mode flag for S3 bucket
0240     S3ListingMode::S3ListingMode getS3ListingMode() const;
0241 
0242     /// set listing mode flag for Swift
0243     void setSwiftListingMode(const SwiftListingMode::SwiftListingMode swift_listing_mode);
0244 
0245     /// get listing mode flag for Swift
0246     SwiftListingMode::SwiftListingMode getSwiftListingMode() const;
0247 
0248     /// set maximum number of key entries return by S3 list object request
0249     void setS3MaxKey(const unsigned long s3_max_key_entries);
0250 
0251     /// get maximun number of key entries return by S3 list object request
0252     unsigned long getS3MaxKey() const;
0253 
0254     /// add the CA certificate in the directory 'path' as trusted certificate
0255     void addCertificateAuthorityPath(const std::string & path);
0256 
0257     /// get the list of the current user defined CA path
0258     const std::vector<std::string> & listCertificateAuthorityPath() const;
0259 
0260     /// define the connexion timeout
0261     /// conn_timeout is a relative time
0262     /// DEFAULT : 30s
0263     void setConnectionTimeout(struct timespec* conn_timeout);
0264 
0265     /// get the current connexion timeout
0266     const struct timespec * getConnectionTimeout()  const;
0267 
0268 
0269     /// define the maximum execution time for a davix request
0270     /// ops_timeout is a relative time
0271     /// DEFAULT : infinite
0272     void setOperationTimeout(struct timespec* ops_timeout);
0273 
0274     /// get the maximum execution time for a davix request
0275     /// DEFAULT : infinite
0276     const struct timespec * getOperationTimeout()const;
0277 
0278 
0279     /// enable or disable transparent redirection support
0280     /// In the transparent redirection mode,
0281     /// davix follows the HTTP redirection automatically
0282     /// DEFAULT : enabled
0283     void setTransparentRedirectionSupport(bool redirection);
0284 
0285     /// return true if the transparent redirection mode is enabled
0286     bool getTransparentRedirectionSupport() const;
0287 
0288     ///
0289     /// \brief number of re-try in case of operation failure
0290     /// \param number_retry
0291     ///
0292     /// define the number of retry attempt  in case of an operation failure
0293     void setOperationRetry(int number_retry);
0294 
0295 
0296     ///
0297     /// \brief getOperationRetry
0298     /// \return
0299     /// get current number of retry attempt, see \ref setOperationRetry for more details
0300     int getOperationRetry() const;
0301 
0302 
0303     ///
0304     /// \brief Delay in second between retry attempts
0305     ///// \param delay_retry
0306     ///
0307     /// define the number of seconds between retry attempts in case of slow servers
0308     void setOperationRetryDelay(int delay_retry);
0309 
0310 
0311     ///
0312     /// \brief getOperationRetryDelay
0313     /// \return
0314     /// get current number of seconds between retry attempts, see \ref setOperationRetryDelay for more details
0315     int getOperationRetryDelay() const;
0316 
0317 
0318     /// set copy mode for 3rd party copy
0319     void setCopyMode(const CopyMode::CopyMode copy_mode);
0320 
0321     /// get copy mode for 3rd party copy
0322     CopyMode::CopyMode getCopyMode() const;
0323 
0324     /// set recursive mode for directory operations
0325     void setRecursiveMode(const bool recursive_mode);
0326 
0327     /// get recursive mode for directory operations
0328     bool getRecursiveMode() const;
0329 
0330     /// set whether the server supports 100-continue. If enabled (default), 100-continue
0331     /// may or may not be sent to the server, depending on when davix decides it's
0332     /// appropriate. If disabled, 100-continue will never be used.
0333     void set100ContinueSupport(const bool enabled);
0334 
0335     /// get whether 100-continue support is enabled
0336     bool get100ContinueSupport() const;
0337 
0338 #ifdef __DAVIX_HAS_STD_FUNCTION
0339     ///
0340     /// @brief setTransfertMonitorCb
0341     /// @param cb
0342     ///
0343     ///  define a transfer callback
0344     ///  The transfer callback is called on a regular based
0345     ///  when a data transfer operation is progressing ( put, get, copy )
0346     ///
0347     ///  The callback is called at least once per transfer for the following operations :
0348     ///  - DavFile::put
0349     ///  - DavixFile::get / getV
0350     ///  - Posix::read / pread / write / prwrite / preadVec
0351     ///
0352     ///
0353     void setTransfertMonitorCb(const TransferMonitorCB & cb);
0354 
0355     ///
0356     /// \brief getTransferMonitorCb
0357     /// \return current transfer monitor callback
0358     ///
0359     ///  see \ref setTransfertMonitorCb for more details
0360     ///
0361     const TransferMonitorCB & getTransferMonitorCb() const;
0362 
0363 #endif //__DAVIX_HAS_STD_FUNCTION
0364 
0365     /// set the user agent for the associated request
0366     void setUserAgent(const std::string & user_agent);
0367 
0368     /// get the current user agent string
0369     const std::string & getUserAgent() const;
0370 
0371     /// set the request protocol ( ex : Webdav, Http-only, S3 )
0372     void setProtocol(const RequestProtocol::Protocol proto);
0373 
0374     /// get the current value of the request protocol
0375     RequestProtocol::Protocol getProtocol() const;
0376 
0377     /// Enable or disable the usage of the Metalink
0378     ///  (RFC-5854 and RFC-6249) with libdavix
0379     /// Metalink can be used for fail-over purpose, or multi-source download
0380     void setMetalinkMode( const MetalinkMode::MetalinkMode mode);
0381 
0382     /// get the Current Metalink mode
0383     MetalinkMode::MetalinkMode getMetalinkMode() const;
0384 
0385     /// set the keep alive value of the associated session
0386     void setKeepAlive(const bool keep_alive_flag);
0387 
0388     /// get the keep alive value of this request params
0389     bool getKeepAlive() const;
0390 
0391 
0392     /// Add a custom header line that has to be included in the requests
0393     ///  @param key key of the header
0394     ///  @param val value of the header
0395     void addHeader(const std::string &key, const std::string &val);
0396 
0397     /// return the list of custom headers configured
0398     const HeaderVec & getHeaders() const;
0399 
0400     /// set a SOCKS5 proxy server for intermediate usage
0401     /// example: setProxyServer("socks5://login:password@socks5.exmaple.org:8080")
0402     /// @param proxy_url url of the proxy server
0403     void setProxyServer(const Uri & proxy_url);
0404 
0405     /// get current SOCKS5 proxy server
0406     /// @return URL of the server or NULL if not defined
0407     const Uri* getProxyServer() const;
0408 
0409     /// internal usage
0410     void* getParmState() const;
0411 
0412 
0413     /// swap two RequestParams content
0414     /// fast operation
0415     void swap(RequestParams & params);
0416 
0417     /// get the number of retries that davix should perform in case
0418     /// it receives 202-Accepted on a GET request
0419     int getAcceptedRetry() const;
0420 
0421     /// set the number of retries that davix should perform in case
0422     /// it receives 202-Accepted on a GET request
0423     /// @param num_retries the number of retries
0424     void setAcceptedRetry(int num_retries);
0425 
0426     /// get the delay in seconds between retries that davix should
0427     /// perform in case it receives 202-Accepted on a GET request
0428     int getAcceptedRetryDelay() const;
0429 
0430     /// set the delay in seconds between retries that davix should
0431     /// perform in case it receives 202-Accepted on a GET request
0432     /// @param delay the delay in seconds
0433     void setAcceptedRetryDelay(int delay);
0434 private:
0435 
0436    // dptr
0437     RequestParamsInternal* d_ptr;
0438 
0439 
0440 };
0441 
0442 
0443 
0444 } // namespace Davix
0445 
0446 #endif // DAVIX_REQUESTPARAMS_HPP