diff --git a/samples/httptest.cpp b/samples/httptest.cpp deleted file mode 100644 index bd47a9f6..00000000 --- a/samples/httptest.cpp +++ /dev/null @@ -1,122 +0,0 @@ -// ***************************************************************** -*- C++ -*- -/* - * Copyright (C) 2004-2021 Exiv2 authors - * This program is part of the Exiv2 distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA. - */ -/* - httptest.cpp - This application is to test http.cpp. It provides the function to GET|HEAD|PUT the file via http protocol. - */ - -#include -#include -#include - -static int testSyntax(const char* arg) -{ - if ( !arg ) { - std::cout << "insufficient input" << std::endl; - exit(0); - } - return 0; -} - -int main(int argc,const char** argv) -{ - Exiv2::XmpParser::initialize(); - ::atexit(Exiv2::XmpParser::terminate); -#ifdef EXV_ENABLE_BMFF - Exiv2::enableBMFF(); -#endif - - if ( argc < 2 ) { - std::cout << "usage : " << argv[0] << " [key value]+" << std::endl; - std::cout << "example: " << argv[0] << " [[-url] url | -server clanmills.com -page /LargsPanorama.jpg] -header \"Range: bytes=0-200\"" << std::endl; - std::cout << "or : " << argv[0] << " http://clanmills.com/LargsPanorama.jpg" << std::endl; - std::cout << "useful keys: -verb {GET|HEAD|PUT} -page str -server str -port number -version [-header something]+ " << std::endl; - std::cout << "default keys: -verb GET -server clanmills.com -page robin.shtml -port 80 -version 1.0" << std::endl; - std::cout << "export http_proxy=url eg export http_proxy=http://64.62.247.244:80" << std::endl; - return 0; - } - - Exiv2::Dictionary response; - Exiv2::Dictionary request; - std::string errors; - - // convert the command-line arguments into the request dictionary - for ( int i = 1 ; i < argc ; i +=2 ) { - const char* arg = argv[i]; - // skip past the -'s on the key - while ( arg[0] == '-' ) arg++; - - if ( std::string(arg) == "header" ) { - testSyntax(argv[i+1]); - std::string header = argv[i+1]; - if ( ! strchr(argv[i+1],'\n') ) { - header += "\r\n"; - } - request[arg] += header; - } else if ( std::string(arg) == "uri" || std::string(arg) == "url" ) { - testSyntax(argv[i+1]); - Exiv2::Uri uri = Exiv2::Uri::Parse(argv[i+1]); - if ( uri.Protocol == "http" ) { - request["server"] = uri.Host; - request["page"] = uri.Path; - request["port"] = uri.Port; - } - } else if ( std::string(arg).substr(0,7) == "http://" ) { - Exiv2::Uri uri = Exiv2::Uri::Parse(argv[i--]); - if ( uri.Protocol == "http" ) { - request["server"] = uri.Host; - request["page"] = uri.Path; - request["port"] = uri.Port; - } - } else { - testSyntax(argv[i+1]); - request[arg]=argv[i+1]; - } - } - if ( !request.count("page" ) ) request["page" ] = "robin.shtml"; - if ( !request.count("server") ) request["server"] = "clanmills.com"; - - int result = Exiv2::http(request,response,errors); - std::cout << "result = " << result << std::endl; - std::cout << "errors = " << errors << std::endl; - std::cout << std::endl; - - for ( Exiv2::Dictionary_i it = response.begin() ; it != response.end() ; it++ ) { - // don't show request header - if (it->first == "requestheaders") continue; - - std::cout << it->first << " -> "; - - if ( it->first == "body") { - std::string value(it->second); - std::cout << "# " << value.length(); - if ( value.length() < 1000 ) std::cout << " = " << value ; - } else { - std::cout << it->second; - } - - std::cout << std::endl; - } - - return 0; -} - -// That's all Folks! -//// diff --git a/samples/mt-test.cpp b/samples/mt-test.cpp deleted file mode 100644 index 41c34192..00000000 --- a/samples/mt-test.cpp +++ /dev/null @@ -1,118 +0,0 @@ -// ***************************************************************** -*- C++ -*- -// mt-test.cpp -// Sample multi-threading program -/* - * Copyright (C) 2004-2021 Exiv2 authors - * This program is part of the Exiv2 distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA. - */ - -// Discussion: http://dev.exiv2.org/issues/1207 -// Caution: This code isn't currently exercised by any bash script in the test suite -// This code is here for use in development when multi-threading issues -// are being discussed. For example #1207 and #1187 -// It may be brought into use when Exiv2 support C++11 (#1188) -// - -// WARNING: Only builds with clang and gcc < 4.9. I've never tried to build with Visual Studio -// requires C++11 -// On Mac #define __cplusplus 201103L -// Older compilers #define __cplusplus 199711 -// Compiler switches: -std=c++11 (set in samples/Makefile) - -// WARNING: auto_ptr is not supported in C++11 implemented by gcc 4.9/C++11 and later - -#include -#include -#include -#include -#include -#include -#include - -// mutex to for exclusive reporting -std::mutex m; - -void reportExifMetadataCount(int n,const char* argv[]) -{ - int count = 0 ; - std::string what; - - // count the exif metadata in the file - try { - Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[n]); - assert(image.get() != 0); - image->readMetadata(); - - Exiv2::ExifData &exifData = image->exifData(); - if (!exifData.empty()) { - Exiv2::ExifData::const_iterator end = exifData.end(); - for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) - count++; - } - } catch (Exiv2::Error& e) { - what = e.what() ; - count = -1; - } - - // report to the user - m.lock(); - std::cout << "file: " << argv[n] << " " - << "n: " << n << " " - << "count: " << count << " " - << (count < 0 ? "exception: " : what) - << what << std::endl; - m.unlock(); -} - -int main(int argc,const char* argv[]) -{ - Exiv2::XmpParser::initialize(); - ::atexit(Exiv2::XmpParser::terminate); -#ifdef EXV_ENABLE_BMFF - Exiv2::enableBMFF(); -#endif - - int result = 0; - - if ( argc < 2 ) { - std::cerr << "syntax: " << argv[0] << " [path]+" << std::endl; - result = 1 ; - } else { - // Initialize XmpParser before starting threads - Exiv2::XmpParser::initialize(); - - // bucket of threads - std::thread* threads = new std::thread[argc+1]; - - // spin up the treads - for ( int arg = 1 ; arg < argc ; arg++ ) { - threads[arg] = std::thread(reportExifMetadataCount,arg,argv); - } - - // wait for them to finish - for ( int arg = 1 ; arg < argc ; arg++ ) { - if ( threads[arg].joinable() ) - threads[arg].join(); - } - delete [] threads; - } - - return result; -} - -// That's all Folks! -//// diff --git a/samples/tiffaddpath-test.cpp b/samples/tiffaddpath-test.cpp deleted file mode 100644 index b1994479..00000000 --- a/samples/tiffaddpath-test.cpp +++ /dev/null @@ -1,161 +0,0 @@ -// ***************************************************************** -*- C++ -*- -/* - * Copyright (C) 2004-2021 Exiv2 authors - * This program is part of the Exiv2 distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA. - */ -// tiffaddpath-test.cpp -// Test driver to test adding new tags to a TIFF composite structure - -#include -#include "tiffcomposite_int.hpp" -#include "makernote2_int.hpp" -#include "tiffimage_int.hpp" - -#include -#include -#include - -#include - -using namespace Exiv2; - -void addPath(TiffComponent* pRootDir, - uint16_t tag, - TiffPath& tiffPath); - -void printPath(TiffPath tiffPath, - uint32_t tag, - uint16_t grp); - -struct TiffTagInfo { - bool operator==(const uint32_t& tag) const; - - uint32_t tag_; - const char* name_; -}; - -static constexpr TiffTagInfo tiffTagInfo[] = { - { 0x10000, "none" }, - { 0x20000, "root" }, - { 0x30000, "next" }, - { 0x40000, "all" } -}; - -bool TiffTagInfo::operator==(const uint32_t& tag) const -{ - return tag_ == tag; -} - -std::string tiffTagName(uint32_t tag) -{ - const TiffTagInfo* gi = find(tiffTagInfo, tag); - std::string name; - if (gi != 0) { - name = gi->name_; - } - else { - std::ostringstream os; - os << "0x" << std::hex << std::setw(4) - << std::setfill('0') << std::right << tag; - name = os.str(); - } - return name; -} - -// ----------------------------------------------------------------------------- -// Main program -int main(int argc, char* const argv[]) -{ - Exiv2::XmpParser::initialize(); - ::atexit(Exiv2::XmpParser::terminate); -#ifdef EXV_ENABLE_BMFF - Exiv2::enableBMFF(); -#endif - - if (argc != 3) { - std::cout << "Usage: " << argv[0] << " tag group\n" - << "Print the TIFF path for a tag and group (decimal numbers)\n"; - return 1; - } - - uint32_t tag = atol(argv[1]); - uint16_t grp = atol(argv[2]); - - TiffComponent* pRootDir = new TiffDirectory(0, 1); - - TiffPath tiffPath1; - TiffCreator::getPath(tiffPath1, tag, grp); - printPath(tiffPath1, tag, grp); - addPath(pRootDir, tag, tiffPath1); - - ++tag; - TiffPath tiffPath2; - TiffCreator::getPath(tiffPath2, tag, grp); - printPath(tiffPath2, tag, grp); - addPath(pRootDir, tag, tiffPath2); - - return 0; -} - -// ----------------------------------------------------------------------------- -void addPath(TiffComponent* pRootDir, - uint16_t tag, - TiffPath& tiffPath) -{ - TiffComponent* tc = pRootDir->addPath(tag, tiffPath); - - TiffPrinter tiffPrinter(std::cout); - pRootDir->accept(tiffPrinter); - - std::cout << std::endl; - if (tc) { - std::cout << "Added tag " << tiffTagName(tc->tag()) - << ", group " << tiffGroupName(tc->group()) << "\n"; - } - else { - std::cout << "No tag added\n"; - } - std::cout << std::endl; -} - -// ----------------------------------------------------------------------------- -void printPath(TiffPath tiffPath, - uint32_t tag, - uint16_t grp) -{ - std::cout << "\nTiff path for tag " - << std::setw(6) << std::setfill(' ') << std::left - << tiffTagName(tag) - << ", group " << tiffGroupName(grp) - << " (id = " << std::dec << grp << "):\n\n" - << "ext. tag group new group \n" - << "-------- ------------ ------------\n"; - - while (!tiffPath.empty()) - { - const TiffStructure* ts = tiffPath.top(); - tiffPath.pop(); - std::cout << std::setw(8) << std::setfill(' ') << std::left - << tiffTagName(ts->extendedTag_) - << " " << std::setw(12) << std::setfill(' ') << std::left - << tiffGroupName(ts->group_) - << " " << std::setw(12) << std::setfill(' ') << std::left - << tiffGroupName(ts->newGroup_) - << "\n"; - } - std::cout << std::endl; -} diff --git a/samples/toexv.cpp b/samples/toexv.cpp deleted file mode 100644 index 290c46b3..00000000 --- a/samples/toexv.cpp +++ /dev/null @@ -1,233 +0,0 @@ -// ***************************************************************** -*- C++ -*- -/* - * Copyright (C) 2004-2017 Andreas Huggel - * - * This program is part of the Exiv2 distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA. - */ - -#include -#include -#include -#include -#include "utils.hpp" -#include "toexv.hpp" - -static size_t exifMetadataCount(Exiv2::Image::AutoPtr& image) -{ - size_t result = 0 ; - Exiv2::ExifData& exif = image->exifData(); - Exiv2::ExifData::const_iterator end = exif.end(); - for (Exiv2::ExifData::const_iterator i = exif.begin(); i != end; ++i) result++; - return result; -} - -// ***************************************************************************** -// Main -int main(int argc, char* const argv[]) -{ - Exiv2::XmpParser::initialize(); - ::atexit(Exiv2::XmpParser::terminate); -#ifdef EXV_ENABLE_BMFF - Exiv2::enableBMFF(); -#endif - - try { - // Handle command line arguments - Params params(":iecCahsx"); - if (params.getopt(argc, argv)) return params.usage(); - if (params.help_ ) return params.help(); - - Exiv2::Image::AutoPtr readImage = Exiv2::ImageFactory::open(params.read_); - assert(readImage.get() != 0); - readImage->readMetadata(); - - if ( params.write_ == "+" ) { - std::cout << "exifMetadataCount = " << exifMetadataCount(readImage) << std::endl; - - // create an in-memory file and write the metadata - Exiv2::BasicIo::AutoPtr memIo (new Exiv2::MemIo()); - Exiv2::Image::AutoPtr memImage(new Exiv2::ExvImage(memIo,true)); - memImage->setMetadata (*readImage); - memImage->writeMetadata(); - - // serialize the in-memory file into buff - size_t size = memImage->io().size(); - Exiv2::byte buff[size]; - memImage->io().seek(0,Exiv2::BasicIo::beg); - memImage->io().read(buff,size); - - std::cout << "size = " << size << std::endl; - - // create an in-memory file with buff and read the metadata into buffImage - Exiv2::BasicIo::AutoPtr buffIo (new Exiv2::MemIo(buff,size)); - Exiv2::Image::AutoPtr buffImage(new Exiv2::ExvImage(buffIo,false)); - assert(buffImage.get() != 0); - buffImage->readMetadata(); - - std::cout << "exifMetadataCount = " << exifMetadataCount(buffImage) << std::endl; - - } else if ( params.write_ != "-" ) { - // create a file and write the metadata - Exiv2::Image::AutoPtr writeImage = Exiv2::ImageFactory::create(Exiv2::ImageType::exv,params.write_); - params.copyMetadata(readImage,writeImage); - } else { - // create an in-memory file - Exiv2::BasicIo::AutoPtr memIo (new Exiv2::MemIo()); - Exiv2::Image::AutoPtr memImage(new Exiv2::ExvImage(memIo,true)); - params.copyMetadata(readImage,memImage); - - // read a few bytes from the in-memory file - size_t size = memImage->io().size(); - if (size>32) size = 32; - Exiv2::byte data[size]; - - memImage->io().seek(0,Exiv2::BasicIo::beg); - memImage->io().read(data,size); - - // dump the bytes - for ( size_t i = 0 ; i < size ; i++ ) { - char c = (char) data[i] ; - if ( !isascii(c) ) c = '.' ; - std::cout << c ; - } - std::cout << std::endl; - } - - return 0; - - } catch (Exiv2::AnyError& e) { - std::cerr << "Caught Exiv2 exception '" << e << "'\n"; - return 3; - } -} - -Params::Params( const char* opts) -: optstring_(opts) -, first_(true) -, help_(false) -, iptc_(false) -, exif_(false) -, ICC_(false) -, all_(false) -, comment_(false) -, xmp_(false) -, size_(false) -, usage_(false) -{} - -void Params::copyMetadata(Exiv2::Image::AutoPtr& readImage,Exiv2::Image::AutoPtr& writeImage) -{ - if (all_ ) writeImage->setMetadata (*readImage); - if (iptc_ ) writeImage->setIptcData ( readImage->iptcData()); - if (exif_ ) writeImage->setExifData ( readImage->exifData()); - if (ICC_ ) writeImage->setIccProfile(*readImage->iccProfile()); - if (comment_) writeImage->setComment ( readImage->comment()); - if (xmp_ ) writeImage->setXmpData ( readImage->xmpData()); - - writeImage->writeMetadata(); - if ( size_ ) std::cout << write_ << " " << writeImage->io().size() << std::endl; -} - -int Params::option(int opt, const std::string& /*optarg*/, int optopt) -{ - int rc = 0; - switch (opt) { - case 'h': help_ = true ; break; - case 'i': iptc_ = true ; break; - case 'e': exif_ = true ; break; - case 'c': comment_ = true ; break; - case 'C': ICC_ = true ; break; - case 'x': xmp_ = true ; break; - case 'a': all_ = true ; break; - case 's': size_ = true ; break; - case 'p': /* ignore for backwards compatibility */ ; break; - case ':': - std::cerr << progname() << ": Option -" << static_cast(optopt) - << " requires an argument\n"; - rc = 1; - break; - case '?': - std::cerr << progname() << ": Unrecognized option -" - << static_cast(optopt) << "\n"; - rc = 1; - break; - default: - std::cerr << progname() - << ": getopt returned unexpected character code " << (char) opt - << " 0x" << std::hex << opt << "\n"; - rc = 1; - break; - } - - return rc; -} - -int Params::nonoption(const std::string& argv) -{ - if (!write_.empty()) { - std::cerr << progname() << ": Unexpected extra argument (" << argv << ")\n"; - return 1; - } - if (first_) read_ = argv; - else write_ = argv; - first_ = false; - return 0; -} - -int Params::getopt(int argc, char* const argv[]) -{ - int rc = Util::Getopt::getopt(argc, argv, optstring_); - if ( argc == 1 ) usage_ = true; - // Further consistency checks - if ( !help_ && !usage_ ) { - if (rc==0 && read_.empty() ) { - std::cerr << progname() << ": Read and write files must be specified\n"; - rc = 1; - } - if (rc==0 && write_.empty() ) { - std::cerr << progname() << ": Write file must be specified\n"; - rc = 1; - } - } - if ( argc == 3 ) { all_ = true; size_ = true; } - if ( usage_ ) return 2 ; - return rc; -} - -int Params::usage(std::ostream& os) const -{ - os << "Reads and writes raw metadata. Use -h option for help.\n" - << "Usage: " << progname() - << " [-" << optstring_ << "]" - << " readfile {-|+|writefile}\n"; - return 2; -} - -int Params::help(std::ostream& os) const -{ - usage(os); - os << "\nOptions:\n" - " -i Read Iptc data from readfile and write to writefile.\n" - " -e Read Exif data from readfile and write to writefile.\n" - " -c Read Jpeg comment from readfile and write to writefile.\n" - " -C Read ICC profile from readfile and write to writefile.\n" - " -x Read XMP data from readfile and write to writefile.\n" - " -a Read all metadata from readfile and write to writefile.\n" - " -s Print size of writefile.\n" - " -h Display this help and exit.\n"; - return 1; -} diff --git a/samples/toexv.hpp b/samples/toexv.hpp deleted file mode 100644 index 8a8a7bcd..00000000 --- a/samples/toexv.hpp +++ /dev/null @@ -1,75 +0,0 @@ -// ***************************************************************** -*- C++ -*- -/* - * This program is part of the Exiv2 distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA. - */ -#ifndef _TOEXC_HPP_ -#define _TOEXC_HPP_ - -class Params : public Util::Getopt { -private: - std::string optstring_; - bool first_; - -public: - bool help_; //!< Help option flag. - bool iptc_; //!< Iptc option flag. - bool exif_; //!< Exif option flag. - bool ICC_ ; //!< ICC option flag. - bool all_ ; //!< All option flag - bool comment_; //!< JPEG comment option flag. - bool xmp_; //!< XMP option flag. - bool size_; //!< Size option flag. - bool usage_; //!< Usage option flag. - std::string read_; //!< Source file - std::string write_; //!< Destination file - -public: - /*! - @brief Default constructor. Note that optstring_ is initialized here. - */ - Params( const char* opts); - - /*! - @brief Call Getopt::getopt() with optstring, to initiate command line - argument parsing, perform consistency checks after all command line - arguments are parsed. - - @param argc Argument count as passed to main() on program invocation. - @param argv Argument array as passed to main() on program invocation. - - @return 0 if successful, >0 in case of errors. - */ - int getopt(int argc, char* const argv[]); - - //! Handle options and their arguments. - virtual int option(int opt, const std::string& optarg, int optopt); - - //! Handle non-option parameters. - virtual int nonoption(const std::string& argv); - - //! Print a minimal usage note to an output stream. - int usage(std::ostream& os =std::cout) const; - - //! Print further usage explanations to an output stream. - int help(std::ostream& os =std::cout) const; - - //! copy metadata from one image to another. - void copyMetadata(Exiv2::Image::UniquePtr& readImage,Exiv2::Image::UniquePtr& writeImage); - -}; // class Params - -#endif // _TOEXV_HPP_