Merge pull request #2177 from neheb/1

clang-tidy and manual stuff
main
Luis Díaz Más 3 years ago committed by GitHub
commit 6e9eca445a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -262,7 +262,7 @@ class EXIV2API Error : public std::exception {
} }
//! Virtual destructor. (Needed because of throw()) //! Virtual destructor. (Needed because of throw())
~Error() noexcept override; ~Error() noexcept override = default;
//@} //@}
//! @name Accessors //! @name Accessors

@ -123,7 +123,7 @@ class Position {
virtual ~Position() = default; virtual ~Position() = default;
// instance methods // instance methods
bool good() const { [[nodiscard]] bool good() const {
return time_ || lon_ || lat_ || ele_; return time_ || lon_ || lat_ || ele_;
} }
std::string getTimeString() { std::string getTimeString() {
@ -131,22 +131,22 @@ class Position {
times_ = getExifTime(time_); times_ = getExifTime(time_);
return times_; return times_;
} }
time_t getTime() const { [[nodiscard]] time_t getTime() const {
return time_; return time_;
} }
std::string toString() const; [[nodiscard]] std::string toString() const;
// getters/setters // getters/setters
double lat() const { [[nodiscard]] double lat() const {
return lat_; return lat_;
} }
double lon() const { [[nodiscard]] double lon() const {
return lon_; return lon_;
} }
double ele() const { [[nodiscard]] double ele() const {
return ele_; return ele_;
} }
int delta() const { [[nodiscard]] int delta() const {
return delta_; return delta_;
} }
void delta(int delta) { void delta(int delta) {

@ -25,16 +25,15 @@ int main() {
if (reader.ParseError() < 0) { if (reader.ParseError() < 0) {
std::cerr << "Can't load '" << ini << "'" << std::endl; std::cerr << "Can't load '" << ini << "'" << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} else {
std::cout << "Config loaded from : '" << ini << "' "
<< "version=" << reader.GetInteger("protocol", "version", -1)
<< ", name=" << reader.Get("user", "name", "UNKNOWN")
<< ", email=" << reader.Get("user", "email", "UNKNOWN") << ", pi=" << reader.GetReal("user", "pi", -1)
<< ", active=" << reader.GetBoolean("user", "active", true) << std::endl;
std::cout << "169=" << reader.Get("canon", "169", "UNDEFINED")
<< ", 170=" << reader.Get("canon", "170", "UNDEFINED") << std::endl;
} }
std::cout << "Config loaded from : '" << ini << "' "
<< "version=" << reader.GetInteger("protocol", "version", -1)
<< ", name=" << reader.Get("user", "name", "UNKNOWN")
<< ", email=" << reader.Get("user", "email", "UNKNOWN") << ", pi=" << reader.GetReal("user", "pi", -1)
<< ", active=" << reader.GetBoolean("user", "active", true) << std::endl;
std::cout << "169=" << reader.Get("canon", "169", "UNDEFINED") << ", 170=" << reader.Get("canon", "170", "UNDEFINED")
<< std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

@ -619,19 +619,19 @@ class EXIV2API BlockMap {
size_ = num; size_ = num;
} }
bool isNone() const { [[nodiscard]] bool isNone() const {
return type_ == bNone; return type_ == bNone;
} }
bool isKnown() const { [[nodiscard]] bool isKnown() const {
return type_ == bKnown; return type_ == bKnown;
} }
byte* getData() const { [[nodiscard]] byte* getData() const {
return data_; return data_;
} }
size_t getSize() const { [[nodiscard]] size_t getSize() const {
return size_; return size_;
} }
@ -1525,7 +1525,7 @@ HttpIo::HttpIo(const std::string& url, size_t blockSize) {
class CurlIo::CurlImpl : public Impl { class CurlIo::CurlImpl : public Impl {
public: public:
//! Constructor //! Constructor
CurlImpl(const std::string& path, size_t blockSize); CurlImpl(const std::string& url, size_t blockSize);
//! Destructor. Cleans up the curl pointer and releases all managed memory. //! Destructor. Cleans up the curl pointer and releases all managed memory.
~CurlImpl() override; ~CurlImpl() override;

@ -527,7 +527,7 @@ void BmffImage::parseXmp(uint64_t length, uint64_t start) {
long restore = io_->tell(); long restore = io_->tell();
io_->seek(static_cast<long>(start), BasicIo::beg); io_->seek(static_cast<long>(start), BasicIo::beg);
size_t lengthSizeT = static_cast<size_t>(length); auto lengthSizeT = static_cast<size_t>(length);
DataBuf xmp(lengthSizeT + 1); DataBuf xmp(lengthSizeT + 1);
xmp.write_uint8(lengthSizeT, 0); // ensure xmp is null terminated! xmp.write_uint8(lengthSizeT, 0); // ensure xmp is null terminated!
if (io_->read(xmp.data(), lengthSizeT) != lengthSizeT) if (io_->read(xmp.data(), lengthSizeT) != lengthSizeT)

@ -26,8 +26,8 @@
#endif #endif
#ifdef EXV_HAVE_ICONV #ifdef EXV_HAVE_ICONV
#include <errno.h>
#include <iconv.h> #include <iconv.h>
#include <cerrno>
#endif #endif
// Adobe XMP Toolkit // Adobe XMP Toolkit
@ -262,7 +262,7 @@ class Converter {
//! @name Accessors //! @name Accessors
//@{ //@{
//! Get the value of the erase flag, see also setErase(bool on). //! Get the value of the erase flag, see also setErase(bool on).
bool erase() const { [[nodiscard]] bool erase() const {
return erase_; return erase_;
} }
//@} //@}
@ -1527,7 +1527,7 @@ bool asciiToUtf8(std::string& /*str*/) {
return true; return true;
} }
using ConvFct = bool (*)(std::string& str); using ConvFct = std::function<bool(std::string&)>;
struct ConvFctList { struct ConvFctList {
bool operator==(const std::pair<const char*, const char*>& fromTo) const { bool operator==(const std::pair<const char*, const char*>& fromTo) const {

@ -17,7 +17,6 @@
// ***************************************************************************** // *****************************************************************************
// class member definitions // class member definitions
namespace Exiv2 { namespace Exiv2 {
using namespace Internal;
Cr2Image::Cr2Image(BasicIo::UniquePtr io, bool /*create*/) : Cr2Image::Cr2Image(BasicIo::UniquePtr io, bool /*create*/) :
Image(ImageType::cr2, mdExif | mdIptc | mdXmp, std::move(io)) { Image(ImageType::cr2, mdExif | mdIptc | mdXmp, std::move(io)) {
@ -87,7 +86,7 @@ void Cr2Image::writeMetadata() {
if (isCr2Type(*io_, false)) { if (isCr2Type(*io_, false)) {
pData = io_->mmap(true); pData = io_->mmap(true);
size = io_->size(); size = io_->size();
Cr2Header cr2Header; Internal::Cr2Header cr2Header;
if (0 == cr2Header.read(pData, 16)) { if (0 == cr2Header.read(pData, 16)) {
bo = cr2Header.byteOrder(); bo = cr2Header.byteOrder();
} }
@ -101,9 +100,9 @@ void Cr2Image::writeMetadata() {
} // Cr2Image::writeMetadata } // Cr2Image::writeMetadata
ByteOrder Cr2Parser::decode(ExifData& exifData, IptcData& iptcData, XmpData& xmpData, const byte* pData, size_t size) { ByteOrder Cr2Parser::decode(ExifData& exifData, IptcData& iptcData, XmpData& xmpData, const byte* pData, size_t size) {
Cr2Header cr2Header; Internal::Cr2Header cr2Header;
return TiffParserWorker::decode(exifData, iptcData, xmpData, pData, size, Tag::root, TiffMapping::findDecoder, return Internal::TiffParserWorker::decode(exifData, iptcData, xmpData, pData, size, Internal::Tag::root,
&cr2Header); Internal::TiffMapping::findDecoder, &cr2Header);
} }
WriteMethod Cr2Parser::encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder, WriteMethod Cr2Parser::encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder,
@ -113,20 +112,20 @@ WriteMethod Cr2Parser::encode(BasicIo& io, const byte* pData, size_t size, ByteO
// Delete IFDs which do not occur in TIFF images // Delete IFDs which do not occur in TIFF images
static constexpr auto filteredIfds = std::array{ static constexpr auto filteredIfds = std::array{
panaRawId, Internal::panaRawId,
}; };
for (auto&& filteredIfd : filteredIfds) { for (auto&& filteredIfd : filteredIfds) {
#ifdef EXIV2_DEBUG_MESSAGES #ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Warning: Exif IFD " << filteredIfd << " not encoded\n"; std::cerr << "Warning: Exif IFD " << filteredIfd << " not encoded\n";
#endif #endif
ed.erase(std::remove_if(ed.begin(), ed.end(), FindExifdatum(filteredIfd)), ed.end()); ed.erase(std::remove_if(ed.begin(), ed.end(), Internal::FindExifdatum(filteredIfd)), ed.end());
} }
Cr2Header header(byteOrder); auto header = Internal::Cr2Header(byteOrder);
OffsetWriter offsetWriter; Internal::OffsetWriter offsetWriter;
offsetWriter.setOrigin(OffsetWriter::cr2RawIfdOffset, Cr2Header::offset2addr(), byteOrder); offsetWriter.setOrigin(Internal::OffsetWriter::cr2RawIfdOffset, Internal::Cr2Header::offset2addr(), byteOrder);
return TiffParserWorker::encode(io, pData, size, ed, iptcData, xmpData, Tag::root, TiffMapping::findEncoder, &header, return Internal::TiffParserWorker::encode(io, pData, size, ed, iptcData, xmpData, Internal::Tag::root,
&offsetWriter); Internal::TiffMapping::findEncoder, &header, &offsetWriter);
} }
// ************************************************************************* // *************************************************************************
@ -146,7 +145,7 @@ bool isCr2Type(BasicIo& iIo, bool advance) {
if (iIo.error() || iIo.eof()) { if (iIo.error() || iIo.eof()) {
return false; return false;
} }
Cr2Header header; Internal::Cr2Header header;
bool rc = header.read(buf, len); bool rc = header.read(buf, len);
if (!advance || !rc) { if (!advance || !rc) {
iIo.seek(-len, BasicIo::cur); iIo.seek(-len, BasicIo::cur);

@ -18,7 +18,6 @@
// ***************************************************************************** // *****************************************************************************
// class member definitions // class member definitions
namespace Exiv2 { namespace Exiv2 {
using namespace Internal;
CrwImage::CrwImage(BasicIo::UniquePtr io, bool /*create*/) : Image(ImageType::crw, mdExif | mdComment, std::move(io)) { CrwImage::CrwImage(BasicIo::UniquePtr io, bool /*create*/) : Image(ImageType::crw, mdExif | mdComment, std::move(io)) {
} // CrwImage::CrwImage } // CrwImage::CrwImage
@ -102,12 +101,12 @@ void CrwImage::writeMetadata() {
void CrwParser::decode(CrwImage* pCrwImage, const byte* pData, size_t size) { void CrwParser::decode(CrwImage* pCrwImage, const byte* pData, size_t size) {
// Parse the image, starting with a CIFF header component // Parse the image, starting with a CIFF header component
CiffHeader header; Internal::CiffHeader header;
header.read(pData, size); header.read(pData, size);
header.decode(*pCrwImage); header.decode(*pCrwImage);
// a hack to get absolute offset of preview image inside CRW structure // a hack to get absolute offset of preview image inside CRW structure
CiffComponent* preview = header.findComponent(0x2007, 0x0000); auto preview = header.findComponent(0x2007, 0x0000);
if (preview) { if (preview) {
(pCrwImage->exifData())["Exif.Image2.JPEGInterchangeFormat"] = uint32_t(preview->pData() - pData); (pCrwImage->exifData())["Exif.Image2.JPEGInterchangeFormat"] = uint32_t(preview->pData() - pData);
(pCrwImage->exifData())["Exif.Image2.JPEGInterchangeFormatLength"] = static_cast<uint32_t>(preview->size()); (pCrwImage->exifData())["Exif.Image2.JPEGInterchangeFormatLength"] = static_cast<uint32_t>(preview->size());
@ -116,14 +115,14 @@ void CrwParser::decode(CrwImage* pCrwImage, const byte* pData, size_t size) {
void CrwParser::encode(Blob& blob, const byte* pData, size_t size, const CrwImage* pCrwImage) { void CrwParser::encode(Blob& blob, const byte* pData, size_t size, const CrwImage* pCrwImage) {
// Parse image, starting with a CIFF header component // Parse image, starting with a CIFF header component
CiffHeader header; Internal::CiffHeader header;
if (size != 0) { if (size != 0) {
header.read(pData, size); header.read(pData, size);
} }
// Encode Exif tags from image into the CRW parse tree and write the // Encode Exif tags from image into the CRW parse tree and write the
// structure to the binary image blob // structure to the binary image blob
CrwMap::encode(&header, *pCrwImage); Internal::CrwMap::encode(&header, *pCrwImage);
header.write(blob); header.write(blob);
} }
@ -147,7 +146,7 @@ bool isCrwType(BasicIo& iIo, bool advance) {
if (!(('I' == tmpBuf[0] && 'I' == tmpBuf[1]) || ('M' == tmpBuf[0] && 'M' == tmpBuf[1]))) { if (!(('I' == tmpBuf[0] && 'I' == tmpBuf[1]) || ('M' == tmpBuf[0] && 'M' == tmpBuf[1]))) {
result = false; result = false;
} }
if (result && std::memcmp(tmpBuf + 6, CiffHeader::signature(), 8) != 0) { if (result && std::memcmp(tmpBuf + 6, Internal::CiffHeader::signature(), 8) != 0) {
result = false; result = false;
} }
if (!advance || !result) if (!advance || !result)

@ -22,10 +22,7 @@ class RotationMap {
private: private:
//! Helper structure for the mapping list //! Helper structure for the mapping list
struct OmList { using OmList = std::pair<uint16_t, int32_t>;
uint16_t orientation; //!< Exif orientation value
int32_t degrees; //!< CRW Rotation degrees
};
// DATA // DATA
static const OmList omList_[]; static const OmList omList_[];
}; // class RotationMap }; // class RotationMap
@ -350,7 +347,7 @@ size_t CiffDirectory::doWrite(Blob& blob, ByteOrder byteOrder, size_t offset) {
for (auto&& component : components_) { for (auto&& component : components_) {
dirOffset = component->write(blob, byteOrder, dirOffset); dirOffset = component->write(blob, byteOrder, dirOffset);
} }
const uint32_t dirStart = static_cast<uint32_t>(dirOffset); const auto dirStart = static_cast<uint32_t>(dirOffset);
// Number of directory entries // Number of directory entries
byte buf[4]; byte buf[4];
@ -520,7 +517,7 @@ CiffComponent* CiffDirectory::doFindComponent(uint16_t crwTagId, uint16_t crwDir
void CiffHeader::add(uint16_t crwTagId, uint16_t crwDir, DataBuf&& buf) { void CiffHeader::add(uint16_t crwTagId, uint16_t crwDir, DataBuf&& buf) {
CrwDirs crwDirs; CrwDirs crwDirs;
CrwMap::loadStack(crwDirs, crwDir); CrwMap::loadStack(crwDirs, crwDir);
[[maybe_unused]] uint16_t rootDirectory = crwDirs.top().crwDir_; [[maybe_unused]] auto [rootDirectory, _] = crwDirs.top();
crwDirs.pop(); crwDirs.pop();
if (!pRootDir_) { if (!pRootDir_) {
pRootDir_ = std::make_unique<CiffDirectory>(); pRootDir_ = std::make_unique<CiffDirectory>();
@ -553,18 +550,18 @@ CiffComponent* CiffDirectory::doAdd(CrwDirs& crwDirs, uint16_t crwTagId) {
set value set value
*/ */
if (!crwDirs.empty()) { if (!crwDirs.empty()) {
CrwSubDir csd = crwDirs.top(); auto [dir, parent] = crwDirs.top();
crwDirs.pop(); crwDirs.pop();
// Find the directory // Find the directory
for (auto&& component : components_) { for (auto&& component : components_) {
if (component->tag() == csd.crwDir_) { if (component->tag() == dir) {
cc_ = component; cc_ = component;
break; break;
} }
} }
if (!cc_) { if (!cc_) {
// Directory doesn't exist yet, add it // Directory doesn't exist yet, add it
m_ = std::make_unique<CiffDirectory>(csd.crwDir_, csd.parent_); m_ = std::make_unique<CiffDirectory>(dir, parent);
cc_ = m_.get(); cc_ = m_.get();
add(std::move(m_)); add(std::move(m_));
} }
@ -592,7 +589,6 @@ void CiffHeader::remove(uint16_t crwTagId, uint16_t crwDir) {
if (pRootDir_) { if (pRootDir_) {
CrwDirs crwDirs; CrwDirs crwDirs;
CrwMap::loadStack(crwDirs, crwDir); CrwMap::loadStack(crwDirs, crwDir);
[[maybe_unused]] uint16_t rootDirectory = crwDirs.top().crwDir_;
crwDirs.pop(); crwDirs.pop();
pRootDir_->remove(crwDirs, crwTagId); pRootDir_->remove(crwDirs, crwTagId);
} }
@ -608,11 +604,11 @@ void CiffComponent::doRemove(CrwDirs& /*crwDirs*/, uint16_t /*crwTagId*/) {
void CiffDirectory::doRemove(CrwDirs& crwDirs, uint16_t crwTagId) { void CiffDirectory::doRemove(CrwDirs& crwDirs, uint16_t crwTagId) {
if (!crwDirs.empty()) { if (!crwDirs.empty()) {
CrwSubDir csd = crwDirs.top(); auto [dir, _] = crwDirs.top();
crwDirs.pop(); crwDirs.pop();
// Find the directory // Find the directory
for (auto i = components_.begin(); i != components_.end(); ++i) { for (auto i = components_.begin(); i != components_.end(); ++i) {
if ((*i)->tag() == csd.crwDir_) { if ((*i)->tag() == dir) {
// Recursive call to next lower level directory // Recursive call to next lower level directory
(*i)->remove(crwDirs, crwTagId); (*i)->remove(crwDirs, crwTagId);
if ((*i)->empty()) if ((*i)->empty())
@ -743,8 +739,8 @@ void CrwMap::decodeArray(const CiffComponent& ciffComponent, const CrwMapping* p
if (ifdId == canonSiId) { if (ifdId == canonSiId) {
// Exif.Photo.FNumber // Exif.Photo.FNumber
float f = fnumber(canonEv(aperture)); float f = fnumber(canonEv(aperture));
Rational r = floatToRationalCast(f); auto [r, s] = floatToRationalCast(f);
URational ur(r.first, r.second); auto ur = URational(r, s);
URationalValue fn; URationalValue fn;
fn.value_.push_back(ur); fn.value_.push_back(ur);
image.exifData().add(ExifKey("Exif.Photo.FNumber"), &fn); image.exifData().add(ExifKey("Exif.Photo.FNumber"), &fn);
@ -835,9 +831,10 @@ void CrwMap::decodeBasic(const CiffComponent& ciffComponent, const CrwMapping* p
void CrwMap::loadStack(CrwDirs& crwDirs, uint16_t crwDir) { void CrwMap::loadStack(CrwDirs& crwDirs, uint16_t crwDir) {
for (auto&& crw : crwSubDir_) { for (auto&& crw : crwSubDir_) {
if (crw.crwDir_ == crwDir) { auto&& [dir, parent] = crw;
if (dir == crwDir) {
crwDirs.push(crw); crwDirs.push(crw);
crwDir = crw.parent_; crwDir = parent;
} }
} }
} // CrwMap::loadStack } // CrwMap::loadStack

@ -20,7 +20,7 @@ namespace Exiv2::Internal {
class CiffHeader; class CiffHeader;
class CiffComponent; class CiffComponent;
struct CrwMapping; struct CrwMapping;
struct CrwSubDir; using CrwSubDir = std::pair<uint16_t, uint16_t>;
// ***************************************************************************** // *****************************************************************************
// type definitions // type definitions
@ -486,12 +486,6 @@ class CiffHeader {
}; // class CiffHeader }; // class CiffHeader
//! Structure for the CIFF directory hierarchy
struct CrwSubDir {
uint16_t crwDir_; //!< Directory tag
uint16_t parent_; //!< Parent directory tag
}; // struct CrwSubDir
/*! /*!
@brief Structure for a mapping table for conversion of CIFF entries to @brief Structure for a mapping table for conversion of CIFF entries to
image metadata and vice versa. image metadata and vice versa.

@ -153,9 +153,6 @@ Error::Error(ErrorCode code) : code_(code) {
setMsg(0); setMsg(0);
} }
Error::~Error() noexcept {
}
ErrorCode Error::code() const noexcept { ErrorCode Error::code() const noexcept {
return code_; return code_;
} }

@ -77,17 +77,17 @@ class Thumbnail {
@brief Return the thumbnail image in a %DataBuf. The caller owns the @brief Return the thumbnail image in a %DataBuf. The caller owns the
data buffer and %DataBuf ensures that it will be deleted. data buffer and %DataBuf ensures that it will be deleted.
*/ */
virtual Exiv2::DataBuf copy(const Exiv2::ExifData& exifData) const = 0; [[nodiscard]] virtual Exiv2::DataBuf copy(const Exiv2::ExifData& exifData) const = 0;
/*! /*!
@brief Return the MIME type of the thumbnail ("image/tiff" or @brief Return the MIME type of the thumbnail ("image/tiff" or
"image/jpeg"). "image/jpeg").
*/ */
virtual const char* mimeType() const = 0; [[nodiscard]] virtual const char* mimeType() const = 0;
/*! /*!
@brief Return the file extension for the format of the thumbnail @brief Return the file extension for the format of the thumbnail
(".tif", ".jpg"). (".tif", ".jpg").
*/ */
virtual const char* extension() const = 0; [[nodiscard]] virtual const char* extension() const = 0;
//@} //@}
}; // class Thumbnail }; // class Thumbnail
@ -101,9 +101,9 @@ class TiffThumbnail : public Thumbnail {
//! @name Accessors //! @name Accessors
//@{ //@{
Exiv2::DataBuf copy(const Exiv2::ExifData& exifData) const override; [[nodiscard]] Exiv2::DataBuf copy(const Exiv2::ExifData& exifData) const override;
const char* mimeType() const override; [[nodiscard]] const char* mimeType() const override;
const char* extension() const override; [[nodiscard]] const char* extension() const override;
//@} //@}
}; // class TiffThumbnail }; // class TiffThumbnail
@ -117,9 +117,9 @@ class JpegThumbnail : public Thumbnail {
//! @name Accessors //! @name Accessors
//@{ //@{
Exiv2::DataBuf copy(const Exiv2::ExifData& exifData) const override; [[nodiscard]] Exiv2::DataBuf copy(const Exiv2::ExifData& exifData) const override;
const char* mimeType() const override; [[nodiscard]] const char* mimeType() const override;
const char* extension() const override; [[nodiscard]] const char* extension() const override;
//@} //@}
}; // class JpegThumbnail }; // class JpegThumbnail

@ -11,6 +11,9 @@
#include "http.hpp" #include "http.hpp"
#include <array> #include <array>
#include <chrono>
#include <cinttypes>
#include <thread>
//////////////////////////////////////// ////////////////////////////////////////
// platform specific code // platform specific code
@ -23,12 +26,12 @@
#define closesocket close #define closesocket close
#include <arpa/inet.h> #include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <netdb.h> #include <netdb.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#include <cerrno>
#define fopen_S(f, n, o) f = fopen(n, o) #define fopen_S(f, n, o) f = fopen(n, o)
#define WINAPI #define WINAPI
@ -41,13 +44,6 @@ using DWORD = unsigned long;
static int WSAGetLastError() { static int WSAGetLastError() {
return errno; return errno;
} }
static void Sleep(int millisecs) {
const struct timespec rqtp = {0, millisecs * 1000000};
struct timespec rmtp;
nanosleep(&rqtp, &rmtp);
}
#endif #endif
//////////////////////////////////////// ////////////////////////////////////////
@ -70,8 +66,8 @@ static constexpr std::array<const char*, 2> blankLines{
"\n\n", // this is commonly sent by CGI scripts "\n\n", // this is commonly sent by CGI scripts
}; };
static constexpr int snooze = 0; static constexpr auto snooze = std::chrono::milliseconds::zero();
static int sleep_ = 1000; static auto sleep_ = std::chrono::milliseconds(1000);
static int forgive(int n, int& err) { static int forgive(int n, int& err) {
err = WSAGetLastError(); err = WSAGetLastError();
@ -245,12 +241,13 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st
//////////////////////////////////// ////////////////////////////////////
// send the header (we'll have to wait for the connection by the non-blocking socket) // send the header (we'll have to wait for the connection by the non-blocking socket)
while (sleep_ >= 0 && send(sockfd, buffer, n, 0) == SOCKET_ERROR /* && WSAGetLastError() == WSAENOTCONN */) { while (sleep_ >= std::chrono::milliseconds::zero() &&
Sleep(snooze); send(sockfd, buffer, n, 0) == SOCKET_ERROR /* && WSAGetLastError() == WSAENOTCONN */) {
std::this_thread::sleep_for(snooze);
sleep_ -= snooze; sleep_ -= snooze;
} }
if (sleep_ < 0) if (sleep_ < std::chrono::milliseconds::zero())
return error(errors, "error - timeout connecting to server = %s port = %s wsa_error = %d", servername, port, return error(errors, "error - timeout connecting to server = %s port = %s wsa_error = %d", servername, port,
WSAGetLastError()); WSAGetLastError());
@ -330,16 +327,16 @@ int Exiv2::http(Exiv2::Dictionary& request, Exiv2::Dictionary& response, std::st
} }
n = forgive(recv(sockfd, buffer + end, static_cast<int>(buff_l - end), 0), err); n = forgive(recv(sockfd, buffer + end, static_cast<int>(buff_l - end), 0), err);
if (!n) { if (!n) {
Sleep(snooze); std::this_thread::sleep_for(snooze);
sleep_ -= snooze; sleep_ -= snooze;
if (sleep_ < 0) if (sleep_ < std::chrono::milliseconds::zero())
n = FINISH; n = FINISH;
} }
} }
if (n != FINISH || !OK(status)) { if (n != FINISH || !OK(status)) {
snprintf(buffer, sizeof buffer, "wsa_error = %d,n = %d,sleep_ = %d status = %d", WSAGetLastError(), n, sleep_, snprintf(buffer, sizeof buffer, "wsa_error = %d,n = %d,sleep_ = %d status = %d", WSAGetLastError(), n,
status); int(sleep_.count()), status);
error(errors, buffer, nullptr, nullptr, 0); error(errors, buffer, nullptr, nullptr, 0);
} else if (bSearching && OK(status)) { } else if (bSearching && OK(status)) {
if (end) { if (end) {

@ -38,11 +38,7 @@ static inline bool inRange2(int value, int lo1, int hi1, int lo2, int hi2) {
bool Photoshop::isIrb(const byte* pPsData, size_t sizePsData) { bool Photoshop::isIrb(const byte* pPsData, size_t sizePsData) {
if (sizePsData < 4) if (sizePsData < 4)
return false; return false;
for (auto&& i : irbId_) { return std::any_of(irbId_.begin(), irbId_.end(), [pPsData](auto id) { return memcmp(pPsData, id, 4) == 0; });
if (memcmp(pPsData, i, 4) == 0)
return true;
}
return false;
} }
bool Photoshop::valid(const byte* pPsData, size_t sizePsData) { bool Photoshop::valid(const byte* pPsData, size_t sizePsData) {

@ -178,7 +178,7 @@ void PgfImage::doWriteMetadata(BasicIo& outIo) {
throw Error(ErrorCode::kerImageWriteFailed); throw Error(ErrorCode::kerImageWriteFailed);
// Write new Header size. // Write new Header size.
uint32_t newHeaderSize = static_cast<uint32_t>(header.size() + imgSize); auto newHeaderSize = static_cast<uint32_t>(header.size() + imgSize);
DataBuf buffer(4); DataBuf buffer(4);
std::copy_n(&newHeaderSize, 4, buffer.data()); std::copy_n(&newHeaderSize, 4, buffer.data());
byteSwap_(buffer, 0, bSwap_); byteSwap_(buffer, 0, bSwap_);

@ -58,15 +58,15 @@ class Loader {
static UniquePtr create(PreviewId id, const Image& image); static UniquePtr create(PreviewId id, const Image& image);
//! Check if a preview image with given params exists in the image //! Check if a preview image with given params exists in the image
virtual bool valid() const { [[nodiscard]] virtual bool valid() const {
return valid_; return valid_;
} }
//! Get properties of a preview image with given params //! Get properties of a preview image with given params
virtual PreviewProperties getProperties() const; [[nodiscard]] virtual PreviewProperties getProperties() const;
//! Get a buffer that contains the preview image //! Get a buffer that contains the preview image
virtual DataBuf getData() const = 0; [[nodiscard]] virtual DataBuf getData() const = 0;
//! Read preview image dimensions when they are not available directly //! Read preview image dimensions when they are not available directly
virtual bool readDimensions() { virtual bool readDimensions() {
@ -119,10 +119,10 @@ class LoaderNative : public Loader {
LoaderNative(PreviewId id, const Image& image, int parIdx); LoaderNative(PreviewId id, const Image& image, int parIdx);
//! Get properties of a preview image with given params //! Get properties of a preview image with given params
PreviewProperties getProperties() const override; [[nodiscard]] PreviewProperties getProperties() const override;
//! Get a buffer that contains the preview image //! Get a buffer that contains the preview image
DataBuf getData() const override; [[nodiscard]] DataBuf getData() const override;
//! Read preview image dimensions //! Read preview image dimensions
bool readDimensions() override; bool readDimensions() override;
@ -142,10 +142,10 @@ class LoaderExifJpeg : public Loader {
LoaderExifJpeg(PreviewId id, const Image& image, int parIdx); LoaderExifJpeg(PreviewId id, const Image& image, int parIdx);
//! Get properties of a preview image with given params //! Get properties of a preview image with given params
PreviewProperties getProperties() const override; [[nodiscard]] PreviewProperties getProperties() const override;
//! Get a buffer that contains the preview image //! Get a buffer that contains the preview image
DataBuf getData() const override; [[nodiscard]] DataBuf getData() const override;
//! Read preview image dimensions //! Read preview image dimensions
bool readDimensions() override; bool readDimensions() override;
@ -175,10 +175,10 @@ class LoaderExifDataJpeg : public Loader {
LoaderExifDataJpeg(PreviewId id, const Image& image, int parIdx); LoaderExifDataJpeg(PreviewId id, const Image& image, int parIdx);
//! Get properties of a preview image with given params //! Get properties of a preview image with given params
PreviewProperties getProperties() const override; [[nodiscard]] PreviewProperties getProperties() const override;
//! Get a buffer that contains the preview image //! Get a buffer that contains the preview image
DataBuf getData() const override; [[nodiscard]] DataBuf getData() const override;
//! Read preview image dimensions //! Read preview image dimensions
bool readDimensions() override; bool readDimensions() override;
@ -207,10 +207,10 @@ class LoaderTiff : public Loader {
LoaderTiff(PreviewId id, const Image& image, int parIdx); LoaderTiff(PreviewId id, const Image& image, int parIdx);
//! Get properties of a preview image with given params //! Get properties of a preview image with given params
PreviewProperties getProperties() const override; [[nodiscard]] PreviewProperties getProperties() const override;
//! Get a buffer that contains the preview image //! Get a buffer that contains the preview image
DataBuf getData() const override; [[nodiscard]] DataBuf getData() const override;
protected: protected:
//! Name of the group that contains the preview image //! Name of the group that contains the preview image
@ -243,10 +243,10 @@ class LoaderXmpJpeg : public Loader {
LoaderXmpJpeg(PreviewId id, const Image& image, int parIdx); LoaderXmpJpeg(PreviewId id, const Image& image, int parIdx);
//! Get properties of a preview image with given params //! Get properties of a preview image with given params
PreviewProperties getProperties() const override; [[nodiscard]] PreviewProperties getProperties() const override;
//! Get a buffer that contains the preview image //! Get a buffer that contains the preview image
DataBuf getData() const override; [[nodiscard]] DataBuf getData() const override;
//! Read preview image dimensions //! Read preview image dimensions
bool readDimensions() override; bool readDimensions() override;

@ -168,7 +168,7 @@ struct ExifKey::Impl {
//! @name Accessors //! @name Accessors
//@{ //@{
//! Return the name of the tag //! Return the name of the tag
std::string tagName() const; [[nodiscard]] std::string tagName() const;
//@} //@}
// DATA // DATA

@ -213,10 +213,7 @@ struct TagDetails {
@brief Helper structure for lookup tables for translations of bitmask @brief Helper structure for lookup tables for translations of bitmask
values to human readable labels. values to human readable labels.
*/ */
struct TagDetailsBitmask { using TagDetailsBitmask = std::pair<uint32_t, const char*>;
uint32_t mask_; //!< Bitmask value
const char* label_; //!< Description of the tag value
}; // struct TagDetailsBitmask
/*! /*!
@brief Helper structure for lookup tables for translations of controlled @brief Helper structure for lookup tables for translations of controlled
@ -271,20 +268,20 @@ template <int N, const TagDetailsBitmask (&array)[N]>
std::ostream& printTagBitmask(std::ostream& os, const Value& value, const ExifData*) { std::ostream& printTagBitmask(std::ostream& os, const Value& value, const ExifData*) {
const auto val = value.toUint32(); const auto val = value.toUint32();
if (val == 0 && N > 0) { if (val == 0 && N > 0) {
const TagDetailsBitmask* td = *(&array); auto [mask, label] = *array;
if (td->mask_ == 0) if (mask == 0)
return os << exvGettext(td->label_); return os << exvGettext(label);
} }
bool sep = false; bool sep = false;
for (int i = 0; i < N; ++i) { for (int i = 0; i < N; ++i) {
// *& acrobatics is a workaround for a MSVC 7.1 bug // *& acrobatics is a workaround for a MSVC 7.1 bug
const TagDetailsBitmask* td = *(&array) + i; auto [mask, label] = *(array + i);
if (val & td->mask_) { if (val & mask) {
if (sep) { if (sep) {
os << ", " << exvGettext(td->label_); os << ", " << exvGettext(label);
} else { } else {
os << exvGettext(td->label_); os << exvGettext(label);
sep = true; sep = true;
} }
} }

@ -1073,7 +1073,7 @@ uint32_t TiffIfdMakernote::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, in
uint32_t /*dataIdx*/, uint32_t& imageIdx) { uint32_t /*dataIdx*/, uint32_t& imageIdx) {
mnOffset_ = static_cast<uint32_t>(offset); mnOffset_ = static_cast<uint32_t>(offset);
setImageByteOrder(byteOrder); setImageByteOrder(byteOrder);
uint32_t len = static_cast<uint32_t>(writeHeader(ioWrapper, this->byteOrder())); auto len = static_cast<uint32_t>(writeHeader(ioWrapper, this->byteOrder()));
len += ifd_.write(ioWrapper, this->byteOrder(), offset - baseOffset() + len, uint32_t(-1), uint32_t(-1), imageIdx); len += ifd_.write(ioWrapper, this->byteOrder(), offset - baseOffset() + len, uint32_t(-1), uint32_t(-1), imageIdx);
return len; return len;
} // TiffIfdMakernote::doWrite } // TiffIfdMakernote::doWrite

@ -134,17 +134,11 @@ class TiffHeader : public TiffHeaderBase {
*/ */
struct TiffImgTagStruct { struct TiffImgTagStruct {
//! Search key for TIFF image tag structure. //! Search key for TIFF image tag structure.
struct Key { using Key = std::pair<uint16_t, IfdId>;
//! Constructor
Key(uint16_t t, IfdId g) : t_(t), g_(g) {
}
uint16_t t_; //!< %Tag
IfdId g_; //!< %Group
};
//! Comparison operator to compare a TiffImgTagStruct with a TiffImgTagStruct::Key //! Comparison operator to compare a TiffImgTagStruct with a TiffImgTagStruct::Key
bool operator==(const Key& key) const { bool operator==(const Key& key) const {
return key.g_ == group_ && key.t_ == tag_; auto [t, g] = key;
return g == group_ && t == tag_;
} }
// DATA // DATA
@ -158,17 +152,12 @@ struct TiffImgTagStruct {
*/ */
struct TiffGroupStruct { struct TiffGroupStruct {
//! Search key for TIFF group structure. //! Search key for TIFF group structure.
struct Key { using Key = std::pair<uint32_t, IfdId>;
//! Constructor
Key(uint32_t e, IfdId g) : e_(e), g_(g) {
}
uint32_t e_; //!< Extended tag
IfdId g_; //!< %Group
};
//! Comparison operator to compare a TiffGroupStruct with a TiffGroupStruct::Key //! Comparison operator to compare a TiffGroupStruct with a TiffGroupStruct::Key
bool operator==(const Key& key) const { bool operator==(const Key& key) const {
return key.g_ == group_ && (Tag::all == extendedTag_ || key.e_ == extendedTag_); auto [e, g] = key;
return g == group_ && (Tag::all == extendedTag_ || e == extendedTag_);
} }
//! Return the tag corresponding to the extended tag //! Return the tag corresponding to the extended tag
[[nodiscard]] uint16_t tag() const { [[nodiscard]] uint16_t tag() const {

@ -843,7 +843,7 @@ size_t DateValue::copy(byte* buf, ByteOrder /*byteOrder*/) const {
// sprintf wants to add the null terminator, so use oversized buffer // sprintf wants to add the null terminator, so use oversized buffer
char temp[9]; char temp[9];
size_t wrote = static_cast<size_t>(snprintf(temp, sizeof(temp), "%04d%02d%02d", date_.year, date_.month, date_.day)); auto wrote = static_cast<size_t>(snprintf(temp, sizeof(temp), "%04d%02d%02d", date_.year, date_.month, date_.day));
std::memcpy(buf, temp, wrote); std::memcpy(buf, temp, wrote);
return wrote; return wrote;
} }

@ -232,7 +232,8 @@ Exiv2::XmpKey::UniquePtr makeXmpKey(const std::string& schemaNs, const std::stri
//! Helper class used to serialize critical sections //! Helper class used to serialize critical sections
class AutoLock { class AutoLock {
public: public:
AutoLock(Exiv2::XmpParser::XmpLockFct xmpLockFct, void* pLockData) : xmpLockFct_(xmpLockFct), pLockData_(pLockData) { AutoLock(Exiv2::XmpParser::XmpLockFct xmpLockFct, void* pLockData) :
xmpLockFct_(std::move(xmpLockFct)), pLockData_(pLockData) {
if (xmpLockFct_) if (xmpLockFct_)
xmpLockFct_(pLockData_, true); xmpLockFct_(pLockData_, true);
} }
@ -510,7 +511,7 @@ void* XmpParser::pLockData_ = nullptr;
#ifdef EXV_HAVE_XMP_TOOLKIT #ifdef EXV_HAVE_XMP_TOOLKIT
bool XmpParser::initialize(XmpParser::XmpLockFct xmpLockFct, void* pLockData) { bool XmpParser::initialize(XmpParser::XmpLockFct xmpLockFct, void* pLockData) {
if (!initialized_) { if (!initialized_) {
xmpLockFct_ = xmpLockFct; xmpLockFct_ = std::move(xmpLockFct);
pLockData_ = pLockData; pLockData_ = pLockData;
initialized_ = SXMPMeta::Initialize(); initialized_ = SXMPMeta::Initialize();
#ifdef EXV_ADOBE_XMPSDK #ifdef EXV_ADOBE_XMPSDK

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <stdint.h> #include <cstdint>
#include <exiv2/exiv2.hpp> #include <exiv2/exiv2.hpp>
#include "slice.hpp" #include "slice.hpp"
#include "types.hpp" #include "types.hpp"

Loading…
Cancel
Save