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 DAVIX_DAVIXSTATUSREQUEST_HPP
0023 #define DAVIX_DAVIXSTATUSREQUEST_HPP
0024 
0025 #include <string>
0026 #include <utils/davix_types.hpp>
0027 #include <iostream>
0028 
0029 /**
0030   @file davixstatusrequest.hpp
0031   @author Devresse Adrien, CERN
0032 
0033   @brief Error report system of davix
0034 */
0035 
0036 #ifndef __DAVIX_INSIDE__
0037 #error "Only davix.h or davix.hpp should be included."
0038 #endif
0039 
0040 
0041 namespace Davix {
0042 
0043 class Context;
0044 class NGQRequest;
0045 struct DavixErrorInternal;
0046 
0047 namespace StatusCode{
0048 
0049 
0050 
0051 /// Common Error code of Davix
0052 /// See \ref DavixError for more details
0053 ///
0054 enum Code {
0055     /// No Error report
0056     OK = 0x000,
0057 
0058     /// Request executed partially
0059     PartialDone = 0x001,
0060 
0061     /// Error in the Webdav properties parsing
0062     WebDavPropertiesParsingError = 0x002,
0063 
0064     /// Error in the Webdav properties parsing
0065     UriParsingError = 0x003,
0066 
0067     /// impossible to create a session
0068     SessionCreationError = 0x004,
0069 
0070     /// DNS resolution failure
0071     NameResolutionFailure= 0x005,
0072 
0073     /// Impossible to connect, host down or network problem
0074     ConnectionProblem = 0x006,
0075 
0076     /// redirection is needed manually
0077     RedirectionNeeded = 0x007,
0078 
0079     /// Impossible to connect, host down or network problem
0080     ConnectionTimeout = 0x008,
0081 
0082     /// operation timeout
0083     OperationTimeout = 0x009,
0084 
0085     /// this operation is not supported
0086     OperationNonSupported= 0x00a,
0087 
0088     /// Action impossible, is a directory or a collection
0089     IsNotADirectory = 0x00b,
0090 
0091     /// Invalid file descriptor
0092     InvalidFileHandle = 0x00c,
0093 
0094     /// Request already running
0095     AlreadyRunning = 0x00d,
0096 
0097     /// Authentication Error
0098     AuthenticationError = 0x00e,
0099 
0100     /// Misspelled - kept for backward compatibility
0101     AuthentificationError = AuthenticationError,
0102 
0103     /// Wrong Login and/or Password
0104     LoginPasswordError = 0x00f,
0105 
0106     /// Impossible to find specified credential
0107     CredentialNotFound = 0x010,
0108 
0109     /// Permission deny, Authorisation problem ( EACCESS, EPERM )
0110     PermissionRefused = 0x011,
0111 
0112     /// File not found (ENOENT )
0113     FileNotFound = 0x012,
0114 
0115     /// This file is not a regular file but a directory ( EISDIR )
0116     IsADirectory = 0x013,
0117 
0118     /// System call related error
0119     SystemError = 0x014,
0120 
0121     /// File already exist ( EEXIST )
0122     FileExist = 0x015,
0123 
0124     /// Invalid argument from user ( EINVAL )
0125     InvalidArgument = 0x016,
0126 
0127     /// Server answer problem ( > 500 )
0128     InvalidServerResponse = 0x017,
0129 
0130     /// SSL/TLS layer Error
0131     SSLError = 0x018,
0132 
0133     /// Impossible to decrypt client credential for usage
0134     CredDecryptionError = 0x019,
0135 
0136     /// Operation canceled
0137     Canceled = 0x020,
0138 
0139     /// Delegation error
0140     DelegationError = 0x021,
0141 
0142     /// Remote error. Used for third party copies: it means the
0143     /// destination failed.
0144     RemoteError = 0x022,
0145 
0146     /// Generic Parsing Error
0147     ParsingError = 0x23,
0148 
0149     /// Invalid Hook type
0150     InvalidHook = 0x24,
0151 
0152     /// Connection timeout during a redirection
0153     TimeoutRedirectionError = 0x25,
0154 
0155     /// Too many redirects
0156     TooManyRedirects = 0x26,
0157 
0158     /// Insufficient storage
0159     InsufficientStorage = 0x27,
0160 
0161     /// Environment Variable Missing
0162     EnvVarNotSet = 0x28,
0163 
0164     /// Undefined error
0165     UnknownError = 0x100,
0166 
0167     /// Misspelled - kept for backward compatibility
0168     UnknowError = UnknownError
0169 
0170 };
0171 
0172 }
0173 
0174 ///  @class DavixError
0175 ///  @brief Davix Error Handler
0176 ///
0177 /// Error report system of Davix, similar behavior to the Glib Error report
0178 /// Davix does not use C++ exception
0179 ///
0180 ///
0181 /// Each function which takes a DavixError** as argument can take the value NULL
0182 ///
0183 /// Example :
0184 ///
0185 ///
0186 class DAVIX_EXPORT DavixError{
0187 public:
0188 
0189     ///
0190     /// Construct a DavixError object
0191     ///
0192     /// @param scope : string parameter representing the scope of the error
0193     /// @param errCode : Davix Error code, see  Davix::StatusCode::Code
0194     /// @param errMsg : String representation of the error
0195     DavixError(const std::string & scope, StatusCode::Code errCode, const std::string & errMsg);
0196     ///
0197     /// \brief copy constructor
0198     /// \param e
0199     ///
0200     DavixError(const DavixError & e);
0201     ///
0202     /// \brief assignment operator
0203     /// \param e
0204     /// \return
0205     ///
0206     DavixError & operator=(const DavixError & e);
0207     ///
0208     /// \brief ~DavixError
0209     ///
0210     virtual ~DavixError();
0211 
0212 
0213     ///
0214     /// \brief clone Error
0215     /// \return new dynamically allocated copy of the Error
0216     ///
0217     DavixError* clone();
0218 
0219     ///
0220     /// @return Davix status code of the error
0221     StatusCode::Code getStatus() const;
0222 
0223     ///
0224     /// set the status code for this error
0225     void setStatus(const StatusCode::Code);
0226 
0227     ///
0228     /// get the string representation of this error
0229     const std::string & getErrMsg() const;
0230 
0231     ///
0232     /// set the string representation of this error
0233     void setErrMsg(const std::string & msg);
0234 
0235     ///
0236     /// set the scope of this error
0237     void setErrScope(const std::string & scope);
0238 
0239     ///
0240     /// get the scope of this error
0241     const std::string & getErrScope() const;
0242 
0243 
0244 
0245     ///
0246     /// \brief create a new DavixError
0247     /// \param err pointer to a DavixError pointer
0248     /// \param scope scope of the Error
0249     /// \param errCode Error code
0250     /// \param errMsg Error message
0251     ///
0252     ///
0253     /// create a new dynamically allocated DavixError Object
0254     /// if err is NULL, silent suppress the error report
0255     static void setupError(DavixError** err, const std::string & scope, StatusCode::Code errCode, const std::string & errMsg);
0256 
0257     ///
0258     /// clear the content of the current error and set err to NULL
0259     static void clearError(DavixError** err);
0260 
0261 
0262 
0263     ///
0264     /// \brief propagate an Error structure to an upper level
0265     /// \param newErr
0266     /// \param oldErr
0267     ///
0268     ///  propagate the Davix Error Object from oldErr to newErr
0269     ///  OldErr can be consider as free after this operation
0270     ///  erase the current error if newErr is not NULL
0271     ///
0272     static void propagateError(DavixError** newErr, DavixError* oldErr);
0273 
0274 
0275     ////
0276     /// \brief swap the two error content
0277     /// \param err
0278     ///
0279     void swap(DavixError & err);
0280 
0281 
0282     ///
0283     /// \brief propagatePrefixedError
0284     /// \param newErr
0285     /// \param oldErr
0286     /// \param prefix
0287     ///
0288     /// same than propagateError but add a string prefix in front of the error description
0289     ///
0290     //////
0291     static void propagatePrefixedError(DavixError** newErr, DavixError* oldErr, const std::string & prefix);
0292 
0293 private:
0294    DavixErrorInternal * d_ptr;
0295 };
0296 
0297 
0298 
0299 ///  @class DavixException
0300 ///  @brief Davix Exception class
0301 ///
0302 /// Contain a Davix Error
0303 ///
0304 ///
0305 class DAVIX_EXPORT DavixException : public std::exception{
0306     struct DavixExceptionIntern;
0307 public:
0308     /// Construct a DavixException
0309     DavixException(const std::string & scope, StatusCode::Code c, const std::string & msg) throw();
0310 
0311     /// Create a DavixEception from a DavixError, err is considered as free and invalid after creation
0312     DavixException(DavixError** err);
0313 
0314     /// Copy Constructor
0315     DavixException(const DavixException & orig) throw();
0316 
0317     virtual ~DavixException() throw();
0318 
0319     /// return a string representation of the scope for this davix exception
0320     virtual const char* scope() const throw();
0321 
0322     /// return the error code association to this DavixException, same than @ref DavixError::getStatus()
0323     virtual StatusCode::Code code() const throw();
0324 
0325     /// return a string representation or the error
0326     virtual const char*  what() const throw();
0327 
0328     /// Extract a DavixError from this exception
0329     void toDavixError(DavixError** err);
0330 
0331 protected:
0332     DavixError e;
0333     DavixExceptionIntern* d_ptr;
0334 };
0335 
0336 
0337 void checkDavixError(DavixError** err);
0338 
0339 
0340 #define TRY_DAVIX try
0341 #define CATCH_DAVIX(err) catch(DavixException & e){ \
0342         e.toDavixError(err); \
0343     }catch(std::exception & e){ \
0344         DavixError::setupError(err, " ", StatusCode::SystemError, std::string("System Error ").append(e.what())); \
0345     }catch(...){ \
0346         DavixError::setupError(err, " ", StatusCode::UnknownError, std::string("Unknown Error .... report this")); \
0347     }
0348 
0349 
0350 /// \cond PRIVATE_SYMBOLS
0351 ///
0352 DAVIX_EXPORT std::string davix_scope_stat_str();
0353 DAVIX_EXPORT std::string davix_scope_davOps_str();
0354 DAVIX_EXPORT std::string davix_scope_mkdir_str();
0355 DAVIX_EXPORT std::string davix_scope_rm_str();
0356 DAVIX_EXPORT std::string davix_scope_mv_str();
0357 DAVIX_EXPORT std::string davix_scope_directory_listing_str();
0358 DAVIX_EXPORT std::string davix_scope_http_request();
0359 DAVIX_EXPORT std::string davix_scope_meta();
0360 DAVIX_EXPORT std::string davix_scope_xml_parser();
0361 DAVIX_EXPORT std::string davix_scope_uri_parser();
0362 DAVIX_EXPORT std::string davix_scope_io_buff();
0363 DAVIX_EXPORT std::string davix_scope_x509cred();
0364 
0365 
0366 
0367 //
0368 DAVIX_EXPORT void davix_errno_to_davix_error(int errcode, const std::string & scope, const std::string & msg, DavixError** newErr);
0369 
0370 DAVIX_EXPORT void errno_to_davix_exception(int errno_code, const std::string & scope, const std::string & msg);
0371 
0372 
0373 
0374 
0375 
0376 
0377 
0378 
0379 
0380 
0381 
0382 
0383 
0384 
0385 
0386 
0387 
0388 
0389 
0390 
0391 
0392 // !!!!!!!!!!!!!!!!!!!
0393 // Warning: Deprecated symbols, do not use anymore
0394 // /////////////////////////////////////////////////
0395 // Deprecated, do not use, API compability only
0396 
0397 typedef enum StatusCode::Code davix_status_t;
0398 
0399 
0400 /// \endcond PRIVATE_SYMBOLS
0401 
0402 } // namespace Davix
0403 
0404 
0405 #endif // DAVIX_DAVIXSTATUSREQUEST_H