diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-12-18 19:45:02 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-12-18 19:45:02 +0000 |
commit | f3eef358ddd8beb04752e2a3e84a576f61f94897 (patch) | |
tree | 386e52965686933e379fb807632156cbb3b884f4 | |
parent | b469f81946127562c859a5c349476af165920ae1 (diff) | |
download | libextractor-f3eef358ddd8beb04752e2a3e84a576f61f94897.tar.gz libextractor-f3eef358ddd8beb04752e2a3e84a576f61f94897.zip |
png
-rw-r--r-- | src/include/extractor.h | 9 | ||||
-rw-r--r-- | src/main/extractor_metatypes.c | 9 | ||||
-rw-r--r-- | src/plugins/Makefile.am | 19 | ||||
-rw-r--r-- | src/plugins/png_extractor.c (renamed from src/plugins/pngextractor.c) | 240 |
4 files changed, 153 insertions, 124 deletions
diff --git a/src/include/extractor.h b/src/include/extractor.h index 08a582a..0b7ff05 100644 --- a/src/include/extractor.h +++ b/src/include/extractor.h | |||
@@ -272,6 +272,12 @@ enum EXTRACTOR_MetaType | |||
272 | EXTRACTOR_METATYPE_EVENT_PICTURE = 140, | 272 | EXTRACTOR_METATYPE_EVENT_PICTURE = 140, |
273 | EXTRACTOR_METATYPE_LOGO = 141, | 273 | EXTRACTOR_METATYPE_LOGO = 141, |
274 | EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM = 142, | 274 | EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM = 142, |
275 | EXTRACTOR_METATYPE_SOURCE_DEVICE = 143, | ||
276 | EXTRACTOR_METATYPE_DISCLAIMER = 144, | ||
277 | EXTRACTOR_METATYPE_WARNING = 145, | ||
278 | |||
279 | |||
280 | /* fixme: used up to here! */ | ||
275 | 281 | ||
276 | EXTRACTOR_METATYPE_LYRICS = 67, | 282 | EXTRACTOR_METATYPE_LYRICS = 67, |
277 | EXTRACTOR_METATYPE_CONDUCTOR = 64, | 283 | EXTRACTOR_METATYPE_CONDUCTOR = 64, |
@@ -283,7 +289,6 @@ enum EXTRACTOR_MetaType | |||
283 | EXTRACTOR_METATYPE_MUSICIAN_CREDITS_LIST = 123, | 289 | EXTRACTOR_METATYPE_MUSICIAN_CREDITS_LIST = 123, |
284 | 290 | ||
285 | 291 | ||
286 | /* fixme: used up to here! */ | ||
287 | EXTRACTOR_METATYPE_SCALE = 108, | 292 | EXTRACTOR_METATYPE_SCALE = 108, |
288 | 293 | ||
289 | 294 | ||
@@ -309,7 +314,6 @@ enum EXTRACTOR_MetaType | |||
309 | EXTRACTOR_METATYPE_ENCODED_BY = 121, | 314 | EXTRACTOR_METATYPE_ENCODED_BY = 121, |
310 | EXTRACTOR_METATYPE_PROUCUCTVERSION = 90, | 315 | EXTRACTOR_METATYPE_PROUCUCTVERSION = 90, |
311 | 316 | ||
312 | EXTRACTOR_METATYPE_DISCLAIMER = 27, | ||
313 | EXTRACTOR_METATYPE_FULL_DATA = 137, | 317 | EXTRACTOR_METATYPE_FULL_DATA = 137, |
314 | 318 | ||
315 | EXTRACTOR_METATYPE_ORGANIZATION = 15, | 319 | EXTRACTOR_METATYPE_ORGANIZATION = 15, |
@@ -317,7 +321,6 @@ enum EXTRACTOR_MetaType | |||
317 | EXTRACTOR_METATYPE_RELATION = 24, | 321 | EXTRACTOR_METATYPE_RELATION = 24, |
318 | EXTRACTOR_METATYPE_COVERAGE = 25, | 322 | EXTRACTOR_METATYPE_COVERAGE = 25, |
319 | EXTRACTOR_METATYPE_SOFTWARE = 26, | 323 | EXTRACTOR_METATYPE_SOFTWARE = 26, |
320 | EXTRACTOR_METATYPE_WARNING = 28, | ||
321 | EXTRACTOR_METATYPE_TRANSLATED = 29, | 324 | EXTRACTOR_METATYPE_TRANSLATED = 29, |
322 | EXTRACTOR_METATYPE_PRODUCER = 33, | 325 | EXTRACTOR_METATYPE_PRODUCER = 33, |
323 | EXTRACTOR_METATYPE_CREATED_FOR = 39, | 326 | EXTRACTOR_METATYPE_CREATED_FOR = 39, |
diff --git a/src/main/extractor_metatypes.c b/src/main/extractor_metatypes.c index 48c659d..26e2ef2 100644 --- a/src/main/extractor_metatypes.c +++ b/src/main/extractor_metatypes.c | |||
@@ -351,6 +351,15 @@ static const struct MetaTypeDescription meta_type_descriptions[] = { | |||
351 | gettext_noop ("logo of an associated organization") }, | 351 | gettext_noop ("logo of an associated organization") }, |
352 | { gettext_noop ("broadcast television system"), | 352 | { gettext_noop ("broadcast television system"), |
353 | gettext_noop ("name of the television system for which the data is coded") }, | 353 | gettext_noop ("name of the television system for which the data is coded") }, |
354 | { gettext_noop ("source device"), | ||
355 | gettext_noop ("device used to create the object") }, | ||
356 | { gettext_noop ("disclaimer"), | ||
357 | gettext_noop ("legal disclaimer") }, | ||
358 | /* 145 */ | ||
359 | { gettext_noop ("warning"), | ||
360 | gettext_noop ("warning about the nature of the content") }, | ||
361 | { gettext_noop (""), | ||
362 | gettext_noop ("") }, | ||
354 | { gettext_noop (""), | 363 | { gettext_noop (""), |
355 | gettext_noop ("") }, | 364 | gettext_noop ("") }, |
356 | { gettext_noop (""), | 365 | { gettext_noop (""), |
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 4d4603a..cc44f8b 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am | |||
@@ -87,6 +87,7 @@ plugin_LTLIBRARIES = \ | |||
87 | $(ogg) \ | 87 | $(ogg) \ |
88 | $(ole2) \ | 88 | $(ole2) \ |
89 | $(pdf) \ | 89 | $(pdf) \ |
90 | libextractor_png.la \ | ||
90 | libextractor_real.la \ | 91 | libextractor_real.la \ |
91 | $(rpm) \ | 92 | $(rpm) \ |
92 | libextractor_tar.la \ | 93 | libextractor_tar.la \ |
@@ -234,6 +235,14 @@ libextractor_pdf_la_LIBADD = \ | |||
234 | $(top_builddir)/src/common/libextractor_common.la \ | 235 | $(top_builddir)/src/common/libextractor_common.la \ |
235 | -lpoppler | 236 | -lpoppler |
236 | 237 | ||
238 | libextractor_png_la_SOURCES = \ | ||
239 | png_extractor.c | ||
240 | libextractor_png_la_LDFLAGS = \ | ||
241 | $(PLUGINFLAGS) | ||
242 | libextractor_png_la_LIBADD = \ | ||
243 | $(top_builddir)/src/common/libextractor_common.la \ | ||
244 | -lz | ||
245 | |||
237 | libextractor_real_la_SOURCES = \ | 246 | libextractor_real_la_SOURCES = \ |
238 | real_extractor.c | 247 | real_extractor.c |
239 | libextractor_real_la_LDFLAGS = \ | 248 | libextractor_real_la_LDFLAGS = \ |
@@ -288,7 +297,6 @@ OLD_LIBS = \ | |||
288 | $(extrampeg) \ | 297 | $(extrampeg) \ |
289 | libextractor_nsf.la \ | 298 | libextractor_nsf.la \ |
290 | libextractor_nsfe.la \ | 299 | libextractor_nsfe.la \ |
291 | libextractor_png.la \ | ||
292 | libextractor_ps.la \ | 300 | libextractor_ps.la \ |
293 | $(extraqt) \ | 301 | $(extraqt) \ |
294 | libextractor_riff.la \ | 302 | libextractor_riff.la \ |
@@ -353,15 +361,6 @@ libextractor_riff_la_LIBADD = \ | |||
353 | $(LE_LIBINTL) \ | 361 | $(LE_LIBINTL) \ |
354 | -lm | 362 | -lm |
355 | 363 | ||
356 | libextractor_png_la_SOURCES = \ | ||
357 | pngextractor.c | ||
358 | libextractor_png_la_LDFLAGS = \ | ||
359 | $(PLUGINFLAGS) | ||
360 | libextractor_png_la_LIBADD = \ | ||
361 | $(top_builddir)/src/common/libextractor_common.la \ | ||
362 | $(top_builddir)/src/main/libextractor.la \ | ||
363 | -lz | ||
364 | |||
365 | libextractor_sid_la_SOURCES = \ | 364 | libextractor_sid_la_SOURCES = \ |
366 | sidextractor.c | 365 | sidextractor.c |
367 | libextractor_sid_la_LDFLAGS = \ | 366 | libextractor_sid_la_LDFLAGS = \ |
diff --git a/src/plugins/pngextractor.c b/src/plugins/png_extractor.c index 991afa2..5fb2b9d 100644 --- a/src/plugins/pngextractor.c +++ b/src/plugins/png_extractor.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libextractor. | 2 | This file is part of libextractor. |
3 | (C) 2002, 2003, 2004, 2005 Vidyut Samanta and Christian Grothoff | 3 | (C) 2002, 2003, 2004, 2005, 2009 Vidyut Samanta and Christian Grothoff |
4 | 4 | ||
5 | libextractor is free software; you can redistribute it and/or modify | 5 | libextractor is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -47,20 +47,6 @@ stnlen (const char *str, size_t maxlen) | |||
47 | return ret; | 47 | return ret; |
48 | } | 48 | } |
49 | 49 | ||
50 | static struct EXTRACTOR_Keywords * | ||
51 | addKeyword (EXTRACTOR_KeywordType type, | ||
52 | char *keyword, struct EXTRACTOR_Keywords *next) | ||
53 | { | ||
54 | EXTRACTOR_KeywordList *result; | ||
55 | |||
56 | if (keyword == NULL) | ||
57 | return next; | ||
58 | result = malloc (sizeof (EXTRACTOR_KeywordList)); | ||
59 | result->next = next; | ||
60 | result->keyword = keyword; | ||
61 | result->keywordType = type; | ||
62 | return result; | ||
63 | } | ||
64 | 50 | ||
65 | static int | 51 | static int |
66 | getIntAt (const void *pos) | 52 | getIntAt (const void *pos) |
@@ -75,61 +61,65 @@ getIntAt (const void *pos) | |||
75 | static struct | 61 | static struct |
76 | { | 62 | { |
77 | char *name; | 63 | char *name; |
78 | EXTRACTOR_KeywordType type; | 64 | enum EXTRACTOR_MetaType type; |
79 | } tagmap[] = | 65 | } tagmap[] = |
80 | { | 66 | { |
81 | { | 67 | { "Author", EXTRACTOR_METATYPE_AUTHOR_NAME}, |
82 | "Author", EXTRACTOR_AUTHOR}, | 68 | { "Description", EXTRACTOR_METATYPE_DESCRIPTION}, |
83 | { | 69 | { "Comment", EXTRACTOR_METATYPE_COMMENT}, |
84 | "Description", EXTRACTOR_DESCRIPTION}, | 70 | { "Copyright", EXTRACTOR_METATYPE_COPYRIGHT}, |
85 | { | 71 | { "Source", EXTRACTOR_METATYPE_SOURCE_DEVICE }, |
86 | "Comment", EXTRACTOR_COMMENT}, | 72 | { "Creation Time", EXTRACTOR_METATYPE_CREATION_DATE}, |
87 | { | 73 | { "Title", EXTRACTOR_METATYPE_TITLE}, |
88 | "Copyright", EXTRACTOR_COPYRIGHT}, | 74 | { "Software", EXTRACTOR_METATYPE_PRODUCED_BY_SOFTWARE}, |
89 | { | 75 | { "Disclaimer", EXTRACTOR_METATYPE_DISCLAIMER}, |
90 | "Source", EXTRACTOR_SOURCE}, | 76 | { "Warning", EXTRACTOR_METATYPE_WARNING}, |
91 | { | 77 | { NULL, EXTRACTOR_METATYPE_RESERVED } |
92 | "Creation Time", EXTRACTOR_CREATION_DATE}, | 78 | }; |
93 | { | 79 | |
94 | "Title", EXTRACTOR_TITLE}, | 80 | |
95 | { | 81 | #define ADD(t,s) do { if (0 != (ret = proc (proc_cls, "tar", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1))) goto FINISH; } while (0) |
96 | "Software", EXTRACTOR_SOFTWARE}, | 82 | #define ADDF(t,s) do { if (0 != (ret = proc (proc_cls, "tar", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1))) { free(s); goto FINISH; } free (s); } while (0) |
97 | { | 83 | |
98 | "Disclaimer", EXTRACTOR_DISCLAIMER}, | 84 | |
99 | { | 85 | static int |
100 | "Warning", EXTRACTOR_WARNING}, | ||
101 | { | ||
102 | "Signature", EXTRACTOR_RESOURCE_IDENTIFIER}, | ||
103 | { | ||
104 | NULL, EXTRACTOR_UNKNOWN},}; | ||
105 | |||
106 | static struct EXTRACTOR_Keywords * | ||
107 | processtEXt (const char *data, | 86 | processtEXt (const char *data, |
108 | unsigned int length, struct EXTRACTOR_Keywords *prev) | 87 | unsigned int length, |
88 | EXTRACTOR_MetaDataProcessor proc, | ||
89 | void *proc_cls) | ||
109 | { | 90 | { |
110 | char *keyword; | 91 | char *keyword; |
111 | unsigned int off; | 92 | unsigned int off; |
112 | int i; | 93 | int i; |
94 | int ret; | ||
113 | 95 | ||
114 | data += 4; | 96 | data += 4; |
115 | off = stnlen (data, length) + 1; | 97 | off = stnlen (data, length) + 1; |
116 | if (off >= length) | 98 | if (off >= length) |
117 | return prev; /* failed to find '\0' */ | 99 | return 0; /* failed to find '\0' */ |
118 | keyword = EXTRACTOR_common_convert_to_utf8 (&data[off], length - off, "ISO-8859-1"); | 100 | keyword = EXTRACTOR_common_convert_to_utf8 (&data[off], length - off, "ISO-8859-1"); |
119 | i = 0; | 101 | i = 0; |
102 | ret = 0; | ||
120 | while (tagmap[i].name != NULL) | 103 | while (tagmap[i].name != NULL) |
121 | { | 104 | { |
122 | if (0 == strcmp (tagmap[i].name, data)) | 105 | if (0 == strcmp (tagmap[i].name, data)) |
123 | return addKeyword (tagmap[i].type, keyword, prev); | 106 | { |
107 | ADDF (tagmap[i].type, keyword); | ||
108 | return 0; | ||
109 | } | ||
124 | 110 | ||
125 | i++; | 111 | i++; |
126 | } | 112 | } |
127 | return addKeyword (EXTRACTOR_UNKNOWN, keyword, prev); | 113 | ADDF (EXTRACTOR_METATYPE_KEYWORDS, keyword); |
114 | FINISH: | ||
115 | return ret; | ||
128 | } | 116 | } |
129 | 117 | ||
130 | static struct EXTRACTOR_Keywords * | 118 | static int |
131 | processiTXt (const char *data, | 119 | processiTXt (const char *data, |
132 | unsigned int length, struct EXTRACTOR_Keywords *prev) | 120 | unsigned int length, |
121 | EXTRACTOR_MetaDataProcessor proc, | ||
122 | void *proc_cls) | ||
133 | { | 123 | { |
134 | unsigned int pos; | 124 | unsigned int pos; |
135 | char *keyword; | 125 | char *keyword; |
@@ -140,27 +130,29 @@ processiTXt (const char *data, | |||
140 | char *buf; | 130 | char *buf; |
141 | uLongf bufLen; | 131 | uLongf bufLen; |
142 | int ret; | 132 | int ret; |
133 | int zret; | ||
143 | 134 | ||
144 | pos = stnlen (data, length) + 1; | 135 | pos = stnlen (data, length) + 1; |
145 | if (pos + 3 >= length) | 136 | if (pos + 3 >= length) |
146 | return prev; | 137 | return 0; |
147 | compressed = data[pos++]; | 138 | compressed = data[pos++]; |
148 | if (compressed && (data[pos++] != 0)) | 139 | if (compressed && (data[pos++] != 0)) |
149 | return prev; /* bad compression method */ | 140 | return 0; /* bad compression method */ |
150 | language = &data[pos]; | 141 | language = &data[pos]; |
142 | ret = 0; | ||
151 | if (stnlen (language, length - pos) > 0) | 143 | if (stnlen (language, length - pos) > 0) |
152 | prev = addKeyword (EXTRACTOR_LANGUAGE, | 144 | ADDF (EXTRACTOR_METATYPE_DOCUMENT_LANGUAGE, |
153 | stndup (language, length - pos), prev); | 145 | stndup (language, length - pos)); |
154 | pos += stnlen (language, length - pos) + 1; | 146 | pos += stnlen (language, length - pos) + 1; |
155 | if (pos + 1 >= length) | 147 | if (pos + 1 >= length) |
156 | return prev; | 148 | return 0; |
157 | translated = &data[pos]; /* already in utf-8! */ | 149 | translated = &data[pos]; /* already in utf-8! */ |
158 | if (stnlen (translated, length - pos) > 0) | 150 | if (stnlen (translated, length - pos) > 0) |
159 | prev = addKeyword (EXTRACTOR_TRANSLATED, | 151 | ADDF (EXTRACTOR_METATYPE_KEYWORDS, |
160 | stndup (translated, length - pos), prev); | 152 | stndup (translated, length - pos)); |
161 | pos += stnlen (translated, length - pos) + 1; | 153 | pos += stnlen (translated, length - pos) + 1; |
162 | if (pos >= length) | 154 | if (pos >= length) |
163 | return prev; | 155 | return 0; |
164 | 156 | ||
165 | if (compressed) | 157 | if (compressed) |
166 | { | 158 | { |
@@ -168,30 +160,30 @@ processiTXt (const char *data, | |||
168 | while (1) | 160 | while (1) |
169 | { | 161 | { |
170 | if (bufLen * 2 < bufLen) | 162 | if (bufLen * 2 < bufLen) |
171 | return prev; | 163 | return 0; |
172 | bufLen *= 2; | 164 | bufLen *= 2; |
173 | if (bufLen > 50 * (length - pos)) | 165 | if (bufLen > 50 * (length - pos)) |
174 | { | 166 | { |
175 | /* printf("zlib problem"); */ | 167 | /* printf("zlib problem"); */ |
176 | return prev; | 168 | return 0; |
177 | } | 169 | } |
178 | buf = malloc (bufLen); | 170 | buf = malloc (bufLen); |
179 | if (buf == NULL) | 171 | if (buf == NULL) |
180 | { | 172 | { |
181 | /* printf("out of memory"); */ | 173 | /* printf("out of memory"); */ |
182 | return prev; /* out of memory */ | 174 | return 0; /* out of memory */ |
183 | } | 175 | } |
184 | ret = uncompress ((Bytef *) buf, | 176 | zret = uncompress ((Bytef *) buf, |
185 | &bufLen, | 177 | &bufLen, |
186 | (const Bytef *) &data[pos], length - pos); | 178 | (const Bytef *) &data[pos], length - pos); |
187 | if (ret == Z_OK) | 179 | if (zret == Z_OK) |
188 | { | 180 | { |
189 | /* printf("zlib ok"); */ | 181 | /* printf("zlib ok"); */ |
190 | break; | 182 | break; |
191 | } | 183 | } |
192 | free (buf); | 184 | free (buf); |
193 | if (ret != Z_BUF_ERROR) | 185 | if (zret != Z_BUF_ERROR) |
194 | return prev; /* unknown error, abort */ | 186 | return 0; /* unknown error, abort */ |
195 | } | 187 | } |
196 | keyword = stndup (buf, bufLen); | 188 | keyword = stndup (buf, bufLen); |
197 | free (buf); | 189 | free (buf); |
@@ -204,33 +196,44 @@ processiTXt (const char *data, | |||
204 | while (tagmap[i].name != NULL) | 196 | while (tagmap[i].name != NULL) |
205 | { | 197 | { |
206 | if (0 == strcmp (tagmap[i].name, data)) | 198 | if (0 == strcmp (tagmap[i].name, data)) |
207 | return addKeyword (tagmap[i].type, keyword, /* already in utf-8 */ | 199 | { |
208 | prev); | 200 | ADDF (tagmap[i].type, keyword /* already in utf8 */); |
201 | return 0; | ||
202 | } | ||
209 | i++; | 203 | i++; |
210 | } | 204 | } |
211 | return addKeyword (EXTRACTOR_UNKNOWN, keyword, prev); | 205 | ADDF (EXTRACTOR_METATYPE_COMMENT, keyword); |
206 | FINISH: | ||
207 | return ret; | ||
212 | } | 208 | } |
213 | 209 | ||
214 | static struct EXTRACTOR_Keywords * | 210 | |
211 | static int | ||
215 | processIHDR (const char *data, | 212 | processIHDR (const char *data, |
216 | unsigned int length, struct EXTRACTOR_Keywords *prev) | 213 | unsigned int length, |
214 | EXTRACTOR_MetaDataProcessor proc, | ||
215 | void *proc_cls) | ||
217 | { | 216 | { |
218 | char *tmp; | 217 | char tmp[128]; |
218 | int ret; | ||
219 | 219 | ||
220 | if (length < 12) | 220 | if (length < 12) |
221 | return prev; | 221 | return 0; |
222 | 222 | ret = 0; | |
223 | tmp = malloc (128); | ||
224 | snprintf (tmp, | 223 | snprintf (tmp, |
225 | 128, | 224 | sizeof(tmp), |
226 | "%ux%u", | 225 | "%ux%u", |
227 | htonl (getIntAt (&data[4])), htonl (getIntAt (&data[8]))); | 226 | htonl (getIntAt (&data[4])), htonl (getIntAt (&data[8]))); |
228 | return addKeyword (EXTRACTOR_SIZE, tmp, prev); | 227 | ADD (EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, tmp); |
228 | FINISH: | ||
229 | return ret; | ||
229 | } | 230 | } |
230 | 231 | ||
231 | static struct EXTRACTOR_Keywords * | 232 | static int |
232 | processzTXt (const char *data, | 233 | processzTXt (const char *data, |
233 | unsigned int length, struct EXTRACTOR_Keywords *prev) | 234 | unsigned int length, |
235 | EXTRACTOR_MetaDataProcessor proc, | ||
236 | void *proc_cls) | ||
234 | { | 237 | { |
235 | char *keyword; | 238 | char *keyword; |
236 | unsigned int off; | 239 | unsigned int off; |
@@ -238,42 +241,43 @@ processzTXt (const char *data, | |||
238 | char *buf; | 241 | char *buf; |
239 | uLongf bufLen; | 242 | uLongf bufLen; |
240 | int ret; | 243 | int ret; |
244 | int zret; | ||
241 | 245 | ||
242 | data += 4; | 246 | data += 4; |
243 | off = stnlen (data, length) + 1; | 247 | off = stnlen (data, length) + 1; |
244 | if (off >= length) | 248 | if (off >= length) |
245 | return prev; /* failed to find '\0' */ | 249 | return 0; /* failed to find '\0' */ |
246 | if (data[off] != 0) | 250 | if (data[off] != 0) |
247 | return prev; /* compression method must be 0 */ | 251 | return 0; /* compression method must be 0 */ |
248 | off++; | 252 | off++; |
249 | 253 | ||
250 | bufLen = 1024 + 2 * (length - off); | 254 | bufLen = 1024 + 2 * (length - off); |
251 | while (1) | 255 | while (1) |
252 | { | 256 | { |
253 | if (bufLen * 2 < bufLen) | 257 | if (bufLen * 2 < bufLen) |
254 | return prev; | 258 | return 0; |
255 | bufLen *= 2; | 259 | bufLen *= 2; |
256 | if (bufLen > 50 * (length - off)) | 260 | if (bufLen > 50 * (length - off)) |
257 | { | 261 | { |
258 | /* printf("zlib problem"); */ | 262 | /* printf("zlib problem"); */ |
259 | return prev; | 263 | return 0; |
260 | } | 264 | } |
261 | buf = malloc (bufLen); | 265 | buf = malloc (bufLen); |
262 | if (buf == NULL) | 266 | if (buf == NULL) |
263 | { | 267 | { |
264 | /* printf("out of memory"); */ | 268 | /* printf("out of memory"); */ |
265 | return prev; /* out of memory */ | 269 | return 0; /* out of memory */ |
266 | } | 270 | } |
267 | ret = uncompress ((Bytef *) buf, | 271 | zret = uncompress ((Bytef *) buf, |
268 | &bufLen, (const Bytef *) &data[off], length - off); | 272 | &bufLen, (const Bytef *) &data[off], length - off); |
269 | if (ret == Z_OK) | 273 | if (zret == Z_OK) |
270 | { | 274 | { |
271 | /* printf("zlib ok"); */ | 275 | /* printf("zlib ok"); */ |
272 | break; | 276 | break; |
273 | } | 277 | } |
274 | free (buf); | 278 | free (buf); |
275 | if (ret != Z_BUF_ERROR) | 279 | if (zret != Z_BUF_ERROR) |
276 | return prev; /* unknown error, abort */ | 280 | return 0; /* unknown error, abort */ |
277 | } | 281 | } |
278 | keyword = EXTRACTOR_common_convert_to_utf8 (buf, bufLen, "ISO-8859-1"); | 282 | keyword = EXTRACTOR_common_convert_to_utf8 (buf, bufLen, "ISO-8859-1"); |
279 | free (buf); | 283 | free (buf); |
@@ -281,16 +285,22 @@ processzTXt (const char *data, | |||
281 | while (tagmap[i].name != NULL) | 285 | while (tagmap[i].name != NULL) |
282 | { | 286 | { |
283 | if (0 == strcmp (tagmap[i].name, data)) | 287 | if (0 == strcmp (tagmap[i].name, data)) |
284 | return addKeyword (tagmap[i].type, keyword, prev); | 288 | { |
285 | 289 | ADDF (tagmap[i].type, keyword); | |
290 | return 0; | ||
291 | } | ||
286 | i++; | 292 | i++; |
287 | } | 293 | } |
288 | return addKeyword (EXTRACTOR_UNKNOWN, keyword, prev); | 294 | ADDF (EXTRACTOR_METATYPE_COMMENT, keyword); |
295 | FINISH: | ||
296 | return ret; | ||
289 | } | 297 | } |
290 | 298 | ||
291 | static struct EXTRACTOR_Keywords * | 299 | static int |
292 | processtIME (const char *data, | 300 | processtIME (const char *data, |
293 | unsigned int length, struct EXTRACTOR_Keywords *prev) | 301 | unsigned int length, |
302 | EXTRACTOR_MetaDataProcessor proc, | ||
303 | void *proc_cls) | ||
294 | { | 304 | { |
295 | unsigned short y; | 305 | unsigned short y; |
296 | unsigned int year; | 306 | unsigned int year; |
@@ -300,9 +310,11 @@ processtIME (const char *data, | |||
300 | unsigned int m; | 310 | unsigned int m; |
301 | unsigned int s; | 311 | unsigned int s; |
302 | char val[256]; | 312 | char val[256]; |
313 | int ret; | ||
303 | 314 | ||
304 | if (length != 7) | 315 | if (length != 7) |
305 | return prev; | 316 | return 0; |
317 | ret = 0; | ||
306 | memcpy (&y, &data[4], sizeof (unsigned short)); | 318 | memcpy (&y, &data[4], sizeof (unsigned short)); |
307 | year = ntohs (y); | 319 | year = ntohs (y); |
308 | mo = (unsigned char) data[6]; | 320 | mo = (unsigned char) data[6]; |
@@ -310,33 +322,39 @@ processtIME (const char *data, | |||
310 | h = (unsigned char) data[8]; | 322 | h = (unsigned char) data[8]; |
311 | m = (unsigned char) data[9]; | 323 | m = (unsigned char) data[9]; |
312 | s = (unsigned char) data[10]; | 324 | s = (unsigned char) data[10]; |
313 | sprintf (val, "%04u-%02u-%02u %02d:%02d:%02d", year, mo, day, h, m, s); | 325 | snprintf (val, |
314 | return addKeyword (EXTRACTOR_MODIFICATION_DATE, strdup (val), prev); | 326 | sizeof(val), |
327 | "%04u-%02u-%02u %02d:%02d:%02d", year, mo, day, h, m, s); | ||
328 | ADD (EXTRACTOR_METATYPE_MODIFICATION_DATE, val); | ||
329 | FINISH: | ||
330 | return ret; | ||
315 | } | 331 | } |
316 | 332 | ||
317 | #define PNG_HEADER "\211PNG\r\n\032\n" | 333 | #define PNG_HEADER "\211PNG\r\n\032\n" |
318 | 334 | ||
319 | 335 | ||
320 | 336 | ||
321 | struct EXTRACTOR_Keywords * | 337 | int |
322 | libextractor_png_extract (const char *filename, | 338 | EXTRACTOR_png_extract (const char *data, |
323 | const char *data, | 339 | size_t size, |
324 | size_t size, struct EXTRACTOR_Keywords *prev) | 340 | EXTRACTOR_MetaDataProcessor proc, |
341 | void *proc_cls, | ||
342 | const char *options) | ||
325 | { | 343 | { |
326 | const char *pos; | 344 | const char *pos; |
327 | const char *end; | 345 | const char *end; |
328 | struct EXTRACTOR_Keywords *result; | ||
329 | unsigned int length; | 346 | unsigned int length; |
347 | int ret; | ||
330 | 348 | ||
331 | if (size < strlen (PNG_HEADER)) | 349 | if (size < strlen (PNG_HEADER)) |
332 | return prev; | 350 | return 0; |
333 | if (0 != strncmp (data, PNG_HEADER, strlen (PNG_HEADER))) | 351 | if (0 != strncmp (data, PNG_HEADER, strlen (PNG_HEADER))) |
334 | return prev; | 352 | return 0; |
335 | result = prev; | ||
336 | end = &data[size]; | 353 | end = &data[size]; |
337 | pos = &data[strlen (PNG_HEADER)]; | 354 | pos = &data[strlen (PNG_HEADER)]; |
338 | result = addKeyword (EXTRACTOR_MIMETYPE, strdup ("image/png"), result); | 355 | ADD (EXTRACTOR_METATYPE_MIMETYPE, "image/png"); |
339 | while (1) | 356 | ret = 0; |
357 | while (ret == 0) | ||
340 | { | 358 | { |
341 | if (pos + 12 >= end) | 359 | if (pos + 12 >= end) |
342 | break; | 360 | break; |
@@ -345,18 +363,18 @@ libextractor_png_extract (const char *filename, | |||
345 | /* printf("Length: %u, pos %u\n", length, pos - data); */ | 363 | /* printf("Length: %u, pos %u\n", length, pos - data); */ |
346 | if ((pos + 4 + length + 4 > end) || (pos + 4 + length + 4 < pos + 8)) | 364 | if ((pos + 4 + length + 4 > end) || (pos + 4 + length + 4 < pos + 8)) |
347 | break; | 365 | break; |
348 | |||
349 | if (0 == strncmp (pos, "IHDR", 4)) | 366 | if (0 == strncmp (pos, "IHDR", 4)) |
350 | result = processIHDR (pos, length, result); | 367 | ret = processIHDR (pos, length, proc, proc_cls); |
351 | if (0 == strncmp (pos, "iTXt", 4)) | 368 | if (0 == strncmp (pos, "iTXt", 4)) |
352 | result = processiTXt (pos, length, result); | 369 | ret = processiTXt (pos, length, proc, proc_cls); |
353 | if (0 == strncmp (pos, "tEXt", 4)) | 370 | if (0 == strncmp (pos, "tEXt", 4)) |
354 | result = processtEXt (pos, length, result); | 371 | ret = processtEXt (pos, length, proc, proc_cls); |
355 | if (0 == strncmp (pos, "zTXt", 4)) | 372 | if (0 == strncmp (pos, "zTXt", 4)) |
356 | result = processzTXt (pos, length, result); | 373 | ret = processzTXt (pos, length, proc, proc_cls); |
357 | if (0 == strncmp (pos, "tIME", 4)) | 374 | if (0 == strncmp (pos, "tIME", 4)) |
358 | result = processtIME (pos, length, result); | 375 | ret = processtIME (pos, length, proc, proc_cls); |
359 | pos += 4 + length + 4; /* Chunk type, data, crc */ | 376 | pos += 4 + length + 4; /* Chunk type, data, crc */ |
360 | } | 377 | } |
361 | return result; | 378 | FINISH: |
379 | return ret; | ||
362 | } | 380 | } |