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

« back to all changes in this revision

Viewing changes to samples/exifcomment.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
/*
 
3
  Abstract : Sample program showing how to set the Exif comment of an image,
 
4
             Exif.Photo.UserComment
 
5
 
 
6
  File:      exifcomment.cpp
 
7
  Version  : $Rev: 1271 $
 
8
  Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
 
9
  History  : 10-May-04, ahu: created
 
10
             16-Jan-05, ahu: updated using CommentValue and operator trickery
 
11
 */
 
12
// *****************************************************************************
 
13
// included header files
 
14
#include <exiv2/image.hpp>
 
15
#include <exiv2/exif.hpp>
 
16
#include <iostream>
 
17
#include <cassert>
 
18
 
 
19
// *****************************************************************************
 
20
// Main
 
21
int main(int argc, char* const argv[])
 
22
try {
 
23
 
 
24
    if (argc != 2) {
 
25
        std::cout << "Usage: " << argv[0] << " file\n";
 
26
        return 1;
 
27
    }
 
28
 
 
29
    Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[1]);
 
30
    assert (image.get() != 0);
 
31
    image->readMetadata();
 
32
    Exiv2::ExifData &exifData = image->exifData();
 
33
 
 
34
    /*
 
35
      Exiv2 uses a CommentValue for Exif user comments. The format of the
 
36
      comment string includes an optional charset specification at the beginning:
 
37
 
 
38
      [charset=["]Ascii|Jis|Unicode|Undefined["] ]comment
 
39
 
 
40
      Undefined is used as a default if the comment doesn't start with a charset
 
41
      definition.
 
42
 
 
43
      Following are a few examples of valid comments. The last one is written to
 
44
      the file.
 
45
     */
 
46
    exifData["Exif.Photo.UserComment"]
 
47
        = "charset=\"Unicode\" An Unicode Exif comment added with Exiv2";
 
48
    exifData["Exif.Photo.UserComment"]
 
49
        = "charset=\"Undefined\" An undefined Exif comment added with Exiv2";
 
50
    exifData["Exif.Photo.UserComment"]
 
51
        = "Another undefined Exif comment added with Exiv2";
 
52
    exifData["Exif.Photo.UserComment"]
 
53
        = "charset=Ascii An ASCII Exif comment added with Exiv2";
 
54
 
 
55
    std::cout << "Writing user comment '"
 
56
              << exifData["Exif.Photo.UserComment"]
 
57
              << "' back to the image\n";
 
58
 
 
59
    image->writeMetadata();
 
60
 
 
61
    return 0;
 
62
}
 
63
catch (Exiv2::AnyError& e) {
 
64
    std::cout << "Caught Exiv2 exception '" << e << "'\n";
 
65
    return -1;
 
66
}