From d3669432975daffdbe636acde2cc15c192c69b93 Mon Sep 17 00:00:00 2001 From: clanmills Date: Wed, 13 Sep 2017 16:54:10 +0100 Subject: [PATCH] Refactoring EXV_USE_CURL and EXV_USE_SSH --- config/config.h.cmake | 100 ++++++++++++++++++++------------------ include/exiv2/basicio.hpp | 12 ++--- include/exiv2/exiv2.hpp | 6 ++- include/exiv2/http.hpp | 6 +-- include/exiv2/ssh.hpp | 2 +- samples/conntest.cpp | 8 +-- src/basicio.cpp | 19 +++++--- src/image.cpp | 7 ++- src/ssh.cpp | 3 +- src/version.cpp | 55 ++++++++------------- 10 files changed, 106 insertions(+), 112 deletions(-) diff --git a/config/config.h.cmake b/config/config.h.cmake index e3b5896c..7e4ed424 100644 --- a/config/config.h.cmake +++ b/config/config.h.cmake @@ -2,46 +2,33 @@ #pragma once -// Defined to 1 if when using `libssh' for SshIO. -#cmakedefine01 EXV_USE_SSH +// Defined if you want to use libssh for SshIO. +#cmakedefine EXV_USE_SSH -// Define to 1 if you want to use `libcurl' in httpIO. -#cmakedefine01 EXV_USE_CURL +// Define to 1 if you want to use libcurl in httpIO. +#cmakedefine EXV_USE_CURL // Define if you require webready support. #cmakedefine EXV_ENABLE_WEBREADY -// Define to 1 if you have the `gmtime_r' function. +// Define if you have the `gmtime_r' function. #cmakedefine EXV_HAVE_GMTIME_R -// Define to 1 if you have the header file. +// Define if you have the header file. #cmakedefine EXV_HAVE_LIBINTL_H -// Define to 1 if translation of program messages to the user's native language is requested. +// Define if you want translation of program messages to the user's native language #cmakedefine EXV_ENABLE_NLS -// Define to 1 if you require video support. +// Define if you want video support. #cmakedefine EXV_ENABLE_VIDEO +// Define if you have correct declaration of strerror_r(). #cmakedefine EXV_HAVE_DECL_STRERROR_R -#ifndef EXV_COMMERCIAL_VERSION - -// Definition to enable translation of Nikon lens names. -#cmakedefine EXV_HAVE_LENSDATA - -// Define to 1 if you have the `iconv' function. -#cmakedefine EXV_HAVE_ICONV - -// Definition to enable conversion of UCS2 encoded Windows tags to UTF-8. -#cmakedefine EXV_HAVE_PRINTUCS2 - -#endif /* !EXV_COMMERCIAL_VERSION */ - -// Definition to enable the Windows unicode path support. +// Define to enable the Windows unicode path support. #cmakedefine EXV_UNICODE_PATH - /* Define to `const' or to empty, depending on the second argument of `iconv'. */ #cmakedefine ICONV_ACCEPTS_CONST_INPUT #if defined ICONV_ACCEPTS_CONST_INPUT @@ -50,22 +37,22 @@ #define EXV_ICONV_CONST #endif -// Definition to indicate if you have the header file. +// Define if you have the header file. #cmakedefine EXV_HAVE_REGEX -// Definition to indicate if you have the header file. +// Define if you have the header file. #cmakedefine EXV_HAVE_REGEX_H -// Definition to indicate you have the header file. +// Define if have the header file. #cmakedefine EXV_HAVE_MEMORY_H -// Definition to indicate if you have the `memset' function. +// Define if you have the memset function. #cmakedefine EXV_HAVE_MEMSET -// Definition to indicate if stdbool.h conforms to C99. +// Define if stdbool.h conforms to C99. #cmakedefine EXV_HAVE_STDBOOL_H -// Definition to indicate if you have the header file. +// Define if you have the header file. #cmakedefine EXV_HAVE_STDINT_H #ifndef EXV_HAVE_STDINT_H @@ -74,53 +61,53 @@ #endif #endif -// Definition to indicate if you have the header file. +// Define if you have the header file. #cmakedefine EXV_HAVE_STDLIB_H -// Definition to indicate if you have the `strchr' function. +// Define if you have the strchr function. #cmakedefine EXV_HAVE_STRCHR -// Definition to indicate if you have the `strerror' function. +// Define if you have the strerror function. #cmakedefine EXV_HAVE_STRERROR -// Definition to indicate if you have the `strerror_r' function. +// Define if you have the strerror_r function. #cmakedefine EXV_HAVE_STRERROR_R -// Definition to indicate if strerror_r returns char *. +// Define if strerror_r returns char *. #cmakedefine STRERROR_R_CHAR_P -// Definition to indicate if you have the header file. +// Define if you have the header file. #cmakedefine EXV_HAVE_STRINGS_H -// Definition to indicate if you have the `strtol' function. +// Define if you have the strtol function. #cmakedefine EXV_HAVE_STRTOL -// Definition to indicate if you have the `mmap' function. +// Define if you have the mmap function. #cmakedefine EXV_HAVE_MMAP -// Definition to indicate if you have the `munmap' function. +// Define if you have the munmap function. #cmakedefine EXV_HAVE_MUNMAP -// Definition to indicate if you have the header file. +// Define if you have header file. #cmakedefine EXV_HAVE_SYS_STAT_H -// Definition to indicate if you have the header file. +// Define if you have the header file. #cmakedefine EXV_HAVE_SYS_TYPES_H -// Definition to indicate if you have the `timegm' function. +// Define if you have the timegm function. #cmakedefine EXV_HAVE_TIMEGM -/* Define to 1 if you have the header file. */ +/* Define if you have the header file. */ #cmakedefine EXV_HAVE_UNISTD_H 1 #if !defined( EXV_HAVE_UNISTD_H) && defined(__CYGWIN__) #define EXV_HAVE_UNISTD_H 1 #endif -// Definition to indicate if you have the header file. +// Define if you have the header file. #cmakedefine EXV_HAVE_SYS_MMAN_H -// Definition to indicate if the `zlib' library will be used +// Define if you have are using the zlib library. #cmakedefine EXV_HAVE_LIBZ #if defined(_MSC_VER) && HAVE_LIBZ @@ -129,11 +116,11 @@ #endif #endif -// Definition to indicate if you have the header file. +// Define if you have the header file. #cmakedefine EXV_HAVE_PROCESS_H -/* Define to 1 if you have the Adobe XMP Toolkit. */ -#cmakedefine EXV_HAVE_XMP_TOOLKIT 1 +/* Define if you have (Exiv2/xmpsdk) Adobe XMP Toolkit. */ +#cmakedefine EXV_HAVE_XMP_TOOLKIT /* Define to 1 if `lstat' dereferences a symlink specified with a trailing slash. */ @@ -168,3 +155,22 @@ /* Define to `unsigned' if does not define. */ #cmakedefine size_t + +// ------------------------------------------------------------------ +// The following features are not available for Commercial use +#ifndef EXV_COMMERCIAL_VERSION + +// Definition to enable translation of Nikon lens names. +#cmakedefine EXV_HAVE_LENSDATA + +// Define if you have the iconv function. +#cmakedefine EXV_HAVE_ICONV + +// Definition to enable conversion of UCS2 encoded Windows tags to UTF-8. +#cmakedefine EXV_HAVE_PRINTUCS2 + +#endif /* !EXV_COMMERCIAL_VERSION */ +// ------------------------------------------------------------------ + +// That's All Folks! +// ------------------------------------------------------------------ diff --git a/include/exiv2/basicio.hpp b/include/exiv2/basicio.hpp index 95713bfc..9d0b31cf 100644 --- a/include/exiv2/basicio.hpp +++ b/include/exiv2/basicio.hpp @@ -43,12 +43,6 @@ #ifndef EXV_XPATH_MEMIO #define EXV_XPATH_MEMIO 0 #endif -#ifndef EXV_USE_CURL -#define EXV_USE_CURL 0 -#endif -#ifndef EXV_USE_SSH -#define EXV_USE_SSH 0 -#endif // ***************************************************************************** // namespace extensions @@ -1117,7 +1111,7 @@ namespace Exiv2 { //@} }; -#if EXV_USE_CURL == 1 +#ifdef EXV_USE_CURL /*! @brief Provides the http, https read/write access and ftp read access for the RemoteIo. This class is based on libcurl. @@ -1173,7 +1167,7 @@ namespace Exiv2 { }; #endif -#if EXV_USE_SSH == 1 +#ifdef EXV_USE_SSH /*! @brief Provides the ssh read/write access and sftp read access for the RemoteIo. This class is based on libssh. @@ -1262,7 +1256,7 @@ namespace Exiv2 { EXIV2API std::wstring ReplaceStringInPlace(std::wstring subject, const std::wstring& search, const std::wstring& replace); #endif -#if EXV_USE_CURL == 1 +#ifdef EXV_USE_CURL /*! @brief The callback function is called by libcurl to write the data */ diff --git a/include/exiv2/exiv2.hpp b/include/exiv2/exiv2.hpp index d4cc566e..0bba515a 100644 --- a/include/exiv2/exiv2.hpp +++ b/include/exiv2/exiv2.hpp @@ -53,17 +53,21 @@ #include "exiv2/mrwimage.hpp" #include "exiv2/orfimage.hpp" #include "exiv2/pgfimage.hpp" + #ifdef EXV_HAVE_LIBZ #include "exiv2/pngimage.hpp" #endif + #include "exiv2/preview.hpp" #include "exiv2/properties.hpp" #include "exiv2/psdimage.hpp" #include "exiv2/rafimage.hpp" #include "exiv2/rw2image.hpp" -#if EXV_USE_SSH == 1 + +#ifdef EXV_USE_SSH #include "exiv2/ssh.hpp" #endif + #include "exiv2/tags.hpp" #include "exiv2/tgaimage.hpp" #include "exiv2/tiffimage.hpp" diff --git a/include/exiv2/http.hpp b/include/exiv2/http.hpp index ccc27a14..eab54f5e 100644 --- a/include/exiv2/http.hpp +++ b/include/exiv2/http.hpp @@ -1,6 +1,7 @@ #ifndef HTTP_HPP_ #define HTTP_HPP_ +#include "config.h" #include #include #include @@ -18,10 +19,7 @@ namespace Exiv2 { EXIV2API int http(Exiv2::Dictionary& request,Exiv2::Dictionary& response,std::string& errors); } -#ifndef EXV_USE_CURL -#define EXV_USE_CURL 0 -#endif -#if EXV_USE_CURL == 1 +#ifdef EXV_USE_CURL #include #endif diff --git a/include/exiv2/ssh.hpp b/include/exiv2/ssh.hpp index 2750c157..cc698d65 100644 --- a/include/exiv2/ssh.hpp +++ b/include/exiv2/ssh.hpp @@ -24,7 +24,7 @@ // included header files #include "config.h" -#if EXV_USE_SSH == 1 +#ifdef EXV_USE_SSH #include #include #include diff --git a/samples/conntest.cpp b/samples/conntest.cpp index 43eb42e3..bb05bab6 100644 --- a/samples/conntest.cpp +++ b/samples/conntest.cpp @@ -26,7 +26,7 @@ void httpcon(const std::string& url, bool useHttp1_0 = false) { } } -#if EXV_USE_CURL == 1 +#ifdef EXV_USE_CURL void curlcon(const std::string& url, bool useHttp1_0 = false) { CURL* curl = curl_easy_init(); if(!curl) { @@ -68,7 +68,7 @@ void curlcon(const std::string& url, bool useHttp1_0 = false) { } #endif -#if EXV_USE_SSH == 1 +#ifdef EXV_USE_SSH void sshcon(const std::string& url) { Exiv2::Uri uri = Exiv2::Uri::Parse(url); Exiv2::Uri::Decode(uri); @@ -125,7 +125,7 @@ int main(int argc,const char** argv) bool isOk = false; try { - #if EXV_USE_SSH == 1 + #ifdef EXV_USE_SSH if (prot == Exiv2::pSsh) { sshcon(url); isOk = true; @@ -134,7 +134,7 @@ int main(int argc,const char** argv) isOk = true; } #endif - #if EXV_USE_CURL == 1 + #ifdef EXV_USE_CURL if (prot == Exiv2::pHttp || prot == Exiv2::pHttps || prot == Exiv2::pFtp) { curlcon(url, useHttp1_0); isOk = true; diff --git a/src/basicio.cpp b/src/basicio.cpp index 28aa454d..697f92a3 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -46,6 +46,7 @@ EXIV2_RCSID("@(#) $Id$") #include // for alloc, realloc, free #include // for stat, chmod #include // for stat, chmod + #ifdef EXV_HAVE_SYS_MMAN_H # include // for mmap and munmap #endif @@ -55,13 +56,15 @@ EXIV2_RCSID("@(#) $Id$") #ifdef EXV_HAVE_UNISTD_H # include // for getpid, stat #endif -#if EXV_USE_CURL == 1 -#include + +#ifdef EXV_USE_CURL +# include #endif -#if EXV_USE_SSH == 1 -#include "ssh.hpp" + +#ifdef EXV_USE_SSH +# include "ssh.hpp" #else -#define mode_t unsigned short +# define mode_t unsigned short #endif // Platform specific headers for handling extended attributes (xattr) @@ -2079,7 +2082,7 @@ namespace Exiv2 { } #endif -#if EXV_USE_CURL == 1 +#ifdef EXV_USE_CURL //! Internal Pimpl structure of class RemoteIo. class CurlIo::CurlImpl : public Impl { public: @@ -2328,7 +2331,7 @@ namespace Exiv2 { #endif -#if EXV_USE_SSH == 1 +#ifdef EXV_USE_SSH //! Internal Pimpl structure of class RemoteIo. class SshIo::SshImpl : public Impl { public: @@ -2627,7 +2630,7 @@ namespace Exiv2 { return subject; } #endif -#if EXV_USE_CURL == 1 +#ifdef EXV_USE_CURL size_t curlWriter(char* data, size_t size, size_t nmemb, std::string* writerData) { diff --git a/src/image.cpp b/src/image.cpp index 0db66eb0..b2840e45 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -798,16 +798,19 @@ namespace Exiv2 { BasicIo::AutoPtr ImageFactory::createIo(const std::string& path, bool useCurl) { Protocol fProt = fileProtocol(path); -#if EXV_USE_SSH == 1 + +#ifdef EXV_USE_SSH if (fProt == pSsh || fProt == pSftp) { return BasicIo::AutoPtr(new SshIo(path)); // may throw } #endif -#if EXV_USE_CURL == 1 + +#ifdef EXV_USE_CURL if (useCurl && (fProt == pHttp || fProt == pHttps || fProt == pFtp)) { return BasicIo::AutoPtr(new CurlIo(path)); // may throw } #endif + if (fProt == pHttp) return BasicIo::AutoPtr(new HttpIo(path)); // may throw if (fProt == pFileUri) diff --git a/src/ssh.cpp b/src/ssh.cpp index eb745676..68ad1273 100644 --- a/src/ssh.cpp +++ b/src/ssh.cpp @@ -32,7 +32,8 @@ EXIV2_RCSID("@(#) $Id: rw2image.cpp 3201 2013-12-01 12:13:42Z ahuggel $") // included header files #include "config.h" #include "ssh.hpp" -#if EXV_USE_SSH == 1 + +#ifdef EXV_USE_SSH // class member definitions namespace Exiv2 { diff --git a/src/version.cpp b/src/version.cpp index a2278429..ddc3b90d 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -31,15 +31,7 @@ EXIV2_RCSID("@(#) $Id$") #include "config.h" -#ifndef EXV_USE_SSH -#define EXV_USE_SSH 0 -#endif - -#ifndef EXV_USE_CURL -#define EXV_USE_CURL 0 -#endif - -#if EXV_USE_CURL == 1 +#ifdef EXV_USE_CURL #include #endif @@ -53,32 +45,12 @@ EXIV2_RCSID("@(#) $Id$") # endif #endif -#ifndef EXV_HAVE_XMP_TOOLKIT -#define EXV_HAVE_XMP_TOOLKIT 0 -#endif - -#ifndef EXV_HAVE_STRINGS -#define EXV_HAVE_STRINGS 0 -#endif - -#ifndef EXV_SYS_TYPES -#define EXV_SYS_TYPES 0 -#endif - -#ifndef EXV_HAVE_UNISTD -#define EXV_HAVE_UNISTD 0 -#endif - -#ifndef EXV_UNICODE_PATH -#define EXV_UNICODE_PATH 0 -#endif - #include "http.hpp" #include "version.hpp" #include "makernote_int.hpp" // Adobe XMP Toolkit -#if EXV_HAVE_XMP_TOOLKIT +#ifdef EXV_HAVE_XMP_TOOLKIT #include "xmp_exiv2.hpp" #endif @@ -319,6 +291,8 @@ void Exiv2::dumpLibraryInfo(std::ostream& os,const exv_grep_keys_t& keys) int enable_video =0; int enable_webready =0; + int use_curl =0; + int use_ssh =0; #ifdef EXV_HAVE_GMTIME_R have_gmtime_r=1; @@ -460,6 +434,14 @@ void Exiv2::dumpLibraryInfo(std::ostream& os,const exv_grep_keys_t& keys) enable_webready=1; #endif +#ifdef EXV_USE_CURL + use_curl=1; +#endif + +#ifdef EXV_USE_SSH + use_ssh=1; +#endif + #if defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW__) // enumerate loaded libraries and determine path to executable HMODULE handles[200]; @@ -516,8 +498,8 @@ void Exiv2::dumpLibraryInfo(std::ostream& os,const exv_grep_keys_t& keys) output(os,keys,"version" , __VERSION__); output(os,keys,"date" , __DATE__ ); output(os,keys,"time" , __TIME__ ); - output(os,keys,"ssh" , EXV_USE_SSH); -#if EXV_USE_CURL == 1 + +#ifdef EXV_USE_CURL std::string curl_protocols; curl_version_info_data* vinfo = curl_version_info(CURLVERSION_NOW); for (int i = 0; vinfo->protocols[i]; i++) { @@ -525,9 +507,9 @@ void Exiv2::dumpLibraryInfo(std::ostream& os,const exv_grep_keys_t& keys) curl_protocols += " " ; } output(os,keys,"curlprotocols" ,curl_protocols); -#else - output(os,keys,"curl" , EXV_USE_CURL); #endif + + output(os,keys,"curl" , use_curl); output(os,keys,"id" , "$Id$"); if ( libs.begin() != libs.end() ) { output(os,keys,"executable" ,*libs.begin()); @@ -570,6 +552,9 @@ void Exiv2::dumpLibraryInfo(std::ostream& os,const exv_grep_keys_t& keys) output(os,keys,"have_unicode_path" ,have_unicode_path); output(os,keys,"enable_video" ,enable_video ); output(os,keys,"enable_webready" ,enable_webready ); + output(os,keys,"use_curl" ,use_curl ); + output(os,keys,"use_ssh" ,use_ssh ); + output(os,keys,"config_path" ,Exiv2::Internal::getExiv2ConfigPath()); // #1147 @@ -579,7 +564,7 @@ void Exiv2::dumpLibraryInfo(std::ostream& os,const exv_grep_keys_t& keys) uid_t gid = getgid() ; output(os,keys,"gid" , gid ); #endif -#if EXV_HAVE_XMP_TOOLKIT +#ifdef EXV_HAVE_XMP_TOOLKIT const char* name = "xmlns"; Exiv2::Dictionary ns;