libextractor  1.11
About: GNU libextractor is a library used to extract meta-data from files of arbitrary type.
  Fossies Dox: libextractor-1.11.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

png_extractor.c File Reference

plugin to support PNG files More...

#include "platform.h"
#include <zlib.h>
#include "extractor.h"
#include "convert.h"
Include dependency graph for png_extractor.c:

Go to the source code of this file.

Macros

#define PNG_HEADER   "\211PNG\r\n\032\n"
 
#define ADD(t, s)
 
#define ADDF(t, s)
 

Functions

static char * stndup (const char *str, size_t n)
 
static size_t stnlen (const char *str, size_t maxlen)
 
static uint32_t get_int_at (const void *pos)
 
static int processtEXt (struct EXTRACTOR_ExtractContext *ec, uint32_t length)
 
static int processiTXt (struct EXTRACTOR_ExtractContext *ec, uint32_t length)
 
static int processIHDR (struct EXTRACTOR_ExtractContext *ec, uint32_t length)
 
static int processzTXt (struct EXTRACTOR_ExtractContext *ec, uint32_t length)
 
static int processtIME (struct EXTRACTOR_ExtractContext *ec, uint32_t length)
 
void EXTRACTOR_png_extract_method (struct EXTRACTOR_ExtractContext *ec)
 

Variables

struct {
   const char *   name
 
   enum EXTRACTOR_MetaType   type
 
tagmap []
 

Detailed Description

plugin to support PNG files

Author
Christian Grothoff

Definition in file png_extractor.c.

Macro Definition Documentation

◆ ADD

#define ADD (   t,
 
)
Value:
do { if (0 != (ret = ec->proc (ec->cls, "png", t, \
"text/plain", s, strlen (s) \
+ 1))) goto FINISH; \
} while (0)
@ EXTRACTOR_METAFORMAT_UTF8
Definition: extractor.h:102

Give the given metadata to LE. Set "ret" to 1 and goto 'FINISH' if LE says we are done.

Parameters
ttype of the metadata
sutf8 string with the metadata

Definition at line 137 of file png_extractor.c.

◆ ADDF

#define ADDF (   t,
 
)
Value:
do { if ( (NULL != s) && (0 != (ret = ec->proc (ec->cls, \
"png", t, \
"text/plain", \
s, strlen (s) \
+ 1))) ) { \
free (s); goto FINISH; } if (NULL != s) free (s); \
} while (0)
#define NULL
Definition: getopt1.c:60

Give the given metadata to LE and free the memory. Set "ret" to 1 and goto 'FINISH' if LE says we are done.

Parameters
ttype of the metadata
sutf8 string with the metadata, to be freed afterwards

Definition at line 151 of file png_extractor.c.

◆ PNG_HEADER

#define PNG_HEADER   "\211PNG\r\n\032\n"

Header that every PNG file must start with.

Definition at line 33 of file png_extractor.c.

Function Documentation

◆ EXTRACTOR_png_extract_method()

void EXTRACTOR_png_extract_method ( struct EXTRACTOR_ExtractContext ec)

Main entry method for the 'image/png' extraction plugin.

Parameters
ecextraction context provided to the plugin

Definition at line 465 of file png_extractor.c.

References ADD, EXTRACTOR_ExtractContext::cls, EXTRACTOR_METATYPE_MIMETYPE, get_int_at(), PNG_HEADER, processIHDR(), processiTXt(), processtEXt(), processtIME(), processzTXt(), EXTRACTOR_ExtractContext::read, and EXTRACTOR_ExtractContext::seek.

◆ get_int_at()

static uint32_t get_int_at ( const void *  pos)
static

Interpret the 4 bytes in 'buf' as a big-endian encoded 32-bit integer, convert and return.

Parameters
pos(unaligned) pointer to 4 byte integer
Returns
converted integer in host byte order

Definition at line 90 of file png_extractor.c.

Referenced by EXTRACTOR_png_extract_method(), and processIHDR().

◆ processIHDR()

static int processIHDR ( struct EXTRACTOR_ExtractContext ec,
uint32_t  length 
)
static

Process IHDR tag.

Parameters
ecextraction context
lengthlength of the tag
Returns
0 to continue extracting, 1 if we are done

Definition at line 313 of file png_extractor.c.

References ADD, EXTRACTOR_ExtractContext::cls, EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, get_int_at(), and EXTRACTOR_ExtractContext::read.

Referenced by EXTRACTOR_png_extract_method().

◆ processiTXt()

static int processiTXt ( struct EXTRACTOR_ExtractContext ec,
uint32_t  length 
)
static

Process iTXt tag.

Parameters
ecextraction context
lengthlength of the tag
Returns
0 to continue extracting, 1 if we are done

Definition at line 210 of file png_extractor.c.

References ADDF, EXTRACTOR_ExtractContext::cls, EXTRACTOR_METATYPE_COMMENT, EXTRACTOR_METATYPE_KEYWORDS, EXTRACTOR_METATYPE_LANGUAGE, name, NULL, EXTRACTOR_ExtractContext::read, stndup(), stnlen(), tagmap, and type.

Referenced by EXTRACTOR_png_extract_method().

◆ processtEXt()

static int processtEXt ( struct EXTRACTOR_ExtractContext ec,
uint32_t  length 
)
static

Process EXt tag.

Parameters
ecextraction context
lengthlength of the tag
Returns
0 to continue extracting, 1 if we are done

Definition at line 169 of file png_extractor.c.

References ADDF, EXTRACTOR_ExtractContext::cls, EXTRACTOR_common_convert_to_utf8(), EXTRACTOR_METATYPE_KEYWORDS, name, NULL, EXTRACTOR_ExtractContext::read, stnlen(), tagmap, and type.

Referenced by EXTRACTOR_png_extract_method().

◆ processtIME()

static int processtIME ( struct EXTRACTOR_ExtractContext ec,
uint32_t  length 
)
static

Process IME tag.

Parameters
ecextraction context
lengthlength of the tag
Returns
0 to continue extracting, 1 if we are done

Definition at line 421 of file png_extractor.c.

References ADD, EXTRACTOR_ExtractContext::cls, EXTRACTOR_METATYPE_MODIFICATION_DATE, and EXTRACTOR_ExtractContext::read.

Referenced by EXTRACTOR_png_extract_method().

◆ processzTXt()

static int processzTXt ( struct EXTRACTOR_ExtractContext ec,
uint32_t  length 
)
static

Process zTXt tag.

Parameters
ecextraction context
lengthlength of the tag
Returns
0 to continue extracting, 1 if we are done

Definition at line 345 of file png_extractor.c.

References ADDF, EXTRACTOR_ExtractContext::cls, EXTRACTOR_common_convert_to_utf8(), EXTRACTOR_METATYPE_COMMENT, name, NULL, EXTRACTOR_ExtractContext::read, stnlen(), tagmap, and type.

Referenced by EXTRACTOR_png_extract_method().

◆ stndup()

static char* stndup ( const char *  str,
size_t  n 
)
static

Function to create 0-terminated string from the first n characters of the given input.

Parameters
strinput string
nlength of the input
Returns
n-bytes from str followed by 0-termination, NULL on error

Definition at line 45 of file png_extractor.c.

References NULL.

Referenced by processiTXt().

◆ stnlen()

static size_t stnlen ( const char *  str,
size_t  maxlen 
)
static

strnlen is GNU specific, let's redo it here to be POSIX compliant.

Parameters
strinput string
maxlenmaximum length of str
Returns
first position of 0-terminator in str, or maxlen

Definition at line 69 of file png_extractor.c.

Referenced by processiTXt(), processtEXt(), and processzTXt().

Variable Documentation

◆ name

const char* name

PNG name.

Definition at line 108 of file png_extractor.c.

Referenced by processiTXt(), processtEXt(), and processzTXt().

◆ 

struct { ... } tagmap[]
Initial value:
= {
{ "Description", EXTRACTOR_METATYPE_DESCRIPTION },
{ "Copyright", EXTRACTOR_METATYPE_COPYRIGHT },
{ "Creation Time", EXTRACTOR_METATYPE_CREATION_DATE },
{ "Disclaimer", EXTRACTOR_METATYPE_DISCLAIMER },
{ "Signature", EXTRACTOR_METATYPE_UNKNOWN },
}
@ EXTRACTOR_METATYPE_PRODUCED_BY_SOFTWARE
Definition: extractor.h:258
@ EXTRACTOR_METATYPE_WARNING
Definition: extractor.h:294
@ EXTRACTOR_METATYPE_UNKNOWN
Definition: extractor.h:181
@ EXTRACTOR_METATYPE_AUTHOR_NAME
Definition: extractor.h:143
@ EXTRACTOR_METATYPE_COMMENT
Definition: extractor.h:131
@ EXTRACTOR_METATYPE_TITLE
Definition: extractor.h:134
@ EXTRACTOR_METATYPE_CREATION_DATE
Definition: extractor.h:196
@ EXTRACTOR_METATYPE_COPYRIGHT
Definition: extractor.h:183
@ EXTRACTOR_METATYPE_SOURCE_DEVICE
Definition: extractor.h:292
@ EXTRACTOR_METATYPE_DISCLAIMER
Definition: extractor.h:293
@ EXTRACTOR_METATYPE_RESERVED
Definition: extractor.h:128
@ EXTRACTOR_METATYPE_DESCRIPTION
Definition: extractor.h:182

Map from PNG meta data descriptor strings to LE types.

Referenced by processiTXt(), processtEXt(), and processzTXt().

◆ type

enum EXTRACTOR_MetaType type

Corresponding LE type.

Definition at line 108 of file png_extractor.c.

Referenced by processiTXt(), processtEXt(), and processzTXt().