[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r9799 - in Extractor/src: include main plugins
From: |
gnunet |
Subject: |
[GNUnet-SVN] r9799 - in Extractor/src: include main plugins |
Date: |
Fri, 18 Dec 2009 20:45:02 +0100 |
Author: grothoff
Date: 2009-12-18 20:45:02 +0100 (Fri, 18 Dec 2009)
New Revision: 9799
Added:
Extractor/src/plugins/png_extractor.c
Removed:
Extractor/src/plugins/pngextractor.c
Modified:
Extractor/src/include/extractor.h
Extractor/src/main/extractor_metatypes.c
Extractor/src/plugins/Makefile.am
Log:
png
Modified: Extractor/src/include/extractor.h
===================================================================
--- Extractor/src/include/extractor.h 2009-12-18 18:43:20 UTC (rev 9798)
+++ Extractor/src/include/extractor.h 2009-12-18 19:45:02 UTC (rev 9799)
@@ -272,7 +272,13 @@
EXTRACTOR_METATYPE_EVENT_PICTURE = 140,
EXTRACTOR_METATYPE_LOGO = 141,
EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM = 142,
+ EXTRACTOR_METATYPE_SOURCE_DEVICE = 143,
+ EXTRACTOR_METATYPE_DISCLAIMER = 144,
+ EXTRACTOR_METATYPE_WARNING = 145,
+
+ /* fixme: used up to here! */
+
EXTRACTOR_METATYPE_LYRICS = 67,
EXTRACTOR_METATYPE_CONDUCTOR = 64,
EXTRACTOR_METATYPE_INTERPRET = 65,
@@ -283,7 +289,6 @@
EXTRACTOR_METATYPE_MUSICIAN_CREDITS_LIST = 123,
- /* fixme: used up to here! */
EXTRACTOR_METATYPE_SCALE = 108,
@@ -309,7 +314,6 @@
EXTRACTOR_METATYPE_ENCODED_BY = 121,
EXTRACTOR_METATYPE_PROUCUCTVERSION = 90,
- EXTRACTOR_METATYPE_DISCLAIMER = 27,
EXTRACTOR_METATYPE_FULL_DATA = 137,
EXTRACTOR_METATYPE_ORGANIZATION = 15,
@@ -317,7 +321,6 @@
EXTRACTOR_METATYPE_RELATION = 24,
EXTRACTOR_METATYPE_COVERAGE = 25,
EXTRACTOR_METATYPE_SOFTWARE = 26,
- EXTRACTOR_METATYPE_WARNING = 28,
EXTRACTOR_METATYPE_TRANSLATED = 29,
EXTRACTOR_METATYPE_PRODUCER = 33,
EXTRACTOR_METATYPE_CREATED_FOR = 39,
Modified: Extractor/src/main/extractor_metatypes.c
===================================================================
--- Extractor/src/main/extractor_metatypes.c 2009-12-18 18:43:20 UTC (rev
9798)
+++ Extractor/src/main/extractor_metatypes.c 2009-12-18 19:45:02 UTC (rev
9799)
@@ -351,12 +351,21 @@
gettext_noop ("logo of an associated organization") },
{ gettext_noop ("broadcast television system"),
gettext_noop ("name of the television system for which the data is coded")
},
+ { gettext_noop ("source device"),
+ gettext_noop ("device used to create the object") },
+ { gettext_noop ("disclaimer"),
+ gettext_noop ("legal disclaimer") },
+ /* 145 */
+ { gettext_noop ("warning"),
+ gettext_noop ("warning about the nature of the content") },
{ gettext_noop (""),
gettext_noop ("") },
{ gettext_noop (""),
gettext_noop ("") },
{ gettext_noop (""),
gettext_noop ("") },
+ { gettext_noop (""),
+ gettext_noop ("") },
#if 0
gettext_noop("author"),
Modified: Extractor/src/plugins/Makefile.am
===================================================================
--- Extractor/src/plugins/Makefile.am 2009-12-18 18:43:20 UTC (rev 9798)
+++ Extractor/src/plugins/Makefile.am 2009-12-18 19:45:02 UTC (rev 9799)
@@ -87,6 +87,7 @@
$(ogg) \
$(ole2) \
$(pdf) \
+ libextractor_png.la \
libextractor_real.la \
$(rpm) \
libextractor_tar.la \
@@ -234,6 +235,14 @@
$(top_builddir)/src/common/libextractor_common.la \
-lpoppler
+libextractor_png_la_SOURCES = \
+ png_extractor.c
+libextractor_png_la_LDFLAGS = \
+ $(PLUGINFLAGS)
+libextractor_png_la_LIBADD = \
+ $(top_builddir)/src/common/libextractor_common.la \
+ -lz
+
libextractor_real_la_SOURCES = \
real_extractor.c
libextractor_real_la_LDFLAGS = \
@@ -288,7 +297,6 @@
$(extrampeg) \
libextractor_nsf.la \
libextractor_nsfe.la \
- libextractor_png.la \
libextractor_ps.la \
$(extraqt) \
libextractor_riff.la \
@@ -353,15 +361,6 @@
$(LE_LIBINTL) \
-lm
-libextractor_png_la_SOURCES = \
- pngextractor.c
-libextractor_png_la_LDFLAGS = \
- $(PLUGINFLAGS)
-libextractor_png_la_LIBADD = \
- $(top_builddir)/src/common/libextractor_common.la \
- $(top_builddir)/src/main/libextractor.la \
- -lz
-
libextractor_sid_la_SOURCES = \
sidextractor.c
libextractor_sid_la_LDFLAGS = \
Copied: Extractor/src/plugins/png_extractor.c (from rev 9791,
Extractor/src/plugins/pngextractor.c)
===================================================================
--- Extractor/src/plugins/png_extractor.c (rev 0)
+++ Extractor/src/plugins/png_extractor.c 2009-12-18 19:45:02 UTC (rev
9799)
@@ -0,0 +1,380 @@
+/*
+ This file is part of libextractor.
+ (C) 2002, 2003, 2004, 2005, 2009 Vidyut Samanta and Christian Grothoff
+
+ libextractor is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ libextractor is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libextractor; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+#include "platform.h"
+#include "extractor.h"
+#include <zlib.h>
+#include "convert.h"
+
+static char *
+stndup (const char *str, size_t n)
+{
+ char *tmp;
+ tmp = malloc (n + 1);
+ tmp[n] = '\0';
+ memcpy (tmp, str, n);
+ return tmp;
+}
+
+/**
+ * strnlen is GNU specific, let's redo it here to be
+ * POSIX compliant.
+ */
+static size_t
+stnlen (const char *str, size_t maxlen)
+{
+ size_t ret;
+ ret = 0;
+ while ((ret < maxlen) && (str[ret] != '\0'))
+ ret++;
+ return ret;
+}
+
+
+static int
+getIntAt (const void *pos)
+{
+ char p[4];
+
+ memcpy (p, pos, 4); /* ensure alignment! */
+ return *(int *) &p[0];
+}
+
+
+static struct
+{
+ char *name;
+ enum EXTRACTOR_MetaType type;
+} tagmap[] =
+{
+ { "Author", EXTRACTOR_METATYPE_AUTHOR_NAME},
+ { "Description", EXTRACTOR_METATYPE_DESCRIPTION},
+ { "Comment", EXTRACTOR_METATYPE_COMMENT},
+ { "Copyright", EXTRACTOR_METATYPE_COPYRIGHT},
+ { "Source", EXTRACTOR_METATYPE_SOURCE_DEVICE },
+ { "Creation Time", EXTRACTOR_METATYPE_CREATION_DATE},
+ { "Title", EXTRACTOR_METATYPE_TITLE},
+ { "Software", EXTRACTOR_METATYPE_PRODUCED_BY_SOFTWARE},
+ { "Disclaimer", EXTRACTOR_METATYPE_DISCLAIMER},
+ { "Warning", EXTRACTOR_METATYPE_WARNING},
+ { NULL, EXTRACTOR_METATYPE_RESERVED }
+};
+
+
+#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)
+#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)
+
+
+static int
+processtEXt (const char *data,
+ unsigned int length,
+ EXTRACTOR_MetaDataProcessor proc,
+ void *proc_cls)
+{
+ char *keyword;
+ unsigned int off;
+ int i;
+ int ret;
+
+ data += 4;
+ off = stnlen (data, length) + 1;
+ if (off >= length)
+ return 0; /* failed to find '\0' */
+ keyword = EXTRACTOR_common_convert_to_utf8 (&data[off], length - off,
"ISO-8859-1");
+ i = 0;
+ ret = 0;
+ while (tagmap[i].name != NULL)
+ {
+ if (0 == strcmp (tagmap[i].name, data))
+ {
+ ADDF (tagmap[i].type, keyword);
+ return 0;
+ }
+
+ i++;
+ }
+ ADDF (EXTRACTOR_METATYPE_KEYWORDS, keyword);
+ FINISH:
+ return ret;
+}
+
+static int
+processiTXt (const char *data,
+ unsigned int length,
+ EXTRACTOR_MetaDataProcessor proc,
+ void *proc_cls)
+{
+ unsigned int pos;
+ char *keyword;
+ const char *language;
+ const char *translated;
+ int i;
+ int compressed;
+ char *buf;
+ uLongf bufLen;
+ int ret;
+ int zret;
+
+ pos = stnlen (data, length) + 1;
+ if (pos + 3 >= length)
+ return 0;
+ compressed = data[pos++];
+ if (compressed && (data[pos++] != 0))
+ return 0; /* bad compression method */
+ language = &data[pos];
+ ret = 0;
+ if (stnlen (language, length - pos) > 0)
+ ADDF (EXTRACTOR_METATYPE_DOCUMENT_LANGUAGE,
+ stndup (language, length - pos));
+ pos += stnlen (language, length - pos) + 1;
+ if (pos + 1 >= length)
+ return 0;
+ translated = &data[pos]; /* already in utf-8! */
+ if (stnlen (translated, length - pos) > 0)
+ ADDF (EXTRACTOR_METATYPE_KEYWORDS,
+ stndup (translated, length - pos));
+ pos += stnlen (translated, length - pos) + 1;
+ if (pos >= length)
+ return 0;
+
+ if (compressed)
+ {
+ bufLen = 1024 + 2 * (length - pos);
+ while (1)
+ {
+ if (bufLen * 2 < bufLen)
+ return 0;
+ bufLen *= 2;
+ if (bufLen > 50 * (length - pos))
+ {
+ /* printf("zlib problem"); */
+ return 0;
+ }
+ buf = malloc (bufLen);
+ if (buf == NULL)
+ {
+ /* printf("out of memory"); */
+ return 0; /* out of memory */
+ }
+ zret = uncompress ((Bytef *) buf,
+ &bufLen,
+ (const Bytef *) &data[pos], length - pos);
+ if (zret == Z_OK)
+ {
+ /* printf("zlib ok"); */
+ break;
+ }
+ free (buf);
+ if (zret != Z_BUF_ERROR)
+ return 0; /* unknown error, abort */
+ }
+ keyword = stndup (buf, bufLen);
+ free (buf);
+ }
+ else
+ {
+ keyword = stndup (&data[pos], length - pos);
+ }
+ i = 0;
+ while (tagmap[i].name != NULL)
+ {
+ if (0 == strcmp (tagmap[i].name, data))
+ {
+ ADDF (tagmap[i].type, keyword /* already in utf8 */);
+ return 0;
+ }
+ i++;
+ }
+ ADDF (EXTRACTOR_METATYPE_COMMENT, keyword);
+ FINISH:
+ return ret;
+}
+
+
+static int
+processIHDR (const char *data,
+ unsigned int length,
+ EXTRACTOR_MetaDataProcessor proc,
+ void *proc_cls)
+{
+ char tmp[128];
+ int ret;
+
+ if (length < 12)
+ return 0;
+ ret = 0;
+ snprintf (tmp,
+ sizeof(tmp),
+ "%ux%u",
+ htonl (getIntAt (&data[4])), htonl (getIntAt (&data[8])));
+ ADD (EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, tmp);
+ FINISH:
+ return ret;
+}
+
+static int
+processzTXt (const char *data,
+ unsigned int length,
+ EXTRACTOR_MetaDataProcessor proc,
+ void *proc_cls)
+{
+ char *keyword;
+ unsigned int off;
+ int i;
+ char *buf;
+ uLongf bufLen;
+ int ret;
+ int zret;
+
+ data += 4;
+ off = stnlen (data, length) + 1;
+ if (off >= length)
+ return 0; /* failed to find '\0' */
+ if (data[off] != 0)
+ return 0; /* compression method must be 0 */
+ off++;
+
+ bufLen = 1024 + 2 * (length - off);
+ while (1)
+ {
+ if (bufLen * 2 < bufLen)
+ return 0;
+ bufLen *= 2;
+ if (bufLen > 50 * (length - off))
+ {
+ /* printf("zlib problem"); */
+ return 0;
+ }
+ buf = malloc (bufLen);
+ if (buf == NULL)
+ {
+ /* printf("out of memory"); */
+ return 0; /* out of memory */
+ }
+ zret = uncompress ((Bytef *) buf,
+ &bufLen, (const Bytef *) &data[off], length - off);
+ if (zret == Z_OK)
+ {
+ /* printf("zlib ok"); */
+ break;
+ }
+ free (buf);
+ if (zret != Z_BUF_ERROR)
+ return 0; /* unknown error, abort */
+ }
+ keyword = EXTRACTOR_common_convert_to_utf8 (buf, bufLen, "ISO-8859-1");
+ free (buf);
+ i = 0;
+ while (tagmap[i].name != NULL)
+ {
+ if (0 == strcmp (tagmap[i].name, data))
+ {
+ ADDF (tagmap[i].type, keyword);
+ return 0;
+ }
+ i++;
+ }
+ ADDF (EXTRACTOR_METATYPE_COMMENT, keyword);
+ FINISH:
+ return ret;
+}
+
+static int
+processtIME (const char *data,
+ unsigned int length,
+ EXTRACTOR_MetaDataProcessor proc,
+ void *proc_cls)
+{
+ unsigned short y;
+ unsigned int year;
+ unsigned int mo;
+ unsigned int day;
+ unsigned int h;
+ unsigned int m;
+ unsigned int s;
+ char val[256];
+ int ret;
+
+ if (length != 7)
+ return 0;
+ ret = 0;
+ memcpy (&y, &data[4], sizeof (unsigned short));
+ year = ntohs (y);
+ mo = (unsigned char) data[6];
+ day = (unsigned char) data[7];
+ h = (unsigned char) data[8];
+ m = (unsigned char) data[9];
+ s = (unsigned char) data[10];
+ snprintf (val,
+ sizeof(val),
+ "%04u-%02u-%02u %02d:%02d:%02d", year, mo, day, h, m, s);
+ ADD (EXTRACTOR_METATYPE_MODIFICATION_DATE, val);
+ FINISH:
+ return ret;
+}
+
+#define PNG_HEADER "\211PNG\r\n\032\n"
+
+
+
+int
+EXTRACTOR_png_extract (const char *data,
+ size_t size,
+ EXTRACTOR_MetaDataProcessor proc,
+ void *proc_cls,
+ const char *options)
+{
+ const char *pos;
+ const char *end;
+ unsigned int length;
+ int ret;
+
+ if (size < strlen (PNG_HEADER))
+ return 0;
+ if (0 != strncmp (data, PNG_HEADER, strlen (PNG_HEADER)))
+ return 0;
+ end = &data[size];
+ pos = &data[strlen (PNG_HEADER)];
+ ADD (EXTRACTOR_METATYPE_MIMETYPE, "image/png");
+ ret = 0;
+ while (ret == 0)
+ {
+ if (pos + 12 >= end)
+ break;
+ length = htonl (getIntAt (pos));
+ pos += 4;
+ /* printf("Length: %u, pos %u\n", length, pos - data); */
+ if ((pos + 4 + length + 4 > end) || (pos + 4 + length + 4 < pos + 8))
+ break;
+ if (0 == strncmp (pos, "IHDR", 4))
+ ret = processIHDR (pos, length, proc, proc_cls);
+ if (0 == strncmp (pos, "iTXt", 4))
+ ret = processiTXt (pos, length, proc, proc_cls);
+ if (0 == strncmp (pos, "tEXt", 4))
+ ret = processtEXt (pos, length, proc, proc_cls);
+ if (0 == strncmp (pos, "zTXt", 4))
+ ret = processzTXt (pos, length, proc, proc_cls);
+ if (0 == strncmp (pos, "tIME", 4))
+ ret = processtIME (pos, length, proc, proc_cls);
+ pos += 4 + length + 4; /* Chunk type, data, crc */
+ }
+ FINISH:
+ return ret;
+}
Deleted: Extractor/src/plugins/pngextractor.c
===================================================================
--- Extractor/src/plugins/pngextractor.c 2009-12-18 18:43:20 UTC (rev
9798)
+++ Extractor/src/plugins/pngextractor.c 2009-12-18 19:45:02 UTC (rev
9799)
@@ -1,362 +0,0 @@
-/*
- This file is part of libextractor.
- (C) 2002, 2003, 2004, 2005 Vidyut Samanta and Christian Grothoff
-
- libextractor is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 2, or (at your
- option) any later version.
-
- libextractor is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with libextractor; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
- */
-
-#include "platform.h"
-#include "extractor.h"
-#include <zlib.h>
-#include "convert.h"
-
-static char *
-stndup (const char *str, size_t n)
-{
- char *tmp;
- tmp = malloc (n + 1);
- tmp[n] = '\0';
- memcpy (tmp, str, n);
- return tmp;
-}
-
-/**
- * strnlen is GNU specific, let's redo it here to be
- * POSIX compliant.
- */
-static size_t
-stnlen (const char *str, size_t maxlen)
-{
- size_t ret;
- ret = 0;
- while ((ret < maxlen) && (str[ret] != '\0'))
- ret++;
- return ret;
-}
-
-static struct EXTRACTOR_Keywords *
-addKeyword (EXTRACTOR_KeywordType type,
- char *keyword, struct EXTRACTOR_Keywords *next)
-{
- EXTRACTOR_KeywordList *result;
-
- if (keyword == NULL)
- return next;
- result = malloc (sizeof (EXTRACTOR_KeywordList));
- result->next = next;
- result->keyword = keyword;
- result->keywordType = type;
- return result;
-}
-
-static int
-getIntAt (const void *pos)
-{
- char p[4];
-
- memcpy (p, pos, 4); /* ensure alignment! */
- return *(int *) &p[0];
-}
-
-
-static struct
-{
- char *name;
- EXTRACTOR_KeywordType type;
-} tagmap[] =
-{
- {
- "Author", EXTRACTOR_AUTHOR},
- {
- "Description", EXTRACTOR_DESCRIPTION},
- {
- "Comment", EXTRACTOR_COMMENT},
- {
- "Copyright", EXTRACTOR_COPYRIGHT},
- {
- "Source", EXTRACTOR_SOURCE},
- {
- "Creation Time", EXTRACTOR_CREATION_DATE},
- {
- "Title", EXTRACTOR_TITLE},
- {
- "Software", EXTRACTOR_SOFTWARE},
- {
- "Disclaimer", EXTRACTOR_DISCLAIMER},
- {
- "Warning", EXTRACTOR_WARNING},
- {
- "Signature", EXTRACTOR_RESOURCE_IDENTIFIER},
- {
-NULL, EXTRACTOR_UNKNOWN},};
-
-static struct EXTRACTOR_Keywords *
-processtEXt (const char *data,
- unsigned int length, struct EXTRACTOR_Keywords *prev)
-{
- char *keyword;
- unsigned int off;
- int i;
-
- data += 4;
- off = stnlen (data, length) + 1;
- if (off >= length)
- return prev; /* failed to find '\0' */
- keyword = EXTRACTOR_common_convert_to_utf8 (&data[off], length - off,
"ISO-8859-1");
- i = 0;
- while (tagmap[i].name != NULL)
- {
- if (0 == strcmp (tagmap[i].name, data))
- return addKeyword (tagmap[i].type, keyword, prev);
-
- i++;
- }
- return addKeyword (EXTRACTOR_UNKNOWN, keyword, prev);
-}
-
-static struct EXTRACTOR_Keywords *
-processiTXt (const char *data,
- unsigned int length, struct EXTRACTOR_Keywords *prev)
-{
- unsigned int pos;
- char *keyword;
- const char *language;
- const char *translated;
- int i;
- int compressed;
- char *buf;
- uLongf bufLen;
- int ret;
-
- pos = stnlen (data, length) + 1;
- if (pos + 3 >= length)
- return prev;
- compressed = data[pos++];
- if (compressed && (data[pos++] != 0))
- return prev; /* bad compression method */
- language = &data[pos];
- if (stnlen (language, length - pos) > 0)
- prev = addKeyword (EXTRACTOR_LANGUAGE,
- stndup (language, length - pos), prev);
- pos += stnlen (language, length - pos) + 1;
- if (pos + 1 >= length)
- return prev;
- translated = &data[pos]; /* already in utf-8! */
- if (stnlen (translated, length - pos) > 0)
- prev = addKeyword (EXTRACTOR_TRANSLATED,
- stndup (translated, length - pos), prev);
- pos += stnlen (translated, length - pos) + 1;
- if (pos >= length)
- return prev;
-
- if (compressed)
- {
- bufLen = 1024 + 2 * (length - pos);
- while (1)
- {
- if (bufLen * 2 < bufLen)
- return prev;
- bufLen *= 2;
- if (bufLen > 50 * (length - pos))
- {
- /* printf("zlib problem"); */
- return prev;
- }
- buf = malloc (bufLen);
- if (buf == NULL)
- {
- /* printf("out of memory"); */
- return prev; /* out of memory */
- }
- ret = uncompress ((Bytef *) buf,
- &bufLen,
- (const Bytef *) &data[pos], length - pos);
- if (ret == Z_OK)
- {
- /* printf("zlib ok"); */
- break;
- }
- free (buf);
- if (ret != Z_BUF_ERROR)
- return prev; /* unknown error, abort */
- }
- keyword = stndup (buf, bufLen);
- free (buf);
- }
- else
- {
- keyword = stndup (&data[pos], length - pos);
- }
- i = 0;
- while (tagmap[i].name != NULL)
- {
- if (0 == strcmp (tagmap[i].name, data))
- return addKeyword (tagmap[i].type, keyword, /* already in utf-8 */
- prev);
- i++;
- }
- return addKeyword (EXTRACTOR_UNKNOWN, keyword, prev);
-}
-
-static struct EXTRACTOR_Keywords *
-processIHDR (const char *data,
- unsigned int length, struct EXTRACTOR_Keywords *prev)
-{
- char *tmp;
-
- if (length < 12)
- return prev;
-
- tmp = malloc (128);
- snprintf (tmp,
- 128,
- "%ux%u",
- htonl (getIntAt (&data[4])), htonl (getIntAt (&data[8])));
- return addKeyword (EXTRACTOR_SIZE, tmp, prev);
-}
-
-static struct EXTRACTOR_Keywords *
-processzTXt (const char *data,
- unsigned int length, struct EXTRACTOR_Keywords *prev)
-{
- char *keyword;
- unsigned int off;
- int i;
- char *buf;
- uLongf bufLen;
- int ret;
-
- data += 4;
- off = stnlen (data, length) + 1;
- if (off >= length)
- return prev; /* failed to find '\0' */
- if (data[off] != 0)
- return prev; /* compression method must be 0 */
- off++;
-
- bufLen = 1024 + 2 * (length - off);
- while (1)
- {
- if (bufLen * 2 < bufLen)
- return prev;
- bufLen *= 2;
- if (bufLen > 50 * (length - off))
- {
- /* printf("zlib problem"); */
- return prev;
- }
- buf = malloc (bufLen);
- if (buf == NULL)
- {
- /* printf("out of memory"); */
- return prev; /* out of memory */
- }
- ret = uncompress ((Bytef *) buf,
- &bufLen, (const Bytef *) &data[off], length - off);
- if (ret == Z_OK)
- {
- /* printf("zlib ok"); */
- break;
- }
- free (buf);
- if (ret != Z_BUF_ERROR)
- return prev; /* unknown error, abort */
- }
- keyword = EXTRACTOR_common_convert_to_utf8 (buf, bufLen, "ISO-8859-1");
- free (buf);
- i = 0;
- while (tagmap[i].name != NULL)
- {
- if (0 == strcmp (tagmap[i].name, data))
- return addKeyword (tagmap[i].type, keyword, prev);
-
- i++;
- }
- return addKeyword (EXTRACTOR_UNKNOWN, keyword, prev);
-}
-
-static struct EXTRACTOR_Keywords *
-processtIME (const char *data,
- unsigned int length, struct EXTRACTOR_Keywords *prev)
-{
- unsigned short y;
- unsigned int year;
- unsigned int mo;
- unsigned int day;
- unsigned int h;
- unsigned int m;
- unsigned int s;
- char val[256];
-
- if (length != 7)
- return prev;
- memcpy (&y, &data[4], sizeof (unsigned short));
- year = ntohs (y);
- mo = (unsigned char) data[6];
- day = (unsigned char) data[7];
- h = (unsigned char) data[8];
- m = (unsigned char) data[9];
- s = (unsigned char) data[10];
- sprintf (val, "%04u-%02u-%02u %02d:%02d:%02d", year, mo, day, h, m, s);
- return addKeyword (EXTRACTOR_MODIFICATION_DATE, strdup (val), prev);
-}
-
-#define PNG_HEADER "\211PNG\r\n\032\n"
-
-
-
-struct EXTRACTOR_Keywords *
-libextractor_png_extract (const char *filename,
- const char *data,
- size_t size, struct EXTRACTOR_Keywords *prev)
-{
- const char *pos;
- const char *end;
- struct EXTRACTOR_Keywords *result;
- unsigned int length;
-
- if (size < strlen (PNG_HEADER))
- return prev;
- if (0 != strncmp (data, PNG_HEADER, strlen (PNG_HEADER)))
- return prev;
- result = prev;
- end = &data[size];
- pos = &data[strlen (PNG_HEADER)];
- result = addKeyword (EXTRACTOR_MIMETYPE, strdup ("image/png"), result);
- while (1)
- {
- if (pos + 12 >= end)
- break;
- length = htonl (getIntAt (pos));
- pos += 4;
- /* printf("Length: %u, pos %u\n", length, pos - data); */
- if ((pos + 4 + length + 4 > end) || (pos + 4 + length + 4 < pos + 8))
- break;
-
- if (0 == strncmp (pos, "IHDR", 4))
- result = processIHDR (pos, length, result);
- if (0 == strncmp (pos, "iTXt", 4))
- result = processiTXt (pos, length, result);
- if (0 == strncmp (pos, "tEXt", 4))
- result = processtEXt (pos, length, result);
- if (0 == strncmp (pos, "zTXt", 4))
- result = processzTXt (pos, length, result);
- if (0 == strncmp (pos, "tIME", 4))
- result = processtIME (pos, length, result);
- pos += 4 + length + 4; /* Chunk type, data, crc */
- }
- return result;
-}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r9799 - in Extractor/src: include main plugins,
gnunet <=