Blame include/exiv2/futils.hpp

Packit Service 21b5d1
// ********************************************************* -*- C++ -*-
Packit Service 21b5d1
/*
Packit Service 21b5d1
 * Copyright (C) 2004-2018 Exiv2 authors
Packit Service 21b5d1
 * This program is part of the Exiv2 distribution.
Packit Service 21b5d1
 *
Packit Service 21b5d1
 * This program is free software; you can redistribute it and/or
Packit Service 21b5d1
 * modify it under the terms of the GNU General Public License
Packit Service 21b5d1
 * as published by the Free Software Foundation; either version 2
Packit Service 21b5d1
 * of the License, or (at your option) any later version.
Packit Service 21b5d1
 *
Packit Service 21b5d1
 * This program is distributed in the hope that it will be useful,
Packit Service 21b5d1
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 21b5d1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 21b5d1
 * GNU General Public License for more details.
Packit Service 21b5d1
 *
Packit Service 21b5d1
 * You should have received a copy of the GNU General Public License
Packit Service 21b5d1
 * along with this program; if not, write to the Free Software
Packit Service 21b5d1
 * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
Packit Service 21b5d1
 */
Packit Service 21b5d1
/*!
Packit Service 21b5d1
  @file    futils.hpp
Packit Service 21b5d1
  @brief   Basic file utility functions required by Exiv2
Packit Service 21b5d1
  @author  Andreas Huggel (ahu)
Packit Service 21b5d1
           ahuggel@gmx.net
Packit Service 21b5d1
  @date    12-Dec-03, ahu: created
Packit Service 21b5d1
           02-Apr-05, ahu: moved to Exiv2 namespace
Packit Service 21b5d1
 */
Packit Service 21b5d1
#ifndef FUTILS_HPP_
Packit Service 21b5d1
#define FUTILS_HPP_
Packit Service 21b5d1
Packit Service 21b5d1
#include "exiv2lib_export.h"
Packit Service 21b5d1
#include "config.h"
Packit Service 21b5d1
Packit Service 21b5d1
#include <string>
Packit Service 21b5d1
Packit Service 21b5d1
// namespace extensions
Packit Service 21b5d1
namespace Exiv2
Packit Service 21b5d1
{
Packit Service 21b5d1
    //! the name of environmental variables.
Packit Service 21b5d1
    enum EnVar
Packit Service 21b5d1
    {
Packit Service 21b5d1
        envHTTPPOST = 0,
Packit Service 21b5d1
        envTIMEOUT = 1
Packit Service 21b5d1
    };
Packit Service 21b5d1
    //! the collection of protocols.
Packit Service 21b5d1
    enum Protocol
Packit Service 21b5d1
    {
Packit Service 21b5d1
        pFile = 0,
Packit Service 21b5d1
        pHttp,
Packit Service 21b5d1
        pFtp,
Packit Service 21b5d1
        pHttps,
Packit Service 21b5d1
        pSftp,
Packit Service 21b5d1
        pSsh,
Packit Service 21b5d1
        pFileUri,
Packit Service 21b5d1
        pDataUri,
Packit Service 21b5d1
        pStdin
Packit Service 21b5d1
    };
Packit Service 21b5d1
    // *********************************************************************
Packit Service 21b5d1
    // free functions
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief  Return the value of environmental variable.
Packit Service 21b5d1
      @param[in]  var The name of environmental variable. Must be a member of the enumeration @ref EnVar.
Packit Service 21b5d1
      @return the value of environmental variable. If it's empty, the default value is returned.
Packit Service 21b5d1
      @throws std::out_of_range when an unexpected EnVar is given as input.
Packit Service 21b5d1
     */
Packit Service 21b5d1
    EXIV2API std::string getEnv(int env_var);
Packit Service 21b5d1
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief Encode the input url.
Packit Service 21b5d1
      @param str The url needs encoding.
Packit Service 21b5d1
      @return the url-encoded version of str.
Packit Service 21b5d1
      @note Source: http://www.geekhideout.com/urlcode.shtml
Packit Service 21b5d1
      @todo This function can probably be hidden into the implementation details
Packit Service 21b5d1
     */
Packit Service 21b5d1
    EXIV2API std::string urlencode(const char* str);
Packit Service 21b5d1
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief Decode the input url.
Packit Service 21b5d1
      @param str The url needs decoding.
Packit Service 21b5d1
      @return the url-decoded version of str.
Packit Service 21b5d1
Packit Service 21b5d1
      @note Be sure to 'free' the returned string after use with 'delete []'.
Packit Service 21b5d1
            Source: http://www.geekhideout.com/urlcode.shtml
Packit Service 21b5d1
      @todo This function can probably be hidden into the implementation details
Packit Service 21b5d1
     */
Packit Service 21b5d1
    EXIV2API char* urldecode(const char* str);
Packit Service 21b5d1
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief Like urlencode(char* str) but accept the input url in the std::string and modify it.
Packit Service 21b5d1
      @todo This function can probably be hidden into the implementation details
Packit Service 21b5d1
     */
Packit Service 21b5d1
    EXIV2API void urldecode(std::string& str);
Packit Service 21b5d1
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief Encode in base64 the data in data_buf and put the resulting string in result.
Packit Service 21b5d1
      @param data_buf The data need to encode
Packit Service 21b5d1
      @param dataLength Size in bytes of the in buffer
Packit Service 21b5d1
      @param result The container for the result, NULL if it fails
Packit Service 21b5d1
      @param resultSize Size in bytes of the out string, it should be at least
Packit Service 21b5d1
             ((dataLength + 2) / 3) * 4 + 1
Packit Service 21b5d1
      @return 1 indicate success
Packit Service 21b5d1
Packit Service 21b5d1
      @note Source: http://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64
Packit Service 21b5d1
      */
Packit Service 21b5d1
    EXIV2API int base64encode(const void* data_buf, size_t dataLength, char* result, size_t resultSize);
Packit Service 21b5d1
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief Decode base64 data and put the resulting string in out.
Packit Service 21b5d1
      @param in The data need to decode.
Packit Service 21b5d1
      @param out The container for the result, it should be large enough to contain the result.
Packit Service 21b5d1
      @param out_size The size of out in bytes.
Packit Service 21b5d1
      @return the size of the resulting string. If it fails, return -1.
Packit Service 21b5d1
Packit Service 21b5d1
      @note Source: https://github.com/davidgaleano/libwebsockets/blob/master/lib/base64-decode.c
Packit Service 21b5d1
      */
Packit Service 21b5d1
    EXIV2API long base64decode(const char* in, char* out, size_t out_size);
Packit Service 21b5d1
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief Return the protocol of the path.
Packit Service 21b5d1
      @param path The path of file to extract the protocol.
Packit Service 21b5d1
      @return the protocol of the path.
Packit Service 21b5d1
     */
Packit Service 21b5d1
    EXIV2API Protocol fileProtocol(const std::string& path);
Packit Service 21b5d1
Packit Service 21b5d1
#ifdef EXV_UNICODE_PATH
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief Like fileProtocol() but accept a unicode path in an std::wstring.
Packit Service 21b5d1
      @note This function is only available on Windows.
Packit Service 21b5d1
     */
Packit Service 21b5d1
    EXIV2API Protocol fileProtocol(const std::wstring& wpath);
Packit Service 21b5d1
#endif
Packit Service 21b5d1
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief Test if a file exists.
Packit Service 21b5d1
Packit Service 21b5d1
      @param  path Name of file to verify.
Packit Service 21b5d1
      @param  ct   Flag to check if path is a regular file.
Packit Service 21b5d1
      @return true if path exists and, if ct is set,
Packit Service 21b5d1
      is a regular file, else false.
Packit Service 21b5d1
Packit Service 21b5d1
      @note The function calls stat() test for path
Packit Service 21b5d1
      and its type, see stat(2). errno is left unchanged
Packit Service 21b5d1
      in case of an error.
Packit Service 21b5d1
     */
Packit Service 21b5d1
    EXIV2API bool fileExists(const std::string& path, bool ct = false);
Packit Service 21b5d1
Packit Service 21b5d1
#ifdef EXV_UNICODE_PATH
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief Like fileExists(const std::string& path, bool ct =false) but
Packit Service 21b5d1
            accepts a unicode path in an std::wstring.
Packit Service 21b5d1
      @note This function is only available on Windows.
Packit Service 21b5d1
     */
Packit Service 21b5d1
    EXIV2API bool fileExists(const std::wstring& wpath, bool ct = false);
Packit Service 21b5d1
#endif
Packit Service 21b5d1
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief Get the path of file URL.
Packit Service 21b5d1
Packit Service 21b5d1
      @param  url The file URL in the format file:///path or file://host/path
Packit Service 21b5d1
      @return the path of file URL.
Packit Service 21b5d1
     */
Packit Service 21b5d1
    EXIV2API std::string pathOfFileUrl(const std::string& url);
Packit Service 21b5d1
Packit Service 21b5d1
#ifdef EXV_UNICODE_PATH
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief Like pathOfFileUrl(const std::string& url) but accepts a unicode path in an std::wstring.
Packit Service 21b5d1
      @note This function is only available on Windows.
Packit Service 21b5d1
     */
Packit Service 21b5d1
    EXIV2API std::wstring pathOfFileUrl(const std::wstring& wurl);
Packit Service 21b5d1
#endif
Packit Service 21b5d1
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief Return a system error message and the error code (errno).
Packit Service 21b5d1
             See %strerror(3).
Packit Service 21b5d1
     */
Packit Service 21b5d1
    EXIV2API std::string strError();
Packit Service 21b5d1
Packit Service 21b5d1
    //! @brief Return the path of the current process.
Packit Service 21b5d1
    EXIV2API std::string getProcessPath();
Packit Service 21b5d1
Packit Service 21b5d1
    /*!
Packit Service 21b5d1
      @brief A container for URL components. It also provides the method to parse a
Packit Service 21b5d1
            URL to get the protocol, host, path, port, querystring, username, password.
Packit Service 21b5d1
Packit Service 21b5d1
      Source: http://stackoverflow.com/questions/2616011/easy-way-to-parse-a-url-in-c-cross-platform
Packit Service 21b5d1
Packit Service 21b5d1
      @todo This class can probably be hidden from the API
Packit Service 21b5d1
     */
Packit Service 21b5d1
    class Uri
Packit Service 21b5d1
    {
Packit Service 21b5d1
    public:
Packit Service 21b5d1
        // DATA
Packit Service 21b5d1
        std::string QueryString;  //!< URL query string
Packit Service 21b5d1
        std::string Path;         //!< URL file path
Packit Service 21b5d1
        std::string Protocol;     //!< URL protocol
Packit Service 21b5d1
        std::string Host;         //!< URL host
Packit Service 21b5d1
        std::string Port;         //!< URL port
Packit Service 21b5d1
        std::string Username;     //!< URL username
Packit Service 21b5d1
        std::string Password;     //!< URL password
Packit Service 21b5d1
Packit Service 21b5d1
        /// @brief Parse the input URL to the protocol, host, path, username, password
Packit Service 21b5d1
        static Uri EXIV2API Parse(const std::string& uri);
Packit Service 21b5d1
Packit Service 21b5d1
        /// @brief Decode the url components.
Packit Service 21b5d1
        static void EXIV2API Decode(Uri& uri);
Packit Service 21b5d1
    };
Packit Service 21b5d1
Packit Service 21b5d1
}  // namespace Exiv2
Packit Service 21b5d1
Packit Service 21b5d1
#endif // #ifndef FUTILS_HPP_