diff --git a/include/exiv2/bmpimage.hpp b/include/exiv2/bmpimage.hpp index d9739229..1df45774 100644 --- a/include/exiv2/bmpimage.hpp +++ b/include/exiv2/bmpimage.hpp @@ -86,22 +86,22 @@ namespace Exiv2 { void readMetadata(); /*! @brief Todo: Write metadata back to the image. This method is not - yet(?) implemented. Calling it will throw an Error(31). + yet(?) implemented. Calling it will throw an Error(kerWritingImageFormatUnsupported). */ void writeMetadata(); /*! @brief Todo: Not supported yet(?). Calling this function will throw - an instance of Error(32). + an instance of Error(kerInvalidSettingForImage). */ void setExifData(const ExifData& exifData); /*! @brief Todo: Not supported yet(?). Calling this function will throw - an instance of Error(32). + an instance of Error(kerInvalidSettingForImage). */ void setIptcData(const IptcData& iptcData); /*! @brief Not supported. Calling this function will throw an instance - of Error(32). + of Error(kerInvalidSettingForImage). */ void setComment(const std::string& comment); //@} diff --git a/include/exiv2/cr2image.hpp b/include/exiv2/cr2image.hpp index 9f81822e..554e5fe3 100644 --- a/include/exiv2/cr2image.hpp +++ b/include/exiv2/cr2image.hpp @@ -88,7 +88,7 @@ namespace Exiv2 { void printStructure(std::ostream& out, PrintStructureOption option,int depth); /*! @brief Not supported. CR2 format does not contain a comment. - Calling this function will throw an Error(32). + Calling this function will throw an Error(kerInvalidSettingForImage). */ void setComment(const std::string& comment); //@} diff --git a/include/exiv2/crwimage.hpp b/include/exiv2/crwimage.hpp index 8e883449..045d3f03 100644 --- a/include/exiv2/crwimage.hpp +++ b/include/exiv2/crwimage.hpp @@ -89,7 +89,7 @@ namespace Exiv2 { void writeMetadata(); /*! @brief Not supported. CRW format does not contain IPTC metadata. - Calling this function will throw an Error(32). + Calling this function will throw an Error(kerInvalidSettingForImage). */ void setIptcData(const IptcData& iptcData); //@} diff --git a/include/exiv2/epsimage.hpp b/include/exiv2/epsimage.hpp index 66c5125d..c4d38c05 100644 --- a/include/exiv2/epsimage.hpp +++ b/include/exiv2/epsimage.hpp @@ -86,7 +86,7 @@ namespace Exiv2 void writeMetadata(); /*! @brief Not supported. - Calling this function will throw an instance of Error(32). + Calling this function will throw an instance of Error(kerInvalidSettingForImage). */ void setComment(const std::string& comment); //@} diff --git a/include/exiv2/gifimage.hpp b/include/exiv2/gifimage.hpp index 656c4653..08992d45 100644 --- a/include/exiv2/gifimage.hpp +++ b/include/exiv2/gifimage.hpp @@ -87,22 +87,22 @@ namespace Exiv2 { void readMetadata(); /*! @brief Todo: Write metadata back to the image. This method is not - yet(?) implemented. Calling it will throw an Error(31). + yet(?) implemented. Calling it will throw an Error(kerWritingImageFormatUnsupported). */ void writeMetadata(); /*! @brief Todo: Not supported yet(?). Calling this function will throw - an instance of Error(32). + an instance of Error(kerInvalidSettingForImage). */ void setExifData(const ExifData& exifData); /*! @brief Todo: Not supported yet(?). Calling this function will throw - an instance of Error(32). + an instance of Error(kerInvalidSettingForImage). */ void setIptcData(const IptcData& iptcData); /*! @brief Not supported. Calling this function will throw an instance - of Error(32). + of Error(kerInvalidSettingForImage). */ void setComment(const std::string& comment); //@} diff --git a/include/exiv2/image.hpp b/include/exiv2/image.hpp index b68a6e8a..5e8d5a9f 100644 --- a/include/exiv2/image.hpp +++ b/include/exiv2/image.hpp @@ -684,7 +684,7 @@ namespace Exiv2 { @param type The image type. @param metadataId The metadata identifier. @return Access mode for the requested image type and metadata identifier. - @throw Error(13) if the image type is not supported. + @throw Error(kerUnsupportedImageType) if the image type is not supported. */ static AccessMode checkMode(int type, MetadataId metadataId); /*! diff --git a/include/exiv2/jp2image.hpp b/include/exiv2/jp2image.hpp index 161ea260..a58dfbde 100644 --- a/include/exiv2/jp2image.hpp +++ b/include/exiv2/jp2image.hpp @@ -89,7 +89,7 @@ namespace Exiv2 /*! @brief Todo: Not supported yet(?). Calling this function will throw - an instance of Error(32). + an instance of Error(kerInvalidSettingForImage). */ void setComment(const std::string& comment); //@} diff --git a/include/exiv2/mrwimage.hpp b/include/exiv2/mrwimage.hpp index d539efc8..45708fcc 100644 --- a/include/exiv2/mrwimage.hpp +++ b/include/exiv2/mrwimage.hpp @@ -81,22 +81,22 @@ namespace Exiv2 { void readMetadata(); /*! @brief Todo: Write metadata back to the image. This method is not - yet implemented. Calling it will throw an Error(31). + yet implemented. Calling it will throw an Error(kerWritingImageFormatUnsupported). */ void writeMetadata(); /*! @brief Todo: Not supported yet, requires writeMetadata(). Calling - this function will throw an Error(32). + this function will throw an Error(kerInvalidSettingForImage). */ void setExifData(const ExifData& exifData); /*! @brief Todo: Not supported yet, requires writeMetadata(). Calling - this function will throw an Error(32). + this function will throw an Error(kerInvalidSettingForImage). */ void setIptcData(const IptcData& iptcData); /*! @brief Not supported. MRW format does not contain a comment. - Calling this function will throw an Error(32). + Calling this function will throw an Error(kerInvalidSettingForImage). */ void setComment(const std::string& comment); //@} diff --git a/include/exiv2/orfimage.hpp b/include/exiv2/orfimage.hpp index 5a7f788d..276d1e6f 100644 --- a/include/exiv2/orfimage.hpp +++ b/include/exiv2/orfimage.hpp @@ -83,7 +83,7 @@ namespace Exiv2 { void writeMetadata(); /*! @brief Not supported. ORF format does not contain a comment. - Calling this function will throw an Error(32). + Calling this function will throw an Error(kerInvalidSettingForImage). */ void setComment(const std::string& comment); //@} diff --git a/include/exiv2/psdimage.hpp b/include/exiv2/psdimage.hpp index 57fcb344..6c5a6d0c 100644 --- a/include/exiv2/psdimage.hpp +++ b/include/exiv2/psdimage.hpp @@ -88,7 +88,7 @@ namespace Exiv2 { void readMetadata(); void writeMetadata(); /*! - @brief Not supported. Calling this function will throw an Error(32). + @brief Not supported. Calling this function will throw an Error(kerInvalidSettingForImage). */ void setComment(const std::string& comment); //@} diff --git a/include/exiv2/rafimage.hpp b/include/exiv2/rafimage.hpp index ad7c5744..33239266 100644 --- a/include/exiv2/rafimage.hpp +++ b/include/exiv2/rafimage.hpp @@ -81,22 +81,22 @@ namespace Exiv2 { void readMetadata(); /*! @brief Todo: Write metadata back to the image. This method is not - yet implemented. Calling it will throw an Error(31). + yet implemented. Calling it will throw an Error(kerWritingImageFormatUnsupported). */ void writeMetadata(); /*! @brief Todo: Not supported yet, requires writeMetadata(). Calling - this function will throw an Error(32). + this function will throw an Error(kerInvalidSettingForImage). */ void setExifData(const ExifData& exifData); /*! @brief Todo: Not supported yet, requires writeMetadata(). Calling - this function will throw an Error(32). + this function will throw an Error(kerInvalidSettingForImage). */ void setIptcData(const IptcData& iptcData); /*! @brief Not supported. RAF format does not contain a comment. - Calling this function will throw an Error(32). + Calling this function will throw an Error(kerInvalidSettingForImage). */ void setComment(const std::string& comment); //@} diff --git a/include/exiv2/rw2image.hpp b/include/exiv2/rw2image.hpp index cbc2b38f..8e82e2d1 100644 --- a/include/exiv2/rw2image.hpp +++ b/include/exiv2/rw2image.hpp @@ -79,22 +79,22 @@ namespace Exiv2 { void readMetadata(); /*! @brief Todo: Write metadata back to the image. This method is not - yet implemented. Calling it will throw an Error(31). + yet implemented. Calling it will throw an Error(kerWritingImageFormatUnsupported). */ void writeMetadata(); /*! @brief Todo: Not supported yet, requires writeMetadata(). Calling - this function will throw an Error(32). + this function will throw an Error(kerInvalidSettingForImage). */ void setExifData(const ExifData& exifData); /*! @brief Todo: Not supported yet, requires writeMetadata(). Calling - this function will throw an Error(32). + this function will throw an Error(kerInvalidSettingForImage). */ void setIptcData(const IptcData& iptcData); /*! @brief Not supported. RW2 format does not contain a comment. - Calling this function will throw an Error(32). + Calling this function will throw an Error(kerInvalidSettingForImage). */ void setComment(const std::string& comment); //@} diff --git a/include/exiv2/tgaimage.hpp b/include/exiv2/tgaimage.hpp index 71b2c41d..6124f9e6 100644 --- a/include/exiv2/tgaimage.hpp +++ b/include/exiv2/tgaimage.hpp @@ -88,22 +88,22 @@ namespace Exiv2 { void readMetadata(); /*! @brief Todo: Write metadata back to the image. This method is not - yet(?) implemented. Calling it will throw an Error(31). + yet(?) implemented. Calling it will throw an Error(kerWritingImageFormatUnsupported). */ void writeMetadata(); /*! @brief Todo: Not supported yet(?). Calling this function will throw - an instance of Error(32). + an instance of Error(kerInvalidSettingForImage). */ void setExifData(const ExifData& exifData); /*! @brief Todo: Not supported yet(?). Calling this function will throw - an instance of Error(32). + an instance of Error(kerInvalidSettingForImage). */ void setIptcData(const IptcData& iptcData); /*! @brief Not supported. Calling this function will throw an instance - of Error(32). + of Error(kerInvalidSettingForImage). */ void setComment(const std::string& comment); //@} diff --git a/include/exiv2/tiffimage.hpp b/include/exiv2/tiffimage.hpp index c762cfe1..9fecaa3f 100644 --- a/include/exiv2/tiffimage.hpp +++ b/include/exiv2/tiffimage.hpp @@ -93,7 +93,7 @@ namespace Exiv2 { /*! @brief Not supported. TIFF format does not contain a comment. - Calling this function will throw an Error(32). + Calling this function will throw an Error(kerInvalidSettingForImage). */ void setComment(const std::string& comment); //@} diff --git a/include/exiv2/webpimage.hpp b/include/exiv2/webpimage.hpp index 8bfd9de2..5aeeacf9 100644 --- a/include/exiv2/webpimage.hpp +++ b/include/exiv2/webpimage.hpp @@ -75,7 +75,7 @@ namespace Exiv2 { //@} /*! - @brief Not supported. Calling this function will throw an Error(32). + @brief Not supported. Calling this function will throw an Error(kerInvalidSettingForImage). */ void setComment(const std::string& comment); void setIptcData(const IptcData& /*iptcData*/); diff --git a/include/exiv2/xmpsidecar.hpp b/include/exiv2/xmpsidecar.hpp index eac8c403..3cbaa525 100644 --- a/include/exiv2/xmpsidecar.hpp +++ b/include/exiv2/xmpsidecar.hpp @@ -78,7 +78,7 @@ namespace Exiv2 { void writeMetadata(); /*! @brief Not supported. XMP sidecar files do not contain a comment. - Calling this function will throw an instance of Error(32). + Calling this function will throw an instance of Error(kerInvalidSettingForImage). */ void setComment(const std::string& comment); //@} diff --git a/samples/addmoddel.cpp b/samples/addmoddel.cpp index 96dab47d..59073e07 100644 --- a/samples/addmoddel.cpp +++ b/samples/addmoddel.cpp @@ -69,12 +69,12 @@ try { // Alternatively, we can use findKey() key = Exiv2::ExifKey("Exif.Image.PrimaryChromaticities"); Exiv2::ExifData::iterator pos = exifData.findKey(key); - if (pos == exifData.end()) throw Exiv2::Error(1, "Key not found"); + if (pos == exifData.end()) throw Exiv2::Error(Exiv2::kerErrorMessage, "Key not found"); // Get a pointer to a copy of the value v = pos->getValue(); // Downcast the Value pointer to its actual type Exiv2::URationalValue* prv = dynamic_cast(v.release()); - if (prv == 0) throw Exiv2::Error(1, "Downcast failed"); + if (prv == 0) throw Exiv2::Error(Exiv2::kerErrorMessage, "Downcast failed"); rv = Exiv2::URationalValue::AutoPtr(prv); // Modify the value directly through the interface of URationalValue rv->value_[2] = std::make_pair(88,77); @@ -89,7 +89,7 @@ try { // Delete the metadatum at iterator position pos key = Exiv2::ExifKey("Exif.Image.PrimaryChromaticities"); pos = exifData.findKey(key); - if (pos == exifData.end()) throw Exiv2::Error(1, "Key not found"); + if (pos == exifData.end()) throw Exiv2::Error(Exiv2::kerErrorMessage, "Key not found"); exifData.erase(pos); std::cout << "Deleted key \"" << key << "\"\n"; diff --git a/samples/conntest.cpp b/samples/conntest.cpp index bb05bab6..3d7d4a69 100644 --- a/samples/conntest.cpp +++ b/samples/conntest.cpp @@ -22,7 +22,7 @@ void httpcon(const std::string& url, bool useHttp1_0 = false) { int serverCode = Exiv2::http(request,response,errors); if (serverCode < 0 || serverCode >= 400 || errors.compare("") != 0) { - throw Exiv2::Error(55, "Server", serverCode); + throw Exiv2::Error(Exiv2::kerTiffDirectoryTooLarge, "Server", serverCode); } } @@ -30,14 +30,14 @@ void httpcon(const std::string& url, bool useHttp1_0 = false) { void curlcon(const std::string& url, bool useHttp1_0 = false) { CURL* curl = curl_easy_init(); if(!curl) { - throw Exiv2::Error(1, "Uable to init libcurl."); + throw Exiv2::Error(Exiv2::kerErrorMessage, "Uable to init libcurl."); } // get the timeout value std::string timeoutStr = Exiv2::getEnv(Exiv2::envTIMEOUT); long timeout = atol(timeoutStr.c_str()); if (timeout == 0) { - throw Exiv2::Error(1, "Timeout Environmental Variable must be a positive integer."); + throw Exiv2::Error(Exiv2::kerErrorMessage, "Timeout Environmental Variable must be a positive integer."); } std::string response; @@ -54,7 +54,7 @@ void curlcon(const std::string& url, bool useHttp1_0 = false) { /* Perform the request, res will get the return code */ CURLcode res = curl_easy_perform(curl); if(res != CURLE_OK) { // error happends - throw Exiv2::Error(1, curl_easy_strerror(res)); + throw Exiv2::Error(Exiv2::kerErrorMessage, curl_easy_strerror(res)); } // get return code @@ -63,7 +63,7 @@ void curlcon(const std::string& url, bool useHttp1_0 = false) { curl_easy_cleanup(curl); if (returnCode >= 400 || returnCode < 0) { - throw Exiv2::Error(55, "Server", returnCode); + throw Exiv2::Error(Exiv2::kerTiffDirectoryTooLarge, "Server", returnCode); } } #endif @@ -82,11 +82,11 @@ void sshcon(const std::string& url) { std::string response = ""; std::string cmd = "declare -a x=($(ls -alt " + page + ")); echo ${x[4]}"; if (ssh.runCommand(cmd, &response) != 0) { - throw Exiv2::Error(1, "Unable to get file length."); + throw Exiv2::Error(Exiv2::kerErrorMessage, "Unable to get file length."); } else { long length = atol(response.c_str()); if (length == 0) { - throw Exiv2::Error(1, "File is empty or not found."); + throw Exiv2::Error(Exiv2::kerErrorMessage, "File is empty or not found."); } } } @@ -103,7 +103,7 @@ void sftpcon(const std::string& url) { Exiv2::SSH ssh(uri.Host, uri.Username, uri.Password, uri.Port); sftp_file handle; ssh.getFileSftp(page, handle); - if (handle == NULL) throw Exiv2::Error(1, "Unable to open the file"); + if (handle == NULL) throw Exiv2::Error(Exiv2::kerErrorMessage, "Unable to open the file"); else sftp_close(handle); } #endif diff --git a/samples/exifdata-test.cpp b/samples/exifdata-test.cpp index 3f8c5d1a..268cc682 100644 --- a/samples/exifdata-test.cpp +++ b/samples/exifdata-test.cpp @@ -37,7 +37,7 @@ try { Exiv2::ExifData &ed = image->exifData(); if (ed.empty()) { std::string error = file + ": No Exif data found in the file"; - throw Exiv2::Error(1, error); + throw Exiv2::Error(Exiv2::kerErrorMessage, error); } std::cout << "Copy construction, non-intrusive changes\n"; diff --git a/samples/exifprint.cpp b/samples/exifprint.cpp index 6bf06944..c1bff835 100644 --- a/samples/exifprint.cpp +++ b/samples/exifprint.cpp @@ -45,7 +45,7 @@ try { Exiv2::ExifData &exifData = image->exifData(); if (exifData.empty()) { std::string error("No Exif data found in file"); - throw Exiv2::Error(1, error); + throw Exiv2::Error(Exiv2::kerErrorMessage, error); } Exiv2::ExifData::const_iterator end = exifData.end(); diff --git a/samples/iotest.cpp b/samples/iotest.cpp index 2d70142c..394b5efe 100644 --- a/samples/iotest.cpp +++ b/samples/iotest.cpp @@ -57,12 +57,12 @@ try { FileIo fileIn(argv[1]); if (fileIn.open() != 0) { - throw Error(9, fileIn.path(), strError()); + throw Error(Exiv2::kerDataSourceOpenFailed, fileIn.path(), strError()); } FileIo fileOut1(argv[2]); if (fileOut1.open("w+b") != 0) { - throw Error(10, argv[2], "w+b", strError()); + throw Error(Exiv2::kerFileOpenFailed, argv[2], "w+b", strError()); } MemIo memIo1; @@ -88,7 +88,7 @@ try { // Create or overwrite the file, then close it FileIo fileTest("iotest.txt"); if (fileTest.open("w+b") != 0) { - throw Error(10, "iotest.txt", "w+b", strError()); + throw Error(Exiv2::kerFileOpenFailed, "iotest.txt", "w+b", strError()); } fileTest.close(); @@ -100,7 +100,7 @@ try { memIo2.seek(0, BasicIo::beg); FileIo fileOut2(argv[3]); if (fileOut2.open("w+b") != 0) { - throw Error(10, argv[3], "w+b", strError()); + throw Error(Exiv2::kerFileOpenFailed, argv[3], "w+b", strError()); } long readCount = 0; @@ -138,7 +138,7 @@ int WriteReadSeek(BasicIo &io) const size_t size2 = std::strlen(tester2) + 1; if (io.open() != 0) { - throw Error(9, io.path(), strError()); + throw Error(Exiv2::kerDataSourceOpenFailed, io.path(), strError()); } IoCloser closer(io); if ((size_t) io.write((byte*)tester1, (long)size1) != size1) { @@ -201,7 +201,7 @@ int WriteReadSeek(BasicIo &io) // open should seek to beginning if (io.open() != 0) { - throw Error(9, io.path(), strError()); + throw Error(Exiv2::kerDataSourceOpenFailed, io.path(), strError()); } std::memset(buf, -1, sizeof(buf)); if ((size_t) io.read(buf, sizeof(buf)) != insert + size2) { diff --git a/samples/iptcprint.cpp b/samples/iptcprint.cpp index 2adc55b1..ee295752 100644 --- a/samples/iptcprint.cpp +++ b/samples/iptcprint.cpp @@ -24,7 +24,7 @@ try { if (iptcData.empty()) { std::string error(argv[1]); error += ": No IPTC data found in the file"; - throw Exiv2::Error(1, error); + throw Exiv2::Error(Exiv2::kerErrorMessage, error); } Exiv2::IptcData::iterator end = iptcData.end(); diff --git a/samples/iptctest.cpp b/samples/iptctest.cpp index b81ef1c0..23b90030 100644 --- a/samples/iptctest.cpp +++ b/samples/iptctest.cpp @@ -78,7 +78,7 @@ bool processLine(const std::string& line, int num, IptcData &iptcData) default: std::ostringstream os; os << "Unknown command (" << line.at(0) << ") at line " << num; - throw Error(1, os.str()); + throw Error(kerErrorMessage, os.str()); } return true; } @@ -94,7 +94,7 @@ void processAdd(const std::string& line, int num, IptcData &iptcData) dataStart == std::string::npos) { std::ostringstream os; os << "Invalid \'a\' command at line " << num; - throw Error(1, os.str()); + throw Error(kerErrorMessage, os.str()); } std::string key(line.substr(keyStart, keyEnd-keyStart)); @@ -111,7 +111,7 @@ void processAdd(const std::string& line, int num, IptcData &iptcData) int rc = iptcData.add(iptcKey, value.get()); if (rc) { - throw Error(1, "Iptc dataset already exists and is not repeatable"); + throw Error(kerErrorMessage, "Iptc dataset already exists and is not repeatable"); } } @@ -122,7 +122,7 @@ void processRemove(const std::string& line, int num, IptcData &iptcData) if (keyStart == std::string::npos) { std::ostringstream os; os << "Invalid \'r\' command at line " << num; - throw Error(1, os.str()); + throw Error(kerErrorMessage, os.str()); } const std::string key( line.substr(keyStart) ); @@ -145,7 +145,7 @@ void processModify(const std::string& line, int num, IptcData &iptcData) dataStart == std::string::npos) { std::ostringstream os; os << "Invalid \'m\' command at line " << num; - throw Error(1, os.str()); + throw Error(kerErrorMessage, os.str()); } std::string key(line.substr(keyStart, keyEnd-keyStart)); @@ -167,7 +167,7 @@ void processModify(const std::string& line, int num, IptcData &iptcData) else { int rc = iptcData.add(iptcKey, value.get()); if (rc) { - throw Error(1, "Iptc dataset already exists and is not repeatable"); + throw Error(kerErrorMessage, "Iptc dataset already exists and is not repeatable"); } } } diff --git a/samples/largeiptc-test.cpp b/samples/largeiptc-test.cpp index 0cc843f9..6ae90b99 100644 --- a/samples/largeiptc-test.cpp +++ b/samples/largeiptc-test.cpp @@ -18,12 +18,12 @@ try { // Read data file into data buffer Exiv2::FileIo io(data); if (io.open() != 0) { - throw Exiv2::Error(9, io.path(), Exiv2::strError()); + throw Exiv2::Error(Exiv2::kerDataSourceOpenFailed, io.path(), Exiv2::strError()); } Exiv2::DataBuf buf((long)io.size()); std::cout << "Reading " << buf.size_ << " bytes from " << data << "\n"; io.read(buf.pData_, buf.size_); - if (io.error() || !io.eof()) throw Exiv2::Error(14); + if (io.error() || !io.eof()) throw Exiv2::Error(Exiv2::kerFailedToReadImageData); // Read metadata from file Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file); diff --git a/samples/mmap-test.cpp b/samples/mmap-test.cpp index b49bdceb..8f24466c 100644 --- a/samples/mmap-test.cpp +++ b/samples/mmap-test.cpp @@ -20,7 +20,7 @@ try { FileIo file(path); // Open the file in read mode if (file.open("rb") != 0) { - throw Error(10, path, "rb", strError()); + throw Error(kerFileOpenFailed, path, "rb", strError()); } // Map it to memory const Exiv2::byte* pData = file.mmap(); diff --git a/samples/remotetest.cpp b/samples/remotetest.cpp index 54a7cec1..703eb136 100644 --- a/samples/remotetest.cpp +++ b/samples/remotetest.cpp @@ -54,7 +54,7 @@ try { if (exifReadData.empty()) { std::string error(argv[1]); error += ": No Exif data found in the file"; - throw Exiv2::Error(1, error); + throw Exiv2::Error(Exiv2::kerErrorMessage, error); } Exiv2::ExifData::const_iterator end = exifReadData.end(); for (Exiv2::ExifData::const_iterator i = exifReadData.begin(); i != end; ++i) { @@ -80,19 +80,19 @@ try { exifReadData["Exif.Image.Copyright"] = "Exiv2.org"; // AsciiValue key = Exiv2::ExifKey("Exif.Image.Make"); Exiv2::ExifData::iterator pos = exifReadData.findKey(key); - if (pos == exifReadData.end()) throw Exiv2::Error(1, "Exif.Image.Make not found"); + if (pos == exifReadData.end()) throw Exiv2::Error(Exiv2::kerErrorMessage, "Exif.Image.Make not found"); exifReadData.erase(pos); key = Exiv2::ExifKey("Exif.Image.DateTime"); pos = exifReadData.findKey(key); - if (pos == exifReadData.end()) throw Exiv2::Error(1, "Exif.Image.DateTime not found"); + if (pos == exifReadData.end()) throw Exiv2::Error(Exiv2::kerErrorMessage, "Exif.Image.DateTime not found"); exifReadData.erase(pos); key = Exiv2::ExifKey("Exif.Canon.OwnerName"); pos = exifReadData.findKey(key); - if (pos == exifReadData.end()) throw Exiv2::Error(1, "Exif.Canon.OwnerName not found"); + if (pos == exifReadData.end()) throw Exiv2::Error(Exiv2::kerErrorMessage, "Exif.Canon.OwnerName not found"); exifReadData.erase(pos); key = Exiv2::ExifKey("Exif.CanonCs.LensType"); pos = exifReadData.findKey(key); - if (pos == exifReadData.end()) throw Exiv2::Error(1, "Exif.CanonCs.LensType not found"); + if (pos == exifReadData.end()) throw Exiv2::Error(Exiv2::kerErrorMessage, "Exif.CanonCs.LensType not found"); exifReadData.erase(pos); readTest->setExifData(exifReadData); readTest->writeMetadata(); diff --git a/samples/tiff-test.cpp b/samples/tiff-test.cpp index c2d8a0da..5f07e221 100644 --- a/samples/tiff-test.cpp +++ b/samples/tiff-test.cpp @@ -87,7 +87,7 @@ void print(const ExifData& exifData) { if (exifData.empty()) { std::string error("No Exif data found in the file"); - throw Exiv2::Error(1, error); + throw Exiv2::Error(kerErrorMessage, error); } Exiv2::ExifData::const_iterator end = exifData.end(); for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) { diff --git a/samples/werror-test.cpp b/samples/werror-test.cpp index c223b0d0..ddce978d 100644 --- a/samples/werror-test.cpp +++ b/samples/werror-test.cpp @@ -9,7 +9,7 @@ int main() { try { - throw Exiv2::Error(-1, "ARG1", "ARG2", "ARG3"); + throw Exiv2::Error(Exiv2::kerGeneralError, "ARG1", "ARG2", "ARG3"); } catch (const Exiv2::Error& e) { std::cout << "Caught Error '" << e.what() << "'\n"; @@ -17,7 +17,7 @@ int main() #ifdef EXV_UNICODE_PATH try { - throw Exiv2::WError(-1, L"WARG1", L"WARG2", L"WARG3"); + throw Exiv2::WError(Exiv2::kerGeneralError, L"WARG1", L"WARG2", L"WARG3"); } catch (const Exiv2::WError& e) { std::wstring wmsg = e.wwhat(); diff --git a/samples/write-test.cpp b/samples/write-test.cpp index 031b50b9..12290f6b 100644 --- a/samples/write-test.cpp +++ b/samples/write-test.cpp @@ -172,7 +172,7 @@ void testCase(const std::string& file1, std::cerr << "---> Modifying Exif data\n"; Exiv2::ExifData::iterator pos = ed1.findKey(ek); if (pos == ed1.end()) { - throw Error(1, "Metadatum with key = " + ek.key() + " not found"); + throw Error(kerErrorMessage, "Metadatum with key = " + ek.key() + " not found"); } pos->setValue(value); diff --git a/samples/xmpparse.cpp b/samples/xmpparse.cpp index 606b9e4b..ab39f640 100644 --- a/samples/xmpparse.cpp +++ b/samples/xmpparse.cpp @@ -21,14 +21,14 @@ try { if (0 != Exiv2::XmpParser::decode(xmpData, xmpPacket)) { std::string error(argv[1]); error += ": Failed to parse file contents (XMP packet)"; - throw Exiv2::Error(1, error); + throw Exiv2::Error(Exiv2::kerErrorMessage, error); } if (xmpData.empty()) { std::string error(argv[1]); error += ": No XMP properties found in the XMP packet"; - throw Exiv2::Error(1, error); + throw Exiv2::Error(Exiv2::kerErrorMessage, error); } - for (Exiv2::XmpData::const_iterator md = xmpData.begin(); + for (Exiv2::XmpData::const_iterator md = xmpData.begin(); md != xmpData.end(); ++md) { std::cout << std::setfill(' ') << std::left << std::setw(44) diff --git a/samples/xmpparser-test.cpp b/samples/xmpparser-test.cpp index 7d16ead1..71bc37d2 100644 --- a/samples/xmpparser-test.cpp +++ b/samples/xmpparser-test.cpp @@ -23,14 +23,14 @@ try { if (0 != Exiv2::XmpParser::decode(xmpData, xmpPacket)) { std::string error(argv[1]); error += ": Failed to parse file contents (XMP packet)"; - throw Exiv2::Error(1, error); + throw Exiv2::Error(Exiv2::kerErrorMessage, error); } if (xmpData.empty()) { std::string error(argv[1]); error += ": No XMP properties found in the XMP packet"; - throw Exiv2::Error(1, error); + throw Exiv2::Error(Exiv2::kerErrorMessage, error); } - for (Exiv2::XmpData::const_iterator md = xmpData.begin(); + for (Exiv2::XmpData::const_iterator md = xmpData.begin(); md != xmpData.end(); ++md) { std::cout << std::setfill(' ') << std::left << std::setw(44) @@ -48,14 +48,14 @@ try { if (0 != Exiv2::XmpParser::encode(xmpPacket, xmpData)) { std::string error(argv[1]); error += ": Failed to encode the XMP data"; - throw Exiv2::Error(1, error); + throw Exiv2::Error(Exiv2::kerErrorMessage, error); } Exiv2::FileIo file(filename); if (file.open("wb") != 0) { - throw Exiv2::Error(10, filename, "wb", Exiv2::strError()); + throw Exiv2::Error(Exiv2::kerFileOpenFailed, filename, "wb", Exiv2::strError()); } if (file.write(reinterpret_cast(xmpPacket.data()), static_cast(xmpPacket.size())) == 0) { - throw Exiv2::Error(2, filename, Exiv2::strError(), "FileIo::write"); + throw Exiv2::Error(Exiv2::kerCallFailed, filename, Exiv2::strError(), "FileIo::write"); } Exiv2::XmpParser::terminate(); return 0; diff --git a/samples/xmpprint.cpp b/samples/xmpprint.cpp index 8cfa3137..49f6436f 100644 --- a/samples/xmpprint.cpp +++ b/samples/xmpprint.cpp @@ -32,13 +32,13 @@ try if (xmpData.empty()) { std::string error(argv[1]); error += ": No XMP data found in the file"; - throw Exiv2::Error(1, error); + throw Exiv2::Error(Exiv2::kerErrorMessage, error); } if (xmpData.empty()) { std::string error(argv[1]); error += ": No XMP properties found in the XMP packet"; - throw Exiv2::Error(1, error); + throw Exiv2::Error(Exiv2::kerErrorMessage, error); } for (Exiv2::XmpData::const_iterator md = xmpData.begin(); diff --git a/samples/xmpsample.cpp b/samples/xmpsample.cpp index b2e84c99..4605913d 100644 --- a/samples/xmpsample.cpp +++ b/samples/xmpsample.cpp @@ -97,7 +97,7 @@ try { // Deleting an XMP property Exiv2::XmpData::iterator pos = xmpData.findKey(Exiv2::XmpKey("Xmp.dc.eight")); - if (pos == xmpData.end()) throw Exiv2::Error(1, "Key not found"); + if (pos == xmpData.end()) throw Exiv2::Error(Exiv2::kerErrorMessage, "Key not found"); xmpData.erase(pos); // ------------------------------------------------------------------------- @@ -201,7 +201,7 @@ try { // Serialize the XMP data and output the XMP packet std::string xmpPacket; if (0 != Exiv2::XmpParser::encode(xmpPacket, xmpData)) { - throw Exiv2::Error(1, "Failed to serialize XMP data"); + throw Exiv2::Error(Exiv2::kerErrorMessage, "Failed to serialize XMP data"); } std::cout << xmpPacket << "\n"; diff --git a/src/asfvideo.cpp b/src/asfvideo.cpp index fe0fe75b..3a61046e 100644 --- a/src/asfvideo.cpp +++ b/src/asfvideo.cpp @@ -307,12 +307,12 @@ namespace Exiv2 { void AsfVideo::readMetadata() { - if (io_->open() != 0) throw Error(9, io_->path(), strError()); + if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError()); // Ensure that this is the correct image type if (!isAsfType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "ASF"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "ASF"); } IoCloser closer(*io_); @@ -454,19 +454,19 @@ namespace Exiv2 { void AsfVideo::contentDescription(uint64_t size) { const long pos = io_->tell(); - if (pos == -1) throw Error(14); + if (pos == -1) throw Error(kerFailedToReadImageData); long length[5]; for (int i = 0 ; i < 5 ; ++i) { byte buf[2]; io_->read(buf, 2); - if (io_->error() || io_->eof()) throw Error(14); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); length[i] = getUShort(buf, littleEndian); } for (int i = 0 ; i < 5 ; ++i) { DataBuf buf(length[i]); std::memset(buf.pData_, 0x0, buf.size_); io_->read(buf.pData_, length[i]); - if (io_->error() || io_->eof()) throw Error(14); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); const TagDetails* td = find(contentDescriptionTags, i); assert(td); std::string str((const char*)buf.pData_, length[i]); @@ -477,7 +477,7 @@ namespace Exiv2 { xmpData_[td->label_] = toString16(buf); } } - if (io_->seek(pos + size, BasicIo::beg)) throw Error(14); + if (io_->seek(pos + size, BasicIo::beg)) throw Error(kerFailedToReadImageData); } // AsfVideo::contentDescription void AsfVideo::streamProperties() diff --git a/src/basicio.cpp b/src/basicio.cpp index ad1233bd..985f6d10 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -281,7 +281,7 @@ namespace Exiv2 { # endif ssize_t namebufSize = ::listxattr(src.p_->path_.c_str(), 0, 0, 0); if (namebufSize < 0) { - throw Error(2, src.p_->path_, strError(), "listxattr"); + throw Error(kerCallFailed, src.p_->path_, strError(), "listxattr"); } if (namebufSize == 0) { // No extended attributes in source file @@ -289,18 +289,18 @@ namespace Exiv2 { } char* namebuf = new char[namebufSize]; if (::listxattr(src.p_->path_.c_str(), namebuf, namebufSize, 0) != namebufSize) { - throw Error(2, src.p_->path_, strError(), "listxattr"); + throw Error(kerCallFailed, src.p_->path_, strError(), "listxattr"); } for (ssize_t namebufPos = 0; namebufPos < namebufSize;) { const char *name = namebuf + namebufPos; namebufPos += strlen(name) + 1; const ssize_t valueSize = ::getxattr(src.p_->path_.c_str(), name, 0, 0, 0, 0); if (valueSize < 0) { - throw Error(2, src.p_->path_, strError(), "getxattr"); + throw Error(kerCallFailed, src.p_->path_, strError(), "getxattr"); } char* value = new char[valueSize]; if (::getxattr(src.p_->path_.c_str(), name, value, valueSize, 0, 0) != valueSize) { - throw Error(2, src.p_->path_, strError(), "getxattr"); + throw Error(kerCallFailed, src.p_->path_, strError(), "getxattr"); } // #906. Mountain Lion 'sandbox' terminates the app when we call setxattr #ifndef __APPLE__ @@ -308,7 +308,7 @@ namespace Exiv2 { EXV_DEBUG << "Copying xattr \"" << name << "\" with value size " << valueSize << "\n"; #endif if (::setxattr(path_.c_str(), name, value, valueSize, 0, 0) != 0) { - throw Error(2, path_, strError(), "setxattr"); + throw Error(kerCallFailed, path_, strError(), "setxattr"); } delete [] value; #endif @@ -414,12 +414,12 @@ namespace Exiv2 { if (munmap() != 0) { #ifdef EXV_UNICODE_PATH if (p_->wpMode_ == Impl::wpUnicode) { - throw WError(2, wpath(), strError().c_str(), "munmap"); + throw WError(kerCallFailed, wpath(), strError().c_str(), "munmap"); } else #endif { - throw Error(2, path(), strError(), "munmap"); + throw Error(kerCallFailed, path(), strError(), "munmap"); } } p_->mappedLength_ = size(); @@ -427,12 +427,12 @@ namespace Exiv2 { if (p_->isWriteable_ && p_->switchMode(Impl::opWrite) != 0) { #ifdef EXV_UNICODE_PATH if (p_->wpMode_ == Impl::wpUnicode) { - throw WError(16, wpath(), strError().c_str()); + throw WError(kerFailedToMapFileForReadWrite, wpath(), strError().c_str()); } else #endif { - throw Error(16, path(), strError()); + throw Error(kerFailedToMapFileForReadWrite, path(), strError()); } } #if defined EXV_HAVE_MMAP && defined EXV_HAVE_MUNMAP @@ -444,12 +444,12 @@ namespace Exiv2 { if (MAP_FAILED == rc) { #ifdef EXV_UNICODE_PATH if (p_->wpMode_ == Impl::wpUnicode) { - throw WError(2, wpath(), strError().c_str(), "mmap"); + throw WError(kerCallFailed, wpath(), strError().c_str(), "mmap"); } else #endif { - throw Error(2, path(), strError(), "mmap"); + throw Error(kerCallFailed, path(), strError(), "mmap"); } } p_->pMappedArea_ = static_cast(rc); @@ -473,47 +473,47 @@ namespace Exiv2 { if (hFd == INVALID_HANDLE_VALUE) { #ifdef EXV_UNICODE_PATH if (p_->wpMode_ == Impl::wpUnicode) { - throw WError(2, wpath(), "MSG1", "_get_osfhandle"); + throw WError(kerCallFailed, wpath(), "MSG1", "_get_osfhandle"); } else #endif { - throw Error(2, path(), "MSG1", "_get_osfhandle"); + throw Error(kerCallFailed, path(), "MSG1", "_get_osfhandle"); } } if (!DuplicateHandle(hPh, hFd, hPh, &p_->hFile_, 0, false, DUPLICATE_SAME_ACCESS)) { #ifdef EXV_UNICODE_PATH if (p_->wpMode_ == Impl::wpUnicode) { - throw WError(2, wpath(), "MSG2", "DuplicateHandle"); + throw WError(kerCallFailed, wpath(), "MSG2", "DuplicateHandle"); } else #endif { - throw Error(2, path(), "MSG2", "DuplicateHandle"); + throw Error(kerCallFailed, path(), "MSG2", "DuplicateHandle"); } } p_->hMap_ = CreateFileMapping(p_->hFile_, 0, flProtect, 0, (DWORD) p_->mappedLength_, 0); if (p_->hMap_ == 0 ) { #ifdef EXV_UNICODE_PATH if (p_->wpMode_ == Impl::wpUnicode) { - throw WError(2, wpath(), "MSG3", "CreateFileMapping"); + throw WError(kerCallFailed, wpath(), "MSG3", "CreateFileMapping"); } else #endif { - throw Error(2, path(), "MSG3", "CreateFileMapping"); + throw Error(kerCallFailed, path(), "MSG3", "CreateFileMapping"); } } void* rc = MapViewOfFile(p_->hMap_, dwAccess, 0, 0, 0); if (rc == 0) { #ifdef EXV_UNICODE_PATH if (p_->wpMode_ == Impl::wpUnicode) { - throw WError(2, wpath(), "MSG4", "CreateFileMapping"); + throw WError(kerCallFailed, wpath(), "MSG4", "CreateFileMapping"); } else #endif { - throw Error(2, path(), "MSG4", "CreateFileMapping"); + throw Error(kerCallFailed, path(), "MSG4", "CreateFileMapping"); } } p_->pMappedArea_ = static_cast(rc); @@ -523,23 +523,23 @@ namespace Exiv2 { if (read(buf.pData_, buf.size_) != buf.size_) { #ifdef EXV_UNICODE_PATH if (p_->wpMode_ == Impl::wpUnicode) { - throw WError(2, wpath(), strError().c_str(), "FileIo::read"); + throw WError(kerCallFailed, wpath(), strError().c_str(), "FileIo::read"); } else #endif { - throw Error(2, path(), strError(), "FileIo::read"); + throw Error(kerCallFailed, path(), strError(), "FileIo::read"); } } if (error()) { #ifdef EXV_UNICODE_PATH if (p_->wpMode_ == Impl::wpUnicode) { - throw WError(2, wpath(), strError().c_str(), "FileIo::mmap"); + throw WError(kerCallFailed, wpath(), strError().c_str(), "FileIo::mmap"); } else #endif { - throw Error(2, path(), strError(), "FileIo::mmap"); + throw Error(kerCallFailed, path(), strError(), "FileIo::mmap"); } } p_->pMappedArea_ = buf.release().first; @@ -628,12 +628,12 @@ namespace Exiv2 { } #ifdef EXV_UNICODE_PATH if (p_->wpMode_ == Impl::wpUnicode) { - throw WError(10, wpath(), "a+b", strError().c_str()); + throw WError(kerFileOpenFailed, wpath(), "a+b", strError().c_str()); } else #endif { - throw Error(10, path(), "a+b", strError()); + throw Error(kerFileOpenFailed, path(), "a+b", strError()); } } close(); @@ -666,7 +666,7 @@ namespace Exiv2 { if (::lstat(pf, &buf1) == -1) { statOk = false; #ifndef SUPPRESS_WARNINGS - EXV_WARNING << Error(2, pf, strError(), "::lstat") << "\n"; + EXV_WARNING << Error(kerCallFailed, pf, strError(), "::lstat") << "\n"; #endif } origStMode = buf1.st_mode; @@ -677,13 +677,13 @@ namespace Exiv2 { memset(lbuf.pData_, 0x0, lbuf.size_); pf = reinterpret_cast(lbuf.pData_); if (::readlink(path().c_str(), pf, lbuf.size_ - 1) == -1) { - throw Error(2, path(), strError(), "readlink"); + throw Error(kerCallFailed, path(), strError(), "readlink"); } // We need the permissions of the file, not the symlink if (::stat(pf, &buf1) == -1) { statOk = false; #ifndef SUPPRESS_WARNINGS - EXV_WARNING << Error(2, pf, strError(), "::stat") << "\n"; + EXV_WARNING << Error(kerCallFailed, pf, strError(), "::stat") << "\n"; #endif } origStMode = buf1.st_mode; @@ -714,31 +714,31 @@ namespace Exiv2 { if (ret == 0) { if (GetLastError() == ERROR_FILE_NOT_FOUND) { if (::_wrename(fileIo->wpath().c_str(), wpf) == -1) { - throw WError(17, fileIo->wpath(), wpf, strError().c_str()); + throw WError(kerFileRenameFailed, fileIo->wpath(), wpf, strError().c_str()); } ::_wremove(fileIo->wpath().c_str()); } else { - throw WError(17, fileIo->wpath(), wpf, strError().c_str()); + throw WError(kerFileRenameFailed, fileIo->wpath(), wpf, strError().c_str()); } } } else { if (fileExists(wpf) && ::_wremove(wpf) != 0) { - throw WError(2, wpf, strError().c_str(), "::_wremove"); + throw WError(kerCallFailed, wpf, strError().c_str(), "::_wremove"); } if (::_wrename(fileIo->wpath().c_str(), wpf) == -1) { - throw WError(17, fileIo->wpath(), wpf, strError().c_str()); + throw WError(kerFileRenameFailed, fileIo->wpath(), wpf, strError().c_str()); } ::_wremove(fileIo->wpath().c_str()); } } #else if (fileExists(wpf) && ::_wremove(wpf) != 0) { - throw WError(2, wpf, strError().c_str(), "::_wremove"); + throw WError(kerCallFailed, wpf, strError().c_str(), "::_wremove"); } if (::_wrename(fileIo->wpath().c_str(), wpf) == -1) { - throw WError(17, fileIo->wpath(), wpf, strError().c_str()); + throw WError(kerFileRenameFailed, fileIo->wpath(), wpf, strError().c_str()); } ::_wremove(fileIo->wpath().c_str()); #endif @@ -747,14 +747,14 @@ namespace Exiv2 { if (statOk && ::_wstat(wpf, &buf2) == -1) { statOk = false; #ifndef SUPPRESS_WARNINGS - EXV_WARNING << Error(2, wpf, strError(), "::_wstat") << "\n"; + EXV_WARNING << Error(kerCallFailed, wpf, strError(), "::_wstat") << "\n"; #endif } if (statOk && origStMode != buf2.st_mode) { // Set original file permissions if (::_wchmod(wpf, origStMode) == -1) { #ifndef SUPPRESS_WARNINGS - EXV_WARNING << Error(2, wpf, strError(), "::_wchmod") << "\n"; + EXV_WARNING << Error(kerCallFailed, wpf, strError(), "::_wchmod") << "\n"; #endif } } @@ -777,31 +777,31 @@ namespace Exiv2 { if (ret == 0) { if (GetLastError() == ERROR_FILE_NOT_FOUND) { if (::rename(fileIo->path().c_str(), pf) == -1) { - throw Error(17, fileIo->path(), pf, strError()); + throw Error(kerFileRenameFailed, fileIo->path(), pf, strError()); } ::remove(fileIo->path().c_str()); } else { - throw Error(17, fileIo->path(), pf, strError()); + throw Error(kerFileRenameFailed, fileIo->path(), pf, strError()); } } } else { if (fileExists(pf) && ::remove(pf) != 0) { - throw Error(2, pf, strError(), "::remove"); + throw Error(kerCallFailed, pf, strError(), "::remove"); } if (::rename(fileIo->path().c_str(), pf) == -1) { - throw Error(17, fileIo->path(), pf, strError()); + throw Error(kerFileRenameFailed, fileIo->path(), pf, strError()); } ::remove(fileIo->path().c_str()); } } #else if (fileExists(pf) && ::remove(pf) != 0) { - throw Error(2, pf, strError(), "::remove"); + throw Error(kerCallFailed, pf, strError(), "::remove"); } if (::rename(fileIo->path().c_str(), pf) == -1) { - throw Error(17, fileIo->path(), pf, strError()); + throw Error(kerFileRenameFailed, fileIo->path(), pf, strError()); } ::remove(fileIo->path().c_str()); #endif @@ -810,14 +810,14 @@ namespace Exiv2 { if (statOk && ::stat(pf, &buf2) == -1) { statOk = false; #ifndef SUPPRESS_WARNINGS - EXV_WARNING << Error(2, pf, strError(), "::stat") << "\n"; + EXV_WARNING << Error(kerCallFailed, pf, strError(), "::stat") << "\n"; #endif } if (statOk && origStMode != buf2.st_mode) { // Set original file permissions if (::chmod(pf, origStMode) == -1) { #ifndef SUPPRESS_WARNINGS - EXV_WARNING << Error(2, pf, strError(), "::chmod") << "\n"; + EXV_WARNING << Error(kerCallFailed, pf, strError(), "::chmod") << "\n"; #endif } } @@ -828,23 +828,23 @@ namespace Exiv2 { if (open("w+b") != 0) { #ifdef EXV_UNICODE_PATH if (p_->wpMode_ == Impl::wpUnicode) { - throw WError(10, wpath(), "w+b", strError().c_str()); + throw WError(kerFileOpenFailed, wpath(), "w+b", strError().c_str()); } else #endif { - throw Error(10, path(), "w+b", strError()); + throw Error(kerFileOpenFailed, path(), "w+b", strError()); } } if (src.open() != 0) { #ifdef EXV_UNICODE_PATH if (p_->wpMode_ == Impl::wpUnicode) { - throw WError(9, src.wpath(), strError().c_str()); + throw WError(kerDataSourceOpenFailed, src.wpath(), strError().c_str()); } else #endif { - throw Error(9, src.path(), strError()); + throw Error(kerDataSourceOpenFailed, src.path(), strError()); } } write(src); @@ -855,12 +855,12 @@ namespace Exiv2 { if (open(lastMode) != 0) { #ifdef EXV_UNICODE_PATH if (p_->wpMode_ == Impl::wpUnicode) { - throw WError(10, wpath(), lastMode.c_str(), strError().c_str()); + throw WError(kerFileOpenFailed, wpath(), lastMode.c_str(), strError().c_str()); } else #endif { - throw Error(10, path(), lastMode, strError()); + throw Error(kerFileOpenFailed, path(), lastMode, strError()); } } } @@ -869,12 +869,12 @@ namespace Exiv2 { if (error() || src.error()) { #ifdef EXV_UNICODE_PATH if (p_->wpMode_ == Impl::wpUnicode) { - throw WError(18, wpath(), strError().c_str()); + throw WError(kerTransferFailed, wpath(), strError().c_str()); } else #endif { - throw Error(18, path(), strError()); + throw Error(kerTransferFailed, path(), strError()); } } } // FileIo::transfer @@ -989,7 +989,7 @@ namespace Exiv2 { DataBuf FileIo::read(long rcount) { assert(p_->fp_ != 0); - if ( (size_t) rcount > size() ) throw Error(57); + if ( (size_t) rcount > size() ) throw Error(kerInvalidMalloc); DataBuf buf(rcount); long readCount = read(buf.pData_, buf.size_); buf.size_ = readCount; @@ -1101,7 +1101,7 @@ namespace Exiv2 { long size = EXV_MAX(blockSize * (1 + need / blockSize), size_); byte* data = (byte*)std::malloc(size); if ( data == NULL ) { - throw Error(60); + throw Error(kerMallocFailed); } std::memcpy(data, data_, size_); data_ = data; @@ -1117,7 +1117,7 @@ namespace Exiv2 { long want = blockSize * (1 + need / blockSize ); data_ = (byte*)std::realloc(data_, want); if ( data_ == NULL ) { - throw Error(60); + throw Error(kerMallocFailed); } sizeAlloced_ = want; isMalloced_ = true; @@ -1173,13 +1173,13 @@ namespace Exiv2 { else { // Generic reopen to reset position to start if (src.open() != 0) { - throw Error(9, src.path(), strError()); + throw Error(kerDataSourceOpenFailed, src.path(), strError()); } p_->idx_ = 0; write(src); src.close(); } - if (error() || src.error()) throw Error(19, strError()); + if (error() || src.error()) throw Error(kerMemoryTransferFailed, strError()); } long MemIo::write(BasicIo& src) @@ -1348,12 +1348,12 @@ namespace Exiv2 { void XPathIo::ReadStdin() { if (isatty(fileno(stdin))) - throw Error(53); + throw Error(kerInvalidIccProfile); #ifdef _O_BINARY // convert stdin to binary if (_setmode(_fileno(stdin), _O_BINARY) == -1) - throw Error(54); + throw Error(kerInvalidXMP); #endif char readBuf[100*1024]; @@ -1370,7 +1370,7 @@ namespace Exiv2 { void XPathIo::ReadDataUri(const std::string& path) { size_t base64Pos = path.find("base64,"); if (base64Pos == std::string::npos) - throw Error(1, "No base64 data"); + throw Error(kerErrorMessage, "No base64 data"); std::string data = path.substr(base64Pos+7); char* decodeData = new char[data.length()]; @@ -1378,7 +1378,7 @@ namespace Exiv2 { if (size > 0) write((byte*)decodeData, size); else - throw Error(1, "Unable to decode base 64."); + throw Error(kerErrorMessage, "Unable to decode base 64."); delete[] decodeData; } @@ -1433,11 +1433,11 @@ namespace Exiv2 { if (prot == pStdin) { if (isatty(fileno(stdin))) - throw Error(53); + throw Error(kerInvalidIccProfile); #if defined(_MSC_VER) || defined(__MINGW__) // convert stdin to binary if (_setmode(_fileno(stdin), _O_BINARY) == -1) - throw Error(54); + throw Error(kerInvalidXMP); #endif // read stdin and write to the temp file. char readBuf[100*1024]; @@ -1453,7 +1453,7 @@ namespace Exiv2 { // read data uri and write to the temp file. size_t base64Pos = orgPath.find("base64,"); if (base64Pos == std::string::npos) - throw Error(1, "No base64 data"); + throw Error(kerErrorMessage, "No base64 data"); std::string data = orgPath.substr(base64Pos+7); char* decodeData = new char[data.length()]; @@ -1461,7 +1461,7 @@ namespace Exiv2 { if (size > 0) fs.write(decodeData, size); else - throw Error(1, "Unable to decode base 64."); + throw Error(kerErrorMessage, "Unable to decode base 64."); delete[] decodeData; } @@ -1572,7 +1572,7 @@ namespace Exiv2 { getDataByRange( (long) lowBlock, (long) highBlock, data); rcount = (size_t)data.length(); if (rcount == 0) { - throw Error(1, "Data By Range is empty. Please check the permission."); + throw Error(kerErrorMessage, "Data By Range is empty. Please check the permission."); } byte* source = (byte*)data.c_str(); size_t remain = rcount, totalRead = 0; @@ -1625,7 +1625,7 @@ namespace Exiv2 { iBlock++; } } else if (length == 0) { // file is empty - throw Error(1, "the file length is 0"); + throw Error(kerErrorMessage, "the file length is 0"); } else { p_->size_ = (size_t) length; size_t nBlocks = (p_->size_ + p_->blockSize_ - 1) / p_->blockSize_; @@ -1761,7 +1761,7 @@ namespace Exiv2 { p_->populateBlocks(lowBlock, highBlock); byte* fakeData = (byte*) std::calloc(p_->blockSize_, sizeof(byte)); if (!fakeData) { - throw Error(1, "Unable to allocate data"); + throw Error(kerErrorMessage, "Unable to allocate data"); } size_t iBlock = lowBlock; @@ -1804,7 +1804,7 @@ namespace Exiv2 { void RemoteIo::transfer(BasicIo& src) { if (src.open() != 0) { - throw Error(1, "unable to open src when transferring"); + throw Error(kerErrorMessage, "unable to open src when transferring"); } write(src); src.close(); @@ -1998,7 +1998,7 @@ namespace Exiv2 { request["verb"] = "HEAD"; long serverCode = (long)http(request, response, errors); if (serverCode < 0 || serverCode >= 400 || errors.compare("") != 0) { - throw Error(55, "Server", serverCode); + throw Error(kerTiffDirectoryTooLarge, "Server", serverCode); } Exiv2::Dictionary_i lengthIter = response.find("Content-Length"); @@ -2022,7 +2022,7 @@ namespace Exiv2 { long serverCode = (long)http(request, responseDic, errors); if (serverCode < 0 || serverCode >= 400 || errors.compare("") != 0) { - throw Error(55, "Server", serverCode); + throw Error(kerTiffDirectoryTooLarge, "Server", serverCode); } response = responseDic["body"]; } @@ -2031,7 +2031,7 @@ namespace Exiv2 { { std::string scriptPath(getEnv(envHTTPPOST)); if (scriptPath == "") { - throw Error(1, "Please set the path of the server script to handle http post data to EXIV2_HTTP_POST environmental variable."); + throw Error(kerErrorMessage, "Please set the path of the server script to handle http post data to EXIV2_HTTP_POST environmental variable."); } // standadize the path without "/" at the beginning. @@ -2074,7 +2074,7 @@ namespace Exiv2 { int serverCode = http(request, response, errors); if (serverCode < 0 || serverCode >= 400 || errors.compare("") != 0) { - throw Error(55, "Server", serverCode); + throw Error(kerTiffDirectoryTooLarge, "Server", serverCode); } } HttpIo::HttpIo(const std::string& url, size_t blockSize) @@ -2147,7 +2147,7 @@ namespace Exiv2 { // init curl pointer curl_ = curl_easy_init(); if(!curl_) { - throw Error(1, "Uable to init libcurl."); + throw Error(kerErrorMessage, "Uable to init libcurl."); } // The default block size for FTP is much larger than other protocols @@ -2160,7 +2160,7 @@ namespace Exiv2 { std::string timeout = getEnv(envTIMEOUT); timeout_ = atol(timeout.c_str()); if (timeout_ == 0) { - throw Error(1, "Timeout Environmental Variable must be a positive integer."); + throw Error(kerErrorMessage, "Timeout Environmental Variable must be a positive integer."); } } #ifdef EXV_UNICODE_PATH @@ -2173,7 +2173,7 @@ namespace Exiv2 { // init curl pointer curl_ = curl_easy_init(); if(!curl_) { - throw Error(1, "Uable to init libcurl."); + throw Error(kerErrorMessage, "Uable to init libcurl."); } // The default block size for FTP is much larger than other protocols @@ -2201,13 +2201,13 @@ namespace Exiv2 { /* Perform the request, res will get the return code */ CURLcode res = curl_easy_perform(curl_); if(res != CURLE_OK) { // error happends - throw Error(1, curl_easy_strerror(res)); + throw Error(kerErrorMessage, curl_easy_strerror(res)); } // get return code long returnCode; curl_easy_getinfo (curl_, CURLINFO_RESPONSE_CODE, &returnCode); // get code if (returnCode >= 400 || returnCode < 0) { - throw Error(55, "Server", returnCode); + throw Error(kerTiffDirectoryTooLarge, "Server", returnCode); } // get length double temp; @@ -2239,12 +2239,12 @@ namespace Exiv2 { CURLcode res = curl_easy_perform(curl_); if(res != CURLE_OK) { - throw Error(1, curl_easy_strerror(res)); + throw Error(kerErrorMessage, curl_easy_strerror(res)); } else { long serverCode; curl_easy_getinfo (curl_, CURLINFO_RESPONSE_CODE, &serverCode); // get code if (serverCode >= 400 || serverCode < 0) { - throw Error(55, "Server", serverCode); + throw Error(kerTiffDirectoryTooLarge, "Server", serverCode); } } } @@ -2253,7 +2253,7 @@ namespace Exiv2 { { std::string scriptPath(getEnv(envHTTPPOST)); if (scriptPath == "") { - throw Error(1, "Please set the path of the server script to handle http post data to EXIV2_HTTP_POST environmental variable."); + throw Error(kerErrorMessage, "Please set the path of the server script to handle http post data to EXIV2_HTTP_POST environmental variable."); } Exiv2::Uri hostInfo = Exiv2::Uri::Parse(path_); @@ -2291,12 +2291,12 @@ namespace Exiv2 { CURLcode res = curl_easy_perform(curl_); if(res != CURLE_OK) { - throw Error(1, curl_easy_strerror(res)); + throw Error(kerErrorMessage, curl_easy_strerror(res)); } else { long serverCode; curl_easy_getinfo (curl_, CURLINFO_RESPONSE_CODE, &serverCode); if (serverCode >= 400 || serverCode < 0) { - throw Error(55, "Server", serverCode); + throw Error(kerTiffDirectoryTooLarge, "Server", serverCode); } } } @@ -2310,7 +2310,7 @@ namespace Exiv2 { if (p_->protocol_ == pHttp || p_->protocol_ == pHttps) { return RemoteIo::write(data, wcount); } else { - throw Error(1, "doesnt support write for this protocol."); + throw Error(kerErrorMessage, "doesnt support write for this protocol."); } } @@ -2319,7 +2319,7 @@ namespace Exiv2 { if (p_->protocol_ == pHttp || p_->protocol_ == pHttps) { return RemoteIo::write(src); } else { - throw Error(1, "doesnt support write for this protocol."); + throw Error(kerErrorMessage, "doesnt support write for this protocol."); } } @@ -2401,7 +2401,7 @@ namespace Exiv2 { if (protocol_ == pSftp) { ssh_->getFileSftp(hostInfo_.Path, fileHandler_); - if (fileHandler_ == NULL) throw Error(1, "Unable to open the file"); + if (fileHandler_ == NULL) throw Error(kerErrorMessage, "Unable to open the file"); } else { fileHandler_ = NULL; } @@ -2424,7 +2424,7 @@ namespace Exiv2 { if (protocol_ == pSftp) { ssh_->getFileSftp(hostInfo_.Path, fileHandler_); - if (fileHandler_ == NULL) throw Error(1, "Unable to open the file"); + if (fileHandler_ == NULL) throw Error(kerErrorMessage, "Unable to open the file"); } else { fileHandler_ = NULL; } @@ -2442,11 +2442,11 @@ namespace Exiv2 { //std::string cmd = "stat -c %s " + hostInfo_.Path; std::string cmd = "declare -a x=($(ls -alt " + hostInfo_.Path + ")); echo ${x[4]}"; if (ssh_->runCommand(cmd, &response) != 0) { - throw Error(1, "Unable to get file length."); + throw Error(kerErrorMessage, "Unable to get file length."); } else { length = atol(response.c_str()); if (length == 0) { - throw Error(1, "File is empty or not found."); + throw Error(kerErrorMessage, "File is empty or not found."); } } } @@ -2456,11 +2456,11 @@ namespace Exiv2 { void SshIo::SshImpl::getDataByRange(long lowBlock, long highBlock, std::string& response) { if (protocol_ == pSftp) { - if (sftp_seek(fileHandler_, (uint32_t) (lowBlock * blockSize_)) < 0) throw Error(1, "SFTP: unable to sftp_seek"); + if (sftp_seek(fileHandler_, (uint32_t) (lowBlock * blockSize_)) < 0) throw Error(kerErrorMessage, "SFTP: unable to sftp_seek"); size_t buffSize = (highBlock - lowBlock + 1) * blockSize_; char* buffer = new char[buffSize]; long nBytes = (long) sftp_read(fileHandler_, buffer, buffSize); - if (nBytes < 0) throw Error(1, "SFTP: unable to sftp_read"); + if (nBytes < 0) throw Error(kerErrorMessage, "SFTP: unable to sftp_read"); response.assign(buffer, buffSize); delete[] buffer; } else { @@ -2477,14 +2477,14 @@ namespace Exiv2 { } std::string cmd = ss.str(); if (ssh_->runCommand(cmd, &response) != 0) { - throw Error(1, "Unable to get data by range."); + throw Error(kerErrorMessage, "Unable to get data by range."); } } } void SshIo::SshImpl::writeRemote(const byte* data, size_t size, long from, long to) { - if (protocol_ == pSftp) throw Error(1, "not support SFTP write access."); + if (protocol_ == pSftp) throw Error(kerErrorMessage, "not support SFTP write access."); //printf("ssh update size=%ld from=%ld to=%ld\n", (long)size, from, to); assert(isMalloced_); @@ -2498,19 +2498,19 @@ namespace Exiv2 { << " > " << tempFile; std::string cmd = ss.str(); if (ssh_->runCommand(cmd, &response) != 0) { - throw Error(1, "SSH: Unable to cope the head of file to temp"); + throw Error(kerErrorMessage, "SSH: Unable to cope the head of file to temp"); } // upload the data (the byte ranges which are different between the original // file and the new file) to filepath.exiv2datatemp if (ssh_->scp(hostInfo_.Path + ".exiv2datatemp", data, size) != 0) { - throw Error(1, "SSH: Unable to copy file"); + throw Error(kerErrorMessage, "SSH: Unable to copy file"); } // concatenate the filepath.exiv2datatemp to filepath.exiv2tmp cmd = "cat " + hostInfo_.Path + ".exiv2datatemp >> " + tempFile; if (ssh_->runCommand(cmd, &response) != 0) { - throw Error(1, "SSH: Unable to copy the rest"); + throw Error(kerErrorMessage, "SSH: Unable to copy the rest"); } // copy the tail (from byte toByte to the end of file) of original file to filepath.exiv2tmp @@ -2520,19 +2520,19 @@ namespace Exiv2 { << " >> " << tempFile; cmd = ss.str(); if (ssh_->runCommand(cmd, &response) != 0) { - throw Error(1, "SSH: Unable to copy the rest"); + throw Error(kerErrorMessage, "SSH: Unable to copy the rest"); } // replace the original file with filepath.exiv2tmp cmd = "mv " + tempFile + " " + hostInfo_.Path; if (ssh_->runCommand(cmd, &response) != 0) { - throw Error(1, "SSH: Unable to copy the rest"); + throw Error(kerErrorMessage, "SSH: Unable to copy the rest"); } // remove filepath.exiv2datatemp cmd = "rm " + hostInfo_.Path + ".exiv2datatemp"; if (ssh_->runCommand(cmd, &response) != 0) { - throw Error(1, "SSH: Unable to copy the rest"); + throw Error(kerErrorMessage, "SSH: Unable to copy the rest"); } } @@ -2561,16 +2561,16 @@ namespace Exiv2 { { FileIo file(path); if (file.open("rb") != 0) { - throw Error(10, path, "rb", strError()); + throw Error(kerFileOpenFailed, path, "rb", strError()); } struct stat st; if (0 != ::stat(path.c_str(), &st)) { - throw Error(2, path, strError(), "::stat"); + throw Error(kerCallFailed, path, strError(), "::stat"); } DataBuf buf(st.st_size); long len = file.read(buf.pData_, buf.size_); if (len != buf.size_) { - throw Error(2, path, strError(), "FileIo::read"); + throw Error(kerCallFailed, path, strError(), "FileIo::read"); } return buf; } @@ -2580,16 +2580,16 @@ namespace Exiv2 { { FileIo file(wpath); if (file.open("rb") != 0) { - throw WError(10, wpath, "rb", strError().c_str()); + throw WError(kerFileOpenFailed, wpath, "rb", strError().c_str()); } struct _stat st; if (0 != ::_wstat(wpath.c_str(), &st)) { - throw WError(2, wpath, strError().c_str(), "::_wstat"); + throw WError(kerCallFailed, wpath, strError().c_str(), "::_wstat"); } DataBuf buf(st.st_size); long len = file.read(buf.pData_, buf.size_); if (len != buf.size_) { - throw WError(2, wpath, strError().c_str(), "FileIo::read"); + throw WError(kerCallFailed, wpath, strError().c_str(), "FileIo::read"); } return buf; } @@ -2599,7 +2599,7 @@ namespace Exiv2 { { FileIo file(path); if (file.open("wb") != 0) { - throw Error(10, path, "wb", strError()); + throw Error(kerFileOpenFailed, path, "wb", strError()); } return file.write(buf.pData_, buf.size_); } @@ -2609,7 +2609,7 @@ namespace Exiv2 { { FileIo file(wpath); if (file.open("wb") != 0) { - throw WError(10, wpath, "wb", strError().c_str()); + throw WError(kerFileOpenFailed, wpath, "wb", strError().c_str()); } return file.write(buf.pData_, buf.size_); } diff --git a/src/bigtiffimage.cpp b/src/bigtiffimage.cpp index 78b8166a..0832ded9 100644 --- a/src/bigtiffimage.cpp +++ b/src/bigtiffimage.cpp @@ -104,7 +104,7 @@ namespace Exiv2 int read = io.read(buffer, 4); if (read < 4) - throw Exiv2::Error(58); + throw Exiv2::Error(kerCorruptedMetadata); const uint32_t offset = getULong(buffer, byteOrder); result = Header(byteOrder, magic, 4, offset); @@ -114,7 +114,7 @@ namespace Exiv2 byte buffer[8] = {0, 0, 0, 0, 0, 0, 0, 0}; int read = io.read(buffer, 2); if (read < 2) - throw Exiv2::Error(58); + throw Exiv2::Error(kerCorruptedMetadata); const int size = getUShort(buffer, byteOrder); @@ -122,21 +122,21 @@ namespace Exiv2 { read = io.read(buffer, 2); // null if (read < 2) - throw Exiv2::Error(58); + throw Exiv2::Error(kerCorruptedMetadata); read = io.read(buffer, 8); if (read < 8) - throw Exiv2::Error(58); + throw Exiv2::Error(kerCorruptedMetadata); const uint64_t offset = getULongLong(buffer, byteOrder); if (offset >= io.size()) - throw Exiv2::Error(58); + throw Exiv2::Error(kerCorruptedMetadata); result = Header(byteOrder, magic, size, offset); } else - throw Exiv2::Error(58); + throw Exiv2::Error(kerCorruptedMetadata); } return result; @@ -252,15 +252,15 @@ namespace Exiv2 // => // size > std::numeric_limits::max() / count if (size > std::numeric_limits::max() / count) - throw Error(57); // we got number bigger than 2^64 + throw Error(kerInvalidMalloc); // we got number bigger than 2^64 // more than we can handle if (size * count > std::numeric_limits::max() - pad) - throw Error(57); // again more than 2^64 + throw Error(kerInvalidMalloc); // again more than 2^64 const uint64_t allocate = size*count + pad; if ( allocate > io.size() ) { - throw Error(57); + throw Error(kerInvalidMalloc); } DataBuf buf(static_cast(allocate)); diff --git a/src/bmpimage.cpp b/src/bmpimage.cpp index 135bdb8d..efb804c9 100644 --- a/src/bmpimage.cpp +++ b/src/bmpimage.cpp @@ -54,19 +54,19 @@ namespace Exiv2 void BmpImage::setExifData(const ExifData& /*exifData*/) { // Todo: implement me! - throw(Error(32, "Exif metadata", "BMP")); + throw(Error(kerInvalidSettingForImage, "Exif metadata", "BMP")); } void BmpImage::setIptcData(const IptcData& /*iptcData*/) { // Todo: implement me! - throw(Error(32, "IPTC metadata", "BMP")); + throw(Error(kerInvalidSettingForImage, "IPTC metadata", "BMP")); } void BmpImage::setComment(const std::string& /*comment*/) { // not supported - throw(Error(32, "Image comment", "BMP")); + throw(Error(kerInvalidSettingForImage, "Image comment", "BMP")); } void BmpImage::readMetadata() @@ -75,13 +75,13 @@ namespace Exiv2 std::cerr << "Exiv2::BmpImage::readMetadata: Reading Windows bitmap file " << io_->path() << "\n"; #endif if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); // Ensure that this is the correct image type if (!isBmpType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "BMP"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "BMP"); } clearMetadata(); @@ -116,7 +116,7 @@ namespace Exiv2 void BmpImage::writeMetadata() { // Todo: implement me! - throw(Error(31, "BMP")); + throw(Error(kerWritingImageFormatUnsupported, "BMP")); } // ************************************************************************* diff --git a/src/cr2image.cpp b/src/cr2image.cpp index 98a6adf2..8323c23a 100644 --- a/src/cr2image.cpp +++ b/src/cr2image.cpp @@ -77,7 +77,7 @@ namespace Exiv2 { void Cr2Image::printStructure(std::ostream& out, Exiv2::PrintStructureOption option,int depth) { - if (io_->open() != 0) throw Error(9, io_->path(), strError()); + if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError()); io_->seek(0,BasicIo::beg); printTiffStructure(io(),out,option,depth-1); } @@ -85,7 +85,7 @@ namespace Exiv2 { void Cr2Image::setComment(const std::string& /*comment*/) { // not supported - throw(Error(32, "Image comment", "CR2")); + throw(Error(kerInvalidSettingForImage, "Image comment", "CR2")); } void Cr2Image::readMetadata() @@ -94,13 +94,13 @@ namespace Exiv2 { std::cerr << "Reading CR2 file " << io_->path() << "\n"; #endif if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); // Ensure that this is the correct image type if (!isCr2Type(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "CR2"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "CR2"); } clearMetadata(); std::ofstream devnull; diff --git a/src/crwedit.cpp b/src/crwedit.cpp index eac3b23d..e6fc423e 100644 --- a/src/crwedit.cpp +++ b/src/crwedit.cpp @@ -26,21 +26,21 @@ try { std::string filename(argv[1]); Exiv2::FileIo io(filename); if(io.open() != 0) { - throw Exiv2::Error(9, io.path(), Exiv2::strError()); + throw Exiv2::Error(Exiv2::kerDataSourceOpenFailed, io.path(), Exiv2::strError()); } Exiv2::IoCloser closer(io); // Ensure that this is a CRW image if (!Exiv2::isCrwType(io, false)) { - if (io.error() || io.eof()) throw Exiv2::Error(14); - throw Exiv2::Error(33); + if (io.error() || io.eof()) throw Exiv2::Error(Exiv2::kerFailedToReadImageData); + throw Exiv2::Error(Exiv2::kerNotACrwImage); } // Read the image into a memory buffer long len = (long)io.size(); Exiv2::DataBuf buf(len); io.read(buf.pData_, len); - if (io.error() || io.eof()) throw Exiv2::Error(14); + if (io.error() || io.eof()) throw Exiv2::Error(Exiv2::kerFailedToReadImageData); // Parse the image, starting with a CIFF header component Exiv2::Internal::CiffHeader::AutoPtr parseTree(new Exiv2::Internal::CiffHeader); @@ -76,11 +76,11 @@ void write(const std::string& filename, const Exiv2::Internal::CiffHeader* pHead Exiv2::FileIo io(filename); if(io.open("wb") != 0) { - throw Exiv2::Error(9, io.path(), Exiv2::strError()); + throw Exiv2::Error(Exiv2::kerDataSourceOpenFailed, io.path(), Exiv2::strError()); } Exiv2::IoCloser closer(io); long ret = io.write(&blob[0], (long) blob.size()); - if (static_cast(ret) != blob.size()) throw Exiv2::Error(21); + if (static_cast(ret) != blob.size()) throw Exiv2::Error(Exiv2::kerImageWriteFailed); io.close(); } diff --git a/src/crwimage.cpp b/src/crwimage.cpp index 82e83ef8..ce9ae16b 100644 --- a/src/crwimage.cpp +++ b/src/crwimage.cpp @@ -84,7 +84,7 @@ namespace Exiv2 { void CrwImage::setIptcData(const IptcData& /*iptcData*/) { // not supported - throw(Error(32, "IPTC metadata", "CRW")); + throw(Error(kerInvalidSettingForImage, "IPTC metadata", "CRW")); } void CrwImage::readMetadata() @@ -93,13 +93,13 @@ namespace Exiv2 { std::cerr << "Reading CRW file " << io_->path() << "\n"; #endif if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); // Ensure that this is the correct image type if (!isCrwType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(33); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotACrwImage); } clearMetadata(); // read all metadata into memory diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index e82c9ae0..fae860f1 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -185,7 +185,7 @@ namespace Exiv2 { void CiffEntry::doAdd(AutoPtr /*component*/) { - throw Error(34, "CiffEntry::add"); + throw Error(kerFunctionNotSupported, "CiffEntry::add"); } // CiffEntry::doAdd void CiffDirectory::doAdd(AutoPtr component) @@ -195,7 +195,7 @@ namespace Exiv2 { void CiffHeader::read(const byte* pData, uint32_t size) { - if (size < 14) throw Error(33); + if (size < 14) throw Error(kerNotACrwImage); if (pData[0] == 'I' && pData[0] == pData[1]) { byteOrder_ = littleEndian; @@ -204,12 +204,12 @@ namespace Exiv2 { byteOrder_ = bigEndian; } else { - throw Error(33); + throw Error(kerNotACrwImage); } offset_ = getULong(pData + 2, byteOrder_); - if (offset_ < 14 || offset_ > size) throw Error(33); + if (offset_ < 14 || offset_ > size) throw Error(kerNotACrwImage); if (std::memcmp(pData + 6, signature(), 8) != 0) { - throw Error(33); + throw Error(kerNotACrwImage); } delete pPadding_; @@ -234,7 +234,7 @@ namespace Exiv2 { uint32_t start, ByteOrder byteOrder) { - if (size < 10) throw Error(33); + if (size < 10) throw Error(kerNotACrwImage); tag_ = getUShort(pData + start, byteOrder); DataLocId dl = dataLocation(); @@ -244,7 +244,7 @@ namespace Exiv2 { size_ = getULong(pData + start + 2, byteOrder); offset_ = getULong(pData + start + 6, byteOrder); } - if ( size_ > size || offset_ > size ) throw Error(26); // #889 + if ( size_ > size || offset_ > size ) throw Error(kerOffsetOutOfRange); // #889 if (dl == directoryData) { size_ = 8; offset_ = start + 2; @@ -279,7 +279,7 @@ namespace Exiv2 { ByteOrder byteOrder) { uint32_t o = getULong(pData + size - 4, byteOrder); - if (size < 2 || o > size-2) throw Error(33); + if (size < 2 || o > size-2) throw Error(kerNotACrwImage); uint16_t count = getUShort(pData + o, byteOrder); #ifdef DEBUG std::cout << "Directory at offset " << std::dec << o @@ -287,7 +287,7 @@ namespace Exiv2 { #endif o += 2; for (uint16_t i = 0; i < count; ++i) { - if (o + 10 > size) throw Error(33); + if (o + 10 > size) throw Error(kerNotACrwImage); uint16_t tag = getUShort(pData + o, byteOrder); CiffComponent::AutoPtr m; switch (CiffComponent::typeId(tag)) { diff --git a/src/crwparse.cpp b/src/crwparse.cpp index 6b5a094c..c3fdbe7f 100644 --- a/src/crwparse.cpp +++ b/src/crwparse.cpp @@ -18,21 +18,21 @@ try { Exiv2::FileIo io(argv[1]); if(io.open() != 0) { - throw Exiv2::Error(9, io.path(), Exiv2::strError()); + throw Exiv2::Error(kerDataSourceOpenFailed, io.path(), Exiv2::strError()); } Exiv2::IoCloser closer(io); // Ensure that this is a CRW image if (!Exiv2::isCrwType(io, false)) { - if (io.error() || io.eof()) throw Exiv2::Error(14); - throw Exiv2::Error(33); + if (io.error() || io.eof()) throw Exiv2::Error(kerFailedToReadImageData); + throw Exiv2::Error(kerNotACrwImage); } // Read the image into a memory buffer long len = io.size(); Exiv2::DataBuf buf(len); io.read(buf.pData_, len); - if (io.error() || io.eof()) throw Exiv2::Error(14); + if (io.error() || io.eof()) throw Exiv2::Error(kerFailedToReadImageData); // Parse the image, starting with a CIFF header component Exiv2::Internal::CiffHeader::AutoPtr parseTree(new Exiv2::Internal::CiffHeader); diff --git a/src/datasets.cpp b/src/datasets.cpp index a74060fd..269f301b 100644 --- a/src/datasets.cpp +++ b/src/datasets.cpp @@ -532,7 +532,7 @@ namespace Exiv2 { dataSet = records_[recordId][idx].number_; } else { - if (!isHex(dataSetName, 4, "0x")) throw Error(4, dataSetName); + if (!isHex(dataSetName, 4, "0x")) throw Error(kerInvalidDataset, dataSetName); std::istringstream is(dataSetName); is >> std::hex >> dataSet; } @@ -566,7 +566,7 @@ namespace Exiv2 { if (recordInfo_[i].name_ == recordName) break; } if (i == 0) { - if (!isHex(recordName, 4, "0x")) throw Error(5, recordName); + if (!isHex(recordName, 4, "0x")) throw Error(kerInvalidRecord, recordName); std::istringstream is(recordName); is >> std::hex >> i; } @@ -671,18 +671,18 @@ namespace Exiv2 { { // Get the family name, record name and dataSet name parts of the key std::string::size_type pos1 = key_.find('.'); - if (pos1 == std::string::npos) throw Error(6, key_); + if (pos1 == std::string::npos) throw Error(kerInvalidKey, key_); std::string familyName = key_.substr(0, pos1); if (0 != strcmp(familyName.c_str(), familyName_)) { - throw Error(6, key_); + throw Error(kerInvalidKey, key_); } std::string::size_type pos0 = pos1 + 1; pos1 = key_.find('.', pos0); - if (pos1 == std::string::npos) throw Error(6, key_); + if (pos1 == std::string::npos) throw Error(kerInvalidKey, key_); std::string recordName = key_.substr(pos0, pos1 - pos0); - if (recordName == "") throw Error(6, key_); + if (recordName == "") throw Error(kerInvalidKey, key_); std::string dataSetName = key_.substr(pos1 + 1); - if (dataSetName == "") throw Error(6, key_); + if (dataSetName == "") throw Error(kerInvalidKey, key_); // Use the parts of the key to find dataSet and recordId uint16_t recId = IptcDataSets::recordId(recordName); diff --git a/src/epsimage.cpp b/src/epsimage.cpp index 0f4ce56d..30f6dd30 100644 --- a/src/epsimage.cpp +++ b/src/epsimage.cpp @@ -110,7 +110,7 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Failed to write to temporary file.\n"; #endif - throw Error(21); + throw Error(kerImageWriteFailed); } } @@ -128,7 +128,7 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Internal error while determining current write position in temporary file.\n"; #endif - throw Error(21); + throw Error(kerImageWriteFailed); } return static_cast(pos); } @@ -223,7 +223,7 @@ namespace { EXV_WARNING << "Unable to handle read-only XMP metadata yet. Please provide your " "sample EPS file to the Exiv2 project: http://dev.exiv2.org/projects/exiv2\n"; #endif - throw Error(write ? 21 : 14); + throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData); } // search for end of XMP trailer @@ -236,13 +236,13 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Found XMP header but incomplete XMP trailer.\n"; #endif - throw Error(write ? 21 : 14); + throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData); } } #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Found XMP header but no XMP trailer.\n"; #endif - throw Error(write ? 21 : 14); + throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData); } } } @@ -252,7 +252,7 @@ namespace { { // open input file if (io.open() != 0) { - throw Error(9, io.path(), strError()); + throw Error(kerDataSourceOpenFailed, io.path(), strError()); } IoCloser closer(io); @@ -278,7 +278,7 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Premature end of file after DOS EPS signature.\n"; #endif - throw Error(write ? 21 : 14); + throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData); } posEps = getULong(data + 4, littleEndian); posEndEps = getULong(data + 8, littleEndian) + posEps; @@ -301,31 +301,31 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "DOS EPS file has both WMF and TIFF section. Only one of those is allowed.\n"; #endif - if (write) throw Error(21); + if (write) throw Error(kerImageWriteFailed); } if (sizeWmf == 0 && sizeTiff == 0) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "DOS EPS file has neither WMF nor TIFF section. Exactly one of those is required.\n"; #endif - if (write) throw Error(21); + if (write) throw Error(kerImageWriteFailed); } if (posEps < 30 || posEndEps > size) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "DOS EPS file has invalid position (" << posEps << ") or size (" << (posEndEps - posEps) << ") for EPS section.\n"; #endif - throw Error(write ? 21 : 14); + throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData); } if (sizeWmf != 0 && (posWmf < 30 || posWmf + sizeWmf > size)) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "DOS EPS file has invalid position (" << posWmf << ") or size (" << sizeWmf << ") for WMF section.\n"; #endif - if (write) throw Error(21); + if (write) throw Error(kerImageWriteFailed); } if (sizeTiff != 0 && (posTiff < 30 || posTiff + sizeTiff > size)) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "DOS EPS file has invalid position (" << posTiff << ") or size (" << sizeTiff << ") for TIFF section.\n"; #endif - if (write) throw Error(21); + if (write) throw Error(kerImageWriteFailed); } } @@ -340,7 +340,7 @@ namespace { matched = (firstLine == epsFirstLine[i]); } if (!matched) { - throw Error(3, "EPS"); + throw Error(kerNotAnImage, "EPS"); } // determine line ending style of the first line @@ -348,7 +348,7 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Premature end of file after first line.\n"; #endif - throw Error(write ? 21 : 14); + throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData); } const std::string lineEnding(reinterpret_cast(data + posEps + firstLine.size()), posSecondLine - (posEps + firstLine.size())); #ifdef DEBUG @@ -403,13 +403,13 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Nested document at invalid position: " << startPos << "\n"; #endif - throw Error(write ? 21 : 14); + throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData); } else if (startsWith(line, "%%BeginDocument:")) { if (depth == maxDepth) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Document too deeply nested at position: " << startPos << "\n"; #endif - throw Error(write ? 21 : 14); + throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData); } depth++; } else if (startsWith(line, "%%EndDocument")) { @@ -417,7 +417,7 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Unmatched EndDocument at position: " << startPos << "\n"; #endif - throw Error(write ? 21 : 14); + throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData); } depth--; } else { @@ -448,12 +448,12 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Page at position " << startPos << " conflicts with implicit page at position: " << posPage << "\n"; #endif - throw Error(write ? 21 : 14); + throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData); } #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Unable to handle multiple PostScript pages. Found second page at position: " << startPos << "\n"; #endif - throw Error(write ? 21 : 14); + throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData); } else if (line == "%%BeginPageSetup") { posBeginPageSetup = startPos; } else if (!inRemovableEmbedding && line == "%Exiv2BeginXMP: Before %%EndPageSetup") { @@ -602,7 +602,7 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Unmatched BeginDocument (" << depth << "x)\n"; #endif - throw Error(write ? 21 : 14); + throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData); } // look for the unmarked trailers of some removable XMP embeddings @@ -622,7 +622,7 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Unable to find XMP embedding trailer ending at position: " << posXmpTrailerEnd << "\n"; #endif - if (write) throw Error(21); + if (write) throw Error(kerImageWriteFailed); break; } removableEmbeddings.push_back(std::make_pair(posXmpTrailer, posXmpTrailerEnd)); @@ -646,7 +646,7 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Invalid line \"" << line << "\" at position: " << posContainsXmp << "\n"; #endif - throw Error(write ? 21 : 14); + throw Error(write ? kerImageWriteFailed : kerFailedToReadImageData); } const bool deleteXmp = (write && xmpPacket.size() == 0); @@ -693,7 +693,7 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Missing %begin_xml_packet in Photoshop EPS at position: " << xmpPos << "\n"; #endif - if (write) throw Error(21); + if (write) throw Error(kerImageWriteFailed); } } if (!useFlexibleEmbedding) { @@ -714,7 +714,7 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "XMP metadata block is not removable at position: " << posOtherXmp << "\n"; #endif - if (write) throw Error(21); + if (write) throw Error(kerImageWriteFailed); break; } } @@ -801,7 +801,7 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Unable to write to EPS files created by Adobe Illustrator 8.0 or older.\n"; #endif - throw Error(21); + throw Error(kerImageWriteFailed); } // create temporary output file @@ -811,7 +811,7 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Unable to create temporary file for writing.\n"; #endif - throw Error(21); + throw Error(kerImageWriteFailed); } #ifdef DEBUG EXV_DEBUG << "readWriteEpsMetadata: Created temporary file " << tempIo->path() << "\n"; @@ -859,7 +859,7 @@ namespace { EXV_WARNING << "Internal error while assembling the result EPS document: " "Unable to continue at position " << pos << " after skipping to position " << prevSkipPos << "\n"; #endif - throw Error(21); + throw Error(kerImageWriteFailed); } writeTemp(*tempIo, data + prevSkipPos, pos - prevSkipPos); const size_t posLineEnd = readLine(line, data, pos, posEndEps); @@ -1048,7 +1048,7 @@ namespace { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Internal error while seeking in temporary file.\n"; #endif - throw Error(21); + throw Error(kerImageWriteFailed); } byte dosEpsHeader[30]; dosEpsSignature.copy(reinterpret_cast(dosEpsHeader), dosEpsSignature.size()); @@ -1089,7 +1089,7 @@ namespace Exiv2 #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Failed to write blank EPS image.\n"; #endif - throw Error(21); + throw Error(kerImageWriteFailed); } } } @@ -1102,7 +1102,7 @@ namespace Exiv2 void EpsImage::setComment(const std::string& /*comment*/) { - throw Error(32, "Image comment", "EPS"); + throw Error(kerInvalidSettingForImage, "Image comment", "EPS"); } void EpsImage::readMetadata() @@ -1119,7 +1119,7 @@ namespace Exiv2 #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Failed to decode XMP metadata.\n"; #endif - throw Error(14); + throw Error(kerFailedToReadImageData); } #ifdef DEBUG @@ -1138,7 +1138,7 @@ namespace Exiv2 #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Failed to encode XMP metadata.\n"; #endif - throw Error(21); + throw Error(kerImageWriteFailed); } // write metadata diff --git a/src/exif.cpp b/src/exif.cpp index 01d8ad69..27f01154 100644 --- a/src/exif.cpp +++ b/src/exif.cpp @@ -228,7 +228,7 @@ namespace Exiv2 { const Value& Exifdatum::value() const { - if (value_.get() == 0) throw Error(8); + if (value_.get() == 0) throw Error(kerValueNotSet); return *value_; } diff --git a/src/exiv2.cpp b/src/exiv2.cpp index 0ec2489d..5ff2879b 100644 --- a/src/exiv2.cpp +++ b/src/exiv2.cpp @@ -1296,14 +1296,14 @@ namespace { #if defined(_MSC_VER) || defined(__MINGW__) for ( int i = 1 ; i < __argc ; i++ ) { cmdLine += std::string(" ") + formatArg(__argv[i]) ; } #endif - throw Exiv2::Error(1, Exiv2::toString(num) + throw Exiv2::Error(Exiv2::kerErrorMessage, Exiv2::toString(num) + ": " + _("Invalid command line:") + cmdLine); } std::string cmd(line.substr(cmdStart, cmdEnd-cmdStart)); CmdId cmdId = commandId(cmd); if (cmdId == invalidCmdId) { - throw Exiv2::Error(1, Exiv2::toString(num) + throw Exiv2::Error(Exiv2::kerErrorMessage, Exiv2::toString(num) + ": " + _("Invalid command") + " `" + cmd + "'"); } @@ -1335,7 +1335,7 @@ namespace { catch (const Exiv2::AnyError&) {} } if (metadataId == invalidMetadataId) { - throw Exiv2::Error(1, Exiv2::toString(num) + throw Exiv2::Error(Exiv2::kerErrorMessage, Exiv2::toString(num) + ": " + _("Invalid key") + " `" + key + "'"); } } @@ -1355,7 +1355,7 @@ namespace { if ( cmdId == reg && ( keyEnd == std::string::npos || valStart == std::string::npos)) { - throw Exiv2::Error(1, Exiv2::toString(num) + throw Exiv2::Error(Exiv2::kerErrorMessage, Exiv2::toString(num) + ": " + _("Invalid command line") + " " ); } @@ -1367,7 +1367,7 @@ namespace { if (tmpType != Exiv2::invalidTypeId) { valStart = line.find_first_not_of(delim, typeEnd+1); if (valStart == std::string::npos) { - throw Exiv2::Error(1, Exiv2::toString(num) + throw Exiv2::Error(Exiv2::kerErrorMessage, Exiv2::toString(num) + ": " + _("Invalid command line") + " " ); } type = tmpType; diff --git a/src/gifimage.cpp b/src/gifimage.cpp index 37adcf2a..cf92c308 100644 --- a/src/gifimage.cpp +++ b/src/gifimage.cpp @@ -55,19 +55,19 @@ namespace Exiv2 { void GifImage::setExifData(const ExifData& /*exifData*/) { // Todo: implement me! - throw(Error(32, "Exif metadata", "GIF")); + throw(Error(kerInvalidSettingForImage, "Exif metadata", "GIF")); } void GifImage::setIptcData(const IptcData& /*iptcData*/) { // Todo: implement me! - throw(Error(32, "IPTC metadata", "GIF")); + throw(Error(kerInvalidSettingForImage, "IPTC metadata", "GIF")); } void GifImage::setComment(const std::string& /*comment*/) { // not supported - throw(Error(32, "Image comment", "GIF")); + throw(Error(kerInvalidSettingForImage, "Image comment", "GIF")); } void GifImage::readMetadata() @@ -77,14 +77,14 @@ namespace Exiv2 { #endif if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); // Ensure that this is the correct image type if (!isGifType(*io_, true)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "GIF"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "GIF"); } clearMetadata(); @@ -99,7 +99,7 @@ namespace Exiv2 { void GifImage::writeMetadata() { // Todo: implement me! - throw(Error(31, "GIF")); + throw(Error(kerWritingImageFormatUnsupported, "GIF")); } // GifImage::writeMetadata // ************************************************************************* diff --git a/src/image.cpp b/src/image.cpp index f3db54aa..bd6ef531 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -173,7 +173,7 @@ namespace Exiv2 { void Image::printStructure(std::ostream&, PrintStructureOption,int /*depth*/) { - throw Error(13, io_->path()); + throw Error(kerUnsupportedImageType, io_->path()); } bool Image::isStringType(uint16_t type) @@ -349,7 +349,7 @@ namespace Exiv2 { uint16_t dirLength = byteSwap2(dir,0,bSwap); bool tooBig = dirLength > 500; - if ( tooBig ) throw Error(55); + if ( tooBig ) throw Error(kerTiffDirectoryTooLarge); if ( bFirst && bPrint ) { out << Internal::indent(depth) << Internal::stringFormat("STRUCTURE OF TIFF FILE (%c%c): ",c,c) << io.path() << std::endl; @@ -375,7 +375,7 @@ namespace Exiv2 { if ( !typeValid(type) ) { std::cerr << "invalid type value detected in Image::printIFDStructure: " << type << std::endl; start = 0; // break from do loop - throw Error(56); + throw Error(kerInvalidTypeValue); break; // break from for loop } @@ -401,7 +401,7 @@ namespace Exiv2 { // #55 and #56 memory allocation crash test/data/POC8 long long allocate = (long long) size*count + pad+20; if ( allocate > (long long) io.size() ) { - throw Error(57); + throw Error(kerInvalidMalloc); } DataBuf buf((long)allocate); // allocate a buffer std::memcpy(buf.pData_,dir.pData_+8,4); // copy dir[8:11] into buffer (short strings) @@ -457,10 +457,10 @@ namespace Exiv2 { } } else if ( option == kpsRecursive && tag == 0x83bb /* IPTCNAA */ ) { if (offset > std::numeric_limits::max() - count) { - throw Error(59); + throw Error(kerArithmeticOverflow); } if (static_cast(offset + count) > io.size()) { - throw Error(58); + throw Error(kerCorruptedMetadata); } size_t restore = io.tell(); // save io.seek(offset,BasicIo::beg); // position @@ -614,7 +614,7 @@ namespace Exiv2 { { xmpPacket_ = xmpPacket; if ( XmpParser::decode(xmpData_, xmpPacket) ) { - throw Error(54); + throw Error(kerInvalidXMP); } xmpPacket_ = xmpPacket; } @@ -653,9 +653,9 @@ namespace Exiv2 { void Image::setIccProfile(Exiv2::DataBuf& iccProfile,bool bTestValid) { if ( bTestValid ) { - if ( iccProfile.pData_ && ( iccProfile.size_ < (long) sizeof(long)) ) throw Error(53); + if ( iccProfile.pData_ && ( iccProfile.size_ < (long) sizeof(long)) ) throw Error(kerInvalidIccProfile); long size = iccProfile.pData_ ? getULong(iccProfile.pData_, bigEndian): -1; - if ( size!= iccProfile.size_ ) throw Error(53); + if ( size!= iccProfile.size_ ) throw Error(kerInvalidIccProfile); } iccProfile_ = iccProfile; } @@ -764,7 +764,7 @@ namespace Exiv2 { AccessMode ImageFactory::checkMode(int type, MetadataId metadataId) { const Registry* r = find(registry, type); - if (!r) throw Error(13, type); + if (!r) throw Error(kerUnsupportedImageType, type); AccessMode am = amNone; switch (metadataId) { case mdNone: @@ -883,7 +883,7 @@ namespace Exiv2 { Image::AutoPtr ImageFactory::open(const std::string& path, bool useCurl) { Image::AutoPtr image = open(ImageFactory::createIo(path, useCurl)); // may throw - if (image.get() == 0) throw Error(11, path); + if (image.get() == 0) throw Error(kerFileContainsUnknownImageType, path); return image; } @@ -891,7 +891,7 @@ namespace Exiv2 { Image::AutoPtr ImageFactory::open(const std::wstring& wpath, bool useCurl) { Image::AutoPtr image = open(ImageFactory::createIo(wpath, useCurl)); // may throw - if (image.get() == 0) throw WError(11, wpath); + if (image.get() == 0) throw WError(kerFileContainsUnknownImageType, wpath); return image; } @@ -900,14 +900,14 @@ namespace Exiv2 { { BasicIo::AutoPtr io(new MemIo(data, size)); Image::AutoPtr image = open(io); // may throw - if (image.get() == 0) throw Error(12); + if (image.get() == 0) throw Error(kerMemoryContainsUnknownImageType); return image; } Image::AutoPtr ImageFactory::open(BasicIo::AutoPtr io) { if (io->open() != 0) { - throw Error(9, io->path(), strError()); + throw Error(kerDataSourceOpenFailed, io->path(), strError()); } for (unsigned int i = 0; registry[i].imageType_ != ImageType::none; ++i) { if (registry[i].isThisType_(*io, false)) { @@ -923,12 +923,12 @@ namespace Exiv2 { std::auto_ptr fileIo(new FileIo(path)); // Create or overwrite the file, then close it if (fileIo->open("w+b") != 0) { - throw Error(10, path, "w+b", strError()); + throw Error(kerFileOpenFailed, path, "w+b", strError()); } fileIo->close(); BasicIo::AutoPtr io(fileIo); Image::AutoPtr image = create(type, io); - if (image.get() == 0) throw Error(13, type); + if (image.get() == 0) throw Error(kerUnsupportedImageType, type); return image; } @@ -939,12 +939,12 @@ namespace Exiv2 { std::auto_ptr fileIo(new FileIo(wpath)); // Create or overwrite the file, then close it if (fileIo->open("w+b") != 0) { - throw WError(10, wpath, "w+b", strError().c_str()); + throw WError(kerFileOpenFailed, wpath, "w+b", strError().c_str()); } fileIo->close(); BasicIo::AutoPtr io(fileIo); Image::AutoPtr image = create(type, io); - if (image.get() == 0) throw Error(13, type); + if (image.get() == 0) throw Error(kerUnsupportedImageType, type); return image; } @@ -953,7 +953,7 @@ namespace Exiv2 { { BasicIo::AutoPtr io(new MemIo); Image::AutoPtr image = create(type, io); - if (image.get() == 0) throw Error(13, type); + if (image.get() == 0) throw Error(kerUnsupportedImageType, type); return image; } diff --git a/src/iptc.cpp b/src/iptc.cpp index f61c3ac2..ec7a58a9 100644 --- a/src/iptc.cpp +++ b/src/iptc.cpp @@ -210,7 +210,7 @@ namespace Exiv2 { const Value& Iptcdatum::value() const { - if (value_.get() == 0) throw Error(8); + if (value_.get() == 0) throw Error(kerValueNotSet); return *value_; } diff --git a/src/jp2image.cpp b/src/jp2image.cpp index 8dd6c9c1..1e85de4d 100644 --- a/src/jp2image.cpp +++ b/src/jp2image.cpp @@ -167,7 +167,7 @@ namespace Exiv2 void Jp2Image::setComment(const std::string& /*comment*/) { // Todo: implement me! - throw(Error(32, "Image comment", "JP2")); + throw(Error(kerInvalidSettingForImage, "Image comment", "JP2")); } // Jp2Image::setComment static void lf(std::ostream& out,bool& bLF) @@ -207,14 +207,14 @@ namespace Exiv2 #endif if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); // Ensure that this is the correct image type if (!isJp2Type(*io_, true)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "JPEG-2000"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "JPEG-2000"); } long position = 0; @@ -271,7 +271,7 @@ namespace Exiv2 const size_t data_length = Safe::add(subBox.length, static_cast(8)); // data_length makes no sense if it is larger than the rest of the file if (data_length > io_->size() - io_->tell()) { - throw Error(58); + throw Error(kerCorruptedMetadata); } DataBuf data(data_length); io_->read(data.pData_,data.size_); @@ -279,7 +279,7 @@ namespace Exiv2 // subtracting pad from data.size_ is safe: // size_ is at least 8 and pad = 3 if (iccLength > data.size_ - pad) { - throw Error(58); + throw Error(kerCorruptedMetadata); } DataBuf icc(iccLength); ::memcpy(icc.pData_,data.pData_+pad,icc.size_); @@ -338,8 +338,8 @@ namespace Exiv2 #endif rawData.alloc(box.length - (sizeof(box) + sizeof(uuid))); bufRead = io_->read(rawData.pData_, rawData.size_); - if (io_->error()) throw Error(14); - if (bufRead != rawData.size_) throw Error(20); + if (io_->error()) throw Error(kerFailedToReadImageData); + if (bufRead != rawData.size_) throw Error(kerInputDataReadFailed); if (rawData.size_ > 0) { @@ -392,8 +392,8 @@ namespace Exiv2 #endif rawData.alloc(box.length - (sizeof(box) + sizeof(uuid))); bufRead = io_->read(rawData.pData_, rawData.size_); - if (io_->error()) throw Error(14); - if (bufRead != rawData.size_) throw Error(20); + if (io_->error()) throw Error(kerFailedToReadImageData); + if (bufRead != rawData.size_) throw Error(kerInputDataReadFailed); if (IptcParser::decode(iptcData_, rawData.pData_, rawData.size_)) { @@ -411,8 +411,8 @@ namespace Exiv2 #endif rawData.alloc(box.length - (uint32_t)(sizeof(box) + sizeof(uuid))); bufRead = io_->read(rawData.pData_, rawData.size_); - if (io_->error()) throw Error(14); - if (bufRead != rawData.size_) throw Error(20); + if (io_->error()) throw Error(kerFailedToReadImageData); + if (bufRead != rawData.size_) throw Error(kerInputDataReadFailed); xmpPacket_.assign(reinterpret_cast(rawData.pData_), rawData.size_); std::string::size_type idx = xmpPacket_.find_first_of('<'); @@ -444,19 +444,19 @@ namespace Exiv2 // Move to the next box. io_->seek(static_cast(position - sizeof(box) + box.length), BasicIo::beg); - if (io_->error()) throw Error(14); + if (io_->error()) throw Error(kerFailedToReadImageData); } } // Jp2Image::readMetadata void Jp2Image::printStructure(std::ostream& out, PrintStructureOption option,int depth) { - if (io_->open() != 0) throw Error(9, io_->path(), strError()); + if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError()); // Ensure that this is the correct image type if (!isJp2Type(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(15); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAJpeg); } bool bPrint = option == kpsBasic || option==kpsRecursive; @@ -552,8 +552,8 @@ namespace Exiv2 DataBuf rawData; rawData.alloc(box.length-sizeof(uuid)-sizeof(box)); long bufRead = io_->read(rawData.pData_, rawData.size_); - if (io_->error()) throw Error(14); - if (bufRead != rawData.size_) throw Error(20); + if (io_->error()) throw Error(kerFailedToReadImageData); + if (bufRead != rawData.size_) throw Error(kerInputDataReadFailed); if ( bPrint ){ out << Internal::binaryToString(rawData,40,0); @@ -588,7 +588,7 @@ namespace Exiv2 // Move to the next box. io_->seek(static_cast(position - sizeof(box) + box.length), BasicIo::beg); - if (io_->error()) throw Error(14); + if (io_->error()) throw Error(kerFailedToReadImageData); if ( bPrint ) lf(out,bLF); } } @@ -598,7 +598,7 @@ namespace Exiv2 { if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); BasicIo::AutoPtr tempIo(new MemIo); @@ -691,8 +691,8 @@ namespace Exiv2 void Jp2Image::doWriteMetadata(BasicIo& outIo) { - if (!io_->isopen()) throw Error(20); - if (!outIo.isopen()) throw Error(21); + if (!io_->isopen()) throw Error(kerInputDataReadFailed); + if (!outIo.isopen()) throw Error(kerImageWriteFailed); #ifdef DEBUG std::cout << "Exiv2::Jp2Image::doWriteMetadata: Writing JPEG-2000 file " << io_->path() << std::endl; @@ -702,12 +702,12 @@ namespace Exiv2 // Ensure that this is the correct image type if (!isJp2Type(*io_, true)) { - if (io_->error() || io_->eof()) throw Error(20); - throw Error(22); + if (io_->error() || io_->eof()) throw Error(kerInputDataReadFailed); + throw Error(kerNoImageInInputData); } // Write JPEG2000 Signature. - if (outIo.write(Jp2Signature, 12) != 12) throw Error(21); + if (outIo.write(Jp2Signature, 12) != 12) throw Error(kerImageWriteFailed); Jp2BoxHeader box = {0,0}; @@ -728,8 +728,8 @@ namespace Exiv2 std::memset(bheaderBuf.pData_, 0x00, bheaderBuf.size_); long bufRead = io_->read(bheaderBuf.pData_, bheaderBuf.size_); - if (io_->error()) throw Error(14); - if (bufRead != bheaderBuf.size_) throw Error(20); + if (io_->error()) throw Error(kerFailedToReadImageData); + if (bufRead != bheaderBuf.size_) throw Error(kerInputDataReadFailed); // Decode box header. @@ -765,7 +765,7 @@ namespace Exiv2 std::cout << "Exiv2::Jp2Image::doWriteMetadata: Error reading source file" << std::endl; #endif - throw Error(14); + throw Error(kerFailedToReadImageData); } if (bufRead != (long)(box.length - 8)) @@ -773,7 +773,7 @@ namespace Exiv2 #ifdef DEBUG std::cout << "Exiv2::Jp2Image::doWriteMetadata: Cannot read source file data" << std::endl; #endif - throw Error(20); + throw Error(kerInputDataReadFailed); } switch(box.type) @@ -785,7 +785,7 @@ namespace Exiv2 #ifdef DEBUG std::cout << "Exiv2::Jp2Image::doWriteMetadata: Write JP2Header box (length: " << box.length << ")" << std::endl; #endif - if (outIo.write(newBuf.pData_, newBuf.size_) != newBuf.size_) throw Error(21); + if (outIo.write(newBuf.pData_, newBuf.size_) != newBuf.size_) throw Error(kerImageWriteFailed); // Write all updated metadata here, just after JP2Header. @@ -812,7 +812,7 @@ namespace Exiv2 std::cout << "Exiv2::Jp2Image::doWriteMetadata: Write box with Exif metadata (length: " << boxData.size_ << std::endl; #endif - if (outIo.write(boxData.pData_, boxData.size_) != boxData.size_) throw Error(21); + if (outIo.write(boxData.pData_, boxData.size_) != boxData.size_) throw Error(kerImageWriteFailed); } } @@ -835,7 +835,7 @@ namespace Exiv2 std::cout << "Exiv2::Jp2Image::doWriteMetadata: Write box with Iptc metadata (length: " << boxData.size_ << std::endl; #endif - if (outIo.write(boxData.pData_, boxData.size_) != boxData.size_) throw Error(21); + if (outIo.write(boxData.pData_, boxData.size_) != boxData.size_) throw Error(kerImageWriteFailed); } } @@ -865,7 +865,7 @@ namespace Exiv2 std::cout << "Exiv2::Jp2Image::doWriteMetadata: Write box with XMP metadata (length: " << boxData.size_ << ")" << std::endl; #endif - if (outIo.write(boxData.pData_, boxData.size_) != boxData.size_) throw Error(21); + if (outIo.write(boxData.pData_, boxData.size_) != boxData.size_) throw Error(kerImageWriteFailed); } break; @@ -896,7 +896,7 @@ namespace Exiv2 #ifdef DEBUG std::cout << "Exiv2::Jp2Image::doWriteMetadata: write Uuid box (length: " << box.length << ")" << std::endl; #endif - if (outIo.write(boxBuf.pData_, boxBuf.size_) != boxBuf.size_) throw Error(21); + if (outIo.write(boxBuf.pData_, boxBuf.size_) != boxBuf.size_) throw Error(kerImageWriteFailed); } break; } @@ -906,7 +906,7 @@ namespace Exiv2 #ifdef DEBUG std::cout << "Exiv2::Jp2Image::doWriteMetadata: write box (length: " << box.length << ")" << std::endl; #endif - if (outIo.write(boxBuf.pData_, boxBuf.size_) != boxBuf.size_) throw Error(21); + if (outIo.write(boxBuf.pData_, boxBuf.size_) != boxBuf.size_) throw Error(kerImageWriteFailed); break; } diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index c613f7a4..7b343a5c 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -338,12 +338,12 @@ namespace Exiv2 { { int rc = 0; // Todo: this should be the return value - if (io_->open() != 0) throw Error(9, io_->path(), strError()); + if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError()); IoCloser closer(*io_); // Ensure that this is the correct image type if (!isThisType(*io_, true)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(15); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAJpeg); } clearMetadata(); int search = 6 ; // Exif, ICC, XMP, Comment, IPTC, SOF @@ -358,14 +358,14 @@ namespace Exiv2 { // Read section marker int marker = advanceToMarker(); - if (marker < 0) throw Error(15); + if (marker < 0) throw Error(kerNotAJpeg); while (marker != sos_ && marker != eoi_ && search > 0) { // Read size and signature (ok if this hits EOF) std::memset(buf.pData_, 0x0, buf.size_); bufRead = io_->read(buf.pData_, bufMinSize); - if (io_->error()) throw Error(14); - if (bufRead < 2) throw Error(15); + if (io_->error()) throw Error(kerFailedToReadImageData); + if (bufRead < 2) throw Error(kerNotAJpeg); uint16_t size = getUShort(buf.pData_, bigEndian); if ( !foundExifData @@ -378,7 +378,7 @@ namespace Exiv2 { io_->seek(8 - bufRead, BasicIo::cur); DataBuf rawExif(size - 8); io_->read(rawExif.pData_, rawExif.size_); - if (io_->error() || io_->eof()) throw Error(14); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); ByteOrder bo = ExifParser::decode(exifData_, rawExif.pData_, rawExif.size_); setByteOrder(bo); if (rawExif.size_ > 0 && byteOrder() == invalidByteOrder) { @@ -400,7 +400,7 @@ namespace Exiv2 { io_->seek(31 - bufRead, BasicIo::cur); DataBuf xmpPacket(size - 31); io_->read(xmpPacket.pData_, xmpPacket.size_); - if (io_->error() || io_->eof()) throw Error(14); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); xmpPacket_.assign(reinterpret_cast(xmpPacket.pData_), xmpPacket.size_); if (xmpPacket_.size() > 0 && XmpParser::decode(xmpData_, xmpPacket_)) { #ifndef SUPPRESS_WARNINGS @@ -420,7 +420,7 @@ namespace Exiv2 { io_->seek(16 - bufRead, BasicIo::cur); DataBuf psData(size - 16); io_->read(psData.pData_, psData.size_); - if (io_->error() || io_->eof()) throw Error(14); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); #ifdef DEBUG std::cerr << "Found app13 segment, size = " << size << "\n"; //hexdump(std::cerr, psData.pData_, psData.size_); @@ -445,7 +445,7 @@ namespace Exiv2 { io_->seek(2 - bufRead, BasicIo::cur); DataBuf comment(size - 2); io_->read(comment.pData_, comment.size_); - if (io_->error() || io_->eof()) throw Error(14); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); comment_.assign(reinterpret_cast(comment.pData_), comment.size_); while ( comment_.length() && comment_.at(comment_.length()-1) == '\0') { @@ -477,7 +477,7 @@ namespace Exiv2 { // read in profile // #1286 profile can be padded DataBuf icc((chunk==1&&chunks==1)?s:size-2-14); - if ( icc.size_ > size-2-14) throw Error(53); + if ( icc.size_ > size-2-14) throw Error(kerInvalidIccProfile); io_->read( icc.pData_,icc.size_); if ( !iccProfileDefined() ) { // first block of profile @@ -509,7 +509,7 @@ namespace Exiv2 { break; } // Skip the remainder of the unknown segment - if (io_->seek(size - bufRead, BasicIo::cur)) throw Error(14); + if (io_->seek(size - bufRead, BasicIo::cur)) throw Error(kerFailedToReadImageData); } // Read the beginning of the next segment marker = advanceToMarker(); @@ -562,11 +562,11 @@ namespace Exiv2 { void JpegBase::printStructure(std::ostream& out, PrintStructureOption option,int depth) { - if (io_->open() != 0) throw Error(9, io_->path(), strError()); + if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError()); // Ensure that this is the correct image type if (!isThisType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(15); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAJpeg); } bool bPrint = option==kpsBasic || option==kpsRecursive; @@ -613,7 +613,7 @@ namespace Exiv2 { // Read section marker int marker = advanceToMarker(); - if (marker < 0) throw Error(15); + if (marker < 0) throw Error(kerNotAJpeg); bool done = false; bool first= true; @@ -630,8 +630,8 @@ namespace Exiv2 { // Read size and signature std::memset(buf.pData_, 0x0, buf.size_); bufRead = io_->read(buf.pData_, bufMinSize); - if (io_->error()) throw Error(14); - if (bufRead < 2) throw Error(15); + if (io_->error()) throw Error(kerFailedToReadImageData); + if (bufRead < 2) throw Error(kerNotAJpeg); uint16_t size = mHasLength[marker] ? getUShort(buf.pData_, bigEndian) : 0 ; if ( bPrint && mHasLength[marker] ) out << Internal::stringFormat(" | %7d ", size); @@ -777,7 +777,7 @@ namespace Exiv2 { } // Skip the segment if the size is known - if (io_->seek(size - bufRead, BasicIo::cur)) throw Error(14); + if (io_->seek(size - bufRead, BasicIo::cur)) throw Error(kerFailedToReadImageData); if ( bLF ) out << std::endl; @@ -852,7 +852,7 @@ namespace Exiv2 { void JpegBase::writeMetadata() { if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); BasicIo::AutoPtr tempIo(new MemIo); @@ -865,13 +865,13 @@ namespace Exiv2 { void JpegBase::doWriteMetadata(BasicIo& outIo) { - if (!io_->isopen()) throw Error(20); - if (!outIo.isopen()) throw Error(21); + if (!io_->isopen()) throw Error(kerInputDataReadFailed); + if (!outIo.isopen()) throw Error(kerImageWriteFailed); // Ensure that this is the correct image type if (!isThisType(*io_, true)) { - if (io_->error() || io_->eof()) throw Error(20); - throw Error(22); + if (io_->error() || io_->eof()) throw Error(kerInputDataReadFailed); + throw Error(kerNoImageInInputData); } const long bufMinSize = 36; @@ -894,11 +894,11 @@ namespace Exiv2 { xmpData().usePacket(writeXmpFromPacket()); // Write image header - if (writeHeader(outIo)) throw Error(21); + if (writeHeader(outIo)) throw Error(kerImageWriteFailed); // Read section marker int marker = advanceToMarker(); - if (marker < 0) throw Error(22); + if (marker < 0) throw Error(kerNoImageInInputData); // First find segments of interest. Normally app0 is first and we want // to insert after it. But if app0 comes after com, app1 and app13 then @@ -906,53 +906,53 @@ namespace Exiv2 { while (marker != sos_ && marker != eoi_ && search < 6) { // Read size and signature (ok if this hits EOF) bufRead = io_->read(buf.pData_, bufMinSize); - if (io_->error()) throw Error(20); + if (io_->error()) throw Error(kerInputDataReadFailed); uint16_t size = getUShort(buf.pData_, bigEndian); if (marker == app0_) { - if (size < 2) throw Error(22); + if (size < 2) throw Error(kerNoImageInInputData); insertPos = count + 1; - if (io_->seek(size-bufRead, BasicIo::cur)) throw Error(22); + if (io_->seek(size-bufRead, BasicIo::cur)) throw Error(kerNoImageInInputData); } else if ( skipApp1Exif == -1 && marker == app1_ && memcmp(buf.pData_ + 2, exifId_, 6) == 0) { - if (size < 8) throw Error(22); + if (size < 8) throw Error(kerNoImageInInputData); skipApp1Exif = count; ++search; // Seek to beginning and read the current Exif data io_->seek(8 - bufRead, BasicIo::cur); rawExif.alloc(size - 8); io_->read(rawExif.pData_, rawExif.size_); - if (io_->error() || io_->eof()) throw Error(22); + if (io_->error() || io_->eof()) throw Error(kerNoImageInInputData); } else if ( skipApp1Xmp == -1 && marker == app1_ && memcmp(buf.pData_ + 2, xmpId_, 29) == 0) { - if (size < 31) throw Error(22); + if (size < 31) throw Error(kerNoImageInInputData); skipApp1Xmp = count; ++search; - if (io_->seek(size-bufRead, BasicIo::cur)) throw Error(22); + if (io_->seek(size-bufRead, BasicIo::cur)) throw Error(kerNoImageInInputData); } else if ( marker == app2_ && memcmp(buf.pData_ + 2, iccId_, 11)== 0 ) { - if (size < 31) throw Error(22); + if (size < 31) throw Error(kerNoImageInInputData); skipApp2Icc.push_back(count); if ( !foundIccData ) { ++search; foundIccData = true ; } - if (io_->seek(size-bufRead, BasicIo::cur)) throw Error(22); + if (io_->seek(size-bufRead, BasicIo::cur)) throw Error(kerNoImageInInputData); } else if ( !foundCompletePsData && marker == app13_ && memcmp(buf.pData_ + 2, Photoshop::ps3Id_, 14) == 0) { #ifdef DEBUG std::cerr << "Found APP13 Photoshop PS3 segment\n"; #endif - if (size < 16) throw Error(22); + if (size < 16) throw Error(kerNoImageInInputData); skipApp13Ps3.push_back(count); io_->seek(16 - bufRead, BasicIo::cur); // Load PS data now to allow reinsertion at any point DataBuf psData(size - 16); io_->read(psData.pData_, size - 16); - if (io_->error() || io_->eof()) throw Error(20); + if (io_->error() || io_->eof()) throw Error(kerInputDataReadFailed); // Append to psBlob append(psBlob, psData.pData_, psData.size_); // Check whether psBlob is complete @@ -961,16 +961,16 @@ namespace Exiv2 { } } else if (marker == com_ && skipCom == -1) { - if (size < 2) throw Error(22); + if (size < 2) throw Error(kerNoImageInInputData); // Jpegs can have multiple comments, but for now only handle // the first one (most jpegs only have one anyway). skipCom = count; ++search; - if (io_->seek(size-bufRead, BasicIo::cur)) throw Error(22); + if (io_->seek(size-bufRead, BasicIo::cur)) throw Error(kerNoImageInInputData); } else { - if (size < 2) throw Error(22); - if (io_->seek(size-bufRead, BasicIo::cur)) throw Error(22); + if (size < 2) throw Error(kerNoImageInInputData); + if (io_->seek(size-bufRead, BasicIo::cur)) throw Error(kerNoImageInInputData); } // As in jpeg-6b/wrjpgcom.c: // We will insert the new comment marker just before SOFn. @@ -982,11 +982,11 @@ namespace Exiv2 { ++search; } marker = advanceToMarker(); - if (marker < 0) throw Error(22); + if (marker < 0) throw Error(kerNoImageInInputData); ++count; } - if (!foundCompletePsData && psBlob.size() > 0) throw Error(22); + if (!foundCompletePsData && psBlob.size() > 0) throw Error(kerNoImageInInputData); search += (int) skipApp13Ps3.size() + (int) skipApp2Icc.size(); if (comPos == 0) { @@ -1003,7 +1003,7 @@ namespace Exiv2 { io_->seek(seek, BasicIo::beg); count = 0; marker = advanceToMarker(); - if (marker < 0) throw Error(22); + if (marker < 0) throw Error(kerNoImageInInputData); // To simplify this a bit, new segments are inserts at either the start // or right after app0. This is standard in most jpegs, but has the @@ -1012,7 +1012,7 @@ namespace Exiv2 { while (marker != sos_ && search > 0) { // Read size and signature (ok if this hits EOF) bufRead = io_->read(buf.pData_, bufMinSize); - if (io_->error()) throw Error(20); + if (io_->error()) throw Error(kerInputDataReadFailed); // Careful, this can be a meaningless number for empty // images with only an eoi_ marker uint16_t size = getUShort(buf.pData_, bigEndian); @@ -1044,15 +1044,15 @@ namespace Exiv2 { tmpBuf[0] = 0xff; tmpBuf[1] = app1_; - if (exifSize + 8 > 0xffff) throw Error(37, "Exif"); + if (exifSize + 8 > 0xffff) throw Error(kerTooLargeJpegSegment, "Exif"); us2Data(tmpBuf + 2, static_cast(exifSize + 8), bigEndian); std::memcpy(tmpBuf + 4, exifId_, 6); - if (outIo.write(tmpBuf, 10) != 10) throw Error(21); + if (outIo.write(tmpBuf, 10) != 10) throw Error(kerImageWriteFailed); // Write new Exif data buffer if ( outIo.write(pExifData, exifSize) - != static_cast(exifSize)) throw Error(21); - if (outIo.error()) throw Error(21); + != static_cast(exifSize)) throw Error(kerImageWriteFailed); + if (outIo.error()) throw Error(kerImageWriteFailed); --search; } } @@ -1068,15 +1068,15 @@ namespace Exiv2 { tmpBuf[0] = 0xff; tmpBuf[1] = app1_; - if (xmpPacket_.size() + 31 > 0xffff) throw Error(37, "XMP"); + if (xmpPacket_.size() + 31 > 0xffff) throw Error(kerTooLargeJpegSegment, "XMP"); us2Data(tmpBuf + 2, static_cast(xmpPacket_.size() + 31), bigEndian); std::memcpy(tmpBuf + 4, xmpId_, 29); - if (outIo.write(tmpBuf, 33) != 33) throw Error(21); + if (outIo.write(tmpBuf, 33) != 33) throw Error(kerImageWriteFailed); // Write new XMP packet if ( outIo.write(reinterpret_cast(xmpPacket_.data()), static_cast(xmpPacket_.size())) - != static_cast(xmpPacket_.size())) throw Error(21); - if (outIo.error()) throw Error(21); + != static_cast(xmpPacket_.size())) throw Error(kerImageWriteFailed); + if (outIo.error()) throw Error(kerImageWriteFailed); --search; } @@ -1089,16 +1089,16 @@ namespace Exiv2 { int chunk_size = 256*256-40 ; // leave bytes for marker, header and padding int size = (int) iccProfile_.size_ ; int chunks = 1 + (size-1) / chunk_size ; - if (iccProfile_.size_ > 256*chunk_size) throw Error(37, "IccProfile"); + if (iccProfile_.size_ > 256*chunk_size) throw Error(kerTooLargeJpegSegment, "IccProfile"); for ( int chunk = 0 ; chunk < chunks ; chunk ++ ) { int bytes = size > chunk_size ? chunk_size : size ; // bytes to write size -= bytes ; // write JPEG marker (2 bytes) - if (outIo.write(tmpBuf, 2) != 2) throw Error(21); // JPEG Marker + if (outIo.write(tmpBuf, 2) != 2) throw Error(kerImageWriteFailed); // JPEG Marker // write length (2 bytes). length includes the 2 bytes for the length us2Data(tmpBuf + 2, 2+14+bytes, bigEndian); - if (outIo.write(tmpBuf+2, 2) != 2) throw Error(21); // JPEG Length + if (outIo.write(tmpBuf+2, 2) != 2) throw Error(kerImageWriteFailed); // JPEG Length // write the ICC_PROFILE header (14 bytes) char pad[2]; @@ -1107,8 +1107,8 @@ namespace Exiv2 { outIo.write((const byte *) iccId_,12); outIo.write((const byte *) pad, 2); if (outIo.write(iccProfile_.pData_+ (chunk*chunk_size), bytes) != bytes) - throw Error(21); - if (outIo.error()) throw Error(21); + throw Error(kerImageWriteFailed); + if (outIo.error()) throw Error(kerImageWriteFailed); } --search; } @@ -1141,12 +1141,12 @@ namespace Exiv2 { tmpBuf[1] = app13_; us2Data(tmpBuf + 2, static_cast(chunkSize + 16), bigEndian); std::memcpy(tmpBuf + 4, Photoshop::ps3Id_, 14); - if (outIo.write(tmpBuf, 18) != 18) throw Error(21); - if (outIo.error()) throw Error(21); + if (outIo.write(tmpBuf, 18) != 18) throw Error(kerImageWriteFailed); + if (outIo.error()) throw Error(kerImageWriteFailed); // Write next chunk of the Photoshop IRB data buffer - if (outIo.write(chunkStart, chunkSize) != chunkSize) throw Error(21); - if (outIo.error()) throw Error(21); + if (outIo.write(chunkStart, chunkSize) != chunkSize) throw Error(kerImageWriteFailed); + if (outIo.error()) throw Error(kerImageWriteFailed); chunkStart += chunkSize; } @@ -1160,14 +1160,14 @@ namespace Exiv2 { tmpBuf[0] = 0xff; tmpBuf[1] = com_; - if (comment_.length() + 3 > 0xffff) throw Error(37, "JPEG comment"); + if (comment_.length() + 3 > 0xffff) throw Error(kerTooLargeJpegSegment, "JPEG comment"); us2Data(tmpBuf + 2, static_cast(comment_.length() + 3), bigEndian); - if (outIo.write(tmpBuf, 4) != 4) throw Error(21); + if (outIo.write(tmpBuf, 4) != 4) throw Error(kerImageWriteFailed); if (outIo.write((byte*)comment_.data(), (long)comment_.length()) - != (long)comment_.length()) throw Error(21); - if (outIo.putb(0)==EOF) throw Error(21); - if (outIo.error()) throw Error(21); + != (long)comment_.length()) throw Error(kerImageWriteFailed); + if (outIo.putb(0)==EOF) throw Error(kerImageWriteFailed); + if (outIo.error()) throw Error(kerImageWriteFailed); --search; } --search; @@ -1184,18 +1184,18 @@ namespace Exiv2 { io_->seek(size-bufRead, BasicIo::cur); } else { - if (size < 2) throw Error(22); + if (size < 2) throw Error(kerNoImageInInputData); buf.alloc(size+2); io_->seek(-bufRead-2, BasicIo::cur); io_->read(buf.pData_, size+2); - if (io_->error() || io_->eof()) throw Error(20); - if (outIo.write(buf.pData_, size+2) != size+2) throw Error(21); - if (outIo.error()) throw Error(21); + if (io_->error() || io_->eof()) throw Error(kerInputDataReadFailed); + if (outIo.write(buf.pData_, size+2) != size+2) throw Error(kerImageWriteFailed); + if (outIo.error()) throw Error(kerImageWriteFailed); } // Next marker marker = advanceToMarker(); - if (marker < 0) throw Error(22); + if (marker < 0) throw Error(kerNoImageInInputData); ++count; } @@ -1208,9 +1208,9 @@ namespace Exiv2 { buf.alloc(4096); long readSize = 0; while ((readSize=io_->read(buf.pData_, buf.size_))) { - if (outIo.write(buf.pData_, readSize) != readSize) throw Error(21); + if (outIo.write(buf.pData_, readSize) != readSize) throw Error(kerImageWriteFailed); } - if (outIo.error()) throw Error(21); + if (outIo.error()) throw Error(kerImageWriteFailed); } // JpegBase::doWriteMetadata diff --git a/src/matroskavideo.cpp b/src/matroskavideo.cpp index 0edd491c..18c278b5 100644 --- a/src/matroskavideo.cpp +++ b/src/matroskavideo.cpp @@ -493,12 +493,12 @@ namespace Exiv2 { void MatroskaVideo::readMetadata() { - if (io_->open() != 0) throw Error(9, io_->path(), strError()); + if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError()); // Ensure that this is the correct image type if (!isMkvType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "Matroska"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "Matroska"); } IoCloser closer(*io_); diff --git a/src/mrwimage.cpp b/src/mrwimage.cpp index e0dec1f6..917e10b9 100644 --- a/src/mrwimage.cpp +++ b/src/mrwimage.cpp @@ -76,19 +76,19 @@ namespace Exiv2 { void MrwImage::setExifData(const ExifData& /*exifData*/) { // Todo: implement me! - throw(Error(32, "Exif metadata", "MRW")); + throw(Error(kerInvalidSettingForImage, "Exif metadata", "MRW")); } void MrwImage::setIptcData(const IptcData& /*iptcData*/) { // Todo: implement me! - throw(Error(32, "IPTC metadata", "MRW")); + throw(Error(kerInvalidSettingForImage, "IPTC metadata", "MRW")); } void MrwImage::setComment(const std::string& /*comment*/) { // not supported - throw(Error(32, "Image comment", "MRW")); + throw(Error(kerInvalidSettingForImage, "Image comment", "MRW")); } void MrwImage::readMetadata() @@ -97,13 +97,13 @@ namespace Exiv2 { std::cerr << "Reading MRW file " << io_->path() << "\n"; #endif if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); // Ensure that this is the correct image type if (!isMrwType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "MRW"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "MRW"); } clearMetadata(); @@ -115,26 +115,26 @@ namespace Exiv2 { uint32_t const end = getULong(tmp + 4, bigEndian); pos += len; - if (pos > end) throw Error(14); + if (pos > end) throw Error(kerFailedToReadImageData); io_->read(tmp, len); - if (io_->error() || io_->eof()) throw Error(14); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); while (memcmp(tmp + 1, "TTW", 3) != 0) { uint32_t const siz = getULong(tmp + 4, bigEndian); pos += siz; - if (pos > end) throw Error(14); + if (pos > end) throw Error(kerFailedToReadImageData); io_->seek(siz, BasicIo::cur); - if (io_->error() || io_->eof()) throw Error(14); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); pos += len; - if (pos > end) throw Error(14); + if (pos > end) throw Error(kerFailedToReadImageData); io_->read(tmp, len); - if (io_->error() || io_->eof()) throw Error(14); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); } DataBuf buf(getULong(tmp + 4, bigEndian)); io_->read(buf.pData_, buf.size_); - if (io_->error() || io_->eof()) throw Error(14); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); ByteOrder bo = TiffParser::decode(exifData_, iptcData_, @@ -147,7 +147,7 @@ namespace Exiv2 { void MrwImage::writeMetadata() { // Todo: implement me! - throw(Error(31, "MRW")); + throw(Error(kerWritingImageFormatUnsupported, "MRW")); } // MrwImage::writeMetadata // ************************************************************************* diff --git a/src/mrwthumb.cpp b/src/mrwthumb.cpp index bb5d8738..c990ba9b 100644 --- a/src/mrwthumb.cpp +++ b/src/mrwthumb.cpp @@ -22,7 +22,7 @@ try { if (exifData.empty()) { std::string error(argv[1]); error += ": No Exif data found in the file"; - throw Exiv2::Error(1, error); + throw Exiv2::Error(kerErrorMessage, error); } Exiv2::ExifKey key("Exif.Minolta.ThumbnailOffset"); diff --git a/src/orfimage.cpp b/src/orfimage.cpp index a2267830..bd17f959 100644 --- a/src/orfimage.cpp +++ b/src/orfimage.cpp @@ -82,17 +82,17 @@ namespace Exiv2 { void OrfImage::setComment(const std::string& /*comment*/) { // not supported - throw(Error(32, "Image comment", "ORF")); + throw(Error(kerInvalidSettingForImage, "Image comment", "ORF")); } void OrfImage::printStructure(std::ostream& out, PrintStructureOption option, int depth) { out << "ORF IMAGE" << std::endl; - if (io_->open() != 0) throw Error(9, io_->path(), strError()); + if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError()); // Ensure that this is the correct image type if ( imageType() == ImageType::none ) if (!isOrfType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(15); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAJpeg); } io_->seek(0,BasicIo::beg); @@ -106,13 +106,13 @@ namespace Exiv2 { std::cerr << "Reading ORF file " << io_->path() << "\n"; #endif if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); // Ensure that this is the correct image type if (!isOrfType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "ORF"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "ORF"); } clearMetadata(); std::ofstream devnull; diff --git a/src/pgfimage.cpp b/src/pgfimage.cpp index 3815475b..47125320 100644 --- a/src/pgfimage.cpp +++ b/src/pgfimage.cpp @@ -111,14 +111,14 @@ namespace Exiv2 { #endif if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); // Ensure that this is the correct image type if (!isPgfType(*io_, true)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "PGF"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "PGF"); } clearMetadata(); @@ -135,14 +135,14 @@ namespace Exiv2 { std::cout << "Exiv2::PgfImage::readMetadata: Found Image data (" << size << " bytes)\n"; #endif - if (size < 0) throw Error(20); + if (size < 0) throw Error(kerInputDataReadFailed); if (size == 0) return; DataBuf imgData(size); std::memset(imgData.pData_, 0x0, imgData.size_); long bufRead = io_->read(imgData.pData_, imgData.size_); - if (io_->error()) throw Error(14); - if (bufRead != imgData.size_) throw Error(20); + if (io_->error()) throw Error(kerFailedToReadImageData); + if (bufRead != imgData.size_) throw Error(kerInputDataReadFailed); Image::AutoPtr image = Exiv2::ImageFactory::open(imgData.pData_, imgData.size_); image->readMetadata(); @@ -156,7 +156,7 @@ namespace Exiv2 { { if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); BasicIo::AutoPtr tempIo(new MemIo); @@ -170,8 +170,8 @@ namespace Exiv2 { void PgfImage::doWriteMetadata(BasicIo& outIo) { - if (!io_->isopen()) throw Error(20); - if (!outIo.isopen()) throw Error(21); + if (!io_->isopen()) throw Error(kerInputDataReadFailed); + if (!outIo.isopen()) throw Error(kerImageWriteFailed); #ifdef DEBUG std::cout << "Exiv2::PgfImage::doWriteMetadata: Writing PGF file " << io_->path() << "\n"; @@ -181,8 +181,8 @@ namespace Exiv2 { // Ensure that this is the correct image type if (!isPgfType(*io_, true)) { - if (io_->error() || io_->eof()) throw Error(20); - throw Error(22); + if (io_->error() || io_->eof()) throw Error(kerInputDataReadFailed); + throw Error(kerNoImageInInputData); } // Ensure PGF version. @@ -209,17 +209,17 @@ namespace Exiv2 { //--------------------------------------------------------------- // Write PGF Signature. - if (outIo.write(pgfSignature, 3) != 3) throw Error(21); + if (outIo.write(pgfSignature, 3) != 3) throw Error(kerImageWriteFailed); // Write Magic number. - if (outIo.putb(mnb) == EOF) throw Error(21); + if (outIo.putb(mnb) == EOF) throw Error(kerImageWriteFailed); // Write new Header size. uint32_t newHeaderSize = header.size_ + imgSize; DataBuf buffer(4); memcpy (buffer.pData_, &newHeaderSize, 4); byteSwap_(buffer,0,bSwap_); - if (outIo.write(buffer.pData_, 4) != 4) throw Error(21); + if (outIo.write(buffer.pData_, 4) != 4) throw Error(kerImageWriteFailed); #ifdef DEBUG std::cout << "Exiv2::PgfImage: new PGF header size : " << newHeaderSize << " bytes\n"; @@ -231,10 +231,10 @@ namespace Exiv2 { #endif // Write Header data. - if (outIo.write(header.pData_, header.size_) != header.size_) throw Error(21); + if (outIo.write(header.pData_, header.size_) != header.size_) throw Error(kerImageWriteFailed); // Write new metadata byte array. - if (outIo.write(imgBuf.pData_, imgBuf.size_) != imgBuf.size_) throw Error(21); + if (outIo.write(imgBuf.pData_, imgBuf.size_) != imgBuf.size_) throw Error(kerImageWriteFailed); // Copy the rest of PGF image data. @@ -242,16 +242,16 @@ namespace Exiv2 { long readSize = 0; while ((readSize=io_->read(buf.pData_, buf.size_))) { - if (outIo.write(buf.pData_, readSize) != readSize) throw Error(21); + if (outIo.write(buf.pData_, readSize) != readSize) throw Error(kerImageWriteFailed); } - if (outIo.error()) throw Error(21); + if (outIo.error()) throw Error(kerImageWriteFailed); } // PgfImage::doWriteMetadata byte PgfImage::readPgfMagicNumber(BasicIo& iIo) { byte b = iIo.getb(); - if (iIo.error()) throw Error(14); + if (iIo.error()) throw Error(kerFailedToReadImageData); if (b < 0x36) // 0x36 = '6'. { @@ -268,11 +268,11 @@ namespace Exiv2 { { DataBuf buffer(4); long bufRead = iIo.read(buffer.pData_, buffer.size_); - if (iIo.error()) throw Error(14); - if (bufRead != buffer.size_) throw Error(20); + if (iIo.error()) throw Error(kerFailedToReadImageData); + if (bufRead != buffer.size_) throw Error(kerInputDataReadFailed); int headerSize = (int) byteSwap_(buffer,0,bSwap_); - if (headerSize <= 0 ) throw Error(22); + if (headerSize <= 0 ) throw Error(kerNoImageInInputData); #ifdef DEBUG std::cout << "Exiv2::PgfImage: PGF header size : " << headerSize << " bytes\n"; @@ -285,8 +285,8 @@ namespace Exiv2 { { DataBuf header(16); long bufRead = iIo.read(header.pData_, header.size_); - if (iIo.error()) throw Error(14); - if (bufRead != header.size_) throw Error(20); + if (iIo.error()) throw Error(kerFailedToReadImageData); + if (bufRead != header.size_) throw Error(kerInputDataReadFailed); DataBuf work(8); // don't disturb the binary data - doWriteMetadata reuses it memcpy (work.pData_,header.pData_,8); @@ -306,8 +306,8 @@ namespace Exiv2 { header.alloc(16 + 256*3); bufRead = iIo.read(&header.pData_[16], 256*3); - if (iIo.error()) throw Error(14); - if (bufRead != 256*3) throw Error(20); + if (iIo.error()) throw Error(kerFailedToReadImageData); + if (bufRead != 256*3) throw Error(kerInputDataReadFailed); } return header; diff --git a/src/pngchunk_int.cpp b/src/pngchunk_int.cpp index 19f5d9b7..7d8aab83 100644 --- a/src/pngchunk_int.cpp +++ b/src/pngchunk_int.cpp @@ -104,7 +104,7 @@ namespace Exiv2 { // From a tEXt, zTXt, or iTXt chunk, // we get the key, it's a null terminated string at the chunk start const int offset = stripHeader ? 8 : 0; - if (data.size_ <= offset) throw Error(14); + if (data.size_ <= offset) throw Error(kerFailedToReadImageData); const byte *key = data.pData_ + offset; // Find null string at end of key. @@ -114,7 +114,7 @@ namespace Exiv2 { keysize++; // look if keysize is valid. if (keysize+offset >= data.size_) - throw Error(14); + throw Error(kerFailedToReadImageData); } return DataBuf(key, keysize); @@ -139,7 +139,7 @@ namespace Exiv2 { #ifdef DEBUG std::cerr << "Exiv2::PngChunk::parseTXTChunk: Non-standard zTXt compression method.\n"; #endif - throw Error(14); + throw Error(kerFailedToReadImageData); } // compressed string after the compression technique spec @@ -206,7 +206,7 @@ namespace Exiv2 { #ifdef DEBUG std::cerr << "Exiv2::PngChunk::parseTXTChunk: Non-standard iTXt compression method.\n"; #endif - throw Error(14); + throw Error(kerFailedToReadImageData); } } else @@ -214,7 +214,7 @@ namespace Exiv2 { #ifdef DEBUG std::cerr << "Exiv2::PngChunk::parseTXTChunk: We found a field, not expected though\n"; #endif - throw Error(14); + throw Error(kerFailedToReadImageData); } return arr; @@ -459,13 +459,13 @@ namespace Exiv2 { } else { // something bad happened - throw Error(14); + throw Error(kerFailedToReadImageData); } } while (zlibResult == Z_BUF_ERROR); if (zlibResult != Z_OK) { - throw Error(14); + throw Error(kerFailedToReadImageData); } } // PngChunk::zlibUncompress @@ -493,11 +493,11 @@ namespace Exiv2 { #endif compressedLen *= 2; // DoS protection. Cap max compressed size - if ( compressedLen > 131072 ) throw Error(14); + if ( compressedLen > 131072 ) throw Error(kerFailedToReadImageData); break; default: // Something bad happened - throw Error(14); + throw Error(kerFailedToReadImageData); } } while (zlibResult == Z_BUF_ERROR); diff --git a/src/pngimage.cpp b/src/pngimage.cpp index 42d26a6d..ba7c68f2 100644 --- a/src/pngimage.cpp +++ b/src/pngimage.cpp @@ -194,12 +194,12 @@ namespace Exiv2 { void PngImage::printStructure(std::ostream& out, PrintStructureOption option, int depth) { if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } // Ensure that this is the correct image type if (!isPngType(*io_, true)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "PNG"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "PNG"); } char chType[5]; @@ -231,8 +231,8 @@ namespace Exiv2 { std::memset(cheaderBuf.pData_, 0x0, cheaderBuf.size_); long bufRead = io_->read(cheaderBuf.pData_, cheaderBuf.size_); - if (io_->error()) throw Error(14); - if (bufRead != cheaderBuf.size_) throw Error(20); + if (io_->error()) throw Error(kerFailedToReadImageData); + if (bufRead != cheaderBuf.size_) throw Error(kerInputDataReadFailed); // Decode chunk data length. uint32_t dataOffset = Exiv2::getULong(cheaderBuf.pData_, Exiv2::bigEndian); @@ -246,7 +246,7 @@ namespace Exiv2 { || dataOffset > uint32_t(0x7FFFFFFF) || static_cast(dataOffset) > imgSize - restore ){ - throw Exiv2::Error(14); + throw Exiv2::Error(kerFailedToReadImageData); } DataBuf buff(dataOffset); @@ -361,7 +361,7 @@ namespace Exiv2 { delete[] data; } io_->seek(dataOffset+4, BasicIo::cur);// jump past checksum - if (io_->error()) throw Error(14); + if (io_->error()) throw Error(kerFailedToReadImageData); } } } @@ -373,14 +373,14 @@ namespace Exiv2 { #endif if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); // Ensure that this is the correct image type if (!isPngType(*io_, true)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "PNG"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "PNG"); } clearMetadata(); @@ -396,15 +396,15 @@ namespace Exiv2 { #endif std::memset(cheaderBuf.pData_, 0x0, cheaderBuf.size_); long bufRead = io_->read(cheaderBuf.pData_, cheaderBuf.size_); - if (io_->error()) throw Error(14); - if (bufRead != cheaderBuf.size_) throw Error(20); + if (io_->error()) throw Error(kerFailedToReadImageData); + if (bufRead != cheaderBuf.size_) throw Error(kerInputDataReadFailed); // Decode chunk data length. uint32_t dataOffset = Exiv2::getULong(cheaderBuf.pData_, Exiv2::bigEndian); long pos = io_->tell(); if ( pos == -1 || dataOffset > uint32_t(0x7FFFFFFF) - || static_cast(dataOffset) > imgSize - pos) throw Exiv2::Error(14); + || static_cast(dataOffset) > imgSize - pos) throw Exiv2::Error(kerFailedToReadImageData); // Perform a chunk triage for item that we need. @@ -419,8 +419,8 @@ namespace Exiv2 { DataBuf cdataBuf(dataOffset); bufRead = io_->read(cdataBuf.pData_, dataOffset); - if (io_->error()) throw Error(14); - if (bufRead != (long)dataOffset) throw Error(20); + if (io_->error()) throw Error(kerFailedToReadImageData); + if (bufRead != (long)dataOffset) throw Error(kerInputDataReadFailed); if (!memcmp(cheaderBuf.pData_ + 4, "IEND", 4)) { @@ -476,7 +476,7 @@ namespace Exiv2 { std::cout << "Exiv2::PngImage::readMetadata: Seek to offset: " << dataOffset + 4 << "\n"; #endif io_->seek(dataOffset + 4 , BasicIo::cur); - if (io_->error() || io_->eof()) throw Error(14); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); } } // PngImage::readMetadata @@ -485,7 +485,7 @@ namespace Exiv2 { { if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); BasicIo::AutoPtr tempIo(new MemIo); @@ -499,8 +499,8 @@ namespace Exiv2 { void PngImage::doWriteMetadata(BasicIo& outIo) { - if (!io_->isopen()) throw Error(20); - if (!outIo.isopen()) throw Error(21); + if (!io_->isopen()) throw Error(kerInputDataReadFailed); + if (!outIo.isopen()) throw Error(kerImageWriteFailed); #ifdef DEBUG std::cout << "Exiv2::PngImage::doWriteMetadata: Writing PNG file " << io_->path() << "\n"; @@ -510,12 +510,12 @@ namespace Exiv2 { // Ensure that this is the correct image type if (!isPngType(*io_, true)) { - if (io_->error() || io_->eof()) throw Error(20); - throw Error(22); + if (io_->error() || io_->eof()) throw Error(kerInputDataReadFailed); + throw Error(kerNoImageInInputData); } // Write PNG Signature. - if (outIo.write(pngSignature, 8) != 8) throw Error(21); + if (outIo.write(pngSignature, 8) != 8) throw Error(kerImageWriteFailed); DataBuf cheaderBuf(8); // Chunk header : 4 bytes (data size) + 4 bytes (chunk type). @@ -525,21 +525,21 @@ namespace Exiv2 { std::memset(cheaderBuf.pData_, 0x00, cheaderBuf.size_); long bufRead = io_->read(cheaderBuf.pData_, cheaderBuf.size_); - if (io_->error()) throw Error(14); - if (bufRead != cheaderBuf.size_) throw Error(20); + if (io_->error()) throw Error(kerFailedToReadImageData); + if (bufRead != cheaderBuf.size_) throw Error(kerInputDataReadFailed); // Decode chunk data length. uint32_t dataOffset = getULong(cheaderBuf.pData_, bigEndian); - if (dataOffset > 0x7FFFFFFF) throw Exiv2::Error(14); + if (dataOffset > 0x7FFFFFFF) throw Exiv2::Error(kerFailedToReadImageData); // Read whole chunk : Chunk header + Chunk data (not fixed size - can be null) + CRC (4 bytes). DataBuf chunkBuf(8 + dataOffset + 4); // Chunk header (8 bytes) + Chunk data + CRC (4 bytes). memcpy(chunkBuf.pData_, cheaderBuf.pData_, 8); // Copy header. bufRead = io_->read(chunkBuf.pData_ + 8, dataOffset + 4); // Extract chunk data + CRC - if (io_->error()) throw Error(14); - if (bufRead != (long)(dataOffset + 4)) throw Error(20); + if (io_->error()) throw Error(kerFailedToReadImageData); + if (bufRead != (long)(dataOffset + 4)) throw Error(kerInputDataReadFailed); char szChunk[5]; memcpy(szChunk,cheaderBuf.pData_ + 4,4); @@ -551,7 +551,7 @@ namespace Exiv2 { #ifdef DEBUG std::cout << "Exiv2::PngImage::doWriteMetadata: Write IEND chunk (length: " << dataOffset << ")\n"; #endif - if (outIo.write(chunkBuf.pData_, chunkBuf.size_) != chunkBuf.size_) throw Error(21); + if (outIo.write(chunkBuf.pData_, chunkBuf.size_) != chunkBuf.size_) throw Error(kerImageWriteFailed); return; } else if (!memcmp(cheaderBuf.pData_ + 4, "IHDR", 4)) @@ -559,7 +559,7 @@ namespace Exiv2 { #ifdef DEBUG std::cout << "Exiv2::PngImage::doWriteMetadata: Write IHDR chunk (length: " << dataOffset << ")\n"; #endif - if (outIo.write(chunkBuf.pData_, chunkBuf.size_) != chunkBuf.size_) throw Error(21); + if (outIo.write(chunkBuf.pData_, chunkBuf.size_) != chunkBuf.size_) throw Error(kerImageWriteFailed); // Write all updated metadata here, just after IHDR. if (!comment_.empty()) @@ -568,7 +568,7 @@ namespace Exiv2 { std::string chunk = PngChunk::makeMetadataChunk(comment_, mdComment); if (outIo.write((const byte*)chunk.data(), static_cast(chunk.size())) != (long)chunk.size()) { - throw Error(21); + throw Error(kerImageWriteFailed); } } @@ -585,7 +585,7 @@ namespace Exiv2 { std::string chunk = PngChunk::makeMetadataChunk(rawExif, mdExif); if (outIo.write((const byte*)chunk.data(), static_cast(chunk.size())) != (long)chunk.size()) { - throw Error(21); + throw Error(kerImageWriteFailed); } } } @@ -600,7 +600,7 @@ namespace Exiv2 { std::string chunk = PngChunk::makeMetadataChunk(rawIptc, mdIptc); if (outIo.write((const byte*)chunk.data(), static_cast(chunk.size())) != (long)chunk.size()) { - throw Error(21); + throw Error(kerImageWriteFailed); } } } @@ -630,7 +630,7 @@ namespace Exiv2 { || outIo.write (compressed.pData_,compressed.size_) != compressed.size_ || outIo.write(crc,4) != 4 ){ - throw Error(21); + throw Error(kerImageWriteFailed); } #ifdef DEBUG std::cout << "Exiv2::PngImage::doWriteMetadata: build iCCP" @@ -650,7 +650,7 @@ namespace Exiv2 { // Update XMP data to a new PNG chunk std::string chunk = PngChunk::makeMetadataChunk(xmpPacket_, mdXmp); if (outIo.write((const byte*)chunk.data(), static_cast(chunk.size())) != (long)chunk.size()) { - throw Error(21); + throw Error(kerImageWriteFailed); } } } @@ -680,7 +680,7 @@ namespace Exiv2 { std::cout << "Exiv2::PngImage::doWriteMetadata: write " << szChunk << " chunk (length: " << dataOffset << ")" << std::endl; #endif - if (outIo.write(chunkBuf.pData_, chunkBuf.size_) != chunkBuf.size_) throw Error(21); + if (outIo.write(chunkBuf.pData_, chunkBuf.size_) != chunkBuf.size_) throw Error(kerImageWriteFailed); } } else @@ -690,7 +690,7 @@ namespace Exiv2 { std::cout << "Exiv2::PngImage::doWriteMetadata: copy " << szChunk << " chunk (length: " << dataOffset << ")" << std::endl; #endif - if (outIo.write(chunkBuf.pData_, chunkBuf.size_) != chunkBuf.size_) throw Error(21); + if (outIo.write(chunkBuf.pData_, chunkBuf.size_) != chunkBuf.size_) throw Error(kerImageWriteFailed); } } diff --git a/src/preview.cpp b/src/preview.cpp index 1d5d48d8..9e1320d2 100644 --- a/src/preview.cpp +++ b/src/preview.cpp @@ -463,7 +463,7 @@ namespace { BasicIo &io = image_.io(); if (io.open() != 0) { - throw Error(9, io.path(), strError()); + throw Error(kerDataSourceOpenFailed, io.path(), strError()); } IoCloser closer(io); const byte* data = io.mmap(); @@ -492,7 +492,7 @@ namespace { } return DataBuf(record + sizeHdr + 28, sizeData - 28); } else { - throw Error(1, "Invalid native preview filter: " + nativePreview_.filter_); + throw Error(kerErrorMessage, "Invalid native preview filter: " + nativePreview_.filter_); } } @@ -570,7 +570,7 @@ namespace { BasicIo &io = image_.io(); if (io.open() != 0) { - throw Error(9, io.path(), strError()); + throw Error(kerDataSourceOpenFailed, io.path(), strError()); } IoCloser closer(io); @@ -587,7 +587,7 @@ namespace { BasicIo &io = image_.io(); if (io.open() != 0) { - throw Error(9, io.path(), strError()); + throw Error(kerDataSourceOpenFailed, io.path(), strError()); } IoCloser closer(io); const Exiv2::byte* base = io.mmap(); @@ -784,7 +784,7 @@ namespace { BasicIo &io = image_.io(); if (io.open() != 0) { - throw Error(9, io.path(), strError()); + throw Error(kerDataSourceOpenFailed, io.path(), strError()); } IoCloser closer(io); diff --git a/src/properties.cpp b/src/properties.cpp index 5686d51a..8b4f1c54 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -2657,7 +2657,7 @@ namespace Exiv2 { const XmpNsInfo::Prefix pf(prefix); const XmpNsInfo* xn = lookupNsRegistryUnsafe(pf); if (!xn) xn = find(xmpNsInfo, pf); - if (!xn) throw Error(35, prefix); + if (!xn) throw Error(kerNoNamespaceInfoForXmpPrefix, prefix); return xn; } @@ -2717,7 +2717,7 @@ namespace Exiv2 { XmpKey::Impl::Impl(const std::string& prefix, const std::string& property) { // Validate prefix - if (XmpProperties::ns(prefix).empty()) throw Error(46, prefix); + if (XmpProperties::ns(prefix).empty()) throw Error(kerNoNamespaceForPrefix, prefix); property_ = property; prefix_ = prefix; @@ -2806,21 +2806,21 @@ namespace Exiv2 { { // Get the family name, prefix and property name parts of the key std::string::size_type pos1 = key.find('.'); - if (pos1 == std::string::npos) throw Error(6, key); + if (pos1 == std::string::npos) throw Error(kerInvalidKey, key); std::string familyName = key.substr(0, pos1); if (0 != strcmp(familyName.c_str(), familyName_)) { - throw Error(6, key); + throw Error(kerInvalidKey, key); } std::string::size_type pos0 = pos1 + 1; pos1 = key.find('.', pos0); - if (pos1 == std::string::npos) throw Error(6, key); + if (pos1 == std::string::npos) throw Error(kerInvalidKey, key); std::string prefix = key.substr(pos0, pos1 - pos0); - if (prefix == "") throw Error(6, key); + if (prefix == "") throw Error(kerInvalidKey, key); std::string property = key.substr(pos1 + 1); - if (property == "") throw Error(6, key); + if (property == "") throw Error(kerInvalidKey, key); // Validate prefix - if (XmpProperties::ns(prefix).empty()) throw Error(46, prefix); + if (XmpProperties::ns(prefix).empty()) throw Error(kerNoNamespaceForPrefix, prefix); property_ = property; prefix_ = prefix; diff --git a/src/psdimage.cpp b/src/psdimage.cpp index 5749794f..26bc345d 100644 --- a/src/psdimage.cpp +++ b/src/psdimage.cpp @@ -134,7 +134,7 @@ namespace Exiv2 { void PsdImage::setComment(const std::string& /*comment*/) { // not supported - throw(Error(32, "Image comment", "Photoshop")); + throw(Error(kerInvalidSettingForImage, "Image comment", "Photoshop")); } void PsdImage::readMetadata() @@ -144,14 +144,14 @@ namespace Exiv2 { #endif if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); // Ensure that this is the correct image type if (!isPsdType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "Photoshop"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "Photoshop"); } clearMetadata(); @@ -172,7 +172,7 @@ namespace Exiv2 { byte buf[26]; if (io_->read(buf, 26) != 26) { - throw Error(3, "Photoshop"); + throw Error(kerNotAnImage, "Photoshop"); } pixelWidth_ = getLong(buf + 18, bigEndian); pixelHeight_ = getLong(buf + 14, bigEndian); @@ -181,27 +181,27 @@ namespace Exiv2 { // the first four bytes of which specify the byte size of the whole section if (io_->read(buf, 4) != 4) { - throw Error(3, "Photoshop"); + throw Error(kerNotAnImage, "Photoshop"); } // skip it uint32_t colorDataLength = getULong(buf, bigEndian); if (io_->seek(colorDataLength, BasicIo::cur)) { - throw Error(3, "Photoshop"); + throw Error(kerNotAnImage, "Photoshop"); } // after the color data section, comes a list of resource blocks, preceded by the total byte size if (io_->read(buf, 4) != 4) { - throw Error(3, "Photoshop"); + throw Error(kerNotAnImage, "Photoshop"); } uint32_t resourcesLength = getULong(buf, bigEndian); while (resourcesLength > 0) { if (io_->read(buf, 8) != 8) { - throw Error(3, "Photoshop"); + throw Error(kerNotAnImage, "Photoshop"); } if (!Photoshop::isIrb(buf, 4)) @@ -217,7 +217,7 @@ namespace Exiv2 { // read resource size if (io_->read(buf, 4) != 4) { - throw Error(3, "Photoshop"); + throw Error(kerNotAnImage, "Photoshop"); } uint32_t resourceSize = getULong(buf, bigEndian); uint32_t curOffset = io_->tell(); @@ -242,7 +242,7 @@ namespace Exiv2 { { DataBuf rawIPTC(resourceSize); io_->read(rawIPTC.pData_, rawIPTC.size_); - if (io_->error() || io_->eof()) throw Error(14); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); if (IptcParser::decode(iptcData_, rawIPTC.pData_, rawIPTC.size_)) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << "Failed to decode IPTC metadata.\n"; @@ -256,7 +256,7 @@ namespace Exiv2 { { DataBuf rawExif(resourceSize); io_->read(rawExif.pData_, rawExif.size_); - if (io_->error() || io_->eof()) throw Error(14); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); ByteOrder bo = ExifParser::decode(exifData_, rawExif.pData_, rawExif.size_); setByteOrder(bo); if (rawExif.size_ > 0 && byteOrder() == invalidByteOrder) { @@ -272,7 +272,7 @@ namespace Exiv2 { { DataBuf xmpPacket(resourceSize); io_->read(xmpPacket.pData_, xmpPacket.size_); - if (io_->error() || io_->eof()) throw Error(14); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); xmpPacket_.assign(reinterpret_cast(xmpPacket.pData_), xmpPacket.size_); if (xmpPacket_.size() > 0 && XmpParser::decode(xmpData_, xmpPacket_)) { #ifndef SUPPRESS_WARNINGS @@ -306,7 +306,7 @@ namespace Exiv2 { byte buf[28]; if (io_->read(buf, 28) != 28) { - throw Error(3, "Photoshop"); + throw Error(kerNotAnImage, "Photoshop"); } NativePreview nativePreview; nativePreview.position_ = io_->tell(); @@ -317,7 +317,7 @@ namespace Exiv2 { if (nativePreview.size_ > 0 && nativePreview.position_ >= 0) { io_->seek(static_cast(nativePreview.size_), BasicIo::cur); - if (io_->error() || io_->eof()) throw Error(14); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); if (format == 1) { nativePreview.filter_ = ""; @@ -341,7 +341,7 @@ namespace Exiv2 { { if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); BasicIo::AutoPtr tempIo(new MemIo); @@ -355,8 +355,8 @@ namespace Exiv2 { void PsdImage::doWriteMetadata(BasicIo& outIo) { - if (!io_->isopen()) throw Error(20); - if (!outIo.isopen()) throw Error(21); + if (!io_->isopen()) throw Error(kerInputDataReadFailed); + if (!outIo.isopen()) throw Error(kerImageWriteFailed); #ifdef DEBUG std::cout << "Exiv2::PsdImage::doWriteMetadata: Writing PSD file " << io_->path() << "\n"; @@ -365,8 +365,8 @@ namespace Exiv2 { // Ensure that this is the correct image type if (!isPsdType(*io_, true)) { - if (io_->error() || io_->eof()) throw Error(20); - throw Error(22); + if (io_->error() || io_->eof()) throw Error(kerInputDataReadFailed); + throw Error(kerNoImageInInputData); } io_->seek(0, BasicIo::beg); // rewind @@ -376,19 +376,19 @@ namespace Exiv2 { // Get Photoshop header from original file byte psd_head[26]; - if (io_->read(psd_head, 26) != 26) throw Error(3, "Photoshop"); + if (io_->read(psd_head, 26) != 26) throw Error(kerNotAnImage, "Photoshop"); // Write Photoshop header data out to new PSD file - if (outIo.write(psd_head, 26) != 26) throw Error(21); + if (outIo.write(psd_head, 26) != 26) throw Error(kerImageWriteFailed); // Read colorDataLength from original PSD - if (io_->read(buf, 4) != 4) throw Error(3, "Photoshop"); + if (io_->read(buf, 4) != 4) throw Error(kerNotAnImage, "Photoshop"); uint32_t colorDataLength = getULong(buf, bigEndian); // Write colorDataLength ul2Data(buf, colorDataLength, bigEndian); - if (outIo.write(buf, 4) != 4) throw Error(21); + if (outIo.write(buf, 4) != 4) throw Error(kerImageWriteFailed); #ifdef DEBUG std::cerr << std::dec << "colorDataLength: " << colorDataLength << "\n"; #endif @@ -398,23 +398,23 @@ namespace Exiv2 { while (readTotal < colorDataLength) { toRead = static_cast(colorDataLength - readTotal) < lbuf.size_ ? static_cast(colorDataLength - readTotal) : lbuf.size_; - if (io_->read(lbuf.pData_, toRead) != toRead) throw Error(3, "Photoshop"); + if (io_->read(lbuf.pData_, toRead) != toRead) throw Error(kerNotAnImage, "Photoshop"); readTotal += toRead; - if (outIo.write(lbuf.pData_, toRead) != toRead) throw Error(21); + if (outIo.write(lbuf.pData_, toRead) != toRead) throw Error(kerImageWriteFailed); } - if (outIo.error()) throw Error(21); + if (outIo.error()) throw Error(kerImageWriteFailed); uint32_t resLenOffset = io_->tell(); // remember for later update // Read length of all resource blocks from original PSD - if (io_->read(buf, 4) != 4) throw Error(3, "Photoshop"); + if (io_->read(buf, 4) != 4) throw Error(kerNotAnImage, "Photoshop"); uint32_t oldResLength = getULong(buf, bigEndian); uint32_t newResLength = 0; // Write oldResLength (will be updated later) ul2Data(buf, oldResLength, bigEndian); - if (outIo.write(buf, 4) != 4) throw Error(21); + if (outIo.write(buf, 4) != 4) throw Error(kerImageWriteFailed); #ifdef DEBUG std::cerr << std::dec << "oldResLength: " << oldResLength << "\n"; @@ -428,14 +428,14 @@ namespace Exiv2 { bool exifDone = false; bool xmpDone = false; while (oldResLength > 0) { - if (io_->read(buf, 8) != 8) throw Error(3, "Photoshop"); + if (io_->read(buf, 8) != 8) throw Error(kerNotAnImage, "Photoshop"); // read resource type and ID uint32_t resourceType = getULong(buf, bigEndian); if (!Photoshop::isIrb(buf, 4)) { - throw Error(3, "Photoshop"); // bad resource type + throw Error(kerNotAnImage, "Photoshop"); // bad resource type } uint16_t resourceId = getUShort(buf + 4, bigEndian); uint32_t resourceNameLength = buf[6]; @@ -445,10 +445,10 @@ namespace Exiv2 { // read rest of resource name, plus any padding DataBuf resName(256); if ( io_->read(resName.pData_, adjResourceNameLen) - != static_cast(adjResourceNameLen)) throw Error(3, "Photoshop"); + != static_cast(adjResourceNameLen)) throw Error(kerNotAnImage, "Photoshop"); // read resource size (actual length w/o padding!) - if (io_->read(buf, 4) != 4) throw Error(3, "Photoshop"); + if (io_->read(buf, 4) != 4) throw Error(kerNotAnImage, "Photoshop"); uint32_t resourceSize = getULong(buf, bigEndian); uint32_t pResourceSize = (resourceSize + 1) & ~1; // padded resource size @@ -486,18 +486,18 @@ namespace Exiv2 { #endif // Copy resource block to new PSD file ul2Data(buf, resourceType, bigEndian); - if (outIo.write(buf, 4) != 4) throw Error(21); + if (outIo.write(buf, 4) != 4) throw Error(kerImageWriteFailed); us2Data(buf, resourceId, bigEndian); - if (outIo.write(buf, 2) != 2) throw Error(21); + if (outIo.write(buf, 2) != 2) throw Error(kerImageWriteFailed); // Write resource name as Pascal string buf[0] = resourceNameLength & 0x00ff; - if (outIo.write(buf, 1) != 1) throw Error(21); + if (outIo.write(buf, 1) != 1) throw Error(kerImageWriteFailed); buf[0] = resourceNameFirstChar; - if (outIo.write(buf, 1) != 1) throw Error(21); + if (outIo.write(buf, 1) != 1) throw Error(kerImageWriteFailed); if ( outIo.write(resName.pData_, adjResourceNameLen) - != static_cast(adjResourceNameLen)) throw Error(21); + != static_cast(adjResourceNameLen)) throw Error(kerImageWriteFailed); ul2Data(buf, resourceSize, bigEndian); - if (outIo.write(buf, 4) != 4) throw Error(21); + if (outIo.write(buf, 4) != 4) throw Error(kerImageWriteFailed); readTotal = 0; toRead = 0; @@ -505,12 +505,12 @@ namespace Exiv2 { toRead = static_cast(pResourceSize - readTotal) < lbuf.size_ ? static_cast(pResourceSize - readTotal) : lbuf.size_; if (io_->read(lbuf.pData_, toRead) != toRead) { - throw Error(3, "Photoshop"); + throw Error(kerNotAnImage, "Photoshop"); } readTotal += toRead; - if (outIo.write(lbuf.pData_, toRead) != toRead) throw Error(21); + if (outIo.write(lbuf.pData_, toRead) != toRead) throw Error(kerImageWriteFailed); } - if (outIo.error()) throw Error(21); + if (outIo.error()) throw Error(kerImageWriteFailed); newResLength += pResourceSize + adjResourceNameLen + 12; } @@ -543,9 +543,9 @@ namespace Exiv2 { // Copy remaining data long readSize = 0; while ((readSize=io_->read(lbuf.pData_, lbuf.size_))) { - if (outIo.write(lbuf.pData_, readSize) != readSize) throw Error(21); + if (outIo.write(lbuf.pData_, readSize) != readSize) throw Error(kerImageWriteFailed); } - if (outIo.error()) throw Error(21); + if (outIo.error()) throw Error(kerImageWriteFailed); // Update length of resources #ifdef DEBUG @@ -553,7 +553,7 @@ namespace Exiv2 { #endif outIo.seek(resLenOffset, BasicIo::beg); ul2Data(buf, newResLength, bigEndian); - if (outIo.write(buf, 4) != 4) throw Error(21); + if (outIo.write(buf, 4) != 4) throw Error(kerImageWriteFailed); } // PsdImage::doWriteMetadata @@ -569,20 +569,20 @@ namespace Exiv2 { std::cerr << std::hex << "write: resourceId: " << kPhotoshopResourceID_IPTC_NAA << "\n"; std::cerr << std::dec << "Writing IPTC_NAA: size: " << rawIptc.size_ << "\n"; #endif - if (out.write(reinterpret_cast(Photoshop::irbId_[0]), 4) != 4) throw Error(21); + if (out.write(reinterpret_cast(Photoshop::irbId_[0]), 4) != 4) throw Error(kerImageWriteFailed); us2Data(buf, kPhotoshopResourceID_IPTC_NAA, bigEndian); - if (out.write(buf, 2) != 2) throw Error(21); + if (out.write(buf, 2) != 2) throw Error(kerImageWriteFailed); us2Data(buf, 0, bigEndian); // NULL resource name - if (out.write(buf, 2) != 2) throw Error(21); + if (out.write(buf, 2) != 2) throw Error(kerImageWriteFailed); ul2Data(buf, rawIptc.size_, bigEndian); - if (out.write(buf, 4) != 4) throw Error(21); + if (out.write(buf, 4) != 4) throw Error(kerImageWriteFailed); // Write encoded Iptc data - if (out.write(rawIptc.pData_, rawIptc.size_) != rawIptc.size_) throw Error(21); + if (out.write(rawIptc.pData_, rawIptc.size_) != rawIptc.size_) throw Error(kerImageWriteFailed); resLength += rawIptc.size_ + 12; if (rawIptc.size_ & 1) // even padding { buf[0] = 0; - if (out.write(buf, 1) != 1) throw Error(21); + if (out.write(buf, 1) != 1) throw Error(kerImageWriteFailed); resLength++; } } @@ -609,20 +609,20 @@ namespace Exiv2 { std::cerr << std::hex << "write: resourceId: " << kPhotoshopResourceID_ExifInfo << "\n"; std::cerr << std::dec << "Writing ExifInfo: size: " << blob.size() << "\n"; #endif - if (out.write(reinterpret_cast(Photoshop::irbId_[0]), 4) != 4) throw Error(21); + if (out.write(reinterpret_cast(Photoshop::irbId_[0]), 4) != 4) throw Error(kerImageWriteFailed); us2Data(buf, kPhotoshopResourceID_ExifInfo, bigEndian); - if (out.write(buf, 2) != 2) throw Error(21); + if (out.write(buf, 2) != 2) throw Error(kerImageWriteFailed); us2Data(buf, 0, bigEndian); // NULL resource name - if (out.write(buf, 2) != 2) throw Error(21); + if (out.write(buf, 2) != 2) throw Error(kerImageWriteFailed); ul2Data(buf, static_cast(blob.size()), bigEndian); - if (out.write(buf, 4) != 4) throw Error(21); + if (out.write(buf, 4) != 4) throw Error(kerImageWriteFailed); // Write encoded Exif data - if (out.write(&blob[0], static_cast(blob.size())) != static_cast(blob.size())) throw Error(21); + if (out.write(&blob[0], static_cast(blob.size())) != static_cast(blob.size())) throw Error(kerImageWriteFailed); resLength += static_cast(blob.size()) + 12; if (blob.size() & 1) // even padding { buf[0] = 0; - if (out.write(buf, 1) != 1) throw Error(21); + if (out.write(buf, 1) != 1) throw Error(kerImageWriteFailed); resLength++; } } @@ -653,22 +653,22 @@ namespace Exiv2 { std::cerr << std::hex << "write: resourceId: " << kPhotoshopResourceID_XMPPacket << "\n"; std::cerr << std::dec << "Writing XMPPacket: size: " << xmpPacket.size() << "\n"; #endif - if (out.write(reinterpret_cast(Photoshop::irbId_[0]), 4) != 4) throw Error(21); + if (out.write(reinterpret_cast(Photoshop::irbId_[0]), 4) != 4) throw Error(kerImageWriteFailed); us2Data(buf, kPhotoshopResourceID_XMPPacket, bigEndian); - if (out.write(buf, 2) != 2) throw Error(21); + if (out.write(buf, 2) != 2) throw Error(kerImageWriteFailed); us2Data(buf, 0, bigEndian); // NULL resource name - if (out.write(buf, 2) != 2) throw Error(21); + if (out.write(buf, 2) != 2) throw Error(kerImageWriteFailed); ul2Data(buf, static_cast(xmpPacket.size()), bigEndian); - if (out.write(buf, 4) != 4) throw Error(21); + if (out.write(buf, 4) != 4) throw Error(kerImageWriteFailed); // Write XMPPacket if (out.write(reinterpret_cast(xmpPacket.data()), static_cast(xmpPacket.size())) - != static_cast(xmpPacket.size())) throw Error(21); - if (out.error()) throw Error(21); + != static_cast(xmpPacket.size())) throw Error(kerImageWriteFailed); + if (out.error()) throw Error(kerImageWriteFailed); resLength += static_cast(xmpPacket.size()) + 12; if (xmpPacket.size() & 1) // even padding { buf[0] = 0; - if (out.write(buf, 1) != 1) throw Error(21); + if (out.write(buf, 1) != 1) throw Error(kerImageWriteFailed); resLength++; } } diff --git a/src/quicktimevideo.cpp b/src/quicktimevideo.cpp index ae1d1828..f9a8b7dd 100644 --- a/src/quicktimevideo.cpp +++ b/src/quicktimevideo.cpp @@ -625,12 +625,12 @@ namespace Exiv2 { void QuickTimeVideo::readMetadata() { - if (io_->open() != 0) throw Error(9, io_->path(), strError()); + if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError()); // Ensure that this is the correct image type if (!isQTimeType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "QuickTime"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "QuickTime"); } IoCloser closer(*io_); diff --git a/src/rafimage.cpp b/src/rafimage.cpp index 9a208268..f709d544 100644 --- a/src/rafimage.cpp +++ b/src/rafimage.cpp @@ -77,29 +77,29 @@ namespace Exiv2 { void RafImage::setExifData(const ExifData& /*exifData*/) { // Todo: implement me! - throw(Error(32, "Exif metadata", "RAF")); + throw(Error(kerInvalidSettingForImage, "Exif metadata", "RAF")); } void RafImage::setIptcData(const IptcData& /*iptcData*/) { // Todo: implement me! - throw(Error(32, "IPTC metadata", "RAF")); + throw(Error(kerInvalidSettingForImage, "IPTC metadata", "RAF")); } void RafImage::setComment(const std::string& /*comment*/) { // not supported - throw(Error(32, "Image comment", "RAF")); + throw(Error(kerInvalidSettingForImage, "Image comment", "RAF")); } void RafImage::printStructure(std::ostream& out, PrintStructureOption option, int depth) { if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } // Ensure this is the correct image type if (!isRafType(*io_, true)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "RAF"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "RAF"); } bool bPrint = option==kpsBasic || option==kpsRecursive; if ( bPrint ) { @@ -280,12 +280,12 @@ namespace Exiv2 { #ifdef DEBUG std::cerr << "Reading RAF file " << io_->path() << "\n"; #endif - if (io_->open() != 0) throw Error(9, io_->path(), strError()); + if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError()); IoCloser closer(*io_); // Ensure that this is the correct image type if (!isRafType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "RAF"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "RAF"); } clearMetadata(); @@ -301,7 +301,7 @@ namespace Exiv2 { DataBuf buf(jpg_img_len - 12); io_->seek(jpg_img_off + 12,BasicIo::beg); io_->read(buf.pData_, buf.size_ - 12); - if (io_->error() || io_->eof()) throw Error(14); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); io_->seek(0,BasicIo::beg); // rewind @@ -320,7 +320,7 @@ namespace Exiv2 { void RafImage::writeMetadata() { //! Todo: implement me! - throw(Error(31, "RAF")); + throw(Error(kerWritingImageFormatUnsupported, "RAF")); } // RafImage::writeMetadata // ************************************************************************* diff --git a/src/riffvideo.cpp b/src/riffvideo.cpp index a14ce5d8..7dfd3cba 100644 --- a/src/riffvideo.cpp +++ b/src/riffvideo.cpp @@ -533,12 +533,12 @@ namespace Exiv2 { void RiffVideo::printStructure(std::ostream& out, PrintStructureOption option, int depth) { if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } // Ensure this is the correct image type if (!isRiffType(*io_, true)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "RIFF"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "RIFF"); } bool bPrint = option==kpsBasic || option==kpsRecursive; @@ -600,12 +600,12 @@ namespace Exiv2 { void RiffVideo::readMetadata() { - if (io_->open() != 0) throw Error(9, io_->path(), strError()); + if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError()); // Ensure that this is the correct image type if (!isRiffType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "RIFF"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "RIFF"); } IoCloser closer(*io_); diff --git a/src/rw2image.cpp b/src/rw2image.cpp index acb91489..c252fba0 100644 --- a/src/rw2image.cpp +++ b/src/rw2image.cpp @@ -81,29 +81,29 @@ namespace Exiv2 { void Rw2Image::setExifData(const ExifData& /*exifData*/) { // Todo: implement me! - throw(Error(32, "Exif metadata", "RW2")); + throw(Error(kerInvalidSettingForImage, "Exif metadata", "RW2")); } void Rw2Image::setIptcData(const IptcData& /*iptcData*/) { // Todo: implement me! - throw(Error(32, "IPTC metadata", "RW2")); + throw(Error(kerInvalidSettingForImage, "IPTC metadata", "RW2")); } void Rw2Image::setComment(const std::string& /*comment*/) { // not supported - throw(Error(32, "Image comment", "RW2")); + throw(Error(kerInvalidSettingForImage, "Image comment", "RW2")); } void Rw2Image::printStructure(std::ostream& out, PrintStructureOption option, int depth) { out << "RW2 IMAGE" << std::endl; - if (io_->open() != 0) throw Error(9, io_->path(), strError()); + if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError()); // Ensure that this is the correct image type if ( imageType() == ImageType::none ) if (!isRw2Type(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(15); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAJpeg); } io_->seek(0,BasicIo::beg); @@ -117,13 +117,13 @@ namespace Exiv2 { std::cerr << "Reading RW2 file " << io_->path() << "\n"; #endif if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); // Ensure that this is the correct image type if (!isRw2Type(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "RW2"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "RW2"); } clearMetadata(); std::ofstream devnull; @@ -223,7 +223,7 @@ namespace Exiv2 { void Rw2Image::writeMetadata() { // Todo: implement me! - throw(Error(31, "RW2")); + throw(Error(kerWritingImageFormatUnsupported, "RW2")); } // Rw2Image::writeMetadata ByteOrder Rw2Parser::decode( diff --git a/src/ssh.cpp b/src/ssh.cpp index a1ba1b91..99a32f62 100644 --- a/src/ssh.cpp +++ b/src/ssh.cpp @@ -39,12 +39,12 @@ namespace Exiv2 { std::string timeout = getEnv(envTIMEOUT); timeout_ = atol(timeout.c_str()); if (timeout_ == 0) { - throw Error(1, "Timeout Environmental Variable must be a positive integer."); + throw Error(kerErrorMessage, "Timeout Environmental Variable must be a positive integer."); } session_ = ssh_new(); if (session_ == NULL) { - throw Error(1, "Unable to create the the ssh session"); + throw Error(kerErrorMessage, "Unable to create the the ssh session"); } // try to connect @@ -54,11 +54,11 @@ namespace Exiv2 { if (port != "") ssh_options_set(session_, SSH_OPTIONS_PORT_STR, port.c_str()); if (ssh_connect(session_) != SSH_OK) { - throw Error(1, ssh_get_error(session_)); + throw Error(kerErrorMessage, ssh_get_error(session_)); } // Authentication if (ssh_userauth_password(session_, NULL, pass_.c_str()) != SSH_AUTH_SUCCESS) { - throw Error(1, ssh_get_error(session_)); + throw Error(kerErrorMessage, ssh_get_error(session_)); } } @@ -99,11 +99,11 @@ namespace Exiv2 { scp = ssh_scp_new(session_, SSH_SCP_WRITE, path.c_str()); if (scp == NULL) { rc = SSH_ERROR; - throw Error(1, ssh_get_error(session_)); + throw Error(kerErrorMessage, ssh_get_error(session_)); } else { rc = ssh_scp_init(scp); if (rc != SSH_OK) { - throw Error(1, ssh_get_error(session_)); + throw Error(kerErrorMessage, ssh_get_error(session_)); } else { #ifdef _MSC_VER // S_IRUSR & S_IWUSR not in MSVC (0000400 & 0000200 in /usr/include/sys/stat.h on MacOS-X 10.8) @@ -112,11 +112,11 @@ namespace Exiv2 { #endif rc = ssh_scp_push_file (scp, filename.c_str(), size, S_IRUSR | S_IWUSR); if (rc != SSH_OK) { - throw Error(1, ssh_get_error(session_)); + throw Error(kerErrorMessage, ssh_get_error(session_)); } else { rc = ssh_scp_write(scp, data, size); if (rc != SSH_OK) { - throw Error(1, ssh_get_error(session_)); + throw Error(kerErrorMessage, ssh_get_error(session_)); } } ssh_scp_close(scp); @@ -132,11 +132,11 @@ namespace Exiv2 { sftp_ = sftp_new(session_); if (sftp_ == NULL) { - throw Error(1, "Unable to create the the sftp session"); + throw Error(kerErrorMessage, "Unable to create the the sftp session"); } if (sftp_init(sftp_) != SSH_OK) { sftp_free(sftp_); - throw Error(1, "Error initializing SFTP session"); + throw Error(kerErrorMessage, "Error initializing SFTP session"); } } diff --git a/src/tags.cpp b/src/tags.cpp index aaceffd9..ab22e577 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -2369,7 +2369,7 @@ namespace Exiv2 { { const TagInfo* ti = tagInfo(tagName, ifdId); if (ti != 0 && ti->tag_ != 0xffff) return ti->tag_; - if (!isHex(tagName, 4, "0x")) throw Error(7, tagName, ifdId); + if (!isHex(tagName, 4, "0x")) throw Error(kerInvalidTag, tagName, ifdId); std::istringstream is(tagName); uint16_t tag; is >> std::hex >> tag; @@ -3088,30 +3088,30 @@ namespace Exiv2 { { // Get the family name, IFD name and tag name parts of the key std::string::size_type pos1 = key.find('.'); - if (pos1 == std::string::npos) throw Error(6, key); + if (pos1 == std::string::npos) throw Error(kerInvalidKey, key); std::string familyName = key.substr(0, pos1); if (0 != strcmp(familyName.c_str(), familyName_)) { - throw Error(6, key); + throw Error(kerInvalidKey, key); } std::string::size_type pos0 = pos1 + 1; pos1 = key.find('.', pos0); - if (pos1 == std::string::npos) throw Error(6, key); + if (pos1 == std::string::npos) throw Error(kerInvalidKey, key); std::string groupName = key.substr(pos0, pos1 - pos0); - if (groupName.empty()) throw Error(6, key); + if (groupName.empty()) throw Error(kerInvalidKey, key); std::string tn = key.substr(pos1 + 1); - if (tn.empty()) throw Error(6, key); + if (tn.empty()) throw Error(kerInvalidKey, key); // Find IfdId IfdId ifdId = groupId(groupName); - if (ifdId == ifdIdNotSet) throw Error(6, key); + if (ifdId == ifdIdNotSet) throw Error(kerInvalidKey, key); if (!Internal::isExifIfd(ifdId) && !Internal::isMakerIfd(ifdId)) { - throw Error(6, key); + throw Error(kerInvalidKey, key); } // Convert tag uint16_t tag = tagNumber(tn, ifdId); // Get tag info tagInfo_ = tagInfo(tag, ifdId); - if (tagInfo_ == 0) throw Error(6, key); + if (tagInfo_ == 0) throw Error(kerInvalidKey, key); tag_ = tag; ifdId_ = ifdId; @@ -3136,11 +3136,11 @@ namespace Exiv2 { IfdId ifdId = groupId(groupName); // Todo: Test if this condition can be removed if (!Internal::isExifIfd(ifdId) && !Internal::isMakerIfd(ifdId)) { - throw Error(23, ifdId); + throw Error(kerInvalidIfdId, ifdId); } const TagInfo* ti = tagInfo(tag, ifdId); if (ti == 0) { - throw Error(23, ifdId); + throw Error(kerInvalidIfdId, ifdId); } p_->groupName_ = groupName; p_->makeKey(tag, ifdId, ti); @@ -3151,7 +3151,7 @@ namespace Exiv2 { { IfdId ifdId = static_cast(ti.ifdId_); if (!Internal::isExifIfd(ifdId) && !Internal::isMakerIfd(ifdId)) { - throw Error(23, ifdId); + throw Error(kerInvalidIfdId, ifdId); } p_->groupName_ = Exiv2::groupName(ifdId); p_->makeKey(ti.tag_, ifdId, &ti); diff --git a/src/tags_int.cpp b/src/tags_int.cpp index 3b34805a..4c9a95d8 100644 --- a/src/tags_int.cpp +++ b/src/tags_int.cpp @@ -2158,7 +2158,7 @@ namespace Exiv2 { { const TagInfo* ti = tagInfo(tagName, ifdId); if (ti != 0 && ti->tag_ != 0xffff) return ti->tag_; - if (!isHex(tagName, 4, "0x")) throw Error(7, tagName, ifdId); + if (!isHex(tagName, 4, "0x")) throw Error(kerInvalidTag, tagName, ifdId); std::istringstream is(tagName); uint16_t tag; is >> std::hex >> tag; diff --git a/src/tgaimage.cpp b/src/tgaimage.cpp index a88b99ac..cf729bdd 100644 --- a/src/tgaimage.cpp +++ b/src/tgaimage.cpp @@ -55,19 +55,19 @@ namespace Exiv2 { void TgaImage::setExifData(const ExifData& /*exifData*/) { // Todo: implement me! - throw(Error(32, "Exif metadata", "TGA")); + throw(Error(kerInvalidSettingForImage, "Exif metadata", "TGA")); } void TgaImage::setIptcData(const IptcData& /*iptcData*/) { // Todo: implement me! - throw(Error(32, "IPTC metadata", "TGA")); + throw(Error(kerInvalidSettingForImage, "IPTC metadata", "TGA")); } void TgaImage::setComment(const std::string& /*comment*/) { // not supported - throw(Error(32, "Image comment", "TGA")); + throw(Error(kerInvalidSettingForImage, "Image comment", "TGA")); } void TgaImage::readMetadata() @@ -77,14 +77,14 @@ namespace Exiv2 { #endif if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); // Ensure that this is the correct image type if (!isTgaType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "TGA"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "TGA"); } clearMetadata(); @@ -121,7 +121,7 @@ namespace Exiv2 { void TgaImage::writeMetadata() { // Todo: implement me! - throw(Error(31, "TGA")); + throw(Error(kerWritingImageFormatUnsupported, "TGA")); } // TgaImage::writeMetadata // ************************************************************************* diff --git a/src/tiff-test.cpp b/src/tiff-test.cpp index 180796b8..43535976 100644 --- a/src/tiff-test.cpp +++ b/src/tiff-test.cpp @@ -57,7 +57,7 @@ void print(const ExifData& exifData) { if (exifData.empty()) { std::string error("No Exif data found in the file"); - throw Exiv2::Error(1, error); + throw Exiv2::Error(kerErrorMessage, error); } Exiv2::ExifData::const_iterator end = exifData.end(); for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) { diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index 7c4fe542..f95dfbe9 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -1086,7 +1086,7 @@ namespace Exiv2 { // Number of components to write const uint32_t compCount = count(); - if (compCount > 0xffff) throw Error(49, groupName(group())); + if (compCount > 0xffff) throw Error(kerTooManyTiffDirectoryEntries, groupName(group())); // Size of next IFD, if any uint32_t sizeNext = 0; @@ -1264,7 +1264,7 @@ namespace Exiv2 { switch(tiffType) { case ttUnsignedShort: case ttSignedShort: - if (static_cast(offset) > 0xffff) throw Error(26); + if (static_cast(offset) > 0xffff) throw Error(kerOffsetOutOfRange); rc = s2Data(buf, static_cast(offset), byteOrder); break; case ttUnsignedLong: @@ -1272,7 +1272,7 @@ namespace Exiv2 { rc = l2Data(buf, static_cast(offset), byteOrder); break; default: - throw Error(27); + throw Error(kerUnsupportedDataAreaOffsetType); break; } return rc; @@ -1607,8 +1607,8 @@ namespace Exiv2 { uint32_t TiffImageEntry::doWriteImage(IoWrapper& ioWrapper, ByteOrder /*byteOrder*/) const { - if ( !pValue() ) throw Error(21); // #1296 - + if ( !pValue() ) throw Error(kerImageWriteFailed); // #1296 + uint32_t len = pValue()->sizeDataArea(); if (len > 0) { #ifdef DEBUG diff --git a/src/tiffimage.cpp b/src/tiffimage.cpp index fe11c12d..9af4bbe9 100644 --- a/src/tiffimage.cpp +++ b/src/tiffimage.cpp @@ -59,7 +59,7 @@ in crwimage.* : + Fix CiffHeader according to TiffHeader - + Combine Error(15) and Error(33), add format argument %1 + + Combine Error(kerNotAJpeg) and Error(kerNotACrwImage), add format argument %1 + Search crwimage for todos, fix writeMetadata comment + rename loadStack to getPath for consistency @@ -164,7 +164,7 @@ namespace Exiv2 { void TiffImage::setComment(const std::string& /*comment*/) { // not supported - throw(Error(32, "Image comment", "TIFF")); + throw(Error(kerInvalidSettingForImage, "Image comment", "TIFF")); } void TiffImage::readMetadata() @@ -172,12 +172,12 @@ namespace Exiv2 { #ifdef DEBUG std::cerr << "Reading TIFF file " << io_->path() << "\n"; #endif - if (io_->open() != 0) throw Error(9, io_->path(), strError()); + if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError()); IoCloser closer(*io_); // Ensure that this is the correct image type if (!isTiffType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "TIFF"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "TIFF"); } clearMetadata(); @@ -331,12 +331,12 @@ namespace Exiv2 { void TiffImage::printStructure(std::ostream& out, Exiv2::PrintStructureOption option,int depth) { - if (io_->open() != 0) throw Error(9, io_->path(), strError()); + if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError()); // Ensure that this is the correct image type if ( imageType() == ImageType::none ) if (!isTiffType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(15); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAJpeg); } io_->seek(0,BasicIo::beg); diff --git a/src/tiffimage_int.cpp b/src/tiffimage_int.cpp index e9f405fc..7cd6656d 100644 --- a/src/tiffimage_int.cpp +++ b/src/tiffimage_int.cpp @@ -1655,7 +1655,7 @@ namespace Exiv2 { { if (pData == 0 || size == 0) return TiffComponent::AutoPtr(0); if (!pHeader->read(pData, size) || pHeader->offset() >= size) { - throw Error(3, "TIFF"); + throw Error(kerNotAnImage, "TIFF"); } TiffComponent::AutoPtr rootDir = TiffCreator::create(root, ifdIdNotSet); if (0 != rootDir.get()) { diff --git a/src/tiffmn-test.cpp b/src/tiffmn-test.cpp index 87b17e84..95a975f0 100644 --- a/src/tiffmn-test.cpp +++ b/src/tiffmn-test.cpp @@ -193,7 +193,7 @@ void print(const ExifData& exifData) { if (exifData.empty()) { std::string error("No Exif data found in the file"); - throw Exiv2::Error(1, error); + throw Exiv2::Error(kerErrorMessage, error); } Exiv2::ExifData::const_iterator end = exifData.end(); for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) { diff --git a/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index c6e5f84f..f993efba 100644 --- a/src/tiffvisitor_int.cpp +++ b/src/tiffvisitor_int.cpp @@ -1493,7 +1493,7 @@ namespace Exiv2 { uint32_t isize= 0; // size of Exif.Sony1.PreviewImage if (count > std::numeric_limits::max() / typeSize) { - throw Error(59); + throw Error(kerArithmeticOverflow); } uint32_t size = typeSize * count; uint32_t offset = getLong(p, byteOrder()); @@ -1523,10 +1523,10 @@ namespace Exiv2 { if ((static_cast(baseOffset()) > std::numeric_limits::max() - static_cast(offset)) || (static_cast(baseOffset() + offset) > std::numeric_limits::max() - reinterpret_cast(pData_))) { - throw Error(59); + throw Error(kerArithmeticOverflow); } if (pData_ + static_cast(baseOffset()) + static_cast(offset) > pLast_) { - throw Error(58); + throw Error(kerCorruptedMetadata); } pData = const_cast(pData_) + baseOffset() + offset; @@ -1551,7 +1551,7 @@ namespace Exiv2 { } Value::AutoPtr v = Value::create(typeId); if (!v.get()) { - throw Error(58); + throw Error(kerCorruptedMetadata); } if ( !isize ) { v->read(pData, size, byteOrder()); diff --git a/src/value.cpp b/src/value.cpp index dce6ff8f..7521cfe1 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -469,7 +469,7 @@ namespace Exiv2 { charsetId = CharsetInfo::charsetIdByName(name); if (charsetId == invalidCharsetId) { #ifndef SUPPRESS_WARNINGS - EXV_WARNING << Error(28, name) << "\n"; + EXV_WARNING << Error(kerInvalidCharset, name) << "\n"; #endif return 1; } @@ -681,7 +681,7 @@ namespace Exiv2 { setXmpStruct(); } else { - throw Error(48, type); + throw Error(kerInvalidXmpText, type); } } value_ = b; @@ -927,7 +927,7 @@ namespace Exiv2 { // Hard coded to read Iptc style dates if (len != 8) { #ifndef SUPPRESS_WARNINGS - EXV_WARNING << Error(29) << "\n"; + EXV_WARNING << Error(kerUnsupportedDateFormat) << "\n"; #endif return 1; } @@ -938,7 +938,7 @@ namespace Exiv2 { &date_.year, &date_.month, &date_.day); if (scanned != 3) { #ifndef SUPPRESS_WARNINGS - EXV_WARNING << Error(29) << "\n"; + EXV_WARNING << Error(kerUnsupportedDateFormat) << "\n"; #endif return 1; } @@ -950,7 +950,7 @@ namespace Exiv2 { // Hard coded to read Iptc style dates if (buf.length() < 8) { #ifndef SUPPRESS_WARNINGS - EXV_WARNING << Error(29) << "\n"; + EXV_WARNING << Error(kerUnsupportedDateFormat) << "\n"; #endif return 1; } @@ -958,7 +958,7 @@ namespace Exiv2 { &date_.year, &date_.month, &date_.day); if (scanned != 3) { #ifndef SUPPRESS_WARNINGS - EXV_WARNING << Error(29) << "\n"; + EXV_WARNING << Error(kerUnsupportedDateFormat) << "\n"; #endif return 1; } @@ -1076,7 +1076,7 @@ namespace Exiv2 { if (rc) { rc = 1; #ifndef SUPPRESS_WARNINGS - EXV_WARNING << Error(30) << "\n"; + EXV_WARNING << Error(kerUnsupportedTimeFormat) << "\n"; #endif } return rc; @@ -1096,7 +1096,7 @@ namespace Exiv2 { if (rc) { rc = 1; #ifndef SUPPRESS_WARNINGS - EXV_WARNING << Error(30) << "\n"; + EXV_WARNING << Error(kerUnsupportedTimeFormat) << "\n"; #endif } return rc; diff --git a/src/webpimage.cpp b/src/webpimage.cpp index 2cac438e..d1fc73e7 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -100,13 +100,13 @@ namespace Exiv2 { { // not supported // just quietly ignore the request - // throw(Error(32, "IPTC metadata", "WebP")); + // throw(Error(kerInvalidSettingForImage, "IPTC metadata", "WebP")); } void WebPImage::setComment(const std::string& /*comment*/) { // not supported - throw(Error(32, "Image comment", "WebP")); + throw(Error(kerInvalidSettingForImage, "Image comment", "WebP")); } /* =========================================== */ @@ -114,7 +114,7 @@ namespace Exiv2 { void WebPImage::writeMetadata() { if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); BasicIo::AutoPtr tempIo(new MemIo); @@ -128,8 +128,8 @@ namespace Exiv2 { void WebPImage::doWriteMetadata(BasicIo& outIo) { - if (!io_->isopen()) throw Error(20); - if (!outIo.isopen()) throw Error(21); + if (!io_->isopen()) throw Error(kerInputDataReadFailed); + if (!outIo.isopen()) throw Error(kerImageWriteFailed); #ifdef DEBUG std::cout << "Writing metadata" << std::endl; @@ -144,7 +144,7 @@ namespace Exiv2 { /* Set up header */ if (outIo.write(data, WEBP_TAG_SIZE * 3) != WEBP_TAG_SIZE * 3) - throw Error(21); + throw Error(kerImageWriteFailed); /* Parse Chunks */ bool has_size = false; @@ -331,21 +331,21 @@ namespace Exiv2 { } if (outIo.write(chunkId.pData_, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) - throw Error(21); + throw Error(kerImageWriteFailed); if (outIo.write(size_buff, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) - throw Error(21); + throw Error(kerImageWriteFailed); if (outIo.write(payload.pData_, payload.size_) != payload.size_) - throw Error(21); + throw Error(kerImageWriteFailed); if (outIo.tell() % 2) { - if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(21); + if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(kerImageWriteFailed); } if (has_icc) { - if (outIo.write((const byte*)WEBP_CHUNK_HEADER_ICCP, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(21); + if (outIo.write((const byte*)WEBP_CHUNK_HEADER_ICCP, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(kerImageWriteFailed); ul2Data(data, (uint32_t) iccProfile_.size_, littleEndian); - if (outIo.write(data, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(21); + if (outIo.write(data, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(kerImageWriteFailed); if (outIo.write(iccProfile_.pData_, (long)iccProfile_.size_) != (long)iccProfile_.size_) { - throw Error(21); + throw Error(kerImageWriteFailed); } has_icc = false; } @@ -357,42 +357,42 @@ namespace Exiv2 { // Skip and add new data afterwards } else { if (outIo.write(chunkId.pData_, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) - throw Error(21); + throw Error(kerImageWriteFailed); if (outIo.write(size_buff, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) - throw Error(21); + throw Error(kerImageWriteFailed); if (outIo.write(payload.pData_, payload.size_) != payload.size_) - throw Error(21); + throw Error(kerImageWriteFailed); } // Encoder required to pad odd sized data with a null byte if (outIo.tell() % 2) { - if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(21); + if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(kerImageWriteFailed); } } if (has_exif) { - if (outIo.write((const byte*)WEBP_CHUNK_HEADER_EXIF, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(21); + if (outIo.write((const byte*)WEBP_CHUNK_HEADER_EXIF, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(kerImageWriteFailed); us2Data(data, (uint16_t) blob.size()+8, bigEndian); ul2Data(data, (uint32_t) blob.size(), littleEndian); - if (outIo.write(data, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(21); + if (outIo.write(data, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(kerImageWriteFailed); if (outIo.write((const byte*)&blob[0], static_cast(blob.size())) != (long)blob.size()) { - throw Error(21); + throw Error(kerImageWriteFailed); } if (outIo.tell() % 2) { - if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(21); + if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(kerImageWriteFailed); } } if (has_xmp) { - if (outIo.write((const byte*)WEBP_CHUNK_HEADER_XMP, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(21); + if (outIo.write((const byte*)WEBP_CHUNK_HEADER_XMP, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(kerImageWriteFailed); ul2Data(data, (uint32_t) xmpPacket().size(), littleEndian); - if (outIo.write(data, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(21); + if (outIo.write(data, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(kerImageWriteFailed); if (outIo.write((const byte*)xmpPacket().data(), static_cast(xmpPacket().size())) != (long)xmpPacket().size()) { - throw Error(21); + throw Error(kerImageWriteFailed); } if (outIo.tell() % 2) { - if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(21); + if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(kerImageWriteFailed); } } @@ -401,7 +401,7 @@ namespace Exiv2 { filesize = outIo.size() - 8; outIo.seek(4, BasicIo::beg); ul2Data(data, (uint32_t) filesize, littleEndian); - if (outIo.write(data, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(21); + if (outIo.write(data, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) throw Error(kerImageWriteFailed); } // WebPImage::writeMetadata @@ -410,12 +410,12 @@ namespace Exiv2 { void WebPImage::printStructure(std::ostream& out, PrintStructureOption option,int depth) { if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } // Ensure this is the correct image type if (!isWebPType(*io_, true)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "WEBP"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "WEBP"); } bool bPrint = option==kpsBasic || option==kpsRecursive; @@ -475,12 +475,12 @@ namespace Exiv2 { void WebPImage::readMetadata() { - if (io_->open() != 0) throw Error(9, io_->path(), strError()); + if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError()); IoCloser closer(*io_); // Ensure that this is the correct image type if (!isWebPType(*io_, true)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(15); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAJpeg); } clearMetadata(); @@ -775,13 +775,13 @@ namespace Exiv2 { byte size_buff[WEBP_TAG_SIZE]; ul2Data(size_buff, iccProfile_.size_, littleEndian); if (iIo.write((const byte*)WEBP_CHUNK_HEADER_VP8X, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) - throw Error(21); + throw Error(kerImageWriteFailed); if (iIo.write(size_buff, WEBP_TAG_SIZE) != WEBP_TAG_SIZE) - throw Error(21); + throw Error(kerImageWriteFailed); if (iIo.write(iccProfile_.pData_, iccProfile_.size_) != iccProfile_.size_) - throw Error(21); + throw Error(kerImageWriteFailed); if (iIo.tell() % 2) { - if (iIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(21); + if (iIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(kerImageWriteFailed); } has_icc = false; diff --git a/src/xmp.cpp b/src/xmp.cpp index 4208cb0d..f149d3f7 100644 --- a/src/xmp.cpp +++ b/src/xmp.cpp @@ -265,13 +265,13 @@ namespace Exiv2 { const Value& Xmpdatum::value() const { - if (p_->value_.get() == 0) throw Error(8); + if (p_->value_.get() == 0) throw Error(kerValueNotSet); return *p_->value_; } long Xmpdatum::copy(byte* /*buf*/, ByteOrder /*byteOrder*/) const { - throw Error(34, "Xmpdatum::copy"); + throw Error(kerFunctionNotSupported, "Xmpdatum::copy"); return 0; } @@ -506,7 +506,7 @@ namespace Exiv2 { SXMPMeta::DumpNamespaces(nsDumper,&dict); if (bInit) terminate(); } catch (const XMP_Error& e) { - throw Error(40, e.GetID(), e.GetErrMsg()); + throw Error(kerXMPToolkitError, e.GetID(), e.GetErrMsg()); } } #else @@ -539,7 +539,7 @@ namespace Exiv2 { #endif } catch (const XMP_Error& /* e */) { - // throw Error(40, e.GetID(), e.GetErrMsg()); + // throw Error(kerXMPToolkitError, e.GetID(), e.GetErrMsg()); } } // XmpParser::registerNs #else @@ -558,7 +558,7 @@ namespace Exiv2 { // SXMPMeta::DeleteNamespace(ns.c_str()); } catch (const XMP_Error& e) { - throw Error(40, e.GetID(), e.GetErrMsg()); + throw Error(kerXMPToolkitError, e.GetID(), e.GetErrMsg()); } #endif } // XmpParser::unregisterNs @@ -585,7 +585,7 @@ namespace Exiv2 { while (iter.Next(&schemaNs, &propPath, &propValue, &opt)) { printNode(schemaNs, propPath, propValue, opt); if (XMP_PropIsAlias(opt)) { - throw Error(47, schemaNs, propPath, propValue); + throw Error(kerAliasesNotSupported, schemaNs, propPath, propValue); continue; } if (XMP_NodeIsSchema(opt)) { @@ -594,7 +594,7 @@ namespace Exiv2 { if (XmpProperties::prefix(schemaNs).empty()) { std::string prefix; bool ret = meta.GetNamespacePrefix(schemaNs.c_str(), &prefix); - if (!ret) throw Error(45, schemaNs); + if (!ret) throw Error(kerSchemaNamespaceNotRegistered, schemaNs); prefix = prefix.substr(0, prefix.size() - 1); XmpProperties::registerNs(schemaNs, prefix); } @@ -612,7 +612,7 @@ namespace Exiv2 { if ( !haveNext || !XMP_PropIsSimple(opt) || !XMP_PropHasLang(opt)) { - throw Error(41, propPath, opt); + throw Error(kerDecodeLangAltPropertyFailed, propPath, opt); } const std::string text = propValue; // Get the language qualifier @@ -622,7 +622,7 @@ namespace Exiv2 { || !XMP_PropIsSimple(opt) || !XMP_PropIsQualifier(opt) || propPath.substr(propPath.size() - 8, 8) != "xml:lang") { - throw Error(42, propPath, opt); + throw Error(kerDecodeLangAltQualifierFailed, propPath, opt); } val->value_[propValue] = text; } @@ -677,14 +677,14 @@ namespace Exiv2 { continue; } // Don't let any node go by unnoticed - throw Error(39, key->key(), opt); + throw Error(kerUnhandledXmpNode, key->key(), opt); } // iterate through all XMP nodes return 0; } #ifndef SUPPRESS_WARNINGS catch (const XMP_Error& e) { - EXV_ERROR << Error(40, e.GetID(), e.GetErrMsg()) << "\n"; + EXV_ERROR << Error(kerXMPToolkitError, e.GetID(), e.GetErrMsg()) << "\n"; xmpData.clear(); return 3; } @@ -743,7 +743,7 @@ namespace Exiv2 { // Encode Lang Alt property const LangAltValue* la = dynamic_cast(&i->value()); - if (la == 0) throw Error(43, i->key()); + if (la == 0) throw Error(kerEncodeLangAltPropertyFailed, i->key()); int idx = 1; for ( LangAltValue::ValueType::const_iterator k = la->value_.begin() @@ -762,7 +762,7 @@ namespace Exiv2 { // Todo: Xmpdatum should have an XmpValue, not a Value const XmpValue* val = dynamic_cast(&i->value()); - if (val == 0) throw Error(52, i->key(), i->typeName()); + if (val == 0) throw Error(kerInvalidKeyXmpValue, i->key(), i->typeName()); options = xmpArrayOptionBits(val->xmpArrayType()) | xmpArrayOptionBits(val->xmpStruct()); if ( i->typeId() == xmpBag @@ -789,7 +789,7 @@ namespace Exiv2 { continue; } // Don't let any Xmpdatum go by unnoticed - throw Error(38, i->tagName(), i->typeName()); + throw Error(kerUnhandledXmpdatum, i->tagName(), i->typeName()); } std::string tmpPacket; meta.SerializeToBuffer(&tmpPacket, xmpFormatOptionBits(static_cast(formatFlags)), padding); // throws @@ -799,7 +799,7 @@ namespace Exiv2 { } #ifndef SUPPRESS_WARNINGS catch (const XMP_Error& e) { - EXV_ERROR << Error(40, e.GetID(), e.GetErrMsg()) << "\n"; + EXV_ERROR << Error(kerXMPToolkitError, e.GetID(), e.GetErrMsg()) << "\n"; return 3; } #else @@ -957,13 +957,13 @@ namespace { std::string property; std::string::size_type idx = propPath.find(':'); if (idx == std::string::npos) { - throw Exiv2::Error(44, propPath, schemaNs); + throw Exiv2::Error(Exiv2::kerPropertyNameIdentificationFailed, propPath, schemaNs); } // Don't worry about out_of_range, XMP parser takes care of this property = propPath.substr(idx + 1); std::string prefix = Exiv2::XmpProperties::prefix(schemaNs); if (prefix.empty()) { - throw Exiv2::Error(36, propPath, schemaNs); + throw Exiv2::Error(Exiv2::kerNoPrefixForNamespace, propPath, schemaNs); } return Exiv2::XmpKey::AutoPtr(new Exiv2::XmpKey(prefix, property)); } // makeXmpKey diff --git a/src/xmpdump.cpp b/src/xmpdump.cpp index ffef474e..1f8159fd 100644 --- a/src/xmpdump.cpp +++ b/src/xmpdump.cpp @@ -23,7 +23,7 @@ try { if (xmpPacket.empty()) { std::string error(argv[1]); error += ": No XMP packet found in the file"; - throw Exiv2::Error(1, error); + throw Exiv2::Error(kerErrorMessage, error); } std::cout << xmpPacket << "\n"; diff --git a/src/xmpsidecar.cpp b/src/xmpsidecar.cpp index 1fa66e73..ba298640 100644 --- a/src/xmpsidecar.cpp +++ b/src/xmpsidecar.cpp @@ -71,7 +71,7 @@ namespace Exiv2 { void XmpSidecar::setComment(const std::string& /*comment*/) { // not supported - throw(Error(32, "Image comment", "XMP")); + throw(Error(kerInvalidSettingForImage, "Image comment", "XMP")); } void XmpSidecar::readMetadata() @@ -80,13 +80,13 @@ namespace Exiv2 { std::cerr << "Reading XMP file " << io_->path() << "\n"; #endif if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); // Ensure that this is the correct image type if (!isXmpType(*io_, false)) { - if (io_->error() || io_->eof()) throw Error(14); - throw Error(3, "XMP"); + if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData); + throw Error(kerNotAnImage, "XMP"); } // Read the XMP packet from the IO stream std::string xmpPacket; @@ -96,7 +96,7 @@ namespace Exiv2 { while ((l = io_->read(buf, len)) > 0) { xmpPacket.append(reinterpret_cast(buf), l); } - if (io_->error()) throw Error(14); + if (io_->error()) throw Error(kerFailedToReadImageData); clearMetadata(); xmpPacket_ = xmpPacket; if (xmpPacket_.size() > 0 && XmpParser::decode(xmpData_, xmpPacket_)) { @@ -121,7 +121,7 @@ namespace Exiv2 { void XmpSidecar::writeMetadata() { if (io_->open() != 0) { - throw Error(9, io_->path(), strError()); + throw Error(kerDataSourceOpenFailed, io_->path(), strError()); } IoCloser closer(*io_); @@ -160,8 +160,8 @@ namespace Exiv2 { // Write XMP packet if ( tempIo->write(reinterpret_cast(xmpPacket_.data()), static_cast(xmpPacket_.size())) - != static_cast(xmpPacket_.size())) throw Error(21); - if (tempIo->error()) throw Error(21); + != static_cast(xmpPacket_.size())) throw Error(kerImageWriteFailed); + if (tempIo->error()) throw Error(kerImageWriteFailed); io_->close(); io_->transfer(*tempIo); // may throw }