~ubuntu-branches/debian/lenny/exiv2/lenny

« back to all changes in this revision

Viewing changes to samples/xmpparse.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2008-06-21 08:23:53 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080621082353-b1n4w08trwfwbfl4
Tags: 0.17.1-1
* New upstream release
  - Library transition cleared on debian-release/ d-d-a
* Version 0.17 also fixes:
  - CVE-2008-2696: DoS via metadata in images (Closes: #486328)
  - crashes when fed with wrong file (Closes: #485670)
* Urgency medium for CVE fix
* debian/patches/gcc4.3.diff unecessary for gcc-4.3
* Add /usr/share/bug/exiv2/presubj message for reportbug(1)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ***************************************************************** -*- C++ -*-
 
2
// xmpparse.cpp, $Rev: 1271 $
 
3
// Read an XMP packet from a file, parse it and print all (known) properties.
 
4
 
 
5
#include <exiv2/basicio.hpp>
 
6
#include <exiv2/xmp.hpp>
 
7
#include <exiv2/error.hpp>
 
8
 
 
9
#include <string>
 
10
#include <iostream>
 
11
#include <iomanip>
 
12
 
 
13
int main(int argc, char* const argv[])
 
14
try {
 
15
    if (argc != 2) {
 
16
        std::cout << "Usage: " << argv[0] << " file\n";
 
17
        return 1;
 
18
    }
 
19
    Exiv2::DataBuf buf = Exiv2::readFile(argv[1]);
 
20
    std::string xmpPacket;
 
21
    xmpPacket.assign(reinterpret_cast<char*>(buf.pData_), buf.size_);
 
22
    Exiv2::XmpData xmpData;
 
23
    if (0 != Exiv2::XmpParser::decode(xmpData, xmpPacket)) {
 
24
        std::string error(argv[1]);
 
25
        error += ": Failed to parse file contents (XMP packet)";
 
26
        throw Exiv2::Error(1, error);
 
27
    }
 
28
    if (xmpData.empty()) {
 
29
        std::string error(argv[1]);
 
30
        error += ": No XMP properties found in the XMP packet";
 
31
        throw Exiv2::Error(1, error);
 
32
    }
 
33
    for (Exiv2::XmpData::const_iterator md = xmpData.begin(); 
 
34
         md != xmpData.end(); ++md) {
 
35
        std::cout << std::setfill(' ') << std::left
 
36
                  << std::setw(44)
 
37
                  << md->key() << " "
 
38
                  << std::setw(9) << std::setfill(' ') << std::left
 
39
                  << md->typeName() << " "
 
40
                  << std::dec << std::setw(3)
 
41
                  << std::setfill(' ') << std::right
 
42
                  << md->count() << "  "
 
43
                  << std::dec << md->value()
 
44
                  << std::endl;
 
45
    }
 
46
    Exiv2::XmpParser::terminate();
 
47
    return 0;
 
48
}
 
49
catch (Exiv2::AnyError& e) {
 
50
    std::cout << "Caught Exiv2 exception '" << e << "'\n";
 
51
    return -1;
 
52
}