aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbootstrap36
-rw-r--r--contrib/uncrustify.cfg95
-rwxr-xr-xcontrib/uncrustify.sh14
-rwxr-xr-xcontrib/uncrustify_precommit35
-rw-r--r--src/common/convert.c43
-rw-r--r--src/common/convert.h8
-rw-r--r--src/common/le_architecture.h8
-rw-r--r--src/common/unzip.c671
-rw-r--r--src/common/unzip.h137
-rw-r--r--src/include/extractor.h686
-rw-r--r--src/include/gettext.h6
-rw-r--r--src/include/platform.h11
-rw-r--r--src/include/plibc.h1138
-rw-r--r--src/intlemu/intlemu.c251
-rw-r--r--src/intlemu/libintlemu.h6
-rw-r--r--src/main/extract.c1015
-rw-r--r--src/main/extractor.c532
-rw-r--r--src/main/extractor_common.c49
-rw-r--r--src/main/extractor_common.h10
-rw-r--r--src/main/extractor_datasource.c1083
-rw-r--r--src/main/extractor_datasource.h28
-rw-r--r--src/main/extractor_ipc.c157
-rw-r--r--src/main/extractor_ipc.h57
-rw-r--r--src/main/extractor_ipc_gnu.c389
-rw-r--r--src/main/extractor_ipc_w32.c223
-rw-r--r--src/main/extractor_logging.c11
-rw-r--r--src/main/extractor_logging.h14
-rw-r--r--src/main/extractor_metatypes.c278
-rw-r--r--src/main/extractor_plugin_main.c524
-rw-r--r--src/main/extractor_plugin_main.h4
-rw-r--r--src/main/extractor_plugins.c313
-rw-r--r--src/main/extractor_plugins.h2
-rw-r--r--src/main/extractor_plugpath.c445
-rw-r--r--src/main/extractor_plugpath.h4
-rw-r--r--src/main/extractor_print.c75
-rw-r--r--src/main/getopt.c1139
-rw-r--r--src/main/getopt.h31
-rw-r--r--src/main/getopt1.c175
-rw-r--r--src/main/iconv.c27
-rw-r--r--src/main/test2_extractor.c122
-rw-r--r--src/main/test_bzip2.c120
-rw-r--r--src/main/test_extractor.c146
-rw-r--r--src/main/test_file.c120
-rw-r--r--src/main/test_gzip.c124
-rw-r--r--src/main/test_ipc.c134
-rw-r--r--src/main/test_plugin_load_multi.c27
-rw-r--r--src/main/test_plugin_loading.c33
-rw-r--r--src/main/test_trivial.c22
-rw-r--r--src/plugins/archive_extractor.c68
-rw-r--r--src/plugins/deb_extractor.c284
-rw-r--r--src/plugins/dvi_extractor.c205
-rw-r--r--src/plugins/flac_extractor.c349
-rw-r--r--src/plugins/gif_extractor.c98
-rw-r--r--src/plugins/gstreamer_extractor.c611
-rw-r--r--src/plugins/html_extractor.c652
-rw-r--r--src/plugins/it_extractor.c49
-rw-r--r--src/plugins/jpeg_extractor.c104
-rw-r--r--src/plugins/man_extractor.c216
-rw-r--r--src/plugins/midi_extractor.c216
-rw-r--r--src/plugins/mime_extractor.c83
-rw-r--r--src/plugins/mp4_extractor.c69
-rw-r--r--src/plugins/mpeg_extractor.c253
-rw-r--r--src/plugins/nsf_extractor.c44
-rw-r--r--src/plugins/nsfe_extractor.c1
-rw-r--r--src/plugins/odf_extractor.c349
-rw-r--r--src/plugins/ogg_extractor.c33
-rw-r--r--src/plugins/old/applefile_extractor.c267
-rw-r--r--src/plugins/old/asf_extractor.c440
-rw-r--r--src/plugins/old/convert_numeric.c423
-rw-r--r--src/plugins/old/convert_numeric.h42
-rw-r--r--src/plugins/old/ebml_extractor.c509
-rw-r--r--src/plugins/old/elf_extractor.c585
-rw-r--r--src/plugins/old/flv_extractor.c878
-rw-r--r--src/plugins/old/mkv_extractor.c144
-rw-r--r--src/plugins/old/mp3_extractor.c110
-rw-r--r--src/plugins/old/pack.c538
-rw-r--r--src/plugins/old/pack.h14
-rw-r--r--src/plugins/old/qt_extractor.c272
-rw-r--r--src/plugins/old/real_extractor.c421
-rw-r--r--src/plugins/ole2_extractor.c814
-rw-r--r--src/plugins/pdf_extractor.c181
-rw-r--r--src/plugins/png_extractor.c225
-rw-r--r--src/plugins/previewopus_extractor.c1235
-rw-r--r--src/plugins/ps_extractor.c129
-rw-r--r--src/plugins/riff_extractor.c39
-rw-r--r--src/plugins/rpm_extractor.c383
-rw-r--r--src/plugins/s3m_extractor.c11
-rw-r--r--src/plugins/sid_extractor.c30
-rw-r--r--src/plugins/template_extractor.c5
-rw-r--r--src/plugins/test_archive.c63
-rw-r--r--src/plugins/test_deb.c259
-rw-r--r--src/plugins/test_dvi.c165
-rw-r--r--src/plugins/test_exiv2.c597
-rw-r--r--src/plugins/test_flac.c59
-rw-r--r--src/plugins/test_gif.c64
-rw-r--r--src/plugins/test_gstreamer.c3088
-rw-r--r--src/plugins/test_html.c159
-rw-r--r--src/plugins/test_it.c63
-rw-r--r--src/plugins/test_jpeg.c64
-rw-r--r--src/plugins/test_lib.c141
-rw-r--r--src/plugins/test_lib.h8
-rw-r--r--src/plugins/test_man.c80
-rw-r--r--src/plugins/test_midi.c95
-rw-r--r--src/plugins/test_mime.c117
-rw-r--r--src/plugins/test_mpeg.c137
-rw-r--r--src/plugins/test_nsf.c144
-rw-r--r--src/plugins/test_nsfe.c176
-rw-r--r--src/plugins/test_odf.c112
-rw-r--r--src/plugins/test_ogg.c96
-rw-r--r--src/plugins/test_ole2.c907
-rw-r--r--src/plugins/test_png.c79
-rw-r--r--src/plugins/test_previewopus.c22
-rw-r--r--src/plugins/test_ps.c189
-rw-r--r--src/plugins/test_riff.c64
-rw-r--r--src/plugins/test_rpm.c542
-rw-r--r--src/plugins/test_s3m.c48
-rw-r--r--src/plugins/test_sid.c159
-rw-r--r--src/plugins/test_thumbnailffmpeg.c20
-rw-r--r--src/plugins/test_thumbnailgtk.c48
-rw-r--r--src/plugins/test_tiff.c152
-rw-r--r--src/plugins/test_wav.c89
-rw-r--r--src/plugins/test_xm.c80
-rw-r--r--src/plugins/test_zip.c127
-rw-r--r--src/plugins/thumbnailffmpeg_extractor.c705
-rw-r--r--src/plugins/thumbnailgtk_extractor.c155
-rw-r--r--src/plugins/tiff_extractor.c123
-rw-r--r--src/plugins/wav_extractor.c44
-rw-r--r--src/plugins/xm_extractor.c21
-rw-r--r--src/plugins/zip_extractor.c131
129 files changed, 16203 insertions, 15146 deletions
diff --git a/bootstrap b/bootstrap
index 60e0203..7e15079 100755
--- a/bootstrap
+++ b/bootstrap
@@ -1,4 +1,34 @@
1#!/bin/sh 1#!/bin/sh
2# This file is in the public domain. 2unset bs_srcdir
3rm -rf libltdl 3if test X"`dirname / 2>/dev/null`" = X"/"; then
4autoreconf -if 4 bs_scrdir=`dirname $0`
5else
6 bs_scrdir="${0%/*}"
7fi
8
9test -n "$bs_scrdir" && cd "$bs_scrdir" || echo "Warning: cannot get sources directory" 1>&2
10
11# This is more portable than `which' but comes with
12# the caveat of not(?) properly working on busybox's ash:
13existence()
14{
15 command -v "$1" >/dev/null 2>&1
16}
17
18
19if existence uncrustify; then
20 echo "Installing uncrustify hook and configuration"
21 # Install uncrustify format symlink (if possible)
22 ln -s contrib/uncrustify.cfg uncrustify.cfg 2> /dev/null
23 # Install pre-commit hook (if possible)
24 ln -s ../../contrib/uncrustify_precommit .git/hooks/pre-commit 2> /dev/null
25else
26 echo "Uncrustify not detected, hook not installed. Please install uncrustify if you plan on doing development"
27fi
28
29if existence libtool || existence libtoolize || existence glibtoolize || existence slibtool; then
30 autoreconf -I m4 -i ${1+"$@"}
31else
32 echo "*** No libtoolize (libtool) or libtool found, please install it ***" >&2;
33 exit 1
34fi
diff --git a/contrib/uncrustify.cfg b/contrib/uncrustify.cfg
new file mode 100644
index 0000000..8c9df2c
--- /dev/null
+++ b/contrib/uncrustify.cfg
@@ -0,0 +1,95 @@
1input_tab_size = 2
2output_tab_size = 2
3
4indent_columns = 2
5indent_with_tabs = 0
6indent_case_brace = 2
7indent_label=-16
8
9code_width=80
10#cmd_width=80
11
12# Leave most comments alone for now
13cmt_indent_multi=false
14sp_cmt_cpp_start=add
15
16sp_not=add
17
18sp_func_call_user_paren_paren=remove
19sp_inside_fparen=remove
20sp_after_cast=add
21
22ls_for_split_full=true
23ls_func_split_full=true
24ls_code_width=true
25
26# Arithmetic operations in wrapped expressions should be at the start
27# of the line.
28pos_arith=lead
29
30# Fully parenthesize boolean exprs
31mod_full_paren_if_bool=true
32
33# Braces should be on their own line
34nl_fdef_brace=add
35nl_enum_brace=add
36nl_struct_brace=add
37nl_union_brace=add
38nl_if_brace=add
39nl_brace_else=add
40nl_elseif_brace=add
41nl_while_brace=add
42nl_switch_brace=add
43
44# no newline between "else" and "if"
45nl_else_if=remove
46
47nl_func_paren=remove
48nl_assign_brace=remove
49
50# No extra newlines that cause noisy diffs
51nl_start_of_file=remove
52nl_after_func_proto = 2
53nl_after_func_body = 3
54# If there's no new line, it's not a text file!
55nl_end_of_file=add
56nl_max_blank_in_func = 3
57nl_max = 3
58
59sp_inside_paren = remove
60
61sp_arith = add
62sp_arith_additive = add
63
64# We want spaces before and after "="
65sp_before_assign = add
66sp_after_assign = add
67
68# we want "char *foo;"
69sp_after_ptr_star = remove
70sp_between_ptr_star = remove
71
72# we want "if (foo) { ... }"
73sp_before_sparen = add
74
75sp_inside_fparen = remove
76sp_inside_sparen = remove
77
78# add space before function call and decl: "foo (x)"
79sp_func_call_paren = add
80sp_func_proto_paren = add
81sp_func_proto_paren_empty = add
82sp_func_def_paren = add
83sp_func_def_paren_empty = add
84
85# We'd want it for "if ( (foo) || (bar) )", but not for "if (m())",
86# so as uncrustify doesn't give exactly what we want => ignore
87sp_paren_paren = ignore
88sp_inside_paren = remove
89sp_bool = force
90
91nl_func_type_name = force
92#nl_branch_else = add
93nl_else_brace = add
94nl_elseif_brace = add
95nl_for_brace = add
diff --git a/contrib/uncrustify.sh b/contrib/uncrustify.sh
new file mode 100755
index 0000000..e8e05d3
--- /dev/null
+++ b/contrib/uncrustify.sh
@@ -0,0 +1,14 @@
1#!/usr/bin/env bash
2
3set -eu
4
5DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
6
7if ! uncrustify --version >/dev/null; then
8 echo "you need to install uncrustify for indentation"
9 exit 1
10fi
11
12find "$DIR/../src" \( -name "*.cpp" -o -name "*.c" -o -name "*.h" \) \
13 -exec uncrustify -c "$DIR/uncrustify.cfg" --replace --no-backup {} + \
14 || true
diff --git a/contrib/uncrustify_precommit b/contrib/uncrustify_precommit
new file mode 100755
index 0000000..fd29998
--- /dev/null
+++ b/contrib/uncrustify_precommit
@@ -0,0 +1,35 @@
1#!/bin/sh
2
3# use as .git/hooks/pre-commit
4
5exec 1>&2
6
7RET=0
8changed=$(git diff --cached --name-only)
9crustified=""
10
11for f in $changed;
12do
13 if echo $f | grep \\.[c,h]\$ > /dev/null
14 then
15 # compare result of uncrustify with changes
16 #
17 # only change any of the invocations here if
18 # they are portable across all cmp and shell
19 # implementations !
20 uncrustify -q -c uncrustify.cfg -f $f | cmp -s $f -
21 if test $? = 1 ;
22 then
23 crustified=" $crustified $f"
24 RET=1
25 fi
26 fi
27done
28
29if [ $RET = 1 ];
30then
31 echo "Run"
32 echo "uncrustify --no-backup -c uncrustify.cfg ${crustified}"
33 echo "before commiting."
34fi
35exit $RET
diff --git a/src/common/convert.c b/src/common/convert.c
index 2be2108..a8a6b9d 100644
--- a/src/common/convert.c
+++ b/src/common/convert.c
@@ -37,8 +37,8 @@
37 */ 37 */
38char * 38char *
39EXTRACTOR_common_convert_to_utf8 (const char *input, 39EXTRACTOR_common_convert_to_utf8 (const char *input,
40 size_t len, 40 size_t len,
41 const char *charset) 41 const char *charset)
42{ 42{
43#if HAVE_ICONV 43#if HAVE_ICONV
44 size_t tmpSize; 44 size_t tmpSize;
@@ -51,35 +51,35 @@ EXTRACTOR_common_convert_to_utf8 (const char *input,
51 51
52 i = input; 52 i = input;
53 cd = iconv_open ("UTF-8", charset); 53 cd = iconv_open ("UTF-8", charset);
54 if (cd == (iconv_t) - 1) 54 if (cd == (iconv_t) -1)
55 return strndup (i, len); 55 return strndup (i, len);
56 if (len > 1024 * 1024) 56 if (len > 1024 * 1024)
57 { 57 {
58 iconv_close (cd); 58 iconv_close (cd);
59 return NULL; /* too big for meta data */ 59 return NULL; /* too big for meta data */
60 } 60 }
61 tmpSize = 3 * len + 4; 61 tmpSize = 3 * len + 4;
62 tmp = malloc (tmpSize); 62 tmp = malloc (tmpSize);
63 if (tmp == NULL) 63 if (tmp == NULL)
64 { 64 {
65 iconv_close (cd); 65 iconv_close (cd);
66 return NULL; 66 return NULL;
67 } 67 }
68 itmp = tmp; 68 itmp = tmp;
69 finSize = tmpSize; 69 finSize = tmpSize;
70 if (iconv (cd, (char **) &input, &len, &itmp, &finSize) == ((size_t) -1)) 70 if (iconv (cd, (char **) &input, &len, &itmp, &finSize) == ((size_t) -1))
71 { 71 {
72 iconv_close (cd); 72 iconv_close (cd);
73 free (tmp); 73 free (tmp);
74 return strndup (i, len); 74 return strndup (i, len);
75 } 75 }
76 ret = malloc (tmpSize - finSize + 1); 76 ret = malloc (tmpSize - finSize + 1);
77 if (ret == NULL) 77 if (ret == NULL)
78 { 78 {
79 iconv_close (cd); 79 iconv_close (cd);
80 free (tmp); 80 free (tmp);
81 return NULL; 81 return NULL;
82 } 82 }
83 memcpy (ret, tmp, tmpSize - finSize); 83 memcpy (ret, tmp, tmpSize - finSize);
84 ret[tmpSize - finSize] = '\0'; 84 ret[tmpSize - finSize] = '\0';
85 free (tmp); 85 free (tmp);
@@ -95,4 +95,5 @@ EXTRACTOR_common_convert_to_utf8 (const char *input,
95#endif 95#endif
96} 96}
97 97
98
98/* end of convert.c */ 99/* end of convert.c */
diff --git a/src/common/convert.h b/src/common/convert.h
index 9e1bf52..0600cbb 100644
--- a/src/common/convert.h
+++ b/src/common/convert.h
@@ -38,10 +38,10 @@ extern "C" {
38 * @param charset input character set 38 * @param charset input character set
39 * @return the converted string (0-terminated), NULL on error 39 * @return the converted string (0-terminated), NULL on error
40 */ 40 */
41char * 41char *
42EXTRACTOR_common_convert_to_utf8 (const char * input, 42EXTRACTOR_common_convert_to_utf8 (const char *input,
43 size_t len, 43 size_t len,
44 const char *charset); 44 const char *charset);
45 45
46#ifdef __cplusplus 46#ifdef __cplusplus
47} 47}
diff --git a/src/common/le_architecture.h b/src/common/le_architecture.h
index b863ddb..fb5044b 100644
--- a/src/common/le_architecture.h
+++ b/src/common/le_architecture.h
@@ -108,13 +108,13 @@
108 * gcc 4.x-ism to pack structures even on W32 (to be used before structs) 108 * gcc 4.x-ism to pack structures even on W32 (to be used before structs)
109 */ 109 */
110#define LE_NETWORK_STRUCT_BEGIN \ 110#define LE_NETWORK_STRUCT_BEGIN \
111 _Pragma("pack(push)") \ 111 _Pragma ("pack(push)") \
112 _Pragma("pack(1)") 112 _Pragma ("pack(1)")
113 113
114/** 114/**
115 * gcc 4.x-ism to pack structures even on W32 (to be used after structs) 115 * gcc 4.x-ism to pack structures even on W32 (to be used after structs)
116 */ 116 */
117#define LE_NETWORK_STRUCT_END _Pragma("pack(pop)") 117#define LE_NETWORK_STRUCT_END _Pragma ("pack(pop)")
118#else 118#else
119#error gcc 4.x or higher required on W32 systems 119#error gcc 4.x or higher required on W32 systems
120#endif 120#endif
@@ -122,7 +122,7 @@
122/** 122/**
123 * Good luck, LE_PACKED should suffice, but this won't work on W32 123 * Good luck, LE_PACKED should suffice, but this won't work on W32
124 */ 124 */
125#define LE_NETWORK_STRUCT_BEGIN 125#define LE_NETWORK_STRUCT_BEGIN
126 126
127/** 127/**
128 * Good luck, LE_PACKED should suffice, but this won't work on W32 128 * Good luck, LE_PACKED should suffice, but this won't work on W32
diff --git a/src/common/unzip.c b/src/common/unzip.c
index 46683f0..a469a5b 100644
--- a/src/common/unzip.c
+++ b/src/common/unzip.c
@@ -87,7 +87,7 @@ struct FileFuncDefs
87 /** 87 /**
88 * Callback for reading 'size' bytes from the ZIP archive into buf. 88 * Callback for reading 'size' bytes from the ZIP archive into buf.
89 */ 89 */
90 uLong (*zread_file) (voidpf opaque, void* buf, uLong size); 90 uLong (*zread_file) (voidpf opaque, void*buf, uLong size);
91 91
92 /** 92 /**
93 * Callback to obtain the current read offset in the ZIP archive. 93 * Callback to obtain the current read offset in the ZIP archive.
@@ -114,7 +114,8 @@ struct FileFuncDefs
114 * @param size number of bytes to read 114 * @param size number of bytes to read
115 * @return number of bytes copied to buf 115 * @return number of bytes copied to buf
116 */ 116 */
117#define ZREAD(filefunc,buf,size) ((*((filefunc).zread_file)) ((filefunc).opaque, buf, size)) 117#define ZREAD(filefunc,buf,size) ((*((filefunc).zread_file))((filefunc).opaque, \
118 buf, size))
118 119
119/** 120/**
120 * Macro to obtain current offset in file using filefunc API. 121 * Macro to obtain current offset in file using filefunc API.
@@ -122,7 +123,7 @@ struct FileFuncDefs
122 * @param filefunc filefunc struct 123 * @param filefunc filefunc struct
123 * @return current offset in file 124 * @return current offset in file
124 */ 125 */
125#define ZTELL(filefunc) ((*((filefunc).ztell_file)) ((filefunc).opaque)) 126#define ZTELL(filefunc) ((*((filefunc).ztell_file))((filefunc).opaque))
126 127
127/** 128/**
128 * Macro to seek using filefunc API. 129 * Macro to seek using filefunc API.
@@ -132,7 +133,8 @@ struct FileFuncDefs
132 * @param mode seek mode 133 * @param mode seek mode
133 * @return 0 on success 134 * @return 0 on success
134 */ 135 */
135#define ZSEEK(filefunc,pos,mode) ((*((filefunc).zseek_file)) ((filefunc).opaque, pos, mode)) 136#define ZSEEK(filefunc,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque, \
137 pos, mode))
136 138
137 139
138/** 140/**
@@ -208,7 +210,7 @@ struct FileInZipReadInfo
208 /** 210 /**
209 * size of the local extra field 211 * size of the local extra field
210 */ 212 */
211 uInt size_local_extrafield; 213 uInt size_local_extrafield;
212 214
213 /** 215 /**
214 * position in the local extra field in read 216 * position in the local extra field in read
@@ -337,7 +339,7 @@ struct EXTRACTOR_UnzipFile
337 */ 339 */
338static int 340static int
339read_byte_from_ffd (const struct FileFuncDefs *ffd, 341read_byte_from_ffd (const struct FileFuncDefs *ffd,
340 int *pi) 342 int *pi)
341{ 343{
342 unsigned char c; 344 unsigned char c;
343 345
@@ -359,7 +361,7 @@ read_byte_from_ffd (const struct FileFuncDefs *ffd,
359 */ 361 */
360static int 362static int
361read_short_from_ffd (const struct FileFuncDefs *ffd, 363read_short_from_ffd (const struct FileFuncDefs *ffd,
362 uLong *pX) 364 uLong *pX)
363{ 365{
364 uLong x; 366 uLong x;
365 int i; 367 int i;
@@ -388,7 +390,7 @@ read_short_from_ffd (const struct FileFuncDefs *ffd,
388 */ 390 */
389static int 391static int
390read_long_from_ffd (const struct FileFuncDefs *ffd, 392read_long_from_ffd (const struct FileFuncDefs *ffd,
391 uLong *pX) 393 uLong *pX)
392{ 394{
393 uLong x; 395 uLong x;
394 int i; 396 int i;
@@ -413,7 +415,7 @@ read_long_from_ffd (const struct FileFuncDefs *ffd,
413 415
414 416
415#ifndef CASESENSITIVITYDEFAULT_NO 417#ifndef CASESENSITIVITYDEFAULT_NO
416#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) 418#if ! defined(unix) && ! defined(CASESENSITIVITYDEFAULT_YES)
417#define CASESENSITIVITYDEFAULT_NO 419#define CASESENSITIVITYDEFAULT_NO
418#endif 420#endif
419#endif 421#endif
@@ -436,14 +438,14 @@ read_long_from_ffd (const struct FileFuncDefs *ffd,
436 * @return 0 if names are equal 438 * @return 0 if names are equal
437 */ 439 */
438static int 440static int
439EXTRACTOR_common_unzip_string_file_name_compare (const char* fileName1, 441EXTRACTOR_common_unzip_string_file_name_compare (const char*fileName1,
440 const char* fileName2, 442 const char*fileName2,
441 int iCaseSensitivity) 443 int iCaseSensitivity)
442{ 444{
443 if (0 == iCaseSensitivity) 445 if (0 == iCaseSensitivity)
444 iCaseSensitivity = CASESENSITIVITYDEFAULTVALUE; 446 iCaseSensitivity = CASESENSITIVITYDEFAULTVALUE;
445 if (1 == iCaseSensitivity) 447 if (1 == iCaseSensitivity)
446 return strcmp(fileName1, fileName2); 448 return strcmp (fileName1, fileName2);
447 return strcasecmp (fileName1, fileName2); 449 return strcasecmp (fileName1, fileName2);
448} 450}
449 451
@@ -474,31 +476,31 @@ locate_central_directory (const struct FileFuncDefs *ffd)
474 uMaxBack = uSizeFile; 476 uMaxBack = uSizeFile;
475 uBackRead = 4; 477 uBackRead = 4;
476 while (uBackRead < uMaxBack) 478 while (uBackRead < uMaxBack)
477 { 479 {
478 uLong uReadSize; 480 uLong uReadSize;
479 uLong uReadPos; 481 uLong uReadPos;
480 int i; 482 int i;
481 483
482 if (uBackRead + BUFREADCOMMENT > uMaxBack) 484 if (uBackRead + BUFREADCOMMENT > uMaxBack)
483 uBackRead = uMaxBack; 485 uBackRead = uMaxBack;
484 else 486 else
485 uBackRead += BUFREADCOMMENT; 487 uBackRead += BUFREADCOMMENT;
486 uReadPos = uSizeFile - uBackRead; 488 uReadPos = uSizeFile - uBackRead;
487 uReadSize = ((BUFREADCOMMENT + 4) < (uSizeFile - uReadPos)) 489 uReadSize = ((BUFREADCOMMENT + 4) < (uSizeFile - uReadPos))
488 ? (BUFREADCOMMENT + 4) 490 ? (BUFREADCOMMENT + 4)
489 : (uSizeFile - uReadPos); 491 : (uSizeFile - uReadPos);
490 if (0 != ZSEEK (*ffd, uReadPos, SEEK_SET)) 492 if (0 != ZSEEK (*ffd, uReadPos, SEEK_SET))
491 break; 493 break;
492 if (ZREAD (*ffd, buf, uReadSize) != uReadSize) 494 if (ZREAD (*ffd, buf, uReadSize) != uReadSize)
493 break; 495 break;
494 i = (int) uReadSize - 3; 496 i = (int) uReadSize - 3;
495 while (i-- > 0) 497 while (i-- > 0)
496 if ( (0x50 == (*(buf+i))) && 498 if ( (0x50 == (*(buf + i))) &&
497 (0x4b == (*(buf+i+1))) && 499 (0x4b == (*(buf + i + 1))) &&
498 (0x05 == (*(buf+i+2))) && 500 (0x05 == (*(buf + i + 2))) &&
499 (0x06 == (*(buf+i+3))) ) 501 (0x06 == (*(buf + i + 3))) )
500 return uReadPos + i; 502 return uReadPos + i;
501 } 503 }
502 return 0; 504 return 0;
503} 505}
504 506
@@ -512,7 +514,7 @@ locate_central_directory (const struct FileFuncDefs *ffd)
512 */ 514 */
513static void 515static void
514dos_date_to_tmu_date (uLong ulDosDate, 516dos_date_to_tmu_date (uLong ulDosDate,
515 struct EXTRACTOR_UnzipDateTimeInfo* ptm) 517 struct EXTRACTOR_UnzipDateTimeInfo*ptm)
516{ 518{
517 uLong uDate; 519 uLong uDate;
518 520
@@ -543,14 +545,14 @@ dos_date_to_tmu_date (uLong ulDosDate,
543 */ 545 */
544static int 546static int
545get_current_file_info (struct EXTRACTOR_UnzipFile *file, 547get_current_file_info (struct EXTRACTOR_UnzipFile *file,
546 struct EXTRACTOR_UnzipFileInfo *pfile_info, 548 struct EXTRACTOR_UnzipFileInfo *pfile_info,
547 struct UnzipFileInfoInternal *pfile_info_internal, 549 struct UnzipFileInfoInternal *pfile_info_internal,
548 char *szFileName, 550 char *szFileName,
549 uLong fileNameBufferSize, 551 uLong fileNameBufferSize,
550 void *extraField, 552 void *extraField,
551 uLong extraFieldBufferSize, 553 uLong extraFieldBufferSize,
552 char *szComment, 554 char *szComment,
553 uLong commentBufferSize) 555 uLong commentBufferSize)
554{ 556{
555 struct EXTRACTOR_UnzipFileInfo file_info; 557 struct EXTRACTOR_UnzipFileInfo file_info;
556 struct UnzipFileInfoInternal file_info_internal; 558 struct UnzipFileInfoInternal file_info_internal;
@@ -560,128 +562,130 @@ get_current_file_info (struct EXTRACTOR_UnzipFile *file,
560 if (NULL == file) 562 if (NULL == file)
561 return EXTRACTOR_UNZIP_PARAMERROR; 563 return EXTRACTOR_UNZIP_PARAMERROR;
562 if (0 != ZSEEK (file->z_filefunc, 564 if (0 != ZSEEK (file->z_filefunc,
563 file->pos_in_central_dir + file->byte_before_the_zipfile, 565 file->pos_in_central_dir + file->byte_before_the_zipfile,
564 SEEK_SET)) 566 SEEK_SET))
565 return EXTRACTOR_UNZIP_ERRNO; 567 return EXTRACTOR_UNZIP_ERRNO;
566 568
567 /* we check the magic */ 569 /* we check the magic */
568 if (EXTRACTOR_UNZIP_OK != 570 if (EXTRACTOR_UNZIP_OK !=
569 read_long_from_ffd(&file->z_filefunc, &uMagic)) 571 read_long_from_ffd (&file->z_filefunc, &uMagic))
570 return EXTRACTOR_UNZIP_ERRNO; 572 return EXTRACTOR_UNZIP_ERRNO;
571 if (0x02014b50 != uMagic) 573 if (0x02014b50 != uMagic)
572 return EXTRACTOR_UNZIP_BADZIPFILE; 574 return EXTRACTOR_UNZIP_BADZIPFILE;
573 575
574 if ( (EXTRACTOR_UNZIP_OK != 576 if ( (EXTRACTOR_UNZIP_OK !=
575 read_short_from_ffd (&file->z_filefunc, &file_info.version)) || 577 read_short_from_ffd (&file->z_filefunc, &file_info.version)) ||
576 (EXTRACTOR_UNZIP_OK != 578 (EXTRACTOR_UNZIP_OK !=
577 read_short_from_ffd (&file->z_filefunc, &file_info.version_needed)) || 579 read_short_from_ffd (&file->z_filefunc, &file_info.version_needed)) ||
578 (EXTRACTOR_UNZIP_OK != 580 (EXTRACTOR_UNZIP_OK !=
579 read_short_from_ffd (&file->z_filefunc, &file_info.flag)) || 581 read_short_from_ffd (&file->z_filefunc, &file_info.flag)) ||
580 (EXTRACTOR_UNZIP_OK != 582 (EXTRACTOR_UNZIP_OK !=
581 read_short_from_ffd (&file->z_filefunc, &file_info.compression_method)) || 583 read_short_from_ffd (&file->z_filefunc,
584 &file_info.compression_method)) ||
582 (EXTRACTOR_UNZIP_OK != 585 (EXTRACTOR_UNZIP_OK !=
583 read_long_from_ffd (&file->z_filefunc, &file_info.dosDate)) ) 586 read_long_from_ffd (&file->z_filefunc, &file_info.dosDate)) )
584 return EXTRACTOR_UNZIP_ERRNO; 587 return EXTRACTOR_UNZIP_ERRNO;
585 dos_date_to_tmu_date (file_info.dosDate, 588 dos_date_to_tmu_date (file_info.dosDate,
586 &file_info.tmu_date); 589 &file_info.tmu_date);
587 if ( (EXTRACTOR_UNZIP_OK != 590 if ( (EXTRACTOR_UNZIP_OK !=
588 read_long_from_ffd(&file->z_filefunc, &file_info.crc)) || 591 read_long_from_ffd (&file->z_filefunc, &file_info.crc)) ||
589 (EXTRACTOR_UNZIP_OK != 592 (EXTRACTOR_UNZIP_OK !=
590 read_long_from_ffd(&file->z_filefunc, &file_info.compressed_size)) || 593 read_long_from_ffd (&file->z_filefunc, &file_info.compressed_size)) ||
591 (EXTRACTOR_UNZIP_OK != 594 (EXTRACTOR_UNZIP_OK !=
592 read_long_from_ffd(&file->z_filefunc, &file_info.uncompressed_size)) || 595 read_long_from_ffd (&file->z_filefunc, &file_info.uncompressed_size)) ||
593 (EXTRACTOR_UNZIP_OK != 596 (EXTRACTOR_UNZIP_OK !=
594 read_short_from_ffd(&file->z_filefunc, &file_info.size_filename)) || 597 read_short_from_ffd (&file->z_filefunc, &file_info.size_filename)) ||
595 (EXTRACTOR_UNZIP_OK != 598 (EXTRACTOR_UNZIP_OK !=
596 read_short_from_ffd(&file->z_filefunc, &file_info.size_file_extra)) || 599 read_short_from_ffd (&file->z_filefunc, &file_info.size_file_extra)) ||
597 (EXTRACTOR_UNZIP_OK != 600 (EXTRACTOR_UNZIP_OK !=
598 read_short_from_ffd(&file->z_filefunc, &file_info.size_file_comment)) || 601 read_short_from_ffd (&file->z_filefunc,
602 &file_info.size_file_comment)) ||
599 (EXTRACTOR_UNZIP_OK != 603 (EXTRACTOR_UNZIP_OK !=
600 read_short_from_ffd(&file->z_filefunc, &file_info.disk_num_start)) || 604 read_short_from_ffd (&file->z_filefunc, &file_info.disk_num_start)) ||
601 (EXTRACTOR_UNZIP_OK != 605 (EXTRACTOR_UNZIP_OK !=
602 read_short_from_ffd(&file->z_filefunc, &file_info.internal_fa)) || 606 read_short_from_ffd (&file->z_filefunc, &file_info.internal_fa)) ||
603 (EXTRACTOR_UNZIP_OK != 607 (EXTRACTOR_UNZIP_OK !=
604 read_long_from_ffd(&file->z_filefunc, &file_info.external_fa)) || 608 read_long_from_ffd (&file->z_filefunc, &file_info.external_fa)) ||
605 (EXTRACTOR_UNZIP_OK != 609 (EXTRACTOR_UNZIP_OK !=
606 read_long_from_ffd (&file->z_filefunc, 610 read_long_from_ffd (&file->z_filefunc,
607 &file_info_internal.offset_curfile)) ) 611 &file_info_internal.offset_curfile)) )
608 return EXTRACTOR_UNZIP_ERRNO; 612 return EXTRACTOR_UNZIP_ERRNO;
609 613
610 lSeek += file_info.size_filename; 614 lSeek += file_info.size_filename;
611 if (NULL != szFileName) 615 if (NULL != szFileName)
612 { 616 {
613 uLong uSizeRead; 617 uLong uSizeRead;
614 618
615 if (file_info.size_filename < fileNameBufferSize) 619 if (file_info.size_filename < fileNameBufferSize)
616 { 620 {
617 *(szFileName + file_info.size_filename) = '\0'; 621 *(szFileName + file_info.size_filename) = '\0';
618 uSizeRead = file_info.size_filename; 622 uSizeRead = file_info.size_filename;
619 }
620 else
621 uSizeRead = fileNameBufferSize;
622
623 if ( (file_info.size_filename > 0) &&
624 (fileNameBufferSize > 0) )
625 if (ZREAD(file->z_filefunc, szFileName, uSizeRead) != uSizeRead)
626 return EXTRACTOR_UNZIP_ERRNO;
627 lSeek -= uSizeRead;
628 } 623 }
624 else
625 uSizeRead = fileNameBufferSize;
626
627 if ( (file_info.size_filename > 0) &&
628 (fileNameBufferSize > 0) )
629 if (ZREAD (file->z_filefunc, szFileName, uSizeRead) != uSizeRead)
630 return EXTRACTOR_UNZIP_ERRNO;
631 lSeek -= uSizeRead;
632 }
629 633
630 if (NULL != extraField) 634 if (NULL != extraField)
631 { 635 {
632 uLong uSizeRead; 636 uLong uSizeRead;
637
638 if (file_info.size_file_extra<extraFieldBufferSize)
639 uSizeRead = file_info.size_file_extra;
640 else
641 uSizeRead = extraFieldBufferSize;
633 642
634 if (file_info.size_file_extra<extraFieldBufferSize) 643 if (0 != lSeek)
635 uSizeRead = file_info.size_file_extra; 644 {
645 if (0 == ZSEEK (file->z_filefunc, lSeek, SEEK_CUR))
646 lSeek = 0;
636 else 647 else
637 uSizeRead = extraFieldBufferSize; 648 return EXTRACTOR_UNZIP_ERRNO;
638
639 if (0 != lSeek)
640 {
641 if (0 == ZSEEK (file->z_filefunc, lSeek, SEEK_CUR))
642 lSeek = 0;
643 else
644 return EXTRACTOR_UNZIP_ERRNO;
645 }
646 if ( (file_info.size_file_extra > 0) &&
647 (extraFieldBufferSize > 0) &&
648 (ZREAD (file->z_filefunc,
649 extraField,
650 uSizeRead) != uSizeRead) )
651 return EXTRACTOR_UNZIP_ERRNO;
652 lSeek += file_info.size_file_extra - uSizeRead;
653 } 649 }
650 if ( (file_info.size_file_extra > 0) &&
651 (extraFieldBufferSize > 0) &&
652 (ZREAD (file->z_filefunc,
653 extraField,
654 uSizeRead) != uSizeRead) )
655 return EXTRACTOR_UNZIP_ERRNO;
656 lSeek += file_info.size_file_extra - uSizeRead;
657 }
654 else 658 else
655 lSeek += file_info.size_file_extra; 659 lSeek += file_info.size_file_extra;
656 660
657 if (NULL != szComment) 661 if (NULL != szComment)
662 {
663 uLong uSizeRead;
664
665 if (file_info.size_file_comment < commentBufferSize)
658 { 666 {
659 uLong uSizeRead; 667 *(szComment + file_info.size_file_comment) = '\0';
668 uSizeRead = file_info.size_file_comment;
669 }
670 else
671 {
672 *(szComment + commentBufferSize - 1) = '\0';
673 uSizeRead = commentBufferSize - 1;
674 }
660 675
661 if (file_info.size_file_comment < commentBufferSize) 676 if (0 != lSeek)
662 { 677 {
663 *(szComment+file_info.size_file_comment) = '\0'; 678 if (0 == ZSEEK (file->z_filefunc, lSeek, SEEK_CUR))
664 uSizeRead = file_info.size_file_comment; 679 lSeek = 0;
665 }
666 else 680 else
667 { 681 return EXTRACTOR_UNZIP_ERRNO;
668 *(szComment+commentBufferSize - 1) = '\0';
669 uSizeRead = commentBufferSize - 1;
670 }
671
672 if (0 != lSeek)
673 {
674 if (0 == ZSEEK (file->z_filefunc, lSeek, SEEK_CUR))
675 lSeek = 0;
676 else
677 return EXTRACTOR_UNZIP_ERRNO;
678 }
679 if ( (file_info.size_file_comment > 0) &&
680 (commentBufferSize > 0) &&
681 (ZREAD (file->z_filefunc, szComment, uSizeRead) != uSizeRead) )
682 return EXTRACTOR_UNZIP_ERRNO;
683 lSeek += file_info.size_file_comment - uSizeRead;
684 } 682 }
683 if ( (file_info.size_file_comment > 0) &&
684 (commentBufferSize > 0) &&
685 (ZREAD (file->z_filefunc, szComment, uSizeRead) != uSizeRead) )
686 return EXTRACTOR_UNZIP_ERRNO;
687 lSeek += file_info.size_file_comment - uSizeRead;
688 }
685 else 689 else
686 lSeek += file_info.size_file_comment; 690 lSeek += file_info.size_file_comment;
687 691
@@ -709,9 +713,9 @@ EXTRACTOR_common_unzip_go_to_first_file (struct EXTRACTOR_UnzipFile *file)
709 file->pos_in_central_dir = file->offset_central_dir; 713 file->pos_in_central_dir = file->offset_central_dir;
710 file->num_file = 0; 714 file->num_file = 0;
711 err = get_current_file_info (file, 715 err = get_current_file_info (file,
712 &file->cur_file_info, 716 &file->cur_file_info,
713 &file->cur_file_info_internal, 717 &file->cur_file_info_internal,
714 NULL, 0, NULL, 0, NULL, 0); 718 NULL, 0, NULL, 0, NULL, 0);
715 file->current_file_ok = (EXTRACTOR_UNZIP_OK == err); 719 file->current_file_ok = (EXTRACTOR_UNZIP_OK == err);
716 return err; 720 return err;
717} 721}
@@ -731,12 +735,12 @@ unzip_open_using_ffd (struct FileFuncDefs *ffd)
731 uLong central_pos; 735 uLong central_pos;
732 uLong uL; 736 uLong uL;
733 uLong number_disk; /* number of the current dist, used for 737 uLong number_disk; /* number of the current dist, used for
734 spaning ZIP, unsupported, always 0*/ 738 spaning ZIP, unsupported, always 0*/
735 uLong number_disk_with_CD; /* number of the disk with central dir, used 739 uLong number_disk_with_CD; /* number of the disk with central dir, used
736 for spaning ZIP, unsupported, always 0*/ 740 for spaning ZIP, unsupported, always 0*/
737 uLong number_entry_CD; /* total number of entries in 741 uLong number_entry_CD; /* total number of entries in
738 the central dir 742 the central dir
739 (same than number_entry on nospan) */ 743 (same than number_entry on nospan) */
740 744
741 memset (&us, 0, sizeof(us)); 745 memset (&us, 0, sizeof(us));
742 us.z_filefunc = *ffd; 746 us.z_filefunc = *ffd;
@@ -744,7 +748,7 @@ unzip_open_using_ffd (struct FileFuncDefs *ffd)
744 if (0 == central_pos) 748 if (0 == central_pos)
745 return NULL; 749 return NULL;
746 if (0 != ZSEEK (us.z_filefunc, 750 if (0 != ZSEEK (us.z_filefunc,
747 central_pos, SEEK_SET)) 751 central_pos, SEEK_SET))
748 return NULL; 752 return NULL;
749 753
750 /* the signature, already checked */ 754 /* the signature, already checked */
@@ -796,8 +800,8 @@ unzip_open_using_ffd (struct FileFuncDefs *ffd)
796 if ((central_pos < us.offset_central_dir + us.size_central_dir)) 800 if ((central_pos < us.offset_central_dir + us.size_central_dir))
797 return NULL; 801 return NULL;
798 802
799 us.byte_before_the_zipfile = central_pos - 803 us.byte_before_the_zipfile = central_pos
800 (us.offset_central_dir + us.size_central_dir); 804 - (us.offset_central_dir + us.size_central_dir);
801 us.central_pos = central_pos; 805 us.central_pos = central_pos;
802 us.pfile_in_zip_read = NULL; 806 us.pfile_in_zip_read = NULL;
803 us.encrypted = 0; 807 us.encrypted = 0;
@@ -818,7 +822,7 @@ unzip_open_using_ffd (struct FileFuncDefs *ffd)
818int 822int
819EXTRACTOR_common_unzip_close_current_file (struct EXTRACTOR_UnzipFile *file) 823EXTRACTOR_common_unzip_close_current_file (struct EXTRACTOR_UnzipFile *file)
820{ 824{
821 struct FileInZipReadInfo* pfile_in_zip_read_info; 825 struct FileInZipReadInfo*pfile_in_zip_read_info;
822 int err = EXTRACTOR_UNZIP_OK; 826 int err = EXTRACTOR_UNZIP_OK;
823 827
824 if (NULL == file) 828 if (NULL == file)
@@ -868,8 +872,8 @@ EXTRACTOR_common_unzip_close (struct EXTRACTOR_UnzipFile *file)
868 */ 872 */
869int 873int
870EXTRACTOR_common_unzip_get_global_comment (struct EXTRACTOR_UnzipFile *file, 874EXTRACTOR_common_unzip_get_global_comment (struct EXTRACTOR_UnzipFile *file,
871 char *comment, 875 char *comment,
872 size_t comment_len) 876 size_t comment_len)
873{ 877{
874 if (NULL == file) 878 if (NULL == file)
875 return EXTRACTOR_UNZIP_PARAMERROR; 879 return EXTRACTOR_UNZIP_PARAMERROR;
@@ -901,19 +905,20 @@ EXTRACTOR_common_unzip_get_global_comment (struct EXTRACTOR_UnzipFile *file,
901 * @return #EXTRACTOR_UNZIP_OK if there is no problem. 905 * @return #EXTRACTOR_UNZIP_OK if there is no problem.
902 */ 906 */
903int 907int
904EXTRACTOR_common_unzip_get_current_file_info (struct EXTRACTOR_UnzipFile * file, 908EXTRACTOR_common_unzip_get_current_file_info (struct EXTRACTOR_UnzipFile *file,
905 struct EXTRACTOR_UnzipFileInfo *pfile_info, 909 struct EXTRACTOR_UnzipFileInfo *
906 char *szFileName, 910 pfile_info,
907 uLong fileNameBufferSize, 911 char *szFileName,
908 void *extraField, 912 uLong fileNameBufferSize,
909 uLong extraFieldBufferSize, 913 void *extraField,
910 char *szComment, 914 uLong extraFieldBufferSize,
911 uLong commentBufferSize) 915 char *szComment,
916 uLong commentBufferSize)
912{ 917{
913 return get_current_file_info (file, pfile_info, NULL, 918 return get_current_file_info (file, pfile_info, NULL,
914 szFileName, fileNameBufferSize, 919 szFileName, fileNameBufferSize,
915 extraField, extraFieldBufferSize, 920 extraField, extraFieldBufferSize,
916 szComment, commentBufferSize); 921 szComment, commentBufferSize);
917} 922}
918 923
919 924
@@ -935,13 +940,15 @@ EXTRACTOR_common_unzip_go_to_next_file (struct EXTRACTOR_UnzipFile *file)
935 return EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE; 940 return EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE;
936 if (file->num_file + 1 == file->gi.number_entry) 941 if (file->num_file + 1 == file->gi.number_entry)
937 return EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE; 942 return EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE;
938 file->pos_in_central_dir += SIZECENTRALDIRITEM + file->cur_file_info.size_filename + 943 file->pos_in_central_dir += SIZECENTRALDIRITEM
939 file->cur_file_info.size_file_extra + file->cur_file_info.size_file_comment; 944 + file->cur_file_info.size_filename
945 + file->cur_file_info.size_file_extra
946 + file->cur_file_info.size_file_comment;
940 file->num_file++; 947 file->num_file++;
941 err = get_current_file_info (file, 948 err = get_current_file_info (file,
942 &file->cur_file_info, 949 &file->cur_file_info,
943 &file->cur_file_info_internal, 950 &file->cur_file_info_internal,
944 NULL, 0, NULL, 0, NULL, 0); 951 NULL, 0, NULL, 0, NULL, 0);
945 file->current_file_ok = (EXTRACTOR_UNZIP_OK == err); 952 file->current_file_ok = (EXTRACTOR_UNZIP_OK == err);
946 return err; 953 return err;
947} 954}
@@ -960,8 +967,8 @@ EXTRACTOR_common_unzip_go_to_next_file (struct EXTRACTOR_UnzipFile *file)
960 */ 967 */
961int 968int
962EXTRACTOR_common_unzip_go_find_local_file (struct EXTRACTOR_UnzipFile *file, 969EXTRACTOR_common_unzip_go_find_local_file (struct EXTRACTOR_UnzipFile *file,
963 const char *szFileName, 970 const char *szFileName,
964 int iCaseSensitivity) 971 int iCaseSensitivity)
965{ 972{
966 int err; 973 int err;
967 /* We remember the 'current' position in the file so that we can jump 974 /* We remember the 'current' position in the file so that we can jump
@@ -987,22 +994,24 @@ EXTRACTOR_common_unzip_go_find_local_file (struct EXTRACTOR_UnzipFile *file,
987 err = EXTRACTOR_common_unzip_go_to_first_file (file); 994 err = EXTRACTOR_common_unzip_go_to_first_file (file);
988 995
989 while (EXTRACTOR_UNZIP_OK == err) 996 while (EXTRACTOR_UNZIP_OK == err)
990 { 997 {
991 char szCurrentFileName[UNZ_MAXFILENAMEINZIP + 1]; 998 char szCurrentFileName[UNZ_MAXFILENAMEINZIP + 1];
992 999
993 if (EXTRACTOR_UNZIP_OK != 1000 if (EXTRACTOR_UNZIP_OK !=
994 (err = EXTRACTOR_common_unzip_get_current_file_info (file, NULL, 1001 (err = EXTRACTOR_common_unzip_get_current_file_info (file, NULL,
995 szCurrentFileName, 1002 szCurrentFileName,
996 sizeof (szCurrentFileName) - 1, 1003 sizeof (
997 NULL, 0, NULL, 0))) 1004 szCurrentFileName)
998 break; 1005 - 1,
999 if (0 == 1006 NULL, 0, NULL, 0)))
1000 EXTRACTOR_common_unzip_string_file_name_compare (szCurrentFileName, 1007 break;
1001 szFileName, 1008 if (0 ==
1002 iCaseSensitivity)) 1009 EXTRACTOR_common_unzip_string_file_name_compare (szCurrentFileName,
1003 return EXTRACTOR_UNZIP_OK; 1010 szFileName,
1004 err = EXTRACTOR_common_unzip_go_to_next_file (file); 1011 iCaseSensitivity))
1005 } 1012 return EXTRACTOR_UNZIP_OK;
1013 err = EXTRACTOR_common_unzip_go_to_next_file (file);
1014 }
1006 1015
1007 /* We failed, so restore the state of the 'current file' to where we 1016 /* We failed, so restore the state of the 'current file' to where we
1008 * were. 1017 * were.
@@ -1027,8 +1036,8 @@ EXTRACTOR_common_unzip_go_find_local_file (struct EXTRACTOR_UnzipFile *file,
1027 */ 1036 */
1028ssize_t 1037ssize_t
1029EXTRACTOR_common_unzip_read_current_file (struct EXTRACTOR_UnzipFile *file, 1038EXTRACTOR_common_unzip_read_current_file (struct EXTRACTOR_UnzipFile *file,
1030 void *buf, 1039 void *buf,
1031 size_t len) 1040 size_t len)
1032{ 1041{
1033 int err = EXTRACTOR_UNZIP_OK; 1042 int err = EXTRACTOR_UNZIP_OK;
1034 uInt iRead = 0; 1043 uInt iRead = 0;
@@ -1050,97 +1059,97 @@ EXTRACTOR_common_unzip_read_current_file (struct EXTRACTOR_UnzipFile *file,
1050 (uInt) pfile_in_zip_read_info->rest_read_uncompressed; 1059 (uInt) pfile_in_zip_read_info->rest_read_uncompressed;
1051 1060
1052 while (pfile_in_zip_read_info->stream.avail_out > 0) 1061 while (pfile_in_zip_read_info->stream.avail_out > 0)
1062 {
1063 if ( (0 == pfile_in_zip_read_info->stream.avail_in) &&
1064 (pfile_in_zip_read_info->rest_read_compressed > 0) )
1053 { 1065 {
1066 uInt uReadThis = UNZ_BUFSIZE;
1067 if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
1068 uReadThis = (uInt) pfile_in_zip_read_info->rest_read_compressed;
1069 if (0 == uReadThis)
1070 return EXTRACTOR_UNZIP_EOF;
1071 if (0 !=
1072 ZSEEK (pfile_in_zip_read_info->z_filefunc,
1073 pfile_in_zip_read_info->pos_in_zipfile
1074 + pfile_in_zip_read_info->byte_before_the_zipfile,
1075 SEEK_SET))
1076 return EXTRACTOR_UNZIP_ERRNO;
1077 if (ZREAD (pfile_in_zip_read_info->z_filefunc,
1078 pfile_in_zip_read_info->read_buffer,
1079 uReadThis) != uReadThis)
1080 return EXTRACTOR_UNZIP_ERRNO;
1081
1082 pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
1083 pfile_in_zip_read_info->rest_read_compressed -= uReadThis;
1084 pfile_in_zip_read_info->stream.next_in =
1085 (Bytef *) pfile_in_zip_read_info->read_buffer;
1086 pfile_in_zip_read_info->stream.avail_in = (uInt) uReadThis;
1087 }
1088
1089 if (0 == pfile_in_zip_read_info->compression_method)
1090 {
1091 uInt uDoCopy;
1092
1054 if ( (0 == pfile_in_zip_read_info->stream.avail_in) && 1093 if ( (0 == pfile_in_zip_read_info->stream.avail_in) &&
1055 (pfile_in_zip_read_info->rest_read_compressed > 0) ) 1094 (0 == pfile_in_zip_read_info->rest_read_compressed) )
1056 { 1095 return (0 == iRead) ? EXTRACTOR_UNZIP_EOF : iRead;
1057 uInt uReadThis = UNZ_BUFSIZE; 1096
1058 if (pfile_in_zip_read_info->rest_read_compressed<uReadThis) 1097 if (pfile_in_zip_read_info->stream.avail_out <
1059 uReadThis = (uInt) pfile_in_zip_read_info->rest_read_compressed; 1098 pfile_in_zip_read_info->stream.avail_in)
1060 if (0 == uReadThis) 1099 uDoCopy = pfile_in_zip_read_info->stream.avail_out;
1061 return EXTRACTOR_UNZIP_EOF;
1062 if (0 !=
1063 ZSEEK (pfile_in_zip_read_info->z_filefunc,
1064 pfile_in_zip_read_info->pos_in_zipfile +
1065 pfile_in_zip_read_info->byte_before_the_zipfile,
1066 SEEK_SET))
1067 return EXTRACTOR_UNZIP_ERRNO;
1068 if (ZREAD (pfile_in_zip_read_info->z_filefunc,
1069 pfile_in_zip_read_info->read_buffer,
1070 uReadThis) != uReadThis)
1071 return EXTRACTOR_UNZIP_ERRNO;
1072
1073 pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
1074 pfile_in_zip_read_info->rest_read_compressed -= uReadThis;
1075 pfile_in_zip_read_info->stream.next_in =
1076 (Bytef *) pfile_in_zip_read_info->read_buffer;
1077 pfile_in_zip_read_info->stream.avail_in = (uInt) uReadThis;
1078 }
1079
1080 if (0 == pfile_in_zip_read_info->compression_method)
1081 {
1082 uInt uDoCopy;
1083
1084 if ( (0 == pfile_in_zip_read_info->stream.avail_in) &&
1085 (0 == pfile_in_zip_read_info->rest_read_compressed) )
1086 return (0 == iRead) ? EXTRACTOR_UNZIP_EOF : iRead;
1087
1088 if (pfile_in_zip_read_info->stream.avail_out <
1089 pfile_in_zip_read_info->stream.avail_in)
1090 uDoCopy = pfile_in_zip_read_info->stream.avail_out;
1091 else
1092 uDoCopy = pfile_in_zip_read_info->stream.avail_in;
1093 memcpy (pfile_in_zip_read_info->stream.next_out,
1094 pfile_in_zip_read_info->stream.next_in,
1095 uDoCopy);
1096 pfile_in_zip_read_info->crc32 = crc32 (pfile_in_zip_read_info->crc32,
1097 pfile_in_zip_read_info->stream.next_out,
1098 uDoCopy);
1099 pfile_in_zip_read_info->rest_read_uncompressed -= uDoCopy;
1100 pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
1101 pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
1102 pfile_in_zip_read_info->stream.next_out += uDoCopy;
1103 pfile_in_zip_read_info->stream.next_in += uDoCopy;
1104 pfile_in_zip_read_info->stream.total_out += uDoCopy;
1105 iRead += uDoCopy;
1106 }
1107 else 1100 else
1108 { 1101 uDoCopy = pfile_in_zip_read_info->stream.avail_in;
1109 uLong uTotalOutBefore; 1102 memcpy (pfile_in_zip_read_info->stream.next_out,
1110 uLong uTotalOutAfter; 1103 pfile_in_zip_read_info->stream.next_in,
1111 const Bytef *bufBefore; 1104 uDoCopy);
1112 uLong uOutThis; 1105 pfile_in_zip_read_info->crc32 = crc32 (pfile_in_zip_read_info->crc32,
1113 int flush = Z_SYNC_FLUSH; 1106 pfile_in_zip_read_info->stream.
1114 1107 next_out,
1115 uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; 1108 uDoCopy);
1116 bufBefore = pfile_in_zip_read_info->stream.next_out; 1109 pfile_in_zip_read_info->rest_read_uncompressed -= uDoCopy;
1117 1110 pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
1118 /* 1111 pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
1119 if ((pfile_in_zip_read_info->rest_read_uncompressed == 1112 pfile_in_zip_read_info->stream.next_out += uDoCopy;
1120 pfile_in_zip_read_info->stream.avail_out) && 1113 pfile_in_zip_read_info->stream.next_in += uDoCopy;
1121 (pfile_in_zip_read_info->rest_read_compressed == 0)) 1114 pfile_in_zip_read_info->stream.total_out += uDoCopy;
1122 flush = Z_FINISH; 1115 iRead += uDoCopy;
1123 */ 1116 }
1124 err = inflate (&pfile_in_zip_read_info->stream, flush); 1117 else
1125 1118 {
1126 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; 1119 uLong uTotalOutBefore;
1127 uOutThis = uTotalOutAfter-uTotalOutBefore; 1120 uLong uTotalOutAfter;
1128 1121 const Bytef *bufBefore;
1129 pfile_in_zip_read_info->crc32 = 1122 uLong uOutThis;
1130 crc32 (pfile_in_zip_read_info->crc32, bufBefore, 1123 int flush = Z_SYNC_FLUSH;
1131 (uInt) (uOutThis)); 1124
1132 1125 uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
1133 pfile_in_zip_read_info->rest_read_uncompressed -= 1126 bufBefore = pfile_in_zip_read_info->stream.next_out;
1134 uOutThis; 1127
1135 1128 /*
1136 iRead += (uInt) (uTotalOutAfter - uTotalOutBefore); 1129 if ((pfile_in_zip_read_info->rest_read_uncompressed ==
1137 1130 pfile_in_zip_read_info->stream.avail_out) &&
1138 if (Z_STREAM_END == err) 1131 (pfile_in_zip_read_info->rest_read_compressed == 0))
1139 return (0 == iRead) ? EXTRACTOR_UNZIP_EOF : iRead; 1132 flush = Z_FINISH;
1140 if (Z_OK != err) 1133 */err = inflate (&pfile_in_zip_read_info->stream, flush);
1141 break; 1134
1142 } 1135 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
1136 uOutThis = uTotalOutAfter - uTotalOutBefore;
1137
1138 pfile_in_zip_read_info->crc32 =
1139 crc32 (pfile_in_zip_read_info->crc32, bufBefore,
1140 (uInt) (uOutThis));
1141
1142 pfile_in_zip_read_info->rest_read_uncompressed -=
1143 uOutThis;
1144
1145 iRead += (uInt) (uTotalOutAfter - uTotalOutBefore);
1146
1147 if (Z_STREAM_END == err)
1148 return (0 == iRead) ? EXTRACTOR_UNZIP_EOF : iRead;
1149 if (Z_OK != err)
1150 break;
1143 } 1151 }
1152 }
1144 1153
1145 if (Z_OK == err) 1154 if (Z_OK == err)
1146 return iRead; 1155 return iRead;
@@ -1162,9 +1171,9 @@ EXTRACTOR_common_unzip_read_current_file (struct EXTRACTOR_UnzipFile *file,
1162 */ 1171 */
1163static int 1172static int
1164parse_current_file_coherency_header (struct EXTRACTOR_UnzipFile *file, 1173parse_current_file_coherency_header (struct EXTRACTOR_UnzipFile *file,
1165 uInt *piSizeVar, 1174 uInt *piSizeVar,
1166 uLong *poffset_local_extrafield, 1175 uLong *poffset_local_extrafield,
1167 uInt *psize_local_extrafield) 1176 uInt *psize_local_extrafield)
1168{ 1177{
1169 uLong uMagic; 1178 uLong uMagic;
1170 uLong uData; 1179 uLong uData;
@@ -1177,20 +1186,20 @@ parse_current_file_coherency_header (struct EXTRACTOR_UnzipFile *file,
1177 *psize_local_extrafield = 0; 1186 *psize_local_extrafield = 0;
1178 1187
1179 if (0 != ZSEEK (file->z_filefunc, 1188 if (0 != ZSEEK (file->z_filefunc,
1180 file->cur_file_info_internal.offset_curfile + 1189 file->cur_file_info_internal.offset_curfile
1181 file->byte_before_the_zipfile, 1190 + file->byte_before_the_zipfile,
1182 SEEK_SET)) 1191 SEEK_SET))
1183 return EXTRACTOR_UNZIP_ERRNO; 1192 return EXTRACTOR_UNZIP_ERRNO;
1184 if (EXTRACTOR_UNZIP_OK != 1193 if (EXTRACTOR_UNZIP_OK !=
1185 read_long_from_ffd (&file->z_filefunc, 1194 read_long_from_ffd (&file->z_filefunc,
1186 &uMagic)) 1195 &uMagic))
1187 return EXTRACTOR_UNZIP_ERRNO; 1196 return EXTRACTOR_UNZIP_ERRNO;
1188 if (0x04034b50 != uMagic) 1197 if (0x04034b50 != uMagic)
1189 return EXTRACTOR_UNZIP_BADZIPFILE; 1198 return EXTRACTOR_UNZIP_BADZIPFILE;
1190 if ( (EXTRACTOR_UNZIP_OK != 1199 if ( (EXTRACTOR_UNZIP_OK !=
1191 read_short_from_ffd (&file->z_filefunc, &uData)) || 1200 read_short_from_ffd (&file->z_filefunc, &uData)) ||
1192 (EXTRACTOR_UNZIP_OK != 1201 (EXTRACTOR_UNZIP_OK !=
1193 read_short_from_ffd (&file->z_filefunc, &uFlags)) ) 1202 read_short_from_ffd (&file->z_filefunc, &uFlags)) )
1194 return EXTRACTOR_UNZIP_ERRNO; 1203 return EXTRACTOR_UNZIP_ERRNO;
1195 if (EXTRACTOR_UNZIP_OK != read_short_from_ffd (&file->z_filefunc, &uData)) 1204 if (EXTRACTOR_UNZIP_OK != read_short_from_ffd (&file->z_filefunc, &uData))
1196 return EXTRACTOR_UNZIP_ERRNO; 1205 return EXTRACTOR_UNZIP_ERRNO;
@@ -1209,14 +1218,14 @@ parse_current_file_coherency_header (struct EXTRACTOR_UnzipFile *file,
1209 (0 == (uFlags & 8)) ) 1218 (0 == (uFlags & 8)) )
1210 return EXTRACTOR_UNZIP_BADZIPFILE; 1219 return EXTRACTOR_UNZIP_BADZIPFILE;
1211 if (EXTRACTOR_UNZIP_OK != 1220 if (EXTRACTOR_UNZIP_OK !=
1212 read_long_from_ffd(&file->z_filefunc, &uData)) /* size compr */ 1221 read_long_from_ffd (&file->z_filefunc, &uData)) /* size compr */
1213 return EXTRACTOR_UNZIP_ERRNO; 1222 return EXTRACTOR_UNZIP_ERRNO;
1214 if ( (uData != file->cur_file_info.compressed_size) && 1223 if ( (uData != file->cur_file_info.compressed_size) &&
1215 (0 == (uFlags & 8)) ) 1224 (0 == (uFlags & 8)) )
1216 return EXTRACTOR_UNZIP_BADZIPFILE; 1225 return EXTRACTOR_UNZIP_BADZIPFILE;
1217 if (EXTRACTOR_UNZIP_OK != 1226 if (EXTRACTOR_UNZIP_OK !=
1218 read_long_from_ffd (&file->z_filefunc, 1227 read_long_from_ffd (&file->z_filefunc,
1219 &uData)) /* size uncompr */ 1228 &uData)) /* size uncompr */
1220 return EXTRACTOR_UNZIP_ERRNO; 1229 return EXTRACTOR_UNZIP_ERRNO;
1221 if ( (uData != file->cur_file_info.uncompressed_size) && 1230 if ( (uData != file->cur_file_info.uncompressed_size) &&
1222 (0 == (uFlags & 8))) 1231 (0 == (uFlags & 8)))
@@ -1229,12 +1238,12 @@ parse_current_file_coherency_header (struct EXTRACTOR_UnzipFile *file,
1229 *piSizeVar += (uInt) size_filename; 1238 *piSizeVar += (uInt) size_filename;
1230 if (EXTRACTOR_UNZIP_OK != 1239 if (EXTRACTOR_UNZIP_OK !=
1231 read_short_from_ffd (&file->z_filefunc, 1240 read_short_from_ffd (&file->z_filefunc,
1232 &size_extra_field)) 1241 &size_extra_field))
1233 return EXTRACTOR_UNZIP_ERRNO; 1242 return EXTRACTOR_UNZIP_ERRNO;
1234 *poffset_local_extrafield = file->cur_file_info_internal.offset_curfile + 1243 *poffset_local_extrafield = file->cur_file_info_internal.offset_curfile
1235 SIZEZIPLOCALHEADER + size_filename; 1244 + SIZEZIPLOCALHEADER + size_filename;
1236 *psize_local_extrafield = (uInt) size_extra_field; 1245 *psize_local_extrafield = (uInt) size_extra_field;
1237 *piSizeVar += (uInt)size_extra_field; 1246 *piSizeVar += (uInt) size_extra_field;
1238 1247
1239 return EXTRACTOR_UNZIP_OK; 1248 return EXTRACTOR_UNZIP_OK;
1240} 1249}
@@ -1253,7 +1262,7 @@ EXTRACTOR_common_unzip_open_current_file (struct EXTRACTOR_UnzipFile *file)
1253 uInt iSizeVar; 1262 uInt iSizeVar;
1254 struct FileInZipReadInfo *pfile_in_zip_read_info; 1263 struct FileInZipReadInfo *pfile_in_zip_read_info;
1255 uLong offset_local_extrafield; /* offset of the local extra field */ 1264 uLong offset_local_extrafield; /* offset of the local extra field */
1256 uInt size_local_extrafield; /* size of the local extra field */ 1265 uInt size_local_extrafield; /* size of the local extra field */
1257 1266
1258 if (NULL == file) 1267 if (NULL == file)
1259 return EXTRACTOR_UNZIP_PARAMERROR; 1268 return EXTRACTOR_UNZIP_PARAMERROR;
@@ -1263,17 +1272,18 @@ EXTRACTOR_common_unzip_open_current_file (struct EXTRACTOR_UnzipFile *file)
1263 EXTRACTOR_common_unzip_close_current_file (file); 1272 EXTRACTOR_common_unzip_close_current_file (file);
1264 if (EXTRACTOR_UNZIP_OK != 1273 if (EXTRACTOR_UNZIP_OK !=
1265 parse_current_file_coherency_header (file, 1274 parse_current_file_coherency_header (file,
1266 &iSizeVar, 1275 &iSizeVar,
1267 &offset_local_extrafield, 1276 &offset_local_extrafield,
1268 &size_local_extrafield)) 1277 &size_local_extrafield))
1269 return EXTRACTOR_UNZIP_BADZIPFILE; 1278 return EXTRACTOR_UNZIP_BADZIPFILE;
1270 if (NULL == (pfile_in_zip_read_info = malloc (sizeof(struct FileInZipReadInfo)))) 1279 if (NULL == (pfile_in_zip_read_info = malloc (sizeof(struct
1280 FileInZipReadInfo))))
1271 return EXTRACTOR_UNZIP_INTERNALERROR; 1281 return EXTRACTOR_UNZIP_INTERNALERROR;
1272 if (NULL == (pfile_in_zip_read_info->read_buffer = malloc (UNZ_BUFSIZE))) 1282 if (NULL == (pfile_in_zip_read_info->read_buffer = malloc (UNZ_BUFSIZE)))
1273 { 1283 {
1274 free (pfile_in_zip_read_info); 1284 free (pfile_in_zip_read_info);
1275 return EXTRACTOR_UNZIP_INTERNALERROR; 1285 return EXTRACTOR_UNZIP_INTERNALERROR;
1276 } 1286 }
1277 pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; 1287 pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
1278 pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; 1288 pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
1279 pfile_in_zip_read_info->pos_local_extrafield = 0; 1289 pfile_in_zip_read_info->pos_local_extrafield = 0;
@@ -1281,45 +1291,49 @@ EXTRACTOR_common_unzip_open_current_file (struct EXTRACTOR_UnzipFile *file)
1281 1291
1282 if ( (0 != file->cur_file_info.compression_method) && 1292 if ( (0 != file->cur_file_info.compression_method) &&
1283 (Z_DEFLATED != file->cur_file_info.compression_method) ) 1293 (Z_DEFLATED != file->cur_file_info.compression_method) )
1284 { 1294 {
1285 // err = EXTRACTOR_UNZIP_BADZIPFILE; 1295 // err = EXTRACTOR_UNZIP_BADZIPFILE;
1286 // FIXME: we don't do anything with this 'err' code. 1296 // FIXME: we don't do anything with this 'err' code.
1287 // Can this happen? Should we abort in this case? 1297 // Can this happen? Should we abort in this case?
1288 } 1298 }
1289 1299
1290 pfile_in_zip_read_info->crc32_wait = file->cur_file_info.crc; 1300 pfile_in_zip_read_info->crc32_wait = file->cur_file_info.crc;
1291 pfile_in_zip_read_info->crc32 = 0; 1301 pfile_in_zip_read_info->crc32 = 0;
1292 pfile_in_zip_read_info->compression_method = file->cur_file_info.compression_method; 1302 pfile_in_zip_read_info->compression_method =
1303 file->cur_file_info.compression_method;
1293 pfile_in_zip_read_info->z_filefunc = file->z_filefunc; 1304 pfile_in_zip_read_info->z_filefunc = file->z_filefunc;
1294 pfile_in_zip_read_info->byte_before_the_zipfile = file->byte_before_the_zipfile; 1305 pfile_in_zip_read_info->byte_before_the_zipfile =
1306 file->byte_before_the_zipfile;
1295 pfile_in_zip_read_info->stream.total_out = 0; 1307 pfile_in_zip_read_info->stream.total_out = 0;
1296 if (Z_DEFLATED == file->cur_file_info.compression_method) 1308 if (Z_DEFLATED == file->cur_file_info.compression_method)
1309 {
1310 pfile_in_zip_read_info->stream.zalloc = (alloc_func) NULL;
1311 pfile_in_zip_read_info->stream.zfree = (free_func) NULL;
1312 pfile_in_zip_read_info->stream.opaque = NULL;
1313 pfile_in_zip_read_info->stream.next_in = NULL;
1314 pfile_in_zip_read_info->stream.avail_in = 0;
1315 if (Z_OK != (err = inflateInit2 (&pfile_in_zip_read_info->stream,
1316 -MAX_WBITS)))
1297 { 1317 {
1298 pfile_in_zip_read_info->stream.zalloc = (alloc_func) NULL; 1318 free (pfile_in_zip_read_info->read_buffer);
1299 pfile_in_zip_read_info->stream.zfree = (free_func) NULL; 1319 free (pfile_in_zip_read_info);
1300 pfile_in_zip_read_info->stream.opaque = NULL; 1320 return err;
1301 pfile_in_zip_read_info->stream.next_in = NULL;
1302 pfile_in_zip_read_info->stream.avail_in = 0;
1303 if (Z_OK != (err = inflateInit2 (&pfile_in_zip_read_info->stream, -MAX_WBITS)))
1304 {
1305 free (pfile_in_zip_read_info->read_buffer);
1306 free (pfile_in_zip_read_info);
1307 return err;
1308 }
1309 pfile_in_zip_read_info->stream_initialised = 1;
1310 /* windowBits is passed < 0 to tell that there is no zlib header.
1311 * Note that in this case inflate *requires* an extra "dummy" byte
1312 * after the compressed stream in order to complete decompression and
1313 * return Z_STREAM_END.
1314 * In unzip, i don't wait absolutely Z_STREAM_END because I known the
1315 * size of both compressed and uncompressed data
1316 */
1317 } 1321 }
1318 pfile_in_zip_read_info->rest_read_compressed = file->cur_file_info.compressed_size; 1322 pfile_in_zip_read_info->stream_initialised = 1;
1319 pfile_in_zip_read_info->rest_read_uncompressed = file->cur_file_info.uncompressed_size; 1323 /* windowBits is passed < 0 to tell that there is no zlib header.
1324 * Note that in this case inflate *requires* an extra "dummy" byte
1325 * after the compressed stream in order to complete decompression and
1326 * return Z_STREAM_END.
1327 * In unzip, i don't wait absolutely Z_STREAM_END because I known the
1328 * size of both compressed and uncompressed data
1329 */}
1330 pfile_in_zip_read_info->rest_read_compressed =
1331 file->cur_file_info.compressed_size;
1332 pfile_in_zip_read_info->rest_read_uncompressed =
1333 file->cur_file_info.uncompressed_size;
1320 pfile_in_zip_read_info->pos_in_zipfile = 1334 pfile_in_zip_read_info->pos_in_zipfile =
1321 file->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + 1335 file->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER
1322 iSizeVar; 1336 + iSizeVar;
1323 pfile_in_zip_read_info->stream.avail_in = 0; 1337 pfile_in_zip_read_info->stream.avail_in = 0;
1324 file->pfile_in_zip_read = pfile_in_zip_read_info; 1338 file->pfile_in_zip_read = pfile_in_zip_read_info;
1325 return EXTRACTOR_UNZIP_OK; 1339 return EXTRACTOR_UNZIP_OK;
@@ -1337,8 +1351,8 @@ EXTRACTOR_common_unzip_open_current_file (struct EXTRACTOR_UnzipFile *file)
1337 */ 1351 */
1338static uLong 1352static uLong
1339ec_read_file_func (voidpf opaque, 1353ec_read_file_func (voidpf opaque,
1340 void* buf, 1354 void*buf,
1341 uLong size) 1355 uLong size)
1342{ 1356{
1343 struct EXTRACTOR_ExtractContext *ec = opaque; 1357 struct EXTRACTOR_ExtractContext *ec = opaque;
1344 void *ptr; 1358 void *ptr;
@@ -1347,15 +1361,15 @@ ec_read_file_func (voidpf opaque,
1347 1361
1348 done = 0; 1362 done = 0;
1349 while (done < size) 1363 while (done < size)
1350 { 1364 {
1351 ret = ec->read (ec->cls, 1365 ret = ec->read (ec->cls,
1352 &ptr, 1366 &ptr,
1353 size - done); 1367 size - done);
1354 if (ret <= 0) 1368 if (ret <= 0)
1355 return done; 1369 return done;
1356 memcpy (buf + done, ptr, ret); 1370 memcpy (buf + done, ptr, ret);
1357 done += ret; 1371 done += ret;
1358 } 1372 }
1359 return done; 1373 return done;
1360} 1374}
1361 1375
@@ -1385,8 +1399,8 @@ ec_tell_file_func (voidpf opaque)
1385 */ 1399 */
1386static long 1400static long
1387ec_seek_file_func (voidpf opaque, 1401ec_seek_file_func (voidpf opaque,
1388 uLong offset, 1402 uLong offset,
1389 int origin) 1403 int origin)
1390{ 1404{
1391 struct EXTRACTOR_ExtractContext *ec = opaque; 1405 struct EXTRACTOR_ExtractContext *ec = opaque;
1392 1406
@@ -1416,4 +1430,5 @@ EXTRACTOR_common_unzip_open (struct EXTRACTOR_ExtractContext *ec)
1416 return unzip_open_using_ffd (&ffd); 1430 return unzip_open_using_ffd (&ffd);
1417} 1431}
1418 1432
1433
1419/* end of unzip.c */ 1434/* end of unzip.c */
diff --git a/src/common/unzip.h b/src/common/unzip.h
index 55e7bb6..9812ad8 100644
--- a/src/common/unzip.h
+++ b/src/common/unzip.h
@@ -21,7 +21,7 @@
21 * @file common/unzip.h 21 * @file common/unzip.h
22 * @brief API to access ZIP archives 22 * @brief API to access ZIP archives
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 * 24 *
25 * This code is based in part on 25 * This code is based in part on
26 * unzip 1.00 Copyright 1998-2003 Gilles Vollant 26 * unzip 1.00 Copyright 1998-2003 Gilles Vollant
27 * http://www.winimage.com/zLibDll" 27 * http://www.winimage.com/zLibDll"
@@ -83,112 +83,112 @@ struct EXTRACTOR_UnzipFile;
83struct EXTRACTOR_UnzipDateTimeInfo 83struct EXTRACTOR_UnzipDateTimeInfo
84{ 84{
85 /** 85 /**
86 * seconds after the minute - [0,59] 86 * seconds after the minute - [0,59]
87 */ 87 */
88 uInt tm_sec; 88 uInt tm_sec;
89 89
90 /** 90 /**
91 * minutes after the hour - [0,59] 91 * minutes after the hour - [0,59]
92 */ 92 */
93 uInt tm_min; 93 uInt tm_min;
94 94
95 /** 95 /**
96 * hours since midnight - [0,23] 96 * hours since midnight - [0,23]
97 */ 97 */
98 uInt tm_hour; 98 uInt tm_hour;
99 99
100 /** 100 /**
101 * day of the month - [1,31] 101 * day of the month - [1,31]
102 */ 102 */
103 uInt tm_mday; 103 uInt tm_mday;
104 104
105 /** 105 /**
106 * months since January - [0,11] 106 * months since January - [0,11]
107 */ 107 */
108 uInt tm_mon; 108 uInt tm_mon;
109 109
110 /** 110 /**
111 * years - [1980..2044] 111 * years - [1980..2044]
112 */ 112 */
113 uInt tm_year; 113 uInt tm_year;
114}; 114};
115 115
116 116
117/** 117/**
118 * Information about a file in the zipfile 118 * Information about a file in the zipfile
119 */ 119 */
120struct EXTRACTOR_UnzipFileInfo 120struct EXTRACTOR_UnzipFileInfo
121{ 121{
122 /** 122 /**
123 * version made by 2 bytes 123 * version made by 2 bytes
124 */ 124 */
125 uLong version; 125 uLong version;
126 126
127 /** 127 /**
128 * version needed to extract 2 bytes 128 * version needed to extract 2 bytes
129 */ 129 */
130 uLong version_needed; 130 uLong version_needed;
131 131
132 /** 132 /**
133 * general purpose bit flag 2 bytes 133 * general purpose bit flag 2 bytes
134 */ 134 */
135 uLong flag; 135 uLong flag;
136 136
137 /** 137 /**
138 * compression method 2 bytes 138 * compression method 2 bytes
139 */ 139 */
140 uLong compression_method; 140 uLong compression_method;
141 141
142 /** 142 /**
143 * last mod file date in Dos fmt 4 bytes 143 * last mod file date in Dos fmt 4 bytes
144 */ 144 */
145 uLong dosDate; 145 uLong dosDate;
146 146
147 /** 147 /**
148 * crc-32 4 bytes 148 * crc-32 4 bytes
149 */ 149 */
150 uLong crc; 150 uLong crc;
151 151
152 /** 152 /**
153 * compressed size 4 bytes 153 * compressed size 4 bytes
154 */ 154 */
155 uLong compressed_size; 155 uLong compressed_size;
156 156
157 /** 157 /**
158 * uncompressed size 4 bytes 158 * uncompressed size 4 bytes
159 */ 159 */
160 uLong uncompressed_size; 160 uLong uncompressed_size;
161 161
162 /** 162 /**
163 * filename length 2 bytes 163 * filename length 2 bytes
164 */ 164 */
165 uLong size_filename; 165 uLong size_filename;
166 166
167 /** 167 /**
168 * extra field length 2 bytes 168 * extra field length 2 bytes
169 */ 169 */
170 uLong size_file_extra; 170 uLong size_file_extra;
171 171
172 /** 172 /**
173 * file comment length 2 bytes 173 * file comment length 2 bytes
174 */ 174 */
175 uLong size_file_comment; 175 uLong size_file_comment;
176 176
177 /** 177 /**
178 * disk number start 2 bytes 178 * disk number start 2 bytes
179 */ 179 */
180 uLong disk_num_start; 180 uLong disk_num_start;
181 181
182 /** 182 /**
183 * internal file attributes 2 bytes 183 * internal file attributes 2 bytes
184 */ 184 */
185 uLong internal_fa; 185 uLong internal_fa;
186 186
187 /** 187 /**
188 * external file attributes 4 bytes 188 * external file attributes 4 bytes
189 */ 189 */
190 uLong external_fa; 190 uLong external_fa;
191 191
192 /** 192 /**
193 * Time and date of last modification. 193 * Time and date of last modification.
194 */ 194 */
@@ -203,7 +203,7 @@ struct EXTRACTOR_UnzipFileInfo
203 * @param ec extract context to use 203 * @param ec extract context to use
204 * @return handle to zip data, NULL on error 204 * @return handle to zip data, NULL on error
205 */ 205 */
206struct EXTRACTOR_UnzipFile * 206struct EXTRACTOR_UnzipFile *
207EXTRACTOR_common_unzip_open (struct EXTRACTOR_ExtractContext *ec); 207EXTRACTOR_common_unzip_open (struct EXTRACTOR_ExtractContext *ec);
208 208
209 209
@@ -217,15 +217,15 @@ EXTRACTOR_common_unzip_open (struct EXTRACTOR_ExtractContext *ec);
217 */ 217 */
218int 218int
219EXTRACTOR_common_unzip_get_global_comment (struct EXTRACTOR_UnzipFile *file, 219EXTRACTOR_common_unzip_get_global_comment (struct EXTRACTOR_UnzipFile *file,
220 char *comment, 220 char *comment,
221 size_t comment_len); 221 size_t comment_len);
222 222
223 223
224/** 224/**
225 * Close a ZipFile. 225 * Close a ZipFile.
226 * 226 *
227 * @param file zip file to close 227 * @param file zip file to close
228 * @return EXTRACTOR_UNZIP_OK if there is no problem. 228 * @return EXTRACTOR_UNZIP_OK if there is no problem.
229 */ 229 */
230int 230int
231EXTRACTOR_common_unzip_close (struct EXTRACTOR_UnzipFile *file); 231EXTRACTOR_common_unzip_close (struct EXTRACTOR_UnzipFile *file);
@@ -237,7 +237,7 @@ EXTRACTOR_common_unzip_close (struct EXTRACTOR_UnzipFile *file);
237 * @param file zipfile to manipulate 237 * @param file zipfile to manipulate
238 * @return UNZ_OK if there is no problem 238 * @return UNZ_OK if there is no problem
239 */ 239 */
240int 240int
241EXTRACTOR_common_unzip_go_to_first_file (struct EXTRACTOR_UnzipFile *file); 241EXTRACTOR_common_unzip_go_to_first_file (struct EXTRACTOR_UnzipFile *file);
242 242
243 243
@@ -254,7 +254,7 @@ EXTRACTOR_common_unzip_go_to_next_file (struct EXTRACTOR_UnzipFile *file);
254 254
255/** 255/**
256 * Try locate the file szFileName in the zipfile. 256 * Try locate the file szFileName in the zipfile.
257 * 257 *
258 * @param file zipfile to manipulate 258 * @param file zipfile to manipulate
259 * @param szFileName name to find 259 * @param szFileName name to find
260 * @param iCaseSensitivity, use 1 for case sensitivity (like strcmp); 260 * @param iCaseSensitivity, use 1 for case sensitivity (like strcmp);
@@ -264,9 +264,9 @@ EXTRACTOR_common_unzip_go_to_next_file (struct EXTRACTOR_UnzipFile *file);
264 * EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE if the file is not found 264 * EXTRACTOR_UNZIP_END_OF_LIST_OF_FILE if the file is not found
265 */ 265 */
266int 266int
267EXTRACTOR_common_unzip_go_find_local_file (struct EXTRACTOR_UnzipFile *file, 267EXTRACTOR_common_unzip_go_find_local_file (struct EXTRACTOR_UnzipFile *file,
268 const char *szFileName, 268 const char *szFileName,
269 int iCaseSensitivity); 269 int iCaseSensitivity);
270 270
271 271
272/** 272/**
@@ -278,20 +278,21 @@ EXTRACTOR_common_unzip_go_find_local_file (struct EXTRACTOR_UnzipFile *file,
278 * @param szFileName where to write the name of the current file 278 * @param szFileName where to write the name of the current file
279 * @param fileNameBufferSize number of bytes available in szFileName 279 * @param fileNameBufferSize number of bytes available in szFileName
280 * @param extraField where to write extra data 280 * @param extraField where to write extra data
281 * @param extraFieldBufferSize number of bytes available in extraField 281 * @param extraFieldBufferSize number of bytes available in extraField
282 * @param szComment where to write the comment on the current file 282 * @param szComment where to write the comment on the current file
283 * @param commentBufferSize number of bytes available in szComment 283 * @param commentBufferSize number of bytes available in szComment
284 * @return EXTRACTOR_UNZIP_OK if there is no problem. 284 * @return EXTRACTOR_UNZIP_OK if there is no problem.
285 */ 285 */
286int 286int
287EXTRACTOR_common_unzip_get_current_file_info (struct EXTRACTOR_UnzipFile *file, 287EXTRACTOR_common_unzip_get_current_file_info (struct EXTRACTOR_UnzipFile *file,
288 struct EXTRACTOR_UnzipFileInfo *pfile_info, 288 struct EXTRACTOR_UnzipFileInfo *
289 char *szFileName, 289 pfile_info,
290 uLong fileNameBufferSize, 290 char *szFileName,
291 void *extraField, 291 uLong fileNameBufferSize,
292 uLong extraFieldBufferSize, 292 void *extraField,
293 char *szComment, 293 uLong extraFieldBufferSize,
294 uLong commentBufferSize); 294 char *szComment,
295 uLong commentBufferSize);
295 296
296 297
297/** 298/**
@@ -314,10 +315,10 @@ EXTRACTOR_common_unzip_open_current_file (struct EXTRACTOR_UnzipFile *file);
314 * <0 with error code if there is an error 315 * <0 with error code if there is an error
315 * (EXTRACTOR_UNZIP_ERRNO for IO error, or zLib error for uncompress error) 316 * (EXTRACTOR_UNZIP_ERRNO for IO error, or zLib error for uncompress error)
316 */ 317 */
317ssize_t 318ssize_t
318EXTRACTOR_common_unzip_read_current_file (struct EXTRACTOR_UnzipFile *file, 319EXTRACTOR_common_unzip_read_current_file (struct EXTRACTOR_UnzipFile *file,
319 void *buf, 320 void *buf,
320 size_t len); 321 size_t len);
321 322
322 323
323/** 324/**
@@ -325,9 +326,9 @@ EXTRACTOR_common_unzip_read_current_file (struct EXTRACTOR_UnzipFile *file,
325 * 326 *
326 * @return EXTRACTOR_UNZIP_CRCERROR if all the file was read but the CRC is not good 327 * @return EXTRACTOR_UNZIP_CRCERROR if all the file was read but the CRC is not good
327 */ 328 */
328int 329int
329EXTRACTOR_common_unzip_close_current_file (struct EXTRACTOR_UnzipFile *file); 330EXTRACTOR_common_unzip_close_current_file (struct EXTRACTOR_UnzipFile *file);
330 331
331 332
332#endif 333#endif
333/* LE_COMMON_UNZIP_H */ 334/* LE_COMMON_UNZIP_H */
diff --git a/src/include/extractor.h b/src/include/extractor.h
index 3e86868..3e6c098 100644
--- a/src/include/extractor.h
+++ b/src/include/extractor.h
@@ -54,65 +54,65 @@ extern "C" {
54 * Options for how plugin execution should be done. 54 * Options for how plugin execution should be done.
55 */ 55 */
56enum EXTRACTOR_Options 56enum EXTRACTOR_Options
57 { 57{
58 58
59 /** 59 /**
60 * Run plugin out-of-process, starting the process once the plugin 60 * Run plugin out-of-process, starting the process once the plugin
61 * is to be run. If a plugin crashes, automatically restart the 61 * is to be run. If a plugin crashes, automatically restart the
62 * respective process for the same file and try once more 62 * respective process for the same file and try once more
63 * (since the crash may be caused by the previous file). If 63 * (since the crash may be caused by the previous file). If
64 * the process crashes immediately again, it is not restarted 64 * the process crashes immediately again, it is not restarted
65 * until the next file. 65 * until the next file.
66 */ 66 */
67 EXTRACTOR_OPTION_DEFAULT_POLICY = 0, 67 EXTRACTOR_OPTION_DEFAULT_POLICY = 0,
68 68
69 /** 69 /**
70 * Deprecated option. Ignored. 70 * Deprecated option. Ignored.
71 */ 71 */
72 EXTRACTOR_OPTION_OUT_OF_PROCESS_NO_RESTART = 1, 72 EXTRACTOR_OPTION_OUT_OF_PROCESS_NO_RESTART = 1,
73 73
74 /** 74 /**
75 * Run plugins in-process. Unsafe, not recommended, 75 * Run plugins in-process. Unsafe, not recommended,
76 * can be nice for debugging. 76 * can be nice for debugging.
77 */ 77 */
78 EXTRACTOR_OPTION_IN_PROCESS = 2, 78 EXTRACTOR_OPTION_IN_PROCESS = 2,
79 79
80 /** 80 /**
81 * Internal value for plugins that have been disabled. 81 * Internal value for plugins that have been disabled.
82 */ 82 */
83 EXTRACTOR_OPTION_DISABLED = 3 83 EXTRACTOR_OPTION_DISABLED = 3
84 84
85 }; 85};
86 86
87 87
88/** 88/**
89 * Format in which the extracted meta data is presented. 89 * Format in which the extracted meta data is presented.
90 */ 90 */
91enum EXTRACTOR_MetaFormat 91enum EXTRACTOR_MetaFormat
92 { 92{
93 /** 93 /**
94 * Format is unknown. 94 * Format is unknown.
95 */ 95 */
96 EXTRACTOR_METAFORMAT_UNKNOWN = 0, 96 EXTRACTOR_METAFORMAT_UNKNOWN = 0,
97 97
98 /** 98 /**
99 * 0-terminated, UTF-8 encoded string. "data_len" 99 * 0-terminated, UTF-8 encoded string. "data_len"
100 * is strlen(data)+1. 100 * is strlen(data)+1.
101 */ 101 */
102 EXTRACTOR_METAFORMAT_UTF8 = 1, 102 EXTRACTOR_METAFORMAT_UTF8 = 1,
103 103
104 /** 104 /**
105 * Some kind of binary format, see given Mime type. 105 * Some kind of binary format, see given Mime type.
106 */ 106 */
107 EXTRACTOR_METAFORMAT_BINARY = 2, 107 EXTRACTOR_METAFORMAT_BINARY = 2,
108 108
109 /** 109 /**
110 * 0-terminated string. The specific encoding is unknown. 110 * 0-terminated string. The specific encoding is unknown.
111 * "data_len" is strlen (data)+1. 111 * "data_len" is strlen (data)+1.
112 */ 112 */
113 EXTRACTOR_METAFORMAT_C_STRING = 3 113 EXTRACTOR_METAFORMAT_C_STRING = 3
114 114
115 }; 115};
116 116
117 117
118/** 118/**
@@ -123,283 +123,283 @@ enum EXTRACTOR_MetaFormat
123 * @{ 123 * @{
124 */ 124 */
125enum EXTRACTOR_MetaType 125enum EXTRACTOR_MetaType
126 { 126{
127 /* fundamental types */ 127 /* fundamental types */
128 EXTRACTOR_METATYPE_RESERVED = 0, 128 EXTRACTOR_METATYPE_RESERVED = 0,
129 EXTRACTOR_METATYPE_MIMETYPE = 1, 129 EXTRACTOR_METATYPE_MIMETYPE = 1,
130 EXTRACTOR_METATYPE_FILENAME = 2, 130 EXTRACTOR_METATYPE_FILENAME = 2,
131 EXTRACTOR_METATYPE_COMMENT = 3, 131 EXTRACTOR_METATYPE_COMMENT = 3,
132 132
133 /* Standard types from bibtex */ 133 /* Standard types from bibtex */
134 EXTRACTOR_METATYPE_TITLE = 4, 134 EXTRACTOR_METATYPE_TITLE = 4,
135 EXTRACTOR_METATYPE_BOOK_TITLE = 5, 135 EXTRACTOR_METATYPE_BOOK_TITLE = 5,
136 EXTRACTOR_METATYPE_BOOK_EDITION = 6, 136 EXTRACTOR_METATYPE_BOOK_EDITION = 6,
137 EXTRACTOR_METATYPE_BOOK_CHAPTER_NUMBER = 7, 137 EXTRACTOR_METATYPE_BOOK_CHAPTER_NUMBER = 7,
138 EXTRACTOR_METATYPE_JOURNAL_NAME = 8, 138 EXTRACTOR_METATYPE_JOURNAL_NAME = 8,
139 EXTRACTOR_METATYPE_JOURNAL_VOLUME = 9, 139 EXTRACTOR_METATYPE_JOURNAL_VOLUME = 9,
140 EXTRACTOR_METATYPE_JOURNAL_NUMBER = 10, 140 EXTRACTOR_METATYPE_JOURNAL_NUMBER = 10,
141 EXTRACTOR_METATYPE_PAGE_COUNT = 11, 141 EXTRACTOR_METATYPE_PAGE_COUNT = 11,
142 EXTRACTOR_METATYPE_PAGE_RANGE = 12, 142 EXTRACTOR_METATYPE_PAGE_RANGE = 12,
143 EXTRACTOR_METATYPE_AUTHOR_NAME = 13, 143 EXTRACTOR_METATYPE_AUTHOR_NAME = 13,
144 EXTRACTOR_METATYPE_AUTHOR_EMAIL = 14, 144 EXTRACTOR_METATYPE_AUTHOR_EMAIL = 14,
145 EXTRACTOR_METATYPE_AUTHOR_INSTITUTION = 15, 145 EXTRACTOR_METATYPE_AUTHOR_INSTITUTION = 15,
146 EXTRACTOR_METATYPE_PUBLISHER = 16, 146 EXTRACTOR_METATYPE_PUBLISHER = 16,
147 EXTRACTOR_METATYPE_PUBLISHER_ADDRESS = 17, 147 EXTRACTOR_METATYPE_PUBLISHER_ADDRESS = 17,
148 EXTRACTOR_METATYPE_PUBLISHER_INSTITUTION = 18, 148 EXTRACTOR_METATYPE_PUBLISHER_INSTITUTION = 18,
149 EXTRACTOR_METATYPE_PUBLISHER_SERIES = 19, 149 EXTRACTOR_METATYPE_PUBLISHER_SERIES = 19,
150 EXTRACTOR_METATYPE_PUBLICATION_TYPE = 20, 150 EXTRACTOR_METATYPE_PUBLICATION_TYPE = 20,
151 EXTRACTOR_METATYPE_PUBLICATION_YEAR = 21, 151 EXTRACTOR_METATYPE_PUBLICATION_YEAR = 21,
152 EXTRACTOR_METATYPE_PUBLICATION_MONTH = 22, 152 EXTRACTOR_METATYPE_PUBLICATION_MONTH = 22,
153 EXTRACTOR_METATYPE_PUBLICATION_DAY = 23, 153 EXTRACTOR_METATYPE_PUBLICATION_DAY = 23,
154 EXTRACTOR_METATYPE_PUBLICATION_DATE = 24, 154 EXTRACTOR_METATYPE_PUBLICATION_DATE = 24,
155 EXTRACTOR_METATYPE_BIBTEX_EPRINT = 25, 155 EXTRACTOR_METATYPE_BIBTEX_EPRINT = 25,
156 EXTRACTOR_METATYPE_BIBTEX_ENTRY_TYPE = 26, 156 EXTRACTOR_METATYPE_BIBTEX_ENTRY_TYPE = 26,
157 EXTRACTOR_METATYPE_LANGUAGE = 27, 157 EXTRACTOR_METATYPE_LANGUAGE = 27,
158 EXTRACTOR_METATYPE_CREATION_TIME = 28, 158 EXTRACTOR_METATYPE_CREATION_TIME = 28,
159 EXTRACTOR_METATYPE_URL = 29, 159 EXTRACTOR_METATYPE_URL = 29,
160 160
161 /* "unique" document identifiers */ 161 /* "unique" document identifiers */
162 EXTRACTOR_METATYPE_URI = 30, 162 EXTRACTOR_METATYPE_URI = 30,
163 EXTRACTOR_METATYPE_ISRC = 31, 163 EXTRACTOR_METATYPE_ISRC = 31,
164 EXTRACTOR_METATYPE_HASH_MD4 = 32, 164 EXTRACTOR_METATYPE_HASH_MD4 = 32,
165 EXTRACTOR_METATYPE_HASH_MD5 = 33, 165 EXTRACTOR_METATYPE_HASH_MD5 = 33,
166 EXTRACTOR_METATYPE_HASH_SHA0 = 34, 166 EXTRACTOR_METATYPE_HASH_SHA0 = 34,
167 EXTRACTOR_METATYPE_HASH_SHA1 = 35, 167 EXTRACTOR_METATYPE_HASH_SHA1 = 35,
168 EXTRACTOR_METATYPE_HASH_RMD160 = 36, 168 EXTRACTOR_METATYPE_HASH_RMD160 = 36,
169 169
170 /* identifiers of a location */ 170 /* identifiers of a location */
171 EXTRACTOR_METATYPE_GPS_LATITUDE_REF = 37, 171 EXTRACTOR_METATYPE_GPS_LATITUDE_REF = 37,
172 EXTRACTOR_METATYPE_GPS_LATITUDE = 38, 172 EXTRACTOR_METATYPE_GPS_LATITUDE = 38,
173 EXTRACTOR_METATYPE_GPS_LONGITUDE_REF = 39, 173 EXTRACTOR_METATYPE_GPS_LONGITUDE_REF = 39,
174 EXTRACTOR_METATYPE_GPS_LONGITUDE = 40, 174 EXTRACTOR_METATYPE_GPS_LONGITUDE = 40,
175 EXTRACTOR_METATYPE_LOCATION_CITY = 41, 175 EXTRACTOR_METATYPE_LOCATION_CITY = 41,
176 EXTRACTOR_METATYPE_LOCATION_SUBLOCATION = 42, 176 EXTRACTOR_METATYPE_LOCATION_SUBLOCATION = 42,
177 EXTRACTOR_METATYPE_LOCATION_COUNTRY = 43, 177 EXTRACTOR_METATYPE_LOCATION_COUNTRY = 43,
178 EXTRACTOR_METATYPE_LOCATION_COUNTRY_CODE = 44, 178 EXTRACTOR_METATYPE_LOCATION_COUNTRY_CODE = 44,
179 179
180 /* generic attributes */ 180 /* generic attributes */
181 EXTRACTOR_METATYPE_UNKNOWN = 45, 181 EXTRACTOR_METATYPE_UNKNOWN = 45,
182 EXTRACTOR_METATYPE_DESCRIPTION = 46, 182 EXTRACTOR_METATYPE_DESCRIPTION = 46,
183 EXTRACTOR_METATYPE_COPYRIGHT = 47, 183 EXTRACTOR_METATYPE_COPYRIGHT = 47,
184 EXTRACTOR_METATYPE_RIGHTS = 48, 184 EXTRACTOR_METATYPE_RIGHTS = 48,
185 EXTRACTOR_METATYPE_KEYWORDS = 49, 185 EXTRACTOR_METATYPE_KEYWORDS = 49,
186 EXTRACTOR_METATYPE_ABSTRACT = 50, 186 EXTRACTOR_METATYPE_ABSTRACT = 50,
187 EXTRACTOR_METATYPE_SUMMARY = 51, 187 EXTRACTOR_METATYPE_SUMMARY = 51,
188 EXTRACTOR_METATYPE_SUBJECT = 52, 188 EXTRACTOR_METATYPE_SUBJECT = 52,
189 EXTRACTOR_METATYPE_CREATOR = 53, 189 EXTRACTOR_METATYPE_CREATOR = 53,
190 EXTRACTOR_METATYPE_FORMAT = 54, 190 EXTRACTOR_METATYPE_FORMAT = 54,
191 EXTRACTOR_METATYPE_FORMAT_VERSION = 55, 191 EXTRACTOR_METATYPE_FORMAT_VERSION = 55,
192 192
193 /* processing history */ 193 /* processing history */
194 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE = 56, 194 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE = 56,
195 EXTRACTOR_METATYPE_UNKNOWN_DATE = 57, 195 EXTRACTOR_METATYPE_UNKNOWN_DATE = 57,
196 EXTRACTOR_METATYPE_CREATION_DATE = 58, 196 EXTRACTOR_METATYPE_CREATION_DATE = 58,
197 EXTRACTOR_METATYPE_MODIFICATION_DATE = 59, 197 EXTRACTOR_METATYPE_MODIFICATION_DATE = 59,
198 EXTRACTOR_METATYPE_LAST_PRINTED = 60, 198 EXTRACTOR_METATYPE_LAST_PRINTED = 60,
199 EXTRACTOR_METATYPE_LAST_SAVED_BY = 61, 199 EXTRACTOR_METATYPE_LAST_SAVED_BY = 61,
200 EXTRACTOR_METATYPE_TOTAL_EDITING_TIME = 62, 200 EXTRACTOR_METATYPE_TOTAL_EDITING_TIME = 62,
201 EXTRACTOR_METATYPE_EDITING_CYCLES = 63, 201 EXTRACTOR_METATYPE_EDITING_CYCLES = 63,
202 EXTRACTOR_METATYPE_MODIFIED_BY_SOFTWARE = 64, 202 EXTRACTOR_METATYPE_MODIFIED_BY_SOFTWARE = 64,
203 EXTRACTOR_METATYPE_REVISION_HISTORY = 65, 203 EXTRACTOR_METATYPE_REVISION_HISTORY = 65,
204 204
205 EXTRACTOR_METATYPE_EMBEDDED_FILE_SIZE = 66, 205 EXTRACTOR_METATYPE_EMBEDDED_FILE_SIZE = 66,
206 EXTRACTOR_METATYPE_FINDER_FILE_TYPE = 67, 206 EXTRACTOR_METATYPE_FINDER_FILE_TYPE = 67,
207 EXTRACTOR_METATYPE_FINDER_FILE_CREATOR = 68, 207 EXTRACTOR_METATYPE_FINDER_FILE_CREATOR = 68,
208 208
209 /* software package specifics (deb, rpm, tgz, elf) */ 209 /* software package specifics (deb, rpm, tgz, elf) */
210 EXTRACTOR_METATYPE_PACKAGE_NAME = 69, 210 EXTRACTOR_METATYPE_PACKAGE_NAME = 69,
211 EXTRACTOR_METATYPE_PACKAGE_VERSION = 70, 211 EXTRACTOR_METATYPE_PACKAGE_VERSION = 70,
212 EXTRACTOR_METATYPE_SECTION = 71, 212 EXTRACTOR_METATYPE_SECTION = 71,
213 EXTRACTOR_METATYPE_UPLOAD_PRIORITY = 72, 213 EXTRACTOR_METATYPE_UPLOAD_PRIORITY = 72,
214 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY = 73, 214 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY = 73,
215 EXTRACTOR_METATYPE_PACKAGE_CONFLICTS = 74, 215 EXTRACTOR_METATYPE_PACKAGE_CONFLICTS = 74,
216 EXTRACTOR_METATYPE_PACKAGE_REPLACES = 75, 216 EXTRACTOR_METATYPE_PACKAGE_REPLACES = 75,
217 EXTRACTOR_METATYPE_PACKAGE_PROVIDES = 76, 217 EXTRACTOR_METATYPE_PACKAGE_PROVIDES = 76,
218 EXTRACTOR_METATYPE_PACKAGE_RECOMMENDS = 77, 218 EXTRACTOR_METATYPE_PACKAGE_RECOMMENDS = 77,
219 EXTRACTOR_METATYPE_PACKAGE_SUGGESTS = 78, 219 EXTRACTOR_METATYPE_PACKAGE_SUGGESTS = 78,
220 EXTRACTOR_METATYPE_PACKAGE_MAINTAINER = 79, 220 EXTRACTOR_METATYPE_PACKAGE_MAINTAINER = 79,
221 EXTRACTOR_METATYPE_PACKAGE_INSTALLED_SIZE = 80, 221 EXTRACTOR_METATYPE_PACKAGE_INSTALLED_SIZE = 80,
222 EXTRACTOR_METATYPE_PACKAGE_SOURCE = 81, 222 EXTRACTOR_METATYPE_PACKAGE_SOURCE = 81,
223 EXTRACTOR_METATYPE_PACKAGE_ESSENTIAL = 82, 223 EXTRACTOR_METATYPE_PACKAGE_ESSENTIAL = 82,
224 EXTRACTOR_METATYPE_TARGET_ARCHITECTURE = 83, 224 EXTRACTOR_METATYPE_TARGET_ARCHITECTURE = 83,
225 EXTRACTOR_METATYPE_PACKAGE_PRE_DEPENDENCY = 84, 225 EXTRACTOR_METATYPE_PACKAGE_PRE_DEPENDENCY = 84,
226 EXTRACTOR_METATYPE_LICENSE = 85, 226 EXTRACTOR_METATYPE_LICENSE = 85,
227 EXTRACTOR_METATYPE_PACKAGE_DISTRIBUTION = 86, 227 EXTRACTOR_METATYPE_PACKAGE_DISTRIBUTION = 86,
228 EXTRACTOR_METATYPE_BUILDHOST = 87, 228 EXTRACTOR_METATYPE_BUILDHOST = 87,
229 EXTRACTOR_METATYPE_VENDOR = 88, 229 EXTRACTOR_METATYPE_VENDOR = 88,
230 EXTRACTOR_METATYPE_TARGET_OS = 89, 230 EXTRACTOR_METATYPE_TARGET_OS = 89,
231 EXTRACTOR_METATYPE_SOFTWARE_VERSION = 90, 231 EXTRACTOR_METATYPE_SOFTWARE_VERSION = 90,
232 EXTRACTOR_METATYPE_TARGET_PLATFORM = 91, 232 EXTRACTOR_METATYPE_TARGET_PLATFORM = 91,
233 EXTRACTOR_METATYPE_RESOURCE_TYPE = 92, 233 EXTRACTOR_METATYPE_RESOURCE_TYPE = 92,
234 EXTRACTOR_METATYPE_LIBRARY_SEARCH_PATH = 93, 234 EXTRACTOR_METATYPE_LIBRARY_SEARCH_PATH = 93,
235 EXTRACTOR_METATYPE_LIBRARY_DEPENDENCY = 94, 235 EXTRACTOR_METATYPE_LIBRARY_DEPENDENCY = 94,
236 236
237 /* photography specifics */ 237 /* photography specifics */
238 EXTRACTOR_METATYPE_CAMERA_MAKE = 95, 238 EXTRACTOR_METATYPE_CAMERA_MAKE = 95,
239 EXTRACTOR_METATYPE_CAMERA_MODEL = 96, 239 EXTRACTOR_METATYPE_CAMERA_MODEL = 96,
240 EXTRACTOR_METATYPE_EXPOSURE = 97, 240 EXTRACTOR_METATYPE_EXPOSURE = 97,
241 EXTRACTOR_METATYPE_APERTURE = 98, 241 EXTRACTOR_METATYPE_APERTURE = 98,
242 EXTRACTOR_METATYPE_EXPOSURE_BIAS = 99, 242 EXTRACTOR_METATYPE_EXPOSURE_BIAS = 99,
243 EXTRACTOR_METATYPE_FLASH = 100, 243 EXTRACTOR_METATYPE_FLASH = 100,
244 EXTRACTOR_METATYPE_FLASH_BIAS = 101, 244 EXTRACTOR_METATYPE_FLASH_BIAS = 101,
245 EXTRACTOR_METATYPE_FOCAL_LENGTH = 102, 245 EXTRACTOR_METATYPE_FOCAL_LENGTH = 102,
246 EXTRACTOR_METATYPE_FOCAL_LENGTH_35MM = 103, 246 EXTRACTOR_METATYPE_FOCAL_LENGTH_35MM = 103,
247 EXTRACTOR_METATYPE_ISO_SPEED = 104, 247 EXTRACTOR_METATYPE_ISO_SPEED = 104,
248 EXTRACTOR_METATYPE_EXPOSURE_MODE = 105, 248 EXTRACTOR_METATYPE_EXPOSURE_MODE = 105,
249 EXTRACTOR_METATYPE_METERING_MODE = 106, 249 EXTRACTOR_METATYPE_METERING_MODE = 106,
250 EXTRACTOR_METATYPE_MACRO_MODE = 107, 250 EXTRACTOR_METATYPE_MACRO_MODE = 107,
251 EXTRACTOR_METATYPE_IMAGE_QUALITY = 108, 251 EXTRACTOR_METATYPE_IMAGE_QUALITY = 108,
252 EXTRACTOR_METATYPE_WHITE_BALANCE = 109, 252 EXTRACTOR_METATYPE_WHITE_BALANCE = 109,
253 EXTRACTOR_METATYPE_ORIENTATION = 110, 253 EXTRACTOR_METATYPE_ORIENTATION = 110,
254 EXTRACTOR_METATYPE_MAGNIFICATION = 111, 254 EXTRACTOR_METATYPE_MAGNIFICATION = 111,
255 255
256 /* image specifics */ 256 /* image specifics */
257 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS = 112, 257 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS = 112,
258 EXTRACTOR_METATYPE_PRODUCED_BY_SOFTWARE = 113, 258 EXTRACTOR_METATYPE_PRODUCED_BY_SOFTWARE = 113,
259 EXTRACTOR_METATYPE_THUMBNAIL = 114, 259 EXTRACTOR_METATYPE_THUMBNAIL = 114,
260 EXTRACTOR_METATYPE_IMAGE_RESOLUTION = 115, 260 EXTRACTOR_METATYPE_IMAGE_RESOLUTION = 115,
261 EXTRACTOR_METATYPE_SOURCE = 116, 261 EXTRACTOR_METATYPE_SOURCE = 116,
262 262
263 /* (text) document processing specifics */ 263 /* (text) document processing specifics */
264 EXTRACTOR_METATYPE_CHARACTER_SET = 117, 264 EXTRACTOR_METATYPE_CHARACTER_SET = 117,
265 EXTRACTOR_METATYPE_LINE_COUNT = 118, 265 EXTRACTOR_METATYPE_LINE_COUNT = 118,
266 EXTRACTOR_METATYPE_PARAGRAPH_COUNT = 119, 266 EXTRACTOR_METATYPE_PARAGRAPH_COUNT = 119,
267 EXTRACTOR_METATYPE_WORD_COUNT = 120, 267 EXTRACTOR_METATYPE_WORD_COUNT = 120,
268 EXTRACTOR_METATYPE_CHARACTER_COUNT = 121, 268 EXTRACTOR_METATYPE_CHARACTER_COUNT = 121,
269 EXTRACTOR_METATYPE_PAGE_ORIENTATION = 122, 269 EXTRACTOR_METATYPE_PAGE_ORIENTATION = 122,
270 EXTRACTOR_METATYPE_PAPER_SIZE = 123, 270 EXTRACTOR_METATYPE_PAPER_SIZE = 123,
271 EXTRACTOR_METATYPE_TEMPLATE = 124, 271 EXTRACTOR_METATYPE_TEMPLATE = 124,
272 EXTRACTOR_METATYPE_COMPANY = 125, 272 EXTRACTOR_METATYPE_COMPANY = 125,
273 EXTRACTOR_METATYPE_MANAGER = 126, 273 EXTRACTOR_METATYPE_MANAGER = 126,
274 EXTRACTOR_METATYPE_REVISION_NUMBER = 127, 274 EXTRACTOR_METATYPE_REVISION_NUMBER = 127,
275 275
276 /* music / video specifics */ 276 /* music / video specifics */
277 EXTRACTOR_METATYPE_DURATION = 128, 277 EXTRACTOR_METATYPE_DURATION = 128,
278 EXTRACTOR_METATYPE_ALBUM = 129, 278 EXTRACTOR_METATYPE_ALBUM = 129,
279 EXTRACTOR_METATYPE_ARTIST = 130, 279 EXTRACTOR_METATYPE_ARTIST = 130,
280 EXTRACTOR_METATYPE_GENRE = 131, 280 EXTRACTOR_METATYPE_GENRE = 131,
281 EXTRACTOR_METATYPE_TRACK_NUMBER = 132, 281 EXTRACTOR_METATYPE_TRACK_NUMBER = 132,
282 EXTRACTOR_METATYPE_DISC_NUMBER = 133, 282 EXTRACTOR_METATYPE_DISC_NUMBER = 133,
283 EXTRACTOR_METATYPE_PERFORMER = 134, 283 EXTRACTOR_METATYPE_PERFORMER = 134,
284 EXTRACTOR_METATYPE_CONTACT_INFORMATION = 135, 284 EXTRACTOR_METATYPE_CONTACT_INFORMATION = 135,
285 EXTRACTOR_METATYPE_SONG_VERSION = 136, 285 EXTRACTOR_METATYPE_SONG_VERSION = 136,
286 EXTRACTOR_METATYPE_PICTURE = 137, 286 EXTRACTOR_METATYPE_PICTURE = 137,
287 EXTRACTOR_METATYPE_COVER_PICTURE = 138, 287 EXTRACTOR_METATYPE_COVER_PICTURE = 138,
288 EXTRACTOR_METATYPE_CONTRIBUTOR_PICTURE = 139, 288 EXTRACTOR_METATYPE_CONTRIBUTOR_PICTURE = 139,
289 EXTRACTOR_METATYPE_EVENT_PICTURE = 140, 289 EXTRACTOR_METATYPE_EVENT_PICTURE = 140,
290 EXTRACTOR_METATYPE_LOGO = 141, 290 EXTRACTOR_METATYPE_LOGO = 141,
291 EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM = 142, 291 EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM = 142,
292 EXTRACTOR_METATYPE_SOURCE_DEVICE = 143, 292 EXTRACTOR_METATYPE_SOURCE_DEVICE = 143,
293 EXTRACTOR_METATYPE_DISCLAIMER = 144, 293 EXTRACTOR_METATYPE_DISCLAIMER = 144,
294 EXTRACTOR_METATYPE_WARNING = 145, 294 EXTRACTOR_METATYPE_WARNING = 145,
295 EXTRACTOR_METATYPE_PAGE_ORDER = 146, 295 EXTRACTOR_METATYPE_PAGE_ORDER = 146,
296 EXTRACTOR_METATYPE_WRITER = 147, 296 EXTRACTOR_METATYPE_WRITER = 147,
297 EXTRACTOR_METATYPE_PRODUCT_VERSION = 148, 297 EXTRACTOR_METATYPE_PRODUCT_VERSION = 148,
298 EXTRACTOR_METATYPE_CONTRIBUTOR_NAME = 149, 298 EXTRACTOR_METATYPE_CONTRIBUTOR_NAME = 149,
299 EXTRACTOR_METATYPE_MOVIE_DIRECTOR = 150, 299 EXTRACTOR_METATYPE_MOVIE_DIRECTOR = 150,
300 EXTRACTOR_METATYPE_NETWORK_NAME = 151, 300 EXTRACTOR_METATYPE_NETWORK_NAME = 151,
301 EXTRACTOR_METATYPE_SHOW_NAME = 152, 301 EXTRACTOR_METATYPE_SHOW_NAME = 152,
302 EXTRACTOR_METATYPE_CHAPTER_NAME = 153, 302 EXTRACTOR_METATYPE_CHAPTER_NAME = 153,
303 EXTRACTOR_METATYPE_SONG_COUNT = 154, 303 EXTRACTOR_METATYPE_SONG_COUNT = 154,
304 EXTRACTOR_METATYPE_STARTING_SONG = 155, 304 EXTRACTOR_METATYPE_STARTING_SONG = 155,
305 EXTRACTOR_METATYPE_PLAY_COUNTER = 156, 305 EXTRACTOR_METATYPE_PLAY_COUNTER = 156,
306 EXTRACTOR_METATYPE_CONDUCTOR = 157, 306 EXTRACTOR_METATYPE_CONDUCTOR = 157,
307 EXTRACTOR_METATYPE_INTERPRETATION = 158, 307 EXTRACTOR_METATYPE_INTERPRETATION = 158,
308 EXTRACTOR_METATYPE_COMPOSER = 159, 308 EXTRACTOR_METATYPE_COMPOSER = 159,
309 EXTRACTOR_METATYPE_BEATS_PER_MINUTE = 160, 309 EXTRACTOR_METATYPE_BEATS_PER_MINUTE = 160,
310 EXTRACTOR_METATYPE_ENCODED_BY = 161, 310 EXTRACTOR_METATYPE_ENCODED_BY = 161,
311 EXTRACTOR_METATYPE_ORIGINAL_TITLE = 162, 311 EXTRACTOR_METATYPE_ORIGINAL_TITLE = 162,
312 EXTRACTOR_METATYPE_ORIGINAL_ARTIST = 163, 312 EXTRACTOR_METATYPE_ORIGINAL_ARTIST = 163,
313 EXTRACTOR_METATYPE_ORIGINAL_WRITER = 164, 313 EXTRACTOR_METATYPE_ORIGINAL_WRITER = 164,
314 EXTRACTOR_METATYPE_ORIGINAL_RELEASE_YEAR = 165, 314 EXTRACTOR_METATYPE_ORIGINAL_RELEASE_YEAR = 165,
315 EXTRACTOR_METATYPE_ORIGINAL_PERFORMER = 166, 315 EXTRACTOR_METATYPE_ORIGINAL_PERFORMER = 166,
316 EXTRACTOR_METATYPE_LYRICS = 167, 316 EXTRACTOR_METATYPE_LYRICS = 167,
317 EXTRACTOR_METATYPE_POPULARITY_METER = 168, 317 EXTRACTOR_METATYPE_POPULARITY_METER = 168,
318 EXTRACTOR_METATYPE_LICENSEE = 169, 318 EXTRACTOR_METATYPE_LICENSEE = 169,
319 EXTRACTOR_METATYPE_MUSICIAN_CREDITS_LIST = 170, 319 EXTRACTOR_METATYPE_MUSICIAN_CREDITS_LIST = 170,
320 EXTRACTOR_METATYPE_MOOD = 171, 320 EXTRACTOR_METATYPE_MOOD = 171,
321 EXTRACTOR_METATYPE_SUBTITLE = 172, 321 EXTRACTOR_METATYPE_SUBTITLE = 172,
322 322
323 /* GNUnet specific values (never extracted) */ 323 /* GNUnet specific values (never extracted) */
324 EXTRACTOR_METATYPE_GNUNET_DISPLAY_TYPE = 173, 324 EXTRACTOR_METATYPE_GNUNET_DISPLAY_TYPE = 173,
325 EXTRACTOR_METATYPE_GNUNET_FULL_DATA = 174, 325 EXTRACTOR_METATYPE_GNUNET_FULL_DATA = 174,
326 EXTRACTOR_METATYPE_RATING = 175, 326 EXTRACTOR_METATYPE_RATING = 175,
327 EXTRACTOR_METATYPE_ORGANIZATION = 176, 327 EXTRACTOR_METATYPE_ORGANIZATION = 176,
328 EXTRACTOR_METATYPE_RIPPER = 177, 328 EXTRACTOR_METATYPE_RIPPER = 177,
329 EXTRACTOR_METATYPE_PRODUCER = 178, 329 EXTRACTOR_METATYPE_PRODUCER = 178,
330 EXTRACTOR_METATYPE_GROUP = 179, 330 EXTRACTOR_METATYPE_GROUP = 179,
331 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME = 180, 331 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME = 180,
332 332
333 EXTRACTOR_METATYPE_DISC_COUNT = 181, 333 EXTRACTOR_METATYPE_DISC_COUNT = 181,
334 334
335 EXTRACTOR_METATYPE_CODEC = 182, 335 EXTRACTOR_METATYPE_CODEC = 182,
336 EXTRACTOR_METATYPE_VIDEO_CODEC = 183, 336 EXTRACTOR_METATYPE_VIDEO_CODEC = 183,
337 EXTRACTOR_METATYPE_AUDIO_CODEC = 184, 337 EXTRACTOR_METATYPE_AUDIO_CODEC = 184,
338 EXTRACTOR_METATYPE_SUBTITLE_CODEC = 185, 338 EXTRACTOR_METATYPE_SUBTITLE_CODEC = 185,
339 339
340 EXTRACTOR_METATYPE_CONTAINER_FORMAT = 186, 340 EXTRACTOR_METATYPE_CONTAINER_FORMAT = 186,
341 341
342 EXTRACTOR_METATYPE_BITRATE = 187, 342 EXTRACTOR_METATYPE_BITRATE = 187,
343 EXTRACTOR_METATYPE_NOMINAL_BITRATE = 188, 343 EXTRACTOR_METATYPE_NOMINAL_BITRATE = 188,
344 EXTRACTOR_METATYPE_MINIMUM_BITRATE = 189, 344 EXTRACTOR_METATYPE_MINIMUM_BITRATE = 189,
345 EXTRACTOR_METATYPE_MAXIMUM_BITRATE = 190, 345 EXTRACTOR_METATYPE_MAXIMUM_BITRATE = 190,
346 346
347 EXTRACTOR_METATYPE_SERIAL = 191, 347 EXTRACTOR_METATYPE_SERIAL = 191,
348 348
349 EXTRACTOR_METATYPE_ENCODER = 192, 349 EXTRACTOR_METATYPE_ENCODER = 192,
350 EXTRACTOR_METATYPE_ENCODER_VERSION = 193, 350 EXTRACTOR_METATYPE_ENCODER_VERSION = 193,
351 351
352 EXTRACTOR_METATYPE_TRACK_GAIN = 194, 352 EXTRACTOR_METATYPE_TRACK_GAIN = 194,
353 EXTRACTOR_METATYPE_TRACK_PEAK = 195, 353 EXTRACTOR_METATYPE_TRACK_PEAK = 195,
354 EXTRACTOR_METATYPE_ALBUM_GAIN = 196, 354 EXTRACTOR_METATYPE_ALBUM_GAIN = 196,
355 EXTRACTOR_METATYPE_ALBUM_PEAK = 197, 355 EXTRACTOR_METATYPE_ALBUM_PEAK = 197,
356 EXTRACTOR_METATYPE_REFERENCE_LEVEL = 198, 356 EXTRACTOR_METATYPE_REFERENCE_LEVEL = 198,
357 357
358 EXTRACTOR_METATYPE_LOCATION_NAME = 199, 358 EXTRACTOR_METATYPE_LOCATION_NAME = 199,
359 EXTRACTOR_METATYPE_LOCATION_ELEVATION = 200, 359 EXTRACTOR_METATYPE_LOCATION_ELEVATION = 200,
360 EXTRACTOR_METATYPE_LOCATION_HORIZONTAL_ERROR = 201, 360 EXTRACTOR_METATYPE_LOCATION_HORIZONTAL_ERROR = 201,
361 EXTRACTOR_METATYPE_LOCATION_MOVEMENT_SPEED = 202, 361 EXTRACTOR_METATYPE_LOCATION_MOVEMENT_SPEED = 202,
362 EXTRACTOR_METATYPE_LOCATION_MOVEMENT_DIRECTION = 203, 362 EXTRACTOR_METATYPE_LOCATION_MOVEMENT_DIRECTION = 203,
363 EXTRACTOR_METATYPE_LOCATION_CAPTURE_DIRECTION = 204, 363 EXTRACTOR_METATYPE_LOCATION_CAPTURE_DIRECTION = 204,
364 364
365 EXTRACTOR_METATYPE_SHOW_EPISODE_NUMBER = 205, 365 EXTRACTOR_METATYPE_SHOW_EPISODE_NUMBER = 205,
366 EXTRACTOR_METATYPE_SHOW_SEASON_NUMBER = 206, 366 EXTRACTOR_METATYPE_SHOW_SEASON_NUMBER = 206,
367 367
368 EXTRACTOR_METATYPE_GROUPING = 207, 368 EXTRACTOR_METATYPE_GROUPING = 207,
369 369
370 EXTRACTOR_METATYPE_DEVICE_MANUFACTURER = 208, 370 EXTRACTOR_METATYPE_DEVICE_MANUFACTURER = 208,
371 EXTRACTOR_METATYPE_DEVICE_MODEL = 209, 371 EXTRACTOR_METATYPE_DEVICE_MODEL = 209,
372 372
373 EXTRACTOR_METATYPE_AUDIO_LANGUAGE = 210, 373 EXTRACTOR_METATYPE_AUDIO_LANGUAGE = 210,
374 EXTRACTOR_METATYPE_CHANNELS = 211, 374 EXTRACTOR_METATYPE_CHANNELS = 211,
375 EXTRACTOR_METATYPE_SAMPLE_RATE = 212, 375 EXTRACTOR_METATYPE_SAMPLE_RATE = 212,
376 EXTRACTOR_METATYPE_AUDIO_DEPTH = 213, 376 EXTRACTOR_METATYPE_AUDIO_DEPTH = 213,
377 EXTRACTOR_METATYPE_AUDIO_BITRATE = 214, 377 EXTRACTOR_METATYPE_AUDIO_BITRATE = 214,
378 EXTRACTOR_METATYPE_MAXIMUM_AUDIO_BITRATE = 215, 378 EXTRACTOR_METATYPE_MAXIMUM_AUDIO_BITRATE = 215,
379 379
380 EXTRACTOR_METATYPE_VIDEO_DIMENSIONS = 216, 380 EXTRACTOR_METATYPE_VIDEO_DIMENSIONS = 216,
381 EXTRACTOR_METATYPE_VIDEO_DEPTH = 217, 381 EXTRACTOR_METATYPE_VIDEO_DEPTH = 217,
382 EXTRACTOR_METATYPE_FRAME_RATE = 218, 382 EXTRACTOR_METATYPE_FRAME_RATE = 218,
383 EXTRACTOR_METATYPE_PIXEL_ASPECT_RATIO = 219, 383 EXTRACTOR_METATYPE_PIXEL_ASPECT_RATIO = 219,
384 EXTRACTOR_METATYPE_VIDEO_BITRATE = 220, 384 EXTRACTOR_METATYPE_VIDEO_BITRATE = 220,
385 EXTRACTOR_METATYPE_MAXIMUM_VIDEO_BITRATE = 221, 385 EXTRACTOR_METATYPE_MAXIMUM_VIDEO_BITRATE = 221,
386 386
387 EXTRACTOR_METATYPE_SUBTITLE_LANGUAGE = 222, 387 EXTRACTOR_METATYPE_SUBTITLE_LANGUAGE = 222,
388 EXTRACTOR_METATYPE_VIDEO_LANGUAGE = 223, 388 EXTRACTOR_METATYPE_VIDEO_LANGUAGE = 223,
389 389
390 EXTRACTOR_METATYPE_TOC = 224, 390 EXTRACTOR_METATYPE_TOC = 224,
391 391
392 EXTRACTOR_METATYPE_VIDEO_DURATION = 225, 392 EXTRACTOR_METATYPE_VIDEO_DURATION = 225,
393 EXTRACTOR_METATYPE_AUDIO_DURATION = 226, 393 EXTRACTOR_METATYPE_AUDIO_DURATION = 226,
394 EXTRACTOR_METATYPE_SUBTITLE_DURATION = 227, 394 EXTRACTOR_METATYPE_SUBTITLE_DURATION = 227,
395 395
396 EXTRACTOR_METATYPE_AUDIO_PREVIEW = 228, 396 EXTRACTOR_METATYPE_AUDIO_PREVIEW = 228,
397 397
398 EXTRACTOR_METATYPE_NARINFO = 229, 398 EXTRACTOR_METATYPE_NARINFO = 229,
399 EXTRACTOR_METATYPE_NAR = 230, 399 EXTRACTOR_METATYPE_NAR = 230,
400 400
401 EXTRACTOR_METATYPE_LAST = 231 401 EXTRACTOR_METATYPE_LAST = 231
402 }; 402};
403 403
404/** @} */ /* end of meta data types */ 404/** @} */ /* end of meta data types */
405 405
@@ -492,8 +492,8 @@ struct EXTRACTOR_ExtractContext
492 * -1 on error 492 * -1 on error
493 */ 493 */
494 ssize_t (*read) (void *cls, 494 ssize_t (*read) (void *cls,
495 void **data, 495 void **data,
496 size_t size); 496 size_t size);
497 497
498 498
499 /** 499 /**
@@ -507,8 +507,8 @@ struct EXTRACTOR_ExtractContext
507 * does not exist) 507 * does not exist)
508 */ 508 */
509 int64_t (*seek) (void *cls, 509 int64_t (*seek) (void *cls,
510 int64_t pos, 510 int64_t pos,
511 int whence); 511 int whence);
512 512
513 513
514 /** 514 /**
@@ -581,10 +581,10 @@ EXTRACTOR_plugin_add_defaults (enum EXTRACTOR_Options flags);
581 * @return the new list of libraries, equal to prev iff an error occured 581 * @return the new list of libraries, equal to prev iff an error occured
582 */ 582 */
583_EXTRACTOR_EXTERN struct EXTRACTOR_PluginList * 583_EXTRACTOR_EXTERN struct EXTRACTOR_PluginList *
584EXTRACTOR_plugin_add (struct EXTRACTOR_PluginList * prev, 584EXTRACTOR_plugin_add (struct EXTRACTOR_PluginList *prev,
585 const char *library, 585 const char *library,
586 const char *options, 586 const char *options,
587 enum EXTRACTOR_Options flags); 587 enum EXTRACTOR_Options flags);
588 588
589 589
590/** 590/**
@@ -604,8 +604,8 @@ EXTRACTOR_plugin_add (struct EXTRACTOR_PluginList * prev,
604 */ 604 */
605_EXTRACTOR_EXTERN struct EXTRACTOR_PluginList * 605_EXTRACTOR_EXTERN struct EXTRACTOR_PluginList *
606EXTRACTOR_plugin_add_config (struct EXTRACTOR_PluginList *prev, 606EXTRACTOR_plugin_add_config (struct EXTRACTOR_PluginList *prev,
607 const char *config, 607 const char *config,
608 enum EXTRACTOR_Options flags); 608 enum EXTRACTOR_Options flags);
609 609
610 610
611/** 611/**
@@ -617,7 +617,7 @@ EXTRACTOR_plugin_add_config (struct EXTRACTOR_PluginList *prev,
617 */ 617 */
618_EXTRACTOR_EXTERN struct EXTRACTOR_PluginList * 618_EXTRACTOR_EXTERN struct EXTRACTOR_PluginList *
619EXTRACTOR_plugin_remove (struct EXTRACTOR_PluginList *prev, 619EXTRACTOR_plugin_remove (struct EXTRACTOR_PluginList *prev,
620 const char *library); 620 const char *library);
621 621
622 622
623/** 623/**
@@ -642,11 +642,11 @@ EXTRACTOR_plugin_remove_all (struct EXTRACTOR_PluginList *plugins);
642 */ 642 */
643_EXTRACTOR_EXTERN void 643_EXTRACTOR_EXTERN void
644EXTRACTOR_extract (struct EXTRACTOR_PluginList *plugins, 644EXTRACTOR_extract (struct EXTRACTOR_PluginList *plugins,
645 const char *filename, 645 const char *filename,
646 const void *data, 646 const void *data,
647 size_t size, 647 size_t size,
648 EXTRACTOR_MetaDataProcessor proc, 648 EXTRACTOR_MetaDataProcessor proc,
649 void *proc_cls); 649 void *proc_cls);
650 650
651 651
652/** 652/**
@@ -667,12 +667,12 @@ EXTRACTOR_extract (struct EXTRACTOR_PluginList *plugins,
667 */ 667 */
668_EXTRACTOR_EXTERN int 668_EXTRACTOR_EXTERN int
669EXTRACTOR_meta_data_print (void *handle, 669EXTRACTOR_meta_data_print (void *handle,
670 const char *plugin_name, 670 const char *plugin_name,
671 enum EXTRACTOR_MetaType type, 671 enum EXTRACTOR_MetaType type,
672 enum EXTRACTOR_MetaFormat format, 672 enum EXTRACTOR_MetaFormat format,
673 const char *data_mime_type, 673 const char *data_mime_type,
674 const char *data, 674 const char *data,
675 size_t data_len); 675 size_t data_len);
676 676
677 677
678#if 0 /* keep Emacsens' auto-indent happy */ 678#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/include/gettext.h b/src/include/gettext.h
index 774965b..98e6784 100644
--- a/src/include/gettext.h
+++ b/src/include/gettext.h
@@ -46,11 +46,11 @@
46# define dgettext(Domainname, Msgid) ((const char *) (Msgid)) 46# define dgettext(Domainname, Msgid) ((const char *) (Msgid))
47# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid)) 47# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
48# define ngettext(Msgid1, Msgid2, N) \ 48# define ngettext(Msgid1, Msgid2, N) \
49 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) 49 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
50# define dngettext(Domainname, Msgid1, Msgid2, N) \ 50# define dngettext(Domainname, Msgid1, Msgid2, N) \
51 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) 51 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
52# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ 52# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
53 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) 53 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
54/* slight modification here to avoid warnings: generate NO code, 54/* slight modification here to avoid warnings: generate NO code,
55 not even the cast... */ 55 not even the cast... */
56# define textdomain(Domainname) 56# define textdomain(Domainname)
diff --git a/src/include/platform.h b/src/include/platform.h
index 060ab5b..9f72f57 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -29,10 +29,10 @@
29#include "config.h" 29#include "config.h"
30#ifndef FRAMEWORK_BUILD 30#ifndef FRAMEWORK_BUILD
31#include "gettext.h" 31#include "gettext.h"
32#define _(a) dgettext(PACKAGE, a) 32#define _(a) dgettext (PACKAGE, a)
33#else 33#else
34#include "libintlemu.h" 34#include "libintlemu.h"
35#define _(a) dgettext("org.gnunet.libextractor", a) 35#define _(a) dgettext ("org.gnunet.libextractor", a)
36#endif 36#endif
37 37
38#include "plibc.h" 38#include "plibc.h"
@@ -67,7 +67,7 @@
67#include <langinfo.h> 67#include <langinfo.h>
68 68
69#ifndef SIZE_MAX 69#ifndef SIZE_MAX
70#define SIZE_MAX ((size_t)-1) 70#define SIZE_MAX ((size_t) -1)
71#endif 71#endif
72 72
73#if DARWIN 73#if DARWIN
@@ -75,12 +75,11 @@
75#include <mach-o/ldsyms.h> 75#include <mach-o/ldsyms.h>
76#endif 76#endif
77 77
78#if !WINDOWS 78#if ! WINDOWS
79#define ABORT() abort() 79#define ABORT() abort ()
80#else 80#else
81#define ABORT() DebugBreak () 81#define ABORT() DebugBreak ()
82#endif 82#endif
83 83
84 84
85
86#endif 85#endif
diff --git a/src/include/plibc.h b/src/include/plibc.h
index c8b6453..9199072 100644
--- a/src/include/plibc.h
+++ b/src/include/plibc.h
@@ -2,19 +2,19 @@
2 This file is part of PlibC. 2 This file is part of PlibC.
3 Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Nils Durner (and other contributing authors) 3 Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Nils Durner (and other contributing authors)
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version. 8 version 2.1 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details. 13 Lesser General Public License for more details.
14 14
15 You should have received a copy of the GNU Lesser General Public 15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software 16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/ 18*/
19 19
20/** 20/**
@@ -68,27 +68,28 @@ extern "C" {
68#define __G_WIN32_H__ 68#define __G_WIN32_H__
69 69
70/* Convert LARGE_INTEGER to double */ 70/* Convert LARGE_INTEGER to double */
71#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \ 71#define Li2Double(x) ((double) ((x).HighPart) * 4.294967296E9 \
72 (double)((x).LowPart)) 72 + (double) ((x).LowPart))
73#ifndef HAVE_DECL__STATI64 73#ifndef HAVE_DECL__STATI64
74struct _stati64 74struct _stati64
75{ 75{
76 _dev_t st_dev; 76 _dev_t st_dev;
77 _ino_t st_ino; 77 _ino_t st_ino;
78 _mode_t st_mode; 78 _mode_t st_mode;
79 short st_nlink; 79 short st_nlink;
80 short st_uid; 80 short st_uid;
81 short st_gid; 81 short st_gid;
82 _dev_t st_rdev; 82 _dev_t st_rdev;
83 __int64 st_size; 83 __int64 st_size;
84 time_t st_atime; 84 time_t st_atime;
85 time_t st_mtime; 85 time_t st_mtime;
86 time_t st_ctime; 86 time_t st_ctime;
87}; 87};
88#endif 88#endif
89typedef unsigned int sa_family_t; 89typedef unsigned int sa_family_t;
90 90
91struct sockaddr_un { 91struct sockaddr_un
92{
92 short sun_family; /*AF_UNIX*/ 93 short sun_family; /*AF_UNIX*/
93 char sun_path[108]; /*path name */ 94 char sun_path[108]; /*path name */
94}; 95};
@@ -102,7 +103,7 @@ struct sockaddr_un {
102#endif 103#endif
103 104
104#ifndef WEXITSTATUS 105#ifndef WEXITSTATUS
105 #define WEXITSTATUS(status) (((status) & 0xff00) >> 8) 106 #define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
106#endif 107#endif
107 108
108#ifndef MSG_DONTWAIT 109#ifndef MSG_DONTWAIT
@@ -115,258 +116,258 @@ enum
115 _SC_PAGE_SIZE = 30 116 _SC_PAGE_SIZE = 30
116}; 117};
117 118
118#if !defined(EACCESS) 119#if ! defined(EACCESS)
119# define EACCESS EACCES 120# define EACCESS EACCES
120#endif 121#endif
121 122
122/* Thanks to the Cygwin project */ 123/* Thanks to the Cygwin project */
123#if !defined(ENOCSI) 124#if ! defined(ENOCSI)
124# define ENOCSI 43 /* No CSI structure available */ 125# define ENOCSI 43 /* No CSI structure available */
125#endif 126#endif
126#if !defined(EL2HLT) 127#if ! defined(EL2HLT)
127# define EL2HLT 44 /* Level 2 halted */ 128# define EL2HLT 44 /* Level 2 halted */
128#endif 129#endif
129#if !defined(EDEADLK) 130#if ! defined(EDEADLK)
130# define EDEADLK 45 /* Deadlock condition */ 131# define EDEADLK 45 /* Deadlock condition */
131#endif 132#endif
132#if !defined(ENOLCK) 133#if ! defined(ENOLCK)
133# define ENOLCK 46 /* No record locks available */ 134# define ENOLCK 46 /* No record locks available */
134#endif 135#endif
135#if !defined(EBADE) 136#if ! defined(EBADE)
136# define EBADE 50 /* Invalid exchange */ 137# define EBADE 50 /* Invalid exchange */
137#endif 138#endif
138#if !defined(EBADR) 139#if ! defined(EBADR)
139# define EBADR 51 /* Invalid request descriptor */ 140# define EBADR 51 /* Invalid request descriptor */
140#endif 141#endif
141#if !defined(EXFULL) 142#if ! defined(EXFULL)
142# define EXFULL 52 /* Exchange full */ 143# define EXFULL 52 /* Exchange full */
143#endif 144#endif
144#if !defined(ENOANO) 145#if ! defined(ENOANO)
145# define ENOANO 53 /* No anode */ 146# define ENOANO 53 /* No anode */
146#endif 147#endif
147#if !defined(EBADRQC) 148#if ! defined(EBADRQC)
148# define EBADRQC 54 /* Invalid request code */ 149# define EBADRQC 54 /* Invalid request code */
149#endif 150#endif
150#if !defined(EBADSLT) 151#if ! defined(EBADSLT)
151# define EBADSLT 55 /* Invalid slot */ 152# define EBADSLT 55 /* Invalid slot */
152#endif 153#endif
153#if !defined(EDEADLOCK) 154#if ! defined(EDEADLOCK)
154# define EDEADLOCK EDEADLK /* File locking deadlock error */ 155# define EDEADLOCK EDEADLK /* File locking deadlock error */
155#endif 156#endif
156#if !defined(EBFONT) 157#if ! defined(EBFONT)
157# define EBFONT 57 /* Bad font file fmt */ 158# define EBFONT 57 /* Bad font file fmt */
158#endif 159#endif
159#if !defined(ENOSTR) 160#if ! defined(ENOSTR)
160# define ENOSTR 60 /* Device not a stream */ 161# define ENOSTR 60 /* Device not a stream */
161#endif 162#endif
162#if !defined(ENODATA) 163#if ! defined(ENODATA)
163# define ENODATA 61 /* No data (for no delay io) */ 164# define ENODATA 61 /* No data (for no delay io) */
164#endif 165#endif
165#if !defined(ETIME) 166#if ! defined(ETIME)
166# define ETIME 62 /* Timer expired */ 167# define ETIME 62 /* Timer expired */
167#endif 168#endif
168#if !defined(ENOSR) 169#if ! defined(ENOSR)
169# define ENOSR 63 /* Out of streams resources */ 170# define ENOSR 63 /* Out of streams resources */
170#endif 171#endif
171#if !defined(ENONET) 172#if ! defined(ENONET)
172# define ENONET 64 /* Machine is not on the network */ 173# define ENONET 64 /* Machine is not on the network */
173#endif 174#endif
174#if !defined(ENOPKG) 175#if ! defined(ENOPKG)
175# define ENOPKG 65 /* Package not installed */ 176# define ENOPKG 65 /* Package not installed */
176#endif 177#endif
177#if !defined(EREMOTE) 178#if ! defined(EREMOTE)
178# define EREMOTE 66 /* The object is remote */ 179# define EREMOTE 66 /* The object is remote */
179#endif 180#endif
180#if !defined(ENOLINK) 181#if ! defined(ENOLINK)
181# define ENOLINK 67 /* The link has been severed */ 182# define ENOLINK 67 /* The link has been severed */
182#endif 183#endif
183#if !defined(EADV) 184#if ! defined(EADV)
184# define EADV 68 /* Advertise error */ 185# define EADV 68 /* Advertise error */
185#endif 186#endif
186#if !defined(ESRMNT) 187#if ! defined(ESRMNT)
187# define ESRMNT 69 /* Srmount error */ 188# define ESRMNT 69 /* Srmount error */
188#endif 189#endif
189#if !defined(ECOMM) 190#if ! defined(ECOMM)
190# define ECOMM 70 /* Communication error on send */ 191# define ECOMM 70 /* Communication error on send */
191#endif 192#endif
192#if !defined(EMULTIHOP) 193#if ! defined(EMULTIHOP)
193# define EMULTIHOP 74 /* Multihop attempted */ 194# define EMULTIHOP 74 /* Multihop attempted */
194#endif 195#endif
195#if !defined(ELBIN) 196#if ! defined(ELBIN)
196# define ELBIN 75 /* Inode is remote (not really error) */ 197# define ELBIN 75 /* Inode is remote (not really error) */
197#endif 198#endif
198#if !defined(EDOTDOT) 199#if ! defined(EDOTDOT)
199# define EDOTDOT 76 /* Cross mount point (not really error) */ 200# define EDOTDOT 76 /* Cross mount point (not really error) */
200#endif 201#endif
201#if !defined(EBADMSG) 202#if ! defined(EBADMSG)
202# define EBADMSG 77 /* Trying to read unreadable message */ 203# define EBADMSG 77 /* Trying to read unreadable message */
203#endif 204#endif
204#if !defined(ENOTUNIQ) 205#if ! defined(ENOTUNIQ)
205# define ENOTUNIQ 80 /* Given log. name not unique */ 206# define ENOTUNIQ 80 /* Given log. name not unique */
206#endif 207#endif
207#if !defined(EBADFD) 208#if ! defined(EBADFD)
208# define EBADFD 81 /* f.d. invalid for this operation */ 209# define EBADFD 81 /* f.d. invalid for this operation */
209#endif 210#endif
210#if !defined(EREMCHG) 211#if ! defined(EREMCHG)
211# define EREMCHG 82 /* Remote address changed */ 212# define EREMCHG 82 /* Remote address changed */
212#endif 213#endif
213#if !defined(ELIBACC) 214#if ! defined(ELIBACC)
214# define ELIBACC 83 /* Can't access a needed shared lib */ 215# define ELIBACC 83 /* Can't access a needed shared lib */
215#endif 216#endif
216#if !defined(ELIBBAD) 217#if ! defined(ELIBBAD)
217# define ELIBBAD 84 /* Accessing a corrupted shared lib */ 218# define ELIBBAD 84 /* Accessing a corrupted shared lib */
218#endif 219#endif
219#if !defined(ELIBSCN) 220#if ! defined(ELIBSCN)
220# define ELIBSCN 85 /* .lib section in a.out corrupted */ 221# define ELIBSCN 85 /* .lib section in a.out corrupted */
221#endif 222#endif
222#if !defined(ELIBMAX) 223#if ! defined(ELIBMAX)
223# define ELIBMAX 86 /* Attempting to link in too many libs */ 224# define ELIBMAX 86 /* Attempting to link in too many libs */
224#endif 225#endif
225#if !defined(ELIBEXEC) 226#if ! defined(ELIBEXEC)
226# define ELIBEXEC 87 /* Attempting to exec a shared library */ 227# define ELIBEXEC 87 /* Attempting to exec a shared library */
227#endif 228#endif
228#if !defined(ENOSYS) 229#if ! defined(ENOSYS)
229# define ENOSYS 88 /* Function not implemented */ 230# define ENOSYS 88 /* Function not implemented */
230#endif 231#endif
231#if !defined(ENMFILE) 232#if ! defined(ENMFILE)
232# define ENMFILE 89 /* No more files */ 233# define ENMFILE 89 /* No more files */
233#endif 234#endif
234#if !defined(ENOTEMPTY) 235#if ! defined(ENOTEMPTY)
235# define ENOTEMPTY 90 /* Directory not empty */ 236# define ENOTEMPTY 90 /* Directory not empty */
236#endif 237#endif
237#if !defined(ENAMETOOLONG) 238#if ! defined(ENAMETOOLONG)
238# define ENAMETOOLONG 91 /* File or path name too long */ 239# define ENAMETOOLONG 91 /* File or path name too long */
239#endif 240#endif
240#if !defined(EPFNOSUPPORT) 241#if ! defined(EPFNOSUPPORT)
241# define EPFNOSUPPORT 96 /* Protocol family not supported */ 242# define EPFNOSUPPORT 96 /* Protocol family not supported */
242#endif 243#endif
243#if !defined(ENOSHARE) 244#if ! defined(ENOSHARE)
244# define ENOSHARE 97 /* No such host or network path */ 245# define ENOSHARE 97 /* No such host or network path */
245#endif 246#endif
246#if !defined(ENOMEDIUM) 247#if ! defined(ENOMEDIUM)
247# define ENOMEDIUM 98 /* No medium (in tape drive) */ 248# define ENOMEDIUM 98 /* No medium (in tape drive) */
248#endif 249#endif
249#if !defined(ESHUTDOWN) 250#if ! defined(ESHUTDOWN)
250# define ESHUTDOWN 99 /* Can't send after socket shutdown */ 251# define ESHUTDOWN 99 /* Can't send after socket shutdown */
251#endif 252#endif
252#if !defined(EADDRINUSE) 253#if ! defined(EADDRINUSE)
253# define EADDRINUSE 100 /* Address already in use */ 254# define EADDRINUSE 100 /* Address already in use */
254#endif 255#endif
255#if !defined(EADDRNOTAVAIL) 256#if ! defined(EADDRNOTAVAIL)
256# define EADDRNOTAVAIL 101 /* Address not available */ 257# define EADDRNOTAVAIL 101 /* Address not available */
257#endif 258#endif
258#if !defined(EAFNOSUPPORT) 259#if ! defined(EAFNOSUPPORT)
259# define EAFNOSUPPORT 102 /* Address family not supported by protocol family */ 260# define EAFNOSUPPORT 102 /* Address family not supported by protocol family */
260#endif 261#endif
261#if !defined(EALREADY) 262#if ! defined(EALREADY)
262# define EALREADY 103 /* Socket already connected */ 263# define EALREADY 103 /* Socket already connected */
263#endif 264#endif
264#if !defined(ECANCELED) 265#if ! defined(ECANCELED)
265# define ECANCELED 105 /* Connection cancelled */ 266# define ECANCELED 105 /* Connection cancelled */
266#endif 267#endif
267#if !defined(ECONNABORTED) 268#if ! defined(ECONNABORTED)
268# define ECONNABORTED 106 /* Connection aborted */ 269# define ECONNABORTED 106 /* Connection aborted */
269#endif 270#endif
270#if !defined(ECONNREFUSED) 271#if ! defined(ECONNREFUSED)
271# define ECONNREFUSED 107 /* Connection refused */ 272# define ECONNREFUSED 107 /* Connection refused */
272#endif 273#endif
273#if !defined(ECONNRESET) 274#if ! defined(ECONNRESET)
274# define ECONNRESET 108 /* Connection reset by peer */ 275# define ECONNRESET 108 /* Connection reset by peer */
275#endif 276#endif
276#if !defined(EDESTADDRREQ) 277#if ! defined(EDESTADDRREQ)
277# define EDESTADDRREQ 109 /* Destination address required */ 278# define EDESTADDRREQ 109 /* Destination address required */
278#endif 279#endif
279#if !defined(EHOSTUNREACH) 280#if ! defined(EHOSTUNREACH)
280# define EHOSTUNREACH 110 /* Host is unreachable */ 281# define EHOSTUNREACH 110 /* Host is unreachable */
281#endif 282#endif
282#if !defined(ECONNABORTED) 283#if ! defined(ECONNABORTED)
283# define ECONNABORTED 111 /* Connection aborted */ 284# define ECONNABORTED 111 /* Connection aborted */
284#endif 285#endif
285#if !defined(EINPROGRESS) 286#if ! defined(EINPROGRESS)
286# define EINPROGRESS 112 /* Connection already in progress */ 287# define EINPROGRESS 112 /* Connection already in progress */
287#endif 288#endif
288#if !defined(EISCONN) 289#if ! defined(EISCONN)
289# define EISCONN 113 /* Socket is already connected */ 290# define EISCONN 113 /* Socket is already connected */
290#endif 291#endif
291#if !defined(ELOOP) 292#if ! defined(ELOOP)
292# define ELOOP 114 /* Too many symbolic links */ 293# define ELOOP 114 /* Too many symbolic links */
293#endif 294#endif
294#if !defined(EMSGSIZE) 295#if ! defined(EMSGSIZE)
295# define EMSGSIZE 115 /* Message too long */ 296# define EMSGSIZE 115 /* Message too long */
296#endif 297#endif
297#if !defined(ENETDOWN) 298#if ! defined(ENETDOWN)
298# define ENETDOWN 116 /* Network interface is not configured */ 299# define ENETDOWN 116 /* Network interface is not configured */
299#endif 300#endif
300#if !defined(ENETRESET) 301#if ! defined(ENETRESET)
301# define ENETRESET 117 /* Connection aborted by network */ 302# define ENETRESET 117 /* Connection aborted by network */
302#endif 303#endif
303#if !defined(ENETUNREACH) 304#if ! defined(ENETUNREACH)
304# define ENETUNREACH 118 /* Network is unreachable */ 305# define ENETUNREACH 118 /* Network is unreachable */
305#endif 306#endif
306#if !defined(ENOBUFS) 307#if ! defined(ENOBUFS)
307# define ENOBUFS 119 /* No buffer space available */ 308# define ENOBUFS 119 /* No buffer space available */
308#endif 309#endif
309#if !defined(EHOSTDOWN) 310#if ! defined(EHOSTDOWN)
310# define EHOSTDOWN 120 /* Host is down */ 311# define EHOSTDOWN 120 /* Host is down */
311#endif 312#endif
312#if !defined(EPROCLIM) 313#if ! defined(EPROCLIM)
313# define EPROCLIM 121 /* Too many processes */ 314# define EPROCLIM 121 /* Too many processes */
314#endif 315#endif
315#if !defined(EDQUOT) 316#if ! defined(EDQUOT)
316# define EDQUOT 122 /* Disk quota exceeded */ 317# define EDQUOT 122 /* Disk quota exceeded */
317#endif 318#endif
318#if !defined(ENOPROTOOPT) 319#if ! defined(ENOPROTOOPT)
319# define ENOPROTOOPT 123 /* Protocol not available */ 320# define ENOPROTOOPT 123 /* Protocol not available */
320#endif 321#endif
321#if !defined(ESOCKTNOSUPPORT) 322#if ! defined(ESOCKTNOSUPPORT)
322# define ESOCKTNOSUPPORT 124 /* Socket type not supported */ 323# define ESOCKTNOSUPPORT 124 /* Socket type not supported */
323#endif 324#endif
324#if !defined(ESTALE) 325#if ! defined(ESTALE)
325# define ESTALE 125 /* Unknown error */ 326# define ESTALE 125 /* Unknown error */
326#endif 327#endif
327#if !defined(ENOTCONN) 328#if ! defined(ENOTCONN)
328# define ENOTCONN 126 /* Socket is not connected */ 329# define ENOTCONN 126 /* Socket is not connected */
329#endif 330#endif
330#if !defined(ETOOMANYREFS) 331#if ! defined(ETOOMANYREFS)
331# define ETOOMANYREFS 127 /* Too many references: cannot splice */ 332# define ETOOMANYREFS 127 /* Too many references: cannot splice */
332#endif 333#endif
333#if !defined(ENOTSOCK) 334#if ! defined(ENOTSOCK)
334# define ENOTSOCK 128 /* Socket operation on non-socket */ 335# define ENOTSOCK 128 /* Socket operation on non-socket */
335#endif 336#endif
336#if !defined(ENOTSUP) 337#if ! defined(ENOTSUP)
337# define ENOTSUP 129 /* Not supported */ 338# define ENOTSUP 129 /* Not supported */
338#endif 339#endif
339#if !defined(EOPNOTSUPP) 340#if ! defined(EOPNOTSUPP)
340# define EOPNOTSUPP 130 /* Operation not supported on transport endpoint */ 341# define EOPNOTSUPP 130 /* Operation not supported on transport endpoint */
341#endif 342#endif
342#if !defined(EUSERS) 343#if ! defined(EUSERS)
343# define EUSERS 131 /* Too many users */ 344# define EUSERS 131 /* Too many users */
344#endif 345#endif
345#if !defined(EOVERFLOW) 346#if ! defined(EOVERFLOW)
346# define EOVERFLOW 132 /* Value too large for defined data type */ 347# define EOVERFLOW 132 /* Value too large for defined data type */
347#endif 348#endif
348#if !defined(EOWNERDEAD) 349#if ! defined(EOWNERDEAD)
349# define EOWNERDEAD 133 /* Unknown error */ 350# define EOWNERDEAD 133 /* Unknown error */
350#endif 351#endif
351#if !defined(EPROTO) 352#if ! defined(EPROTO)
352# define EPROTO 134 /* Protocol error */ 353# define EPROTO 134 /* Protocol error */
353#endif 354#endif
354#if !defined(EPROTONOSUPPORT) 355#if ! defined(EPROTONOSUPPORT)
355# define EPROTONOSUPPORT 135 /* Unknown protocol */ 356# define EPROTONOSUPPORT 135 /* Unknown protocol */
356#endif 357#endif
357#if !defined(EPROTOTYPE) 358#if ! defined(EPROTOTYPE)
358# define EPROTOTYPE 136 /* Protocol wrong type for socket */ 359# define EPROTOTYPE 136 /* Protocol wrong type for socket */
359#endif 360#endif
360#if !defined(ECASECLASH) 361#if ! defined(ECASECLASH)
361# define ECASECLASH 137 /* Filename exists with different case */ 362# define ECASECLASH 137 /* Filename exists with different case */
362#endif 363#endif
363#if !defined(ETIMEDOUT) 364#if ! defined(ETIMEDOUT)
364/* Make sure it's the same as WSATIMEDOUT */ 365/* Make sure it's the same as WSATIMEDOUT */
365# define ETIMEDOUT 138 /* Connection timed out */ 366# define ETIMEDOUT 138 /* Connection timed out */
366#endif 367#endif
367#if !defined(EWOULDBLOCK) || EWOULDBLOCK == 140 368#if ! defined(EWOULDBLOCK) || EWOULDBLOCK == 140
368# undef EWOULDBLOCK /* MinGW-w64 defines it as 140, but we want it as EAGAIN */ 369# undef EWOULDBLOCK /* MinGW-w64 defines it as 140, but we want it as EAGAIN */
369# define EWOULDBLOCK EAGAIN /* Operation would block */ 370# define EWOULDBLOCK EAGAIN /* Operation would block */
370#endif 371#endif
371 372
372#undef HOST_NOT_FOUND 373#undef HOST_NOT_FOUND
@@ -384,7 +385,7 @@ enum
384#define MAP_PRIVATE 0x2 /* unsupported */ 385#define MAP_PRIVATE 0x2 /* unsupported */
385#define MAP_FIXED 0x10 386#define MAP_FIXED 0x10
386#define MAP_ANONYMOUS 0x20 /* unsupported */ 387#define MAP_ANONYMOUS 0x20 /* unsupported */
387#define MAP_FAILED ((void *)-1) 388#define MAP_FAILED ((void *) -1)
388 389
389#define MS_ASYNC 1 /* sync memory asynchronously */ 390#define MS_ASYNC 1 /* sync memory asynchronously */
390#define MS_INVALIDATE 2 /* invalidate the caches */ 391#define MS_INVALIDATE 2 /* invalidate the caches */
@@ -403,7 +404,7 @@ struct statfs
403 long f_namelen; /* maximum length of filenames */ 404 long f_namelen; /* maximum length of filenames */
404 long f_spare[6]; /* spare for later */ 405 long f_spare[6]; /* spare for later */
405}; 406};
406#define sleep(secs) (Sleep(secs * 1000)) 407#define sleep(secs) (Sleep (secs * 1000))
407 408
408/*********************** statfs *****************************/ 409/*********************** statfs *****************************/
409/* fake block size */ 410/* fake block size */
@@ -466,159 +467,265 @@ struct statfs
466#define SIGKILL 9 467#define SIGKILL 9
467#define SIGTERM 15 468#define SIGTERM 15
468 469
469#define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__) 470#define SetErrnoFromWinError(e) _SetErrnoFromWinError (e, __FILE__, __LINE__)
471
472BOOL _plibc_CreateShortcut (const char *pszSrc, const char *pszDest);
473
474BOOL _plibc_CreateShortcutW (const wchar_t *pwszSrc, const wchar_t *pwszDest);
475
476BOOL _plibc_DereferenceShortcut (char *pszShortcut);
477
478BOOL _plibc_DereferenceShortcutW (wchar_t *pwszShortcut);
479
480char *plibc_ChooseDir (char *pszTitle, unsigned long ulFlags);
481
482wchar_t *plibc_ChooseDirW (wchar_t *pwszTitle, unsigned long ulFlags);
483
484char *plibc_ChooseFile (char *pszTitle, unsigned long ulFlags);
485
486wchar_t *plibc_ChooseFileW (wchar_t *pwszTitle, unsigned long ulFlags);
487
488long QueryRegistry (HKEY hMainKey, const char *pszKey, const char *pszSubKey,
489 char *pszBuffer, long *pdLength);
490
491long QueryRegistryW (HKEY hMainKey, const wchar_t *pszKey, const
492 wchar_t *pszSubKey,
493 wchar_t *pszBuffer, long *pdLength);
494
495BOOL __win_IsHandleMarkedAsBlocking (int hHandle);
496
497void __win_SetHandleBlockingMode (int s, BOOL bBlocking);
498
499void __win_DiscardHandleBlockingMode (int s);
500
501int _win_isSocketValid (int s);
470 502
471BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest); 503int plibc_conv_to_win_path (const char *pszUnix, char *pszWindows);
472BOOL _plibc_CreateShortcutW(const wchar_t *pwszSrc, const wchar_t *pwszDest);
473BOOL _plibc_DereferenceShortcut(char *pszShortcut);
474BOOL _plibc_DereferenceShortcutW(wchar_t *pwszShortcut);
475char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags);
476wchar_t *plibc_ChooseDirW(wchar_t *pwszTitle, unsigned long ulFlags);
477char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags);
478wchar_t *plibc_ChooseFileW(wchar_t *pwszTitle, unsigned long ulFlags);
479 504
480long QueryRegistry(HKEY hMainKey, const char *pszKey, const char *pszSubKey, 505int plibc_conv_to_win_pathw (const wchar_t *pszUnix, wchar_t *pwszWindows);
481 char *pszBuffer, long *pdLength);
482long QueryRegistryW(HKEY hMainKey, const wchar_t *pszKey, const wchar_t *pszSubKey,
483 wchar_t *pszBuffer, long *pdLength);
484 506
485BOOL __win_IsHandleMarkedAsBlocking(int hHandle); 507int plibc_conv_to_win_pathwconv (const char *pszUnix, wchar_t *pwszWindows);
486void __win_SetHandleBlockingMode(int s, BOOL bBlocking);
487void __win_DiscardHandleBlockingMode(int s);
488int _win_isSocketValid(int s);
489int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows);
490int plibc_conv_to_win_pathw(const wchar_t *pszUnix, wchar_t *pwszWindows);
491 508
492int plibc_conv_to_win_pathwconv(const char *pszUnix, wchar_t *pwszWindows); 509int plibc_conv_to_win_pathwconv_ex (const char *pszUnix, wchar_t *pszWindows,
493int plibc_conv_to_win_pathwconv_ex(const char *pszUnix, wchar_t *pszWindows, int derefLinks); 510 int derefLinks);
494 511
495unsigned plibc_get_handle_count(); 512unsigned plibc_get_handle_count ();
496 513
497typedef void (*TPanicProc) (int, char *); 514typedef void (*TPanicProc) (int, char *);
498void plibc_set_panic_proc(TPanicProc proc); 515void plibc_set_panic_proc (TPanicProc proc);
499void plibc_set_stat_size_size(int iLength); 516
500void plibc_set_stat_time_size(int iLength); 517void plibc_set_stat_size_size (int iLength);
501 518
502int flock(int fd, int operation); 519void plibc_set_stat_time_size (int iLength);
503int fsync(int fildes); 520
504int inet_pton(int af, const char *src, void *dst); 521int flock (int fd, int operation);
505int inet_pton4(const char *src, u_char *dst, int pton); 522
523int fsync (int fildes);
524
525int inet_pton (int af, const char *src, void *dst);
526
527int inet_pton4 (const char *src, u_char *dst, int pton);
528
506#if USE_IPV6 529#if USE_IPV6
507int inet_pton6(const char *src, u_char *dst); 530int inet_pton6 (const char *src, u_char *dst);
531
508#endif 532#endif
509int statfs(const char *path, struct statfs *buf); 533int statfs (const char *path, struct statfs *buf);
510const char *hstrerror(int err); 534
511int mkstemp(char *tmplate); 535const char *hstrerror (int err);
536
537int mkstemp (char *tmplate);
538
512char *strptime (const char *buf, const char *format, struct tm *tm); 539char *strptime (const char *buf, const char *format, struct tm *tm);
513const char *inet_ntop(int af, const void *src, char *dst, size_t size); 540
541const char *inet_ntop (int af, const void *src, char *dst, size_t size);
542
514#ifndef gmtime_r 543#ifndef gmtime_r
515struct tm *gmtime_r(const time_t *clock, struct tm *result); 544struct tm *gmtime_r (const time_t *clock, struct tm *result);
516#endif 545
517 546#endif
518int plibc_init(char *pszOrg, char *pszApp); 547
519int plibc_init_utf8(char *pszOrg, char *pszApp, int utf8_mode); 548int plibc_init (char *pszOrg, char *pszApp);
520void plibc_shutdown(); 549
521int plibc_initialized(); 550int plibc_init_utf8 (char *pszOrg, char *pszApp, int utf8_mode);
522 551
523void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine); 552void plibc_shutdown ();
524void SetErrnoFromWinsockError(long lWinError); 553
525void SetHErrnoFromWinError(long lWinError); 554int plibc_initialized ();
526void SetErrnoFromHRESULT(HRESULT hRes); 555
527int GetErrnoFromWinsockError(long lWinError); 556void _SetErrnoFromWinError (long lWinError, char *pszCaller, int iLine);
528FILE *_win_fopen(const char *filename, const char *mode); 557
529int _win_fclose(FILE *); 558void SetErrnoFromWinsockError (long lWinError);
530DIR *_win_opendir(const char *dirname); 559
531struct dirent *_win_readdir(DIR *dirp); 560void SetHErrnoFromWinError (long lWinError);
532int _win_closedir(DIR *dirp); 561
533int _win_open(const char *filename, int oflag, ...); 562void SetErrnoFromHRESULT (HRESULT hRes);
563
564int GetErrnoFromWinsockError (long lWinError);
565
566FILE *_win_fopen (const char *filename, const char *mode);
567
568int _win_fclose (FILE *);
569
570DIR *_win_opendir (const char *dirname);
571
572struct dirent *_win_readdir (DIR *dirp);
573
574int _win_closedir (DIR *dirp);
575
576int _win_open (const char *filename, int oflag, ...);
577
534#ifdef ENABLE_NLS 578#ifdef ENABLE_NLS
535char *_win_bindtextdomain(const char *domainname, const char *dirname); 579char *_win_bindtextdomain (const char *domainname, const char *dirname);
536#endif 580
537int _win_chdir(const char *path); 581#endif
538int _win_close(int fd); 582int _win_chdir (const char *path);
539int _win_creat(const char *path, mode_t mode); 583
540char *_win_ctime(const time_t *clock); 584int _win_close (int fd);
541char *_win_ctime_r(const time_t *clock, char *buf); 585
542int _win_fstat(int handle, struct stat *buffer); 586int _win_creat (const char *path, mode_t mode);
543int _win_ftruncate(int fildes, off_t length); 587
544int _win_truncate(const char *fname, int distance); 588char *_win_ctime (const time_t *clock);
545int _win_kill(pid_t pid, int sig); 589
546int _win_pipe(int *phandles); 590char *_win_ctime_r (const time_t *clock, char *buf);
547int _win_mkfifo(const char *path, mode_t mode); 591
548int _win_rmdir(const char *path); 592int _win_fstat (int handle, struct stat *buffer);
549int _win_access( const char *path, int mode ); 593
550int _win_chmod(const char *filename, int pmode); 594int _win_ftruncate (int fildes, off_t length);
551char *realpath(const char *file_name, char *resolved_name); 595
552long _win_random(void); 596int _win_truncate (const char *fname, int distance);
553void _win_srandom(unsigned int seed); 597
554int _win_remove(const char *path); 598int _win_kill (pid_t pid, int sig);
555int _win_rename(const char *oldname, const char *newname); 599
556int _win_stat(const char *path, struct stat *buffer); 600int _win_pipe (int *phandles);
557int _win_stati64(const char *path, struct _stati64 *buffer); 601
558long _win_sysconf(int name); 602int _win_mkfifo (const char *path, mode_t mode);
559int _win_unlink(const char *filename); 603
560int _win_write(int fildes, const void *buf, size_t nbyte); 604int _win_rmdir (const char *path);
561int _win_read(int fildes, void *buf, size_t nbyte); 605
562size_t _win_fwrite(const void *buffer, size_t size, size_t count, FILE *stream); 606int _win_access (const char *path, int mode);
563size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream ); 607
564int _win_symlink(const char *path1, const char *path2); 608int _win_chmod (const char *filename, int pmode);
565void *_win_mmap(void *start, size_t len, int access, int flags, int fd, 609
566 unsigned long long offset); 610char *realpath (const char *file_name, char *resolved_name);
567int _win_msync(void *start, size_t length, int flags); 611
568int _win_munmap(void *start, size_t length); 612long _win_random (void);
569int _win_lstat(const char *path, struct stat *buf); 613
570int _win_lstati64(const char *path, struct _stati64 *buf); 614void _win_srandom (unsigned int seed);
571int _win_readlink(const char *path, char *buf, size_t bufsize); 615
572int _win_accept(int s, struct sockaddr *addr, int *addrlen); 616int _win_remove (const char *path);
573 617
574pid_t _win_waitpid(pid_t pid, int *stat_loc, int options); 618int _win_rename (const char *oldname, const char *newname);
575int _win_bind(int s, const struct sockaddr *name, int namelen); 619
576int _win_connect(int s,const struct sockaddr *name, int namelen); 620int _win_stat (const char *path, struct stat *buffer);
577int _win_getpeername(int s, struct sockaddr *name, 621
578 int *namelen); 622int _win_stati64 (const char *path, struct _stati64 *buffer);
579int _win_getsockname(int s, struct sockaddr *name, 623
580 int *namelen); 624long _win_sysconf (int name);
581int _win_getsockopt(int s, int level, int optname, char *optval, 625
582 int *optlen); 626int _win_unlink (const char *filename);
583int _win_listen(int s, int backlog); 627
584int _win_recv(int s, char *buf, int len, int flags); 628int _win_write (int fildes, const void *buf, size_t nbyte);
585int _win_recvfrom(int s, void *buf, int len, int flags, 629
586 struct sockaddr *from, int *fromlen); 630int _win_read (int fildes, void *buf, size_t nbyte);
587int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds, 631
588 const struct timeval *tv); 632size_t _win_fwrite (const void *buffer, size_t size, size_t count,
589int _win_send(int s, const char *buf, int len, int flags); 633 FILE *stream);
590int _win_sendto(int s, const char *buf, int len, int flags, 634
591 const struct sockaddr *to, int tolen); 635size_t _win_fread (void *buffer, size_t size, size_t count, FILE *stream);
592int _win_setsockopt(int s, int level, int optname, const void *optval, 636
593 int optlen); 637int _win_symlink (const char *path1, const char *path2);
594int _win_shutdown(int s, int how); 638
595int _win_socket(int af, int type, int protocol); 639void *_win_mmap (void *start, size_t len, int access, int flags, int fd,
596int _win_socketpair(int af, int type, int protocol, int socket_vector[2]); 640 unsigned long long offset);
597struct hostent *_win_gethostbyaddr(const char *addr, int len, int type); 641
598struct hostent *_win_gethostbyname(const char *name); 642int _win_msync (void *start, size_t length, int flags);
599struct hostent *gethostbyname2(const char *name, int af); 643
600char *_win_strerror(int errnum); 644int _win_munmap (void *start, size_t length);
601int IsWinNT(); 645
602char *index(const char *s, int c); 646int _win_lstat (const char *path, struct stat *buf);
647
648int _win_lstati64 (const char *path, struct _stati64 *buf);
649
650int _win_readlink (const char *path, char *buf, size_t bufsize);
651
652int _win_accept (int s, struct sockaddr *addr, int *addrlen);
653
654pid_t _win_waitpid (pid_t pid, int *stat_loc, int options);
655
656int _win_bind (int s, const struct sockaddr *name, int namelen);
657
658int _win_connect (int s,const struct sockaddr *name, int namelen);
659
660int _win_getpeername (int s, struct sockaddr *name,
661 int *namelen);
662
663int _win_getsockname (int s, struct sockaddr *name,
664 int *namelen);
665
666int _win_getsockopt (int s, int level, int optname, char *optval,
667 int *optlen);
668
669int _win_listen (int s, int backlog);
670
671int _win_recv (int s, char *buf, int len, int flags);
672
673int _win_recvfrom (int s, void *buf, int len, int flags,
674 struct sockaddr *from, int *fromlen);
675
676int _win_select (int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds,
677 const struct timeval *tv);
678
679int _win_send (int s, const char *buf, int len, int flags);
680
681int _win_sendto (int s, const char *buf, int len, int flags,
682 const struct sockaddr *to, int tolen);
683
684int _win_setsockopt (int s, int level, int optname, const void *optval,
685 int optlen);
686
687int _win_shutdown (int s, int how);
688
689int _win_socket (int af, int type, int protocol);
690
691int _win_socketpair (int af, int type, int protocol, int socket_vector[2]);
692
693struct hostent *_win_gethostbyaddr (const char *addr, int len, int type);
694
695struct hostent *_win_gethostbyname (const char *name);
696
697struct hostent *gethostbyname2 (const char *name, int af);
698
699char *_win_strerror (int errnum);
700
701int IsWinNT ();
702
703char *index (const char *s, int c);
704
603char *_win_strtok_r (char *ptr, const char *sep, char **end); 705char *_win_strtok_r (char *ptr, const char *sep, char **end);
604 706
605#if !HAVE_STRNDUP 707#if ! HAVE_STRNDUP
606char *strndup (const char *s, size_t n); 708char *strndup (const char *s, size_t n);
709
607#endif 710#endif
608#if !HAVE_STRNLEN && (!defined(__MINGW64_VERSION_MAJOR) || !defined(_INC_STRING)) 711#if ! HAVE_STRNLEN && (! defined(__MINGW64_VERSION_MAJOR) || \
712 ! defined(_INC_STRING))
609size_t strnlen (const char *str, size_t maxlen); 713size_t strnlen (const char *str, size_t maxlen);
714
610#endif 715#endif
611char *stpcpy(char *dest, const char *src); 716char *stpcpy (char *dest, const char *src);
612char *strcasestr(const char *haystack_start, const char *needle_start); 717
718char *strcasestr (const char *haystack_start, const char *needle_start);
719
613#ifndef __MINGW64_VERSION_MAJOR 720#ifndef __MINGW64_VERSION_MAJOR
614#define strcasecmp(a, b) stricmp(a, b) 721#define strcasecmp(a, b) stricmp (a, b)
615#define strncasecmp(a, b, c) strnicmp(a, b, c) 722#define strncasecmp(a, b, c) strnicmp (a, b, c)
616#endif 723#endif
617#ifndef wcscasecmp 724#ifndef wcscasecmp
618#define wcscasecmp(a, b) wcsicmp(a, b) 725#define wcscasecmp(a, b) wcsicmp (a, b)
619#endif 726#endif
620#ifndef wcsncasecmp 727#ifndef wcsncasecmp
621#define wcsncasecmp(a, b, c) wcsnicmp(a, b, c) 728#define wcsncasecmp(a, b, c) wcsnicmp (a, b, c)
622#endif 729#endif
623#ifndef strtok_r /* winpthreads defines it in pthread.h */ 730#ifndef strtok_r /* winpthreads defines it in pthread.h */
624#define strtok_r _win_strtok_r 731#define strtok_r _win_strtok_r
@@ -633,99 +740,99 @@ char *strcasestr(const char *haystack_start, const char *needle_start);
633 #define NEWLINE "\n" 740 #define NEWLINE "\n"
634 741
635#ifdef ENABLE_NLS 742#ifdef ENABLE_NLS
636 #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n) 743 #define BINDTEXTDOMAIN(d, n) bindtextdomain (d, n)
637#endif 744#endif
638 #define CREAT(p, m) creat(p, m) 745 #define CREAT(p, m) creat (p, m)
639 #define PLIBC_CTIME(c) ctime(c) 746 #define PLIBC_CTIME(c) ctime (c)
640 #define CTIME_R(c, b) ctime_r(c, b) 747 #define CTIME_R(c, b) ctime_r (c, b)
641 #undef FOPEN 748 #undef FOPEN
642 #define FOPEN(f, m) fopen(f, m) 749 #define FOPEN(f, m) fopen (f, m)
643 #define FCLOSE(f) fclose(f) 750 #define FCLOSE(f) fclose (f)
644 #define FTRUNCATE(f, l) ftruncate(f, l) 751 #define FTRUNCATE(f, l) ftruncate (f, l)
645 #define TRUNCATE(f, l) truncate(f, l) 752 #define TRUNCATE(f, l) truncate (f, l)
646 #define OPENDIR(d) opendir(d) 753 #define OPENDIR(d) opendir (d)
647 #define CLOSEDIR(d) closedir(d) 754 #define CLOSEDIR(d) closedir (d)
648 #define READDIR(d) readdir(d) 755 #define READDIR(d) readdir (d)
649 #define OPEN open 756 #define OPEN open
650 #define CHDIR(d) chdir(d) 757 #define CHDIR(d) chdir (d)
651 #define CLOSE(f) close(f) 758 #define CLOSE(f) close (f)
652 #define LSEEK(f, o, w) lseek(f, o, w) 759 #define LSEEK(f, o, w) lseek (f, o, w)
653 #define RMDIR(f) rmdir(f) 760 #define RMDIR(f) rmdir (f)
654 #define ACCESS(p, m) access(p, m) 761 #define ACCESS(p, m) access (p, m)
655 #define CHMOD(f, p) chmod(f, p) 762 #define CHMOD(f, p) chmod (f, p)
656 #define FSTAT(h, b) fstat(h, b) 763 #define FSTAT(h, b) fstat (h, b)
657 #define PLIBC_KILL(p, s) kill(p, s) 764 #define PLIBC_KILL(p, s) kill (p, s)
658 #define PIPE(h) pipe(h) 765 #define PIPE(h) pipe (h)
659 #define REMOVE(p) remove(p) 766 #define REMOVE(p) remove (p)
660 #define RENAME(o, n) rename(o, n) 767 #define RENAME(o, n) rename (o, n)
661 #define STAT(p, b) stat(p, b) 768 #define STAT(p, b) stat (p, b)
662 #define STAT64(p, b) stat64(p, b) 769 #define STAT64(p, b) stat64 (p, b)
663 #define SYSCONF(n) sysconf(n) 770 #define SYSCONF(n) sysconf (n)
664 #define UNLINK(f) unlink(f) 771 #define UNLINK(f) unlink (f)
665 #define WRITE(f, b, n) write(f, b, n) 772 #define WRITE(f, b, n) write (f, b, n)
666 #define READ(f, b, n) read(f, b, n) 773 #define READ(f, b, n) read (f, b, n)
667 #define GN_FREAD(b, s, c, f) fread(b, s, c, f) 774 #define GN_FREAD(b, s, c, f) fread (b, s, c, f)
668 #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f) 775 #define GN_FWRITE(b, s, c, f) fwrite (b, s, c, f)
669 #define SYMLINK(a, b) symlink(a, b) 776 #define SYMLINK(a, b) symlink (a, b)
670 #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o) 777 #define MMAP(s, l, p, f, d, o) mmap (s, l, p, f, d, o)
671 #define MKFIFO(p, m) mkfifo(p, m) 778 #define MKFIFO(p, m) mkfifo (p, m)
672 #define MSYNC(s, l, f) msync(s, l, f) 779 #define MSYNC(s, l, f) msync (s, l, f)
673 #define MUNMAP(s, l) munmap(s, l) 780 #define MUNMAP(s, l) munmap (s, l)
674 #define STRERROR(i) strerror(i) 781 #define STRERROR(i) strerror (i)
675 #define RANDOM() random() 782 #define RANDOM() random ()
676 #define SRANDOM(s) srandom(s) 783 #define SRANDOM(s) srandom (s)
677 #define READLINK(p, b, s) readlink(p, b, s) 784 #define READLINK(p, b, s) readlink (p, b, s)
678 #define LSTAT(p, b) lstat(p, b) 785 #define LSTAT(p, b) lstat (p, b)
679 #define LSTAT64(p, b) lstat64(p, b) 786 #define LSTAT64(p, b) lstat64 (p, b)
680 #define PRINTF printf 787 #define PRINTF printf
681 #define FPRINTF fprintf 788 #define FPRINTF fprintf
682 #define VPRINTF(f, a) vprintf(f, a) 789 #define VPRINTF(f, a) vprintf (f, a)
683 #define VFPRINTF(s, f, a) vfprintf(s, f, a) 790 #define VFPRINTF(s, f, a) vfprintf (s, f, a)
684 #define VSPRINTF(d, f, a) vsprintf(d, f, a) 791 #define VSPRINTF(d, f, a) vsprintf (d, f, a)
685 #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a) 792 #define VSNPRINTF(str, size, fmt, a) vsnprintf (str, size, fmt, a)
686 #define _REAL_SNPRINTF snprintf 793 #define _REAL_SNPRINTF snprintf
687 #define SPRINTF sprintf 794 #define SPRINTF sprintf
688 #define VSSCANF(s, f, a) vsscanf(s, f, a) 795 #define VSSCANF(s, f, a) vsscanf (s, f, a)
689 #define SSCANF sscanf 796 #define SSCANF sscanf
690 #define VFSCANF(s, f, a) vfscanf(s, f, a) 797 #define VFSCANF(s, f, a) vfscanf (s, f, a)
691 #define VSCANF(f, a) vscanf(f, a) 798 #define VSCANF(f, a) vscanf (f, a)
692 #define SCANF scanf 799 #define SCANF scanf
693 #define FSCANF fscanf 800 #define FSCANF fscanf
694 #define WAITPID(p, s, o) waitpid(p, s, o) 801 #define WAITPID(p, s, o) waitpid (p, s, o)
695 #define ACCEPT(s, a, l) accept(s, a, l) 802 #define ACCEPT(s, a, l) accept (s, a, l)
696 #define BIND(s, n, l) bind(s, n, l) 803 #define BIND(s, n, l) bind (s, n, l)
697 #define CONNECT(s, n, l) connect(s, n, l) 804 #define CONNECT(s, n, l) connect (s, n, l)
698 #define GETPEERNAME(s, n, l) getpeername(s, n, l) 805 #define GETPEERNAME(s, n, l) getpeername (s, n, l)
699 #define GETSOCKNAME(s, n, l) getsockname(s, n, l) 806 #define GETSOCKNAME(s, n, l) getsockname (s, n, l)
700 #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p) 807 #define GETSOCKOPT(s, l, o, v, p) getsockopt (s, l, o, v, p)
701 #define LISTEN(s, b) listen(s, b) 808 #define LISTEN(s, b) listen (s, b)
702 #define RECV(s, b, l, f) recv(s, b, l, f) 809 #define RECV(s, b, l, f) recv (s, b, l, f)
703 #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o) 810 #define RECVFROM(s, b, l, f, r, o) recvfrom (s, b, l, f, r, o)
704 #define SELECT(n, r, w, e, t) select(n, r, w, e, t) 811 #define SELECT(n, r, w, e, t) select (n, r, w, e, t)
705 #define SEND(s, b, l, f) send(s, b, l, f) 812 #define SEND(s, b, l, f) send (s, b, l, f)
706 #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n) 813 #define SENDTO(s, b, l, f, o, n) sendto (s, b, l, f, o, n)
707 #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n) 814 #define SETSOCKOPT(s, l, o, v, n) setsockopt (s, l, o, v, n)
708 #define SHUTDOWN(s, h) shutdown(s, h) 815 #define SHUTDOWN(s, h) shutdown (s, h)
709 #define SOCKET(a, t, p) socket(a, t, p) 816 #define SOCKET(a, t, p) socket (a, t, p)
710 #define SOCKETPAIR(a, t, p, v) socketpair(a, t, p, v) 817 #define SOCKETPAIR(a, t, p, v) socketpair (a, t, p, v)
711 #define GETHOSTBYADDR(a, l, t) gethostbyaddr(a, l, t) 818 #define GETHOSTBYADDR(a, l, t) gethostbyaddr (a, l, t)
712 #define GETHOSTBYNAME(n) gethostbyname(n) 819 #define GETHOSTBYNAME(n) gethostbyname (n)
713 #define GETTIMEOFDAY(t, n) gettimeofday(t, n) 820 #define GETTIMEOFDAY(t, n) gettimeofday (t, n)
714 #define INSQUE(e, p) insque(e, p) 821 #define INSQUE(e, p) insque (e, p)
715 #define REMQUE(e) remque(e) 822 #define REMQUE(e) remque (e)
716 #define HSEARCH(i, a) hsearch(i, a) 823 #define HSEARCH(i, a) hsearch (i, a)
717 #define HCREATE(n) hcreate(n) 824 #define HCREATE(n) hcreate (n)
718 #define HDESTROY() hdestroy() 825 #define HDESTROY() hdestroy ()
719 #define HSEARCH_R(i, a, r, h) hsearch_r(i, a, r, h) 826 #define HSEARCH_R(i, a, r, h) hsearch_r (i, a, r, h)
720 #define HCREATE_R(n, h) hcreate_r(n, h) 827 #define HCREATE_R(n, h) hcreate_r (n, h)
721 #define HDESTROY_R(h) hdestroy_r(h) 828 #define HDESTROY_R(h) hdestroy_r (h)
722 #define TSEARCH(k, r, c) tsearch(k, r, c) 829 #define TSEARCH(k, r, c) tsearch (k, r, c)
723 #define TFIND(k, r, c) tfind(k, r, c) 830 #define TFIND(k, r, c) tfind (k, r, c)
724 #define TDELETE(k, r, c) tdelete(k, r, c) 831 #define TDELETE(k, r, c) tdelete (k, r, c)
725 #define TWALK(r, a) twalk(r, a) 832 #define TWALK(r, a) twalk (r, a)
726 #define TDESTROY(r, f) tdestroy(r, f) 833 #define TDESTROY(r, f) tdestroy (r, f)
727 #define LFIND(k, b, n, s, c) lfind(k, b, n, s, c) 834 #define LFIND(k, b, n, s, c) lfind (k, b, n, s, c)
728 #define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c) 835 #define LSEARCH(k, b, n, s, c) lsearch (k, b, n, s, c)
729 #define STRUCT_STAT64 struct stat64 836 #define STRUCT_STAT64 struct stat64
730#else 837#else
731 #define DIR_SEPARATOR '\\' 838 #define DIR_SEPARATOR '\\'
@@ -735,98 +842,98 @@ char *strcasestr(const char *haystack_start, const char *needle_start);
735 #define NEWLINE "\r\n" 842 #define NEWLINE "\r\n"
736 843
737#ifdef ENABLE_NLS 844#ifdef ENABLE_NLS
738 #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n) 845 #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain (d, n)
739#endif 846#endif
740 #define CREAT(p, m) _win_creat(p, m) 847 #define CREAT(p, m) _win_creat (p, m)
741 #define PLIBC_CTIME(c) _win_ctime(c) 848 #define PLIBC_CTIME(c) _win_ctime (c)
742 #define CTIME_R(c, b) _win_ctime_r(c, b) 849 #define CTIME_R(c, b) _win_ctime_r (c, b)
743 #define FOPEN(f, m) _win_fopen(f, m) 850 #define FOPEN(f, m) _win_fopen (f, m)
744 #define FCLOSE(f) _win_fclose(f) 851 #define FCLOSE(f) _win_fclose (f)
745 #define FTRUNCATE(f, l) _win_ftruncate(f, l) 852 #define FTRUNCATE(f, l) _win_ftruncate (f, l)
746 #define TRUNCATE(f, l) _win_truncate(f, l) 853 #define TRUNCATE(f, l) _win_truncate (f, l)
747 #define OPENDIR(d) _win_opendir(d) 854 #define OPENDIR(d) _win_opendir (d)
748 #define CLOSEDIR(d) _win_closedir(d) 855 #define CLOSEDIR(d) _win_closedir (d)
749 #define READDIR(d) _win_readdir(d) 856 #define READDIR(d) _win_readdir (d)
750 #define OPEN _win_open 857 #define OPEN _win_open
751 #define CHDIR(d) _win_chdir(d) 858 #define CHDIR(d) _win_chdir (d)
752 #define CLOSE(f) _win_close(f) 859 #define CLOSE(f) _win_close (f)
753 #define PLIBC_KILL(p, s) _win_kill(p, s) 860 #define PLIBC_KILL(p, s) _win_kill (p, s)
754 #define LSEEK(f, o, w) lseek(f, o, w) 861 #define LSEEK(f, o, w) lseek (f, o, w)
755 #define FSTAT(h, b) _win_fstat(h, b) 862 #define FSTAT(h, b) _win_fstat (h, b)
756 #define RMDIR(f) _win_rmdir(f) 863 #define RMDIR(f) _win_rmdir (f)
757 #define ACCESS(p, m) _win_access(p, m) 864 #define ACCESS(p, m) _win_access (p, m)
758 #define CHMOD(f, p) _win_chmod(f, p) 865 #define CHMOD(f, p) _win_chmod (f, p)
759 #define PIPE(h) _win_pipe(h) 866 #define PIPE(h) _win_pipe (h)
760 #define RANDOM() _win_random() 867 #define RANDOM() _win_random ()
761 #define SRANDOM(s) _win_srandom(s) 868 #define SRANDOM(s) _win_srandom (s)
762 #define REMOVE(p) _win_remove(p) 869 #define REMOVE(p) _win_remove (p)
763 #define RENAME(o, n) _win_rename(o, n) 870 #define RENAME(o, n) _win_rename (o, n)
764 #define STAT(p, b) _win_stat(p, b) 871 #define STAT(p, b) _win_stat (p, b)
765 #define STAT64(p, b) _win_stati64(p, b) 872 #define STAT64(p, b) _win_stati64 (p, b)
766 #define SYSCONF(n) _win_sysconf(n) 873 #define SYSCONF(n) _win_sysconf (n)
767 #define UNLINK(f) _win_unlink(f) 874 #define UNLINK(f) _win_unlink (f)
768 #define WRITE(f, b, n) _win_write(f, b, n) 875 #define WRITE(f, b, n) _win_write (f, b, n)
769 #define READ(f, b, n) _win_read(f, b, n) 876 #define READ(f, b, n) _win_read (f, b, n)
770 #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f) 877 #define GN_FREAD(b, s, c, f) _win_fread (b, s, c, f)
771 #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f) 878 #define GN_FWRITE(b, s, c, f) _win_fwrite (b, s, c, f)
772 #define SYMLINK(a, b) _win_symlink(a, b) 879 #define SYMLINK(a, b) _win_symlink (a, b)
773 #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o) 880 #define MMAP(s, l, p, f, d, o) _win_mmap (s, l, p, f, d, o)
774 #define MKFIFO(p, m) _win_mkfifo(p, m) 881 #define MKFIFO(p, m) _win_mkfifo (p, m)
775 #define MSYNC(s, l, f) _win_msync(s, l, f) 882 #define MSYNC(s, l, f) _win_msync (s, l, f)
776 #define MUNMAP(s, l) _win_munmap(s, l) 883 #define MUNMAP(s, l) _win_munmap (s, l)
777 #define STRERROR(i) _win_strerror(i) 884 #define STRERROR(i) _win_strerror (i)
778 #define READLINK(p, b, s) _win_readlink(p, b, s) 885 #define READLINK(p, b, s) _win_readlink (p, b, s)
779 #define LSTAT(p, b) _win_lstat(p, b) 886 #define LSTAT(p, b) _win_lstat (p, b)
780 #define LSTAT64(p, b) _win_lstati64(p, b) 887 #define LSTAT64(p, b) _win_lstati64 (p, b)
781 #define PRINTF printf 888 #define PRINTF printf
782 #define FPRINTF fprintf 889 #define FPRINTF fprintf
783 #define VPRINTF(f, a) vprintf(f, a) 890 #define VPRINTF(f, a) vprintf (f, a)
784 #define VFPRINTF(s, f, a) vfprintf(s, f, a) 891 #define VFPRINTF(s, f, a) vfprintf (s, f, a)
785 #define VSPRINTF(d, f, a) vsprintf(d, f, a) 892 #define VSPRINTF(d, f, a) vsprintf (d, f, a)
786 #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a) 893 #define VSNPRINTF(str, size, fmt, a) vsnprintf (str, size, fmt, a)
787 #define _REAL_SNPRINTF snprintf 894 #define _REAL_SNPRINTF snprintf
788 #define SPRINTF sprintf 895 #define SPRINTF sprintf
789 #define VSSCANF(s, f, a) vsscanf(s, f, a) 896 #define VSSCANF(s, f, a) vsscanf (s, f, a)
790 #define SSCANF sscanf 897 #define SSCANF sscanf
791 #define VFSCANF(s, f, a) vfscanf(s, f, a) 898 #define VFSCANF(s, f, a) vfscanf (s, f, a)
792 #define VSCANF(f, a) vscanf(f, a) 899 #define VSCANF(f, a) vscanf (f, a)
793 #define SCANF scanf 900 #define SCANF scanf
794 #define FSCANF fscanf 901 #define FSCANF fscanf
795 #define WAITPID(p, s, o) _win_waitpid(p, s, o) 902 #define WAITPID(p, s, o) _win_waitpid (p, s, o)
796 #define ACCEPT(s, a, l) _win_accept(s, a, l) 903 #define ACCEPT(s, a, l) _win_accept (s, a, l)
797 #define BIND(s, n, l) _win_bind(s, n, l) 904 #define BIND(s, n, l) _win_bind (s, n, l)
798 #define CONNECT(s, n, l) _win_connect(s, n, l) 905 #define CONNECT(s, n, l) _win_connect (s, n, l)
799 #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l) 906 #define GETPEERNAME(s, n, l) _win_getpeername (s, n, l)
800 #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l) 907 #define GETSOCKNAME(s, n, l) _win_getsockname (s, n, l)
801 #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p) 908 #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt (s, l, o, v, p)
802 #define LISTEN(s, b) _win_listen(s, b) 909 #define LISTEN(s, b) _win_listen (s, b)
803 #define RECV(s, b, l, f) _win_recv(s, b, l, f) 910 #define RECV(s, b, l, f) _win_recv (s, b, l, f)
804 #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o) 911 #define RECVFROM(s, b, l, f, r, o) _win_recvfrom (s, b, l, f, r, o)
805 #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t) 912 #define SELECT(n, r, w, e, t) _win_select (n, r, w, e, t)
806 #define SEND(s, b, l, f) _win_send(s, b, l, f) 913 #define SEND(s, b, l, f) _win_send (s, b, l, f)
807 #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n) 914 #define SENDTO(s, b, l, f, o, n) _win_sendto (s, b, l, f, o, n)
808 #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n) 915 #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt (s, l, o, v, n)
809 #define SHUTDOWN(s, h) _win_shutdown(s, h) 916 #define SHUTDOWN(s, h) _win_shutdown (s, h)
810 #define SOCKET(a, t, p) _win_socket(a, t, p) 917 #define SOCKET(a, t, p) _win_socket (a, t, p)
811 #define SOCKETPAIR(a, t, p, v) _win_socketpair(a, t, p, v) 918 #define SOCKETPAIR(a, t, p, v) _win_socketpair (a, t, p, v)
812 #define GETHOSTBYADDR(a, l, t) _win_gethostbyaddr(a, l, t) 919 #define GETHOSTBYADDR(a, l, t) _win_gethostbyaddr (a, l, t)
813 #define GETHOSTBYNAME(n) _win_gethostbyname(n) 920 #define GETHOSTBYNAME(n) _win_gethostbyname (n)
814 #define GETTIMEOFDAY(t, n) gettimeofday(t, n) 921 #define GETTIMEOFDAY(t, n) gettimeofday (t, n)
815 #define INSQUE(e, p) _win_insque(e, p) 922 #define INSQUE(e, p) _win_insque (e, p)
816 #define REMQUE(e) _win_remque(e) 923 #define REMQUE(e) _win_remque (e)
817 #define HSEARCH(i, a) _win_hsearch(i, a) 924 #define HSEARCH(i, a) _win_hsearch (i, a)
818 #define HCREATE(n) _win_hcreate(n) 925 #define HCREATE(n) _win_hcreate (n)
819 #define HDESTROY() _win_hdestroy() 926 #define HDESTROY() _win_hdestroy ()
820 #define HSEARCH_R(i, a, r, h) _win_hsearch_r(i, a, r, h) 927 #define HSEARCH_R(i, a, r, h) _win_hsearch_r (i, a, r, h)
821 #define HCREATE_R(n, h) _win_hcreate_r(n, h) 928 #define HCREATE_R(n, h) _win_hcreate_r (n, h)
822 #define HDESTROY_R(h) _win_hdestroy_r(h) 929 #define HDESTROY_R(h) _win_hdestroy_r (h)
823 #define TSEARCH(k, r, c) _win_tsearch(k, r, c) 930 #define TSEARCH(k, r, c) _win_tsearch (k, r, c)
824 #define TFIND(k, r, c) _win_tfind(k, r, c) 931 #define TFIND(k, r, c) _win_tfind (k, r, c)
825 #define TDELETE(k, r, c) _win_tdelete(k, r, c) 932 #define TDELETE(k, r, c) _win_tdelete (k, r, c)
826 #define TWALK(r, a) _win_twalk(r, a) 933 #define TWALK(r, a) _win_twalk (r, a)
827 #define TDESTROY(r, f) _win_tdestroy(r, f) 934 #define TDESTROY(r, f) _win_tdestroy (r, f)
828 #define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c) 935 #define LFIND(k, b, n, s, c) _win_lfind (k, b, n, s, c)
829 #define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c) 936 #define LSEARCH(k, b, n, s, c) _win_lsearch (k, b, n, s, c)
830 #define STRUCT_STAT64 struct _stati64 937 #define STRUCT_STAT64 struct _stati64
831#endif 938#endif
832 939
@@ -836,11 +943,11 @@ char *strcasestr(const char *haystack_start, const char *needle_start);
836 This is the type used by the `insque' and `remque' functions. */ 943 This is the type used by the `insque' and `remque' functions. */
837 944
838struct PLIBC_SEARCH_QELEM 945struct PLIBC_SEARCH_QELEM
839 { 946{
840 struct qelem *q_forw; 947 struct qelem *q_forw;
841 struct qelem *q_back; 948 struct qelem *q_back;
842 char q_data[1]; 949 char q_data[1];
843 }; 950};
844 951
845 952
846/* Insert ELEM into a doubly-linked list, after PREV. */ 953/* Insert ELEM into a doubly-linked list, after PREV. */
@@ -857,17 +964,17 @@ typedef PLIBC_SEARCH__compar_fn_t _win_comparison_fn_t;
857 964
858/* Action which shall be performed in the call the hsearch. */ 965/* Action which shall be performed in the call the hsearch. */
859typedef enum 966typedef enum
860 { 967{
861 PLIBC_SEARCH_FIND, 968 PLIBC_SEARCH_FIND,
862 PLIBC_SEARCH_ENTER 969 PLIBC_SEARCH_ENTER
863 } 970}
864PLIBC_SEARCH_ACTION; 971PLIBC_SEARCH_ACTION;
865 972
866typedef struct PLIBC_SEARCH_entry 973typedef struct PLIBC_SEARCH_entry
867 { 974{
868 char *key; 975 char *key;
869 void *data; 976 void *data;
870 } 977}
871PLIBC_SEARCH_ENTRY; 978PLIBC_SEARCH_ENTRY;
872 979
873/* The reentrant version has no static variables to maintain the state. 980/* The reentrant version has no static variables to maintain the state.
@@ -889,7 +996,8 @@ _PLIBC_SEARCH_ENTRY;
889 ACTION is `FIND' return found entry or signal error by returning 996 ACTION is `FIND' return found entry or signal error by returning
890 NULL. If ACTION is `ENTER' replace existing data (if any) with 997 NULL. If ACTION is `ENTER' replace existing data (if any) with
891 ITEM.data. */ 998 ITEM.data. */
892PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action); 999PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION
1000 __action);
893 1001
894/* Create a new hashing table which will at most contain NEL elements. */ 1002/* Create a new hashing table which will at most contain NEL elements. */
895int _win_hcreate (size_t __nel); 1003int _win_hcreate (size_t __nel);
@@ -899,17 +1007,20 @@ void _win_hdestroy (void);
899 1007
900/* Data type for reentrant functions. */ 1008/* Data type for reentrant functions. */
901struct PLIBC_SEARCH_hsearch_data 1009struct PLIBC_SEARCH_hsearch_data
902 { 1010{
903 struct _PLIBC_SEARCH_ENTRY *table; 1011 struct _PLIBC_SEARCH_ENTRY *table;
904 unsigned int size; 1012 unsigned int size;
905 unsigned int filled; 1013 unsigned int filled;
906 }; 1014};
907 1015
908/* Reentrant versions which can handle multiple hashing tables at the 1016/* Reentrant versions which can handle multiple hashing tables at the
909 same time. */ 1017 same time. */
910int _win_hsearch_r (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action, PLIBC_SEARCH_ENTRY **__retval, 1018int _win_hsearch_r (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action,
911 struct PLIBC_SEARCH_hsearch_data *__htab); 1019 PLIBC_SEARCH_ENTRY **__retval,
1020 struct PLIBC_SEARCH_hsearch_data *__htab);
1021
912int _win_hcreate_r (size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab); 1022int _win_hcreate_r (size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab);
1023
913void _win_hdestroy_r (struct PLIBC_SEARCH_hsearch_data *__htab); 1024void _win_hdestroy_r (struct PLIBC_SEARCH_hsearch_data *__htab);
914 1025
915 1026
@@ -930,20 +1041,21 @@ PLIBC_SEARCH_VISIT;
930/* Search for an entry matching the given KEY in the tree pointed to 1041/* Search for an entry matching the given KEY in the tree pointed to
931 by *ROOTP and insert a new element if not found. */ 1042 by *ROOTP and insert a new element if not found. */
932void *_win_tsearch (__const void *__key, void **__rootp, 1043void *_win_tsearch (__const void *__key, void **__rootp,
933 PLIBC_SEARCH__compar_fn_t __compar); 1044 PLIBC_SEARCH__compar_fn_t __compar);
934 1045
935/* Search for an entry matching the given KEY in the tree pointed to 1046/* Search for an entry matching the given KEY in the tree pointed to
936 by *ROOTP. If no matching entry is available return NULL. */ 1047 by *ROOTP. If no matching entry is available return NULL. */
937void *_win_tfind (__const void *__key, void *__const *__rootp, 1048void *_win_tfind (__const void *__key, void *__const *__rootp,
938 PLIBC_SEARCH__compar_fn_t __compar); 1049 PLIBC_SEARCH__compar_fn_t __compar);
939 1050
940/* Remove the element matching KEY from the tree pointed to by *ROOTP. */ 1051/* Remove the element matching KEY from the tree pointed to by *ROOTP. */
941void *_win_tdelete (__const void *__restrict __key, 1052void *_win_tdelete (__const void *__restrict __key,
942 void **__restrict __rootp, 1053 void **__restrict __rootp,
943 PLIBC_SEARCH__compar_fn_t __compar); 1054 PLIBC_SEARCH__compar_fn_t __compar);
944 1055
945typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep, PLIBC_SEARCH_VISIT __value, 1056typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep,
946 int __level); 1057 PLIBC_SEARCH_VISIT __value,
1058 int __level);
947 1059
948/* Walk through the whole tree and call the ACTION callback for every node 1060/* Walk through the whole tree and call the ACTION callback for every node
949 or leaf. */ 1061 or leaf. */
@@ -960,12 +1072,14 @@ void _win_tdestroy (void *__root, PLIBC_SEARCH__free_fn_t __freefct);
960/* Perform linear search for KEY by comparing by COMPAR in an array 1072/* Perform linear search for KEY by comparing by COMPAR in an array
961 [BASE,BASE+NMEMB*SIZE). */ 1073 [BASE,BASE+NMEMB*SIZE). */
962void *_win_lfind (__const void *__key, __const void *__base, 1074void *_win_lfind (__const void *__key, __const void *__base,
963 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar); 1075 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t
1076 __compar);
964 1077
965/* Perform linear search for KEY by comparing by COMPAR function in 1078/* Perform linear search for KEY by comparing by COMPAR function in
966 array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */ 1079 array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */
967void *_win_lsearch (__const void *__key, void *__base, 1080void *_win_lsearch (__const void *__key, void *__base,
968 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar); 1081 size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t
1082 __compar);
969 1083
970 1084
971#ifdef __cplusplus 1085#ifdef __cplusplus
@@ -973,6 +1087,6 @@ void *_win_lsearch (__const void *__key, void *__base,
973#endif 1087#endif
974 1088
975 1089
976#endif //_PLIBC_H_ 1090#endif // _PLIBC_H_
977 1091
978/* end of plibc.h */ 1092/* end of plibc.h */
diff --git a/src/intlemu/intlemu.c b/src/intlemu/intlemu.c
index a8461b7..eaa9252 100644
--- a/src/intlemu/intlemu.c
+++ b/src/intlemu/intlemu.c
@@ -15,132 +15,145 @@
15static pthread_mutex_t intlemu_lock; 15static pthread_mutex_t intlemu_lock;
16static CFMutableDictionaryRef intlemu_dict; 16static CFMutableDictionaryRef intlemu_dict;
17 17
18static void intlemu_cstring_release(CFAllocatorRef allocator, const void *value) 18static void
19intlemu_cstring_release (CFAllocatorRef allocator, const void *value)
19{ 20{
20 free((void *)value); 21 free ((void *) value);
21} 22}
22 23
23void __attribute__ ((constructor)) intlemu_init_() {
24 CFDictionaryValueCallBacks cstring_value_callbacks =
25 {
26 0, /* version */
27 NULL, /* retain callback */
28 &intlemu_cstring_release, /* release callback */
29 NULL, /* copy description */
30 NULL /* equal */
31 };
32 if (pthread_mutex_init(&intlemu_lock, NULL) != 0)
33 abort();
34
35 intlemu_dict = CFDictionaryCreateMutable(
36 kCFAllocatorDefault,
37 0,
38 &kCFCopyStringDictionaryKeyCallBacks,
39 &cstring_value_callbacks);
40 if (intlemu_dict == NULL)
41 abort();
42}
43 24
44void __attribute__ ((destructor)) intlemu_fini_() { 25void __attribute__ ((constructor))
45 if (intlemu_dict) 26intlemu_init_ ()
46 CFRelease(intlemu_dict); 27{
28 CFDictionaryValueCallBacks cstring_value_callbacks = {
29 0, /* version */
30 NULL, /* retain callback */
31 &intlemu_cstring_release, /* release callback */
32 NULL, /* copy description */
33 NULL /* equal */
34 };
35 if (pthread_mutex_init (&intlemu_lock, NULL) != 0)
36 abort ();
47 37
48 pthread_mutex_destroy(&intlemu_lock); 38 intlemu_dict = CFDictionaryCreateMutable (
39 kCFAllocatorDefault,
40 0,
41 &kCFCopyStringDictionaryKeyCallBacks,
42 &cstring_value_callbacks);
43 if (intlemu_dict == NULL)
44 abort ();
49} 45}
50 46
51char * intlemu_bgettext (CFBundleRef bundle, const char *msgid) 47
48void __attribute__ ((destructor))
49intlemu_fini_ ()
52{ 50{
53 CFStringRef key; 51 if (intlemu_dict)
54 const char *value; 52 CFRelease (intlemu_dict);
55 CFStringRef s; 53
56 CFRange r; 54 pthread_mutex_destroy (&intlemu_lock);
57 CFIndex len;
58 CFIndex clen;
59 char *buf;
60
61 if (msgid == NULL)
62 return NULL;
63 if (bundle == NULL)
64 return msgid;
65
66 key = CFStringCreateWithBytes(
67 kCFAllocatorDefault,
68 (const UInt8 *)msgid,
69 (CFIndex)strlen(msgid),
70 kCFStringEncodingUTF8,
71 false);
72
73 if (pthread_mutex_lock(&intlemu_lock) != 0)
74 abort();
75 value = (char *)CFDictionaryGetValue(intlemu_dict, key);
76 if (pthread_mutex_unlock(&intlemu_lock) != 0)
77 abort();
78 if (value != NULL) {
79 CFRelease(key);
80 return (char *)value;
81 }
82
83 /* no cached translaation, so, find one from the bundle */
84 s = CFBundleCopyLocalizedString(
85 bundle,
86 key,
87 NULL,
88 NULL);
89 if (s == key) {
90 CFRelease(key);
91 return (char *)msgid;
92 }
93 /* get the length in bytes */
94 r.location = 0;
95 r.length = CFStringGetLength(s);
96 len = 0;
97 clen = CFStringGetBytes(
98 s,
99 r,
100 kCFStringEncodingUTF8,
101 0,
102 false,
103 NULL,
104 0,
105 &len);
106 buf = NULL;
107 if (clen == r.length) {
108 buf = malloc(len + 1);
109 }
110
111 if (buf == NULL) {
112 CFRelease(s);
113 CFRelease(key);
114 return (char *)msgid;
115 }
116
117 clen = CFStringGetBytes(
118 s,
119 r,
120 kCFStringEncodingUTF8,
121 0,
122 false,
123 (UInt8 *)buf,
124 len,
125 &len);
126 buf[len] = '\0';
127 if (clen == r.length) {
128 if (pthread_mutex_lock(&intlemu_lock) != 0)
129 abort();
130 CFDictionaryAddValue(intlemu_dict, key, buf);
131 if (pthread_mutex_unlock(&intlemu_lock) != 0)
132 abort();
133 value = buf;
134 }
135 else {
136 free(buf);
137 value = msgid;
138 }
139
140 CFRelease(s);
141
142 CFRelease(key);
143
144 return (char *)value;
145} 55}
146 56
57
58char *
59intlemu_bgettext (CFBundleRef bundle, const char *msgid)
60{
61 CFStringRef key;
62 const char *value;
63 CFStringRef s;
64 CFRange r;
65 CFIndex len;
66 CFIndex clen;
67 char *buf;
68
69 if (msgid == NULL)
70 return NULL;
71 if (bundle == NULL)
72 return msgid;
73
74 key = CFStringCreateWithBytes (
75 kCFAllocatorDefault,
76 (const UInt8 *) msgid,
77 (CFIndex) strlen (msgid),
78 kCFStringEncodingUTF8,
79 false);
80
81 if (pthread_mutex_lock (&intlemu_lock) != 0)
82 abort ();
83 value = (char *) CFDictionaryGetValue (intlemu_dict, key);
84 if (pthread_mutex_unlock (&intlemu_lock) != 0)
85 abort ();
86 if (value != NULL)
87 {
88 CFRelease (key);
89 return (char *) value;
90 }
91
92 /* no cached translaation, so, find one from the bundle */
93 s = CFBundleCopyLocalizedString (
94 bundle,
95 key,
96 NULL,
97 NULL);
98 if (s == key)
99 {
100 CFRelease (key);
101 return (char *) msgid;
102 }
103 /* get the length in bytes */
104 r.location = 0;
105 r.length = CFStringGetLength (s);
106 len = 0;
107 clen = CFStringGetBytes (
108 s,
109 r,
110 kCFStringEncodingUTF8,
111 0,
112 false,
113 NULL,
114 0,
115 &len);
116 buf = NULL;
117 if (clen == r.length)
118 {
119 buf = malloc (len + 1);
120 }
121
122 if (buf == NULL)
123 {
124 CFRelease (s);
125 CFRelease (key);
126 return (char *) msgid;
127 }
128
129 clen = CFStringGetBytes (
130 s,
131 r,
132 kCFStringEncodingUTF8,
133 0,
134 false,
135 (UInt8 *) buf,
136 len,
137 &len);
138 buf[len] = '\0';
139 if (clen == r.length)
140 {
141 if (pthread_mutex_lock (&intlemu_lock) != 0)
142 abort ();
143 CFDictionaryAddValue (intlemu_dict, key, buf);
144 if (pthread_mutex_unlock (&intlemu_lock) != 0)
145 abort ();
146 value = buf;
147 }
148 else
149 {
150 free (buf);
151 value = msgid;
152 }
153
154 CFRelease (s);
155
156 CFRelease (key);
157
158 return (char *) value;
159}
diff --git a/src/intlemu/libintlemu.h b/src/intlemu/libintlemu.h
index 6118a66..27a295e 100644
--- a/src/intlemu/libintlemu.h
+++ b/src/intlemu/libintlemu.h
@@ -14,13 +14,13 @@
14#include <CoreFoundation/CoreFoundation.h> 14#include <CoreFoundation/CoreFoundation.h>
15 15
16#define gettext(msgid) \ 16#define gettext(msgid) \
17 intlemu_bgettext(CFBundleGetMainBundle(), msgid) 17 intlemu_bgettext (CFBundleGetMainBundle (), msgid)
18 18
19#define dgettext(domainname, msgid) \ 19#define dgettext(domainname, msgid) \
20 intlemu_bgettext(CFBundleGetBundleWithIdentifier(CFSTR(domainname)), msgid) 20 intlemu_bgettext (CFBundleGetBundleWithIdentifier (CFSTR (domainname)), msgid)
21 21
22#define gettext_noop(s) s 22#define gettext_noop(s) s
23 23
24extern char * intlemu_bgettext (CFBundleRef bundle, const char *msgid); 24extern char *intlemu_bgettext (CFBundleRef bundle, const char *msgid);
25 25
26#endif 26#endif
diff --git a/src/main/extract.c b/src/main/extract.c
index 2492fa9..144f2c3 100644
--- a/src/main/extract.c
+++ b/src/main/extract.c
@@ -73,6 +73,8 @@ ignore_sigpipe ()
73 FPRINTF (stderr, 73 FPRINTF (stderr,
74 "Failed to install SIGPIPE handler: %s\n", strerror (errno)); 74 "Failed to install SIGPIPE handler: %s\n", strerror (errno));
75} 75}
76
77
76#endif 78#endif
77 79
78 80
@@ -89,17 +91,17 @@ struct Help
89 /** 91 /**
90 * Long name of the option. 92 * Long name of the option.
91 */ 93 */
92 const char * longArg; 94 const char *longArg;
93 95
94 /** 96 /**
95 * Name of the mandatory argument, NULL for no argument. 97 * Name of the mandatory argument, NULL for no argument.
96 */ 98 */
97 const char * mandatoryArg; 99 const char *mandatoryArg;
98 100
99 /** 101 /**
100 * Help text for the option. 102 * Help text for the option.
101 */ 103 */
102 const char * description; 104 const char *description;
103}; 105};
104 106
105 107
@@ -118,8 +120,8 @@ struct Help
118 */ 120 */
119static void 121static void
120format_help (const char *general, 122format_help (const char *general,
121 const char *description, 123 const char *description,
122 const struct Help *opt) 124 const struct Help *opt)
123{ 125{
124 size_t slen; 126 size_t slen;
125 unsigned int i; 127 unsigned int i;
@@ -129,79 +131,80 @@ format_help (const char *general,
129 char scp[80]; 131 char scp[80];
130 const char *trans; 132 const char *trans;
131 133
132 printf (_("Usage: %s\n%s\n\n"), 134 printf (_ ("Usage: %s\n%s\n\n"),
133 gettext(general), 135 gettext (general),
134 gettext(description)); 136 gettext (description));
135 printf (_("Arguments mandatory for long options are also mandatory for short options.\n")); 137 printf (_ (
138 "Arguments mandatory for long options are also mandatory for short options.\n"));
136 slen = 0; 139 slen = 0;
137 i = 0; 140 i = 0;
138 while (NULL != opt[i].description) 141 while (NULL != opt[i].description)
142 {
143 if (0 == opt[i].shortArg)
144 printf (" ");
145 else
146 printf (" -%c, ",
147 opt[i].shortArg);
148 printf ("--%s",
149 opt[i].longArg);
150 slen = 8 + strlen (opt[i].longArg);
151 if (NULL != opt[i].mandatoryArg)
139 { 152 {
140 if (0 == opt[i].shortArg) 153 printf ("=%s",
141 printf (" "); 154 opt[i].mandatoryArg);
142 else 155 slen += 1 + strlen (opt[i].mandatoryArg);
143 printf (" -%c, ", 156 }
144 opt[i].shortArg); 157 if (slen > BORDER)
145 printf ("--%s", 158 {
146 opt[i].longArg); 159 printf ("\n%*s", BORDER, "");
147 slen = 8 + strlen(opt[i].longArg); 160 slen = BORDER;
148 if (NULL != opt[i].mandatoryArg) 161 }
149 { 162 if (slen < BORDER)
150 printf ("=%s", 163 {
151 opt[i].mandatoryArg); 164 printf ("%*s", (int) (BORDER - slen), "");
152 slen += 1+strlen(opt[i].mandatoryArg); 165 slen = BORDER;
153 } 166 }
154 if (slen > BORDER) 167 trans = gettext (opt[i].description);
155 { 168 ml = strlen (trans);
156 printf ("\n%*s", BORDER, ""); 169 p = 0;
157 slen = BORDER; 170OUTER:
158 } 171 while (ml - p > 78 - slen)
159 if (slen < BORDER) 172 {
160 { 173 for (j = p + 78 - slen; j>p; j--)
161 printf ("%*s", (int) (BORDER - slen), ""); 174 {
162 slen = BORDER; 175 if (isspace ( (unsigned char) trans[j]))
163 } 176 {
164 trans = gettext(opt[i].description); 177 memcpy (scp,
165 ml = strlen(trans); 178 &trans[p],
166 p = 0; 179 j - p);
167 OUTER: 180 scp[j - p] = '\0';
168 while (ml - p > 78 - slen) 181 printf ("%s\n%*s",
169 { 182 scp,
170 for (j=p+78-slen;j>p;j--) 183 BORDER + 2,
171 { 184 "");
172 if (isspace( (unsigned char) trans[j])) 185 p = j + 1;
173 { 186 slen = BORDER + 2;
174 memcpy(scp, 187 goto OUTER;
175 &trans[p], 188 }
176 j-p); 189 }
177 scp[j-p] = '\0'; 190 /* could not find space to break line */
178 printf ("%s\n%*s", 191 memcpy (scp,
179 scp, 192 &trans[p],
180 BORDER + 2, 193 78 - slen);
181 ""); 194 scp[78 - slen] = '\0';
182 p = j+1; 195 printf ("%s\n%*s",
183 slen = BORDER + 2; 196 scp,
184 goto OUTER; 197 BORDER + 2,
185 } 198 "");
186 } 199 slen = BORDER + 2;
187 /* could not find space to break line */ 200 p = p + 78 - slen;
188 memcpy (scp,
189 &trans[p],
190 78 - slen);
191 scp[78 - slen] = '\0';
192 printf ("%s\n%*s",
193 scp,
194 BORDER+2,
195 "");
196 slen = BORDER+2;
197 p = p + 78 - slen;
198 }
199 /* print rest */
200 if (p < ml)
201 printf("%s\n",
202 &trans[p]);
203 i++;
204 } 201 }
202 /* print rest */
203 if (p < ml)
204 printf ("%s\n",
205 &trans[p]);
206 i++;
207 }
205} 208}
206 209
207 210
@@ -211,40 +214,43 @@ format_help (const char *general,
211static void 214static void
212print_help () 215print_help ()
213{ 216{
214 static struct Help help[] = 217 static struct Help help[] = {
215 { 218 { 'b', "bibtex", NULL,
216 { 'b', "bibtex", NULL, 219 gettext_noop ("print output in bibtex format") },
217 gettext_noop("print output in bibtex format") }, 220 { 'g', "grep-friendly", NULL,
218 { 'g', "grep-friendly", NULL, 221 gettext_noop (
219 gettext_noop("produce grep-friendly output (all results on one line per file)") }, 222 "produce grep-friendly output (all results on one line per file)") },
220 { 'h', "help", NULL, 223 { 'h', "help", NULL,
221 gettext_noop("print this help") }, 224 gettext_noop ("print this help") },
222 { 'i', "in-process", NULL, 225 { 'i', "in-process", NULL,
223 gettext_noop("run plugins in-process (simplifies debugging)") }, 226 gettext_noop ("run plugins in-process (simplifies debugging)") },
224 { 'm', "from-memory", NULL, 227 { 'm', "from-memory", NULL,
225 gettext_noop("read data from file into memory and extract from memory") }, 228 gettext_noop (
226 { 'l', "library", "LIBRARY", 229 "read data from file into memory and extract from memory") },
227 gettext_noop("load an extractor plugin named LIBRARY") }, 230 { 'l', "library", "LIBRARY",
228 { 'L', "list", NULL, 231 gettext_noop ("load an extractor plugin named LIBRARY") },
229 gettext_noop("list all keyword types") }, 232 { 'L', "list", NULL,
230 { 'n', "nodefault", NULL, 233 gettext_noop ("list all keyword types") },
231 gettext_noop("do not use the default set of extractor plugins") }, 234 { 'n', "nodefault", NULL,
232 { 'p', "print", "TYPE", 235 gettext_noop ("do not use the default set of extractor plugins") },
233 gettext_noop("print only keywords of the given TYPE (use -L to get a list)") }, 236 { 'p', "print", "TYPE",
234 { 'v', "version", NULL, 237 gettext_noop (
235 gettext_noop("print the version number") }, 238 "print only keywords of the given TYPE (use -L to get a list)") },
236 { 'V', "verbose", NULL, 239 { 'v', "version", NULL,
237 gettext_noop("be verbose") }, 240 gettext_noop ("print the version number") },
238 { 'x', "exclude", "TYPE", 241 { 'V', "verbose", NULL,
239 gettext_noop("do not print keywords of the given TYPE") }, 242 gettext_noop ("be verbose") },
240 { 0, NULL, NULL, NULL }, 243 { 'x', "exclude", "TYPE",
241 }; 244 gettext_noop ("do not print keywords of the given TYPE") },
242 format_help (_("extract [OPTIONS] [FILENAME]*"), 245 { 0, NULL, NULL, NULL },
243 _("Extract metadata from files."), 246 };
244 help); 247 format_help (_ ("extract [OPTIONS] [FILENAME]*"),
248 _ ("Extract metadata from files."),
249 help);
245 250
246} 251}
247 252
253
248#if HAVE_ICONV 254#if HAVE_ICONV
249#include "iconv.c" 255#include "iconv.c"
250#endif 256#endif
@@ -267,12 +273,12 @@ print_help ()
267 */ 273 */
268static int 274static int
269print_selected_keywords (void *cls, 275print_selected_keywords (void *cls,
270 const char *plugin_name, 276 const char *plugin_name,
271 enum EXTRACTOR_MetaType type, 277 enum EXTRACTOR_MetaType type,
272 enum EXTRACTOR_MetaFormat format, 278 enum EXTRACTOR_MetaFormat format,
273 const char *data_mime_type, 279 const char *data_mime_type,
274 const char *data, 280 const char *data,
275 size_t data_len) 281 size_t data_len)
276{ 282{
277 char *keyword; 283 char *keyword;
278#if HAVE_ICONV 284#if HAVE_ICONV
@@ -285,59 +291,59 @@ print_selected_keywords (void *cls,
285 return 0; 291 return 0;
286 if (verbose > 3) 292 if (verbose > 3)
287 FPRINTF (stdout, 293 FPRINTF (stdout,
288 _("Found by `%s' plugin:\n"), 294 _ ("Found by `%s' plugin:\n"),
289 plugin_name); 295 plugin_name);
290 mt = EXTRACTOR_metatype_to_string (type); 296 mt = EXTRACTOR_metatype_to_string (type);
291 stype = (NULL == mt) ? _("unknown") : gettext(mt); 297 stype = (NULL == mt) ? _ ("unknown") : gettext (mt);
292 switch (format) 298 switch (format)
293 { 299 {
294 case EXTRACTOR_METAFORMAT_UNKNOWN: 300 case EXTRACTOR_METAFORMAT_UNKNOWN:
295 FPRINTF (stdout, 301 FPRINTF (stdout,
296 _("%s - (unknown, %u bytes)\n"), 302 _ ("%s - (unknown, %u bytes)\n"),
297 stype, 303 stype,
298 (unsigned int) data_len); 304 (unsigned int) data_len);
305 break;
306 case EXTRACTOR_METAFORMAT_UTF8:
307 if (0 == data_len)
299 break; 308 break;
300 case EXTRACTOR_METAFORMAT_UTF8:
301 if (0 == data_len)
302 break;
303#if HAVE_ICONV
304 cd = iconv_open (nl_langinfo(CODESET), "UTF-8");
305 if (((iconv_t) -1) != cd)
306 keyword = iconv_helper (cd,
307 data,
308 data_len);
309 else
310#endif
311 keyword = strdup (data);
312 if (NULL != keyword)
313 {
314 FPRINTF (stdout,
315 "%s - %s\n",
316 stype,
317 keyword);
318 free (keyword);
319 }
320#if HAVE_ICONV 309#if HAVE_ICONV
321 if (((iconv_t) -1) != cd) 310 cd = iconv_open (nl_langinfo (CODESET), "UTF-8");
322 iconv_close (cd); 311 if (((iconv_t) -1) != cd)
312 keyword = iconv_helper (cd,
313 data,
314 data_len);
315 else
323#endif 316#endif
324 break; 317 keyword = strdup (data);
325 case EXTRACTOR_METAFORMAT_BINARY: 318 if (NULL != keyword)
326 FPRINTF (stdout, 319 {
327 _("%s - (binary, %u bytes)\n"),
328 stype,
329 (unsigned int) data_len);
330 break;
331 case EXTRACTOR_METAFORMAT_C_STRING:
332 FPRINTF (stdout, 320 FPRINTF (stdout,
333 "%s - %.*s\n", 321 "%s - %s\n",
334 stype, 322 stype,
335 (int) data_len, 323 keyword);
336 data); 324 free (keyword);
337 break;
338 default:
339 break;
340 } 325 }
326#if HAVE_ICONV
327 if (((iconv_t) -1) != cd)
328 iconv_close (cd);
329#endif
330 break;
331 case EXTRACTOR_METAFORMAT_BINARY:
332 FPRINTF (stdout,
333 _ ("%s - (binary, %u bytes)\n"),
334 stype,
335 (unsigned int) data_len);
336 break;
337 case EXTRACTOR_METAFORMAT_C_STRING:
338 FPRINTF (stdout,
339 "%s - %.*s\n",
340 stype,
341 (int) data_len,
342 data);
343 break;
344 default:
345 break;
346 }
341 return 0; 347 return 0;
342} 348}
343 349
@@ -360,12 +366,12 @@ print_selected_keywords (void *cls,
360 */ 366 */
361static int 367static int
362print_selected_keywords_grep_friendly (void *cls, 368print_selected_keywords_grep_friendly (void *cls,
363 const char *plugin_name, 369 const char *plugin_name,
364 enum EXTRACTOR_MetaType type, 370 enum EXTRACTOR_MetaType type,
365 enum EXTRACTOR_MetaFormat format, 371 enum EXTRACTOR_MetaFormat format,
366 const char *data_mime_type, 372 const char *data_mime_type,
367 const char *data, 373 const char *data,
368 size_t data_len) 374 size_t data_len)
369{ 375{
370 char *keyword; 376 char *keyword;
371#if HAVE_ICONV 377#if HAVE_ICONV
@@ -379,51 +385,51 @@ print_selected_keywords_grep_friendly (void *cls,
379 if (NULL == mt) 385 if (NULL == mt)
380 mt = gettext_noop ("unknown"); 386 mt = gettext_noop ("unknown");
381 switch (format) 387 switch (format)
382 { 388 {
383 case EXTRACTOR_METAFORMAT_UNKNOWN: 389 case EXTRACTOR_METAFORMAT_UNKNOWN:
384 break; 390 break;
385 case EXTRACTOR_METAFORMAT_UTF8: 391 case EXTRACTOR_METAFORMAT_UTF8:
386 if (0 == data_len) 392 if (0 == data_len)
387 return 0; 393 return 0;
388 if (verbose > 1) 394 if (verbose > 1)
389 FPRINTF (stdout, 395 FPRINTF (stdout,
390 "%s: ", 396 "%s: ",
391 gettext(mt)); 397 gettext (mt));
392#if HAVE_ICONV 398#if HAVE_ICONV
393 cd = iconv_open (nl_langinfo (CODESET), "UTF-8"); 399 cd = iconv_open (nl_langinfo (CODESET), "UTF-8");
394 if (((iconv_t) -1) != cd) 400 if (((iconv_t) -1) != cd)
395 keyword = iconv_helper (cd, 401 keyword = iconv_helper (cd,
396 data, 402 data,
397 data_len); 403 data_len);
398 else 404 else
399#endif 405#endif
400 keyword = strdup (data); 406 keyword = strdup (data);
401 if (NULL != keyword) 407 if (NULL != keyword)
402 { 408 {
403 FPRINTF (stdout, 409 FPRINTF (stdout,
404 "`%s' ", 410 "`%s' ",
405 keyword); 411 keyword);
406 free (keyword); 412 free (keyword);
407 } 413 }
408#if HAVE_ICONV 414#if HAVE_ICONV
409 if (((iconv_t) -1) != cd) 415 if (((iconv_t) -1) != cd)
410 iconv_close (cd); 416 iconv_close (cd);
411#endif 417#endif
412 break; 418 break;
413 case EXTRACTOR_METAFORMAT_BINARY: 419 case EXTRACTOR_METAFORMAT_BINARY:
414 break; 420 break;
415 case EXTRACTOR_METAFORMAT_C_STRING: 421 case EXTRACTOR_METAFORMAT_C_STRING:
416 if (verbose > 1) 422 if (verbose > 1)
417 FPRINTF (stdout,
418 "%s ",
419 gettext(mt));
420 FPRINTF (stdout, 423 FPRINTF (stdout,
421 "`%s'", 424 "%s ",
422 data); 425 gettext (mt));
423 break; 426 FPRINTF (stdout,
424 default: 427 "`%s'",
425 break; 428 data);
426 } 429 break;
430 default:
431 break;
432 }
427 return 0; 433 return 0;
428} 434}
429 435
@@ -459,31 +465,30 @@ static char *entry_type;
459 * Mapping between bibTeX strings, libextractor 465 * Mapping between bibTeX strings, libextractor
460 * meta data types and values for the current document. 466 * meta data types and values for the current document.
461 */ 467 */
462static struct BibTexMap btm[] = 468static struct BibTexMap btm[] = {
463 { 469 { "title", EXTRACTOR_METATYPE_TITLE, NULL},
464 { "title", EXTRACTOR_METATYPE_TITLE, NULL}, 470 { "year", EXTRACTOR_METATYPE_PUBLICATION_YEAR, NULL },
465 { "year", EXTRACTOR_METATYPE_PUBLICATION_YEAR, NULL }, 471 { "author", EXTRACTOR_METATYPE_AUTHOR_NAME, NULL },
466 { "author", EXTRACTOR_METATYPE_AUTHOR_NAME, NULL }, 472 { "book", EXTRACTOR_METATYPE_BOOK_TITLE, NULL},
467 { "book", EXTRACTOR_METATYPE_BOOK_TITLE, NULL}, 473 { "edition", EXTRACTOR_METATYPE_BOOK_EDITION, NULL},
468 { "edition", EXTRACTOR_METATYPE_BOOK_EDITION, NULL}, 474 { "chapter", EXTRACTOR_METATYPE_BOOK_CHAPTER_NUMBER, NULL},
469 { "chapter", EXTRACTOR_METATYPE_BOOK_CHAPTER_NUMBER, NULL}, 475 { "journal", EXTRACTOR_METATYPE_JOURNAL_NAME, NULL},
470 { "journal", EXTRACTOR_METATYPE_JOURNAL_NAME, NULL}, 476 { "volume", EXTRACTOR_METATYPE_JOURNAL_VOLUME, NULL},
471 { "volume", EXTRACTOR_METATYPE_JOURNAL_VOLUME, NULL}, 477 { "number", EXTRACTOR_METATYPE_JOURNAL_NUMBER, NULL},
472 { "number", EXTRACTOR_METATYPE_JOURNAL_NUMBER, NULL}, 478 { "pages", EXTRACTOR_METATYPE_PAGE_COUNT, NULL },
473 { "pages", EXTRACTOR_METATYPE_PAGE_COUNT, NULL }, 479 { "pages", EXTRACTOR_METATYPE_PAGE_RANGE, NULL },
474 { "pages", EXTRACTOR_METATYPE_PAGE_RANGE, NULL }, 480 { "school", EXTRACTOR_METATYPE_AUTHOR_INSTITUTION, NULL},
475 { "school", EXTRACTOR_METATYPE_AUTHOR_INSTITUTION, NULL}, 481 { "publisher", EXTRACTOR_METATYPE_PUBLISHER, NULL },
476 { "publisher", EXTRACTOR_METATYPE_PUBLISHER, NULL }, 482 { "address", EXTRACTOR_METATYPE_PUBLISHER_ADDRESS, NULL },
477 { "address", EXTRACTOR_METATYPE_PUBLISHER_ADDRESS, NULL }, 483 { "institution", EXTRACTOR_METATYPE_PUBLISHER_INSTITUTION, NULL },
478 { "institution", EXTRACTOR_METATYPE_PUBLISHER_INSTITUTION, NULL }, 484 { "series", EXTRACTOR_METATYPE_PUBLISHER_SERIES, NULL},
479 { "series", EXTRACTOR_METATYPE_PUBLISHER_SERIES, NULL}, 485 { "month", EXTRACTOR_METATYPE_PUBLICATION_MONTH, NULL },
480 { "month", EXTRACTOR_METATYPE_PUBLICATION_MONTH, NULL }, 486 { "url", EXTRACTOR_METATYPE_URL, NULL},
481 { "url", EXTRACTOR_METATYPE_URL, NULL}, 487 { "note", EXTRACTOR_METATYPE_COMMENT, NULL},
482 { "note", EXTRACTOR_METATYPE_COMMENT, NULL}, 488 { "eprint", EXTRACTOR_METATYPE_BIBTEX_EPRINT, NULL },
483 { "eprint", EXTRACTOR_METATYPE_BIBTEX_EPRINT, NULL }, 489 { "type", EXTRACTOR_METATYPE_PUBLICATION_TYPE, NULL },
484 { "type", EXTRACTOR_METATYPE_PUBLICATION_TYPE, NULL }, 490 { NULL, 0, NULL }
485 { NULL, 0, NULL } 491};
486 };
487 492
488 493
489/** 494/**
@@ -495,10 +500,10 @@ cleanup_bibtex ()
495 unsigned int i; 500 unsigned int i;
496 501
497 for (i = 0; NULL != btm[i].bibTexName; i++) 502 for (i = 0; NULL != btm[i].bibTexName; i++)
498 { 503 {
499 free (btm[i].value); 504 free (btm[i].value);
500 btm[i].value = NULL; 505 btm[i].value = NULL;
501 } 506 }
502 free (entry_type); 507 free (entry_type);
503 entry_type = NULL; 508 entry_type = NULL;
504} 509}
@@ -522,12 +527,12 @@ cleanup_bibtex ()
522 */ 527 */
523static int 528static int
524print_bibtex (void *cls, 529print_bibtex (void *cls,
525 const char *plugin_name, 530 const char *plugin_name,
526 enum EXTRACTOR_MetaType type, 531 enum EXTRACTOR_MetaType type,
527 enum EXTRACTOR_MetaFormat format, 532 enum EXTRACTOR_MetaFormat format,
528 const char *data_mime_type, 533 const char *data_mime_type,
529 const char *data, 534 const char *data,
530 size_t data_len) 535 size_t data_len)
531{ 536{
532 unsigned int i; 537 unsigned int i;
533 538
@@ -538,13 +543,13 @@ print_bibtex (void *cls,
538 if (EXTRACTOR_METAFORMAT_UTF8 != format) 543 if (EXTRACTOR_METAFORMAT_UTF8 != format)
539 return 0; 544 return 0;
540 if (EXTRACTOR_METATYPE_BIBTEX_ENTRY_TYPE == type) 545 if (EXTRACTOR_METATYPE_BIBTEX_ENTRY_TYPE == type)
541 { 546 {
542 entry_type = strdup (data); 547 entry_type = strdup (data);
543 return 0; 548 return 0;
544 } 549 }
545 for (i = 0; NULL != btm[i].bibTexName; i++) 550 for (i = 0; NULL != btm[i].bibTexName; i++)
546 if ( (NULL == btm[i].value) && 551 if ( (NULL == btm[i].value) &&
547 (btm[i].le_type == type) ) 552 (btm[i].le_type == type) )
548 btm[i].value = strdup (data); 553 btm[i].value = strdup (data);
549 return 0; 554 return 0;
550} 555}
@@ -571,33 +576,33 @@ finish_bibtex (const char *fn)
571 (NULL == btm[1].value) || 576 (NULL == btm[1].value) ||
572 (NULL == btm[2].value) ) 577 (NULL == btm[2].value) )
573 FPRINTF (stdout, 578 FPRINTF (stdout,
574 "@%s %s { ", 579 "@%s %s { ",
575 et, 580 et,
576 fn); 581 fn);
577 else 582 else
578 { 583 {
579 snprintf (temp, 584 snprintf (temp,
580 sizeof (temp), 585 sizeof (temp),
581 "%.5s%.5s%.5s", 586 "%.5s%.5s%.5s",
582 btm[2].value, 587 btm[2].value,
583 btm[1].value, 588 btm[1].value,
584 btm[0].value); 589 btm[0].value);
585 for (n=strlen (temp)-1;n>=0;n-- ) 590 for (n = strlen (temp) - 1; n>=0; n--)
586 if (! isalnum ( (unsigned char) temp[n]) ) 591 if (! isalnum ( (unsigned char) temp[n]) )
587 temp[n] = '_'; 592 temp[n] = '_';
588 else 593 else
589 temp[n] = tolower ( (unsigned char) temp[n]); 594 temp[n] = tolower ( (unsigned char) temp[n]);
590 FPRINTF (stdout, 595 FPRINTF (stdout,
591 "@%s %s { ", 596 "@%s %s { ",
592 et, 597 et,
593 temp); 598 temp);
594 } 599 }
595 for (i=0; NULL != btm[i].bibTexName; i++) 600 for (i = 0; NULL != btm[i].bibTexName; i++)
596 if (NULL != btm[i].value) 601 if (NULL != btm[i].value)
597 FPRINTF (stdout, 602 FPRINTF (stdout,
598 "\t%s = {%s},\n", 603 "\t%s = {%s},\n",
599 btm[i].bibTexName, 604 btm[i].bibTexName,
600 btm[i].value); 605 btm[i].value);
601 FPRINTF (stdout, "%s", "}\n\n"); 606 FPRINTF (stdout, "%s", "}\n\n");
602} 607}
603 608
@@ -612,7 +617,9 @@ _wchar_to_str (const wchar_t *wstr, char **retstr, UINT cp)
612 DWORD error; 617 DWORD error;
613 618
614 SetLastError (0); 619 SetLastError (0);
615 len = WideCharToMultiByte (cp, 0, wstr, -1, NULL, 0, NULL, (cp == CP_UTF8 || cp == CP_UTF7) ? NULL : &lossy); 620 len = WideCharToMultiByte (cp, 0, wstr, -1, NULL, 0, NULL, (cp == CP_UTF8 ||
621 cp == CP_UTF7) ?
622 NULL : &lossy);
616 error = GetLastError (); 623 error = GetLastError ();
617 if (len <= 0) 624 if (len <= 0)
618 return -1; 625 return -1;
@@ -620,7 +627,9 @@ _wchar_to_str (const wchar_t *wstr, char **retstr, UINT cp)
620 str = malloc (sizeof (char) * len); 627 str = malloc (sizeof (char) * len);
621 628
622 SetLastError (0); 629 SetLastError (0);
623 lenc = WideCharToMultiByte (cp, 0, wstr, -1, str, len, NULL, (cp == CP_UTF8 || cp == CP_UTF7) ? NULL : &lossy); 630 lenc = WideCharToMultiByte (cp, 0, wstr, -1, str, len, NULL, (cp == CP_UTF8 ||
631 cp == CP_UTF7) ?
632 NULL : &lossy);
624 error = GetLastError (); 633 error = GetLastError ();
625 if (lenc != len) 634 if (lenc != len)
626 { 635 {
@@ -632,6 +641,8 @@ _wchar_to_str (const wchar_t *wstr, char **retstr, UINT cp)
632 return 1; 641 return 1;
633 return 0; 642 return 0;
634} 643}
644
645
635#endif 646#endif
636 647
637 648
@@ -711,10 +722,10 @@ _get_utf8_args (int argc, char *const *argv, int *u8argc, char ***u8argv)
711 722
712 *u8argv = _make_continuous_arg_copy (wargc, split_u8argv); 723 *u8argv = _make_continuous_arg_copy (wargc, split_u8argv);
713 if (NULL == *u8argv) 724 if (NULL == *u8argv)
714 { 725 {
715 free (split_u8argv); 726 free (split_u8argv);
716 return -1; 727 return -1;
717 } 728 }
718 *u8argc = wargc; 729 *u8argc = wargc;
719 730
720 for (i = 0; i < wargc; i++) 731 for (i = 0; i < wargc; i++)
@@ -756,21 +767,21 @@ main (int argc, char *argv[])
756 int utf8_argc; 767 int utf8_argc;
757 768
758#if ENABLE_NLS 769#if ENABLE_NLS
759 setlocale(LC_ALL, ""); 770 setlocale (LC_ALL, "");
760 textdomain(PACKAGE); 771 textdomain (PACKAGE);
761#endif 772#endif
762#ifndef WINDOWS 773#ifndef WINDOWS
763 ignore_sigpipe (); 774 ignore_sigpipe ();
764#endif 775#endif
765 if (NULL == (print = malloc (sizeof (int) * EXTRACTOR_metatype_get_max ()))) 776 if (NULL == (print = malloc (sizeof (int) * EXTRACTOR_metatype_get_max ())))
766 { 777 {
767 FPRINTF (stderr, 778 FPRINTF (stderr,
768 "malloc failed: %s\n", 779 "malloc failed: %s\n",
769 strerror (errno)); 780 strerror (errno));
770 return 1; 781 return 1;
771 } 782 }
772 for (i = 0; i < EXTRACTOR_metatype_get_max (); i++) 783 for (i = 0; i < EXTRACTOR_metatype_get_max (); i++)
773 print[i] = YES; /* default: print everything */ 784 print[i] = YES; /* default: print everything */
774 785
775 if (0 != _get_utf8_args (argc, argv, &utf8_argc, &utf8_argv)) 786 if (0 != _get_utf8_args (argc, argv, &utf8_argc, &utf8_argv))
776 { 787 {
@@ -779,249 +790,252 @@ main (int argc, char *argv[])
779 } 790 }
780 791
781 while (1) 792 while (1)
793 {
794 static struct option long_options[] = {
795 {"bibtex", 0, 0, 'b'},
796 {"grep-friendly", 0, 0, 'g'},
797 {"help", 0, 0, 'h'},
798 {"in-process", 0, 0, 'i'},
799 {"from-memory", 0, 0, 'm'},
800 {"list", 0, 0, 'L'},
801 {"library", 1, 0, 'l'},
802 {"nodefault", 0, 0, 'n'},
803 {"print", 1, 0, 'p'},
804 {"verbose", 0, 0, 'V'},
805 {"version", 0, 0, 'v'},
806 {"exclude", 1, 0, 'x'},
807 {0, 0, 0, 0}
808 };
809 option_index = 0;
810 c = getopt_long (utf8_argc,
811 utf8_argv,
812 "abghiml:Lnp:vVx:",
813 long_options,
814 &option_index);
815
816 if (c == -1)
817 break; /* No more flags to process */
818 switch (c)
782 { 819 {
783 static struct option long_options[] = { 820 case 'b':
784 {"bibtex", 0, 0, 'b'}, 821 bibtex = YES;
785 {"grep-friendly", 0, 0, 'g'}, 822 if (NULL != processor)
786 {"help", 0, 0, 'h'}, 823 {
787 {"in-process", 0, 0, 'i'}, 824 FPRINTF (stderr,
788 {"from-memory", 0, 0, 'm'}, 825 "%s",
789 {"list", 0, 0, 'L'}, 826 _ (
790 {"library", 1, 0, 'l'}, 827 "Illegal combination of options, cannot combine multiple styles of printing.\n"));
791 {"nodefault", 0, 0, 'n'}, 828 free (utf8_argv);
792 {"print", 1, 0, 'p'}, 829 return 0;
793 {"verbose", 0, 0, 'V'}, 830 }
794 {"version", 0, 0, 'v'}, 831 processor = &print_bibtex;
795 {"exclude", 1, 0, 'x'}, 832 break;
796 {0, 0, 0, 0} 833 case 'g':
797 }; 834 grepfriendly = YES;
798 option_index = 0; 835 if (NULL != processor)
799 c = getopt_long (utf8_argc, 836 {
800 utf8_argv, 837 FPRINTF (stderr,
801 "abghiml:Lnp:vVx:", 838 "%s",
802 long_options, 839 _ (
803 &option_index); 840 "Illegal combination of options, cannot combine multiple styles of printing.\n"));
804 841 free (utf8_argv);
805 if (c == -1) 842 return 0;
806 break; /* No more flags to process */ 843 }
807 switch (c) 844 processor = &print_selected_keywords_grep_friendly;
808 { 845 break;
809 case 'b': 846 case 'h':
810 bibtex = YES; 847 print_help ();
811 if (NULL != processor) 848 free (utf8_argv);
812 { 849 return 0;
813 FPRINTF (stderr, 850 case 'i':
814 "%s", 851 in_process = YES;
815 _("Illegal combination of options, cannot combine multiple styles of printing.\n")); 852 break;
816 free (utf8_argv); 853 case 'm':
817 return 0; 854 from_memory = YES;
818 } 855 break;
819 processor = &print_bibtex; 856 case 'l':
820 break; 857 libraries = optarg;
821 case 'g': 858 break;
822 grepfriendly = YES; 859 case 'L':
823 if (NULL != processor) 860 i = 0;
824 { 861 while (NULL != EXTRACTOR_metatype_to_string (i))
825 FPRINTF (stderr, 862 printf ("%s\n",
826 "%s", 863 gettext (EXTRACTOR_metatype_to_string (i++)));
827 _("Illegal combination of options, cannot combine multiple styles of printing.\n")); 864 free (utf8_argv);
828 free (utf8_argv); 865 return 0;
829 return 0; 866 case 'n':
830 } 867 nodefault = YES;
831 processor = &print_selected_keywords_grep_friendly; 868 break;
832 break; 869 case 'p':
833 case 'h': 870 if (NULL == optarg)
834 print_help (); 871 {
835 free (utf8_argv); 872 FPRINTF (stderr,
836 return 0; 873 _ (
837 case 'i': 874 "You must specify an argument for the `%s' option (option ignored).\n"),
838 in_process = YES; 875 "-p");
839 break; 876 break;
840 case 'm': 877 }
841 from_memory = YES; 878 if (YES == defaultAll)
879 {
880 defaultAll = NO;
881 i = 0;
882 while (NULL != EXTRACTOR_metatype_to_string (i))
883 print[i++] = NO;
884 }
885 i = 0;
886 while (NULL != EXTRACTOR_metatype_to_string (i))
887 {
888 if ( (0 == strcmp (optarg,
889 EXTRACTOR_metatype_to_string (i))) ||
890 (0 == strcmp (optarg,
891 gettext (EXTRACTOR_metatype_to_string (i)))) )
892
893 {
894 print[i] = YES;
842 break; 895 break;
843 case 'l': 896 }
844 libraries = optarg; 897 i++;
845 break; 898 }
846 case 'L': 899 if (NULL == EXTRACTOR_metatype_to_string (i))
847 i = 0; 900 {
848 while (NULL != EXTRACTOR_metatype_to_string (i)) 901 FPRINTF (stderr,
849 printf ("%s\n", 902 "Unknown keyword type `%s', use option `%s' to get a list.\n",
850 gettext(EXTRACTOR_metatype_to_string (i++))); 903 optarg,
851 free (utf8_argv); 904 "-L");
852 return 0; 905 free (utf8_argv);
853 case 'n': 906 return -1;
854 nodefault = YES; 907 }
855 break; 908 break;
856 case 'p': 909 case 'v':
857 if (NULL == optarg) 910 printf ("extract v%s\n", PACKAGE_VERSION);
858 {
859 FPRINTF(stderr,
860 _("You must specify an argument for the `%s' option (option ignored).\n"),
861 "-p");
862 break;
863 }
864 if (YES == defaultAll)
865 {
866 defaultAll = NO;
867 i = 0;
868 while (NULL != EXTRACTOR_metatype_to_string (i))
869 print[i++] = NO;
870 }
871 i = 0;
872 while (NULL != EXTRACTOR_metatype_to_string (i))
873 {
874 if ( (0 == strcmp (optarg,
875 EXTRACTOR_metatype_to_string (i))) ||
876 (0 == strcmp (optarg,
877 gettext(EXTRACTOR_metatype_to_string (i)))) )
878
879 {
880 print[i] = YES;
881 break;
882 }
883 i++;
884 }
885 if (NULL == EXTRACTOR_metatype_to_string (i))
886 {
887 FPRINTF(stderr,
888 "Unknown keyword type `%s', use option `%s' to get a list.\n",
889 optarg,
890 "-L");
891 free (utf8_argv);
892 return -1;
893 }
894 break;
895 case 'v':
896 printf ("extract v%s\n", PACKAGE_VERSION);
897 free (utf8_argv);
898 return 0;
899 case 'V':
900 verbose++;
901 break;
902 case 'x':
903 i = 0;
904 while (NULL != EXTRACTOR_metatype_to_string (i))
905 {
906 if ( (0 == strcmp (optarg,
907 EXTRACTOR_metatype_to_string (i))) ||
908 (0 == strcmp (optarg,
909 gettext(EXTRACTOR_metatype_to_string (i)))) )
910 {
911 print[i] = NO;
912 break;
913 }
914 i++;
915 }
916 if (NULL == EXTRACTOR_metatype_to_string (i))
917 {
918 FPRINTF (stderr,
919 "Unknown keyword type `%s', use option `%s' to get a list.\n",
920 optarg,
921 "-L");
922 free (utf8_argv);
923 return -1;
924 }
925 break;
926 default:
927 FPRINTF (stderr,
928 "%s",
929 _("Use --help to get a list of options.\n"));
930 free (utf8_argv);
931 return -1;
932 } /* end of parsing commandline */
933 } /* while (1) */
934 if (optind < 0)
935 {
936 FPRINTF (stderr,
937 "%s", "Unknown error parsing options\n");
938 free (print);
939 free (utf8_argv); 911 free (utf8_argv);
940 return -1; 912 return 0;
941 } 913 case 'V':
942 if (utf8_argc - optind < 1) 914 verbose++;
943 { 915 break;
916 case 'x':
917 i = 0;
918 while (NULL != EXTRACTOR_metatype_to_string (i))
919 {
920 if ( (0 == strcmp (optarg,
921 EXTRACTOR_metatype_to_string (i))) ||
922 (0 == strcmp (optarg,
923 gettext (EXTRACTOR_metatype_to_string (i)))) )
924 {
925 print[i] = NO;
926 break;
927 }
928 i++;
929 }
930 if (NULL == EXTRACTOR_metatype_to_string (i))
931 {
932 FPRINTF (stderr,
933 "Unknown keyword type `%s', use option `%s' to get a list.\n",
934 optarg,
935 "-L");
936 free (utf8_argv);
937 return -1;
938 }
939 break;
940 default:
944 FPRINTF (stderr, 941 FPRINTF (stderr,
945 "%s", "Invoke with list of filenames to extract keywords form!\n"); 942 "%s",
946 free (print); 943 _ ("Use --help to get a list of options.\n"));
947 free (utf8_argv); 944 free (utf8_argv);
948 return -1; 945 return -1;
949 } 946 } /* end of parsing commandline */
947 } /* while (1) */
948 if (optind < 0)
949 {
950 FPRINTF (stderr,
951 "%s", "Unknown error parsing options\n");
952 free (print);
953 free (utf8_argv);
954 return -1;
955 }
956 if (utf8_argc - optind < 1)
957 {
958 FPRINTF (stderr,
959 "%s", "Invoke with list of filenames to extract keywords form!\n");
960 free (print);
961 free (utf8_argv);
962 return -1;
963 }
950 964
951 /* build list of libraries */ 965 /* build list of libraries */
952 if (NO == nodefault) 966 if (NO == nodefault)
953 plugins = EXTRACTOR_plugin_add_defaults (in_process 967 plugins = EXTRACTOR_plugin_add_defaults (in_process
954 ? EXTRACTOR_OPTION_IN_PROCESS 968 ? EXTRACTOR_OPTION_IN_PROCESS
955 : EXTRACTOR_OPTION_DEFAULT_POLICY); 969 : EXTRACTOR_OPTION_DEFAULT_POLICY);
956 else 970 else
957 plugins = NULL; 971 plugins = NULL;
958 if (NULL != libraries) 972 if (NULL != libraries)
959 plugins = EXTRACTOR_plugin_add_config (plugins, 973 plugins = EXTRACTOR_plugin_add_config (plugins,
960 libraries, 974 libraries,
961 in_process 975 in_process
962 ? EXTRACTOR_OPTION_IN_PROCESS 976 ? EXTRACTOR_OPTION_IN_PROCESS
963 : EXTRACTOR_OPTION_DEFAULT_POLICY); 977 : EXTRACTOR_OPTION_DEFAULT_POLICY);
964 if (NULL == processor) 978 if (NULL == processor)
965 processor = &print_selected_keywords; 979 processor = &print_selected_keywords;
966 980
967 /* extract keywords */ 981 /* extract keywords */
968 if (YES == bibtex) 982 if (YES == bibtex)
969 FPRINTF(stdout, 983 FPRINTF (stdout,
970 "%s", _("% BiBTeX file\n")); 984 "%s", _ ("% BiBTeX file\n"));
971 for (i = optind; i < utf8_argc; i++) 985 for (i = optind; i < utf8_argc; i++)
986 {
987 errno = 0;
988 if (YES == grepfriendly)
989 FPRINTF (stdout, "%s ", utf8_argv[i]);
990 else if (NO == bibtex)
991 FPRINTF (stdout,
992 _ ("Keywords for file %s:\n"),
993 utf8_argv[i]);
994 else
995 cleanup_bibtex ();
996 if (NO == from_memory)
997 EXTRACTOR_extract (plugins,
998 utf8_argv[i],
999 NULL, 0,
1000 processor,
1001 NULL);
1002 else
972 { 1003 {
973 errno = 0; 1004 struct stat sb;
974 if (YES == grepfriendly) 1005 unsigned char *data = NULL;
975 FPRINTF (stdout, "%s ", utf8_argv[i]); 1006 int f = OPEN (utf8_argv[i], O_RDONLY
976 else if (NO == bibtex)
977 FPRINTF (stdout,
978 _("Keywords for file %s:\n"),
979 utf8_argv[i]);
980 else
981 cleanup_bibtex ();
982 if (NO == from_memory)
983 EXTRACTOR_extract (plugins,
984 utf8_argv[i],
985 NULL, 0,
986 processor,
987 NULL);
988 else
989 {
990 struct stat sb;
991 unsigned char *data = NULL;
992 int f = OPEN (utf8_argv[i], O_RDONLY
993#if WINDOWS 1007#if WINDOWS
994 | O_BINARY 1008 | O_BINARY
995#endif 1009#endif
996 ); 1010 );
997 if ( (-1 != f) && 1011 if ( (-1 != f) &&
998 (0 == FSTAT (f, &sb)) && 1012 (0 == FSTAT (f, &sb)) &&
999 (NULL != (data = malloc ((size_t) sb.st_size))) && 1013 (NULL != (data = malloc ((size_t) sb.st_size))) &&
1000 (sb.st_size == READ (f, data, (size_t) sb.st_size) ) ) 1014 (sb.st_size == READ (f, data, (size_t) sb.st_size) ) )
1001 { 1015 {
1002 EXTRACTOR_extract (plugins, 1016 EXTRACTOR_extract (plugins,
1003 NULL, 1017 NULL,
1004 data, sb.st_size, 1018 data, sb.st_size,
1005 processor, 1019 processor,
1006 NULL); 1020 NULL);
1007 } 1021 }
1008 else 1022 else
1009 { 1023 {
1010 if (verbose > 0) 1024 if (verbose > 0)
1011 FPRINTF(stderr, 1025 FPRINTF (stderr,
1012 "%s: %s: %s\n", 1026 "%s: %s: %s\n",
1013 utf8_argv[0], utf8_argv[i], strerror(errno)); 1027 utf8_argv[0], utf8_argv[i], strerror (errno));
1014 ret = 1; 1028 ret = 1;
1015 } 1029 }
1016 if (NULL != data) 1030 if (NULL != data)
1017 free (data); 1031 free (data);
1018 if (-1 != f) 1032 if (-1 != f)
1019 (void) CLOSE (f); 1033 (void) CLOSE (f);
1020 }
1021 if (YES == grepfriendly)
1022 FPRINTF (stdout, "%s", "\n");
1023 continue;
1024 } 1034 }
1035 if (YES == grepfriendly)
1036 FPRINTF (stdout, "%s", "\n");
1037 continue;
1038 }
1025 if (YES == grepfriendly) 1039 if (YES == grepfriendly)
1026 FPRINTF (stdout, "%s", "\n"); 1040 FPRINTF (stdout, "%s", "\n");
1027 if (bibtex) 1041 if (bibtex)
@@ -1036,4 +1050,5 @@ main (int argc, char *argv[])
1036 return ret; 1050 return ret;
1037} 1051}
1038 1052
1053
1039/* end of extract.c */ 1054/* end of extract.c */
diff --git a/src/main/extractor.c b/src/main/extractor.c
index 3755da9..cb64b95 100644
--- a/src/main/extractor.c
+++ b/src/main/extractor.c
@@ -71,9 +71,9 @@ struct PluginReplyProcessor
71 */ 71 */
72static void 72static void
73send_update_message (struct EXTRACTOR_PluginList *plugin, 73send_update_message (struct EXTRACTOR_PluginList *plugin,
74 int64_t shm_off, 74 int64_t shm_off,
75 size_t data_available, 75 size_t data_available,
76 struct EXTRACTOR_Datasource *ds) 76 struct EXTRACTOR_Datasource *ds)
77{ 77{
78 struct UpdateMessage um; 78 struct UpdateMessage um;
79 79
@@ -85,14 +85,14 @@ send_update_message (struct EXTRACTOR_PluginList *plugin,
85 um.file_size = EXTRACTOR_datasource_get_size_ (ds, 0); 85 um.file_size = EXTRACTOR_datasource_get_size_ (ds, 0);
86 if (sizeof (um) != 86 if (sizeof (um) !=
87 EXTRACTOR_IPC_channel_send_ (plugin->channel, 87 EXTRACTOR_IPC_channel_send_ (plugin->channel,
88 &um, 88 &um,
89 sizeof (um)) ) 89 sizeof (um)) )
90 { 90 {
91 LOG ("Failed to send UPDATED_SHM message to plugin\n"); 91 LOG ("Failed to send UPDATED_SHM message to plugin\n");
92 EXTRACTOR_IPC_channel_destroy_ (plugin->channel); 92 EXTRACTOR_IPC_channel_destroy_ (plugin->channel);
93 plugin->channel = NULL; 93 plugin->channel = NULL;
94 plugin->round_finished = 1; 94 plugin->round_finished = 1;
95 } 95 }
96} 96}
97 97
98 98
@@ -109,14 +109,14 @@ send_discard_message (struct EXTRACTOR_PluginList *plugin)
109 109
110 if (sizeof (disc_msg) != 110 if (sizeof (disc_msg) !=
111 EXTRACTOR_IPC_channel_send_ (plugin->channel, 111 EXTRACTOR_IPC_channel_send_ (plugin->channel,
112 &disc_msg, 112 &disc_msg,
113 sizeof (disc_msg)) ) 113 sizeof (disc_msg)) )
114 { 114 {
115 LOG ("Failed to send DISCARD_STATE message to plugin\n"); 115 LOG ("Failed to send DISCARD_STATE message to plugin\n");
116 EXTRACTOR_IPC_channel_destroy_ (plugin->channel); 116 EXTRACTOR_IPC_channel_destroy_ (plugin->channel);
117 plugin->channel = NULL; 117 plugin->channel = NULL;
118 plugin->round_finished = 1; 118 plugin->round_finished = 1;
119 } 119 }
120} 120}
121 121
122 122
@@ -131,12 +131,12 @@ abort_all_channels (struct EXTRACTOR_PluginList *plugins)
131 struct EXTRACTOR_PluginList *pos; 131 struct EXTRACTOR_PluginList *pos;
132 132
133 for (pos = plugins; NULL != pos; pos = pos->next) 133 for (pos = plugins; NULL != pos; pos = pos->next)
134 { 134 {
135 if (NULL == pos->channel) 135 if (NULL == pos->channel)
136 continue; 136 continue;
137 EXTRACTOR_IPC_channel_destroy_ (pos->channel); 137 EXTRACTOR_IPC_channel_destroy_ (pos->channel);
138 pos->channel = NULL; 138 pos->channel = NULL;
139 } 139 }
140} 140}
141 141
142 142
@@ -153,46 +153,46 @@ abort_all_channels (struct EXTRACTOR_PluginList *plugins)
153 */ 153 */
154static void 154static void
155process_plugin_reply (void *cls, 155process_plugin_reply (void *cls,
156 struct EXTRACTOR_PluginList *plugin, 156 struct EXTRACTOR_PluginList *plugin,
157 enum EXTRACTOR_MetaType meta_type, 157 enum EXTRACTOR_MetaType meta_type,
158 enum EXTRACTOR_MetaFormat meta_format, 158 enum EXTRACTOR_MetaFormat meta_format,
159 const char *mime, 159 const char *mime,
160 const void *value, 160 const void *value,
161 size_t value_len) 161 size_t value_len)
162{ 162{
163 static unsigned char cont_msg = MESSAGE_CONTINUE_EXTRACTING; 163 static unsigned char cont_msg = MESSAGE_CONTINUE_EXTRACTING;
164 struct PluginReplyProcessor *prp = cls; 164 struct PluginReplyProcessor *prp = cls;
165 165
166 if (0 != prp->file_finished) 166 if (0 != prp->file_finished)
167 { 167 {
168 /* client already aborted, ignore message, tell plugin about abort */ 168 /* client already aborted, ignore message, tell plugin about abort */
169 return; 169 return;
170 } 170 }
171 if (0 != prp->proc (prp->proc_cls, 171 if (0 != prp->proc (prp->proc_cls,
172 plugin->short_libname, 172 plugin->short_libname,
173 meta_type, 173 meta_type,
174 meta_format, 174 meta_format,
175 mime, 175 mime,
176 value, 176 value,
177 value_len)) 177 value_len))
178 { 178 {
179 prp->file_finished = 1; 179 prp->file_finished = 1;
180#if DEBUG 180#if DEBUG
181 fprintf (stderr, "Sending ABRT\n"); 181 fprintf (stderr, "Sending ABRT\n");
182#endif 182#endif
183 send_discard_message (plugin); 183 send_discard_message (plugin);
184 return; 184 return;
185 } 185 }
186 if (sizeof (cont_msg) != 186 if (sizeof (cont_msg) !=
187 EXTRACTOR_IPC_channel_send_ (plugin->channel, 187 EXTRACTOR_IPC_channel_send_ (plugin->channel,
188 &cont_msg, 188 &cont_msg,
189 sizeof (cont_msg)) ) 189 sizeof (cont_msg)) )
190 { 190 {
191 LOG ("Failed to send CONTINUE_EXTRACTING message to plugin\n"); 191 LOG ("Failed to send CONTINUE_EXTRACTING message to plugin\n");
192 EXTRACTOR_IPC_channel_destroy_ (plugin->channel); 192 EXTRACTOR_IPC_channel_destroy_ (plugin->channel);
193 plugin->channel = NULL; 193 plugin->channel = NULL;
194 plugin->round_finished = 1; 194 plugin->round_finished = 1;
195 } 195 }
196} 196}
197 197
198 198
@@ -245,8 +245,8 @@ struct InProcessContext
245 */ 245 */
246static ssize_t 246static ssize_t
247in_process_read (void *cls, 247in_process_read (void *cls,
248 void **data, 248 void **data,
249 size_t size) 249 size_t size)
250{ 250{
251 struct InProcessContext *ctx = cls; 251 struct InProcessContext *ctx = cls;
252 ssize_t ret; 252 ssize_t ret;
@@ -256,8 +256,8 @@ in_process_read (void *cls,
256 if (size < bsize) 256 if (size < bsize)
257 bsize = size; 257 bsize = size;
258 ret = EXTRACTOR_datasource_read_ (ctx->ds, 258 ret = EXTRACTOR_datasource_read_ (ctx->ds,
259 ctx->buf, 259 ctx->buf,
260 bsize); 260 bsize);
261 if (-1 == ret) 261 if (-1 == ret)
262 *data = NULL; 262 *data = NULL;
263 else 263 else
@@ -279,14 +279,14 @@ in_process_read (void *cls,
279 */ 279 */
280static int64_t 280static int64_t
281in_process_seek (void *cls, 281in_process_seek (void *cls,
282 int64_t pos, 282 int64_t pos,
283 int whence) 283 int whence)
284{ 284{
285 struct InProcessContext *ctx = cls; 285 struct InProcessContext *ctx = cls;
286 286
287 return EXTRACTOR_datasource_seek_ (ctx->ds, 287 return EXTRACTOR_datasource_seek_ (ctx->ds,
288 pos, 288 pos,
289 whence); 289 whence);
290} 290}
291 291
292 292
@@ -326,12 +326,12 @@ in_process_get_size (void *cls)
326 */ 326 */
327static int 327static int
328in_process_proc (void *cls, 328in_process_proc (void *cls,
329 const char *plugin_name, 329 const char *plugin_name,
330 enum EXTRACTOR_MetaType type, 330 enum EXTRACTOR_MetaType type,
331 enum EXTRACTOR_MetaFormat format, 331 enum EXTRACTOR_MetaFormat format,
332 const char *data_mime_type, 332 const char *data_mime_type,
333 const char *data, 333 const char *data,
334 size_t data_len) 334 size_t data_len)
335{ 335{
336 struct InProcessContext *ctx = cls; 336 struct InProcessContext *ctx = cls;
337 int ret; 337 int ret;
@@ -339,12 +339,12 @@ in_process_proc (void *cls,
339 if (0 != ctx->finished) 339 if (0 != ctx->finished)
340 return 1; 340 return 1;
341 ret = ctx->proc (ctx->proc_cls, 341 ret = ctx->proc (ctx->proc_cls,
342 plugin_name, 342 plugin_name,
343 type, 343 type,
344 format, 344 format,
345 data_mime_type, 345 data_mime_type,
346 data, 346 data,
347 data_len); 347 data_len);
348 if (0 != ret) 348 if (0 != ret)
349 ctx->finished = 1; 349 ctx->finished = 1;
350 return ret; 350 return ret;
@@ -363,9 +363,9 @@ in_process_proc (void *cls,
363 */ 363 */
364static void 364static void
365do_extract (struct EXTRACTOR_PluginList *plugins, 365do_extract (struct EXTRACTOR_PluginList *plugins,
366 struct EXTRACTOR_SharedMemory *shm, 366 struct EXTRACTOR_SharedMemory *shm,
367 struct EXTRACTOR_Datasource *ds, 367 struct EXTRACTOR_Datasource *ds,
368 EXTRACTOR_MetaDataProcessor proc, void *proc_cls) 368 EXTRACTOR_MetaDataProcessor proc, void *proc_cls)
369{ 369{
370 unsigned int plugin_count; 370 unsigned int plugin_count;
371 unsigned int plugin_off; 371 unsigned int plugin_off;
@@ -406,153 +406,153 @@ do_extract (struct EXTRACTOR_PluginList *plugins,
406 start.shm_ready_bytes = (uint32_t) ready; 406 start.shm_ready_bytes = (uint32_t) ready;
407 start.file_size = EXTRACTOR_datasource_get_size_ (ds, 0); 407 start.file_size = EXTRACTOR_datasource_get_size_ (ds, 0);
408 for (pos = plugins; NULL != pos; pos = pos->next) 408 for (pos = plugins; NULL != pos; pos = pos->next)
409 {
410 if (EXTRACTOR_OPTION_IN_PROCESS == pos->flags)
411 have_in_memory = 1;
412 if ( (NULL != pos->channel) &&
413 (-1 == EXTRACTOR_IPC_channel_send_ (pos->channel,
414 &start,
415 sizeof (start)) ) )
409 { 416 {
410 if (EXTRACTOR_OPTION_IN_PROCESS == pos->flags) 417 LOG ("Failed to send EXTRACT_START message to plugin\n");
411 have_in_memory = 1; 418 EXTRACTOR_IPC_channel_destroy_ (pos->channel);
412 if ( (NULL != pos->channel) && 419 pos->channel = NULL;
413 (-1 == EXTRACTOR_IPC_channel_send_ (pos->channel,
414 &start,
415 sizeof (start)) ) )
416 {
417 LOG ("Failed to send EXTRACT_START message to plugin\n");
418 EXTRACTOR_IPC_channel_destroy_ (pos->channel);
419 pos->channel = NULL;
420 }
421 } 420 }
421 }
422 if (-1 == ready) 422 if (-1 == ready)
423 { 423 {
424 LOG ("Failed to initialize IPC shared memory, cannot extract\n"); 424 LOG ("Failed to initialize IPC shared memory, cannot extract\n");
425 done = 1; 425 done = 1;
426 } 426 }
427 else 427 else
428 done = 0; 428 done = 0;
429 while (! done) 429 while (! done)
430 {
431 struct EXTRACTOR_Channel *channels[plugin_count];
432
433 /* calculate current 'channels' array */
434 plugin_off = 0;
435 for (pos = plugins; NULL != pos; pos = pos->next)
430 { 436 {
431 struct EXTRACTOR_Channel *channels[plugin_count]; 437 if (-1 == pos->seek_request)
432 438 {
433 /* calculate current 'channels' array */ 439 /* channel is not seeking, must be running or done */
434 plugin_off = 0; 440 channels[plugin_off] = pos->channel;
435 for (pos = plugins; NULL != pos; pos = pos->next) 441 }
436 { 442 else
437 if (-1 == pos->seek_request) 443 {
438 { 444 /* not running this round, seeking! */
439 /* channel is not seeking, must be running or done */ 445 channels[plugin_off] = NULL;
440 channels[plugin_off] = pos->channel; 446 }
441 } 447 plugin_off++;
442 else 448 }
443 { 449 /* give plugins chance to send us meta data, seek or finished messages */
444 /* not running this round, seeking! */ 450 if (-1 ==
445 channels[plugin_off] = NULL; 451 EXTRACTOR_IPC_channel_recv_ (channels,
446 } 452 plugin_count,
447 plugin_off++; 453 &process_plugin_reply,
448 } 454 &prp))
449 /* give plugins chance to send us meta data, seek or finished messages */ 455 {
450 if (-1 == 456 /* serious problem in IPC; reset *all* channels */
451 EXTRACTOR_IPC_channel_recv_ (channels, 457 LOG ("Failed to receive message from channels; full reset\n");
452 plugin_count, 458 abort_all_channels (plugins);
453 &process_plugin_reply, 459 break;
454 &prp)) 460 }
455 { 461
456 /* serious problem in IPC; reset *all* channels */ 462 /* calculate minimum seek request (or set done=0 to continue here) */
457 LOG ("Failed to receive message from channels; full reset\n"); 463 done = 1;
458 abort_all_channels (plugins); 464 min_seek = -1;
459 break; 465 plugin_off = 0;
460 } 466 for (pos = plugins; NULL != pos; pos = pos->next)
461 467 {
462 /* calculate minimum seek request (or set done=0 to continue here) */ 468 plugin_off++;
463 done = 1; 469 if ( (1 == pos->round_finished) ||
464 min_seek = -1; 470 (NULL == pos->channel) )
465 plugin_off = 0; 471 {
466 for (pos = plugins; NULL != pos; pos = pos->next) 472 continue; /* inactive plugin */
467 { 473 }
468 plugin_off++; 474 if (-1 == pos->seek_request)
469 if ( (1 == pos->round_finished) || 475 {
470 (NULL == pos->channel) ) 476 /* possibly more meta data at current position, at least
477 this plugin is still working on it... */
478 done = 0;
479 break;
480 }
481 if (-1 != pos->seek_request)
482 {
483 if (SEEK_END == pos->seek_whence)
484 {
485 /* convert distance from end to absolute position */
486 pos->seek_whence = 0;
487 end = EXTRACTOR_datasource_get_size_ (ds, 1);
488 if (pos->seek_request > end)
471 { 489 {
472 continue; /* inactive plugin */ 490 LOG ("Cannot seek to before the beginning of the file!\n");
491 pos->seek_request = 0;
473 } 492 }
474 if (-1 == pos->seek_request) 493 else
475 { 494 {
476 /* possibly more meta data at current position, at least 495 pos->seek_request = end - pos->seek_request;
477 this plugin is still working on it... */ 496 }
478 done = 0; 497 }
479 break; 498 if ( (-1 == min_seek) ||
480 } 499 (min_seek > pos->seek_request) )
481 if (-1 != pos->seek_request) 500 {
482 { 501 min_seek = pos->seek_request;
483 if (SEEK_END == pos->seek_whence) 502 }
484 { 503 }
485 /* convert distance from end to absolute position */ 504 }
486 pos->seek_whence = 0; 505 data_available = -1;
487 end = EXTRACTOR_datasource_get_size_ (ds, 1); 506 if ( (1 == done) &&
488 if (pos->seek_request > end) 507 (-1 != min_seek) &&
489 { 508 (NULL != shm) )
490 LOG ("Cannot seek to before the beginning of the file!\n"); 509 {
491 pos->seek_request = 0; 510 /* current position done, but seek requested */
492 } 511 done = 0;
493 else 512 if (-1 ==
494 { 513 (data_available = EXTRACTOR_IPC_shared_memory_set_ (shm,
495 pos->seek_request = end - pos->seek_request; 514 ds,
496 } 515 min_seek,
497 } 516 DEFAULT_SHM_SIZE)))
498 if ( (-1 == min_seek) || 517 {
499 (min_seek > pos->seek_request) ) 518 LOG ("Failed to seek; full reset\n");
500 { 519 abort_all_channels (plugins);
501 min_seek = pos->seek_request; 520 break;
502 } 521 }
503 } 522 }
504 } 523 /* if 'prp.file_finished', send 'abort' to plugins;
505 data_available = -1; 524 if not, send 'seek' notification to plugins in range */
506 if ( (1 == done) && 525 for (pos = plugins; NULL != pos; pos = pos->next)
507 (-1 != min_seek) && 526 {
508 (NULL != shm) ) 527 if (NULL == (channel = pos->channel))
509 { 528 {
510 /* current position done, but seek requested */ 529 /* Skipping plugin: channel down */
511 done = 0; 530 continue;
512 if (-1 == 531 }
513 (data_available = EXTRACTOR_IPC_shared_memory_set_ (shm, 532 if ( (-1 != pos->seek_request) &&
514 ds, 533 (1 == prp.file_finished) )
515 min_seek, 534 {
516 DEFAULT_SHM_SIZE))) 535 send_discard_message (pos);
517 { 536 pos->round_finished = 1;
518 LOG ("Failed to seek; full reset\n"); 537 pos->seek_request = -1;
519 abort_all_channels (plugins); 538 }
520 break; 539 if ( (-1 != data_available) &&
521 } 540 (-1 != pos->seek_request) &&
522 } 541 (min_seek <= pos->seek_request) &&
523 /* if 'prp.file_finished', send 'abort' to plugins; 542 ( (min_seek + data_available > pos->seek_request) ||
524 if not, send 'seek' notification to plugins in range */ 543 (min_seek == EXTRACTOR_datasource_get_size_ (ds, 0))) )
525 for (pos = plugins; NULL != pos; pos = pos->next) 544 {
526 { 545 /* Notify plugin about seek to 'min_seek' */
527 if (NULL == (channel = pos->channel)) 546 send_update_message (pos,
528 { 547 min_seek,
529 /* Skipping plugin: channel down */ 548 data_available,
530 continue; 549 ds);
531 } 550 pos->seek_request = -1;
532 if ( (-1 != pos->seek_request) && 551 }
533 (1 == prp.file_finished) ) 552 if (0 == pos->round_finished)
534 { 553 done = 0; /* can't be done, plugin still active */
535 send_discard_message (pos);
536 pos->round_finished = 1;
537 pos->seek_request = -1;
538 }
539 if ( (-1 != data_available) &&
540 (-1 != pos->seek_request) &&
541 (min_seek <= pos->seek_request) &&
542 ( (min_seek + data_available > pos->seek_request) ||
543 (min_seek == EXTRACTOR_datasource_get_size_ (ds, 0))) )
544 {
545 /* Notify plugin about seek to 'min_seek' */
546 send_update_message (pos,
547 min_seek,
548 data_available,
549 ds);
550 pos->seek_request = -1;
551 }
552 if (0 == pos->round_finished)
553 done = 0; /* can't be done, plugin still active */
554 }
555 } 554 }
555 }
556 556
557 if (0 == have_in_memory) 557 if (0 == have_in_memory)
558 return; 558 return;
@@ -567,22 +567,22 @@ do_extract (struct EXTRACTOR_PluginList *plugins,
567 ec.get_size = &in_process_get_size; 567 ec.get_size = &in_process_get_size;
568 ec.proc = &in_process_proc; 568 ec.proc = &in_process_proc;
569 for (pos = plugins; NULL != pos; pos = pos->next) 569 for (pos = plugins; NULL != pos; pos = pos->next)
570 {
571 if (EXTRACTOR_OPTION_IN_PROCESS != pos->flags)
572 continue;
573 if (-1 == EXTRACTOR_plugin_load_ (pos))
574 continue;
575 ctx.plugin = pos;
576 ec.config = pos->plugin_options;
577 if (-1 == EXTRACTOR_datasource_seek_ (ds, 0, SEEK_SET))
570 { 578 {
571 if (EXTRACTOR_OPTION_IN_PROCESS != pos->flags) 579 LOG ("Failed to seek to 0 for in-memory plugins\n");
572 continue; 580 return;
573 if (-1 == EXTRACTOR_plugin_load_ (pos))
574 continue;
575 ctx.plugin = pos;
576 ec.config = pos->plugin_options;
577 if (-1 == EXTRACTOR_datasource_seek_ (ds, 0, SEEK_SET))
578 {
579 LOG ("Failed to seek to 0 for in-memory plugins\n");
580 return;
581 }
582 pos->extract_method (&ec);
583 if (1 == ctx.finished)
584 break;
585 } 581 }
582 pos->extract_method (&ec);
583 if (1 == ctx.finished)
584 break;
585 }
586} 586}
587 587
588 588
@@ -602,11 +602,11 @@ do_extract (struct EXTRACTOR_PluginList *plugins,
602 */ 602 */
603void 603void
604EXTRACTOR_extract (struct EXTRACTOR_PluginList *plugins, 604EXTRACTOR_extract (struct EXTRACTOR_PluginList *plugins,
605 const char *filename, 605 const char *filename,
606 const void *data, 606 const void *data,
607 size_t size, 607 size_t size,
608 EXTRACTOR_MetaDataProcessor proc, 608 EXTRACTOR_MetaDataProcessor proc,
609 void *proc_cls) 609 void *proc_cls)
610{ 610{
611 struct EXTRACTOR_Datasource *datasource; 611 struct EXTRACTOR_Datasource *datasource;
612 struct EXTRACTOR_SharedMemory *shm; 612 struct EXTRACTOR_SharedMemory *shm;
@@ -617,47 +617,47 @@ EXTRACTOR_extract (struct EXTRACTOR_PluginList *plugins,
617 return; 617 return;
618 if (NULL == filename) 618 if (NULL == filename)
619 datasource = EXTRACTOR_datasource_create_from_buffer_ (data, size, 619 datasource = EXTRACTOR_datasource_create_from_buffer_ (data, size,
620 proc, proc_cls); 620 proc, proc_cls);
621 else 621 else
622 datasource = EXTRACTOR_datasource_create_from_file_ (filename, 622 datasource = EXTRACTOR_datasource_create_from_file_ (filename,
623 proc, proc_cls); 623 proc, proc_cls);
624 if (NULL == datasource) 624 if (NULL == datasource)
625 return; 625 return;
626 shm = NULL; 626 shm = NULL;
627 have_oop = 0; 627 have_oop = 0;
628 for (pos = plugins; NULL != pos; pos = pos->next) 628 for (pos = plugins; NULL != pos; pos = pos->next)
629 { 629 {
630 if (NULL == shm) 630 if (NULL == shm)
631 shm = pos->shm; 631 shm = pos->shm;
632 if (EXTRACTOR_OPTION_IN_PROCESS != pos->flags) 632 if (EXTRACTOR_OPTION_IN_PROCESS != pos->flags)
633 have_oop = 1; 633 have_oop = 1;
634 pos->round_finished = 0; 634 pos->round_finished = 0;
635 } 635 }
636 if ( (NULL == shm) && 636 if ( (NULL == shm) &&
637 (1 == have_oop) ) 637 (1 == have_oop) )
638 {
639 /* need to create shared memory segment */
640 shm = EXTRACTOR_IPC_shared_memory_create_ (DEFAULT_SHM_SIZE);
641 if (NULL == shm)
638 { 642 {
639 /* need to create shared memory segment */ 643 LOG ("Failed to setup IPC\n");
640 shm = EXTRACTOR_IPC_shared_memory_create_ (DEFAULT_SHM_SIZE); 644 EXTRACTOR_datasource_destroy_ (datasource);
641 if (NULL == shm) 645 return;
642 {
643 LOG ("Failed to setup IPC\n");
644 EXTRACTOR_datasource_destroy_ (datasource);
645 return;
646 }
647 } 646 }
647 }
648 for (pos = plugins; NULL != pos; pos = pos->next) 648 for (pos = plugins; NULL != pos; pos = pos->next)
649 if ( (NULL == pos->channel) && 649 if ( (NULL == pos->channel) &&
650 (NULL != shm) && 650 (NULL != shm) &&
651 (EXTRACTOR_OPTION_IN_PROCESS != pos->flags) ) 651 (EXTRACTOR_OPTION_IN_PROCESS != pos->flags) )
652 {
653 if (NULL == pos->shm)
652 { 654 {
653 if (NULL == pos->shm) 655 pos->shm = shm;
654 { 656 (void) EXTRACTOR_IPC_shared_memory_change_rc_ (shm, 1);
655 pos->shm = shm;
656 (void) EXTRACTOR_IPC_shared_memory_change_rc_ (shm, 1);
657 }
658 pos->channel = EXTRACTOR_IPC_channel_create_ (pos,
659 shm);
660 } 657 }
658 pos->channel = EXTRACTOR_IPC_channel_create_ (pos,
659 shm);
660 }
661 do_extract (plugins, 661 do_extract (plugins,
662 shm, 662 shm,
663 datasource, 663 datasource,
@@ -680,14 +680,14 @@ EXTRACTOR_ltdl_init ()
680#endif 680#endif
681 err = lt_dlinit (); 681 err = lt_dlinit ();
682 if (err > 0) 682 if (err > 0)
683 { 683 {
684#if DEBUG 684#if DEBUG
685 fprintf (stderr, 685 fprintf (stderr,
686 _("Initialization of plugin mechanism failed: %s!\n"), 686 _ ("Initialization of plugin mechanism failed: %s!\n"),
687 lt_dlerror ()); 687 lt_dlerror ());
688#endif 688#endif
689 return; 689 return;
690 } 690 }
691#if WINDOWS 691#if WINDOWS
692 plibc_init_utf8 ("GNU", PACKAGE, 1); 692 plibc_init_utf8 ("GNU", PACKAGE, 1);
693 plibc_set_stat_size_size (sizeof (((struct stat *) 0)->st_size)); 693 plibc_set_stat_size_size (sizeof (((struct stat *) 0)->st_size));
@@ -700,11 +700,13 @@ EXTRACTOR_ltdl_init ()
700 * Deinit. 700 * Deinit.
701 */ 701 */
702void __attribute__ ((destructor)) 702void __attribute__ ((destructor))
703EXTRACTOR_ltdl_fini () { 703EXTRACTOR_ltdl_fini ()
704{
704#if WINDOWS 705#if WINDOWS
705 plibc_shutdown (); 706 plibc_shutdown ();
706#endif 707#endif
707 lt_dlexit (); 708 lt_dlexit ();
708} 709}
709 710
711
710/* end of extractor.c */ 712/* end of extractor.c */
diff --git a/src/main/extractor_common.c b/src/main/extractor_common.c
index 866609e..59524b3 100644
--- a/src/main/extractor_common.c
+++ b/src/main/extractor_common.c
@@ -39,27 +39,27 @@
39 * @param buf buffer to read from 39 * @param buf buffer to read from
40 * @param size number of bytes to write 40 * @param size number of bytes to write
41 * @return number of bytes written (that is 'size'), or -1 on error 41 * @return number of bytes written (that is 'size'), or -1 on error
42 */ 42 */
43ssize_t 43ssize_t
44EXTRACTOR_write_all_ (int fd, 44EXTRACTOR_write_all_ (int fd,
45 const void *buf, 45 const void *buf,
46 size_t size) 46 size_t size)
47{ 47{
48 const char *data = buf; 48 const char *data = buf;
49 size_t off = 0; 49 size_t off = 0;
50 ssize_t ret; 50 ssize_t ret;
51 51
52 while (off < size) 52 while (off < size)
53 {
54 ret = write (fd, &data[off], size - off);
55 if (ret <= 0)
53 { 56 {
54 ret = write (fd, &data[off], size - off); 57 if (-1 == ret)
55 if (ret <= 0) 58 LOG_STRERROR ("write");
56 { 59 return -1;
57 if (-1 == ret)
58 LOG_STRERROR ("write");
59 return -1;
60 }
61 off += ret;
62 } 60 }
61 off += ret;
62 }
63 return size; 63 return size;
64} 64}
65 65
@@ -74,28 +74,27 @@ EXTRACTOR_write_all_ (int fd,
74 */ 74 */
75ssize_t 75ssize_t
76EXTRACTOR_read_all_ (int fd, 76EXTRACTOR_read_all_ (int fd,
77 void *buf, 77 void *buf,
78 size_t size) 78 size_t size)
79{ 79{
80 char *data = buf; 80 char *data = buf;
81 size_t off = 0; 81 size_t off = 0;
82 ssize_t ret; 82 ssize_t ret;
83 83
84 while (off < size) 84 while (off < size)
85 {
86 ret = read (fd, &data[off], size - off);
87 if (ret <= 0)
85 { 88 {
86 ret = read (fd, &data[off], size - off); 89 if (-1 == ret)
87 if (ret <= 0) 90 LOG_STRERROR ("write");
88 { 91 return -1;
89 if (-1 == ret)
90 LOG_STRERROR ("write");
91 return -1;
92 }
93 off += ret;
94 } 92 }
93 off += ret;
94 }
95 return size; 95 return size;
96
97}
98 96
97}
99 98
100 99
101/* end of extractor_common.c */ 100/* end of extractor_common.c */
diff --git a/src/main/extractor_common.h b/src/main/extractor_common.h
index 14b1c7f..5887c05 100644
--- a/src/main/extractor_common.h
+++ b/src/main/extractor_common.h
@@ -35,11 +35,11 @@
35 * @param buf buffer to read from 35 * @param buf buffer to read from
36 * @param size number of bytes to write 36 * @param size number of bytes to write
37 * @return number of bytes written (that is 'size'), or -1 on error 37 * @return number of bytes written (that is 'size'), or -1 on error
38 */ 38 */
39ssize_t 39ssize_t
40EXTRACTOR_write_all_ (int fd, 40EXTRACTOR_write_all_ (int fd,
41 const void *buf, 41 const void *buf,
42 size_t size); 42 size_t size);
43 43
44 44
45/** 45/**
@@ -52,8 +52,8 @@ EXTRACTOR_write_all_ (int fd,
52 */ 52 */
53ssize_t 53ssize_t
54EXTRACTOR_read_all_ (int fd, 54EXTRACTOR_read_all_ (int fd,
55 void *buf, 55 void *buf,
56 size_t size); 56 size_t size);
57 57
58 58
59#endif 59#endif
diff --git a/src/main/extractor_datasource.c b/src/main/extractor_datasource.c
index 888e524..0b18d7c 100644
--- a/src/main/extractor_datasource.c
+++ b/src/main/extractor_datasource.c
@@ -214,35 +214,35 @@ struct CompressedFileSource
214 */ 214 */
215static int 215static int
216bfds_pick_next_buffer_at (struct BufferedFileDataSource *bfds, 216bfds_pick_next_buffer_at (struct BufferedFileDataSource *bfds,
217 uint64_t pos) 217 uint64_t pos)
218{ 218{
219 int64_t position; 219 int64_t position;
220 ssize_t rd; 220 ssize_t rd;
221 221
222 if (pos > bfds->fsize) 222 if (pos > bfds->fsize)
223 { 223 {
224 LOG ("Invalid seek operation\n"); 224 LOG ("Invalid seek operation\n");
225 return -1; /* invalid */ 225 return -1; /* invalid */
226 } 226 }
227 if (NULL == bfds->buffer) 227 if (NULL == bfds->buffer)
228 { 228 {
229 bfds->buffer_pos = pos; 229 bfds->buffer_pos = pos;
230 return 0; 230 return 0;
231 } 231 }
232 position = (int64_t) LSEEK (bfds->fd, pos, SEEK_SET); 232 position = (int64_t) LSEEK (bfds->fd, pos, SEEK_SET);
233 if (position < 0) 233 if (position < 0)
234 { 234 {
235 LOG_STRERROR ("lseek"); 235 LOG_STRERROR ("lseek");
236 return -1; 236 return -1;
237 } 237 }
238 bfds->fpos = position; 238 bfds->fpos = position;
239 bfds->buffer_pos = 0; 239 bfds->buffer_pos = 0;
240 rd = read (bfds->fd, bfds->buffer, bfds->buffer_size); 240 rd = read (bfds->fd, bfds->buffer, bfds->buffer_size);
241 if (rd < 0) 241 if (rd < 0)
242 { 242 {
243 LOG_STRERROR ("read"); 243 LOG_STRERROR ("read");
244 return -1; 244 return -1;
245 } 245 }
246 bfds->buffer_bytes = rd; 246 bfds->buffer_bytes = rd;
247 return 0; 247 return 0;
248} 248}
@@ -258,8 +258,8 @@ bfds_pick_next_buffer_at (struct BufferedFileDataSource *bfds,
258 */ 258 */
259static struct BufferedFileDataSource * 259static struct BufferedFileDataSource *
260bfds_new (const void *data, 260bfds_new (const void *data,
261 int fd, 261 int fd,
262 int64_t fsize) 262 int64_t fsize)
263{ 263{
264 struct BufferedFileDataSource *result; 264 struct BufferedFileDataSource *result;
265 size_t xtra; 265 size_t xtra;
@@ -269,19 +269,19 @@ bfds_new (const void *data,
269 else 269 else
270 xtra = (size_t) fsize; 270 xtra = (size_t) fsize;
271 if ( (-1 == fd) && (NULL == data) ) 271 if ( (-1 == fd) && (NULL == data) )
272 { 272 {
273 LOG ("Invalid arguments\n"); 273 LOG ("Invalid arguments\n");
274 return NULL; 274 return NULL;
275 } 275 }
276 if ( (-1 != fd) && (NULL != data) ) 276 if ( (-1 != fd) && (NULL != data) )
277 fd = -1; /* don't need fd */ 277 fd = -1; /* don't need fd */
278 if (NULL != data) 278 if (NULL != data)
279 xtra = 0; 279 xtra = 0;
280 if (NULL == (result = malloc (sizeof (struct BufferedFileDataSource) + xtra))) 280 if (NULL == (result = malloc (sizeof (struct BufferedFileDataSource) + xtra)))
281 { 281 {
282 LOG_STRERROR ("malloc"); 282 LOG_STRERROR ("malloc");
283 return NULL; 283 return NULL;
284 } 284 }
285 memset (result, 0, sizeof (struct BufferedFileDataSource)); 285 memset (result, 0, sizeof (struct BufferedFileDataSource));
286 result->data = (NULL != data) ? data : &result[1]; 286 result->data = (NULL != data) ? data : &result[1];
287 result->buffer = (NULL != data) ? NULL : &result[1]; 287 result->buffer = (NULL != data) ? NULL : &result[1];
@@ -318,79 +318,79 @@ bfds_delete (struct BufferedFileDataSource *bfds)
318 */ 318 */
319static int64_t 319static int64_t
320bfds_seek (struct BufferedFileDataSource *bfds, 320bfds_seek (struct BufferedFileDataSource *bfds,
321 int64_t pos, int whence) 321 int64_t pos, int whence)
322{ 322{
323 uint64_t npos; 323 uint64_t npos;
324 size_t nbpos; 324 size_t nbpos;
325 325
326 switch (whence) 326 switch (whence)
327 {
328 case SEEK_CUR:
329 npos = bfds->fpos + bfds->buffer_pos + pos;
330 if (npos > bfds->fsize)
327 { 331 {
328 case SEEK_CUR: 332 LOG ("Invalid seek operation to %lld from %llu (max is %llu)\n",
329 npos = bfds->fpos + bfds->buffer_pos + pos; 333 (long long) pos,
330 if (npos > bfds->fsize) 334 bfds->fpos + bfds->buffer_pos,
331 { 335 (unsigned long long) bfds->fsize);
332 LOG ("Invalid seek operation to %lld from %llu (max is %llu)\n", 336 return -1;
333 (long long) pos, 337 }
334 bfds->fpos + bfds->buffer_pos, 338 nbpos = bfds->buffer_pos + pos;
335 (unsigned long long) bfds->fsize); 339 if ( (NULL == bfds->buffer) ||
336 return -1; 340 (nbpos < bfds->buffer_bytes) )
337 } 341 {
338 nbpos = bfds->buffer_pos + pos; 342 bfds->buffer_pos = nbpos;
339 if ( (NULL == bfds->buffer) ||
340 (nbpos < bfds->buffer_bytes) )
341 {
342 bfds->buffer_pos = nbpos;
343 return npos;
344 }
345 if (0 != bfds_pick_next_buffer_at (bfds,
346 npos))
347 {
348 LOG ("seek operation failed\n");
349 return -1;
350 }
351 return npos; 343 return npos;
352 case SEEK_END: 344 }
353 if (pos > 0) 345 if (0 != bfds_pick_next_buffer_at (bfds,
354 { 346 npos))
355 LOG ("Invalid seek operation\n"); 347 {
356 return -1; 348 LOG ("seek operation failed\n");
357 } 349 return -1;
358 if (bfds->fsize < - pos) 350 }
359 { 351 return npos;
360 LOG ("Invalid seek operation\n"); 352 case SEEK_END:
361 return -1; 353 if (pos > 0)
362 } 354 {
363 pos = bfds->fsize + pos; 355 LOG ("Invalid seek operation\n");
364 /* fall-through! */ 356 return -1;
365 case SEEK_SET: 357 }
366 if (pos < 0) 358 if (bfds->fsize < -pos)
367 { 359 {
368 LOG ("Invalid seek operation\n"); 360 LOG ("Invalid seek operation\n");
369 return -1; 361 return -1;
370 } 362 }
371 if (pos > bfds->fsize) 363 pos = bfds->fsize + pos;
372 { 364 /* fall-through! */
373 LOG ("Invalid seek operation (%lld > %llu) %d\n", 365 case SEEK_SET:
374 (long long) pos, 366 if (pos < 0)
375 (unsigned long long) bfds->fsize, 367 {
376 SEEK_SET == whence); 368 LOG ("Invalid seek operation\n");
377 return -1; 369 return -1;
378 } 370 }
379 if ( (NULL == bfds->buffer) || 371 if (pos > bfds->fsize)
380 ( (bfds->fpos <= pos) && 372 {
381 (bfds->fpos + bfds->buffer_bytes > pos) ) ) 373 LOG ("Invalid seek operation (%lld > %llu) %d\n",
382 { 374 (long long) pos,
383 bfds->buffer_pos = pos - bfds->fpos; 375 (unsigned long long) bfds->fsize,
384 return pos; 376 SEEK_SET == whence);
385 } 377 return -1;
386 if (0 != bfds_pick_next_buffer_at (bfds, pos)) 378 }
387 { 379 if ( (NULL == bfds->buffer) ||
388 LOG ("seek operation failed\n"); 380 ( (bfds->fpos <= pos) &&
389 return -1; 381 (bfds->fpos + bfds->buffer_bytes > pos) ) )
390 } 382 {
391 ASSERT (pos == bfds->fpos + bfds->buffer_pos); 383 bfds->buffer_pos = pos - bfds->fpos;
392 return pos; 384 return pos;
393 } 385 }
386 if (0 != bfds_pick_next_buffer_at (bfds, pos))
387 {
388 LOG ("seek operation failed\n");
389 return -1;
390 }
391 ASSERT (pos == bfds->fpos + bfds->buffer_pos);
392 return pos;
393 }
394 return -1; 394 return -1;
395} 395}
396 396
@@ -407,8 +407,8 @@ bfds_seek (struct BufferedFileDataSource *bfds,
407 */ 407 */
408static ssize_t 408static ssize_t
409bfds_read (struct BufferedFileDataSource *bfds, 409bfds_read (struct BufferedFileDataSource *bfds,
410 void *buf_ptr, 410 void *buf_ptr,
411 size_t count) 411 size_t count)
412{ 412{
413 char *cbuf = buf_ptr; 413 char *cbuf = buf_ptr;
414 uint64_t old_off; 414 uint64_t old_off;
@@ -420,28 +420,28 @@ bfds_read (struct BufferedFileDataSource *bfds,
420 return 0; /* end of stream */ 420 return 0; /* end of stream */
421 ret = 0; 421 ret = 0;
422 while (count > 0) 422 while (count > 0)
423 {
424 if ( (bfds->buffer_bytes == bfds->buffer_pos) &&
425 (0 != bfds_pick_next_buffer_at (bfds,
426 bfds->fpos + bfds->buffer_bytes)) )
423 { 427 {
424 if ( (bfds->buffer_bytes == bfds->buffer_pos) && 428 /* revert to original position, invalidate buffer */
425 (0 != bfds_pick_next_buffer_at (bfds, 429 bfds->fpos = old_off;
426 bfds->fpos + bfds->buffer_bytes)) ) 430 bfds->buffer_bytes = 0;
427 { 431 bfds->buffer_pos = 0;
428 /* revert to original position, invalidate buffer */ 432 LOG ("read operation failed\n");
429 bfds->fpos = old_off; 433 return -1; /* getting more failed */
430 bfds->buffer_bytes = 0;
431 bfds->buffer_pos = 0;
432 LOG ("read operation failed\n");
433 return -1; /* getting more failed */
434 }
435 avail = bfds->buffer_bytes - bfds->buffer_pos;
436 if (avail > count)
437 avail = count;
438 if (0 == avail)
439 break;
440 memcpy (&cbuf[ret], bfds->data + bfds->buffer_pos, avail);
441 bfds->buffer_pos += avail;
442 count -= avail;
443 ret += avail;
444 } 434 }
435 avail = bfds->buffer_bytes - bfds->buffer_pos;
436 if (avail > count)
437 avail = count;
438 if (0 == avail)
439 break;
440 memcpy (&cbuf[ret], bfds->data + bfds->buffer_pos, avail);
441 bfds->buffer_pos += avail;
442 count -= avail;
443 ret += avail;
444 }
445 return ret; 445 return ret;
446} 446}
447 447
@@ -458,17 +458,17 @@ bfds_read (struct BufferedFileDataSource *bfds,
458 */ 458 */
459static int 459static int
460cfs_init_decompressor_zlib (struct CompressedFileSource *cfs, 460cfs_init_decompressor_zlib (struct CompressedFileSource *cfs,
461 EXTRACTOR_MetaDataProcessor proc, void *proc_cls) 461 EXTRACTOR_MetaDataProcessor proc, void *proc_cls)
462{ 462{
463 unsigned int gzip_header_length = 10; 463 unsigned int gzip_header_length = 10;
464 unsigned char hdata[12]; 464 unsigned char hdata[12];
465 ssize_t rsize; 465 ssize_t rsize;
466 466
467 if (0 != bfds_seek (cfs->bfds, 0, SEEK_SET)) 467 if (0 != bfds_seek (cfs->bfds, 0, SEEK_SET))
468 { 468 {
469 LOG ("Failed to seek to offset 0!\n"); 469 LOG ("Failed to seek to offset 0!\n");
470 return -1; 470 return -1;
471 } 471 }
472 /* Process gzip header */ 472 /* Process gzip header */
473 rsize = bfds_read (cfs->bfds, hdata, sizeof (hdata)); 473 rsize = bfds_read (cfs->bfds, hdata, sizeof (hdata));
474 if ( (-1 == rsize) || 474 if ( (-1 == rsize) ||
@@ -478,72 +478,74 @@ cfs_init_decompressor_zlib (struct CompressedFileSource *cfs,
478 gzip_header_length += 2 + (hdata[10] & 0xff) + ((hdata[11] & 0xff) * 256); 478 gzip_header_length += 2 + (hdata[10] & 0xff) + ((hdata[11] & 0xff) * 256);
479 479
480 if (0 != (hdata[3] & 0x8)) 480 if (0 != (hdata[3] & 0x8))
481 {
482 /* FNAME set */
483 char fname[1024];
484 char *cptr;
485 size_t len;
486 ssize_t buf_bytes;
487
488 if (gzip_header_length > bfds_seek (cfs->bfds, gzip_header_length,
489 SEEK_SET))
481 { 490 {
482 /* FNAME set */ 491 LOG ("Corrupt gzip, failed to seek to end of header\n");
483 char fname[1024]; 492 return -1;
484 char *cptr;
485 size_t len;
486 ssize_t buf_bytes;
487
488 if (gzip_header_length > bfds_seek (cfs->bfds, gzip_header_length, SEEK_SET))
489 {
490 LOG ("Corrupt gzip, failed to seek to end of header\n");
491 return -1;
492 }
493 buf_bytes = bfds_read (cfs->bfds, fname, sizeof (fname));
494 if (buf_bytes <= 0)
495 {
496 LOG ("Corrupt gzip, failed to read filename\n");
497 return -1;
498 }
499 if (NULL == (cptr = memchr (fname, 0, buf_bytes)))
500 {
501 LOG ("Corrupt gzip, failed to read filename terminator\n");
502 return -1;
503 }
504 len = cptr - fname;
505 if ( (NULL != proc) &&
506 (0 != proc (proc_cls, "<zlib>", EXTRACTOR_METATYPE_FILENAME,
507 EXTRACTOR_METAFORMAT_C_STRING, "text/plain",
508 fname,
509 len)) )
510 return 0; /* done */
511 gzip_header_length += len + 1;
512 } 493 }
494 buf_bytes = bfds_read (cfs->bfds, fname, sizeof (fname));
495 if (buf_bytes <= 0)
496 {
497 LOG ("Corrupt gzip, failed to read filename\n");
498 return -1;
499 }
500 if (NULL == (cptr = memchr (fname, 0, buf_bytes)))
501 {
502 LOG ("Corrupt gzip, failed to read filename terminator\n");
503 return -1;
504 }
505 len = cptr - fname;
506 if ( (NULL != proc) &&
507 (0 != proc (proc_cls, "<zlib>", EXTRACTOR_METATYPE_FILENAME,
508 EXTRACTOR_METAFORMAT_C_STRING, "text/plain",
509 fname,
510 len)) )
511 return 0; /* done */
512 gzip_header_length += len + 1;
513 }
513 514
514 if (0 != (hdata[3] & 0x16)) 515 if (0 != (hdata[3] & 0x16))
516 {
517 /* FCOMMENT set */
518 char fcomment[1024];
519 char *cptr;
520 ssize_t buf_bytes;
521 size_t len;
522
523 if (gzip_header_length > bfds_seek (cfs->bfds, gzip_header_length,
524 SEEK_SET))
515 { 525 {
516 /* FCOMMENT set */ 526 LOG ("Corrupt gzip, failed to seek to end of header\n");
517 char fcomment[1024]; 527 return -1;
518 char *cptr; 528 }
519 ssize_t buf_bytes; 529 buf_bytes = bfds_read (cfs->bfds, fcomment, sizeof (fcomment));
520 size_t len; 530 if (buf_bytes <= 0)
521 531 {
522 if (gzip_header_length > bfds_seek (cfs->bfds, gzip_header_length, SEEK_SET)) 532 LOG ("Corrupt gzip, failed to read comment\n");
523 { 533 return -1;
524 LOG ("Corrupt gzip, failed to seek to end of header\n"); 534 }
525 return -1; 535 if (NULL == (cptr = memchr (fcomment, 0, buf_bytes)))
526 } 536 {
527 buf_bytes = bfds_read (cfs->bfds, fcomment, sizeof (fcomment)); 537 LOG ("Corrupt gzip, failed to read comment terminator\n");
528 if (buf_bytes <= 0) 538 return -1;
529 {
530 LOG ("Corrupt gzip, failed to read comment\n");
531 return -1;
532 }
533 if (NULL == (cptr = memchr (fcomment, 0, buf_bytes)))
534 {
535 LOG ("Corrupt gzip, failed to read comment terminator\n");
536 return -1;
537 }
538 len = cptr - fcomment;
539 if ( (NULL != proc) &&
540 (0 != proc (proc_cls, "<zlib>", EXTRACTOR_METATYPE_COMMENT,
541 EXTRACTOR_METAFORMAT_C_STRING, "text/plain",
542 (const char *) fcomment,
543 len)) )
544 return 0; /* done */
545 gzip_header_length += len + 1;
546 } 539 }
540 len = cptr - fcomment;
541 if ( (NULL != proc) &&
542 (0 != proc (proc_cls, "<zlib>", EXTRACTOR_METATYPE_COMMENT,
543 EXTRACTOR_METAFORMAT_C_STRING, "text/plain",
544 (const char *) fcomment,
545 len)) )
546 return 0; /* done */
547 gzip_header_length += len + 1;
548 }
547 if (0 != (hdata[3] & 0x2)) /* FCHRC set */ 549 if (0 != (hdata[3] & 0x2)) /* FCHRC set */
548 gzip_header_length += 2; 550 gzip_header_length += 2;
549 memset (&cfs->strm, 0, sizeof (z_stream)); 551 memset (&cfs->strm, 0, sizeof (z_stream));
@@ -556,10 +558,10 @@ cfs_init_decompressor_zlib (struct CompressedFileSource *cfs,
556 558
557 if (cfs->gzip_header_length != 559 if (cfs->gzip_header_length !=
558 bfds_seek (cfs->bfds, cfs->gzip_header_length, SEEK_SET)) 560 bfds_seek (cfs->bfds, cfs->gzip_header_length, SEEK_SET))
559 { 561 {
560 LOG ("Failed to seek to start to initialize gzip decompressor\n"); 562 LOG ("Failed to seek to start to initialize gzip decompressor\n");
561 return -1; 563 return -1;
562 } 564 }
563 cfs->strm.avail_out = COM_CHUNK_SIZE; 565 cfs->strm.avail_out = COM_CHUNK_SIZE;
564 /* 566 /*
565 * note: maybe plain inflateInit(&strm) is adequate, 567 * note: maybe plain inflateInit(&strm) is adequate,
@@ -567,20 +569,21 @@ cfs_init_decompressor_zlib (struct CompressedFileSource *cfs,
567 * 569 *
568 * ZLIB_VERNUM isn't defined by zlib version 1.1.4 ; 570 * ZLIB_VERNUM isn't defined by zlib version 1.1.4 ;
569 * there might be a better check. 571 * there might be a better check.
570 */ 572 */if (Z_OK != inflateInit2 (&cfs->strm,
571 if (Z_OK != inflateInit2 (&cfs->strm,
572#ifdef ZLIB_VERNUM 573#ifdef ZLIB_VERNUM
573 15 + 32 574 15 + 32
574#else 575#else
575 - MAX_WBITS 576 -MAX_WBITS
576#endif 577#endif
577 )) 578 ))
578 { 579 {
579 LOG ("Failed to initialize zlib decompression\n"); 580 LOG ("Failed to initialize zlib decompression\n");
580 return -1; 581 return -1;
581 } 582 }
582 return 1; 583 return 1;
583} 584}
585
586
584#endif 587#endif
585 588
586 589
@@ -596,24 +599,26 @@ cfs_init_decompressor_zlib (struct CompressedFileSource *cfs,
596 */ 599 */
597static int 600static int
598cfs_init_decompressor_bz2 (struct CompressedFileSource *cfs, 601cfs_init_decompressor_bz2 (struct CompressedFileSource *cfs,
599 EXTRACTOR_MetaDataProcessor proc, void *proc_cls) 602 EXTRACTOR_MetaDataProcessor proc, void *proc_cls)
600{ 603{
601 if (0 != 604 if (0 !=
602 bfds_seek (cfs->bfds, 0, SEEK_SET)) 605 bfds_seek (cfs->bfds, 0, SEEK_SET))
603 { 606 {
604 LOG ("Failed to seek to start to initialize BZ2 decompressor\n"); 607 LOG ("Failed to seek to start to initialize BZ2 decompressor\n");
605 return -1; 608 return -1;
606 } 609 }
607 memset (&cfs->bstrm, 0, sizeof (bz_stream)); 610 memset (&cfs->bstrm, 0, sizeof (bz_stream));
608 if (BZ_OK != 611 if (BZ_OK !=
609 BZ2_bzDecompressInit (&cfs->bstrm, 0, 0)) 612 BZ2_bzDecompressInit (&cfs->bstrm, 0, 0))
610 { 613 {
611 LOG ("Failed to initialize BZ2 decompressor\n"); 614 LOG ("Failed to initialize BZ2 decompressor\n");
612 return -1; 615 return -1;
613 } 616 }
614 cfs->bstrm.avail_out = COM_CHUNK_SIZE; 617 cfs->bstrm.avail_out = COM_CHUNK_SIZE;
615 return 1; 618 return 1;
616} 619}
620
621
617#endif 622#endif
618 623
619 624
@@ -628,24 +633,24 @@ cfs_init_decompressor_bz2 (struct CompressedFileSource *cfs,
628 */ 633 */
629static int 634static int
630cfs_init_decompressor (struct CompressedFileSource *cfs, 635cfs_init_decompressor (struct CompressedFileSource *cfs,
631 EXTRACTOR_MetaDataProcessor proc, void *proc_cls) 636 EXTRACTOR_MetaDataProcessor proc, void *proc_cls)
632{ 637{
633 cfs->result_pos = 0; 638 cfs->result_pos = 0;
634 cfs->fpos = 0; 639 cfs->fpos = 0;
635 switch (cfs->compression_type) 640 switch (cfs->compression_type)
636 { 641 {
637#if HAVE_ZLIB 642#if HAVE_ZLIB
638 case COMP_TYPE_ZLIB: 643 case COMP_TYPE_ZLIB:
639 return cfs_init_decompressor_zlib (cfs, proc, proc_cls); 644 return cfs_init_decompressor_zlib (cfs, proc, proc_cls);
640#endif 645#endif
641#if HAVE_LIBBZ2 646#if HAVE_LIBBZ2
642 case COMP_TYPE_BZ2: 647 case COMP_TYPE_BZ2:
643 return cfs_init_decompressor_bz2 (cfs, proc, proc_cls); 648 return cfs_init_decompressor_bz2 (cfs, proc, proc_cls);
644#endif 649#endif
645 default: 650 default:
646 LOG ("invalid compression type selected\n"); 651 LOG ("invalid compression type selected\n");
647 return -1; 652 return -1;
648 } 653 }
649} 654}
650 655
651 656
@@ -662,6 +667,8 @@ cfs_deinit_decompressor_zlib (struct CompressedFileSource *cfs)
662 inflateEnd (&cfs->strm); 667 inflateEnd (&cfs->strm);
663 return 1; 668 return 1;
664} 669}
670
671
665#endif 672#endif
666 673
667 674
@@ -678,6 +685,8 @@ cfs_deinit_decompressor_bz2 (struct CompressedFileSource *cfs)
678 BZ2_bzDecompressEnd (&cfs->bstrm); 685 BZ2_bzDecompressEnd (&cfs->bstrm);
679 return 1; 686 return 1;
680} 687}
688
689
681#endif 690#endif
682 691
683 692
@@ -691,19 +700,19 @@ static int
691cfs_deinit_decompressor (struct CompressedFileSource *cfs) 700cfs_deinit_decompressor (struct CompressedFileSource *cfs)
692{ 701{
693 switch (cfs->compression_type) 702 switch (cfs->compression_type)
694 { 703 {
695#if HAVE_ZLIB 704#if HAVE_ZLIB
696 case COMP_TYPE_ZLIB: 705 case COMP_TYPE_ZLIB:
697 return cfs_deinit_decompressor_zlib (cfs); 706 return cfs_deinit_decompressor_zlib (cfs);
698#endif 707#endif
699#if HAVE_LIBBZ2 708#if HAVE_LIBBZ2
700 case COMP_TYPE_BZ2: 709 case COMP_TYPE_BZ2:
701 return cfs_deinit_decompressor_bz2 (cfs); 710 return cfs_deinit_decompressor_bz2 (cfs);
702#endif 711#endif
703 default: 712 default:
704 LOG ("invalid compression type selected\n"); 713 LOG ("invalid compression type selected\n");
705 return -1; 714 return -1;
706 } 715 }
707} 716}
708 717
709 718
@@ -750,28 +759,28 @@ cfs_destroy (struct CompressedFileSource *cfs)
750 */ 759 */
751struct CompressedFileSource * 760struct CompressedFileSource *
752cfs_new (struct BufferedFileDataSource *bfds, 761cfs_new (struct BufferedFileDataSource *bfds,
753 int64_t fsize, 762 int64_t fsize,
754 enum ExtractorCompressionType compression_type, 763 enum ExtractorCompressionType compression_type,
755 EXTRACTOR_MetaDataProcessor proc, void *proc_cls) 764 EXTRACTOR_MetaDataProcessor proc, void *proc_cls)
756{ 765{
757 struct CompressedFileSource *cfs; 766 struct CompressedFileSource *cfs;
758 767
759 if (NULL == (cfs = malloc (sizeof (struct CompressedFileSource)))) 768 if (NULL == (cfs = malloc (sizeof (struct CompressedFileSource))))
760 { 769 {
761 LOG_STRERROR ("malloc"); 770 LOG_STRERROR ("malloc");
762 return NULL; 771 return NULL;
763 } 772 }
764 memset (cfs, 0, sizeof (struct CompressedFileSource)); 773 memset (cfs, 0, sizeof (struct CompressedFileSource));
765 cfs->compression_type = compression_type; 774 cfs->compression_type = compression_type;
766 cfs->bfds = bfds; 775 cfs->bfds = bfds;
767 cfs->fsize = fsize; 776 cfs->fsize = fsize;
768 cfs->uncompressed_size = -1; 777 cfs->uncompressed_size = -1;
769 if (1 != cfs_init_decompressor (cfs, 778 if (1 != cfs_init_decompressor (cfs,
770 proc, proc_cls)) 779 proc, proc_cls))
771 { 780 {
772 free (cfs); 781 free (cfs);
773 return NULL; 782 return NULL;
774 } 783 }
775 return cfs; 784 return cfs;
776} 785}
777 786
@@ -789,8 +798,8 @@ cfs_new (struct BufferedFileDataSource *bfds,
789 */ 798 */
790static ssize_t 799static ssize_t
791cfs_read_zlib (struct CompressedFileSource *cfs, 800cfs_read_zlib (struct CompressedFileSource *cfs,
792 void *data, 801 void *data,
793 size_t size) 802 size_t size)
794{ 803{
795 char *dst = data; 804 char *dst = data;
796 int ret; 805 int ret;
@@ -799,77 +808,79 @@ cfs_read_zlib (struct CompressedFileSource *cfs,
799 unsigned char buf[COM_CHUNK_SIZE]; 808 unsigned char buf[COM_CHUNK_SIZE];
800 809
801 if (cfs->fpos == cfs->uncompressed_size) 810 if (cfs->fpos == cfs->uncompressed_size)
802 { 811 {
803 /* end of file */ 812 /* end of file */
804 return 0; 813 return 0;
805 } 814 }
806 rc = 0; 815 rc = 0;
807 if (COM_CHUNK_SIZE > cfs->strm.avail_out + cfs->result_pos) 816 if (COM_CHUNK_SIZE > cfs->strm.avail_out + cfs->result_pos)
808 { 817 {
809 /* got left-over decompressed data from previous round! */ 818 /* got left-over decompressed data from previous round! */
810 in = COM_CHUNK_SIZE - (cfs->strm.avail_out + cfs->result_pos); 819 in = COM_CHUNK_SIZE - (cfs->strm.avail_out + cfs->result_pos);
811 if (in > size) 820 if (in > size)
812 in = size; 821 in = size;
813 memcpy (&dst[rc], &cfs->result[cfs->result_pos], in); 822 memcpy (&dst[rc], &cfs->result[cfs->result_pos], in);
814 cfs->fpos += in; 823 cfs->fpos += in;
815 cfs->result_pos += in; 824 cfs->result_pos += in;
816 rc += in; 825 rc += in;
817 } 826 }
818 ret = Z_OK; 827 ret = Z_OK;
819 while ( (rc < size) && (Z_STREAM_END != ret) ) 828 while ( (rc < size) && (Z_STREAM_END != ret) )
829 {
830 /* read block from original data source */
831 in = bfds_read (cfs->bfds,
832 buf, sizeof (buf));
833 if (in < 0)
820 { 834 {
821 /* read block from original data source */ 835 LOG ("unexpected EOF\n");
822 in = bfds_read (cfs->bfds, 836 return -1; /* unexpected EOF */
823 buf, sizeof (buf));
824 if (in < 0)
825 {
826 LOG ("unexpected EOF\n");
827 return -1; /* unexpected EOF */
828 }
829 if (0 == in)
830 {
831 cfs->uncompressed_size = cfs->fpos;
832 return rc;
833 }
834 cfs->strm.next_in = buf;
835 cfs->strm.avail_in = (uInt) in;
836 cfs->strm.next_out = (unsigned char *) cfs->result;
837 cfs->strm.avail_out = COM_CHUNK_SIZE;
838 cfs->result_pos = 0;
839 ret = inflate (&cfs->strm, Z_SYNC_FLUSH);
840 if ( (Z_OK != ret) && (Z_STREAM_END != ret) )
841 {
842 LOG ("unexpected gzip inflate error: %d\n", ret);
843 return -1; /* unexpected error */
844 }
845 /* go backwards by the number of bytes left in the buffer */
846 if (-1 == bfds_seek (cfs->bfds, - (int64_t) cfs->strm.avail_in, SEEK_CUR))
847 {
848 LOG ("seek failed\n");
849 return -1;
850 }
851 /* copy decompressed bytes to target buffer */
852 in = COM_CHUNK_SIZE - cfs->strm.avail_out;
853 if (in > size - rc)
854 {
855 if (Z_STREAM_END == ret)
856 {
857 cfs->uncompressed_size = cfs->fpos + in;
858 ret = Z_OK;
859 }
860 in = size - rc;
861 }
862 memcpy (&dst[rc], &cfs->result[cfs->result_pos], in);
863 cfs->fpos += in;
864 cfs->result_pos += in;
865 rc += in;
866 } 837 }
867 if (Z_STREAM_END == ret) 838 if (0 == in)
868 { 839 {
869 cfs->uncompressed_size = cfs->fpos; 840 cfs->uncompressed_size = cfs->fpos;
841 return rc;
842 }
843 cfs->strm.next_in = buf;
844 cfs->strm.avail_in = (uInt) in;
845 cfs->strm.next_out = (unsigned char *) cfs->result;
846 cfs->strm.avail_out = COM_CHUNK_SIZE;
847 cfs->result_pos = 0;
848 ret = inflate (&cfs->strm, Z_SYNC_FLUSH);
849 if ( (Z_OK != ret) && (Z_STREAM_END != ret) )
850 {
851 LOG ("unexpected gzip inflate error: %d\n", ret);
852 return -1; /* unexpected error */
853 }
854 /* go backwards by the number of bytes left in the buffer */
855 if (-1 == bfds_seek (cfs->bfds, -(int64_t) cfs->strm.avail_in, SEEK_CUR))
856 {
857 LOG ("seek failed\n");
858 return -1;
859 }
860 /* copy decompressed bytes to target buffer */
861 in = COM_CHUNK_SIZE - cfs->strm.avail_out;
862 if (in > size - rc)
863 {
864 if (Z_STREAM_END == ret)
865 {
866 cfs->uncompressed_size = cfs->fpos + in;
867 ret = Z_OK;
868 }
869 in = size - rc;
870 } 870 }
871 memcpy (&dst[rc], &cfs->result[cfs->result_pos], in);
872 cfs->fpos += in;
873 cfs->result_pos += in;
874 rc += in;
875 }
876 if (Z_STREAM_END == ret)
877 {
878 cfs->uncompressed_size = cfs->fpos;
879 }
871 return rc; 880 return rc;
872} 881}
882
883
873#endif 884#endif
874 885
875 886
@@ -886,8 +897,8 @@ cfs_read_zlib (struct CompressedFileSource *cfs,
886 */ 897 */
887static ssize_t 898static ssize_t
888cfs_read_bz2 (struct CompressedFileSource *cfs, 899cfs_read_bz2 (struct CompressedFileSource *cfs,
889 void *data, 900 void *data,
890 size_t size) 901 size_t size)
891{ 902{
892 char *dst = data; 903 char *dst = data;
893 int ret; 904 int ret;
@@ -896,77 +907,79 @@ cfs_read_bz2 (struct CompressedFileSource *cfs,
896 char buf[COM_CHUNK_SIZE]; 907 char buf[COM_CHUNK_SIZE];
897 908
898 if (cfs->fpos == cfs->uncompressed_size) 909 if (cfs->fpos == cfs->uncompressed_size)
899 { 910 {
900 /* end of file */ 911 /* end of file */
901 return 0; 912 return 0;
902 } 913 }
903 rc = 0; 914 rc = 0;
904 if (COM_CHUNK_SIZE > cfs->bstrm.avail_out + cfs->result_pos) 915 if (COM_CHUNK_SIZE > cfs->bstrm.avail_out + cfs->result_pos)
905 { 916 {
906 /* got left-over decompressed data from previous round! */ 917 /* got left-over decompressed data from previous round! */
907 in = COM_CHUNK_SIZE - (cfs->bstrm.avail_out + cfs->result_pos); 918 in = COM_CHUNK_SIZE - (cfs->bstrm.avail_out + cfs->result_pos);
908 if (in > size) 919 if (in > size)
909 in = size; 920 in = size;
910 memcpy (&dst[rc], &cfs->result[cfs->result_pos], in); 921 memcpy (&dst[rc], &cfs->result[cfs->result_pos], in);
911 cfs->fpos += in; 922 cfs->fpos += in;
912 cfs->result_pos += in; 923 cfs->result_pos += in;
913 rc += in; 924 rc += in;
914 } 925 }
915 ret = BZ_OK; 926 ret = BZ_OK;
916 while ( (rc < size) && (BZ_STREAM_END != ret) ) 927 while ( (rc < size) && (BZ_STREAM_END != ret) )
928 {
929 /* read block from original data source */
930 in = bfds_read (cfs->bfds,
931 buf, sizeof (buf));
932 if (in < 0)
917 { 933 {
918 /* read block from original data source */ 934 LOG ("unexpected EOF\n");
919 in = bfds_read (cfs->bfds, 935 return -1; /* unexpected EOF */
920 buf, sizeof (buf));
921 if (in < 0)
922 {
923 LOG ("unexpected EOF\n");
924 return -1; /* unexpected EOF */
925 }
926 if (0 == in)
927 {
928 cfs->uncompressed_size = cfs->fpos;
929 return rc;
930 }
931 cfs->bstrm.next_in = buf;
932 cfs->bstrm.avail_in = (unsigned int) in;
933 cfs->bstrm.next_out = cfs->result;
934 cfs->bstrm.avail_out = COM_CHUNK_SIZE;
935 cfs->result_pos = 0;
936 ret = BZ2_bzDecompress (&cfs->bstrm);
937 if ( (BZ_OK != ret) && (BZ_STREAM_END != ret) )
938 {
939 LOG ("unexpected bzip2 decompress error: %d\n", ret);
940 return -1; /* unexpected error */
941 }
942 /* go backwards by the number of bytes left in the buffer */
943 if (-1 == bfds_seek (cfs->bfds, - (int64_t) cfs->bstrm.avail_in, SEEK_CUR))
944 {
945 LOG ("seek failed\n");
946 return -1;
947 }
948 /* copy decompressed bytes to target buffer */
949 in = COM_CHUNK_SIZE - cfs->bstrm.avail_out;
950 if (in > size - rc)
951 {
952 if (BZ_STREAM_END == ret)
953 {
954 cfs->uncompressed_size = cfs->fpos + in;
955 ret = BZ_OK;
956 }
957 in = size - rc;
958 }
959 memcpy (&dst[rc], &cfs->result[cfs->result_pos], in);
960 cfs->fpos += in;
961 cfs->result_pos += in;
962 rc += in;
963 } 936 }
964 if (BZ_STREAM_END == ret) 937 if (0 == in)
965 { 938 {
966 cfs->uncompressed_size = cfs->fpos; 939 cfs->uncompressed_size = cfs->fpos;
940 return rc;
941 }
942 cfs->bstrm.next_in = buf;
943 cfs->bstrm.avail_in = (unsigned int) in;
944 cfs->bstrm.next_out = cfs->result;
945 cfs->bstrm.avail_out = COM_CHUNK_SIZE;
946 cfs->result_pos = 0;
947 ret = BZ2_bzDecompress (&cfs->bstrm);
948 if ( (BZ_OK != ret) && (BZ_STREAM_END != ret) )
949 {
950 LOG ("unexpected bzip2 decompress error: %d\n", ret);
951 return -1; /* unexpected error */
952 }
953 /* go backwards by the number of bytes left in the buffer */
954 if (-1 == bfds_seek (cfs->bfds, -(int64_t) cfs->bstrm.avail_in, SEEK_CUR))
955 {
956 LOG ("seek failed\n");
957 return -1;
967 } 958 }
959 /* copy decompressed bytes to target buffer */
960 in = COM_CHUNK_SIZE - cfs->bstrm.avail_out;
961 if (in > size - rc)
962 {
963 if (BZ_STREAM_END == ret)
964 {
965 cfs->uncompressed_size = cfs->fpos + in;
966 ret = BZ_OK;
967 }
968 in = size - rc;
969 }
970 memcpy (&dst[rc], &cfs->result[cfs->result_pos], in);
971 cfs->fpos += in;
972 cfs->result_pos += in;
973 rc += in;
974 }
975 if (BZ_STREAM_END == ret)
976 {
977 cfs->uncompressed_size = cfs->fpos;
978 }
968 return rc; 979 return rc;
969} 980}
981
982
970#endif 983#endif
971 984
972 985
@@ -982,23 +995,23 @@ cfs_read_bz2 (struct CompressedFileSource *cfs,
982 */ 995 */
983static ssize_t 996static ssize_t
984cfs_read (struct CompressedFileSource *cfs, 997cfs_read (struct CompressedFileSource *cfs,
985 void *data, 998 void *data,
986 size_t size) 999 size_t size)
987{ 1000{
988 switch (cfs->compression_type) 1001 switch (cfs->compression_type)
989 { 1002 {
990#if HAVE_ZLIB 1003#if HAVE_ZLIB
991 case COMP_TYPE_ZLIB: 1004 case COMP_TYPE_ZLIB:
992 return cfs_read_zlib (cfs, data, size); 1005 return cfs_read_zlib (cfs, data, size);
993#endif 1006#endif
994#if HAVE_LIBBZ2 1007#if HAVE_LIBBZ2
995 case COMP_TYPE_BZ2: 1008 case COMP_TYPE_BZ2:
996 return cfs_read_bz2 (cfs, data, size); 1009 return cfs_read_bz2 (cfs, data, size);
997#endif 1010#endif
998 default: 1011 default:
999 LOG ("invalid compression type selected\n"); 1012 LOG ("invalid compression type selected\n");
1000 return -1; 1013 return -1;
1001 } 1014 }
1002} 1015}
1003 1016
1004 1017
@@ -1014,104 +1027,105 @@ cfs_read (struct CompressedFileSource *cfs,
1014 */ 1027 */
1015static int64_t 1028static int64_t
1016cfs_seek (struct CompressedFileSource *cfs, 1029cfs_seek (struct CompressedFileSource *cfs,
1017 int64_t position, 1030 int64_t position,
1018 int whence) 1031 int whence)
1019{ 1032{
1020 uint64_t nposition; 1033 uint64_t nposition;
1021 int64_t delta; 1034 int64_t delta;
1022 1035
1023 switch (whence) 1036 switch (whence)
1037 {
1038 case SEEK_CUR:
1039 if (cfs->fpos + position < 0)
1040 {
1041 /* underflow */
1042 LOG ("Invalid seek operation\n");
1043 return -1;
1044 }
1045 if ( (-1 != cfs->uncompressed_size) &&
1046 (cfs->fpos + position > cfs->uncompressed_size) )
1047 {
1048 LOG ("Invalid seek operation\n");
1049 return -1;
1050 }
1051 nposition = cfs->fpos + position;
1052 break;
1053 case SEEK_END:
1054 ASSERT (-1 != cfs->uncompressed_size);
1055 if (position > 0)
1024 { 1056 {
1025 case SEEK_CUR:
1026 if (cfs->fpos + position < 0)
1027 {
1028 /* underflow */
1029 LOG ("Invalid seek operation\n");
1030 return -1;
1031 }
1032 if ( (-1 != cfs->uncompressed_size) &&
1033 (cfs->fpos + position > cfs->uncompressed_size) )
1034 {
1035 LOG ("Invalid seek operation\n");
1036 return -1;
1037 }
1038 nposition = cfs->fpos + position;
1039 break;
1040 case SEEK_END:
1041 ASSERT (-1 != cfs->uncompressed_size);
1042 if (position > 0)
1043 {
1044 LOG ("Invalid seek operation\n");
1045 return -1;
1046 }
1047 if (cfs->uncompressed_size < - position)
1048 {
1049 LOG ("Invalid seek operation\n");
1050 return -1;
1051 }
1052 nposition = cfs->uncompressed_size + position;
1053 break;
1054 case SEEK_SET:
1055 if (position < 0)
1056 {
1057 LOG ("Invalid seek operation\n");
1058 return -1;
1059 }
1060 if ( (-1 != cfs->uncompressed_size) &&
1061 (cfs->uncompressed_size < position ) )
1062 {
1063 LOG ("Invalid seek operation\n");
1064 return -1;
1065 }
1066 nposition = (uint64_t) position;
1067 break;
1068 default:
1069 LOG ("Invalid seek operation\n"); 1057 LOG ("Invalid seek operation\n");
1070 return -1; 1058 return -1;
1071 } 1059 }
1060 if (cfs->uncompressed_size < -position)
1061 {
1062 LOG ("Invalid seek operation\n");
1063 return -1;
1064 }
1065 nposition = cfs->uncompressed_size + position;
1066 break;
1067 case SEEK_SET:
1068 if (position < 0)
1069 {
1070 LOG ("Invalid seek operation\n");
1071 return -1;
1072 }
1073 if ( (-1 != cfs->uncompressed_size) &&
1074 (cfs->uncompressed_size < position) )
1075 {
1076 LOG ("Invalid seek operation\n");
1077 return -1;
1078 }
1079 nposition = (uint64_t) position;
1080 break;
1081 default:
1082 LOG ("Invalid seek operation\n");
1083 return -1;
1084 }
1072 delta = nposition - cfs->fpos; 1085 delta = nposition - cfs->fpos;
1073 if (delta < 0) 1086 if (delta < 0)
1087 {
1088 if (cfs->result_pos >= -delta)
1074 { 1089 {
1075 if (cfs->result_pos >= - delta) 1090 cfs->result_pos += delta;
1076 { 1091 cfs->fpos += delta;
1077 cfs->result_pos += delta; 1092 delta = 0;
1078 cfs->fpos += delta;
1079 delta = 0;
1080 }
1081 else
1082 {
1083 if (-1 == cfs_reset_stream (cfs))
1084 {
1085 LOG ("Failed to restart compressed stream for seek operation\n");
1086 return -1;
1087 }
1088 delta = nposition;
1089 }
1090 } 1093 }
1094 else
1095 {
1096 if (-1 == cfs_reset_stream (cfs))
1097 {
1098 LOG ("Failed to restart compressed stream for seek operation\n");
1099 return -1;
1100 }
1101 delta = nposition;
1102 }
1103 }
1091 while (delta > 0) 1104 while (delta > 0)
1105 {
1106 char buf[COM_CHUNK_SIZE];
1107 size_t max;
1108 int64_t ret;
1109
1110 max = (sizeof (buf) > delta) ? delta : sizeof (buf);
1111 ret = cfs_read (cfs, buf, max);
1112 if (-1 == ret)
1113 {
1114 LOG ("Failed to read decompressed stream for seek operation\n");
1115 return -1;
1116 }
1117 if (0 == ret)
1092 { 1118 {
1093 char buf[COM_CHUNK_SIZE]; 1119 LOG (
1094 size_t max; 1120 "Reached unexpected end of stream at %llu during seek operation to %llu (%d left)\n",
1095 int64_t ret; 1121 (unsigned long long) cfs->fpos,
1096 1122 (unsigned long long) nposition,
1097 max = (sizeof (buf) > delta) ? delta : sizeof (buf); 1123 delta);
1098 ret = cfs_read (cfs, buf, max); 1124 return -1;
1099 if (-1 == ret)
1100 {
1101 LOG ("Failed to read decompressed stream for seek operation\n");
1102 return -1;
1103 }
1104 if (0 == ret)
1105 {
1106 LOG ("Reached unexpected end of stream at %llu during seek operation to %llu (%d left)\n",
1107 (unsigned long long) cfs->fpos,
1108 (unsigned long long) nposition,
1109 delta);
1110 return -1;
1111 }
1112 ASSERT (ret <= delta);
1113 delta -= ret;
1114 } 1125 }
1126 ASSERT (ret <= delta);
1127 delta -= ret;
1128 }
1115 return cfs->fpos; 1129 return cfs->fpos;
1116} 1130}
1117 1131
@@ -1186,8 +1200,8 @@ struct EXTRACTOR_Datasource
1186 */ 1200 */
1187struct EXTRACTOR_Datasource * 1201struct EXTRACTOR_Datasource *
1188EXTRACTOR_datasource_create_from_file_ (const char *filename, 1202EXTRACTOR_datasource_create_from_file_ (const char *filename,
1189 EXTRACTOR_MetaDataProcessor proc, 1203 EXTRACTOR_MetaDataProcessor proc,
1190 void *proc_cls) 1204 void *proc_cls)
1191{ 1205{
1192 struct BufferedFileDataSource *bfds; 1206 struct BufferedFileDataSource *bfds;
1193 struct EXTRACTOR_Datasource *ds; 1207 struct EXTRACTOR_Datasource *ds;
@@ -1201,56 +1215,56 @@ EXTRACTOR_datasource_create_from_file_ (const char *filename,
1201#endif 1215#endif
1202 1216
1203 if (-1 == (fd = OPEN (filename, O_RDONLY | O_LARGEFILE | winmode))) 1217 if (-1 == (fd = OPEN (filename, O_RDONLY | O_LARGEFILE | winmode)))
1204 { 1218 {
1205 LOG_STRERROR_FILE ("open", filename); 1219 LOG_STRERROR_FILE ("open", filename);
1206 return NULL; 1220 return NULL;
1207 } 1221 }
1208 if ( (0 != FSTAT (fd, &sb)) || 1222 if ( (0 != FSTAT (fd, &sb)) ||
1209 (S_ISDIR (sb.st_mode)) ) 1223 (S_ISDIR (sb.st_mode)) )
1210 { 1224 {
1211 if (! S_ISDIR (sb.st_mode)) 1225 if (! S_ISDIR (sb.st_mode))
1212 LOG_STRERROR_FILE ("fstat", filename); 1226 LOG_STRERROR_FILE ("fstat", filename);
1213 else 1227 else
1214 LOG ("Skipping directory `%s'\n", filename); 1228 LOG ("Skipping directory `%s'\n", filename);
1215 (void) CLOSE (fd); 1229 (void) CLOSE (fd);
1216 return NULL; 1230 return NULL;
1217 } 1231 }
1218 fsize = (int64_t) sb.st_size; 1232 fsize = (int64_t) sb.st_size;
1219 if (0 == fsize) 1233 if (0 == fsize)
1220 { 1234 {
1221 (void) CLOSE (fd); 1235 (void) CLOSE (fd);
1222 return NULL; 1236 return NULL;
1223 } 1237 }
1224 bfds = bfds_new (NULL, fd, fsize); 1238 bfds = bfds_new (NULL, fd, fsize);
1225 if (NULL == bfds) 1239 if (NULL == bfds)
1226 { 1240 {
1227 (void) CLOSE (fd); 1241 (void) CLOSE (fd);
1228 return NULL; 1242 return NULL;
1229 } 1243 }
1230 if (NULL == (ds = malloc (sizeof (struct EXTRACTOR_Datasource)))) 1244 if (NULL == (ds = malloc (sizeof (struct EXTRACTOR_Datasource))))
1231 { 1245 {
1232 LOG_STRERROR ("malloc"); 1246 LOG_STRERROR ("malloc");
1233 bfds_delete (bfds); 1247 bfds_delete (bfds);
1234 (void) CLOSE (fd); 1248 (void) CLOSE (fd);
1235 return NULL; 1249 return NULL;
1236 } 1250 }
1237 ds->bfds = bfds; 1251 ds->bfds = bfds;
1238 ds->fd = fd; 1252 ds->fd = fd;
1239 ds->cfs = NULL; 1253 ds->cfs = NULL;
1240 ct = get_compression_type (bfds); 1254 ct = get_compression_type (bfds);
1241 if ( (COMP_TYPE_ZLIB == ct) || 1255 if ( (COMP_TYPE_ZLIB == ct) ||
1242 (COMP_TYPE_BZ2 == ct) ) 1256 (COMP_TYPE_BZ2 == ct) )
1257 {
1258 ds->cfs = cfs_new (bfds, fsize, ct, proc, proc_cls);
1259 if (NULL == ds->cfs)
1243 { 1260 {
1244 ds->cfs = cfs_new (bfds, fsize, ct, proc, proc_cls); 1261 LOG ("Failed to initialize decompressor\n");
1245 if (NULL == ds->cfs) 1262 bfds_delete (bfds);
1246 { 1263 free (ds);
1247 LOG ("Failed to initialize decompressor\n"); 1264 (void) CLOSE (fd);
1248 bfds_delete (bfds); 1265 return NULL;
1249 free (ds);
1250 (void) CLOSE (fd);
1251 return NULL;
1252 }
1253 } 1266 }
1267 }
1254 return ds; 1268 return ds;
1255} 1269}
1256 1270
@@ -1266,8 +1280,9 @@ EXTRACTOR_datasource_create_from_file_ (const char *filename,
1266 */ 1280 */
1267struct EXTRACTOR_Datasource * 1281struct EXTRACTOR_Datasource *
1268EXTRACTOR_datasource_create_from_buffer_ (const char *buf, 1282EXTRACTOR_datasource_create_from_buffer_ (const char *buf,
1269 size_t size, 1283 size_t size,
1270 EXTRACTOR_MetaDataProcessor proc, void *proc_cls) 1284 EXTRACTOR_MetaDataProcessor proc,
1285 void *proc_cls)
1271{ 1286{
1272 struct BufferedFileDataSource *bfds; 1287 struct BufferedFileDataSource *bfds;
1273 struct EXTRACTOR_Datasource *ds; 1288 struct EXTRACTOR_Datasource *ds;
@@ -1276,32 +1291,32 @@ EXTRACTOR_datasource_create_from_buffer_ (const char *buf,
1276 if (0 == size) 1291 if (0 == size)
1277 return NULL; 1292 return NULL;
1278 if (NULL == (bfds = bfds_new (buf, -1, size))) 1293 if (NULL == (bfds = bfds_new (buf, -1, size)))
1279 { 1294 {
1280 LOG ("Failed to initialize buffer data source\n"); 1295 LOG ("Failed to initialize buffer data source\n");
1281 return NULL; 1296 return NULL;
1282 } 1297 }
1283 if (NULL == (ds = malloc (sizeof (struct EXTRACTOR_Datasource)))) 1298 if (NULL == (ds = malloc (sizeof (struct EXTRACTOR_Datasource))))
1284 { 1299 {
1285 LOG_STRERROR ("malloc"); 1300 LOG_STRERROR ("malloc");
1286 bfds_delete (bfds); 1301 bfds_delete (bfds);
1287 return NULL; 1302 return NULL;
1288 } 1303 }
1289 ds->bfds = bfds; 1304 ds->bfds = bfds;
1290 ds->fd = -1; 1305 ds->fd = -1;
1291 ds->cfs = NULL; 1306 ds->cfs = NULL;
1292 ct = get_compression_type (bfds); 1307 ct = get_compression_type (bfds);
1293 if ( (COMP_TYPE_ZLIB == ct) || 1308 if ( (COMP_TYPE_ZLIB == ct) ||
1294 (COMP_TYPE_BZ2 == ct) ) 1309 (COMP_TYPE_BZ2 == ct) )
1310 {
1311 ds->cfs = cfs_new (bfds, size, ct, proc, proc_cls);
1312 if (NULL == ds->cfs)
1295 { 1313 {
1296 ds->cfs = cfs_new (bfds, size, ct, proc, proc_cls); 1314 LOG ("Failed to initialize decompressor\n");
1297 if (NULL == ds->cfs) 1315 bfds_delete (bfds);
1298 { 1316 free (ds);
1299 LOG ("Failed to initialize decompressor\n"); 1317 return NULL;
1300 bfds_delete (bfds);
1301 free (ds);
1302 return NULL;
1303 }
1304 } 1318 }
1319 }
1305 return ds; 1320 return ds;
1306} 1321}
1307 1322
@@ -1334,8 +1349,8 @@ EXTRACTOR_datasource_destroy_ (struct EXTRACTOR_Datasource *ds)
1334 */ 1349 */
1335ssize_t 1350ssize_t
1336EXTRACTOR_datasource_read_ (void *cls, 1351EXTRACTOR_datasource_read_ (void *cls,
1337 void *data, 1352 void *data,
1338 size_t size) 1353 size_t size)
1339{ 1354{
1340 struct EXTRACTOR_Datasource *ds = cls; 1355 struct EXTRACTOR_Datasource *ds = cls;
1341 1356
@@ -1357,23 +1372,23 @@ EXTRACTOR_datasource_read_ (void *cls,
1357 */ 1372 */
1358int64_t 1373int64_t
1359EXTRACTOR_datasource_seek_ (void *cls, 1374EXTRACTOR_datasource_seek_ (void *cls,
1360 int64_t pos, 1375 int64_t pos,
1361 int whence) 1376 int whence)
1362{ 1377{
1363 struct EXTRACTOR_Datasource *ds = cls; 1378 struct EXTRACTOR_Datasource *ds = cls;
1364 1379
1365 if (NULL != ds->cfs) 1380 if (NULL != ds->cfs)
1381 {
1382 if ( (SEEK_END == whence) &&
1383 (-1 == ds->cfs->uncompressed_size) )
1366 { 1384 {
1367 if ( (SEEK_END == whence) && 1385 /* need to obtain uncompressed size */
1368 (-1 == ds->cfs->uncompressed_size) ) 1386 (void) EXTRACTOR_datasource_get_size_ (ds, 1);
1369 { 1387 if (-1 == ds->cfs->uncompressed_size)
1370 /* need to obtain uncompressed size */ 1388 return -1;
1371 (void) EXTRACTOR_datasource_get_size_ (ds, 1);
1372 if (-1 == ds->cfs->uncompressed_size)
1373 return -1;
1374 }
1375 return cfs_seek (ds->cfs, pos, whence);
1376 } 1389 }
1390 return cfs_seek (ds->cfs, pos, whence);
1391 }
1377 return bfds_seek (ds->bfds, pos, whence); 1392 return bfds_seek (ds->bfds, pos, whence);
1378} 1393}
1379 1394
@@ -1387,30 +1402,32 @@ EXTRACTOR_datasource_seek_ (void *cls,
1387 */ 1402 */
1388int64_t 1403int64_t
1389EXTRACTOR_datasource_get_size_ (void *cls, 1404EXTRACTOR_datasource_get_size_ (void *cls,
1390 int force) 1405 int force)
1391{ 1406{
1392 struct EXTRACTOR_Datasource *ds = cls; 1407 struct EXTRACTOR_Datasource *ds = cls;
1393 char buf[32 * 1024]; 1408 char buf[32 * 1024];
1394 uint64_t pos; 1409 uint64_t pos;
1395 1410
1396 if (NULL != ds->cfs) 1411 if (NULL != ds->cfs)
1412 {
1413 if ( (force) &&
1414 (-1 == ds->cfs->uncompressed_size) )
1397 { 1415 {
1398 if ( (force) && 1416 pos = ds->cfs->fpos;
1399 (-1 == ds->cfs->uncompressed_size) ) 1417 while ( (-1 == ds->cfs->uncompressed_size) &&
1400 { 1418 (-1 != cfs_read (ds->cfs, buf, sizeof (buf))) )
1401 pos = ds->cfs->fpos; 1419 ;
1402 while ( (-1 == ds->cfs->uncompressed_size) && 1420 if (-1 == cfs_seek (ds->cfs, pos, SEEK_SET))
1403 (-1 != cfs_read (ds->cfs, buf, sizeof (buf))) ) ; 1421 {
1404 if (-1 == cfs_seek (ds->cfs, pos, SEEK_SET)) 1422 LOG (
1405 { 1423 "Serious problem, I moved the buffer to determine the file size but could not restore it...\n");
1406 LOG ("Serious problem, I moved the buffer to determine the file size but could not restore it...\n"); 1424 return -1;
1407 return -1; 1425 }
1408 } 1426 if (-1 == ds->cfs->uncompressed_size)
1409 if (-1 == ds->cfs->uncompressed_size) 1427 return -1;
1410 return -1;
1411 }
1412 return ds->cfs->uncompressed_size;
1413 } 1428 }
1429 return ds->cfs->uncompressed_size;
1430 }
1414 return ds->bfds->fsize; 1431 return ds->bfds->fsize;
1415} 1432}
1416 1433
diff --git a/src/main/extractor_datasource.h b/src/main/extractor_datasource.h
index f25cc4b..dc548a6 100644
--- a/src/main/extractor_datasource.h
+++ b/src/main/extractor_datasource.h
@@ -29,7 +29,7 @@
29 29
30/** 30/**
31 * Handle to a datasource we can use for the plugins. 31 * Handle to a datasource we can use for the plugins.
32 */ 32 */
33struct EXTRACTOR_Datasource; 33struct EXTRACTOR_Datasource;
34 34
35 35
@@ -43,7 +43,8 @@ struct EXTRACTOR_Datasource;
43 */ 43 */
44struct EXTRACTOR_Datasource * 44struct EXTRACTOR_Datasource *
45EXTRACTOR_datasource_create_from_file_ (const char *filename, 45EXTRACTOR_datasource_create_from_file_ (const char *filename,
46 EXTRACTOR_MetaDataProcessor proc, void *proc_cls); 46 EXTRACTOR_MetaDataProcessor proc,
47 void *proc_cls);
47 48
48 49
49/** 50/**
@@ -57,8 +58,9 @@ EXTRACTOR_datasource_create_from_file_ (const char *filename,
57 */ 58 */
58struct EXTRACTOR_Datasource * 59struct EXTRACTOR_Datasource *
59EXTRACTOR_datasource_create_from_buffer_ (const char *buf, 60EXTRACTOR_datasource_create_from_buffer_ (const char *buf,
60 size_t size, 61 size_t size,
61 EXTRACTOR_MetaDataProcessor proc, void *proc_cls); 62 EXTRACTOR_MetaDataProcessor proc,
63 void *proc_cls);
62 64
63 65
64/** 66/**
@@ -81,14 +83,14 @@ EXTRACTOR_datasource_destroy_ (struct EXTRACTOR_Datasource *ds);
81 */ 83 */
82ssize_t 84ssize_t
83EXTRACTOR_datasource_read_ (void *cls, 85EXTRACTOR_datasource_read_ (void *cls,
84 void *data, 86 void *data,
85 size_t size); 87 size_t size);
86 88
87 89
88/** 90/**
89 * Seek in the datasource. Use 'SEEK_CUR' for whence and 'pos' of 0 to 91 * Seek in the datasource. Use 'SEEK_CUR' for whence and 'pos' of 0 to
90 * obtain the current position in the file. 92 * obtain the current position in the file.
91 * 93 *
92 * @param cls must be a 'struct EXTRACTOR_Datasource' 94 * @param cls must be a 'struct EXTRACTOR_Datasource'
93 * @param pos position to seek (see 'man lseek')o 95 * @param pos position to seek (see 'man lseek')o
94 * @param whence how to see (absolute to start, relative, absolute to end) 96 * @param whence how to see (absolute to start, relative, absolute to end)
@@ -97,20 +99,20 @@ EXTRACTOR_datasource_read_ (void *cls,
97 */ 99 */
98int64_t 100int64_t
99EXTRACTOR_datasource_seek_ (void *cls, 101EXTRACTOR_datasource_seek_ (void *cls,
100 int64_t pos, 102 int64_t pos,
101 int whence); 103 int whence);
102 104
103 105
104/** 106/**
105 * Determine the overall size of the data source (after compression). 107 * Determine the overall size of the data source (after compression).
106 * 108 *
107 * @param cls must be a 'struct EXTRACTOR_Datasource' 109 * @param cls must be a 'struct EXTRACTOR_Datasource'
108 * @param force force computing the size if it is unavailable 110 * @param force force computing the size if it is unavailable
109 * @return overall file size, -1 on error or unknown 111 * @return overall file size, -1 on error or unknown
110 */ 112 */
111int64_t 113int64_t
112EXTRACTOR_datasource_get_size_ (void *cls, 114EXTRACTOR_datasource_get_size_ (void *cls,
113 int force); 115 int force);
114 116
115 117
116#endif 118#endif
diff --git a/src/main/extractor_ipc.c b/src/main/extractor_ipc.c
index 47d9d4d..b343bd6 100644
--- a/src/main/extractor_ipc.c
+++ b/src/main/extractor_ipc.c
@@ -40,10 +40,10 @@
40 */ 40 */
41ssize_t 41ssize_t
42EXTRACTOR_IPC_process_reply_ (struct EXTRACTOR_PluginList *plugin, 42EXTRACTOR_IPC_process_reply_ (struct EXTRACTOR_PluginList *plugin,
43 const void *data, 43 const void *data,
44 size_t size, 44 size_t size,
45 EXTRACTOR_ChannelMessageProcessor proc, 45 EXTRACTOR_ChannelMessageProcessor proc,
46 void *proc_cls) 46 void *proc_cls)
47{ 47{
48 const char *cdata; 48 const char *cdata;
49 unsigned char code; 49 unsigned char code;
@@ -55,83 +55,84 @@ EXTRACTOR_IPC_process_reply_ (struct EXTRACTOR_PluginList *plugin,
55 55
56 ret = 0; 56 ret = 0;
57 while (size > 0) 57 while (size > 0)
58 {
59 cdata = data;
60 code = (unsigned char) cdata[0];
61 switch (code)
58 { 62 {
59 cdata = data; 63 case MESSAGE_DONE: /* Done */
60 code = (unsigned char) cdata[0]; 64 plugin->seek_request = -1;
61 switch (code) 65 plugin->round_finished = 1;
62 { 66 ret++;
63 case MESSAGE_DONE: /* Done */ 67 size--;
64 plugin->seek_request = -1; 68 data++;
65 plugin->round_finished = 1; 69 continue;
66 ret++; 70 case MESSAGE_SEEK: /* Seek */
67 size--; 71 if (size < sizeof (struct SeekRequestMessage))
68 data++; 72 {
69 continue; 73 plugin->seek_request = -1;
70 case MESSAGE_SEEK: /* Seek */ 74 return ret;
71 if (size < sizeof (struct SeekRequestMessage)) 75 }
72 { 76 memcpy (&seek, cdata, sizeof (seek));
73 plugin->seek_request = -1; 77 plugin->seek_request = (int64_t) seek.file_offset;
74 return ret; 78 plugin->seek_whence = seek.whence;
75 } 79 ret += sizeof (struct SeekRequestMessage);
76 memcpy (&seek, cdata, sizeof (seek)); 80 data += sizeof (struct SeekRequestMessage);
77 plugin->seek_request = (int64_t) seek.file_offset; 81 size -= sizeof (struct SeekRequestMessage);
78 plugin->seek_whence = seek.whence; 82 continue;
79 ret += sizeof (struct SeekRequestMessage); 83 case MESSAGE_META: /* Meta */
80 data += sizeof (struct SeekRequestMessage); 84 if (size < sizeof (struct MetaMessage))
81 size -= sizeof (struct SeekRequestMessage); 85 {
82 continue; 86 plugin->seek_request = -1;
83 case MESSAGE_META: /* Meta */ 87 return ret;
84 if (size < sizeof (struct MetaMessage)) 88 }
85 { 89 memcpy (&meta, cdata, sizeof (meta));
86 plugin->seek_request = -1; 90 /* check hdr for sanity */
87 return ret; 91 if (meta.value_size > MAX_META_DATA)
88 } 92 {
89 memcpy (&meta, cdata, sizeof (meta)); 93 LOG ("Meta data exceeds size limit\n");
90 /* check hdr for sanity */ 94 return -1; /* not allowing more than MAX_META_DATA meta data */
91 if (meta.value_size > MAX_META_DATA) 95 }
92 { 96 if (size < sizeof (meta) + meta.mime_length + meta.value_size)
93 LOG ("Meta data exceeds size limit\n"); 97 {
94 return -1; /* not allowing more than MAX_META_DATA meta data */ 98 plugin->seek_request = -1;
95 } 99 return ret;
96 if (size < sizeof (meta) + meta.mime_length + meta.value_size) 100 }
97 { 101 if (0 == meta.mime_length)
98 plugin->seek_request = -1; 102 {
99 return ret; 103 mime_type = NULL;
100 } 104 }
101 if (0 == meta.mime_length) 105 else
102 { 106 {
103 mime_type = NULL; 107 mime_type = &cdata[sizeof (struct MetaMessage)];
104 } 108 if ('\0' != mime_type[meta.mime_length - 1])
105 else 109 {
106 { 110 LOG ("Mime type not 0-terminated\n");
107 mime_type = &cdata[sizeof (struct MetaMessage)]; 111 return -1;
108 if ('\0' != mime_type[meta.mime_length - 1]) 112 }
109 { 113 }
110 LOG ("Mime type not 0-terminated\n"); 114 if (0 == meta.value_size)
111 return -1; 115 value = NULL;
112 } 116 else
113 } 117 value = &cdata[sizeof (struct MetaMessage) + meta.mime_length];
114 if (0 == meta.value_size) 118 if (meta.meta_type >= EXTRACTOR_metatype_get_max ())
115 value = NULL; 119 meta.meta_type = EXTRACTOR_METATYPE_UNKNOWN;
116 else 120 proc (proc_cls,
117 value = &cdata[sizeof (struct MetaMessage) + meta.mime_length]; 121 plugin,
118 if (meta.meta_type >= EXTRACTOR_metatype_get_max ()) 122 (enum EXTRACTOR_MetaType) meta.meta_type,
119 meta.meta_type = EXTRACTOR_METATYPE_UNKNOWN; 123 (enum EXTRACTOR_MetaFormat) meta.meta_format,
120 proc (proc_cls, 124 mime_type, value, meta.value_size);
121 plugin, 125 ret += sizeof (struct MetaMessage) + meta.mime_length + meta.value_size;
122 (enum EXTRACTOR_MetaType) meta.meta_type, 126 size -= sizeof (struct MetaMessage) + meta.mime_length + meta.value_size;
123 (enum EXTRACTOR_MetaFormat) meta.meta_format, 127 data += sizeof (struct MetaMessage) + meta.mime_length + meta.value_size;
124 mime_type, value, meta.value_size); 128 continue;
125 ret += sizeof (struct MetaMessage) + meta.mime_length + meta.value_size; 129 default:
126 size -= sizeof (struct MetaMessage) + meta.mime_length + meta.value_size; 130 LOG ("Invalid message type %d\n", (int) code);
127 data += sizeof (struct MetaMessage) + meta.mime_length + meta.value_size; 131 return -1;
128 continue;
129 default:
130 LOG ("Invalid message type %d\n", (int) code);
131 return -1;
132 }
133 } 132 }
133 }
134 return ret; 134 return ret;
135} 135}
136 136
137
137/* end of extractor_ipc.c */ 138/* end of extractor_ipc.c */
diff --git a/src/main/extractor_ipc.h b/src/main/extractor_ipc.h
index 0109b66..8e7fe09 100644
--- a/src/main/extractor_ipc.h
+++ b/src/main/extractor_ipc.h
@@ -27,7 +27,7 @@
27 * as follows. Each message begins with a 1-character opcode which 27 * as follows. Each message begins with a 1-character opcode which
28 * specifies the message type. The main library starts the plugins 28 * specifies the message type. The main library starts the plugins
29 * by forking the helper process and establishes two pipes for 29 * by forking the helper process and establishes two pipes for
30 * communication in both directions. 30 * communication in both directions.
31 * First, the main library send an 'INIT_STATE' message 31 * First, the main library send an 'INIT_STATE' message
32 * to the plugin. The start message specifies the name (and size) 32 * to the plugin. The start message specifies the name (and size)
33 * of a shared memory segment which will contain parts of the (uncompressed) 33 * of a shared memory segment which will contain parts of the (uncompressed)
@@ -39,7 +39,7 @@
39 * size of the file (or -1 if unknown) and the number of bytes 39 * size of the file (or -1 if unknown) and the number of bytes
40 * ready in the shared memory segment. The plugin then answers 40 * ready in the shared memory segment. The plugin then answers
41 * with either: 41 * with either:
42 * 1) MESSAGE_DONE to indicate that no further processing is 42 * 1) MESSAGE_DONE to indicate that no further processing is
43 * required for this file; the IPC continues with the 43 * required for this file; the IPC continues with the
44 * EXTRACT_START message for the next file afterwards; 44 * EXTRACT_START message for the next file afterwards;
45 * 2) MESSAGE_SEEK to indicate that the plugin would like to 45 * 2) MESSAGE_SEEK to indicate that the plugin would like to
@@ -161,7 +161,7 @@ struct StartMessage
161 161
162/** 162/**
163 * Sent from LE to a plugin to tell it that shm contents 163 * Sent from LE to a plugin to tell it that shm contents
164 * were updated. 164 * were updated.
165 */ 165 */
166#define MESSAGE_UPDATED_SHM 0x02 166#define MESSAGE_UPDATED_SHM 0x02
167 167
@@ -245,7 +245,7 @@ struct SeekRequestMessage
245 /** 245 /**
246 * Requested offset; a positive value from the end of the 246 * Requested offset; a positive value from the end of the
247 * file is used of 'whence' is SEEK_END; a postive value 247 * file is used of 'whence' is SEEK_END; a postive value
248 * from the start is used of 'whence' is SEEK_SET. 248 * from the start is used of 'whence' is SEEK_SET.
249 * 'SEEK_CUR' is never used. 249 * 'SEEK_CUR' is never used.
250 */ 250 */
251 uint64_t file_offset; 251 uint64_t file_offset;
@@ -292,9 +292,9 @@ struct MetaMessage
292 */ 292 */
293 uint32_t value_size; 293 uint32_t value_size;
294 294
295 /* followed by mime_length bytes of 0-terminated 295 /* followed by mime_length bytes of 0-terminated
296 mime-type (unless mime_length is 0) */ 296 mime-type (unless mime_length is 0) */
297 297
298 /* followed by value_size bytes of value */ 298 /* followed by value_size bytes of value */
299 299
300}; 300};
@@ -355,7 +355,7 @@ EXTRACTOR_IPC_shared_memory_destroy_ (struct EXTRACTOR_SharedMemory *shm);
355 */ 355 */
356unsigned int 356unsigned int
357EXTRACTOR_IPC_shared_memory_change_rc_ (struct EXTRACTOR_SharedMemory *shm, 357EXTRACTOR_IPC_shared_memory_change_rc_ (struct EXTRACTOR_SharedMemory *shm,
358 int delta); 358 int delta);
359 359
360 360
361/** 361/**
@@ -369,9 +369,9 @@ EXTRACTOR_IPC_shared_memory_change_rc_ (struct EXTRACTOR_SharedMemory *shm,
369 */ 369 */
370ssize_t 370ssize_t
371EXTRACTOR_IPC_shared_memory_set_ (struct EXTRACTOR_SharedMemory *shm, 371EXTRACTOR_IPC_shared_memory_set_ (struct EXTRACTOR_SharedMemory *shm,
372 struct EXTRACTOR_Datasource *ds, 372 struct EXTRACTOR_Datasource *ds,
373 uint64_t off, 373 uint64_t off,
374 size_t size); 374 size_t size);
375 375
376 376
377/** 377/**
@@ -391,10 +391,10 @@ EXTRACTOR_datasource_get_pos_ (struct EXTRACTOR_Datasource *ds);
391 * @param plugin the plugin 391 * @param plugin the plugin
392 * @param shm memory to share with the process 392 * @param shm memory to share with the process
393 * @return NULL on error, otherwise IPC channel 393 * @return NULL on error, otherwise IPC channel
394 */ 394 */
395struct EXTRACTOR_Channel * 395struct EXTRACTOR_Channel *
396EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin, 396EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
397 struct EXTRACTOR_SharedMemory *shm); 397 struct EXTRACTOR_SharedMemory *shm);
398 398
399 399
400/** 400/**
@@ -418,8 +418,8 @@ EXTRACTOR_IPC_channel_destroy_ (struct EXTRACTOR_Channel *channel);
418 */ 418 */
419ssize_t 419ssize_t
420EXTRACTOR_IPC_channel_send_ (struct EXTRACTOR_Channel *channel, 420EXTRACTOR_IPC_channel_send_ (struct EXTRACTOR_Channel *channel,
421 const void *data, 421 const void *data,
422 size_t size); 422 size_t size);
423 423
424 424
425/** 425/**
@@ -434,12 +434,15 @@ EXTRACTOR_IPC_channel_send_ (struct EXTRACTOR_Channel *channel,
434 * @param value_len number of bytes in 'value' 434 * @param value_len number of bytes in 'value'
435 */ 435 */
436typedef void (*EXTRACTOR_ChannelMessageProcessor) (void *cls, 436typedef void (*EXTRACTOR_ChannelMessageProcessor) (void *cls,
437 struct EXTRACTOR_PluginList *plugin, 437 struct EXTRACTOR_PluginList *
438 enum EXTRACTOR_MetaType meta_type, 438 plugin,
439 enum EXTRACTOR_MetaFormat meta_format, 439 enum EXTRACTOR_MetaType
440 const char *mime, 440 meta_type,
441 const void *value, 441 enum EXTRACTOR_MetaFormat
442 size_t value_len); 442 meta_format,
443 const char *mime,
444 const void *value,
445 size_t value_len);
443 446
444 447
445/** 448/**
@@ -454,10 +457,10 @@ typedef void (*EXTRACTOR_ChannelMessageProcessor) (void *cls,
454 */ 457 */
455ssize_t 458ssize_t
456EXTRACTOR_IPC_process_reply_ (struct EXTRACTOR_PluginList *plugin, 459EXTRACTOR_IPC_process_reply_ (struct EXTRACTOR_PluginList *plugin,
457 const void *data, 460 const void *data,
458 size_t size, 461 size_t size,
459 EXTRACTOR_ChannelMessageProcessor proc, 462 EXTRACTOR_ChannelMessageProcessor proc,
460 void *proc_cls); 463 void *proc_cls);
461 464
462 465
463/** 466/**
@@ -473,9 +476,9 @@ EXTRACTOR_IPC_process_reply_ (struct EXTRACTOR_PluginList *plugin,
473 */ 476 */
474int 477int
475EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels, 478EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels,
476 unsigned int num_channels, 479 unsigned int num_channels,
477 EXTRACTOR_ChannelMessageProcessor proc, 480 EXTRACTOR_ChannelMessageProcessor proc,
478 void *proc_cls); 481 void *proc_cls);
479 482
480 483
481#endif 484#endif
diff --git a/src/main/extractor_ipc_gnu.c b/src/main/extractor_ipc_gnu.c
index 7bb8914..5400636 100644
--- a/src/main/extractor_ipc_gnu.c
+++ b/src/main/extractor_ipc_gnu.c
@@ -138,10 +138,10 @@ EXTRACTOR_IPC_shared_memory_create_ (size_t size)
138 const char *tpath; 138 const char *tpath;
139 139
140 if (NULL == (shm = malloc (sizeof (struct EXTRACTOR_SharedMemory)))) 140 if (NULL == (shm = malloc (sizeof (struct EXTRACTOR_SharedMemory))))
141 { 141 {
142 LOG_STRERROR ("malloc"); 142 LOG_STRERROR ("malloc");
143 return NULL; 143 return NULL;
144 } 144 }
145#if SOMEBSD 145#if SOMEBSD
146 /* this works on FreeBSD, not sure about others... */ 146 /* this works on FreeBSD, not sure about others... */
147 tpath = getenv ("TMPDIR"); 147 tpath = getenv ("TMPDIR");
@@ -151,24 +151,24 @@ EXTRACTOR_IPC_shared_memory_create_ (size_t size)
151 tpath = "/"; /* Linux */ 151 tpath = "/"; /* Linux */
152#endif 152#endif
153 snprintf (shm->shm_name, 153 snprintf (shm->shm_name,
154 MAX_SHM_NAME, 154 MAX_SHM_NAME,
155 "%sLE-%u-%u", 155 "%sLE-%u-%u",
156 tpath, getpid (), 156 tpath, getpid (),
157 (unsigned int) RANDOM()); 157 (unsigned int) RANDOM ());
158 if (-1 == (shm->shm_id = shm_open (shm->shm_name, 158 if (-1 == (shm->shm_id = shm_open (shm->shm_name,
159 O_RDWR | O_CREAT, S_IRUSR | S_IWUSR))) 159 O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)))
160 { 160 {
161 LOG_STRERROR_FILE ("shm_open", 161 LOG_STRERROR_FILE ("shm_open",
162 shm->shm_name); 162 shm->shm_name);
163 free (shm); 163 free (shm);
164 return NULL; 164 return NULL;
165 } 165 }
166 if ( (0 != ftruncate (shm->shm_id, size)) || 166 if ( (0 != ftruncate (shm->shm_id, size)) ||
167 (NULL == (shm->shm_ptr = mmap (NULL, 167 (NULL == (shm->shm_ptr = mmap (NULL,
168 size, 168 size,
169 PROT_WRITE, 169 PROT_WRITE,
170 MAP_SHARED, 170 MAP_SHARED,
171 shm->shm_id, 171 shm->shm_id,
172 0))) || 172 0))) ||
173 (((void*) -1) == shm->shm_ptr) ) 173 (((void*) -1) == shm->shm_ptr) )
174 { 174 {
@@ -193,7 +193,7 @@ EXTRACTOR_IPC_shared_memory_create_ (size_t size)
193 */ 193 */
194unsigned int 194unsigned int
195EXTRACTOR_IPC_shared_memory_change_rc_ (struct EXTRACTOR_SharedMemory *shm, 195EXTRACTOR_IPC_shared_memory_change_rc_ (struct EXTRACTOR_SharedMemory *shm,
196 int delta) 196 int delta)
197{ 197{
198 shm->rc += delta; 198 shm->rc += delta;
199 return shm->rc; 199 return shm->rc;
@@ -228,23 +228,23 @@ EXTRACTOR_IPC_shared_memory_destroy_ (struct EXTRACTOR_SharedMemory *shm)
228 */ 228 */
229ssize_t 229ssize_t
230EXTRACTOR_IPC_shared_memory_set_ (struct EXTRACTOR_SharedMemory *shm, 230EXTRACTOR_IPC_shared_memory_set_ (struct EXTRACTOR_SharedMemory *shm,
231 struct EXTRACTOR_Datasource *ds, 231 struct EXTRACTOR_Datasource *ds,
232 uint64_t off, 232 uint64_t off,
233 size_t size) 233 size_t size)
234{ 234{
235 if (-1 == 235 if (-1 ==
236 EXTRACTOR_datasource_seek_ (ds, 236 EXTRACTOR_datasource_seek_ (ds,
237 off, 237 off,
238 SEEK_SET)) 238 SEEK_SET))
239 { 239 {
240 LOG ("Failed to set IPC memory due to seek error\n"); 240 LOG ("Failed to set IPC memory due to seek error\n");
241 return -1; 241 return -1;
242 } 242 }
243 if (size > shm->shm_size) 243 if (size > shm->shm_size)
244 size = shm->shm_size; 244 size = shm->shm_size;
245 return EXTRACTOR_datasource_read_ (ds, 245 return EXTRACTOR_datasource_read_ (ds,
246 shm->shm_ptr, 246 shm->shm_ptr,
247 size); 247 size);
248} 248}
249 249
250 250
@@ -277,7 +277,7 @@ EXTRACTOR_datasource_get_pos_ (struct EXTRACTOR_Datasource *ds)
277 */ 277 */
278struct EXTRACTOR_Channel * 278struct EXTRACTOR_Channel *
279EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin, 279EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
280 struct EXTRACTOR_SharedMemory *shm) 280 struct EXTRACTOR_SharedMemory *shm)
281{ 281{
282 struct EXTRACTOR_Channel *channel; 282 struct EXTRACTOR_Channel *channel;
283 int p1[2]; 283 int p1[2];
@@ -287,74 +287,74 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
287 size_t slen; 287 size_t slen;
288 288
289 if (NULL == (channel = malloc (sizeof (struct EXTRACTOR_Channel)))) 289 if (NULL == (channel = malloc (sizeof (struct EXTRACTOR_Channel))))
290 { 290 {
291 LOG_STRERROR ("malloc"); 291 LOG_STRERROR ("malloc");
292 return NULL; 292 return NULL;
293 } 293 }
294 channel->mdata_size = 1024; 294 channel->mdata_size = 1024;
295 if (NULL == (channel->mdata = malloc (channel->mdata_size))) 295 if (NULL == (channel->mdata = malloc (channel->mdata_size)))
296 { 296 {
297 LOG_STRERROR ("malloc"); 297 LOG_STRERROR ("malloc");
298 free (channel); 298 free (channel);
299 return NULL; 299 return NULL;
300 } 300 }
301 channel->shm = shm; 301 channel->shm = shm;
302 channel->plugin = plugin; 302 channel->plugin = plugin;
303 channel->size = 0; 303 channel->size = 0;
304 if (0 != pipe (p1)) 304 if (0 != pipe (p1))
305 { 305 {
306 LOG_STRERROR ("pipe"); 306 LOG_STRERROR ("pipe");
307 free (channel->mdata); 307 free (channel->mdata);
308 free (channel); 308 free (channel);
309 return NULL; 309 return NULL;
310 } 310 }
311 if (0 != pipe (p2)) 311 if (0 != pipe (p2))
312 { 312 {
313 LOG_STRERROR ("pipe"); 313 LOG_STRERROR ("pipe");
314 (void) close (p1[0]); 314 (void) close (p1[0]);
315 (void) close (p1[1]); 315 (void) close (p1[1]);
316 free (channel->mdata); 316 free (channel->mdata);
317 free (channel); 317 free (channel);
318 return NULL; 318 return NULL;
319 } 319 }
320 pid = fork (); 320 pid = fork ();
321 if (pid == -1) 321 if (pid == -1)
322 { 322 {
323 LOG_STRERROR ("fork"); 323 LOG_STRERROR ("fork");
324 (void) close (p1[0]); 324 (void) close (p1[0]);
325 (void) close (p1[1]); 325 (void) close (p1[1]);
326 (void) close (p2[0]); 326 (void) close (p2[0]);
327 (void) close (p2[1]); 327 (void) close (p2[1]);
328 free (channel->mdata); 328 free (channel->mdata);
329 free (channel); 329 free (channel);
330 return NULL; 330 return NULL;
331 } 331 }
332 if (0 == pid) 332 if (0 == pid)
333 { 333 {
334 (void) close (p1[1]); 334 (void) close (p1[1]);
335 (void) close (p2[0]); 335 (void) close (p2[0]);
336 free (channel->mdata); 336 free (channel->mdata);
337 free (channel); 337 free (channel);
338#if HAVE_SYS_APPARMOR_H 338#if HAVE_SYS_APPARMOR_H
339#if HAVE_APPARMOR 339#if HAVE_APPARMOR
340 if (0 > aa_change_profile("libextractor")) 340 if (0 > aa_change_profile ("libextractor"))
341 {
342 int eno = errno;
343
344 if ( (EINVAL != eno) &&
345 (ENOENT != eno) )
341 { 346 {
342 int eno = errno; 347 fprintf (stderr,
343 348 "Failure changing AppArmor profile: %s\n",
344 if ( (EINVAL != eno) && 349 strerror (errno));
345 (ENOENT != eno) ) 350 _exit (1);
346 {
347 fprintf (stderr,
348 "Failure changing AppArmor profile: %s\n",
349 strerror (errno));
350 _exit(1);
351 }
352 } 351 }
352 }
353#endif 353#endif
354#endif 354#endif
355 EXTRACTOR_plugin_main_ (plugin, p1[0], p2[1]); 355 EXTRACTOR_plugin_main_ (plugin, p1[0], p2[1]);
356 _exit (0); 356 _exit (0);
357 } 357 }
358 (void) close (p1[0]); 358 (void) close (p1[0]);
359 (void) close (p2[1]); 359 (void) close (p2[1]);
360 channel->cpipe_in = p1[1]; 360 channel->cpipe_in = p1[1];
@@ -362,11 +362,11 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
362 channel->cpid = pid; 362 channel->cpid = pid;
363 slen = strlen (shm->shm_name) + 1; 363 slen = strlen (shm->shm_name) + 1;
364 if (NULL == (init = malloc (sizeof (struct InitMessage) + slen))) 364 if (NULL == (init = malloc (sizeof (struct InitMessage) + slen)))
365 { 365 {
366 LOG_STRERROR ("malloc"); 366 LOG_STRERROR ("malloc");
367 EXTRACTOR_IPC_channel_destroy_ (channel); 367 EXTRACTOR_IPC_channel_destroy_ (channel);
368 return NULL; 368 return NULL;
369 } 369 }
370 init->opcode = MESSAGE_INIT_STATE; 370 init->opcode = MESSAGE_INIT_STATE;
371 init->reserved = 0; 371 init->reserved = 0;
372 init->reserved2 = 0; 372 init->reserved2 = 0;
@@ -375,14 +375,14 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
375 memcpy (&init[1], shm->shm_name, slen); 375 memcpy (&init[1], shm->shm_name, slen);
376 if (sizeof (struct InitMessage) + slen != 376 if (sizeof (struct InitMessage) + slen !=
377 EXTRACTOR_IPC_channel_send_ (channel, 377 EXTRACTOR_IPC_channel_send_ (channel,
378 init, 378 init,
379 sizeof (struct InitMessage) + slen) ) 379 sizeof (struct InitMessage) + slen) )
380 { 380 {
381 LOG ("Failed to send INIT_STATE message to plugin\n"); 381 LOG ("Failed to send INIT_STATE message to plugin\n");
382 EXTRACTOR_IPC_channel_destroy_ (channel); 382 EXTRACTOR_IPC_channel_destroy_ (channel);
383 free (init); 383 free (init);
384 return NULL; 384 return NULL;
385 } 385 }
386 free (init); 386 free (init);
387 return channel; 387 return channel;
388} 388}
@@ -425,24 +425,24 @@ EXTRACTOR_IPC_channel_destroy_ (struct EXTRACTOR_Channel *channel)
425 */ 425 */
426ssize_t 426ssize_t
427EXTRACTOR_IPC_channel_send_ (struct EXTRACTOR_Channel *channel, 427EXTRACTOR_IPC_channel_send_ (struct EXTRACTOR_Channel *channel,
428 const void *data, 428 const void *data,
429 size_t size) 429 size_t size)
430{ 430{
431 const char *cdata = data; 431 const char *cdata = data;
432 size_t off = 0; 432 size_t off = 0;
433 ssize_t ret; 433 ssize_t ret;
434 434
435 while (off < size) 435 while (off < size)
436 {
437 ret = write (channel->cpipe_in, &cdata[off], size - off);
438 if (ret <= 0)
436 { 439 {
437 ret = write (channel->cpipe_in, &cdata[off], size - off); 440 if (-1 == ret)
438 if (ret <= 0) 441 LOG_STRERROR ("write");
439 { 442 return -1;
440 if (-1 == ret)
441 LOG_STRERROR ("write");
442 return -1;
443 }
444 off += ret;
445 } 443 }
444 off += ret;
445 }
446 return size; 446 return size;
447} 447}
448 448
@@ -464,9 +464,9 @@ EXTRACTOR_IPC_channel_send_ (struct EXTRACTOR_Channel *channel,
464 */ 464 */
465int 465int
466EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels, 466EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels,
467 unsigned int num_channels, 467 unsigned int num_channels,
468 EXTRACTOR_ChannelMessageProcessor proc, 468 EXTRACTOR_ChannelMessageProcessor proc,
469 void *proc_cls) 469 void *proc_cls)
470{ 470{
471 struct timeval tv; 471 struct timeval tv;
472 fd_set to_check; 472 fd_set to_check;
@@ -480,105 +480,106 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels,
480 480
481 FD_ZERO (&to_check); 481 FD_ZERO (&to_check);
482 max = -1; 482 max = -1;
483 for (i=0;i<num_channels;i++) 483 for (i = 0; i<num_channels; i++)
484 {
485 channel = channels[i];
486 if (NULL == channel)
487 continue;
488 FD_SET (channel->cpipe_out, &to_check);
489 if (max < channel->cpipe_out)
490 max = channel->cpipe_out;
491 }
492 if (-1 == max)
493 {
494 return 1; /* nothing left to do! */
495 }
496 tv.tv_sec = 0;
497 tv.tv_usec = 500000; /* 500 ms */
498 if (0 >= select (max + 1, &to_check, NULL, NULL, &tv))
499 {
500 /* an error or timeout -> something's wrong or all plugins hung up */
501 closed_channel = 0;
502 for (i = 0; i<num_channels; i++)
484 { 503 {
485 channel = channels[i]; 504 channel = channels[i];
486 if (NULL == channel) 505 if (NULL == channel)
487 continue; 506 continue;
488 FD_SET (channel->cpipe_out, &to_check); 507 if (-1 == channel->plugin->seek_request)
489 if (max < channel->cpipe_out) 508 {
490 max = channel->cpipe_out; 509 /* plugin blocked for too long, kill channel */
510 LOG ("Channel blocked, closing channel to %s\n",
511 channel->plugin->libname);
512 channel->plugin->channel = NULL;
513 channel->plugin->round_finished = 1;
514 EXTRACTOR_IPC_channel_destroy_ (channel);
515 channels[i] = NULL;
516 closed_channel = 1;
517 }
491 } 518 }
492 if (-1 == max) 519 if (1 == closed_channel)
520 return 1;
521 /* strange, no channel is to blame, let's die just to be safe */
522 if ((EINTR != errno) && (0 != errno))
523 LOG_STRERROR ("select");
524 return -1;
525 }
526 for (i = 0; i<num_channels; i++)
527 {
528 channel = channels[i];
529 if (NULL == channel)
530 continue;
531 if (! FD_ISSET (channel->cpipe_out, &to_check))
532 continue;
533 if (channel->mdata_size == channel->size)
493 { 534 {
494 return 1; /* nothing left to do! */ 535 /* not enough space, need to grow allocation (if allowed) */
536 if (MAX_META_DATA == channel->mdata_size)
537 {
538 LOG ("Inbound message from channel too large, aborting\n");
539 EXTRACTOR_IPC_channel_destroy_ (channel);
540 channels[i] = NULL;
541 continue;
542 }
543 channel->mdata_size *= 2;
544 if (channel->mdata_size > MAX_META_DATA)
545 channel->mdata_size = MAX_META_DATA;
546 if (NULL == (ndata = realloc (channel->mdata,
547 channel->mdata_size)))
548 {
549 LOG_STRERROR ("realloc");
550 EXTRACTOR_IPC_channel_destroy_ (channel);
551 channels[i] = NULL;
552 continue;
553 }
554 channel->mdata = ndata;
495 } 555 }
496 tv.tv_sec = 0; 556 if ( (-1 == (iret = read (channel->cpipe_out,
497 tv.tv_usec = 500000; /* 500 ms */ 557 &channel->mdata[channel->size],
498 if (0 >= select (max + 1, &to_check, NULL, NULL, &tv)) 558 channel->mdata_size - channel->size)) ) ||
559 (0 == iret) ||
560 (-1 == (ret = EXTRACTOR_IPC_process_reply_ (channel->plugin,
561 channel->mdata,
562 channel->size + iret,
563 proc, proc_cls)) ) )
499 { 564 {
500 /* an error or timeout -> something's wrong or all plugins hung up */ 565 if (-1 == iret)
501 closed_channel = 0; 566 LOG_STRERROR ("read");
502 for (i=0;i<num_channels;i++) 567 LOG ("Read error from channel, closing channel %s\n",
503 { 568 channel->plugin->libname);
504 channel = channels[i]; 569 EXTRACTOR_IPC_channel_destroy_ (channel);
505 if (NULL == channel) 570 channels[i] = NULL;
506 continue; 571 continue;
507 if (-1 == channel->plugin->seek_request)
508 {
509 /* plugin blocked for too long, kill channel */
510 LOG ("Channel blocked, closing channel to %s\n",
511 channel->plugin->libname);
512 channel->plugin->channel = NULL;
513 channel->plugin->round_finished = 1;
514 EXTRACTOR_IPC_channel_destroy_ (channel);
515 channels[i] = NULL;
516 closed_channel = 1;
517 }
518 }
519 if (1 == closed_channel)
520 return 1;
521 /* strange, no channel is to blame, let's die just to be safe */
522 if ((EINTR != errno) && (0 != errno))
523 LOG_STRERROR ("select");
524 return -1;
525 } 572 }
526 for (i=0;i<num_channels;i++) 573 else
527 { 574 {
528 channel = channels[i]; 575 channel->size = channel->size + iret - ret;
529 if (NULL == channel) 576 memmove (channel->mdata,
530 continue; 577 &channel->mdata[ret],
531 if (! FD_ISSET (channel->cpipe_out, &to_check)) 578 channel->size);
532 continue;
533 if (channel->mdata_size == channel->size)
534 {
535 /* not enough space, need to grow allocation (if allowed) */
536 if (MAX_META_DATA == channel->mdata_size)
537 {
538 LOG ("Inbound message from channel too large, aborting\n");
539 EXTRACTOR_IPC_channel_destroy_ (channel);
540 channels[i] = NULL;
541 continue;
542 }
543 channel->mdata_size *= 2;
544 if (channel->mdata_size > MAX_META_DATA)
545 channel->mdata_size = MAX_META_DATA;
546 if (NULL == (ndata = realloc (channel->mdata,
547 channel->mdata_size)))
548 {
549 LOG_STRERROR ("realloc");
550 EXTRACTOR_IPC_channel_destroy_ (channel);
551 channels[i] = NULL;
552 continue;
553 }
554 channel->mdata = ndata;
555 }
556 if ( (-1 == (iret = read (channel->cpipe_out,
557 &channel->mdata[channel->size],
558 channel->mdata_size - channel->size)) ) ||
559 (0 == iret) ||
560 (-1 == (ret = EXTRACTOR_IPC_process_reply_ (channel->plugin,
561 channel->mdata,
562 channel->size + iret,
563 proc, proc_cls)) ) )
564 {
565 if (-1 == iret)
566 LOG_STRERROR ("read");
567 LOG ("Read error from channel, closing channel %s\n",
568 channel->plugin->libname);
569 EXTRACTOR_IPC_channel_destroy_ (channel);
570 channels[i] = NULL;
571 continue;
572 }
573 else
574 {
575 channel->size = channel->size + iret - ret;
576 memmove (channel->mdata,
577 &channel->mdata[ret],
578 channel->size);
579 }
580 } 579 }
580 }
581 return 1; 581 return 1;
582} 582}
583 583
584
584/* end of extractor_ipc_gnu.c */ 585/* end of extractor_ipc_gnu.c */
diff --git a/src/main/extractor_ipc_w32.c b/src/main/extractor_ipc_w32.c
index c4fbf1b..b53bc3c 100644
--- a/src/main/extractor_ipc_w32.c
+++ b/src/main/extractor_ipc_w32.c
@@ -34,32 +34,32 @@ struct EXTRACTOR_SharedMemory
34 34
35 /** 35 /**
36 * W32 handle of the shm into which data is uncompressed 36 * W32 handle of the shm into which data is uncompressed
37 */ 37 */
38 HANDLE map; 38 HANDLE map;
39 39
40 /** 40 /**
41 * Name of the shm 41 * Name of the shm
42 */ 42 */
43 char shm_name[MAX_SHM_NAME + 1]; 43 char shm_name[MAX_SHM_NAME + 1];
44 44
45 /** 45 /**
46 * Pointer to the mapped region of the shm (covers the whole shm) 46 * Pointer to the mapped region of the shm (covers the whole shm)
47 */ 47 */
48 void *ptr; 48 void *ptr;
49 49
50 /** 50 /**
51 * Position within shm 51 * Position within shm
52 */ 52 */
53 int64_t pos; 53 int64_t pos;
54 54
55 /** 55 /**
56 * Allocated size of the shm 56 * Allocated size of the shm
57 */ 57 */
58 int64_t shm_size; 58 int64_t shm_size;
59 59
60 /** 60 /**
61 * Number of bytes in shm (<= shm_size) 61 * Number of bytes in shm (<= shm_size)
62 */ 62 */
63 size_t shm_buf_size; 63 size_t shm_buf_size;
64 64
65 size_t shm_map_size; 65 size_t shm_map_size;
@@ -132,11 +132,11 @@ struct EXTRACTOR_Channel
132 */ 132 */
133 char *mdata; 133 char *mdata;
134 134
135 /** 135 /**
136 * Size of the 'mdata' buffer. 136 * Size of the 'mdata' buffer.
137 */ 137 */
138 size_t mdata_size; 138 size_t mdata_size;
139 139
140 /** 140 /**
141 * Number of valid bytes in the channel's buffer. 141 * Number of valid bytes in the channel's buffer.
142 */ 142 */
@@ -159,11 +159,12 @@ EXTRACTOR_IPC_shared_memory_create_ (size_t size)
159 if (NULL == (shm = malloc (sizeof (struct EXTRACTOR_SharedMemory)))) 159 if (NULL == (shm = malloc (sizeof (struct EXTRACTOR_SharedMemory))))
160 return NULL; 160 return NULL;
161 161
162 snprintf (shm->shm_name, MAX_SHM_NAME, 162 snprintf (shm->shm_name, MAX_SHM_NAME,
163 "%slibextractor-shm-%u-%u", 163 "%slibextractor-shm-%u-%u",
164 tpath, getpid(), 164 tpath, getpid (),
165 (unsigned int) RANDOM()); 165 (unsigned int) RANDOM ());
166 shm->map = CreateFileMapping (INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, shm->shm_name); 166 shm->map = CreateFileMapping (INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0,
167 size, shm->shm_name);
167 shm->ptr = MapViewOfFile (shm->map, FILE_MAP_WRITE, 0, 0, size); 168 shm->ptr = MapViewOfFile (shm->map, FILE_MAP_WRITE, 0, 0, size);
168 if (shm->ptr == NULL) 169 if (shm->ptr == NULL)
169 { 170 {
@@ -176,6 +177,7 @@ EXTRACTOR_IPC_shared_memory_create_ (size_t size)
176 return shm; 177 return shm;
177} 178}
178 179
180
179/** 181/**
180 * Change the reference counter for this shm instance. 182 * Change the reference counter for this shm instance.
181 * 183 *
@@ -185,7 +187,7 @@ EXTRACTOR_IPC_shared_memory_create_ (size_t size)
185 */ 187 */
186unsigned int 188unsigned int
187EXTRACTOR_IPC_shared_memory_change_rc_ (struct EXTRACTOR_SharedMemory *shm, 189EXTRACTOR_IPC_shared_memory_change_rc_ (struct EXTRACTOR_SharedMemory *shm,
188 int delta) 190 int delta)
189{ 191{
190 shm->rc += delta; 192 shm->rc += delta;
191 return shm->rc; 193 return shm->rc;
@@ -200,7 +202,7 @@ EXTRACTOR_IPC_shared_memory_change_rc_ (struct EXTRACTOR_SharedMemory *shm,
200 */ 202 */
201void 203void
202EXTRACTOR_IPC_shared_memory_destroy_ (struct EXTRACTOR_SharedMemory *shm) 204EXTRACTOR_IPC_shared_memory_destroy_ (struct EXTRACTOR_SharedMemory *shm)
203{ 205{
204 if (shm->ptr != NULL) 206 if (shm->ptr != NULL)
205 UnmapViewOfFile (shm->ptr); 207 UnmapViewOfFile (shm->ptr);
206 if (shm->map != 0) 208 if (shm->map != 0)
@@ -208,6 +210,7 @@ EXTRACTOR_IPC_shared_memory_destroy_ (struct EXTRACTOR_SharedMemory *shm)
208 free (shm); 210 free (shm);
209} 211}
210 212
213
211/** 214/**
212 * Initialize shared memory area from data source. 215 * Initialize shared memory area from data source.
213 * 216 *
@@ -219,21 +222,21 @@ EXTRACTOR_IPC_shared_memory_destroy_ (struct EXTRACTOR_SharedMemory *shm)
219 */ 222 */
220ssize_t 223ssize_t
221EXTRACTOR_IPC_shared_memory_set_ (struct EXTRACTOR_SharedMemory *shm, 224EXTRACTOR_IPC_shared_memory_set_ (struct EXTRACTOR_SharedMemory *shm,
222 struct EXTRACTOR_Datasource *ds, 225 struct EXTRACTOR_Datasource *ds,
223 uint64_t off, 226 uint64_t off,
224 size_t size) 227 size_t size)
225{ 228{
226 if (-1 == 229 if (-1 ==
227 EXTRACTOR_datasource_seek_ (ds, off, SEEK_SET)) 230 EXTRACTOR_datasource_seek_ (ds, off, SEEK_SET))
228 { 231 {
229 LOG ("Failed to set IPC memory due to seek error\n"); 232 LOG ("Failed to set IPC memory due to seek error\n");
230 return -1; 233 return -1;
231 } 234 }
232 if (size > shm->shm_size) 235 if (size > shm->shm_size)
233 size = shm->shm_size; 236 size = shm->shm_size;
234 return EXTRACTOR_datasource_read_ (ds, 237 return EXTRACTOR_datasource_read_ (ds,
235 shm->ptr, 238 shm->ptr,
236 size); 239 size);
237} 240}
238 241
239 242
@@ -291,7 +294,7 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
291 static volatile LONG pipe_unique_id; 294 static volatile LONG pipe_unique_id;
292 295
293 snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld", 296 snprintf (pipename, sizeof pipename, "\\\\.\\pipe\\gnunet-%d-%ld",
294 getpid (), InterlockedIncrement ((LONG *) & pipe_unique_id)); 297 getpid (), InterlockedIncrement ((LONG *) &pipe_unique_id));
295 /* Use CreateNamedPipe instead of CreatePipe, because the latter 298 /* Use CreateNamedPipe instead of CreatePipe, because the latter
296 * returns a write handle that does not permit FILE_READ_ATTRIBUTES 299 * returns a write handle that does not permit FILE_READ_ATTRIBUTES
297 * access, on versions of win32 earlier than WinXP SP2. 300 * access, on versions of win32 earlier than WinXP SP2.
@@ -300,8 +303,8 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
300 * It's important to only allow a single instance, to ensure that 303 * It's important to only allow a single instance, to ensure that
301 * the pipe was not created earlier by some other process, even if 304 * the pipe was not created earlier by some other process, even if
302 * the pid has been reused. We avoid FILE_FLAG_FIRST_PIPE_INSTANCE 305 * the pid has been reused. We avoid FILE_FLAG_FIRST_PIPE_INSTANCE
303 * because that is only available for Win2k SP2 and WinXP. */ 306 * because that is only available for Win2k SP2 and WinXP. */read_pipe = CreateNamedPipeA (pipename, PIPE_ACCESS_INBOUND | dwReadMode,
304 read_pipe = CreateNamedPipeA (pipename, PIPE_ACCESS_INBOUND | dwReadMode, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, /* max instances */ 307 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, /* max instances */
305 psize, /* output buffer size */ 308 psize, /* output buffer size */
306 psize, /* input buffer size */ 309 psize, /* input buffer size */
307 NMPWAIT_USE_DEFAULT_WAIT, sa_ptr); 310 NMPWAIT_USE_DEFAULT_WAIT, sa_ptr);
@@ -359,6 +362,7 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
359 return 0; 362 return 0;
360} 363}
361 364
365
362/** 366/**
363 * Communicates plugin data (library name, options) to the plugin 367 * Communicates plugin data (library name, options) to the plugin
364 * process. This is only necessary on W32, where this information 368 * process. This is only necessary on W32, where this information
@@ -367,10 +371,10 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, PHANDLE write_pipe_ptr,
367 * @param plugin plugin context 371 * @param plugin plugin context
368 * 372 *
369 * @return 0 on success, -1 on failure 373 * @return 0 on success, -1 on failure
370 */ 374 */
371static int 375static int
372write_plugin_data (struct EXTRACTOR_PluginList *plugin, 376write_plugin_data (struct EXTRACTOR_PluginList *plugin,
373 struct EXTRACTOR_Channel *channel) 377 struct EXTRACTOR_Channel *channel)
374{ 378{
375 size_t libname_len, shortname_len, opts_len; 379 size_t libname_len, shortname_len, opts_len;
376 DWORD len; 380 DWORD len;
@@ -418,6 +422,7 @@ write_plugin_data (struct EXTRACTOR_PluginList *plugin,
418 return total_len == write_result; 422 return total_len == write_result;
419} 423}
420 424
425
421/** 426/**
422 * Create a channel to communicate with a process wrapping 427 * Create a channel to communicate with a process wrapping
423 * the plugin of the given name. Starts the process as well. 428 * the plugin of the given name. Starts the process as well.
@@ -425,10 +430,10 @@ write_plugin_data (struct EXTRACTOR_PluginList *plugin,
425 * @param plugin the plugin 430 * @param plugin the plugin
426 * @param shm memory to share with the process 431 * @param shm memory to share with the process
427 * @return NULL on error, otherwise IPC channel 432 * @return NULL on error, otherwise IPC channel
428 */ 433 */
429struct EXTRACTOR_Channel * 434struct EXTRACTOR_Channel *
430EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin, 435EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
431 struct EXTRACTOR_SharedMemory *shm) 436 struct EXTRACTOR_SharedMemory *shm)
432{ 437{
433 struct EXTRACTOR_Channel *channel; 438 struct EXTRACTOR_Channel *channel;
434 HANDLE p1[2]; 439 HANDLE p1[2];
@@ -445,18 +450,19 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
445 SECURITY_ATTRIBUTES sa; 450 SECURITY_ATTRIBUTES sa;
446 451
447 if (NULL == (channel = malloc (sizeof (struct EXTRACTOR_Channel)))) 452 if (NULL == (channel = malloc (sizeof (struct EXTRACTOR_Channel))))
448 { 453 {
449 LOG_STRERROR ("malloc"); 454 LOG_STRERROR ("malloc");
450 return NULL; 455 return NULL;
451 } 456 }
452 memset (channel, 0, sizeof (struct EXTRACTOR_Channel)); 457 memset (channel, 0, sizeof (struct EXTRACTOR_Channel));
453 channel->mdata_size = 1024; 458 channel->mdata_size = 1024;
454 if (NULL == (channel->mdata = malloc (channel->mdata_size))) 459 if (NULL == (channel->mdata = malloc (channel->mdata_size)))
455 { 460 {
456 LOG_STRERROR ("malloc"); 461 LOG_STRERROR ("malloc");
457 free (channel); 462 free (channel);
458 return NULL; 463 return NULL;
459 } channel->shm = shm; 464 }
465 channel->shm = shm;
460 channel->plugin = plugin; 466 channel->plugin = plugin;
461 channel->size = 0; 467 channel->size = 0;
462 468
@@ -464,13 +470,15 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
464 sa.lpSecurityDescriptor = NULL; 470 sa.lpSecurityDescriptor = NULL;
465 sa.bInheritHandle = FALSE; 471 sa.bInheritHandle = FALSE;
466 472
467 if (0 != create_selectable_pipe (&p1[0], &p1[1], &sa, 1024, FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED)) 473 if (0 != create_selectable_pipe (&p1[0], &p1[1], &sa, 1024,
474 FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED))
468 { 475 {
469 LOG_STRERROR ("pipe"); 476 LOG_STRERROR ("pipe");
470 free (channel); 477 free (channel);
471 return NULL; 478 return NULL;
472 } 479 }
473 if (0 != create_selectable_pipe (&p2[0], &p2[1], &sa, 1024, FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED)) 480 if (0 != create_selectable_pipe (&p2[0], &p2[1], &sa, 1024,
481 FILE_FLAG_OVERLAPPED, FILE_FLAG_OVERLAPPED))
474 { 482 {
475 LOG_STRERROR ("pipe"); 483 LOG_STRERROR ("pipe");
476 CloseHandle (p1[0]); 484 CloseHandle (p1[0]);
@@ -479,10 +487,10 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
479 return NULL; 487 return NULL;
480 } 488 }
481 489
482 if (!DuplicateHandle (GetCurrentProcess (), p1[0], GetCurrentProcess (), 490 if (! DuplicateHandle (GetCurrentProcess (), p1[0], GetCurrentProcess (),
483 &p10_os_inh, 0, TRUE, DUPLICATE_SAME_ACCESS) 491 &p10_os_inh, 0, TRUE, DUPLICATE_SAME_ACCESS)
484 || !DuplicateHandle (GetCurrentProcess (), p2[1], GetCurrentProcess (), 492 || ! DuplicateHandle (GetCurrentProcess (), p2[1], GetCurrentProcess (),
485 &p21_os_inh, 0, TRUE, DUPLICATE_SAME_ACCESS)) 493 &p21_os_inh, 0, TRUE, DUPLICATE_SAME_ACCESS))
486 { 494 {
487 LOG_STRERROR ("DuplicateHandle"); 495 LOG_STRERROR ("DuplicateHandle");
488 if (p10_os_inh != INVALID_HANDLE_VALUE) 496 if (p10_os_inh != INVALID_HANDLE_VALUE)
@@ -506,13 +514,13 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
506 * Also, users might freak out seeing over 9000 rundll32 processes (seeing over 9000 processes named 514 * Also, users might freak out seeing over 9000 rundll32 processes (seeing over 9000 processes named
507 * "libextractor_plugin_helper" is probably less confusing). 515 * "libextractor_plugin_helper" is probably less confusing).
508 */ 516 */
509 snprintf(cmd, MAX_PATH, 517 snprintf (cmd, MAX_PATH,
510 "rundll32.exe libextractor-3.dll,RundllEntryPoint@16 %lu %lu", 518 "rundll32.exe libextractor-3.dll,RundllEntryPoint@16 %lu %lu",
511 p10_os_inh, p21_os_inh); 519 p10_os_inh, p21_os_inh);
512 cmd[MAX_PATH] = '\0'; 520 cmd[MAX_PATH] = '\0';
513 startup.cb = sizeof (STARTUPINFOA); 521 startup.cb = sizeof (STARTUPINFOA);
514 if (CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL, 522 if (CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL,
515 &startup, &proc)) 523 &startup, &proc))
516 { 524 {
517 channel->hProcess = proc.hProcess; 525 channel->hProcess = proc.hProcess;
518 ResumeThread (proc.hThread); 526 ResumeThread (proc.hThread);
@@ -544,7 +552,7 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
544 channel->ov_write.hEvent = CreateEvent (NULL, TRUE, TRUE, NULL); 552 channel->ov_write.hEvent = CreateEvent (NULL, TRUE, TRUE, NULL);
545 channel->ov_read.hEvent = CreateEvent (NULL, TRUE, TRUE, NULL); 553 channel->ov_read.hEvent = CreateEvent (NULL, TRUE, TRUE, NULL);
546 554
547 if (!write_plugin_data (plugin, channel)) 555 if (! write_plugin_data (plugin, channel))
548 { 556 {
549 LOG_STRERROR ("write_plugin_data"); 557 LOG_STRERROR ("write_plugin_data");
550 EXTRACTOR_IPC_channel_destroy_ (channel); 558 EXTRACTOR_IPC_channel_destroy_ (channel);
@@ -553,11 +561,11 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
553 561
554 slen = strlen (shm->shm_name) + 1; 562 slen = strlen (shm->shm_name) + 1;
555 if (NULL == (init = malloc (sizeof (struct InitMessage) + slen))) 563 if (NULL == (init = malloc (sizeof (struct InitMessage) + slen)))
556 { 564 {
557 LOG_STRERROR ("malloc"); 565 LOG_STRERROR ("malloc");
558 EXTRACTOR_IPC_channel_destroy_ (channel); 566 EXTRACTOR_IPC_channel_destroy_ (channel);
559 return NULL; 567 return NULL;
560 } 568 }
561 init->opcode = MESSAGE_INIT_STATE; 569 init->opcode = MESSAGE_INIT_STATE;
562 init->reserved = 0; 570 init->reserved = 0;
563 init->reserved2 = 0; 571 init->reserved2 = 0;
@@ -566,17 +574,18 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
566 memcpy (&init[1], shm->shm_name, slen); 574 memcpy (&init[1], shm->shm_name, slen);
567 if (sizeof (struct InitMessage) + slen != 575 if (sizeof (struct InitMessage) + slen !=
568 EXTRACTOR_IPC_channel_send_ (channel, init, 576 EXTRACTOR_IPC_channel_send_ (channel, init,
569 sizeof (struct InitMessage) + slen)) 577 sizeof (struct InitMessage) + slen))
570 { 578 {
571 LOG ("Failed to send INIT_STATE message to plugin\n"); 579 LOG ("Failed to send INIT_STATE message to plugin\n");
572 EXTRACTOR_IPC_channel_destroy_ (channel); 580 EXTRACTOR_IPC_channel_destroy_ (channel);
573 free (init); 581 free (init);
574 return NULL; 582 return NULL;
575 } 583 }
576 free (init); 584 free (init);
577 return channel; 585 return channel;
578} 586}
579 587
588
580/** 589/**
581 * Destroy communication channel with a plugin/process. Also 590 * Destroy communication channel with a plugin/process. Also
582 * destroys the process. 591 * destroys the process.
@@ -606,6 +615,7 @@ EXTRACTOR_IPC_channel_destroy_ (struct EXTRACTOR_Channel *channel)
606 free (channel); 615 free (channel);
607} 616}
608 617
618
609/** 619/**
610 * Send data via the given IPC channel (blocking). 620 * Send data via the given IPC channel (blocking).
611 * 621 *
@@ -617,8 +627,8 @@ EXTRACTOR_IPC_channel_destroy_ (struct EXTRACTOR_Channel *channel)
617 */ 627 */
618ssize_t 628ssize_t
619EXTRACTOR_IPC_channel_send_ (struct EXTRACTOR_Channel *channel, 629EXTRACTOR_IPC_channel_send_ (struct EXTRACTOR_Channel *channel,
620 const void *data, 630 const void *data,
621 size_t size) 631 size_t size)
622{ 632{
623 DWORD written; 633 DWORD written;
624 DWORD err; 634 DWORD err;
@@ -644,7 +654,8 @@ EXTRACTOR_IPC_channel_send_ (struct EXTRACTOR_Channel *channel,
644 channel->ov_write.Pointer = 0; 654 channel->ov_write.Pointer = 0;
645 channel->ov_write.Internal = 0; 655 channel->ov_write.Internal = 0;
646 channel->ov_write.InternalHigh = 0; 656 channel->ov_write.InternalHigh = 0;
647 bresult = WriteFile (channel->cpipe_in, channel->old_buf, size, &written, &channel->ov_write); 657 bresult = WriteFile (channel->cpipe_in, channel->old_buf, size, &written,
658 &channel->ov_write);
648 659
649 if (bresult == TRUE) 660 if (bresult == TRUE)
650 { 661 {
@@ -682,9 +693,9 @@ EXTRACTOR_IPC_channel_send_ (struct EXTRACTOR_Channel *channel,
682 */ 693 */
683int 694int
684EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels, 695EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels,
685 unsigned int num_channels, 696 unsigned int num_channels,
686 EXTRACTOR_ChannelMessageProcessor proc, 697 EXTRACTOR_ChannelMessageProcessor proc,
687 void *proc_cls) 698 void *proc_cls)
688{ 699{
689 DWORD ms; 700 DWORD ms;
690 DWORD first_ready; 701 DWORD first_ready;
@@ -707,7 +718,8 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels,
707 if (WaitForSingleObject (channels[i]->ov_read.hEvent, 0) == WAIT_OBJECT_0) 718 if (WaitForSingleObject (channels[i]->ov_read.hEvent, 0) == WAIT_OBJECT_0)
708 { 719 {
709 ResetEvent (channels[i]->ov_read.hEvent); 720 ResetEvent (channels[i]->ov_read.hEvent);
710 bresult = ReadFile (channels[i]->cpipe_out, &i, 0, &bytes_read, &channels[i]->ov_read); 721 bresult = ReadFile (channels[i]->cpipe_out, &i, 0, &bytes_read,
722 &channels[i]->ov_read);
711 if (bresult == TRUE) 723 if (bresult == TRUE)
712 { 724 {
713 SetEvent (channels[i]->ov_read.hEvent); 725 SetEvent (channels[i]->ov_read.hEvent);
@@ -728,7 +740,7 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels,
728 740
729 ms = 500; 741 ms = 500;
730 first_ready = WaitForMultipleObjects (c, events, FALSE, ms); 742 first_ready = WaitForMultipleObjects (c, events, FALSE, ms);
731 if (first_ready == WAIT_TIMEOUT || first_ready == WAIT_FAILED) 743 if ((first_ready == WAIT_TIMEOUT) || (first_ready == WAIT_FAILED))
732 { 744 {
733 /* an error or timeout -> something's wrong or all plugins hung up */ 745 /* an error or timeout -> something's wrong or all plugins hung up */
734 closed_channel = 0; 746 closed_channel = 0;
@@ -765,37 +777,40 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels,
765 { 777 {
766 int ret; 778 int ret;
767 if (channels[i]->mdata_size == channels[i]->size) 779 if (channels[i]->mdata_size == channels[i]->size)
768 { 780 {
769 /* not enough space, need to grow allocation (if allowed) */ 781 /* not enough space, need to grow allocation (if allowed) */
770 if (MAX_META_DATA == channels[i]->mdata_size) 782 if (MAX_META_DATA == channels[i]->mdata_size)
771 { 783 {
772 LOG ("Inbound message from channel too large, aborting\n"); 784 LOG ("Inbound message from channel too large, aborting\n");
773 EXTRACTOR_IPC_channel_destroy_ (channels[i]); 785 EXTRACTOR_IPC_channel_destroy_ (channels[i]);
774 channels[i] = NULL; 786 channels[i] = NULL;
775 } 787 }
776 channels[i]->mdata_size *= 2; 788 channels[i]->mdata_size *= 2;
777 if (channels[i]->mdata_size > MAX_META_DATA) 789 if (channels[i]->mdata_size > MAX_META_DATA)
778 channels[i]->mdata_size = MAX_META_DATA; 790 channels[i]->mdata_size = MAX_META_DATA;
779 if (NULL == (ndata = realloc (channels[i]->mdata, 791 if (NULL == (ndata = realloc (channels[i]->mdata,
780 channels[i]->mdata_size))) 792 channels[i]->mdata_size)))
781 { 793 {
782 LOG_STRERROR ("realloc"); 794 LOG_STRERROR ("realloc");
783 EXTRACTOR_IPC_channel_destroy_ (channels[i]); 795 EXTRACTOR_IPC_channel_destroy_ (channels[i]);
784 channels[i] = NULL; 796 channels[i] = NULL;
785 } 797 }
786 channels[i]->mdata = ndata; 798 channels[i]->mdata = ndata;
787 } 799 }
788 bresult = ReadFile (channels[i]->cpipe_out, 800 bresult = ReadFile (channels[i]->cpipe_out,
789 &channels[i]->mdata[channels[i]->size], 801 &channels[i]->mdata[channels[i]->size],
790 channels[i]->mdata_size - channels[i]->size, &bytes_read, NULL); 802 channels[i]->mdata_size - channels[i]->size,
803 &bytes_read, NULL);
791 if (bresult) 804 if (bresult)
792 ret = EXTRACTOR_IPC_process_reply_ (channels[i]->plugin, 805 ret = EXTRACTOR_IPC_process_reply_ (channels[i]->plugin,
793 channels[i]->mdata, channels[i]->size + bytes_read, proc, proc_cls); 806 channels[i]->mdata,
794 if (!bresult || -1 == ret) 807 channels[i]->size + bytes_read,
808 proc, proc_cls);
809 if (! bresult || (-1 == ret))
795 { 810 {
796 DWORD error = GetLastError (); 811 DWORD error = GetLastError ();
797 SetErrnoFromWinError (error); 812 SetErrnoFromWinError (error);
798 if (!bresult) 813 if (! bresult)
799 LOG_STRERROR ("ReadFile"); 814 LOG_STRERROR ("ReadFile");
800 EXTRACTOR_IPC_channel_destroy_ (channels[i]); 815 EXTRACTOR_IPC_channel_destroy_ (channels[i]);
801 channels[i] = NULL; 816 channels[i] = NULL;
@@ -803,12 +818,10 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels,
803 else 818 else
804 { 819 {
805 memmove (channels[i]->mdata, &channels[i]->mdata[ret], 820 memmove (channels[i]->mdata, &channels[i]->mdata[ret],
806 channels[i]->size + bytes_read - ret); 821 channels[i]->size + bytes_read - ret);
807 channels[i]->size = channels[i]->size + bytes_read- ret; 822 channels[i]->size = channels[i]->size + bytes_read - ret;
808 } 823 }
809 } 824 }
810 } 825 }
811 return 1; 826 return 1;
812} 827}
813
814
diff --git a/src/main/extractor_logging.c b/src/main/extractor_logging.c
index b1518ae..17192fe 100644
--- a/src/main/extractor_logging.c
+++ b/src/main/extractor_logging.c
@@ -39,13 +39,15 @@ EXTRACTOR_log_ (const char *file, int line, const char *format, ...)
39 va_list va; 39 va_list va;
40 40
41 fprintf (stderr, 41 fprintf (stderr,
42 "EXTRACTOR %s:%d ", 42 "EXTRACTOR %s:%d ",
43 file, line); 43 file, line);
44 va_start (va, format); 44 va_start (va, format);
45 vfprintf (stderr, format, va); 45 vfprintf (stderr, format, va);
46 va_end (va); 46 va_end (va);
47 fflush (stderr); 47 fflush (stderr);
48} 48}
49
50
49#endif 51#endif
50 52
51 53
@@ -57,7 +59,7 @@ EXTRACTOR_log_ (const char *file, int line, const char *format, ...)
57 */ 59 */
58void 60void
59EXTRACTOR_abort_ (const char *file, 61EXTRACTOR_abort_ (const char *file,
60 int line) 62 int line)
61{ 63{
62#if DEBUG 64#if DEBUG
63 EXTRACTOR_log_ (file, line, "Assertion failed.\n"); 65 EXTRACTOR_log_ (file, line, "Assertion failed.\n");
@@ -65,4 +67,5 @@ EXTRACTOR_abort_ (const char *file,
65 ABORT (); 67 ABORT ();
66} 68}
67 69
70
68/* end of extractor_logging.c */ 71/* end of extractor_logging.c */
diff --git a/src/main/extractor_logging.h b/src/main/extractor_logging.h
index 5db9ae1..535a9a7 100644
--- a/src/main/extractor_logging.h
+++ b/src/main/extractor_logging.h
@@ -44,7 +44,7 @@ EXTRACTOR_log_ (const char *file, int line, const char *format, ...);
44 * 44 *
45 * @param ... format string and arguments for fmt (printf-style) 45 * @param ... format string and arguments for fmt (printf-style)
46 */ 46 */
47#define LOG(...) EXTRACTOR_log_(__FILE__, __LINE__, __VA_ARGS__) 47#define LOG(...) EXTRACTOR_log_ (__FILE__, __LINE__, __VA_ARGS__)
48 48
49#else 49#else
50 50
@@ -64,7 +64,8 @@ EXTRACTOR_log_ (const char *file, int line, const char *format, ...);
64 * 64 *
65 * @param syscall name of the syscall that failed 65 * @param syscall name of the syscall that failed
66 */ 66 */
67#define LOG_STRERROR(syscall) LOG("System call `%s' failed: %s\n", syscall, STRERROR (errno)) 67#define LOG_STRERROR(syscall) LOG ("System call `%s' failed: %s\n", syscall, \
68 STRERROR (errno))
68 69
69 70
70/** 71/**
@@ -74,7 +75,9 @@ EXTRACTOR_log_ (const char *file, int line, const char *format, ...);
74 * @param syscall name of the syscall that failed 75 * @param syscall name of the syscall that failed
75 * @param filename name of the file that was involved 76 * @param filename name of the file that was involved
76 */ 77 */
77#define LOG_STRERROR_FILE(syscall,filename) LOG("System call `%s' failed for file `%s': %s\n", syscall, filename, STRERROR (errno)) 78#define LOG_STRERROR_FILE(syscall,filename) LOG ( \
79 "System call `%s' failed for file `%s': %s\n", syscall, filename, STRERROR ( \
80 errno))
78 81
79 82
80/** 83/**
@@ -85,7 +88,7 @@ EXTRACTOR_log_ (const char *file, int line, const char *format, ...);
85 */ 88 */
86void 89void
87EXTRACTOR_abort_ (const char *file, 90EXTRACTOR_abort_ (const char *file,
88 int line); 91 int line);
89 92
90 93
91/** 94/**
@@ -93,7 +96,8 @@ EXTRACTOR_abort_ (const char *file,
93 * 96 *
94 * @param cond assertion that must hold. 97 * @param cond assertion that must hold.
95 */ 98 */
96#define ASSERT(cond) do { if (! (cond)) EXTRACTOR_abort_ (__FILE__, __LINE__); } while (0) 99#define ASSERT(cond) do { if (! (cond)) EXTRACTOR_abort_ (__FILE__, __LINE__); \
100} while (0)
97 101
98 102
99#endif 103#endif
diff --git a/src/main/extractor_metatypes.c b/src/main/extractor_metatypes.c
index 41d1061..277a39f 100644
--- a/src/main/extractor_metatypes.c
+++ b/src/main/extractor_metatypes.c
@@ -30,7 +30,7 @@ struct MetaTypeDescription
30 * Short (typically 1-word) description. 30 * Short (typically 1-word) description.
31 */ 31 */
32 const char *short_description; 32 const char *short_description;
33 33
34 /** 34 /**
35 * More detailed description. 35 * More detailed description.
36 */ 36 */
@@ -48,7 +48,8 @@ static const struct MetaTypeDescription meta_type_descriptions[] = {
48 { gettext_noop ("mimetype"), 48 { gettext_noop ("mimetype"),
49 gettext_noop ("mime type") }, 49 gettext_noop ("mime type") },
50 { gettext_noop ("embedded filename"), 50 { gettext_noop ("embedded filename"),
51 gettext_noop ("filename that was embedded (not necessarily the current filename)") }, 51 gettext_noop (
52 "filename that was embedded (not necessarily the current filename)") },
52 { gettext_noop ("comment"), 53 { gettext_noop ("comment"),
53 gettext_noop ("comment about the content") }, 54 gettext_noop ("comment about the content") },
54 { gettext_noop ("title"), 55 { gettext_noop ("title"),
@@ -62,15 +63,16 @@ static const struct MetaTypeDescription meta_type_descriptions[] = {
62 gettext_noop ("chapter number") }, 63 gettext_noop ("chapter number") },
63 { gettext_noop ("journal name"), 64 { gettext_noop ("journal name"),
64 gettext_noop ("journal or magazine the work was published in") }, 65 gettext_noop ("journal or magazine the work was published in") },
65 { gettext_noop ("journal volume"), 66 { gettext_noop ("journal volume"),
66 gettext_noop ("volume of a journal or multi-volume book") }, 67 gettext_noop ("volume of a journal or multi-volume book") },
67 /* 10 */ 68 /* 10 */
68 { gettext_noop ("journal number"), 69 { gettext_noop ("journal number"),
69 gettext_noop ("number of a journal, magazine or tech-report") }, 70 gettext_noop ("number of a journal, magazine or tech-report") },
70 { gettext_noop ("page count"), 71 { gettext_noop ("page count"),
71 gettext_noop ("total number of pages of the work") }, 72 gettext_noop ("total number of pages of the work") },
72 { gettext_noop ("page range"), 73 { gettext_noop ("page range"),
73 gettext_noop ("page numbers of the publication in the respective journal or book") }, 74 gettext_noop (
75 "page numbers of the publication in the respective journal or book") },
74 { gettext_noop ("author name"), 76 { gettext_noop ("author name"),
75 gettext_noop ("name of the author(s)") }, 77 gettext_noop ("name of the author(s)") },
76 { gettext_noop ("author email"), 78 { gettext_noop ("author email"),
@@ -83,20 +85,25 @@ static const struct MetaTypeDescription meta_type_descriptions[] = {
83 { gettext_noop ("publisher's address"), 85 { gettext_noop ("publisher's address"),
84 gettext_noop ("Address of the publisher (often only the city)") }, 86 gettext_noop ("Address of the publisher (often only the city)") },
85 { gettext_noop ("publishing institution"), 87 { gettext_noop ("publishing institution"),
86 gettext_noop ("institution that was involved in the publishing, but not necessarily the publisher") }, 88 gettext_noop (
89 "institution that was involved in the publishing, but not necessarily the publisher") },
87 { gettext_noop ("publication series"), 90 { gettext_noop ("publication series"),
88 gettext_noop ("series of books the book was published in") }, 91 gettext_noop ("series of books the book was published in") },
89 /* 20 */ 92 /* 20 */
90 { gettext_noop ("publication type"), 93 { gettext_noop ("publication type"),
91 gettext_noop ("type of the tech-report") }, 94 gettext_noop ("type of the tech-report") },
92 { gettext_noop ("publication year"), 95 { gettext_noop ("publication year"),
93 gettext_noop ("year of publication (or, if unpublished, the year of creation)") }, 96 gettext_noop (
97 "year of publication (or, if unpublished, the year of creation)") },
94 { gettext_noop ("publication month"), 98 { gettext_noop ("publication month"),
95 gettext_noop ("month of publication (or, if unpublished, the month of creation)") }, 99 gettext_noop (
100 "month of publication (or, if unpublished, the month of creation)") },
96 { gettext_noop ("publication day"), 101 { gettext_noop ("publication day"),
97 gettext_noop ("day of publication (or, if unpublished, the day of creation), relative to the given month") }, 102 gettext_noop (
103 "day of publication (or, if unpublished, the day of creation), relative to the given month") },
98 { gettext_noop ("publication date"), 104 { gettext_noop ("publication date"),
99 gettext_noop ("date of publication (or, if unpublished, the date of creation)") }, 105 gettext_noop (
106 "date of publication (or, if unpublished, the date of creation)") },
100 /* 25 */ 107 /* 25 */
101 { gettext_noop ("bibtex eprint"), 108 { gettext_noop ("bibtex eprint"),
102 gettext_noop ("specification of an electronic publication") }, 109 gettext_noop ("specification of an electronic publication") },
@@ -107,7 +114,8 @@ static const struct MetaTypeDescription meta_type_descriptions[] = {
107 { gettext_noop ("creation time"), 114 { gettext_noop ("creation time"),
108 gettext_noop ("time and date of creation") }, 115 gettext_noop ("time and date of creation") },
109 { gettext_noop ("URL"), 116 { gettext_noop ("URL"),
110 gettext_noop ("universal resource location (where the work is made available)") }, 117 gettext_noop (
118 "universal resource location (where the work is made available)") },
111 /* 30 */ 119 /* 30 */
112 { gettext_noop ("URI"), 120 { gettext_noop ("URI"),
113 gettext_noop ("universal resource identifier") }, 121 gettext_noop ("universal resource identifier") },
@@ -120,7 +128,7 @@ static const struct MetaTypeDescription meta_type_descriptions[] = {
120 { gettext_noop ("SHA-0"), 128 { gettext_noop ("SHA-0"),
121 gettext_noop ("SHA-0 hash") }, 129 gettext_noop ("SHA-0 hash") },
122 /* 35 */ 130 /* 35 */
123 { gettext_noop ("SHA-1"), 131 { gettext_noop ("SHA-1"),
124 gettext_noop ("SHA-1 hash") }, 132 gettext_noop ("SHA-1 hash") },
125 { gettext_noop ("RipeMD160"), 133 { gettext_noop ("RipeMD160"),
126 gettext_noop ("RipeMD150 hash") }, 134 gettext_noop ("RipeMD150 hash") },
@@ -135,7 +143,7 @@ static const struct MetaTypeDescription meta_type_descriptions[] = {
135 gettext_noop ("GPS longitude") }, 143 gettext_noop ("GPS longitude") },
136 { gettext_noop ("city"), 144 { gettext_noop ("city"),
137 gettext_noop ("name of the city where the document originated") }, 145 gettext_noop ("name of the city where the document originated") },
138 { gettext_noop ("sublocation"), 146 { gettext_noop ("sublocation"),
139 gettext_noop ("more specific location of the geographic origin") }, 147 gettext_noop ("more specific location of the geographic origin") },
140 { gettext_noop ("country"), 148 { gettext_noop ("country"),
141 gettext_noop ("name of the country where the document originated") }, 149 gettext_noop ("name of the country where the document originated") },
@@ -169,7 +177,8 @@ static const struct MetaTypeDescription meta_type_descriptions[] = {
169 { gettext_noop ("created by software"), 177 { gettext_noop ("created by software"),
170 gettext_noop ("name of the software that created the document") }, 178 gettext_noop ("name of the software that created the document") },
171 { gettext_noop ("unknown date"), 179 { gettext_noop ("unknown date"),
172 gettext_noop ("ambiguous date (could specify creation time, modification time or access time)") }, 180 gettext_noop (
181 "ambiguous date (could specify creation time, modification time or access time)") },
173 { gettext_noop ("creation date"), 182 { gettext_noop ("creation date"),
174 gettext_noop ("date the document was created") }, 183 gettext_noop ("date the document was created") },
175 { gettext_noop ("modification date"), 184 { gettext_noop ("modification date"),
@@ -189,7 +198,8 @@ static const struct MetaTypeDescription meta_type_descriptions[] = {
189 { gettext_noop ("revision history"), 198 { gettext_noop ("revision history"),
190 gettext_noop ("information about the revision history") }, 199 gettext_noop ("information about the revision history") },
191 { gettext_noop ("embedded file size"), 200 { gettext_noop ("embedded file size"),
192 gettext_noop ("size of the contents of the container as embedded in the file") }, 201 gettext_noop (
202 "size of the contents of the container as embedded in the file") },
193 { gettext_noop ("file type"), 203 { gettext_noop ("file type"),
194 gettext_noop ("standard Macintosh Finder file type information") }, 204 gettext_noop ("standard Macintosh Finder file type information") },
195 { gettext_noop ("creator"), 205 { gettext_noop ("creator"),
@@ -213,9 +223,11 @@ static const struct MetaTypeDescription meta_type_descriptions[] = {
213 { gettext_noop ("provides"), 223 { gettext_noop ("provides"),
214 gettext_noop ("functionality provided by this package") }, 224 gettext_noop ("functionality provided by this package") },
215 { gettext_noop ("recommendations"), 225 { gettext_noop ("recommendations"),
216 gettext_noop ("packages recommended for installation in conjunction with this package") }, 226 gettext_noop (
227 "packages recommended for installation in conjunction with this package") },
217 { gettext_noop ("suggestions"), 228 { gettext_noop ("suggestions"),
218 gettext_noop ("packages suggested for installation in conjunction with this package") }, 229 gettext_noop (
230 "packages suggested for installation in conjunction with this package") },
219 { gettext_noop ("maintainer"), 231 { gettext_noop ("maintainer"),
220 gettext_noop ("name of the maintainer") }, 232 gettext_noop ("name of the maintainer") },
221 /* 80 */ 233 /* 80 */
@@ -228,208 +240,218 @@ static const struct MetaTypeDescription meta_type_descriptions[] = {
228 { gettext_noop ("target architecture"), 240 { gettext_noop ("target architecture"),
229 gettext_noop ("hardware architecture the contents can be used for") }, 241 gettext_noop ("hardware architecture the contents can be used for") },
230 { gettext_noop ("pre-dependency"), 242 { gettext_noop ("pre-dependency"),
231 gettext_noop ("dependency that must be satisfied before installation") }, 243 gettext_noop ("dependency that must be satisfied before installation") },
232 /* 85 */ 244 /* 85 */
233 { gettext_noop ("license"), 245 { gettext_noop ("license"),
234 gettext_noop ("applicable copyright license") }, 246 gettext_noop ("applicable copyright license") },
235 { gettext_noop ("distribution"), 247 { gettext_noop ("distribution"),
236 gettext_noop ("distribution the package is a part of") }, 248 gettext_noop ("distribution the package is a part of") },
237 { gettext_noop ("build host"), 249 { gettext_noop ("build host"),
238 gettext_noop ("machine the package was build on") }, 250 gettext_noop ("machine the package was build on") },
239 { gettext_noop ("vendor"), 251 { gettext_noop ("vendor"),
240 gettext_noop ("name of the software vendor") }, 252 gettext_noop ("name of the software vendor") },
241 { gettext_noop ("target operating system"), 253 { gettext_noop ("target operating system"),
242 gettext_noop ("operating system for which this package was made") }, 254 gettext_noop ("operating system for which this package was made") },
243 /* 90 */ 255 /* 90 */
244 { gettext_noop ("software version"), 256 { gettext_noop ("software version"),
245 gettext_noop ("version of the software contained in the file") }, 257 gettext_noop ("version of the software contained in the file") },
246 { gettext_noop ("target platform"), 258 { gettext_noop ("target platform"),
247 gettext_noop ("name of the architecture, operating system and distribution this package is for") }, 259 gettext_noop (
260 "name of the architecture, operating system and distribution this package is for") },
248 { gettext_noop ("resource type"), 261 { gettext_noop ("resource type"),
249 gettext_noop ("categorization of the nature of the resource that is more specific than the file format") }, 262 gettext_noop (
263 "categorization of the nature of the resource that is more specific than the file format") },
250 { gettext_noop ("library search path"), 264 { gettext_noop ("library search path"),
251 gettext_noop ("path in the file system to be considered when looking for required libraries") }, 265 gettext_noop (
266 "path in the file system to be considered when looking for required libraries") },
252 { gettext_noop ("library dependency"), 267 { gettext_noop ("library dependency"),
253 gettext_noop ("name of a library that this file depends on") }, 268 gettext_noop ("name of a library that this file depends on") },
254 /* 95 */ 269 /* 95 */
255 { gettext_noop ("camera make"), 270 { gettext_noop ("camera make"),
256 gettext_noop ("camera make") }, 271 gettext_noop ("camera make") },
257 { gettext_noop ("camera model"), 272 { gettext_noop ("camera model"),
258 gettext_noop ("camera model") }, 273 gettext_noop ("camera model") },
259 { gettext_noop ("exposure"), 274 { gettext_noop ("exposure"),
260 gettext_noop ("exposure") }, 275 gettext_noop ("exposure") },
261 { gettext_noop ("aperture"), 276 { gettext_noop ("aperture"),
262 gettext_noop ("aperture") }, 277 gettext_noop ("aperture") },
263 { gettext_noop ("exposure bias"), 278 { gettext_noop ("exposure bias"),
264 gettext_noop ("exposure bias") }, 279 gettext_noop ("exposure bias") },
265 /* 100 */ 280 /* 100 */
266 { gettext_noop ("flash"), 281 { gettext_noop ("flash"),
267 gettext_noop ("flash") }, 282 gettext_noop ("flash") },
268 { gettext_noop ("flash bias"), 283 { gettext_noop ("flash bias"),
269 gettext_noop ("flash bias") }, 284 gettext_noop ("flash bias") },
270 { gettext_noop ("focal length"), 285 { gettext_noop ("focal length"),
271 gettext_noop ("focal length") }, 286 gettext_noop ("focal length") },
272 { gettext_noop ("focal length 35mm"), 287 { gettext_noop ("focal length 35mm"),
273 gettext_noop ("focal length 35mm") }, 288 gettext_noop ("focal length 35mm") },
274 { gettext_noop ("iso speed"), 289 { gettext_noop ("iso speed"),
275 gettext_noop ("iso speed") }, 290 gettext_noop ("iso speed") },
276 /* 105 */ 291 /* 105 */
277 { gettext_noop ("exposure mode"), 292 { gettext_noop ("exposure mode"),
278 gettext_noop ("exposure mode") }, 293 gettext_noop ("exposure mode") },
279 { gettext_noop ("metering mode"), 294 { gettext_noop ("metering mode"),
280 gettext_noop ("metering mode") }, 295 gettext_noop ("metering mode") },
281 { gettext_noop ("macro mode"), 296 { gettext_noop ("macro mode"),
282 gettext_noop ("macro mode") }, 297 gettext_noop ("macro mode") },
283 { gettext_noop ("image quality"), 298 { gettext_noop ("image quality"),
284 gettext_noop ("image quality") }, 299 gettext_noop ("image quality") },
285 { gettext_noop ("white balance"), 300 { gettext_noop ("white balance"),
286 gettext_noop ("white balance") }, 301 gettext_noop ("white balance") },
287 /* 110 */ 302 /* 110 */
288 { gettext_noop ("orientation"), 303 { gettext_noop ("orientation"),
289 gettext_noop ("orientation") }, 304 gettext_noop ("orientation") },
290 { gettext_noop ("magnification"), 305 { gettext_noop ("magnification"),
291 gettext_noop ("magnification") }, 306 gettext_noop ("magnification") },
292 { gettext_noop ("image dimensions"), 307 { gettext_noop ("image dimensions"),
293 gettext_noop ("size of the image in pixels (width times height)") }, 308 gettext_noop ("size of the image in pixels (width times height)") },
294 { gettext_noop ("produced by software"), 309 { gettext_noop ("produced by software"),
295 gettext_noop ("produced by software") }, /* what is the exact difference between the software 310 gettext_noop ("produced by software") }, /* what is the exact difference between the software
296 creator and the software producer? PDF and DVI 311 creator and the software producer? PDF and DVI
297 both have this distinction (i.e., Writer vs. 312 both have this distinction (i.e., Writer vs.
298 OpenOffice) */ 313 OpenOffice) */
299 { gettext_noop ("thumbnail"), 314 { gettext_noop ("thumbnail"),
300 gettext_noop ("smaller version of the image for previewing") }, 315 gettext_noop ("smaller version of the image for previewing") },
301 /* 115 */ 316 /* 115 */
302 { gettext_noop ("image resolution"), 317 { gettext_noop ("image resolution"),
303 gettext_noop ("resolution in dots per inch") }, 318 gettext_noop ("resolution in dots per inch") },
304 { gettext_noop ("source"), 319 { gettext_noop ("source"),
305 gettext_noop ("Originating entity") }, 320 gettext_noop ("Originating entity") },
306 { gettext_noop ("character set"), 321 { gettext_noop ("character set"),
307 gettext_noop ("character encoding used") }, 322 gettext_noop ("character encoding used") },
308 { gettext_noop ("line count"), 323 { gettext_noop ("line count"),
309 gettext_noop ("number of lines") }, 324 gettext_noop ("number of lines") },
310 { gettext_noop ("paragraph count"), 325 { gettext_noop ("paragraph count"),
311 gettext_noop ("number of paragraphs") }, 326 gettext_noop ("number of paragraphs") },
312 /* 120 */ 327 /* 120 */
313 { gettext_noop ("word count"), 328 { gettext_noop ("word count"),
314 gettext_noop ("number of words") }, 329 gettext_noop ("number of words") },
315 { gettext_noop ("character count"), 330 { gettext_noop ("character count"),
316 gettext_noop ("number of characters") }, 331 gettext_noop ("number of characters") },
317 { gettext_noop ("page orientation"), 332 { gettext_noop ("page orientation"),
318 gettext_noop ("page orientation") }, 333 gettext_noop ("page orientation") },
319 { gettext_noop ("paper size"), 334 { gettext_noop ("paper size"),
320 gettext_noop ("paper size") }, 335 gettext_noop ("paper size") },
321 { gettext_noop ("template"), 336 { gettext_noop ("template"),
322 gettext_noop ("template the document uses or is based on") }, 337 gettext_noop ("template the document uses or is based on") },
323 /* 125 */ 338 /* 125 */
324 { gettext_noop ("company"), 339 { gettext_noop ("company"),
325 gettext_noop ("company") }, 340 gettext_noop ("company") },
326 { gettext_noop ("manager"), 341 { gettext_noop ("manager"),
327 gettext_noop ("manager") }, 342 gettext_noop ("manager") },
328 { gettext_noop ("revision number"), 343 { gettext_noop ("revision number"),
329 gettext_noop ("revision number") }, 344 gettext_noop ("revision number") },
330 { gettext_noop ("duration"), 345 { gettext_noop ("duration"),
331 gettext_noop ("play time for the medium") }, 346 gettext_noop ("play time for the medium") },
332 { gettext_noop ("album"), 347 { gettext_noop ("album"),
333 gettext_noop ("name of the album") }, 348 gettext_noop ("name of the album") },
334 /* 130 */ 349 /* 130 */
335 { gettext_noop ("artist"), 350 { gettext_noop ("artist"),
336 gettext_noop ("name of the artist or band") }, 351 gettext_noop ("name of the artist or band") },
337 { gettext_noop ("genre"), 352 { gettext_noop ("genre"),
338 gettext_noop ("genre") }, 353 gettext_noop ("genre") },
339 { gettext_noop ("track number"), 354 { gettext_noop ("track number"),
340 gettext_noop ("original number of the track on the distribution medium") }, 355 gettext_noop ("original number of the track on the distribution medium") },
341 { gettext_noop ("disk number"), 356 { gettext_noop ("disk number"),
342 gettext_noop ("number of the disk in a multi-disk (or volume) distribution") }, 357 gettext_noop (
358 "number of the disk in a multi-disk (or volume) distribution") },
343 { gettext_noop ("performer"), 359 { gettext_noop ("performer"),
344 gettext_noop ("The artist(s) who performed the work (conductor, orchestra, soloists, actor, etc.)") }, 360 gettext_noop (
361 "The artist(s) who performed the work (conductor, orchestra, soloists, actor, etc.)") },
345 /* 135 */ 362 /* 135 */
346 { gettext_noop ("contact"), 363 { gettext_noop ("contact"),
347 gettext_noop ("Contact information for the creator or distributor") }, 364 gettext_noop ("Contact information for the creator or distributor") },
348 { gettext_noop ("song version"), 365 { gettext_noop ("song version"),
349 gettext_noop ("name of the version of the song (i.e. remix information)") }, 366 gettext_noop ("name of the version of the song (i.e. remix information)") },
350 { gettext_noop ("picture"), 367 { gettext_noop ("picture"),
351 gettext_noop ("associated misc. picture") }, 368 gettext_noop ("associated misc. picture") },
352 { gettext_noop ("cover picture"), 369 { gettext_noop ("cover picture"),
353 gettext_noop ("picture of the cover of the distribution medium") }, 370 gettext_noop ("picture of the cover of the distribution medium") },
354 { gettext_noop ("contributor picture"), 371 { gettext_noop ("contributor picture"),
355 gettext_noop ("picture of one of the contributors") }, 372 gettext_noop ("picture of one of the contributors") },
356 /* 140 */ 373 /* 140 */
357 { gettext_noop ("event picture"), 374 { gettext_noop ("event picture"),
358 gettext_noop ("picture of an associated event") }, 375 gettext_noop ("picture of an associated event") },
359 { gettext_noop ("logo"), 376 { gettext_noop ("logo"),
360 gettext_noop ("logo of an associated organization") }, 377 gettext_noop ("logo of an associated organization") },
361 { gettext_noop ("broadcast television system"), 378 { gettext_noop ("broadcast television system"),
362 gettext_noop ("name of the television system for which the data is coded") }, 379 gettext_noop (
380 "name of the television system for which the data is coded") },
363 { gettext_noop ("source device"), 381 { gettext_noop ("source device"),
364 gettext_noop ("device used to create the object") }, 382 gettext_noop ("device used to create the object") },
365 { gettext_noop ("disclaimer"), 383 { gettext_noop ("disclaimer"),
366 gettext_noop ("legal disclaimer") }, 384 gettext_noop ("legal disclaimer") },
367 /* 145 */ 385 /* 145 */
368 { gettext_noop ("warning"), 386 { gettext_noop ("warning"),
369 gettext_noop ("warning about the nature of the content") }, 387 gettext_noop ("warning about the nature of the content") },
370 { gettext_noop ("page order"), 388 { gettext_noop ("page order"),
371 gettext_noop ("order of the pages") }, 389 gettext_noop ("order of the pages") },
372 { gettext_noop ("writer"), 390 { gettext_noop ("writer"),
373 gettext_noop ("contributing writer") }, 391 gettext_noop ("contributing writer") },
374 { gettext_noop ("product version"), 392 { gettext_noop ("product version"),
375 gettext_noop ("product version") }, 393 gettext_noop ("product version") },
376 { gettext_noop ("contributor"), 394 { gettext_noop ("contributor"),
377 gettext_noop ("name of a contributor") }, 395 gettext_noop ("name of a contributor") },
378 /* 150 */ 396 /* 150 */
379 { gettext_noop ("movie director"), 397 { gettext_noop ("movie director"),
380 gettext_noop ("name of the director") }, 398 gettext_noop ("name of the director") },
381 { gettext_noop ("network"), 399 { gettext_noop ("network"),
382 gettext_noop ("name of the broadcasting network or station") }, 400 gettext_noop ("name of the broadcasting network or station") },
383 { gettext_noop ("show"), 401 { gettext_noop ("show"),
384 gettext_noop ("name of the show") }, 402 gettext_noop ("name of the show") },
385 { gettext_noop ("chapter name"), 403 { gettext_noop ("chapter name"),
386 gettext_noop ("name of the chapter") }, 404 gettext_noop ("name of the chapter") },
387 { gettext_noop ("song count"), 405 { gettext_noop ("song count"),
388 gettext_noop ("number of songs") }, 406 gettext_noop ("number of songs") },
389 /* 155 */ 407 /* 155 */
390 { gettext_noop ("starting song"), 408 { gettext_noop ("starting song"),
391 gettext_noop ("number of the first song to play") }, 409 gettext_noop ("number of the first song to play") },
392 { gettext_noop ("play counter"), 410 { gettext_noop ("play counter"),
393 gettext_noop ("number of times the media has been played") }, 411 gettext_noop ("number of times the media has been played") },
394 { gettext_noop ("conductor"), 412 { gettext_noop ("conductor"),
395 gettext_noop ("name of the conductor") }, 413 gettext_noop ("name of the conductor") },
396 { gettext_noop ("interpretation"), 414 { gettext_noop ("interpretation"),
397 gettext_noop ("information about the people behind interpretations of an existing piece") }, 415 gettext_noop (
416 "information about the people behind interpretations of an existing piece") },
398 { gettext_noop ("composer"), 417 { gettext_noop ("composer"),
399 gettext_noop ("name of the composer") }, 418 gettext_noop ("name of the composer") },
400 /* 160 */ 419 /* 160 */
401 { gettext_noop ("beats per minute"), 420 { gettext_noop ("beats per minute"),
402 gettext_noop ("beats per minute") }, 421 gettext_noop ("beats per minute") },
403 { gettext_noop ("encoded by"), 422 { gettext_noop ("encoded by"),
404 gettext_noop ("name of person or organization that encoded the file") }, 423 gettext_noop ("name of person or organization that encoded the file") },
405 { gettext_noop ("original title"), 424 { gettext_noop ("original title"),
406 gettext_noop ("title of the original work") }, 425 gettext_noop ("title of the original work") },
407 { gettext_noop ("original artist"), 426 { gettext_noop ("original artist"),
408 gettext_noop ("name of the original artist") }, 427 gettext_noop ("name of the original artist") },
409 { gettext_noop ("original writer"), 428 { gettext_noop ("original writer"),
410 gettext_noop ("name of the original lyricist or writer") }, 429 gettext_noop ("name of the original lyricist or writer") },
411 /* 165 */ 430 /* 165 */
412 { gettext_noop ("original release year"), 431 { gettext_noop ("original release year"),
413 gettext_noop ("year of the original release") }, 432 gettext_noop ("year of the original release") },
414 { gettext_noop ("original performer"), 433 { gettext_noop ("original performer"),
415 gettext_noop ("name of the original performer") }, 434 gettext_noop ("name of the original performer") },
416 { gettext_noop ("lyrics"), 435 { gettext_noop ("lyrics"),
417 gettext_noop ("lyrics of the song or text description of vocal activities") }, 436 gettext_noop (
437 "lyrics of the song or text description of vocal activities") },
418 { gettext_noop ("popularity"), 438 { gettext_noop ("popularity"),
419 gettext_noop ("information about the file's popularity") }, 439 gettext_noop ("information about the file's popularity") },
420 { gettext_noop ("licensee"), 440 { gettext_noop ("licensee"),
421 gettext_noop ("name of the owner or licensee of the file") }, 441 gettext_noop ("name of the owner or licensee of the file") },
422 /* 170 */ 442 /* 170 */
423 { gettext_noop ("musician credit list"), 443 { gettext_noop ("musician credit list"),
424 gettext_noop ("names of contributing musicians") }, 444 gettext_noop ("names of contributing musicians") },
425 { gettext_noop ("mood"), 445 { gettext_noop ("mood"),
426 gettext_noop ("keywords reflecting the mood of the piece") }, 446 gettext_noop ("keywords reflecting the mood of the piece") },
427 { gettext_noop ("subtitle"), 447 { gettext_noop ("subtitle"),
428 gettext_noop ("subtitle of this part") }, 448 gettext_noop ("subtitle of this part") },
429 { gettext_noop ("display type"), 449 { gettext_noop ("display type"),
430 gettext_noop ("what rendering method should be used to display this item") }, 450 gettext_noop (
451 "what rendering method should be used to display this item") },
431 { gettext_noop ("full data"), 452 { gettext_noop ("full data"),
432 gettext_noop ("entry that contains the full, original binary data (not really meta data)") }, 453 gettext_noop (
454 "entry that contains the full, original binary data (not really meta data)") },
433 /* 175 */ 455 /* 175 */
434 { gettext_noop ("rating"), 456 { gettext_noop ("rating"),
435 gettext_noop ("rating of the content") }, 457 gettext_noop ("rating of the content") },
@@ -437,9 +459,9 @@ static const struct MetaTypeDescription meta_type_descriptions[] = {
437 gettext_noop ("organization") }, 459 gettext_noop ("organization") },
438 { gettext_noop ("ripper"), /* any difference to "encoded by"? */ 460 { gettext_noop ("ripper"), /* any difference to "encoded by"? */
439 gettext_noop ("ripper") }, 461 gettext_noop ("ripper") },
440 { gettext_noop ("producer"), 462 { gettext_noop ("producer"),
441 gettext_noop ("producer") }, 463 gettext_noop ("producer") },
442 { gettext_noop ("group"), 464 { gettext_noop ("group"),
443 gettext_noop ("name of the group or band") }, 465 gettext_noop ("name of the group or band") },
444 /* 180 */ 466 /* 180 */
445 { gettext_noop ("original filename"), 467 { gettext_noop ("original filename"),
@@ -460,7 +482,8 @@ static const struct MetaTypeDescription meta_type_descriptions[] = {
460 { gettext_noop ("bitrate"), 482 { gettext_noop ("bitrate"),
461 gettext_noop ("exact or average bitrate in bits/s") }, 483 gettext_noop ("exact or average bitrate in bits/s") },
462 { gettext_noop ("nominal bitrate"), 484 { gettext_noop ("nominal bitrate"),
463 gettext_noop ("nominal bitrate in bits/s. The actual bitrate might be different from this target bitrate.") }, 485 gettext_noop (
486 "nominal bitrate in bits/s. The actual bitrate might be different from this target bitrate.") },
464 { gettext_noop ("minimum bitrate"), 487 { gettext_noop ("minimum bitrate"),
465 gettext_noop ("minimum bitrate in bits/s") }, 488 gettext_noop ("minimum bitrate in bits/s") },
466 /* 190 */ 489 /* 190 */
@@ -484,25 +507,32 @@ static const struct MetaTypeDescription meta_type_descriptions[] = {
484 { gettext_noop ("reference level"), 507 { gettext_noop ("reference level"),
485 gettext_noop ("reference level of track and album gain values") }, 508 gettext_noop ("reference level of track and album gain values") },
486 { gettext_noop ("location name"), 509 { gettext_noop ("location name"),
487 gettext_noop ("human readable descriptive location of where the media has been recorded or produced") }, 510 gettext_noop (
511 "human readable descriptive location of where the media has been recorded or produced") },
488 /* 200 */ 512 /* 200 */
489 { gettext_noop ("location elevation"), 513 { gettext_noop ("location elevation"),
490 gettext_noop ("geo elevation of where the media has been recorded or produced in meters according to WGS84 (zero is average sea level)") }, 514 gettext_noop (
515 "geo elevation of where the media has been recorded or produced in meters according to WGS84 (zero is average sea level)") },
491 { gettext_noop ("location horizontal error"), 516 { gettext_noop ("location horizontal error"),
492 gettext_noop ("represents the expected error on the horizontal positioning in meters") }, 517 gettext_noop (
518 "represents the expected error on the horizontal positioning in meters") },
493 { gettext_noop ("location movement speed"), 519 { gettext_noop ("location movement speed"),
494 gettext_noop ("speed of the capturing device when performing the capture. Represented in m/s") }, 520 gettext_noop (
521 "speed of the capturing device when performing the capture. Represented in m/s") },
495 { gettext_noop ("location movement direction"), 522 { gettext_noop ("location movement direction"),
496 gettext_noop ("indicates the movement direction of the device performing the capture of a media. It is represented as degrees in floating point representation, 0 means the geographic north, and increases clockwise") }, 523 gettext_noop (
524 "indicates the movement direction of the device performing the capture of a media. It is represented as degrees in floating point representation, 0 means the geographic north, and increases clockwise") },
497 { gettext_noop ("location capture direction"), 525 { gettext_noop ("location capture direction"),
498 gettext_noop ("indicates the direction the device is pointing to when capturing a media. It is represented as degrees in floating point representation, 0 means the geographic north, and increases clockwise") }, 526 gettext_noop (
527 "indicates the direction the device is pointing to when capturing a media. It is represented as degrees in floating point representation, 0 means the geographic north, and increases clockwise") },
499 /* 205 */ 528 /* 205 */
500 { gettext_noop ("show episode number"), 529 { gettext_noop ("show episode number"),
501 gettext_noop ("number of the episode within a season/show") }, 530 gettext_noop ("number of the episode within a season/show") },
502 { gettext_noop ("show season number"), 531 { gettext_noop ("show season number"),
503 gettext_noop ("number of the season of a show/series") }, 532 gettext_noop ("number of the season of a show/series") },
504 { gettext_noop ("grouping"), 533 { gettext_noop ("grouping"),
505 gettext_noop ("groups together media that are related and spans multiple tracks. An example are multiple pieces of a concerto") }, 534 gettext_noop (
535 "groups together media that are related and spans multiple tracks. An example are multiple pieces of a concerto") },
506 { gettext_noop ("device manufacturer"), 536 { gettext_noop ("device manufacturer"),
507 gettext_noop ("manufacturer of the device used to create the media") }, 537 gettext_noop ("manufacturer of the device used to create the media") },
508 { gettext_noop ("device model"), 538 { gettext_noop ("device model"),
@@ -552,7 +582,8 @@ static const struct MetaTypeDescription meta_type_descriptions[] = {
552 gettext_noop ("a preview of the file audio stream") }, 582 gettext_noop ("a preview of the file audio stream") },
553 583
554 { gettext_noop ("narinfo"), 584 { gettext_noop ("narinfo"),
555 gettext_noop ("file containing information about contents of a normalized archive (nar)") }, 585 gettext_noop (
586 "file containing information about contents of a normalized archive (nar)") },
556 /* 230 */ 587 /* 230 */
557 { gettext_noop ("nar"), 588 { gettext_noop ("nar"),
558 gettext_noop ("normalized archive") }, 589 gettext_noop ("normalized archive") },
@@ -562,9 +593,10 @@ static const struct MetaTypeDescription meta_type_descriptions[] = {
562}; 593};
563 594
564/** 595/**
565 * Total number of keyword types (for bounds-checking) 596 * Total number of keyword types (for bounds-checking)
566 */ 597 */
567#define HIGHEST_METATYPE_NUMBER (sizeof (meta_type_descriptions) / sizeof(*meta_type_descriptions)) 598#define HIGHEST_METATYPE_NUMBER (sizeof (meta_type_descriptions) \
599 / sizeof(*meta_type_descriptions))
568 600
569 601
570/** 602/**
diff --git a/src/main/extractor_plugin_main.c b/src/main/extractor_plugin_main.c
index 7b01140..fd4912f 100644
--- a/src/main/extractor_plugin_main.c
+++ b/src/main/extractor_plugin_main.c
@@ -116,8 +116,8 @@ struct ProcessingContext
116 */ 116 */
117static int64_t 117static int64_t
118plugin_env_seek (void *cls, 118plugin_env_seek (void *cls,
119 int64_t pos, 119 int64_t pos,
120 int whence) 120 int whence)
121{ 121{
122 struct ProcessingContext *pc = cls; 122 struct ProcessingContext *pc = cls;
123 struct SeekRequestMessage srm; 123 struct SeekRequestMessage srm;
@@ -127,117 +127,118 @@ plugin_env_seek (void *cls,
127 uint16_t wval; 127 uint16_t wval;
128 128
129 switch (whence) 129 switch (whence)
130 {
131 case SEEK_CUR:
132 if ( (pos < 0) && (pc->read_position < -pos) )
130 { 133 {
131 case SEEK_CUR: 134 LOG ("Invalid seek operation\n");
132 if ( (pos < 0) && (pc->read_position < - pos) ) 135 return -1;
133 { 136 }
134 LOG ("Invalid seek operation\n"); 137 if ((pos > 0) && ((pc->read_position + pos < pc->read_position) ||
135 return -1; 138 (pc->read_position + pos > pc->file_size)))
136 } 139 {
137 if ((pos > 0) && ((pc->read_position + pos < pc->read_position) || 140 LOG ("Invalid seek operation\n");
138 (pc->read_position + pos > pc->file_size))) 141 return -1;
139 { 142 }
140 LOG ("Invalid seek operation\n"); 143 npos = (uint64_t) (pc->read_position + pos);
141 return -1; 144 wval = 0;
142 } 145 break;
143 npos = (uint64_t) (pc->read_position + pos); 146 case SEEK_END:
144 wval = 0; 147 if (pos > 0)
145 break; 148 {
146 case SEEK_END: 149 LOG ("Invalid seek operation\n");
147 if (pos > 0) 150 return -1;
148 { 151 }
149 LOG ("Invalid seek operation\n"); 152 if (UINT64_MAX == pc->file_size)
150 return -1; 153 {
151 } 154 wval = 2;
152 if (UINT64_MAX == pc->file_size) 155 npos = (uint64_t) -pos;
153 {
154 wval = 2;
155 npos = (uint64_t) - pos;
156 break;
157 }
158 pos = (int64_t) (pc->file_size + pos);
159 /* fall-through! */
160 case SEEK_SET:
161 if ( (pos < 0) || (pc->file_size < pos) )
162 {
163 LOG ("Invalid seek operation\n");
164 return -1;
165 }
166 npos = (uint64_t) pos;
167 wval = 0;
168 break; 156 break;
169 default: 157 }
158 pos = (int64_t) (pc->file_size + pos);
159 /* fall-through! */
160 case SEEK_SET:
161 if ( (pos < 0) || (pc->file_size < pos) )
162 {
170 LOG ("Invalid seek operation\n"); 163 LOG ("Invalid seek operation\n");
171 return -1; 164 return -1;
172 } 165 }
166 npos = (uint64_t) pos;
167 wval = 0;
168 break;
169 default:
170 LOG ("Invalid seek operation\n");
171 return -1;
172 }
173 if ( (pc->shm_off <= npos) && 173 if ( (pc->shm_off <= npos) &&
174 (pc->shm_off + pc->shm_ready_bytes > npos) && 174 (pc->shm_off + pc->shm_ready_bytes > npos) &&
175 (0 == wval) ) 175 (0 == wval) )
176 { 176 {
177 pc->read_position = npos; 177 pc->read_position = npos;
178 return (int64_t) npos; 178 return (int64_t) npos;
179 } 179 }
180 /* need to seek */ 180 /* need to seek */
181 srm.opcode = MESSAGE_SEEK; 181 srm.opcode = MESSAGE_SEEK;
182 srm.reserved = 0; 182 srm.reserved = 0;
183 srm.whence = wval; 183 srm.whence = wval;
184 srm.requested_bytes = pc->shm_map_size; 184 srm.requested_bytes = pc->shm_map_size;
185 if (0 == wval) 185 if (0 == wval)
186 { 186 {
187 if (srm.requested_bytes > pc->file_size - npos) 187 if (srm.requested_bytes > pc->file_size - npos)
188 srm.requested_bytes = pc->file_size - npos; 188 srm.requested_bytes = pc->file_size - npos;
189 } 189 }
190 else 190 else
191 { 191 {
192 srm.requested_bytes = npos; 192 srm.requested_bytes = npos;
193 } 193 }
194 srm.file_offset = npos; 194 srm.file_offset = npos;
195 if (-1 == EXTRACTOR_write_all_ (pc->out, &srm, sizeof (srm))) 195 if (-1 == EXTRACTOR_write_all_ (pc->out, &srm, sizeof (srm)))
196 { 196 {
197 LOG ("Failed to send MESSAGE_SEEK\n"); 197 LOG ("Failed to send MESSAGE_SEEK\n");
198 return -1; 198 return -1;
199 } 199 }
200 if (-1 == 200 if (-1 ==
201 EXTRACTOR_read_all_ (pc->in, 201 EXTRACTOR_read_all_ (pc->in,
202 &reply, sizeof (reply))) 202 &reply, sizeof (reply)))
203 { 203 {
204 LOG ("Plugin `%s' failed to read response to MESSAGE_SEEK\n", 204 LOG ("Plugin `%s' failed to read response to MESSAGE_SEEK\n",
205 pc->plugin->short_libname); 205 pc->plugin->short_libname);
206 return -1; 206 return -1;
207 } 207 }
208 if (MESSAGE_UPDATED_SHM != reply) 208 if (MESSAGE_UPDATED_SHM != reply)
209 { 209 {
210 LOG ("Unexpected reply %d to seek\n", reply); 210 LOG ("Unexpected reply %d to seek\n", reply);
211 return -1; /* was likely a MESSAGE_DISCARD_STATE */ 211 return -1; /* was likely a MESSAGE_DISCARD_STATE */
212 } 212 }
213 if (-1 == EXTRACTOR_read_all_ (pc->in, &um.reserved, sizeof (um) - 1)) 213 if (-1 == EXTRACTOR_read_all_ (pc->in, &um.reserved, sizeof (um) - 1))
214 { 214 {
215 LOG ("Failed to read MESSAGE_UPDATED_SHM\n"); 215 LOG ("Failed to read MESSAGE_UPDATED_SHM\n");
216 return -1; 216 return -1;
217 } 217 }
218 pc->shm_off = um.shm_off; 218 pc->shm_off = um.shm_off;
219 pc->shm_ready_bytes = um.shm_ready_bytes; 219 pc->shm_ready_bytes = um.shm_ready_bytes;
220 pc->file_size = um.file_size; 220 pc->file_size = um.file_size;
221 if (2 == wval) 221 if (2 == wval)
222 { 222 {
223 /* convert offset to be absolute from beginning of the file */ 223 /* convert offset to be absolute from beginning of the file */
224 npos = pc->file_size - npos; 224 npos = pc->file_size - npos;
225 } 225 }
226 if ( (pc->shm_off <= npos) && 226 if ( (pc->shm_off <= npos) &&
227 ((pc->shm_off + pc->shm_ready_bytes > npos) || 227 ((pc->shm_off + pc->shm_ready_bytes > npos) ||
228 (pc->file_size == pc->shm_off)) ) 228 (pc->file_size == pc->shm_off)) )
229 { 229 {
230 pc->read_position = npos; 230 pc->read_position = npos;
231 return (int64_t) npos; 231 return (int64_t) npos;
232 } 232 }
233 /* oops, serious missunderstanding, we asked to seek 233 /* oops, serious missunderstanding, we asked to seek
234 and then were notified about a different position!? */ 234 and then were notified about a different position!? */
235 LOG ("Plugin `%s' got invalid MESSAGE_UPDATED_SHM in response to my %d-seek (%llu not in %llu-%llu)\n", 235 LOG (
236 pc->plugin->short_libname, 236 "Plugin `%s' got invalid MESSAGE_UPDATED_SHM in response to my %d-seek (%llu not in %llu-%llu)\n",
237 (int) wval, 237 pc->plugin->short_libname,
238 (unsigned long long) npos, 238 (int) wval,
239 (unsigned long long) pc->shm_off, 239 (unsigned long long) npos,
240 (unsigned long long) pc->shm_off + pc->shm_ready_bytes); 240 (unsigned long long) pc->shm_off,
241 (unsigned long long) pc->shm_off + pc->shm_ready_bytes);
241 return -1; 242 return -1;
242} 243}
243 244
@@ -252,7 +253,7 @@ plugin_env_seek (void *cls,
252 */ 253 */
253static ssize_t 254static ssize_t
254plugin_env_read (void *cls, 255plugin_env_read (void *cls,
255 void **data, 256 void **data,
256 size_t count) 257 size_t count)
257{ 258{
258 struct ProcessingContext *pc = cls; 259 struct ProcessingContext *pc = cls;
@@ -266,10 +267,10 @@ plugin_env_read (void *cls,
266 (pc->read_position < pc->file_size)) || 267 (pc->read_position < pc->file_size)) ||
267 (pc->read_position < pc->shm_off) ) && 268 (pc->read_position < pc->shm_off) ) &&
268 (-1 == plugin_env_seek (pc, pc->read_position, SEEK_SET) ) ) 269 (-1 == plugin_env_seek (pc, pc->read_position, SEEK_SET) ) )
269 { 270 {
270 LOG ("Failed to seek to satisfy read\n"); 271 LOG ("Failed to seek to satisfy read\n");
271 return -1; 272 return -1;
272 } 273 }
273 if (pc->read_position + count > pc->shm_off + pc->shm_ready_bytes) 274 if (pc->read_position + count > pc->shm_off + pc->shm_ready_bytes)
274 count = pc->shm_off + pc->shm_ready_bytes - pc->read_position; 275 count = pc->shm_off + pc->shm_ready_bytes - pc->read_position;
275 dp = pc->shm; 276 dp = pc->shm;
@@ -313,12 +314,12 @@ plugin_env_get_size (void *cls)
313 */ 314 */
314static int 315static int
315plugin_env_send_proc (void *cls, 316plugin_env_send_proc (void *cls,
316 const char *plugin_name, 317 const char *plugin_name,
317 enum EXTRACTOR_MetaType type, 318 enum EXTRACTOR_MetaType type,
318 enum EXTRACTOR_MetaFormat format, 319 enum EXTRACTOR_MetaFormat format,
319 const char *data_mime_type, 320 const char *data_mime_type,
320 const char *data, 321 const char *data,
321 size_t data_len) 322 size_t data_len)
322{ 323{
323 struct ProcessingContext *pc = cls; 324 struct ProcessingContext *pc = cls;
324 struct MetaMessage mm; 325 struct MetaMessage mm;
@@ -340,32 +341,32 @@ plugin_env_send_proc (void *cls,
340 mm.mime_length = (uint16_t) mime_len; 341 mm.mime_length = (uint16_t) mime_len;
341 mm.value_size = (uint32_t) data_len; 342 mm.value_size = (uint32_t) data_len;
342 if ( (sizeof (mm) != 343 if ( (sizeof (mm) !=
343 EXTRACTOR_write_all_ (pc->out, 344 EXTRACTOR_write_all_ (pc->out,
344 &mm, sizeof (mm))) || 345 &mm, sizeof (mm))) ||
345 (mime_len != 346 (mime_len !=
346 EXTRACTOR_write_all_ (pc->out, 347 EXTRACTOR_write_all_ (pc->out,
347 data_mime_type, mime_len)) || 348 data_mime_type, mime_len)) ||
348 (data_len != 349 (data_len !=
349 EXTRACTOR_write_all_ (pc->out, 350 EXTRACTOR_write_all_ (pc->out,
350 data, data_len)) ) 351 data, data_len)) )
351 { 352 {
352 LOG ("Failed to send meta message\n"); 353 LOG ("Failed to send meta message\n");
353 return 1; 354 return 1;
354 } 355 }
355 if (-1 == 356 if (-1 ==
356 EXTRACTOR_read_all_ (pc->in, 357 EXTRACTOR_read_all_ (pc->in,
357 &reply, sizeof (reply))) 358 &reply, sizeof (reply)))
358 { 359 {
359 LOG ("Failed to read response to meta message\n"); 360 LOG ("Failed to read response to meta message\n");
360 return 1; 361 return 1;
361 } 362 }
362 if (MESSAGE_DISCARD_STATE == reply) 363 if (MESSAGE_DISCARD_STATE == reply)
363 return 1; 364 return 1;
364 if (MESSAGE_CONTINUE_EXTRACTING != reply) 365 if (MESSAGE_CONTINUE_EXTRACTING != reply)
365 { 366 {
366 LOG ("Received unexpected reply to meta data: %d\n", reply); 367 LOG ("Received unexpected reply to meta data: %d\n", reply);
367 return 1; 368 return 1;
368 } 369 }
369 return 0; 370 return 0;
370} 371}
371 372
@@ -382,34 +383,34 @@ handle_init_message (struct ProcessingContext *pc)
382 struct InitMessage init; 383 struct InitMessage init;
383 384
384 if (NULL != pc->shm) 385 if (NULL != pc->shm)
385 { 386 {
386 LOG ("Cannot handle 'init' message, have already been initialized\n"); 387 LOG ("Cannot handle 'init' message, have already been initialized\n");
387 return -1; 388 return -1;
388 } 389 }
389 if (sizeof (struct InitMessage) - 1 390 if (sizeof (struct InitMessage) - 1
390 != EXTRACTOR_read_all_ (pc->in, 391 != EXTRACTOR_read_all_ (pc->in,
391 &init.reserved, 392 &init.reserved,
392 sizeof (struct InitMessage) - 1)) 393 sizeof (struct InitMessage) - 1))
393 { 394 {
394 LOG ("Failed to read 'init' message\n"); 395 LOG ("Failed to read 'init' message\n");
395 return -1; 396 return -1;
396 } 397 }
397 if (init.shm_name_length > MAX_SHM_NAME) 398 if (init.shm_name_length > MAX_SHM_NAME)
398 { 399 {
399 LOG ("Invalid 'init' message\n"); 400 LOG ("Invalid 'init' message\n");
400 return -1; 401 return -1;
401 } 402 }
402 { 403 {
403 char shm_name[init.shm_name_length + 1]; 404 char shm_name[init.shm_name_length + 1];
404 405
405 if (init.shm_name_length 406 if (init.shm_name_length
406 != EXTRACTOR_read_all_ (pc->in, 407 != EXTRACTOR_read_all_ (pc->in,
407 shm_name, 408 shm_name,
408 init.shm_name_length)) 409 init.shm_name_length))
409 { 410 {
410 LOG ("Failed to read 'init' message\n"); 411 LOG ("Failed to read 'init' message\n");
411 return -1; 412 return -1;
412 } 413 }
413 shm_name[init.shm_name_length] = '\0'; 414 shm_name[init.shm_name_length] = '\0';
414 415
415 pc->shm_map_size = init.shm_map_size; 416 pc->shm_map_size = init.shm_map_size;
@@ -427,20 +428,20 @@ handle_init_message (struct ProcessingContext *pc)
427#else 428#else
428 pc->shm_id = shm_open (shm_name, O_RDONLY, 0); 429 pc->shm_id = shm_open (shm_name, O_RDONLY, 0);
429 if (-1 == pc->shm_id) 430 if (-1 == pc->shm_id)
430 { 431 {
431 LOG_STRERROR_FILE ("open", shm_name); 432 LOG_STRERROR_FILE ("open", shm_name);
432 return -1; 433 return -1;
433 } 434 }
434 pc->shm = mmap (NULL, 435 pc->shm = mmap (NULL,
435 pc->shm_map_size, 436 pc->shm_map_size,
436 PROT_READ, 437 PROT_READ,
437 MAP_SHARED, 438 MAP_SHARED,
438 pc->shm_id, 0); 439 pc->shm_id, 0);
439 if ( ((void*) -1) == pc->shm) 440 if ( ((void*) -1) == pc->shm)
440 { 441 {
441 LOG_STRERROR_FILE ("mmap", shm_name); 442 LOG_STRERROR_FILE ("mmap", shm_name);
442 return -1; 443 return -1;
443 } 444 }
444#endif 445#endif
445 } 446 }
446 return 0; 447 return 0;
@@ -462,12 +463,12 @@ handle_start_message (struct ProcessingContext *pc)
462 463
463 if (sizeof (struct StartMessage) - 1 464 if (sizeof (struct StartMessage) - 1
464 != EXTRACTOR_read_all_ (pc->in, 465 != EXTRACTOR_read_all_ (pc->in,
465 &start.reserved, 466 &start.reserved,
466 sizeof (struct StartMessage) - 1)) 467 sizeof (struct StartMessage) - 1))
467 { 468 {
468 LOG ("Failed to read 'start' message\n"); 469 LOG ("Failed to read 'start' message\n");
469 return -1; 470 return -1;
470 } 471 }
471 pc->shm_ready_bytes = start.shm_ready_bytes; 472 pc->shm_ready_bytes = start.shm_ready_bytes;
472 pc->file_size = start.file_size; 473 pc->file_size = start.file_size;
473 pc->read_position = 0; 474 pc->read_position = 0;
@@ -481,22 +482,22 @@ handle_start_message (struct ProcessingContext *pc)
481 pc->plugin->extract_method (&ec); 482 pc->plugin->extract_method (&ec);
482 done = MESSAGE_DONE; 483 done = MESSAGE_DONE;
483 if (-1 == EXTRACTOR_write_all_ (pc->out, &done, sizeof (done))) 484 if (-1 == EXTRACTOR_write_all_ (pc->out, &done, sizeof (done)))
484 { 485 {
485 LOG ("Failed to write 'done' message\n"); 486 LOG ("Failed to write 'done' message\n");
486 return -1; 487 return -1;
487 } 488 }
488 if ( (NULL != pc->plugin->specials) && 489 if ( (NULL != pc->plugin->specials) &&
489 (NULL != strstr (pc->plugin->specials, "force-kill")) ) 490 (NULL != strstr (pc->plugin->specials, "force-kill")) )
490 { 491 {
491 /* we're required to die after each file since this 492 /* we're required to die after each file since this
492 plugin only supports a single file at a time */ 493 plugin only supports a single file at a time */
493#if !WINDOWS 494#if ! WINDOWS
494 fsync (pc->out); 495 fsync (pc->out);
495#else 496#else
496 _commit (pc->out); 497 _commit (pc->out);
497#endif 498#endif
498 _exit (0); 499 _exit (0);
499 } 500 }
500 return 0; 501 return 0;
501} 502}
502 503
@@ -511,43 +512,43 @@ static void
511process_requests (struct ProcessingContext *pc) 512process_requests (struct ProcessingContext *pc)
512{ 513{
513 while (1) 514 while (1)
515 {
516 unsigned char code;
517
518 if (1 != EXTRACTOR_read_all_ (pc->in, &code, 1))
514 { 519 {
515 unsigned char code; 520 LOG ("Failed to read next request\n");
516 521 break;
517 if (1 != EXTRACTOR_read_all_ (pc->in, &code, 1))
518 {
519 LOG ("Failed to read next request\n");
520 break;
521 }
522 switch (code)
523 {
524 case MESSAGE_INIT_STATE:
525 if (0 != handle_init_message (pc))
526 {
527 LOG ("Failure to handle INIT\n");
528 return;
529 }
530 break;
531 case MESSAGE_EXTRACT_START:
532 if (0 != handle_start_message (pc))
533 {
534 LOG ("Failure to handle START\n");
535 return;
536 }
537 break;
538 case MESSAGE_UPDATED_SHM:
539 LOG ("Illegal message\n");
540 /* not allowed here, we're not waiting for SHM to move! */
541 return;
542 case MESSAGE_DISCARD_STATE:
543 /* odd, we're already in the start state... */
544 continue;
545 default:
546 LOG ("Received invalid messag %d\n", (int) code);
547 /* error, unexpected message */
548 return;
549 }
550 } 522 }
523 switch (code)
524 {
525 case MESSAGE_INIT_STATE:
526 if (0 != handle_init_message (pc))
527 {
528 LOG ("Failure to handle INIT\n");
529 return;
530 }
531 break;
532 case MESSAGE_EXTRACT_START:
533 if (0 != handle_start_message (pc))
534 {
535 LOG ("Failure to handle START\n");
536 return;
537 }
538 break;
539 case MESSAGE_UPDATED_SHM:
540 LOG ("Illegal message\n");
541 /* not allowed here, we're not waiting for SHM to move! */
542 return;
543 case MESSAGE_DISCARD_STATE:
544 /* odd, we're already in the start state... */
545 continue;
546 default:
547 LOG ("Received invalid messag %d\n", (int) code);
548 /* error, unexpected message */
549 return;
550 }
551 }
551} 552}
552 553
553 554
@@ -560,7 +561,7 @@ process_requests (struct ProcessingContext *pc)
560 */ 561 */
561static void 562static void
562open_dev_null (int target_fd, 563open_dev_null (int target_fd,
563 int flags) 564 int flags)
564{ 565{
565 int fd; 566 int fd;
566 567
@@ -570,10 +571,10 @@ open_dev_null (int target_fd,
570 fd = open ("\\\\?\\NUL", flags); 571 fd = open ("\\\\?\\NUL", flags);
571#endif 572#endif
572 if (-1 == fd) 573 if (-1 == fd)
573 { 574 {
574 LOG_STRERROR_FILE ("open", "/dev/null"); 575 LOG_STRERROR_FILE ("open", "/dev/null");
575 return; /* good luck */ 576 return; /* good luck */
576 } 577 }
577 if (fd == target_fd) 578 if (fd == target_fd)
578 return; /* already done */ 579 return; /* already done */
579 if (-1 == dup2 (fd, target_fd)) 580 if (-1 == dup2 (fd, target_fd))
@@ -598,32 +599,32 @@ open_dev_null (int target_fd,
598 */ 599 */
599void 600void
600EXTRACTOR_plugin_main_ (struct EXTRACTOR_PluginList *plugin, 601EXTRACTOR_plugin_main_ (struct EXTRACTOR_PluginList *plugin,
601 int in, int out) 602 int in, int out)
602{ 603{
603 struct ProcessingContext pc; 604 struct ProcessingContext pc;
604 605
605 if (0 != EXTRACTOR_plugin_load_ (plugin)) 606 if (0 != EXTRACTOR_plugin_load_ (plugin))
606 { 607 {
607#if DEBUG 608#if DEBUG
608 fprintf (stderr, "Plugin `%s' failed to load!\n", 609 fprintf (stderr, "Plugin `%s' failed to load!\n",
609 plugin->short_libname); 610 plugin->short_libname);
610#endif 611#endif
611 return; 612 return;
612 } 613 }
613 if ( (NULL != plugin->specials) && 614 if ( (NULL != plugin->specials) &&
614 (NULL != strstr (plugin->specials, "close-stderr"))) 615 (NULL != strstr (plugin->specials, "close-stderr")))
615 { 616 {
616 if (0 != close (2)) 617 if (0 != close (2))
617 LOG_STRERROR ("close"); 618 LOG_STRERROR ("close");
618 open_dev_null (2, O_WRONLY); 619 open_dev_null (2, O_WRONLY);
619 } 620 }
620 if ( (NULL != plugin->specials) && 621 if ( (NULL != plugin->specials) &&
621 (NULL != strstr (plugin->specials, "close-stdout"))) 622 (NULL != strstr (plugin->specials, "close-stdout")))
622 { 623 {
623 if (0 != close (1)) 624 if (0 != close (1))
624 LOG_STRERROR ("close"); 625 LOG_STRERROR ("close");
625 open_dev_null (1, O_WRONLY); 626 open_dev_null (1, O_WRONLY);
626 } 627 }
627 pc.plugin = plugin; 628 pc.plugin = plugin;
628 pc.in = in; 629 pc.in = in;
629 pc.out = out; 630 pc.out = out;
@@ -643,10 +644,10 @@ EXTRACTOR_plugin_main_ (struct EXTRACTOR_PluginList *plugin,
643 (((void*) 1) != pc.shm) ) 644 (((void*) 1) != pc.shm) )
644 munmap (pc.shm, pc.shm_map_size); 645 munmap (pc.shm, pc.shm_map_size);
645 if (-1 != pc.shm_id) 646 if (-1 != pc.shm_id)
646 { 647 {
647 if (0 != close (pc.shm_id)) 648 if (0 != close (pc.shm_id))
648 LOG_STRERROR ("close"); 649 LOG_STRERROR ("close");
649 } 650 }
650#endif 651#endif
651} 652}
652 653
@@ -668,43 +669,43 @@ read_plugin_data (int fd)
668 669
669 // FIXME: check for errors from 'EXTRACTOR_read_all_'! 670 // FIXME: check for errors from 'EXTRACTOR_read_all_'!
670 if (NULL == (ret = malloc (sizeof (struct EXTRACTOR_PluginList)))) 671 if (NULL == (ret = malloc (sizeof (struct EXTRACTOR_PluginList))))
671 { 672 {
672 LOG_STRERROR ("malloc"); 673 LOG_STRERROR ("malloc");
673 return NULL; 674 return NULL;
674 } 675 }
675 memset (ret, 0, sizeof (struct EXTRACTOR_PluginList)); 676 memset (ret, 0, sizeof (struct EXTRACTOR_PluginList));
676 /*GetSystemInfo (&si); 677 /*GetSystemInfo (&si);
677 ret->allocation_granularity = si.dwAllocationGranularity;*/ 678 ret->allocation_granularity = si.dwAllocationGranularity;*/
678 EXTRACTOR_read_all_ (fd, &i, sizeof (size_t)); 679 EXTRACTOR_read_all_ (fd, &i, sizeof (size_t));
679 if (NULL == (ret->libname = malloc (i))) 680 if (NULL == (ret->libname = malloc (i)))
680 { 681 {
681 free (ret); 682 free (ret);
682 return NULL; 683 return NULL;
683 } 684 }
684 EXTRACTOR_read_all_ (fd, ret->libname, i); 685 EXTRACTOR_read_all_ (fd, ret->libname, i);
685 ret->libname[i - 1] = '\0'; 686 ret->libname[i - 1] = '\0';
686 EXTRACTOR_read_all_ (fd, &i, sizeof (size_t)); 687 EXTRACTOR_read_all_ (fd, &i, sizeof (size_t));
687 if (NULL == (ret->short_libname = malloc (i))) 688 if (NULL == (ret->short_libname = malloc (i)))
688 { 689 {
689 free (ret->libname); 690 free (ret->libname);
690 free (ret); 691 free (ret);
691 return NULL; 692 return NULL;
692 } 693 }
693 EXTRACTOR_read_all_ (fd, ret->short_libname, i); 694 EXTRACTOR_read_all_ (fd, ret->short_libname, i);
694 ret->short_libname[i - 1] = '\0'; 695 ret->short_libname[i - 1] = '\0';
695 EXTRACTOR_read_all_ (fd, &i, sizeof (size_t)); 696 EXTRACTOR_read_all_ (fd, &i, sizeof (size_t));
696 if (0 == i) 697 if (0 == i)
697 { 698 {
698 ret->plugin_options = NULL; 699 ret->plugin_options = NULL;
699 return ret; 700 return ret;
700 } 701 }
701 if (NULL == (ret->plugin_options = malloc (i))) 702 if (NULL == (ret->plugin_options = malloc (i)))
702 { 703 {
703 free (ret->short_libname); 704 free (ret->short_libname);
704 free (ret->libname); 705 free (ret->libname);
705 free (ret); 706 free (ret);
706 return NULL; 707 return NULL;
707 } 708 }
708 EXTRACTOR_read_all_ (fd, ret->plugin_options, i); 709 EXTRACTOR_read_all_ (fd, ret->plugin_options, i);
709 ret->plugin_options[i - 1] = '\0'; 710 ret->plugin_options[i - 1] = '\0';
710 return ret; 711 return ret;
@@ -716,9 +717,9 @@ read_plugin_data (int fd)
716 */ 717 */
717void CALLBACK 718void CALLBACK
718RundllEntryPoint (HWND hwnd, 719RundllEntryPoint (HWND hwnd,
719 HINSTANCE hinst, 720 HINSTANCE hinst,
720 LPSTR lpszCmdLine, 721 LPSTR lpszCmdLine,
721 int nCmdShow) 722 int nCmdShow)
722{ 723{
723 struct EXTRACTOR_PluginList *plugin; 724 struct EXTRACTOR_PluginList *plugin;
724 intptr_t in_h; 725 intptr_t in_h;
@@ -732,11 +733,11 @@ RundllEntryPoint (HWND hwnd,
732 setmode (in, _O_BINARY); 733 setmode (in, _O_BINARY);
733 setmode (out, _O_BINARY); 734 setmode (out, _O_BINARY);
734 if (NULL == (plugin = read_plugin_data (in))) 735 if (NULL == (plugin = read_plugin_data (in)))
735 { 736 {
736 close (in); 737 close (in);
737 close (out); 738 close (out);
738 return; 739 return;
739 } 740 }
740 EXTRACTOR_plugin_main_ (plugin, in, out); 741 EXTRACTOR_plugin_main_ (plugin, in, out);
741 close (in); 742 close (in);
742 close (out); 743 close (out);
@@ -745,8 +746,7 @@ RundllEntryPoint (HWND hwnd,
745 * called by the OS) or call FreeLibrary() on it directly or 746 * called by the OS) or call FreeLibrary() on it directly or
746 * indirectly. 747 * indirectly.
747 * By terminating here we alleviate that problem. 748 * By terminating here we alleviate that problem.
748 */ 749 */TerminateProcess (GetCurrentProcess (), 0);
749 TerminateProcess (GetCurrentProcess (), 0);
750} 750}
751 751
752 752
@@ -755,9 +755,9 @@ RundllEntryPoint (HWND hwnd,
755 */ 755 */
756void CALLBACK 756void CALLBACK
757RundllEntryPointA (HWND hwnd, 757RundllEntryPointA (HWND hwnd,
758 HINSTANCE hinst, 758 HINSTANCE hinst,
759 LPSTR lpszCmdLine, 759 LPSTR lpszCmdLine,
760 int nCmdShow) 760 int nCmdShow)
761{ 761{
762 return RundllEntryPoint (hwnd, hinst, lpszCmdLine, nCmdShow); 762 return RundllEntryPoint (hwnd, hinst, lpszCmdLine, nCmdShow);
763} 763}
diff --git a/src/main/extractor_plugin_main.h b/src/main/extractor_plugin_main.h
index 1b33c8c..a683768 100644
--- a/src/main/extractor_plugin_main.h
+++ b/src/main/extractor_plugin_main.h
@@ -37,7 +37,7 @@
37 * @param out stream to write to 37 * @param out stream to write to
38 */ 38 */
39void 39void
40EXTRACTOR_plugin_main_ (struct EXTRACTOR_PluginList *plugin, 40 EXTRACTOR_plugin_main_ (struct EXTRACTOR_PluginList *plugin,
41 int in, int out); 41 int in, int out);
42 42
43#endif 43#endif
diff --git a/src/main/extractor_plugins.c b/src/main/extractor_plugins.c
index 0fa10d6..1ab777b 100644
--- a/src/main/extractor_plugins.c
+++ b/src/main/extractor_plugins.c
@@ -39,9 +39,9 @@
39 */ 39 */
40static void * 40static void *
41get_symbol_with_prefix (void *lib_handle, 41get_symbol_with_prefix (void *lib_handle,
42 const char *template, 42 const char *template,
43 const char *prefix, 43 const char *prefix,
44 const char **options) 44 const char **options)
45{ 45{
46 char *name; 46 char *name;
47 void *symbol; 47 void *symbol;
@@ -56,55 +56,55 @@ get_symbol_with_prefix (void *lib_handle,
56 return NULL; 56 return NULL;
57 sym_name++; 57 sym_name++;
58 if (NULL == (sym = strdup (sym_name))) 58 if (NULL == (sym = strdup (sym_name)))
59 { 59 {
60 LOG_STRERROR ("strdup"); 60 LOG_STRERROR ("strdup");
61 return NULL; 61 return NULL;
62 } 62 }
63 if (NULL != (dot = strchr (sym, '.'))) 63 if (NULL != (dot = strchr (sym, '.')))
64 *dot = '\0'; 64 *dot = '\0';
65 if (NULL == (name = malloc(strlen(sym) + strlen(template) + 1))) 65 if (NULL == (name = malloc (strlen (sym) + strlen (template) + 1)))
66 { 66 {
67 free (sym); 67 free (sym);
68 return NULL; 68 return NULL;
69 } 69 }
70 sprintf(name, 70 sprintf (name,
71 template, 71 template,
72 sym); 72 sym);
73 /* try without '_' first */ 73 /* try without '_' first */
74 symbol = lt_dlsym (lib_handle, name + 1); 74 symbol = lt_dlsym (lib_handle, name + 1);
75 if (NULL == symbol) 75 if (NULL == symbol)
76 {
77 /* now try with the '_' */
78 char *first_error = strdup (lt_dlerror ());
79 symbol = lt_dlsym (lib_handle, name);
80 if (NULL == symbol)
76 { 81 {
77 /* now try with the '_' */ 82 LOG ("Resolving symbol `%s' failed, "
78 char *first_error = strdup (lt_dlerror ()); 83 "so I tried `%s', but that failed also. Errors are: "
79 symbol = lt_dlsym (lib_handle, name); 84 "`%s' and `%s'.\n",
80 if (NULL == symbol) 85 name + 1,
81 { 86 name,
82 LOG ("Resolving symbol `%s' failed, " 87 first_error == NULL ? "out of memory" : first_error,
83 "so I tried `%s', but that failed also. Errors are: " 88 lt_dlerror ());
84 "`%s' and `%s'.\n",
85 name+1,
86 name,
87 first_error == NULL ? "out of memory" : first_error,
88 lt_dlerror ());
89 }
90 if (NULL != first_error)
91 free (first_error);
92 } 89 }
90 if (NULL != first_error)
91 free (first_error);
92 }
93 93
94 if ( (NULL != symbol) && 94 if ( (NULL != symbol) &&
95 (NULL != options) ) 95 (NULL != options) )
96 { 96 {
97 /* get special options */ 97 /* get special options */
98 sprintf (name, 98 sprintf (name,
99 "_EXTRACTOR_%s_options", 99 "_EXTRACTOR_%s_options",
100 sym); 100 sym);
101 /* try without '_' first */ 101 /* try without '_' first */
102 opt_fun = lt_dlsym (lib_handle, name + 1); 102 opt_fun = lt_dlsym (lib_handle, name + 1);
103 if (NULL == opt_fun) 103 if (NULL == opt_fun)
104 opt_fun = lt_dlsym (lib_handle, name); 104 opt_fun = lt_dlsym (lib_handle, name);
105 if (NULL != opt_fun) 105 if (NULL != opt_fun)
106 *options = opt_fun (); 106 *options = opt_fun ();
107 } 107 }
108 free (sym); 108 free (sym);
109 free (name); 109 free (name);
110 return symbol; 110 return symbol;
@@ -131,12 +131,12 @@ EXTRACTOR_plugin_load_ (struct EXTRACTOR_PluginList *plugin)
131 if (NULL == plugin->libname) 131 if (NULL == plugin->libname)
132 plugin->libname = EXTRACTOR_find_plugin_ (plugin->short_libname); 132 plugin->libname = EXTRACTOR_find_plugin_ (plugin->short_libname);
133 if (NULL == plugin->libname) 133 if (NULL == plugin->libname)
134 { 134 {
135 LOG ("Failed to find plugin `%s'\n", 135 LOG ("Failed to find plugin `%s'\n",
136 plugin->short_libname); 136 plugin->short_libname);
137 plugin->flags = EXTRACTOR_OPTION_DISABLED; 137 plugin->flags = EXTRACTOR_OPTION_DISABLED;
138 return -1; 138 return -1;
139 } 139 }
140 lt_dladvise_init (&advise); 140 lt_dladvise_init (&advise);
141 lt_dladvise_ext (&advise); 141 lt_dladvise_ext (&advise);
142 lt_dladvise_local (&advise); 142 lt_dladvise_local (&advise);
@@ -144,51 +144,51 @@ EXTRACTOR_plugin_load_ (struct EXTRACTOR_PluginList *plugin)
144 wlibname[0] = L'\0'; 144 wlibname[0] = L'\0';
145 llibname[0] = '\0'; 145 llibname[0] = '\0';
146 if ( (MultiByteToWideChar (CP_UTF8, 0, plugin->libname, -1, 146 if ( (MultiByteToWideChar (CP_UTF8, 0, plugin->libname, -1,
147 wlibname, sizeof (wlibname)) <= 0) || 147 wlibname, sizeof (wlibname)) <= 0) ||
148 (WideCharToMultiByte (CP_ACP, 0, wlibname, -1, 148 (WideCharToMultiByte (CP_ACP, 0, wlibname, -1,
149 llibname, sizeof (llibname), NULL, NULL) < 0) ) 149 llibname, sizeof (llibname), NULL, NULL) < 0) )
150 { 150 {
151 LOG ("Loading `%s' plugin failed: %s\n", 151 LOG ("Loading `%s' plugin failed: %s\n",
152 plugin->short_libname, 152 plugin->short_libname,
153 "can't convert plugin name to local encoding"); 153 "can't convert plugin name to local encoding");
154 free (plugin->libname); 154 free (plugin->libname);
155 plugin->libname = NULL; 155 plugin->libname = NULL;
156 plugin->flags = EXTRACTOR_OPTION_DISABLED; 156 plugin->flags = EXTRACTOR_OPTION_DISABLED;
157 return -1; 157 return -1;
158 } 158 }
159 plugin->libraryHandle = lt_dlopenadvise (llibname, 159 plugin->libraryHandle = lt_dlopenadvise (llibname,
160 advise); 160 advise);
161#else 161#else
162 plugin->libraryHandle = lt_dlopenadvise (plugin->libname, 162 plugin->libraryHandle = lt_dlopenadvise (plugin->libname,
163 advise); 163 advise);
164#endif 164#endif
165 lt_dladvise_destroy (&advise); 165 lt_dladvise_destroy (&advise);
166 if (NULL == plugin->libraryHandle) 166 if (NULL == plugin->libraryHandle)
167 { 167 {
168 LOG ("Loading `%s' plugin failed (using name `%s'): %s\n", 168 LOG ("Loading `%s' plugin failed (using name `%s'): %s\n",
169 plugin->short_libname, 169 plugin->short_libname,
170 plugin->libname, 170 plugin->libname,
171 lt_dlerror ()); 171 lt_dlerror ());
172 free (plugin->libname); 172 free (plugin->libname);
173 plugin->libname = NULL; 173 plugin->libname = NULL;
174 plugin->flags = EXTRACTOR_OPTION_DISABLED; 174 plugin->flags = EXTRACTOR_OPTION_DISABLED;
175 return -1; 175 return -1;
176 } 176 }
177 plugin->extract_method = get_symbol_with_prefix (plugin->libraryHandle, 177 plugin->extract_method = get_symbol_with_prefix (plugin->libraryHandle,
178 "_EXTRACTOR_%s_extract_method", 178 "_EXTRACTOR_%s_extract_method",
179 plugin->libname, 179 plugin->libname,
180 &plugin->specials); 180 &plugin->specials);
181 if (NULL == plugin->extract_method) 181 if (NULL == plugin->extract_method)
182 { 182 {
183 LOG ("Resolving `extract' method of plugin `%s' failed: %s\n", 183 LOG ("Resolving `extract' method of plugin `%s' failed: %s\n",
184 plugin->short_libname, 184 plugin->short_libname,
185 lt_dlerror ()); 185 lt_dlerror ());
186 lt_dlclose (plugin->libraryHandle); 186 lt_dlclose (plugin->libraryHandle);
187 free (plugin->libname); 187 free (plugin->libname);
188 plugin->libname = NULL; 188 plugin->libname = NULL;
189 plugin->flags = EXTRACTOR_OPTION_DISABLED; 189 plugin->flags = EXTRACTOR_OPTION_DISABLED;
190 return -1; 190 return -1;
191 } 191 }
192 return 0; 192 return 0;
193} 193}
194 194
@@ -204,9 +204,9 @@ EXTRACTOR_plugin_load_ (struct EXTRACTOR_PluginList *plugin)
204 */ 204 */
205struct EXTRACTOR_PluginList * 205struct EXTRACTOR_PluginList *
206EXTRACTOR_plugin_add (struct EXTRACTOR_PluginList *prev, 206EXTRACTOR_plugin_add (struct EXTRACTOR_PluginList *prev,
207 const char *library, 207 const char *library,
208 const char *options, 208 const char *options,
209 enum EXTRACTOR_Options flags) 209 enum EXTRACTOR_Options flags)
210{ 210{
211 struct EXTRACTOR_PluginList *plugin; 211 struct EXTRACTOR_PluginList *plugin;
212 struct EXTRACTOR_PluginList *pos; 212 struct EXTRACTOR_PluginList *pos;
@@ -214,22 +214,23 @@ EXTRACTOR_plugin_add (struct EXTRACTOR_PluginList *prev,
214 214
215 for (pos = prev; NULL != pos; pos = pos->next) 215 for (pos = prev; NULL != pos; pos = pos->next)
216 if (0 == strcmp (pos->short_libname, library)) 216 if (0 == strcmp (pos->short_libname, library))
217 return prev; /* no change, library already loaded */
218 if (NULL == (libname = EXTRACTOR_find_plugin_ (library)))
219 {
220 LOG ("Could not load plugin `%s'\n",
221 library);
222 return prev; 217 return prev;
223 } 218 /* no change, library already loaded */
219 if (NULL == (libname = EXTRACTOR_find_plugin_ (library)))
220 {
221 LOG ("Could not load plugin `%s'\n",
222 library);
223 return prev;
224 }
224 if (NULL == (plugin = malloc (sizeof (struct EXTRACTOR_PluginList)))) 225 if (NULL == (plugin = malloc (sizeof (struct EXTRACTOR_PluginList))))
225 return prev; 226 return prev;
226 memset (plugin, 0, sizeof (struct EXTRACTOR_PluginList)); 227 memset (plugin, 0, sizeof (struct EXTRACTOR_PluginList));
227 plugin->next = prev; 228 plugin->next = prev;
228 if (NULL == (plugin->short_libname = strdup (library))) 229 if (NULL == (plugin->short_libname = strdup (library)))
229 { 230 {
230 free (plugin); 231 free (plugin);
231 return NULL; 232 return NULL;
232 } 233 }
233 plugin->libname = libname; 234 plugin->libname = libname;
234 plugin->flags = flags; 235 plugin->flags = flags;
235 if (NULL != options) 236 if (NULL != options)
@@ -258,8 +259,8 @@ EXTRACTOR_plugin_add (struct EXTRACTOR_PluginList *prev,
258 */ 259 */
259struct EXTRACTOR_PluginList * 260struct EXTRACTOR_PluginList *
260EXTRACTOR_plugin_add_config (struct EXTRACTOR_PluginList *prev, 261EXTRACTOR_plugin_add_config (struct EXTRACTOR_PluginList *prev,
261 const char *config, 262 const char *config,
262 enum EXTRACTOR_Options flags) 263 enum EXTRACTOR_Options flags)
263{ 264{
264 char *cpy; 265 char *cpy;
265 size_t pos; 266 size_t pos;
@@ -276,55 +277,55 @@ EXTRACTOR_plugin_add_config (struct EXTRACTOR_PluginList *prev,
276 last = 0; 277 last = 0;
277 lastconf = 0; 278 lastconf = 0;
278 while (pos < len) 279 while (pos < len)
280 {
281 while ( (':' != cpy[pos]) &&
282 ('\0' != cpy[pos]) &&
283 ('(' != cpy[pos]) )
284 pos++;
285 switch (cpy[pos])
279 { 286 {
280 while ( (':' != cpy[pos]) && 287 case '(':
281 ('\0' != cpy[pos]) && 288 cpy[pos++] = '\0'; /* replace '(' by termination */
282 ('(' != cpy[pos]) ) 289 lastconf = pos; /* start config from here, after (. */
283 pos++; 290 while ( ('\0' != cpy[pos]) &&
284 switch (cpy[pos]) 291 (')' != cpy[pos]))
285 { 292 pos++; /* config until ) or EOS. */
286 case '(': 293 if (')' == cpy[pos])
287 cpy[pos++] = '\0'; /* replace '(' by termination */ 294 {
288 lastconf = pos; /* start config from here, after (. */ 295 cpy[pos++] = '\0'; /* write end of config here. */
289 while ( ('\0' != cpy[pos]) && 296 while ( (':' != cpy[pos]) &&
290 (')' != cpy[pos])) 297 ('\0' != cpy[pos]) )
291 pos++; /* config until ) or EOS. */ 298 pos++; /* forward until real end of string found. */
292 if (')' == cpy[pos]) 299 cpy[pos++] = '\0';
293 { 300 }
294 cpy[pos++] = '\0'; /* write end of config here. */
295 while ( (':' != cpy[pos]) &&
296 ('\0' != cpy[pos]) )
297 pos++; /* forward until real end of string found. */
298 cpy[pos++] = '\0';
299 }
300 else
301 {
302 cpy[pos++] = '\0'; /* end of string. */
303 }
304 break;
305 case ':':
306 case '\0':
307 lastconf = -1; /* NULL config when no (). */
308 cpy[pos++] = '\0'; /* replace ':' by termination */
309 break;
310 default:
311 ABORT ();
312 }
313 if ('-' == cpy[last])
314 {
315 last++;
316 prev = EXTRACTOR_plugin_remove (prev,
317 &cpy[last]);
318 }
319 else 301 else
320 { 302 {
321 prev = EXTRACTOR_plugin_add (prev, 303 cpy[pos++] = '\0'; /* end of string. */
322 &cpy[last], 304 }
323 (-1 != lastconf) ? &cpy[lastconf] : NULL, 305 break;
324 flags); 306 case ':':
325 } 307 case '\0':
326 last = pos; 308 lastconf = -1; /* NULL config when no (). */
309 cpy[pos++] = '\0'; /* replace ':' by termination */
310 break;
311 default:
312 ABORT ();
327 } 313 }
314 if ('-' == cpy[last])
315 {
316 last++;
317 prev = EXTRACTOR_plugin_remove (prev,
318 &cpy[last]);
319 }
320 else
321 {
322 prev = EXTRACTOR_plugin_add (prev,
323 &cpy[last],
324 (-1 != lastconf) ? &cpy[lastconf] : NULL,
325 flags);
326 }
327 last = pos;
328 }
328 free (cpy); 329 free (cpy);
329 return prev; 330 return prev;
330} 331}
@@ -339,7 +340,7 @@ EXTRACTOR_plugin_add_config (struct EXTRACTOR_PluginList *prev,
339 */ 340 */
340struct EXTRACTOR_PluginList * 341struct EXTRACTOR_PluginList *
341EXTRACTOR_plugin_remove (struct EXTRACTOR_PluginList *prev, 342EXTRACTOR_plugin_remove (struct EXTRACTOR_PluginList *prev,
342 const char *library) 343 const char *library)
343{ 344{
344 struct EXTRACTOR_PluginList *pos; 345 struct EXTRACTOR_PluginList *pos;
345 struct EXTRACTOR_PluginList *first; 346 struct EXTRACTOR_PluginList *first;
@@ -347,17 +348,17 @@ EXTRACTOR_plugin_remove (struct EXTRACTOR_PluginList *prev,
347 pos = prev; 348 pos = prev;
348 first = prev; 349 first = prev;
349 while ( (NULL != pos) && 350 while ( (NULL != pos) &&
350 (0 != strcmp (pos->short_libname, library)) ) 351 (0 != strcmp (pos->short_libname, library)) )
351 { 352 {
352 prev = pos; 353 prev = pos;
353 pos = pos->next; 354 pos = pos->next;
354 } 355 }
355 if (NULL == pos) 356 if (NULL == pos)
356 { 357 {
357 LOG ("Unloading plugin `%s' failed!\n", 358 LOG ("Unloading plugin `%s' failed!\n",
358 library); 359 library);
359 return first; 360 return first;
360 } 361 }
361 /* found, close library */ 362 /* found, close library */
362 if (first == pos) 363 if (first == pos)
363 first = pos->next; 364 first = pos->next;
@@ -374,7 +375,7 @@ EXTRACTOR_plugin_remove (struct EXTRACTOR_PluginList *prev,
374 free (pos->libname); 375 free (pos->libname);
375 free (pos->plugin_options); 376 free (pos->plugin_options);
376 if (NULL != pos->libraryHandle) 377 if (NULL != pos->libraryHandle)
377 lt_dlclose (pos->libraryHandle); 378 lt_dlclose (pos->libraryHandle);
378 free (pos); 379 free (pos);
379 return first; 380 return first;
380} 381}
diff --git a/src/main/extractor_plugins.h b/src/main/extractor_plugins.h
index 958ad94..8b0f5e6 100644
--- a/src/main/extractor_plugins.h
+++ b/src/main/extractor_plugins.h
@@ -59,7 +59,7 @@ struct EXTRACTOR_PluginList
59 * Short name of the plugin (i.e., 'foo') 59 * Short name of the plugin (i.e., 'foo')
60 */ 60 */
61 char *short_libname; 61 char *short_libname;
62 62
63 /** 63 /**
64 * Pointer to the function used for meta data extraction. 64 * Pointer to the function used for meta data extraction.
65 */ 65 */
diff --git a/src/main/extractor_plugpath.c b/src/main/extractor_plugpath.c
index 461f25e..4374bc5 100644
--- a/src/main/extractor_plugpath.c
+++ b/src/main/extractor_plugpath.c
@@ -41,7 +41,7 @@
41 * @param path a directory path 41 * @param path a directory path
42 */ 42 */
43typedef void (*EXTRACTOR_PathProcessor) (void *cls, 43typedef void (*EXTRACTOR_PathProcessor) (void *cls,
44 const char *path); 44 const char *path);
45 45
46 46
47/** 47/**
@@ -51,7 +51,7 @@ typedef void (*EXTRACTOR_PathProcessor) (void *cls,
51 * @return NULL if 'in' is NULL, otherwise 'in' with '/bin/' removed 51 * @return NULL if 'in' is NULL, otherwise 'in' with '/bin/' removed
52 */ 52 */
53static char * 53static char *
54cut_bin (char * in) 54cut_bin (char *in)
55{ 55{
56 size_t p; 56 size_t p;
57 57
@@ -60,21 +60,21 @@ cut_bin (char * in)
60 p = strlen (in); 60 p = strlen (in);
61 if (p < 4) 61 if (p < 4)
62 return in; 62 return in;
63 if ( ('/' == in[p-1]) || 63 if ( ('/' == in[p - 1]) ||
64 ('\\' == in[p-1]) ) 64 ('\\' == in[p - 1]) )
65 in[--p] = '\0'; 65 in[--p] = '\0';
66 if (0 == strcmp (&in[p-4], 66 if (0 == strcmp (&in[p - 4],
67 "/bin")) 67 "/bin"))
68 { 68 {
69 in[p-4] = '\0'; 69 in[p - 4] = '\0';
70 p -= 4; 70 p -= 4;
71 } 71 }
72 else if (0 == strcmp (&in[p-4], 72 else if (0 == strcmp (&in[p - 4],
73 "\\bin")) 73 "\\bin"))
74 { 74 {
75 in[p-4] = '\0'; 75 in[p - 4] = '\0';
76 p -= 4; 76 p -= 4;
77 } 77 }
78 return in; 78 return in;
79} 79}
80 80
@@ -100,60 +100,62 @@ get_path_from_proc_exe ()
100 FILE *f; 100 FILE *f;
101 101
102 snprintf (fn, 102 snprintf (fn,
103 sizeof (fn), 103 sizeof (fn),
104 "/proc/%u/maps", 104 "/proc/%u/maps",
105 getpid ()); 105 getpid ());
106 if (NULL != (f = FOPEN (fn, "r"))) 106 if (NULL != (f = FOPEN (fn, "r")))
107 {
108 while (NULL != fgets (line, 1024, f))
107 { 109 {
108 while (NULL != fgets (line, 1024, f)) 110 if ( (1 == sscanf (line,
109 { 111 "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%s",
110 if ( (1 == sscanf (line, 112 dir)) &&
111 "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%s", 113 (NULL != (lestr = strstr (dir,
112 dir)) && 114 "libextractor")) ) )
113 (NULL != (lestr = strstr (dir, 115 {
114 "libextractor")) ) ) 116 lestr[0] = '\0';
115 { 117 fclose (f);
116 lestr[0] = '\0'; 118 return strdup (dir);
117 fclose (f); 119 }
118 return strdup (dir);
119 }
120 }
121 fclose (f);
122 } 120 }
121 fclose (f);
122 }
123 snprintf (fn, 123 snprintf (fn,
124 sizeof (fn), 124 sizeof (fn),
125 "/proc/%u/exe", 125 "/proc/%u/exe",
126 getpid ()); 126 getpid ());
127 if (NULL == (lnk = malloc (1029))) /* 1024 + 6 for "/lib/" catenation */ 127 if (NULL == (lnk = malloc (1029))) /* 1024 + 6 for "/lib/" catenation */
128 return NULL; 128 return NULL;
129 size = readlink (fn, lnk, 1023); 129 size = readlink (fn, lnk, 1023);
130 if ( (size <= 0) || (size >= 1024) ) 130 if ( (size <= 0) || (size >= 1024) )
131 { 131 {
132 free (lnk); 132 free (lnk);
133 return NULL; 133 return NULL;
134 } 134 }
135 lnk[size] = '\0'; 135 lnk[size] = '\0';
136 while ( ('/' != lnk[size]) && 136 while ( ('/' != lnk[size]) &&
137 (size > 0) ) 137 (size > 0) )
138 size--; 138 size--;
139 if ( (size < 4) || 139 if ( (size < 4) ||
140 ('/' != lnk[size-4]) ) 140 ('/' != lnk[size - 4]) )
141 { 141 {
142 /* not installed in "/bin/" -- binary path probably useless */ 142 /* not installed in "/bin/" -- binary path probably useless */
143 free (lnk); 143 free (lnk);
144 return NULL; 144 return NULL;
145 } 145 }
146 lnk[size] = '\0'; 146 lnk[size] = '\0';
147 lnk = cut_bin (lnk); 147 lnk = cut_bin (lnk);
148 if (NULL == (ret = realloc (lnk, strlen(lnk) + 6))) 148 if (NULL == (ret = realloc (lnk, strlen (lnk) + 6)))
149 { 149 {
150 LOG_STRERROR ("realloc"); 150 LOG_STRERROR ("realloc");
151 free (lnk); 151 free (lnk);
152 return NULL; 152 return NULL;
153 } 153 }
154 strcat (ret, "/lib/"); /* guess "lib/" as the library dir */ 154 strcat (ret, "/lib/"); /* guess "lib/" as the library dir */
155 return ret; 155 return ret;
156} 156}
157
158
157#endif 159#endif
158 160
159 161
@@ -162,8 +164,8 @@ static HMODULE le_dll = NULL;
162 164
163BOOL WINAPI 165BOOL WINAPI
164DllMain (HINSTANCE hinstDLL, 166DllMain (HINSTANCE hinstDLL,
165 DWORD fdwReason, 167 DWORD fdwReason,
166 LPVOID lpvReserved) 168 LPVOID lpvReserved)
167{ 169{
168 switch (fdwReason) 170 switch (fdwReason)
169 { 171 {
@@ -175,6 +177,7 @@ DllMain (HINSTANCE hinstDLL,
175 return TRUE; 177 return TRUE;
176} 178}
177 179
180
178/** 181/**
179 * Try to determine path with win32-specific function 182 * Try to determine path with win32-specific function
180 */ 183 */
@@ -190,20 +193,22 @@ get_path_from_module_filename ()
190 GetModuleFileName (le_dll, path, 4096); 193 GetModuleFileName (le_dll, path, 4096);
191 idx = path + strlen (path); 194 idx = path + strlen (path);
192 while ( (idx > path) && 195 while ( (idx > path) &&
193 ('\\' != *idx) && 196 ('\\' != *idx) &&
194 ('/' != *idx) ) 197 ('/' != *idx) )
195 idx--; 198 idx--;
196 *idx = '\0'; 199 *idx = '\0';
197 path = cut_bin (path); 200 path = cut_bin (path);
198 if (NULL == (ret = realloc (path, strlen(path) + 6))) 201 if (NULL == (ret = realloc (path, strlen (path) + 6)))
199 { 202 {
200 LOG_STRERROR ("realloc"); 203 LOG_STRERROR ("realloc");
201 free (path); 204 free (path);
202 return NULL; 205 return NULL;
203 } 206 }
204 strcat (ret, "/lib/"); /* guess "lib/" as the library dir */ 207 strcat (ret, "/lib/"); /* guess "lib/" as the library dir */
205 return ret; 208 return ret;
206} 209}
210
211
207#endif 212#endif
208 213
209 214
@@ -239,8 +244,8 @@ get_path_from_NSGetExecutablePath ()
239 244
240 path = NULL; 245 path = NULL;
241 if (NULL == (func = 246 if (NULL == (func =
242 (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, 247 (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT,
243 "_NSGetExecutablePath"))) 248 "_NSGetExecutablePath")))
244 return NULL; 249 return NULL;
245 path = &zero; 250 path = &zero;
246 len = 0; 251 len = 0;
@@ -249,10 +254,10 @@ get_path_from_NSGetExecutablePath ()
249 if (0 == len) 254 if (0 == len)
250 return NULL; 255 return NULL;
251 if (NULL == (path = malloc (len))) 256 if (NULL == (path = malloc (len)))
252 { 257 {
253 LOG_STRERROR ("malloc"); 258 LOG_STRERROR ("malloc");
254 return NULL; 259 return NULL;
255 } 260 }
256 if (0 != func (path, &len)) 261 if (0 != func (path, &len))
257 { 262 {
258 free (path); 263 free (path);
@@ -267,9 +272,9 @@ get_path_from_NSGetExecutablePath ()
267 path = cut_bin (path); 272 path = cut_bin (path);
268 if (NULL == (ret = realloc (path, strlen (path) + 5))) 273 if (NULL == (ret = realloc (path, strlen (path) + 5)))
269 { 274 {
270 LOG_STRERROR ("realloc"); 275 LOG_STRERROR ("realloc");
271 free (path); 276 free (path);
272 return NULL; 277 return NULL;
273 } 278 }
274 strcat (ret, "/lib/"); 279 strcat (ret, "/lib/");
275 return ret; 280 return ret;
@@ -292,26 +297,28 @@ get_path_from_dyld_image ()
292 297
293 c = _dyld_image_count (); 298 c = _dyld_image_count ();
294 for (i = 0; i < c; i++) 299 for (i = 0; i < c; i++)
300 {
301 if (((void *) _dyld_get_image_header (i)) != (void *) &_mh_dylib_header)
302 continue;
303 path = _dyld_get_image_name (i);
304 if ( (NULL == path) || (0 == strlen (path)) )
305 continue;
306 if (NULL == (p = strdup (path)))
295 { 307 {
296 if (((void *) _dyld_get_image_header (i)) != (void *) &_mh_dylib_header) 308 LOG_STRERROR ("strdup");
297 continue; 309 return NULL;
298 path = _dyld_get_image_name (i);
299 if ( (NULL == path) || (0 == strlen (path)) )
300 continue;
301 if (NULL == (p = strdup (path)))
302 {
303 LOG_STRERROR ("strdup");
304 return NULL;
305 }
306 s = p + strlen (p);
307 while ( (s > p) && ('/' != *s) )
308 s--;
309 s++;
310 *s = '\0';
311 return p;
312 } 310 }
311 s = p + strlen (p);
312 while ( (s > p) && ('/' != *s) )
313 s--;
314 s++;
315 *s = '\0';
316 return p;
317 }
313 return NULL; 318 return NULL;
314} 319}
320
321
315#endif 322#endif
316 323
317 324
@@ -322,7 +329,7 @@ get_path_from_dyld_image ()
322 * @return path to binary, NULL if not found 329 * @return path to binary, NULL if not found
323 */ 330 */
324static char * 331static char *
325get_path_from_PATH() 332get_path_from_PATH ()
326{ 333{
327 struct stat sbuf; 334 struct stat sbuf;
328 char *path; 335 char *path;
@@ -335,61 +342,61 @@ get_path_from_PATH()
335 if (NULL == (p = getenv ("PATH"))) 342 if (NULL == (p = getenv ("PATH")))
336 return NULL; 343 return NULL;
337 if (NULL == (path = strdup (p))) /* because we write on it */ 344 if (NULL == (path = strdup (p))) /* because we write on it */
338 { 345 {
339 LOG_STRERROR ("strdup"); 346 LOG_STRERROR ("strdup");
340 return NULL; 347 return NULL;
341 } 348 }
342 if (NULL == (buf = malloc (strlen (path) + 20))) 349 if (NULL == (buf = malloc (strlen (path) + 20)))
343 { 350 {
344 LOG_STRERROR ("malloc"); 351 LOG_STRERROR ("malloc");
345 free (path); 352 free (path);
346 return NULL; 353 return NULL;
347 } 354 }
348 pos = path; 355 pos = path;
349 while (NULL != (end = strchr(pos, ':'))) 356 while (NULL != (end = strchr (pos, ':')))
350 { 357 {
351 *end = '\0'; 358 *end = '\0';
352 sprintf (buf, "%s/%s", pos, "extract"); 359 sprintf (buf, "%s/%s", pos, "extract");
353 if (0 == stat(buf, &sbuf)) 360 if (0 == stat (buf, &sbuf))
354 {
355 free (buf);
356 if (NULL == (pos = strdup (pos)))
357 {
358 LOG_STRERROR ("strdup");
359 free (path);
360 return NULL;
361 }
362 free (path);
363 pos = cut_bin (pos);
364 if (NULL == (ret = realloc (pos, strlen (pos) + 6)))
365 {
366 LOG_STRERROR ("realloc");
367 free (pos);
368 return NULL;
369 }
370 strcat (ret, "/lib/");
371 return ret;
372 }
373 pos = end + 1;
374 }
375 sprintf (buf, "%s/%s", pos, "extract");
376 if (0 == stat (buf, &sbuf))
377 { 361 {
378 pos = strdup (pos);
379 free (buf); 362 free (buf);
363 if (NULL == (pos = strdup (pos)))
364 {
365 LOG_STRERROR ("strdup");
366 free (path);
367 return NULL;
368 }
380 free (path); 369 free (path);
381 if (NULL == pos)
382 return NULL;
383 pos = cut_bin (pos); 370 pos = cut_bin (pos);
384 if (NULL == (ret = realloc (pos, strlen (pos) + 6))) 371 if (NULL == (ret = realloc (pos, strlen (pos) + 6)))
385 { 372 {
386 LOG_STRERROR ("realloc"); 373 LOG_STRERROR ("realloc");
387 free (pos); 374 free (pos);
388 return NULL; 375 return NULL;
389 } 376 }
390 strcat (ret, "/lib/"); 377 strcat (ret, "/lib/");
391 return ret; 378 return ret;
392 } 379 }
380 pos = end + 1;
381 }
382 sprintf (buf, "%s/%s", pos, "extract");
383 if (0 == stat (buf, &sbuf))
384 {
385 pos = strdup (pos);
386 free (buf);
387 free (path);
388 if (NULL == pos)
389 return NULL;
390 pos = cut_bin (pos);
391 if (NULL == (ret = realloc (pos, strlen (pos) + 6)))
392 {
393 LOG_STRERROR ("realloc");
394 free (pos);
395 return NULL;
396 }
397 strcat (ret, "/lib/");
398 return ret;
399 }
393 free (buf); 400 free (buf);
394 free (path); 401 free (path);
395 return NULL; 402 return NULL;
@@ -405,7 +412,7 @@ get_path_from_PATH()
405 */ 412 */
406static char * 413static char *
407append_to_dir (const char *path, 414append_to_dir (const char *path,
408 const char *fname) 415 const char *fname)
409{ 416{
410 char *ret; 417 char *ret;
411 size_t slen; 418 size_t slen;
@@ -414,31 +421,31 @@ append_to_dir (const char *path,
414 return NULL; 421 return NULL;
415 if (DIR_SEPARATOR == fname[0]) 422 if (DIR_SEPARATOR == fname[0])
416 fname++; 423 fname++;
417 ret = malloc (slen + strlen(fname) + 2); 424 ret = malloc (slen + strlen (fname) + 2);
418 if (NULL == ret) 425 if (NULL == ret)
419 return NULL; 426 return NULL;
420#ifdef MINGW 427#ifdef MINGW
421 if ('\\' == path[slen-1]) 428 if ('\\' == path[slen - 1])
422 sprintf (ret, 429 sprintf (ret,
423 "%s%s", 430 "%s%s",
424 path, 431 path,
425 fname); 432 fname);
426 else 433 else
427 sprintf (ret, 434 sprintf (ret,
428 "%s\\%s", 435 "%s\\%s",
429 path, 436 path,
430 fname); 437 fname);
431#else 438#else
432 if ('/' == path[slen-1]) 439 if ('/' == path[slen - 1])
433 sprintf (ret, 440 sprintf (ret,
434 "%s%s", 441 "%s%s",
435 path, 442 path,
436 fname); 443 fname);
437 else 444 else
438 sprintf (ret, 445 sprintf (ret,
439 "%s/%s", 446 "%s/%s",
440 path, 447 path,
441 fname); 448 fname);
442#endif 449#endif
443 return ret; 450 return ret;
444} 451}
@@ -453,7 +460,7 @@ append_to_dir (const char *path,
453 */ 460 */
454static void 461static void
455get_installation_paths (EXTRACTOR_PathProcessor pp, 462get_installation_paths (EXTRACTOR_PathProcessor pp,
456 void *pp_cls) 463 void *pp_cls)
457{ 464{
458 const char *p; 465 const char *p;
459 char *path; 466 char *path;
@@ -463,19 +470,19 @@ get_installation_paths (EXTRACTOR_PathProcessor pp,
463 470
464 prefix = NULL; 471 prefix = NULL;
465 if (NULL != (p = getenv ("LIBEXTRACTOR_PREFIX"))) 472 if (NULL != (p = getenv ("LIBEXTRACTOR_PREFIX")))
473 {
474 if (NULL == (d = strdup (p)))
466 { 475 {
467 if (NULL == (d = strdup (p))) 476 LOG_STRERROR ("strdup");
468 {
469 LOG_STRERROR ("strdup");
470 return;
471 }
472 for (prefix = strtok_r (d, PATH_SEPARATOR_STR, &saveptr);
473 NULL != prefix;
474 prefix = strtok_r (NULL, PATH_SEPARATOR_STR, &saveptr))
475 pp (pp_cls, prefix);
476 free (d);
477 return; 477 return;
478 } 478 }
479 for (prefix = strtok_r (d, PATH_SEPARATOR_STR, &saveptr);
480 NULL != prefix;
481 prefix = strtok_r (NULL, PATH_SEPARATOR_STR, &saveptr))
482 pp (pp_cls, prefix);
483 free (d);
484 return;
485 }
479#if GNU_LINUX 486#if GNU_LINUX
480 if (NULL == prefix) 487 if (NULL == prefix)
481 prefix = get_path_from_proc_exe (); 488 prefix = get_path_from_proc_exe ();
@@ -497,12 +504,12 @@ get_installation_paths (EXTRACTOR_PathProcessor pp,
497 return; 504 return;
498 path = append_to_dir (prefix, PLUGINDIR); 505 path = append_to_dir (prefix, PLUGINDIR);
499 if (NULL != path) 506 if (NULL != path)
500 { 507 {
501 if (0 != strcmp (path, 508 if (0 != strcmp (path,
502 PLUGININSTDIR)) 509 PLUGININSTDIR))
503 pp (pp_cls, path); 510 pp (pp_cls, path);
504 free (path); 511 free (path);
505 } 512 }
506 free (prefix); 513 free (prefix);
507} 514}
508 515
@@ -532,7 +539,7 @@ struct SearchContext
532 */ 539 */
533static void 540static void
534find_plugin_in_path (void *cls, 541find_plugin_in_path (void *cls,
535 const char *path) 542 const char *path)
536{ 543{
537 struct SearchContext *sc = cls; 544 struct SearchContext *sc = cls;
538 DIR *dir; 545 DIR *dir;
@@ -547,34 +554,34 @@ find_plugin_in_path (void *cls,
547 if (NULL == (dir = OPENDIR (path))) 554 if (NULL == (dir = OPENDIR (path)))
548 return; 555 return;
549 while (NULL != (ent = READDIR (dir))) 556 while (NULL != (ent = READDIR (dir)))
557 {
558 if ('.' == ent->d_name[0])
559 continue;
560 dlen = strlen (ent->d_name);
561 if ( (dlen < 4) ||
562 ( (0 != strcmp (&ent->d_name[dlen - 3], ".so")) &&
563 (0 != strcasecmp (&ent->d_name[dlen - 4], ".dll")) ) )
564 continue; /* only load '.so' and '.dll' */
565 if (NULL == (sym_name = strrchr (ent->d_name, '_')))
566 continue;
567 sym_name++;
568 if (NULL == (sym = strdup (sym_name)))
569 {
570 LOG_STRERROR ("strdup");
571 CLOSEDIR (dir);
572 return;
573 }
574 dot = strchr (sym, '.');
575 if (NULL != dot)
576 *dot = '\0';
577 if (0 == strcmp (sym, sc->short_name))
550 { 578 {
551 if ('.' == ent->d_name[0]) 579 sc->path = append_to_dir (path, ent->d_name);
552 continue;
553 dlen = strlen (ent->d_name);
554 if ( (dlen < 4) ||
555 ( (0 != strcmp (&ent->d_name[dlen-3], ".so")) &&
556 (0 != strcasecmp (&ent->d_name[dlen-4], ".dll")) ) )
557 continue; /* only load '.so' and '.dll' */
558 if (NULL == (sym_name = strrchr (ent->d_name, '_')))
559 continue;
560 sym_name++;
561 if (NULL == (sym = strdup (sym_name)))
562 {
563 LOG_STRERROR ("strdup");
564 CLOSEDIR (dir);
565 return;
566 }
567 dot = strchr (sym, '.');
568 if (NULL != dot)
569 *dot = '\0';
570 if (0 == strcmp (sym, sc->short_name))
571 {
572 sc->path = append_to_dir (path, ent->d_name);
573 free (sym);
574 break;
575 }
576 free (sym); 580 free (sym);
581 break;
577 } 582 }
583 free (sym);
584 }
578 CLOSEDIR (dir); 585 CLOSEDIR (dir);
579} 586}
580 587
@@ -591,7 +598,7 @@ EXTRACTOR_find_plugin_ (const char *short_name)
591 sc.path = NULL; 598 sc.path = NULL;
592 sc.short_name = short_name; 599 sc.short_name = short_name;
593 get_installation_paths (&find_plugin_in_path, 600 get_installation_paths (&find_plugin_in_path,
594 &sc); 601 &sc);
595 return sc.path; 602 return sc.path;
596} 603}
597 604
@@ -621,7 +628,7 @@ struct DefaultLoaderContext
621 */ 628 */
622static void 629static void
623load_plugins_from_dir (void *cls, 630load_plugins_from_dir (void *cls,
624 const char *path) 631 const char *path)
625{ 632{
626 struct DefaultLoaderContext *dlc = cls; 633 struct DefaultLoaderContext *dlc = cls;
627 DIR *dir; 634 DIR *dir;
@@ -634,31 +641,31 @@ load_plugins_from_dir (void *cls,
634 if (NULL == (dir = opendir (path))) 641 if (NULL == (dir = opendir (path)))
635 return; 642 return;
636 while (NULL != (ent = readdir (dir))) 643 while (NULL != (ent = readdir (dir)))
644 {
645 if (ent->d_name[0] == '.')
646 continue;
647 dlen = strlen (ent->d_name);
648 if ( (dlen < 4) ||
649 ( (0 != strcmp (&ent->d_name[dlen - 3], ".so")) &&
650 (0 != strcasecmp (&ent->d_name[dlen - 4], ".dll")) ) )
651 continue; /* only load '.so' and '.dll' */
652 if (NULL == (sym_name = strrchr (ent->d_name, '_')))
653 continue;
654 sym_name++;
655 if (NULL == (sym = strdup (sym_name)))
637 { 656 {
638 if (ent->d_name[0] == '.') 657 LOG_STRERROR ("strdup");
639 continue; 658 closedir (dir);
640 dlen = strlen (ent->d_name); 659 return;
641 if ( (dlen < 4) ||
642 ( (0 != strcmp (&ent->d_name[dlen-3], ".so")) &&
643 (0 != strcasecmp (&ent->d_name[dlen-4], ".dll")) ) )
644 continue; /* only load '.so' and '.dll' */
645 if (NULL == (sym_name = strrchr (ent->d_name, '_')))
646 continue;
647 sym_name++;
648 if (NULL == (sym = strdup (sym_name)))
649 {
650 LOG_STRERROR ("strdup");
651 closedir (dir);
652 return;
653 }
654 if (NULL != (dot = strchr (sym, '.')))
655 *dot = '\0';
656 dlc->res = EXTRACTOR_plugin_add (dlc->res,
657 sym,
658 NULL,
659 dlc->flags);
660 free (sym);
661 } 660 }
661 if (NULL != (dot = strchr (sym, '.')))
662 *dot = '\0';
663 dlc->res = EXTRACTOR_plugin_add (dlc->res,
664 sym,
665 NULL,
666 dlc->flags);
667 free (sym);
668 }
662 closedir (dir); 669 closedir (dir);
663} 670}
664 671
@@ -685,7 +692,7 @@ EXTRACTOR_plugin_add_defaults (enum EXTRACTOR_Options flags)
685 dlc.res = NULL; 692 dlc.res = NULL;
686 dlc.flags = flags; 693 dlc.flags = flags;
687 get_installation_paths (&load_plugins_from_dir, 694 get_installation_paths (&load_plugins_from_dir,
688 &dlc); 695 &dlc);
689 return dlc.res; 696 return dlc.res;
690} 697}
691 698
diff --git a/src/main/extractor_plugpath.h b/src/main/extractor_plugpath.h
index 848be52..3a3b217 100644
--- a/src/main/extractor_plugpath.h
+++ b/src/main/extractor_plugpath.h
@@ -29,9 +29,9 @@
29 * Given a short name of a library (i.e. "mime"), find 29 * Given a short name of a library (i.e. "mime"), find
30 * the full path of the respective plugin. 30 * the full path of the respective plugin.
31 */ 31 */
32char * 32char *
33EXTRACTOR_find_plugin_ (const char *short_name); 33EXTRACTOR_find_plugin_ (const char *short_name);
34 34
35 35
36#endif 36#endif
37/* EXTRACTOR_PLUGPATH_H */ 37/* EXTRACTOR_PLUGPATH_H */
diff --git a/src/main/extractor_print.c b/src/main/extractor_print.c
index 3530430..a89b522 100644
--- a/src/main/extractor_print.c
+++ b/src/main/extractor_print.c
@@ -33,72 +33,73 @@
33 * Simple EXTRACTOR_MetaDataProcessor implementation that simply 33 * Simple EXTRACTOR_MetaDataProcessor implementation that simply
34 * prints the extracted meta data to the given file. Only prints 34 * prints the extracted meta data to the given file. Only prints
35 * those keywords that are in UTF-8 format. 35 * those keywords that are in UTF-8 format.
36 * 36 *
37 * @param handle the file to write to (stdout, stderr), must NOT be NULL, 37 * @param handle the file to write to (stdout, stderr), must NOT be NULL,
38 * must be of type "FILE *". 38 * must be of type "FILE *".
39 * @param plugin_name name of the plugin that produced this value 39 * @param plugin_name name of the plugin that produced this value
40 * @param type libextractor-type describing the meta data 40 * @param type libextractor-type describing the meta data
41 * @param format basic format information about data 41 * @param format basic format information about data
42 * @param data_mime_type mime-type of data (not of the original file); 42 * @param data_mime_type mime-type of data (not of the original file);
43 * can be NULL (if mime-type is not known) 43 * can be NULL (if mime-type is not known)
44 * @param data actual meta-data found 44 * @param data actual meta-data found
45 * @param data_len number of bytes in data 45 * @param data_len number of bytes in data
46 * @return non-zero if printing failed, otherwise 0. 46 * @return non-zero if printing failed, otherwise 0.
47 */ 47 */
48int 48int
49EXTRACTOR_meta_data_print (void *handle, 49EXTRACTOR_meta_data_print (void *handle,
50 const char *plugin_name, 50 const char *plugin_name,
51 enum EXTRACTOR_MetaType type, 51 enum EXTRACTOR_MetaType type,
52 enum EXTRACTOR_MetaFormat format, 52 enum EXTRACTOR_MetaFormat format,
53 const char *data_mime_type, 53 const char *data_mime_type,
54 const char *data, 54 const char *data,
55 size_t data_len) 55 size_t data_len)
56{ 56{
57#if HAVE_ICONV 57#if HAVE_ICONV
58 iconv_t cd; 58 iconv_t cd;
59#endif 59#endif
60 char * buf; 60 char *buf;
61 int ret; 61 int ret;
62 const char *mt; 62 const char *mt;
63 63
64 if (EXTRACTOR_METAFORMAT_UTF8 != format) 64 if (EXTRACTOR_METAFORMAT_UTF8 != format)
65 return 0; 65 return 0;
66#if HAVE_ICONV 66#if HAVE_ICONV
67 cd = iconv_open (nl_langinfo(CODESET), 67 cd = iconv_open (nl_langinfo (CODESET),
68 "UTF-8"); 68 "UTF-8");
69 if (((iconv_t) -1) == cd) 69 if (((iconv_t) -1) == cd)
70 { 70 {
71 LOG_STRERROR ("iconv_open"); 71 LOG_STRERROR ("iconv_open");
72 return 1; 72 return 1;
73 } 73 }
74 buf = iconv_helper (cd, data, data_len); 74 buf = iconv_helper (cd, data, data_len);
75 if (NULL == buf) 75 if (NULL == buf)
76 { 76 {
77 LOG_STRERROR ("iconv_helper"); 77 LOG_STRERROR ("iconv_helper");
78 ret = -1; 78 ret = -1;
79 } 79 }
80 else 80 else
81 { 81 {
82 mt = EXTRACTOR_metatype_to_string (type); 82 mt = EXTRACTOR_metatype_to_string (type);
83 ret = fprintf (handle, 83 ret = fprintf (handle,
84 "%s - %s\n", 84 "%s - %s\n",
85 (NULL == mt) 85 (NULL == mt)
86 ? dgettext ("libextractor", gettext_noop ("unknown")) 86 ? dgettext ("libextractor", gettext_noop ("unknown"))
87 : dgettext ("libextractor", mt), 87 : dgettext ("libextractor", mt),
88 buf); 88 buf);
89 free(buf); 89 free (buf);
90 } 90 }
91 iconv_close(cd); 91 iconv_close (cd);
92#else 92#else
93 ret = fprintf (handle, 93 ret = fprintf (handle,
94 "%s - %.*s\n", 94 "%s - %.*s\n",
95 (NULL == mt) 95 (NULL == mt)
96 ? dgettext ("libextractor", gettext_noop ("unknown")) 96 ? dgettext ("libextractor", gettext_noop ("unknown"))
97 : dgettext ("libextractor", mt), 97 : dgettext ("libextractor", mt),
98 (int) data_len, 98 (int) data_len,
99 data); 99 data);
100#endif 100#endif
101 return (ret < 0) ? 1 : 0; 101 return (ret < 0) ? 1 : 0;
102} 102}
103 103
104
104/* end of extractor_print.c */ 105/* end of extractor_print.c */
diff --git a/src/main/getopt.c b/src/main/getopt.c
index b64fdf5..890aa9b 100644
--- a/src/main/getopt.c
+++ b/src/main/getopt.c
@@ -4,7 +4,7 @@
4 before changing it! 4 before changing it!
5 5
6 Copyright Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97 6 Copyright Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97
7 Free Software Foundation, Inc. 7 Free Software Foundation, Inc.
8 8
9NOTE: The canonical source of this file is maintained with the GNU C Library. 9NOTE: The canonical source of this file is maintained with the GNU C Library.
10Bugs can be reported to bug-glibc@prep.ai.mit.edu. 10Bugs can be reported to bug-glibc@prep.ai.mit.edu.
@@ -32,7 +32,7 @@ USA. */
32 32
33#include "config.h" 33#include "config.h"
34 34
35#if !defined (__STDC__) || !__STDC__ 35#if ! defined (__STDC__) || ! __STDC__
36/* This is a separate conditional since some stdc systems 36/* This is a separate conditional since some stdc systems
37 reject `defined (const)'. */ 37 reject `defined (const)'. */
38#ifndef const 38#ifndef const
@@ -51,7 +51,7 @@ USA. */
51 it is simpler to just do this in the source for each such file. */ 51 it is simpler to just do this in the source for each such file. */
52 52
53#define GETOPT_INTERFACE_VERSION 2 53#define GETOPT_INTERFACE_VERSION 2
54#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2 54#if ! defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2
55#include <gnu-versions.h> 55#include <gnu-versions.h>
56#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION 56#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
57#define ELIDE_CODE 57#define ELIDE_CODE
@@ -63,7 +63,7 @@ USA. */
63 63
64/* This needs to come after some library #include 64/* This needs to come after some library #include
65 to get __GNU_LIBRARY__ defined. */ 65 to get __GNU_LIBRARY__ defined. */
66#ifdef __GNU_LIBRARY__ 66#ifdef __GNU_LIBRARY__
67/* Don't include stdlib.h for non-GNU C libraries because some of them 67/* Don't include stdlib.h for non-GNU C libraries because some of them
68 contain conflicting prototypes for getopt. */ 68 contain conflicting prototypes for getopt. */
69#include <stdlib.h> 69#include <stdlib.h>
@@ -77,10 +77,10 @@ USA. */
77#include <string.h> 77#include <string.h>
78#endif 78#endif
79 79
80#if defined (WIN32) && !defined (__CYGWIN32__) 80#if defined (WIN32) && ! defined (__CYGWIN32__)
81/* It's not Unix, really. See? Capital letters. */ 81/* It's not Unix, really. See? Capital letters. */
82#include <windows.h> 82#include <windows.h>
83#define getpid() GetCurrentProcessId() 83#define getpid() GetCurrentProcessId ()
84#endif 84#endif
85 85
86#ifndef _ 86#ifndef _
@@ -88,9 +88,9 @@ USA. */
88 When compiling libc, the _ macro is predefined. */ 88 When compiling libc, the _ macro is predefined. */
89#ifdef NEVER_HAVE_LIBINTL_H 89#ifdef NEVER_HAVE_LIBINTL_H
90# include <libintl.h> 90# include <libintl.h>
91# define _(msgid) gettext (msgid) 91# define _(msgid) gettext (msgid)
92#else 92#else
93# define _(msgid) (msgid) 93# define _(msgid) (msgid)
94#endif 94#endif
95#endif 95#endif
96 96
@@ -195,14 +195,14 @@ static enum
195 195
196/* Value of POSIXLY_CORRECT environment variable. */ 196/* Value of POSIXLY_CORRECT environment variable. */
197static char *posixly_correct; 197static char *posixly_correct;
198 198
199#ifdef __GNU_LIBRARY__ 199#ifdef __GNU_LIBRARY__
200/* We want to avoid inclusion of string.h with non-GNU libraries 200/* We want to avoid inclusion of string.h with non-GNU libraries
201 because there are many ways it can cause trouble. 201 because there are many ways it can cause trouble.
202 On some systems, it contains special magic macros that don't work 202 On some systems, it contains special magic macros that don't work
203 in GCC. */ 203 in GCC. */
204#include <string.h> 204#include <string.h>
205#define my_index strchr 205#define my_index strchr
206#else 206#else
207 207
208/* Avoid depending on library functions or files 208/* Avoid depending on library functions or files
@@ -212,15 +212,16 @@ char *getenv ();
212 212
213static char * 213static char *
214my_index (str, chr) 214my_index (str, chr)
215 const char *str; 215const char *str;
216 int chr; 216
217int chr;
217{ 218{
218 while (*str) 219 while (*str)
219 { 220 {
220 if (*str == chr) 221 if (*str == chr)
221 return (char *) str; 222 return (char *) str;
222 str++; 223 str++;
223 } 224 }
224 return 0; 225 return 0;
225} 226}
226 227
@@ -229,18 +230,20 @@ my_index (str, chr)
229#ifdef __GNUC__ 230#ifdef __GNUC__
230/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. 231/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
231 That was relevant to code that was here before. */ 232 That was relevant to code that was here before. */
232#if !defined (__STDC__) || !__STDC__ 233#if ! defined (__STDC__) || ! __STDC__
233/* gcc with -traditional declares the built-in strlen to return int, 234/* gcc with -traditional declares the built-in strlen to return int,
234 and has done so at least since version 2.4.5. -- rms. */ 235 and has done so at least since version 2.4.5. -- rms. */
235extern int strlen (const char *); 236extern int strlen (const char *);
237
236#endif /* not __STDC__ */ 238#endif /* not __STDC__ */
237#if defined(__APPLE__) 239#if defined(__APPLE__)
238extern size_t strlen (const char *); 240extern size_t strlen (const char *);
241
239#endif 242#endif
240#endif /* __GNUC__ */ 243#endif /* __GNUC__ */
241 244
242#endif /* not __GNU_LIBRARY__ */ 245#endif /* not __GNU_LIBRARY__ */
243 246
244/* Handle permutation of arguments. */ 247/* Handle permutation of arguments. */
245 248
246/* Describe the part of ARGV that contains non-options that have 249/* Describe the part of ARGV that contains non-options that have
@@ -269,7 +272,8 @@ extern pid_t __libc_pid;
269 is valid for the getopt call we must make sure that the ARGV passed 272 is valid for the getopt call we must make sure that the ARGV passed
270 to getopt is that one passed to the process. */ 273 to getopt is that one passed to the process. */
271static void 274static void
272 __attribute__ ((unused)) store_args_and_env (int argc, char *const *argv) 275__attribute__ ((unused))
276store_args_and_env (int argc, char *const *argv)
273{ 277{
274 /* XXX This is no good solution. We should rather copy the args so 278 /* XXX This is no good solution. We should rather copy the args so
275 that we can compare them later. But we must not use malloc(3). */ 279 that we can compare them later. But we must not use malloc(3). */
@@ -277,15 +281,16 @@ static void
277 original_argv = argv; 281 original_argv = argv;
278} 282}
279 283
284
280text_set_element (__libc_subinit, store_args_and_env); 285text_set_element (__libc_subinit, store_args_and_env);
281 286
282# define SWAP_FLAGS(ch1, ch2) \ 287# define SWAP_FLAGS(ch1, ch2) \
283 if (nonoption_flags_len > 0) \ 288 if (nonoption_flags_len > 0) \
284 { \ 289 { \
285 char __tmp = __getopt_nonoption_flags[ch1]; \ 290 char __tmp = __getopt_nonoption_flags[ch1]; \
286 __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ 291 __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
287 __getopt_nonoption_flags[ch2] = __tmp; \ 292 __getopt_nonoption_flags[ch2] = __tmp; \
288 } 293 }
289#else /* !_LIBC */ 294#else /* !_LIBC */
290# define SWAP_FLAGS(ch1, ch2) 295# define SWAP_FLAGS(ch1, ch2)
291#endif /* _LIBC */ 296#endif /* _LIBC */
@@ -301,11 +306,13 @@ text_set_element (__libc_subinit, store_args_and_env);
301 306
302#if defined (__STDC__) && __STDC__ 307#if defined (__STDC__) && __STDC__
303static void exchange (char **); 308static void exchange (char **);
309
304#endif 310#endif
305 311
306static void 312static void
307exchange (argv) 313exchange (argv)
308 char **argv; 314char **argv;
315
309{ 316{
310 int bottom = first_nonopt; 317 int bottom = first_nonopt;
311 int middle = last_nonopt; 318 int middle = last_nonopt;
@@ -321,61 +328,61 @@ exchange (argv)
321 /* First make sure the handling of the `__getopt_nonoption_flags' 328 /* First make sure the handling of the `__getopt_nonoption_flags'
322 string can work normally. Our top argument must be in the range 329 string can work normally. Our top argument must be in the range
323 of the string. */ 330 of the string. */
324 if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) 331 if ((nonoption_flags_len > 0) && (top >= nonoption_flags_max_len))
332 {
333 /* We must extend the array. The user plays games with us and
334 presents new arguments. */
335 char *new_str = malloc (top + 1);
336 if (new_str == NULL)
337 nonoption_flags_len = nonoption_flags_max_len = 0;
338 else
325 { 339 {
326 /* We must extend the array. The user plays games with us and 340 memcpy (new_str, __getopt_nonoption_flags, nonoption_flags_max_len);
327 presents new arguments. */ 341 memset (&new_str[nonoption_flags_max_len], '\0',
328 char *new_str = malloc (top + 1); 342 top + 1 - nonoption_flags_max_len);
329 if (new_str == NULL) 343 nonoption_flags_max_len = top + 1;
330 nonoption_flags_len = nonoption_flags_max_len = 0; 344 __getopt_nonoption_flags = new_str;
331 else
332 {
333 memcpy (new_str, __getopt_nonoption_flags, nonoption_flags_max_len);
334 memset (&new_str[nonoption_flags_max_len], '\0',
335 top + 1 - nonoption_flags_max_len);
336 nonoption_flags_max_len = top + 1;
337 __getopt_nonoption_flags = new_str;
338 }
339 } 345 }
346 }
340#endif 347#endif
341 348
342 while (top > middle && middle > bottom) 349 while (top > middle && middle > bottom)
350 {
351 if (top - middle > middle - bottom)
343 { 352 {
344 if (top - middle > middle - bottom) 353 /* Bottom segment is the short one. */
345 { 354 int len = middle - bottom;
346 /* Bottom segment is the short one. */ 355 register int i;
347 int len = middle - bottom; 356
348 register int i; 357 /* Swap it with the top part of the top segment. */
349 358 for (i = 0; i < len; i++)
350 /* Swap it with the top part of the top segment. */ 359 {
351 for (i = 0; i < len; i++) 360 tem = argv[bottom + i];
352 { 361 argv[bottom + i] = argv[top - (middle - bottom) + i];
353 tem = argv[bottom + i]; 362 argv[top - (middle - bottom) + i] = tem;
354 argv[bottom + i] = argv[top - (middle - bottom) + i]; 363 SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
355 argv[top - (middle - bottom) + i] = tem; 364 }
356 SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); 365 /* Exclude the moved bottom segment from further swapping. */
357 } 366 top -= len;
358 /* Exclude the moved bottom segment from further swapping. */ 367 }
359 top -= len; 368 else
360 } 369 {
361 else 370 /* Top segment is the short one. */
362 { 371 int len = top - middle;
363 /* Top segment is the short one. */ 372 register int i;
364 int len = top - middle; 373
365 register int i; 374 /* Swap it with the bottom part of the bottom segment. */
366 375 for (i = 0; i < len; i++)
367 /* Swap it with the bottom part of the bottom segment. */ 376 {
368 for (i = 0; i < len; i++) 377 tem = argv[bottom + i];
369 { 378 argv[bottom + i] = argv[middle + i];
370 tem = argv[bottom + i]; 379 argv[middle + i] = tem;
371 argv[bottom + i] = argv[middle + i]; 380 SWAP_FLAGS (bottom + i, middle + i);
372 argv[middle + i] = tem; 381 }
373 SWAP_FLAGS (bottom + i, middle + i); 382 /* Exclude the moved top segment from further swapping. */
374 } 383 bottom += len;
375 /* Exclude the moved top segment from further swapping. */
376 bottom += len;
377 }
378 } 384 }
385 }
379 386
380 /* Update records for the slots the non-options now occupy. */ 387 /* Update records for the slots the non-options now occupy. */
381 388
@@ -387,12 +394,14 @@ exchange (argv)
387 394
388#if defined (__STDC__) && __STDC__ 395#if defined (__STDC__) && __STDC__
389static const char *_getopt_initialize (int, char *const *, const char *); 396static const char *_getopt_initialize (int, char *const *, const char *);
397
390#endif 398#endif
391static const char * 399static const char *
392_getopt_initialize (argc, argv, optstring) 400_getopt_initialize (argc, argv, optstring)
393 int argc; 401int argc;
394 char *const *argv; 402
395 const char *optstring; 403char *const *argv;
404const char *optstring;
396{ 405{
397 /* Start processing options with ARGV-element 1 (since ARGV-element 0 406 /* Start processing options with ARGV-element 1 (since ARGV-element 0
398 is the program name); the sequence of previously skipped 407 is the program name); the sequence of previously skipped
@@ -407,56 +416,56 @@ _getopt_initialize (argc, argv, optstring)
407 /* Determine how to handle the ordering of options and nonoptions. */ 416 /* Determine how to handle the ordering of options and nonoptions. */
408 417
409 if (optstring[0] == '-') 418 if (optstring[0] == '-')
410 { 419 {
411 ordering = RETURN_IN_ORDER; 420 ordering = RETURN_IN_ORDER;
412 ++optstring; 421 ++optstring;
413 } 422 }
414 else if (optstring[0] == '+') 423 else if (optstring[0] == '+')
415 { 424 {
416 ordering = REQUIRE_ORDER; 425 ordering = REQUIRE_ORDER;
417 ++optstring; 426 ++optstring;
418 } 427 }
419 else if (posixly_correct != NULL) 428 else if (posixly_correct != NULL)
420 ordering = REQUIRE_ORDER; 429 ordering = REQUIRE_ORDER;
421 else 430 else
422 ordering = PERMUTE; 431 ordering = PERMUTE;
423 432
424#ifdef _LIBC 433#ifdef _LIBC
425 if (posixly_correct == NULL 434 if ((posixly_correct == NULL)
426 && argc == original_argc && argv == original_argv) 435 && (argc == original_argc) && (argv == original_argv))
436 {
437 if (nonoption_flags_max_len == 0)
427 { 438 {
428 if (nonoption_flags_max_len == 0) 439 if ((__getopt_nonoption_flags == NULL)
429 { 440 || (__getopt_nonoption_flags[0] == '\0') )
430 if (__getopt_nonoption_flags == NULL 441 nonoption_flags_max_len = -1;
431 || __getopt_nonoption_flags[0] == '\0') 442 else
432 nonoption_flags_max_len = -1; 443 {
433 else 444 const char *orig_str = __getopt_nonoption_flags;
434 { 445 int len = nonoption_flags_max_len = strlen (orig_str);
435 const char *orig_str = __getopt_nonoption_flags; 446 if (nonoption_flags_max_len < argc)
436 int len = nonoption_flags_max_len = strlen (orig_str); 447 nonoption_flags_max_len = argc;
437 if (nonoption_flags_max_len < argc) 448 __getopt_nonoption_flags =
438 nonoption_flags_max_len = argc; 449 (char *) malloc (nonoption_flags_max_len);
439 __getopt_nonoption_flags = 450 if (__getopt_nonoption_flags == NULL)
440 (char *) malloc (nonoption_flags_max_len); 451 nonoption_flags_max_len = -1;
441 if (__getopt_nonoption_flags == NULL) 452 else
442 nonoption_flags_max_len = -1; 453 {
443 else 454 memcpy (__getopt_nonoption_flags, orig_str, len);
444 { 455 memset (&__getopt_nonoption_flags[len], '\0',
445 memcpy (__getopt_nonoption_flags, orig_str, len); 456 nonoption_flags_max_len - len);
446 memset (&__getopt_nonoption_flags[len], '\0', 457 }
447 nonoption_flags_max_len - len); 458 }
448 }
449 }
450 }
451 nonoption_flags_len = nonoption_flags_max_len;
452 } 459 }
460 nonoption_flags_len = nonoption_flags_max_len;
461 }
453 else 462 else
454 nonoption_flags_len = 0; 463 nonoption_flags_len = 0;
455#endif 464#endif
456 465
457 return optstring; 466 return optstring;
458} 467}
459 468
460/* Scan elements of ARGV (whose length is ARGC) for option characters 469/* Scan elements of ARGV (whose length is ARGC) for option characters
461 given in OPTSTRING. 470 given in OPTSTRING.
462 471
@@ -515,112 +524,113 @@ _getopt_initialize (argc, argv, optstring)
515 524
516int 525int
517_getopt_internal (argc, argv, optstring, longopts, longind, long_only) 526_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
518 int argc; 527int argc;
519 char *const *argv; 528
520 const char *optstring; 529char *const *argv;
521 const struct option *longopts; 530const char *optstring;
522 int *longind; 531const struct option *longopts;
523 int long_only; 532int *longind;
533int long_only;
524{ 534{
525 optarg = NULL; 535 optarg = NULL;
526 536
527 if (optind == 0 || !__getopt_initialized) 537 if ((optind == 0) || ! __getopt_initialized)
528 { 538 {
529 if (optind == 0) 539 if (optind == 0)
530 optind = 1; /* Don't scan ARGV[0], the program name. */ 540 optind = 1; /* Don't scan ARGV[0], the program name. */
531 optstring = _getopt_initialize (argc, argv, optstring); 541 optstring = _getopt_initialize (argc, argv, optstring);
532 __getopt_initialized = 1; 542 __getopt_initialized = 1;
533 } 543 }
534 544
535 /* Test whether ARGV[optind] points to a non-option argument. 545 /* Test whether ARGV[optind] points to a non-option argument.
536 Either it does not have option syntax, or there is an environment flag 546 Either it does not have option syntax, or there is an environment flag
537 from the shell indicating it is not an option. The later information 547 from the shell indicating it is not an option. The later information
538 is only used when the used in the GNU libc. */ 548 is only used when the used in the GNU libc. */
539#ifdef _LIBC 549#ifdef _LIBC
540#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ 550#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \
541 || (optind < nonoption_flags_len \ 551 || (optind < nonoption_flags_len \
542 && __getopt_nonoption_flags[optind] == '1')) 552 && __getopt_nonoption_flags[optind] == '1'))
543#else 553#else
544#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') 554#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
545#endif 555#endif
546 556
547 if (nextchar == NULL || *nextchar == '\0') 557 if ((nextchar == NULL) || (*nextchar == '\0'))
558 {
559 /* Advance to the next ARGV-element. */
560
561 /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
562 moved back by the user (who may also have changed the arguments). */
563 if (last_nonopt > optind)
564 last_nonopt = optind;
565 if (first_nonopt > optind)
566 first_nonopt = optind;
567
568 if (ordering == PERMUTE)
548 { 569 {
549 /* Advance to the next ARGV-element. */ 570 /* If we have just processed some options following some non-options,
550 571 exchange them so that the options come first. */
551 /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been 572
552 moved back by the user (who may also have changed the arguments). */ 573 if ((first_nonopt != last_nonopt) && (last_nonopt != optind) )
553 if (last_nonopt > optind) 574 exchange ((char **) argv);
554 last_nonopt = optind; 575 else if (last_nonopt != optind)
555 if (first_nonopt > optind) 576 first_nonopt = optind;
556 first_nonopt = optind; 577
557 578 /* Skip any additional non-options
558 if (ordering == PERMUTE) 579 and extend the range of non-options previously skipped. */
559 { 580
560 /* If we have just processed some options following some non-options, 581 while (optind < argc && NONOPTION_P)
561 exchange them so that the options come first. */ 582 optind++;
562 583 last_nonopt = optind;
563 if (first_nonopt != last_nonopt && last_nonopt != optind)
564 exchange ((char **) argv);
565 else if (last_nonopt != optind)
566 first_nonopt = optind;
567
568 /* Skip any additional non-options
569 and extend the range of non-options previously skipped. */
570
571 while (optind < argc && NONOPTION_P)
572 optind++;
573 last_nonopt = optind;
574 }
575
576 /* The special ARGV-element `--' means premature end of options.
577 Skip it like a null option,
578 then exchange with previous non-options as if it were an option,
579 then skip everything else like a non-option. */
580
581 if (optind != argc && !strcmp (argv[optind], "--"))
582 {
583 optind++;
584
585 if (first_nonopt != last_nonopt && last_nonopt != optind)
586 exchange ((char **) argv);
587 else if (first_nonopt == last_nonopt)
588 first_nonopt = optind;
589 last_nonopt = argc;
590
591 optind = argc;
592 }
593
594 /* If we have done all the ARGV-elements, stop the scan
595 and back over any non-options that we skipped and permuted. */
596
597 if (optind == argc)
598 {
599 /* Set the next-arg-index to point at the non-options
600 that we previously skipped, so the caller will digest them. */
601 if (first_nonopt != last_nonopt)
602 optind = first_nonopt;
603 return -1;
604 }
605
606 /* If we have come to a non-option and did not permute it,
607 either stop the scan or describe it to the caller and pass it by. */
608
609 if (NONOPTION_P)
610 {
611 if (ordering == REQUIRE_ORDER)
612 return -1;
613 optarg = argv[optind++];
614 return 1;
615 }
616
617 /* We have found another option-ARGV-element.
618 Skip the initial punctuation. */
619
620 nextchar = (argv[optind] + 1
621 + (longopts != NULL && argv[optind][1] == '-'));
622 } 584 }
623 585
586 /* The special ARGV-element `--' means premature end of options.
587 Skip it like a null option,
588 then exchange with previous non-options as if it were an option,
589 then skip everything else like a non-option. */
590
591 if ((optind != argc) && ! strcmp (argv[optind], "--"))
592 {
593 optind++;
594
595 if ((first_nonopt != last_nonopt) && (last_nonopt != optind) )
596 exchange ((char **) argv);
597 else if (first_nonopt == last_nonopt)
598 first_nonopt = optind;
599 last_nonopt = argc;
600
601 optind = argc;
602 }
603
604 /* If we have done all the ARGV-elements, stop the scan
605 and back over any non-options that we skipped and permuted. */
606
607 if (optind == argc)
608 {
609 /* Set the next-arg-index to point at the non-options
610 that we previously skipped, so the caller will digest them. */
611 if (first_nonopt != last_nonopt)
612 optind = first_nonopt;
613 return -1;
614 }
615
616 /* If we have come to a non-option and did not permute it,
617 either stop the scan or describe it to the caller and pass it by. */
618
619 if (NONOPTION_P)
620 {
621 if (ordering == REQUIRE_ORDER)
622 return -1;
623 optarg = argv[optind++];
624 return 1;
625 }
626
627 /* We have found another option-ARGV-element.
628 Skip the initial punctuation. */
629
630 nextchar = (argv[optind] + 1
631 + (longopts != NULL && argv[optind][1] == '-'));
632 }
633
624 /* Decode the current option-ARGV-element. */ 634 /* Decode the current option-ARGV-element. */
625 635
626 /* Check whether the ARGV-element is a long option. 636 /* Check whether the ARGV-element is a long option.
@@ -636,141 +646,141 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
636 646
637 This distinction seems to be the most useful approach. */ 647 This distinction seems to be the most useful approach. */
638 648
639 if (longopts != NULL 649 if ((longopts != NULL)
640 && (argv[optind][1] == '-' 650 && ((argv[optind][1] == '-')
641 || (long_only 651 || (long_only
642 && (argv[optind][2] 652 && (argv[optind][2]
643 || !my_index (optstring, argv[optind][1]))))) 653 || ! my_index (optstring, argv[optind][1])))))
644 { 654 {
645 char *nameend; 655 char *nameend;
646 const struct option *p; 656 const struct option *p;
647 const struct option *pfound = NULL; 657 const struct option *pfound = NULL;
648 int exact = 0; 658 int exact = 0;
649 int ambig = 0; 659 int ambig = 0;
650 int indfound = -1; 660 int indfound = -1;
651 int option_index; 661 int option_index;
662
663 for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
664 /* Do nothing. */;
665
666 /* Test all long options for either exact match
667 or abbreviated matches. */
668 for (p = longopts, option_index = 0; p->name; p++, option_index++)
669 if (! strncmp (p->name, nextchar, nameend - nextchar))
670 {
671 if ((unsigned int) (nameend - nextchar)
672 == (unsigned int) strlen (p->name))
673 {
674 /* Exact match found. */
675 pfound = p;
676 indfound = option_index;
677 exact = 1;
678 break;
679 }
680 else if (pfound == NULL)
681 {
682 /* First nonexact match found. */
683 pfound = p;
684 indfound = option_index;
685 }
686 else
687 /* Second or later nonexact match found. */
688 ambig = 1;
689 }
652 690
653 for (nameend = nextchar; *nameend && *nameend != '='; nameend++) 691 if (ambig && ! exact)
654 /* Do nothing. */ ; 692 {
693 if (opterr)
694 fprintf (stderr, _ ("%s: option `%s' is ambiguous\n"),
695 argv[0], argv[optind]);
696 nextchar += strlen (nextchar);
697 optind++;
698 optopt = 0;
699 return '?';
700 }
655 701
656 /* Test all long options for either exact match 702 if (pfound != NULL)
657 or abbreviated matches. */ 703 {
658 for (p = longopts, option_index = 0; p->name; p++, option_index++) 704 option_index = indfound;
659 if (!strncmp (p->name, nextchar, nameend - nextchar)) 705 optind++;
660 { 706 if (*nameend)
661 if ((unsigned int) (nameend - nextchar) 707 {
662 == (unsigned int) strlen (p->name)) 708 /* Don't test has_arg with >, because some C compilers don't
663 { 709 allow it to be used on enums. */
664 /* Exact match found. */ 710 if (pfound->has_arg)
665 pfound = p; 711 optarg = nameend + 1;
666 indfound = option_index; 712 else
667 exact = 1; 713 {
668 break; 714 if (opterr)
669 } 715 if (argv[optind - 1][1] == '-')
670 else if (pfound == NULL) 716 /* --option */
671 { 717 fprintf (stderr,
672 /* First nonexact match found. */ 718 _
673 pfound = p; 719 ("%s: option `--%s' doesn't allow an argument\n"),
674 indfound = option_index; 720 argv[0], pfound->name);
675 } 721 else
676 else 722 /* +option or -option */
677 /* Second or later nonexact match found. */ 723 fprintf (stderr,
678 ambig = 1; 724 _
679 } 725 ("%s: option `%c%s' doesn't allow an argument\n"),
680 726 argv[0], argv[optind - 1][0], pfound->name);
681 if (ambig && !exact) 727
682 { 728 nextchar += strlen (nextchar);
683 if (opterr) 729
684 fprintf (stderr, _("%s: option `%s' is ambiguous\n"), 730 optopt = pfound->val;
685 argv[0], argv[optind]); 731 return '?';
686 nextchar += strlen (nextchar); 732 }
687 optind++; 733 }
688 optopt = 0; 734 else if (pfound->has_arg == 1)
689 return '?'; 735 {
690 } 736 if (optind < argc)
737 optarg = argv[optind++];
738 else
739 {
740 if (opterr)
741 fprintf (stderr,
742 _ ("%s: option `%s' requires an argument\n"),
743 argv[0], argv[optind - 1]);
744 nextchar += strlen (nextchar);
745 optopt = pfound->val;
746 return optstring[0] == ':' ? ':' : '?';
747 }
748 }
749 nextchar += strlen (nextchar);
750 if (longind != NULL)
751 *longind = option_index;
752 if (pfound->flag)
753 {
754 *(pfound->flag) = pfound->val;
755 return 0;
756 }
757 return pfound->val;
758 }
691 759
692 if (pfound != NULL) 760 /* Can't find it as a long option. If this is not getopt_long_only,
693 { 761 or the option starts with '--' or is not a valid short
694 option_index = indfound; 762 option, then it's an error.
695 optind++; 763 Otherwise interpret it as a short option. */
696 if (*nameend) 764 if (! long_only || (argv[optind][1] == '-')
697 { 765 || (my_index (optstring, *nextchar) == NULL) )
698 /* Don't test has_arg with >, because some C compilers don't 766 {
699 allow it to be used on enums. */ 767 if (opterr)
700 if (pfound->has_arg) 768 {
701 optarg = nameend + 1; 769 if (argv[optind][1] == '-')
702 else 770 /* --option */
703 { 771 fprintf (stderr, _ ("%s: unrecognized option `--%s'\n"),
704 if (opterr) 772 argv[0], nextchar);
705 if (argv[optind - 1][1] == '-') 773 else
706 /* --option */ 774 /* +option or -option */
707 fprintf (stderr, 775 fprintf (stderr, _ ("%s: unrecognized option `%c%s'\n"),
708 _ 776 argv[0], argv[optind][0], nextchar);
709 ("%s: option `--%s' doesn't allow an argument\n"), 777 }
710 argv[0], pfound->name); 778 nextchar = (char *) "";
711 else 779 optind++;
712 /* +option or -option */ 780 optopt = 0;
713 fprintf (stderr, 781 return '?';
714 _
715 ("%s: option `%c%s' doesn't allow an argument\n"),
716 argv[0], argv[optind - 1][0], pfound->name);
717
718 nextchar += strlen (nextchar);
719
720 optopt = pfound->val;
721 return '?';
722 }
723 }
724 else if (pfound->has_arg == 1)
725 {
726 if (optind < argc)
727 optarg = argv[optind++];
728 else
729 {
730 if (opterr)
731 fprintf (stderr,
732 _("%s: option `%s' requires an argument\n"),
733 argv[0], argv[optind - 1]);
734 nextchar += strlen (nextchar);
735 optopt = pfound->val;
736 return optstring[0] == ':' ? ':' : '?';
737 }
738 }
739 nextchar += strlen (nextchar);
740 if (longind != NULL)
741 *longind = option_index;
742 if (pfound->flag)
743 {
744 *(pfound->flag) = pfound->val;
745 return 0;
746 }
747 return pfound->val;
748 }
749
750 /* Can't find it as a long option. If this is not getopt_long_only,
751 or the option starts with '--' or is not a valid short
752 option, then it's an error.
753 Otherwise interpret it as a short option. */
754 if (!long_only || argv[optind][1] == '-'
755 || my_index (optstring, *nextchar) == NULL)
756 {
757 if (opterr)
758 {
759 if (argv[optind][1] == '-')
760 /* --option */
761 fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
762 argv[0], nextchar);
763 else
764 /* +option or -option */
765 fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
766 argv[0], argv[optind][0], nextchar);
767 }
768 nextchar = (char *) "";
769 optind++;
770 optopt = 0;
771 return '?';
772 }
773 } 782 }
783 }
774 784
775 /* Look at and handle the next short option-character. */ 785 /* Look at and handle the next short option-character. */
776 786
@@ -782,205 +792,207 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
782 if (*nextchar == '\0') 792 if (*nextchar == '\0')
783 ++optind; 793 ++optind;
784 794
785 if (temp == NULL || c == ':') 795 if ((temp == NULL) || (c == ':'))
796 {
797 if (opterr)
786 { 798 {
787 if (opterr) 799 if (posixly_correct)
788 { 800 /* 1003.2 specifies the format of this message. */
789 if (posixly_correct) 801 fprintf (stderr, _ ("%s: illegal option -- %c\n"), argv[0], c);
790 /* 1003.2 specifies the format of this message. */ 802 else
791 fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c); 803 fprintf (stderr, _ ("%s: invalid option -- %c\n"), argv[0], c);
792 else
793 fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c);
794 }
795 optopt = c;
796 return '?';
797 } 804 }
805 optopt = c;
806 return '?';
807 }
798 /* Convenience. Treat POSIX -W foo same as long option --foo */ 808 /* Convenience. Treat POSIX -W foo same as long option --foo */
799 if (temp[0] == 'W' && temp[1] == ';') 809 if ((temp[0] == 'W') && (temp[1] == ';'))
810 {
811 char *nameend;
812 const struct option *p;
813 const struct option *pfound = NULL;
814 int exact = 0;
815 int ambig = 0;
816 int indfound = 0;
817 int option_index;
818
819 /* This is an option that requires an argument. */
820 if (*nextchar != '\0')
821 {
822 optarg = nextchar;
823 /* If we end this ARGV-element by taking the rest as an arg,
824 we must advance to the next element now. */
825 optind++;
826 }
827 else if (optind == argc)
828 {
829 if (opterr)
830 {
831 /* 1003.2 specifies the format of this message. */
832 fprintf (stderr, _ ("%s: option requires an argument -- %c\n"),
833 argv[0], c);
834 }
835 optopt = c;
836 if (optstring[0] == ':')
837 c = ':';
838 else
839 c = '?';
840 return c;
841 }
842 else
843 /* We already incremented `optind' once;
844 increment it again when taking next ARGV-elt as argument. */
845 optarg = argv[optind++];
846
847 /* optarg is now the argument, see if it's in the
848 table of longopts. */
849
850 for (nextchar = nameend = optarg; *nameend && *nameend != '=';
851 nameend++)
852 /* Do nothing. */;
853
854 /* Test all long options for either exact match
855 or abbreviated matches. */
856 for (p = longopts, option_index = 0; p->name; p++, option_index++)
857 if (! strncmp (p->name, nextchar, nameend - nextchar))
858 {
859 if ((unsigned int) (nameend - nextchar) == strlen (p->name))
860 {
861 /* Exact match found. */
862 pfound = p;
863 indfound = option_index;
864 exact = 1;
865 break;
866 }
867 else if (pfound == NULL)
868 {
869 /* First nonexact match found. */
870 pfound = p;
871 indfound = option_index;
872 }
873 else
874 /* Second or later nonexact match found. */
875 ambig = 1;
876 }
877 if (ambig && ! exact)
878 {
879 if (opterr)
880 fprintf (stderr, _ ("%s: option `-W %s' is ambiguous\n"),
881 argv[0], argv[optind]);
882 nextchar += strlen (nextchar);
883 optind++;
884 return '?';
885 }
886 if (pfound != NULL)
800 { 887 {
801 char *nameend; 888 option_index = indfound;
802 const struct option *p; 889 if (*nameend)
803 const struct option *pfound = NULL; 890 {
804 int exact = 0; 891 /* Don't test has_arg with >, because some C compilers don't
805 int ambig = 0; 892 allow it to be used on enums. */
806 int indfound = 0; 893 if (pfound->has_arg)
807 int option_index; 894 optarg = nameend + 1;
808 895 else
809 /* This is an option that requires an argument. */ 896 {
810 if (*nextchar != '\0') 897 if (opterr)
811 { 898 fprintf (stderr, _ (
812 optarg = nextchar; 899 "\
813 /* If we end this ARGV-element by taking the rest as an arg,
814 we must advance to the next element now. */
815 optind++;
816 }
817 else if (optind == argc)
818 {
819 if (opterr)
820 {
821 /* 1003.2 specifies the format of this message. */
822 fprintf (stderr, _("%s: option requires an argument -- %c\n"),
823 argv[0], c);
824 }
825 optopt = c;
826 if (optstring[0] == ':')
827 c = ':';
828 else
829 c = '?';
830 return c;
831 }
832 else
833 /* We already incremented `optind' once;
834 increment it again when taking next ARGV-elt as argument. */
835 optarg = argv[optind++];
836
837 /* optarg is now the argument, see if it's in the
838 table of longopts. */
839
840 for (nextchar = nameend = optarg; *nameend && *nameend != '=';
841 nameend++)
842 /* Do nothing. */ ;
843
844 /* Test all long options for either exact match
845 or abbreviated matches. */
846 for (p = longopts, option_index = 0; p->name; p++, option_index++)
847 if (!strncmp (p->name, nextchar, nameend - nextchar))
848 {
849 if ((unsigned int) (nameend - nextchar) == strlen (p->name))
850 {
851 /* Exact match found. */
852 pfound = p;
853 indfound = option_index;
854 exact = 1;
855 break;
856 }
857 else if (pfound == NULL)
858 {
859 /* First nonexact match found. */
860 pfound = p;
861 indfound = option_index;
862 }
863 else
864 /* Second or later nonexact match found. */
865 ambig = 1;
866 }
867 if (ambig && !exact)
868 {
869 if (opterr)
870 fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
871 argv[0], argv[optind]);
872 nextchar += strlen (nextchar);
873 optind++;
874 return '?';
875 }
876 if (pfound != NULL)
877 {
878 option_index = indfound;
879 if (*nameend)
880 {
881 /* Don't test has_arg with >, because some C compilers don't
882 allow it to be used on enums. */
883 if (pfound->has_arg)
884 optarg = nameend + 1;
885 else
886 {
887 if (opterr)
888 fprintf (stderr, _("\
889%s: option `-W %s' doesn't allow an argument\n"), argv[0], pfound->name); 900%s: option `-W %s' doesn't allow an argument\n"), argv[0], pfound->name);
890 901
891 nextchar += strlen (nextchar); 902 nextchar += strlen (nextchar);
892 return '?'; 903 return '?';
893 } 904 }
894 } 905 }
895 else if (pfound->has_arg == 1) 906 else if (pfound->has_arg == 1)
896 { 907 {
897 if (optind < argc) 908 if (optind < argc)
898 optarg = argv[optind++]; 909 optarg = argv[optind++];
899 else 910 else
900 { 911 {
901 if (opterr) 912 if (opterr)
902 fprintf (stderr, 913 fprintf (stderr,
903 _("%s: option `%s' requires an argument\n"), 914 _ ("%s: option `%s' requires an argument\n"),
904 argv[0], argv[optind - 1]); 915 argv[0], argv[optind - 1]);
905 nextchar += strlen (nextchar); 916 nextchar += strlen (nextchar);
906 return optstring[0] == ':' ? ':' : '?'; 917 return optstring[0] == ':' ? ':' : '?';
907 } 918 }
908 } 919 }
909 nextchar += strlen (nextchar); 920 nextchar += strlen (nextchar);
910 if (longind != NULL) 921 if (longind != NULL)
911 *longind = option_index; 922 *longind = option_index;
912 if (pfound->flag) 923 if (pfound->flag)
913 { 924 {
914 *(pfound->flag) = pfound->val; 925 *(pfound->flag) = pfound->val;
915 return 0; 926 return 0;
916 } 927 }
917 return pfound->val; 928 return pfound->val;
918 }
919 nextchar = NULL;
920 return 'W'; /* Let the application handle it. */
921 } 929 }
930 nextchar = NULL;
931 return 'W'; /* Let the application handle it. */
932 }
922 if (temp[1] == ':') 933 if (temp[1] == ':')
934 {
935 if (temp[2] == ':')
936 {
937 /* This is an option that accepts an argument optionally. */
938 if (*nextchar != '\0')
939 {
940 optarg = nextchar;
941 optind++;
942 }
943 else
944 optarg = NULL;
945 nextchar = NULL;
946 }
947 else
923 { 948 {
924 if (temp[2] == ':') 949 /* This is an option that requires an argument. */
925 { 950 if (*nextchar != '\0')
926 /* This is an option that accepts an argument optionally. */ 951 {
927 if (*nextchar != '\0') 952 optarg = nextchar;
928 { 953 /* If we end this ARGV-element by taking the rest as an arg,
929 optarg = nextchar; 954 we must advance to the next element now. */
930 optind++; 955 optind++;
931 } 956 }
932 else 957 else if (optind == argc)
933 optarg = NULL; 958 {
934 nextchar = NULL; 959 if (opterr)
935 } 960 {
936 else 961 /* 1003.2 specifies the format of this message. */
937 { 962 fprintf (stderr,
938 /* This is an option that requires an argument. */ 963 _ ("%s: option requires an argument -- %c\n"),
939 if (*nextchar != '\0') 964 argv[0], c);
940 { 965 }
941 optarg = nextchar; 966 optopt = c;
942 /* If we end this ARGV-element by taking the rest as an arg, 967 if (optstring[0] == ':')
943 we must advance to the next element now. */ 968 c = ':';
944 optind++; 969 else
945 } 970 c = '?';
946 else if (optind == argc) 971 }
947 { 972 else
948 if (opterr) 973 /* We already incremented `optind' once;
949 { 974 increment it again when taking next ARGV-elt as argument. */
950 /* 1003.2 specifies the format of this message. */ 975 optarg = argv[optind++];
951 fprintf (stderr, 976 nextchar = NULL;
952 _("%s: option requires an argument -- %c\n"),
953 argv[0], c);
954 }
955 optopt = c;
956 if (optstring[0] == ':')
957 c = ':';
958 else
959 c = '?';
960 }
961 else
962 /* We already incremented `optind' once;
963 increment it again when taking next ARGV-elt as argument. */
964 optarg = argv[optind++];
965 nextchar = NULL;
966 }
967 } 977 }
978 }
968 return c; 979 return c;
969 } 980 }
970} 981}
971 982
972int 983int
973getopt (argc, argv, optstring) 984getopt (argc, argv, optstring)
974 int argc; 985int argc;
975 char *const *argv; 986
976 const char *optstring; 987char *const *argv;
988const char *optstring;
977{ 989{
978 return _getopt_internal (argc, argv, optstring, 990 return _getopt_internal (argc, argv, optstring,
979 (const struct option *) 0, (int *) 0, 0); 991 (const struct option *) 0, (int *) 0, 0);
980} 992}
981 993
982#endif /* Not ELIDE_CODE. */ 994#endif /* Not ELIDE_CODE. */
983 995
984#ifdef TEST 996#ifdef TEST
985 997
986/* Compile with -DTEST to make an executable for use in testing 998/* Compile with -DTEST to make an executable for use in testing
@@ -988,65 +1000,66 @@ getopt (argc, argv, optstring)
988 1000
989int 1001int
990main (argc, argv) 1002main (argc, argv)
991 int argc; 1003int argc;
992 char **argv; 1004
1005char **argv;
993{ 1006{
994 int c; 1007 int c;
995 int digit_optind = 0; 1008 int digit_optind = 0;
996 1009
997 while (1) 1010 while (1)
1011 {
1012 int this_option_optind = optind ? optind : 1;
1013
1014 c = getopt (argc, argv, "abc:d:0123456789");
1015 if (c == -1)
1016 break;
1017
1018 switch (c)
998 { 1019 {
999 int this_option_optind = optind ? optind : 1; 1020 case '0':
1000 1021 case '1':
1001 c = getopt (argc, argv, "abc:d:0123456789"); 1022 case '2':
1002 if (c == -1) 1023 case '3':
1003 break; 1024 case '4':
1004 1025 case '5':
1005 switch (c) 1026 case '6':
1006 { 1027 case '7':
1007 case '0': 1028 case '8':
1008 case '1': 1029 case '9':
1009 case '2': 1030 if ((digit_optind != 0) && (digit_optind != this_option_optind) )
1010 case '3': 1031 printf ("digits occur in two different argv-elements.\n");
1011 case '4': 1032 digit_optind = this_option_optind;
1012 case '5': 1033 printf ("option %c\n", c);
1013 case '6': 1034 break;
1014 case '7': 1035
1015 case '8': 1036 case 'a':
1016 case '9': 1037 printf ("option a\n");
1017 if (digit_optind != 0 && digit_optind != this_option_optind) 1038 break;
1018 printf ("digits occur in two different argv-elements.\n"); 1039
1019 digit_optind = this_option_optind; 1040 case 'b':
1020 printf ("option %c\n", c); 1041 printf ("option b\n");
1021 break; 1042 break;
1022 1043
1023 case 'a': 1044 case 'c':
1024 printf ("option a\n"); 1045 printf ("option c with value `%s'\n", optarg);
1025 break; 1046 break;
1026 1047
1027 case 'b': 1048 case '?':
1028 printf ("option b\n"); 1049 break;
1029 break; 1050
1030 1051 default:
1031 case 'c': 1052 printf ("?? getopt returned character code 0%o ??\n", c);
1032 printf ("option c with value `%s'\n", optarg);
1033 break;
1034
1035 case '?':
1036 break;
1037
1038 default:
1039 printf ("?? getopt returned character code 0%o ??\n", c);
1040 }
1041 } 1053 }
1054 }
1042 1055
1043 if (optind < argc) 1056 if (optind < argc)
1044 { 1057 {
1045 printf ("non-option ARGV-elements: "); 1058 printf ("non-option ARGV-elements: ");
1046 while (optind < argc) 1059 while (optind < argc)
1047 printf ("%s ", argv[optind++]); 1060 printf ("%s ", argv[optind++]);
1048 printf ("\n"); 1061 printf ("\n");
1049 } 1062 }
1050 1063
1051 exit (0); 1064 exit (0);
1052} 1065}
diff --git a/src/main/getopt.h b/src/main/getopt.h
index d50c90e..89fd8eb 100644
--- a/src/main/getopt.h
+++ b/src/main/getopt.h
@@ -24,7 +24,7 @@ USA. */
24 24
25#include "config.h" 25#include "config.h"
26 26
27#ifdef __cplusplus 27#ifdef __cplusplus
28extern "C" { 28extern "C" {
29#endif 29#endif
30 30
@@ -67,7 +67,7 @@ extern int optopt;
67 The field `has_arg' is: 67 The field `has_arg' is:
68 no_argument (or 0) if the option does not take an argument, 68 no_argument (or 0) if the option does not take an argument,
69 required_argument (or 1) if the option requires an argument, 69 required_argument (or 1) if the option requires an argument,
70 optional_argument (or 2) if the option takes an optional argument. 70 optional_argument (or 2) if the option takes an optional argument.
71 71
72 If the field `flag' is not NULL, it points to a variable that is set 72 If the field `flag' is not NULL, it points to a variable that is set
73 to the value given in the field `val' when the option is found, but 73 to the value given in the field `val' when the option is found, but
@@ -96,9 +96,9 @@ struct option
96 96
97/* Names for the values of the `has_arg' field of `struct option'. */ 97/* Names for the values of the `has_arg' field of `struct option'. */
98 98
99#define no_argument 0 99#define no_argument 0
100#define required_argument 1 100#define required_argument 1
101#define optional_argument 2 101#define optional_argument 2
102 102
103#if defined (__STDC__) && __STDC__ 103#if defined (__STDC__) && __STDC__
104#ifdef __GNU_LIBRARY__ 104#ifdef __GNU_LIBRARY__
@@ -106,29 +106,36 @@ struct option
106 differences in the consts, in stdlib.h. To avoid compilation 106 differences in the consts, in stdlib.h. To avoid compilation
107 errors, only prototype getopt for the GNU C library. */ 107 errors, only prototype getopt for the GNU C library. */
108extern int getopt (int argc, char *const *argv, const char *shortopts); 108extern int getopt (int argc, char *const *argv, const char *shortopts);
109
109#else /* not __GNU_LIBRARY__ */ 110#else /* not __GNU_LIBRARY__ */
110extern int getopt (); 111extern int getopt ();
112
111#endif /* __GNU_LIBRARY__ */ 113#endif /* __GNU_LIBRARY__ */
112extern int getopt_long (int argc, char *const *argv, const char *shortopts, 114extern int getopt_long (int argc, char *const *argv, const char *shortopts,
113 const struct option *longopts, int *longind); 115 const struct option *longopts, int *longind);
116
114extern int getopt_long_only (int argc, char *const *argv, 117extern int getopt_long_only (int argc, char *const *argv,
115 const char *shortopts, 118 const char *shortopts,
116 const struct option *longopts, int *longind); 119 const struct option *longopts, int *longind);
117 120
118/* Internal only. Users should not call this directly. */ 121/* Internal only. Users should not call this directly. */
119extern int _getopt_internal (int argc, char *const *argv, 122extern int _getopt_internal (int argc, char *const *argv,
120 const char *shortopts, 123 const char *shortopts,
121 const struct option *longopts, int *longind, 124 const struct option *longopts, int *longind,
122 int long_only); 125 int long_only);
126
123#else /* not __STDC__ */ 127#else /* not __STDC__ */
124extern int getopt (); 128extern int getopt ();
129
125extern int getopt_long (); 130extern int getopt_long ();
131
126extern int getopt_long_only (); 132extern int getopt_long_only ();
127 133
128extern int _getopt_internal (); 134extern int _getopt_internal ();
135
129#endif /* __STDC__ */ 136#endif /* __STDC__ */
130 137
131#ifdef __cplusplus 138#ifdef __cplusplus
132} 139}
133#endif 140#endif
134 141
diff --git a/src/main/getopt1.c b/src/main/getopt1.c
index 6409986..d089fd4 100644
--- a/src/main/getopt1.c
+++ b/src/main/getopt1.c
@@ -21,7 +21,7 @@ USA. */
21#include "config.h" 21#include "config.h"
22#include "getopt.h" 22#include "getopt.h"
23 23
24#if !defined (__STDC__) || !__STDC__ 24#if ! defined (__STDC__) || ! __STDC__
25/* This is a separate conditional since some stdc systems 25/* This is a separate conditional since some stdc systems
26 reject `defined (const)'. */ 26 reject `defined (const)'. */
27#ifndef const 27#ifndef const
@@ -40,7 +40,7 @@ USA. */
40 it is simpler to just do this in the source for each such file. */ 40 it is simpler to just do this in the source for each such file. */
41 41
42#define GETOPT_INTERFACE_VERSION 2 42#define GETOPT_INTERFACE_VERSION 2
43#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2 43#if ! defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2
44#include <gnu-versions.h> 44#include <gnu-versions.h>
45#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION 45#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
46#define ELIDE_CODE 46#define ELIDE_CODE
@@ -56,17 +56,18 @@ USA. */
56#include <stdlib.h> 56#include <stdlib.h>
57#endif 57#endif
58 58
59#ifndef NULL 59#ifndef NULL
60#define NULL 0 60#define NULL 0
61#endif 61#endif
62 62
63int 63int
64getopt_long (argc, argv, options, long_options, opt_index) 64getopt_long (argc, argv, options, long_options, opt_index)
65 int argc; 65int argc;
66 char *const *argv; 66
67 const char *options; 67char *const *argv;
68 const struct option *long_options; 68const char *options;
69 int *opt_index; 69const struct option *long_options;
70int *opt_index;
70{ 71{
71 return _getopt_internal (argc, argv, options, long_options, opt_index, 0); 72 return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
72} 73}
@@ -78,105 +79,107 @@ getopt_long (argc, argv, options, long_options, opt_index)
78 79
79int 80int
80getopt_long_only (argc, argv, options, long_options, opt_index) 81getopt_long_only (argc, argv, options, long_options, opt_index)
81 int argc; 82int argc;
82 char *const *argv; 83
83 const char *options; 84char *const *argv;
84 const struct option *long_options; 85const char *options;
85 int *opt_index; 86const struct option *long_options;
87int *opt_index;
86{ 88{
87 return _getopt_internal (argc, argv, options, long_options, opt_index, 1); 89 return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
88} 90}
89 91
90 92
91#endif /* Not ELIDE_CODE. */ 93#endif /* Not ELIDE_CODE. */
92 94
93#ifdef TEST 95#ifdef TEST
94 96
95#include <stdio.h> 97#include <stdio.h>
96 98
97int 99int
98main (argc, argv) 100main (argc, argv)
99 int argc; 101int argc;
100 char **argv; 102
103char **argv;
101{ 104{
102 int c; 105 int c;
103 int digit_optind = 0; 106 int digit_optind = 0;
104 107
105 while (1) 108 while (1)
109 {
110 int this_option_optind = optind ? optind : 1;
111 int option_index = 0;
112 static struct option long_options[] = {
113 {"add", 1, 0, 0},
114 {"append", 0, 0, 0},
115 {"delete", 1, 0, 0},
116 {"verbose", 0, 0, 0},
117 {"create", 0, 0, 0},
118 {"file", 1, 0, 0},
119 {0, 0, 0, 0}
120 };
121
122 c = getopt_long (argc, argv, "abc:d:0123456789",
123 long_options, &option_index);
124 if (c == -1)
125 break;
126
127 switch (c)
106 { 128 {
107 int this_option_optind = optind ? optind : 1; 129 case 0:
108 int option_index = 0; 130 printf ("option %s", long_options[option_index].name);
109 static struct option long_options[] = { 131 if (optarg)
110 {"add", 1, 0, 0}, 132 printf (" with arg %s", optarg);
111 {"append", 0, 0, 0}, 133 printf ("\n");
112 {"delete", 1, 0, 0}, 134 break;
113 {"verbose", 0, 0, 0}, 135
114 {"create", 0, 0, 0}, 136 case '0':
115 {"file", 1, 0, 0}, 137 case '1':
116 {0, 0, 0, 0} 138 case '2':
117 }; 139 case '3':
118 140 case '4':
119 c = getopt_long (argc, argv, "abc:d:0123456789", 141 case '5':
120 long_options, &option_index); 142 case '6':
121 if (c == -1) 143 case '7':
122 break; 144 case '8':
123 145 case '9':
124 switch (c) 146 if ((digit_optind != 0) && (digit_optind != this_option_optind) )
125 { 147 printf ("digits occur in two different argv-elements.\n");
126 case 0: 148 digit_optind = this_option_optind;
127 printf ("option %s", long_options[option_index].name); 149 printf ("option %c\n", c);
128 if (optarg) 150 break;
129 printf (" with arg %s", optarg); 151
130 printf ("\n"); 152 case 'a':
131 break; 153 printf ("option a\n");
132 154 break;
133 case '0': 155
134 case '1': 156 case 'b':
135 case '2': 157 printf ("option b\n");
136 case '3': 158 break;
137 case '4': 159
138 case '5': 160 case 'c':
139 case '6': 161 printf ("option c with value `%s'\n", optarg);
140 case '7': 162 break;
141 case '8': 163
142 case '9': 164 case 'd':
143 if (digit_optind != 0 && digit_optind != this_option_optind) 165 printf ("option d with value `%s'\n", optarg);
144 printf ("digits occur in two different argv-elements.\n"); 166 break;
145 digit_optind = this_option_optind; 167
146 printf ("option %c\n", c); 168 case '?':
147 break; 169 break;
148 170
149 case 'a': 171 default:
150 printf ("option a\n"); 172 printf ("?? getopt returned character code 0%o ??\n", c);
151 break;
152
153 case 'b':
154 printf ("option b\n");
155 break;
156
157 case 'c':
158 printf ("option c with value `%s'\n", optarg);
159 break;
160
161 case 'd':
162 printf ("option d with value `%s'\n", optarg);
163 break;
164
165 case '?':
166 break;
167
168 default:
169 printf ("?? getopt returned character code 0%o ??\n", c);
170 }
171 } 173 }
174 }
172 175
173 if (optind < argc) 176 if (optind < argc)
174 { 177 {
175 printf ("non-option ARGV-elements: "); 178 printf ("non-option ARGV-elements: ");
176 while (optind < argc) 179 while (optind < argc)
177 printf ("%s ", argv[optind++]); 180 printf ("%s ", argv[optind++]);
178 printf ("\n"); 181 printf ("\n");
179 } 182 }
180 183
181 exit (0); 184 exit (0);
182} 185}
diff --git a/src/main/iconv.c b/src/main/iconv.c
index 3f95d44..7daa017 100644
--- a/src/main/iconv.c
+++ b/src/main/iconv.c
@@ -33,10 +33,10 @@
33 * @param inSize number of bytes in 'in' 33 * @param inSize number of bytes in 'in'
34 * @return NULL on error, otherwise the converted string (to be free'd by caller) 34 * @return NULL on error, otherwise the converted string (to be free'd by caller)
35 */ 35 */
36static char * 36static char *
37iconv_helper (iconv_t cd, 37iconv_helper (iconv_t cd,
38 const char *in, 38 const char *in,
39 size_t inSize) 39 size_t inSize)
40{ 40{
41#if HAVE_ICONV 41#if HAVE_ICONV
42 char *buf; 42 char *buf;
@@ -57,24 +57,25 @@ iconv_helper (iconv_t cd,
57 ibuf = buf; 57 ibuf = buf;
58 memset (buf, 0, outSize); 58 memset (buf, 0, outSize);
59 if (iconv (cd, 59 if (iconv (cd,
60 (char**) &in, 60 (char**) &in,
61 &inSize, 61 &inSize,
62 &ibuf, 62 &ibuf,
63 &outLeft) == SIZE_MAX) 63 &outLeft) == SIZE_MAX)
64 { 64 {
65 /* conversion failed */ 65 /* conversion failed */
66 free (buf); 66 free (buf);
67 return strdup (i); 67 return strdup (i);
68 } 68 }
69 return buf; 69 return buf;
70#else 70#else
71 /* good luck, just copying string... */ 71 /* good luck, just copying string... */
72 char *buf; 72 char *buf;
73 73
74 buf = malloc (inSize + 1); 74 buf = malloc (inSize + 1);
75 memcpy (buf, in, inSize); 75 memcpy (buf, in, inSize);
76 buf[inSize] = '\0'; 76 buf[inSize] = '\0';
77#endif 77#endif
78} 78}
79 79
80
80/* end of iconv.c */ 81/* end of iconv.c */
diff --git a/src/main/test2_extractor.c b/src/main/test2_extractor.c
index 4d55dc3..a2c1d53 100644
--- a/src/main/test2_extractor.c
+++ b/src/main/test2_extractor.c
@@ -36,7 +36,6 @@
36#include <unistd.h> 36#include <unistd.h>
37#include <stdlib.h> 37#include <stdlib.h>
38 38
39
40 39
41/** 40/**
42 * Signature of the extract method that each plugin 41 * Signature of the extract method that each plugin
@@ -52,77 +51,78 @@ EXTRACTOR_test2_extract_method (struct EXTRACTOR_ExtractContext *ec)
52 if ((NULL == ec->config) || (0 != strcmp (ec->config, "test2"))) 51 if ((NULL == ec->config) || (0 != strcmp (ec->config, "test2")))
53 return; /* only run in test mode */ 52 return; /* only run in test mode */
54 if (4 != ec->read (ec->cls, &dp, 4)) 53 if (4 != ec->read (ec->cls, &dp, 4))
55 { 54 {
56 fprintf (stderr, "Reading at offset 0 failed\n"); 55 fprintf (stderr, "Reading at offset 0 failed\n");
57 ABORT (); 56 ABORT ();
58 } 57 }
59 if (0 != strncmp ("test", dp, 4)) 58 if (0 != strncmp ("test", dp, 4))
60 { 59 {
61 fprintf (stderr, "Unexpected data at offset 0\n"); 60 fprintf (stderr, "Unexpected data at offset 0\n");
62 ABORT (); 61 ABORT ();
63 } 62 }
64 if ( (1024 * 150 != ec->get_size (ec->cls)) && 63 if ( (1024 * 150 != ec->get_size (ec->cls)) &&
65 (UINT64_MAX != ec->get_size (ec->cls)) ) 64 (UINT64_MAX != ec->get_size (ec->cls)) )
66 { 65 {
67 fprintf (stderr, "Unexpected file size returned (expected 150k)\n"); 66 fprintf (stderr, "Unexpected file size returned (expected 150k)\n");
68 ABORT (); 67 ABORT ();
69 } 68 }
70 if (1024 * 100 + 4 != ec->seek (ec->cls, 1024 * 100 + 4, SEEK_SET)) 69 if (1024 * 100 + 4 != ec->seek (ec->cls, 1024 * 100 + 4, SEEK_SET))
71 { 70 {
72 fprintf (stderr, "Failure to seek (SEEK_SET)\n"); 71 fprintf (stderr, "Failure to seek (SEEK_SET)\n");
73 ABORT (); 72 ABORT ();
74 } 73 }
75 if (1 != ec->read (ec->cls, &dp, 1)) 74 if (1 != ec->read (ec->cls, &dp, 1))
76 { 75 {
77 fprintf (stderr, "Failure to read at 100k + 4\n"); 76 fprintf (stderr, "Failure to read at 100k + 4\n");
78 ABORT (); 77 ABORT ();
79 } 78 }
80 if ((1024 * 100 + 4) % 256 != * (unsigned char *) dp) 79 if ((1024 * 100 + 4) % 256 != *(unsigned char *) dp)
81 { 80 {
82 fprintf (stderr, "Unexpected data at offset 100k + 4\n"); 81 fprintf (stderr, "Unexpected data at offset 100k + 4\n");
83 ABORT (); 82 ABORT ();
84 } 83 }
85 if (((1024 * 100 + 4) + 1 - (1024 * 50 + 7)) != 84 if (((1024 * 100 + 4) + 1 - (1024 * 50 + 7)) !=
86 ec->seek (ec->cls, - (1024 * 50 + 7), SEEK_CUR)) 85 ec->seek (ec->cls, -(1024 * 50 + 7), SEEK_CUR))
87 { 86 {
88 fprintf (stderr, "Failure to seek (SEEK_SET)\n"); 87 fprintf (stderr, "Failure to seek (SEEK_SET)\n");
89 ABORT (); 88 ABORT ();
90 } 89 }
91 if (1 != ec->read (ec->cls, &dp, 1)) 90 if (1 != ec->read (ec->cls, &dp, 1))
92 { 91 {
93 fprintf (stderr, "Failure to read at 50k - 3\n"); 92 fprintf (stderr, "Failure to read at 50k - 3\n");
94 ABORT (); 93 ABORT ();
95 } 94 }
96 if (((1024 * 100 + 4) + 1 - (1024 * 50 + 7)) % 256 != * (unsigned char *) dp) 95 if (((1024 * 100 + 4) + 1 - (1024 * 50 + 7)) % 256 != *(unsigned char *) dp)
97 { 96 {
98 fprintf (stderr, "Unexpected data at offset 100k - 3\n"); 97 fprintf (stderr, "Unexpected data at offset 100k - 3\n");
99 ABORT (); 98 ABORT ();
100 } 99 }
101 if (1024 * 150 != ec->seek (ec->cls, 0, SEEK_END)) 100 if (1024 * 150 != ec->seek (ec->cls, 0, SEEK_END))
102 { 101 {
103 fprintf (stderr, "Failure to seek (SEEK_END)\n"); 102 fprintf (stderr, "Failure to seek (SEEK_END)\n");
104 ABORT (); 103 ABORT ();
105 } 104 }
106 if (0 != ec->read (ec->cls, &dp, 1)) 105 if (0 != ec->read (ec->cls, &dp, 1))
107 { 106 {
108 fprintf (stderr, "Failed to receive EOF at 150k\n"); 107 fprintf (stderr, "Failed to receive EOF at 150k\n");
109 ABORT (); 108 ABORT ();
110 } 109 }
111 if (1024 * 150 - 2 != ec->seek (ec->cls, -2, SEEK_END)) 110 if (1024 * 150 - 2 != ec->seek (ec->cls, -2, SEEK_END))
112 { 111 {
113 fprintf (stderr, "Failure to seek (SEEK_END - 2)\n"); 112 fprintf (stderr, "Failure to seek (SEEK_END - 2)\n");
114 ABORT (); 113 ABORT ();
115 } 114 }
116 if (1 != ec->read (ec->cls, &dp, 1)) 115 if (1 != ec->read (ec->cls, &dp, 1))
117 { 116 {
118 fprintf (stderr, "Failure to read at 150k - 3\n"); 117 fprintf (stderr, "Failure to read at 150k - 3\n");
119 ABORT (); 118 ABORT ();
120 } 119 }
121 if ((1024 * 150 - 2) % 256 != * (unsigned char *) dp) 120 if ((1024 * 150 - 2) % 256 != *(unsigned char *) dp)
122 { 121 {
123 fprintf (stderr, "Unexpected data at offset 150k - 3\n"); 122 fprintf (stderr, "Unexpected data at offset 150k - 3\n");
124 ABORT (); 123 ABORT ();
125 } 124 }
126} 125}
127 126
127
128/* end of test2_extractor.c */ 128/* end of test2_extractor.c */
diff --git a/src/main/test_bzip2.c b/src/main/test_bzip2.c
index 37c9aed..598e913 100644
--- a/src/main/test_bzip2.c
+++ b/src/main/test_bzip2.c
@@ -46,74 +46,74 @@ static int ret = 2;
46 * @param data hello world or good bye 46 * @param data hello world or good bye
47 * @param data_len number of bytes in data 47 * @param data_len number of bytes in data
48 * @return 0 on hello world, 1 on goodbye 48 * @return 0 on hello world, 1 on goodbye
49 */ 49 */
50static int 50static int
51process_replies (void *cls, 51process_replies (void *cls,
52 const char *plugin_name, 52 const char *plugin_name,
53 enum EXTRACTOR_MetaType type, 53 enum EXTRACTOR_MetaType type,
54 enum EXTRACTOR_MetaFormat format, 54 enum EXTRACTOR_MetaFormat format,
55 const char *data_mime_type, 55 const char *data_mime_type,
56 const char *data, 56 const char *data,
57 size_t data_len) 57 size_t data_len)
58{ 58{
59 if (0 != strcmp (cls, 59 if (0 != strcmp (cls,
60 "main-cls")) 60 "main-cls"))
61 { 61 {
62 fprintf (stderr, "closure invalid\n"); 62 fprintf (stderr, "closure invalid\n");
63 ret = 3; 63 ret = 3;
64 return 1; 64 return 1;
65 } 65 }
66 if (0 != strcmp (plugin_name, 66 if (0 != strcmp (plugin_name,
67 "test")) 67 "test"))
68 { 68 {
69 fprintf (stderr, "plugin name invalid\n"); 69 fprintf (stderr, "plugin name invalid\n");
70 ret = 4; 70 ret = 4;
71 return 1; 71 return 1;
72 } 72 }
73 if (EXTRACTOR_METATYPE_COMMENT != type) 73 if (EXTRACTOR_METATYPE_COMMENT != type)
74 { 74 {
75 fprintf (stderr, "type invalid\n"); 75 fprintf (stderr, "type invalid\n");
76 ret = 5; 76 ret = 5;
77 return 1; 77 return 1;
78 } 78 }
79 if (EXTRACTOR_METAFORMAT_UTF8 != format) 79 if (EXTRACTOR_METAFORMAT_UTF8 != format)
80 { 80 {
81 fprintf (stderr, "format invalid\n"); 81 fprintf (stderr, "format invalid\n");
82 ret = 6; 82 ret = 6;
83 return 1; 83 return 1;
84 } 84 }
85 if ( (NULL == data_mime_type) || 85 if ( (NULL == data_mime_type) ||
86 (0 != strcmp ("<no mime>", 86 (0 != strcmp ("<no mime>",
87 data_mime_type) ) ) 87 data_mime_type) ) )
88 { 88 {
89 fprintf (stderr, "bad mime type\n"); 89 fprintf (stderr, "bad mime type\n");
90 ret = 7; 90 ret = 7;
91 return 1; 91 return 1;
92 } 92 }
93 if ( (2 == ret) && 93 if ( (2 == ret) &&
94 (data_len == strlen (HLO) + 1) && 94 (data_len == strlen (HLO) + 1) &&
95 (0 == strncmp (data, 95 (0 == strncmp (data,
96 HLO, 96 HLO,
97 strlen (HLO))) ) 97 strlen (HLO))) )
98 { 98 {
99#if 0 99#if 0
100 fprintf (stderr, "Received '%s'\n", HLO); 100 fprintf (stderr, "Received '%s'\n", HLO);
101#endif 101#endif
102 ret = 1; 102 ret = 1;
103 return 0; 103 return 0;
104 } 104 }
105 if ( (1 == ret) && 105 if ( (1 == ret) &&
106 (data_len == strlen (GOB) + 1) && 106 (data_len == strlen (GOB) + 1) &&
107 (0 == strncmp (data, 107 (0 == strncmp (data,
108 GOB, 108 GOB,
109 strlen (GOB))) ) 109 strlen (GOB))) )
110 { 110 {
111#if 0 111#if 0
112 fprintf (stderr, "Received '%s'\n", GOB); 112 fprintf (stderr, "Received '%s'\n", GOB);
113#endif 113#endif
114 ret = 0; 114 ret = 0;
115 return 1; 115 return 1;
116 } 116 }
117 fprintf (stderr, "Invalid meta data\n"); 117 fprintf (stderr, "Invalid meta data\n");
118 ret = 8; 118 ret = 8;
119 return 1; 119 return 1;
@@ -132,23 +132,25 @@ main (int argc, char *argv[])
132{ 132{
133 struct EXTRACTOR_PluginList *pl; 133 struct EXTRACTOR_PluginList *pl;
134 134
135 /* change environment to find 'extractor_test' plugin which is 135 /* change environment to find 'extractor_test' plugin which is
136 not installed but should be in the current directory (or .libs) 136 not installed but should be in the current directory (or .libs)
137 on 'make check' */ 137 on 'make check' */
138 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) 138 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/"))
139 fprintf (stderr, 139 fprintf (stderr,
140 "Failed to update my environment, plugin loading may fail: %s\n", 140 "Failed to update my environment, plugin loading may fail: %s\n",
141 strerror (errno)); 141 strerror (errno));
142 pl = EXTRACTOR_plugin_add_config (NULL, "test(test)", 142 pl = EXTRACTOR_plugin_add_config (NULL, "test(test)",
143 EXTRACTOR_OPTION_DEFAULT_POLICY); 143 EXTRACTOR_OPTION_DEFAULT_POLICY);
144 if (NULL == pl) 144 if (NULL == pl)
145 { 145 {
146 fprintf (stderr, "failed to load test plugin\n"); 146 fprintf (stderr, "failed to load test plugin\n");
147 return 1; 147 return 1;
148 } 148 }
149 EXTRACTOR_extract (pl, "test_file.dat.bz2", NULL, 0, &process_replies, "main-cls"); 149 EXTRACTOR_extract (pl, "test_file.dat.bz2", NULL, 0, &process_replies,
150 "main-cls");
150 EXTRACTOR_plugin_remove_all (pl); 151 EXTRACTOR_plugin_remove_all (pl);
151 return ret; 152 return ret;
152} 153}
153 154
155
154/* end of test_bzip2.c */ 156/* end of test_bzip2.c */
diff --git a/src/main/test_extractor.c b/src/main/test_extractor.c
index 8c15fca..dd1376f 100644
--- a/src/main/test_extractor.c
+++ b/src/main/test_extractor.c
@@ -37,7 +37,6 @@
37#include <stdlib.h> 37#include <stdlib.h>
38 38
39 39
40
41/** 40/**
42 * Signature of the extract method that each plugin 41 * Signature of the extract method that each plugin
43 * must provide. 42 * must provide.
@@ -52,94 +51,95 @@ EXTRACTOR_test_extract_method (struct EXTRACTOR_ExtractContext *ec)
52 if ((NULL == ec->config) || (0 != strcmp (ec->config, "test"))) 51 if ((NULL == ec->config) || (0 != strcmp (ec->config, "test")))
53 return; /* only run in test mode */ 52 return; /* only run in test mode */
54 if (4 != ec->read (ec->cls, &dp, 4)) 53 if (4 != ec->read (ec->cls, &dp, 4))
55 { 54 {
56 fprintf (stderr, "Reading at offset 0 failed\n"); 55 fprintf (stderr, "Reading at offset 0 failed\n");
57 ABORT (); 56 ABORT ();
58 } 57 }
59 if (0 != strncmp ("test", dp, 4)) 58 if (0 != strncmp ("test", dp, 4))
60 { 59 {
61 fprintf (stderr, "Unexpected data at offset 0\n"); 60 fprintf (stderr, "Unexpected data at offset 0\n");
62 ABORT (); 61 ABORT ();
63 } 62 }
64 if ( (1024 * 150 != ec->get_size (ec->cls)) && 63 if ( (1024 * 150 != ec->get_size (ec->cls)) &&
65 (UINT64_MAX != ec->get_size (ec->cls)) ) 64 (UINT64_MAX != ec->get_size (ec->cls)) )
66 { 65 {
67 fprintf (stderr, "Unexpected file size returned (expected 150k)\n"); 66 fprintf (stderr, "Unexpected file size returned (expected 150k)\n");
68 ABORT (); 67 ABORT ();
69 } 68 }
70 if (1024 * 100 + 4 != ec->seek (ec->cls, 1024 * 100 + 4, SEEK_SET)) 69 if (1024 * 100 + 4 != ec->seek (ec->cls, 1024 * 100 + 4, SEEK_SET))
71 { 70 {
72 fprintf (stderr, "Failure to seek (SEEK_SET)\n"); 71 fprintf (stderr, "Failure to seek (SEEK_SET)\n");
73 ABORT (); 72 ABORT ();
74 } 73 }
75 if (1 != ec->read (ec->cls, &dp, 1)) 74 if (1 != ec->read (ec->cls, &dp, 1))
76 { 75 {
77 fprintf (stderr, "Failure to read at 100k + 4\n"); 76 fprintf (stderr, "Failure to read at 100k + 4\n");
78 ABORT (); 77 ABORT ();
79 } 78 }
80 if ((1024 * 100 + 4) % 256 != * (unsigned char *) dp) 79 if ((1024 * 100 + 4) % 256 != *(unsigned char *) dp)
81 { 80 {
82 fprintf (stderr, "Unexpected data at offset 100k + 4\n"); 81 fprintf (stderr, "Unexpected data at offset 100k + 4\n");
83 ABORT (); 82 ABORT ();
84 } 83 }
85 if (((1024 * 100 + 4) + 1 - (1024 * 50 + 7)) != 84 if (((1024 * 100 + 4) + 1 - (1024 * 50 + 7)) !=
86 ec->seek (ec->cls, - (1024 * 50 + 7), SEEK_CUR)) 85 ec->seek (ec->cls, -(1024 * 50 + 7), SEEK_CUR))
87 { 86 {
88 fprintf (stderr, "Failure to seek (SEEK_SET)\n"); 87 fprintf (stderr, "Failure to seek (SEEK_SET)\n");
89 ABORT (); 88 ABORT ();
90 } 89 }
91 if (1 != ec->read (ec->cls, &dp, 1)) 90 if (1 != ec->read (ec->cls, &dp, 1))
92 { 91 {
93 fprintf (stderr, "Failure to read at 50k - 3\n"); 92 fprintf (stderr, "Failure to read at 50k - 3\n");
94 ABORT (); 93 ABORT ();
95 } 94 }
96 if (((1024 * 100 + 4) + 1 - (1024 * 50 + 7)) % 256 != * (unsigned char *) dp) 95 if (((1024 * 100 + 4) + 1 - (1024 * 50 + 7)) % 256 != *(unsigned char *) dp)
97 { 96 {
98 fprintf (stderr, "Unexpected data at offset 100k - 3\n"); 97 fprintf (stderr, "Unexpected data at offset 100k - 3\n");
99 ABORT (); 98 ABORT ();
100 } 99 }
101 if (1024 * 150 != ec->seek (ec->cls, 0, SEEK_END)) 100 if (1024 * 150 != ec->seek (ec->cls, 0, SEEK_END))
102 { 101 {
103 fprintf (stderr, "Failure to seek (SEEK_END)\n"); 102 fprintf (stderr, "Failure to seek (SEEK_END)\n");
104 ABORT (); 103 ABORT ();
105 } 104 }
106 if (0 != ec->read (ec->cls, &dp, 1)) 105 if (0 != ec->read (ec->cls, &dp, 1))
107 { 106 {
108 fprintf (stderr, "Failed to receive EOF at 150k\n"); 107 fprintf (stderr, "Failed to receive EOF at 150k\n");
109 ABORT (); 108 ABORT ();
110 } 109 }
111 if (1024 * 150 - 2 != ec->seek (ec->cls, -2, SEEK_END)) 110 if (1024 * 150 - 2 != ec->seek (ec->cls, -2, SEEK_END))
112 { 111 {
113 fprintf (stderr, "Failure to seek (SEEK_END - 2)\n"); 112 fprintf (stderr, "Failure to seek (SEEK_END - 2)\n");
114 ABORT (); 113 ABORT ();
115 } 114 }
116 if (1 != ec->read (ec->cls, &dp, 1)) 115 if (1 != ec->read (ec->cls, &dp, 1))
117 { 116 {
118 fprintf (stderr, "Failure to read at 150k - 3\n"); 117 fprintf (stderr, "Failure to read at 150k - 3\n");
119 ABORT (); 118 ABORT ();
120 } 119 }
121 if ((1024 * 150 - 2) % 256 != * (unsigned char *) dp) 120 if ((1024 * 150 - 2) % 256 != *(unsigned char *) dp)
122 { 121 {
123 fprintf (stderr, "Unexpected data at offset 150k - 3\n"); 122 fprintf (stderr, "Unexpected data at offset 150k - 3\n");
124 ABORT (); 123 ABORT ();
125 } 124 }
126 if (0 != ec->proc (ec->cls, "test", EXTRACTOR_METATYPE_COMMENT, 125 if (0 != ec->proc (ec->cls, "test", EXTRACTOR_METATYPE_COMMENT,
127 EXTRACTOR_METAFORMAT_UTF8, "<no mime>", "Hello world!", 126 EXTRACTOR_METAFORMAT_UTF8, "<no mime>", "Hello world!",
128 strlen ("Hello world!") + 1)) 127 strlen ("Hello world!") + 1))
129 { 128 {
130 fprintf (stderr, "Unexpected return value from 'proc'\n"); 129 fprintf (stderr, "Unexpected return value from 'proc'\n");
131 ABORT (); 130 ABORT ();
132 } 131 }
133 /* The test assumes that client orders us to stop extraction 132 /* The test assumes that client orders us to stop extraction
134 * after seeing "Goodbye!". 133 * after seeing "Goodbye!".
135 */ 134 */
136 if (1 != ec->proc (ec->cls, "test", EXTRACTOR_METATYPE_COMMENT, 135 if (1 != ec->proc (ec->cls, "test", EXTRACTOR_METATYPE_COMMENT,
137 EXTRACTOR_METAFORMAT_UTF8, "<no mime>", "Goodbye!", 136 EXTRACTOR_METAFORMAT_UTF8, "<no mime>", "Goodbye!",
138 strlen ("Goodbye!") + 1)) 137 strlen ("Goodbye!") + 1))
139 { 138 {
140 fprintf (stderr, "Unexpected return value from 'proc'\n"); 139 fprintf (stderr, "Unexpected return value from 'proc'\n");
141 ABORT (); 140 ABORT ();
142 } 141 }
143} 142}
144 143
144
145/* end of test_extractor.c */ 145/* end of test_extractor.c */
diff --git a/src/main/test_file.c b/src/main/test_file.c
index 52803c9..a2d6a5e 100644
--- a/src/main/test_file.c
+++ b/src/main/test_file.c
@@ -46,74 +46,74 @@ static int ret = 2;
46 * @param data hello world or good bye 46 * @param data hello world or good bye
47 * @param data_len number of bytes in data 47 * @param data_len number of bytes in data
48 * @return 0 on hello world, 1 on goodbye 48 * @return 0 on hello world, 1 on goodbye
49 */ 49 */
50static int 50static int
51process_replies (void *cls, 51process_replies (void *cls,
52 const char *plugin_name, 52 const char *plugin_name,
53 enum EXTRACTOR_MetaType type, 53 enum EXTRACTOR_MetaType type,
54 enum EXTRACTOR_MetaFormat format, 54 enum EXTRACTOR_MetaFormat format,
55 const char *data_mime_type, 55 const char *data_mime_type,
56 const char *data, 56 const char *data,
57 size_t data_len) 57 size_t data_len)
58{ 58{
59 if (0 != strcmp (cls, 59 if (0 != strcmp (cls,
60 "main-cls")) 60 "main-cls"))
61 { 61 {
62 fprintf (stderr, "closure invalid\n"); 62 fprintf (stderr, "closure invalid\n");
63 ret = 3; 63 ret = 3;
64 return 1; 64 return 1;
65 } 65 }
66 if (0 != strcmp (plugin_name, 66 if (0 != strcmp (plugin_name,
67 "test")) 67 "test"))
68 { 68 {
69 fprintf (stderr, "plugin name invalid\n"); 69 fprintf (stderr, "plugin name invalid\n");
70 ret = 4; 70 ret = 4;
71 return 1; 71 return 1;
72 } 72 }
73 if (EXTRACTOR_METATYPE_COMMENT != type) 73 if (EXTRACTOR_METATYPE_COMMENT != type)
74 { 74 {
75 fprintf (stderr, "type invalid\n"); 75 fprintf (stderr, "type invalid\n");
76 ret = 5; 76 ret = 5;
77 return 1; 77 return 1;
78 } 78 }
79 if (EXTRACTOR_METAFORMAT_UTF8 != format) 79 if (EXTRACTOR_METAFORMAT_UTF8 != format)
80 { 80 {
81 fprintf (stderr, "format invalid\n"); 81 fprintf (stderr, "format invalid\n");
82 ret = 6; 82 ret = 6;
83 return 1; 83 return 1;
84 } 84 }
85 if ( (NULL == data_mime_type) || 85 if ( (NULL == data_mime_type) ||
86 (0 != strcmp ("<no mime>", 86 (0 != strcmp ("<no mime>",
87 data_mime_type) ) ) 87 data_mime_type) ) )
88 { 88 {
89 fprintf (stderr, "bad mime type\n"); 89 fprintf (stderr, "bad mime type\n");
90 ret = 7; 90 ret = 7;
91 return 1; 91 return 1;
92 } 92 }
93 if ( (2 == ret) && 93 if ( (2 == ret) &&
94 (data_len == strlen (HLO) + 1) && 94 (data_len == strlen (HLO) + 1) &&
95 (0 == strncmp (data, 95 (0 == strncmp (data,
96 HLO, 96 HLO,
97 strlen (HLO))) ) 97 strlen (HLO))) )
98 { 98 {
99#if 0 99#if 0
100 fprintf (stderr, "Received '%s'\n", HLO); 100 fprintf (stderr, "Received '%s'\n", HLO);
101#endif 101#endif
102 ret = 1; 102 ret = 1;
103 return 0; 103 return 0;
104 } 104 }
105 if ( (1 == ret) && 105 if ( (1 == ret) &&
106 (data_len == strlen (GOB) + 1) && 106 (data_len == strlen (GOB) + 1) &&
107 (0 == strncmp (data, 107 (0 == strncmp (data,
108 GOB, 108 GOB,
109 strlen (GOB))) ) 109 strlen (GOB))) )
110 { 110 {
111#if 0 111#if 0
112 fprintf (stderr, "Received '%s'\n", GOB); 112 fprintf (stderr, "Received '%s'\n", GOB);
113#endif 113#endif
114 ret = 0; 114 ret = 0;
115 return 1; 115 return 1;
116 } 116 }
117 fprintf (stderr, "Invalid meta data\n"); 117 fprintf (stderr, "Invalid meta data\n");
118 ret = 8; 118 ret = 8;
119 return 1; 119 return 1;
@@ -132,23 +132,25 @@ main (int argc, char *argv[])
132{ 132{
133 struct EXTRACTOR_PluginList *pl; 133 struct EXTRACTOR_PluginList *pl;
134 134
135 /* change environment to find 'extractor_test' plugin which is 135 /* change environment to find 'extractor_test' plugin which is
136 not installed but should be in the current directory (or .libs) 136 not installed but should be in the current directory (or .libs)
137 on 'make check' */ 137 on 'make check' */
138 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) 138 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/"))
139 fprintf (stderr, 139 fprintf (stderr,
140 "Failed to update my environment, plugin loading may fail: %s\n", 140 "Failed to update my environment, plugin loading may fail: %s\n",
141 strerror (errno)); 141 strerror (errno));
142 pl = EXTRACTOR_plugin_add_config (NULL, "test(test)", 142 pl = EXTRACTOR_plugin_add_config (NULL, "test(test)",
143 EXTRACTOR_OPTION_DEFAULT_POLICY); 143 EXTRACTOR_OPTION_DEFAULT_POLICY);
144 if (NULL == pl) 144 if (NULL == pl)
145 { 145 {
146 fprintf (stderr, "failed to load test plugin\n"); 146 fprintf (stderr, "failed to load test plugin\n");
147 return 1; 147 return 1;
148 } 148 }
149 EXTRACTOR_extract (pl, "test_file.dat", NULL, 0, &process_replies, "main-cls"); 149 EXTRACTOR_extract (pl, "test_file.dat", NULL, 0, &process_replies,
150 "main-cls");
150 EXTRACTOR_plugin_remove_all (pl); 151 EXTRACTOR_plugin_remove_all (pl);
151 return ret; 152 return ret;
152} 153}
153 154
155
154/* end of test_file.c */ 156/* end of test_file.c */
diff --git a/src/main/test_gzip.c b/src/main/test_gzip.c
index 87a61cb..071c74c 100644
--- a/src/main/test_gzip.c
+++ b/src/main/test_gzip.c
@@ -46,78 +46,78 @@ static int ret = 2;
46 * @param data hello world or good bye 46 * @param data hello world or good bye
47 * @param data_len number of bytes in data 47 * @param data_len number of bytes in data
48 * @return 0 on hello world, 1 on goodbye 48 * @return 0 on hello world, 1 on goodbye
49 */ 49 */
50static int 50static int
51process_replies (void *cls, 51process_replies (void *cls,
52 const char *plugin_name, 52 const char *plugin_name,
53 enum EXTRACTOR_MetaType type, 53 enum EXTRACTOR_MetaType type,
54 enum EXTRACTOR_MetaFormat format, 54 enum EXTRACTOR_MetaFormat format,
55 const char *data_mime_type, 55 const char *data_mime_type,
56 const char *data, 56 const char *data,
57 size_t data_len) 57 size_t data_len)
58{ 58{
59 if (0 != strcmp (cls, 59 if (0 != strcmp (cls,
60 "main-cls")) 60 "main-cls"))
61 { 61 {
62 fprintf (stderr, "closure invalid\n"); 62 fprintf (stderr, "closure invalid\n");
63 ret = 3; 63 ret = 3;
64 return 1; 64 return 1;
65 } 65 }
66 if (0 == strcmp (plugin_name, 66 if (0 == strcmp (plugin_name,
67 "<zlib>")) 67 "<zlib>"))
68 return 0; /* skip this one */ 68 return 0; /* skip this one */
69 if (0 != strcmp (plugin_name, 69 if (0 != strcmp (plugin_name,
70 "test")) 70 "test"))
71 { 71 {
72 fprintf (stderr, "plugin name invalid: `%s'\n", 72 fprintf (stderr, "plugin name invalid: `%s'\n",
73 plugin_name); 73 plugin_name);
74 ret = 4; 74 ret = 4;
75 return 1; 75 return 1;
76 } 76 }
77 if (EXTRACTOR_METATYPE_COMMENT != type) 77 if (EXTRACTOR_METATYPE_COMMENT != type)
78 { 78 {
79 fprintf (stderr, "type invalid\n"); 79 fprintf (stderr, "type invalid\n");
80 ret = 5; 80 ret = 5;
81 return 1; 81 return 1;
82 } 82 }
83 if (EXTRACTOR_METAFORMAT_UTF8 != format) 83 if (EXTRACTOR_METAFORMAT_UTF8 != format)
84 { 84 {
85 fprintf (stderr, "format invalid\n"); 85 fprintf (stderr, "format invalid\n");
86 ret = 6; 86 ret = 6;
87 return 1; 87 return 1;
88 } 88 }
89 if ( (NULL == data_mime_type) || 89 if ( (NULL == data_mime_type) ||
90 (0 != strcmp ("<no mime>", 90 (0 != strcmp ("<no mime>",
91 data_mime_type) ) ) 91 data_mime_type) ) )
92 { 92 {
93 fprintf (stderr, "bad mime type\n"); 93 fprintf (stderr, "bad mime type\n");
94 ret = 7; 94 ret = 7;
95 return 1; 95 return 1;
96 } 96 }
97 if ( (2 == ret) && 97 if ( (2 == ret) &&
98 (data_len == strlen (HLO) + 1) && 98 (data_len == strlen (HLO) + 1) &&
99 (0 == strncmp (data, 99 (0 == strncmp (data,
100 HLO, 100 HLO,
101 strlen (HLO))) ) 101 strlen (HLO))) )
102 { 102 {
103#if 0 103#if 0
104 fprintf (stderr, "Received '%s'\n", HLO); 104 fprintf (stderr, "Received '%s'\n", HLO);
105#endif 105#endif
106 ret = 1; 106 ret = 1;
107 return 0; 107 return 0;
108 } 108 }
109 if ( (1 == ret) && 109 if ( (1 == ret) &&
110 (data_len == strlen (GOB) + 1) && 110 (data_len == strlen (GOB) + 1) &&
111 (0 == strncmp (data, 111 (0 == strncmp (data,
112 GOB, 112 GOB,
113 strlen (GOB))) ) 113 strlen (GOB))) )
114 { 114 {
115#if 0 115#if 0
116 fprintf (stderr, "Received '%s'\n", GOB); 116 fprintf (stderr, "Received '%s'\n", GOB);
117#endif 117#endif
118 ret = 0; 118 ret = 0;
119 return 1; 119 return 1;
120 } 120 }
121 fprintf (stderr, "Invalid meta data\n"); 121 fprintf (stderr, "Invalid meta data\n");
122 ret = 8; 122 ret = 8;
123 return 1; 123 return 1;
@@ -136,23 +136,25 @@ main (int argc, char *argv[])
136{ 136{
137 struct EXTRACTOR_PluginList *pl; 137 struct EXTRACTOR_PluginList *pl;
138 138
139 /* change environment to find 'extractor_test' plugin which is 139 /* change environment to find 'extractor_test' plugin which is
140 not installed but should be in the current directory (or .libs) 140 not installed but should be in the current directory (or .libs)
141 on 'make check' */ 141 on 'make check' */
142 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) 142 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/"))
143 fprintf (stderr, 143 fprintf (stderr,
144 "Failed to update my environment, plugin loading may fail: %s\n", 144 "Failed to update my environment, plugin loading may fail: %s\n",
145 strerror (errno)); 145 strerror (errno));
146 pl = EXTRACTOR_plugin_add_config (NULL, "test(test)", 146 pl = EXTRACTOR_plugin_add_config (NULL, "test(test)",
147 EXTRACTOR_OPTION_DEFAULT_POLICY); 147 EXTRACTOR_OPTION_DEFAULT_POLICY);
148 if (NULL == pl) 148 if (NULL == pl)
149 { 149 {
150 fprintf (stderr, "failed to load test plugin\n"); 150 fprintf (stderr, "failed to load test plugin\n");
151 return 1; 151 return 1;
152 } 152 }
153 EXTRACTOR_extract (pl, "test_file.dat.gz", NULL, 0, &process_replies, "main-cls"); 153 EXTRACTOR_extract (pl, "test_file.dat.gz", NULL, 0, &process_replies,
154 "main-cls");
154 EXTRACTOR_plugin_remove_all (pl); 155 EXTRACTOR_plugin_remove_all (pl);
155 return ret; 156 return ret;
156} 157}
157 158
159
158/* end of test_gzip.c */ 160/* end of test_gzip.c */
diff --git a/src/main/test_ipc.c b/src/main/test_ipc.c
index 5e118fd..4da3ef5 100644
--- a/src/main/test_ipc.c
+++ b/src/main/test_ipc.c
@@ -46,77 +46,77 @@ static int ret = 2;
46 * @param data hello world or good bye 46 * @param data hello world or good bye
47 * @param data_len number of bytes in data 47 * @param data_len number of bytes in data
48 * @return 0 on hello world, 1 on goodbye 48 * @return 0 on hello world, 1 on goodbye
49 */ 49 */
50static int 50static int
51process_replies (void *cls, 51process_replies (void *cls,
52 const char *plugin_name, 52 const char *plugin_name,
53 enum EXTRACTOR_MetaType type, 53 enum EXTRACTOR_MetaType type,
54 enum EXTRACTOR_MetaFormat format, 54 enum EXTRACTOR_MetaFormat format,
55 const char *data_mime_type, 55 const char *data_mime_type,
56 const char *data, 56 const char *data,
57 size_t data_len) 57 size_t data_len)
58{ 58{
59 if (0 != strcmp (cls, 59 if (0 != strcmp (cls,
60 "main-cls")) 60 "main-cls"))
61 { 61 {
62 fprintf (stderr, "closure invalid\n"); 62 fprintf (stderr, "closure invalid\n");
63 ret = 3; 63 ret = 3;
64 return 1; 64 return 1;
65 } 65 }
66 if (0 == strcmp (plugin_name, 66 if (0 == strcmp (plugin_name,
67 "test2")) 67 "test2"))
68 return 0; /* ignore 'test2' plugins */ 68 return 0; /* ignore 'test2' plugins */
69 if (0 != strcmp (plugin_name, 69 if (0 != strcmp (plugin_name,
70 "test")) 70 "test"))
71 { 71 {
72 fprintf (stderr, "plugin name invalid\n"); 72 fprintf (stderr, "plugin name invalid\n");
73 ret = 4; 73 ret = 4;
74 return 1; 74 return 1;
75 } 75 }
76 if (EXTRACTOR_METATYPE_COMMENT != type) 76 if (EXTRACTOR_METATYPE_COMMENT != type)
77 { 77 {
78 fprintf (stderr, "type invalid\n"); 78 fprintf (stderr, "type invalid\n");
79 ret = 5; 79 ret = 5;
80 return 1; 80 return 1;
81 } 81 }
82 if (EXTRACTOR_METAFORMAT_UTF8 != format) 82 if (EXTRACTOR_METAFORMAT_UTF8 != format)
83 { 83 {
84 fprintf (stderr, "format invalid\n"); 84 fprintf (stderr, "format invalid\n");
85 ret = 6; 85 ret = 6;
86 return 1; 86 return 1;
87 } 87 }
88 if ( (NULL == data_mime_type) || 88 if ( (NULL == data_mime_type) ||
89 (0 != strcmp ("<no mime>", 89 (0 != strcmp ("<no mime>",
90 data_mime_type) ) ) 90 data_mime_type) ) )
91 { 91 {
92 fprintf (stderr, "bad mime type\n"); 92 fprintf (stderr, "bad mime type\n");
93 ret = 7; 93 ret = 7;
94 return 1; 94 return 1;
95 } 95 }
96 if ( (2 == ret) && 96 if ( (2 == ret) &&
97 (data_len == strlen (HLO) + 1) && 97 (data_len == strlen (HLO) + 1) &&
98 (0 == strncmp (data, 98 (0 == strncmp (data,
99 HLO, 99 HLO,
100 strlen (HLO))) ) 100 strlen (HLO))) )
101 { 101 {
102#if 0 102#if 0
103 fprintf (stderr, "Received '%s'\n", HLO); 103 fprintf (stderr, "Received '%s'\n", HLO);
104#endif 104#endif
105 ret = 1; 105 ret = 1;
106 return 0; 106 return 0;
107 } 107 }
108 if ( (1 == ret) && 108 if ( (1 == ret) &&
109 (data_len == strlen (GOB) + 1) && 109 (data_len == strlen (GOB) + 1) &&
110 (0 == strncmp (data, 110 (0 == strncmp (data,
111 GOB, 111 GOB,
112 strlen (GOB))) ) 112 strlen (GOB))) )
113 { 113 {
114#if 0 114#if 0
115 fprintf (stderr, "Received '%s'\n", GOB); 115 fprintf (stderr, "Received '%s'\n", GOB);
116#endif 116#endif
117 ret = 0; 117 ret = 0;
118 return 1; 118 return 1;
119 } 119 }
120 fprintf (stderr, "Invalid meta data\n"); 120 fprintf (stderr, "Invalid meta data\n");
121 ret = 8; 121 ret = 8;
122 return 1; 122 return 1;
@@ -138,35 +138,37 @@ main (int argc, char *argv[])
138 size_t i; 138 size_t i;
139 139
140 /* initialize test buffer as expected by test plugin */ 140 /* initialize test buffer as expected by test plugin */
141 for (i=0;i<sizeof(buf);i++) 141 for (i = 0; i<sizeof(buf); i++)
142 buf[i] = (unsigned char) (i % 256); 142 buf[i] = (unsigned char) (i % 256);
143 memcpy (buf, "test", 4); 143 memcpy (buf, "test", 4);
144 144
145 /* change environment to find 'extractor_test' plugin which is 145 /* change environment to find 'extractor_test' plugin which is
146 not installed but should be in the current directory (or .libs) 146 not installed but should be in the current directory (or .libs)
147 on 'make check' */ 147 on 'make check' */
148 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) 148 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/"))
149 fprintf (stderr, 149 fprintf (stderr,
150 "Failed to update my environment, plugin loading may fail: %s\n", 150 "Failed to update my environment, plugin loading may fail: %s\n",
151 strerror (errno)); 151 strerror (errno));
152 pl = EXTRACTOR_plugin_add_config (NULL, "test(test)", 152 pl = EXTRACTOR_plugin_add_config (NULL, "test(test)",
153 EXTRACTOR_OPTION_DEFAULT_POLICY); 153 EXTRACTOR_OPTION_DEFAULT_POLICY);
154 pl = EXTRACTOR_plugin_add_config (pl, "test2(test2)", 154 pl = EXTRACTOR_plugin_add_config (pl, "test2(test2)",
155 EXTRACTOR_OPTION_DEFAULT_POLICY); 155 EXTRACTOR_OPTION_DEFAULT_POLICY);
156 if (NULL == pl) 156 if (NULL == pl)
157 { 157 {
158 fprintf (stderr, "failed to load test plugin\n"); 158 fprintf (stderr, "failed to load test plugin\n");
159 return 1; 159 return 1;
160 } 160 }
161 EXTRACTOR_extract (pl, NULL, buf, sizeof (buf), &process_replies, "main-cls"); 161 EXTRACTOR_extract (pl, NULL, buf, sizeof (buf), &process_replies, "main-cls");
162 if (0 == ret) 162 if (0 == ret)
163 { 163 {
164 /* do it again... */ 164 /* do it again... */
165 ret = 2; 165 ret = 2;
166 EXTRACTOR_extract (pl, NULL, buf, sizeof (buf), &process_replies, "main-cls"); 166 EXTRACTOR_extract (pl, NULL, buf, sizeof (buf), &process_replies,
167 } 167 "main-cls");
168 }
168 EXTRACTOR_plugin_remove_all (pl); 169 EXTRACTOR_plugin_remove_all (pl);
169 return ret; 170 return ret;
170} 171}
171 172
173
172/* end of test_ipc.c */ 174/* end of test_ipc.c */
diff --git a/src/main/test_plugin_load_multi.c b/src/main/test_plugin_load_multi.c
index b7958f2..6b30390 100644
--- a/src/main/test_plugin_load_multi.c
+++ b/src/main/test_plugin_load_multi.c
@@ -37,15 +37,15 @@ testLoadPlugins ()
37 el1 = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); 37 el1 = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY);
38 el2 = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); 38 el2 = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY);
39 if ((NULL == el1) || (NULL == el2)) 39 if ((NULL == el1) || (NULL == el2))
40 { 40 {
41 fprintf (stderr, 41 fprintf (stderr,
42 "Failed to load default plugins!\n"); 42 "Failed to load default plugins!\n");
43 if (NULL != el1) 43 if (NULL != el1)
44 EXTRACTOR_plugin_remove_all (el1); 44 EXTRACTOR_plugin_remove_all (el1);
45 if (NULL != el2) 45 if (NULL != el2)
46 EXTRACTOR_plugin_remove_all (el2); 46 EXTRACTOR_plugin_remove_all (el2);
47 return 1; 47 return 1;
48 } 48 }
49 EXTRACTOR_plugin_remove_all (el1); 49 EXTRACTOR_plugin_remove_all (el1);
50 EXTRACTOR_plugin_remove_all (el2); 50 EXTRACTOR_plugin_remove_all (el2);
51 return 0; 51 return 0;
@@ -57,16 +57,17 @@ main (int argc, char *argv[])
57{ 57{
58 int ret = 0; 58 int ret = 0;
59 59
60 /* change environment to find 'extractor_test' plugin which is 60 /* change environment to find 'extractor_test' plugin which is
61 not installed but should be in the current directory (or .libs) 61 not installed but should be in the current directory (or .libs)
62 on 'make check' */ 62 on 'make check' */
63 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) 63 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/"))
64 fprintf (stderr, 64 fprintf (stderr,
65 "Failed to update my environment, plugin loading may fail: %s\n", 65 "Failed to update my environment, plugin loading may fail: %s\n",
66 strerror (errno)); 66 strerror (errno));
67 ret += testLoadPlugins (); 67 ret += testLoadPlugins ();
68 ret += testLoadPlugins (); 68 ret += testLoadPlugins ();
69 return ret; 69 return ret;
70} 70}
71 71
72
72/* end of test_plugin_load_multi.c */ 73/* end of test_plugin_load_multi.c */
diff --git a/src/main/test_plugin_loading.c b/src/main/test_plugin_loading.c
index ddcfb92..537b703 100644
--- a/src/main/test_plugin_loading.c
+++ b/src/main/test_plugin_loading.c
@@ -30,29 +30,32 @@ main (int argc, char *argv[])
30{ 30{
31 struct EXTRACTOR_PluginList *arg; 31 struct EXTRACTOR_PluginList *arg;
32 32
33 /* change environment to find 'extractor_test' plugin which is 33 /* change environment to find 'extractor_test' plugin which is
34 not installed but should be in the current directory (or .libs) 34 not installed but should be in the current directory (or .libs)
35 on 'make check' */ 35 on 'make check' */
36 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) 36 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/"))
37 fprintf (stderr, 37 fprintf (stderr,
38 "Failed to update my environment, plugin loading may fail: %s\n", 38 "Failed to update my environment, plugin loading may fail: %s\n",
39 strerror (errno)); 39 strerror (errno));
40 40
41 /* do some load/unload tests */ 41 /* do some load/unload tests */
42 arg = EXTRACTOR_plugin_add (NULL, "test", NULL, EXTRACTOR_OPTION_DEFAULT_POLICY); 42 arg = EXTRACTOR_plugin_add (NULL, "test", NULL,
43 if (arg != EXTRACTOR_plugin_add (arg, "test", NULL, EXTRACTOR_OPTION_DEFAULT_POLICY)) 43 EXTRACTOR_OPTION_DEFAULT_POLICY);
44 { 44 if (arg != EXTRACTOR_plugin_add (arg, "test", NULL,
45 fprintf (stderr, 45 EXTRACTOR_OPTION_DEFAULT_POLICY))
46 "Could load plugin twice, that should not be allowed\n"); 46 {
47 } 47 fprintf (stderr,
48 "Could load plugin twice, that should not be allowed\n");
49 }
48 arg = EXTRACTOR_plugin_remove (arg, "test"); 50 arg = EXTRACTOR_plugin_remove (arg, "test");
49 if (NULL != arg) 51 if (NULL != arg)
50 { 52 {
51 fprintf (stderr, 53 fprintf (stderr,
52 "add-remove test failed!\n"); 54 "add-remove test failed!\n");
53 return -1; 55 return -1;
54 } 56 }
55 return 0; 57 return 0;
56} 58}
57 59
60
58/* end of test_plugin_loading.c */ 61/* end of test_plugin_loading.c */
diff --git a/src/main/test_trivial.c b/src/main/test_trivial.c
index fac9a91..b0860b4 100644
--- a/src/main/test_trivial.c
+++ b/src/main/test_trivial.c
@@ -30,34 +30,36 @@ static int
30testLoadPlugins (enum EXTRACTOR_Options policy) 30testLoadPlugins (enum EXTRACTOR_Options policy)
31{ 31{
32 struct EXTRACTOR_PluginList *pl; 32 struct EXTRACTOR_PluginList *pl;
33 33
34 if (NULL == (pl = EXTRACTOR_plugin_add_defaults (policy))) 34 if (NULL == (pl = EXTRACTOR_plugin_add_defaults (policy)))
35 { 35 {
36 fprintf (stderr, 36 fprintf (stderr,
37 "Failed to load default plugins!\n"); 37 "Failed to load default plugins!\n");
38 return 1; 38 return 1;
39 } 39 }
40 EXTRACTOR_plugin_remove_all (pl); 40 EXTRACTOR_plugin_remove_all (pl);
41 return 0; 41 return 0;
42} 42}
43 43
44
44int 45int
45main (int argc, char *argv[]) 46main (int argc, char *argv[])
46{ 47{
47 int ret = 0; 48 int ret = 0;
48 49
49 50
50 /* change environment to find 'extractor_test' plugin which is 51 /* change environment to find 'extractor_test' plugin which is
51 not installed but should be in the current directory (or .libs) 52 not installed but should be in the current directory (or .libs)
52 on 'make check' */ 53 on 'make check' */
53 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) 54 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/"))
54 fprintf (stderr, 55 fprintf (stderr,
55 "Failed to update my environment, plugin loading may fail: %s\n", 56 "Failed to update my environment, plugin loading may fail: %s\n",
56 strerror (errno)); 57 strerror (errno));
57 ret += testLoadPlugins (EXTRACTOR_OPTION_DEFAULT_POLICY); 58 ret += testLoadPlugins (EXTRACTOR_OPTION_DEFAULT_POLICY);
58 ret += testLoadPlugins (EXTRACTOR_OPTION_DEFAULT_POLICY); 59 ret += testLoadPlugins (EXTRACTOR_OPTION_DEFAULT_POLICY);
59 ret += testLoadPlugins (EXTRACTOR_OPTION_DEFAULT_POLICY); 60 ret += testLoadPlugins (EXTRACTOR_OPTION_DEFAULT_POLICY);
60 return ret; 61 return ret;
61} 62}
62 63
64
63/* end of test_trivial.c */ 65/* end of test_trivial.c */
diff --git a/src/plugins/archive_extractor.c b/src/plugins/archive_extractor.c
index 7a80ac5..6d413de 100644
--- a/src/plugins/archive_extractor.c
+++ b/src/plugins/archive_extractor.c
@@ -36,9 +36,9 @@
36 * @return number of bytes read 36 * @return number of bytes read
37 */ 37 */
38static ssize_t 38static ssize_t
39read_cb (struct archive *a, 39read_cb (struct archive *a,
40 void *client_data, 40 void *client_data,
41 const void **buff) 41 const void **buff)
42{ 42{
43 struct EXTRACTOR_ExtractContext *ec = client_data; 43 struct EXTRACTOR_ExtractContext *ec = client_data;
44 ssize_t ret; 44 ssize_t ret;
@@ -71,9 +71,9 @@ read_cb (struct archive *a,
71 * @return number of bytes skipped 71 * @return number of bytes skipped
72 */ 72 */
73static __LA_INT64_T 73static __LA_INT64_T
74skip_cb (struct archive *a, 74skip_cb (struct archive *a,
75 void *client_data, 75 void *client_data,
76 __LA_INT64_T request) 76 __LA_INT64_T request)
77{ 77{
78 struct EXTRACTOR_ExtractContext *ec = client_data; 78 struct EXTRACTOR_ExtractContext *ec = client_data;
79 79
@@ -84,11 +84,11 @@ skip_cb (struct archive *a,
84 84
85 85
86/** 86/**
87 * Main entry method for the ARCHIVE extraction plugin. 87 * Main entry method for the ARCHIVE extraction plugin.
88 * 88 *
89 * @param ec extraction context provided to the plugin 89 * @param ec extraction context provided to the plugin
90 */ 90 */
91void 91void
92EXTRACTOR_archive_extract_method (struct EXTRACTOR_ExtractContext *ec) 92EXTRACTOR_archive_extract_method (struct EXTRACTOR_ExtractContext *ec)
93{ 93{
94 struct archive *a; 94 struct archive *a;
@@ -105,41 +105,41 @@ EXTRACTOR_archive_extract_method (struct EXTRACTOR_ExtractContext *ec)
105 archive_read_support_compression_all (a); 105 archive_read_support_compression_all (a);
106#endif 106#endif
107 archive_read_support_format_all (a); 107 archive_read_support_format_all (a);
108 if(archive_read_open2 (a, ec, NULL, &read_cb, &skip_cb, NULL)!= ARCHIVE_OK) 108 if (archive_read_open2 (a, ec, NULL, &read_cb, &skip_cb, NULL)!= ARCHIVE_OK)
109 return; 109 return;
110 110
111 while (ARCHIVE_OK == archive_read_next_header(a, &entry)) 111 while (ARCHIVE_OK == archive_read_next_header (a, &entry))
112 { 112 {
113 if ( (NULL == format) && 113 if ( (NULL == format) &&
114 (NULL != (fname = archive_format_name (a))) ) 114 (NULL != (fname = archive_format_name (a))) )
115 format = strdup (fname); 115 format = strdup (fname);
116 s = archive_entry_pathname (entry); 116 s = archive_entry_pathname (entry);
117 if (0 != ec->proc (ec->cls, 117 if (0 != ec->proc (ec->cls,
118 "tar", 118 "tar",
119 EXTRACTOR_METATYPE_FILENAME, 119 EXTRACTOR_METATYPE_FILENAME,
120 EXTRACTOR_METAFORMAT_UTF8, 120 EXTRACTOR_METAFORMAT_UTF8,
121 "text/plain", 121 "text/plain",
122 s, strlen (s) + 1)) 122 s, strlen (s) + 1))
123 break; 123 break;
124 } 124 }
125#if ARCHIVE_VERSION_NUMBER >= 3000000 125#if ARCHIVE_VERSION_NUMBER >= 3000000
126 archive_read_free (a); 126 archive_read_free (a);
127#else 127#else
128 archive_read_finish (a); 128 archive_read_finish (a);
129#endif 129#endif
130 if (NULL != format) 130 if (NULL != format)
131 {
132 if (0 != ec->proc (ec->cls,
133 "tar",
134 EXTRACTOR_METATYPE_FORMAT,
135 EXTRACTOR_METAFORMAT_UTF8,
136 "text/plain", format, strlen (format) + 1))
131 { 137 {
132 if (0 != ec->proc (ec->cls,
133 "tar",
134 EXTRACTOR_METATYPE_FORMAT,
135 EXTRACTOR_METAFORMAT_UTF8,
136 "text/plain", format, strlen (format) + 1))
137 {
138 free (format);
139 return;
140 }
141 free (format); 138 free (format);
139 return;
142 } 140 }
141 free (format);
142 }
143} 143}
144 144
145 145
diff --git a/src/plugins/deb_extractor.c b/src/plugins/deb_extractor.c
index 2eb0028..16c6285 100644
--- a/src/plugins/deb_extractor.c
+++ b/src/plugins/deb_extractor.c
@@ -122,8 +122,8 @@ static struct Matches tmap[] = {
122static int 122static int
123processControl (const char *data, 123processControl (const char *data,
124 const size_t size, 124 const size_t size,
125 EXTRACTOR_MetaDataProcessor proc, 125 EXTRACTOR_MetaDataProcessor proc,
126 void *proc_cls) 126 void *proc_cls)
127{ 127{
128 size_t pos; 128 size_t pos;
129 char *key; 129 char *key;
@@ -134,49 +134,49 @@ processControl (const char *data,
134 134
135 pos = 0; 135 pos = 0;
136 while (pos < size) 136 while (pos < size)
137 { 137 {
138 for (colon = pos; ':' != data[colon]; colon++) 138 for (colon = pos; ':' != data[colon]; colon++)
139 if ((colon > size) || ('\n' == data[colon])) 139 if ((colon > size) || ('\n' == data[colon]))
140 return 0; 140 return 0;
141 colon++;
142 while ((colon < size) && (isspace ((unsigned char) data[colon])))
141 colon++; 143 colon++;
142 while ((colon < size) && (isspace ((unsigned char) data[colon]))) 144 eol = colon;
143 colon++; 145 while ((eol < size) &&
144 eol = colon; 146 (('\n' != data[eol]) ||
145 while ((eol < size) && 147 ((eol + 1 < size) && (' ' == data[eol + 1]))))
146 (('\n' != data[eol]) || 148 eol++;
147 ((eol + 1 < size) && (' ' == data[eol + 1])))) 149 if ((eol == colon) || (eol > size))
148 eol++; 150 return 0;
149 if ((eol == colon) || (eol > size)) 151 if (NULL == (key = stndup (&data[pos], colon - pos)))
152 return 0;
153 for (i = 0; NULL != tmap[i].text; i++)
154 {
155 if (0 != strcmp (key, tmap[i].text))
156 continue;
157 if (NULL == (val = stndup (&data[colon], eol - colon)))
158 {
159 free (key);
150 return 0; 160 return 0;
151 if (NULL == (key = stndup (&data[pos], colon - pos))) 161 }
152 return 0; 162 if (0 != proc (proc_cls,
153 for (i = 0; NULL != tmap[i].text; i++) 163 "deb",
154 { 164 tmap[i].type,
155 if (0 != strcmp (key, tmap[i].text)) 165 EXTRACTOR_METAFORMAT_UTF8,
156 continue; 166 "text/plain",
157 if (NULL == (val = stndup (&data[colon], eol - colon))) 167 val,
158 { 168 strlen (val) + 1))
159 free (key); 169 {
160 return 0; 170 free (val);
161 } 171 free (key);
162 if (0 != proc (proc_cls, 172 return 1;
163 "deb", 173 }
164 tmap[i].type, 174 free (val);
165 EXTRACTOR_METAFORMAT_UTF8, 175 break;
166 "text/plain",
167 val,
168 strlen(val) + 1))
169 {
170 free (val);
171 free (key);
172 return 1;
173 }
174 free (val);
175 break;
176 }
177 free (key);
178 pos = eol + 1;
179 } 176 }
177 free (key);
178 pos = eol + 1;
179 }
180 return 0; 180 return 0;
181} 181}
182 182
@@ -291,9 +291,9 @@ struct USTarHeader
291 */ 291 */
292static int 292static int
293processControlTar (const char *data, 293processControlTar (const char *data,
294 size_t size, 294 size_t size,
295 EXTRACTOR_MetaDataProcessor proc, 295 EXTRACTOR_MetaDataProcessor proc,
296 void *proc_cls) 296 void *proc_cls)
297{ 297{
298 struct TarHeader *tar; 298 struct TarHeader *tar;
299 struct USTarHeader *ustar; 299 struct USTarHeader *ustar;
@@ -301,42 +301,42 @@ processControlTar (const char *data,
301 301
302 pos = 0; 302 pos = 0;
303 while (pos + sizeof (struct TarHeader) < size) 303 while (pos + sizeof (struct TarHeader) < size)
304 {
305 unsigned long long fsize;
306 char buf[13];
307
308 tar = (struct TarHeader *) &data[pos];
309 if (pos + sizeof (struct USTarHeader) < size)
304 { 310 {
305 unsigned long long fsize; 311 ustar = (struct USTarHeader *) &data[pos];
306 char buf[13]; 312 if (0 == strncmp ("ustar", &ustar->magic[0], strlen ("ustar")))
307 313 pos += 512; /* sizeof (struct USTarHeader); */
308 tar = (struct TarHeader *) & data[pos];
309 if (pos + sizeof (struct USTarHeader) < size)
310 {
311 ustar = (struct USTarHeader *) & data[pos];
312 if (0 == strncmp ("ustar", &ustar->magic[0], strlen ("ustar")))
313 pos += 512; /* sizeof (struct USTarHeader); */
314 else
315 pos += 257; /* sizeof (struct TarHeader); minus gcc alignment... */
316 }
317 else 314 else
318 { 315 pos += 257; /* sizeof (struct TarHeader); minus gcc alignment... */
319 pos += 257; /* sizeof (struct TarHeader); minus gcc alignment... */ 316 }
320 } 317 else
318 {
319 pos += 257; /* sizeof (struct TarHeader); minus gcc alignment... */
320 }
321 321
322 memcpy (buf, &tar->filesize[0], 12); 322 memcpy (buf, &tar->filesize[0], 12);
323 buf[12] = '\0'; 323 buf[12] = '\0';
324 if (1 != sscanf (buf, "%12llo", &fsize)) /* octal! Yuck yuck! */ 324 if (1 != sscanf (buf, "%12llo", &fsize)) /* octal! Yuck yuck! */
325 return 0; 325 return 0;
326 if ((pos + fsize > size) || (fsize > size) || (pos + fsize < pos)) 326 if ((pos + fsize > size) || (fsize > size) || (pos + fsize < pos))
327 return 0; 327 return 0;
328 328
329 if (0 == strncmp (&tar->name[0], "./control", strlen ("./control"))) 329 if (0 == strncmp (&tar->name[0], "./control", strlen ("./control")))
330 { 330 {
331 /* found the 'control' file we were looking for */ 331 /* found the 'control' file we were looking for */
332 return processControl (&data[pos], fsize, proc, proc_cls); 332 return processControl (&data[pos], fsize, proc, proc_cls);
333 }
334 if (0 != (fsize & 511))
335 fsize = (fsize | 511) + 1; /* round up! */
336 if (pos + fsize < pos)
337 return 0;
338 pos += fsize;
339 } 333 }
334 if (0 != (fsize & 511))
335 fsize = (fsize | 511) + 1; /* round up! */
336 if (pos + fsize < pos)
337 return 0;
338 pos += fsize;
339 }
340 return 0; 340 return 0;
341} 341}
342 342
@@ -371,42 +371,43 @@ processControlTGZ (struct EXTRACTOR_ExtractContext *ec,
371 return 0; 371 return 0;
372 off = 0; 372 off = 0;
373 while (off < size) 373 while (off < size)
374 { 374 {
375 if (0 >= (sret = ec->read (ec->cls, &data, size - off))) 375 if (0 >= (sret = ec->read (ec->cls, &data, size - off)))
376 {
377 free (cdata);
378 return 0;
379 }
380 memcpy (&cdata[off],
381 data,
382 sret);
383 off += sret;
384 }
385 bufSize = cdata[size - 4] + (cdata[size - 3] << 8) + (cdata[size - 2] << 16) + (cdata[size - 1] << 24);
386 if (bufSize > MAX_CONTROL_SIZE)
387 { 376 {
388 free (cdata); 377 free (cdata);
389 return 0; 378 return 0;
390 } 379 }
380 memcpy (&cdata[off],
381 data,
382 sret);
383 off += sret;
384 }
385 bufSize = cdata[size - 4] + (cdata[size - 3] << 8) + (cdata[size - 2] << 16)
386 + (cdata[size - 1] << 24);
387 if (bufSize > MAX_CONTROL_SIZE)
388 {
389 free (cdata);
390 return 0;
391 }
391 if (NULL == (buf = malloc (bufSize))) 392 if (NULL == (buf = malloc (bufSize)))
392 { 393 {
393 free (cdata); 394 free (cdata);
394 return 0; 395 return 0;
395 } 396 }
396 ret = 0; 397 ret = 0;
397 memset (&strm, 0, sizeof (z_stream)); 398 memset (&strm, 0, sizeof (z_stream));
398 strm.next_in = (Bytef *) data; 399 strm.next_in = (Bytef *) data;
399 strm.avail_in = size; 400 strm.avail_in = size;
400 if (Z_OK == inflateInit2 (&strm, 15 + 32)) 401 if (Z_OK == inflateInit2 (&strm, 15 + 32))
401 { 402 {
402 strm.next_out = (Bytef *) buf; 403 strm.next_out = (Bytef *) buf;
403 strm.avail_out = bufSize; 404 strm.avail_out = bufSize;
404 inflate (&strm, Z_FINISH); 405 inflate (&strm, Z_FINISH);
405 if (strm.total_out > 0) 406 if (strm.total_out > 0)
406 ret = processControlTar (buf, strm.total_out, 407 ret = processControlTar (buf, strm.total_out,
407 ec->proc, ec->cls); 408 ec->proc, ec->cls);
408 inflateEnd (&strm); 409 inflateEnd (&strm);
409 } 410 }
410 free (buf); 411 free (buf);
411 free (cdata); 412 free (cdata);
412 return ret; 413 return ret;
@@ -481,49 +482,50 @@ EXTRACTOR_deb_extract_method (struct EXTRACTOR_ExtractContext *ec)
481 return; 482 return;
482 pos = 8; 483 pos = 8;
483 while (pos + sizeof (struct ObjectHeader) < fsize) 484 while (pos + sizeof (struct ObjectHeader) < fsize)
485 {
486 if (pos !=
487 ec->seek (ec->cls, pos, SEEK_SET))
488 return;
489 if (sizeof (struct ObjectHeader) !=
490 ec->read (ec->cls, &data, sizeof (struct ObjectHeader)))
491 return;
492 hdr = data;
493 if (0 != strncmp (&hdr->trailer[0], "`\n", 2))
494 return;
495 memcpy (buf, &hdr->filesize[0], 10);
496 buf[10] = '\0';
497 if (1 != sscanf (buf, "%10llu", &csize))
498 return;
499 pos += sizeof (struct ObjectHeader);
500 if ((pos + csize > fsize) || (csize > fsize) || (pos + csize < pos))
501 return;
502 if (0 == strncmp (&hdr->name[0],
503 "control.tar.gz",
504 strlen ("control.tar.gz")))
484 { 505 {
485 if (pos != 506 if (0 != processControlTGZ (ec,
486 ec->seek (ec->cls, pos, SEEK_SET)) 507 csize))
487 return;
488 if (sizeof (struct ObjectHeader) !=
489 ec->read (ec->cls, &data, sizeof (struct ObjectHeader)))
490 return;
491 hdr = data;
492 if (0 != strncmp (&hdr->trailer[0], "`\n", 2))
493 return; 508 return;
494 memcpy (buf, &hdr->filesize[0], 10); 509 done++;
495 buf[10] = '\0'; 510 }
496 if (1 != sscanf (buf, "%10llu", &csize)) 511 if (0 == strncmp (&hdr->name[0],
497 return; 512 "debian-binary", strlen ("debian-binary")))
498 pos += sizeof (struct ObjectHeader); 513 {
499 if ((pos + csize > fsize) || (csize > fsize) || (pos + csize < pos)) 514 if (0 != ec->proc (ec->cls,
515 "deb",
516 EXTRACTOR_METATYPE_MIMETYPE,
517 EXTRACTOR_METAFORMAT_UTF8,
518 "text/plain",
519 "application/x-debian-package",
520 strlen ("application/x-debian-package") + 1))
500 return; 521 return;
501 if (0 == strncmp (&hdr->name[0], 522 done++;
502 "control.tar.gz",
503 strlen ("control.tar.gz")))
504 {
505 if (0 != processControlTGZ (ec,
506 csize))
507 return;
508 done++;
509 }
510 if (0 == strncmp (&hdr->name[0],
511 "debian-binary", strlen ("debian-binary")))
512 {
513 if (0 != ec->proc (ec->cls,
514 "deb",
515 EXTRACTOR_METATYPE_MIMETYPE,
516 EXTRACTOR_METAFORMAT_UTF8,
517 "text/plain",
518 "application/x-debian-package",
519 strlen ("application/x-debian-package")+1))
520 return;
521 done++;
522 }
523 pos += csize;
524 if (2 == done)
525 break; /* no need to process the rest of the archive */
526 } 523 }
524 pos += csize;
525 if (2 == done)
526 break; /* no need to process the rest of the archive */
527 }
527} 528}
528 529
530
529/* end of deb_extractor.c */ 531/* end of deb_extractor.c */
diff --git a/src/plugins/dvi_extractor.c b/src/plugins/dvi_extractor.c
index e3aa450..4e52150 100644
--- a/src/plugins/dvi_extractor.c
+++ b/src/plugins/dvi_extractor.c
@@ -53,12 +53,12 @@ static struct Matches tmap[] = {
53 { "/Keywords (", EXTRACTOR_METATYPE_KEYWORDS }, 53 { "/Keywords (", EXTRACTOR_METATYPE_KEYWORDS },
54 { "/Creator (", EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE }, 54 { "/Creator (", EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE },
55 { "/Producer (", EXTRACTOR_METATYPE_PRODUCED_BY_SOFTWARE }, 55 { "/Producer (", EXTRACTOR_METATYPE_PRODUCED_BY_SOFTWARE },
56 { NULL, 0 } 56 { NULL, 0 }
57}; 57};
58 58
59 59
60/** 60/**
61 * Parse a "ZZZ" tag. Specifically, the data may contain a 61 * Parse a "ZZZ" tag. Specifically, the data may contain a
62 * postscript dictionary with metadata. 62 * postscript dictionary with metadata.
63 * 63 *
64 * @param data overall input stream 64 * @param data overall input stream
@@ -71,8 +71,8 @@ static struct Matches tmap[] = {
71static int 71static int
72parseZZZ (const char *data, 72parseZZZ (const char *data,
73 size_t pos, size_t len, 73 size_t pos, size_t len,
74 EXTRACTOR_MetaDataProcessor proc, 74 EXTRACTOR_MetaDataProcessor proc,
75 void *proc_cls) 75 void *proc_cls)
76{ 76{
77 size_t slen; 77 size_t slen;
78 size_t end; 78 size_t end;
@@ -85,37 +85,37 @@ parseZZZ (const char *data,
85 return 0; 85 return 0;
86 pos += slen; 86 pos += slen;
87 while (pos < end) 87 while (pos < end)
88 {
89 for (i = 0; NULL != tmap[i].text; i++)
88 { 90 {
89 for (i = 0; NULL != tmap[i].text; i++) 91 slen = strlen (tmap[i].text);
90 { 92 if ( (pos + slen > end) ||
91 slen = strlen (tmap[i].text); 93 (0 != strncmp (&data[pos], tmap[i].text, slen)) )
92 if ( (pos + slen > end) || 94 continue;
93 (0 != strncmp (&data[pos], tmap[i].text, slen)) ) 95 pos += slen;
94 continue; 96 slen = pos;
95 pos += slen; 97 while ((slen < end) && (data[slen] != ')'))
96 slen = pos; 98 slen++;
97 while ((slen < end) && (data[slen] != ')')) 99 slen = slen - pos;
98 slen++; 100 {
99 slen = slen - pos; 101 char value[slen + 1];
100 { 102
101 char value[slen + 1]; 103 value[slen] = '\0';
102 104 memcpy (value, &data[pos], slen);
103 value[slen] = '\0'; 105 if (0 != proc (proc_cls,
104 memcpy (value, &data[pos], slen); 106 "dvi",
105 if (0 != proc (proc_cls, 107 tmap[i].type,
106 "dvi", 108 EXTRACTOR_METAFORMAT_C_STRING,
107 tmap[i].type, 109 "text/plain",
108 EXTRACTOR_METAFORMAT_C_STRING, 110 value,
109 "text/plain", 111 slen + 1))
110 value, 112 return 1;
111 slen + 1)) 113 }
112 return 1; 114 pos += slen + 1;
113 } 115 break;
114 pos += slen + 1;
115 break;
116 }
117 pos++;
118 } 116 }
117 pos++;
118 }
119 return 0; 119 return 0;
120} 120}
121 121
@@ -153,7 +153,7 @@ getShortAt (const void *data)
153 153
154 154
155/** 155/**
156 * Main entry method for the 'application/x-dvi' extraction plugin. 156 * Main entry method for the 'application/x-dvi' extraction plugin.
157 * 157 *
158 * @param ec extraction context provided to the plugin 158 * @param ec extraction context provided to the plugin
159 */ 159 */
@@ -171,7 +171,7 @@ EXTRACTOR_dvi_extract_method (struct EXTRACTOR_ExtractContext *ec)
171 uint64_t size; 171 uint64_t size;
172 uint64_t off; 172 uint64_t off;
173 ssize_t iret; 173 ssize_t iret;
174 174
175 if (40 >= (iret = ec->read (ec->cls, &buf, 1024))) 175 if (40 >= (iret = ec->read (ec->cls, &buf, 1024)))
176 return; 176 return;
177 data = buf; 177 data = buf;
@@ -189,15 +189,15 @@ EXTRACTOR_dvi_extract_method (struct EXTRACTOR_ExtractContext *ec)
189 memcpy (data, buf, iret); 189 memcpy (data, buf, iret);
190 off = iret; 190 off = iret;
191 while (off < size) 191 while (off < size)
192 {
193 if (0 >= (iret = ec->read (ec->cls, &buf, 16 * 1024)))
192 { 194 {
193 if (0 >= (iret = ec->read (ec->cls, &buf, 16 * 1024))) 195 free (data);
194 { 196 return;
195 free (data);
196 return;
197 }
198 memcpy (&data[off], buf, iret);
199 off += iret;
200 } 197 }
198 memcpy (&data[off], buf, iret);
199 off += iret;
200 }
201 pos = size - 1; 201 pos = size - 1;
202 while ( (223 == data[pos]) && 202 while ( (223 == data[pos]) &&
203 (pos > 0) ) 203 (pos > 0) )
@@ -222,28 +222,28 @@ EXTRACTOR_dvi_extract_method (struct EXTRACTOR_ExtractContext *ec)
222 opos = pos; 222 opos = pos;
223 pos = getIntAt (&data[opos + 1]); 223 pos = getIntAt (&data[opos + 1]);
224 while (1) 224 while (1)
225 { 225 {
226 if (UINT32_MAX == pos) 226 if (UINT32_MAX == pos)
227 break; 227 break;
228 if ( (pos + 45 > size) || 228 if ( (pos + 45 > size) ||
229 (pos + 45 < pos) ) 229 (pos + 45 < pos) )
230 goto CLEANUP; 230 goto CLEANUP;
231 if (data[pos] != 139) /* expect 'bop' */ 231 if (data[pos] != 139) /* expect 'bop' */
232 goto CLEANUP; 232 goto CLEANUP;
233 pageCount++; 233 pageCount++;
234 opos = pos; 234 opos = pos;
235 pos = getIntAt (&data[opos + 41]); 235 pos = getIntAt (&data[opos + 41]);
236 if (UINT32_MAX == pos) 236 if (UINT32_MAX == pos)
237 break; 237 break;
238 if (pos >= opos) 238 if (pos >= opos)
239 goto CLEANUP; /* invalid! */ 239 goto CLEANUP; /* invalid! */
240 } 240 }
241 /* ok, now we believe it's a dvi... */ 241 /* ok, now we believe it's a dvi... */
242 snprintf (pages, 242 snprintf (pages,
243 sizeof (pages), 243 sizeof (pages),
244 "%u", 244 "%u",
245 pageCount); 245 pageCount);
246 if (0 != ec->proc (ec->cls, 246 if (0 != ec->proc (ec->cls,
247 "dvi", 247 "dvi",
248 EXTRACTOR_METATYPE_PAGE_COUNT, 248 EXTRACTOR_METATYPE_PAGE_COUNT,
249 EXTRACTOR_METAFORMAT_UTF8, 249 EXTRACTOR_METAFORMAT_UTF8,
@@ -251,7 +251,7 @@ EXTRACTOR_dvi_extract_method (struct EXTRACTOR_ExtractContext *ec)
251 pages, 251 pages,
252 strlen (pages) + 1)) 252 strlen (pages) + 1))
253 goto CLEANUP; 253 goto CLEANUP;
254 if (0 != ec->proc (ec->cls, 254 if (0 != ec->proc (ec->cls,
255 "dvi", 255 "dvi",
256 EXTRACTOR_METATYPE_MIMETYPE, 256 EXTRACTOR_METATYPE_MIMETYPE,
257 EXTRACTOR_METAFORMAT_UTF8, 257 EXTRACTOR_METAFORMAT_UTF8,
@@ -261,10 +261,10 @@ EXTRACTOR_dvi_extract_method (struct EXTRACTOR_ExtractContext *ec)
261 goto CLEANUP; 261 goto CLEANUP;
262 { 262 {
263 char comment[klen + 1]; 263 char comment[klen + 1];
264 264
265 comment[klen] = '\0'; 265 comment[klen] = '\0';
266 memcpy (comment, &data[15], klen); 266 memcpy (comment, &data[15], klen);
267 if (0 != ec->proc (ec->cls, 267 if (0 != ec->proc (ec->cls,
268 "dvi", 268 "dvi",
269 EXTRACTOR_METATYPE_COMMENT, 269 EXTRACTOR_METATYPE_COMMENT,
270 EXTRACTOR_METAFORMAT_C_STRING, 270 EXTRACTOR_METAFORMAT_C_STRING,
@@ -277,47 +277,52 @@ EXTRACTOR_dvi_extract_method (struct EXTRACTOR_ExtractContext *ec)
277 pos = opos; 277 pos = opos;
278 while ( (size >= 100) && 278 while ( (size >= 100) &&
279 (pos < size - 100) ) 279 (pos < size - 100) )
280 {
281 switch (data[pos])
280 { 282 {
281 switch (data[pos]) 283 case 139: /* begin page 'bop', we typically have to skip that one to
282 {
283 case 139: /* begin page 'bop', we typically have to skip that one to
284 find the zzz's */ 284 find the zzz's */
285 pos += 45; /* skip bop */ 285 pos += 45; /* skip bop */
286 break; 286 break;
287 case 239: /* zzz1 */ 287 case 239: /* zzz1 */
288 len = data[pos + 1]; 288 len = data[pos + 1];
289 if ( (pos + 2 + len < size) && 289 if ( (pos + 2 + len < size) &&
290 (0 != parseZZZ ((const char *) data, pos + 2, len, ec->proc, ec->cls)) ) 290 (0 != parseZZZ ((const char *) data, pos + 2, len, ec->proc,
291 goto CLEANUP; 291 ec->cls)) )
292 pos += len + 2; 292 goto CLEANUP;
293 break; 293 pos += len + 2;
294 case 240: /* zzz2 */ 294 break;
295 len = getShortAt (&data[pos + 1]); 295 case 240: /* zzz2 */
296 if ( (pos + 3 + len < size) && 296 len = getShortAt (&data[pos + 1]);
297 (0 != parseZZZ ((const char *) data, pos + 3, len, ec->proc, ec->cls)) ) 297 if ( (pos + 3 + len < size) &&
298 goto CLEANUP; 298 (0 != parseZZZ ((const char *) data, pos + 3, len, ec->proc,
299 pos += len + 3; 299 ec->cls)) )
300 break; 300 goto CLEANUP;
301 case 241: /* zzz3, who uses that? */ 301 pos += len + 3;
302 len = (getShortAt (&data[pos + 1])) + 65536 * data[pos + 3]; 302 break;
303 if ( (pos + 4 + len < size) && 303 case 241: /* zzz3, who uses that? */
304 (0 != parseZZZ ((const char *) data, pos + 4, len, ec->proc, ec->cls)) ) 304 len = (getShortAt (&data[pos + 1])) + 65536 * data[pos + 3];
305 goto CLEANUP; 305 if ( (pos + 4 + len < size) &&
306 pos += len + 4; 306 (0 != parseZZZ ((const char *) data, pos + 4, len, ec->proc,
307 break; 307 ec->cls)) )
308 case 242: /* zzz4, hurray! */ 308 goto CLEANUP;
309 len = getIntAt (&data[pos + 1]); 309 pos += len + 4;
310 if ( (pos + 1 + len < size) && 310 break;
311 (0 != parseZZZ ((const char *) data, pos + 5, len, ec->proc, ec->cls)) ) 311 case 242: /* zzz4, hurray! */
312 goto CLEANUP; 312 len = getIntAt (&data[pos + 1]);
313 pos += len + 5; 313 if ( (pos + 1 + len < size) &&
314 break; 314 (0 != parseZZZ ((const char *) data, pos + 5, len, ec->proc,
315 default: /* unsupported opcode, abort scan */ 315 ec->cls)) )
316 goto CLEANUP; 316 goto CLEANUP;
317 } 317 pos += len + 5;
318 break;
319 default: /* unsupported opcode, abort scan */
320 goto CLEANUP;
318 } 321 }
319 CLEANUP: 322 }
323CLEANUP:
320 free (data); 324 free (data);
321} 325}
322 326
327
323/* end of dvi_extractor.c */ 328/* end of dvi_extractor.c */
diff --git a/src/plugins/flac_extractor.c b/src/plugins/flac_extractor.c
index 7f04df3..2d36c56 100644
--- a/src/plugins/flac_extractor.c
+++ b/src/plugins/flac_extractor.c
@@ -47,9 +47,9 @@
47 */ 47 */
48static FLAC__StreamDecoderReadStatus 48static FLAC__StreamDecoderReadStatus
49flac_read (const FLAC__StreamDecoder *decoder, 49flac_read (const FLAC__StreamDecoder *decoder,
50 FLAC__byte buffer[], 50 FLAC__byte buffer[],
51 size_t *bytes, 51 size_t *bytes,
52 void *client_data) 52 void *client_data)
53{ 53{
54 struct EXTRACTOR_ExtractContext *ec = client_data; 54 struct EXTRACTOR_ExtractContext *ec = client_data;
55 void *data; 55 void *data;
@@ -57,15 +57,15 @@ flac_read (const FLAC__StreamDecoder *decoder,
57 57
58 data = NULL; 58 data = NULL;
59 ret = ec->read (ec->cls, 59 ret = ec->read (ec->cls,
60 &data, 60 &data,
61 *bytes); 61 *bytes);
62 if (-1 == ret) 62 if (-1 == ret)
63 return FLAC__STREAM_DECODER_READ_STATUS_ABORT; 63 return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
64 if (0 == ret) 64 if (0 == ret)
65 { 65 {
66 errno = 0; 66 errno = 0;
67 return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; 67 return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
68 } 68 }
69 memcpy (buffer, data, ret); 69 memcpy (buffer, data, ret);
70 *bytes = ret; 70 *bytes = ret;
71 errno = 0; 71 errno = 0;
@@ -83,8 +83,8 @@ flac_read (const FLAC__StreamDecoder *decoder,
83 */ 83 */
84static FLAC__StreamDecoderSeekStatus 84static FLAC__StreamDecoderSeekStatus
85flac_seek (const FLAC__StreamDecoder *decoder, 85flac_seek (const FLAC__StreamDecoder *decoder,
86 FLAC__uint64 absolute_byte_offset, 86 FLAC__uint64 absolute_byte_offset,
87 void *client_data) 87 void *client_data)
88{ 88{
89 struct EXTRACTOR_ExtractContext *ec = client_data; 89 struct EXTRACTOR_ExtractContext *ec = client_data;
90 90
@@ -105,14 +105,14 @@ flac_seek (const FLAC__StreamDecoder *decoder,
105 */ 105 */
106static FLAC__StreamDecoderTellStatus 106static FLAC__StreamDecoderTellStatus
107flac_tell (const FLAC__StreamDecoder *decoder, 107flac_tell (const FLAC__StreamDecoder *decoder,
108 FLAC__uint64 *absolute_byte_offset, 108 FLAC__uint64 *absolute_byte_offset,
109 void *client_data) 109 void *client_data)
110{ 110{
111 struct EXTRACTOR_ExtractContext *ec = client_data; 111 struct EXTRACTOR_ExtractContext *ec = client_data;
112 112
113 *absolute_byte_offset = ec->seek (ec->cls, 113 *absolute_byte_offset = ec->seek (ec->cls,
114 0, 114 0,
115 SEEK_CUR); 115 SEEK_CUR);
116 return FLAC__STREAM_DECODER_TELL_STATUS_OK; 116 return FLAC__STREAM_DECODER_TELL_STATUS_OK;
117} 117}
118 118
@@ -127,8 +127,8 @@ flac_tell (const FLAC__StreamDecoder *decoder,
127 */ 127 */
128static FLAC__StreamDecoderLengthStatus 128static FLAC__StreamDecoderLengthStatus
129flac_length (const FLAC__StreamDecoder *decoder, 129flac_length (const FLAC__StreamDecoder *decoder,
130 FLAC__uint64 *stream_length, 130 FLAC__uint64 *stream_length,
131 void *client_data) 131 void *client_data)
132{ 132{
133 struct EXTRACTOR_ExtractContext *ec = client_data; 133 struct EXTRACTOR_ExtractContext *ec = client_data;
134 134
@@ -147,7 +147,7 @@ flac_length (const FLAC__StreamDecoder *decoder,
147 */ 147 */
148static FLAC__bool 148static FLAC__bool
149flac_eof (const FLAC__StreamDecoder *decoder, 149flac_eof (const FLAC__StreamDecoder *decoder,
150 void *client_data) 150 void *client_data)
151{ 151{
152 struct EXTRACTOR_ExtractContext *ec = client_data; 152 struct EXTRACTOR_ExtractContext *ec = client_data;
153 uint64_t size; 153 uint64_t size;
@@ -175,9 +175,9 @@ flac_eof (const FLAC__StreamDecoder *decoder,
175 */ 175 */
176static FLAC__StreamDecoderWriteStatus 176static FLAC__StreamDecoderWriteStatus
177flac_write (const FLAC__StreamDecoder *decoder, 177flac_write (const FLAC__StreamDecoder *decoder,
178 const FLAC__Frame *frame, 178 const FLAC__Frame *frame,
179 const FLAC__int32 *const buffer[], 179 const FLAC__int32 *const buffer[],
180 void *client_data) 180 void *client_data)
181{ 181{
182 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; 182 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
183} 183}
@@ -230,7 +230,8 @@ static struct Matches tmap[] = {
230 * @param t type of the meta data 230 * @param t type of the meta data
231 * @param s meta data value in utf8 format 231 * @param s meta data value in utf8 format
232 */ 232 */
233#define ADD(t,s) do { ec->proc (ec->cls, "flac", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen (s) + 1); } while (0) 233#define ADD(t,s) do { ec->proc (ec->cls, "flac", t, EXTRACTOR_METAFORMAT_UTF8, \
234 "text/plain", s, strlen (s) + 1); } while (0)
234 235
235 236
236/** 237/**
@@ -242,9 +243,9 @@ static struct Matches tmap[] = {
242 */ 243 */
243static char * 244static char *
244xstrndup (const char *s, 245xstrndup (const char *s,
245 size_t n) 246 size_t n)
246{ 247{
247 char * d; 248 char *d;
248 249
249 if (NULL == (d = malloc (n + 1))) 250 if (NULL == (d = malloc (n + 1)))
250 return NULL; 251 return NULL;
@@ -274,21 +275,21 @@ check (const char *type,
274 unsigned int i; 275 unsigned int i;
275 char *tmp; 276 char *tmp;
276 277
277 for (i=0; NULL != tmap[i].text; i++) 278 for (i = 0; NULL != tmap[i].text; i++)
278 { 279 {
279 if ( (type_length != strlen (tmap[i].text)) || 280 if ( (type_length != strlen (tmap[i].text)) ||
280 (0 != strncasecmp (tmap[i].text, 281 (0 != strncasecmp (tmap[i].text,
281 type, 282 type,
282 type_length)) ) 283 type_length)) )
283 continue; 284 continue;
284 if (NULL == 285 if (NULL ==
285 (tmp = xstrndup (value, 286 (tmp = xstrndup (value,
286 value_length))) 287 value_length)))
287 continue; 288 continue;
288 ADD (tmap[i].type, tmp); 289 ADD (tmap[i].type, tmp);
289 free (tmp); 290 free (tmp);
290 break; 291 break;
291 } 292 }
292} 293}
293 294
294 295
@@ -301,117 +302,117 @@ check (const char *type,
301 */ 302 */
302static void 303static void
303flac_metadata (const FLAC__StreamDecoder *decoder, 304flac_metadata (const FLAC__StreamDecoder *decoder,
304 const FLAC__StreamMetadata *metadata, 305 const FLAC__StreamMetadata *metadata,
305 void *client_data) 306 void *client_data)
306{ 307{
307 struct EXTRACTOR_ExtractContext *ec = client_data; 308 struct EXTRACTOR_ExtractContext *ec = client_data;
308 enum EXTRACTOR_MetaType type; 309 enum EXTRACTOR_MetaType type;
309 const FLAC__StreamMetadata_VorbisComment * vc; 310 const FLAC__StreamMetadata_VorbisComment *vc;
310 unsigned int count; 311 unsigned int count;
311 const FLAC__StreamMetadata_VorbisComment_Entry * entry; 312 const FLAC__StreamMetadata_VorbisComment_Entry *entry;
312 const char * eq; 313 const char *eq;
313 unsigned int len; 314 unsigned int len;
314 unsigned int ilen; 315 unsigned int ilen;
315 char buf[128]; 316 char buf[128];
316 317
317 switch (metadata->type) 318 switch (metadata->type)
319 {
320 case FLAC__METADATA_TYPE_STREAMINFO:
318 { 321 {
319 case FLAC__METADATA_TYPE_STREAMINFO: 322 snprintf (buf, sizeof (buf),
320 { 323 _ ("%u Hz, %u channels"),
321 snprintf (buf, sizeof (buf), 324 metadata->data.stream_info.sample_rate,
322 _("%u Hz, %u channels"), 325 metadata->data.stream_info.channels);
323 metadata->data.stream_info.sample_rate, 326 ADD (EXTRACTOR_METATYPE_RESOURCE_TYPE, buf);
324 metadata->data.stream_info.channels);
325 ADD (EXTRACTOR_METATYPE_RESOURCE_TYPE, buf);
326 break;
327 }
328 case FLAC__METADATA_TYPE_APPLICATION:
329 /* FIXME: could find out generator application here:
330 http://flac.sourceforge.net/api/structFLAC____StreamMetadata__Application.html and
331 http://flac.sourceforge.net/id.html
332 */
333 break; 327 break;
334 case FLAC__METADATA_TYPE_VORBIS_COMMENT: 328 }
329 case FLAC__METADATA_TYPE_APPLICATION:
330 /* FIXME: could find out generator application here:
331 http://flac.sourceforge.net/api/structFLAC____StreamMetadata__Application.html and
332 http://flac.sourceforge.net/id.html
333 */
334 break;
335 case FLAC__METADATA_TYPE_VORBIS_COMMENT:
336 {
337 vc = &metadata->data.vorbis_comment;
338 count = vc->num_comments;
339 while (count-- > 0)
335 { 340 {
336 vc = &metadata->data.vorbis_comment; 341 entry = &vc->comments[count];
337 count = vc->num_comments; 342 eq = (const char*) entry->entry;
338 while (count-- > 0) 343 if (NULL == eq)
339 { 344 break;
340 entry = &vc->comments[count]; 345 len = entry->length;
341 eq = (const char*) entry->entry; 346 ilen = 0;
342 if (NULL == eq) 347 while ( ('=' != *eq) && ('\0' != *eq) &&
343 break; 348 (ilen < len) )
344 len = entry->length; 349 {
345 ilen = 0; 350 eq++;
346 while ( ('=' != *eq) && ('\0' != *eq) && 351 ilen++;
347 (ilen < len) ) 352 }
348 { 353 if ( ('=' != *eq) ||
349 eq++; 354 (ilen == len) )
350 ilen++; 355 break;
351 } 356 eq++;
352 if ( ('=' != *eq) || 357 check ((const char*) entry->entry,
353 (ilen == len) ) 358 ilen,
354 break; 359 eq,
355 eq++; 360 len - ilen,
356 check ((const char*) entry->entry, 361 ec);
357 ilen,
358 eq,
359 len - ilen,
360 ec);
361 }
362 break;
363 } 362 }
364 case FLAC__METADATA_TYPE_PICTURE: 363 break;
364 }
365 case FLAC__METADATA_TYPE_PICTURE:
366 {
367 switch (metadata->data.picture.type)
365 { 368 {
366 switch (metadata->data.picture.type) 369 case FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER:
367 { 370 case FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD:
368 case FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER: 371 case FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON:
369 case FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD: 372 type = EXTRACTOR_METATYPE_THUMBNAIL;
370 case FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON: 373 break;
371 type = EXTRACTOR_METATYPE_THUMBNAIL; 374 case FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER:
372 break; 375 case FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER:
373 case FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER: 376 type = EXTRACTOR_METATYPE_COVER_PICTURE;
374 case FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER: 377 break;
375 type = EXTRACTOR_METATYPE_COVER_PICTURE; 378 case FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST:
376 break; 379 case FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST:
377 case FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST: 380 case FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR:
378 case FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST: 381 case FLAC__STREAM_METADATA_PICTURE_TYPE_BAND:
379 case FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR: 382 case FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER:
380 case FLAC__STREAM_METADATA_PICTURE_TYPE_BAND: 383 case FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST:
381 case FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER: 384 type = EXTRACTOR_METATYPE_CONTRIBUTOR_PICTURE;
382 case FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST: 385 break;
383 type = EXTRACTOR_METATYPE_CONTRIBUTOR_PICTURE; 386 case FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION:
384 break; 387 case FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING:
385 case FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION: 388 case FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE:
386 case FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING: 389 case FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE:
387 case FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE: 390 type = EXTRACTOR_METATYPE_EVENT_PICTURE;
388 case FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE: 391 break;
389 type = EXTRACTOR_METATYPE_EVENT_PICTURE; 392 case FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE:
390 break; 393 case FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE:
391 case FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE: 394 type = EXTRACTOR_METATYPE_LOGO;
392 case FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE: 395 break;
393 type = EXTRACTOR_METATYPE_LOGO; 396 case FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE:
394 break; 397 case FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA:
395 case FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE: 398 case FLAC__STREAM_METADATA_PICTURE_TYPE_FISH:
396 case FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA: 399 case FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION:
397 case FLAC__STREAM_METADATA_PICTURE_TYPE_FISH: 400 default:
398 case FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION: 401 type = EXTRACTOR_METATYPE_PICTURE;
399 default: 402 break;
400 type = EXTRACTOR_METATYPE_PICTURE;
401 break;
402 }
403 ec->proc (ec->cls,
404 "flac",
405 type,
406 EXTRACTOR_METAFORMAT_BINARY,
407 metadata->data.picture.mime_type,
408 (const char*) metadata->data.picture.data,
409 metadata->data.picture.data_length);
410 break;
411 } 403 }
412 default: 404 ec->proc (ec->cls,
405 "flac",
406 type,
407 EXTRACTOR_METAFORMAT_BINARY,
408 metadata->data.picture.mime_type,
409 (const char*) metadata->data.picture.data,
410 metadata->data.picture.data_length);
413 break; 411 break;
414 } 412 }
413 default:
414 break;
415 }
415} 416}
416 417
417 418
@@ -424,8 +425,8 @@ flac_metadata (const FLAC__StreamDecoder *decoder,
424 */ 425 */
425static void 426static void
426flac_error (const FLAC__StreamDecoder *decoder, 427flac_error (const FLAC__StreamDecoder *decoder,
427 FLAC__StreamDecoderErrorStatus status, 428 FLAC__StreamDecoderErrorStatus status,
428 void *client_data) 429 void *client_data)
429{ 430{
430 /* ignore errors */ 431 /* ignore errors */
431} 432}
@@ -439,55 +440,57 @@ flac_error (const FLAC__StreamDecoder *decoder,
439void 440void
440EXTRACTOR_flac_extract_method (struct EXTRACTOR_ExtractContext *ec) 441EXTRACTOR_flac_extract_method (struct EXTRACTOR_ExtractContext *ec)
441{ 442{
442 FLAC__StreamDecoder * decoder; 443 FLAC__StreamDecoder *decoder;
443 444
444 if (NULL == (decoder = FLAC__stream_decoder_new ())) 445 if (NULL == (decoder = FLAC__stream_decoder_new ()))
445 return; 446 return;
446 FLAC__stream_decoder_set_md5_checking (decoder, false); 447 FLAC__stream_decoder_set_md5_checking (decoder, false);
447 FLAC__stream_decoder_set_metadata_ignore_all (decoder); 448 FLAC__stream_decoder_set_metadata_ignore_all (decoder);
448 if (false == FLAC__stream_decoder_set_metadata_respond_all (decoder)) 449 if (false == FLAC__stream_decoder_set_metadata_respond_all (decoder))
449 { 450 {
450 FLAC__stream_decoder_delete (decoder); 451 FLAC__stream_decoder_delete (decoder);
451 return; 452 return;
452 } 453 }
453 if (FLAC__STREAM_DECODER_INIT_STATUS_OK != 454 if (FLAC__STREAM_DECODER_INIT_STATUS_OK !=
454 FLAC__stream_decoder_init_stream (decoder, 455 FLAC__stream_decoder_init_stream (decoder,
455 &flac_read, 456 &flac_read,
456 &flac_seek, 457 &flac_seek,
457 &flac_tell, 458 &flac_tell,
458 &flac_length, 459 &flac_length,
459 &flac_eof, 460 &flac_eof,
460 &flac_write, 461 &flac_write,
461 &flac_metadata, 462 &flac_metadata,
462 &flac_error, 463 &flac_error,
463 ec)) 464 ec))
464 { 465 {
465 FLAC__stream_decoder_delete (decoder); 466 FLAC__stream_decoder_delete (decoder);
466 return; 467 return;
467 } 468 }
468 if (FLAC__STREAM_DECODER_SEARCH_FOR_METADATA != FLAC__stream_decoder_get_state(decoder)) 469 if (FLAC__STREAM_DECODER_SEARCH_FOR_METADATA !=
469 { 470 FLAC__stream_decoder_get_state (decoder))
470 FLAC__stream_decoder_delete (decoder); 471 {
471 return; 472 FLAC__stream_decoder_delete (decoder);
472 } 473 return;
473 if (! FLAC__stream_decoder_process_until_end_of_metadata(decoder)) 474 }
474 { 475 if (! FLAC__stream_decoder_process_until_end_of_metadata (decoder))
475 FLAC__stream_decoder_delete (decoder); 476 {
476 return; 477 FLAC__stream_decoder_delete (decoder);
477 } 478 return;
479 }
478 switch (FLAC__stream_decoder_get_state (decoder)) 480 switch (FLAC__stream_decoder_get_state (decoder))
479 { 481 {
480 case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC: 482 case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
481 case FLAC__STREAM_DECODER_READ_METADATA: 483 case FLAC__STREAM_DECODER_READ_METADATA:
482 case FLAC__STREAM_DECODER_END_OF_STREAM: 484 case FLAC__STREAM_DECODER_END_OF_STREAM:
483 case FLAC__STREAM_DECODER_READ_FRAME: 485 case FLAC__STREAM_DECODER_READ_FRAME:
484 break; 486 break;
485 default: 487 default:
486 /* not so sure... */ 488 /* not so sure... */
487 break; 489 break;
488 } 490 }
489 FLAC__stream_decoder_finish (decoder); 491 FLAC__stream_decoder_finish (decoder);
490 FLAC__stream_decoder_delete (decoder); 492 FLAC__stream_decoder_delete (decoder);
491} 493}
492 494
495
493/* end of flac_extractor.c */ 496/* end of flac_extractor.c */
diff --git a/src/plugins/gif_extractor.c b/src/plugins/gif_extractor.c
index 8ee5807..405eebe 100644
--- a/src/plugins/gif_extractor.c
+++ b/src/plugins/gif_extractor.c
@@ -37,16 +37,16 @@
37 */ 37 */
38static int 38static int
39gif_read_func (GifFileType *ft, 39gif_read_func (GifFileType *ft,
40 GifByteType *bt, 40 GifByteType *bt,
41 int arg) 41 int arg)
42{ 42{
43 struct EXTRACTOR_ExtractContext *ec = ft->UserData; 43 struct EXTRACTOR_ExtractContext *ec = ft->UserData;
44 void *data; 44 void *data;
45 ssize_t ret; 45 ssize_t ret;
46 46
47 ret = ec->read (ec->cls, 47 ret = ec->read (ec->cls,
48 &data, 48 &data,
49 arg); 49 arg);
50 if (-1 == ret) 50 if (-1 == ret)
51 return -1; 51 return -1;
52 memcpy (bt, data, ret); 52 memcpy (bt, data, ret);
@@ -75,7 +75,7 @@ EXTRACTOR_gif_extract_method (struct EXTRACTOR_ExtractContext *ec)
75 75
76 gif_error = 0; 76 gif_error = 0;
77 gif_file = DGifOpen (ec, &gif_read_func, &gif_error); 77 gif_file = DGifOpen (ec, &gif_read_func, &gif_error);
78 if (gif_file == NULL || gif_error != 0) 78 if ((gif_file == NULL) || (gif_error != 0))
79 { 79 {
80 if (gif_file != NULL) 80 if (gif_file != NULL)
81#if GIFLIB_MAJOR < 5 || GIFLIB_MINOR < 1 81#if GIFLIB_MAJOR < 5 || GIFLIB_MINOR < 1
@@ -88,57 +88,58 @@ EXTRACTOR_gif_extract_method (struct EXTRACTOR_ExtractContext *ec)
88#endif 88#endif
89 if (0 != 89 if (0 !=
90 ec->proc (ec->cls, 90 ec->proc (ec->cls,
91 "gif", 91 "gif",
92 EXTRACTOR_METATYPE_MIMETYPE, 92 EXTRACTOR_METATYPE_MIMETYPE,
93 EXTRACTOR_METAFORMAT_UTF8, 93 EXTRACTOR_METAFORMAT_UTF8,
94 "text/plain", 94 "text/plain",
95 "image/gif", 95 "image/gif",
96 strlen ("image/gif") + 1)) 96 strlen ("image/gif") + 1))
97 return; 97 return;
98 snprintf (dims, 98 snprintf (dims,
99 sizeof (dims), 99 sizeof (dims),
100 "%dx%d", 100 "%dx%d",
101 gif_file->SHeight, 101 gif_file->SHeight,
102 gif_file->SWidth); 102 gif_file->SWidth);
103 if (0 != 103 if (0 !=
104 ec->proc (ec->cls, 104 ec->proc (ec->cls,
105 "gif", 105 "gif",
106 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, 106 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
107 EXTRACTOR_METAFORMAT_UTF8, 107 EXTRACTOR_METAFORMAT_UTF8,
108 "text/plain", 108 "text/plain",
109 dims, 109 dims,
110 strlen (dims) + 1)) 110 strlen (dims) + 1))
111 return; 111 return;
112 while (1) 112 while (1)
113 {
114 if (GIF_OK !=
115 DGifGetRecordType (gif_file,
116 &gif_type))
117 break;
118 if (UNDEFINED_RECORD_TYPE == gif_type)
119 break;
120 if (EXTENSION_RECORD_TYPE != gif_type)
121 continue;
122 if (GIF_OK !=
123 DGifGetExtension (gif_file, &et, &ext))
124 continue;
125 if (NULL == ext)
126 continue;
127 if (COMMENT_EXT_FUNC_CODE == et)
113 { 128 {
114 if (GIF_OK != 129 ec->proc (ec->cls,
115 DGifGetRecordType (gif_file, 130 "gif",
116 &gif_type)) 131 EXTRACTOR_METATYPE_COMMENT,
117 break; 132 EXTRACTOR_METAFORMAT_C_STRING,
118 if (UNDEFINED_RECORD_TYPE == gif_type) 133 "text/plain",
119 break; 134 (char*) &ext[1],
120 if (EXTENSION_RECORD_TYPE != gif_type) 135 (uint8_t) ext[0]);
121 continue; 136 break;
122 if (GIF_OK !=
123 DGifGetExtension (gif_file, &et, &ext))
124 continue;
125 if (NULL == ext)
126 continue;
127 if (COMMENT_EXT_FUNC_CODE == et)
128 {
129 ec->proc (ec->cls,
130 "gif",
131 EXTRACTOR_METATYPE_COMMENT,
132 EXTRACTOR_METAFORMAT_C_STRING,
133 "text/plain",
134 (char*) &ext[1],
135 (uint8_t) ext[0]);
136 break;
137 }
138 while ( (GIF_ERROR !=
139 DGifGetExtensionNext(gif_file, &ext)) &&
140 (NULL != ext) ) ; /* keep going */
141 } 137 }
138 while ( (GIF_ERROR !=
139 DGifGetExtensionNext (gif_file, &ext)) &&
140 (NULL != ext) )
141 ; /* keep going */
142 }
142#if defined (GIF_LIB_VERSION) || GIFLIB_MAJOR < 5 || GIFLIB_MINOR < 1 143#if defined (GIF_LIB_VERSION) || GIFLIB_MAJOR < 5 || GIFLIB_MINOR < 1
143 DGifCloseFile (gif_file); 144 DGifCloseFile (gif_file);
144#else 145#else
@@ -146,4 +147,5 @@ EXTRACTOR_gif_extract_method (struct EXTRACTOR_ExtractContext *ec)
146#endif 147#endif
147} 148}
148 149
150
149/* end of gif_extractor.c */ 151/* end of gif_extractor.c */
diff --git a/src/plugins/gstreamer_extractor.c b/src/plugins/gstreamer_extractor.c
index 31568a7..87f0153 100644
--- a/src/plugins/gstreamer_extractor.c
+++ b/src/plugins/gstreamer_extractor.c
@@ -64,8 +64,7 @@ struct KnownTag
64/** 64/**
65 * Struct mapping known tags (that do occur in GST API) to LE tags. 65 * Struct mapping known tags (that do occur in GST API) to LE tags.
66 */ 66 */
67static struct KnownTag __known_tags[] = 67static struct KnownTag __known_tags[] = {
68{
69 /** 68 /**
70 * GST_TAG_TITLE: 69 * GST_TAG_TITLE:
71 * 70 *
@@ -562,7 +561,8 @@ static struct KnownTag __known_tags[] =
562 * Represents the expected error on the horizontal positioning in 561 * Represents the expected error on the horizontal positioning in
563 * meters (double). 562 * meters (double).
564 */ 563 */
565 {GST_TAG_GEO_LOCATION_HORIZONTAL_ERROR, EXTRACTOR_METATYPE_LOCATION_HORIZONTAL_ERROR}, 564 {GST_TAG_GEO_LOCATION_HORIZONTAL_ERROR,
565 EXTRACTOR_METATYPE_LOCATION_HORIZONTAL_ERROR},
566 566
567 /** 567 /**
568 * GST_TAG_GEO_LOCATION_MOVEMENT_SPEED: 568 * GST_TAG_GEO_LOCATION_MOVEMENT_SPEED:
@@ -572,7 +572,8 @@ static struct KnownTag __known_tags[] =
572 * 572 *
573 * See also #GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION 573 * See also #GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION
574 */ 574 */
575 {GST_TAG_GEO_LOCATION_MOVEMENT_SPEED, EXTRACTOR_METATYPE_LOCATION_MOVEMENT_SPEED}, 575 {GST_TAG_GEO_LOCATION_MOVEMENT_SPEED,
576 EXTRACTOR_METATYPE_LOCATION_MOVEMENT_SPEED},
576 577
577 /** 578 /**
578 * GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION: 579 * GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION:
@@ -583,7 +584,8 @@ static struct KnownTag __known_tags[] =
583 * 584 *
584 * See also #GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION 585 * See also #GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION
585 */ 586 */
586 {GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION, EXTRACTOR_METATYPE_LOCATION_MOVEMENT_DIRECTION}, 587 {GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION,
588 EXTRACTOR_METATYPE_LOCATION_MOVEMENT_DIRECTION},
587 589
588 /** 590 /**
589 * GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION: 591 * GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION:
@@ -594,7 +596,8 @@ static struct KnownTag __known_tags[] =
594 * 596 *
595 * See also #GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION 597 * See also #GST_TAG_GEO_LOCATION_MOVEMENT_DIRECTION
596 */ 598 */
597 {GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION, EXTRACTOR_METATYPE_LOCATION_CAPTURE_DIRECTION}, 599 {GST_TAG_GEO_LOCATION_CAPTURE_DIRECTION,
600 EXTRACTOR_METATYPE_LOCATION_CAPTURE_DIRECTION},
598 601
599 /** 602 /**
600 * GST_TAG_SHOW_NAME: 603 * GST_TAG_SHOW_NAME:
@@ -735,23 +738,22 @@ struct NamedTag
735 * Mapping from GST tag names to LE types for tags that are not in 738 * Mapping from GST tag names to LE types for tags that are not in
736 * the public GST API. 739 * the public GST API.
737 */ 740 */
738struct NamedTag named_tags[] = 741struct NamedTag named_tags[] = {
739 { 742 { "FPS", EXTRACTOR_METATYPE_FRAME_RATE },
740 { "FPS", EXTRACTOR_METATYPE_FRAME_RATE }, 743 { "PLAY_COUNTER", EXTRACTOR_METATYPE_PLAY_COUNTER },
741 { "PLAY_COUNTER", EXTRACTOR_METATYPE_PLAY_COUNTER }, 744 { "RATING", EXTRACTOR_METATYPE_RATING },
742 { "RATING", EXTRACTOR_METATYPE_RATING }, 745 { "SUMMARY", EXTRACTOR_METATYPE_SUMMARY },
743 { "SUMMARY", EXTRACTOR_METATYPE_SUMMARY }, 746 { "SUBJECT", EXTRACTOR_METATYPE_SUBJECT },
744 { "SUBJECT", EXTRACTOR_METATYPE_SUBJECT }, 747 { "MOOD", EXTRACTOR_METATYPE_MOOD },
745 { "MOOD", EXTRACTOR_METATYPE_MOOD }, 748 { "LEAD_PERFORMER", EXTRACTOR_METATYPE_PERFORMER },
746 { "LEAD_PERFORMER", EXTRACTOR_METATYPE_PERFORMER }, 749 { "DIRECTOR", EXTRACTOR_METATYPE_MOVIE_DIRECTOR },
747 { "DIRECTOR", EXTRACTOR_METATYPE_MOVIE_DIRECTOR }, 750 { "WRITTEN_BY", EXTRACTOR_METATYPE_WRITER },
748 { "WRITTEN_BY", EXTRACTOR_METATYPE_WRITER }, 751 { "PRODUCER", EXTRACTOR_METATYPE_PRODUCER },
749 { "PRODUCER", EXTRACTOR_METATYPE_PRODUCER }, 752 { "PUBLISHER", EXTRACTOR_METATYPE_PUBLISHER },
750 { "PUBLISHER", EXTRACTOR_METATYPE_PUBLISHER }, 753 { "ORIGINAL/ARTIST", EXTRACTOR_METATYPE_ORIGINAL_ARTIST },
751 { "ORIGINAL/ARTIST", EXTRACTOR_METATYPE_ORIGINAL_ARTIST }, 754 { "ORIGINAL/TITLE", EXTRACTOR_METATYPE_ORIGINAL_TITLE },
752 { "ORIGINAL/TITLE", EXTRACTOR_METATYPE_ORIGINAL_TITLE }, 755 { NULL, EXTRACTOR_METATYPE_UNKNOWN }
753 { NULL, EXTRACTOR_METATYPE_UNKNOWN } 756};
754 };
755 757
756 758
757/** 759/**
@@ -914,9 +916,9 @@ _data_timeout (struct PrivStruct *ps)
914 * @param ps our execution context 916 * @param ps our execution context
915 */ 917 */
916static void 918static void
917feed_data (GstElement * appsrc, 919feed_data (GstElement *appsrc,
918 guint size, 920 guint size,
919 struct PrivStruct * ps) 921 struct PrivStruct *ps)
920{ 922{
921 ssize_t data_len; 923 ssize_t data_len;
922 uint8_t *le_data; 924 uint8_t *le_data;
@@ -929,7 +931,8 @@ feed_data (GstElement * appsrc,
929 931
930 if (ps->timeout_id > 0) 932 if (ps->timeout_id > 0)
931 g_source_remove (ps->timeout_id); 933 g_source_remove (ps->timeout_id);
932 ps->timeout_id = g_timeout_add (DATA_TIMEOUT, (GSourceFunc) _data_timeout, ps); 934 ps->timeout_id = g_timeout_add (DATA_TIMEOUT, (GSourceFunc) _data_timeout,
935 ps);
933 936
934 if ( (ps->length > 0) && (ps->offset >= ps->length) ) 937 if ( (ps->length > 0) && (ps->offset >= ps->length) )
935 { 938 {
@@ -938,11 +941,11 @@ feed_data (GstElement * appsrc,
938 return; 941 return;
939 } 942 }
940 943
941 if (ps->length > 0 && ps->offset + size > ps->length) 944 if ((ps->length > 0) && (ps->offset + size > ps->length))
942 size = ps->length - ps->offset; 945 size = ps->length - ps->offset;
943 946
944 mem = gst_allocator_alloc (NULL, size, NULL); 947 mem = gst_allocator_alloc (NULL, size, NULL);
945 if (!gst_memory_map (mem, &mi, GST_MAP_WRITE)) 948 if (! gst_memory_map (mem, &mi, GST_MAP_WRITE))
946 { 949 {
947 gst_memory_unref (mem); 950 gst_memory_unref (mem);
948 GST_DEBUG ("Failed to map the memory"); 951 GST_DEBUG ("Failed to map the memory");
@@ -955,7 +958,8 @@ feed_data (GstElement * appsrc,
955 pthread_mutex_lock (&pipe_mutex); 958 pthread_mutex_lock (&pipe_mutex);
956 while ( (accumulated < size) && (data_len > 0) ) 959 while ( (accumulated < size) && (data_len > 0) )
957 { 960 {
958 data_len = ps->ec->read (ps->ec->cls, (void **) &le_data, size - accumulated); 961 data_len = ps->ec->read (ps->ec->cls, (void **) &le_data, size
962 - accumulated);
959 if (data_len > 0) 963 if (data_len > 0)
960 { 964 {
961 memcpy (&mi.data[accumulated], le_data, data_len); 965 memcpy (&mi.data[accumulated], le_data, data_len);
@@ -974,7 +978,7 @@ feed_data (GstElement * appsrc,
974 GST_BUFFER_OFFSET_END (buffer) = ps->offset + size; 978 GST_BUFFER_OFFSET_END (buffer) = ps->offset + size;
975 979
976 GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", 980 GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u",
977 buffer, ps->offset, size); 981 buffer, ps->offset, size);
978 gst_app_src_push_buffer (GST_APP_SRC (ps->source), buffer); 982 gst_app_src_push_buffer (GST_APP_SRC (ps->source), buffer);
979 ps->offset += size; 983 ps->offset += size;
980 } 984 }
@@ -987,7 +991,8 @@ feed_data (GstElement * appsrc,
987 991
988 if (ps->timeout_id > 0) 992 if (ps->timeout_id > 0)
989 g_source_remove (ps->timeout_id); 993 g_source_remove (ps->timeout_id);
990 ps->timeout_id = g_timeout_add (DATA_TIMEOUT, (GSourceFunc) _data_timeout, ps); 994 ps->timeout_id = g_timeout_add (DATA_TIMEOUT, (GSourceFunc) _data_timeout,
995 ps);
991} 996}
992 997
993 998
@@ -1001,9 +1006,9 @@ feed_data (GstElement * appsrc,
1001 * @return TRUE if seeking succeeded, FALSE if not 1006 * @return TRUE if seeking succeeded, FALSE if not
1002 */ 1007 */
1003static gboolean 1008static gboolean
1004seek_data (GstElement * appsrc, 1009seek_data (GstElement *appsrc,
1005 guint64 position, 1010 guint64 position,
1006 struct PrivStruct * ps) 1011 struct PrivStruct *ps)
1007{ 1012{
1008 GST_DEBUG ("seek to offset %" G_GUINT64_FORMAT, position); 1013 GST_DEBUG ("seek to offset %" G_GUINT64_FORMAT, position);
1009 pthread_mutex_lock (&pipe_mutex); 1014 pthread_mutex_lock (&pipe_mutex);
@@ -1011,7 +1016,8 @@ seek_data (GstElement * appsrc,
1011 pthread_mutex_unlock (&pipe_mutex); 1016 pthread_mutex_unlock (&pipe_mutex);
1012 if (ps->timeout_id > 0) 1017 if (ps->timeout_id > 0)
1013 g_source_remove (ps->timeout_id); 1018 g_source_remove (ps->timeout_id);
1014 ps->timeout_id = g_timeout_add (DATA_TIMEOUT, (GSourceFunc) _data_timeout, ps); 1019 ps->timeout_id = g_timeout_add (DATA_TIMEOUT, (GSourceFunc) _data_timeout,
1020 ps);
1015 return ps->offset == position; 1021 return ps->offset == position;
1016} 1022}
1017 1023
@@ -1026,8 +1032,8 @@ seek_data (GstElement * appsrc,
1026 */ 1032 */
1027static gboolean 1033static gboolean
1028send_structure_foreach (GQuark field_id, 1034send_structure_foreach (GQuark field_id,
1029 const GValue *value, 1035 const GValue *value,
1030 gpointer user_data) 1036 gpointer user_data)
1031{ 1037{
1032 struct PrivStruct *ps = user_data; 1038 struct PrivStruct *ps = user_data;
1033 gchar *str; 1039 gchar *str;
@@ -1095,20 +1101,21 @@ send_structure_foreach (GQuark field_id,
1095 { 1101 {
1096 unsigned int i; 1102 unsigned int i;
1097 1103
1098 for (i=0; NULL != named_tags[i].tag; i++) 1104 for (i = 0; NULL != named_tags[i].tag; i++)
1099 if (0 == strcmp (named_tags[i].tag, field_name)) 1105 if (0 == strcmp (named_tags[i].tag, field_name))
1100 { 1106 {
1101 ps->time_to_leave = ps->ec->proc (ps->ec->cls, "gstreamer", 1107 ps->time_to_leave = ps->ec->proc (ps->ec->cls, "gstreamer",
1102 named_tags[i].le_type, 1108 named_tags[i].le_type,
1103 EXTRACTOR_METAFORMAT_UTF8, "text/plain", 1109 EXTRACTOR_METAFORMAT_UTF8,
1104 (const char *) str, strlen (str) + 1); 1110 "text/plain",
1105 if (NULL != str) 1111 (const char *) str, strlen (str) + 1);
1106 { 1112 if (NULL != str)
1107 g_free (str); 1113 {
1108 str = NULL; 1114 g_free (str);
1109 } 1115 str = NULL;
1110 break; 1116 }
1111 } 1117 break;
1118 }
1112 } 1119 }
1113 if (NULL != str) 1120 if (NULL != str)
1114 { 1121 {
@@ -1116,16 +1123,16 @@ send_structure_foreach (GQuark field_id,
1116 field_name, 1123 field_name,
1117 str); 1124 str);
1118 if (NULL != senddata) 1125 if (NULL != senddata)
1119 { 1126 {
1120 ps->time_to_leave = ps->ec->proc (ps->ec->cls, 1127 ps->time_to_leave = ps->ec->proc (ps->ec->cls,
1121 "gstreamer", 1128 "gstreamer",
1122 EXTRACTOR_METATYPE_UNKNOWN, 1129 EXTRACTOR_METATYPE_UNKNOWN,
1123 EXTRACTOR_METAFORMAT_UTF8, 1130 EXTRACTOR_METAFORMAT_UTF8,
1124 "text/plain", 1131 "text/plain",
1125 (const char *) senddata, 1132 (const char *) senddata,
1126 strlen (senddata) + 1); 1133 strlen (senddata) + 1);
1127 g_free (senddata); 1134 g_free (senddata);
1128 } 1135 }
1129 } 1136 }
1130 if (NULL != str) 1137 if (NULL != str)
1131 g_free (str); 1138 g_free (str);
@@ -1143,7 +1150,7 @@ send_structure_foreach (GQuark field_id,
1143 */ 1150 */
1144static gboolean 1151static gboolean
1145send_audio_info (GstDiscovererAudioInfo *info, 1152send_audio_info (GstDiscovererAudioInfo *info,
1146 struct PrivStruct *ps) 1153 struct PrivStruct *ps)
1147{ 1154{
1148 gchar *tmp; 1155 gchar *tmp;
1149 const gchar *ctmp; 1156 const gchar *ctmp;
@@ -1152,10 +1159,11 @@ send_audio_info (GstDiscovererAudioInfo *info,
1152 ctmp = gst_discoverer_audio_info_get_language (info); 1159 ctmp = gst_discoverer_audio_info_get_language (info);
1153 if (ctmp) 1160 if (ctmp)
1154 if ((ps->time_to_leave = ps->ec->proc (ps->ec->cls, "gstreamer", 1161 if ((ps->time_to_leave = ps->ec->proc (ps->ec->cls, "gstreamer",
1155 EXTRACTOR_METATYPE_AUDIO_LANGUAGE, 1162 EXTRACTOR_METATYPE_AUDIO_LANGUAGE,
1156 EXTRACTOR_METAFORMAT_UTF8, 1163 EXTRACTOR_METAFORMAT_UTF8,
1157 "text/plain", 1164 "text/plain",
1158 (const char *) ctmp, strlen (ctmp) + 1))) 1165 (const char *) ctmp, strlen (ctmp)
1166 + 1)))
1159 return TRUE; 1167 return TRUE;
1160 1168
1161 u = gst_discoverer_audio_info_get_channels (info); 1169 u = gst_discoverer_audio_info_get_channels (info);
@@ -1163,16 +1171,16 @@ send_audio_info (GstDiscovererAudioInfo *info,
1163 { 1171 {
1164 tmp = g_strdup_printf ("%u", u); 1172 tmp = g_strdup_printf ("%u", u);
1165 if (NULL != tmp) 1173 if (NULL != tmp)
1166 { 1174 {
1167 ps->time_to_leave = ps->ec->proc (ps->ec->cls, 1175 ps->time_to_leave = ps->ec->proc (ps->ec->cls,
1168 "gstreamer", 1176 "gstreamer",
1169 EXTRACTOR_METATYPE_CHANNELS, 1177 EXTRACTOR_METATYPE_CHANNELS,
1170 EXTRACTOR_METAFORMAT_UTF8, 1178 EXTRACTOR_METAFORMAT_UTF8,
1171 "text/plain", 1179 "text/plain",
1172 (const char *) tmp, 1180 (const char *) tmp,
1173 strlen (tmp) + 1); 1181 strlen (tmp) + 1);
1174 g_free (tmp); 1182 g_free (tmp);
1175 } 1183 }
1176 if (ps->time_to_leave) 1184 if (ps->time_to_leave)
1177 return TRUE; 1185 return TRUE;
1178 } 1186 }
@@ -1182,16 +1190,16 @@ send_audio_info (GstDiscovererAudioInfo *info,
1182 { 1190 {
1183 tmp = g_strdup_printf ("%u", u); 1191 tmp = g_strdup_printf ("%u", u);
1184 if (NULL != tmp) 1192 if (NULL != tmp)
1185 { 1193 {
1186 ps->time_to_leave = ps->ec->proc (ps->ec->cls, 1194 ps->time_to_leave = ps->ec->proc (ps->ec->cls,
1187 "gstreamer", 1195 "gstreamer",
1188 EXTRACTOR_METATYPE_SAMPLE_RATE, 1196 EXTRACTOR_METATYPE_SAMPLE_RATE,
1189 EXTRACTOR_METAFORMAT_UTF8, 1197 EXTRACTOR_METAFORMAT_UTF8,
1190 "text/plain", 1198 "text/plain",
1191 (const char *) tmp, 1199 (const char *) tmp,
1192 strlen (tmp) + 1); 1200 strlen (tmp) + 1);
1193 g_free (tmp); 1201 g_free (tmp);
1194 } 1202 }
1195 if (ps->time_to_leave) 1203 if (ps->time_to_leave)
1196 return TRUE; 1204 return TRUE;
1197 } 1205 }
@@ -1201,16 +1209,16 @@ send_audio_info (GstDiscovererAudioInfo *info,
1201 { 1209 {
1202 tmp = g_strdup_printf ("%u", u); 1210 tmp = g_strdup_printf ("%u", u);
1203 if (NULL != tmp) 1211 if (NULL != tmp)
1204 { 1212 {
1205 ps->time_to_leave = ps->ec->proc (ps->ec->cls, 1213 ps->time_to_leave = ps->ec->proc (ps->ec->cls,
1206 "gstreamer", 1214 "gstreamer",
1207 EXTRACTOR_METATYPE_AUDIO_DEPTH, 1215 EXTRACTOR_METATYPE_AUDIO_DEPTH,
1208 EXTRACTOR_METAFORMAT_UTF8, 1216 EXTRACTOR_METAFORMAT_UTF8,
1209 "text/plain", 1217 "text/plain",
1210 (const char *) tmp, 1218 (const char *) tmp,
1211 strlen (tmp) + 1); 1219 strlen (tmp) + 1);
1212 g_free (tmp); 1220 g_free (tmp);
1213 } 1221 }
1214 if (ps->time_to_leave) 1222 if (ps->time_to_leave)
1215 return TRUE; 1223 return TRUE;
1216 } 1224 }
@@ -1220,16 +1228,16 @@ send_audio_info (GstDiscovererAudioInfo *info,
1220 { 1228 {
1221 tmp = g_strdup_printf ("%u", u); 1229 tmp = g_strdup_printf ("%u", u);
1222 if (NULL != tmp) 1230 if (NULL != tmp)
1223 { 1231 {
1224 ps->time_to_leave = ps->ec->proc (ps->ec->cls, 1232 ps->time_to_leave = ps->ec->proc (ps->ec->cls,
1225 "gstreamer", 1233 "gstreamer",
1226 EXTRACTOR_METATYPE_AUDIO_BITRATE, 1234 EXTRACTOR_METATYPE_AUDIO_BITRATE,
1227 EXTRACTOR_METAFORMAT_UTF8, 1235 EXTRACTOR_METAFORMAT_UTF8,
1228 "text/plain", 1236 "text/plain",
1229 (const char *) tmp, 1237 (const char *) tmp,
1230 strlen (tmp) + 1); 1238 strlen (tmp) + 1);
1231 g_free (tmp); 1239 g_free (tmp);
1232 } 1240 }
1233 if (ps->time_to_leave) 1241 if (ps->time_to_leave)
1234 return TRUE; 1242 return TRUE;
1235 } 1243 }
@@ -1239,16 +1247,16 @@ send_audio_info (GstDiscovererAudioInfo *info,
1239 { 1247 {
1240 tmp = g_strdup_printf ("%u", u); 1248 tmp = g_strdup_printf ("%u", u);
1241 if (NULL != tmp) 1249 if (NULL != tmp)
1242 { 1250 {
1243 ps->time_to_leave = ps->ec->proc (ps->ec->cls, 1251 ps->time_to_leave = ps->ec->proc (ps->ec->cls,
1244 "gstreamer", 1252 "gstreamer",
1245 EXTRACTOR_METATYPE_MAXIMUM_AUDIO_BITRATE, 1253 EXTRACTOR_METATYPE_MAXIMUM_AUDIO_BITRATE,
1246 EXTRACTOR_METAFORMAT_UTF8, 1254 EXTRACTOR_METAFORMAT_UTF8,
1247 "text/plain", 1255 "text/plain",
1248 (const char *) tmp, 1256 (const char *) tmp,
1249 strlen (tmp) + 1); 1257 strlen (tmp) + 1);
1250 g_free (tmp); 1258 g_free (tmp);
1251 } 1259 }
1252 if (ps->time_to_leave) 1260 if (ps->time_to_leave)
1253 return TRUE; 1261 return TRUE;
1254 } 1262 }
@@ -1266,7 +1274,7 @@ send_audio_info (GstDiscovererAudioInfo *info,
1266 */ 1274 */
1267static int 1275static int
1268send_video_info (GstDiscovererVideoInfo *info, 1276send_video_info (GstDiscovererVideoInfo *info,
1269 struct PrivStruct *ps) 1277 struct PrivStruct *ps)
1270{ 1278{
1271 gchar *tmp; 1279 gchar *tmp;
1272 guint u; 1280 guint u;
@@ -1278,16 +1286,16 @@ send_video_info (GstDiscovererVideoInfo *info,
1278 { 1286 {
1279 tmp = g_strdup_printf ("%ux%u", u, u2); 1287 tmp = g_strdup_printf ("%ux%u", u, u2);
1280 if (NULL != tmp) 1288 if (NULL != tmp)
1281 { 1289 {
1282 ps->time_to_leave = ps->ec->proc (ps->ec->cls, 1290 ps->time_to_leave = ps->ec->proc (ps->ec->cls,
1283 "gstreamer", 1291 "gstreamer",
1284 EXTRACTOR_METATYPE_VIDEO_DIMENSIONS, 1292 EXTRACTOR_METATYPE_VIDEO_DIMENSIONS,
1285 EXTRACTOR_METAFORMAT_UTF8, 1293 EXTRACTOR_METAFORMAT_UTF8,
1286 "text/plain", 1294 "text/plain",
1287 (const char *) tmp, 1295 (const char *) tmp,
1288 strlen (tmp) + 1); 1296 strlen (tmp) + 1);
1289 g_free (tmp); 1297 g_free (tmp);
1290 } 1298 }
1291 if (ps->time_to_leave) 1299 if (ps->time_to_leave)
1292 return TRUE; 1300 return TRUE;
1293 } 1301 }
@@ -1297,16 +1305,16 @@ send_video_info (GstDiscovererVideoInfo *info,
1297 { 1305 {
1298 tmp = g_strdup_printf ("%u", u); 1306 tmp = g_strdup_printf ("%u", u);
1299 if (NULL != tmp) 1307 if (NULL != tmp)
1300 { 1308 {
1301 ps->time_to_leave = ps->ec->proc (ps->ec->cls, 1309 ps->time_to_leave = ps->ec->proc (ps->ec->cls,
1302 "gstreamer", 1310 "gstreamer",
1303 EXTRACTOR_METATYPE_VIDEO_DEPTH, 1311 EXTRACTOR_METATYPE_VIDEO_DEPTH,
1304 EXTRACTOR_METAFORMAT_UTF8, 1312 EXTRACTOR_METAFORMAT_UTF8,
1305 "text/plain", 1313 "text/plain",
1306 (const char *) tmp, 1314 (const char *) tmp,
1307 strlen (tmp) + 1); 1315 strlen (tmp) + 1);
1308 g_free (tmp); 1316 g_free (tmp);
1309 } 1317 }
1310 if (ps->time_to_leave) 1318 if (ps->time_to_leave)
1311 return TRUE; 1319 return TRUE;
1312 } 1320 }
@@ -1317,16 +1325,16 @@ send_video_info (GstDiscovererVideoInfo *info,
1317 { 1325 {
1318 tmp = g_strdup_printf ("%u/%u", u, u2); 1326 tmp = g_strdup_printf ("%u/%u", u, u2);
1319 if (NULL != tmp) 1327 if (NULL != tmp)
1320 { 1328 {
1321 ps->time_to_leave = ps->ec->proc (ps->ec->cls, 1329 ps->time_to_leave = ps->ec->proc (ps->ec->cls,
1322 "gstreamer", 1330 "gstreamer",
1323 EXTRACTOR_METATYPE_FRAME_RATE, 1331 EXTRACTOR_METATYPE_FRAME_RATE,
1324 EXTRACTOR_METAFORMAT_UTF8, 1332 EXTRACTOR_METAFORMAT_UTF8,
1325 "text/plain", 1333 "text/plain",
1326 (const char *) tmp, 1334 (const char *) tmp,
1327 strlen (tmp) + 1); 1335 strlen (tmp) + 1);
1328 g_free (tmp); 1336 g_free (tmp);
1329 } 1337 }
1330 if (ps->time_to_leave) 1338 if (ps->time_to_leave)
1331 return TRUE; 1339 return TRUE;
1332 } 1340 }
@@ -1337,16 +1345,16 @@ send_video_info (GstDiscovererVideoInfo *info,
1337 { 1345 {
1338 tmp = g_strdup_printf ("%u/%u", u, u2); 1346 tmp = g_strdup_printf ("%u/%u", u, u2);
1339 if (NULL != tmp) 1347 if (NULL != tmp)
1340 { 1348 {
1341 ps->time_to_leave = ps->ec->proc (ps->ec->cls, 1349 ps->time_to_leave = ps->ec->proc (ps->ec->cls,
1342 "gstreamer", 1350 "gstreamer",
1343 EXTRACTOR_METATYPE_PIXEL_ASPECT_RATIO, 1351 EXTRACTOR_METATYPE_PIXEL_ASPECT_RATIO,
1344 EXTRACTOR_METAFORMAT_UTF8, 1352 EXTRACTOR_METAFORMAT_UTF8,
1345 "text/plain", 1353 "text/plain",
1346 (const char *) tmp, 1354 (const char *) tmp,
1347 strlen (tmp) + 1); 1355 strlen (tmp) + 1);
1348 g_free (tmp); 1356 g_free (tmp);
1349 } 1357 }
1350 if (ps->time_to_leave) 1358 if (ps->time_to_leave)
1351 return TRUE; 1359 return TRUE;
1352 } 1360 }
@@ -1358,16 +1366,16 @@ send_video_info (GstDiscovererVideoInfo *info,
1358 { 1366 {
1359 tmp = g_strdup_printf ("%u", u); 1367 tmp = g_strdup_printf ("%u", u);
1360 if (NULL != tmp) 1368 if (NULL != tmp)
1361 { 1369 {
1362 ps->time_to_leave = ps->ec->proc (ps->ec->cls, 1370 ps->time_to_leave = ps->ec->proc (ps->ec->cls,
1363 "gstreamer", 1371 "gstreamer",
1364 EXTRACTOR_METATYPE_VIDEO_BITRATE, 1372 EXTRACTOR_METATYPE_VIDEO_BITRATE,
1365 EXTRACTOR_METAFORMAT_UTF8, 1373 EXTRACTOR_METAFORMAT_UTF8,
1366 "text/plain", 1374 "text/plain",
1367 (const char *) tmp, 1375 (const char *) tmp,
1368 strlen (tmp) + 1); 1376 strlen (tmp) + 1);
1369 g_free (tmp); 1377 g_free (tmp);
1370 } 1378 }
1371 if (ps->time_to_leave) 1379 if (ps->time_to_leave)
1372 return TRUE; 1380 return TRUE;
1373 } 1381 }
@@ -1377,16 +1385,16 @@ send_video_info (GstDiscovererVideoInfo *info,
1377 { 1385 {
1378 tmp = g_strdup_printf ("%u", u); 1386 tmp = g_strdup_printf ("%u", u);
1379 if (NULL != tmp) 1387 if (NULL != tmp)
1380 { 1388 {
1381 ps->time_to_leave = ps->ec->proc (ps->ec->cls, 1389 ps->time_to_leave = ps->ec->proc (ps->ec->cls,
1382 "gstreamer", 1390 "gstreamer",
1383 EXTRACTOR_METATYPE_MAXIMUM_VIDEO_BITRATE, 1391 EXTRACTOR_METATYPE_MAXIMUM_VIDEO_BITRATE,
1384 EXTRACTOR_METAFORMAT_UTF8, 1392 EXTRACTOR_METAFORMAT_UTF8,
1385 "text/plain", 1393 "text/plain",
1386 (const char *) tmp, 1394 (const char *) tmp,
1387 strlen (tmp) + 1); 1395 strlen (tmp) + 1);
1388 g_free (tmp); 1396 g_free (tmp);
1389 } 1397 }
1390 if (ps->time_to_leave) 1398 if (ps->time_to_leave)
1391 return TRUE; 1399 return TRUE;
1392 } 1400 }
@@ -1404,26 +1412,27 @@ send_video_info (GstDiscovererVideoInfo *info,
1404 */ 1412 */
1405static int 1413static int
1406send_subtitle_info (GstDiscovererSubtitleInfo *info, 1414send_subtitle_info (GstDiscovererSubtitleInfo *info,
1407 struct PrivStruct *ps) 1415 struct PrivStruct *ps)
1408{ 1416{
1409 const gchar *ctmp; 1417 const gchar *ctmp;
1410 1418
1411 ctmp = gst_discoverer_subtitle_info_get_language (info); 1419 ctmp = gst_discoverer_subtitle_info_get_language (info);
1412 if ( (NULL != ctmp) && 1420 if ( (NULL != ctmp) &&
1413 (0 != (ps->time_to_leave = ps->ec->proc (ps->ec->cls, "gstreamer", 1421 (0 != (ps->time_to_leave = ps->ec->proc (ps->ec->cls, "gstreamer",
1414 EXTRACTOR_METATYPE_SUBTITLE_LANGUAGE, 1422 EXTRACTOR_METATYPE_SUBTITLE_LANGUAGE,
1415 EXTRACTOR_METAFORMAT_UTF8, 1423 EXTRACTOR_METAFORMAT_UTF8,
1416 "text/plain", 1424 "text/plain",
1417 (const char *) ctmp, strlen (ctmp) + 1))) ) 1425 (const char *) ctmp, strlen (
1426 ctmp) + 1))) )
1418 return TRUE; 1427 return TRUE;
1419 return FALSE; 1428 return FALSE;
1420} 1429}
1421 1430
1422 1431
1423static void 1432static void
1424send_tag_foreach (const GstTagList * tags, 1433send_tag_foreach (const GstTagList *tags,
1425 const gchar * tag, 1434 const gchar *tag,
1426 gpointer user_data) 1435 gpointer user_data)
1427{ 1436{
1428 static struct KnownTag unknown_tag = {NULL, EXTRACTOR_METATYPE_UNKNOWN}; 1437 static struct KnownTag unknown_tag = {NULL, EXTRACTOR_METATYPE_UNKNOWN};
1429 struct PrivStruct *ps = user_data; 1438 struct PrivStruct *ps = user_data;
@@ -1480,7 +1489,9 @@ send_tag_foreach (const GstTagList * tags,
1480 str = gst_value_serialize (&val); 1489 str = gst_value_serialize (&val);
1481 break; 1490 break;
1482 default: 1491 default:
1483 if (G_VALUE_TYPE (&val) == GST_TYPE_SAMPLE && (sample = gst_value_get_sample (&val))) 1492 if ((G_VALUE_TYPE (&val) == GST_TYPE_SAMPLE) && (sample =
1493 gst_value_get_sample (
1494 &val)))
1484 { 1495 {
1485 GstMapInfo mi; 1496 GstMapInfo mi;
1486 GstCaps *caps; 1497 GstCaps *caps;
@@ -1498,7 +1509,9 @@ send_tag_foreach (const GstTagList * tags,
1498 info = gst_sample_get_info (sample); 1509 info = gst_sample_get_info (sample);
1499 1510
1500 if ( (NULL == info) || 1511 if ( (NULL == info) ||
1501 (!gst_structure_get (info, "image-type", GST_TYPE_TAG_IMAGE_TYPE, &imagetype, NULL)) ) 1512 (! gst_structure_get (info, "image-type",
1513 GST_TYPE_TAG_IMAGE_TYPE, &imagetype,
1514 NULL)) )
1502 le_type = EXTRACTOR_METATYPE_PICTURE; 1515 le_type = EXTRACTOR_METATYPE_PICTURE;
1503 else 1516 else
1504 { 1517 {
@@ -1545,12 +1558,12 @@ send_tag_foreach (const GstTagList * tags,
1545 le_type, 1558 le_type,
1546 EXTRACTOR_METAFORMAT_BINARY, 1559 EXTRACTOR_METAFORMAT_BINARY,
1547 mime_type, 1560 mime_type,
1548 (const char *) mi.data, mi.size); 1561 (const char *) mi.data, mi.size);
1549 gst_buffer_unmap (buf, &mi); 1562 gst_buffer_unmap (buf, &mi);
1550 } 1563 }
1551 } 1564 }
1552 else if ((G_VALUE_TYPE (&val) == G_TYPE_UINT64) && 1565 else if ((G_VALUE_TYPE (&val) == G_TYPE_UINT64) &&
1553 (tag_quark == duration_quark)) 1566 (tag_quark == duration_quark))
1554 { 1567 {
1555 GstClockTime duration = (GstClockTime) g_value_get_uint64 (&val); 1568 GstClockTime duration = (GstClockTime) g_value_get_uint64 (&val);
1556 if ((GST_CLOCK_TIME_IS_VALID (duration)) && (duration > 0)) 1569 if ((GST_CLOCK_TIME_IS_VALID (duration)) && (duration > 0))
@@ -1566,14 +1579,12 @@ send_tag_foreach (const GstTagList * tags,
1566 * ignore these tags to avoid duplicates. 1579 * ignore these tags to avoid duplicates.
1567 * This MIGHT be fixed in new GStreamer versions, but won't affect 1580 * This MIGHT be fixed in new GStreamer versions, but won't affect
1568 * this code (we simply won't get the tags that we think we should skip). 1581 * this code (we simply won't get the tags that we think we should skip).
1569 */ 1582 */gboolean skip = FALSE;
1570 gboolean skip = FALSE;
1571 /* We have one tag-processing routine and use it for different 1583 /* We have one tag-processing routine and use it for different
1572 * stream types. However, tags themselves don't know the type of the 1584 * stream types. However, tags themselves don't know the type of the
1573 * stream they are attached to. We remember that before listing the 1585 * stream they are attached to. We remember that before listing the
1574 * tags, and adjust LE type accordingly. 1586 * tags, and adjust LE type accordingly.
1575 */ 1587 */enum EXTRACTOR_MetaType le_type = kt->le_type;
1576 enum EXTRACTOR_MetaType le_type = kt->le_type;
1577 switch (kt->le_type) 1588 switch (kt->le_type)
1578 { 1589 {
1579 case EXTRACTOR_METATYPE_LANGUAGE: 1590 case EXTRACTOR_METATYPE_LANGUAGE:
@@ -1662,7 +1673,7 @@ send_tag_foreach (const GstTagList * tags,
1662 { 1673 {
1663 gchar *new_str; 1674 gchar *new_str;
1664 /* GST_TAG_EXTENDED_COMMENT is already in key=value form */ 1675 /* GST_TAG_EXTENDED_COMMENT is already in key=value form */
1665 if ((0 != strcmp (tag, "extended-comment")) || !strchr (str, '=')) 1676 if ((0 != strcmp (tag, "extended-comment")) || ! strchr (str, '='))
1666 { 1677 {
1667 new_str = g_strdup_printf ("%s=%s", tag, str); 1678 new_str = g_strdup_printf ("%s=%s", tag, str);
1668 if (NULL != str) 1679 if (NULL != str)
@@ -1693,12 +1704,12 @@ send_tag_foreach (const GstTagList * tags,
1693 1704
1694static void 1705static void
1695send_streams (GstDiscovererStreamInfo *info, 1706send_streams (GstDiscovererStreamInfo *info,
1696 struct PrivStruct *ps); 1707 struct PrivStruct *ps);
1697 1708
1698 1709
1699static void 1710static void
1700send_stream_info (GstDiscovererStreamInfo * info, 1711send_stream_info (GstDiscovererStreamInfo *info,
1701 struct PrivStruct *ps) 1712 struct PrivStruct *ps)
1702{ 1713{
1703 const GstStructure *misc; 1714 const GstStructure *misc;
1704 GstCaps *caps; 1715 GstCaps *caps;
@@ -1722,9 +1733,11 @@ send_stream_info (GstDiscovererStreamInfo * info,
1722 if (g_str_has_prefix (structname, "image/")) 1733 if (g_str_has_prefix (structname, "image/"))
1723 ps->st = STREAM_TYPE_IMAGE; 1734 ps->st = STREAM_TYPE_IMAGE;
1724 ps->time_to_leave = ps->ec->proc (ps->ec->cls, "gstreamer", 1735 ps->time_to_leave = ps->ec->proc (ps->ec->cls, "gstreamer",
1725 EXTRACTOR_METATYPE_MIMETYPE, EXTRACTOR_METAFORMAT_UTF8, "text/plain", 1736 EXTRACTOR_METATYPE_MIMETYPE,
1726 (const char *) structname, strlen (structname) + 1); 1737 EXTRACTOR_METAFORMAT_UTF8, "text/plain",
1727 if (!ps->time_to_leave) 1738 (const char *) structname, strlen (
1739 structname) + 1);
1740 if (! ps->time_to_leave)
1728 { 1741 {
1729 gst_structure_foreach (structure, send_structure_foreach, ps); 1742 gst_structure_foreach (structure, send_structure_foreach, ps);
1730 } 1743 }
@@ -1770,8 +1783,8 @@ send_stream_info (GstDiscovererStreamInfo * info,
1770 GList *child; 1783 GList *child;
1771 GstDiscovererContainerInfo *c = GST_DISCOVERER_CONTAINER_INFO (info); 1784 GstDiscovererContainerInfo *c = GST_DISCOVERER_CONTAINER_INFO (info);
1772 GList *children = gst_discoverer_container_info_get_streams (c); 1785 GList *children = gst_discoverer_container_info_get_streams (c);
1773 for (child = children; (NULL != child) && (!ps->time_to_leave); 1786 for (child = children; (NULL != child) && (! ps->time_to_leave);
1774 child = child->next) 1787 child = child->next)
1775 { 1788 {
1776 GstDiscovererStreamInfo *sinfo = child->data; 1789 GstDiscovererStreamInfo *sinfo = child->data;
1777 /* send_streams () will unref it */ 1790 /* send_streams () will unref it */
@@ -1786,7 +1799,7 @@ send_stream_info (GstDiscovererStreamInfo * info,
1786 1799
1787static void 1800static void
1788send_streams (GstDiscovererStreamInfo *info, 1801send_streams (GstDiscovererStreamInfo *info,
1789 struct PrivStruct *ps) 1802 struct PrivStruct *ps)
1790{ 1803{
1791 GstDiscovererStreamInfo *next; 1804 GstDiscovererStreamInfo *next;
1792 1805
@@ -1808,9 +1821,9 @@ send_streams (GstDiscovererStreamInfo *info,
1808 * @param user_data the 'struct PrivStruct' with the 'toc' string we are assembling 1821 * @param user_data the 'struct PrivStruct' with the 'toc' string we are assembling
1809 */ 1822 */
1810static void 1823static void
1811send_toc_tags_foreach (const GstTagList * tags, 1824send_toc_tags_foreach (const GstTagList *tags,
1812 const gchar * tag, 1825 const gchar *tag,
1813 gpointer user_data) 1826 gpointer user_data)
1814{ 1827{
1815 struct PrivStruct *ps = user_data; 1828 struct PrivStruct *ps = user_data;
1816 GValue val = { 0 }; 1829 GValue val = { 0 };
@@ -1899,9 +1912,11 @@ send_toc_foreach (gpointer data, gpointer user_data)
1899 return; 1912 return;
1900 gst_toc_entry_get_start_stop_times (entry, &start, &stop); 1913 gst_toc_entry_get_start_stop_times (entry, &start, &stop);
1901 s = g_strdup_printf ("%*.*s<%s start=\"%" GST_TIME_FORMAT "\" stop=\"%" 1914 s = g_strdup_printf ("%*.*s<%s start=\"%" GST_TIME_FORMAT "\" stop=\"%"
1902 GST_TIME_FORMAT"\">\n", ps->toc_depth * 2, ps->toc_depth * 2, " ", 1915 GST_TIME_FORMAT "\">\n", ps->toc_depth * 2,
1903 gst_toc_entry_type_get_nick (entype), GST_TIME_ARGS (start), 1916 ps->toc_depth * 2, " ",
1904 GST_TIME_ARGS (stop)); 1917 gst_toc_entry_type_get_nick (entype), GST_TIME_ARGS (
1918 start),
1919 GST_TIME_ARGS (stop));
1905 if (NULL != s) 1920 if (NULL != s)
1906 { 1921 {
1907 if (ps->toc_print_phase) 1922 if (ps->toc_print_phase)
@@ -1916,21 +1931,25 @@ send_toc_foreach (gpointer data, gpointer user_data)
1916 ps->toc_depth++; 1931 ps->toc_depth++;
1917 tags = gst_toc_entry_get_tags (entry); 1932 tags = gst_toc_entry_get_tags (entry);
1918 if (tags) 1933 if (tags)
1919 { 1934 {
1920 if (ps->toc_print_phase) 1935 if (ps->toc_print_phase)
1921 ps->toc_pos += g_snprintf (&ps->toc[ps->toc_pos], ps->toc_length - ps->toc_pos, 1936 ps->toc_pos += g_snprintf (&ps->toc[ps->toc_pos], ps->toc_length
1922 "%*.*s<tags>\n", ps->toc_depth * 2, ps->toc_depth * 2, " "); 1937 - ps->toc_pos,
1923 else 1938 "%*.*s<tags>\n", ps->toc_depth * 2,
1924 ps->toc_length += strlen ("<tags>\n") + ps->toc_depth * 2; 1939 ps->toc_depth * 2, " ");
1925 ps->toc_depth++; 1940 else
1926 gst_tag_list_foreach (tags, &send_toc_tags_foreach, ps); 1941 ps->toc_length += strlen ("<tags>\n") + ps->toc_depth * 2;
1927 ps->toc_depth--; 1942 ps->toc_depth++;
1928 if (ps->toc_print_phase) 1943 gst_tag_list_foreach (tags, &send_toc_tags_foreach, ps);
1929 ps->toc_pos += g_snprintf (&ps->toc[ps->toc_pos], ps->toc_length - ps->toc_pos, 1944 ps->toc_depth--;
1930 "%*.*s</tags>\n", ps->toc_depth * 2, ps->toc_depth * 2, " "); 1945 if (ps->toc_print_phase)
1931 else 1946 ps->toc_pos += g_snprintf (&ps->toc[ps->toc_pos], ps->toc_length
1932 ps->toc_length += strlen ("</tags>\n") + ps->toc_depth * 2; 1947 - ps->toc_pos,
1933 } 1948 "%*.*s</tags>\n", ps->toc_depth * 2,
1949 ps->toc_depth * 2, " ");
1950 else
1951 ps->toc_length += strlen ("</tags>\n") + ps->toc_depth * 2;
1952 }
1934 1953
1935 subentries = gst_toc_entry_get_sub_entries (entry); 1954 subentries = gst_toc_entry_get_sub_entries (entry);
1936 g_list_foreach (subentries, send_toc_foreach, ps); 1955 g_list_foreach (subentries, send_toc_foreach, ps);
@@ -1939,11 +1958,12 @@ send_toc_foreach (gpointer data, gpointer user_data)
1939 s = g_strdup_printf ("%*.*s</%s>\n", 1958 s = g_strdup_printf ("%*.*s</%s>\n",
1940 ps->toc_depth * 2, 1959 ps->toc_depth * 2,
1941 ps->toc_depth * 2, " ", 1960 ps->toc_depth * 2, " ",
1942 gst_toc_entry_type_get_nick (entype)); 1961 gst_toc_entry_type_get_nick (entype));
1943 if (NULL != s) 1962 if (NULL != s)
1944 { 1963 {
1945 if (ps->toc_print_phase) 1964 if (ps->toc_print_phase)
1946 ps->toc_pos += g_snprintf (&ps->toc[ps->toc_pos], ps->toc_length - ps->toc_pos, "%s", s); 1965 ps->toc_pos += g_snprintf (&ps->toc[ps->toc_pos], ps->toc_length
1966 - ps->toc_pos, "%s", s);
1947 else 1967 else
1948 ps->toc_length += strlen (s); 1968 ps->toc_length += strlen (s);
1949 g_free (s); 1969 g_free (s);
@@ -1958,8 +1978,8 @@ send_toc_foreach (gpointer data, gpointer user_data)
1958 1978
1959 1979
1960static void 1980static void
1961send_info (GstDiscovererInfo * info, 1981send_info (GstDiscovererInfo *info,
1962 struct PrivStruct *ps) 1982 struct PrivStruct *ps)
1963{ 1983{
1964 const GstToc *toc; 1984 const GstToc *toc;
1965 gchar *s; 1985 gchar *s;
@@ -1992,9 +2012,7 @@ send_info (GstDiscovererInfo * info,
1992 { 2012 {
1993 gst_tag_list_foreach (tags, send_tag_foreach, ps); 2013 gst_tag_list_foreach (tags, send_tag_foreach, ps);
1994 } 2014 }
1995 */ 2015 */if (ps->time_to_leave)
1996
1997 if (ps->time_to_leave)
1998 return; 2016 return;
1999 2017
2000 if ((toc = gst_discoverer_info_get_toc (info))) 2018 if ((toc = gst_discoverer_info_get_toc (info)))
@@ -2040,8 +2058,8 @@ send_info (GstDiscovererInfo * info,
2040 2058
2041 2059
2042static void 2060static void
2043send_discovered_info (GstDiscovererInfo * info, 2061send_discovered_info (GstDiscovererInfo *info,
2044 struct PrivStruct * ps) 2062 struct PrivStruct *ps)
2045{ 2063{
2046 GstDiscovererResult result; 2064 GstDiscovererResult result;
2047 2065
@@ -2051,20 +2069,20 @@ send_discovered_info (GstDiscovererInfo * info,
2051 result = gst_discoverer_info_get_result (info); 2069 result = gst_discoverer_info_get_result (info);
2052 2070
2053 switch (result) 2071 switch (result)
2054 { 2072 {
2055 case GST_DISCOVERER_OK: 2073 case GST_DISCOVERER_OK:
2056 break; 2074 break;
2057 case GST_DISCOVERER_URI_INVALID: 2075 case GST_DISCOVERER_URI_INVALID:
2058 break; 2076 break;
2059 case GST_DISCOVERER_ERROR: 2077 case GST_DISCOVERER_ERROR:
2060 break; 2078 break;
2061 case GST_DISCOVERER_TIMEOUT: 2079 case GST_DISCOVERER_TIMEOUT:
2062 break; 2080 break;
2063 case GST_DISCOVERER_BUSY: 2081 case GST_DISCOVERER_BUSY:
2064 break; 2082 break;
2065 case GST_DISCOVERER_MISSING_PLUGINS: 2083 case GST_DISCOVERER_MISSING_PLUGINS:
2066 break; 2084 break;
2067 } 2085 }
2068 pthread_mutex_lock (&pipe_mutex); 2086 pthread_mutex_lock (&pipe_mutex);
2069 send_info (info, ps); 2087 send_info (info, ps);
2070 pthread_mutex_unlock (&pipe_mutex); 2088 pthread_mutex_unlock (&pipe_mutex);
@@ -2072,20 +2090,21 @@ send_discovered_info (GstDiscovererInfo * info,
2072 2090
2073 2091
2074static void 2092static void
2075_new_discovered_uri (GstDiscoverer * dc, 2093_new_discovered_uri (GstDiscoverer *dc,
2076 GstDiscovererInfo * info, 2094 GstDiscovererInfo *info,
2077 GError * err, 2095 GError *err,
2078 struct PrivStruct *ps) 2096 struct PrivStruct *ps)
2079{ 2097{
2080 send_discovered_info (info, ps); 2098 send_discovered_info (info, ps);
2081 if (ps->timeout_id > 0) 2099 if (ps->timeout_id > 0)
2082 g_source_remove (ps->timeout_id); 2100 g_source_remove (ps->timeout_id);
2083 ps->timeout_id = g_timeout_add (DATA_TIMEOUT, (GSourceFunc) _data_timeout, ps); 2101 ps->timeout_id = g_timeout_add (DATA_TIMEOUT, (GSourceFunc) _data_timeout,
2102 ps);
2084} 2103}
2085 2104
2086 2105
2087static void 2106static void
2088_discoverer_finished (GstDiscoverer * dc, struct PrivStruct *ps) 2107_discoverer_finished (GstDiscoverer *dc, struct PrivStruct *ps)
2089{ 2108{
2090 if (ps->timeout_id > 0) 2109 if (ps->timeout_id > 0)
2091 g_source_remove (ps->timeout_id); 2110 g_source_remove (ps->timeout_id);
@@ -2105,9 +2124,9 @@ _discoverer_finished (GstDiscoverer * dc, struct PrivStruct *ps)
2105 * @param ps 2124 * @param ps
2106 */ 2125 */
2107static void 2126static void
2108_source_setup (GstDiscoverer * dc, 2127_source_setup (GstDiscoverer *dc,
2109 GstElement * source, 2128 GstElement *source,
2110 struct PrivStruct *ps) 2129 struct PrivStruct *ps)
2111{ 2130{
2112 if (ps->source) 2131 if (ps->source)
2113 gst_object_unref (GST_OBJECT (ps->source)); 2132 gst_object_unref (GST_OBJECT (ps->source));
@@ -2120,7 +2139,8 @@ _source_setup (GstDiscoverer * dc,
2120 if (ps->length > 0) 2139 if (ps->length > 0)
2121 { 2140 {
2122 g_object_set (ps->source, "size", (gint64) ps->length, NULL); 2141 g_object_set (ps->source, "size", (gint64) ps->length, NULL);
2123 gst_util_set_object_arg (G_OBJECT (ps->source), "stream-type", "random-access"); 2142 gst_util_set_object_arg (G_OBJECT (ps->source), "stream-type",
2143 "random-access");
2124 } 2144 }
2125 else 2145 else
2126 gst_util_set_object_arg (G_OBJECT (ps->source), "stream-type", "seekable"); 2146 gst_util_set_object_arg (G_OBJECT (ps->source), "stream-type", "seekable");
@@ -2129,16 +2149,16 @@ _source_setup (GstDiscoverer * dc,
2129 * data */ 2149 * data */
2130 g_signal_connect (ps->source, "need-data", G_CALLBACK (feed_data), ps); 2150 g_signal_connect (ps->source, "need-data", G_CALLBACK (feed_data), ps);
2131 g_signal_connect (ps->source, "seek-data", G_CALLBACK (seek_data), ps); 2151 g_signal_connect (ps->source, "seek-data", G_CALLBACK (seek_data), ps);
2132 ps->timeout_id = g_timeout_add (DATA_TIMEOUT, (GSourceFunc) _data_timeout, ps); 2152 ps->timeout_id = g_timeout_add (DATA_TIMEOUT, (GSourceFunc) _data_timeout,
2153 ps);
2133} 2154}
2134 2155
2135 2156
2136
2137static void 2157static void
2138log_handler (const gchar *log_domain, 2158log_handler (const gchar *log_domain,
2139 GLogLevelFlags log_level, 2159 GLogLevelFlags log_level,
2140 const gchar *message, 2160 const gchar *message,
2141 gpointer unused_data) 2161 gpointer unused_data)
2142{ 2162{
2143 /* do nothing */ 2163 /* do nothing */
2144} 2164}
@@ -2151,11 +2171,12 @@ log_handler (const gchar *log_domain,
2151 * @return FALSE (always) 2171 * @return FALSE (always)
2152 */ 2172 */
2153static gboolean 2173static gboolean
2154_run_async (struct PrivStruct * ps) 2174_run_async (struct PrivStruct *ps)
2155{ 2175{
2156 g_log_set_default_handler (&log_handler, NULL); 2176 g_log_set_default_handler (&log_handler, NULL);
2157 g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, 2177 g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
2158 &log_handler, NULL); 2178 | G_LOG_FLAG_RECURSION,
2179 &log_handler, NULL);
2159 gst_discoverer_discover_uri_async (ps->dc, "appsrc://"); 2180 gst_discoverer_discover_uri_async (ps->dc, "appsrc://");
2160 return FALSE; 2181 return FALSE;
2161} 2182}
@@ -2178,11 +2199,11 @@ EXTRACTOR_gstreamer_extract_method (struct EXTRACTOR_ExtractContext *ec)
2178 memset (&ps, 0, sizeof (ps)); 2199 memset (&ps, 0, sizeof (ps));
2179 ps.dc = gst_discoverer_new (8 * GST_SECOND, &err); 2200 ps.dc = gst_discoverer_new (8 * GST_SECOND, &err);
2180 if (NULL == ps.dc) 2201 if (NULL == ps.dc)
2181 { 2202 {
2182 if (NULL != err) 2203 if (NULL != err)
2183 g_error_free (err); 2204 g_error_free (err);
2184 return; 2205 return;
2185 } 2206 }
2186 if (NULL != err) 2207 if (NULL != err)
2187 g_error_free (err); 2208 g_error_free (err);
2188 /* connect signals */ 2209 /* connect signals */
@@ -2195,10 +2216,11 @@ EXTRACTOR_gstreamer_extract_method (struct EXTRACTOR_ExtractContext *ec)
2195 if (ps.length == UINT_MAX) 2216 if (ps.length == UINT_MAX)
2196 ps.length = 0; 2217 ps.length = 0;
2197 g_log_set_default_handler (&log_handler, NULL); 2218 g_log_set_default_handler (&log_handler, NULL);
2198 g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, 2219 g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
2199 &log_handler, NULL); 2220 | G_LOG_FLAG_RECURSION,
2221 &log_handler, NULL);
2200 gst_discoverer_start (ps.dc); 2222 gst_discoverer_start (ps.dc);
2201 g_idle_add ((GSourceFunc) &_run_async, &ps); 2223 g_idle_add ((GSourceFunc) & _run_async, &ps);
2202 g_main_loop_run (ps.loop); 2224 g_main_loop_run (ps.loop);
2203 if (ps.timeout_id > 0) 2225 if (ps.timeout_id > 0)
2204 g_source_remove (ps.timeout_id); 2226 g_source_remove (ps.timeout_id);
@@ -2216,35 +2238,36 @@ gstreamer_init ()
2216{ 2238{
2217 gst_init (NULL, NULL); 2239 gst_init (NULL, NULL);
2218 g_log_set_default_handler (&log_handler, NULL); 2240 g_log_set_default_handler (&log_handler, NULL);
2219 g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, 2241 g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
2220 &log_handler, NULL); 2242 | G_LOG_FLAG_RECURSION,
2243 &log_handler, NULL);
2221 GST_DEBUG_CATEGORY_INIT (gstreamer_extractor, "GstExtractor", 2244 GST_DEBUG_CATEGORY_INIT (gstreamer_extractor, "GstExtractor",
2222 0, "GStreamer-based libextractor plugin"); 2245 0, "GStreamer-based libextractor plugin");
2223 2246
2224 audio_quarks = g_new0 (GQuark, 4); 2247 audio_quarks = g_new0 (GQuark, 4);
2225 if (NULL != audio_quarks) 2248 if (NULL != audio_quarks)
2226 { 2249 {
2227 audio_quarks[0] = g_quark_from_string ("rate"); 2250 audio_quarks[0] = g_quark_from_string ("rate");
2228 audio_quarks[1] = g_quark_from_string ("channels"); 2251 audio_quarks[1] = g_quark_from_string ("channels");
2229 audio_quarks[2] = g_quark_from_string ("depth"); 2252 audio_quarks[2] = g_quark_from_string ("depth");
2230 audio_quarks[3] = g_quark_from_string (NULL); 2253 audio_quarks[3] = g_quark_from_string (NULL);
2231 } 2254 }
2232 video_quarks = g_new0 (GQuark, 6); 2255 video_quarks = g_new0 (GQuark, 6);
2233 if (NULL != video_quarks) 2256 if (NULL != video_quarks)
2234 { 2257 {
2235 video_quarks[0] = g_quark_from_string ("width"); 2258 video_quarks[0] = g_quark_from_string ("width");
2236 video_quarks[1] = g_quark_from_string ("height"); 2259 video_quarks[1] = g_quark_from_string ("height");
2237 video_quarks[2] = g_quark_from_string ("framerate"); 2260 video_quarks[2] = g_quark_from_string ("framerate");
2238 video_quarks[3] = g_quark_from_string ("max-framerate"); 2261 video_quarks[3] = g_quark_from_string ("max-framerate");
2239 video_quarks[4] = g_quark_from_string ("pixel-aspect-ratio"); 2262 video_quarks[4] = g_quark_from_string ("pixel-aspect-ratio");
2240 video_quarks[5] = g_quark_from_string (NULL); 2263 video_quarks[5] = g_quark_from_string (NULL);
2241 } 2264 }
2242 subtitle_quarks = g_new0 (GQuark, 2); 2265 subtitle_quarks = g_new0 (GQuark, 2);
2243 if (NULL != subtitle_quarks) 2266 if (NULL != subtitle_quarks)
2244 { 2267 {
2245 subtitle_quarks[0] = g_quark_from_string ("language-code"); 2268 subtitle_quarks[0] = g_quark_from_string ("language-code");
2246 subtitle_quarks[1] = g_quark_from_string (NULL); 2269 subtitle_quarks[1] = g_quark_from_string (NULL);
2247 } 2270 }
2248 2271
2249 duration_quark = g_quark_from_string ("duration"); 2272 duration_quark = g_quark_from_string ("duration");
2250 2273
diff --git a/src/plugins/html_extractor.c b/src/plugins/html_extractor.c
index 8cd4aba..5ebf97b 100644
--- a/src/plugins/html_extractor.c
+++ b/src/plugins/html_extractor.c
@@ -87,9 +87,9 @@ tag_to_type (const char *tag)
87{ 87{
88 unsigned int i; 88 unsigned int i;
89 89
90 for (i=0; NULL != tagmap[i].name; i++) 90 for (i = 0; NULL != tagmap[i].name; i++)
91 if (0 == strcasecmp (tag, 91 if (0 == strcasecmp (tag,
92 tagmap[i].name)) 92 tagmap[i].name))
93 return tagmap[i].type; 93 return tagmap[i].type;
94 return EXTRACTOR_METATYPE_RESERVED; 94 return EXTRACTOR_METATYPE_RESERVED;
95} 95}
@@ -107,10 +107,10 @@ tag_to_type (const char *tag)
107 */ 107 */
108static Bool TIDY_CALL 108static Bool TIDY_CALL
109report_cb (TidyDoc doc, 109report_cb (TidyDoc doc,
110 TidyReportLevel lvl, 110 TidyReportLevel lvl,
111 uint line, 111 uint line,
112 uint col, 112 uint col,
113 ctmbstr mssg) 113 ctmbstr mssg)
114{ 114{
115 return 0; 115 return 0;
116} 116}
@@ -130,7 +130,7 @@ get_byte_cb (void *sourceData)
130 130
131 if (1 != 131 if (1 !=
132 ec->read (ec->cls, 132 ec->read (ec->cls,
133 &data, 1)) 133 &data, 1))
134 return EndOfStream; 134 return EndOfStream;
135 return *(unsigned char*) data; 135 return *(unsigned char*) data;
136} 136}
@@ -188,130 +188,129 @@ EXTRACTOR_html_extract_method (struct EXTRACTOR_ExtractContext *ec)
188 const char *mime; 188 const char *mime;
189 189
190 if (-1 == (iret = ec->read (ec->cls, 190 if (-1 == (iret = ec->read (ec->cls,
191 &data, 191 &data,
192 16 * 1024))) 192 16 * 1024)))
193 return; 193 return;
194 if (NULL == (mime = magic_buffer (magic, data, iret))) 194 if (NULL == (mime = magic_buffer (magic, data, iret)))
195 return; 195 return;
196 if (0 != strncmp (mime, 196 if (0 != strncmp (mime,
197 "text/html", 197 "text/html",
198 strlen ("text/html"))) 198 strlen ("text/html")))
199 return; /* not HTML */ 199 return; /* not HTML */
200 200
201 if (0 != ec->seek (ec->cls, 0, SEEK_SET)) 201 if (0 != ec->seek (ec->cls, 0, SEEK_SET))
202 return; /* seek failed !? */ 202 return; /* seek failed !? */
203 203
204 tidyInitSource (&src, ec, 204 tidyInitSource (&src, ec,
205 &get_byte_cb, 205 &get_byte_cb,
206 &unget_byte_cb, 206 &unget_byte_cb,
207 &eof_cb); 207 &eof_cb);
208 if (NULL == (doc = tidyCreate ())) 208 if (NULL == (doc = tidyCreate ()))
209 return; 209 return;
210 tidySetReportFilter (doc, &report_cb); 210 tidySetReportFilter (doc, &report_cb);
211 tidySetAppData (doc, ec); 211 tidySetAppData (doc, ec);
212 if (0 > tidyParseSource (doc, &src)) 212 if (0 > tidyParseSource (doc, &src))
213 { 213 {
214 tidyRelease (doc); 214 tidyRelease (doc);
215 return; 215 return;
216 } 216 }
217 if (1 != tidyStatus (doc)) 217 if (1 != tidyStatus (doc))
218 { 218 {
219 tidyRelease (doc); 219 tidyRelease (doc);
220 return; 220 return;
221 } 221 }
222 if (NULL == (head = tidyGetHead (doc))) 222 if (NULL == (head = tidyGetHead (doc)))
223 { 223 {
224 fprintf (stderr, "no head\n"); 224 fprintf (stderr, "no head\n");
225 tidyRelease (doc); 225 tidyRelease (doc);
226 return; 226 return;
227 } 227 }
228 for (child = tidyGetChild (head); NULL != child; child = tidyGetNext (child)) 228 for (child = tidyGetChild (head); NULL != child; child = tidyGetNext (child))
229 {
230 switch (tidyNodeGetType (child))
229 { 231 {
230 switch (tidyNodeGetType(child)) 232 case TidyNode_Root:
231 { 233 break;
232 case TidyNode_Root: 234 case TidyNode_DocType:
233 break; 235 break;
234 case TidyNode_DocType: 236 case TidyNode_Comment:
235 break; 237 break;
236 case TidyNode_Comment: 238 case TidyNode_ProcIns:
237 break; 239 break;
238 case TidyNode_ProcIns: 240 case TidyNode_Text:
239 break; 241 break;
240 case TidyNode_Text: 242 case TidyNode_CDATA:
241 break; 243 break;
242 case TidyNode_CDATA: 244 case TidyNode_Section:
243 break; 245 break;
244 case TidyNode_Section: 246 case TidyNode_Asp:
245 break; 247 break;
246 case TidyNode_Asp: 248 case TidyNode_Jste:
247 break; 249 break;
248 case TidyNode_Jste: 250 case TidyNode_Php:
249 break; 251 break;
250 case TidyNode_Php: 252 case TidyNode_XmlDecl:
251 break; 253 break;
252 case TidyNode_XmlDecl: 254 case TidyNode_Start:
253 break; 255 case TidyNode_StartEnd:
254 case TidyNode_Start: 256 name = tidyNodeGetName (child);
255 case TidyNode_StartEnd: 257 if ( (0 == strcasecmp (name, "title")) &&
256 name = tidyNodeGetName (child); 258 (NULL != (title = tidyGetChild (child))) )
257 if ( (0 == strcasecmp (name, "title")) && 259 {
258 (NULL != (title = tidyGetChild (child))) ) 260 tidyBufInit (&tbuf);
259 { 261 tidyNodeGetValue (doc, title, &tbuf);
260 tidyBufInit (&tbuf); 262 /* add 0-termination */
261 tidyNodeGetValue (doc, title, &tbuf); 263 tidyBufPutByte (&tbuf, 0);
262 /* add 0-termination */ 264 if (0 !=
263 tidyBufPutByte (&tbuf, 0); 265 ec->proc (ec->cls,
264 if (0 != 266 "html",
265 ec->proc (ec->cls, 267 EXTRACTOR_METATYPE_TITLE,
266 "html", 268 EXTRACTOR_METAFORMAT_UTF8,
267 EXTRACTOR_METATYPE_TITLE, 269 "text/plain",
268 EXTRACTOR_METAFORMAT_UTF8, 270 (const char *) tbuf.bp,
269 "text/plain", 271 tbuf.size))
270 (const char *) tbuf.bp, 272 {
271 tbuf.size)) 273 tidyBufFree (&tbuf);
272 { 274 goto CLEANUP;
273 tidyBufFree (&tbuf); 275 }
274 goto CLEANUP; 276 tidyBufFree (&tbuf);
275 } 277 break;
276 tidyBufFree (&tbuf); 278 }
277 break; 279 if (0 == strcasecmp (name, "meta"))
278 } 280 {
279 if (0 == strcasecmp (name, "meta")) 281 if (NULL == (attr = tidyAttrGetById (child,
280 { 282 TidyAttr_NAME)))
281 if (NULL == (attr = tidyAttrGetById (child, 283 break;
282 TidyAttr_NAME))) 284 if (EXTRACTOR_METATYPE_RESERVED ==
283 break; 285 (type = tag_to_type (tidyAttrValue (attr))))
284 if (EXTRACTOR_METATYPE_RESERVED == 286 break;
285 (type = tag_to_type (tidyAttrValue (attr)))) 287 if (NULL == (attr = tidyAttrGetById (child,
286 break; 288 TidyAttr_CONTENT)))
287 if (NULL == (attr = tidyAttrGetById (child, 289 break;
288 TidyAttr_CONTENT))) 290 name = tidyAttrValue (attr);
289 break; 291 if (0 !=
290 name = tidyAttrValue (attr); 292 ec->proc (ec->cls,
291 if (0 != 293 "html",
292 ec->proc (ec->cls, 294 type,
293 "html", 295 EXTRACTOR_METAFORMAT_UTF8,
294 type, 296 "text/plain",
295 EXTRACTOR_METAFORMAT_UTF8, 297 name,
296 "text/plain", 298 strlen (name) + 1))
297 name, 299 goto CLEANUP;
298 strlen (name) + 1)) 300 break;
299 goto CLEANUP; 301 }
300 break; 302 break;
301 } 303 case TidyNode_End:
302 break; 304 break;
303 case TidyNode_End: 305 default:
304 break; 306 break;
305 default:
306 break;
307 }
308 } 307 }
309 CLEANUP: 308 }
309CLEANUP:
310 tidyRelease (doc); 310 tidyRelease (doc);
311} 311}
312 312
313 313
314
315#if OLD 314#if OLD
316 315
317 316
@@ -323,66 +322,71 @@ tagMatch (const char *tag, const char *s, const char *e)
323 return (((e - s) == strlen (tag)) && (0 == strncasecmp (tag, s, e - s))); 322 return (((e - s) == strlen (tag)) && (0 == strncasecmp (tag, s, e - s)));
324} 323}
325 324
325
326static int 326static int
327lookFor (char c, size_t * pos, const char *data, size_t size) 327lookFor (char c, size_t *pos, const char *data, size_t size)
328{ 328{
329 size_t p = *pos; 329 size_t p = *pos;
330 330
331 while ((p < size) && (data[p] != c)) 331 while ((p < size) && (data[p] != c))
332 { 332 {
333 if (data[p] == '\0') 333 if (data[p] == '\0')
334 return 0; 334 return 0;
335 p++; 335 p++;
336 } 336 }
337 *pos = p; 337 *pos = p;
338 return p < size; 338 return p < size;
339} 339}
340 340
341
341static int 342static int
342skipWhitespace (size_t * pos, const char *data, size_t size) 343skipWhitespace (size_t *pos, const char *data, size_t size)
343{ 344{
344 size_t p = *pos; 345 size_t p = *pos;
345 346
346 while ((p < size) && (isspace ( (unsigned char) data[p]))) 347 while ((p < size) && (isspace ( (unsigned char) data[p])))
347 { 348 {
348 if (data[p] == '\0') 349 if (data[p] == '\0')
349 return 0; 350 return 0;
350 p++; 351 p++;
351 } 352 }
352 *pos = p; 353 *pos = p;
353 return p < size; 354 return p < size;
354} 355}
355 356
357
356static int 358static int
357skipLetters (size_t * pos, const char *data, size_t size) 359skipLetters (size_t *pos, const char *data, size_t size)
358{ 360{
359 size_t p = *pos; 361 size_t p = *pos;
360 362
361 while ((p < size) && (isalpha ( (unsigned char) data[p]))) 363 while ((p < size) && (isalpha ( (unsigned char) data[p])))
362 { 364 {
363 if (data[p] == '\0') 365 if (data[p] == '\0')
364 return 0; 366 return 0;
365 p++; 367 p++;
366 } 368 }
367 *pos = p; 369 *pos = p;
368 return p < size; 370 return p < size;
369} 371}
370 372
373
371static int 374static int
372lookForMultiple (const char *c, size_t * pos, const char *data, size_t size) 375lookForMultiple (const char *c, size_t *pos, const char *data, size_t size)
373{ 376{
374 size_t p = *pos; 377 size_t p = *pos;
375 378
376 while ((p < size) && (strchr (c, data[p]) == NULL)) 379 while ((p < size) && (strchr (c, data[p]) == NULL))
377 { 380 {
378 if (data[p] == '\0') 381 if (data[p] == '\0')
379 return 0; 382 return 0;
380 p++; 383 p++;
381 } 384 }
382 *pos = p; 385 *pos = p;
383 return p < size; 386 return p < size;
384} 387}
385 388
389
386static void 390static void
387findEntry (const char *key, 391findEntry (const char *key,
388 const char *start, 392 const char *start,
@@ -394,32 +398,33 @@ findEntry (const char *key,
394 *mend = NULL; 398 *mend = NULL;
395 len = strlen (key); 399 len = strlen (key);
396 while (start < end - len - 1) 400 while (start < end - len - 1)
401 {
402 start++;
403 if (start[len] != '=')
404 continue;
405 if (0 == strncasecmp (start, key, len))
397 { 406 {
398 start++; 407 start += len + 1;
399 if (start[len] != '=') 408 *mstart = start;
400 continue; 409 if ((*start == '\"') || (*start == '\''))
401 if (0 == strncasecmp (start, key, len)) 410 {
402 { 411 start++;
403 start += len + 1; 412 while ((start < end) && (*start != **mstart))
404 *mstart = start; 413 start++;
405 if ((*start == '\"') || (*start == '\'')) 414 (*mstart)++; /* skip quote */
406 { 415 }
407 start++; 416 else
408 while ((start < end) && (*start != **mstart)) 417 {
409 start++; 418 while ((start < end) && (! isspace ( (unsigned char) *start)))
410 (*mstart)++; /* skip quote */ 419 start++;
411 } 420 }
412 else 421 *mend = start;
413 { 422 return;
414 while ((start < end) && (!isspace ( (unsigned char) *start)))
415 start++;
416 }
417 *mend = start;
418 return;
419 }
420 } 423 }
424 }
421} 425}
422 426
427
423/** 428/**
424 * Search all tags that correspond to "tagname". Example: 429 * Search all tags that correspond to "tagname". Example:
425 * If the tag is <meta name="foo" desc="bar">, and 430 * If the tag is <meta name="foo" desc="bar">, and
@@ -430,7 +435,7 @@ findEntry (const char *key,
430 * @return NULL if nothing is found 435 * @return NULL if nothing is found
431 */ 436 */
432static char * 437static char *
433findInTags (struct TagInfo * t, 438findInTags (struct TagInfo *t,
434 const char *tagname, 439 const char *tagname,
435 const char *keyname, const char *keyvalue, const char *searchname) 440 const char *keyname, const char *keyvalue, const char *searchname)
436{ 441{
@@ -438,26 +443,26 @@ findInTags (struct TagInfo * t,
438 const char *pend; 443 const char *pend;
439 444
440 while (t != NULL) 445 while (t != NULL)
446 {
447 if (tagMatch (tagname, t->tagStart, t->tagEnd))
441 { 448 {
442 if (tagMatch (tagname, t->tagStart, t->tagEnd)) 449 findEntry (keyname, t->tagEnd, t->dataStart, &pstart, &pend);
450 if ((pstart != NULL) && (tagMatch (keyvalue, pstart, pend)))
451 {
452 findEntry (searchname, t->tagEnd, t->dataStart, &pstart, &pend);
453 if (pstart != NULL)
443 { 454 {
444 findEntry (keyname, t->tagEnd, t->dataStart, &pstart, &pend); 455 char *ret = malloc (pend - pstart + 1);
445 if ((pstart != NULL) && (tagMatch (keyvalue, pstart, pend))) 456 if (ret == NULL)
446 { 457 return NULL;
447 findEntry (searchname, t->tagEnd, t->dataStart, &pstart, &pend); 458 memcpy (ret, pstart, pend - pstart);
448 if (pstart != NULL) 459 ret[pend - pstart] = '\0';
449 { 460 return ret;
450 char *ret = malloc (pend - pstart + 1);
451 if (ret == NULL)
452 return NULL;
453 memcpy (ret, pstart, pend - pstart);
454 ret[pend - pstart] = '\0';
455 return ret;
456 }
457 }
458 } 461 }
459 t = t->next; 462 }
460 } 463 }
464 t = t->next;
465 }
461 return NULL; 466 return NULL;
462} 467}
463 468
@@ -465,10 +470,10 @@ findInTags (struct TagInfo * t,
465/* mimetype = text/html */ 470/* mimetype = text/html */
466int 471int
467EXTRACTOR_html_extract (const char *data, 472EXTRACTOR_html_extract (const char *data,
468 size_t size, 473 size_t size,
469 EXTRACTOR_MetaDataProcessor proc, 474 EXTRACTOR_MetaDataProcessor proc,
470 void *proc_cls, 475 void *proc_cls,
471 const char *options) 476 const char *options)
472{ 477{
473 size_t xsize; 478 size_t xsize;
474 struct TagInfo *tags; 479 struct TagInfo *tags;
@@ -494,60 +499,60 @@ EXTRACTOR_html_extract (const char *data,
494 tag.next = NULL; 499 tag.next = NULL;
495 pos = 0; 500 pos = 0;
496 while (pos < xsize) 501 while (pos < xsize)
502 {
503 if (! lookFor ('<', &pos, data, size))
504 break;
505 tag.tagStart = &data[++pos];
506 if (! skipLetters (&pos, data, size))
507 break;
508 tag.tagEnd = &data[pos];
509 if (! skipWhitespace (&pos, data, size))
510 break;
511STEP3:
512 if (! lookForMultiple (">\"\'", &pos, data, size))
513 break;
514 if (data[pos] != '>')
497 { 515 {
498 if (!lookFor ('<', &pos, data, size)) 516 /* find end-quote, ignore escaped quotes (\') */
499 break; 517 do
500 tag.tagStart = &data[++pos]; 518 {
501 if (!skipLetters (&pos, data, size)) 519 tpos = pos;
502 break; 520 pos++;
503 tag.tagEnd = &data[pos]; 521 if (! lookFor (data[tpos], &pos, data, size))
504 if (!skipWhitespace (&pos, data, size)) 522 break;
505 break; 523 }
506 STEP3: 524 while (data[pos - 1] == '\\');
507 if (!lookForMultiple (">\"\'", &pos, data, size))
508 break;
509 if (data[pos] != '>')
510 {
511 /* find end-quote, ignore escaped quotes (\') */
512 do
513 {
514 tpos = pos;
515 pos++;
516 if (!lookFor (data[tpos], &pos, data, size))
517 break;
518 }
519 while (data[pos - 1] == '\\');
520 pos++;
521 goto STEP3;
522 }
523 pos++; 525 pos++;
524 if (!skipWhitespace (&pos, data, size)) 526 goto STEP3;
525 break; 527 }
526 tag.dataStart = &data[pos]; 528 pos++;
527 if (!lookFor ('<', &pos, data, size)) 529 if (! skipWhitespace (&pos, data, size))
528 break; 530 break;
529 tag.dataEnd = &data[pos]; 531 tag.dataStart = &data[pos];
530 i = 0; 532 if (! lookFor ('<', &pos, data, size))
531 while (relevantTags[i] != NULL) 533 break;
532 { 534 tag.dataEnd = &data[pos];
533 if ((strlen (relevantTags[i]) == tag.tagEnd - tag.tagStart) && 535 i = 0;
534 (0 == strncasecmp (relevantTags[i], 536 while (relevantTags[i] != NULL)
535 tag.tagStart, tag.tagEnd - tag.tagStart))) 537 {
536 { 538 if ((strlen (relevantTags[i]) == tag.tagEnd - tag.tagStart) &&
537 t = malloc (sizeof (struct TagInfo)); 539 (0 == strncasecmp (relevantTags[i],
538 if (t == NULL) 540 tag.tagStart, tag.tagEnd - tag.tagStart)))
539 return 0; 541 {
540 *t = tag; 542 t = malloc (sizeof (struct TagInfo));
541 t->next = tags; 543 if (t == NULL)
542 tags = t; 544 return 0;
543 break; 545 *t = tag;
544 } 546 t->next = tags;
545 i++; 547 tags = t;
546 }
547 /* abort early if we hit the body tag */
548 if (tagMatch ("body", tag.tagStart, tag.tagEnd))
549 break; 548 break;
549 }
550 i++;
550 } 551 }
552 /* abort early if we hit the body tag */
553 if (tagMatch ("body", tag.tagStart, tag.tagEnd))
554 break;
555 }
551 556
552 /* fast exit */ 557 /* fast exit */
553 if (tags == NULL) 558 if (tags == NULL)
@@ -557,110 +562,112 @@ EXTRACTOR_html_extract (const char *data,
557 /* first, try to determine mime type and/or character set */ 562 /* first, try to determine mime type and/or character set */
558 tmp = findInTags (tags, "meta", "http-equiv", "content-type", "content"); 563 tmp = findInTags (tags, "meta", "http-equiv", "content-type", "content");
559 if (tmp != NULL) 564 if (tmp != NULL)
560 { 565 {
561 /* ideally, tmp == "test/html; charset=ISO-XXXX-Y" or something like that; 566 /* ideally, tmp == "test/html; charset=ISO-XXXX-Y" or something like that;
562 if text/html is present, we take that as the mime-type; if charset= 567 if text/html is present, we take that as the mime-type; if charset=
563 is present, we try to use that for character set conversion. */ 568 is present, we try to use that for character set conversion. */
564 if (0 == strncasecmp (tmp, "text/html", strlen ("text/html"))) 569 if (0 == strncasecmp (tmp, "text/html", strlen ("text/html")))
565 ret = proc (proc_cls, 570 ret = proc (proc_cls,
566 "html", 571 "html",
567 EXTRACTOR_METATYPE_MIMETYPE, 572 EXTRACTOR_METATYPE_MIMETYPE,
568 EXTRACTOR_METAFORMAT_UTF8, 573 EXTRACTOR_METAFORMAT_UTF8,
569 "text/plain", 574 "text/plain",
570 "text/html", 575 "text/html",
571 strlen ("text/html")+1); 576 strlen ("text/html") + 1);
572 charset = strcasestr (tmp, "charset="); 577 charset = strcasestr (tmp, "charset=");
573 if (charset != NULL) 578 if (charset != NULL)
574 charset = strdup (&charset[strlen ("charset=")]); 579 charset = strdup (&charset[strlen ("charset=")]);
575 free (tmp); 580 free (tmp);
576 } 581 }
577 i = 0; 582 i = 0;
578 while (tagmap[i].name != NULL) 583 while (tagmap[i].name != NULL)
584 {
585 tmp = findInTags (tags, "meta", "name", tagmap[i].name, "content");
586 if ( (tmp != NULL) &&
587 (ret == 0) )
579 { 588 {
580 tmp = findInTags (tags, "meta", "name", tagmap[i].name, "content"); 589 if (charset == NULL)
581 if ( (tmp != NULL) && 590 {
582 (ret == 0) ) 591 ret = proc (proc_cls,
592 "html",
593 tagmap[i].type,
594 EXTRACTOR_METAFORMAT_C_STRING,
595 "text/plain",
596 tmp,
597 strlen (tmp) + 1);
598 }
599 else
600 {
601 xtmp = EXTRACTOR_common_convert_to_utf8 (tmp,
602 strlen (tmp),
603 charset);
604 if (xtmp != NULL)
583 { 605 {
584 if (charset == NULL) 606 ret = proc (proc_cls,
585 { 607 "html",
586 ret = proc (proc_cls, 608 tagmap[i].type,
587 "html", 609 EXTRACTOR_METAFORMAT_UTF8,
588 tagmap[i].type, 610 "text/plain",
589 EXTRACTOR_METAFORMAT_C_STRING, 611 xtmp,
590 "text/plain", 612 strlen (xtmp) + 1);
591 tmp, 613 free (xtmp);
592 strlen (tmp) + 1);
593 }
594 else
595 {
596 xtmp = EXTRACTOR_common_convert_to_utf8 (tmp,
597 strlen (tmp),
598 charset);
599 if (xtmp != NULL)
600 {
601 ret = proc (proc_cls,
602 "html",
603 tagmap[i].type,
604 EXTRACTOR_METAFORMAT_UTF8,
605 "text/plain",
606 xtmp,
607 strlen (xtmp) + 1);
608 free (xtmp);
609 }
610 }
611 } 614 }
612 if (tmp != NULL) 615 }
613 free (tmp);
614 i++;
615 } 616 }
617 if (tmp != NULL)
618 free (tmp);
619 i++;
620 }
616 while (tags != NULL) 621 while (tags != NULL)
622 {
623 t = tags;
624 if ( (tagMatch ("title", t->tagStart, t->tagEnd)) &&
625 (ret == 0) )
617 { 626 {
618 t = tags; 627 if (charset == NULL)
619 if ( (tagMatch ("title", t->tagStart, t->tagEnd)) && 628 {
620 (ret == 0) ) 629 xtmp = malloc (t->dataEnd - t->dataStart + 1);
621 { 630 if (xtmp != NULL)
622 if (charset == NULL) 631 {
623 { 632 memcpy (xtmp, t->dataStart, t->dataEnd - t->dataStart);
624 xtmp = malloc (t->dataEnd - t->dataStart + 1); 633 xtmp[t->dataEnd - t->dataStart] = '\0';
625 if (xtmp != NULL) 634 ret = proc (proc_cls,
626 { 635 "html",
627 memcpy (xtmp, t->dataStart, t->dataEnd - t->dataStart); 636 EXTRACTOR_METATYPE_TITLE,
628 xtmp[t->dataEnd - t->dataStart] = '\0'; 637 EXTRACTOR_METAFORMAT_C_STRING,
629 ret = proc (proc_cls, 638 "text/plain",
630 "html", 639 xtmp,
631 EXTRACTOR_METATYPE_TITLE, 640 strlen (xtmp) + 1);
632 EXTRACTOR_METAFORMAT_C_STRING, 641 free (xtmp);
633 "text/plain", 642 }
634 xtmp, 643 }
635 strlen (xtmp) + 1); 644 else
636 free (xtmp); 645 {
637 } 646 xtmp = EXTRACTOR_common_convert_to_utf8 (t->dataStart,
638 } 647 t->dataEnd - t->dataStart,
639 else 648 charset);
640 { 649 if (xtmp != NULL)
641 xtmp = EXTRACTOR_common_convert_to_utf8 (t->dataStart, 650 {
642 t->dataEnd - t->dataStart, 651 ret = proc (proc_cls,
643 charset); 652 "html",
644 if (xtmp != NULL) 653 EXTRACTOR_METATYPE_TITLE,
645 { 654 EXTRACTOR_METAFORMAT_UTF8,
646 ret = proc (proc_cls, 655 "text/plain",
647 "html", 656 xtmp,
648 EXTRACTOR_METATYPE_TITLE, 657 strlen (xtmp) + 1);
649 EXTRACTOR_METAFORMAT_UTF8, 658 free (xtmp);
650 "text/plain", 659 }
651 xtmp, 660 }
652 strlen (xtmp) + 1);
653 free (xtmp);
654 }
655 }
656 }
657 tags = t->next;
658 free (t);
659 } 661 }
662 tags = t->next;
663 free (t);
664 }
660 if (charset != NULL) 665 if (charset != NULL)
661 free (charset); 666 free (charset);
662 return ret; 667 return ret;
663} 668}
669
670
664#endif 671#endif
665 672
666 673
@@ -672,9 +679,9 @@ html_gobject_init ()
672{ 679{
673 magic = magic_open (MAGIC_MIME_TYPE); 680 magic = magic_open (MAGIC_MIME_TYPE);
674 if (0 != magic_load (magic, NULL)) 681 if (0 != magic_load (magic, NULL))
675 { 682 {
676 /* FIXME: how to deal with errors? */ 683 /* FIXME: how to deal with errors? */
677 } 684 }
678} 685}
679 686
680 687
@@ -685,10 +692,11 @@ void __attribute__ ((destructor))
685html_ltdl_fini () 692html_ltdl_fini ()
686{ 693{
687 if (NULL != magic) 694 if (NULL != magic)
688 { 695 {
689 magic_close (magic); 696 magic_close (magic);
690 magic = NULL; 697 magic = NULL;
691 } 698 }
692} 699}
693 700
701
694/* end of html_extractor.c */ 702/* end of html_extractor.c */
diff --git a/src/plugins/it_extractor.c b/src/plugins/it_extractor.c
index 3d8803f..336392f 100644
--- a/src/plugins/it_extractor.c
+++ b/src/plugins/it_extractor.c
@@ -72,8 +72,8 @@ EXTRACTOR_it_extract_method (struct EXTRACTOR_ExtractContext *ec)
72 72
73 if ((ssize_t) HEADER_SIZE > 73 if ((ssize_t) HEADER_SIZE >
74 ec->read (ec->cls, 74 ec->read (ec->cls,
75 &data, 75 &data,
76 HEADER_SIZE)) 76 HEADER_SIZE))
77 return; 77 return;
78 head = (struct Header *) data; 78 head = (struct Header *) data;
79 /* Check "magic" id bytes */ 79 /* Check "magic" id bytes */
@@ -81,40 +81,41 @@ EXTRACTOR_it_extract_method (struct EXTRACTOR_ExtractContext *ec)
81 return; 81 return;
82 /* Mime-type */ 82 /* Mime-type */
83 if (0 != ec->proc (ec->cls, 83 if (0 != ec->proc (ec->cls,
84 "it", 84 "it",
85 EXTRACTOR_METATYPE_MIMETYPE, 85 EXTRACTOR_METATYPE_MIMETYPE,
86 EXTRACTOR_METAFORMAT_UTF8, 86 EXTRACTOR_METAFORMAT_UTF8,
87 "text/plain", 87 "text/plain",
88 "audio/x-mod", 88 "audio/x-mod",
89 strlen ("audio/x-mod") + 1)) 89 strlen ("audio/x-mod") + 1))
90 return; 90 return;
91 91
92 /* Version of Tracker */ 92 /* Version of Tracker */
93 snprintf (itversion, 93 snprintf (itversion,
94 sizeof (itversion), 94 sizeof (itversion),
95 "%d.%d", 95 "%d.%d",
96 (head->version[0] & 0x01), 96 (head->version[0] & 0x01),
97 head->version[1]); 97 head->version[1]);
98 if (0 != ec->proc (ec->cls, 98 if (0 != ec->proc (ec->cls,
99 "it", 99 "it",
100 EXTRACTOR_METATYPE_FORMAT_VERSION, 100 EXTRACTOR_METATYPE_FORMAT_VERSION,
101 EXTRACTOR_METAFORMAT_C_STRING, 101 EXTRACTOR_METAFORMAT_C_STRING,
102 "text/plain", 102 "text/plain",
103 itversion, 103 itversion,
104 strlen (itversion) + 1)) 104 strlen (itversion) + 1))
105 return; 105 return;
106 106
107 /* Song title */ 107 /* Song title */
108 memcpy (&title, head->title, 26); 108 memcpy (&title, head->title, 26);
109 title[26] = '\0'; 109 title[26] = '\0';
110 if (0 != ec->proc (ec->cls, 110 if (0 != ec->proc (ec->cls,
111 "it", 111 "it",
112 EXTRACTOR_METATYPE_TITLE, 112 EXTRACTOR_METATYPE_TITLE,
113 EXTRACTOR_METAFORMAT_C_STRING, 113 EXTRACTOR_METAFORMAT_C_STRING,
114 "text/plain", 114 "text/plain",
115 title, 115 title,
116 strlen (title) + 1)) 116 strlen (title) + 1))
117 return; 117 return;
118} 118}
119 119
120
120/* end of it_extractor.c */ 121/* end of it_extractor.c */
diff --git a/src/plugins/jpeg_extractor.c b/src/plugins/jpeg_extractor.c
index d6c1f6f..24812bd 100644
--- a/src/plugins/jpeg_extractor.c
+++ b/src/plugins/jpeg_extractor.c
@@ -112,71 +112,73 @@ EXTRACTOR_jpeg_extract_method (struct EXTRACTOR_ExtractContext *ec)
112 jpeg_create_decompress (&jds); 112 jpeg_create_decompress (&jds);
113 jpeg_save_markers (&jds, JPEG_COM, 1024 * 8); 113 jpeg_save_markers (&jds, JPEG_COM, 1024 * 8);
114 while ( (1 == is_jpeg) || (rounds++ < 8) ) 114 while ( (1 == is_jpeg) || (rounds++ < 8) )
115 {
116 if (-1 == (size = ec->read (ec->cls,
117 &buf,
118 16 * 1024)))
119 break;
120 if (0 == size)
121 break;
122 jpeg_mem_src (&jds, buf, size);
123 if (0 == is_jpeg)
115 { 124 {
116 if (-1 == (size = ec->read (ec->cls, 125 if (JPEG_HEADER_OK == jpeg_read_header (&jds, 1))
117 &buf, 126 is_jpeg = 1; /* ok, really a jpeg, keep going until the end */
118 16 * 1024))) 127 continue;
119 break;
120 if (0 == size)
121 break;
122 jpeg_mem_src (&jds, buf, size);
123 if (0 == is_jpeg)
124 {
125 if (JPEG_HEADER_OK == jpeg_read_header (&jds, 1))
126 is_jpeg = 1; /* ok, really a jpeg, keep going until the end */
127 continue;
128 }
129 jpeg_consume_input (&jds);
130 } 128 }
129 jpeg_consume_input (&jds);
130 }
131 131
132 if (1 != is_jpeg) 132 if (1 != is_jpeg)
133 goto EXIT; 133 goto EXIT;
134 if (0 != 134 if (0 !=
135 ec->proc (ec->cls, 135 ec->proc (ec->cls,
136 "jpeg", 136 "jpeg",
137 EXTRACTOR_METATYPE_MIMETYPE, 137 EXTRACTOR_METATYPE_MIMETYPE,
138 EXTRACTOR_METAFORMAT_UTF8, 138 EXTRACTOR_METAFORMAT_UTF8,
139 "text/plain", 139 "text/plain",
140 "image/jpeg", 140 "image/jpeg",
141 strlen ("image/jpeg") + 1)) 141 strlen ("image/jpeg") + 1))
142 goto EXIT; 142 goto EXIT;
143 snprintf (format, 143 snprintf (format,
144 sizeof (format), 144 sizeof (format),
145 "%ux%u", 145 "%ux%u",
146 (unsigned int) jds.image_width, 146 (unsigned int) jds.image_width,
147 (unsigned int) jds.image_height); 147 (unsigned int) jds.image_height);
148 if (0 != 148 if (0 !=
149 ec->proc (ec->cls, 149 ec->proc (ec->cls,
150 "jpeg", 150 "jpeg",
151 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, 151 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
152 EXTRACTOR_METAFORMAT_UTF8, 152 EXTRACTOR_METAFORMAT_UTF8,
153 "text/plain", 153 "text/plain",
154 format, 154 format,
155 strlen (format) + 1)) 155 strlen (format) + 1))
156 goto EXIT; 156 goto EXIT;
157 for (mptr = jds.marker_list; NULL != mptr; mptr = mptr->next) 157 for (mptr = jds.marker_list; NULL != mptr; mptr = mptr->next)
158 { 158 {
159 size_t off; 159 size_t off;
160 160
161 if (JPEG_COM != mptr->marker) 161 if (JPEG_COM != mptr->marker)
162 continue; 162 continue;
163 off = 0; 163 off = 0;
164 while ( (off < mptr->data_length) && 164 while ( (off < mptr->data_length) &&
165 (isspace (((const unsigned char *)mptr->data)[mptr->data_length - 1 - off])) ) 165 (isspace (((const unsigned char *) mptr->data)[mptr->data_length
166 off++; 166 - 1 - off])) )
167 if (0 != 167 off++;
168 ec->proc (ec->cls, 168 if (0 !=
169 "jpeg", 169 ec->proc (ec->cls,
170 EXTRACTOR_METATYPE_COMMENT, 170 "jpeg",
171 EXTRACTOR_METAFORMAT_C_STRING, 171 EXTRACTOR_METATYPE_COMMENT,
172 "text/plain", 172 EXTRACTOR_METAFORMAT_C_STRING,
173 (const char *) mptr->data, 173 "text/plain",
174 mptr->data_length - off)) 174 (const char *) mptr->data,
175 goto EXIT; 175 mptr->data_length - off))
176 } 176 goto EXIT;
177 177 }
178 EXIT: 178
179EXIT:
179 jpeg_destroy_decompress (&jds); 180 jpeg_destroy_decompress (&jds);
180} 181}
181 182
183
182/* end of jpeg_extractor.c */ 184/* end of jpeg_extractor.c */
diff --git a/src/plugins/man_extractor.c b/src/plugins/man_extractor.c
index b92fc9e..86ba68d 100644
--- a/src/plugins/man_extractor.c
+++ b/src/plugins/man_extractor.c
@@ -59,35 +59,35 @@ stndup (const char *str, size_t n)
59 */ 59 */
60static int 60static int
61add_keyword (enum EXTRACTOR_MetaType type, 61add_keyword (enum EXTRACTOR_MetaType type,
62 char *keyword, 62 char *keyword,
63 EXTRACTOR_MetaDataProcessor proc, 63 EXTRACTOR_MetaDataProcessor proc,
64 void *proc_cls) 64 void *proc_cls)
65{ 65{
66 int ret; 66 int ret;
67 char *value; 67 char *value;
68 68
69 if (NULL == keyword) 69 if (NULL == keyword)
70 return 0; 70 return 0;
71 if ( (keyword[0] == '\"') && 71 if ( (keyword[0] == '\"') &&
72 (keyword[strlen (keyword) - 1] == '\"') ) 72 (keyword[strlen (keyword) - 1] == '\"') )
73 { 73 {
74 keyword[strlen (keyword) - 1] = '\0'; 74 keyword[strlen (keyword) - 1] = '\0';
75 value = &keyword[1]; 75 value = &keyword[1];
76 } 76 }
77 else 77 else
78 value = keyword; 78 value = keyword;
79 if (0 == strlen (value)) 79 if (0 == strlen (value))
80 { 80 {
81 free (keyword); 81 free (keyword);
82 return 0; 82 return 0;
83 } 83 }
84 ret = proc (proc_cls, 84 ret = proc (proc_cls,
85 "man", 85 "man",
86 type, 86 type,
87 EXTRACTOR_METAFORMAT_UTF8, 87 EXTRACTOR_METAFORMAT_UTF8,
88 "text/plain", 88 "text/plain",
89 value, 89 value,
90 strlen (value)+1); 90 strlen (value) + 1);
91 free (keyword); 91 free (keyword);
92 return ret; 92 return ret;
93} 93}
@@ -102,20 +102,20 @@ add_keyword (enum EXTRACTOR_MetaType type,
102 */ 102 */
103static void 103static void
104find_end_of_token (size_t *end, 104find_end_of_token (size_t *end,
105 const char *buf, 105 const char *buf,
106 const size_t size) 106 const size_t size)
107{ 107{
108 int quot; 108 int quot;
109 109
110 quot = 0; 110 quot = 0;
111 while ( (*end < size) && 111 while ( (*end < size) &&
112 ( (0 != (quot & 1)) || 112 ( (0 != (quot & 1)) ||
113 ((' ' != buf[*end])) ) ) 113 ((' ' != buf[*end])) ) )
114 { 114 {
115 if ('\"' == buf[*end]) 115 if ('\"' == buf[*end])
116 quot++; 116 quot++;
117 (*end)++; 117 (*end)++;
118 } 118 }
119 if (1 == (quot & 1)) 119 if (1 == (quot & 1))
120 (*end) = size + 1; 120 (*end) = size + 1;
121} 121}
@@ -130,15 +130,16 @@ find_end_of_token (size_t *end,
130 130
131/** 131/**
132 * Add a keyword to LE. 132 * Add a keyword to LE.
133 * 133 *
134 * @param t type to use 134 * @param t type to use
135 * @param s keyword to give to LE 135 * @param s keyword to give to LE
136 */ 136 */
137#define ADD(t,s) do { if (0 != add_keyword (t, s, ec->proc, ec->cls)) return; } while (0) 137#define ADD(t,s) do { if (0 != add_keyword (t, s, ec->proc, ec->cls)) return; \
138} while (0)
138 139
139 140
140/** 141/**
141 * Main entry method for the man page extraction plugin. 142 * Main entry method for the man page extraction plugin.
142 * 143 *
143 * @param ec extraction context provided to the plugin 144 * @param ec extraction context provided to the plugin
144 */ 145 */
@@ -152,7 +153,7 @@ EXTRACTOR_man_extract_method (struct EXTRACTOR_ExtractContext *ec)
152 void *data; 153 void *data;
153 ssize_t size; 154 ssize_t size;
154 char *buf; 155 char *buf;
155 156
156 if (0 >= (size = ec->read (ec->cls, &data, MAX_READ))) 157 if (0 >= (size = ec->read (ec->cls, &data, MAX_READ)))
157 return; 158 return;
158 buf = data; 159 buf = data;
@@ -162,17 +163,17 @@ EXTRACTOR_man_extract_method (struct EXTRACTOR_ExtractContext *ec)
162 /* find actual beginning of the man page (.TH); 163 /* find actual beginning of the man page (.TH);
163 abort if we find non-printable characters */ 164 abort if we find non-printable characters */
164 while ( (pos < size - xlen) && 165 while ( (pos < size - xlen) &&
165 ( (0 != strncmp (".TH ", 166 ( (0 != strncmp (".TH ",
166 &buf[pos], 167 &buf[pos],
167 xlen)) || 168 xlen)) ||
168 ( (0 != pos) && 169 ( (0 != pos) &&
169 (buf[pos - 1] != '\n') ) ) ) 170 (buf[pos - 1] != '\n') ) ) )
170 { 171 {
171 if ( (! isgraph ((unsigned char) buf[pos])) && 172 if ( (! isgraph ((unsigned char) buf[pos])) &&
172 (! isspace ((unsigned char) buf[pos])) ) 173 (! isspace ((unsigned char) buf[pos])) )
173 return; 174 return;
174 pos++; 175 pos++;
175 } 176 }
176 if (0 != strncmp (".TH ", &buf[pos], xlen)) 177 if (0 != strncmp (".TH ", &buf[pos], xlen))
177 return; 178 return;
178 179
@@ -192,13 +193,13 @@ EXTRACTOR_man_extract_method (struct EXTRACTOR_ExtractContext *ec)
192 if (end > size) 193 if (end > size)
193 return; 194 return;
194 if (end > pos) 195 if (end > pos)
195 { 196 {
196 ADD (EXTRACTOR_METATYPE_TITLE, stndup (&buf[pos], end - pos)); 197 ADD (EXTRACTOR_METATYPE_TITLE, stndup (&buf[pos], end - pos));
197 pos = end + 1; 198 pos = end + 1;
198 } 199 }
199 if (pos >= size) 200 if (pos >= size)
200 return; 201 return;
201 202
202 /* next token is the section */ 203 /* next token is the section */
203 end = pos; 204 end = pos;
204 find_end_of_token (&end, buf, size); 205 find_end_of_token (&end, buf, size);
@@ -207,62 +208,62 @@ EXTRACTOR_man_extract_method (struct EXTRACTOR_ExtractContext *ec)
207 if ('\"' == buf[pos]) 208 if ('\"' == buf[pos])
208 pos++; 209 pos++;
209 if ((end - pos >= 1) && (end - pos <= 4)) 210 if ((end - pos >= 1) && (end - pos <= 4))
211 {
212 switch (buf[pos])
210 { 213 {
211 switch (buf[pos]) 214 case '1':
212 { 215 ADD (EXTRACTOR_METATYPE_SECTION,
213 case '1': 216 strdup (_ ("Commands")));
214 ADD (EXTRACTOR_METATYPE_SECTION, 217 break;
215 strdup (_("Commands"))); 218 case '2':
216 break; 219 ADD (EXTRACTOR_METATYPE_SECTION,
217 case '2': 220 strdup (_ ("System calls")));
218 ADD (EXTRACTOR_METATYPE_SECTION, 221 break;
219 strdup (_("System calls"))); 222 case '3':
220 break; 223 ADD (EXTRACTOR_METATYPE_SECTION,
221 case '3': 224 strdup (_ ("Library calls")));
222 ADD (EXTRACTOR_METATYPE_SECTION, 225 break;
223 strdup (_("Library calls"))); 226 case '4':
224 break; 227 ADD (EXTRACTOR_METATYPE_SECTION,
225 case '4': 228 strdup (_ ("Special files")));
226 ADD (EXTRACTOR_METATYPE_SECTION, 229 break;
227 strdup (_("Special files"))); 230 case '5':
228 break; 231 ADD (EXTRACTOR_METATYPE_SECTION,
229 case '5': 232 strdup (_ ("File formats and conventions")));
230 ADD (EXTRACTOR_METATYPE_SECTION, 233 break;
231 strdup (_("File formats and conventions"))); 234 case '6':
232 break; 235 ADD (EXTRACTOR_METATYPE_SECTION,
233 case '6': 236 strdup (_ ("Games")));
234 ADD (EXTRACTOR_METATYPE_SECTION, 237 break;
235 strdup (_("Games"))); 238 case '7':
236 break; 239 ADD (EXTRACTOR_METATYPE_SECTION,
237 case '7': 240 strdup (_ ("Conventions and miscellaneous")));
238 ADD (EXTRACTOR_METATYPE_SECTION, 241 break;
239 strdup (_("Conventions and miscellaneous"))); 242 case '8':
240 break; 243 ADD (EXTRACTOR_METATYPE_SECTION,
241 case '8': 244 strdup (_ ("System management commands")));
242 ADD (EXTRACTOR_METATYPE_SECTION, 245 break;
243 strdup (_("System management commands"))); 246 case '9':
244 break; 247 ADD (EXTRACTOR_METATYPE_SECTION,
245 case '9': 248 strdup (_ ("Kernel routines")));
246 ADD (EXTRACTOR_METATYPE_SECTION, 249 break;
247 strdup (_("Kernel routines"))); 250 default:
248 break; 251 ADD (EXTRACTOR_METATYPE_SECTION,
249 default: 252 stndup (&buf[pos], 1));
250 ADD (EXTRACTOR_METATYPE_SECTION,
251 stndup (&buf[pos], 1));
252 }
253 pos = end + 1;
254 } 253 }
254 pos = end + 1;
255 }
255 end = pos; 256 end = pos;
256 257
257 /* next token is the modification date */ 258 /* next token is the modification date */
258 find_end_of_token (&end, buf, size); 259 find_end_of_token (&end, buf, size);
259 if (end > size) 260 if (end > size)
260 return; 261 return;
261 if (end > pos) 262 if (end > pos)
262 { 263 {
263 ADD (EXTRACTOR_METATYPE_MODIFICATION_DATE, stndup (&buf[pos], end - pos)); 264 ADD (EXTRACTOR_METATYPE_MODIFICATION_DATE, stndup (&buf[pos], end - pos));
264 pos = end + 1; 265 pos = end + 1;
265 } 266 }
266 267
267 /* next token is the source of the man page */ 268 /* next token is the source of the man page */
268 end = pos; 269 end = pos;
@@ -270,11 +271,11 @@ EXTRACTOR_man_extract_method (struct EXTRACTOR_ExtractContext *ec)
270 if (end > size) 271 if (end > size)
271 return; 272 return;
272 if (end > pos) 273 if (end > pos)
273 { 274 {
274 ADD (EXTRACTOR_METATYPE_SOURCE, 275 ADD (EXTRACTOR_METATYPE_SOURCE,
275 stndup (&buf[pos], end - pos)); 276 stndup (&buf[pos], end - pos));
276 pos = end + 1; 277 pos = end + 1;
277 } 278 }
278 279
279 /* last token is the title of the book the man page belongs to */ 280 /* last token is the title of the book the man page belongs to */
280 end = pos; 281 end = pos;
@@ -282,11 +283,12 @@ EXTRACTOR_man_extract_method (struct EXTRACTOR_ExtractContext *ec)
282 if (end > size) 283 if (end > size)
283 return; 284 return;
284 if (end > pos) 285 if (end > pos)
285 { 286 {
286 ADD (EXTRACTOR_METATYPE_BOOK_TITLE, 287 ADD (EXTRACTOR_METATYPE_BOOK_TITLE,
287 stndup (&buf[pos], end - pos)); 288 stndup (&buf[pos], end - pos));
288 pos = end + 1; 289 pos = end + 1;
289 } 290 }
290} 291}
291 292
293
292/* end of man_extractor.c */ 294/* end of man_extractor.c */
diff --git a/src/plugins/midi_extractor.c b/src/plugins/midi_extractor.c
index 4ceff6a..66ea71d 100644
--- a/src/plugins/midi_extractor.c
+++ b/src/plugins/midi_extractor.c
@@ -31,27 +31,27 @@
31 * Types of events in MIDI. 31 * Types of events in MIDI.
32 */ 32 */
33enum EventType 33enum EventType
34 { 34{
35 ET_SEQUENCE_NUMBER = 0, 35 ET_SEQUENCE_NUMBER = 0,
36 ET_TEXT_EVENT = 1, 36 ET_TEXT_EVENT = 1,
37 ET_COPYRIGHT_NOTICE = 2, 37 ET_COPYRIGHT_NOTICE = 2,
38 ET_TRACK_NAME = 3, 38 ET_TRACK_NAME = 3,
39 ET_INSTRUMENT_NAME = 4, 39 ET_INSTRUMENT_NAME = 4,
40 ET_LYRIC_TEXT = 5, 40 ET_LYRIC_TEXT = 5,
41 ET_MARKER_TEXT = 6, 41 ET_MARKER_TEXT = 6,
42 ET_CUE_POINT = 7, 42 ET_CUE_POINT = 7,
43 ET_CHANNEL_PREFIX_ASSIGNMENT = 0x20, 43 ET_CHANNEL_PREFIX_ASSIGNMENT = 0x20,
44 ET_END_OF_TRACK = 0x2F, 44 ET_END_OF_TRACK = 0x2F,
45 ET_TEMPO_SETTING = 0x51, 45 ET_TEMPO_SETTING = 0x51,
46 ET_SMPTE_OFFSET = 0x54, 46 ET_SMPTE_OFFSET = 0x54,
47 ET_TIME_SIGNATURE = 0x58, 47 ET_TIME_SIGNATURE = 0x58,
48 ET_KEY_SIGNATURE = 0x59, 48 ET_KEY_SIGNATURE = 0x59,
49 ET_SEQUENCE_SPECIRFIC_EVENT = 0x7F 49 ET_SEQUENCE_SPECIRFIC_EVENT = 0x7F
50 }; 50};
51 51
52 52
53/** 53/**
54 * Main entry method for the 'audio/midi' extraction plugin. 54 * Main entry method for the 'audio/midi' extraction plugin.
55 * 55 *
56 * @param ec extraction context provided to the plugin 56 * @param ec extraction context provided to the plugin
57 */ 57 */
@@ -66,7 +66,7 @@ EXTRACTOR_midi_extract_method (struct EXTRACTOR_ExtractContext *ec)
66 smf_t *m = NULL; 66 smf_t *m = NULL;
67 smf_event_t *event; 67 smf_event_t *event;
68 uint8_t len; 68 uint8_t len;
69 69
70 if (4 >= (iret = ec->read (ec->cls, &buf, 1024))) 70 if (4 >= (iret = ec->read (ec->cls, &buf, 1024)))
71 return; 71 return;
72 data = buf; 72 data = buf;
@@ -81,103 +81,103 @@ EXTRACTOR_midi_extract_method (struct EXTRACTOR_ExtractContext *ec)
81 memcpy (data, buf, iret); 81 memcpy (data, buf, iret);
82 off = iret; 82 off = iret;
83 while (off < size) 83 while (off < size)
84 {
85 if (0 >= (iret = ec->read (ec->cls, &buf, 16 * 1024)))
84 { 86 {
85 if (0 >= (iret = ec->read (ec->cls, &buf, 16 * 1024))) 87 free (data);
86 { 88 return;
87 free (data); 89 }
88 return; 90 memcpy (&data[off], buf, iret);
89 } 91 off += iret;
90 memcpy (&data[off], buf, iret); 92 }
91 off += iret; 93 if (0 != ec->proc (ec->cls,
92 } 94 "midi",
93 if (0 != ec->proc (ec->cls, 95 EXTRACTOR_METATYPE_MIMETYPE,
94 "midi", 96 EXTRACTOR_METAFORMAT_UTF8,
95 EXTRACTOR_METATYPE_MIMETYPE, 97 "text/plain",
96 EXTRACTOR_METAFORMAT_UTF8, 98 "audio/midi",
97 "text/plain", 99 strlen ("audio/midi") + 1))
98 "audio/midi",
99 strlen ("audio/midi") + 1))
100 goto CLEANUP; 100 goto CLEANUP;
101 if (NULL == (m = smf_load_from_memory (data, size))) 101 if (NULL == (m = smf_load_from_memory (data, size)))
102 goto CLEANUP; 102 goto CLEANUP;
103 while (NULL != (event = smf_get_next_event (m))) 103 while (NULL != (event = smf_get_next_event (m)))
104 { 104 {
105 if (! smf_event_is_metadata (event)) 105 if (! smf_event_is_metadata (event))
106 break; 106 break;
107 len = event->midi_buffer[2]; 107 len = event->midi_buffer[2];
108 if ( (len > 0) && 108 if ( (len > 0) &&
109 isspace (event->midi_buffer[2 + len])) 109 isspace (event->midi_buffer[2 + len]))
110 len--; 110 len--;
111#if 0 111#if 0
112 fprintf (stderr, 112 fprintf (stderr,
113 "type: %d, len: %d value: %.*s\n", 113 "type: %d, len: %d value: %.*s\n",
114 event->midi_buffer[1], 114 event->midi_buffer[1],
115 event->midi_buffer[2], 115 event->midi_buffer[2],
116 (int) event->midi_buffer_length - 3, 116 (int) event->midi_buffer_length - 3,
117 (char *) &event->midi_buffer[3]); 117 (char *) &event->midi_buffer[3]);
118#endif 118#endif
119 if (1 != event->track_number) 119 if (1 != event->track_number)
120 continue; /* heuristic to not get instruments */ 120 continue; /* heuristic to not get instruments */
121 if (0 == len) 121 if (0 == len)
122 continue; 122 continue;
123 switch (event->midi_buffer[1]) 123 switch (event->midi_buffer[1])
124 { 124 {
125 case ET_TEXT_EVENT: 125 case ET_TEXT_EVENT:
126 if (0 != ec->proc (ec->cls, 126 if (0 != ec->proc (ec->cls,
127 "midi", 127 "midi",
128 EXTRACTOR_METATYPE_COMMENT, 128 EXTRACTOR_METATYPE_COMMENT,
129 EXTRACTOR_METAFORMAT_UTF8, 129 EXTRACTOR_METAFORMAT_UTF8,
130 "text/plain", 130 "text/plain",
131 (void*) &event->midi_buffer[3], 131 (void*) &event->midi_buffer[3],
132 len)) 132 len))
133 goto CLEANUP; 133 goto CLEANUP;
134 break; 134 break;
135 case ET_COPYRIGHT_NOTICE: 135 case ET_COPYRIGHT_NOTICE:
136 if (0 != ec->proc (ec->cls, 136 if (0 != ec->proc (ec->cls,
137 "midi", 137 "midi",
138 EXTRACTOR_METATYPE_COPYRIGHT, 138 EXTRACTOR_METATYPE_COPYRIGHT,
139 EXTRACTOR_METAFORMAT_UTF8, 139 EXTRACTOR_METAFORMAT_UTF8,
140 "text/plain", 140 "text/plain",
141 (void*) &event->midi_buffer[3], 141 (void*) &event->midi_buffer[3],
142 len)) 142 len))
143 goto CLEANUP; 143 goto CLEANUP;
144 break; 144 break;
145 case ET_TRACK_NAME: 145 case ET_TRACK_NAME:
146 if (0 != ec->proc (ec->cls, 146 if (0 != ec->proc (ec->cls,
147 "midi", 147 "midi",
148 EXTRACTOR_METATYPE_TITLE, 148 EXTRACTOR_METATYPE_TITLE,
149 EXTRACTOR_METAFORMAT_UTF8, 149 EXTRACTOR_METAFORMAT_UTF8,
150 "text/plain", 150 "text/plain",
151 (void*) &event->midi_buffer[3], 151 (void*) &event->midi_buffer[3],
152 len)) 152 len))
153 goto CLEANUP; 153 goto CLEANUP;
154 break; 154 break;
155 case ET_INSTRUMENT_NAME: 155 case ET_INSTRUMENT_NAME:
156 if (0 != ec->proc (ec->cls, 156 if (0 != ec->proc (ec->cls,
157 "midi", 157 "midi",
158 EXTRACTOR_METATYPE_SOURCE_DEVICE, 158 EXTRACTOR_METATYPE_SOURCE_DEVICE,
159 EXTRACTOR_METAFORMAT_UTF8, 159 EXTRACTOR_METAFORMAT_UTF8,
160 "text/plain", 160 "text/plain",
161 (void*) &event->midi_buffer[3], 161 (void*) &event->midi_buffer[3],
162 len)) 162 len))
163 goto CLEANUP; 163 goto CLEANUP;
164 break; 164 break;
165 case ET_LYRIC_TEXT: 165 case ET_LYRIC_TEXT:
166 if (0 != ec->proc (ec->cls, 166 if (0 != ec->proc (ec->cls,
167 "midi", 167 "midi",
168 EXTRACTOR_METATYPE_LYRICS, 168 EXTRACTOR_METATYPE_LYRICS,
169 EXTRACTOR_METAFORMAT_UTF8, 169 EXTRACTOR_METAFORMAT_UTF8,
170 "text/plain", 170 "text/plain",
171 (void*) &event->midi_buffer[3], 171 (void*) &event->midi_buffer[3],
172 len)) 172 len))
173 goto CLEANUP; 173 goto CLEANUP;
174 break; 174 break;
175 default: 175 default:
176 break; 176 break;
177 }
178 } 177 }
179 178 }
180 CLEANUP: 179
180CLEANUP:
181 if (NULL != m) 181 if (NULL != m)
182 smf_delete (m); 182 smf_delete (m);
183 free (data); 183 free (data);
diff --git a/src/plugins/mime_extractor.c b/src/plugins/mime_extractor.c
index b9fb3cf..cfcfab9 100644
--- a/src/plugins/mime_extractor.c
+++ b/src/plugins/mime_extractor.c
@@ -36,7 +36,7 @@ static magic_t magic;
36 * Path we used for loading magic data, NULL is used for 'default'. 36 * Path we used for loading magic data, NULL is used for 'default'.
37 */ 37 */
38static char *magic_path; 38static char *magic_path;
39 39
40 40
41/** 41/**
42 * Main entry method for the 'application/ogg' extraction plugin. The 42 * Main entry method for the 'application/ogg' extraction plugin. The
@@ -54,74 +54,75 @@ EXTRACTOR_mime_extract_method (struct EXTRACTOR_ExtractContext *ec)
54 const char *mime; 54 const char *mime;
55 55
56 ret = ec->read (ec->cls, 56 ret = ec->read (ec->cls,
57 &buf, 57 &buf,
58 16 * 1024); 58 16 * 1024);
59 if (-1 == ret) 59 if (-1 == ret)
60 return; 60 return;
61 if ( ( (NULL == magic_path) && 61 if ( ( (NULL == magic_path) &&
62 (NULL != ec->config) ) || 62 (NULL != ec->config) ) ||
63 ( (NULL != magic_path) && 63 ( (NULL != magic_path) &&
64 (NULL == ec->config) ) || 64 (NULL == ec->config) ) ||
65 ( (NULL != magic_path) && 65 ( (NULL != magic_path) &&
66 (NULL != ec->config) && 66 (NULL != ec->config) &&
67 (0 != strcmp (magic_path, 67 (0 != strcmp (magic_path,
68 ec->config) )) ) 68 ec->config) )) )
69 {
70 if (NULL != magic_path)
71 free (magic_path);
72 magic_close (magic);
73 magic = magic_open (MAGIC_MIME_TYPE);
74 if (0 != magic_load (magic, ec->config))
69 { 75 {
70 if (NULL != magic_path) 76 /* FIXME: report errors? */
71 free (magic_path);
72 magic_close (magic);
73 magic = magic_open (MAGIC_MIME_TYPE);
74 if (0 != magic_load (magic, ec->config))
75 {
76 /* FIXME: report errors? */
77 }
78 if (NULL != ec->config)
79 magic_path = strdup (ec->config);
80 else
81 magic_path = NULL;
82 } 77 }
78 if (NULL != ec->config)
79 magic_path = strdup (ec->config);
80 else
81 magic_path = NULL;
82 }
83 if (NULL == (mime = magic_buffer (magic, buf, ret))) 83 if (NULL == (mime = magic_buffer (magic, buf, ret)))
84 return; 84 return;
85 ec->proc (ec->cls, 85 ec->proc (ec->cls,
86 "mime", 86 "mime",
87 EXTRACTOR_METATYPE_MIMETYPE, 87 EXTRACTOR_METATYPE_MIMETYPE,
88 EXTRACTOR_METAFORMAT_UTF8, 88 EXTRACTOR_METAFORMAT_UTF8,
89 "text/plain", 89 "text/plain",
90 mime, 90 mime,
91 strlen (mime) + 1); 91 strlen (mime) + 1);
92} 92}
93 93
94 94
95/** 95/**
96 * Constructor for the library. Loads the magic file. 96 * Constructor for the library. Loads the magic file.
97 */ 97 */
98void __attribute__ ((constructor)) 98void __attribute__ ((constructor))
99mime_ltdl_init () 99mime_ltdl_init ()
100{ 100{
101 magic = magic_open (MAGIC_MIME_TYPE); 101 magic = magic_open (MAGIC_MIME_TYPE);
102 if (0 != magic_load (magic, magic_path)) 102 if (0 != magic_load (magic, magic_path))
103 { 103 {
104 /* FIXME: how to deal with errors? */ 104 /* FIXME: how to deal with errors? */
105 } 105 }
106} 106}
107 107
108 108
109/** 109/**
110 * Destructor for the library, cleans up. 110 * Destructor for the library, cleans up.
111 */ 111 */
112void __attribute__ ((destructor)) 112void __attribute__ ((destructor))
113mime_ltdl_fini () 113mime_ltdl_fini ()
114{ 114{
115 if (NULL != magic) 115 if (NULL != magic)
116 { 116 {
117 magic_close (magic); 117 magic_close (magic);
118 magic = NULL; 118 magic = NULL;
119 } 119 }
120 if (NULL != magic_path) 120 if (NULL != magic_path)
121 { 121 {
122 free (magic_path); 122 free (magic_path);
123 magic_path = NULL; 123 magic_path = NULL;
124 } 124 }
125} 125}
126 126
127
127/* end of mime_extractor.c */ 128/* end of mime_extractor.c */
diff --git a/src/plugins/mp4_extractor.c b/src/plugins/mp4_extractor.c
index 89be634..b8ad84c 100644
--- a/src/plugins/mp4_extractor.c
+++ b/src/plugins/mp4_extractor.c
@@ -29,7 +29,7 @@
29 29
30 30
31/** 31/**
32 * Callback invoked by libmp4v2 to open the file. 32 * Callback invoked by libmp4v2 to open the file.
33 * We cheated and passed our extractor context as 33 * We cheated and passed our extractor context as
34 * the filename (fingers crossed) and will simply 34 * the filename (fingers crossed) and will simply
35 * return it again to make it the handle. 35 * return it again to make it the handle.
@@ -40,7 +40,7 @@
40 */ 40 */
41static void* 41static void*
42open_cb (const char *name, 42open_cb (const char *name,
43 MP4FileMode mode) 43 MP4FileMode mode)
44{ 44{
45 void *ecp; 45 void *ecp;
46 46
@@ -61,15 +61,15 @@ open_cb (const char *name,
61 */ 61 */
62static int 62static int
63seek_cb (void *handle, 63seek_cb (void *handle,
64 int64_t pos) 64 int64_t pos)
65{ 65{
66 struct EXTRACTOR_ExtractContext *ec = handle; 66 struct EXTRACTOR_ExtractContext *ec = handle;
67 67
68 fprintf (stderr, "Seek: %lld!\n", (long long) pos); 68 fprintf (stderr, "Seek: %lld!\n", (long long) pos);
69 if (-1 == 69 if (-1 ==
70 ec->seek (ec->cls, 70 ec->seek (ec->cls,
71 pos, 71 pos,
72 SEEK_CUR)) 72 SEEK_CUR))
73 return true; /* failure */ 73 return true; /* failure */
74 return false; 74 return false;
75} 75}
@@ -85,23 +85,23 @@ seek_cb (void *handle,
85 * @param maxChunkSize some chunk size (ignored) 85 * @param maxChunkSize some chunk size (ignored)
86 * @return true on failure, false on success 86 * @return true on failure, false on success
87 */ 87 */
88static int 88static int
89read_cb (void *handle, 89read_cb (void *handle,
90 void *buffer, 90 void *buffer,
91 int64_t size, 91 int64_t size,
92 int64_t *nin, 92 int64_t *nin,
93 int64_t maxChunkSize) 93 int64_t maxChunkSize)
94{ 94{
95 struct EXTRACTOR_ExtractContext *ec = handle; 95 struct EXTRACTOR_ExtractContext *ec = handle;
96 void *buf; 96 void *buf;
97 ssize_t ret; 97 ssize_t ret;
98 98
99 fprintf (stderr, "read!\n"); 99 fprintf (stderr, "read!\n");
100 *nin = 0; 100 *nin = 0;
101 if (-1 == 101 if (-1 ==
102 (ret = ec->read (ec->cls, 102 (ret = ec->read (ec->cls,
103 &buf, 103 &buf,
104 size))) 104 size)))
105 return true; /* failure */ 105 return true; /* failure */
106 memcpy (buffer, buf, ret); 106 memcpy (buffer, buf, ret);
107 *nin = ret; 107 *nin = ret;
@@ -121,10 +121,10 @@ read_cb (void *handle,
121 */ 121 */
122static int 122static int
123write_cb (void *handle, 123write_cb (void *handle,
124 const void *buffer, 124 const void *buffer,
125 int64_t size, 125 int64_t size,
126 int64_t *nout, 126 int64_t *nout,
127 int64_t maxChunkSize) 127 int64_t maxChunkSize)
128{ 128{
129 fprintf (stderr, "Write!?\n"); 129 fprintf (stderr, "Write!?\n");
130 return true; /* failure */ 130 return true; /* failure */
@@ -149,24 +149,26 @@ close_cb (void *handle)
149/** 149/**
150 * Wrapper to replace 'stat64' call by libmp4v2. 150 * Wrapper to replace 'stat64' call by libmp4v2.
151 */ 151 */
152int 152int
153stat_cb (const char * path, 153stat_cb (const char *path,
154 struct stat64 * buf) 154 struct stat64 *buf)
155{ 155{
156 void *ecp; 156 void *ecp;
157 struct EXTRACTOR_ExtractContext *ec; 157 struct EXTRACTOR_ExtractContext *ec;
158 158
159 fprintf (stderr, "stat!\n"); 159 fprintf (stderr, "stat!\n");
160 if (1 != sscanf (path, "%p", &ecp)) 160 if (1 != sscanf (path, "%p", &ecp))
161 { 161 {
162 errno = EINVAL; 162 errno = EINVAL;
163 return -1; 163 return -1;
164 } 164 }
165 ec = ecp; 165 ec = ecp;
166 memset (buf, 0, sizeof (struct stat)); 166 memset (buf, 0, sizeof (struct stat));
167 buf->st_size = ec->get_size (ec->cls); 167 buf->st_size = ec->get_size (ec->cls);
168 return 0; 168 return 0;
169} 169}
170
171
170#endif 172#endif
171 173
172 174
@@ -175,7 +177,7 @@ stat_cb (const char * path,
175 * 177 *
176 * @param ec extraction context provided to the plugin 178 * @param ec extraction context provided to the plugin
177 */ 179 */
178void 180void
179EXTRACTOR_mp4_extract_method (struct EXTRACTOR_ExtractContext *ec) 181EXTRACTOR_mp4_extract_method (struct EXTRACTOR_ExtractContext *ec)
180{ 182{
181 MP4FileProvider fp; 183 MP4FileProvider fp;
@@ -185,7 +187,7 @@ EXTRACTOR_mp4_extract_method (struct EXTRACTOR_ExtractContext *ec)
185 187
186 if (1) 188 if (1)
187 return; /* plugin is known not to work yet; 189 return; /* plugin is known not to work yet;
188 see issue 138 filed against MP4v2 lib */ 190 see issue 138 filed against MP4v2 lib */
189 snprintf (ecp, sizeof (ecp), "%p", ec); 191 snprintf (ecp, sizeof (ecp), "%p", ec);
190 fp.open = &open_cb; 192 fp.open = &open_cb;
191 fp.seek = &seek_cb; 193 fp.seek = &seek_cb;
@@ -193,14 +195,15 @@ EXTRACTOR_mp4_extract_method (struct EXTRACTOR_ExtractContext *ec)
193 fp.write = &write_cb; 195 fp.write = &write_cb;
194 fp.close = &close_cb; 196 fp.close = &close_cb;
195 if (NULL == (mp4 = MP4ReadProvider (ecp, 197 if (NULL == (mp4 = MP4ReadProvider (ecp,
196 &fp))) 198 &fp)))
197 return; 199 return;
198 tags = MP4TagsAlloc (); 200 tags = MP4TagsAlloc ();
199 if (MP4TagsFetch (tags, mp4)) 201 if (MP4TagsFetch (tags, mp4))
200 { 202 {
201 fprintf (stderr, "got tags!\n"); 203 fprintf (stderr, "got tags!\n");
202 } 204 }
203 MP4Close (mp4, 0); 205 MP4Close (mp4, 0);
204} 206}
205 207
208
206/* end of mp4_extractor.c */ 209/* end of mp4_extractor.c */
diff --git a/src/plugins/mpeg_extractor.c b/src/plugins/mpeg_extractor.c
index 627cae0..9c5f0b8 100644
--- a/src/plugins/mpeg_extractor.c
+++ b/src/plugins/mpeg_extractor.c
@@ -34,7 +34,11 @@
34 * @param t type of the meta data 34 * @param t type of the meta data
35 * @param s meta data value in utf8 format 35 * @param s meta data value in utf8 format
36 */ 36 */
37#define ADD(s,t) do { if (0 != ec->proc (ec->cls, "mpeg", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen (s) + 1)) goto EXIT; } while (0) 37#define ADD(s,t) do { if (0 != ec->proc (ec->cls, "mpeg", t, \
38 EXTRACTOR_METAFORMAT_UTF8, \
39 "text/plain", s, strlen (s) \
40 + 1)) goto EXIT; \
41} while (0)
38 42
39 43
40/** 44/**
@@ -68,10 +72,10 @@ EXTRACTOR_mpeg_extract_method (struct EXTRACTOR_ExtractContext *ec)
68 if (NULL == (handle = mpeg2_init ())) 72 if (NULL == (handle = mpeg2_init ()))
69 return; 73 return;
70 if (NULL == (info = mpeg2_info (handle))) 74 if (NULL == (info = mpeg2_info (handle)))
71 { 75 {
72 mpeg2_close (handle); 76 mpeg2_close (handle);
73 return; 77 return;
74 } 78 }
75 fsize = ec->get_size (ec->cls); 79 fsize = ec->get_size (ec->cls);
76 buf = NULL; 80 buf = NULL;
77 have_gop = 0; 81 have_gop = 0;
@@ -86,130 +90,131 @@ EXTRACTOR_mpeg_extract_method (struct EXTRACTOR_ExtractContext *ec)
86 fmac = 0; 90 fmac = 0;
87 lformat[0] = '\0'; 91 lformat[0] = '\0';
88 while (1) 92 while (1)
93 {
94 state = mpeg2_parse (handle);
95 switch (state)
89 { 96 {
90 state = mpeg2_parse (handle); 97 case STATE_BUFFER:
91 switch (state) 98 if (fail_count > 16)
92 { 99 goto EXIT; /* do not read large non-mpeg files */
93 case STATE_BUFFER: 100 fail_count++;
94 if (fail_count > 16) 101 if (0 >= (avail = ec->read (ec->cls,
95 goto EXIT; /* do not read large non-mpeg files */ 102 &buf,
96 fail_count++; 103 16 * 1024)))
97 if (0 >= (avail = ec->read (ec->cls, 104 goto EXIT;
98 &buf, 105 mpeg2_buffer (handle, buf, buf + avail);
99 16 * 1024))) 106 break;
100 goto EXIT; 107 case STATE_SEQUENCE:
101 mpeg2_buffer (handle, buf, buf + avail); 108 fail_count = 0;
102 break; 109 format[0] = fsize;
103 case STATE_SEQUENCE: 110 format[0]++;
104 fail_count = 0; 111 if (0 == mime)
105 format[0] = fsize; 112 {
106 format[0]++; 113 mime = 1;
107 if (0 == mime) 114 ADD ("video/mpeg", EXTRACTOR_METATYPE_MIMETYPE);
108 { 115 }
109 mime = 1; 116 snprintf (format,
110 ADD ("video/mpeg", EXTRACTOR_METATYPE_MIMETYPE); 117 sizeof(format), "%ux%u",
111 } 118 info->sequence->width, info->sequence->height);
112 snprintf (format, 119 if (0 != strcmp (lformat,
113 sizeof(format), "%ux%u", 120 format))
114 info->sequence->width, info->sequence->height); 121 {
115 if (0 != strcmp (lformat, 122 strcpy (lformat,
116 format)) 123 format);
117 { 124 ADD (format, EXTRACTOR_METATYPE_IMAGE_DIMENSIONS);
118 strcpy (lformat, 125 }
119 format); 126 switch (info->sequence->flags & SEQ_VIDEO_FORMAT_UNSPECIFIED)
120 ADD (format, EXTRACTOR_METATYPE_IMAGE_DIMENSIONS); 127 {
121 } 128 case SEQ_VIDEO_FORMAT_PAL:
122 switch (info->sequence->flags & SEQ_VIDEO_FORMAT_UNSPECIFIED) 129 if (0 == fpal)
123 { 130 {
124 case SEQ_VIDEO_FORMAT_PAL: 131 fpal = 1;
125 if (0 == fpal) 132 ADD ("PAL", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM);
126 { 133 }
127 fpal = 1; 134 break;
128 ADD ("PAL", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM); 135 case SEQ_VIDEO_FORMAT_NTSC:
129 } 136 if (0 == fntsc)
130 break; 137 {
131 case SEQ_VIDEO_FORMAT_NTSC: 138 fntsc = 1;
132 if (0 == fntsc) 139 ADD ("NTSC", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM);
133 { 140 }
134 fntsc = 1; 141 break;
135 ADD ("NTSC", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM); 142 case SEQ_VIDEO_FORMAT_SECAM:
136 } 143 if (0 == fsecam)
137 break; 144 {
138 case SEQ_VIDEO_FORMAT_SECAM: 145 fsecam = 1;
139 if (0 == fsecam) 146 ADD ("SECAM", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM);
140 { 147 }
141 fsecam = 1; 148 break;
142 ADD ("SECAM", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM); 149 case SEQ_VIDEO_FORMAT_MAC:
143 } 150 if (0 == fmac)
144 break; 151 {
145 case SEQ_VIDEO_FORMAT_MAC: 152 fmac = 1;
146 if (0 == fmac) 153 ADD ("MAC", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM);
147 { 154 }
148 fmac = 1; 155 break;
149 ADD ("MAC", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM); 156 default:
150 } 157 break;
151 break; 158 }
152 default: 159 if ((info->sequence->flags & SEQ_FLAG_MPEG2) > 0)
153 break; 160 {
154 } 161 if (0 == fmt1)
155 if ((info->sequence->flags & SEQ_FLAG_MPEG2) > 0) 162 {
156 { 163 fmt1 = 1;
157 if (0 == fmt1) 164 ADD ("MPEG2", EXTRACTOR_METATYPE_FORMAT_VERSION);
158 { 165 }
159 fmt1 = 1; 166 }
160 ADD ("MPEG2", EXTRACTOR_METATYPE_FORMAT_VERSION); 167 else
161 } 168 {
162 } 169 if (0 == fmt2)
163 else 170 {
164 { 171 fmt2 = 1;
165 if (0 == fmt2) 172 ADD ("MPEG1", EXTRACTOR_METATYPE_FORMAT_VERSION);
166 { 173 }
167 fmt2 = 1; 174 }
168 ADD ("MPEG1", EXTRACTOR_METATYPE_FORMAT_VERSION); 175 if ( (0 == did_seek) &&
169 } 176 (fsize != -1) &&
170 } 177 (fsize > 1024 * 256 * 2) )
171 if ( (0 == did_seek) && 178 {
172 (fsize != -1) && 179 /* skip to the end of the mpeg for speed */
173 (fsize > 1024 * 256 * 2) ) 180 did_seek = 1;
174 { 181 ec->seek (ec->cls,
175 /* skip to the end of the mpeg for speed */ 182 fsize - 256 * 1024,
176 did_seek = 1; 183 SEEK_SET);
177 ec->seek (ec->cls, 184 }
178 fsize - 256 * 1024, 185 break;
179 SEEK_SET); 186 case STATE_GOP:
180 } 187 fail_count = 0;
181 break; 188 if ( (NULL != info->gop) &&
182 case STATE_GOP: 189 (0 != info->gop->pictures) )
183 fail_count = 0; 190 {
184 if ( (NULL != info->gop) && 191 snprintf (gop_format,
185 (0 != info->gop->pictures) ) 192 sizeof (gop_format),
186 { 193 "%02u:%02u:%02u (%u frames)",
187 snprintf (gop_format, 194 info->gop->hours,
188 sizeof (gop_format), 195 info->gop->minutes,
189 "%02u:%02u:%02u (%u frames)", 196 info->gop->seconds,
190 info->gop->hours, 197 info->gop->pictures);
191 info->gop->minutes, 198 have_gop = 1;
192 info->gop->seconds, 199 }
193 info->gop->pictures); 200 break;
194 have_gop = 1; 201 case STATE_SLICE:
195 } 202 fail_count = 0;
196 break; 203 break;
197 case STATE_SLICE: 204 case STATE_END:
198 fail_count = 0; 205 fail_count = 0;
199 break; 206 break;
200 case STATE_END: 207 case STATE_INVALID:
201 fail_count = 0; 208 goto EXIT;
202 break; 209 default:
203 case STATE_INVALID: 210 break;
204 goto EXIT;
205 default:
206 break;
207 }
208 } 211 }
209 EXIT: 212 }
213EXIT:
210 if (1 == have_gop) 214 if (1 == have_gop)
211 ADD (gop_format, EXTRACTOR_METATYPE_DURATION); 215 ADD (gop_format, EXTRACTOR_METATYPE_DURATION);
212 mpeg2_close (handle); 216 mpeg2_close (handle);
213} 217}
214 218
219
215/* end of mpeg_extractor.c */ 220/* end of mpeg_extractor.c */
diff --git a/src/plugins/nsf_extractor.c b/src/plugins/nsf_extractor.c
index a02aaee..8028e92 100644
--- a/src/plugins/nsf_extractor.c
+++ b/src/plugins/nsf_extractor.c
@@ -28,7 +28,6 @@
28#include "extractor.h" 28#include "extractor.h"
29 29
30 30
31
32/* television system flags */ 31/* television system flags */
33#define PAL_FLAG 0x01 32#define PAL_FLAG 0x01
34#define DUAL_FLAG 0x02 33#define DUAL_FLAG 0x02
@@ -130,7 +129,11 @@ struct header
130 * @param s metadata value as UTF8 129 * @param s metadata value as UTF8
131 * @param t metadata type to use 130 * @param t metadata type to use
132 */ 131 */
133#define ADD(s,t) do { if (0 != ec->proc (ec->cls, "nsf", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen (s) + 1)) return; } while (0) 132#define ADD(s,t) do { if (0 != ec->proc (ec->cls, "nsf", t, \
133 EXTRACTOR_METAFORMAT_UTF8, \
134 "text/plain", s, strlen (s) \
135 + 1)) return; \
136} while (0)
134 137
135 138
136/** 139/**
@@ -167,19 +170,19 @@ EXTRACTOR_nsf_extract_method (struct EXTRACTOR_ExtractContext *ec)
167 return; 170 return;
168 ADD ("audio/x-nsf", EXTRACTOR_METATYPE_MIMETYPE); 171 ADD ("audio/x-nsf", EXTRACTOR_METATYPE_MIMETYPE);
169 snprintf (nsfversion, 172 snprintf (nsfversion,
170 sizeof(nsfversion), 173 sizeof(nsfversion),
171 "%d", 174 "%d",
172 head->nsfversion); 175 head->nsfversion);
173 ADD (nsfversion, EXTRACTOR_METATYPE_FORMAT_VERSION); 176 ADD (nsfversion, EXTRACTOR_METATYPE_FORMAT_VERSION);
174 snprintf (songs, 177 snprintf (songs,
175 sizeof(songs), 178 sizeof(songs),
176 "%d", 179 "%d",
177 (int) head->songs); 180 (int) head->songs);
178 ADD (songs, EXTRACTOR_METATYPE_SONG_COUNT); 181 ADD (songs, EXTRACTOR_METATYPE_SONG_COUNT);
179 snprintf (startingsong, 182 snprintf (startingsong,
180 sizeof(startingsong), 183 sizeof(startingsong),
181 "%d", 184 "%d",
182 (int) head->firstsong); 185 (int) head->firstsong);
183 ADD (startingsong, EXTRACTOR_METATYPE_STARTING_SONG); 186 ADD (startingsong, EXTRACTOR_METATYPE_STARTING_SONG);
184 memcpy (&album, head->title, 32); 187 memcpy (&album, head->title, 32);
185 album[32] = '\0'; 188 album[32] = '\0';
@@ -192,16 +195,16 @@ EXTRACTOR_nsf_extract_method (struct EXTRACTOR_ExtractContext *ec)
192 ADD (copyright, EXTRACTOR_METATYPE_COPYRIGHT); 195 ADD (copyright, EXTRACTOR_METATYPE_COPYRIGHT);
193 196
194 if (0 != (head->tvflags & DUAL_FLAG)) 197 if (0 != (head->tvflags & DUAL_FLAG))
195 { 198 {
196 ADD ("PAL/NTSC", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM); 199 ADD ("PAL/NTSC", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM);
197 } 200 }
198 else 201 else
199 { 202 {
200 if (0 != (head->tvflags & PAL_FLAG)) 203 if (0 != (head->tvflags & PAL_FLAG))
201 ADD ("PAL", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM); 204 ADD ("PAL", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM);
202 else 205 else
203 ADD ("NTSC", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM); 206 ADD ("NTSC", EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM);
204 } 207 }
205 208
206 /* Detect Extra Sound Chips needed to play the files */ 209 /* Detect Extra Sound Chips needed to play the files */
207 if (0 != (head->chipflags & VRCVI_FLAG)) 210 if (0 != (head->chipflags & VRCVI_FLAG))
@@ -218,4 +221,5 @@ EXTRACTOR_nsf_extract_method (struct EXTRACTOR_ExtractContext *ec)
218 ADD ("Sunsoft FME-07", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 221 ADD ("Sunsoft FME-07", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
219} 222}
220 223
224
221/* end of nsf_extractor.c */ 225/* end of nsf_extractor.c */
diff --git a/src/plugins/nsfe_extractor.c b/src/plugins/nsfe_extractor.c
index 36ba115..c7f44b9 100644
--- a/src/plugins/nsfe_extractor.c
+++ b/src/plugins/nsfe_extractor.c
@@ -396,4 +396,5 @@ EXTRACTOR_nsfe_extract_method (struct EXTRACTOR_ExtractContext *ec)
396 } 396 }
397} 397}
398 398
399
399/* end of nsfe_extractor.c */ 400/* end of nsfe_extractor.c */
diff --git a/src/plugins/odf_extractor.c b/src/plugins/odf_extractor.c
index 6a68f7c..ff8f9b2 100644
--- a/src/plugins/odf_extractor.c
+++ b/src/plugins/odf_extractor.c
@@ -41,12 +41,12 @@
41/** 41/**
42 * Mapping from ODF meta data strings to LE types. 42 * Mapping from ODF meta data strings to LE types.
43 */ 43 */
44struct Matches 44struct Matches
45{ 45{
46 /** 46 /**
47 * ODF description. 47 * ODF description.
48 */ 48 */
49 const char * text; 49 const char *text;
50 50
51 /** 51 /**
52 * Corresponding LE type. 52 * Corresponding LE type.
@@ -85,7 +85,7 @@ static struct Matches tmap[] = {
85 * @return NULL if no mimetype could be found, otherwise the mime type 85 * @return NULL if no mimetype could be found, otherwise the mime type
86 */ 86 */
87static char * 87static char *
88libextractor_oo_getmimetype (struct EXTRACTOR_UnzipFile * uf) 88libextractor_oo_getmimetype (struct EXTRACTOR_UnzipFile *uf)
89{ 89{
90 char filename_inzip[MAXFILENAME]; 90 char filename_inzip[MAXFILENAME];
91 struct EXTRACTOR_UnzipFileInfo file_info; 91 struct EXTRACTOR_UnzipFileInfo file_info;
@@ -94,61 +94,61 @@ libextractor_oo_getmimetype (struct EXTRACTOR_UnzipFile * uf)
94 94
95 if (EXTRACTOR_UNZIP_OK != 95 if (EXTRACTOR_UNZIP_OK !=
96 EXTRACTOR_common_unzip_go_find_local_file (uf, 96 EXTRACTOR_common_unzip_go_find_local_file (uf,
97 "mimetype", 97 "mimetype",
98 2)) 98 2))
99 return NULL; 99 return NULL;
100 if (EXTRACTOR_UNZIP_OK != 100 if (EXTRACTOR_UNZIP_OK !=
101 EXTRACTOR_common_unzip_get_current_file_info (uf, 101 EXTRACTOR_common_unzip_get_current_file_info (uf,
102 &file_info, 102 &file_info,
103 filename_inzip, 103 filename_inzip,
104 sizeof (filename_inzip), 104 sizeof (filename_inzip),
105 NULL, 105 NULL,
106 0, 106 0,
107 NULL, 107 NULL,
108 0)) 108 0))
109 return NULL; 109 return NULL;
110 if (EXTRACTOR_UNZIP_OK != 110 if (EXTRACTOR_UNZIP_OK !=
111 EXTRACTOR_common_unzip_open_current_file (uf)) 111 EXTRACTOR_common_unzip_open_current_file (uf))
112 return NULL; 112 return NULL;
113 buf_size = file_info.uncompressed_size; 113 buf_size = file_info.uncompressed_size;
114 if (buf_size > 1024) 114 if (buf_size > 1024)
115 { 115 {
116 /* way too large! */ 116 /* way too large! */
117 EXTRACTOR_common_unzip_close_current_file (uf); 117 EXTRACTOR_common_unzip_close_current_file (uf);
118 return NULL; 118 return NULL;
119 } 119 }
120 if (NULL == (buf = malloc (1 + buf_size))) 120 if (NULL == (buf = malloc (1 + buf_size)))
121 { 121 {
122 /* memory exhausted! */ 122 /* memory exhausted! */
123 EXTRACTOR_common_unzip_close_current_file (uf); 123 EXTRACTOR_common_unzip_close_current_file (uf);
124 return NULL; 124 return NULL;
125 } 125 }
126 if (buf_size != 126 if (buf_size !=
127 (size_t) EXTRACTOR_common_unzip_read_current_file (uf, 127 (size_t) EXTRACTOR_common_unzip_read_current_file (uf,
128 buf, 128 buf,
129 buf_size)) 129 buf_size))
130 { 130 {
131 free(buf); 131 free (buf);
132 EXTRACTOR_common_unzip_close_current_file(uf); 132 EXTRACTOR_common_unzip_close_current_file (uf);
133 return NULL; 133 return NULL;
134 } 134 }
135 /* found something */ 135 /* found something */
136 buf[buf_size] = '\0'; 136 buf[buf_size] = '\0';
137 while ( (0 < buf_size) && 137 while ( (0 < buf_size) &&
138 isspace( (unsigned char) buf[buf_size - 1])) 138 isspace ( (unsigned char) buf[buf_size - 1]))
139 buf[--buf_size] = '\0'; 139 buf[--buf_size] = '\0';
140 if ('\0' == buf[0]) 140 if ('\0' == buf[0])
141 { 141 {
142 free (buf); 142 free (buf);
143 buf = NULL; 143 buf = NULL;
144 } 144 }
145 EXTRACTOR_common_unzip_close_current_file (uf); 145 EXTRACTOR_common_unzip_close_current_file (uf);
146 return buf; 146 return buf;
147} 147}
148 148
149 149
150/** 150/**
151 * Main entry method for the ODF extraction plugin. 151 * Main entry method for the ODF extraction plugin.
152 * 152 *
153 * @param ec extraction context provided to the plugin 153 * @param ec extraction context provided to the plugin
154 */ 154 */
@@ -167,154 +167,157 @@ EXTRACTOR_odf_extract_method (struct EXTRACTOR_ExtractContext *ec)
167 if (NULL == (uf = EXTRACTOR_common_unzip_open (ec))) 167 if (NULL == (uf = EXTRACTOR_common_unzip_open (ec)))
168 return; 168 return;
169 if (NULL != (mimetype = libextractor_oo_getmimetype (uf))) 169 if (NULL != (mimetype = libextractor_oo_getmimetype (uf)))
170 {
171 if (0 != ec->proc (ec->cls,
172 "odf",
173 EXTRACTOR_METATYPE_MIMETYPE,
174 EXTRACTOR_METAFORMAT_UTF8,
175 "text/plain",
176 mimetype,
177 strlen (mimetype) + 1))
170 { 178 {
171 if (0 != ec->proc (ec->cls, 179 EXTRACTOR_common_unzip_close (uf);
172 "odf",
173 EXTRACTOR_METATYPE_MIMETYPE,
174 EXTRACTOR_METAFORMAT_UTF8,
175 "text/plain",
176 mimetype,
177 strlen (mimetype) + 1))
178 {
179 EXTRACTOR_common_unzip_close (uf);
180 free (mimetype);
181 return;
182 }
183 free (mimetype); 180 free (mimetype);
181 return;
184 } 182 }
183 free (mimetype);
184 }
185 if (EXTRACTOR_UNZIP_OK != 185 if (EXTRACTOR_UNZIP_OK !=
186 EXTRACTOR_common_unzip_go_find_local_file (uf, 186 EXTRACTOR_common_unzip_go_find_local_file (uf,
187 METAFILE, 187 METAFILE,
188 2)) 188 2))
189 { 189 {
190 /* metafile not found */ 190 /* metafile not found */
191 EXTRACTOR_common_unzip_close (uf); 191 EXTRACTOR_common_unzip_close (uf);
192 return; 192 return;
193 } 193 }
194 if (EXTRACTOR_UNZIP_OK != 194 if (EXTRACTOR_UNZIP_OK !=
195 EXTRACTOR_common_unzip_get_current_file_info (uf, 195 EXTRACTOR_common_unzip_get_current_file_info (uf,
196 &file_info, 196 &file_info,
197 filename_inzip, 197 filename_inzip,
198 sizeof (filename_inzip), 198 sizeof (filename_inzip),
199 NULL, 0, NULL, 0)) 199 NULL, 0, NULL, 0))
200 { 200 {
201 /* problems accessing metafile */ 201 /* problems accessing metafile */
202 EXTRACTOR_common_unzip_close (uf); 202 EXTRACTOR_common_unzip_close (uf);
203 return; 203 return;
204 } 204 }
205 if (EXTRACTOR_UNZIP_OK != 205 if (EXTRACTOR_UNZIP_OK !=
206 EXTRACTOR_common_unzip_open_current_file (uf)) 206 EXTRACTOR_common_unzip_open_current_file (uf))
207 { 207 {
208 /* problems with unzip */ 208 /* problems with unzip */
209 EXTRACTOR_common_unzip_close (uf); 209 EXTRACTOR_common_unzip_close (uf);
210 return; 210 return;
211 } 211 }
212 212
213 buf_size = file_info.uncompressed_size; 213 buf_size = file_info.uncompressed_size;
214 if (buf_size > 128 * 1024) 214 if (buf_size > 128 * 1024)
215 { 215 {
216 /* too big to be meta-data! */ 216 /* too big to be meta-data! */
217 EXTRACTOR_common_unzip_close_current_file (uf); 217 EXTRACTOR_common_unzip_close_current_file (uf);
218 EXTRACTOR_common_unzip_close (uf); 218 EXTRACTOR_common_unzip_close (uf);
219 return; 219 return;
220 } 220 }
221 if (NULL == (buf = malloc (buf_size+1))) 221 if (NULL == (buf = malloc (buf_size + 1)))
222 { 222 {
223 /* out of memory */ 223 /* out of memory */
224 EXTRACTOR_common_unzip_close_current_file (uf); 224 EXTRACTOR_common_unzip_close_current_file (uf);
225 EXTRACTOR_common_unzip_close (uf); 225 EXTRACTOR_common_unzip_close (uf);
226 return; 226 return;
227 } 227 }
228 if (buf_size != EXTRACTOR_common_unzip_read_current_file (uf, buf, buf_size)) 228 if (buf_size != EXTRACTOR_common_unzip_read_current_file (uf, buf, buf_size))
229 { 229 {
230 EXTRACTOR_common_unzip_close_current_file (uf); 230 EXTRACTOR_common_unzip_close_current_file (uf);
231 goto CLEANUP; 231 goto CLEANUP;
232 } 232 }
233 EXTRACTOR_common_unzip_close_current_file (uf); 233 EXTRACTOR_common_unzip_close_current_file (uf);
234 /* we don't do "proper" parsing of the meta-data but rather use some heuristics 234 /* we don't do "proper" parsing of the meta-data but rather use some heuristics
235 to get values out that we understand */ 235 to get values out that we understand */
236 buf[buf_size] = '\0'; 236 buf[buf_size] = '\0';
237 /* printf("%s\n", buf); */ 237 /* printf("%s\n", buf); */
238 /* try to find some of the typical OO xml headers */ 238 /* try to find some of the typical OO xml headers */
239 if ( (strstr (buf, "xmlns:meta=\"http://openoffice.org/2000/meta\"") != NULL) || 239 if ( (strstr (buf, "xmlns:meta=\"http://openoffice.org/2000/meta\"") !=
240 (strstr (buf, "xmlns:dc=\"http://purl.org/dc/elements/1.1/\"") != NULL) || 240 NULL) ||
241 (strstr (buf, "xmlns:xlink=\"http://www.w3.org/1999/xlink\"") != NULL) ) 241 (strstr (buf, "xmlns:dc=\"http://purl.org/dc/elements/1.1/\"") !=
242 NULL) ||
243 (strstr (buf, "xmlns:xlink=\"http://www.w3.org/1999/xlink\"") != NULL) )
244 {
245 /* accept as meta-data */
246 for (i = 0; NULL != tmap[i].text; i++)
242 { 247 {
243 /* accept as meta-data */ 248 char *spos;
244 for (i = 0; NULL != tmap[i].text; i++) 249 char *epos;
245 { 250 char needle[256];
246 char * spos; 251 int oc;
247 char * epos; 252
248 char needle[256]; 253 pbuf = buf;
249 int oc; 254
250 255 while (1)
251 pbuf = buf; 256 {
252 257 strcpy (needle, "<");
253 while (1) 258 strcat (needle, tmap[i].text);
254 { 259 strcat (needle, ">");
255 strcpy(needle, "<"); 260 spos = strstr (pbuf, needle);
256 strcat(needle, tmap[i].text); 261 if (NULL == spos)
257 strcat(needle, ">"); 262 {
258 spos = strstr(pbuf, needle); 263 strcpy (needle, tmap[i].text);
259 if (NULL == spos) 264 strcat (needle, "=\"");
260 { 265 spos = strstr (pbuf, needle);
261 strcpy(needle, tmap[i].text); 266 if (spos == NULL)
262 strcat(needle, "=\""); 267 break;
263 spos = strstr(pbuf, needle); 268 spos += strlen (needle);
264 if (spos == NULL) 269 epos = spos;
265 break; 270 while ( (epos[0] != '\0') &&
266 spos += strlen(needle); 271 (epos[0] != '"') )
267 epos = spos; 272 epos++;
268 while ( (epos[0] != '\0') && 273 }
269 (epos[0] != '"') ) 274 else
270 epos++; 275 {
271 } 276 oc = 0;
272 else 277 spos += strlen (needle);
273 { 278 while ( (spos[0] != '\0') &&
274 oc = 0; 279 ( (spos[0] == '<') ||
275 spos += strlen(needle); 280 (oc > 0) ) )
276 while ( (spos[0] != '\0') && 281 {
277 ( (spos[0] == '<') || 282 if (spos[0] == '<')
278 (oc > 0) ) ) 283 oc++;
279 { 284 if (spos[0] == '>')
280 if (spos[0] == '<') 285 oc--;
281 oc++; 286 spos++;
282 if (spos[0] == '>') 287 }
283 oc--; 288 epos = spos;
284 spos++; 289 while ( (epos[0] != '\0') &&
285 } 290 (epos[0] != '<') &&
286 epos = spos; 291 (epos[0] != '>') )
287 while ( (epos[0] != '\0') && 292 {
288 (epos[0] != '<') && 293 epos++;
289 (epos[0] != '>') ) 294 }
290 { 295 }
291 epos++; 296 if (spos != epos)
292 } 297 {
293 } 298 char key[epos - spos + 1];
294 if (spos != epos) 299
295 { 300 memcpy (key, spos, epos - spos);
296 char key[epos - spos + 1]; 301 key[epos - spos] = '\0';
297 302 if (0 != ec->proc (ec->cls,
298 memcpy(key, spos, epos-spos); 303 "odf",
299 key[epos-spos] = '\0'; 304 tmap[i].type,
300 if (0 != ec->proc (ec->cls, 305 EXTRACTOR_METAFORMAT_UTF8,
301 "odf", 306 "text/plain",
302 tmap[i].type, 307 key,
303 EXTRACTOR_METAFORMAT_UTF8, 308 epos - spos + 1))
304 "text/plain", 309 goto CLEANUP;
305 key, 310 pbuf = epos;
306 epos - spos + 1)) 311 }
307 goto CLEANUP; 312 else
308 pbuf = epos; 313 break;
309 } 314 }
310 else
311 break;
312 }
313 }
314 } 315 }
315 CLEANUP: 316 }
317CLEANUP:
316 free (buf); 318 free (buf);
317 EXTRACTOR_common_unzip_close (uf); 319 EXTRACTOR_common_unzip_close (uf);
318} 320}
319 321
322
320/* end of odf_extractor.c */ 323/* end of odf_extractor.c */
diff --git a/src/plugins/ogg_extractor.c b/src/plugins/ogg_extractor.c
index d7005ef..4c773aa 100644
--- a/src/plugins/ogg_extractor.c
+++ b/src/plugins/ogg_extractor.c
@@ -52,15 +52,15 @@ read_ogg (void *ptr, size_t size, size_t nmemb, void *datasource)
52 52
53 data = NULL; 53 data = NULL;
54 ret = ec->read (ec->cls, 54 ret = ec->read (ec->cls,
55 &data, 55 &data,
56 size * nmemb); 56 size * nmemb);
57 if (-1 == ret) 57 if (-1 == ret)
58 return 0; 58 return 0;
59 if (0 == ret) 59 if (0 == ret)
60 { 60 {
61 errno = 0; 61 errno = 0;
62 return 0; 62 return 0;
63 } 63 }
64 memcpy (ptr, data, ret); 64 memcpy (ptr, data, ret);
65 errno = 0; 65 errno = 0;
66 return ret; 66 return ret;
@@ -77,8 +77,8 @@ read_ogg (void *ptr, size_t size, size_t nmemb, void *datasource)
77 */ 77 */
78static int 78static int
79seek_ogg (void *datasource, 79seek_ogg (void *datasource,
80 ogg_int64_t offset, 80 ogg_int64_t offset,
81 int whence) 81 int whence)
82{ 82{
83 struct EXTRACTOR_ExtractContext *ec = datasource; 83 struct EXTRACTOR_ExtractContext *ec = datasource;
84 int64_t new_position; 84 int64_t new_position;
@@ -100,12 +100,11 @@ tell_ogg (void *datasource)
100 struct EXTRACTOR_ExtractContext *ec = datasource; 100 struct EXTRACTOR_ExtractContext *ec = datasource;
101 101
102 return (long) ec->seek (ec->cls, 102 return (long) ec->seek (ec->cls,
103 0, 103 0,
104 SEEK_CUR); 104 SEEK_CUR);
105} 105}
106 106
107 107
108
109/** 108/**
110 * Extract the associated meta data for a given label from vorbis. 109 * Extract the associated meta data for a given label from vorbis.
111 * 110 *
@@ -115,7 +114,7 @@ tell_ogg (void *datasource)
115 */ 114 */
116static char * 115static char *
117get_comment (vorbis_comment *vc, 116get_comment (vorbis_comment *vc,
118 const char *label) 117 const char *label)
119{ 118{
120 if (NULL == vc) 119 if (NULL == vc)
121 return NULL; 120 return NULL;
@@ -129,7 +128,11 @@ get_comment (vorbis_comment *vc,
129 * @param t LE meta data type 128 * @param t LE meta data type
130 * @param s meta data to add 129 * @param s meta data to add
131 */ 130 */
132#define ADD(t,s) do { if (0 != (ret = ec->proc (ec->cls, "ogg", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1))) goto FINISH; } while (0) 131#define ADD(t,s) do { if (0 != (ret = ec->proc (ec->cls, "ogg", t, \
132 EXTRACTOR_METAFORMAT_UTF8, \
133 "text/plain", s, strlen (s) \
134 + 1))) goto FINISH; \
135} while (0)
133 136
134 137
135/** 138/**
@@ -138,7 +141,8 @@ get_comment (vorbis_comment *vc,
138 * @param t LE meta data type 141 * @param t LE meta data type
139 * @param d vorbis meta data label 142 * @param d vorbis meta data label
140 */ 143 */
141#define ADDG(t,d) do { m = get_comment (comments, d); if (NULL != m) ADD(t,m); } while (0) 144#define ADDG(t,d) do { m = get_comment (comments, d); if (NULL != m) ADD (t,m); \
145} while (0)
142 146
143 147
144/** 148/**
@@ -200,4 +204,5 @@ FINISH:
200 ov_clear (&vf); 204 ov_clear (&vf);
201} 205}
202 206
207
203/* end of ogg_extractor.c */ 208/* end of ogg_extractor.c */
diff --git a/src/plugins/old/applefile_extractor.c b/src/plugins/old/applefile_extractor.c
index cc82dc8..dcaf7d0 100644
--- a/src/plugins/old/applefile_extractor.c
+++ b/src/plugins/old/applefile_extractor.c
@@ -42,10 +42,10 @@ typedef struct
42#define APPLEFILE_HEADER_SIZE 26 42#define APPLEFILE_HEADER_SIZE 26
43#define APPLEFILE_HEADER_SPEC "4bW16bH" 43#define APPLEFILE_HEADER_SPEC "4bW16bH"
44#define APPLEFILE_HEADER_FIELDS(p) \ 44#define APPLEFILE_HEADER_FIELDS(p) \
45 &(p)->magic, \ 45 & (p)->magic, \
46 &(p)->version, \ 46 &(p)->version, \
47 &(p)->homeFileSystem, \ 47 &(p)->homeFileSystem, \
48 &(p)->entries 48 &(p)->entries
49 49
50typedef struct 50typedef struct
51{ 51{
@@ -57,9 +57,9 @@ typedef struct
57#define APPLEFILE_ENTRY_DESCRIPTOR_SIZE 12 57#define APPLEFILE_ENTRY_DESCRIPTOR_SIZE 12
58#define APPLEFILE_ENTRY_DESCRIPTOR_SPEC "WWW" 58#define APPLEFILE_ENTRY_DESCRIPTOR_SPEC "WWW"
59#define APPLEFILE_ENTRY_DESCRIPTOR_FIELDS(p) \ 59#define APPLEFILE_ENTRY_DESCRIPTOR_FIELDS(p) \
60 &(p)->id, \ 60 & (p)->id, \
61 &(p)->offset, \ 61 &(p)->offset, \
62 &(p)->length 62 &(p)->length
63 63
64#define AED_ID_DATA_FORK 1 64#define AED_ID_DATA_FORK 1
65#define AED_ID_RESOURCE_FORK 2 65#define AED_ID_RESOURCE_FORK 2
@@ -76,43 +76,47 @@ typedef struct
76#define AED_ID_AFP_FILE_INFO 14 76#define AED_ID_AFP_FILE_INFO 14
77#define AED_ID_DIRECTORY_ID 15 77#define AED_ID_DIRECTORY_ID 15
78 78
79static int readApplefileHeader(const unsigned char *data, 79static int
80 size_t *offset, 80readApplefileHeader (const unsigned char *data,
81 size_t size, 81 size_t *offset,
82 ApplefileHeader *hdr) 82 size_t size,
83 ApplefileHeader *hdr)
83{ 84{
84 if ((*offset + APPLEFILE_HEADER_SIZE) > size) 85 if ((*offset + APPLEFILE_HEADER_SIZE) > size)
85 return -1; 86 return -1;
86 87
87 EXTRACTOR_common_cat_unpack(data + *offset, 88 EXTRACTOR_common_cat_unpack (data + *offset,
88 APPLEFILE_HEADER_SPEC, 89 APPLEFILE_HEADER_SPEC,
89 APPLEFILE_HEADER_FIELDS(hdr)); 90 APPLEFILE_HEADER_FIELDS (hdr));
90 *offset += APPLEFILE_HEADER_SIZE; 91 *offset += APPLEFILE_HEADER_SIZE;
91 return 0; 92 return 0;
92} 93}
93 94
94static int readEntryDescriptor(const unsigned char *data, 95
95 size_t *offset, 96static int
96 size_t size, 97readEntryDescriptor (const unsigned char *data,
97 ApplefileEntryDescriptor *dsc) 98 size_t *offset,
99 size_t size,
100 ApplefileEntryDescriptor *dsc)
98{ 101{
99 if ((*offset + APPLEFILE_ENTRY_DESCRIPTOR_SIZE) > size) 102 if ((*offset + APPLEFILE_ENTRY_DESCRIPTOR_SIZE) > size)
100 return -1; 103 return -1;
101 104
102 EXTRACTOR_common_cat_unpack(data + *offset, 105 EXTRACTOR_common_cat_unpack (data + *offset,
103 APPLEFILE_ENTRY_DESCRIPTOR_SPEC, 106 APPLEFILE_ENTRY_DESCRIPTOR_SPEC,
104 APPLEFILE_ENTRY_DESCRIPTOR_FIELDS(dsc)); 107 APPLEFILE_ENTRY_DESCRIPTOR_FIELDS (dsc));
105 *offset += APPLEFILE_ENTRY_DESCRIPTOR_SIZE; 108 *offset += APPLEFILE_ENTRY_DESCRIPTOR_SIZE;
106 return 0; 109 return 0;
107} 110}
108 111
112
109/* mimetype = application/applefile */ 113/* mimetype = application/applefile */
110int 114int
111EXTRACTOR_applefile_extract (const char *sdata, 115EXTRACTOR_applefile_extract (const char *sdata,
112 size_t size, 116 size_t size,
113 EXTRACTOR_MetaDataProcessor proc, 117 EXTRACTOR_MetaDataProcessor proc,
114 void *proc_cls, 118 void *proc_cls,
115 const char *options) 119 const char *options)
116{ 120{
117 const unsigned char *data = (const unsigned char*) sdata; 121 const unsigned char *data = (const unsigned char*) sdata;
118 size_t offset; 122 size_t offset;
@@ -121,129 +125,134 @@ EXTRACTOR_applefile_extract (const char *sdata,
121 int i; 125 int i;
122 126
123 offset = 0; 127 offset = 0;
124 if (readApplefileHeader(data, &offset, size, &header) == -1) 128 if (readApplefileHeader (data, &offset, size, &header) == -1)
125 return 0; 129 return 0;
126 if ( (memcmp(header.magic, APPLESINGLE_SIGNATURE, 4) != 0) && 130 if ( (memcmp (header.magic, APPLESINGLE_SIGNATURE, 4) != 0) &&
127 (memcmp(header.magic, APPLEDOUBLE_SIGNATURE, 4) != 0) ) 131 (memcmp (header.magic, APPLEDOUBLE_SIGNATURE, 4) != 0) )
128 return 0; 132 return 0;
129 if (0 != proc (proc_cls, 133 if (0 != proc (proc_cls,
130 "applefile", 134 "applefile",
131 EXTRACTOR_METATYPE_MIMETYPE, 135 EXTRACTOR_METATYPE_MIMETYPE,
132 EXTRACTOR_METAFORMAT_UTF8, 136 EXTRACTOR_METAFORMAT_UTF8,
133 "text/plain", 137 "text/plain",
134 "application/applefile", 138 "application/applefile",
135 strlen ("application/applefile")+1)) 139 strlen ("application/applefile") + 1))
136 return 1; 140 return 1;
137#if DEBUG 141#if DEBUG
138 fprintf(stderr, 142 fprintf (stderr,
139 "applefile header: %08x %d\n", header.version, header.entries); 143 "applefile header: %08x %d\n", header.version, header.entries);
140#endif 144#endif
141 if ( (header.version != 0x00010000) && 145 if ( (header.version != 0x00010000) &&
142 (header.version != 0x00020000) ) 146 (header.version != 0x00020000) )
143 return 0; 147 return 0;
144 148
145 for (i = 0; i < header.entries; i++) { 149 for (i = 0; i < header.entries; i++)
146 if (readEntryDescriptor(data, &offset, size, &dsc) == -1) 150 {
151 if (readEntryDescriptor (data, &offset, size, &dsc) == -1)
147 break; 152 break;
148 153
149#if DEBUG 154#if DEBUG
150 fprintf(stderr, 155 fprintf (stderr,
151 "applefile entry: %u %u %u\n", dsc.id, dsc.offset, dsc.length); 156 "applefile entry: %u %u %u\n", dsc.id, dsc.offset, dsc.length);
152#endif 157#endif
153 switch (dsc.id) 158 switch (dsc.id)
159 {
160 case AED_ID_DATA_FORK:
154 { 161 {
155 case AED_ID_DATA_FORK: 162 /* same as in filenameextractor.c */
156 { 163 char s[14];
157 /* same as in filenameextractor.c */
158 char s[14];
159 164
160 if (dsc.length >= 1000000000) 165 if (dsc.length >= 1000000000)
161 snprintf (s, 13, "%.2f %s", dsc.length / 1000000000.0, 166 snprintf (s, 13, "%.2f %s", dsc.length / 1000000000.0,
162 _("GB")); 167 _ ("GB"));
163 else if (dsc.length >= 1000000) 168 else if (dsc.length >= 1000000)
164 snprintf (s, 13, "%.2f %s", dsc.length / 1000000.0, _("MB")); 169 snprintf (s, 13, "%.2f %s", dsc.length / 1000000.0, _ ("MB"));
165 else if (dsc.length >= 1000) 170 else if (dsc.length >= 1000)
166 snprintf (s, 13, "%.2f %s", dsc.length / 1000.0, _("KB")); 171 snprintf (s, 13, "%.2f %s", dsc.length / 1000.0, _ ("KB"));
167 else 172 else
168 snprintf (s, 13, "%.2f %s", (double) dsc.length, _("Bytes")); 173 snprintf (s, 13, "%.2f %s", (double) dsc.length, _ ("Bytes"));
169 174
170 if (0 != proc (proc_cls, 175 if (0 != proc (proc_cls,
171 "applefile", 176 "applefile",
172 EXTRACTOR_METATYPE_EMBEDDED_FILE_SIZE, 177 EXTRACTOR_METATYPE_EMBEDDED_FILE_SIZE,
173 EXTRACTOR_METAFORMAT_UTF8, 178 EXTRACTOR_METAFORMAT_UTF8,
174 "text/plain", 179 "text/plain",
175 s, 180 s,
176 strlen (s) + 1)) 181 strlen (s) + 1))
177 return 1; 182 return 1;
178 } 183 }
179 break; 184 break;
180 case AED_ID_REAL_NAME: 185 case AED_ID_REAL_NAME:
181 { 186 {
182 char s[2048]; 187 char s[2048];
183 if ( (dsc.length < sizeof(s)) && 188 if ( (dsc.length < sizeof(s)) &&
184 ((dsc.offset + dsc.length) < size) ) { 189 ((dsc.offset + dsc.length) < size) )
185 memcpy(s, data + dsc.offset, dsc.length); 190 {
186 s[dsc.length] = '\0'; 191 memcpy (s, data + dsc.offset, dsc.length);
187 if (0 != proc (proc_cls, 192 s[dsc.length] = '\0';
188 "applefile", 193 if (0 != proc (proc_cls,
189 EXTRACTOR_METATYPE_FILENAME, 194 "applefile",
190 EXTRACTOR_METAFORMAT_UTF8, 195 EXTRACTOR_METATYPE_FILENAME,
191 "text/plain", 196 EXTRACTOR_METAFORMAT_UTF8,
192 s, 197 "text/plain",
193 dsc.length + 1)) 198 s,
194 return 1; 199 dsc.length + 1))
195 } 200 return 1;
196 } 201 }
197 break; 202 }
198 case AED_ID_COMMENT: 203 break;
199 if ( (dsc.length < 65536) && ((dsc.offset + dsc.length) < size) ) { 204 case AED_ID_COMMENT:
200 char *s = malloc(dsc.length + 1); 205 if ( (dsc.length < 65536) && ((dsc.offset + dsc.length) < size) )
201 if (s != NULL) { 206 {
202 memcpy(s, data + dsc.offset, dsc.length); 207 char *s = malloc (dsc.length + 1);
203 s[dsc.length] = '\0'; 208 if (s != NULL)
204 if (0 != proc (proc_cls, 209 {
205 "applefile", 210 memcpy (s, data + dsc.offset, dsc.length);
206 EXTRACTOR_METATYPE_COMMENT, 211 s[dsc.length] = '\0';
207 EXTRACTOR_METAFORMAT_UTF8, 212 if (0 != proc (proc_cls,
208 "text/plain", 213 "applefile",
209 s, 214 EXTRACTOR_METATYPE_COMMENT,
210 dsc.length + 1)) 215 EXTRACTOR_METAFORMAT_UTF8,
211 { 216 "text/plain",
212 free (s); 217 s,
213 return 1; 218 dsc.length + 1))
214 } 219 {
215 free (s); 220 free (s);
216 } 221 return 1;
217 } 222 }
218 break; 223 free (s);
219 case AED_ID_FINDER_INFO:
220 if (dsc.length >= 16 && (dsc.offset + dsc.length) < size) {
221 char s[5];
222 memcpy(s, data + dsc.offset, 4);
223 s[4] = '\0';
224 if (0 != proc (proc_cls,
225 "applefile",
226 EXTRACTOR_METATYPE_FINDER_FILE_TYPE,
227 EXTRACTOR_METAFORMAT_C_STRING,
228 "text/plain",
229 s,
230 strlen(s) + 1))
231 return 1;
232
233 memcpy(s, data + dsc.offset + 4, 4);
234 s[4] = '\0';
235 if (0 != proc (proc_cls,
236 "applefile",
237 EXTRACTOR_METATYPE_FINDER_FILE_CREATOR,
238 EXTRACTOR_METAFORMAT_C_STRING,
239 "text/plain",
240 s,
241 strlen(s) + 1))
242 return 1;
243 } 224 }
244 break; 225 }
245 default: 226 break;
246 break; 227 case AED_ID_FINDER_INFO:
228 if ((dsc.length >= 16) && ( (dsc.offset + dsc.length) < size) )
229 {
230 char s[5];
231 memcpy (s, data + dsc.offset, 4);
232 s[4] = '\0';
233 if (0 != proc (proc_cls,
234 "applefile",
235 EXTRACTOR_METATYPE_FINDER_FILE_TYPE,
236 EXTRACTOR_METAFORMAT_C_STRING,
237 "text/plain",
238 s,
239 strlen (s) + 1))
240 return 1;
241
242 memcpy (s, data + dsc.offset + 4, 4);
243 s[4] = '\0';
244 if (0 != proc (proc_cls,
245 "applefile",
246 EXTRACTOR_METATYPE_FINDER_FILE_CREATOR,
247 EXTRACTOR_METAFORMAT_C_STRING,
248 "text/plain",
249 s,
250 strlen (s) + 1))
251 return 1;
252 }
253 break;
254 default:
255 break;
247 } 256 }
248 } 257 }
249 return 0; 258 return 0;
diff --git a/src/plugins/old/asf_extractor.c b/src/plugins/old/asf_extractor.c
index 0581ded..6be0a16 100644
--- a/src/plugins/old/asf_extractor.c
+++ b/src/plugins/old/asf_extractor.c
@@ -110,199 +110,288 @@ static const struct
110{ 110{
111 const char *name; 111 const char *name;
112 const LE_GUID guid; 112 const LE_GUID guid;
113} guids[] = 113} guids[] = {
114{
115 { 114 {
116 "error", 115 "error",
117 { 116 {
118 0x0,}}, 117 0x0,
119 /* base ASF objects */ 118 }
119 },
120 /* base ASF objects */
120 { 121 {
121 "header", 122 "header",
122 { 123 {
123 0x75b22630, 0x668e, 0x11cf, 124 0x75b22630, 0x668e, 0x11cf,
124 { 125 {
125 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}}}, 126 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c
127 }
128 }
129 },
126 { 130 {
127 "data", 131 "data",
128 { 132 {
129 0x75b22636, 0x668e, 0x11cf, 133 0x75b22636, 0x668e, 0x11cf,
130 { 134 {
131 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}}}, 135 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c
136 }
137 }
138 },
132 { 139 {
133 "simple index", 140 "simple index",
134 { 141 {
135 0x33000890, 0xe5b1, 0x11cf, 142 0x33000890, 0xe5b1, 0x11cf,
136 { 143 {
137 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb}}}, 144 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb
138 /* header ASF objects */ 145 }
146 }
147 },
148 /* header ASF objects */
139 { 149 {
140 "file properties", 150 "file properties",
141 { 151 {
142 0x8cabdca1, 0xa947, 0x11cf, 152 0x8cabdca1, 0xa947, 0x11cf,
143 { 153 {
144 0x8e, 0xe4, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65}}}, 154 0x8e, 0xe4, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65
155 }
156 }
157 },
145 { 158 {
146 "stream header", 159 "stream header",
147 { 160 {
148 0xb7dc0791, 0xa9b7, 0x11cf, 161 0xb7dc0791, 0xa9b7, 0x11cf,
149 { 162 {
150 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65}}}, 163 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65
164 }
165 }
166 },
151 { 167 {
152 "stream bitrate properties", /* (http://get.to/sdp) */ 168 "stream bitrate properties", /* (http://get.to/sdp) */
153 { 169 {
154 0x7bf875ce, 0x468d, 0x11d1, 170 0x7bf875ce, 0x468d, 0x11d1,
155 { 171 {
156 0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2}}}, 172 0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2
173 }
174 }
175 },
157 { 176 {
158 "content description", 177 "content description",
159 { 178 {
160 0x75b22633, 0x668e, 0x11cf, 179 0x75b22633, 0x668e, 0x11cf,
161 { 180 {
162 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}}}, 181 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c
182 }
183 }
184 },
163 { 185 {
164 "extended content encryption", 186 "extended content encryption",
165 { 187 {
166 0x298ae614, 0x2622, 0x4c17, 188 0x298ae614, 0x2622, 0x4c17,
167 { 189 {
168 0xb9, 0x35, 0xda, 0xe0, 0x7e, 0xe9, 0x28, 0x9c}}}, 190 0xb9, 0x35, 0xda, 0xe0, 0x7e, 0xe9, 0x28, 0x9c
191 }
192 }
193 },
169 { 194 {
170 "script command", 195 "script command",
171 { 196 {
172 0x1efb1a30, 0x0b62, 0x11d0, 197 0x1efb1a30, 0x0b62, 0x11d0,
173 { 198 {
174 0xa3, 0x9b, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6}}}, 199 0xa3, 0x9b, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6
200 }
201 }
202 },
175 { 203 {
176 "marker", 204 "marker",
177 { 205 {
178 0xf487cd01, 0xa951, 0x11cf, 206 0xf487cd01, 0xa951, 0x11cf,
179 { 207 {
180 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65}}}, 208 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65
209 }
210 }
211 },
181 { 212 {
182 "header extension", 213 "header extension",
183 { 214 {
184 0x5fbf03b5, 0xa92e, 0x11cf, 215 0x5fbf03b5, 0xa92e, 0x11cf,
185 { 216 {
186 0x8e, 0xe3, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65}}}, 217 0x8e, 0xe3, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65
218 }
219 }
220 },
187 { 221 {
188 "bitrate mutual exclusion", 222 "bitrate mutual exclusion",
189 { 223 {
190 0xd6e229dc, 0x35da, 0x11d1, 224 0xd6e229dc, 0x35da, 0x11d1,
191 { 225 {
192 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe}}}, 226 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe
227 }
228 }
229 },
193 { 230 {
194 "codec list", 231 "codec list",
195 { 232 {
196 0x86d15240, 0x311d, 0x11d0, 233 0x86d15240, 0x311d, 0x11d0,
197 { 234 {
198 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6}}}, 235 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6
236 }
237 }
238 },
199 { 239 {
200 "extended content description", 240 "extended content description",
201 { 241 {
202 0xd2d0a440, 0xe307, 0x11d2, 242 0xd2d0a440, 0xe307, 0x11d2,
203 { 243 {
204 0x97, 0xf0, 0x00, 0xa0, 0xc9, 0x5e, 0xa8, 0x50}}}, 244 0x97, 0xf0, 0x00, 0xa0, 0xc9, 0x5e, 0xa8, 0x50
245 }
246 }
247 },
205 { 248 {
206 "error correction", 249 "error correction",
207 { 250 {
208 0x75b22635, 0x668e, 0x11cf, 251 0x75b22635, 0x668e, 0x11cf,
209 { 252 {
210 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}}}, 253 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c
254 }
255 }
256 },
211 { 257 {
212 "padding", 258 "padding",
213 { 259 {
214 0x1806d474, 0xcadf, 0x4509, 260 0x1806d474, 0xcadf, 0x4509,
215 { 261 {
216 0xa4, 0xba, 0x9a, 0xab, 0xcb, 0x96, 0xaa, 0xe8}}}, 262 0xa4, 0xba, 0x9a, 0xab, 0xcb, 0x96, 0xaa, 0xe8
217 /* stream properties object stream type */ 263 }
264 }
265 },
266 /* stream properties object stream type */
218 { 267 {
219 "audio media", 268 "audio media",
220 { 269 {
221 0xf8699e40, 0x5b4d, 0x11cf, 270 0xf8699e40, 0x5b4d, 0x11cf,
222 { 271 {
223 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b}}}, 272 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b
273 }
274 }
275 },
224 { 276 {
225 "video media", 277 "video media",
226 { 278 {
227 0xbc19efc0, 0x5b4d, 0x11cf, 279 0xbc19efc0, 0x5b4d, 0x11cf,
228 { 280 {
229 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b}}}, 281 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b
282 }
283 }
284 },
230 { 285 {
231 "command media", 286 "command media",
232 { 287 {
233 0x59dacfc0, 0x59e6, 0x11d0, 288 0x59dacfc0, 0x59e6, 0x11d0,
234 { 289 {
235 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6}}}, 290 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6
236 /* stream properties object error correction */ 291 }
292 }
293 },
294 /* stream properties object error correction */
237 { 295 {
238 "no error correction", 296 "no error correction",
239 { 297 {
240 0x20fb5700, 0x5b55, 0x11cf, 298 0x20fb5700, 0x5b55, 0x11cf,
241 { 299 {
242 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b}}}, 300 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b
301 }
302 }
303 },
243 { 304 {
244 "audio spread", 305 "audio spread",
245 { 306 {
246 0xbfc3cd50, 0x618f, 0x11cf, 307 0xbfc3cd50, 0x618f, 0x11cf,
247 { 308 {
248 0x8b, 0xb2, 0x00, 0xaa, 0x00, 0xb4, 0xe2, 0x20}}}, 309 0x8b, 0xb2, 0x00, 0xaa, 0x00, 0xb4, 0xe2, 0x20
249 /* mutual exclusion object exlusion type */ 310 }
311 }
312 },
313 /* mutual exclusion object exlusion type */
250 { 314 {
251 "mutex bitrate", 315 "mutex bitrate",
252 { 316 {
253 0xd6e22a01, 0x35da, 0x11d1, 317 0xd6e22a01, 0x35da, 0x11d1,
254 { 318 {
255 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe}}}, 319 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe
320 }
321 }
322 },
256 { 323 {
257 "mutex unknown", 324 "mutex unknown",
258 { 325 {
259 0xd6e22a02, 0x35da, 0x11d1, 326 0xd6e22a02, 0x35da, 0x11d1,
260 { 327 {
261 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe}}}, 328 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe
262 /* header extension */ 329 }
330 }
331 },
332 /* header extension */
263 { 333 {
264 "reserved_1", 334 "reserved_1",
265 { 335 {
266 0xabd3d211, 0xa9ba, 0x11cf, 336 0xabd3d211, 0xa9ba, 0x11cf,
267 { 337 {
268 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65}}}, 338 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65
269 /* script command */ 339 }
340 }
341 },
342 /* script command */
270 { 343 {
271 "reserved script command", 344 "reserved script command",
272 { 345 {
273 0x4B1ACBE3, 0x100B, 0x11D0, 346 0x4B1ACBE3, 0x100B, 0x11D0,
274 { 347 {
275 0xA3, 0x9B, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6}}}, 348 0xA3, 0x9B, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6
276 /* marker object */ 349 }
350 }
351 },
352 /* marker object */
277 { 353 {
278 "reserved marker", 354 "reserved marker",
279 { 355 {
280 0x4CFEDB20, 0x75F6, 0x11CF, 356 0x4CFEDB20, 0x75F6, 0x11CF,
281 { 357 {
282 0x9C, 0x0F, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xCB}}}, 358 0x9C, 0x0F, 0x00, 0xA0, 0xC9, 0x03, 0x49, 0xCB
283 /* various */ 359 }
284 /* Already defined (reserved_1) 360 }
285 { "head2", 361 },
286 { 0xabd3d211, 0xa9ba, 0x11cf, { 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 }} }, 362 /* various */
287 */ 363 /* Already defined (reserved_1)
364 { "head2",
365 { 0xabd3d211, 0xa9ba, 0x11cf, { 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 }} },
366 */
288 { 367 {
289 "audio conceal none", 368 "audio conceal none",
290 { 369 {
291 0x49f1a440, 0x4ece, 0x11d0, 370 0x49f1a440, 0x4ece, 0x11d0,
292 { 371 {
293 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6}}}, 372 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6
373 }
374 }
375 },
294 { 376 {
295 "codec comment1 header", 377 "codec comment1 header",
296 { 378 {
297 0x86d15241, 0x311d, 0x11d0, 379 0x86d15241, 0x311d, 0x11d0,
298 { 380 {
299 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6}}}, 381 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6
382 }
383 }
384 },
300 { 385 {
301 "asf 2.0 header", 386 "asf 2.0 header",
302 { 387 {
303 0xd6e229d1, 0x35da, 0x11d1, 388 0xd6e229d1, 0x35da, 0x11d1,
304 { 389 {
3050x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe}}},}; 390 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe
391 }
392 }
393 },
394};
306 395
307 396
308struct demux_asf_s 397struct demux_asf_s
@@ -326,7 +415,7 @@ struct demux_asf_s
326}; 415};
327 416
328static int 417static int
329readBuf (struct demux_asf_s * this, void *buf, int len) 418readBuf (struct demux_asf_s *this, void *buf, int len)
330{ 419{
331 int min; 420 int min;
332 421
@@ -338,8 +427,9 @@ readBuf (struct demux_asf_s * this, void *buf, int len)
338 return min; 427 return min;
339} 428}
340 429
430
341static uint8_t 431static uint8_t
342get_byte (struct demux_asf_s * this) 432get_byte (struct demux_asf_s *this)
343{ 433{
344 uint8_t buf; 434 uint8_t buf;
345 int i; 435 int i;
@@ -350,8 +440,9 @@ get_byte (struct demux_asf_s * this)
350 return buf; 440 return buf;
351} 441}
352 442
443
353static uint16_t 444static uint16_t
354get_le16 (struct demux_asf_s * this) 445get_le16 (struct demux_asf_s *this)
355{ 446{
356 uint8_t buf[2]; 447 uint8_t buf[2];
357 int i; 448 int i;
@@ -362,8 +453,9 @@ get_le16 (struct demux_asf_s * this)
362 return buf[0] | (buf[1] << 8); 453 return buf[0] | (buf[1] << 8);
363} 454}
364 455
456
365static uint32_t 457static uint32_t
366get_le32 (struct demux_asf_s * this) 458get_le32 (struct demux_asf_s *this)
367{ 459{
368 uint8_t buf[4]; 460 uint8_t buf[4];
369 int i; 461 int i;
@@ -374,8 +466,9 @@ get_le32 (struct demux_asf_s * this)
374 return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); 466 return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
375} 467}
376 468
469
377static uint64_t 470static uint64_t
378get_le64 (struct demux_asf_s * this) 471get_le64 (struct demux_asf_s *this)
379{ 472{
380 uint8_t buf[8]; 473 uint8_t buf[8];
381 int i; 474 int i;
@@ -384,16 +477,17 @@ get_le64 (struct demux_asf_s * this)
384 if (i != 8) 477 if (i != 8)
385 this->status = DEMUX_FINISHED; 478 this->status = DEMUX_FINISHED;
386 return (uint64_t) buf[0] 479 return (uint64_t) buf[0]
387 | ((uint64_t) buf[1] << 8) 480 | ((uint64_t) buf[1] << 8)
388 | ((uint64_t) buf[2] << 16) 481 | ((uint64_t) buf[2] << 16)
389 | ((uint64_t) buf[3] << 24) 482 | ((uint64_t) buf[3] << 24)
390 | ((uint64_t) buf[4] << 32) 483 | ((uint64_t) buf[4] << 32)
391 | ((uint64_t) buf[5] << 40) 484 | ((uint64_t) buf[5] << 40)
392 | ((uint64_t) buf[6] << 48) | ((uint64_t) buf[7] << 54); 485 | ((uint64_t) buf[6] << 48) | ((uint64_t) buf[7] << 54);
393} 486}
394 487
488
395static int 489static int
396get_guid (struct demux_asf_s * this) 490get_guid (struct demux_asf_s *this)
397{ 491{
398 int i; 492 int i;
399 LE_GUID g; 493 LE_GUID g;
@@ -406,7 +500,7 @@ get_guid (struct demux_asf_s * this)
406 if (this->status == DEMUX_FINISHED) 500 if (this->status == DEMUX_FINISHED)
407 return GUID_ERROR; 501 return GUID_ERROR;
408 for (i = 1; i < GUID_END; i++) 502 for (i = 1; i < GUID_END; i++)
409 if (!memcmp (&g, &guids[i].guid, sizeof (LE_GUID))) 503 if (! memcmp (&g, &guids[i].guid, sizeof (LE_GUID)))
410 return i; 504 return i;
411 505
412 return GUID_ERROR; 506 return GUID_ERROR;
@@ -414,7 +508,7 @@ get_guid (struct demux_asf_s * this)
414 508
415 509
416static int 510static int
417asf_read_header (struct demux_asf_s * this) 511asf_read_header (struct demux_asf_s *this)
418{ 512{
419 int guid; 513 int guid;
420 uint64_t gsize; 514 uint64_t gsize;
@@ -426,62 +520,67 @@ asf_read_header (struct demux_asf_s * this)
426 get_le64 (this); /* object size */ 520 get_le64 (this); /* object size */
427 get_le32 (this); /* number of header objects */ 521 get_le32 (this); /* number of header objects */
428 get_byte (this); /* reserved 1 */ 522 get_byte (this); /* reserved 1 */
429 get_byte (this); /* reserved 2 */ 523 get_byte (this); /* reserved 2 */
430 while (this->status != DEMUX_FINISHED) 524 while (this->status != DEMUX_FINISHED)
525 {
526 guid = get_guid (this); /* object ID */
527 gsize = get_le64 (this); /* object size */
528 if (gsize < 24)
529 goto fail;
530 switch (guid)
431 { 531 {
432 guid = get_guid (this); /* object ID */ 532 case GUID_ASF_FILE_PROPERTIES:
433 gsize = get_le64 (this); /* object size */ 533 guid = get_guid (this); /* file ID */
434 if (gsize < 24) 534 get_le64 (this); /* file size */
435 goto fail; 535 get_le64 (this); /* creation date */
436 switch (guid) 536 get_le64 (this); /* nb_packets */
437 { 537 this->length = get_le64 (this); /* play duration in 100 ns units */
438 case GUID_ASF_FILE_PROPERTIES: 538 get_le64 (this); /* send duration */
439 guid = get_guid (this); /* file ID */ 539 get_le64 (this); /* preroll */
440 get_le64 (this); /* file size */ 540 get_le32 (this); /* flags */
441 get_le64 (this); /* creation date */ 541 get_le32 (this); /* min size */
442 get_le64 (this); /* nb_packets */ 542 get_le32 (this); /* max size */
443 this->length = get_le64 (this); /* play duration in 100 ns units */ 543 get_le32 (this); /* max bitrate */
444 get_le64 (this); /* send duration */ 544 break;
445 get_le64 (this); /* preroll */ 545 case GUID_ASF_DATA:
446 get_le32 (this); /* flags */ 546 goto headers_ok;
447 get_le32 (this); /* min size */ 547 break;
448 get_le32 (this); /* max size */ 548 case GUID_ASF_CONTENT_DESCRIPTION:
449 get_le32 (this); /* max bitrate */ 549 len1 = get_le16 (this);
450 break; 550 len2 = get_le16 (this);
451 case GUID_ASF_DATA: 551 len3 = get_le16 (this);
452 goto headers_ok; 552 len4 = get_le16 (this);
453 break; 553 len5 = get_le16 (this);
454 case GUID_ASF_CONTENT_DESCRIPTION: 554 this->title = EXTRACTOR_common_convert_to_utf8 (
455 len1 = get_le16 (this); 555 &this->input[this->inputPos],
456 len2 = get_le16 (this); 556 len1,
457 len3 = get_le16 (this); 557 "UTF-16");
458 len4 = get_le16 (this); 558 this->inputPos += len1;
459 len5 = get_le16 (this); 559 this->author = EXTRACTOR_common_convert_to_utf8 (
460 this->title = EXTRACTOR_common_convert_to_utf8 (&this->input[this->inputPos], 560 &this->input[this->inputPos],
461 len1, 561 len2,
462 "UTF-16"); 562 "UTF-16");
463 this->inputPos += len1; 563 this->inputPos += len2;
464 this->author = EXTRACTOR_common_convert_to_utf8 (&this->input[this->inputPos], 564 this->copyright = EXTRACTOR_common_convert_to_utf8 (
465 len2, 565 &this->input[this->inputPos],
466 "UTF-16"); 566 len3,
467 this->inputPos += len2; 567 "UTF-16");
468 this->copyright = EXTRACTOR_common_convert_to_utf8 (&this->input[this->inputPos], 568 this->inputPos += len3;
469 len3, 569 this->comment = EXTRACTOR_common_convert_to_utf8 (
470 "UTF-16"); 570 &this->input[this->inputPos],
471 this->inputPos += len3; 571 len4,
472 this->comment = EXTRACTOR_common_convert_to_utf8 (&this->input[this->inputPos], 572 "UTF-16");
473 len4, 573 this->inputPos += len4;
474 "UTF-16"); 574 this->rating = EXTRACTOR_common_convert_to_utf8 (
475 this->inputPos += len4; 575 &this->input[this->inputPos],
476 this->rating = EXTRACTOR_common_convert_to_utf8 (&this->input[this->inputPos], 576 len5,
477 len5, 577 "UTF-16");
478 "UTF-16"); 578 this->inputPos += len5;
479 this->inputPos += len5; 579 break;
480 break; 580 default:
481 default: 581 this->inputPos += gsize - 24;
482 this->inputPos += gsize - 24;
483 }
484 } 582 }
583 }
485 584
486headers_ok: 585headers_ok:
487 this->inputPos += sizeof (LE_GUID) + 10; 586 this->inputPos += sizeof (LE_GUID) + 10;
@@ -502,12 +601,12 @@ fail:
502 video/x-ms-wax: wva: wma metafile; */ 601 video/x-ms-wax: wva: wma metafile; */
503 602
504/* mimetype = application/applefile */ 603/* mimetype = application/applefile */
505int 604int
506EXTRACTOR_asf_extract (const char *data, 605EXTRACTOR_asf_extract (const char *data,
507 size_t size, 606 size_t size,
508 EXTRACTOR_MetaDataProcessor proc, 607 EXTRACTOR_MetaDataProcessor proc,
509 void *proc_cls, 608 void *proc_cls,
510 const char *options) 609 const char *options)
511{ 610{
512 struct demux_asf_s this; 611 struct demux_asf_s this;
513 size_t slen; 612 size_t slen;
@@ -521,60 +620,60 @@ EXTRACTOR_asf_extract (const char *data,
521 ret = 0; 620 ret = 0;
522 if (1 == asf_read_header (&this)) 621 if (1 == asf_read_header (&this))
523 { 622 {
524 snprintf (duration_str, 623 snprintf (duration_str,
525 sizeof (duration_str), 624 sizeof (duration_str),
526 "%llu ms", (unsigned long long) (this.length / 10000LL)); 625 "%llu ms", (unsigned long long) (this.length / 10000LL));
527 if ( ( (this.title != NULL) && 626 if ( ( (this.title != NULL) &&
528 (0 < (slen = strlen(this.title))) && 627 (0 < (slen = strlen (this.title))) &&
529 (0 != proc (proc_cls, 628 (0 != proc (proc_cls,
530 "asf", 629 "asf",
531 EXTRACTOR_METATYPE_TITLE, 630 EXTRACTOR_METATYPE_TITLE,
532 EXTRACTOR_METAFORMAT_C_STRING, 631 EXTRACTOR_METAFORMAT_C_STRING,
533 "text/plain", 632 "text/plain",
534 this.title, 633 this.title,
535 slen + 1)) ) || 634 slen + 1)) ) ||
536 ( (this.author != NULL) && 635 ( (this.author != NULL) &&
537 (0 < (slen = strlen(this.author))) && 636 (0 < (slen = strlen (this.author))) &&
538 (0 != proc (proc_cls, 637 (0 != proc (proc_cls,
539 "asf", 638 "asf",
540 EXTRACTOR_METATYPE_AUTHOR_NAME, 639 EXTRACTOR_METATYPE_AUTHOR_NAME,
541 EXTRACTOR_METAFORMAT_C_STRING, 640 EXTRACTOR_METAFORMAT_C_STRING,
542 "text/plain", 641 "text/plain",
543 this.author, 642 this.author,
544 slen + 1)) ) || 643 slen + 1)) ) ||
545 ( (this.comment != NULL) && 644 ( (this.comment != NULL) &&
546 (0 < (slen = strlen(this.comment))) && 645 (0 < (slen = strlen (this.comment))) &&
547 (0 != proc (proc_cls, 646 (0 != proc (proc_cls,
548 "asf", 647 "asf",
549 EXTRACTOR_METATYPE_COMMENT, 648 EXTRACTOR_METATYPE_COMMENT,
550 EXTRACTOR_METAFORMAT_C_STRING, 649 EXTRACTOR_METAFORMAT_C_STRING,
551 "text/plain", 650 "text/plain",
552 this.comment, 651 this.comment,
553 slen + 1)) ) || 652 slen + 1)) ) ||
554 ( (this.copyright != NULL) && 653 ( (this.copyright != NULL) &&
555 (0 < (slen = strlen(this.copyright))) && 654 (0 < (slen = strlen (this.copyright))) &&
556 (0 != proc (proc_cls, 655 (0 != proc (proc_cls,
557 "asf", 656 "asf",
558 EXTRACTOR_METATYPE_COPYRIGHT, 657 EXTRACTOR_METATYPE_COPYRIGHT,
559 EXTRACTOR_METAFORMAT_C_STRING, 658 EXTRACTOR_METAFORMAT_C_STRING,
560 "text/plain", 659 "text/plain",
561 this.copyright, 660 this.copyright,
562 slen + 1)) ) || 661 slen + 1)) ) ||
563 (0 != proc (proc_cls, 662 (0 != proc (proc_cls,
564 "asf", 663 "asf",
565 EXTRACTOR_METATYPE_MIMETYPE, 664 EXTRACTOR_METATYPE_MIMETYPE,
566 EXTRACTOR_METAFORMAT_C_STRING, 665 EXTRACTOR_METAFORMAT_C_STRING,
567 "text/plain", 666 "text/plain",
568 "video/x-ms-asf", 667 "video/x-ms-asf",
569 strlen("video/x-ms-asf") + 1)) || 668 strlen ("video/x-ms-asf") + 1)) ||
570 (0 != proc (proc_cls, 669 (0 != proc (proc_cls,
571 "asf", 670 "asf",
572 EXTRACTOR_METATYPE_DURATION, 671 EXTRACTOR_METATYPE_DURATION,
573 EXTRACTOR_METAFORMAT_C_STRING, 672 EXTRACTOR_METAFORMAT_C_STRING,
574 "text/plain", 673 "text/plain",
575 duration_str, 674 duration_str,
576 strlen(duration_str) + 1)) ) 675 strlen (duration_str) + 1)) )
577 ret = 1; 676 ret = 1;
578 } 677 }
579 free (this.title); 678 free (this.title);
580 free (this.author); 679 free (this.author);
@@ -584,4 +683,5 @@ EXTRACTOR_asf_extract (const char *data,
584 return ret; 683 return ret;
585} 684}
586 685
686
587/* end of asf_extractor.c */ 687/* end of asf_extractor.c */
diff --git a/src/plugins/old/convert_numeric.c b/src/plugins/old/convert_numeric.c
index b345014..35bd65a 100644
--- a/src/plugins/old/convert_numeric.c
+++ b/src/plugins/old/convert_numeric.c
@@ -61,45 +61,44 @@ static unsigned long get_field (const unsigned char *,
61 unsigned int, 61 unsigned int,
62 unsigned int, 62 unsigned int,
63 unsigned int); 63 unsigned int);
64
64static int floatformat_always_valid (const struct EXTRACTOR_floatformat *fmt, 65static int floatformat_always_valid (const struct EXTRACTOR_floatformat *fmt,
65 const void *from); 66 const void *from);
66 67
67static int 68static int
68floatformat_always_valid (const struct EXTRACTOR_floatformat *fmt /*ATTRIBUTE_UNUSED*/, 69floatformat_always_valid (const struct
70 EXTRACTOR_floatformat *fmt /*ATTRIBUTE_UNUSED*/,
69 const void *from /*ATTRIBUTE_UNUSED*/) 71 const void *from /*ATTRIBUTE_UNUSED*/)
70{ 72{
71 return 1; 73 return 1;
72} 74}
73 75
76
74/* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not 77/* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not
75 going to bother with trying to muck around with whether it is defined in 78 going to bother with trying to muck around with whether it is defined in
76 a system header, what we do if not, etc. */ 79 a system header, what we do if not, etc. */
77#define FLOATFORMAT_CHAR_BIT 8 80#define FLOATFORMAT_CHAR_BIT 8
78 81
79/* floatformats for IEEE single and double, big and little endian. */ 82/* floatformats for IEEE single and double, big and little endian. */
80const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_big = 83const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_big = {
81{
82 floatformat_big, 32, 0, 1, 8, 127, 255, 9, 23, 84 floatformat_big, 32, 0, 1, 8, 127, 255, 9, 23,
83 floatformat_intbit_no, 85 floatformat_intbit_no,
84 "floatformat_ieee_single_big", 86 "floatformat_ieee_single_big",
85 floatformat_always_valid 87 floatformat_always_valid
86}; 88};
87const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_little = 89const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_little = {
88{
89 floatformat_little, 32, 0, 1, 8, 127, 255, 9, 23, 90 floatformat_little, 32, 0, 1, 8, 127, 255, 9, 23,
90 floatformat_intbit_no, 91 floatformat_intbit_no,
91 "floatformat_ieee_single_little", 92 "floatformat_ieee_single_little",
92 floatformat_always_valid 93 floatformat_always_valid
93}; 94};
94const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_big = 95const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_big = {
95{
96 floatformat_big, 64, 0, 1, 11, 1023, 2047, 12, 52, 96 floatformat_big, 64, 0, 1, 11, 1023, 2047, 12, 52,
97 floatformat_intbit_no, 97 floatformat_intbit_no,
98 "floatformat_ieee_double_big", 98 "floatformat_ieee_double_big",
99 floatformat_always_valid 99 floatformat_always_valid
100}; 100};
101const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_little = 101const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_little = {
102{
103 floatformat_little, 64, 0, 1, 11, 1023, 2047, 12, 52, 102 floatformat_little, 64, 0, 1, 11, 1023, 2047, 12, 52,
104 floatformat_intbit_no, 103 floatformat_intbit_no,
105 "floatformat_ieee_double_little", 104 "floatformat_ieee_double_little",
@@ -109,8 +108,8 @@ const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_little =
109/* floatformat for IEEE double, little endian byte order, with big endian word 108/* floatformat for IEEE double, little endian byte order, with big endian word
110 ordering, as on the ARM. */ 109 ordering, as on the ARM. */
111 110
112const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_littlebyte_bigword = 111const struct EXTRACTOR_floatformat
113{ 112 EXTRACTOR_floatformat_ieee_double_littlebyte_bigword = {
114 floatformat_littlebyte_bigword, 64, 0, 1, 11, 1023, 2047, 12, 52, 113 floatformat_littlebyte_bigword, 64, 0, 1, 11, 1023, 2047, 12, 52,
115 floatformat_intbit_no, 114 floatformat_intbit_no,
116 "floatformat_ieee_double_littlebyte_bigword", 115 "floatformat_ieee_double_littlebyte_bigword",
@@ -119,33 +118,32 @@ const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_littlebyte_
119 118
120/* floatformat for VAX. Not quite IEEE, but close enough. */ 119/* floatformat for VAX. Not quite IEEE, but close enough. */
121 120
122const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_f = 121const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_f = {
123{
124 floatformat_vax, 32, 0, 1, 8, 129, 0, 9, 23, 122 floatformat_vax, 32, 0, 1, 8, 129, 0, 9, 23,
125 floatformat_intbit_no, 123 floatformat_intbit_no,
126 "floatformat_vax_f", 124 "floatformat_vax_f",
127 floatformat_always_valid 125 floatformat_always_valid
128}; 126};
129const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_d = 127const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_d = {
130{
131 floatformat_vax, 64, 0, 1, 8, 129, 0, 9, 55, 128 floatformat_vax, 64, 0, 1, 8, 129, 0, 9, 55,
132 floatformat_intbit_no, 129 floatformat_intbit_no,
133 "floatformat_vax_d", 130 "floatformat_vax_d",
134 floatformat_always_valid 131 floatformat_always_valid
135}; 132};
136const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_g = 133const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_g = {
137{
138 floatformat_vax, 64, 0, 1, 11, 1025, 0, 12, 52, 134 floatformat_vax, 64, 0, 1, 11, 1025, 0, 12, 52,
139 floatformat_intbit_no, 135 floatformat_intbit_no,
140 "floatformat_vax_g", 136 "floatformat_vax_g",
141 floatformat_always_valid 137 floatformat_always_valid
142}; 138};
143 139
144static int floatformat_i387_ext_is_valid (const struct EXTRACTOR_floatformat *fmt, 140static int floatformat_i387_ext_is_valid (const struct
145 const void *from); 141 EXTRACTOR_floatformat *fmt,
142 const void *from);
146 143
147static int 144static int
148floatformat_i387_ext_is_valid (const struct EXTRACTOR_floatformat *fmt, const void *from) 145floatformat_i387_ext_is_valid (const struct EXTRACTOR_floatformat *fmt, const
146 void *from)
149{ 147{
150 /* In the i387 double-extended format, if the exponent is all ones, 148 /* In the i387 double-extended format, if the exponent is all ones,
151 then the integer bit must be set. If the exponent is neither 0 149 then the integer bit must be set. If the exponent is neither 0
@@ -155,9 +153,9 @@ floatformat_i387_ext_is_valid (const struct EXTRACTOR_floatformat *fmt, const vo
155 const unsigned char *ufrom = (const unsigned char *) from; 153 const unsigned char *ufrom = (const unsigned char *) from;
156 154
157 exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize, 155 exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
158 fmt->exp_start, fmt->exp_len); 156 fmt->exp_start, fmt->exp_len);
159 int_bit = get_field (ufrom, fmt->byteorder, fmt->totalsize, 157 int_bit = get_field (ufrom, fmt->byteorder, fmt->totalsize,
160 fmt->man_start, 1); 158 fmt->man_start, 1);
161 159
162 if ((exponent == 0) != (int_bit == 0)) 160 if ((exponent == 0) != (int_bit == 0))
163 return 0; 161 return 0;
@@ -165,38 +163,34 @@ floatformat_i387_ext_is_valid (const struct EXTRACTOR_floatformat *fmt, const vo
165 return 1; 163 return 1;
166} 164}
167 165
168const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i387_ext = 166
169{ 167const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i387_ext = {
170 floatformat_little, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64, 168 floatformat_little, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64,
171 floatformat_intbit_yes, 169 floatformat_intbit_yes,
172 "floatformat_i387_ext", 170 "floatformat_i387_ext",
173 floatformat_i387_ext_is_valid 171 floatformat_i387_ext_is_valid
174}; 172};
175const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m68881_ext = 173const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m68881_ext = {
176{
177 /* Note that the bits from 16 to 31 are unused. */ 174 /* Note that the bits from 16 to 31 are unused. */
178 floatformat_big, 96, 0, 1, 15, 0x3fff, 0x7fff, 32, 64, 175 floatformat_big, 96, 0, 1, 15, 0x3fff, 0x7fff, 32, 64,
179 floatformat_intbit_yes, 176 floatformat_intbit_yes,
180 "floatformat_m68881_ext", 177 "floatformat_m68881_ext",
181 floatformat_always_valid 178 floatformat_always_valid
182}; 179};
183const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i960_ext = 180const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i960_ext = {
184{
185 /* Note that the bits from 0 to 15 are unused. */ 181 /* Note that the bits from 0 to 15 are unused. */
186 floatformat_little, 96, 16, 17, 15, 0x3fff, 0x7fff, 32, 64, 182 floatformat_little, 96, 16, 17, 15, 0x3fff, 0x7fff, 32, 64,
187 floatformat_intbit_yes, 183 floatformat_intbit_yes,
188 "floatformat_i960_ext", 184 "floatformat_i960_ext",
189 floatformat_always_valid 185 floatformat_always_valid
190}; 186};
191const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_ext = 187const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_ext = {
192{
193 floatformat_big, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64, 188 floatformat_big, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64,
194 floatformat_intbit_yes, 189 floatformat_intbit_yes,
195 "floatformat_m88110_ext", 190 "floatformat_m88110_ext",
196 floatformat_always_valid 191 floatformat_always_valid
197}; 192};
198const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_harris_ext = 193const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_harris_ext = {
199{
200 /* Harris uses raw format 128 bytes long, but the number is just an ieee 194 /* Harris uses raw format 128 bytes long, but the number is just an ieee
201 double, and the last 64 bits are wasted. */ 195 double, and the last 64 bits are wasted. */
202 floatformat_big,128, 0, 1, 11, 0x3ff, 0x7ff, 12, 52, 196 floatformat_big,128, 0, 1, 11, 0x3ff, 0x7ff, 12, 52,
@@ -204,45 +198,40 @@ const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_harris_ext =
204 "floatformat_m88110_ext_harris", 198 "floatformat_m88110_ext_harris",
205 floatformat_always_valid 199 floatformat_always_valid
206}; 200};
207const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_big = 201const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_big = {
208{
209 /* Bits 1 to 16 are unused. */ 202 /* Bits 1 to 16 are unused. */
210 floatformat_big, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64, 203 floatformat_big, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64,
211 floatformat_intbit_yes, 204 floatformat_intbit_yes,
212 "floatformat_arm_ext_big", 205 "floatformat_arm_ext_big",
213 floatformat_always_valid 206 floatformat_always_valid
214}; 207};
215const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_littlebyte_bigword = 208const struct EXTRACTOR_floatformat
216{ 209 EXTRACTOR_floatformat_arm_ext_littlebyte_bigword = {
217 /* Bits 1 to 16 are unused. */ 210 /* Bits 1 to 16 are unused. */
218 floatformat_littlebyte_bigword, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64, 211 floatformat_littlebyte_bigword, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64,
219 floatformat_intbit_yes, 212 floatformat_intbit_yes,
220 "floatformat_arm_ext_littlebyte_bigword", 213 "floatformat_arm_ext_littlebyte_bigword",
221 floatformat_always_valid 214 floatformat_always_valid
222}; 215};
223const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_big = 216const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_big = {
224{
225 floatformat_big, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64, 217 floatformat_big, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64,
226 floatformat_intbit_yes, 218 floatformat_intbit_yes,
227 "floatformat_ia64_spill_big", 219 "floatformat_ia64_spill_big",
228 floatformat_always_valid 220 floatformat_always_valid
229}; 221};
230const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_little = 222const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_little = {
231{
232 floatformat_little, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64, 223 floatformat_little, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64,
233 floatformat_intbit_yes, 224 floatformat_intbit_yes,
234 "floatformat_ia64_spill_little", 225 "floatformat_ia64_spill_little",
235 floatformat_always_valid 226 floatformat_always_valid
236}; 227};
237const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_big = 228const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_big = {
238{
239 floatformat_big, 128, 0, 1, 15, 16383, 0x7fff, 16, 112, 229 floatformat_big, 128, 0, 1, 15, 16383, 0x7fff, 16, 112,
240 floatformat_intbit_no, 230 floatformat_intbit_no,
241 "floatformat_ia64_quad_big", 231 "floatformat_ia64_quad_big",
242 floatformat_always_valid 232 floatformat_always_valid
243}; 233};
244const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_little = 234const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_little = {
245{
246 floatformat_little, 128, 0, 1, 15, 16383, 0x7fff, 16, 112, 235 floatformat_little, 128, 0, 1, 15, 16383, 0x7fff, 16, 112,
247 floatformat_intbit_no, 236 floatformat_intbit_no,
248 "floatformat_ia64_quad_little", 237 "floatformat_ia64_quad_little",
@@ -257,7 +246,8 @@ const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_little =
257/* Extract a field which starts at START and is LEN bits long. DATA and 246/* Extract a field which starts at START and is LEN bits long. DATA and
258 TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */ 247 TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
259static unsigned long 248static unsigned long
260get_field (const unsigned char *data, enum EXTRACTOR_floatformat_byteorders order, 249get_field (const unsigned char *data, enum EXTRACTOR_floatformat_byteorders
250 order,
261 unsigned int total_len, unsigned int start, unsigned int len) 251 unsigned int total_len, unsigned int start, unsigned int len)
262{ 252{
263 unsigned long result = 0; 253 unsigned long result = 0;
@@ -278,29 +268,30 @@ get_field (const unsigned char *data, enum EXTRACTOR_floatformat_byteorders orde
278 hi_bit = min (lo_bit + len, FLOATFORMAT_CHAR_BIT); 268 hi_bit = min (lo_bit + len, FLOATFORMAT_CHAR_BIT);
279 269
280 do 270 do
281 { 271 {
282 unsigned int shifted = *(data + cur_byte) >> lo_bit; 272 unsigned int shifted = *(data + cur_byte) >> lo_bit;
283 unsigned int bits = hi_bit - lo_bit; 273 unsigned int bits = hi_bit - lo_bit;
284 unsigned int mask = (1 << bits) - 1; 274 unsigned int mask = (1 << bits) - 1;
285 result |= (shifted & mask) << cur_bitshift; 275 result |= (shifted & mask) << cur_bitshift;
286 len -= bits; 276 len -= bits;
287 cur_bitshift += bits; 277 cur_bitshift += bits;
288 cur_byte += nextbyte; 278 cur_byte += nextbyte;
289 lo_bit = 0; 279 lo_bit = 0;
290 hi_bit = min (len, FLOATFORMAT_CHAR_BIT); 280 hi_bit = min (len, FLOATFORMAT_CHAR_BIT);
291 } 281 }
292 while (len != 0); 282 while (len != 0);
293 283
294 return result; 284 return result;
295} 285}
296 286
287
297/* Convert from FMT to a double. 288/* Convert from FMT to a double.
298 FROM is the address of the extended float. 289 FROM is the address of the extended float.
299 Store the double in *TO. */ 290 Store the double in *TO. */
300 291
301void 292void
302EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *fmt, 293EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *fmt,
303 const void *from, double *to) 294 const void *from, double *to)
304{ 295{
305 const unsigned char *ufrom = (const unsigned char *) from; 296 const unsigned char *ufrom = (const unsigned char *) from;
306 double dto; 297 double dto;
@@ -308,65 +299,65 @@ EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *fmt,
308 unsigned long mant; 299 unsigned long mant;
309 unsigned int mant_bits, mant_off; 300 unsigned int mant_bits, mant_off;
310 int mant_bits_left; 301 int mant_bits_left;
311 int special_exponent; /* It's a NaN, denorm or zero */ 302 int special_exponent; /* It's a NaN, denorm or zero */
312 303
313 exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize, 304 exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
314 fmt->exp_start, fmt->exp_len); 305 fmt->exp_start, fmt->exp_len);
315 306
316 /* If the exponent indicates a NaN, we don't have information to 307 /* If the exponent indicates a NaN, we don't have information to
317 decide what to do. So we handle it like IEEE, except that we 308 decide what to do. So we handle it like IEEE, except that we
318 don't try to preserve the type of NaN. FIXME. */ 309 don't try to preserve the type of NaN. FIXME. */
319 if ((unsigned long) exponent == fmt->exp_nan) 310 if ((unsigned long) exponent == fmt->exp_nan)
311 {
312 int nan;
313
314 mant_off = fmt->man_start;
315 mant_bits_left = fmt->man_len;
316 nan = 0;
317 while (mant_bits_left > 0)
320 { 318 {
321 int nan; 319 mant_bits = min (mant_bits_left, 32);
322 320
323 mant_off = fmt->man_start; 321 if (get_field (ufrom, fmt->byteorder, fmt->totalsize,
324 mant_bits_left = fmt->man_len; 322 mant_off, mant_bits) != 0)
325 nan = 0; 323 {
326 while (mant_bits_left > 0) 324 /* This is a NaN. */
327 { 325 nan = 1;
328 mant_bits = min (mant_bits_left, 32); 326 break;
329 327 }
330 if (get_field (ufrom, fmt->byteorder, fmt->totalsize, 328
331 mant_off, mant_bits) != 0) 329 mant_off += mant_bits;
332 { 330 mant_bits_left -= mant_bits;
333 /* This is a NaN. */
334 nan = 1;
335 break;
336 }
337
338 mant_off += mant_bits;
339 mant_bits_left -= mant_bits;
340 }
341
342 /* On certain systems (such as GNU/Linux), the use of the
343 INFINITY macro below may generate a warning that can not be
344 silenced due to a bug in GCC (PR preprocessor/11931). The
345 preprocessor fails to recognise the __extension__ keyword in
346 conjunction with the GNU/C99 extension for hexadecimal
347 floating point constants and will issue a warning when
348 compiling with -pedantic. */
349 if (nan)
350 dto = NAN;
351 else
352 dto = INFINITY;
353
354 if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1))
355 dto = -dto;
356
357 *to = dto;
358
359 return;
360 } 331 }
361 332
333 /* On certain systems (such as GNU/Linux), the use of the
334 INFINITY macro below may generate a warning that can not be
335 silenced due to a bug in GCC (PR preprocessor/11931). The
336 preprocessor fails to recognise the __extension__ keyword in
337 conjunction with the GNU/C99 extension for hexadecimal
338 floating point constants and will issue a warning when
339 compiling with -pedantic. */if (nan)
340 dto = NAN;
341 else
342 dto = INFINITY;
343
344 if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1))
345 dto = -dto;
346
347 *to = dto;
348
349 return;
350 }
351
362 mant_bits_left = fmt->man_len; 352 mant_bits_left = fmt->man_len;
363 mant_off = fmt->man_start; 353 mant_off = fmt->man_start;
364 dto = 0.0; 354 dto = 0.0;
365 355
366 special_exponent = (exponent == 0) || ((unsigned long) exponent == fmt->exp_nan); 356 special_exponent = (exponent == 0) || ((unsigned long) exponent ==
357 fmt->exp_nan);
367 358
368 /* Don't bias zero's, denorms or NaNs. */ 359 /* Don't bias zero's, denorms or NaNs. */
369 if (!special_exponent) 360 if (! special_exponent)
370 exponent -= fmt->exp_bias; 361 exponent -= fmt->exp_bias;
371 362
372 /* Build the result algebraically. Might go infinite, underflow, etc; 363 /* Build the result algebraically. Might go infinite, underflow, etc;
@@ -375,36 +366,36 @@ EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *fmt,
375 /* If this format uses a hidden bit, explicitly add it in now. Otherwise, 366 /* If this format uses a hidden bit, explicitly add it in now. Otherwise,
376 increment the exponent by one to account for the integer bit. */ 367 increment the exponent by one to account for the integer bit. */
377 368
378 if (!special_exponent) 369 if (! special_exponent)
379 { 370 {
380 if (fmt->intbit == floatformat_intbit_no) 371 if (fmt->intbit == floatformat_intbit_no)
381 dto = ldexp (1.0, exponent); 372 dto = ldexp (1.0, exponent);
382 else 373 else
383 exponent++; 374 exponent++;
384 } 375 }
385 376
386 while (mant_bits_left > 0) 377 while (mant_bits_left > 0)
387 { 378 {
388 mant_bits = min (mant_bits_left, 32); 379 mant_bits = min (mant_bits_left, 32);
389 380
390 mant = get_field (ufrom, fmt->byteorder, fmt->totalsize, 381 mant = get_field (ufrom, fmt->byteorder, fmt->totalsize,
391 mant_off, mant_bits); 382 mant_off, mant_bits);
392 383
393 /* Handle denormalized numbers. FIXME: What should we do for 384 /* Handle denormalized numbers. FIXME: What should we do for
394 non-IEEE formats? */ 385 non-IEEE formats? */
395 if (special_exponent && exponent == 0 && mant != 0) 386 if (special_exponent && (exponent == 0) && (mant != 0) )
396 dto += ldexp ((double)mant, 387 dto += ldexp ((double) mant,
397 (- fmt->exp_bias 388 (-fmt->exp_bias
398 - mant_bits 389 - mant_bits
399 - (mant_off - fmt->man_start) 390 - (mant_off - fmt->man_start)
400 + 1)); 391 + 1));
401 else 392 else
402 dto += ldexp ((double)mant, exponent - mant_bits); 393 dto += ldexp ((double) mant, exponent - mant_bits);
403 if (exponent != 0) 394 if (exponent != 0)
404 exponent -= mant_bits; 395 exponent -= mant_bits;
405 mant_off += mant_bits; 396 mant_off += mant_bits;
406 mant_bits_left -= mant_bits; 397 mant_bits_left -= mant_bits;
407 } 398 }
408 399
409 /* Negate it if negative. */ 400 /* Negate it if negative. */
410 if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1)) 401 if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1))
@@ -412,6 +403,7 @@ EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *fmt,
412 *to = dto; 403 *to = dto;
413} 404}
414 405
406
415static void put_field (unsigned char *, enum EXTRACTOR_floatformat_byteorders, 407static void put_field (unsigned char *, enum EXTRACTOR_floatformat_byteorders,
416 unsigned int, 408 unsigned int,
417 unsigned int, 409 unsigned int,
@@ -442,27 +434,29 @@ put_field (unsigned char *data, enum EXTRACTOR_floatformat_byteorders order,
442 hi_bit = min (lo_bit + len, FLOATFORMAT_CHAR_BIT); 434 hi_bit = min (lo_bit + len, FLOATFORMAT_CHAR_BIT);
443 435
444 do 436 do
445 { 437 {
446 unsigned char *byte_ptr = data + cur_byte; 438 unsigned char *byte_ptr = data + cur_byte;
447 unsigned int bits = hi_bit - lo_bit; 439 unsigned int bits = hi_bit - lo_bit;
448 unsigned int mask = ((1 << bits) - 1) << lo_bit; 440 unsigned int mask = ((1 << bits) - 1) << lo_bit;
449 *byte_ptr = (*byte_ptr & ~mask) | ((stuff_to_put << lo_bit) & mask); 441 *byte_ptr = (*byte_ptr & ~mask) | ((stuff_to_put << lo_bit) & mask);
450 stuff_to_put >>= bits; 442 stuff_to_put >>= bits;
451 len -= bits; 443 len -= bits;
452 cur_byte += nextbyte; 444 cur_byte += nextbyte;
453 lo_bit = 0; 445 lo_bit = 0;
454 hi_bit = min (len, FLOATFORMAT_CHAR_BIT); 446 hi_bit = min (len, FLOATFORMAT_CHAR_BIT);
455 } 447 }
456 while (len != 0); 448 while (len != 0);
457} 449}
458 450
451
459/* The converse: convert the double *FROM to an extended float 452/* The converse: convert the double *FROM to an extended float
460 and store where TO points. Neither FROM nor TO have any alignment 453 and store where TO points. Neither FROM nor TO have any alignment
461 restrictions. */ 454 restrictions. */
462 455
463void 456void
464EXTRACTOR_common_floatformat_from_double (const struct EXTRACTOR_floatformat *fmt, 457EXTRACTOR_common_floatformat_from_double (const struct
465 const double *from, void *to) 458 EXTRACTOR_floatformat *fmt,
459 const double *from, void *to)
466{ 460{
467 double dfrom; 461 double dfrom;
468 int exponent; 462 int exponent;
@@ -476,88 +470,90 @@ EXTRACTOR_common_floatformat_from_double (const struct EXTRACTOR_floatformat *fm
476 470
477 /* If negative, set the sign bit. */ 471 /* If negative, set the sign bit. */
478 if (dfrom < 0) 472 if (dfrom < 0)
479 { 473 {
480 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1, 1); 474 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1, 1);
481 dfrom = -dfrom; 475 dfrom = -dfrom;
482 } 476 }
483 477
484 if (dfrom == 0) 478 if (dfrom == 0)
485 { 479 {
486 /* 0.0. */ 480 /* 0.0. */
487 return; 481 return;
488 } 482 }
489 483
490 if (dfrom != dfrom) 484 if (dfrom != dfrom)
491 { 485 {
492 /* NaN. */ 486 /* NaN. */
493 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, 487 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
494 fmt->exp_len, fmt->exp_nan); 488 fmt->exp_len, fmt->exp_nan);
495 /* Be sure it's not infinity, but NaN value is irrelevant. */ 489 /* Be sure it's not infinity, but NaN value is irrelevant. */
496 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start, 490 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start,
497 32, 1); 491 32, 1);
498 return; 492 return;
499 } 493 }
500 494
501 if (dfrom + dfrom == dfrom) 495 if (dfrom + dfrom == dfrom)
502 { 496 {
503 /* This can only happen for an infinite value (or zero, which we 497 /* This can only happen for an infinite value (or zero, which we
504 already handled above). */ 498 already handled above). */
505 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, 499 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
506 fmt->exp_len, fmt->exp_nan); 500 fmt->exp_len, fmt->exp_nan);
507 return; 501 return;
508 } 502 }
509 503
510 mant = frexp (dfrom, &exponent); 504 mant = frexp (dfrom, &exponent);
511 if (exponent + fmt->exp_bias - 1 > 0) 505 if (exponent + fmt->exp_bias - 1 > 0)
512 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, 506 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
513 fmt->exp_len, exponent + fmt->exp_bias - 1); 507 fmt->exp_len, exponent + fmt->exp_bias - 1);
514 else 508 else
515 { 509 {
516 /* Handle a denormalized number. FIXME: What should we do for 510 /* Handle a denormalized number. FIXME: What should we do for
517 non-IEEE formats? */ 511 non-IEEE formats? */
518 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start, 512 put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
519 fmt->exp_len, 0); 513 fmt->exp_len, 0);
520 mant = ldexp (mant, exponent + fmt->exp_bias - 1); 514 mant = ldexp (mant, exponent + fmt->exp_bias - 1);
521 } 515 }
522 516
523 mant_bits_left = fmt->man_len; 517 mant_bits_left = fmt->man_len;
524 mant_off = fmt->man_start; 518 mant_off = fmt->man_start;
525 while (mant_bits_left > 0) 519 while (mant_bits_left > 0)
520 {
521 unsigned long mant_long;
522 mant_bits = mant_bits_left < 32 ? mant_bits_left : 32;
523
524 mant *= 4294967296.0;
525 mant_long = (unsigned long) mant;
526 mant -= mant_long;
527
528 /* If the integer bit is implicit, and we are not creating a
529 denormalized number, then we need to discard it. */
530 if (( (unsigned int) mant_bits_left == fmt->man_len)
531 && (fmt->intbit == floatformat_intbit_no)
532 && (exponent + fmt->exp_bias - 1 > 0) )
526 { 533 {
527 unsigned long mant_long; 534 mant_long &= 0x7fffffff;
528 mant_bits = mant_bits_left < 32 ? mant_bits_left : 32; 535 mant_bits -= 1;
529
530 mant *= 4294967296.0;
531 mant_long = (unsigned long)mant;
532 mant -= mant_long;
533
534 /* If the integer bit is implicit, and we are not creating a
535 denormalized number, then we need to discard it. */
536 if ((unsigned int) mant_bits_left == fmt->man_len
537 && fmt->intbit == floatformat_intbit_no
538 && exponent + fmt->exp_bias - 1 > 0)
539 {
540 mant_long &= 0x7fffffff;
541 mant_bits -= 1;
542 }
543 else if (mant_bits < 32)
544 {
545 /* The bits we want are in the most significant MANT_BITS bits of
546 mant_long. Move them to the least significant. */
547 mant_long >>= 32 - mant_bits;
548 }
549
550 put_field (uto, fmt->byteorder, fmt->totalsize,
551 mant_off, mant_bits, mant_long);
552 mant_off += mant_bits;
553 mant_bits_left -= mant_bits;
554 } 536 }
537 else if (mant_bits < 32)
538 {
539 /* The bits we want are in the most significant MANT_BITS bits of
540 mant_long. Move them to the least significant. */
541 mant_long >>= 32 - mant_bits;
542 }
543
544 put_field (uto, fmt->byteorder, fmt->totalsize,
545 mant_off, mant_bits, mant_long);
546 mant_off += mant_bits;
547 mant_bits_left -= mant_bits;
548 }
555} 549}
556 550
551
557/* Return non-zero iff the data at FROM is a valid number in format FMT. */ 552/* Return non-zero iff the data at FROM is a valid number in format FMT. */
558 553
559int 554int
560EXTRACTOR_common_floatformat_is_valid (const struct EXTRACTOR_floatformat *fmt, const void *from) 555EXTRACTOR_common_floatformat_is_valid (const struct EXTRACTOR_floatformat *fmt,
556 const void *from)
561{ 557{
562 return fmt->is_valid (fmt, from); 558 return fmt->is_valid (fmt, from);
563} 559}
@@ -575,15 +571,15 @@ ieee_test (double n)
575 double result; 571 double result;
576 572
577 floatformat_to_double (&floatformat_ieee_double_little, &n, &result); 573 floatformat_to_double (&floatformat_ieee_double_little, &n, &result);
578 if ((n != result && (! isnan (n) || ! isnan (result))) 574 if (((n != result) && (! isnan (n) || ! isnan (result)))
579 || (n < 0 && result >= 0) 575 || ((n < 0) && (result >= 0))
580 || (n >= 0 && result < 0)) 576 || ((n >= 0) && (result < 0)))
581 printf ("Differ(to): %.20g -> %.20g\n", n, result); 577 printf ("Differ(to): %.20g -> %.20g\n", n, result);
582 578
583 floatformat_from_double (&floatformat_ieee_double_little, &n, &result); 579 floatformat_from_double (&floatformat_ieee_double_little, &n, &result);
584 if ((n != result && (! isnan (n) || ! isnan (result))) 580 if (((n != result) && (! isnan (n) || ! isnan (result)))
585 || (n < 0 && result >= 0) 581 || ((n < 0) && (result >= 0))
586 || (n >= 0 && result < 0)) 582 || ((n >= 0) && (result < 0)))
587 printf ("Differ(from): %.20g -> %.20g\n", n, result); 583 printf ("Differ(from): %.20g -> %.20g\n", n, result);
588 584
589#if 0 585#if 0
@@ -600,13 +596,14 @@ ieee_test (double n)
600#if IEEE_DEBUG > 1 596#if IEEE_DEBUG > 1
601 /* This is to be run on a host which uses 68881 format. */ 597 /* This is to be run on a host which uses 68881 format. */
602 { 598 {
603 long double ex = *(long double *)exten; 599 long double ex = *(long double *) exten;
604 if (ex != n) 600 if (ex != n)
605 printf ("Differ(from vs. extended): %.20g\n", n); 601 printf ("Differ(from vs. extended): %.20g\n", n);
606 } 602 }
607#endif 603#endif
608} 604}
609 605
606
610int 607int
611main (void) 608main (void)
612{ 609{
@@ -620,12 +617,14 @@ main (void)
620 ieee_test (1.2E-70); 617 ieee_test (1.2E-70);
621 ieee_test (1.2E-316); 618 ieee_test (1.2E-316);
622 ieee_test (4.9406564584124654E-324); 619 ieee_test (4.9406564584124654E-324);
623 ieee_test (- 4.9406564584124654E-324); 620 ieee_test (-4.9406564584124654E-324);
624 ieee_test (- 0.0); 621 ieee_test (-0.0);
625 ieee_test (- INFINITY); 622 ieee_test (-INFINITY);
626 ieee_test (- NAN); 623 ieee_test (-NAN);
627 ieee_test (INFINITY); 624 ieee_test (INFINITY);
628 ieee_test (NAN); 625 ieee_test (NAN);
629 return 0; 626 return 0;
630} 627}
628
629
631#endif 630#endif
diff --git a/src/plugins/old/convert_numeric.h b/src/plugins/old/convert_numeric.h
index cc425f5..f3adead 100644
--- a/src/plugins/old/convert_numeric.h
+++ b/src/plugins/old/convert_numeric.h
@@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software 18along with this program; if not, write to the Free Software
19Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 19Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
20 20
21#if !defined (FLOATFORMAT_H) 21#if ! defined (FLOATFORMAT_H)
22#define FLOATFORMAT_H 1 22#define FLOATFORMAT_H 1
23 23
24/*#include "ansidecl.h"*/ 24/*#include "ansidecl.h"*/
@@ -31,7 +31,8 @@ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
31 31
32/* What is the order of the bytes? */ 32/* What is the order of the bytes? */
33 33
34enum EXTRACTOR_floatformat_byteorders { 34enum EXTRACTOR_floatformat_byteorders
35{
35 /* Standard little endian byte order. 36 /* Standard little endian byte order.
36 EX: 1.2345678e10 => 00 00 80 c5 e0 fe 06 42 */ 37 EX: 1.2345678e10 => 00 00 80 c5 e0 fe 06 42 */
37 floatformat_little, 38 floatformat_little,
@@ -51,12 +52,13 @@ enum EXTRACTOR_floatformat_byteorders {
51 floatformat_vax 52 floatformat_vax
52}; 53};
53 54
54enum EXTRACTOR_floatformat_intbit { floatformat_intbit_yes, floatformat_intbit_no }; 55enum EXTRACTOR_floatformat_intbit { floatformat_intbit_yes,
56 floatformat_intbit_no };
55 57
56struct EXTRACTOR_floatformat 58struct EXTRACTOR_floatformat
57{ 59{
58 enum EXTRACTOR_floatformat_byteorders byteorder; 60 enum EXTRACTOR_floatformat_byteorders byteorder;
59 unsigned int totalsize; /* Total size of number in bits */ 61 unsigned int totalsize; /* Total size of number in bits */
60 62
61 /* Sign bit is always one bit long. 1 means negative, 0 means positive. */ 63 /* Sign bit is always one bit long. 1 means negative, 0 means positive. */
62 unsigned int sign_start; 64 unsigned int sign_start;
@@ -90,13 +92,16 @@ struct EXTRACTOR_floatformat
90/* floatformats for IEEE single and double, big and little endian. */ 92/* floatformats for IEEE single and double, big and little endian. */
91 93
92extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_big; 94extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_big;
93extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_little; 95extern const struct EXTRACTOR_floatformat
96 EXTRACTOR_floatformat_ieee_single_little;
94extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_big; 97extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_big;
95extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_little; 98extern const struct EXTRACTOR_floatformat
99 EXTRACTOR_floatformat_ieee_double_little;
96 100
97/* floatformat for ARM IEEE double, little endian bytes and big endian words */ 101/* floatformat for ARM IEEE double, little endian bytes and big endian words */
98 102
99extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_littlebyte_bigword; 103extern const struct EXTRACTOR_floatformat
104 EXTRACTOR_floatformat_ieee_double_littlebyte_bigword;
100 105
101/* floatformats for VAX. */ 106/* floatformats for VAX. */
102 107
@@ -110,31 +115,38 @@ extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i387_ext;
110extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m68881_ext; 115extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m68881_ext;
111extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i960_ext; 116extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i960_ext;
112extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_ext; 117extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_ext;
113extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_harris_ext; 118extern const struct EXTRACTOR_floatformat
119 EXTRACTOR_floatformat_m88110_harris_ext;
114extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_big; 120extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_big;
115extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_littlebyte_bigword; 121extern const struct EXTRACTOR_floatformat
122 EXTRACTOR_floatformat_arm_ext_littlebyte_bigword;
116/* IA-64 Floating Point register spilt into memory. */ 123/* IA-64 Floating Point register spilt into memory. */
117extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_big; 124extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_big;
118extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_little; 125extern const struct EXTRACTOR_floatformat
126 EXTRACTOR_floatformat_ia64_spill_little;
119extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_big; 127extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_big;
120extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_little; 128extern const struct EXTRACTOR_floatformat
129 EXTRACTOR_floatformat_ia64_quad_little;
121 130
122/* Convert from FMT to a double. 131/* Convert from FMT to a double.
123 FROM is the address of the extended float. 132 FROM is the address of the extended float.
124 Store the double in *TO. */ 133 Store the double in *TO. */
125 134
126extern void 135extern void
127EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *, const void *, double *); 136EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *,
137 const void *, double *);
128 138
129/* The converse: convert the double *FROM to FMT 139/* The converse: convert the double *FROM to FMT
130 and store where TO points. */ 140 and store where TO points. */
131 141
132extern void 142extern void
133EXTRACTOR_common_floatformat_from_double (const struct EXTRACTOR_floatformat *, const double *, void *); 143EXTRACTOR_common_floatformat_from_double (const struct EXTRACTOR_floatformat *,
144 const double *, void *);
134 145
135/* Return non-zero iff the data at FROM is a valid number in format FMT. */ 146/* Return non-zero iff the data at FROM is a valid number in format FMT. */
136 147
137extern int 148extern int
138EXTRACTOR_common_floatformat_is_valid (const struct EXTRACTOR_floatformat *fmt, const void *from); 149EXTRACTOR_common_floatformat_is_valid (const struct EXTRACTOR_floatformat *fmt,
150 const void *from);
139 151
140#endif /* defined (FLOATFORMAT_H) */ 152#endif /* defined (FLOATFORMAT_H) */
diff --git a/src/plugins/old/ebml_extractor.c b/src/plugins/old/ebml_extractor.c
index 2d52d90..f7daa9a 100644
--- a/src/plugins/old/ebml_extractor.c
+++ b/src/plugins/old/ebml_extractor.c
@@ -18,11 +18,11 @@
18 Boston, MA 02110-1301, USA. 18 Boston, MA 02110-1301, USA.
19 */ 19 */
20 20
21 /* 21/*
22 * Made by Gabriel Peixoto 22 * Made by Gabriel Peixoto
23 * Using AVInfo 1.x code. Copyright (c) 2004 George Shuklin. 23 * Using AVInfo 1.x code. Copyright (c) 2004 George Shuklin.
24 * Nearly complete rewrite by LRN, Copyright (c) 2012 24 * Nearly complete rewrite by LRN, Copyright (c) 2012
25 */ 25 */
26 26
27#include "platform.h" 27#include "platform.h"
28#include "extractor.h" 28#include "extractor.h"
@@ -44,20 +44,25 @@
44struct tm * 44struct tm *
45gmtime_undocumented_64_r (const __time64_t *timer, struct tm *result) 45gmtime_undocumented_64_r (const __time64_t *timer, struct tm *result)
46{ 46{
47 struct tm *local_result = NULL;//_gmtime64 (timer); 47 struct tm *local_result = NULL; // _gmtime64 (timer);
48 48
49 if (local_result == NULL || result == NULL) 49 if ((local_result == NULL) || (result == NULL) )
50 return NULL; 50 return NULL;
51 51
52 memcpy (result, local_result, sizeof (*result)); 52 memcpy (result, local_result, sizeof (*result));
53 return result; 53 return result;
54} 54}
55
56
55#endif 57#endif
56 58
57#include "extractor_plugins.h" 59#include "extractor_plugins.h"
58 60
59#define ADD_EBML(s,t) do { proc (proc_cls, "ebml", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1); } while (0) 61#define ADD_EBML(s,t) do { proc (proc_cls, "ebml", t, EXTRACTOR_METAFORMAT_UTF8, \
60#define ADD_MATROSKA(s,t) do { proc (proc_cls, "matroska", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1); } while (0) 62 "text/plain", s, strlen (s) + 1); } while (0)
63#define ADD_MATROSKA(s,t) do { proc (proc_cls, "matroska", t, \
64 EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, \
65 strlen (s) + 1); } while (0)
61 66
62/** 67/**
63 * String length limit. The spec does not limit the strings, 68 * String length limit. The spec does not limit the strings,
@@ -162,9 +167,9 @@ struct MatroskaTagMap tag_map[] = {
162 {"KEYWORDS", EXTRACTOR_METATYPE_KEYWORDS}, 167 {"KEYWORDS", EXTRACTOR_METATYPE_KEYWORDS},
163 {"SUMMARY", EXTRACTOR_METATYPE_SUMMARY}, 168 {"SUMMARY", EXTRACTOR_METATYPE_SUMMARY},
164 /* 169 /*
165 SYNOPSIS UTF-8 A description of the story line of the item. 170 SYNOPSIS UTF-8 A description of the story line of the item.
166 INITIAL_KEY UTF-8 The initial key that a musical track starts in. The format is identical to ID3. 171 INITIAL_KEY UTF-8 The initial key that a musical track starts in. The format is identical to ID3.
167 PERIOD UTF-8 Describes the period that the piece is from or about. For example, "Renaissance". 172 PERIOD UTF-8 Describes the period that the piece is from or about. For example, "Renaissance".
168 LAW_RATING UTF-8 Depending on the country it's the format of the rating of a movie (P, R, X in the USA, an age in other countries or a URI defining a logo). 173 LAW_RATING UTF-8 Depending on the country it's the format of the rating of a movie (P, R, X in the USA, an age in other countries or a URI defining a logo).
169 ICRA binary The ICRA content rating for parental control. (Previously RSACi) 174 ICRA binary The ICRA content rating for parental control. (Previously RSACi)
170 */ 175 */
@@ -176,7 +181,7 @@ struct MatroskaTagMap tag_map[] = {
176 {"DATE_WRITTEN", EXTRACTOR_METATYPE_UNKNOWN_DATE}, 181 {"DATE_WRITTEN", EXTRACTOR_METATYPE_UNKNOWN_DATE},
177 {"DATE_PURCHASED", EXTRACTOR_METATYPE_UNKNOWN_DATE}, 182 {"DATE_PURCHASED", EXTRACTOR_METATYPE_UNKNOWN_DATE},
178 /* 183 /*
179 RECORDING_LOCATION UTF-8 The location where the item was recorded. The countries corresponding to the string, same 2 octets as in Internet domains, or possibly ISO-3166. This code is followed by a comma, then more detailed information such as state/province, another comma, and then city. For example, "US, Texas, Austin". This will allow for easy sorting. It is okay to only store the country, or the country and the state/province. More detailed information can be added after the city through the use of additional commas. In cases where the province/state is unknown, but you want to store the city, simply leave a space between the two commas. For example, "US, , Austin". 184 RECORDING_LOCATION UTF-8 The location where the item was recorded. The countries corresponding to the string, same 2 octets as in Internet domains, or possibly ISO-3166. This code is followed by a comma, then more detailed information such as state/province, another comma, and then city. For example, "US, Texas, Austin". This will allow for easy sorting. It is okay to only store the country, or the country and the state/province. More detailed information can be added after the city through the use of additional commas. In cases where the province/state is unknown, but you want to store the city, simply leave a space between the two commas. For example, "US, , Austin".
180 COMPOSITION_LOCATION UTF-8 Location that the item was originaly designed/written. The countries corresponding to the string, same 2 octets as in Internet domains, or possibly ISO-3166. This code is followed by a comma, then more detailed information such as state/province, another comma, and then city. For example, "US, Texas, Austin". This will allow for easy sorting. It is okay to only store the country, or the country and the state/province. More detailed information can be added after the city through the use of additional commas. In cases where the province/state is unknown, but you want to store the city, simply leave a space between the two commas. For example, "US, , Austin". 185 COMPOSITION_LOCATION UTF-8 Location that the item was originaly designed/written. The countries corresponding to the string, same 2 octets as in Internet domains, or possibly ISO-3166. This code is followed by a comma, then more detailed information such as state/province, another comma, and then city. For example, "US, Texas, Austin". This will allow for easy sorting. It is okay to only store the country, or the country and the state/province. More detailed information can be added after the city through the use of additional commas. In cases where the province/state is unknown, but you want to store the city, simply leave a space between the two commas. For example, "US, , Austin".
181 COMPOSER_NATIONALITY UTF-8 Nationality of the main composer of the item, mostly for classical music. The countries corresponding to the string, same 2 octets as in Internet domains, or possibly ISO-3166. 186 COMPOSER_NATIONALITY UTF-8 Nationality of the main composer of the item, mostly for classical music. The countries corresponding to the string, same 2 octets as in Internet domains, or possibly ISO-3166.
182 */ 187 */
@@ -188,7 +193,7 @@ struct MatroskaTagMap tag_map[] = {
188 ENCODER UTF-8 The software or hardware used to encode this item. ("LAME" or "XviD") 193 ENCODER UTF-8 The software or hardware used to encode this item. ("LAME" or "XviD")
189 ENCODER_SETTINGS UTF-8 A list of the settings used for encoding this item. No specific format. 194 ENCODER_SETTINGS UTF-8 A list of the settings used for encoding this item. No specific format.
190 BPS UTF-8 The average bits per second of the specified item. This is only the data in the Blocks, and excludes headers and any container overhead. 195 BPS UTF-8 The average bits per second of the specified item. This is only the data in the Blocks, and excludes headers and any container overhead.
191 FPS UTF-8 The average frames per second of the specified item. This is typically the average number of Blocks per second. In the event that lacing is used, each laced chunk is to be counted as a seperate frame. 196 FPS UTF-8 The average frames per second of the specified item. This is typically the average number of Blocks per second. In the event that lacing is used, each laced chunk is to be counted as a seperate frame.
192 */ 197 */
193 {"BPM", EXTRACTOR_METATYPE_BEATS_PER_MINUTE}, 198 {"BPM", EXTRACTOR_METATYPE_BEATS_PER_MINUTE},
194 /* 199 /*
@@ -201,7 +206,7 @@ struct MatroskaTagMap tag_map[] = {
201 /* 206 /*
202 MCDI binary This is a binary dump of the TOC of the CDROM that this item was taken from. This holds the same information as the MCDI in ID3. 207 MCDI binary This is a binary dump of the TOC of the CDROM that this item was taken from. This holds the same information as the MCDI in ID3.
203 ISBN UTF-8 International Standard Book Number 208 ISBN UTF-8 International Standard Book Number
204 BARCODE UTF-8 EAN-13 (European Article Numbering) or UPC-A (Universal Product Code) bar code identifier 209 BARCODE UTF-8 EAN-13 (European Article Numbering) or UPC-A (Universal Product Code) bar code identifier
205 CATALOG_NUMBER UTF-8 A label-specific string used to identify the release (TIC 01 for example). 210 CATALOG_NUMBER UTF-8 A label-specific string used to identify the release (TIC 01 for example).
206 LABEL_CODE UTF-8 A 4-digit or 5-digit number to identify the record label, typically printed as (LC) xxxx or (LC) 0xxxx on CDs medias or covers (only the number is stored). 211 LABEL_CODE UTF-8 A 4-digit or 5-digit number to identify the record label, typically printed as (LC) xxxx or (LC) 0xxxx on CDs medias or covers (only the number is stored).
207 LCCN UTF-8 Library of Congress Control Number 212 LCCN UTF-8 Library of Congress Control Number
@@ -281,7 +286,6 @@ enum
281 MatroskaID_Tracks_Audio_BitDepth = 0x6264, /* not 0, UINT. Bits per sample, mostly used for PCM. */ 286 MatroskaID_Tracks_Audio_BitDepth = 0x6264, /* not 0, UINT. Bits per sample, mostly used for PCM. */
282 287
283 288
284
285 MatroskaID_Tags = 0x1254C367, /* can appear more than once. Element containing elements specific to Tracks/Chapters. A list of valid tags can be found here. */ 289 MatroskaID_Tags = 0x1254C367, /* can appear more than once. Element containing elements specific to Tracks/Chapters. A list of valid tags can be found here. */
286 MatroskaID_Tags_Tag = 0x7373, /* mandatory, can appear more than once. Element containing elements specific to Tracks/Chapters. */ 290 MatroskaID_Tags_Tag = 0x7373, /* mandatory, can appear more than once. Element containing elements specific to Tracks/Chapters. */
287 MatroskaID_Tags_Tag_SimpleTag = 0x67C8, /* mandatory, can appear more than once, recursive. Contains general information about the target. */ 291 MatroskaID_Tags_Tag_SimpleTag = 0x67C8, /* mandatory, can appear more than once, recursive. Contains general information about the target. */
@@ -315,12 +319,14 @@ enum VINTParseMode
315 */ 319 */
316static ssize_t 320static ssize_t
317VINTparse (struct EXTRACTOR_PluginList *plugin, 321VINTparse (struct EXTRACTOR_PluginList *plugin,
318 int64_t * result, enum VINTParseMode mode) 322 int64_t *result, enum VINTParseMode mode)
319{ 323{
320 /* 10000000 01000000 00100000 00010000 00001000 00000100 00000010 00000001 */ 324 /* 10000000 01000000 00100000 00010000 00001000 00000100 00000010 00000001 */
321 static const unsigned char mask[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; 325 static const unsigned char mask[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04,
326 0x02, 0x01 };
322 /* 01111111 00111111 00011111 00001111 00000111 00000011 00000001 00000000 */ 327 /* 01111111 00111111 00011111 00001111 00000111 00000011 00000001 00000000 */
323 static const unsigned char imask[8] = { 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01, 0x00 }; 328 static const unsigned char imask[8] = { 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03,
329 0x01, 0x00 };
324 static const int64_t int_negative_limits[8] = { 330 static const int64_t int_negative_limits[8] = {
325 -0x00000000000040LL, /* 7-bit integer */ 331 -0x00000000000040LL, /* 7-bit integer */
326 -0x00000000002000LL, /* 14-bit integer */ 332 -0x00000000002000LL, /* 14-bit integer */
@@ -374,13 +380,11 @@ VINTparse (struct EXTRACTOR_PluginList *plugin,
374 * 1-byte integer has 2^7 different values, 380 * 1-byte integer has 2^7 different values,
375 * 2-byte integer has 2^14 different values, 381 * 2-byte integer has 2^14 different values,
376 * etc 382 * etc
377 */ 383 *//*
378 /*
379 * Examine the first byte and see how many 0-bytes are at its beginning. 384 * Examine the first byte and see how many 0-bytes are at its beginning.
380 */ 385 */vint_width = 0;
381 vint_width = 0;
382 for (c = 0; c < 8; c++) 386 for (c = 0; c < 8; c++)
383 if (!(first_byte & mask[c])) 387 if (! (first_byte & mask[c]))
384 vint_width++; 388 vint_width++;
385 else 389 else
386 break; 390 break;
@@ -403,7 +407,7 @@ VINTparse (struct EXTRACTOR_PluginList *plugin,
403 * 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 407 * 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
404 * 4-bit signed integer: 408 * 4-bit signed integer:
405 * 0 1 2 3 4 5 6 7 -8 -7 -6 -5 -4 -3 -2 -1 409 * 0 1 2 3 4 5 6 7 -8 -7 -6 -5 -4 -3 -2 -1
406 * 410 *
407 * 3 here is 0011b, and -3 is 1101b 411 * 3 here is 0011b, and -3 is 1101b
408 * However, writing 1101b into int8_t memory location will NOT make 412 * However, writing 1101b into int8_t memory location will NOT make
409 * the machine interpret it as -3, it will be interpreted as 00001101b, 413 * the machine interpret it as -3, it will be interpreted as 00001101b,
@@ -427,9 +431,7 @@ VINTparse (struct EXTRACTOR_PluginList *plugin,
427 * which is outside of the signed integer range (remember, we're in 4-bit space here). 431 * which is outside of the signed integer range (remember, we're in 4-bit space here).
428 * on the other hand, 5 and -3 both are within the range. 432 * on the other hand, 5 and -3 both are within the range.
429 * 4) if the number does not exceed the signed integer maximum (7), store it as-is 433 * 4) if the number does not exceed the signed integer maximum (7), store it as-is
430 */ 434 */result_u = 0;
431
432 result_u = 0;
433 /* Copy the extra bytes into a temporary buffer, in the right order */ 435 /* Copy the extra bytes into a temporary buffer, in the right order */
434 for (c = 0; c < vint_width; c++) 436 for (c = 0; c < vint_width; c++)
435 result_u += ((uint64_t) int_bytes[vint_width - c]) << (c * 8); 437 result_u += ((uint64_t) int_bytes[vint_width - c]) << (c * 8);
@@ -439,7 +441,8 @@ VINTparse (struct EXTRACTOR_PluginList *plugin,
439 { 441 {
440 case VINT_READ_UINT: 442 case VINT_READ_UINT:
441 /* Unset the 1-bit marker */ 443 /* Unset the 1-bit marker */
442 result_u += ((uint64_t) int_bytes[0] & imask[vint_width]) << (vint_width * 8); 444 result_u += ((uint64_t) int_bytes[0] & imask[vint_width]) << (vint_width
445 * 8);
443 memcpy (result, &result_u, sizeof (uint64_t)); 446 memcpy (result, &result_u, sizeof (uint64_t));
444 break; 447 break;
445 case VINT_READ_ID: 448 case VINT_READ_ID:
@@ -449,7 +452,8 @@ VINTparse (struct EXTRACTOR_PluginList *plugin,
449 break; 452 break;
450 case VINT_READ_SIZE: 453 case VINT_READ_SIZE:
451 /* Unset the 1-bit marker */ 454 /* Unset the 1-bit marker */
452 result_u += ((uint64_t) int_bytes[0] & imask[vint_width]) << (vint_width * 8); 455 result_u += ((uint64_t) int_bytes[0] & imask[vint_width]) << (vint_width
456 * 8);
453 /* Special case: all-1 size means "size is unknown". We indicate this 457 /* Special case: all-1 size means "size is unknown". We indicate this
454 * in the return value by setting it to UINT64_MAX. 458 * in the return value by setting it to UINT64_MAX.
455 */ 459 */
@@ -459,7 +463,8 @@ VINTparse (struct EXTRACTOR_PluginList *plugin,
459 break; 463 break;
460 case VINT_READ_SINT: 464 case VINT_READ_SINT:
461 /* Unset the 1-bit marker */ 465 /* Unset the 1-bit marker */
462 result_u += ((uint64_t) int_bytes[0] & imask[vint_width]) << (vint_width * 8); 466 result_u += ((uint64_t) int_bytes[0] & imask[vint_width]) << (vint_width
467 * 8);
463 /* Interpret large values as negative signed values */ 468 /* Interpret large values as negative signed values */
464 if (result_u > int_positive_limits[vint_width]) 469 if (result_u > int_positive_limits[vint_width])
465 { 470 {
@@ -492,7 +497,7 @@ VINTparse (struct EXTRACTOR_PluginList *plugin,
492 */ 497 */
493static ssize_t 498static ssize_t
494elementRead (struct EXTRACTOR_PluginList *plugin, 499elementRead (struct EXTRACTOR_PluginList *plugin,
495 uint32_t *id, int64_t * size) 500 uint32_t *id, int64_t *size)
496{ 501{
497 int64_t tempID; 502 int64_t tempID;
498 int64_t tempsize; 503 int64_t tempsize;
@@ -519,6 +524,7 @@ elementRead (struct EXTRACTOR_PluginList *plugin,
519 return id_offset + size_offset; 524 return id_offset + size_offset;
520} 525}
521 526
527
522static ssize_t 528static ssize_t
523idRead (struct EXTRACTOR_PluginList *plugin, 529idRead (struct EXTRACTOR_PluginList *plugin,
524 uint64_t length, uint32_t *id) 530 uint64_t length, uint32_t *id)
@@ -537,8 +543,10 @@ idRead (struct EXTRACTOR_PluginList *plugin,
537 return id_offset; 543 return id_offset;
538} 544}
539 545
546
540static ssize_t 547static ssize_t
541uintRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, uint64_t *result) 548uintRead (struct EXTRACTOR_PluginList *plugin, uint64_t length,
549 uint64_t *result)
542{ 550{
543 size_t c; 551 size_t c;
544 unsigned char *data; 552 unsigned char *data;
@@ -552,6 +560,7 @@ uintRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, uint64_t *result
552 return (ssize_t) length; 560 return (ssize_t) length;
553} 561}
554 562
563
555static ssize_t 564static ssize_t
556sintRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, int64_t *result) 565sintRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, int64_t *result)
557{ 566{
@@ -579,6 +588,7 @@ sintRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, int64_t *result)
579 return (ssize_t) length; 588 return (ssize_t) length;
580} 589}
581 590
591
582static ssize_t 592static ssize_t
583stringRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, char *result) 593stringRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, char *result)
584{ 594{
@@ -601,8 +611,10 @@ stringRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, char *result)
601 return 1; 611 return 1;
602} 612}
603 613
614
604static ssize_t 615static ssize_t
605floatRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, long double *result) 616floatRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, long
617 double *result)
606{ 618{
607 size_t c; 619 size_t c;
608 unsigned char t[8]; 620 unsigned char t[8];
@@ -612,7 +624,7 @@ floatRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, long double *re
612 return -1; 624 return -1;
613 625
614 /* we don't support 10-byte floats, because not all C compilers will guarantee that long double is stored in 10 bytes in a IEEE-conformant format */ 626 /* we don't support 10-byte floats, because not all C compilers will guarantee that long double is stored in 10 bytes in a IEEE-conformant format */
615 if (length != 4 && length != 8 /* && length != 10 */) 627 if ((length != 4) && (length != 8) /* && length != 10 */)
616 return 0; 628 return 0;
617 629
618 for (c = 0; c < length; c++) 630 for (c = 0; c < length; c++)
@@ -624,14 +636,15 @@ floatRead (struct EXTRACTOR_PluginList *plugin, uint64_t length, long double *re
624#endif 636#endif
625 } 637 }
626 if (length == 4) 638 if (length == 4)
627 *result = * ((float *) t); 639 *result = *((float *) t);
628 else if (length == 8) 640 else if (length == 8)
629 *result = * ((double *) t); 641 *result = *((double *) t);
630 else 642 else
631 *result = * ((long double *) t); 643 *result = *((long double *) t);
632 return (ssize_t) length; 644 return (ssize_t) length;
633} 645}
634 646
647
635static const char stream_type_letters[] = "?vat"; /*[0]-no, [1]-video,[2]-audio,[3]-text */ 648static const char stream_type_letters[] = "?vat"; /*[0]-no, [1]-video,[2]-audio,[3]-text */
636 649
637enum EBMLState 650enum EBMLState
@@ -791,6 +804,7 @@ clean_ebml_state_ebml (struct ebml_state *state)
791 state->doctype_read_version = 0; 804 state->doctype_read_version = 0;
792} 805}
793 806
807
794static void 808static void
795clean_ebml_state_matroska_simpletags (struct ebml_state *state) 809clean_ebml_state_matroska_simpletags (struct ebml_state *state)
796{ 810{
@@ -809,7 +823,7 @@ clean_ebml_state_matroska_simpletags (struct ebml_state *state)
809 if (el->string != NULL) 823 if (el->string != NULL)
810 free (el->string); 824 free (el->string);
811 free (el); 825 free (el);
812 if (parent != NULL && parent->child == el) 826 if ((parent != NULL) && (parent->child == el))
813 parent->child = next; 827 parent->child = next;
814 el = next; 828 el = next;
815 if (next == NULL) 829 if (next == NULL)
@@ -820,8 +834,10 @@ clean_ebml_state_matroska_simpletags (struct ebml_state *state)
820 state->tag_current = NULL; 834 state->tag_current = NULL;
821} 835}
822 836
837
823void 838void
824matroska_add_tag (struct ebml_state *state, struct matroska_simpletag *parent, char *name, char *string) 839matroska_add_tag (struct ebml_state *state, struct matroska_simpletag *parent,
840 char *name, char *string)
825{ 841{
826 struct matroska_simpletag *el = malloc (sizeof (struct matroska_simpletag)); 842 struct matroska_simpletag *el = malloc (sizeof (struct matroska_simpletag));
827 el->parent = parent; 843 el->parent = parent;
@@ -839,6 +855,7 @@ matroska_add_tag (struct ebml_state *state, struct matroska_simpletag *parent, c
839 state->tag_last = el; 855 state->tag_last = el;
840} 856}
841 857
858
842static void 859static void
843clean_ebml_state_matroska_seeks (struct ebml_state *state) 860clean_ebml_state_matroska_seeks (struct ebml_state *state)
844{ 861{
@@ -852,6 +869,7 @@ clean_ebml_state_matroska_seeks (struct ebml_state *state)
852 state->matroska_seeks_tail = NULL; 869 state->matroska_seeks_tail = NULL;
853} 870}
854 871
872
855static void 873static void
856clean_ebml_state_matroska_segment (struct ebml_state *state) 874clean_ebml_state_matroska_segment (struct ebml_state *state)
857{ 875{
@@ -862,6 +880,7 @@ clean_ebml_state_matroska_segment (struct ebml_state *state)
862 clean_ebml_state_matroska_simpletags (state); 880 clean_ebml_state_matroska_simpletags (state);
863} 881}
864 882
883
865static void 884static void
866clean_ebml_state_matroska_seek (struct ebml_state *state) 885clean_ebml_state_matroska_seek (struct ebml_state *state)
867{ 886{
@@ -869,6 +888,7 @@ clean_ebml_state_matroska_seek (struct ebml_state *state)
869 state->matroska_seek_position = 0; 888 state->matroska_seek_position = 0;
870} 889}
871 890
891
872static void 892static void
873clean_ebml_state_matroska_info (struct ebml_state *state) 893clean_ebml_state_matroska_info (struct ebml_state *state)
874{ 894{
@@ -889,6 +909,7 @@ clean_ebml_state_matroska_info (struct ebml_state *state)
889 state->matroska_info_writing_app = NULL; 909 state->matroska_info_writing_app = NULL;
890} 910}
891 911
912
892static void 913static void
893clean_ebml_state_matroska_track_video (struct ebml_state *state) 914clean_ebml_state_matroska_track_video (struct ebml_state *state)
894{ 915{
@@ -902,6 +923,7 @@ clean_ebml_state_matroska_track_video (struct ebml_state *state)
902 state->matroska_track_video_display_unit = 0; 923 state->matroska_track_video_display_unit = 0;
903} 924}
904 925
926
905static void 927static void
906clean_ebml_state_matroska_track_audio (struct ebml_state *state) 928clean_ebml_state_matroska_track_audio (struct ebml_state *state)
907{ 929{
@@ -912,6 +934,7 @@ clean_ebml_state_matroska_track_audio (struct ebml_state *state)
912 state->matroska_track_audio_bit_depth = 0; 934 state->matroska_track_audio_bit_depth = 0;
913} 935}
914 936
937
915static void 938static void
916clean_ebml_state_matroska_track (struct ebml_state *state) 939clean_ebml_state_matroska_track (struct ebml_state *state)
917{ 940{
@@ -935,6 +958,7 @@ clean_ebml_state_matroska_track (struct ebml_state *state)
935 clean_ebml_state_matroska_track_audio (state); 958 clean_ebml_state_matroska_track_audio (state);
936} 959}
937 960
961
938static struct ebml_state * 962static struct ebml_state *
939EXTRACTOR_ebml_init_state_method () 963EXTRACTOR_ebml_init_state_method ()
940{ 964{
@@ -952,14 +976,17 @@ EXTRACTOR_ebml_init_state_method ()
952 return state; 976 return state;
953} 977}
954 978
979
955static void 980static void
956report_simpletag (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, void *proc_cls) 981report_simpletag (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc,
982 void *proc_cls)
957{ 983{
958 struct matroska_simpletag *el, *next; 984 struct matroska_simpletag *el, *next;
959 char format[MAX_STRING_SIZE + 1]; 985 char format[MAX_STRING_SIZE + 1];
960 for (el = state->tag_tree; el != NULL; el = next) 986 for (el = state->tag_tree; el != NULL; el = next)
961 { 987 {
962 if (el->name != NULL && el->name[0] != '\0' && el->string != NULL && el->string[0] != '\0') 988 if ((el->name != NULL) && (el->name[0] != '\0') && (el->string != NULL) &&
989 (el->string[0] != '\0') )
963 { 990 {
964 enum EXTRACTOR_MetaType metatype = EXTRACTOR_METATYPE_RESERVED; 991 enum EXTRACTOR_MetaType metatype = EXTRACTOR_METATYPE_RESERVED;
965 struct MatroskaTagMap *map_item; 992 struct MatroskaTagMap *map_item;
@@ -975,10 +1002,10 @@ report_simpletag (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, vo
975 { 1002 {
976 snprintf (format, MAX_STRING_SIZE, "%s=%s", el->name, el->string); 1003 snprintf (format, MAX_STRING_SIZE, "%s=%s", el->name, el->string);
977 format[MAX_STRING_SIZE] = '\0'; 1004 format[MAX_STRING_SIZE] = '\0';
978 ADD_MATROSKA(format, EXTRACTOR_METATYPE_UNKNOWN); 1005 ADD_MATROSKA (format, EXTRACTOR_METATYPE_UNKNOWN);
979 } 1006 }
980 else 1007 else
981 ADD_MATROSKA(el->string, metatype); 1008 ADD_MATROSKA (el->string, metatype);
982 } 1009 }
983 next = el->child; 1010 next = el->child;
984 while (next == NULL && el != NULL) 1011 while (next == NULL && el != NULL)
@@ -991,18 +1018,21 @@ report_simpletag (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, vo
991 clean_ebml_state_matroska_simpletags (state); 1018 clean_ebml_state_matroska_simpletags (state);
992} 1019}
993 1020
1021
994static void 1022static void
995report_state (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, void *proc_cls) 1023report_state (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc,
1024 void *proc_cls)
996{ 1025{
997 char format[MAX_STRING_SIZE + 1]; 1026 char format[MAX_STRING_SIZE + 1];
998 report_simpletag (state, proc, proc_cls); 1027 report_simpletag (state, proc, proc_cls);
999 if (state->valid_ebml && !state->reported_ebml) 1028 if (state->valid_ebml && ! state->reported_ebml)
1000 { 1029 {
1001 state->reported_ebml = 1; 1030 state->reported_ebml = 1;
1002 snprintf (format, MAX_STRING_SIZE, "%llu", (unsigned long long) state->ebml_version); 1031 snprintf (format, MAX_STRING_SIZE, "%llu", (unsigned long
1032 long) state->ebml_version);
1003 format[MAX_STRING_SIZE] = '\0'; 1033 format[MAX_STRING_SIZE] = '\0';
1004 ADD_EBML(format, EXTRACTOR_METATYPE_FORMAT_VERSION); 1034 ADD_EBML (format, EXTRACTOR_METATYPE_FORMAT_VERSION);
1005 snprintf (format, MAX_STRING_SIZE, "%s %llu (EBML %llu)", state->doctype, 1035 snprintf (format, MAX_STRING_SIZE, "%s %llu (EBML %llu)", state->doctype,
1006 (unsigned long long) state->doctype_version, 1036 (unsigned long long) state->doctype_version,
1007 (unsigned long long) state->ebml_version); 1037 (unsigned long long) state->ebml_version);
1008 format[MAX_STRING_SIZE] = '\0'; 1038 format[MAX_STRING_SIZE] = '\0';
@@ -1012,21 +1042,25 @@ report_state (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, void *
1012 clean_ebml_state_ebml (state); 1042 clean_ebml_state_ebml (state);
1013 if (state->valid_matroska_info == -1) 1043 if (state->valid_matroska_info == -1)
1014 { 1044 {
1015 if ((state->matroska_info_duration > 0 || state->matroska_info_duration == -1.0) && 1045 if (((state->matroska_info_duration > 0) ||
1016 state->matroska_info_muxing_app != NULL && state->matroska_info_writing_app != NULL) 1046 (state->matroska_info_duration == -1.0) ) &&
1047 (state->matroska_info_muxing_app != NULL) &&
1048 (state->matroska_info_writing_app != NULL) )
1017 state->valid_matroska_info = 1; 1049 state->valid_matroska_info = 1;
1018 else 1050 else
1019 state->valid_matroska_info = 0; 1051 state->valid_matroska_info = 0;
1020 } 1052 }
1021 if (state->valid_matroska_info == 1 && !state->reported_matroska_info) 1053 if ((state->valid_matroska_info == 1) && ! state->reported_matroska_info)
1022 { 1054 {
1023 state->reported_matroska_info = 1; 1055 state->reported_matroska_info = 1;
1024 if (state->matroska_info_duration != -1.0) 1056 if (state->matroska_info_duration != -1.0)
1025 { 1057 {
1026 uint64_t seconds = (uint64_t) ((state->matroska_info_duration * (float) state->matroska_info_timecode_scale) / 1e+9); 1058 uint64_t seconds = (uint64_t) ((state->matroska_info_duration
1059 * (float) state->
1060 matroska_info_timecode_scale) / 1e+9);
1027 snprintf (format, MAX_STRING_SIZE, "%llus", (unsigned long long) seconds); 1061 snprintf (format, MAX_STRING_SIZE, "%llus", (unsigned long long) seconds);
1028 format[MAX_STRING_SIZE] = '\0'; 1062 format[MAX_STRING_SIZE] = '\0';
1029 ADD_MATROSKA(format, EXTRACTOR_METATYPE_DURATION); 1063 ADD_MATROSKA (format, EXTRACTOR_METATYPE_DURATION);
1030 } 1064 }
1031 if (state->matroska_info_date_utc_is_set) 1065 if (state->matroska_info_date_utc_is_set)
1032 { 1066 {
@@ -1052,8 +1086,7 @@ report_state (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, void *
1052 * millenium is known and never changes), but we want to use 64-bit integer to 1086 * millenium is known and never changes), but we want to use 64-bit integer to
1053 * manipulate time. If it gets trimmed later, when assigning back to a TIME_TYPE 1087 * manipulate time. If it gets trimmed later, when assigning back to a TIME_TYPE
1054 * that happens to be 32-bit long - well, tough luck. 1088 * that happens to be 32-bit long - well, tough luck.
1055 */ 1089 */errno = 0;
1056 errno = 0;
1057#if WINDOWS 1090#if WINDOWS
1058 millenium_start_stamp = _mktime64 (&millenium_start); 1091 millenium_start_stamp = _mktime64 (&millenium_start);
1059#else 1092#else
@@ -1061,58 +1094,69 @@ report_state (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, void *
1061#endif 1094#endif
1062 if (millenium_start_stamp == -1) 1095 if (millenium_start_stamp == -1)
1063 printf ("Failed to convert time: %d\n", errno); 1096 printf ("Failed to convert time: %d\n", errno);
1064 matroska_date_stamp = millenium_start_stamp * 1000000000 + state->matroska_info_date_utc; 1097 matroska_date_stamp = millenium_start_stamp * 1000000000
1098 + state->matroska_info_date_utc;
1065 /* Now matroska_date_stamp is the number of nanoseconds since UNIX Epoch */ 1099 /* Now matroska_date_stamp is the number of nanoseconds since UNIX Epoch */
1066 matroska_date_stamp_time_t = matroska_date_stamp / 1000000000; 1100 matroska_date_stamp_time_t = matroska_date_stamp / 1000000000;
1067 /* Now matroska_date_stamp_time_t is the number of seconds since UNIX Epoch */ 1101 /* Now matroska_date_stamp_time_t is the number of seconds since UNIX Epoch */
1068#if WINDOWS 1102#if WINDOWS
1069 if (NULL != gmtime_undocumented_64_r (&matroska_date_stamp_time_t, &matroska_date)) 1103 if (NULL != gmtime_undocumented_64_r (&matroska_date_stamp_time_t,
1104 &matroska_date))
1070#else 1105#else
1071 /* We want to be thread-safe. If you have no gmtime_r(), think of something! */ 1106 /* We want to be thread-safe. If you have no gmtime_r(), think of something! */
1072 if (NULL != gmtime_r (&matroska_date_stamp_time_t, &matroska_date)) 1107 if (NULL != gmtime_r (&matroska_date_stamp_time_t, &matroska_date))
1073#endif 1108#endif
1074 { 1109 {
1075 if (0 != strftime (format, MAX_STRING_SIZE, "%Y.%m.%d %H:%M:%S UTC", &matroska_date)) 1110 if (0 != strftime (format, MAX_STRING_SIZE, "%Y.%m.%d %H:%M:%S UTC",
1076 ADD_MATROSKA(format, EXTRACTOR_METATYPE_CREATION_DATE); 1111 &matroska_date))
1112 ADD_MATROSKA (format, EXTRACTOR_METATYPE_CREATION_DATE);
1077 } 1113 }
1078 } 1114 }
1079 if (state->matroska_info_title != NULL) 1115 if (state->matroska_info_title != NULL)
1080 ADD_MATROSKA(state->matroska_info_title, EXTRACTOR_METATYPE_TITLE); 1116 ADD_MATROSKA (state->matroska_info_title, EXTRACTOR_METATYPE_TITLE);
1081 if (strcmp (state->matroska_info_writing_app, state->matroska_info_muxing_app) == 0) 1117 if (strcmp (state->matroska_info_writing_app,
1082 snprintf (format, MAX_STRING_SIZE, "Written and muxed with %s", state->matroska_info_writing_app); 1118 state->matroska_info_muxing_app) == 0)
1119 snprintf (format, MAX_STRING_SIZE, "Written and muxed with %s",
1120 state->matroska_info_writing_app);
1083 else 1121 else
1084 snprintf (format, MAX_STRING_SIZE, "Written with %s, muxed with %s", state->matroska_info_writing_app, state->matroska_info_muxing_app); 1122 snprintf (format, MAX_STRING_SIZE, "Written with %s, muxed with %s",
1123 state->matroska_info_writing_app,
1124 state->matroska_info_muxing_app);
1085 format[MAX_STRING_SIZE] = '\0'; 1125 format[MAX_STRING_SIZE] = '\0';
1086 ADD_MATROSKA(format, EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE); 1126 ADD_MATROSKA (format, EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE);
1087 } 1127 }
1088 if (state->valid_matroska_info == 1) 1128 if (state->valid_matroska_info == 1)
1089 clean_ebml_state_matroska_info (state); 1129 clean_ebml_state_matroska_info (state);
1090 if (state->valid_matroska_track == -1) 1130 if (state->valid_matroska_track == -1)
1091 { 1131 {
1092 if ((state->matroska_track_type > 0 && state->matroska_track_type < 255) && 1132 if (((state->matroska_track_type > 0) && (state->matroska_track_type <
1093 state->matroska_track_codec_id != NULL) 1133 255) ) &&
1134 (state->matroska_track_codec_id != NULL) )
1094 state->valid_matroska_track = 1; 1135 state->valid_matroska_track = 1;
1095 else 1136 else
1096 state->valid_matroska_track = 0; 1137 state->valid_matroska_track = 0;
1097 } 1138 }
1098 if (state->valid_matroska_track_video == -1) 1139 if (state->valid_matroska_track_video == -1)
1099 { 1140 {
1100 if ((state->matroska_track_video_flag_interlaced == 0 || state->matroska_track_video_flag_interlaced == 1) && 1141 if (((state->matroska_track_video_flag_interlaced == 0) ||
1101 (state->matroska_track_video_stereo_mode >= 0 && state->matroska_track_video_stereo_mode <= 14) && 1142 (state->matroska_track_video_flag_interlaced == 1) ) &&
1102 state->matroska_track_video_pixel_width > 0 && state->matroska_track_video_pixel_height > 0) 1143 ((state->matroska_track_video_stereo_mode >= 0) &&
1144 (state->matroska_track_video_stereo_mode <= 14) ) &&
1145 (state->matroska_track_video_pixel_width > 0) &&
1146 (state->matroska_track_video_pixel_height > 0) )
1103 state->valid_matroska_track_video = 1; 1147 state->valid_matroska_track_video = 1;
1104 else 1148 else
1105 state->valid_matroska_track_video = 0; 1149 state->valid_matroska_track_video = 0;
1106 } 1150 }
1107 if (state->valid_matroska_track_audio == -1) 1151 if (state->valid_matroska_track_audio == -1)
1108 { 1152 {
1109 if (state->matroska_track_audio_sampling_frequency > 0 && 1153 if ((state->matroska_track_audio_sampling_frequency > 0) &&
1110 state->matroska_track_audio_channels > 0) 1154 (state->matroska_track_audio_channels > 0) )
1111 state->valid_matroska_track_audio = 1; 1155 state->valid_matroska_track_audio = 1;
1112 else 1156 else
1113 state->valid_matroska_track_audio = 0; 1157 state->valid_matroska_track_audio = 0;
1114 } 1158 }
1115 if (state->valid_matroska_track == 1 && !state->reported_matroska_track) 1159 if ((state->valid_matroska_track == 1) && ! state->reported_matroska_track)
1116 { 1160 {
1117 char name_part[MAX_STRING_SIZE + 1]; 1161 char name_part[MAX_STRING_SIZE + 1];
1118 char codec_part[MAX_STRING_SIZE + 1]; 1162 char codec_part[MAX_STRING_SIZE + 1];
@@ -1142,28 +1186,32 @@ report_state (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, void *
1142 if (state->matroska_track_name == NULL) 1186 if (state->matroska_track_name == NULL)
1143 snprintf (name_part, MAX_STRING_SIZE, "%s", ""); 1187 snprintf (name_part, MAX_STRING_SIZE, "%s", "");
1144 else 1188 else
1145 snprintf (name_part, MAX_STRING_SIZE, "`%s' ", state->matroska_track_name); 1189 snprintf (name_part, MAX_STRING_SIZE, "`%s' ",
1190 state->matroska_track_name);
1146 name_part[MAX_STRING_SIZE] = '\0'; 1191 name_part[MAX_STRING_SIZE] = '\0';
1147 1192
1148 if (state->matroska_track_codec_name == NULL) 1193 if (state->matroska_track_codec_name == NULL)
1149 snprintf (codec_part, MAX_STRING_SIZE, "%s", state->matroska_track_codec_id); 1194 snprintf (codec_part, MAX_STRING_SIZE, "%s",
1195 state->matroska_track_codec_id);
1150 else 1196 else
1151 snprintf (codec_part, MAX_STRING_SIZE, "%s [%s]", state->matroska_track_codec_id, state->matroska_track_codec_name); 1197 snprintf (codec_part, MAX_STRING_SIZE, "%s [%s]",
1198 state->matroska_track_codec_id,
1199 state->matroska_track_codec_name);
1152 codec_part[MAX_STRING_SIZE] = '\0'; 1200 codec_part[MAX_STRING_SIZE] = '\0';
1153 1201
1154 if (use_video && state->valid_matroska_track_video == 1) 1202 if (use_video && (state->valid_matroska_track_video == 1))
1155 { 1203 {
1156 /* Ignore Display* for now. Aspect ratio correction could be 1204 /* Ignore Display* for now. Aspect ratio correction could be
1157 * done either way (stretching horizontally or squishing vertically), 1205 * done either way (stretching horizontally or squishing vertically),
1158 * so let's stick to hard cold pixel counts. 1206 * so let's stick to hard cold pixel counts.
1159 */ 1207 */
1160 snprintf (format, MAX_STRING_SIZE, "%llux%llu", 1208 snprintf (format, MAX_STRING_SIZE, "%llux%llu",
1161 (unsigned long long) state->matroska_track_video_pixel_width, 1209 (unsigned long long) state->matroska_track_video_pixel_width,
1162 (unsigned long long) state->matroska_track_video_pixel_height); 1210 (unsigned long long) state->matroska_track_video_pixel_height);
1163 format[MAX_STRING_SIZE] = '\0'; 1211 format[MAX_STRING_SIZE] = '\0';
1164 ADD_MATROSKA (format, EXTRACTOR_METATYPE_IMAGE_DIMENSIONS); 1212 ADD_MATROSKA (format, EXTRACTOR_METATYPE_IMAGE_DIMENSIONS);
1165 } 1213 }
1166 if (use_audio && state->valid_matroska_track_audio == 1) 1214 if (use_audio && (state->valid_matroska_track_audio == 1))
1167 { 1215 {
1168 double freq = state->matroska_track_audio_sampling_frequency; 1216 double freq = state->matroska_track_audio_sampling_frequency;
1169 double rfreq = freq; 1217 double rfreq = freq;
@@ -1176,20 +1224,24 @@ report_state (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, void *
1176 hz_part[MAX_STRING_SIZE] = '\0'; 1224 hz_part[MAX_STRING_SIZE] = '\0';
1177 1225
1178 if (state->matroska_track_audio_bit_depth > 0) 1226 if (state->matroska_track_audio_bit_depth > 0)
1179 snprintf (bit_part, MAX_STRING_SIZE, "%llu-bit ", (unsigned long long) state->matroska_track_audio_bit_depth); 1227 snprintf (bit_part, MAX_STRING_SIZE, "%llu-bit ", (unsigned long
1228 long) state->
1229 matroska_track_audio_bit_depth);
1180 else 1230 else
1181 bit_part[0] = '\0'; 1231 bit_part[0] = '\0';
1182 bit_part[MAX_STRING_SIZE] = '\0'; 1232 bit_part[MAX_STRING_SIZE] = '\0';
1183 1233
1184 snprintf (format, MAX_STRING_SIZE, "%s track %s(%s, %llu-channel %sat %s) [%s]", 1234 snprintf (format, MAX_STRING_SIZE,
1185 track_type_string, name_part, codec_part, 1235 "%s track %s(%s, %llu-channel %sat %s) [%s]",
1186 (unsigned long long) state->matroska_track_audio_channels, 1236 track_type_string, name_part, codec_part,
1187 bit_part, hz_part, state->matroska_track_language); 1237 (unsigned long long) state->matroska_track_audio_channels,
1238 bit_part, hz_part, state->matroska_track_language);
1188 } 1239 }
1189 else 1240 else
1190 { 1241 {
1191 snprintf (format, MAX_STRING_SIZE, "%s track %s(%s) [%s]", 1242 snprintf (format, MAX_STRING_SIZE, "%s track %s(%s) [%s]",
1192 track_type_string, name_part, codec_part, state->matroska_track_language); 1243 track_type_string, name_part, codec_part,
1244 state->matroska_track_language);
1193 } 1245 }
1194 format[MAX_STRING_SIZE] = '\0'; 1246 format[MAX_STRING_SIZE] = '\0';
1195 ADD_EBML (format, EXTRACTOR_METATYPE_RESOURCE_TYPE); 1247 ADD_EBML (format, EXTRACTOR_METATYPE_RESOURCE_TYPE);
@@ -1199,7 +1251,7 @@ report_state (struct ebml_state *state, EXTRACTOR_MetaDataProcessor proc, void *
1199} 1251}
1200 1252
1201 1253
1202static int 1254static int
1203EXTRACTOR_ebml_discard_state_method (struct ebml_state *state) 1255EXTRACTOR_ebml_discard_state_method (struct ebml_state *state)
1204{ 1256{
1205 if (state != NULL) 1257 if (state != NULL)
@@ -1214,6 +1266,7 @@ EXTRACTOR_ebml_discard_state_method (struct ebml_state *state)
1214 return 1; 1266 return 1;
1215} 1267}
1216 1268
1269
1217static struct ebml_element * 1270static struct ebml_element *
1218ebml_stack_pop (struct ebml_state *state) 1271ebml_stack_pop (struct ebml_state *state)
1219{ 1272{
@@ -1227,7 +1280,10 @@ ebml_stack_pop (struct ebml_state *state)
1227 1280
1228 1281
1229static void 1282static void
1230ebml_stack_push_new (struct ebml_state *state, uint64_t position, uint32_t id, uint64_t size, uint64_t header_size, int finish_state, int prev_state, int bail_state, int bail_next_state) 1283ebml_stack_push_new (struct ebml_state *state, uint64_t position, uint32_t id,
1284 uint64_t size, uint64_t header_size, int finish_state, int
1285 prev_state, int
1286 bail_state, int bail_next_state)
1231{ 1287{
1232 struct ebml_element *element = malloc (sizeof (struct ebml_element)); 1288 struct ebml_element *element = malloc (sizeof (struct ebml_element));
1233 element->parent = state->stack_top; 1289 element->parent = state->stack_top;
@@ -1242,8 +1298,10 @@ ebml_stack_push_new (struct ebml_state *state, uint64_t position, uint32_t id, u
1242 element->bail_next_state = bail_next_state; 1298 element->bail_next_state = bail_next_state;
1243} 1299}
1244 1300
1301
1245static int 1302static int
1246check_result (struct EXTRACTOR_PluginList *plugin, ssize_t read_result, struct ebml_state *state) 1303check_result (struct EXTRACTOR_PluginList *plugin, ssize_t read_result, struct
1304 ebml_state *state)
1247{ 1305{
1248 if (read_result == 0) 1306 if (read_result == 0)
1249 { 1307 {
@@ -1256,7 +1314,7 @@ check_result (struct EXTRACTOR_PluginList *plugin, ssize_t read_result, struct e
1256 return 0; 1314 return 0;
1257 } 1315 }
1258 offset = parent->position + parent->header_size + parent->size; 1316 offset = parent->position + parent->header_size + parent->size;
1259 if (offset < 0 || offset != pl_seek (plugin, offset, SEEK_SET)) 1317 if ((offset < 0) || (offset != pl_seek (plugin, offset, SEEK_SET)))
1260 { 1318 {
1261 state->state = EBML_BAD_STATE; 1319 state->state = EBML_BAD_STATE;
1262 return 0; 1320 return 0;
@@ -1269,12 +1327,16 @@ check_result (struct EXTRACTOR_PluginList *plugin, ssize_t read_result, struct e
1269 return 1; 1327 return 1;
1270} 1328}
1271 1329
1330
1272static int 1331static int
1273maybe_rise_up (struct EXTRACTOR_PluginList *plugin, struct ebml_state *state, int *do_break, int64_t read_result) 1332maybe_rise_up (struct EXTRACTOR_PluginList *plugin, struct ebml_state *state,
1333 int *do_break, int64_t read_result)
1274{ 1334{
1275 int64_t offset; 1335 int64_t offset;
1276 offset = pl_get_pos (plugin) - read_result; 1336 offset = pl_get_pos (plugin) - read_result;
1277 if (state->stack_top != NULL && offset >= state->stack_top->position + state->stack_top->header_size + state->stack_top->size) 1337 if ((state->stack_top != NULL) && (offset >= state->stack_top->position
1338 + state->stack_top->header_size
1339 + state->stack_top->size) )
1278 { 1340 {
1279 state->state = state->stack_top->finish_state; 1341 state->state = state->stack_top->finish_state;
1280 pl_seek (plugin, -read_result, SEEK_CUR); 1342 pl_seek (plugin, -read_result, SEEK_CUR);
@@ -1284,24 +1346,29 @@ maybe_rise_up (struct EXTRACTOR_PluginList *plugin, struct ebml_state *state, in
1284 return 0; 1346 return 0;
1285} 1347}
1286 1348
1349
1287static void 1350static void
1288rise_up_after_value (struct EXTRACTOR_PluginList *plugin, struct ebml_state *state, int next_state) 1351rise_up_after_value (struct EXTRACTOR_PluginList *plugin, struct
1352 ebml_state *state, int next_state)
1289{ 1353{
1290 int64_t offset; 1354 int64_t offset;
1291 state->state = EBML_READ_ELEMENT; 1355 state->state = EBML_READ_ELEMENT;
1292 offset = state->stack_top->position + state->stack_top->header_size + state->stack_top->size; 1356 offset = state->stack_top->position + state->stack_top->header_size
1357 + state->stack_top->size;
1293 free (ebml_stack_pop (state)); 1358 free (ebml_stack_pop (state));
1294 state->next_state = next_state; 1359 state->next_state = next_state;
1295 pl_seek (plugin, offset, SEEK_SET); 1360 pl_seek (plugin, offset, SEEK_SET);
1296} 1361}
1297 1362
1363
1298static void 1364static void
1299try_to_find_pos (struct EXTRACTOR_PluginList *plugin, struct ebml_state *state) 1365try_to_find_pos (struct EXTRACTOR_PluginList *plugin, struct ebml_state *state)
1300{ 1366{
1301 if (state->matroska_seeks != NULL) 1367 if (state->matroska_seeks != NULL)
1302 { 1368 {
1303 struct matroska_seek_list *el, *pos = NULL; 1369 struct matroska_seek_list *el, *pos = NULL;
1304 int64_t segment_position = pl_get_pos (plugin) - state->segment_contents_start; 1370 int64_t segment_position = pl_get_pos (plugin)
1371 - state->segment_contents_start;
1305 for (el = state->matroska_seeks; el != NULL; el = el->next) 1372 for (el = state->matroska_seeks; el != NULL; el = el->next)
1306 { 1373 {
1307 if (el->position <= segment_position) 1374 if (el->position <= segment_position)
@@ -1314,8 +1381,10 @@ try_to_find_pos (struct EXTRACTOR_PluginList *plugin, struct ebml_state *state)
1314 } 1381 }
1315} 1382}
1316 1383
1384
1317static void 1385static void
1318maybe_seek_to_something_interesting (struct EXTRACTOR_PluginList *plugin, struct ebml_state *state) 1386maybe_seek_to_something_interesting (struct EXTRACTOR_PluginList *plugin, struct
1387 ebml_state *state)
1319{ 1388{
1320 int64_t offset; 1389 int64_t offset;
1321 struct matroska_seek_list *el; 1390 struct matroska_seek_list *el;
@@ -1350,12 +1419,14 @@ maybe_seek_to_something_interesting (struct EXTRACTOR_PluginList *plugin, struct
1350 * the one we've got from seek table. If it doesn't match - stop parsing the file. 1419 * the one we've got from seek table. If it doesn't match - stop parsing the file.
1351 */ 1420 */
1352#if DEBUG_EBML 1421#if DEBUG_EBML
1353 printf ("Seeking from %llu to %llu\n", offset, el->position + state->segment_contents_start); 1422 printf ("Seeking from %llu to %llu\n", offset, el->position
1423 + state->segment_contents_start);
1354#endif 1424#endif
1355 pl_seek (plugin, el->position + state->segment_contents_start, SEEK_SET); 1425 pl_seek (plugin, el->position + state->segment_contents_start, SEEK_SET);
1356 } 1426 }
1357} 1427}
1358 1428
1429
1359static void 1430static void
1360sort_seeks (struct ebml_state *state) 1431sort_seeks (struct ebml_state *state)
1361{ 1432{
@@ -1363,7 +1434,7 @@ sort_seeks (struct ebml_state *state)
1363 int64_t position; 1434 int64_t position;
1364 struct matroska_seek_list *el; 1435 struct matroska_seek_list *el;
1365 char sorted = 0; 1436 char sorted = 0;
1366 while (!sorted) 1437 while (! sorted)
1367 { 1438 {
1368 sorted = 1; 1439 sorted = 1;
1369 for (el = state->matroska_seeks; el != NULL; el = el->next) 1440 for (el = state->matroska_seeks; el != NULL; el = el->next)
@@ -1386,7 +1457,8 @@ sort_seeks (struct ebml_state *state)
1386 1457
1387 1458
1388int 1459int
1389EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_MetaDataProcessor proc, void *proc_cls) 1460EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin,
1461 EXTRACTOR_MetaDataProcessor proc, void *proc_cls)
1390{ 1462{
1391 uint64_t offset = 0; 1463 uint64_t offset = 0;
1392 ssize_t read_result; 1464 ssize_t read_result;
@@ -1406,7 +1478,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1406 1478
1407 if (plugin == NULL) 1479 if (plugin == NULL)
1408 return 1; 1480 return 1;
1409 1481
1410 state = EXTRACTOR_ebml_init_state_method (); 1482 state = EXTRACTOR_ebml_init_state_method ();
1411 if (state == NULL) 1483 if (state == NULL)
1412 return 1; 1484 return 1;
@@ -1421,7 +1493,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1421 return EXTRACTOR_ebml_discard_state_method (state); 1493 return EXTRACTOR_ebml_discard_state_method (state);
1422 case EBML_LOOKING_FOR_HEADER: 1494 case EBML_LOOKING_FOR_HEADER:
1423 offset = pl_get_pos (plugin); 1495 offset = pl_get_pos (plugin);
1424 sint_value = pl_read (plugin, &data, 1024*1024); 1496 sint_value = pl_read (plugin, &data, 1024 * 1024);
1425 if (sint_value < 4) 1497 if (sint_value < 4)
1426 return EXTRACTOR_ebml_discard_state_method (state); 1498 return EXTRACTOR_ebml_discard_state_method (state);
1427 start = NULL; 1499 start = NULL;
@@ -1433,12 +1505,13 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1433 offset = pl_get_pos (plugin) - 3; 1505 offset = pl_get_pos (plugin) - 3;
1434 if (offset != pl_seek (plugin, offset, SEEK_SET)) 1506 if (offset != pl_seek (plugin, offset, SEEK_SET))
1435 return EXTRACTOR_ebml_discard_state_method (state); 1507 return EXTRACTOR_ebml_discard_state_method (state);
1436 sint_value = pl_read (plugin, &data, 1024*1024); 1508 sint_value = pl_read (plugin, &data, 1024 * 1024);
1437 if (sint_value < 4) 1509 if (sint_value < 4)
1438 return EXTRACTOR_ebml_discard_state_method (state); 1510 return EXTRACTOR_ebml_discard_state_method (state);
1439 } 1511 }
1440 } 1512 }
1441 if (offset + start - data != pl_seek (plugin, offset + start - data, SEEK_SET)) 1513 if (offset + start - data != pl_seek (plugin, offset + start - data,
1514 SEEK_SET))
1442 return EXTRACTOR_ebml_discard_state_method (state); 1515 return EXTRACTOR_ebml_discard_state_method (state);
1443 state->state = EBML_READING_HEADER; 1516 state->state = EBML_READING_HEADER;
1444 break; 1517 break;
@@ -1458,7 +1531,9 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1458 } 1531 }
1459 state->state = EBML_READ_ELEMENT; 1532 state->state = EBML_READ_ELEMENT;
1460 state->next_state = EBML_READING_HEADER_ELEMENTS; 1533 state->next_state = EBML_READING_HEADER_ELEMENTS;
1461 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_HEADER, EBML_BAD_STATE, EBML_FINISHED_READING_HEADER, EBML_BAD_STATE); 1534 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result,
1535 EBML_FINISHED_READING_HEADER, EBML_BAD_STATE,
1536 EBML_FINISHED_READING_HEADER, EBML_BAD_STATE);
1462 break; 1537 break;
1463 case EBML_READ_ELEMENT: 1538 case EBML_READ_ELEMENT:
1464#if DEBUG_EBML 1539#if DEBUG_EBML
@@ -1475,19 +1550,14 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1475 } 1550 }
1476 state->state = state->next_state; 1551 state->state = state->next_state;
1477 break; 1552 break;
1478 */ 1553 *//* while the following code crashes with SIGILL.
1479 /* while the following code crashes with SIGILL. 1554 *//*
1480 */
1481 /*
1482 read_result = elementRead (plugin, &eID, &eSize); 1555 read_result = elementRead (plugin, &eID, &eSize);
1483 state->state = state->next_state; 1556 state->state = state->next_state;
1484 if (read_result < 0) 1557 if (read_result < 0)
1485 state->state = EBML_BAD_STATE; 1558 state->state = EBML_BAD_STATE;
1486 break; 1559 break;
1487 */ 1560 *//* but the following code works as intended *//* All three code snippets were compiled with -O0 */{
1488 /* but the following code works as intended */
1489 /* All three code snippets were compiled with -O0 */
1490 {
1491 enum EBMLState next_state = state->next_state; 1561 enum EBMLState next_state = state->next_state;
1492 state->state = EBML_BAD_STATE; 1562 state->state = EBML_BAD_STATE;
1493 read_result = elementRead (plugin, &eID, (int64_t*) &eSize); 1563 read_result = elementRead (plugin, &eID, (int64_t*) &eSize);
@@ -1506,7 +1576,8 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1506 read_result = 0; 1576 read_result = 0;
1507 else 1577 else
1508 { 1578 {
1509 if (0 > (read_result = uintRead (plugin, state->stack_top->size, &uint_value))) 1579 if (0 > (read_result = uintRead (plugin, state->stack_top->size,
1580 &uint_value)))
1510 { 1581 {
1511 state->state = EBML_BAD_STATE; 1582 state->state = EBML_BAD_STATE;
1512 break; 1583 break;
@@ -1516,7 +1587,8 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1516 state->state = state->next_state; 1587 state->state = state->next_state;
1517 break; 1588 break;
1518 case EBML_READ_ID: 1589 case EBML_READ_ID:
1519 if (0 > (read_result = idRead (plugin, state->stack_top->size, &id_value))) 1590 if (0 > (read_result = idRead (plugin, state->stack_top->size,
1591 &id_value)))
1520 { 1592 {
1521 state->state = EBML_BAD_STATE; 1593 state->state = EBML_BAD_STATE;
1522 break; 1594 break;
@@ -1534,7 +1606,8 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1534 read_result = 0; 1606 read_result = 0;
1535 else 1607 else
1536 { 1608 {
1537 if (0 > (read_result = sintRead (plugin, state->stack_top->size, &sint_value))) 1609 if (0 > (read_result = sintRead (plugin, state->stack_top->size,
1610 &sint_value)))
1538 { 1611 {
1539 state->state = EBML_BAD_STATE; 1612 state->state = EBML_BAD_STATE;
1540 break; 1613 break;
@@ -1554,7 +1627,8 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1554 read_result = 0; 1627 read_result = 0;
1555 else 1628 else
1556 { 1629 {
1557 if (0 > (read_result = floatRead (plugin, state->stack_top->size, &float_value))) 1630 if (0 > (read_result = floatRead (plugin, state->stack_top->size,
1631 &float_value)))
1558 { 1632 {
1559 state->state = EBML_BAD_STATE; 1633 state->state = EBML_BAD_STATE;
1560 break; 1634 break;
@@ -1571,7 +1645,8 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1571 } 1645 }
1572 else 1646 else
1573 { 1647 {
1574 if (0 > (read_result = stringRead (plugin, state->stack_top->size, (char *) &string_value))) 1648 if (0 > (read_result = stringRead (plugin, state->stack_top->size,
1649 (char *) &string_value)))
1575 { 1650 {
1576 state->state = EBML_BAD_STATE; 1651 state->state = EBML_BAD_STATE;
1577 break; 1652 break;
@@ -1581,7 +1656,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1581 state->state = state->next_state; 1656 state->state = state->next_state;
1582 break; 1657 break;
1583 case EBML_READING_HEADER_ELEMENTS: 1658 case EBML_READING_HEADER_ELEMENTS:
1584 if (!check_result (plugin, read_result, state)) 1659 if (! check_result (plugin, read_result, state))
1585 break; 1660 break;
1586 do_break = 0; 1661 do_break = 0;
1587 switch (eID) 1662 switch (eID)
@@ -1609,10 +1684,13 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1609 if (do_break) 1684 if (do_break)
1610 break; 1685 break;
1611 state->next_state = EBML_READING_HEADER_ELEMENT_VALUE; 1686 state->next_state = EBML_READING_HEADER_ELEMENT_VALUE;
1612 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_BAD_STATE, EBML_READING_HEADER_ELEMENTS, EBML_READ_ELEMENT, EBML_READING_HEADER_ELEMENTS); 1687 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result,
1688 EBML_BAD_STATE, EBML_READING_HEADER_ELEMENTS,
1689 EBML_READ_ELEMENT,
1690 EBML_READING_HEADER_ELEMENTS);
1613 break; 1691 break;
1614 case EBML_READING_HEADER_ELEMENT_VALUE: 1692 case EBML_READING_HEADER_ELEMENT_VALUE:
1615 if (!check_result (plugin, read_result, state)) 1693 if (! check_result (plugin, read_result, state))
1616 break; 1694 break;
1617 1695
1618 switch (state->stack_top->id) 1696 switch (state->stack_top->id)
@@ -1632,8 +1710,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1632 * We also stop right here and do not assume that somewhere further 1710 * We also stop right here and do not assume that somewhere further
1633 * in the file there's another EBML header that is, maybe, readable 1711 * in the file there's another EBML header that is, maybe, readable
1634 * by us. If you think this is worth correcting - patches are welcome. 1712 * by us. If you think this is worth correcting - patches are welcome.
1635 */ 1713 */continue;
1636 continue;
1637 } 1714 }
1638 break; 1715 break;
1639 case EBMLID_MAX_ID_LENGTH: 1716 case EBMLID_MAX_ID_LENGTH:
@@ -1658,7 +1735,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1658 rise_up_after_value (plugin, state, EBML_READING_HEADER_ELEMENTS); 1735 rise_up_after_value (plugin, state, EBML_READING_HEADER_ELEMENTS);
1659 break; 1736 break;
1660 case EBML_FINISHED_READING_HEADER: 1737 case EBML_FINISHED_READING_HEADER:
1661 if (!state->valid_ebml) 1738 if (! state->valid_ebml)
1662 { 1739 {
1663 /* Header was invalid (lacking doctype). */ 1740 /* Header was invalid (lacking doctype). */
1664 state->next_state = EBML_SKIP_UNTIL_NEXT_HEADER; 1741 state->next_state = EBML_SKIP_UNTIL_NEXT_HEADER;
@@ -1680,8 +1757,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1680 * metadata from it!), we do not care about these differences 1757 * metadata from it!), we do not care about these differences
1681 * (which means that this code will happily read webm files that do 1758 * (which means that this code will happily read webm files that do
1682 * not conform to Webm spec, but conform to Matroska spec). 1759 * not conform to Webm spec, but conform to Matroska spec).
1683 */ 1760 */state->next_state = EBML_READING_MATROSKA_SEGMENT;
1684 state->next_state = EBML_READING_MATROSKA_SEGMENT;
1685 } 1761 }
1686 else 1762 else
1687 { 1763 {
@@ -1727,11 +1803,14 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1727 state->state = EBML_READ_ELEMENT; 1803 state->state = EBML_READ_ELEMENT;
1728 state->next_state = EBML_READING_MATROSKA_SEGMENT_CONTENTS; 1804 state->next_state = EBML_READING_MATROSKA_SEGMENT_CONTENTS;
1729 clean_ebml_state_matroska_segment (state); 1805 clean_ebml_state_matroska_segment (state);
1730 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_SEGMENT_CONTENTS, EBML_READING_MATROSKA_SEGMENT, EBML_READ_ELEMENT, EBML_READING_MATROSKA_SEGMENT); 1806 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result,
1807 EBML_FINISHED_READING_MATROSKA_SEGMENT_CONTENTS,
1808 EBML_READING_MATROSKA_SEGMENT, EBML_READ_ELEMENT,
1809 EBML_READING_MATROSKA_SEGMENT);
1731 state->segment_contents_start = pl_get_pos (plugin); 1810 state->segment_contents_start = pl_get_pos (plugin);
1732 break; 1811 break;
1733 case EBML_READING_MATROSKA_SEGMENT_CONTENTS: 1812 case EBML_READING_MATROSKA_SEGMENT_CONTENTS:
1734 if (!check_result (plugin, read_result, state)) 1813 if (! check_result (plugin, read_result, state))
1735 break; 1814 break;
1736 1815
1737 state->state = EBML_READ_ELEMENT; 1816 state->state = EBML_READ_ELEMENT;
@@ -1739,20 +1818,40 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1739 { 1818 {
1740 case MatroskaID_SeekHead: 1819 case MatroskaID_SeekHead:
1741 state->next_state = EBML_READING_MATROSKA_SEEK_HEAD_CONTENTS; 1820 state->next_state = EBML_READING_MATROSKA_SEEK_HEAD_CONTENTS;
1742 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_SEEK_HEAD_CONTENTS, EBML_READING_MATROSKA_SEGMENT_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_SEGMENT_CONTENTS); 1821 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize,
1822 read_result,
1823 EBML_FINISHED_READING_MATROSKA_SEEK_HEAD_CONTENTS,
1824 EBML_READING_MATROSKA_SEGMENT_CONTENTS,
1825 EBML_READ_ELEMENT,
1826 EBML_READING_MATROSKA_SEGMENT_CONTENTS);
1743 break; 1827 break;
1744 case MatroskaID_Info: 1828 case MatroskaID_Info:
1745 state->next_state = EBML_READING_MATROSKA_INFO_CONTENTS; 1829 state->next_state = EBML_READING_MATROSKA_INFO_CONTENTS;
1746 clean_ebml_state_matroska_info (state); 1830 clean_ebml_state_matroska_info (state);
1747 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_INFO_CONTENTS, EBML_READING_MATROSKA_SEGMENT_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_SEGMENT_CONTENTS); 1831 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize,
1832 read_result,
1833 EBML_FINISHED_READING_MATROSKA_INFO_CONTENTS,
1834 EBML_READING_MATROSKA_SEGMENT_CONTENTS,
1835 EBML_READ_ELEMENT,
1836 EBML_READING_MATROSKA_SEGMENT_CONTENTS);
1748 break; 1837 break;
1749 case MatroskaID_Tracks: 1838 case MatroskaID_Tracks:
1750 state->next_state = EBML_READING_MATROSKA_TRACKS_CONTENTS; 1839 state->next_state = EBML_READING_MATROSKA_TRACKS_CONTENTS;
1751 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_TRACKS_CONTENTS, EBML_READING_MATROSKA_SEGMENT_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_SEGMENT_CONTENTS); 1840 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize,
1841 read_result,
1842 EBML_FINISHED_READING_MATROSKA_TRACKS_CONTENTS,
1843 EBML_READING_MATROSKA_SEGMENT_CONTENTS,
1844 EBML_READ_ELEMENT,
1845 EBML_READING_MATROSKA_SEGMENT_CONTENTS);
1752 break; 1846 break;
1753 case MatroskaID_Tags: 1847 case MatroskaID_Tags:
1754 state->next_state = EBML_READING_MATROSKA_TAGS_CONTENTS; 1848 state->next_state = EBML_READING_MATROSKA_TAGS_CONTENTS;
1755 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_TAGS_CONTENTS, EBML_READING_MATROSKA_SEGMENT_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_SEGMENT_CONTENTS); 1849 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize,
1850 read_result,
1851 EBML_FINISHED_READING_MATROSKA_TAGS_CONTENTS,
1852 EBML_READING_MATROSKA_SEGMENT_CONTENTS,
1853 EBML_READ_ELEMENT,
1854 EBML_READING_MATROSKA_SEGMENT_CONTENTS);
1756 break; 1855 break;
1757 default: 1856 default:
1758 if (maybe_rise_up (plugin, state, &do_break, read_result)) 1857 if (maybe_rise_up (plugin, state, &do_break, read_result))
@@ -1763,7 +1862,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1763 } 1862 }
1764 break; 1863 break;
1765 case EBML_READING_MATROSKA_TAGS_CONTENTS: 1864 case EBML_READING_MATROSKA_TAGS_CONTENTS:
1766 if (!check_result (plugin, read_result, state)) 1865 if (! check_result (plugin, read_result, state))
1767 break; 1866 break;
1768 state->state = EBML_READ_ELEMENT; 1867 state->state = EBML_READ_ELEMENT;
1769 switch (eID) 1868 switch (eID)
@@ -1771,7 +1870,12 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1771 case MatroskaID_Tags_Tag: 1870 case MatroskaID_Tags_Tag:
1772 state->next_state = EBML_READING_MATROSKA_TAG_CONTENTS; 1871 state->next_state = EBML_READING_MATROSKA_TAG_CONTENTS;
1773 clean_ebml_state_matroska_seek (state); 1872 clean_ebml_state_matroska_seek (state);
1774 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_TAG_CONTENTS, EBML_READING_MATROSKA_TAGS_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_TAGS_CONTENTS); 1873 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize,
1874 read_result,
1875 EBML_FINISHED_READING_MATROSKA_TAG_CONTENTS,
1876 EBML_READING_MATROSKA_TAGS_CONTENTS,
1877 EBML_READ_ELEMENT,
1878 EBML_READING_MATROSKA_TAGS_CONTENTS);
1775 break; 1879 break;
1776 default: 1880 default:
1777 if (maybe_rise_up (plugin, state, &do_break, read_result)) 1881 if (maybe_rise_up (plugin, state, &do_break, read_result))
@@ -1781,7 +1885,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1781 } 1885 }
1782 break; 1886 break;
1783 case EBML_READING_MATROSKA_TAG_CONTENTS: 1887 case EBML_READING_MATROSKA_TAG_CONTENTS:
1784 if (!check_result (plugin, read_result, state)) 1888 if (! check_result (plugin, read_result, state))
1785 break; 1889 break;
1786 1890
1787 state->state = EBML_READ_ELEMENT; 1891 state->state = EBML_READ_ELEMENT;
@@ -1793,7 +1897,12 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1793 matroska_add_tag (state, NULL, NULL, NULL); 1897 matroska_add_tag (state, NULL, NULL, NULL);
1794 state->tag_current = state->tag_last; 1898 state->tag_current = state->tag_last;
1795 state->tag_tree = state->tag_current; 1899 state->tag_tree = state->tag_current;
1796 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_SIMPLETAG_CONTENTS, EBML_READING_MATROSKA_TAG_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_TAG_CONTENTS); 1900 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize,
1901 read_result,
1902 EBML_FINISHED_READING_MATROSKA_SIMPLETAG_CONTENTS,
1903 EBML_READING_MATROSKA_TAG_CONTENTS,
1904 EBML_READ_ELEMENT,
1905 EBML_READING_MATROSKA_TAG_CONTENTS);
1797 break; 1906 break;
1798 default: 1907 default:
1799 if (maybe_rise_up (plugin, state, &do_break, read_result)) 1908 if (maybe_rise_up (plugin, state, &do_break, read_result))
@@ -1803,7 +1912,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1803 } 1912 }
1804 break; 1913 break;
1805 case EBML_READING_MATROSKA_SIMPLETAG_CONTENTS: 1914 case EBML_READING_MATROSKA_SIMPLETAG_CONTENTS:
1806 if (!check_result (plugin, read_result, state)) 1915 if (! check_result (plugin, read_result, state))
1807 break; 1916 break;
1808 1917
1809 do_break = 0; 1918 do_break = 0;
@@ -1823,7 +1932,12 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1823 state->next_state = EBML_READING_MATROSKA_SIMPLETAG_CONTENTS; 1932 state->next_state = EBML_READING_MATROSKA_SIMPLETAG_CONTENTS;
1824 matroska_add_tag (state, state->tag_current, NULL, NULL); 1933 matroska_add_tag (state, state->tag_current, NULL, NULL);
1825 state->tag_current = state->tag_last; 1934 state->tag_current = state->tag_last;
1826 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_SIMPLETAG_CONTENTS, EBML_READING_MATROSKA_SIMPLETAG_CONTENTS, EBML_READ_ELEMENT, EBML_FINISHED_READING_MATROSKA_SIMPLETAG_CONTENTS); 1935 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize,
1936 read_result,
1937 EBML_FINISHED_READING_MATROSKA_SIMPLETAG_CONTENTS,
1938 EBML_READING_MATROSKA_SIMPLETAG_CONTENTS,
1939 EBML_READ_ELEMENT,
1940 EBML_FINISHED_READING_MATROSKA_SIMPLETAG_CONTENTS);
1827 do_break = 1; 1941 do_break = 1;
1828 break; 1942 break;
1829 default: 1943 default:
@@ -1838,10 +1952,14 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1838 if (do_break) 1952 if (do_break)
1839 break; 1953 break;
1840 state->next_state = EBML_READING_MATROSKA_SIMPLETAG_CONTENTS_VALUE; 1954 state->next_state = EBML_READING_MATROSKA_SIMPLETAG_CONTENTS_VALUE;
1841 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_BAD_STATE, EBML_READING_MATROSKA_SIMPLETAG_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_SIMPLETAG_CONTENTS); 1955 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result,
1956 EBML_BAD_STATE,
1957 EBML_READING_MATROSKA_SIMPLETAG_CONTENTS,
1958 EBML_READ_ELEMENT,
1959 EBML_READING_MATROSKA_SIMPLETAG_CONTENTS);
1842 break; 1960 break;
1843 case EBML_READING_MATROSKA_SIMPLETAG_CONTENTS_VALUE: 1961 case EBML_READING_MATROSKA_SIMPLETAG_CONTENTS_VALUE:
1844 if (!check_result (plugin, read_result, state)) 1962 if (! check_result (plugin, read_result, state))
1845 break; 1963 break;
1846 1964
1847 /* This breaks the specs, as there should be only one instance of each 1965 /* This breaks the specs, as there should be only one instance of each
@@ -1861,10 +1979,11 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1861 state->tag_current->string = strdup (string_value); 1979 state->tag_current->string = strdup (string_value);
1862 break; 1980 break;
1863 } 1981 }
1864 rise_up_after_value (plugin, state, EBML_READING_MATROSKA_SIMPLETAG_CONTENTS); 1982 rise_up_after_value (plugin, state,
1983 EBML_READING_MATROSKA_SIMPLETAG_CONTENTS);
1865 break; 1984 break;
1866 case EBML_READING_MATROSKA_SEEK_HEAD_CONTENTS: 1985 case EBML_READING_MATROSKA_SEEK_HEAD_CONTENTS:
1867 if (!check_result (plugin, read_result, state)) 1986 if (! check_result (plugin, read_result, state))
1868 break; 1987 break;
1869 1988
1870 state->state = EBML_READ_ELEMENT; 1989 state->state = EBML_READ_ELEMENT;
@@ -1873,7 +1992,12 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1873 case MatroskaID_Seek: 1992 case MatroskaID_Seek:
1874 state->next_state = EBML_READING_MATROSKA_SEEK_CONTENTS; 1993 state->next_state = EBML_READING_MATROSKA_SEEK_CONTENTS;
1875 clean_ebml_state_matroska_seek (state); 1994 clean_ebml_state_matroska_seek (state);
1876 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_SEEK_CONTENTS, EBML_READING_MATROSKA_SEEK_HEAD_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_SEEK_HEAD_CONTENTS); 1995 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize,
1996 read_result,
1997 EBML_FINISHED_READING_MATROSKA_SEEK_CONTENTS,
1998 EBML_READING_MATROSKA_SEEK_HEAD_CONTENTS,
1999 EBML_READ_ELEMENT,
2000 EBML_READING_MATROSKA_SEEK_HEAD_CONTENTS);
1877 break; 2001 break;
1878 default: 2002 default:
1879 if (maybe_rise_up (plugin, state, &do_break, read_result)) 2003 if (maybe_rise_up (plugin, state, &do_break, read_result))
@@ -1883,7 +2007,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1883 } 2007 }
1884 break; 2008 break;
1885 case EBML_READING_MATROSKA_SEEK_CONTENTS: 2009 case EBML_READING_MATROSKA_SEEK_CONTENTS:
1886 if (!check_result (plugin, read_result, state)) 2010 if (! check_result (plugin, read_result, state))
1887 break; 2011 break;
1888 2012
1889 do_break = 0; 2013 do_break = 0;
@@ -1907,10 +2031,13 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1907 if (do_break) 2031 if (do_break)
1908 break; 2032 break;
1909 state->next_state = EBML_READING_MATROSKA_SEEK_CONTENTS_VALUE; 2033 state->next_state = EBML_READING_MATROSKA_SEEK_CONTENTS_VALUE;
1910 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_BAD_STATE, EBML_READING_MATROSKA_SEEK_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_SEEK_CONTENTS); 2034 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result,
2035 EBML_BAD_STATE, EBML_READING_MATROSKA_SEEK_CONTENTS,
2036 EBML_READ_ELEMENT,
2037 EBML_READING_MATROSKA_SEEK_CONTENTS);
1911 break; 2038 break;
1912 case EBML_READING_MATROSKA_SEEK_CONTENTS_VALUE: 2039 case EBML_READING_MATROSKA_SEEK_CONTENTS_VALUE:
1913 if (!check_result (plugin, read_result, state)) 2040 if (! check_result (plugin, read_result, state))
1914 break; 2041 break;
1915 2042
1916 /* This breaks the specs, as there should be only one instance of each 2043 /* This breaks the specs, as there should be only one instance of each
@@ -1929,7 +2056,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1929 rise_up_after_value (plugin, state, EBML_READING_MATROSKA_SEEK_CONTENTS); 2056 rise_up_after_value (plugin, state, EBML_READING_MATROSKA_SEEK_CONTENTS);
1930 break; 2057 break;
1931 case EBML_READING_MATROSKA_TRACKS_CONTENTS: 2058 case EBML_READING_MATROSKA_TRACKS_CONTENTS:
1932 if (!check_result (plugin, read_result, state)) 2059 if (! check_result (plugin, read_result, state))
1933 break; 2060 break;
1934 2061
1935 state->state = EBML_READ_ELEMENT; 2062 state->state = EBML_READ_ELEMENT;
@@ -1938,7 +2065,12 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1938 case MatroskaID_Tracks_TrackEntry: 2065 case MatroskaID_Tracks_TrackEntry:
1939 state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS; 2066 state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS;
1940 clean_ebml_state_matroska_track (state); 2067 clean_ebml_state_matroska_track (state);
1941 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_TRACK_ENTRY_CONTENTS, EBML_READING_MATROSKA_TRACKS_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_TRACKS_CONTENTS); 2068 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize,
2069 read_result,
2070 EBML_FINISHED_READING_MATROSKA_TRACK_ENTRY_CONTENTS,
2071 EBML_READING_MATROSKA_TRACKS_CONTENTS,
2072 EBML_READ_ELEMENT,
2073 EBML_READING_MATROSKA_TRACKS_CONTENTS);
1942 break; 2074 break;
1943 default: 2075 default:
1944 if (maybe_rise_up (plugin, state, &do_break, read_result)) 2076 if (maybe_rise_up (plugin, state, &do_break, read_result))
@@ -1948,7 +2080,7 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1948 } 2080 }
1949 break; 2081 break;
1950 case EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS: 2082 case EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS:
1951 if (!check_result (plugin, read_result, state)) 2083 if (! check_result (plugin, read_result, state))
1952 break; 2084 break;
1953 2085
1954 do_break = 0; 2086 do_break = 0;
@@ -1967,14 +2099,24 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1967 state->state = EBML_READ_ELEMENT; 2099 state->state = EBML_READ_ELEMENT;
1968 state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS; 2100 state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS;
1969 clean_ebml_state_matroska_track_video (state); 2101 clean_ebml_state_matroska_track_video (state);
1970 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS, EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS); 2102 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize,
2103 read_result,
2104 EBML_FINISHED_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS,
2105 EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS,
2106 EBML_READ_ELEMENT,
2107 EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS);
1971 do_break = 1; 2108 do_break = 1;
1972 break; 2109 break;
1973 case MatroskaID_Tracks_Audio: 2110 case MatroskaID_Tracks_Audio:
1974 state->state = EBML_READ_ELEMENT; 2111 state->state = EBML_READ_ELEMENT;
1975 state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS; 2112 state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS;
1976 clean_ebml_state_matroska_track_audio (state); 2113 clean_ebml_state_matroska_track_audio (state);
1977 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_FINISHED_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS, EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS); 2114 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize,
2115 read_result,
2116 EBML_FINISHED_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS,
2117 EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS,
2118 EBML_READ_ELEMENT,
2119 EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS);
1978 do_break = 1; 2120 do_break = 1;
1979 break; 2121 break;
1980 default: 2122 default:
@@ -1989,10 +2131,14 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
1989 if (do_break) 2131 if (do_break)
1990 break; 2132 break;
1991 state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS_VALUE; 2133 state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS_VALUE;
1992 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_BAD_STATE, EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS); 2134 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result,
2135 EBML_BAD_STATE,
2136 EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS,
2137 EBML_READ_ELEMENT,
2138 EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS);
1993 break; 2139 break;
1994 case EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS: 2140 case EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS:
1995 if (!check_result (plugin, read_result, state)) 2141 if (! check_result (plugin, read_result, state))
1996 break; 2142 break;
1997 2143
1998 do_break = 0; 2144 do_break = 0;
@@ -2017,11 +2163,16 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
2017 } 2163 }
2018 if (do_break) 2164 if (do_break)
2019 break; 2165 break;
2020 state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS_VALUE; 2166 state->next_state =
2021 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_BAD_STATE, EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS); 2167 EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS_VALUE;
2168 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result,
2169 EBML_BAD_STATE,
2170 EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS,
2171 EBML_READ_ELEMENT,
2172 EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS);
2022 break; 2173 break;
2023 case EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS_VALUE: 2174 case EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS_VALUE:
2024 if (!check_result (plugin, read_result, state)) 2175 if (! check_result (plugin, read_result, state))
2025 break; 2176 break;
2026 2177
2027 /* This breaks the specs, as there should be only one instance of each 2178 /* This breaks the specs, as there should be only one instance of each
@@ -2043,10 +2194,11 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
2043 state->matroska_track_audio_bit_depth = uint_value; 2194 state->matroska_track_audio_bit_depth = uint_value;
2044 break; 2195 break;
2045 } 2196 }
2046 rise_up_after_value (plugin, state, EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS); 2197 rise_up_after_value (plugin, state,
2198 EBML_READING_MATROSKA_TRACK_ENTRY_AUDIO_CONTENTS);
2047 break; 2199 break;
2048 case EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS: 2200 case EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS:
2049 if (!check_result (plugin, read_result, state)) 2201 if (! check_result (plugin, read_result, state))
2050 break; 2202 break;
2051 2203
2052 do_break = 0; 2204 do_break = 0;
@@ -2072,11 +2224,16 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
2072 } 2224 }
2073 if (do_break) 2225 if (do_break)
2074 break; 2226 break;
2075 state->next_state = EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS_VALUE; 2227 state->next_state =
2076 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_BAD_STATE, EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS); 2228 EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS_VALUE;
2229 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result,
2230 EBML_BAD_STATE,
2231 EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS,
2232 EBML_READ_ELEMENT,
2233 EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS);
2077 break; 2234 break;
2078 case EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS_VALUE: 2235 case EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS_VALUE:
2079 if (!check_result (plugin, read_result, state)) 2236 if (! check_result (plugin, read_result, state))
2080 break; 2237 break;
2081 2238
2082 /* This breaks the specs, as there should be only one instance of each 2239 /* This breaks the specs, as there should be only one instance of each
@@ -2107,10 +2264,11 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
2107 state->matroska_track_video_display_unit = uint_value; 2264 state->matroska_track_video_display_unit = uint_value;
2108 break; 2265 break;
2109 } 2266 }
2110 rise_up_after_value (plugin, state, EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS); 2267 rise_up_after_value (plugin, state,
2268 EBML_READING_MATROSKA_TRACK_ENTRY_VIDEO_CONTENTS);
2111 break; 2269 break;
2112 case EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS_VALUE: 2270 case EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS_VALUE:
2113 if (!check_result (plugin, read_result, state)) 2271 if (! check_result (plugin, read_result, state))
2114 break; 2272 break;
2115 2273
2116 /* This breaks the specs, as there should be only one instance of each 2274 /* This breaks the specs, as there should be only one instance of each
@@ -2143,10 +2301,11 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
2143 state->matroska_track_codec_name = strdup (string_value); 2301 state->matroska_track_codec_name = strdup (string_value);
2144 break; /* UTF-8-encoded. A human-readable string specifying the codec. */ 2302 break; /* UTF-8-encoded. A human-readable string specifying the codec. */
2145 } 2303 }
2146 rise_up_after_value (plugin, state, EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS); 2304 rise_up_after_value (plugin, state,
2305 EBML_READING_MATROSKA_TRACK_ENTRY_CONTENTS);
2147 break; 2306 break;
2148 case EBML_READING_MATROSKA_INFO_CONTENTS: 2307 case EBML_READING_MATROSKA_INFO_CONTENTS:
2149 if (!check_result (plugin, read_result, state)) 2308 if (! check_result (plugin, read_result, state))
2150 break; 2309 break;
2151 2310
2152 do_break = 0; 2311 do_break = 0;
@@ -2178,10 +2337,13 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
2178 if (do_break) 2337 if (do_break)
2179 break; 2338 break;
2180 state->next_state = EBML_READING_MATROSKA_INFO_CONTENTS_VALUE; 2339 state->next_state = EBML_READING_MATROSKA_INFO_CONTENTS_VALUE;
2181 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result, EBML_BAD_STATE, EBML_READING_MATROSKA_INFO_CONTENTS, EBML_READ_ELEMENT, EBML_READING_MATROSKA_INFO_CONTENTS); 2340 ebml_stack_push_new (state, pl_get_pos (plugin), eID, eSize, read_result,
2341 EBML_BAD_STATE, EBML_READING_MATROSKA_INFO_CONTENTS,
2342 EBML_READ_ELEMENT,
2343 EBML_READING_MATROSKA_INFO_CONTENTS);
2182 break; 2344 break;
2183 case EBML_READING_MATROSKA_INFO_CONTENTS_VALUE: 2345 case EBML_READING_MATROSKA_INFO_CONTENTS_VALUE:
2184 if (!check_result (plugin, read_result, state)) 2346 if (! check_result (plugin, read_result, state))
2185 break; 2347 break;
2186 2348
2187 /* This breaks the specs, as there should be only one instance of each 2349 /* This breaks the specs, as there should be only one instance of each
@@ -2219,7 +2381,10 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
2219 rise_up_after_value (plugin, state, EBML_READING_MATROSKA_INFO_CONTENTS); 2381 rise_up_after_value (plugin, state, EBML_READING_MATROSKA_INFO_CONTENTS);
2220 break; 2382 break;
2221 case EBML_FINISHED_READING_MATROSKA_INFO_CONTENTS: 2383 case EBML_FINISHED_READING_MATROSKA_INFO_CONTENTS:
2222 if (state->stack_top != NULL && pl_get_pos (plugin) >= state->stack_top->position + state->stack_top->header_size + state->stack_top->size) 2384 if ((state->stack_top != NULL) && (pl_get_pos (plugin) >=
2385 state->stack_top->position
2386 + state->stack_top->header_size
2387 + state->stack_top->size) )
2223 report_state (state, proc, proc_cls); 2388 report_state (state, proc, proc_cls);
2224 maybe_seek_to_something_interesting (plugin, state); 2389 maybe_seek_to_something_interesting (plugin, state);
2225 state->state = EBML_READ_ELEMENT; 2390 state->state = EBML_READ_ELEMENT;
@@ -2227,7 +2392,10 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
2227 free (ebml_stack_pop (state)); 2392 free (ebml_stack_pop (state));
2228 break; 2393 break;
2229 case EBML_FINISHED_READING_MATROSKA_TRACK_ENTRY_CONTENTS: 2394 case EBML_FINISHED_READING_MATROSKA_TRACK_ENTRY_CONTENTS:
2230 if (state->stack_top != NULL && pl_get_pos (plugin) >= state->stack_top->position + state->stack_top->header_size + state->stack_top->size) 2395 if ((state->stack_top != NULL) && (pl_get_pos (plugin) >=
2396 state->stack_top->position
2397 + state->stack_top->header_size
2398 + state->stack_top->size) )
2231 report_state (state, proc, proc_cls); 2399 report_state (state, proc, proc_cls);
2232 state->state = EBML_READ_ELEMENT; 2400 state->state = EBML_READ_ELEMENT;
2233 state->next_state = state->stack_top->prev_state; 2401 state->next_state = state->stack_top->prev_state;
@@ -2235,7 +2403,8 @@ EXTRACTOR_ebml_extract_method (struct EXTRACTOR_PluginList *plugin, EXTRACTOR_Me
2235 break; 2403 break;
2236 case EBML_FINISHED_READING_MATROSKA_SEEK_CONTENTS: 2404 case EBML_FINISHED_READING_MATROSKA_SEEK_CONTENTS:
2237 if ((state->matroska_seek_id != 0) && 2405 if ((state->matroska_seek_id != 0) &&
2238 ((state->matroska_seek_position > 0) || state->matroska_seeks_tail == NULL)) 2406 ((state->matroska_seek_position > 0) || (state->matroska_seeks_tail ==
2407 NULL) ))
2239 { 2408 {
2240 struct matroska_seek_list *el; 2409 struct matroska_seek_list *el;
2241 el = malloc (sizeof (struct matroska_seek_list)); 2410 el = malloc (sizeof (struct matroska_seek_list));
diff --git a/src/plugins/old/elf_extractor.c b/src/plugins/old/elf_extractor.c
index 0a14736..9c35e7c 100644
--- a/src/plugins/old/elf_extractor.c
+++ b/src/plugins/old/elf_extractor.c
@@ -26,7 +26,7 @@
26typedef uint32_t Elf32_Addr; 26typedef uint32_t Elf32_Addr;
27typedef uint16_t Elf32_Half; 27typedef uint16_t Elf32_Half;
28typedef uint32_t Elf32_Off; 28typedef uint32_t Elf32_Off;
29typedef int32_t Elf32_Sword; 29typedef int32_t Elf32_Sword;
30typedef uint32_t Elf32_Word; 30typedef uint32_t Elf32_Word;
31 31
32typedef uint16_t Elf64_Half; 32typedef uint16_t Elf64_Half;
@@ -64,57 +64,58 @@ typedef struct
64#define ELF_HEADER_SIZE sizeof (Elf32_Ehdr) 64#define ELF_HEADER_SIZE sizeof (Elf32_Ehdr)
65 65
66#define ELF_HEADER_FIELDS(p) \ 66#define ELF_HEADER_FIELDS(p) \
67 &(p)->e_type, \ 67 & (p)->e_type, \
68 &(p)->e_machine, \ 68 &(p)->e_machine, \
69 &(p)->e_version, \ 69 &(p)->e_version, \
70 &(p)->e_entry, \ 70 &(p)->e_entry, \
71 &(p)->e_phoff, \ 71 &(p)->e_phoff, \
72 &(p)->e_shoff, \ 72 &(p)->e_shoff, \
73 &(p)->e_flags, \ 73 &(p)->e_flags, \
74 &(p)->e_ehsize, \ 74 &(p)->e_ehsize, \
75 &(p)->e_phensize, \ 75 &(p)->e_phensize, \
76 &(p)->e_phnum, \ 76 &(p)->e_phnum, \
77 &(p)->e_shentsize, \ 77 &(p)->e_shentsize, \
78 &(p)->e_shnum, \ 78 &(p)->e_shnum, \
79 &(p)->e_shstrndx 79 &(p)->e_shstrndx
80static char *ELF_HEADER_SPECS[] = { 80static char *ELF_HEADER_SPECS[] = {
81 "hhwwwwwhhhhhh", 81 "hhwwwwwhhhhhh",
82 "HHWWWWWHHHHHH", 82 "HHWWWWWHHHHHH",
83}; 83};
84 84
85typedef struct { 85typedef struct
86 Elf64_Half e_type; 86{
87 Elf64_Half e_machine; 87 Elf64_Half e_type;
88 Elf64_Word e_version; 88 Elf64_Half e_machine;
89 Elf64_Addr e_entry; 89 Elf64_Word e_version;
90 Elf64_Off e_phoff; 90 Elf64_Addr e_entry;
91 Elf64_Off e_shoff; 91 Elf64_Off e_phoff;
92 Elf64_Word e_flags; 92 Elf64_Off e_shoff;
93 Elf64_Half e_ehsize; 93 Elf64_Word e_flags;
94 Elf64_Half e_phensize; 94 Elf64_Half e_ehsize;
95 Elf64_Half e_phnum; 95 Elf64_Half e_phensize;
96 Elf64_Half e_shentsize; 96 Elf64_Half e_phnum;
97 Elf64_Half e_shnum; 97 Elf64_Half e_shentsize;
98 Elf64_Half e_shstrndx; 98 Elf64_Half e_shnum;
99 Elf64_Half e_shstrndx;
99} Elf64_Ehdr; 100} Elf64_Ehdr;
100 101
101/* elf-header minus e_ident */ 102/* elf-header minus e_ident */
102#define ELF64_HEADER_SIZE sizeof (Elf64_Ehdr) 103#define ELF64_HEADER_SIZE sizeof (Elf64_Ehdr)
103 104
104#define ELF64_HEADER_FIELDS(p) \ 105#define ELF64_HEADER_FIELDS(p) \
105 &(p)->e_type, \ 106 & (p)->e_type, \
106 &(p)->e_machine, \ 107 &(p)->e_machine, \
107 &(p)->e_version, \ 108 &(p)->e_version, \
108 &(p)->e_entry, \ 109 &(p)->e_entry, \
109 &(p)->e_phoff, \ 110 &(p)->e_phoff, \
110 &(p)->e_shoff, \ 111 &(p)->e_shoff, \
111 &(p)->e_flags, \ 112 &(p)->e_flags, \
112 &(p)->e_ehsize, \ 113 &(p)->e_ehsize, \
113 &(p)->e_phensize, \ 114 &(p)->e_phensize, \
114 &(p)->e_phnum, \ 115 &(p)->e_phnum, \
115 &(p)->e_shentsize, \ 116 &(p)->e_shentsize, \
116 &(p)->e_shnum, \ 117 &(p)->e_shnum, \
117 &(p)->e_shstrndx 118 &(p)->e_shstrndx
118static char *ELF64_HEADER_SPECS[] = { 119static char *ELF64_HEADER_SPECS[] = {
119 "hhwxxxwhhhhhh", 120 "hhwxxxwhhhhhh",
120 "HHWXXXWHHHHHH", 121 "HHWXXXWHHHHHH",
@@ -137,16 +138,16 @@ typedef struct
137#define ELF_SECTION_SIZE 40 138#define ELF_SECTION_SIZE 40
138 139
139#define ELF_SECTION_FIELDS(p) \ 140#define ELF_SECTION_FIELDS(p) \
140 &(p)->sh_name, \ 141 & (p)->sh_name, \
141 &(p)->sh_type, \ 142 &(p)->sh_type, \
142 &(p)->sh_flags, \ 143 &(p)->sh_flags, \
143 &(p)->sh_addr, \ 144 &(p)->sh_addr, \
144 &(p)->sh_offset, \ 145 &(p)->sh_offset, \
145 &(p)->sh_size, \ 146 &(p)->sh_size, \
146 &(p)->sh_link, \ 147 &(p)->sh_link, \
147 &(p)->sh_info, \ 148 &(p)->sh_info, \
148 &(p)->sh_addralign, \ 149 &(p)->sh_addralign, \
149 &(p)->sh_entsize 150 &(p)->sh_entsize
150static char *ELF_SECTION_SPECS[] = { 151static char *ELF_SECTION_SPECS[] = {
151 "wwwwwwwwww", 152 "wwwwwwwwww",
152 "WWWWWWWWWW", 153 "WWWWWWWWWW",
@@ -164,15 +165,15 @@ typedef struct
164 Elf32_Word p_align; 165 Elf32_Word p_align;
165} Elf32_Phdr; 166} Elf32_Phdr;
166#define ELF_PDHR_SIZE 32 167#define ELF_PDHR_SIZE 32
167#define ELF_PHDR_FIELDS(p) \ 168#define ELF_PHDR_FIELDS(p) \
168 &(p)->p_type, \ 169 & (p)->p_type, \
169 &(p)->p_offset, \ 170 &(p)->p_offset, \
170 &(p)->p_vaddr, \ 171 &(p)->p_vaddr, \
171 &(p)->p_paddr, \ 172 &(p)->p_paddr, \
172 &(p)->p_filesz, \ 173 &(p)->p_filesz, \
173 &(p)->p_memsz, \ 174 &(p)->p_memsz, \
174 &(p)->p_flags, \ 175 &(p)->p_flags, \
175 &(p)->p_align 176 &(p)->p_align
176static char *ELF_PHDR_SPECS[] = { 177static char *ELF_PHDR_SPECS[] = {
177 "wwwwwwww", 178 "wwwwwwww",
178 "WWWWWWWW", 179 "WWWWWWWW",
@@ -188,9 +189,9 @@ typedef struct
188 } d_un; 189 } d_un;
189} Elf32_Dyn; 190} Elf32_Dyn;
190#define ELF_DYN_SIZE 8 191#define ELF_DYN_SIZE 8
191#define ELF_DYN_FIELDS(p) \ 192#define ELF_DYN_FIELDS(p) \
192 &(p)->d_tag, \ 193 & (p)->d_tag, \
193 &(p)->d_un 194 &(p)->d_un
194static char *ELF_DYN_SPECS[] = { 195static char *ELF_DYN_SPECS[] = {
195 "ww", 196 "ww",
196 "WW", 197 "WW",
@@ -292,8 +293,6 @@ static char *ELF_DYN_SPECS[] = {
292#define PT_HIPROC 0x7fffffff 293#define PT_HIPROC 0x7fffffff
293 294
294 295
295
296
297#define ELFCLASSNONE 0 296#define ELFCLASSNONE 0
298#define ELFCLASS32 1 297#define ELFCLASS32 1
299#define ELFCLASS64 2 298#define ELFCLASS64 2
@@ -312,23 +311,24 @@ static int
312getByteorder (char ei_data) 311getByteorder (char ei_data)
313{ 312{
314 if (ei_data == ELFDATA2LSB) 313 if (ei_data == ELFDATA2LSB)
315 { 314 {
316#if __BYTE_ORDER == __BIG_ENDIAN 315#if __BYTE_ORDER == __BIG_ENDIAN
317 return 1; 316 return 1;
318#else 317#else
319 return 0; 318 return 0;
320#endif 319#endif
321 } 320 }
322 else 321 else
323 { 322 {
324#if __BYTE_ORDER == __BIG_ENDIAN 323#if __BYTE_ORDER == __BIG_ENDIAN
325 return 0; 324 return 0;
326#else 325#else
327 return 1; 326 return 1;
328#endif 327#endif
329 } 328 }
330} 329}
331 330
331
332/** 332/**
333 * 333 *
334 * @return 0 on success, -1 on error 334 * @return 0 on success, -1 on error
@@ -336,17 +336,18 @@ getByteorder (char ei_data)
336static int 336static int
337getSectionHdr (const char *data, 337getSectionHdr (const char *data,
338 size_t size, 338 size_t size,
339 Elf32_Ehdr * ehdr, Elf32_Half idx, Elf32_Shdr * ret) 339 Elf32_Ehdr *ehdr, Elf32_Half idx, Elf32_Shdr *ret)
340{ 340{
341 if (ehdr->e_shnum <= idx) 341 if (ehdr->e_shnum <= idx)
342 return -1; 342 return -1;
343 343
344 EXTRACTOR_common_cat_unpack (&data[ehdr->e_shoff + ehdr->e_shentsize * idx], 344 EXTRACTOR_common_cat_unpack (&data[ehdr->e_shoff + ehdr->e_shentsize * idx],
345 ELF_SECTION_SPECS[getByteorder (data[EI_CLASS])], 345 ELF_SECTION_SPECS[getByteorder (data[EI_CLASS])],
346 ELF_SECTION_FIELDS (ret)); 346 ELF_SECTION_FIELDS (ret));
347 return 0; 347 return 0;
348} 348}
349 349
350
350/** 351/**
351 * 352 *
352 * @return 0 on success, -1 on error 353 * @return 0 on success, -1 on error
@@ -354,17 +355,18 @@ getSectionHdr (const char *data,
354static int 355static int
355getDynTag (const char *data, 356getDynTag (const char *data,
356 size_t size, 357 size_t size,
357 Elf32_Ehdr * ehdr, 358 Elf32_Ehdr *ehdr,
358 Elf32_Off off, Elf32_Word osize, unsigned int idx, Elf32_Dyn * ret) 359 Elf32_Off off, Elf32_Word osize, unsigned int idx, Elf32_Dyn *ret)
359{ 360{
360 if ((off + osize > size) || ((idx + 1) * ELF_DYN_SIZE > osize)) 361 if ((off + osize > size) || ((idx + 1) * ELF_DYN_SIZE > osize))
361 return -1; 362 return -1;
362 EXTRACTOR_common_cat_unpack (&data[off + idx * ELF_DYN_SIZE], 363 EXTRACTOR_common_cat_unpack (&data[off + idx * ELF_DYN_SIZE],
363 ELF_DYN_SPECS[getByteorder (data[EI_CLASS])], 364 ELF_DYN_SPECS[getByteorder (data[EI_CLASS])],
364 ELF_DYN_FIELDS (ret)); 365 ELF_DYN_FIELDS (ret));
365 return 0; 366 return 0;
366} 367}
367 368
369
368/** 370/**
369 * 371 *
370 * @return 0 on success, -1 on error 372 * @return 0 on success, -1 on error
@@ -372,26 +374,27 @@ getDynTag (const char *data,
372static int 374static int
373getProgramHdr (const char *data, 375getProgramHdr (const char *data,
374 size_t size, 376 size_t size,
375 Elf32_Ehdr * ehdr, Elf32_Half idx, Elf32_Phdr * ret) 377 Elf32_Ehdr *ehdr, Elf32_Half idx, Elf32_Phdr *ret)
376{ 378{
377 if (ehdr->e_phnum <= idx) 379 if (ehdr->e_phnum <= idx)
378 return -1; 380 return -1;
379 381
380 EXTRACTOR_common_cat_unpack (&data[ehdr->e_phoff + ehdr->e_phensize * idx], 382 EXTRACTOR_common_cat_unpack (&data[ehdr->e_phoff + ehdr->e_phensize * idx],
381 ELF_PHDR_SPECS[getByteorder (data[EI_CLASS])], 383 ELF_PHDR_SPECS[getByteorder (data[EI_CLASS])],
382 ELF_PHDR_FIELDS (ret)); 384 ELF_PHDR_FIELDS (ret));
383 return 0; 385 return 0;
384} 386}
385 387
388
386/** 389/**
387 * Parse ELF header. 390 * Parse ELF header.
388 * @return 0 on success for 32 bit, 1 on success for 64 bit, -1 on error 391 * @return 0 on success for 32 bit, 1 on success for 64 bit, -1 on error
389 */ 392 */
390static int 393static int
391getELFHdr (const char *data, 394getELFHdr (const char *data,
392 size_t size, 395 size_t size,
393 Elf32_Ehdr * ehdr, 396 Elf32_Ehdr *ehdr,
394 Elf64_Ehdr * ehdr64) 397 Elf64_Ehdr *ehdr64)
395{ 398{
396 /* catlib */ 399 /* catlib */
397 if (size < EI_NIDENT) 400 if (size < EI_NIDENT)
@@ -400,43 +403,47 @@ getELFHdr (const char *data,
400 return -1; /* not an elf */ 403 return -1; /* not an elf */
401 404
402 switch (data[EI_CLASS]) 405 switch (data[EI_CLASS])
403 { 406 {
404 case ELFCLASS32: 407 case ELFCLASS32:
405 if (size < sizeof (Elf32_Ehdr) + EI_NIDENT) 408 if (size < sizeof (Elf32_Ehdr) + EI_NIDENT)
406 return -1;
407 EXTRACTOR_common_cat_unpack (&data[EI_NIDENT],
408 ELF_HEADER_SPECS[getByteorder (data[EI_DATA])],
409 ELF_HEADER_FIELDS (ehdr));
410 if (ehdr->e_shoff + ehdr->e_shentsize * ehdr->e_shnum > size)
411 return -1; /* invalid offsets... */
412 if (ehdr->e_shentsize < ELF_SECTION_SIZE)
413 return -1; /* huh? */
414 if (ehdr->e_phoff + ehdr->e_phensize * ehdr->e_phnum > size)
415 return -1;
416 return 0;
417 case ELFCLASS64:
418 if (size < sizeof (Elf64_Ehdr) + EI_NIDENT)
419 return -1;
420 EXTRACTOR_common_cat_unpack (&data[EI_NIDENT],
421 ELF64_HEADER_SPECS[getByteorder (data[EI_DATA])],
422 ELF64_HEADER_FIELDS (ehdr64));
423 if (ehdr64->e_shoff + ((uint32_t) ehdr64->e_shentsize * ehdr64->e_shnum) > size)
424 return -1; /* invalid offsets... */
425 if (ehdr64->e_phoff + ((uint32_t) ehdr64->e_phensize * ehdr64->e_phnum) > size)
426 return -1;
427 return 1;
428 default:
429 return -1; 409 return -1;
430 } 410 EXTRACTOR_common_cat_unpack (&data[EI_NIDENT],
411 ELF_HEADER_SPECS[getByteorder (data[EI_DATA])],
412 ELF_HEADER_FIELDS (ehdr));
413 if (ehdr->e_shoff + ehdr->e_shentsize * ehdr->e_shnum > size)
414 return -1; /* invalid offsets... */
415 if (ehdr->e_shentsize < ELF_SECTION_SIZE)
416 return -1; /* huh? */
417 if (ehdr->e_phoff + ehdr->e_phensize * ehdr->e_phnum > size)
418 return -1;
419 return 0;
420 case ELFCLASS64:
421 if (size < sizeof (Elf64_Ehdr) + EI_NIDENT)
422 return -1;
423 EXTRACTOR_common_cat_unpack (&data[EI_NIDENT],
424 ELF64_HEADER_SPECS[getByteorder (
425 data[EI_DATA])],
426 ELF64_HEADER_FIELDS (ehdr64));
427 if (ehdr64->e_shoff + ((uint32_t) ehdr64->e_shentsize * ehdr64->e_shnum) >
428 size)
429 return -1; /* invalid offsets... */
430 if (ehdr64->e_phoff + ((uint32_t) ehdr64->e_phensize * ehdr64->e_phnum) >
431 size)
432 return -1;
433 return 1;
434 default:
435 return -1;
436 }
431} 437}
432 438
439
433/** 440/**
434 * @return the string (offset into data, do NOT free), NULL on error 441 * @return the string (offset into data, do NOT free), NULL on error
435 */ 442 */
436static const char * 443static const char *
437readStringTable (const char *data, 444readStringTable (const char *data,
438 size_t size, 445 size_t size,
439 Elf32_Ehdr * ehdr, 446 Elf32_Ehdr *ehdr,
440 Elf32_Half strTableOffset, Elf32_Word sh_name) 447 Elf32_Half strTableOffset, Elf32_Word sh_name)
441{ 448{
442 Elf32_Shdr shrd; 449 Elf32_Shdr shrd;
@@ -450,15 +457,19 @@ readStringTable (const char *data,
450 return &data[shrd.sh_offset + sh_name]; 457 return &data[shrd.sh_offset + sh_name];
451} 458}
452 459
453#define ADD(s, type) do { if (0!=proc(proc_cls, "elf", type, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1)) return 1; } while (0) 460
461#define ADD(s, type) do { if (0!=proc (proc_cls, "elf", type, \
462 EXTRACTOR_METAFORMAT_UTF8, "text/plain", \
463 s, strlen (s) + 1)) return 1; \
464} while (0)
454 465
455/* application/x-executable, ELF */ 466/* application/x-executable, ELF */
456int 467int
457EXTRACTOR_elf_extract (const char *data, 468EXTRACTOR_elf_extract (const char *data,
458 size_t size, 469 size_t size,
459 EXTRACTOR_MetaDataProcessor proc, 470 EXTRACTOR_MetaDataProcessor proc,
460 void *proc_cls, 471 void *proc_cls,
461 const char *options) 472 const char *options)
462{ 473{
463 Elf32_Ehdr ehdr; 474 Elf32_Ehdr ehdr;
464 Elf32_Half idx; 475 Elf32_Half idx;
@@ -470,186 +481,186 @@ EXTRACTOR_elf_extract (const char *data,
470 return 0; 481 return 0;
471 ADD ("application/x-executable", EXTRACTOR_METATYPE_MIMETYPE); 482 ADD ("application/x-executable", EXTRACTOR_METATYPE_MIMETYPE);
472 switch ( ((unsigned char*) data)[EI_OSABI]) 483 switch ( ((unsigned char*) data)[EI_OSABI])
473 { 484 {
474 case ELFOSABI_LINUX: 485 case ELFOSABI_LINUX:
475 ADD ("Linux", EXTRACTOR_METATYPE_TARGET_OS); 486 ADD ("Linux", EXTRACTOR_METATYPE_TARGET_OS);
476 break; 487 break;
477 case ELFOSABI_FREEBSD: 488 case ELFOSABI_FREEBSD:
478 ADD ("FreeBSD", EXTRACTOR_METATYPE_TARGET_OS); 489 ADD ("FreeBSD", EXTRACTOR_METATYPE_TARGET_OS);
479 break; 490 break;
480 case ELFOSABI_NETBSD: 491 case ELFOSABI_NETBSD:
481 ADD ("NetBSD", EXTRACTOR_METATYPE_TARGET_OS); 492 ADD ("NetBSD", EXTRACTOR_METATYPE_TARGET_OS);
482 break; 493 break;
483 case ELFOSABI_OPENBSD: 494 case ELFOSABI_OPENBSD:
484 ADD ("OpenBSD", EXTRACTOR_METATYPE_TARGET_OS); 495 ADD ("OpenBSD", EXTRACTOR_METATYPE_TARGET_OS);
485 break; 496 break;
486 case ELFOSABI_IRIX: 497 case ELFOSABI_IRIX:
487 ADD ("IRIX", EXTRACTOR_METATYPE_TARGET_OS); 498 ADD ("IRIX", EXTRACTOR_METATYPE_TARGET_OS);
488 break; 499 break;
489 default: 500 default:
490 break; 501 break;
491 } 502 }
492 switch ( (ret == 0) ? ehdr.e_type : ehdr64.e_type) 503 switch ( (ret == 0) ? ehdr.e_type : ehdr64.e_type)
493 { 504 {
494 case ET_REL: 505 case ET_REL:
495 ADD ("Relocatable file", EXTRACTOR_METATYPE_RESOURCE_TYPE); 506 ADD ("Relocatable file", EXTRACTOR_METATYPE_RESOURCE_TYPE);
496 break; 507 break;
497 case ET_EXEC: 508 case ET_EXEC:
498 ADD ("Executable file", EXTRACTOR_METATYPE_RESOURCE_TYPE); 509 ADD ("Executable file", EXTRACTOR_METATYPE_RESOURCE_TYPE);
499 break; 510 break;
500 case ET_DYN: 511 case ET_DYN:
501 ADD ("Shared object file", EXTRACTOR_METATYPE_RESOURCE_TYPE); 512 ADD ("Shared object file", EXTRACTOR_METATYPE_RESOURCE_TYPE);
502 break; 513 break;
503 case ET_CORE: 514 case ET_CORE:
504 ADD ("Core file", EXTRACTOR_METATYPE_RESOURCE_TYPE); 515 ADD ("Core file", EXTRACTOR_METATYPE_RESOURCE_TYPE);
505 break; 516 break;
506 default: 517 default:
507 break; /* unknown */ 518 break; /* unknown */
508 } 519 }
509 switch ( (ret == 0) ? ehdr.e_machine : ehdr64.e_machine) 520 switch ( (ret == 0) ? ehdr.e_machine : ehdr64.e_machine)
510 { 521 {
511 case EM_M32: 522 case EM_M32:
512 ADD ("M32", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 523 ADD ("M32", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
513 break; 524 break;
514 case EM_386: 525 case EM_386:
515 ADD ("i386", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 526 ADD ("i386", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
516 break; 527 break;
517 case EM_68K: 528 case EM_68K:
518 ADD ("68K", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 529 ADD ("68K", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
519 break; 530 break;
520 case EM_88K: 531 case EM_88K:
521 ADD ("88K", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 532 ADD ("88K", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
522 break; 533 break;
523 case EM_SPARC: 534 case EM_SPARC:
524 ADD ("Sparc", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 535 ADD ("Sparc", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
525 break; 536 break;
526 case EM_860: 537 case EM_860:
527 ADD ("960", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 538 ADD ("960", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
528 break; 539 break;
529 case EM_MIPS: 540 case EM_MIPS:
530 ADD ("MIPS", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 541 ADD ("MIPS", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
531 break; 542 break;
532 case EM_PPC: 543 case EM_PPC:
533 ADD ("PPC", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 544 ADD ("PPC", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
534 break; 545 break;
535 case EM_PPC64: 546 case EM_PPC64:
536 ADD ("PPC64", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 547 ADD ("PPC64", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
537 break; 548 break;
538 case EM_S390: 549 case EM_S390:
539 ADD ("S390", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 550 ADD ("S390", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
540 break; 551 break;
541 case EM_ARM: 552 case EM_ARM:
542 ADD ("ARM", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 553 ADD ("ARM", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
543 break; 554 break;
544 case EM_ALPHA: 555 case EM_ALPHA:
545 ADD ("ALPHA", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 556 ADD ("ALPHA", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
546 break; 557 break;
547 case EM_IA_64: 558 case EM_IA_64:
548 ADD ("IA-64", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 559 ADD ("IA-64", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
549 break; 560 break;
550 case EM_X86_64: 561 case EM_X86_64:
551 ADD ("x86_64", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 562 ADD ("x86_64", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
552 break; 563 break;
553 case EM_CUDA: 564 case EM_CUDA:
554 ADD ("NVIDIA CUDA", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 565 ADD ("NVIDIA CUDA", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
555 break; 566 break;
556 default: 567 default:
557 break; /* oops */ 568 break; /* oops */
558 } 569 }
559 570
560 if (ret != 0) 571 if (ret != 0)
561 return 0; /* FIXME: full support for 64-bit ELF... */ 572 return 0; /* FIXME: full support for 64-bit ELF... */
562 for (idx = 0; idx < ehdr.e_phnum; idx++) 573 for (idx = 0; idx < ehdr.e_phnum; idx++)
563 { 574 {
564 Elf32_Phdr phdr; 575 Elf32_Phdr phdr;
565 576
566 if (0 != getProgramHdr (data, size, &ehdr, idx, &phdr)) 577 if (0 != getProgramHdr (data, size, &ehdr, idx, &phdr))
578 return 0;
579 if (phdr.p_type == PT_DYNAMIC)
580 {
581 unsigned int dc = phdr.p_filesz / ELF_DYN_SIZE;
582 unsigned int id;
583 Elf32_Addr stringPtr;
584 Elf32_Half stringIdx;
585 Elf32_Half six;
586
587 stringPtr = 0;
588
589 for (id = 0; id < dc; id++)
590 {
591 Elf32_Dyn dyn;
592 if (0 != getDynTag (data,
593 size,
594 &ehdr,
595 phdr.p_offset, phdr.p_filesz, id, &dyn))
596 return 0;
597 if (DT_STRTAB == dyn.d_tag)
598 {
599 stringPtr = dyn.d_un.d_ptr;
600 break;
601 }
602 }
603 if (stringPtr == 0)
567 return 0; 604 return 0;
568 if (phdr.p_type == PT_DYNAMIC) 605 for (six = 0; six < ehdr.e_shnum; six++)
606 {
607 Elf32_Shdr sec;
608 if (-1 == getSectionHdr (data, size, &ehdr, six, &sec))
609 return 0;
610 if ((sec.sh_addr == stringPtr) && (sec.sh_type == SHT_STRTAB))
569 { 611 {
570 unsigned int dc = phdr.p_filesz / ELF_DYN_SIZE; 612 stringIdx = six;
571 unsigned int id; 613 break;
572 Elf32_Addr stringPtr; 614 }
573 Elf32_Half stringIdx; 615 }
574 Elf32_Half six; 616 if (six == ehdr.e_shnum)
575 617 return 0; /* stringIdx not found */
576 stringPtr = 0; 618
577 619 for (id = 0; id < dc; id++)
578 for (id = 0; id < dc; id++) 620 {
579 { 621 Elf32_Dyn dyn;
580 Elf32_Dyn dyn; 622 if (0 != getDynTag (data,
581 if (0 != getDynTag (data, 623 size,
582 size, 624 &ehdr,
583 &ehdr, 625 phdr.p_offset, phdr.p_filesz, id, &dyn))
584 phdr.p_offset, phdr.p_filesz, id, &dyn)) 626 return 0;
585 return 0; 627 switch (dyn.d_tag)
586 if (DT_STRTAB == dyn.d_tag) 628 {
587 { 629 case DT_RPATH:
588 stringPtr = dyn.d_un.d_ptr; 630 {
589 break; 631 const char *rpath;
590 } 632
591 } 633 rpath = readStringTable (data,
592 if (stringPtr == 0) 634 size,
593 return 0; 635 &ehdr,
594 for (six = 0; six < ehdr.e_shnum; six++) 636 stringIdx, dyn.d_un.d_val);
637 /* "source" of the dependencies: path
638 to dynamic libraries */
639 if (rpath != NULL)
595 { 640 {
596 Elf32_Shdr sec; 641 ADD (rpath, EXTRACTOR_METATYPE_LIBRARY_SEARCH_PATH);
597 if (-1 == getSectionHdr (data, size, &ehdr, six, &sec))
598 return 0;
599 if ((sec.sh_addr == stringPtr) && (sec.sh_type == SHT_STRTAB))
600 {
601 stringIdx = six;
602 break;
603 }
604 } 642 }
605 if (six == ehdr.e_shnum) 643 break;
606 return 0; /* stringIdx not found */ 644 }
607 645 case DT_NEEDED:
608 for (id = 0; id < dc; id++) 646 {
647 const char *needed;
648
649 needed = readStringTable (data,
650 size,
651 &ehdr,
652 stringIdx, dyn.d_un.d_val);
653 if (needed != NULL)
609 { 654 {
610 Elf32_Dyn dyn; 655 ADD (needed, EXTRACTOR_METATYPE_LIBRARY_DEPENDENCY);
611 if (0 != getDynTag (data,
612 size,
613 &ehdr,
614 phdr.p_offset, phdr.p_filesz, id, &dyn))
615 return 0;
616 switch (dyn.d_tag)
617 {
618 case DT_RPATH:
619 {
620 const char *rpath;
621
622 rpath = readStringTable (data,
623 size,
624 &ehdr,
625 stringIdx, dyn.d_un.d_val);
626 /* "source" of the dependencies: path
627 to dynamic libraries */
628 if (rpath != NULL)
629 {
630 ADD (rpath, EXTRACTOR_METATYPE_LIBRARY_SEARCH_PATH);
631 }
632 break;
633 }
634 case DT_NEEDED:
635 {
636 const char *needed;
637
638 needed = readStringTable (data,
639 size,
640 &ehdr,
641 stringIdx, dyn.d_un.d_val);
642 if (needed != NULL)
643 {
644 ADD (needed, EXTRACTOR_METATYPE_LIBRARY_DEPENDENCY);
645 }
646 break;
647 }
648 }
649 } 656 }
650 657 break;
658 }
651 } 659 }
660 }
661
652 } 662 }
663 }
653 664
654 return 0; 665 return 0;
655} 666}
diff --git a/src/plugins/old/flv_extractor.c b/src/plugins/old/flv_extractor.c
index f7d762d..2104d79 100644
--- a/src/plugins/old/flv_extractor.c
+++ b/src/plugins/old/flv_extractor.c
@@ -55,16 +55,18 @@
55#define ASTYPE_TYPEDOBJECT 0x10 55#define ASTYPE_TYPEDOBJECT 0x10
56#define ASTYPE_AMF3DATA 0x11 56#define ASTYPE_AMF3DATA 0x11
57 57
58typedef struct { 58typedef struct
59 void * userdata; 59{
60 void (*as_begin_callback)(unsigned char type, void * userdata); 60 void *userdata;
61 void (*as_key_callback)(char * key, void * userdata); 61 void (*as_begin_callback)(unsigned char type, void *userdata);
62 void (*as_end_callback)(unsigned char type, void * value, void * userdata); 62 void (*as_key_callback)(char *key, void *userdata);
63 void (*as_end_callback)(unsigned char type, void *value, void *userdata);
63} AMFParserHandler; 64} AMFParserHandler;
64 65
65/* core datatypes */ 66/* core datatypes */
66 67
67static uint32_t readInt32(const unsigned char **data) 68static uint32_t
69readInt32 (const unsigned char **data)
68{ 70{
69 const unsigned char *ptr = *data; 71 const unsigned char *ptr = *data;
70 uint32_t val; 72 uint32_t val;
@@ -75,7 +77,9 @@ static uint32_t readInt32(const unsigned char **data)
75 return val; 77 return val;
76} 78}
77 79
78static uint32_t readInt24(const unsigned char **data) 80
81static uint32_t
82readInt24 (const unsigned char **data)
79{ 83{
80 const unsigned char *ptr = *data; 84 const unsigned char *ptr = *data;
81 uint32_t val; 85 uint32_t val;
@@ -86,7 +90,9 @@ static uint32_t readInt24(const unsigned char **data)
86 return val; 90 return val;
87} 91}
88 92
89static uint16_t readInt16(const unsigned char **data) 93
94static uint16_t
95readInt16 (const unsigned char **data)
90{ 96{
91 const unsigned char *ptr = *data; 97 const unsigned char *ptr = *data;
92 uint16_t val; 98 uint16_t val;
@@ -97,14 +103,17 @@ static uint16_t readInt16(const unsigned char **data)
97 return val; 103 return val;
98} 104}
99 105
100static double readDouble(const unsigned char **data) 106
107static double
108readDouble (const unsigned char **data)
101{ 109{
102 const unsigned char *ptr = *data; 110 const unsigned char *ptr = *data;
103 double val; 111 double val;
104 112
105 EXTRACTOR_common_floatformat_to_double(&EXTRACTOR_floatformat_ieee_double_big, 113 EXTRACTOR_common_floatformat_to_double (
106 (const void *)ptr, 114 &EXTRACTOR_floatformat_ieee_double_big,
107 &val); 115 (const void *) ptr,
116 &val);
108 ptr += 8; 117 ptr += 8;
109 *data = ptr; 118 *data = ptr;
110 return val; 119 return val;
@@ -113,9 +122,10 @@ static double readDouble(const unsigned char **data)
113 122
114/* actionscript types */ 123/* actionscript types */
115 124
116static int readASNumber(const unsigned char **data, 125static int
117 size_t *len, 126readASNumber (const unsigned char **data,
118 double *retval) 127 size_t *len,
128 double *retval)
119{ 129{
120 const unsigned char *ptr = *data; 130 const unsigned char *ptr = *data;
121 double val; 131 double val;
@@ -123,7 +133,7 @@ static int readASNumber(const unsigned char **data,
123 if (*len < 8) 133 if (*len < 8)
124 return -1; 134 return -1;
125 135
126 val = readDouble(&ptr); 136 val = readDouble (&ptr);
127 *len -= 8; 137 *len -= 8;
128 138
129 *retval = val; 139 *retval = val;
@@ -131,9 +141,11 @@ static int readASNumber(const unsigned char **data,
131 return 0; 141 return 0;
132} 142}
133 143
134static int readASBoolean(const unsigned char **data, 144
135 size_t *len, 145static int
136 int *retval) 146readASBoolean (const unsigned char **data,
147 size_t *len,
148 int *retval)
137{ 149{
138 const unsigned char *ptr = *data; 150 const unsigned char *ptr = *data;
139 int val; 151 int val;
@@ -150,29 +162,33 @@ static int readASBoolean(const unsigned char **data,
150 return 0; 162 return 0;
151} 163}
152 164
153static int readASDate(const unsigned char **data, 165
154 size_t *len, 166static int
155 double *millis, 167readASDate (const unsigned char **data,
156 short *zone) 168 size_t *len,
169 double *millis,
170 short *zone)
157{ 171{
158 const unsigned char *ptr = *data; 172 const unsigned char *ptr = *data;
159 173
160 if (*len < 10) 174 if (*len < 10)
161 return -1; 175 return -1;
162 176
163 *millis = readDouble(&ptr); 177 *millis = readDouble (&ptr);
164 *len -= 8; 178 *len -= 8;
165 179
166 *zone = readInt16(&ptr); 180 *zone = readInt16 (&ptr);
167 *len -= 2; 181 *len -= 2;
168 182
169 *data = ptr; 183 *data = ptr;
170 return 0; 184 return 0;
171} 185}
172 186
173static int readASString(const unsigned char **data, 187
174 size_t *len, 188static int
175 char **retval) 189readASString (const unsigned char **data,
190 size_t *len,
191 char **retval)
176{ 192{
177 const unsigned char *ptr = *data; 193 const unsigned char *ptr = *data;
178 char *ret; 194 char *ret;
@@ -181,15 +197,15 @@ static int readASString(const unsigned char **data,
181 if (*len < 2) 197 if (*len < 2)
182 return -1; 198 return -1;
183 199
184 slen = readInt16(&ptr); 200 slen = readInt16 (&ptr);
185 201
186 if (*len < (2 + slen)) 202 if (*len < (2 + slen))
187 return -1; 203 return -1;
188 204
189 ret = malloc(slen+1); 205 ret = malloc (slen + 1);
190 if (ret == NULL) 206 if (ret == NULL)
191 return -1; 207 return -1;
192 memcpy(ret, ptr, slen); 208 memcpy (ret, ptr, slen);
193 ret[slen] = '\0'; 209 ret[slen] = '\0';
194 ptr += slen; 210 ptr += slen;
195 *len -= (2 + slen); 211 *len -= (2 + slen);
@@ -199,9 +215,11 @@ static int readASString(const unsigned char **data,
199 return 0; 215 return 0;
200} 216}
201 217
202static int parse_amf(const unsigned char **data, 218
203 size_t *len, 219static int
204 AMFParserHandler *handler) 220parse_amf (const unsigned char **data,
221 size_t *len,
222 AMFParserHandler *handler)
205{ 223{
206 const unsigned char *ptr = *data; 224 const unsigned char *ptr = *data;
207 unsigned char astype; 225 unsigned char astype;
@@ -210,45 +228,47 @@ static int parse_amf(const unsigned char **data,
210 ret = 0; 228 ret = 0;
211 astype = *ptr++; 229 astype = *ptr++;
212 (*(handler->as_begin_callback))(astype, handler->userdata); 230 (*(handler->as_begin_callback))(astype, handler->userdata);
213 switch (astype) { 231 switch (astype)
214 case ASTYPE_NUMBER: 232 {
233 case ASTYPE_NUMBER:
215 { 234 {
216 double val; 235 double val;
217 ret = readASNumber(&ptr, len, &val); 236 ret = readASNumber (&ptr, len, &val);
218 if (ret == 0) 237 if (ret == 0)
219 (*(handler->as_end_callback))(astype, 238 (*(handler->as_end_callback))(astype,
220 &val, 239 &val,
221 handler->userdata); 240 handler->userdata);
222 break; 241 break;
223 } 242 }
224 case ASTYPE_BOOLEAN: 243 case ASTYPE_BOOLEAN:
225 { 244 {
226 int val; 245 int val;
227 ret = readASBoolean(&ptr, len, &val); 246 ret = readASBoolean (&ptr, len, &val);
228 if (ret == 0) 247 if (ret == 0)
229 (*(handler->as_end_callback))(astype, 248 (*(handler->as_end_callback))(astype,
230 &val, 249 &val,
231 handler->userdata); 250 handler->userdata);
232 break; 251 break;
233 } 252 }
234 case ASTYPE_STRING: 253 case ASTYPE_STRING:
235 { 254 {
236 char *val; 255 char *val;
237 ret = readASString(&ptr, len, &val); 256 ret = readASString (&ptr, len, &val);
238 if (ret == 0) { 257 if (ret == 0)
258 {
239 (*(handler->as_end_callback))(astype, 259 (*(handler->as_end_callback))(astype,
240 val, 260 val,
241 handler->userdata); 261 handler->userdata);
242 free(val); 262 free (val);
243 } 263 }
244 break; 264 break;
245 } 265 }
246 case ASTYPE_DATE: 266 case ASTYPE_DATE:
247 { 267 {
248 void *tmp[2]; 268 void *tmp[2];
249 double millis; 269 double millis;
250 short tz; 270 short tz;
251 ret = readASDate(&ptr, len, &millis, &tz); 271 ret = readASDate (&ptr, len, &millis, &tz);
252 tmp[0] = &millis; 272 tmp[0] = &millis;
253 tmp[1] = &tz; 273 tmp[1] = &tz;
254 if (ret == 0) 274 if (ret == 0)
@@ -257,53 +277,56 @@ static int parse_amf(const unsigned char **data,
257 handler->userdata); 277 handler->userdata);
258 break; 278 break;
259 } 279 }
260 case ASTYPE_NULL: 280 case ASTYPE_NULL:
261 case ASTYPE_UNDEFINED: 281 case ASTYPE_UNDEFINED:
262 case ASTYPE_UNSUPPORTED: 282 case ASTYPE_UNSUPPORTED:
263 case ASTYPE_ENDOFOBJECT: 283 case ASTYPE_ENDOFOBJECT:
264 (*(handler->as_end_callback))(astype, NULL, handler->userdata); 284 (*(handler->as_end_callback))(astype, NULL, handler->userdata);
265 break; 285 break;
266 case ASTYPE_ARRAY: 286 case ASTYPE_ARRAY:
267 { 287 {
268 long i, alen; 288 long i, alen;
269 if (*len < 4) { 289 if (*len < 4)
290 {
270 ret = -1; 291 ret = -1;
271 break; 292 break;
272 } 293 }
273 alen = readInt32(&ptr); 294 alen = readInt32 (&ptr);
274 *len -= 4; 295 *len -= 4;
275 for (i = 0; i < alen; i++) { 296 for (i = 0; i < alen; i++)
276 ret = parse_amf(&ptr, len, handler); 297 {
298 ret = parse_amf (&ptr, len, handler);
277 if (ret == -1) 299 if (ret == -1)
278 break; 300 break;
279 } 301 }
280 (*(handler->as_end_callback))(ASTYPE_ARRAY, 302 (*(handler->as_end_callback))(ASTYPE_ARRAY,
281 NULL, 303 NULL,
282 handler->userdata); 304 handler->userdata);
283 break; 305 break;
284 } 306 }
285 case ASTYPE_OBJECT: 307 case ASTYPE_OBJECT:
286 { 308 {
287 char *key; 309 char *key;
288 unsigned char type; 310 unsigned char type;
289 311
290 ret = readASString(&ptr, len, &key); 312 ret = readASString (&ptr, len, &key);
291 if (ret == -1) 313 if (ret == -1)
292 break; 314 break;
293 (*(handler->as_key_callback))(key, 315 (*(handler->as_key_callback))(key,
294 handler->userdata); 316 handler->userdata);
295 free(key); 317 free (key);
296 type = *ptr; 318 type = *ptr;
297 while (type != ASTYPE_ENDOFOBJECT) { 319 while (type != ASTYPE_ENDOFOBJECT)
298 ret = parse_amf(&ptr, len, handler); 320 {
321 ret = parse_amf (&ptr, len, handler);
299 if (ret == -1) 322 if (ret == -1)
300 break; 323 break;
301 ret = readASString(&ptr, len, &key); 324 ret = readASString (&ptr, len, &key);
302 if (ret == -1) 325 if (ret == -1)
303 break; 326 break;
304 (*(handler->as_key_callback))(key, 327 (*(handler->as_key_callback))(key,
305 handler->userdata); 328 handler->userdata);
306 free(key); 329 free (key);
307 type = *ptr; 330 type = *ptr;
308 } 331 }
309 if (ret == 0) 332 if (ret == 0)
@@ -312,34 +335,36 @@ static int parse_amf(const unsigned char **data,
312 handler->userdata); 335 handler->userdata);
313 break; 336 break;
314 } 337 }
315 case ASTYPE_MIXEDARRAY: 338 case ASTYPE_MIXEDARRAY:
316 { 339 {
317 char *key; 340 char *key;
318 unsigned char type; 341 unsigned char type;
319 342
320 if (*len < 4) { 343 if (*len < 4)
344 {
321 ret = -1; 345 ret = -1;
322 break; 346 break;
323 } 347 }
324 /* max_index */ readInt32(&ptr); 348 /* max_index */ readInt32 (&ptr);
325 *len -= 4; 349 *len -= 4;
326 ret = readASString(&ptr, len, &key); 350 ret = readASString (&ptr, len, &key);
327 if (ret == -1) 351 if (ret == -1)
328 break; 352 break;
329 (*(handler->as_key_callback))(key, 353 (*(handler->as_key_callback))(key,
330 handler->userdata); 354 handler->userdata);
331 free(key); 355 free (key);
332 type = *ptr; 356 type = *ptr;
333 while (type != ASTYPE_ENDOFOBJECT) { 357 while (type != ASTYPE_ENDOFOBJECT)
334 ret = parse_amf(&ptr, len, handler); 358 {
359 ret = parse_amf (&ptr, len, handler);
335 if (ret == -1) 360 if (ret == -1)
336 break; 361 break;
337 ret = readASString(&ptr, len, &key); 362 ret = readASString (&ptr, len, &key);
338 if (ret == -1) 363 if (ret == -1)
339 break; 364 break;
340 (*(handler->as_key_callback))(key, 365 (*(handler->as_key_callback))(key,
341 handler->userdata); 366 handler->userdata);
342 free(key); 367 free (key);
343 type = *ptr; 368 type = *ptr;
344 } 369 }
345 if (ret == 0) 370 if (ret == 0)
@@ -348,21 +373,22 @@ static int parse_amf(const unsigned char **data,
348 handler->userdata); 373 handler->userdata);
349 break; 374 break;
350 } 375 }
351 default: 376 default:
352 ret = -1; 377 ret = -1;
353 (*(handler->as_end_callback))(astype, 378 (*(handler->as_end_callback))(astype,
354 NULL, 379 NULL,
355 handler->userdata); 380 handler->userdata);
356#if DEBUG 381#if DEBUG
357 printf("parse_amf: Unknown type %02x", astype); 382 printf ("parse_amf: Unknown type %02x", astype);
358#endif 383#endif
359 break; 384 break;
360 } 385 }
361 386
362 *data = ptr; 387 *data = ptr;
363 return ret; 388 return ret;
364} 389}
365 390
391
366/* 392/*
367 * FLV parser 393 * FLV parser
368 */ 394 */
@@ -379,8 +405,9 @@ flv_to_iso_date (double timeval, short timezone,
379 * shift epoch to proleptic times 405 * shift epoch to proleptic times
380 * to make subsequent modulo operations safer. 406 * to make subsequent modulo operations safer.
381 */ 407 */
382 long long my_timeval = (timeval/1000) 408 long long my_timeval = (timeval / 1000)
383 + ((long long) ((1970 * 365) + 478) * (long long) 86400); 409 + ((long long) ((1970 * 365) + 478) * (long
410 long) 86400);
384 411
385 unsigned int seconds = (unsigned int) (my_timeval % 60); 412 unsigned int seconds = (unsigned int) (my_timeval % 60);
386 unsigned int minutes = (unsigned int) ((my_timeval / 60) % 60); 413 unsigned int minutes = (unsigned int) ((my_timeval / 60) % 60);
@@ -396,7 +423,7 @@ flv_to_iso_date (double timeval, short timezone,
396 unsigned int days = (unsigned int) (my_timeval / (24 * 3600)); 423 unsigned int days = (unsigned int) (my_timeval / (24 * 3600));
397 424
398 unsigned int days_in_month[] = 425 unsigned int days_in_month[] =
399 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 426 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
400 unsigned int diff = 0; 427 unsigned int diff = 0;
401 428
402 if ((long long) 0 > my_timeval) 429 if ((long long) 0 > my_timeval)
@@ -413,15 +440,15 @@ flv_to_iso_date (double timeval, short timezone,
413 */ 440 */
414 diff = (days / ((365 * 100) + 24)); 441 diff = (days / ((365 * 100) + 24));
415 if (4 <= diff) 442 if (4 <= diff)
416 { 443 {
417 year += 399; 444 year += 399;
418 days = 364; 445 days = 364;
419 } 446 }
420 else 447 else
421 { 448 {
422 year += (100 * diff); 449 year += (100 * diff);
423 days %= ((365 * 100) + 24); 450 days %= ((365 * 100) + 24);
424 } 451 }
425 452
426 /* 453 /*
427 * remaining leap years 454 * remaining leap years
@@ -430,32 +457,32 @@ flv_to_iso_date (double timeval, short timezone,
430 days %= ((365 * 4) + 1); 457 days %= ((365 * 4) + 1);
431 458
432 while (1) 459 while (1)
460 {
461 if ((0 == (year % 400)) || ((0 == (year % 4)) && (0 != (year % 100))))
433 { 462 {
434 if ((0 == (year % 400)) || ((0 == (year % 4)) && (0 != (year % 100)))) 463 if (366 > days)
435 { 464 {
436 if (366 > days) 465 break;
437 { 466 }
438 break;
439 }
440 else
441 {
442 days -= 366;
443 year++;
444 }
445 }
446 else 467 else
447 { 468 {
448 if (365 > days) 469 days -= 366;
449 { 470 year++;
450 break; 471 }
451 } 472 }
452 else 473 else
453 { 474 {
454 days -= 365; 475 if (365 > days)
455 year++; 476 {
456 } 477 break;
457 } 478 }
479 else
480 {
481 days -= 365;
482 year++;
483 }
458 } 484 }
485 }
459 486
460 if ((0 == (year % 400)) || ((0 == (year % 4)) && (0 != (year % 100)))) 487 if ((0 == (year % 400)) || ((0 == (year % 4)) && (0 != (year % 100))))
461 days_in_month[1] = 29; 488 days_in_month[1] = 29;
@@ -465,12 +492,12 @@ flv_to_iso_date (double timeval, short timezone,
465 492
466 zone_sign = 0; 493 zone_sign = 0;
467 if (timezone < 0) 494 if (timezone < 0)
468 { 495 {
469 zone_sign = -1; 496 zone_sign = -1;
470 timezone = -timezone; 497 timezone = -timezone;
471 } 498 }
472 zone_hours = timezone/60; 499 zone_hours = timezone / 60;
473 zone_minutes = timezone - zone_hours*60; 500 zone_minutes = timezone - zone_hours * 60;
474 501
475 retval = snprintf (rtime, rsize, "%04u-%02u-%02uT%02u:%02u:%02u%c%02d:%02u", 502 retval = snprintf (rtime, rsize, "%04u-%02u-%02uT%02u:%02u:%02u%c%02d:%02u",
476 year, month + 1, days + 1, hours, minutes, seconds, 503 year, month + 1, days + 1, hours, minutes, seconds,
@@ -479,6 +506,7 @@ flv_to_iso_date (double timeval, short timezone,
479 return (retval < rsize) ? 0 : EOVERFLOW; 506 return (retval < rsize) ? 0 : EOVERFLOW;
480} 507}
481 508
509
482typedef struct 510typedef struct
483{ 511{
484 char signature[3]; 512 char signature[3];
@@ -503,20 +531,21 @@ typedef struct
503 531
504#define FLV_TAG_HEADER_SIZE 11 532#define FLV_TAG_HEADER_SIZE 11
505 533
506static int readFLVHeader(const unsigned char **data, 534static int
507 const unsigned char *end, 535readFLVHeader (const unsigned char **data,
508 FLVHeader *hdr) 536 const unsigned char *end,
537 FLVHeader *hdr)
509{ 538{
510 const unsigned char *ptr = *data; 539 const unsigned char *ptr = *data;
511 540
512 if ((ptr + FLV_HEADER_SIZE) > end) 541 if ((ptr + FLV_HEADER_SIZE) > end)
513 return -1; 542 return -1;
514 543
515 memcpy(hdr->signature, ptr, 3); 544 memcpy (hdr->signature, ptr, 3);
516 ptr += 3; 545 ptr += 3;
517 hdr->version = *ptr++; 546 hdr->version = *ptr++;
518 hdr->flags = *ptr++; 547 hdr->flags = *ptr++;
519 hdr->offset = readInt32(&ptr); 548 hdr->offset = readInt32 (&ptr);
520 if (hdr->offset != FLV_HEADER_SIZE) 549 if (hdr->offset != FLV_HEADER_SIZE)
521 return -1; 550 return -1;
522 551
@@ -524,24 +553,28 @@ static int readFLVHeader(const unsigned char **data,
524 return 0; 553 return 0;
525} 554}
526 555
527static int readPreviousTagSize(const unsigned char **data, 556
528 const unsigned char *end, 557static int
529 unsigned long *prev_size) 558readPreviousTagSize (const unsigned char **data,
559 const unsigned char *end,
560 unsigned long *prev_size)
530{ 561{
531 const unsigned char *ptr = *data; 562 const unsigned char *ptr = *data;
532 563
533 if ((ptr + 4) > end) 564 if ((ptr + 4) > end)
534 return -1; 565 return -1;
535 566
536 *prev_size = readInt32(&ptr); 567 *prev_size = readInt32 (&ptr);
537 568
538 *data = ptr; 569 *data = ptr;
539 return 0; 570 return 0;
540} 571}
541 572
542static int readFLVTagHeader(const unsigned char **data, 573
543 const unsigned char *end, 574static int
544 FLVTagHeader *hdr) 575readFLVTagHeader (const unsigned char **data,
576 const unsigned char *end,
577 FLVTagHeader *hdr)
545{ 578{
546 const unsigned char *ptr = *data; 579 const unsigned char *ptr = *data;
547 580
@@ -549,15 +582,17 @@ static int readFLVTagHeader(const unsigned char **data,
549 return -1; 582 return -1;
550 583
551 hdr->type = *ptr++; 584 hdr->type = *ptr++;
552 hdr->bodyLength = readInt24(&ptr); 585 hdr->bodyLength = readInt24 (&ptr);
553 hdr->timestamp = readInt32(&ptr); 586 hdr->timestamp = readInt32 (&ptr);
554 hdr->streamId = readInt24(&ptr); 587 hdr->streamId = readInt24 (&ptr);
555 588
556 *data = ptr; 589 *data = ptr;
557 return 0; 590 return 0;
558} 591}
559 592
560typedef struct { 593
594typedef struct
595{
561 int videoCodec; 596 int videoCodec;
562 char *videoCodecStr; 597 char *videoCodecStr;
563 int videoWidth; 598 int videoWidth;
@@ -573,7 +608,8 @@ typedef struct {
573 int audioRate; 608 int audioRate;
574} FLVStreamInfo; 609} FLVStreamInfo;
575 610
576typedef enum { 611typedef enum
612{
577 FLV_NONE = 0, 613 FLV_NONE = 0,
578 FLV_WIDTH, 614 FLV_WIDTH,
579 FLV_HEIGHT, 615 FLV_HEIGHT,
@@ -586,7 +622,8 @@ typedef enum {
586 FLV_ACODECID 622 FLV_ACODECID
587} FLVStreamAttribute; 623} FLVStreamAttribute;
588 624
589typedef struct { 625typedef struct
626{
590 const char *key; 627 const char *key;
591 FLVStreamAttribute attribute; 628 FLVStreamAttribute attribute;
592} MetaKeyToStreamAttribute; 629} MetaKeyToStreamAttribute;
@@ -605,7 +642,8 @@ static MetaKeyToStreamAttribute key_to_attribute_map[] = {
605 { NULL, FLV_NONE } 642 { NULL, FLV_NONE }
606}; 643};
607 644
608typedef struct { 645typedef struct
646{
609 const char *key; 647 const char *key;
610 enum EXTRACTOR_MetaType type; 648 enum EXTRACTOR_MetaType type;
611} MetaKeyToExtractorItem; 649} MetaKeyToExtractorItem;
@@ -619,7 +657,8 @@ static MetaKeyToExtractorItem key_to_extractor_map[] = {
619 { NULL, EXTRACTOR_METATYPE_RESERVED } 657 { NULL, EXTRACTOR_METATYPE_RESERVED }
620}; 658};
621 659
622typedef struct { 660typedef struct
661{
623 int onMetaData; 662 int onMetaData;
624 int parsingDepth; 663 int parsingDepth;
625 int ret; 664 int ret;
@@ -632,22 +671,25 @@ typedef struct {
632 FLVStreamInfo *streamInfo; 671 FLVStreamInfo *streamInfo;
633} FLVMetaParserState; 672} FLVMetaParserState;
634 673
635static void handleASBegin(unsigned char type, void * userdata) 674static void
675handleASBegin (unsigned char type, void *userdata)
636{ 676{
637 FLVMetaParserState *state = (FLVMetaParserState *)userdata; 677 FLVMetaParserState *state = (FLVMetaParserState *) userdata;
638 678
639 if (state->onMetaData && state->parsingDepth == 0 && 679 if (state->onMetaData && (state->parsingDepth == 0) &&
640 type != ASTYPE_MIXEDARRAY) 680 (type != ASTYPE_MIXEDARRAY) )
641 state->onMetaData = 0; 681 state->onMetaData = 0;
642 682
643 if (type == ASTYPE_ARRAY || type == ASTYPE_MIXEDARRAY || 683 if ((type == ASTYPE_ARRAY) || (type == ASTYPE_MIXEDARRAY) ||
644 type == ASTYPE_OBJECT) 684 (type == ASTYPE_OBJECT) )
645 state->parsingDepth++; 685 state->parsingDepth++;
646} 686}
647 687
648static void handleASKey(char * key, void * userdata) 688
689static void
690handleASKey (char *key, void *userdata)
649{ 691{
650 FLVMetaParserState *state = (FLVMetaParserState *)userdata; 692 FLVMetaParserState *state = (FLVMetaParserState *) userdata;
651 int i; 693 int i;
652 694
653 if (key == NULL) 695 if (key == NULL)
@@ -655,26 +697,29 @@ static void handleASKey(char * key, void * userdata)
655 697
656 i = 0; 698 i = 0;
657 while ((key_to_extractor_map[i].key != NULL) && 699 while ((key_to_extractor_map[i].key != NULL) &&
658 (strcasecmp(key, key_to_extractor_map[i].key) != 0)) 700 (strcasecmp (key, key_to_extractor_map[i].key) != 0))
659 i++; 701 i++;
660 state->currentKeyType = key_to_extractor_map[i].type; 702 state->currentKeyType = key_to_extractor_map[i].type;
661 703
662 i = 0; 704 i = 0;
663 while ((key_to_attribute_map[i].key != NULL) && 705 while ((key_to_attribute_map[i].key != NULL) &&
664 (strcasecmp(key, key_to_attribute_map[i].key) != 0)) 706 (strcasecmp (key, key_to_attribute_map[i].key) != 0))
665 i++; 707 i++;
666 state->currentAttribute = key_to_attribute_map[i].attribute; 708 state->currentAttribute = key_to_attribute_map[i].attribute;
667} 709}
668 710
669static void handleASEnd(unsigned char type, void * value, void * userdata) 711
712static void
713handleASEnd (unsigned char type, void *value, void *userdata)
670{ 714{
671 FLVMetaParserState *state = (FLVMetaParserState *)userdata; 715 FLVMetaParserState *state = (FLVMetaParserState *) userdata;
672 const char *s; 716 const char *s;
673 char tmpstr[30]; 717 char tmpstr[30];
674 718
675 if ((state->parsingDepth == 0) && (type == ASTYPE_STRING)) { 719 if ((state->parsingDepth == 0) && (type == ASTYPE_STRING))
676 s = (const char *)value; 720 {
677 if (!strcmp(s, "onMetaData")) 721 s = (const char *) value;
722 if (! strcmp (s, "onMetaData"))
678 state->onMetaData = 1; 723 state->onMetaData = 1;
679 } 724 }
680 725
@@ -686,50 +731,53 @@ static void handleASEnd(unsigned char type, void * value, void * userdata)
686 (state->currentAttribute != FLV_NONE) && 731 (state->currentAttribute != FLV_NONE) &&
687 (type == ASTYPE_NUMBER)) 732 (type == ASTYPE_NUMBER))
688 { 733 {
689 double n = *((double *)value); 734 double n = *((double *) value);
690 switch (state->currentAttribute) { 735 switch (state->currentAttribute)
691 case FLV_NONE: /* make gcc happy */ 736 {
692 break; 737 case FLV_NONE: /* make gcc happy */
693 case FLV_STEREO: 738 break;
694 break; 739 case FLV_STEREO:
695 case FLV_ACHANNELS: 740 break;
696 state->streamInfo->audioChannels = n; 741 case FLV_ACHANNELS:
697 break; 742 state->streamInfo->audioChannels = n;
698 case FLV_WIDTH: 743 break;
699 if (state->streamInfo->videoWidth == -1) 744 case FLV_WIDTH:
700 state->streamInfo->videoWidth = n; 745 if (state->streamInfo->videoWidth == -1)
701 break; 746 state->streamInfo->videoWidth = n;
702 case FLV_HEIGHT: 747 break;
703 if (state->streamInfo->videoHeight == -1) 748 case FLV_HEIGHT:
704 state->streamInfo->videoHeight = n; 749 if (state->streamInfo->videoHeight == -1)
705 break; 750 state->streamInfo->videoHeight = n;
706 case FLV_FRAMERATE: 751 break;
707 state->streamInfo->videoFrameRate = n; 752 case FLV_FRAMERATE:
708 break; 753 state->streamInfo->videoFrameRate = n;
709 case FLV_VDATARATE: 754 break;
710 state->streamInfo->videoDataRate = n; 755 case FLV_VDATARATE:
711 break; 756 state->streamInfo->videoDataRate = n;
712 case FLV_ADATARATE: 757 break;
713 state->streamInfo->audioDataRate = n; 758 case FLV_ADATARATE:
714 break; 759 state->streamInfo->audioDataRate = n;
715 case FLV_VCODECID: 760 break;
716 if (state->streamInfo->videoCodec == -1) 761 case FLV_VCODECID:
717 state->streamInfo->videoCodec = n; 762 if (state->streamInfo->videoCodec == -1)
718 /* prefer codec ids to fourcc codes */ 763 state->streamInfo->videoCodec = n;
719 if (state->streamInfo->videoCodecStr != NULL) { 764 /* prefer codec ids to fourcc codes */
720 free(state->streamInfo->videoCodecStr); 765 if (state->streamInfo->videoCodecStr != NULL)
721 state->streamInfo->videoCodecStr = NULL; 766 {
722 } 767 free (state->streamInfo->videoCodecStr);
723 break; 768 state->streamInfo->videoCodecStr = NULL;
724 case FLV_ACODECID: 769 }
725 if (state->streamInfo->audioCodec == -1) 770 break;
726 state->streamInfo->audioCodec = n; 771 case FLV_ACODECID:
727 /* prefer codec ids to fourcc codes */ 772 if (state->streamInfo->audioCodec == -1)
728 if (state->streamInfo->audioCodecStr != NULL) { 773 state->streamInfo->audioCodec = n;
729 free(state->streamInfo->audioCodecStr); 774 /* prefer codec ids to fourcc codes */
730 state->streamInfo->audioCodecStr = NULL; 775 if (state->streamInfo->audioCodecStr != NULL)
731 } 776 {
732 break; 777 free (state->streamInfo->audioCodecStr);
778 state->streamInfo->audioCodecStr = NULL;
779 }
780 break;
733 } 781 }
734 } 782 }
735 783
@@ -738,20 +786,21 @@ static void handleASEnd(unsigned char type, void * value, void * userdata)
738 (state->currentAttribute != FLV_NONE) && 786 (state->currentAttribute != FLV_NONE) &&
739 (type == ASTYPE_STRING)) 787 (type == ASTYPE_STRING))
740 { 788 {
741 s = (const char *)value; 789 s = (const char *) value;
742 switch (state->currentAttribute) { 790 switch (state->currentAttribute)
743 case FLV_VCODECID: 791 {
744 if (s != NULL && state->streamInfo->videoCodecStr == NULL && 792 case FLV_VCODECID:
745 state->streamInfo->videoCodec == -1) 793 if ((s != NULL) && (state->streamInfo->videoCodecStr == NULL) &&
746 state->streamInfo->videoCodecStr = strdup(s); 794 (state->streamInfo->videoCodec == -1) )
747 break; 795 state->streamInfo->videoCodecStr = strdup (s);
748 case FLV_ACODECID: 796 break;
749 if (s != NULL && state->streamInfo->audioCodecStr == NULL && 797 case FLV_ACODECID:
750 state->streamInfo->audioCodec == -1) 798 if ((s != NULL) && (state->streamInfo->audioCodecStr == NULL) &&
751 state->streamInfo->audioCodecStr = strdup(s); 799 (state->streamInfo->audioCodec == -1) )
752 break; 800 state->streamInfo->audioCodecStr = strdup (s);
753 default: 801 break;
754 break; 802 default:
803 break;
755 } 804 }
756 } 805 }
757 806
@@ -759,7 +808,7 @@ static void handleASEnd(unsigned char type, void * value, void * userdata)
759 (state->currentAttribute == FLV_STEREO) && 808 (state->currentAttribute == FLV_STEREO) &&
760 (type == ASTYPE_BOOLEAN)) 809 (type == ASTYPE_BOOLEAN))
761 { 810 {
762 int n = *((int *)value); 811 int n = *((int *) value);
763 if (state->streamInfo->audioChannels == -1) 812 if (state->streamInfo->audioChannels == -1)
764 state->streamInfo->audioChannels = (n == 0) ? 1 : 2; 813 state->streamInfo->audioChannels = (n == 0) ? 1 : 2;
765 } 814 }
@@ -769,57 +818,59 @@ static void handleASEnd(unsigned char type, void * value, void * userdata)
769 (state->currentKeyType != EXTRACTOR_METATYPE_RESERVED)) 818 (state->currentKeyType != EXTRACTOR_METATYPE_RESERVED))
770 { 819 {
771 s = NULL; 820 s = NULL;
772 switch (type) { 821 switch (type)
773 case ASTYPE_NUMBER: 822 {
823 case ASTYPE_NUMBER:
774 { 824 {
775 double n = *((double *)value); 825 double n = *((double *) value);
776 s = tmpstr; 826 s = tmpstr;
777 if (state->currentKeyType == EXTRACTOR_METATYPE_DURATION) 827 if (state->currentKeyType == EXTRACTOR_METATYPE_DURATION)
778 snprintf(tmpstr, sizeof(tmpstr), "%.2f s", n); 828 snprintf (tmpstr, sizeof(tmpstr), "%.2f s", n);
779 else 829 else
780 snprintf(tmpstr, sizeof(tmpstr), "%f", n); 830 snprintf (tmpstr, sizeof(tmpstr), "%f", n);
781 break; 831 break;
782 } 832 }
783 case ASTYPE_STRING: 833 case ASTYPE_STRING:
784 { 834 {
785 s = (char *)value; 835 s = (char *) value;
786 break; 836 break;
787 } 837 }
788 case ASTYPE_DATE: 838 case ASTYPE_DATE:
789 { 839 {
790 void **tmp = (void **)value; 840 void **tmp = (void **) value;
791 double *millis; 841 double *millis;
792 short *tz; 842 short *tz;
793 millis = (double *)tmp[0]; 843 millis = (double *) tmp[0];
794 tz = (short *)tmp[1]; 844 tz = (short *) tmp[1];
795 if (0 == flv_to_iso_date(*millis, *tz, tmpstr, sizeof(tmpstr))) 845 if (0 == flv_to_iso_date (*millis, *tz, tmpstr, sizeof(tmpstr)))
796 s = tmpstr; 846 s = tmpstr;
797 break; 847 break;
798 } 848 }
799 } 849 }
800 if ( (s != NULL) && 850 if ( (s != NULL) &&
801 (state->ret == 0) ) 851 (state->ret == 0) )
802 state->ret = state->proc (state->proc_cls, 852 state->ret = state->proc (state->proc_cls,
803 "flv", 853 "flv",
804 state->currentKeyType, 854 state->currentKeyType,
805 EXTRACTOR_METAFORMAT_UTF8, 855 EXTRACTOR_METAFORMAT_UTF8,
806 "text/plain", 856 "text/plain",
807 s, 857 s,
808 strlen (s) + 1); 858 strlen (s) + 1);
809 } 859 }
810 state->currentKeyType = EXTRACTOR_METATYPE_RESERVED; 860 state->currentKeyType = EXTRACTOR_METATYPE_RESERVED;
811 state->currentAttribute = FLV_NONE; 861 state->currentAttribute = FLV_NONE;
812 862
813 if (type == ASTYPE_ARRAY || type == ASTYPE_MIXEDARRAY || 863 if ((type == ASTYPE_ARRAY) || (type == ASTYPE_MIXEDARRAY) ||
814 type == ASTYPE_OBJECT) 864 (type == ASTYPE_OBJECT) )
815 state->parsingDepth--; 865 state->parsingDepth--;
816} 866}
817 867
868
818static int 869static int
819handleMetaBody(const unsigned char *data, size_t len, 870handleMetaBody (const unsigned char *data, size_t len,
820 FLVStreamInfo *stinfo, 871 FLVStreamInfo *stinfo,
821 EXTRACTOR_MetaDataProcessor proc, 872 EXTRACTOR_MetaDataProcessor proc,
822 void *proc_cls) 873 void *proc_cls)
823{ 874{
824 AMFParserHandler handler; 875 AMFParserHandler handler;
825 FLVMetaParserState pstate; 876 FLVMetaParserState pstate;
@@ -836,12 +887,14 @@ handleMetaBody(const unsigned char *data, size_t len,
836 handler.as_key_callback = &handleASKey; 887 handler.as_key_callback = &handleASKey;
837 handler.as_end_callback = &handleASEnd; 888 handler.as_end_callback = &handleASEnd;
838 889
839 while (len > 0 && parse_amf(&data, &len, &handler) == 0); 890 while (len > 0 && parse_amf (&data, &len, &handler) == 0)
891 ;
840 if (pstate.ret != 0) 892 if (pstate.ret != 0)
841 return 1; 893 return 1;
842 return 0; 894 return 0;
843} 895}
844 896
897
845static char *FLVAudioCodecs[] = { 898static char *FLVAudioCodecs[] = {
846 "Uncompressed", 899 "Uncompressed",
847 "ADPCM", 900 "ADPCM",
@@ -875,19 +928,21 @@ static char *FLVAudioSampleRates[] = {
875}; 928};
876 929
877static void 930static void
878handleAudioBody(const unsigned char *data, size_t len, 931handleAudioBody (const unsigned char *data, size_t len,
879 FLVStreamInfo *stinfo) 932 FLVStreamInfo *stinfo)
880{ 933{
881 stinfo->audioChannels = (*data & 0x01) + 1; 934 stinfo->audioChannels = (*data & 0x01) + 1;
882 stinfo->audioSampleBits = (*data & 0x02) >> 1; 935 stinfo->audioSampleBits = (*data & 0x02) >> 1;
883 stinfo->audioRate = (*data & 0x0C) >> 2; 936 stinfo->audioRate = (*data & 0x0C) >> 2;
884 stinfo->audioCodec = (*data & 0xF0) >> 4; 937 stinfo->audioCodec = (*data & 0xF0) >> 4;
885 if (stinfo->audioCodecStr != NULL) { 938 if (stinfo->audioCodecStr != NULL)
886 free(stinfo->audioCodecStr); 939 {
940 free (stinfo->audioCodecStr);
887 stinfo->audioCodecStr = NULL; 941 stinfo->audioCodecStr = NULL;
888 } 942 }
889} 943}
890 944
945
891static char *FLVVideoCodecs[] = { 946static char *FLVVideoCodecs[] = {
892 NULL, 947 NULL,
893 NULL, 948 NULL,
@@ -911,8 +966,8 @@ static int sorenson_predefined_res[][2] = {
911}; 966};
912 967
913static void 968static void
914handleVideoBody(const unsigned char *data, size_t len, 969handleVideoBody (const unsigned char *data, size_t len,
915 FLVStreamInfo *stinfo) 970 FLVStreamInfo *stinfo)
916{ 971{
917 int codecId, frameType; 972 int codecId, frameType;
918 973
@@ -921,84 +976,94 @@ handleVideoBody(const unsigned char *data, size_t len,
921 data++; 976 data++;
922 977
923 /* try to get video dimensions */ 978 /* try to get video dimensions */
924 switch (codecId) { 979 switch (codecId)
925 case 0x02: /* Sorenson */ 980 {
926 if (len < 9) 981 case 0x02: /* Sorenson */
927 break; 982 if (len < 9)
928 if (frameType == 1) {
929 int start_code = (data[0] << 9) | (data[1] << 1) | ((data[2] >> 7)&0x1);
930 int version = (data[2] & 0x7C) >> 2;
931 int frame_size = ((data[3] & 0x03) << 1) | (data[4] >> 7);
932 if (start_code != 0x00000001)
933 break;
934 if (!(version == 0 || version == 1))
935 break;
936 if (frame_size == 0) {
937 stinfo->videoWidth = ((data[4] & 0x7F) >> 1) | (data[5] >> 7);
938 stinfo->videoHeight = ((data[5] & 0x7F) >> 1) | (data[6] >> 7);
939 }
940 else if (frame_size == 1) {
941 stinfo->videoWidth = ((data[4] & 0x7F) << 9) | (data[5] << 1) |
942 (data[6] >> 7);
943 stinfo->videoHeight = ((data[6] & 0x7F) << 9) | (data[7] << 1) |
944 (data[8] >> 7);
945 }
946 else {
947 stinfo->videoWidth = sorenson_predefined_res[frame_size][0];
948 stinfo->videoHeight = sorenson_predefined_res[frame_size][1];
949 }
950 }
951 break; 983 break;
952 case 0x03: /* ScreenVideo */ 984 if (frameType == 1)
953 if (len < 5) 985 {
986 int start_code = (data[0] << 9) | (data[1] << 1) | ((data[2] >> 7) & 0x1);
987 int version = (data[2] & 0x7C) >> 2;
988 int frame_size = ((data[3] & 0x03) << 1) | (data[4] >> 7);
989 if (start_code != 0x00000001)
954 break; 990 break;
955 stinfo->videoWidth = readInt16(&data) & 0x0FFF; 991 if (! ((version == 0) || (version == 1) ))
956 stinfo->videoHeight = readInt16(&data) & 0x0FFF; 992 break;
993 if (frame_size == 0)
994 {
995 stinfo->videoWidth = ((data[4] & 0x7F) >> 1) | (data[5] >> 7);
996 stinfo->videoHeight = ((data[5] & 0x7F) >> 1) | (data[6] >> 7);
997 }
998 else if (frame_size == 1)
999 {
1000 stinfo->videoWidth = ((data[4] & 0x7F) << 9) | (data[5] << 1)
1001 | (data[6] >> 7);
1002 stinfo->videoHeight = ((data[6] & 0x7F) << 9) | (data[7] << 1)
1003 | (data[8] >> 7);
1004 }
1005 else
1006 {
1007 stinfo->videoWidth = sorenson_predefined_res[frame_size][0];
1008 stinfo->videoHeight = sorenson_predefined_res[frame_size][1];
1009 }
1010 }
1011 break;
1012 case 0x03: /* ScreenVideo */
1013 if (len < 5)
957 break; 1014 break;
958 case 0x04: /* On2 VP6 */ 1015 stinfo->videoWidth = readInt16 (&data) & 0x0FFF;
959 case 0x05: 1016 stinfo->videoHeight = readInt16 (&data) & 0x0FFF;
1017 break;
1018 case 0x04: /* On2 VP6 */
1019 case 0x05:
960 { 1020 {
961 unsigned char dim_adj; 1021 unsigned char dim_adj;
962 if (len < 10) 1022 if (len < 10)
963 break; 1023 break;
964 dim_adj = *data++; 1024 dim_adj = *data++;
965 if ((frameType == 1) && ((data[0] & 0x80) == 0)) { 1025 if ((frameType == 1) && ((data[0] & 0x80) == 0))
1026 {
966 /* see ffmpeg vp6 decoder */ 1027 /* see ffmpeg vp6 decoder */
967 int separated_coeff = data[0] & 0x01; 1028 int separated_coeff = data[0] & 0x01;
968 int filter_header = data[1] & 0x06; 1029 int filter_header = data[1] & 0x06;
969 /*int interlaced = data[1] & 0x01; TODO: used in flv ever? */ 1030 /*int interlaced = data[1] & 0x01; TODO: used in flv ever? */
970 if (separated_coeff || !filter_header) { 1031 if (separated_coeff || ! filter_header)
1032 {
971 data += 2; 1033 data += 2;
972 } 1034 }
973 /* XXX encoded/displayed dimensions might vary, but which are the 1035 /* XXX encoded/displayed dimensions might vary, but which are the
974 * right ones? */ 1036 * right ones? */
975 stinfo->videoWidth = (data[3]*16) - (dim_adj>>4); 1037 stinfo->videoWidth = (data[3] * 16) - (dim_adj >> 4);
976 stinfo->videoHeight = (data[2]*16) - (dim_adj&0x0F); 1038 stinfo->videoHeight = (data[2] * 16) - (dim_adj & 0x0F);
977 } 1039 }
978 break; 1040 break;
979 } 1041 }
980 default: 1042 default:
981 break; 1043 break;
982 } 1044 }
983 1045
984 stinfo->videoCodec = codecId; 1046 stinfo->videoCodec = codecId;
985 if (stinfo->videoCodecStr != NULL) { 1047 if (stinfo->videoCodecStr != NULL)
986 free(stinfo->videoCodecStr); 1048 {
1049 free (stinfo->videoCodecStr);
987 stinfo->videoCodecStr = NULL; 1050 stinfo->videoCodecStr = NULL;
988 } 1051 }
989} 1052}
990 1053
991static int readFLVTag(const unsigned char **data, 1054
992 const unsigned char *end, 1055static int
993 FLVStreamInfo *stinfo, 1056readFLVTag (const unsigned char **data,
994 EXTRACTOR_MetaDataProcessor proc, 1057 const unsigned char *end,
995 void *proc_cls) 1058 FLVStreamInfo *stinfo,
1059 EXTRACTOR_MetaDataProcessor proc,
1060 void *proc_cls)
996{ 1061{
997 const unsigned char *ptr = *data; 1062 const unsigned char *ptr = *data;
998 FLVTagHeader header; 1063 FLVTagHeader header;
999 int ret = 0; 1064 int ret = 0;
1000 1065
1001 if (readFLVTagHeader(&ptr, end, &header) == -1) 1066 if (readFLVTagHeader (&ptr, end, &header) == -1)
1002 return -1; 1067 return -1;
1003 1068
1004 if ((ptr + header.bodyLength) > end) 1069 if ((ptr + header.bodyLength) > end)
@@ -1006,17 +1071,17 @@ static int readFLVTag(const unsigned char **data,
1006 1071
1007 switch (header.type) 1072 switch (header.type)
1008 { 1073 {
1009 case FLV_TAG_TYPE_AUDIO: 1074 case FLV_TAG_TYPE_AUDIO:
1010 handleAudioBody(ptr, header.bodyLength, stinfo); 1075 handleAudioBody (ptr, header.bodyLength, stinfo);
1011 break; 1076 break;
1012 case FLV_TAG_TYPE_VIDEO: 1077 case FLV_TAG_TYPE_VIDEO:
1013 handleVideoBody(ptr, header.bodyLength, stinfo); 1078 handleVideoBody (ptr, header.bodyLength, stinfo);
1014 break; 1079 break;
1015 case FLV_TAG_TYPE_META: 1080 case FLV_TAG_TYPE_META:
1016 ret = handleMetaBody(ptr, header.bodyLength, stinfo, proc, proc_cls); 1081 ret = handleMetaBody (ptr, header.bodyLength, stinfo, proc, proc_cls);
1017 break; 1082 break;
1018 default: 1083 default:
1019 break; 1084 break;
1020 } 1085 }
1021 1086
1022 ptr += header.bodyLength; 1087 ptr += header.bodyLength;
@@ -1024,129 +1089,149 @@ static int readFLVTag(const unsigned char **data,
1024 return ret; 1089 return ret;
1025} 1090}
1026 1091
1092
1027#define MAX_FLV_FORMAT_LINE 80 1093#define MAX_FLV_FORMAT_LINE 80
1028static char * printVideoFormat(FLVStreamInfo *stinfo) 1094static char *
1095printVideoFormat (FLVStreamInfo *stinfo)
1029{ 1096{
1030 char s[MAX_FLV_FORMAT_LINE+1]; 1097 char s[MAX_FLV_FORMAT_LINE + 1];
1031 int n; 1098 int n;
1032 size_t len = MAX_FLV_FORMAT_LINE; 1099 size_t len = MAX_FLV_FORMAT_LINE;
1033 1100
1034 n = 0; 1101 n = 0;
1035 /* some files seem to specify only the width or the height, print '?' for 1102 /* some files seem to specify only the width or the height, print '?' for
1036 * the unknown dimension */ 1103 * the unknown dimension */
1037 if (stinfo->videoWidth != -1 || stinfo->videoHeight != -1) { 1104 if ((stinfo->videoWidth != -1) || (stinfo->videoHeight != -1))
1038 if (n < len) { 1105 {
1106 if (n < len)
1107 {
1039 if (stinfo->videoWidth != -1) 1108 if (stinfo->videoWidth != -1)
1040 n += snprintf(s+n, len-n, "%d", stinfo->videoWidth); 1109 n += snprintf (s + n, len - n, "%d", stinfo->videoWidth);
1041 else 1110 else
1042 n += snprintf(s+n, len-n, "?"); 1111 n += snprintf (s + n, len - n, "?");
1043 } 1112 }
1044 1113
1045 if (n < len) { 1114 if (n < len)
1115 {
1046 if (stinfo->videoHeight != -1) 1116 if (stinfo->videoHeight != -1)
1047 n += snprintf(s+n, len-n, "x%d", stinfo->videoHeight); 1117 n += snprintf (s + n, len - n, "x%d", stinfo->videoHeight);
1048 else 1118 else
1049 n += snprintf(s+n, len-n, "x?"); 1119 n += snprintf (s + n, len - n, "x?");
1050 } 1120 }
1051 } 1121 }
1052 1122
1053 if (stinfo->videoFrameRate != 0.0 && n < len) { 1123 if ((stinfo->videoFrameRate != 0.0) && (n < len))
1124 {
1054 if (n > 0) 1125 if (n > 0)
1055 n += snprintf(s+n, len-n, ", "); 1126 n += snprintf (s + n, len - n, ", ");
1056 if (n < len) 1127 if (n < len)
1057 n += snprintf(s+n, len-n, "%0.2f fps", stinfo->videoFrameRate); 1128 n += snprintf (s + n, len - n, "%0.2f fps", stinfo->videoFrameRate);
1058 } 1129 }
1059 1130
1060 if (stinfo->videoCodec > -1 && stinfo->videoCodec < 8 && 1131 if ((stinfo->videoCodec > -1) && (stinfo->videoCodec < 8) &&
1061 FLVVideoCodecs[stinfo->videoCodec] != NULL && n < len) { 1132 (FLVVideoCodecs[stinfo->videoCodec] != NULL) && (n < len) )
1133 {
1062 if (n > 0) 1134 if (n > 0)
1063 n += snprintf(s+n, len-n, ", "); 1135 n += snprintf (s + n, len - n, ", ");
1064 if (n < len) 1136 if (n < len)
1065 n += snprintf(s+n, len-n, "%s", FLVVideoCodecs[stinfo->videoCodec]); 1137 n += snprintf (s + n, len - n, "%s", FLVVideoCodecs[stinfo->videoCodec]);
1066 } 1138 }
1067 else if (stinfo->videoCodecStr != NULL && n < len) { 1139 else if ((stinfo->videoCodecStr != NULL) && (n < len))
1140 {
1068 if (n > 0) 1141 if (n > 0)
1069 n += snprintf(s+n, len-n, ", "); 1142 n += snprintf (s + n, len - n, ", ");
1070 if (n < len) 1143 if (n < len)
1071 n += snprintf(s+n, len-n, "%s", stinfo->videoCodecStr); 1144 n += snprintf (s + n, len - n, "%s", stinfo->videoCodecStr);
1072 } 1145 }
1073 1146
1074 if (stinfo->videoDataRate != 0.0 && n < len) { 1147 if ((stinfo->videoDataRate != 0.0) && (n < len))
1148 {
1075 if (n > 0) 1149 if (n > 0)
1076 n += snprintf(s+n, len-n, ", "); 1150 n += snprintf (s + n, len - n, ", ");
1077 if (n < len) 1151 if (n < len)
1078 n += snprintf(s+n, len-n, "%.4f kbps", stinfo->videoDataRate); 1152 n += snprintf (s + n, len - n, "%.4f kbps", stinfo->videoDataRate);
1079 } 1153 }
1080 1154
1081 if (n == 0) 1155 if (n == 0)
1082 return NULL; 1156 return NULL;
1083 return strdup(s); 1157 return strdup (s);
1084} 1158}
1085 1159
1086static char * printAudioFormat(FLVStreamInfo *stinfo) 1160
1161static char *
1162printAudioFormat (FLVStreamInfo *stinfo)
1087{ 1163{
1088 char s[MAX_FLV_FORMAT_LINE+1]; 1164 char s[MAX_FLV_FORMAT_LINE + 1];
1089 int n; 1165 int n;
1090 size_t len = MAX_FLV_FORMAT_LINE; 1166 size_t len = MAX_FLV_FORMAT_LINE;
1091 1167
1092 n = 0; 1168 n = 0;
1093 if ( (stinfo->audioRate != -1) && (n < len)) { 1169 if ( (stinfo->audioRate != -1) && (n < len))
1094 n += snprintf(s+n, len-n, "%s Hz", FLVAudioSampleRates[stinfo->audioRate]); 1170 {
1171 n += snprintf (s + n, len - n, "%s Hz",
1172 FLVAudioSampleRates[stinfo->audioRate]);
1095 } 1173 }
1096 1174
1097 if ((stinfo->audioSampleBits != -1) && (n < len)) { 1175 if ((stinfo->audioSampleBits != -1) && (n < len))
1176 {
1098 if (n > 0) 1177 if (n > 0)
1099 n += snprintf(s+n, len-n, ", "); 1178 n += snprintf (s + n, len - n, ", ");
1100 if (n < len) 1179 if (n < len)
1101 n += snprintf(s+n, len-n, "%s", 1180 n += snprintf (s + n, len - n, "%s",
1102 FLVAudioSampleSizes[stinfo->audioSampleBits]); 1181 FLVAudioSampleSizes[stinfo->audioSampleBits]);
1103 } 1182 }
1104 1183
1105 if ((stinfo->audioChannels != -1) && (n < len)) { 1184 if ((stinfo->audioChannels != -1) && (n < len))
1185 {
1106 if (n > 0) 1186 if (n > 0)
1107 n += snprintf(s+n, len-n, ", "); 1187 n += snprintf (s + n, len - n, ", ");
1108 if (n < len) { 1188 if (n < len)
1109 if (stinfo->audioChannels >= 1 && stinfo->audioChannels <= 2) 1189 {
1110 n += snprintf(s+n, len-n, "%s", 1190 if ((stinfo->audioChannels >= 1) && (stinfo->audioChannels <= 2))
1111 FLVAudioChannels[stinfo->audioChannels-1]); 1191 n += snprintf (s + n, len - n, "%s",
1192 FLVAudioChannels[stinfo->audioChannels - 1]);
1112 else 1193 else
1113 n += snprintf(s+n, len-n, "%d", 1194 n += snprintf (s + n, len - n, "%d",
1114 stinfo->audioChannels); 1195 stinfo->audioChannels);
1115 } 1196 }
1116 } 1197 }
1117 1198
1118 if ((stinfo->audioCodec > -1) && (stinfo->audioCodec < 12) && 1199 if ((stinfo->audioCodec > -1) && (stinfo->audioCodec < 12) &&
1119 (FLVAudioCodecs[stinfo->audioCodec] != NULL) && (n < len)) { 1200 (FLVAudioCodecs[stinfo->audioCodec] != NULL) && (n < len))
1201 {
1120 if (n > 0) 1202 if (n > 0)
1121 n += snprintf(s+n, len-n, ", "); 1203 n += snprintf (s + n, len - n, ", ");
1122 if (n < len) 1204 if (n < len)
1123 n += snprintf(s+n, len-n, "%s", FLVAudioCodecs[stinfo->audioCodec]); 1205 n += snprintf (s + n, len - n, "%s", FLVAudioCodecs[stinfo->audioCodec]);
1124 } 1206 }
1125 else if ((stinfo->audioCodecStr != NULL) && (n < len)) { 1207 else if ((stinfo->audioCodecStr != NULL) && (n < len))
1208 {
1126 if (n > 0) 1209 if (n > 0)
1127 n += snprintf(s+n, len-n, ", "); 1210 n += snprintf (s + n, len - n, ", ");
1128 if (n < len) 1211 if (n < len)
1129 n += snprintf(s+n, len-n, "%s", stinfo->audioCodecStr); 1212 n += snprintf (s + n, len - n, "%s", stinfo->audioCodecStr);
1130 } 1213 }
1131 1214
1132 if ((stinfo->audioDataRate != 0.0) && (n < len)) { 1215 if ((stinfo->audioDataRate != 0.0) && (n < len))
1216 {
1133 if (n > 0) 1217 if (n > 0)
1134 n += snprintf(s+n, len-n, ", "); 1218 n += snprintf (s + n, len - n, ", ");
1135 if (n < len) 1219 if (n < len)
1136 n += snprintf(s+n, len-n, "%.4f kbps", stinfo->audioDataRate); 1220 n += snprintf (s + n, len - n, "%.4f kbps", stinfo->audioDataRate);
1137 } 1221 }
1138 1222
1139 if (n == 0) 1223 if (n == 0)
1140 return NULL; 1224 return NULL;
1141 return strdup(s); 1225 return strdup (s);
1142} 1226}
1143 1227
1144int 1228
1229int
1145EXTRACTOR_flv_extract (const unsigned char *data, 1230EXTRACTOR_flv_extract (const unsigned char *data,
1146 size_t size, 1231 size_t size,
1147 EXTRACTOR_MetaDataProcessor proc, 1232 EXTRACTOR_MetaDataProcessor proc,
1148 void *proc_cls, 1233 void *proc_cls,
1149 const char *options) 1234 const char *options)
1150{ 1235{
1151 const unsigned char *ptr; 1236 const unsigned char *ptr;
1152 const unsigned char *end; 1237 const unsigned char *end;
@@ -1159,19 +1244,19 @@ EXTRACTOR_flv_extract (const unsigned char *data,
1159 ptr = data; 1244 ptr = data;
1160 end = ptr + size; 1245 end = ptr + size;
1161 1246
1162 if (readFLVHeader(&ptr, end, &header) == -1) 1247 if (readFLVHeader (&ptr, end, &header) == -1)
1163 return 0; 1248 return 0;
1164 1249
1165 if (memcmp(header.signature, FLV_SIGNATURE, 3) != 0) 1250 if (memcmp (header.signature, FLV_SIGNATURE, 3) != 0)
1166 return 0; 1251 return 0;
1167 1252
1168 if (0 != proc (proc_cls, 1253 if (0 != proc (proc_cls,
1169 "flv", 1254 "flv",
1170 EXTRACTOR_METATYPE_MIMETYPE, 1255 EXTRACTOR_METATYPE_MIMETYPE,
1171 EXTRACTOR_METAFORMAT_UTF8, 1256 EXTRACTOR_METAFORMAT_UTF8,
1172 "text/plain", 1257 "text/plain",
1173 "video/x-flv", 1258 "video/x-flv",
1174 strlen ("video/x-flv") + 1)) 1259 strlen ("video/x-flv") + 1))
1175 return 0; 1260 return 0;
1176 if (header.version != 1) 1261 if (header.version != 1)
1177 return 0; 1262 return 0;
@@ -1191,7 +1276,8 @@ EXTRACTOR_flv_extract (const unsigned char *data,
1191 stinfo.audioChannels = -1; 1276 stinfo.audioChannels = -1;
1192 stinfo.audioDataRate = 0.0; 1277 stinfo.audioDataRate = 0.0;
1193 ret = 0; 1278 ret = 0;
1194 while (ptr < end) { 1279 while (ptr < end)
1280 {
1195 if (-1 == (ret = readFLVTag (&ptr, end, &stinfo, proc, proc_cls))) 1281 if (-1 == (ret = readFLVTag (&ptr, end, &stinfo, proc, proc_cls)))
1196 break; 1282 break;
1197 if (readPreviousTagSize (&ptr, end, &prev_tag_size) == -1) 1283 if (readPreviousTagSize (&ptr, end, &prev_tag_size) == -1)
@@ -1201,35 +1287,35 @@ EXTRACTOR_flv_extract (const unsigned char *data,
1201 return 1; 1287 return 1;
1202 s = printVideoFormat (&stinfo); 1288 s = printVideoFormat (&stinfo);
1203 if (s != NULL) 1289 if (s != NULL)
1290 {
1291 if (0 != proc (proc_cls,
1292 "flv",
1293 EXTRACTOR_METATYPE_RESOURCE_TYPE,
1294 EXTRACTOR_METAFORMAT_UTF8,
1295 "text/plain",
1296 s,
1297 strlen (s) + 1))
1204 { 1298 {
1205 if (0 != proc (proc_cls,
1206 "flv",
1207 EXTRACTOR_METATYPE_RESOURCE_TYPE,
1208 EXTRACTOR_METAFORMAT_UTF8,
1209 "text/plain",
1210 s,
1211 strlen (s)+1))
1212 {
1213 free (s);
1214 return 1;
1215 }
1216 free (s); 1299 free (s);
1300 return 1;
1217 } 1301 }
1302 free (s);
1303 }
1218 s = printAudioFormat (&stinfo); 1304 s = printAudioFormat (&stinfo);
1219 if (s != NULL) 1305 if (s != NULL)
1306 {
1307 if (0 != proc (proc_cls,
1308 "flv",
1309 EXTRACTOR_METATYPE_RESOURCE_TYPE,
1310 EXTRACTOR_METAFORMAT_UTF8,
1311 "text/plain",
1312 s,
1313 strlen (s) + 1))
1220 { 1314 {
1221 if (0 != proc (proc_cls,
1222 "flv",
1223 EXTRACTOR_METATYPE_RESOURCE_TYPE,
1224 EXTRACTOR_METAFORMAT_UTF8,
1225 "text/plain",
1226 s,
1227 strlen (s)+1))
1228 {
1229 free (s);
1230 return 1;
1231 }
1232 free (s); 1315 free (s);
1316 return 1;
1233 } 1317 }
1318 free (s);
1319 }
1234 return 0; 1320 return 0;
1235} 1321}
diff --git a/src/plugins/old/mkv_extractor.c b/src/plugins/old/mkv_extractor.c
index 9e2f1f9..ff052dc 100644
--- a/src/plugins/old/mkv_extractor.c
+++ b/src/plugins/old/mkv_extractor.c
@@ -18,17 +18,21 @@
18 Boston, MA 02110-1301, USA. 18 Boston, MA 02110-1301, USA.
19 */ 19 */
20 20
21 /* 21/*
22 * Made by Gabriel Peixoto 22 * Made by Gabriel Peixoto
23 * Using AVInfo 1.x code. Copyright (c) 2004 George Shuklin. 23 * Using AVInfo 1.x code. Copyright (c) 2004 George Shuklin.
24 * 24 *
25 */ 25 */
26 26
27#include "platform.h" 27#include "platform.h"
28#include "extractor.h" 28#include "extractor.h"
29#include <stdint.h> 29#include <stdint.h>
30 30
31#define ADD(s,t) do { if (0 != (ret = proc (proc_cls, "mkv", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1))) goto EXIT; } while (0) 31#define ADD(s,t) do { if (0 != (ret = proc (proc_cls, "mkv", t, \
32 EXTRACTOR_METAFORMAT_UTF8, \
33 "text/plain", s, strlen (s) \
34 + 1))) goto EXIT; \
35} while (0)
32 36
33/** 37/**
34 * FIXME: document 38 * FIXME: document
@@ -98,27 +102,29 @@ enum
98 */ 102 */
99static size_t 103static size_t
100VINTparse (const unsigned char *buffer, size_t start, size_t end, 104VINTparse (const unsigned char *buffer, size_t start, size_t end,
101 int64_t * result, int flag) 105 int64_t *result, int flag)
102{ 106{
103 static const unsigned char mask[8] = { 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1 }; 107 static const unsigned char mask[8] = { 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2,
104 static const unsigned char imask[8] = { 0x7F, 0x3F, 0x1F, 0xF, 0x7, 0x3, 0x1, 00 }; 108 0x1 };
109 static const unsigned char imask[8] = { 0x7F, 0x3F, 0x1F, 0xF, 0x7, 0x3, 0x1,
110 00 };
105 int vint_width; 111 int vint_width;
106 unsigned int c; 112 unsigned int c;
107 int64_t temp; 113 int64_t temp;
108 unsigned char tempc; 114 unsigned char tempc;
109 115
110 if (end - start < 2) 116 if (end - start < 2)
111 return 0; /*ops */ 117 return 0; /*ops */
112 118
113 vint_width = 0; 119 vint_width = 0;
114 for (c = 0; c < 8; c++) 120 for (c = 0; c < 8; c++)
115 if (!(buffer[start] & mask[c])) 121 if (! (buffer[start] & mask[c]))
116 vint_width++; 122 vint_width++;
117 else 123 else
118 break; 124 break;
119 if ( (vint_width >= 8) || (vint_width + start + 1 >= end) ) 125 if ( (vint_width >= 8) || (vint_width + start + 1 >= end) )
120 return 0; 126 return 0;
121 127
122 *result = 0; 128 *result = 0;
123 for (c = 0; c < vint_width; c++) 129 for (c = 0; c < vint_width; c++)
124 { 130 {
@@ -139,7 +145,7 @@ VINTparse (const unsigned char *buffer, size_t start, size_t end,
139 */ 145 */
140static unsigned int 146static unsigned int
141elementRead (const unsigned char *buffer, size_t start, size_t end, 147elementRead (const unsigned char *buffer, size_t start, size_t end,
142 uint32_t *id, int64_t * size) 148 uint32_t *id, int64_t *size)
143{ 149{
144 int64_t tempID; 150 int64_t tempID;
145 int64_t tempsize; 151 int64_t tempsize;
@@ -147,12 +153,12 @@ elementRead (const unsigned char *buffer, size_t start, size_t end,
147 size_t size_offset; 153 size_t size_offset;
148 154
149 tempID = 0; 155 tempID = 0;
150 156
151 id_offset = VINTparse (buffer, start, end, &tempID, 0); 157 id_offset = VINTparse (buffer, start, end, &tempID, 0);
152 if (!id_offset) 158 if (! id_offset)
153 return 0; 159 return 0;
154 size_offset = VINTparse (buffer, start + id_offset, end, &tempsize, 1); 160 size_offset = VINTparse (buffer, start + id_offset, end, &tempsize, 1);
155 if (!size_offset) 161 if (! size_offset)
156 return 0; 162 return 0;
157 *id = (uint32_t) tempID; 163 *id = (uint32_t) tempID;
158 *size = tempsize; 164 *size = tempsize;
@@ -172,10 +178,11 @@ getInt (const unsigned char *buffer, size_t start, size_t size)
172 178
173 result = 0; 179 result = 0;
174 for (c = 1; c <= size; c++) 180 for (c = 1; c <= size; c++)
175 result += ((uint64_t)buffer[start + c - 1]) << (8 * (size - c)); 181 result += ((uint64_t) buffer[start + c - 1]) << (8 * (size - c));
176 return result; 182 return result;
177} 183}
178 184
185
179static float 186static float
180getFloat (const unsigned char *buffer, size_t start, size_t size) 187getFloat (const unsigned char *buffer, size_t start, size_t size)
181{ 188{
@@ -194,7 +201,8 @@ getFloat (const unsigned char *buffer, size_t start, size_t size)
194 return 0.0; 201 return 0.0;
195} 202}
196 203
197static const unsigned int MKV_Parse_list[] = { 204
205static const unsigned int MKV_Parse_list[] = {
198 /*Elements, containing requed information (sub-elements), see enum in mkv.h for values */ 206 /*Elements, containing requed information (sub-elements), see enum in mkv.h for values */
199 MKVID_Segment, 207 MKVID_Segment,
200 MKVID_Info, 208 MKVID_Info,
@@ -244,14 +252,14 @@ EXTRACTOR_mkv_extract (const unsigned char *data, size_t size,
244 if (NULL == start) 252 if (NULL == start)
245 return 0; 253 return 0;
246 p = start - data; 254 p = start - data;
247 255
248/*main loop*/ 256/*main loop*/
249 ret = 0; 257 ret = 0;
250 do 258 do
251 { 259 {
252 offs = elementRead (data, p, size, &eID, &eSize); 260 offs = elementRead (data, p, size, &eID, &eSize);
253 p += offs; 261 p += offs;
254 if (!offs || p >= size) 262 if (! offs || (p >= size))
255 break; 263 break;
256 if (MKVID_EBML == eID) 264 if (MKVID_EBML == eID)
257 { 265 {
@@ -262,8 +270,8 @@ EXTRACTOR_mkv_extract (const unsigned char *data, size_t size,
262 if (! is_mkv) 270 if (! is_mkv)
263 return 0; 271 return 0;
264 for (c = 0; c < sizeof (MKV_Parse_list) / sizeof (*MKV_Parse_list); c++) 272 for (c = 0; c < sizeof (MKV_Parse_list) / sizeof (*MKV_Parse_list); c++)
265 if (MKV_Parse_list[c] == eID) 273 if (MKV_Parse_list[c] == eID)
266 break; 274 break;
267 if (c < sizeof (MKV_Parse_list) / sizeof (*MKV_Parse_list)) 275 if (c < sizeof (MKV_Parse_list) / sizeof (*MKV_Parse_list))
268 continue; 276 continue;
269 277
@@ -272,7 +280,7 @@ EXTRACTOR_mkv_extract (const unsigned char *data, size_t size,
272 280
273 if ( (eSize == 4) || (eSize == 8) || (eSize == 1) || (eSize == 2)) 281 if ( (eSize == 4) || (eSize == 8) || (eSize == 1) || (eSize == 2))
274 value = getInt (data, p, eSize); 282 value = getInt (data, p, eSize);
275 283
276 switch (eID) 284 switch (eID)
277 { 285 {
278 case MKVID_TrackType: /*detect a stream type (video/audio/text) */ 286 case MKVID_TrackType: /*detect a stream type (video/audio/text) */
@@ -286,9 +294,9 @@ EXTRACTOR_mkv_extract (const unsigned char *data, size_t size,
286 have_audio = 1; 294 have_audio = 1;
287 break; 295 break;
288 case MKV_Track_subtitle: 296 case MKV_Track_subtitle:
289 break; 297 break;
290 case MKV_Track_subtitle_orig: 298 case MKV_Track_subtitle_orig:
291 break; 299 break;
292 } 300 }
293 break; 301 break;
294 case MKVID_DefaultDuration: 302 case MKVID_DefaultDuration:
@@ -298,11 +306,11 @@ EXTRACTOR_mkv_extract (const unsigned char *data, size_t size,
298 fps = 0; 306 fps = 0;
299 break; 307 break;
300 case MKVID_Language: 308 case MKVID_Language:
301 snprintf (buffer, 309 snprintf (buffer,
302 sizeof (buffer), 310 sizeof (buffer),
303 "%.*s", 311 "%.*s",
304 (int) eSize, 312 (int) eSize,
305 data + p); 313 data + p);
306 ADD (buffer, EXTRACTOR_METATYPE_LANGUAGE); 314 ADD (buffer, EXTRACTOR_METATYPE_LANGUAGE);
307 break; 315 break;
308 case MKVID_CodecName: 316 case MKVID_CodecName:
@@ -340,10 +348,10 @@ EXTRACTOR_mkv_extract (const unsigned char *data, size_t size,
340 if (eSize > MAX_STRING_SIZE) 348 if (eSize > MAX_STRING_SIZE)
341 break; 349 break;
342 snprintf (buffer, 350 snprintf (buffer,
343 sizeof (buffer), 351 sizeof (buffer),
344 "%.*s", 352 "%.*s",
345 (int) eSize, 353 (int) eSize,
346 (const char*) data + p); 354 (const char*) data + p);
347 ADD (buffer, EXTRACTOR_METATYPE_TITLE); 355 ADD (buffer, EXTRACTOR_METATYPE_TITLE);
348 break; 356 break;
349 default: 357 default:
@@ -354,20 +362,20 @@ EXTRACTOR_mkv_extract (const unsigned char *data, size_t size,
354 while (1); 362 while (1);
355 363
356 snprintf (buffer, 364 snprintf (buffer,
357 sizeof (buffer), 365 sizeof (buffer),
358 "%u s (%s%s%s)", 366 "%u s (%s%s%s)",
359 (unsigned int) (duration / 1e+9 * (float) timescale), 367 (unsigned int) (duration / 1e+9 * (float) timescale),
360 (have_audio ? "audio" : ""), 368 (have_audio ? "audio" : ""),
361 ((have_audio && have_video) ? "/" : ""), 369 ((have_audio && have_video) ? "/" : ""),
362 (have_video ? "video" : "")); 370 (have_video ? "video" : ""));
363 if ( (have_audio || have_video) && (duration >= 0.0) ) 371 if ( (have_audio || have_video) && (duration >= 0.0) )
364 ADD (buffer, EXTRACTOR_METATYPE_DURATION); 372 ADD (buffer, EXTRACTOR_METATYPE_DURATION);
365 if ( (value_width != 0) && (value_height != 0) ) 373 if ( (value_width != 0) && (value_height != 0) )
366 { 374 {
367 snprintf (buffer, 375 snprintf (buffer,
368 sizeof(buffer), 376 sizeof(buffer),
369 "%ux%u", 377 "%ux%u",
370 value_width, value_height); 378 value_width, value_height);
371 ADD (buffer, EXTRACTOR_METATYPE_IMAGE_DIMENSIONS); 379 ADD (buffer, EXTRACTOR_METATYPE_IMAGE_DIMENSIONS);
372 } 380 }
373 381
@@ -375,34 +383,34 @@ EXTRACTOR_mkv_extract (const unsigned char *data, size_t size,
375 { 383 {
376 if ( (fps != 0) && (bit_depth != 0) ) 384 if ( (fps != 0) && (bit_depth != 0) )
377 snprintf (buffer, 385 snprintf (buffer,
378 sizeof (buffer), 386 sizeof (buffer),
379 "%.*s (%u fps, %u bit)", 387 "%.*s (%u fps, %u bit)",
380 codec_strlen, 388 codec_strlen,
381 codec, 389 codec,
382 fps, 390 fps,
383 bit_depth); 391 bit_depth);
384 else if (fps != 0) 392 else if (fps != 0)
385 snprintf (buffer, 393 snprintf (buffer,
386 sizeof (buffer), 394 sizeof (buffer),
387 "%.*s (%u fps)", 395 "%.*s (%u fps)",
388 codec_strlen, 396 codec_strlen,
389 codec, 397 codec,
390 fps); 398 fps);
391 else if (bit_depth != 0) 399 else if (bit_depth != 0)
392 snprintf (buffer, 400 snprintf (buffer,
393 sizeof (buffer), 401 sizeof (buffer),
394 "%.*s (%u bit)", 402 "%.*s (%u bit)",
395 codec_strlen, 403 codec_strlen,
396 codec, 404 codec,
397 bit_depth); 405 bit_depth);
398 else 406 else
399 snprintf (buffer, 407 snprintf (buffer,
400 sizeof (buffer), 408 sizeof (buffer),
401 "%.*s", 409 "%.*s",
402 codec_strlen, 410 codec_strlen,
403 codec); 411 codec);
404 ADD (buffer, 412 ADD (buffer,
405 EXTRACTOR_METATYPE_FORMAT); 413 EXTRACTOR_METATYPE_FORMAT);
406 } 414 }
407EXIT: 415EXIT:
408 return ret; 416 return ret;
diff --git a/src/plugins/old/mp3_extractor.c b/src/plugins/old/mp3_extractor.c
index 99afd15..076b427 100644
--- a/src/plugins/old/mp3_extractor.c
+++ b/src/plugins/old/mp3_extractor.c
@@ -91,21 +91,21 @@ static const int freq_table[4][3] = {
91 {48000, 24000, 12000}, 91 {48000, 24000, 12000},
92 {32000, 16000, 8000} 92 {32000, 16000, 8000}
93}; 93};
94static const char * const channel_modes[4] = { 94static const char *const channel_modes[4] = {
95 gettext_noop("stereo"), 95 gettext_noop ("stereo"),
96 gettext_noop("joint stereo"), 96 gettext_noop ("joint stereo"),
97 gettext_noop("dual channel"), 97 gettext_noop ("dual channel"),
98 gettext_noop("mono") 98 gettext_noop ("mono")
99}; 99};
100static const char * const mpeg_versions[3] = { 100static const char *const mpeg_versions[3] = {
101 gettext_noop("MPEG-1"), 101 gettext_noop ("MPEG-1"),
102 gettext_noop("MPEG-2"), 102 gettext_noop ("MPEG-2"),
103 gettext_noop("MPEG-2.5") 103 gettext_noop ("MPEG-2.5")
104}; 104};
105static const char * const layer_names[3] = { 105static const char *const layer_names[3] = {
106 gettext_noop("Layer I"), 106 gettext_noop ("Layer I"),
107 gettext_noop("Layer II"), 107 gettext_noop ("Layer II"),
108 gettext_noop("Layer III") 108 gettext_noop ("Layer III")
109}; 109};
110 110
111 111
@@ -113,7 +113,10 @@ static const char * const layer_names[3] = {
113#define SYSERR 1 113#define SYSERR 1
114#define INVALID_ID3 2 114#define INVALID_ID3 2
115 115
116#define ADDR(s,t) do { if (0 != proc (proc_cls, "mp3", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1)) return 1; } while (0) 116#define ADDR(s,t) do { if (0 != proc (proc_cls, "mp3", t, \
117 EXTRACTOR_METAFORMAT_UTF8, "text/plain", \
118 s, strlen (s) + 1)) return 1; \
119} while (0)
117 120
118struct mp3_state 121struct mp3_state
119{ 122{
@@ -163,6 +166,7 @@ EXTRACTOR_mp3_init_state_method ()
163 return state; 166 return state;
164} 167}
165 168
169
166static int 170static int
167EXTRACTOR_mp3_discard_state_method (struct mp3_state *state) 171EXTRACTOR_mp3_discard_state_method (struct mp3_state *state)
168{ 172{
@@ -173,51 +177,58 @@ EXTRACTOR_mp3_discard_state_method (struct mp3_state *state)
173 return 1; 177 return 1;
174} 178}
175 179
180
176static int 181static int
177calculate_frame_statistics_and_maybe_report_it (struct EXTRACTOR_PluginList *plugin, 182calculate_frame_statistics_and_maybe_report_it (struct
178 struct mp3_state *state, EXTRACTOR_MetaDataProcessor proc, void *proc_cls) 183 EXTRACTOR_PluginList *plugin,
184 struct mp3_state *state,
185 EXTRACTOR_MetaDataProcessor proc,
186 void *proc_cls)
179{ 187{
180 int length; 188 int length;
181 char format[512]; 189 char format[512];
182 190
183 if (((double) state->number_of_valid_frames / (double) state->number_of_frames) < 0.8 || 191 if ((((double) state->number_of_valid_frames
184 state->number_of_valid_frames <= 2) 192 / (double) state->number_of_frames) < 0.8) ||
193 (state->number_of_valid_frames <= 2) )
185 /* Unlikely to be an mp3 file */ 194 /* Unlikely to be an mp3 file */
186 return 0; 195 return 0;
187 ADDR ("audio/mpeg", EXTRACTOR_METATYPE_MIMETYPE); 196 ADDR ("audio/mpeg", EXTRACTOR_METATYPE_MIMETYPE);
188 state->avg_bps = state->avg_bps / state->number_of_valid_frames; 197 state->avg_bps = state->avg_bps / state->number_of_valid_frames;
189 if (state->sample_rate > 0) 198 if (state->sample_rate > 0)
190 length = 1152 * state->number_of_valid_frames / state->sample_rate; 199 length = 1152 * state->number_of_valid_frames / state->sample_rate;
191 else if (state->avg_bps > 0 || state->bitrate > 0) 200 else if ((state->avg_bps > 0) || (state->bitrate > 0))
192 length = plugin->fsize / (state->avg_bps ? state->avg_bps : state->bitrate ? state->bitrate : 1) / 125; 201 length = plugin->fsize / (state->avg_bps ? state->avg_bps : state->bitrate ?
202 state->bitrate : 1) / 125;
193 else 203 else
194 length = 0; 204 length = 0;
195 205
196 ADDR (mpeg_versions[state->mpeg_ver - 1], EXTRACTOR_METATYPE_FORMAT_VERSION); 206 ADDR (mpeg_versions[state->mpeg_ver - 1], EXTRACTOR_METATYPE_FORMAT_VERSION);
197 snprintf (format, 207 snprintf (format,
198 sizeof (format), 208 sizeof (format),
199 "%s %s audio, %d kbps (%s), %d Hz, %s, %s, %s", 209 "%s %s audio, %d kbps (%s), %d Hz, %s, %s, %s",
200 mpeg_versions[state->mpeg_ver - 1], 210 mpeg_versions[state->mpeg_ver - 1],
201 layer_names[state->layer - 1], 211 layer_names[state->layer - 1],
202 state->avg_bps, 212 state->avg_bps,
203 state->vbr_flag ? _("VBR") : _("CBR"), 213 state->vbr_flag ? _ ("VBR") : _ ("CBR"),
204 state->sample_rate, 214 state->sample_rate,
205 channel_modes[state->ch], 215 channel_modes[state->ch],
206 state->copyright_flag ? _("copyright") : _("no copyright"), 216 state->copyright_flag ? _ ("copyright") : _ ("no copyright"),
207 state->original_flag ? _("original") : _("copy") ); 217 state->original_flag ? _ ("original") : _ ("copy") );
208 218
209 ADDR (format, EXTRACTOR_METATYPE_RESOURCE_TYPE); 219 ADDR (format, EXTRACTOR_METATYPE_RESOURCE_TYPE);
210 snprintf (format, 220 snprintf (format,
211 sizeof (format), "%dm%02d", 221 sizeof (format), "%dm%02d",
212 length / 60, length % 60); 222 length / 60, length % 60);
213 ADDR (format, EXTRACTOR_METATYPE_DURATION); 223 ADDR (format, EXTRACTOR_METATYPE_DURATION);
214 return 0; 224 return 0;
215} 225}
216 226
227
217int 228int
218EXTRACTOR_mp3_extract_method (struct EXTRACTOR_PluginList *plugin, 229EXTRACTOR_mp3_extract_method (struct EXTRACTOR_PluginList *plugin,
219 EXTRACTOR_MetaDataProcessor proc, 230 EXTRACTOR_MetaDataProcessor proc,
220 void *proc_cls) 231 void *proc_cls)
221{ 232{
222 int64_t offset = 0; 233 int64_t offset = 0;
223 int64_t round_offset; 234 int64_t round_offset;
@@ -255,24 +266,29 @@ EXTRACTOR_mp3_extract_method (struct EXTRACTOR_PluginList *plugin,
255 while (1) 266 while (1)
256 { 267 {
257 pl_seek (plugin, offset, SEEK_SET); 268 pl_seek (plugin, offset, SEEK_SET);
258 read_result = pl_read (plugin, &data, 1024*1024); 269 read_result = pl_read (plugin, &data, 1024 * 1024);
259 if (read_result < 4) 270 if (read_result < 4)
260 { 271 {
261 calculate_frame_statistics_and_maybe_report_it (plugin, state, proc, proc_cls); 272 calculate_frame_statistics_and_maybe_report_it (plugin, state, proc,
273 proc_cls);
262 return EXTRACTOR_mp3_discard_state_method (state); 274 return EXTRACTOR_mp3_discard_state_method (state);
263 } 275 }
264 for (i = 0; i + 3 < read_result; i++) 276 for (i = 0; i + 3 < read_result; i++)
265 if (((*((uint32_t *) &data[i])) & MPA_SYNC_MASK_MEM) == MPA_SYNC_MASK_MEM) 277 if (((*((uint32_t *) &data[i])) & MPA_SYNC_MASK_MEM) ==
278 MPA_SYNC_MASK_MEM)
266 break; 279 break;
267 if (i + 3 >= 1024*1024) 280 if (i + 3 >= 1024 * 1024)
268 offset += read_result - 3; 281 offset += read_result - 3;
269 else 282 else
270 break; 283 break;
271 if (offset > round_offset + 31*1024*1024) 284 if (offset > round_offset + 31 * 1024 * 1024)
272 { 285 {
273 if (((state->number_of_valid_frames > 2) && ((double) state->number_of_valid_frames / (double) state->number_of_frames) < 0.8)) 286 if (((state->number_of_valid_frames > 2) &&
287 ( ((double) state->number_of_valid_frames
288 / (double) state->number_of_frames) < 0.8) ))
274 { 289 {
275 calculate_frame_statistics_and_maybe_report_it (plugin, state, proc, proc_cls); 290 calculate_frame_statistics_and_maybe_report_it (plugin, state, proc,
291 proc_cls);
276 } 292 }
277 return EXTRACTOR_mp3_discard_state_method (state); 293 return EXTRACTOR_mp3_discard_state_method (state);
278 } 294 }
@@ -280,11 +296,12 @@ EXTRACTOR_mp3_extract_method (struct EXTRACTOR_PluginList *plugin,
280 pl_seek (plugin, offset + i, SEEK_SET); 296 pl_seek (plugin, offset + i, SEEK_SET);
281 if (4 != pl_read (plugin, &data, 4)) 297 if (4 != pl_read (plugin, &data, 4))
282 { 298 {
283 calculate_frame_statistics_and_maybe_report_it (plugin, state, proc, proc_cls); 299 calculate_frame_statistics_and_maybe_report_it (plugin, state, proc,
300 proc_cls);
284 return EXTRACTOR_mp3_discard_state_method (state); 301 return EXTRACTOR_mp3_discard_state_method (state);
285 } 302 }
286 state->header = (data[0] << 24) | (data[1] << 16) | 303 state->header = (data[0] << 24) | (data[1] << 16)
287 (data[2] << 8) | data[3]; 304 | (data[2] << 8) | data[3];
288 if ((state->header & MPA_SYNC_MASK) == MPA_SYNC_MASK) 305 if ((state->header & MPA_SYNC_MASK) == MPA_SYNC_MASK)
289 { 306 {
290 state->state = MP3_READING_FRAME; 307 state->state = MP3_READING_FRAME;
@@ -336,8 +353,8 @@ EXTRACTOR_mp3_extract_method (struct EXTRACTOR_PluginList *plugin,
336 idx_num = (mpeg_ver - 1) * 3 + layer - 1; 353 idx_num = (mpeg_ver - 1) * 3 + layer - 1;
337 else 354 else
338 idx_num = 2 + layer; 355 idx_num = 2 + layer;
339 bitrate = 1000 * bitrate_table[(state->header >> MPA_BITRATE_SHIFT) & 356 bitrate = 1000 * bitrate_table[(state->header >> MPA_BITRATE_SHIFT)
340 MPA_BITRATE_MASK][idx_num]; 357 & MPA_BITRATE_MASK][idx_num];
341 if (bitrate < 0) 358 if (bitrate < 0)
342 { 359 {
343 /*error in header */ 360 /*error in header */
@@ -345,8 +362,8 @@ EXTRACTOR_mp3_extract_method (struct EXTRACTOR_PluginList *plugin,
345 offset += 1; 362 offset += 1;
346 break; 363 break;
347 } 364 }
348 sample_rate = freq_table[(state->header >> MPA_FREQ_SHIFT) & 365 sample_rate = freq_table[(state->header >> MPA_FREQ_SHIFT)
349 MPA_FREQ_MASK][mpeg_ver - 1]; 366 & MPA_FREQ_MASK][mpeg_ver - 1];
350 if (sample_rate <= 0) 367 if (sample_rate <= 0)
351 { 368 {
352 /*error in header */ 369 /*error in header */
@@ -358,9 +375,13 @@ EXTRACTOR_mp3_extract_method (struct EXTRACTOR_PluginList *plugin,
358 copyright_flag = (state->header >> MPA_COPYRIGHT_SHIFT) & 0x1; 375 copyright_flag = (state->header >> MPA_COPYRIGHT_SHIFT) & 0x1;
359 original_flag = (state->header >> MPA_ORIGINAL_SHIFT) & 0x1; 376 original_flag = (state->header >> MPA_ORIGINAL_SHIFT) & 0x1;
360 if (layer == LAYER_1) 377 if (layer == LAYER_1)
361 frame_size = (12 * bitrate / sample_rate + ((state->header >> MPA_PADDING_SHIFT) & 0x1)) * 4; 378 frame_size = (12 * bitrate / sample_rate + ((state->header
379 >> MPA_PADDING_SHIFT)
380 & 0x1)) * 4;
362 else 381 else
363 frame_size = 144 * bitrate / sample_rate + ((state->header >> MPA_PADDING_SHIFT) & 0x1); 382 frame_size = 144 * bitrate / sample_rate + ((state->header
383 >> MPA_PADDING_SHIFT)
384 & 0x1);
364 if (frame_size < 8) 385 if (frame_size < 8)
365 { 386 {
366 /*error in header */ 387 /*error in header */
@@ -390,4 +411,5 @@ EXTRACTOR_mp3_extract_method (struct EXTRACTOR_PluginList *plugin,
390 return 1; 411 return 1;
391} 412}
392 413
414
393/* end of mp3_extractor.c */ 415/* end of mp3_extractor.c */
diff --git a/src/plugins/old/pack.c b/src/plugins/old/pack.c
index 968cf67..4f9e19d 100644
--- a/src/plugins/old/pack.c
+++ b/src/plugins/old/pack.c
@@ -27,7 +27,7 @@ MODIFICATIONS.
27#include "platform.h" 27#include "platform.h"
28#include "pack.h" 28#include "pack.h"
29 29
30#if !(defined(_WIN32) && defined(cbNDRContext)) 30#if ! (defined(_WIN32) && defined(cbNDRContext))
31typedef unsigned char byte; 31typedef unsigned char byte;
32#endif 32#endif
33typedef unsigned short half; 33typedef unsigned short half;
@@ -37,11 +37,10 @@ typedef signed short shalf;
37typedef signed int sword; 37typedef signed int sword;
38 38
39 39
40
41int 40int
42EXTRACTOR_common_cat_unpack (const void *buf, 41EXTRACTOR_common_cat_unpack (const void *buf,
43 const char *fmt, 42 const char *fmt,
44 ...) 43 ...)
45{ 44{
46 va_list ap; 45 va_list ap;
47 word maxlen, len, *wordp; 46 word maxlen, len, *wordp;
@@ -63,283 +62,282 @@ EXTRACTOR_common_cat_unpack (const void *buf,
63 va_start (ap, fmt); 62 va_start (ap, fmt);
64 63
65 while (*fmt) 64 while (*fmt)
65 {
66 nreps = 1;
67
68 if (isdigit ( (unsigned char) *fmt))
66 { 69 {
67 nreps = 1; 70 /* We use cp instead of format to keep the 'const' qualifier of fmt */
71 nreps = strtoul (fmt, &cp, 0);
72 fmt = cp;
73 if (*fmt == 'a')
74 isnonprefixed = 0;
75 }
68 76
69 if (isdigit ( (unsigned char) *fmt)) 77 switch (*fmt)
78 {
79 case 'B':
80 case 'b':
81 bytep = va_arg (ap, byte *);
82 for (i = 0; i < nreps; ++i)
83 {
84 *bytep = *bp++;
85 ++bytep;
86 npacked += 1;
87 }
88 break;
89
90
91 case 'h':
92 halfp = va_arg (ap, half *);
93 for (i = 0; i < nreps; ++i)
94 {
95 *halfp = *bp++;
96 *halfp |= *bp++ << 8;
97 ++halfp;
98 npacked += 2;
99 }
100 break;
101
102 case 'H':
103 halfp = va_arg (ap, half *);
104 for (i = 0; i < nreps; ++i)
105 {
106 *halfp = *bp++ << 8;
107 *halfp |= *bp++;
108 ++halfp;
109 npacked += 2;
110 }
111 break;
112
113
114 case 'w':
115 wordp = va_arg (ap, word *);
116 for (i = 0; i < nreps; ++i)
117 {
118 *wordp = *bp++;
119 *wordp |= *bp++ << 8;
120 *wordp |= *bp++ << 16;
121 *wordp |= *bp++ << 24;
122 ++wordp;
123 npacked += 4;
124 }
125 break;
126
127 case 'x':
128 ll = va_arg (ap, long long *);
129 for (i = 0; i < nreps; ++i)
130 {
131 *ll = ((long long) *bp++);
132 *ll |= ((long long) *bp++) << 8;
133 *ll |= ((long long) *bp++) << 16;
134 *ll |= ((long long) *bp++) << 24;
135 *ll |= ((long long) *bp++) << 32;
136 *ll |= ((long long) *bp++) << 40;
137 *ll |= ((long long) *bp++) << 48;
138 *ll |= ((long long) *bp++) << 56;
139 ++ll;
140 npacked += 8;
141 }
142 break;
143
144 case 'W':
145 wordp = va_arg (ap, word *);
146 for (i = 0; i < nreps; ++i)
147 {
148 *wordp = *bp++ << 24;
149 *wordp |= *bp++ << 16;
150 *wordp |= *bp++ << 8;
151 *wordp |= *bp++;
152 ++wordp;
153 npacked += 4;
154 }
155 break;
156
157 case 'X':
158 ll = va_arg (ap, long long *);
159 for (i = 0; i < nreps; ++i)
160 {
161 *ll = ((long long) *bp++) << 56;
162 *ll |= ((long long) *bp++) << 48;
163 *ll |= ((long long) *bp++) << 40;
164 *ll |= ((long long) *bp++) << 32;
165 *ll |= ((long long) *bp++) << 24;
166 *ll |= ((long long) *bp++) << 18;
167 *ll |= ((long long) *bp++) << 8;
168 *ll |= ((long long) *bp++);
169 ++ll;
170 npacked += 8;
171 }
172 break;
173
174
175 case 'A':
176 if (isnonprefixed)
177 {
178 maxlen = va_arg (ap, word);
179 arr = va_arg (ap, void *);
180
181 len = *bp++ << 24;
182 len |= *bp++ << 16;
183 len |= *bp++ << 8;
184 len |= *bp++;
185
186 if (len > maxlen)
70 { 187 {
71 /* We use cp instead of format to keep the 'const' qualifier of fmt */ 188 va_end (ap);
72 nreps = strtoul (fmt, &cp, 0); 189 return -1;
73 fmt = cp;
74 if (*fmt == 'a')
75 isnonprefixed = 0;
76 } 190 }
77 191
78 switch (*fmt) 192 memmove (arr, bp, len);
193 bp += len;
194
195 npacked += len;
196 }
197 else
198 {
199 cbvp = va_arg (ap, struct cat_bvec *);
200 for (i = 0; i < nreps; ++i)
201 {
202 maxlen = cbvp->len;
203 arr = cbvp->data;
204
205 len = *bp++ << 24;
206 len |= *bp++ << 16;
207 len |= *bp++ << 8;
208 len |= *bp++;
209
210 if (len > maxlen)
211 return -1;
212
213 memmove (arr, bp, len);
214 cbvp->len = len;
215 bp += len;
216
217 ++cbvp;
218 npacked += len;
219 }
220 isnonprefixed = 1;
221 }
222 break;
223
224 case 'C':
225 case 'c':
226 sbytep = va_arg (ap, sbyte *);
227 for (i = 0; i < nreps; ++i)
228 {
229 *sbytep = *bp++;
230
231 if ((sizeof (sbyte) > 1) && (*sbytep & 0x80))
232 *sbytep |= (~0) << ((sizeof (sbyte) - 1) * 8);
233
234 ++sbytep;
235 npacked += 1;
236 }
237 break;
238
239
240 case 's':
241 shalfp = va_arg (ap, shalf *);
242 for (i = 0; i < nreps; ++i)
243 {
244 *shalfp = *bp++;
245 *shalfp |= *bp++ << 8;
246
247 if ((sizeof (shalf) > 2) && (*shalfp & 0x8000))
248 *shalfp |= (~0) << ((sizeof (shalf) - 2) * 8);
249
250 ++shalfp;
251 npacked += 2;
252 }
253 break;
254
255 case 'S':
256 shalfp = va_arg (ap, shalf *);
257 for (i = 0; i < nreps; ++i)
258 {
259 *shalfp = *bp++ << 8;
260 *shalfp |= *bp++;
261
262 if ((sizeof (shalf) > 2) && (*shalfp & 0x8000))
263 *shalfp |= (~0) << ((sizeof (shalf) - 2) * 8);
264
265 ++shalfp;
266 npacked += 2;
267 }
268 break;
269
270 case 'l':
271 swordp = va_arg (ap, sword *);
272 for (i = 0; i < nreps; ++i)
273 {
274 *swordp = *bp++;
275 *swordp |= *bp++ << 8;
276 *swordp |= *bp++ << 16;
277 *swordp |= *bp++ << 24;
278
279 if ((sizeof (swordp) > 4) && (*swordp & 0x80000000))
280 *swordp |= (~0) << ((sizeof (sword) - 4) * 8);
281
282 ++swordp;
283 npacked += 4;
284 }
285 break;
286
287 case 'L':
288 swordp = va_arg (ap, sword *);
289 for (i = 0; i < nreps; ++i)
290 {
291 *swordp = *bp++ << 24;
292 *swordp |= *bp++ << 16;
293 *swordp |= *bp++ << 8;
294 *swordp |= *bp++;
295
296 if ((sizeof (swordp) > 4) && (*swordp & 0x80000000))
297 *swordp |= (~0) << ((sizeof (sword) - 4) * 8);
298
299 ++swordp;
300 npacked += 4;
301 }
302 break;
303
304 case 'P':
305 cbvp = va_arg (ap, struct cat_bvec *);
306 for (i = 0; i < nreps; ++i)
307 {
308 len = *bp++ << 24;
309 len |= *bp++ << 16;
310 len |= *bp++ << 8;
311 len |= *bp++;
312
313 newbuf = (byte *) malloc (len);
314
315 if (! newbuf)
79 { 316 {
80 case 'B': 317 int j;
81 case 'b': 318 for (j = 0; j < i; j++)
82 bytep = va_arg (ap, byte *); 319 free (cbvp[i].data);
83 for (i = 0; i < nreps; ++i)
84 {
85 *bytep = *bp++;
86 ++bytep;
87 npacked += 1;
88 }
89 break;
90
91
92
93 case 'h':
94 halfp = va_arg (ap, half *);
95 for (i = 0; i < nreps; ++i)
96 {
97 *halfp = *bp++;
98 *halfp |= *bp++ << 8;
99 ++halfp;
100 npacked += 2;
101 }
102 break;
103
104 case 'H':
105 halfp = va_arg (ap, half *);
106 for (i = 0; i < nreps; ++i)
107 {
108 *halfp = *bp++ << 8;
109 *halfp |= *bp++;
110 ++halfp;
111 npacked += 2;
112 }
113 break;
114
115
116 case 'w':
117 wordp = va_arg (ap, word *);
118 for (i = 0; i < nreps; ++i)
119 {
120 *wordp = *bp++;
121 *wordp |= *bp++ << 8;
122 *wordp |= *bp++ << 16;
123 *wordp |= *bp++ << 24;
124 ++wordp;
125 npacked += 4;
126 }
127 break;
128
129 case 'x':
130 ll = va_arg (ap, long long *);
131 for (i = 0; i < nreps; ++i)
132 {
133 *ll = ((long long) *bp++);
134 *ll |= ((long long) *bp++) << 8;
135 *ll |= ((long long) *bp++) << 16;
136 *ll |= ((long long) *bp++) << 24;
137 *ll |= ((long long) *bp++) << 32;
138 *ll |= ((long long) *bp++) << 40;
139 *ll |= ((long long) *bp++) << 48;
140 *ll |= ((long long) *bp++) << 56;
141 ++ll;
142 npacked += 8;
143 }
144 break;
145
146 case 'W':
147 wordp = va_arg (ap, word *);
148 for (i = 0; i < nreps; ++i)
149 {
150 *wordp = *bp++ << 24;
151 *wordp |= *bp++ << 16;
152 *wordp |= *bp++ << 8;
153 *wordp |= *bp++;
154 ++wordp;
155 npacked += 4;
156 }
157 break;
158
159 case 'X':
160 ll = va_arg (ap, long long *);
161 for (i = 0; i < nreps; ++i)
162 {
163 *ll = ((long long) *bp++) << 56;
164 *ll |= ((long long) *bp++) << 48;
165 *ll |= ((long long) *bp++) << 40;
166 *ll |= ((long long) *bp++) << 32;
167 *ll |= ((long long) *bp++) << 24;
168 *ll |= ((long long) *bp++) << 18;
169 *ll |= ((long long) *bp++) << 8;
170 *ll |= ((long long) *bp++);
171 ++ll;
172 npacked += 8;
173 }
174 break;
175
176
177 case 'A':
178 if (isnonprefixed)
179 {
180 maxlen = va_arg (ap, word);
181 arr = va_arg (ap, void *);
182
183 len = *bp++ << 24;
184 len |= *bp++ << 16;
185 len |= *bp++ << 8;
186 len |= *bp++;
187
188 if (len > maxlen)
189 {
190 va_end (ap);
191 return -1;
192 }
193
194 memmove (arr, bp, len);
195 bp += len;
196
197 npacked += len;
198 }
199 else
200 {
201 cbvp = va_arg (ap, struct cat_bvec *);
202 for (i = 0; i < nreps; ++i)
203 {
204 maxlen = cbvp->len;
205 arr = cbvp->data;
206
207 len = *bp++ << 24;
208 len |= *bp++ << 16;
209 len |= *bp++ << 8;
210 len |= *bp++;
211
212 if (len > maxlen)
213 return -1;
214
215 memmove (arr, bp, len);
216 cbvp->len = len;
217 bp += len;
218
219 ++cbvp;
220 npacked += len;
221 }
222 isnonprefixed = 1;
223 }
224 break;
225
226 case 'C':
227 case 'c':
228 sbytep = va_arg (ap, sbyte *);
229 for (i = 0; i < nreps; ++i)
230 {
231 *sbytep = *bp++;
232
233 if ((sizeof (sbyte) > 1) && (*sbytep & 0x80))
234 *sbytep |= (~0) << ((sizeof (sbyte) - 1) * 8);
235
236 ++sbytep;
237 npacked += 1;
238 }
239 break;
240
241
242 case 's':
243 shalfp = va_arg (ap, shalf *);
244 for (i = 0; i < nreps; ++i)
245 {
246 *shalfp = *bp++;
247 *shalfp |= *bp++ << 8;
248
249 if ((sizeof (shalf) > 2) && (*shalfp & 0x8000))
250 *shalfp |= (~0) << ((sizeof (shalf) - 2) * 8);
251
252 ++shalfp;
253 npacked += 2;
254 }
255 break;
256
257 case 'S':
258 shalfp = va_arg (ap, shalf *);
259 for (i = 0; i < nreps; ++i)
260 {
261 *shalfp = *bp++ << 8;
262 *shalfp |= *bp++;
263
264 if ((sizeof (shalf) > 2) && (*shalfp & 0x8000))
265 *shalfp |= (~0) << ((sizeof (shalf) - 2) * 8);
266
267 ++shalfp;
268 npacked += 2;
269 }
270 break;
271
272 case 'l':
273 swordp = va_arg (ap, sword *);
274 for (i = 0; i < nreps; ++i)
275 {
276 *swordp = *bp++;
277 *swordp |= *bp++ << 8;
278 *swordp |= *bp++ << 16;
279 *swordp |= *bp++ << 24;
280
281 if ((sizeof (swordp) > 4) && (*swordp & 0x80000000))
282 *swordp |= (~0) << ((sizeof (sword) - 4) * 8);
283
284 ++swordp;
285 npacked += 4;
286 }
287 break;
288
289 case 'L':
290 swordp = va_arg (ap, sword *);
291 for (i = 0; i < nreps; ++i)
292 {
293 *swordp = *bp++ << 24;
294 *swordp |= *bp++ << 16;
295 *swordp |= *bp++ << 8;
296 *swordp |= *bp++;
297
298 if ((sizeof (swordp) > 4) && (*swordp & 0x80000000))
299 *swordp |= (~0) << ((sizeof (sword) - 4) * 8);
300
301 ++swordp;
302 npacked += 4;
303 }
304 break;
305
306 case 'P':
307 cbvp = va_arg (ap, struct cat_bvec *);
308 for (i = 0; i < nreps; ++i)
309 {
310 len = *bp++ << 24;
311 len |= *bp++ << 16;
312 len |= *bp++ << 8;
313 len |= *bp++;
314
315 newbuf = (byte *) malloc (len);
316
317 if (!newbuf)
318 {
319 int j;
320 for (j = 0; j < i; j++)
321 free (cbvp[i].data);
322 va_end (ap);
323 return -1;
324 }
325
326 memmove (newbuf, bp, len);
327 cbvp[i].data = newbuf;
328 cbvp[i].len = len;
329
330 bp += len;
331 npacked += len;
332 }
333 break;
334
335 default:
336 va_end (ap); 320 va_end (ap);
337 return -1; 321 return -1;
338 } 322 }
339 323
340 ++fmt; 324 memmove (newbuf, bp, len);
325 cbvp[i].data = newbuf;
326 cbvp[i].len = len;
327
328 bp += len;
329 npacked += len;
330 }
331 break;
332
333 default:
334 va_end (ap);
335 return -1;
341 } 336 }
342 337
338 ++fmt;
339 }
340
343 va_end (ap); 341 va_end (ap);
344 return 0; 342 return 0;
345} 343}
diff --git a/src/plugins/old/pack.h b/src/plugins/old/pack.h
index fe4e168..74bc172 100644
--- a/src/plugins/old/pack.h
+++ b/src/plugins/old/pack.h
@@ -45,18 +45,16 @@ MODIFICATIONS.
45 p - (unpack only) value is a pointer to a pointer. Generate the buffer 45 p - (unpack only) value is a pointer to a pointer. Generate the buffer
46 to hold the data. 46 to hold the data.
47 */ 47 */
48int 48int
49EXTRACTOR_common_cat_unpack(const void * buf, 49EXTRACTOR_common_cat_unpack (const void *buf,
50 const char *fmt, 50 const char *fmt,
51 ...); 51 ...);
52 52
53struct cat_bvec 53struct cat_bvec
54{ 54{
55 unsigned long len; 55 unsigned long len;
56 void * data; 56 void *data;
57}; 57};
58 58
59 59
60#endif /* __CAT_PACK_H */ 60#endif /* __CAT_PACK_H */
61
62
diff --git a/src/plugins/old/qt_extractor.c b/src/plugins/old/qt_extractor.c
index f3420bb..2db3306 100644
--- a/src/plugins/old/qt_extractor.c
+++ b/src/plugins/old/qt_extractor.c
@@ -178,7 +178,7 @@ static const char *const genre_names[] = {
178}; 178};
179 179
180#define GENRE_NAME_COUNT \ 180#define GENRE_NAME_COUNT \
181 ((unsigned int)(sizeof genre_names / sizeof (const char *const))) 181 ((unsigned int) (sizeof genre_names / sizeof (const char *const)))
182 182
183 183
184static const char *languages[] = { 184static const char *languages[] = {
@@ -299,7 +299,7 @@ typedef struct
299 const char *mime; 299 const char *mime;
300} C2M; 300} C2M;
301 301
302/* see http://www.mp4ra.org/filetype.html 302/* see http://www.mp4ra.org/filetype.html
303 * http://www.ftyps.com/ */ 303 * http://www.ftyps.com/ */
304static C2M ftMap[] = { 304static C2M ftMap[] = {
305 {"qt ", "video/quicktime"}, 305 {"qt ", "video/quicktime"},
@@ -356,7 +356,7 @@ static CHE cHm[] = {
356 {"src", EXTRACTOR_METATYPE_CONTRIBUTOR_NAME}, 356 {"src", EXTRACTOR_METATYPE_CONTRIBUTOR_NAME},
357 {"prf", EXTRACTOR_METATYPE_PERFORMER }, 357 {"prf", EXTRACTOR_METATYPE_PERFORMER },
358 {"prd", EXTRACTOR_METATYPE_PRODUCER}, 358 {"prd", EXTRACTOR_METATYPE_PRODUCER},
359 {"PRD", EXTRACTOR_METATYPE_PRODUCT_VERSION}, 359 {"PRD", EXTRACTOR_METATYPE_PRODUCT_VERSION},
360 {"swr", EXTRACTOR_METATYPE_PRODUCED_BY_SOFTWARE}, 360 {"swr", EXTRACTOR_METATYPE_PRODUCED_BY_SOFTWARE},
361 {"isr", EXTRACTOR_METATYPE_ISRC}, 361 {"isr", EXTRACTOR_METATYPE_ISRC},
362 {"wrt", EXTRACTOR_METATYPE_WRITER}, 362 {"wrt", EXTRACTOR_METATYPE_WRITER},
@@ -396,7 +396,7 @@ static ITTagConversionEntry it_to_extr_table[] = {
396 {"keyw", EXTRACTOR_METATYPE_KEYWORDS}, 396 {"keyw", EXTRACTOR_METATYPE_KEYWORDS},
397 {"desc", EXTRACTOR_METATYPE_DESCRIPTION}, 397 {"desc", EXTRACTOR_METATYPE_DESCRIPTION},
398 {"tvnn", EXTRACTOR_METATYPE_NETWORK_NAME}, 398 {"tvnn", EXTRACTOR_METATYPE_NETWORK_NAME},
399 {"tvsh", EXTRACTOR_METATYPE_SHOW_NAME}, 399 {"tvsh", EXTRACTOR_METATYPE_SHOW_NAME},
400 {"tven", EXTRACTOR_METATYPE_NETWORK_NAME}, 400 {"tven", EXTRACTOR_METATYPE_NETWORK_NAME},
401 {NULL, EXTRACTOR_METATYPE_RESERVED} 401 {NULL, EXTRACTOR_METATYPE_RESERVED}
402}; 402};
@@ -441,25 +441,26 @@ checkAtomValid (const char *buffer, size_t size, size_t pos)
441 return 0; 441 return 0;
442 atom = (const Atom *) &buffer[pos]; 442 atom = (const Atom *) &buffer[pos];
443 if (ntohl (atom->size) == 1) 443 if (ntohl (atom->size) == 1)
444 { 444 {
445 if ((pos + sizeof (LongAtom) > size) || (pos + sizeof (LongAtom) < pos)) 445 if ((pos + sizeof (LongAtom) > size) || (pos + sizeof (LongAtom) < pos))
446 return 0; 446 return 0;
447 latom = (const LongAtom *) &buffer[pos]; 447 latom = (const LongAtom *) &buffer[pos];
448 atomSize = ntohll (latom->size); 448 atomSize = ntohll (latom->size);
449 if ((atomSize < sizeof (LongAtom)) || 449 if ((atomSize < sizeof (LongAtom)) ||
450 (atomSize + pos > size) || (atomSize + pos < atomSize)) 450 (atomSize + pos > size) || (atomSize + pos < atomSize))
451 return 0; 451 return 0;
452 } 452 }
453 else 453 else
454 { 454 {
455 atomSize = ntohl (atom->size); 455 atomSize = ntohl (atom->size);
456 if ((atomSize < sizeof (Atom)) || 456 if ((atomSize < sizeof (Atom)) ||
457 (atomSize + pos > size) || (atomSize + pos < atomSize)) 457 (atomSize + pos > size) || (atomSize + pos < atomSize))
458 return 0; 458 return 0;
459 } 459 }
460 return 1; 460 return 1;
461} 461}
462 462
463
463/** 464/**
464 * Assumes that checkAtomValid has already been called. 465 * Assumes that checkAtomValid has already been called.
465 */ 466 */
@@ -470,13 +471,14 @@ getAtomSize (const char *buf)
470 const LongAtom *latom; 471 const LongAtom *latom;
471 atom = (const Atom *) buf; 472 atom = (const Atom *) buf;
472 if (ntohl (atom->size) == 1) 473 if (ntohl (atom->size) == 1)
473 { 474 {
474 latom = (const LongAtom *) buf; 475 latom = (const LongAtom *) buf;
475 return ntohll (latom->size); 476 return ntohll (latom->size);
476 } 477 }
477 return ntohl (atom->size); 478 return ntohl (atom->size);
478} 479}
479 480
481
480/** 482/**
481 * Assumes that checkAtomValid has already been called. 483 * Assumes that checkAtomValid has already been called.
482 */ 484 */
@@ -491,6 +493,7 @@ getAtomHeaderSize (const char *buf)
491 return sizeof (Atom); 493 return sizeof (Atom);
492} 494}
493 495
496
494struct ExtractContext 497struct ExtractContext
495{ 498{
496 EXTRACTOR_MetaDataProcessor proc; 499 EXTRACTOR_MetaDataProcessor proc;
@@ -500,22 +503,21 @@ struct ExtractContext
500 503
501static void 504static void
502addKeyword (enum EXTRACTOR_MetaType type, 505addKeyword (enum EXTRACTOR_MetaType type,
503 const char *str, 506 const char *str,
504 struct ExtractContext *ec) 507 struct ExtractContext *ec)
505{ 508{
506 if (ec->ret != 0) 509 if (ec->ret != 0)
507 return; 510 return;
508 ec->ret = ec->proc (ec->proc_cls, 511 ec->ret = ec->proc (ec->proc_cls,
509 "qt", 512 "qt",
510 type, 513 type,
511 EXTRACTOR_METAFORMAT_UTF8, 514 EXTRACTOR_METAFORMAT_UTF8,
512 "text/plain", 515 "text/plain",
513 str, 516 str,
514 strlen(str)+1); 517 strlen (str) + 1);
515} 518}
516 519
517 520
518
519/** 521/**
520 * Assumes that checkAtomValid has already been called. 522 * Assumes that checkAtomValid has already been called.
521 */ 523 */
@@ -538,8 +540,8 @@ typedef struct
538static int handleAtom (HandlerEntry *handlers, 540static int handleAtom (HandlerEntry *handlers,
539 const char *input, 541 const char *input,
540 size_t size, 542 size_t size,
541 size_t pos, 543 size_t pos,
542 struct ExtractContext *ec); 544 struct ExtractContext *ec);
543 545
544static HandlerEntry all_handlers[]; 546static HandlerEntry all_handlers[];
545static HandlerEntry ilst_handlers[]; 547static HandlerEntry ilst_handlers[];
@@ -550,7 +552,7 @@ static HandlerEntry ilst_handlers[];
550 */ 552 */
551static int 553static int
552processAtoms (HandlerEntry *handlers, const char *input, 554processAtoms (HandlerEntry *handlers, const char *input,
553 size_t size, struct ExtractContext *ec) 555 size_t size, struct ExtractContext *ec)
554{ 556{
555 size_t pos; 557 size_t pos;
556 558
@@ -558,14 +560,15 @@ processAtoms (HandlerEntry *handlers, const char *input,
558 return 1; 560 return 1;
559 pos = 0; 561 pos = 0;
560 while (pos < size - sizeof (Atom)) 562 while (pos < size - sizeof (Atom))
561 { 563 {
562 if (0 == handleAtom (handlers, input, size, pos, ec)) 564 if (0 == handleAtom (handlers, input, size, pos, ec))
563 return 0; 565 return 0;
564 pos += getAtomSize (&input[pos]); 566 pos += getAtomSize (&input[pos]);
565 } 567 }
566 return 1; 568 return 1;
567} 569}
568 570
571
569/** 572/**
570 * Process all atoms. 573 * Process all atoms.
571 * @return 0 on error, 1 for success, -1 for unknown atom type 574 * @return 0 on error, 1 for success, -1 for unknown atom type
@@ -574,9 +577,10 @@ static int
574processAllAtoms (const char *input, 577processAllAtoms (const char *input,
575 size_t size, struct ExtractContext *ec) 578 size_t size, struct ExtractContext *ec)
576{ 579{
577 return processAtoms(all_handlers, input, size, ec); 580 return processAtoms (all_handlers, input, size, ec);
578} 581}
579 582
583
580/** 584/**
581 * Handle the moov atom. 585 * Handle the moov atom.
582 * @return 0 on error, 1 for success, -1 for unknown atom type 586 * @return 0 on error, 1 for success, -1 for unknown atom type
@@ -590,6 +594,7 @@ moovHandler (const char *input,
590 getAtomSize (&input[pos]) - hdr, ec); 594 getAtomSize (&input[pos]) - hdr, ec);
591} 595}
592 596
597
593/* see http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap1/chapter_2_section_5.html */ 598/* see http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap1/chapter_2_section_5.html */
594typedef struct 599typedef struct
595{ 600{
@@ -609,7 +614,8 @@ ftypHandler (const char *input,
609 const FileType *ft; 614 const FileType *ft;
610 int i; 615 int i;
611 616
612 if (getAtomSize (&input[pos]) < sizeof (FileType)) { 617 if (getAtomSize (&input[pos]) < sizeof (FileType))
618 {
613 return 0; 619 return 0;
614 } 620 }
615 ft = (const FileType *) &input[pos]; 621 ft = (const FileType *) &input[pos];
@@ -622,6 +628,7 @@ ftypHandler (const char *input,
622 return 1; 628 return 1;
623} 629}
624 630
631
625typedef struct 632typedef struct
626{ 633{
627 Atom hdr; 634 Atom hdr;
@@ -662,13 +669,14 @@ mvhdHandler (const char *input,
662 return 0; 669 return 0;
663 m = (const MovieHeaderAtom *) &input[pos]; 670 m = (const MovieHeaderAtom *) &input[pos];
664 snprintf (duration, 671 snprintf (duration,
665 sizeof(duration), 672 sizeof(duration),
666 "%us", 673 "%us",
667 ntohl (m->duration) / ntohl (m->timeScale)); 674 ntohl (m->duration) / ntohl (m->timeScale));
668 addKeyword (EXTRACTOR_METATYPE_DURATION, duration, ec); 675 addKeyword (EXTRACTOR_METATYPE_DURATION, duration, ec);
669 return 1; 676 return 1;
670} 677}
671 678
679
672typedef struct 680typedef struct
673{ 681{
674 Atom cmovAtom; 682 Atom cmovAtom;
@@ -699,9 +707,9 @@ cmovHandler (const char *input,
699 (0 != memcmp (&c->cmvdAtom.type, "cmvd", 4)) || 707 (0 != memcmp (&c->cmvdAtom.type, "cmvd", 4)) ||
700 (ntohl (c->cmvdAtom.size) != 708 (ntohl (c->cmvdAtom.size) !=
701 getAtomSize (&input[pos]) - sizeof (Atom) * 2 - 4)) 709 getAtomSize (&input[pos]) - sizeof (Atom) * 2 - 4))
702 { 710 {
703 return 0; /* dcom must be 12 bytes */ 711 return 0; /* dcom must be 12 bytes */
704 } 712 }
705 s = ntohl (c->decompressedSize); 713 s = ntohl (c->decompressedSize);
706 if (s > 16 * 1024 * 1024) 714 if (s > 16 * 1024 * 1024)
707 return 1; /* ignore, too big! */ 715 return 1; /* ignore, too big! */
@@ -718,27 +726,28 @@ cmovHandler (const char *input,
718 z_state.opaque = (voidpf) 0; 726 z_state.opaque = (voidpf) 0;
719 z_ret_code = inflateInit (&z_state); 727 z_ret_code = inflateInit (&z_state);
720 if (Z_OK != z_ret_code) 728 if (Z_OK != z_ret_code)
721 { 729 {
722 free (buf); 730 free (buf);
723 return 0; /* crc error? */ 731 return 0; /* crc error? */
724 } 732 }
725 z_ret_code = inflate (&z_state, Z_NO_FLUSH); 733 z_ret_code = inflate (&z_state, Z_NO_FLUSH);
726 if ((z_ret_code != Z_OK) && (z_ret_code != Z_STREAM_END)) 734 if ((z_ret_code != Z_OK) && (z_ret_code != Z_STREAM_END))
727 { 735 {
728 free (buf); 736 free (buf);
729 return 0; /* decode error? */ 737 return 0; /* decode error? */
730 } 738 }
731 z_ret_code = inflateEnd (&z_state); 739 z_ret_code = inflateEnd (&z_state);
732 if (Z_OK != z_ret_code) 740 if (Z_OK != z_ret_code)
733 { 741 {
734 free (buf); 742 free (buf);
735 return 0; /* decode error? */ 743 return 0; /* decode error? */
736 } 744 }
737 ret = handleAtom (all_handlers, buf, s, 0, ec); 745 ret = handleAtom (all_handlers, buf, s, 0, ec);
738 free (buf); 746 free (buf);
739 return ret; 747 return ret;
740} 748}
741 749
750
742typedef struct 751typedef struct
743{ 752{
744 short integer; 753 short integer;
@@ -780,18 +789,19 @@ tkhdHandler (const char *input,
780 return 0; 789 return 0;
781 m = (const TrackAtom *) &input[pos]; 790 m = (const TrackAtom *) &input[pos];
782 if (ntohs (m->track_width.integer) != 0) 791 if (ntohs (m->track_width.integer) != 0)
783 { 792 {
784 /* if actually a/the video track */ 793 /* if actually a/the video track */
785 snprintf (dimensions, 794 snprintf (dimensions,
786 sizeof(dimensions), 795 sizeof(dimensions),
787 "%dx%d", 796 "%dx%d",
788 ntohs (m->track_width.integer), 797 ntohs (m->track_width.integer),
789 ntohs (m->track_height.integer)); 798 ntohs (m->track_height.integer));
790 addKeyword (EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, dimensions, ec); 799 addKeyword (EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, dimensions, ec);
791 } 800 }
792 return 1; 801 return 1;
793} 802}
794 803
804
795static int 805static int
796trakHandler (const char *input, 806trakHandler (const char *input,
797 size_t size, size_t pos, struct ExtractContext *ec) 807 size_t size, size_t pos, struct ExtractContext *ec)
@@ -801,6 +811,7 @@ trakHandler (const char *input,
801 getAtomSize (&input[pos]) - hdr, ec); 811 getAtomSize (&input[pos]) - hdr, ec);
802} 812}
803 813
814
804static int 815static int
805metaHandler (const char *input, 816metaHandler (const char *input,
806 size_t size, size_t pos, struct ExtractContext *ec) 817 size_t size, size_t pos, struct ExtractContext *ec)
@@ -812,6 +823,7 @@ metaHandler (const char *input,
812 getAtomSize (&input[pos]) - hdr - 4, ec); 823 getAtomSize (&input[pos]) - hdr - 4, ec);
813} 824}
814 825
826
815typedef struct 827typedef struct
816{ 828{
817 Atom header; 829 Atom header;
@@ -873,13 +885,14 @@ c_Handler (const char *input,
873 int i; 885 int i;
874 886
875 i = 0; 887 i = 0;
876 while ((cHm[i].pfx != NULL) && (0 != memcmp (&input[pos+5], cHm[i].pfx, 3))) 888 while ((cHm[i].pfx != NULL) && (0 != memcmp (&input[pos + 5], cHm[i].pfx, 3)))
877 i++; 889 i++;
878 if (cHm[i].pfx != NULL) 890 if (cHm[i].pfx != NULL)
879 return processTextTag (input, size, pos, cHm[i].type, ec); 891 return processTextTag (input, size, pos, cHm[i].type, ec);
880 return -1; /* not found */ 892 return -1; /* not found */
881} 893}
882 894
895
883static int 896static int
884udtaHandler (const char *input, 897udtaHandler (const char *input,
885 size_t size, size_t pos, struct ExtractContext *ec) 898 size_t size, size_t pos, struct ExtractContext *ec)
@@ -889,13 +902,14 @@ udtaHandler (const char *input,
889 getAtomSize (&input[pos]) - hdr, ec); 902 getAtomSize (&input[pos]) - hdr, ec);
890} 903}
891 904
905
892static int 906static int
893processDataAtom (const char *input, 907processDataAtom (const char *input,
894 size_t size, /* parent atom size */ 908 size_t size, /* parent atom size */
895 size_t pos, 909 size_t pos,
896 const char *patom, 910 const char *patom,
897 enum EXTRACTOR_MetaType type, 911 enum EXTRACTOR_MetaType type,
898 struct ExtractContext *ec) 912 struct ExtractContext *ec)
899{ 913{
900 char *meta; 914 char *meta;
901 unsigned char version; 915 unsigned char version;
@@ -907,55 +921,62 @@ processDataAtom (const char *input,
907 921
908 hdr = getAtomHeaderSize (&input[pos]); 922 hdr = getAtomHeaderSize (&input[pos]);
909 asize = getAtomSize (&input[pos]); 923 asize = getAtomSize (&input[pos]);
910 if (memcmp(&input[pos+4], "data", 4) != 0) 924 if (memcmp (&input[pos + 4], "data", 4) != 0)
911 return -1; 925 return -1;
912 926
913 if (asize < hdr + 8 || /* header + u32 flags + u32 reserved */ 927 if ((asize < hdr + 8) || /* header + u32 flags + u32 reserved */
914 asize > (getAtomSize(&patom[0]) - 8)) 928 (asize > (getAtomSize (&patom[0]) - 8)) )
915 return 0; 929 return 0;
916 930
917 len = (unsigned int)(asize - (hdr + 8)); 931 len = (unsigned int) (asize - (hdr + 8));
918 932
919 version = input[pos+8]; 933 version = input[pos + 8];
920 flags = ((unsigned char)input[pos+9]<<16) | 934 flags = ((unsigned char) input[pos + 9] << 16)
921 ((unsigned char)input[pos+10]<<8) | 935 | ((unsigned char) input[pos + 10] << 8)
922 (unsigned char)input[pos+11]; 936 | (unsigned char) input[pos + 11];
923#if DEBUG 937#if DEBUG
924 printf("[data] version:%02x flags:%08x txtlen:%d\n", version, flags, len); 938 printf ("[data] version:%02x flags:%08x txtlen:%d\n", version, flags, len);
925#endif 939#endif
926 940
927 if (version != 0) 941 if (version != 0)
928 return -1; 942 return -1;
929 943
930 if (flags == 0x0) { /* binary data */ 944 if (flags == 0x0) /* binary data */
931 if (memcmp(&patom[4], "gnre", 4) == 0) { 945 {
932 if (len >= 2) { 946 if (memcmp (&patom[4], "gnre", 4) == 0)
933 unsigned short genre = ((unsigned char)input[pos+16] << 8) | 947 {
934 (unsigned char)input[pos+17]; 948 if (len >= 2)
935 if (genre > 0 && genre < GENRE_NAME_COUNT) 949 {
936 addKeyword(type, genre_names[genre-1], ec); 950 unsigned short genre = ((unsigned char) input[pos + 16] << 8)
951 | (unsigned char) input[pos + 17];
952 if ((genre > 0) && (genre < GENRE_NAME_COUNT))
953 addKeyword (type, genre_names[genre - 1], ec);
937 } 954 }
938 return 1; 955 return 1;
939 } 956 }
940 else if ((memcmp(&patom[4], "trkn", 4) == 0) || 957 else if ((memcmp (&patom[4], "trkn", 4) == 0) ||
941 (memcmp(&patom[4], "disk", 4) == 0)) { 958 (memcmp (&patom[4], "disk", 4) == 0))
942 if (len >= 4) { 959 {
943 unsigned short n = ((unsigned char)input[pos+18] << 8) | 960 if (len >= 4)
944 (unsigned char)input[pos+19]; 961 {
962 unsigned short n = ((unsigned char) input[pos + 18] << 8)
963 | (unsigned char) input[pos + 19];
945 char s[8]; 964 char s[8];
946 snprintf(s, 8, "%d", n); 965 snprintf (s, 8, "%d", n);
947 addKeyword(type, s, ec); 966 addKeyword (type, s, ec);
948 } 967 }
949 } 968 }
950 else { 969 else
970 {
951 return -1; 971 return -1;
952 } 972 }
953 } 973 }
954 else if (flags == 0x1) { /* text data */ 974 else if (flags == 0x1) /* text data */
975 {
955 meta = malloc (len + 1); 976 meta = malloc (len + 1);
956 if (meta == NULL) 977 if (meta == NULL)
957 return 0; 978 return 0;
958 memcpy (meta, &input[pos+16], len); 979 memcpy (meta, &input[pos + 16], len);
959 meta[len] = '\0'; 980 meta[len] = '\0';
960 for (i = 0; i < len; i++) 981 for (i = 0; i < len; i++)
961 if (meta[i] == '\r') 982 if (meta[i] == '\r')
@@ -968,12 +989,13 @@ processDataAtom (const char *input,
968 return -1; 989 return -1;
969} 990}
970 991
992
971/* NOTE: iTunes tag processing should, in theory, be limited to iTunes 993/* NOTE: iTunes tag processing should, in theory, be limited to iTunes
972 * file types (from ftyp), but, in reality, it seems that there are other 994 * file types (from ftyp), but, in reality, it seems that there are other
973 * files, like 3gpp, out in the wild with iTunes tags. */ 995 * files, like 3gpp, out in the wild with iTunes tags. */
974static int 996static int
975iTunesTagHandler (const char *input, 997iTunesTagHandler (const char *input,
976 size_t size, size_t pos, struct ExtractContext *ec) 998 size_t size, size_t pos, struct ExtractContext *ec)
977{ 999{
978 unsigned long long asize; 1000 unsigned long long asize;
979 unsigned int hdr; 1001 unsigned int hdr;
@@ -986,24 +1008,24 @@ iTunesTagHandler (const char *input,
986 return 0; 1008 return 0;
987 1009
988 i = 0; 1010 i = 0;
989 while ((it_to_extr_table[i].atom_type != NULL) && 1011 while ((it_to_extr_table[i].atom_type != NULL) &&
990 (0 != memcmp (&input[pos+4], it_to_extr_table[i].atom_type, 4))) 1012 (0 != memcmp (&input[pos + 4], it_to_extr_table[i].atom_type, 4)))
991 i++; 1013 i++;
992 if (it_to_extr_table[i].atom_type != NULL) 1014 if (it_to_extr_table[i].atom_type != NULL)
993 return processDataAtom(input, asize, pos+hdr, &input[pos], 1015 return processDataAtom (input, asize, pos + hdr, &input[pos],
994 it_to_extr_table[i].type, ec); 1016 it_to_extr_table[i].type, ec);
995 1017
996 return -1; 1018 return -1;
997} 1019}
998 1020
999 1021
1000static int 1022static int
1001ilstHandler (const char *input, 1023ilstHandler (const char *input,
1002 size_t size, size_t pos, struct ExtractContext *ec) 1024 size_t size, size_t pos, struct ExtractContext *ec)
1003{ 1025{
1004 unsigned int hdr = getAtomHeaderSize (&input[pos]); 1026 unsigned int hdr = getAtomHeaderSize (&input[pos]);
1005 return processAtoms(ilst_handlers, &input[pos + hdr], 1027 return processAtoms (ilst_handlers, &input[pos + hdr],
1006 getAtomSize(&input[pos]) - hdr, ec); 1028 getAtomSize (&input[pos]) - hdr, ec);
1007} 1029}
1008 1030
1009 1031
@@ -1099,23 +1121,23 @@ handleAtom (HandlerEntry *handlers, const char *input,
1099{ 1121{
1100 int i; 1122 int i;
1101 if (0 == checkAtomValid (input, size, pos)) 1123 if (0 == checkAtomValid (input, size, pos))
1102 { 1124 {
1103 return 0; 1125 return 0;
1104 } 1126 }
1105 i = 0; 1127 i = 0;
1106 while ((handlers[i].name != NULL) && 1128 while ((handlers[i].name != NULL) &&
1107 (0 != memcmp (&input[pos + 4], handlers[i].name, 4))) 1129 (0 != memcmp (&input[pos + 4], handlers[i].name, 4)))
1108 i++; 1130 i++;
1109 if (handlers[i].name == NULL) 1131 if (handlers[i].name == NULL)
1110 { 1132 {
1111#if DEBUG 1133#if DEBUG
1112 char b[5]; 1134 char b[5];
1113 memcpy (b, &input[pos + 4], 4); 1135 memcpy (b, &input[pos + 4], 4);
1114 b[4] = '\0'; 1136 b[4] = '\0';
1115 printf ("No handler for `%s'\n", b); 1137 printf ("No handler for `%s'\n", b);
1116#endif 1138#endif
1117 return -1; 1139 return -1;
1118 } 1140 }
1119 i = handlers[i].handler (input, size, pos, ec); 1141 i = handlers[i].handler (input, size, pos, ec);
1120#if DEBUG 1142#if DEBUG
1121 printf ("Running handler for `%4s' at %u completed with result %d\n", 1143 printf ("Running handler for `%4s' at %u completed with result %d\n",
@@ -1124,18 +1146,19 @@ handleAtom (HandlerEntry *handlers, const char *input,
1124 return i; 1146 return i;
1125} 1147}
1126 1148
1149
1127/* mimetypes: 1150/* mimetypes:
1128 video/quicktime: mov,qt: Quicktime animation; 1151 video/quicktime: mov,qt: Quicktime animation;
1129 video/x-quicktime: mov,qt: Quicktime animation; 1152 video/x-quicktime: mov,qt: Quicktime animation;
1130 application/x-quicktimeplayer: qtl: Quicktime list; 1153 application/x-quicktimeplayer: qtl: Quicktime list;
1131 */ 1154 */
1132 1155
1133int 1156int
1134EXTRACTOR_qt_extract (const char *data, 1157EXTRACTOR_qt_extract (const char *data,
1135 size_t size, 1158 size_t size,
1136 EXTRACTOR_MetaDataProcessor proc, 1159 EXTRACTOR_MetaDataProcessor proc,
1137 void *proc_cls, 1160 void *proc_cls,
1138 const char *options) 1161 const char *options)
1139{ 1162{
1140 struct ExtractContext ec; 1163 struct ExtractContext ec;
1141 ec.proc = proc; 1164 ec.proc = proc;
@@ -1145,4 +1168,5 @@ EXTRACTOR_qt_extract (const char *data,
1145 return ec.ret; 1168 return ec.ret;
1146} 1169}
1147 1170
1171
1148/* end of qt_extractor.c */ 1172/* end of qt_extractor.c */
diff --git a/src/plugins/old/real_extractor.c b/src/plugins/old/real_extractor.c
index 0ca343c..cfac031 100644
--- a/src/plugins/old/real_extractor.c
+++ b/src/plugins/old/real_extractor.c
@@ -77,9 +77,9 @@ typedef struct
77 77
78 78
79static int 79static int
80processMediaProperties (const Media_Properties * prop, 80processMediaProperties (const Media_Properties *prop,
81 EXTRACTOR_MetaDataProcessor proc, 81 EXTRACTOR_MetaDataProcessor proc,
82 void *proc_cls) 82 void *proc_cls)
83{ 83{
84 84
85 UINT8 mime_type_size; 85 UINT8 mime_type_size;
@@ -95,28 +95,29 @@ processMediaProperties (const Media_Properties * prop,
95 return 0; 95 return 0;
96 96
97 mime_type_size = prop->data[prop->stream_name_size]; 97 mime_type_size = prop->data[prop->stream_name_size];
98 if (prop_size > prop->stream_name_size + sizeof (UINT8) + 98 if (prop_size > prop->stream_name_size + sizeof (UINT8)
99 +mime_type_size + sizeof (Media_Properties)) 99 + +mime_type_size + sizeof (Media_Properties))
100 { 100 {
101 char data[mime_type_size + 1]; 101 char data[mime_type_size + 1];
102 memcpy (data, &prop->data[prop->stream_name_size + 1], mime_type_size); 102 memcpy (data, &prop->data[prop->stream_name_size + 1], mime_type_size);
103 data[mime_type_size] = '\0'; 103 data[mime_type_size] = '\0';
104 104
105 return proc (proc_cls, 105 return proc (proc_cls,
106 "real", 106 "real",
107 EXTRACTOR_METATYPE_MIMETYPE, 107 EXTRACTOR_METATYPE_MIMETYPE,
108 EXTRACTOR_METAFORMAT_UTF8, 108 EXTRACTOR_METAFORMAT_UTF8,
109 "text/plain", 109 "text/plain",
110 data, 110 data,
111 strlen (data)); 111 strlen (data));
112 } 112 }
113 return 0; 113 return 0;
114} 114}
115 115
116
116static int 117static int
117processContentDescription (const Content_Description * prop, 118processContentDescription (const Content_Description *prop,
118 EXTRACTOR_MetaDataProcessor proc, 119 EXTRACTOR_MetaDataProcessor proc,
119 void *proc_cls) 120 void *proc_cls)
120{ 121{
121 UINT16 author_len; 122 UINT16 author_len;
122 UINT16 copyright_len; 123 UINT16 copyright_len;
@@ -137,23 +138,23 @@ processContentDescription (const Content_Description * prop,
137 title_len = ntohs (prop->title_len); 138 title_len = ntohs (prop->title_len);
138 if (prop_size <= title_len + sizeof (UINT16) + sizeof (Content_Description)) 139 if (prop_size <= title_len + sizeof (UINT16) + sizeof (Content_Description))
139 return 0; 140 return 0;
140 author_len = ntohs (*(UINT16 *) & prop->data[title_len]); 141 author_len = ntohs (*(UINT16 *) &prop->data[title_len]);
141 if (prop_size <= title_len + sizeof (UINT16) 142 if (prop_size <= title_len + sizeof (UINT16)
142 + author_len + sizeof (Content_Description)) 143 + author_len + sizeof (Content_Description))
143 return 0; 144 return 0;
144 145
145 copyright_len = ntohs (*(UINT16 *) & prop->data[title_len + 146 copyright_len = ntohs (*(UINT16 *) &prop->data[title_len
146 author_len + 147 + author_len
147 sizeof (UINT16)]); 148 + sizeof (UINT16)]);
148 149
149 if (prop_size <= title_len + 2 * sizeof (UINT16) 150 if (prop_size <= title_len + 2 * sizeof (UINT16)
150 + author_len + copyright_len + sizeof (Content_Description)) 151 + author_len + copyright_len + sizeof (Content_Description))
151 return 0; 152 return 0;
152 153
153 comment_len = ntohs (*(UINT16 *) & prop->data[title_len + 154 comment_len = ntohs (*(UINT16 *) &prop->data[title_len
154 author_len + 155 + author_len
155 copyright_len + 156 + copyright_len
156 2 * sizeof (UINT16)]); 157 + 2 * sizeof (UINT16)]);
157 158
158 if (prop_size < title_len + 3 * sizeof (UINT16) 159 if (prop_size < title_len + 3 * sizeof (UINT16)
159 + author_len + copyright_len + comment_len 160 + author_len + copyright_len + comment_len
@@ -163,78 +164,79 @@ processContentDescription (const Content_Description * prop,
163 ret = 0; 164 ret = 0;
164 title = malloc (title_len + 1); 165 title = malloc (title_len + 1);
165 if (title != NULL) 166 if (title != NULL)
166 { 167 {
167 memcpy (title, &prop->data[0], title_len); 168 memcpy (title, &prop->data[0], title_len);
168 title[title_len] = '\0'; 169 title[title_len] = '\0';
169 ret = proc (proc_cls, 170 ret = proc (proc_cls,
170 "real", 171 "real",
171 EXTRACTOR_METATYPE_TITLE, 172 EXTRACTOR_METATYPE_TITLE,
172 EXTRACTOR_METAFORMAT_UTF8, 173 EXTRACTOR_METAFORMAT_UTF8,
173 "text/plain", 174 "text/plain",
174 title, 175 title,
175 strlen (title)+1); 176 strlen (title) + 1);
176 free (title); 177 free (title);
177 } 178 }
178 if (ret != 0) 179 if (ret != 0)
179 return ret; 180 return ret;
180 181
181 author = malloc (author_len + 1); 182 author = malloc (author_len + 1);
182 if (author != NULL) 183 if (author != NULL)
183 { 184 {
184 memcpy (author, &prop->data[title_len + sizeof (UINT16)], author_len); 185 memcpy (author, &prop->data[title_len + sizeof (UINT16)], author_len);
185 author[author_len] = '\0'; 186 author[author_len] = '\0';
186 ret = proc (proc_cls, 187 ret = proc (proc_cls,
187 "real", 188 "real",
188 EXTRACTOR_METATYPE_AUTHOR_NAME, 189 EXTRACTOR_METATYPE_AUTHOR_NAME,
189 EXTRACTOR_METAFORMAT_UTF8, 190 EXTRACTOR_METAFORMAT_UTF8,
190 "text/plain", 191 "text/plain",
191 author, 192 author,
192 strlen (author)+1); 193 strlen (author) + 1);
193 free (author); 194 free (author);
194 } 195 }
195 if (ret != 0) 196 if (ret != 0)
196 return ret; 197 return ret;
197 198
198 copyright = malloc (copyright_len + 1); 199 copyright = malloc (copyright_len + 1);
199 if (copyright != NULL) 200 if (copyright != NULL)
200 { 201 {
201 memcpy (copyright, 202 memcpy (copyright,
202 &prop->data[title_len + sizeof (UINT16) * 2 + author_len], 203 &prop->data[title_len + sizeof (UINT16) * 2 + author_len],
203 copyright_len); 204 copyright_len);
204 copyright[copyright_len] = '\0'; 205 copyright[copyright_len] = '\0';
205 ret = proc (proc_cls, 206 ret = proc (proc_cls,
206 "real", 207 "real",
207 EXTRACTOR_METATYPE_COPYRIGHT, 208 EXTRACTOR_METATYPE_COPYRIGHT,
208 EXTRACTOR_METAFORMAT_UTF8, 209 EXTRACTOR_METAFORMAT_UTF8,
209 "text/plain", 210 "text/plain",
210 copyright, 211 copyright,
211 strlen (copyright)+1); 212 strlen (copyright) + 1);
212 free (copyright); 213 free (copyright);
213 } 214 }
214 if (ret != 0) 215 if (ret != 0)
215 return ret; 216 return ret;
216 217
217 comment = malloc (comment_len + 1); 218 comment = malloc (comment_len + 1);
218 if (comment != NULL) 219 if (comment != NULL)
219 { 220 {
220 memcpy (comment, 221 memcpy (comment,
221 &prop->data[title_len + sizeof (UINT16) * 3 + author_len + 222 &prop->data[title_len + sizeof (UINT16) * 3 + author_len
222 copyright_len], comment_len); 223 + copyright_len], comment_len);
223 comment[comment_len] = '\0'; 224 comment[comment_len] = '\0';
224 ret = proc (proc_cls, 225 ret = proc (proc_cls,
225 "real", 226 "real",
226 EXTRACTOR_METATYPE_COMMENT, 227 EXTRACTOR_METATYPE_COMMENT,
227 EXTRACTOR_METAFORMAT_UTF8, 228 EXTRACTOR_METAFORMAT_UTF8,
228 "text/plain", 229 "text/plain",
229 comment, 230 comment,
230 strlen (comment)+1); 231 strlen (comment) + 1);
231 free (comment); 232 free (comment);
232 } 233 }
233 if (ret != 0) 234 if (ret != 0)
234 return ret; 235 return ret;
235 return 0; 236 return 0;
236} 237}
237 238
239
238typedef struct RAFF4_header 240typedef struct RAFF4_header
239{ 241{
240 unsigned short version; 242 unsigned short version;
@@ -281,13 +283,14 @@ stndup (const char *str, size_t n)
281 return tmp; 283 return tmp;
282} 284}
283 285
286
284/* audio/vnd.rn-realaudio */ 287/* audio/vnd.rn-realaudio */
285int 288int
286EXTRACTOR_real_extract (const unsigned char *data, 289EXTRACTOR_real_extract (const unsigned char *data,
287 size_t size, 290 size_t size,
288 EXTRACTOR_MetaDataProcessor proc, 291 EXTRACTOR_MetaDataProcessor proc,
289 void *proc_cls, 292 void *proc_cls,
290 const char *options) 293 const char *options)
291{ 294{
292 const unsigned char *pos; 295 const unsigned char *pos;
293 const unsigned char *end; 296 const unsigned char *end;
@@ -303,132 +306,134 @@ EXTRACTOR_real_extract (const unsigned char *data,
303 if (size <= 2 * sizeof (int)) 306 if (size <= 2 * sizeof (int))
304 return 0; 307 return 0;
305 if (RAFF4_HEADER == ntohl (*(int *) data)) 308 if (RAFF4_HEADER == ntohl (*(int *) data))
309 {
310 /* HELIX */
311 if (size <= RAFF4_HDR_SIZE + 16 + 4)
312 return 0;
313 if (0 != proc (proc_cls,
314 "real",
315 EXTRACTOR_METATYPE_MIMETYPE,
316 EXTRACTOR_METAFORMAT_UTF8,
317 "text/plain",
318 "audio/vnd.rn-realaudio",
319 strlen ("audio/vnd.rn-realaudio") + 1))
320 return 1;
321 hdr = (const RAFF4_header *) &data[16];
322 if (ntohs (hdr->header_length) + 16 > size)
323 return 0;
324 tlen = data[16 + RAFF4_HDR_SIZE];
325 if (tlen + RAFF4_HDR_SIZE + 20 > size)
326 return 0;
327 alen = data[17 + tlen + RAFF4_HDR_SIZE];
328 if (tlen + alen + RAFF4_HDR_SIZE + 20 > size)
329 return 0;
330 clen = data[18 + tlen + alen + RAFF4_HDR_SIZE];
331 if (tlen + alen + clen + RAFF4_HDR_SIZE + 20 > size)
332 return 0;
333 aplen = data[19 + tlen + clen + alen + RAFF4_HDR_SIZE];
334 if (tlen + alen + clen + aplen + RAFF4_HDR_SIZE + 20 > size)
335 return 0;
336 ret = 0;
337 if ( (tlen > 0) && (ret == 0) )
306 { 338 {
307 /* HELIX */ 339 x = stndup ((const char *) &data[17 + RAFF4_HDR_SIZE], tlen);
308 if (size <= RAFF4_HDR_SIZE + 16 + 4) 340 if (x != NULL)
309 return 0; 341 {
310 if (0 != proc (proc_cls, 342 ret = proc (proc_cls,
311 "real", 343 "real",
312 EXTRACTOR_METATYPE_MIMETYPE, 344 EXTRACTOR_METATYPE_MIMETYPE,
313 EXTRACTOR_METAFORMAT_UTF8, 345 EXTRACTOR_METAFORMAT_UTF8,
314 "text/plain", 346 "text/plain",
315 "audio/vnd.rn-realaudio", 347 x,
316 strlen ("audio/vnd.rn-realaudio")+1)) 348 strlen (x) + 1);
317 return 1; 349 free (x);
318 hdr = (const RAFF4_header *) &data[16]; 350 }
319 if (ntohs (hdr->header_length) + 16 > size)
320 return 0;
321 tlen = data[16 + RAFF4_HDR_SIZE];
322 if (tlen + RAFF4_HDR_SIZE + 20 > size)
323 return 0;
324 alen = data[17 + tlen + RAFF4_HDR_SIZE];
325 if (tlen + alen + RAFF4_HDR_SIZE + 20 > size)
326 return 0;
327 clen = data[18 + tlen + alen + RAFF4_HDR_SIZE];
328 if (tlen + alen + clen + RAFF4_HDR_SIZE + 20 > size)
329 return 0;
330 aplen = data[19 + tlen + clen + alen + RAFF4_HDR_SIZE];
331 if (tlen + alen + clen + aplen + RAFF4_HDR_SIZE + 20 > size)
332 return 0;
333 ret = 0;
334 if ( (tlen > 0) && (ret == 0) )
335 {
336 x = stndup ((const char *) &data[17 + RAFF4_HDR_SIZE], tlen);
337 if (x != NULL)
338 {
339 ret = proc (proc_cls,
340 "real",
341 EXTRACTOR_METATYPE_MIMETYPE,
342 EXTRACTOR_METAFORMAT_UTF8,
343 "text/plain",
344 x,
345 strlen (x)+1);
346 free (x);
347 }
348 }
349 if ( (alen > 0) && (ret == 0) )
350 {
351 x = stndup ((const char *) &data[18 + RAFF4_HDR_SIZE + tlen], alen);
352 if (x != NULL)
353 {
354 ret = proc (proc_cls,
355 "real",
356 EXTRACTOR_METATYPE_MIMETYPE,
357 EXTRACTOR_METAFORMAT_UTF8,
358 "text/plain",
359 x,
360 strlen (x)+1);
361 free (x);
362 }
363 }
364 if ( (clen > 0) && (ret == 0) )
365 {
366 x = stndup ((const char *) &data[19 + RAFF4_HDR_SIZE + tlen + alen], clen);
367 if (x != NULL)
368 {
369 ret = proc (proc_cls,
370 "real",
371 EXTRACTOR_METATYPE_MIMETYPE,
372 EXTRACTOR_METAFORMAT_UTF8,
373 "text/plain",
374 x,
375 strlen (x)+1);
376 free (x);
377 }
378 }
379 if ( (aplen > 0) && (ret == 0) )
380 {
381 x = stndup ((const char *) &data[20 + RAFF4_HDR_SIZE + tlen + alen + clen], aplen);
382 if (x != NULL)
383 {
384 ret = proc (proc_cls,
385 "real",
386 EXTRACTOR_METATYPE_MIMETYPE,
387 EXTRACTOR_METAFORMAT_UTF8,
388 "text/plain",
389 x,
390 strlen (x)+1);
391 free (x);
392 }
393 }
394 return ret;
395 } 351 }
352 if ( (alen > 0) && (ret == 0) )
353 {
354 x = stndup ((const char *) &data[18 + RAFF4_HDR_SIZE + tlen], alen);
355 if (x != NULL)
356 {
357 ret = proc (proc_cls,
358 "real",
359 EXTRACTOR_METATYPE_MIMETYPE,
360 EXTRACTOR_METAFORMAT_UTF8,
361 "text/plain",
362 x,
363 strlen (x) + 1);
364 free (x);
365 }
366 }
367 if ( (clen > 0) && (ret == 0) )
368 {
369 x = stndup ((const char *) &data[19 + RAFF4_HDR_SIZE + tlen + alen],
370 clen);
371 if (x != NULL)
372 {
373 ret = proc (proc_cls,
374 "real",
375 EXTRACTOR_METATYPE_MIMETYPE,
376 EXTRACTOR_METAFORMAT_UTF8,
377 "text/plain",
378 x,
379 strlen (x) + 1);
380 free (x);
381 }
382 }
383 if ( (aplen > 0) && (ret == 0) )
384 {
385 x = stndup ((const char *) &data[20 + RAFF4_HDR_SIZE + tlen + alen
386 + clen], aplen);
387 if (x != NULL)
388 {
389 ret = proc (proc_cls,
390 "real",
391 EXTRACTOR_METATYPE_MIMETYPE,
392 EXTRACTOR_METAFORMAT_UTF8,
393 "text/plain",
394 x,
395 strlen (x) + 1);
396 free (x);
397 }
398 }
399 return ret;
400 }
396 if (REAL_HEADER == ntohl (*(int *) data)) 401 if (REAL_HEADER == ntohl (*(int *) data))
402 {
403 /* old real */
404 end = &data[size];
405 pos = &data[0];
406 ret = 0;
407 while (0 == ret)
397 { 408 {
398 /* old real */ 409 if ((pos + 8 >= end) || (pos + 8 < pos))
399 end = &data[size]; 410 break;
400 pos = &data[0]; 411 length = ntohl (*(((unsigned int *) pos) + 1));
401 ret = 0; 412 if (length <= 0)
402 while (0 == ret) 413 break;
403 { 414 if ((pos + length >= end) || (pos + length < pos))
404 if ((pos + 8 >= end) || (pos + 8 < pos)) 415 break;
405 break; 416 switch (ntohl (*((unsigned int *) pos)))
406 length = ntohl (*(((unsigned int *) pos) + 1)); 417 {
407 if (length <= 0) 418 case MDPR_HEADER:
408 break; 419 ret = processMediaProperties ((Media_Properties *) pos,
409 if ((pos + length >= end) || (pos + length < pos)) 420 proc,
410 break; 421 proc_cls);
411 switch (ntohl (*((unsigned int *) pos))) 422 pos += length;
412 { 423 break;
413 case MDPR_HEADER: 424 case CONT_HEADER:
414 ret = processMediaProperties ((Media_Properties *) pos, 425 ret = processContentDescription ((Content_Description *) pos,
415 proc, 426 proc,
416 proc_cls); 427 proc_cls);
417 pos += length; 428 pos += length;
418 break; 429 break;
419 case CONT_HEADER: 430 case REAL_HEADER: /* treat like default */
420 ret = processContentDescription ((Content_Description *) pos, 431 default:
421 proc, 432 pos += length;
422 proc_cls); 433 break;
423 pos += length; 434 }
424 break;
425 case REAL_HEADER: /* treat like default */
426 default:
427 pos += length;
428 break;
429 }
430 }
431 return ret;
432 } 435 }
436 return ret;
437 }
433 return 0; 438 return 0;
434} 439}
diff --git a/src/plugins/ole2_extractor.c b/src/plugins/ole2_extractor.c
index a48b726..38b380a 100644
--- a/src/plugins/ole2_extractor.c
+++ b/src/plugins/ole2_extractor.c
@@ -66,9 +66,9 @@
66 */ 66 */
67static int 67static int
68add_metadata (EXTRACTOR_MetaDataProcessor proc, 68add_metadata (EXTRACTOR_MetaDataProcessor proc,
69 void *proc_cls, 69 void *proc_cls,
70 const char *phrase, 70 const char *phrase,
71 enum EXTRACTOR_MetaType type) 71 enum EXTRACTOR_MetaType type)
72{ 72{
73 char *tmp; 73 char *tmp;
74 int ret; 74 int ret;
@@ -85,15 +85,15 @@ add_metadata (EXTRACTOR_MetaDataProcessor proc,
85 return 0; 85 return 0;
86 86
87 while ( (strlen (tmp) > 0) && 87 while ( (strlen (tmp) > 0) &&
88 (isblank ((unsigned char) tmp [strlen (tmp) - 1])) ) 88 (isblank ((unsigned char) tmp [strlen (tmp) - 1])) )
89 tmp [strlen (tmp) - 1] = '\0'; 89 tmp [strlen (tmp) - 1] = '\0';
90 ret = proc (proc_cls, 90 ret = proc (proc_cls,
91 "ole2", 91 "ole2",
92 type, 92 type,
93 EXTRACTOR_METAFORMAT_UTF8, 93 EXTRACTOR_METAFORMAT_UTF8,
94 "text/plain", 94 "text/plain",
95 tmp, 95 tmp,
96 strlen (tmp) + 1); 96 strlen (tmp) + 1);
97 free (tmp); 97 free (tmp);
98 return ret; 98 return ret;
99} 99}
@@ -133,7 +133,7 @@ static struct Matches tmap[] = {
133 { "RevisionNumber", EXTRACTOR_METATYPE_REVISION_NUMBER }, 133 { "RevisionNumber", EXTRACTOR_METATYPE_REVISION_NUMBER },
134 { "NumBytes", EXTRACTOR_METATYPE_EMBEDDED_FILE_SIZE }, 134 { "NumBytes", EXTRACTOR_METATYPE_EMBEDDED_FILE_SIZE },
135 { "CreatedTime", EXTRACTOR_METATYPE_CREATION_DATE }, 135 { "CreatedTime", EXTRACTOR_METATYPE_CREATION_DATE },
136 { "LastSavedTime" , EXTRACTOR_METATYPE_MODIFICATION_DATE }, 136 { "LastSavedTime", EXTRACTOR_METATYPE_MODIFICATION_DATE },
137 { "gsf:company", EXTRACTOR_METATYPE_COMPANY }, 137 { "gsf:company", EXTRACTOR_METATYPE_COMPANY },
138 { "gsf:character-count", EXTRACTOR_METATYPE_CHARACTER_COUNT }, 138 { "gsf:character-count", EXTRACTOR_METATYPE_CHARACTER_COUNT },
139 { "gsf:page-count", EXTRACTOR_METATYPE_PAGE_COUNT }, 139 { "gsf:page-count", EXTRACTOR_METATYPE_PAGE_COUNT },
@@ -194,8 +194,8 @@ struct ProcContext
194 */ 194 */
195static void 195static void
196process_metadata (gpointer key, 196process_metadata (gpointer key,
197 gpointer value, 197 gpointer value,
198 gpointer user_data) 198 gpointer user_data)
199{ 199{
200 const char *type = key; 200 const char *type = key;
201 const GsfDocProp *prop = value; 201 const GsfDocProp *prop = value;
@@ -211,75 +211,76 @@ process_metadata (gpointer key,
211 return; 211 return;
212 gval = gsf_doc_prop_get_val (prop); 212 gval = gsf_doc_prop_get_val (prop);
213 213
214 if (G_VALUE_TYPE(gval) == G_TYPE_STRING) 214 if (G_VALUE_TYPE (gval) == G_TYPE_STRING)
215 { 215 {
216 const char *gvals; 216 const char *gvals;
217 217
218 gvals = g_value_get_string (gval); 218 gvals = g_value_get_string (gval);
219 if (NULL == gvals) 219 if (NULL == gvals)
220 return; 220 return;
221 contents = strdup (gvals); 221 contents = strdup (gvals);
222 } 222 }
223 else 223 else
224 { 224 {
225 /* convert other formats? */ 225 /* convert other formats? */
226 contents = g_strdup_value_contents (gval); 226 contents = g_strdup_value_contents (gval);
227 } 227 }
228 if (NULL == contents) 228 if (NULL == contents)
229 return; 229 return;
230 if (0 == strcmp (type, 230 if (0 == strcmp (type,
231 "meta:generator")) 231 "meta:generator"))
232 {
233 const char *mimetype = "application/vnd.ms-files";
234 struct
232 { 235 {
233 const char *mimetype = "application/vnd.ms-files"; 236 const char *v;
234 struct { 237 const char *m;
235 const char *v; 238 } mm[] = {
236 const char *m; 239 { "Microsoft Word", "application/msword" },
237 } mm[] = { 240 { "Microsoft Office Word", "application/msword" },
238 { "Microsoft Word", "application/msword" }, 241 { "Microsoft Excel", "application/vnd.ms-excel" },
239 { "Microsoft Office Word", "application/msword" }, 242 { "Microsoft Office Excel", "application/vnd.ms-excel" },
240 { "Microsoft Excel", "application/vnd.ms-excel" }, 243 { "Microsoft PowerPoint", "application/vnd.ms-powerpoint" },
241 { "Microsoft Office Excel", "application/vnd.ms-excel" }, 244 { "Microsoft Office PowerPoint", "application/vnd.ms-powerpoint"},
242 { "Microsoft PowerPoint", "application/vnd.ms-powerpoint" }, 245 { "Microsoft Project", "application/vnd.ms-project" },
243 { "Microsoft Office PowerPoint", "application/vnd.ms-powerpoint"}, 246 { "Microsoft Visio", "application/vnd.visio" },
244 { "Microsoft Project", "application/vnd.ms-project" }, 247 { "Microsoft Office", "application/vnd.ms-office" },
245 { "Microsoft Visio", "application/vnd.visio" }, 248 { NULL, NULL }
246 { "Microsoft Office", "application/vnd.ms-office" }, 249 };
247 { NULL, NULL } 250 int i;
248 }; 251
249 int i; 252 for (i = 0; NULL != mm[i].v; i++)
250 253 if (0 == strncmp (value,
251 for (i=0;NULL != mm[i].v; i++) 254 mm[i].v,
252 if (0 == strncmp (value, 255 strlen (mm[i].v) + 1))
253 mm[i].v, 256 {
254 strlen (mm[i].v) + 1)) 257 mimetype = mm[i].m;
255 { 258 break;
256 mimetype = mm[i].m; 259 }
257 break; 260 if (0 != add_metadata (pc->proc,
258 } 261 pc->proc_cls,
259 if (0 != add_metadata (pc->proc, 262 mimetype,
260 pc->proc_cls, 263 EXTRACTOR_METATYPE_MIMETYPE))
261 mimetype, 264 {
262 EXTRACTOR_METATYPE_MIMETYPE)) 265 free (contents);
263 { 266 pc->ret = 1;
264 free (contents); 267 return;
265 pc->ret = 1;
266 return;
267 }
268 } 268 }
269 }
269 for (pos = 0; NULL != tmap[pos].text; pos++) 270 for (pos = 0; NULL != tmap[pos].text; pos++)
270 if (0 == strcmp (tmap[pos].text, 271 if (0 == strcmp (tmap[pos].text,
271 type)) 272 type))
272 break; 273 break;
273 if ( (NULL != tmap[pos].text) && 274 if ( (NULL != tmap[pos].text) &&
274 (0 != add_metadata (pc->proc, pc->proc_cls, 275 (0 != add_metadata (pc->proc, pc->proc_cls,
275 contents, 276 contents,
276 tmap[pos].type)) ) 277 tmap[pos].type)) )
277 { 278 {
278 free (contents); 279 free (contents);
279 pc->ret = 1; 280 pc->ret = 1;
280 return; 281 return;
281 } 282 }
282 free(contents); 283 free (contents);
283} 284}
284 285
285 286
@@ -294,8 +295,8 @@ process_metadata (gpointer key,
294 */ 295 */
295static int 296static int
296process (GsfInput *in, 297process (GsfInput *in,
297 EXTRACTOR_MetaDataProcessor proc, 298 EXTRACTOR_MetaDataProcessor proc,
298 void *proc_cls) 299 void *proc_cls)
299{ 300{
300 struct ProcContext pc; 301 struct ProcContext pc;
301 GsfDocMetaData *sections; 302 GsfDocMetaData *sections;
@@ -311,15 +312,15 @@ process (GsfInput *in,
311 error = gsf_msole_metadata_read (in, sections); 312 error = gsf_msole_metadata_read (in, sections);
312#endif 313#endif
313 if (NULL == error) 314 if (NULL == error)
314 { 315 {
315 gsf_doc_meta_data_foreach (sections, 316 gsf_doc_meta_data_foreach (sections,
316 &process_metadata, 317 &process_metadata,
317 &pc); 318 &pc);
318 } 319 }
319 else 320 else
320 { 321 {
321 g_error_free (error); 322 g_error_free (error);
322 } 323 }
323 g_object_unref (G_OBJECT (sections)); 324 g_object_unref (G_OBJECT (sections));
324 return pc.ret; 325 return pc.ret;
325} 326}
@@ -336,50 +337,50 @@ process (GsfInput *in,
336 */ 337 */
337static int 338static int
338process_star_office (GsfInput *src, 339process_star_office (GsfInput *src,
339 EXTRACTOR_MetaDataProcessor proc, 340 EXTRACTOR_MetaDataProcessor proc,
340 void *proc_cls) 341 void *proc_cls)
341{ 342{
342 off_t size = gsf_input_size (src); 343 off_t size = gsf_input_size (src);
343 344
344 if ( (size < 0x374) || 345 if ( (size < 0x374) ||
345 (size > 4*1024*1024) ) /* == 0x375?? */ 346 (size > 4 * 1024 * 1024) ) /* == 0x375?? */
346 return 0; 347 return 0;
347 { 348 {
348 char buf[size]; 349 char buf[size];
349 350
350 gsf_input_read (src, size, (unsigned char*) buf); 351 gsf_input_read (src, size, (unsigned char*) buf);
351 if ( (buf[0] != 0x0F) || 352 if ( (buf[0] != 0x0F) ||
352 (buf[1] != 0x0) || 353 (buf[1] != 0x0) ||
353 (0 != strncmp (&buf[2], 354 (0 != strncmp (&buf[2],
354 "SfxDocumentInfo", 355 "SfxDocumentInfo",
355 strlen ("SfxDocumentInfo"))) || 356 strlen ("SfxDocumentInfo"))) ||
356 (buf[0x11] != 0x0B) || 357 (buf[0x11] != 0x0B) ||
357 (buf[0x13] != 0x00) || /* pw protected! */ 358 (buf[0x13] != 0x00) || /* pw protected! */
358 (buf[0x12] != 0x00) ) 359 (buf[0x12] != 0x00) )
359 return 0; 360 return 0;
360 buf[0xd3] = '\0'; 361 buf[0xd3] = '\0';
361 if ( (buf[0x94] + buf[0x93] > 0) && 362 if ( (buf[0x94] + buf[0x93] > 0) &&
362 (0 != add_metadata (proc, proc_cls, 363 (0 != add_metadata (proc, proc_cls,
363 &buf[0x95], 364 &buf[0x95],
364 EXTRACTOR_METATYPE_TITLE)) ) 365 EXTRACTOR_METATYPE_TITLE)) )
365 return 1; 366 return 1;
366 buf[0x114] = '\0'; 367 buf[0x114] = '\0';
367 if ( (buf[0xd5] + buf[0xd4] > 0) && 368 if ( (buf[0xd5] + buf[0xd4] > 0) &&
368 (0 != add_metadata (proc, proc_cls, 369 (0 != add_metadata (proc, proc_cls,
369 &buf[0xd6], 370 &buf[0xd6],
370 EXTRACTOR_METATYPE_SUBJECT)) ) 371 EXTRACTOR_METATYPE_SUBJECT)) )
371 return 1; 372 return 1;
372 buf[0x215] = '\0'; 373 buf[0x215] = '\0';
373 if ( (buf[0x115] + buf[0x116] > 0) && 374 if ( (buf[0x115] + buf[0x116] > 0) &&
374 (0 != add_metadata (proc, proc_cls, 375 (0 != add_metadata (proc, proc_cls,
375 &buf[0x117], 376 &buf[0x117],
376 EXTRACTOR_METATYPE_COMMENT)) ) 377 EXTRACTOR_METATYPE_COMMENT)) )
377 return 1; 378 return 1;
378 buf[0x296] = '\0'; 379 buf[0x296] = '\0';
379 if ( (buf[0x216] + buf[0x217] > 0) && 380 if ( (buf[0x216] + buf[0x217] > 0) &&
380 (0 != add_metadata(proc, proc_cls, 381 (0 != add_metadata (proc, proc_cls,
381 &buf[0x218], 382 &buf[0x218],
382 EXTRACTOR_METATYPE_KEYWORDS)) ) 383 EXTRACTOR_METATYPE_KEYWORDS)) )
383 return 1; 384 return 1;
384 /* fixme: do timestamps, 385 /* fixme: do timestamps,
385 mime-type, user-defined info's */ 386 mime-type, user-defined info's */
@@ -394,7 +395,7 @@ process_star_office (GsfInput *src,
394 * @param a string to translate 395 * @param a string to translate
395 * @return translated string 396 * @return translated string
396 */ 397 */
397#define __(a) dgettext("iso-639", a) 398#define __(a) dgettext ("iso-639", a)
398 399
399 400
400/** 401/**
@@ -408,126 +409,126 @@ static const char *
408lid_to_language (unsigned int lid) 409lid_to_language (unsigned int lid)
409{ 410{
410 switch (lid) 411 switch (lid)
411 { 412 {
412 case 0x0400: 413 case 0x0400:
413 return _("No Proofing"); 414 return _ ("No Proofing");
414 case 0x0401: 415 case 0x0401:
415 return __("Arabic"); 416 return __ ("Arabic");
416 case 0x0402: 417 case 0x0402:
417 return __("Bulgarian"); 418 return __ ("Bulgarian");
418 case 0x0403: 419 case 0x0403:
419 return __("Catalan"); 420 return __ ("Catalan");
420 case 0x0404: 421 case 0x0404:
421 return _("Traditional Chinese"); 422 return _ ("Traditional Chinese");
422 case 0x0804: 423 case 0x0804:
423 return _("Simplified Chinese"); 424 return _ ("Simplified Chinese");
424 case 0x0405: 425 case 0x0405:
425 return __("Chechen"); 426 return __ ("Chechen");
426 case 0x0406: 427 case 0x0406:
427 return __("Danish"); 428 return __ ("Danish");
428 case 0x0407: 429 case 0x0407:
429 return __("German"); 430 return __ ("German");
430 case 0x0807: 431 case 0x0807:
431 return _("Swiss German"); 432 return _ ("Swiss German");
432 case 0x0408: 433 case 0x0408:
433 return __("Greek"); 434 return __ ("Greek");
434 case 0x0409: 435 case 0x0409:
435 return _("U.S. English"); 436 return _ ("U.S. English");
436 case 0x0809: 437 case 0x0809:
437 return _("U.K. English"); 438 return _ ("U.K. English");
438 case 0x0c09: 439 case 0x0c09:
439 return _("Australian English"); 440 return _ ("Australian English");
440 case 0x040a: 441 case 0x040a:
441 return _("Castilian Spanish"); 442 return _ ("Castilian Spanish");
442 case 0x080a: 443 case 0x080a:
443 return _("Mexican Spanish"); 444 return _ ("Mexican Spanish");
444 case 0x040b: 445 case 0x040b:
445 return __("Finnish"); 446 return __ ("Finnish");
446 case 0x040c: 447 case 0x040c:
447 return __("French"); 448 return __ ("French");
448 case 0x080c: 449 case 0x080c:
449 return _("Belgian French"); 450 return _ ("Belgian French");
450 case 0x0c0c: 451 case 0x0c0c:
451 return _("Canadian French"); 452 return _ ("Canadian French");
452 case 0x100c: 453 case 0x100c:
453 return _("Swiss French"); 454 return _ ("Swiss French");
454 case 0x040d: 455 case 0x040d:
455 return __("Hebrew"); 456 return __ ("Hebrew");
456 case 0x040e: 457 case 0x040e:
457 return __("Hungarian"); 458 return __ ("Hungarian");
458 case 0x040f: 459 case 0x040f:
459 return __("Icelandic"); 460 return __ ("Icelandic");
460 case 0x0410: 461 case 0x0410:
461 return __("Italian"); 462 return __ ("Italian");
462 case 0x0810: 463 case 0x0810:
463 return _("Swiss Italian"); 464 return _ ("Swiss Italian");
464 case 0x0411: 465 case 0x0411:
465 return __("Japanese"); 466 return __ ("Japanese");
466 case 0x0412: 467 case 0x0412:
467 return __("Korean"); 468 return __ ("Korean");
468 case 0x0413: 469 case 0x0413:
469 return __("Dutch"); 470 return __ ("Dutch");
470 case 0x0813: 471 case 0x0813:
471 return _("Belgian Dutch"); 472 return _ ("Belgian Dutch");
472 case 0x0414: 473 case 0x0414:
473 return _("Norwegian Bokmal"); 474 return _ ("Norwegian Bokmal");
474 case 0x0814: 475 case 0x0814:
475 return __("Norwegian Nynorsk"); 476 return __ ("Norwegian Nynorsk");
476 case 0x0415: 477 case 0x0415:
477 return __("Polish"); 478 return __ ("Polish");
478 case 0x0416: 479 case 0x0416:
479 return __("Brazilian Portuguese"); 480 return __ ("Brazilian Portuguese");
480 case 0x0816: 481 case 0x0816:
481 return __("Portuguese"); 482 return __ ("Portuguese");
482 case 0x0417: 483 case 0x0417:
483 return _("Rhaeto-Romanic"); 484 return _ ("Rhaeto-Romanic");
484 case 0x0418: 485 case 0x0418:
485 return __("Romanian"); 486 return __ ("Romanian");
486 case 0x0419: 487 case 0x0419:
487 return __("Russian"); 488 return __ ("Russian");
488 case 0x041a: 489 case 0x041a:
489 return _("Croato-Serbian (Latin)"); 490 return _ ("Croato-Serbian (Latin)");
490 case 0x081a: 491 case 0x081a:
491 return _("Serbo-Croatian (Cyrillic)"); 492 return _ ("Serbo-Croatian (Cyrillic)");
492 case 0x041b: 493 case 0x041b:
493 return __("Slovak"); 494 return __ ("Slovak");
494 case 0x041c: 495 case 0x041c:
495 return __("Albanian"); 496 return __ ("Albanian");
496 case 0x041d: 497 case 0x041d:
497 return __("Swedish"); 498 return __ ("Swedish");
498 case 0x041e: 499 case 0x041e:
499 return __("Thai"); 500 return __ ("Thai");
500 case 0x041f: 501 case 0x041f:
501 return __("Turkish"); 502 return __ ("Turkish");
502 case 0x0420: 503 case 0x0420:
503 return __("Urdu"); 504 return __ ("Urdu");
504 case 0x0421: 505 case 0x0421:
505 return __("Bahasa"); 506 return __ ("Bahasa");
506 case 0x0422: 507 case 0x0422:
507 return __("Ukrainian"); 508 return __ ("Ukrainian");
508 case 0x0423: 509 case 0x0423:
509 return __("Byelorussian"); 510 return __ ("Byelorussian");
510 case 0x0424: 511 case 0x0424:
511 return __("Slovenian"); 512 return __ ("Slovenian");
512 case 0x0425: 513 case 0x0425:
513 return __("Estonian"); 514 return __ ("Estonian");
514 case 0x0426: 515 case 0x0426:
515 return __("Latvian"); 516 return __ ("Latvian");
516 case 0x0427: 517 case 0x0427:
517 return __("Lithuanian"); 518 return __ ("Lithuanian");
518 case 0x0429: 519 case 0x0429:
519 return _("Farsi"); 520 return _ ("Farsi");
520 case 0x042D: 521 case 0x042D:
521 return __("Basque"); 522 return __ ("Basque");
522 case 0x042F: 523 case 0x042F:
523 return __("Macedonian"); 524 return __ ("Macedonian");
524 case 0x0436: 525 case 0x0436:
525 return __("Afrikaans"); 526 return __ ("Afrikaans");
526 case 0x043E: 527 case 0x043E:
527 return __("Malayalam"); 528 return __ ("Malayalam");
528 default: 529 default:
529 return NULL; 530 return NULL;
530 } 531 }
531} 532}
532 533
533 534
@@ -543,10 +544,10 @@ lid_to_language (unsigned int lid)
543 */ 544 */
544static int 545static int
545history_extract (GsfInput *stream, 546history_extract (GsfInput *stream,
546 unsigned int lcbSttbSavedBy, 547 unsigned int lcbSttbSavedBy,
547 unsigned int fcSttbSavedBy, 548 unsigned int fcSttbSavedBy,
548 EXTRACTOR_MetaDataProcessor proc, 549 EXTRACTOR_MetaDataProcessor proc,
549 void *proc_cls) 550 void *proc_cls)
550{ 551{
551 unsigned int where; 552 unsigned int where;
552 unsigned char *lbuffer; 553 unsigned char *lbuffer;
@@ -570,64 +571,64 @@ history_extract (GsfInput *stream,
570 nRev = (lbuffer[2] + (lbuffer[3] << 8)) / 2; 571 nRev = (lbuffer[2] + (lbuffer[3] << 8)) / 2;
571 where = 6; 572 where = 6;
572 ret = 0; 573 ret = 0;
573 for (i=0; i < nRev; i++) 574 for (i = 0; i < nRev; i++)
575 {
576 if (where >= lcbSttbSavedBy)
577 break;
578 length = lbuffer[where++];
579 if ( (where + 2 * length + 2 >= lcbSttbSavedBy) ||
580 (where + 2 * length + 2 <= where) )
581 break;
582 author = EXTRACTOR_common_convert_to_utf8 ((const char*) &lbuffer[where],
583 length * 2,
584 "UTF-16BE");
585 where += length * 2 + 1;
586 length = lbuffer[where++];
587 if ( (where + 2 * length >= lcbSttbSavedBy) ||
588 (where + 2 * length + 1 <= where) )
574 { 589 {
575 if (where >= lcbSttbSavedBy)
576 break;
577 length = lbuffer[where++];
578 if ( (where + 2 * length + 2 >= lcbSttbSavedBy) ||
579 (where + 2 * length + 2 <= where) )
580 break;
581 author = EXTRACTOR_common_convert_to_utf8 ((const char*) &lbuffer[where],
582 length * 2,
583 "UTF-16BE");
584 where += length * 2 + 1;
585 length = lbuffer[where++];
586 if ( (where + 2 * length >= lcbSttbSavedBy) ||
587 (where + 2 * length + 1 <= where) )
588 {
589 if (NULL != author)
590 free(author);
591 break;
592 }
593 filename = EXTRACTOR_common_convert_to_utf8 ((const char*) &lbuffer[where],
594 length * 2,
595 "UTF-16BE");
596 where += length * 2 + 1;
597 if ( (NULL != author) &&
598 (NULL != filename) )
599 {
600 size_t bsize;
601
602 bsize = strlen (author) + strlen (filename) + 512;
603 if (NULL != (rbuf = malloc (bsize)))
604 {
605 int snret;
606
607 snret = snprintf (rbuf,
608 bsize,
609 _("Revision #%u: Author `%s' worked on `%s'"),
610 i,
611 author,
612 filename);
613 if ( (-1 != snret) &&
614 (bsize > (size_t) snret) )
615 {
616 ret = add_metadata (proc,
617 proc_cls,
618 rbuf,
619 EXTRACTOR_METATYPE_REVISION_HISTORY);
620 }
621 free (rbuf);
622 }
623 }
624 if (NULL != author) 590 if (NULL != author)
625 free (author); 591 free (author);
626 if (NULL != filename) 592 break;
627 free (filename); 593 }
628 if (0 != ret) 594 filename = EXTRACTOR_common_convert_to_utf8 ((const char*) &lbuffer[where],
629 break; 595 length * 2,
596 "UTF-16BE");
597 where += length * 2 + 1;
598 if ( (NULL != author) &&
599 (NULL != filename) )
600 {
601 size_t bsize;
602
603 bsize = strlen (author) + strlen (filename) + 512;
604 if (NULL != (rbuf = malloc (bsize)))
605 {
606 int snret;
607
608 snret = snprintf (rbuf,
609 bsize,
610 _ ("Revision #%u: Author `%s' worked on `%s'"),
611 i,
612 author,
613 filename);
614 if ( (-1 != snret) &&
615 (bsize > (size_t) snret) )
616 {
617 ret = add_metadata (proc,
618 proc_cls,
619 rbuf,
620 EXTRACTOR_METATYPE_REVISION_HISTORY);
621 }
622 free (rbuf);
623 }
630 } 624 }
625 if (NULL != author)
626 free (author);
627 if (NULL != filename)
628 free (filename);
629 if (0 != ret)
630 break;
631 }
631 free (lbuffer); 632 free (lbuffer);
632 return ret; 633 return ret;
633} 634}
@@ -636,11 +637,19 @@ history_extract (GsfInput *stream,
636/* *************************** custom GSF input method ***************** */ 637/* *************************** custom GSF input method ***************** */
637 638
638#define LE_TYPE_INPUT (le_input_get_type ()) 639#define LE_TYPE_INPUT (le_input_get_type ())
639#define LE_INPUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LE_TYPE_INPUT, LeInput)) 640#define LE_INPUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
640#define LE_INPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LE_TYPE_INPUT, LeInputClass)) 641 LE_TYPE_INPUT, \
641#define IS_LE_INPUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LE_TYPE_INPUT)) 642 LeInput))
642#define IS_LE_INPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LE_TYPE_INPUT)) 643#define LE_INPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), \
643#define LE_INPUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LE_TYPE_INPUT, LeInputClass)) 644 LE_TYPE_INPUT, \
645 LeInputClass))
646#define IS_LE_INPUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
647 LE_TYPE_INPUT))
648#define IS_LE_INPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), \
649 LE_TYPE_INPUT))
650#define LE_INPUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
651 LE_TYPE_INPUT, \
652 LeInputClass))
644 653
645/** 654/**
646 * Internal state of an "LeInput" object. 655 * Internal state of an "LeInput" object.
@@ -683,10 +692,10 @@ typedef struct _LeInputClass
683 GsfInputClass parent_class; 692 GsfInputClass parent_class;
684 693
685 /* Padding for future expansion */ 694 /* Padding for future expansion */
686 void (*_gtk_reserved1) (void); 695 void (*_gtk_reserved1)(void);
687 void (*_gtk_reserved2) (void); 696 void (*_gtk_reserved2)(void);
688 void (*_gtk_reserved3) (void); 697 void (*_gtk_reserved3)(void);
689 void (*_gtk_reserved4) (void); 698 void (*_gtk_reserved4)(void);
690} LeInputClass; 699} LeInputClass;
691 700
692 701
@@ -721,7 +730,8 @@ le_input_init (LeInput *input);
721/** 730/**
722 * Macro to create LeInput type definition and register the class. 731 * Macro to create LeInput type definition and register the class.
723 */ 732 */
724GSF_CLASS (LeInput, le_input, le_input_class_init, le_input_init, GSF_INPUT_TYPE) 733GSF_CLASS (LeInput, le_input, le_input_class_init, le_input_init,
734 GSF_INPUT_TYPE)
725 735
726 736
727/** 737/**
@@ -732,12 +742,12 @@ GSF_CLASS (LeInput, le_input, le_input_class_init, le_input_init, GSF_INPUT_TYPE
732 * @return NULL on error (always) 742 * @return NULL on error (always)
733 */ 743 */
734static GsfInput * 744static GsfInput *
735le_input_dup (GsfInput *input, 745le_input_dup (GsfInput * input,
736 GError **err) 746 GError * *err)
737{ 747{
738 if (NULL != err) 748 if (NULL != err)
739 *err = g_error_new (gsf_input_error_id (), 0, 749 *err = g_error_new (gsf_input_error_id (), 0,
740 "dup not supported on LeInput"); 750 "dup not supported on LeInput");
741 return NULL; 751 return NULL;
742} 752}
743 753
@@ -755,8 +765,8 @@ le_input_dup (GsfInput *input,
755 */ 765 */
756static const guint8 * 766static const guint8 *
757le_input_read (GsfInput *input, 767le_input_read (GsfInput *input,
758 size_t num_bytes, 768 size_t num_bytes,
759 guint8 *optional_buffer) 769 guint8 *optional_buffer)
760{ 770{
761 LeInput *li = LE_INPUT (input); 771 LeInput *li = LE_INPUT (input);
762 struct EXTRACTOR_ExtractContext *ec; 772 struct EXTRACTOR_ExtractContext *ec;
@@ -768,21 +778,21 @@ le_input_read (GsfInput *input,
768 old_off = ec->seek (ec->cls, 0, SEEK_CUR); 778 old_off = ec->seek (ec->cls, 0, SEEK_CUR);
769 if (num_bytes 779 if (num_bytes
770 != (ret = ec->read (ec->cls, 780 != (ret = ec->read (ec->cls,
771 &buf, 781 &buf,
772 num_bytes))) 782 num_bytes)))
773 { 783 {
774 /* we don't support partial reads; 784 /* we don't support partial reads;
775 most other GsfInput implementations in this case 785 most other GsfInput implementations in this case
776 allocate some huge temporary buffer just to avoid 786 allocate some huge temporary buffer just to avoid
777 the partial read; we might need to do that as well!? */ 787 the partial read; we might need to do that as well!? */
778 ec->seek (ec->cls, SEEK_SET, old_off); 788 ec->seek (ec->cls, SEEK_SET, old_off);
779 return NULL; 789 return NULL;
780 } 790 }
781 if (NULL != optional_buffer) 791 if (NULL != optional_buffer)
782 { 792 {
783 memcpy (optional_buffer, buf, num_bytes); 793 memcpy (optional_buffer, buf, num_bytes);
784 return optional_buffer; 794 return optional_buffer;
785 } 795 }
786 return buf; 796 return buf;
787} 797}
788 798
@@ -797,8 +807,8 @@ le_input_read (GsfInput *input,
797 */ 807 */
798static gboolean 808static gboolean
799le_input_seek (GsfInput *input, 809le_input_seek (GsfInput *input,
800 gsf_off_t offset, 810 gsf_off_t offset,
801 GSeekType whence) 811 GSeekType whence)
802{ 812{
803 LeInput *li = LE_INPUT (input); 813 LeInput *li = LE_INPUT (input);
804 struct EXTRACTOR_ExtractContext *ec; 814 struct EXTRACTOR_ExtractContext *ec;
@@ -807,23 +817,23 @@ le_input_seek (GsfInput *input,
807 817
808 ec = li->priv->ec; 818 ec = li->priv->ec;
809 switch (whence) 819 switch (whence)
810 { 820 {
811 case G_SEEK_SET: 821 case G_SEEK_SET:
812 w = SEEK_SET; 822 w = SEEK_SET;
813 break; 823 break;
814 case G_SEEK_CUR: 824 case G_SEEK_CUR:
815 w = SEEK_CUR; 825 w = SEEK_CUR;
816 break; 826 break;
817 case G_SEEK_END: 827 case G_SEEK_END:
818 w = SEEK_END; 828 w = SEEK_END;
819 break; 829 break;
820 default: 830 default:
821 return TRUE; 831 return TRUE;
822 } 832 }
823 if (-1 == 833 if (-1 ==
824 (ret = ec->seek (ec->cls, 834 (ret = ec->seek (ec->cls,
825 offset, 835 offset,
826 w))) 836 w)))
827 return TRUE; 837 return TRUE;
828 return FALSE; 838 return FALSE;
829} 839}
@@ -859,7 +869,7 @@ le_input_init (LeInput *input)
859 869
860 input->priv = 870 input->priv =
861 G_TYPE_INSTANCE_GET_PRIVATE (input, LE_TYPE_INPUT, 871 G_TYPE_INSTANCE_GET_PRIVATE (input, LE_TYPE_INPUT,
862 LeInputPrivate); 872 LeInputPrivate);
863 priv = input->priv; 873 priv = input->priv;
864 priv->ec = NULL; 874 priv->ec = NULL;
865} 875}
@@ -878,9 +888,9 @@ le_input_new (struct EXTRACTOR_ExtractContext *ec)
878 888
879 input = g_object_new (LE_TYPE_INPUT, NULL); 889 input = g_object_new (LE_TYPE_INPUT, NULL);
880 gsf_input_set_size (GSF_INPUT (input), 890 gsf_input_set_size (GSF_INPUT (input),
881 ec->get_size (ec->cls)); 891 ec->get_size (ec->cls));
882 gsf_input_seek_emulate (GSF_INPUT (input), 892 gsf_input_seek_emulate (GSF_INPUT (input),
883 0); 893 0);
884 input->input.name = NULL; 894 input->input.name = NULL;
885 input->input.container = NULL; 895 input->input.container = NULL;
886 input->priv->ec = ec; 896 input->priv->ec = ec;
@@ -889,8 +899,6 @@ le_input_new (struct EXTRACTOR_ExtractContext *ec)
889} 899}
890 900
891 901
892
893
894/* *********************** end of custom GSF input method ************* */ 902/* *********************** end of custom GSF input method ************* */
895 903
896 904
@@ -919,90 +927,92 @@ EXTRACTOR_ole2_extract_method (struct EXTRACTOR_ExtractContext *ec)
919 927
920 fsize = ec->get_size (ec->cls); 928 fsize = ec->get_size (ec->cls);
921 if (fsize < 512 + 898) 929 if (fsize < 512 + 898)
922 { 930 {
923 /* File too small for OLE2 */ 931 /* File too small for OLE2 */
924 return; /* can hardly be OLE2 */ 932 return; /* can hardly be OLE2 */
925 } 933 }
926 if (512 + 898 > (data_size = ec->read (ec->cls, &data, fsize))) 934 if (512 + 898 > (data_size = ec->read (ec->cls, &data, fsize)))
927 { 935 {
928 /* Failed to read minimum file size to buffer */ 936 /* Failed to read minimum file size to buffer */
929 return; 937 return;
930 } 938 }
931 data512 = (const unsigned char*) data + 512; 939 data512 = (const unsigned char*) data + 512;
932 lid = data512[6] + (data512[7] << 8); 940 lid = data512[6] + (data512[7] << 8);
933 if ( (NULL != (lang = lid_to_language (lid))) && 941 if ( (NULL != (lang = lid_to_language (lid))) &&
934 (0 != (ret = add_metadata (ec->proc, ec->cls, 942 (0 != (ret = add_metadata (ec->proc, ec->cls,
935 lang, 943 lang,
936 EXTRACTOR_METATYPE_LANGUAGE))) ) 944 EXTRACTOR_METATYPE_LANGUAGE))) )
937 return; 945 return;
938 lcb = data512[726] + (data512[727] << 8) + (data512[728] << 16) + (data512[729] << 24); 946 lcb = data512[726] + (data512[727] << 8) + (data512[728] << 16)
939 fcb = data512[722] + (data512[723] << 8) + (data512[724] << 16) + (data512[725] << 24); 947 + (data512[729] << 24);
948 fcb = data512[722] + (data512[723] << 8) + (data512[724] << 16)
949 + (data512[725] << 24);
940 if (0 != ec->seek (ec->cls, 0, SEEK_SET)) 950 if (0 != ec->seek (ec->cls, 0, SEEK_SET))
941 { 951 {
942 /* seek failed!? */ 952 /* seek failed!? */
943 return; 953 return;
944 } 954 }
945#if USE_LE_INPUT 955#if USE_LE_INPUT
946 if (NULL == (input = le_input_new (ec))) 956 if (NULL == (input = le_input_new (ec)))
947 { 957 {
948 fprintf (stderr, "le_input_new failed\n"); 958 fprintf (stderr, "le_input_new failed\n");
949 return; 959 return;
950 } 960 }
951#else 961#else
952 input = gsf_input_memory_new ((const guint8 *) data, 962 input = gsf_input_memory_new ((const guint8 *) data,
953 data_size, 963 data_size,
954 FALSE); 964 FALSE);
955#endif 965#endif
956 if (NULL == (infile = gsf_infile_msole_new (input, NULL))) 966 if (NULL == (infile = gsf_infile_msole_new (input, NULL)))
957 { 967 {
958 g_object_unref (G_OBJECT (input)); 968 g_object_unref (G_OBJECT (input));
959 return; 969 return;
960 } 970 }
961 ret = 0; 971 ret = 0;
962 for (i=0;i<gsf_infile_num_children (infile);i++) 972 for (i = 0; i<gsf_infile_num_children (infile); i++)
963 { 973 {
964 if (0 != ret) 974 if (0 != ret)
965 break; 975 break;
966 if (NULL == (name = gsf_infile_name_by_index (infile, i))) 976 if (NULL == (name = gsf_infile_name_by_index (infile, i)))
967 continue; 977 continue;
968 src = NULL; 978 src = NULL;
969 if ( ( (0 == strcmp (name, "\005SummaryInformation")) || 979 if ( ( (0 == strcmp (name, "\005SummaryInformation")) ||
970 (0 == strcmp (name, "\005DocumentSummaryInformation")) ) && 980 (0 == strcmp (name, "\005DocumentSummaryInformation")) ) &&
971 (NULL != (src = gsf_infile_child_by_index (infile, i))) ) 981 (NULL != (src = gsf_infile_child_by_index (infile, i))) )
972 ret = process (src, 982 ret = process (src,
973 ec->proc, 983 ec->proc,
974 ec->cls); 984 ec->cls);
975 if ( (0 == strcmp (name, "SfxDocumentInfo")) && 985 if ( (0 == strcmp (name, "SfxDocumentInfo")) &&
976 (NULL != (src = gsf_infile_child_by_index (infile, i))) ) 986 (NULL != (src = gsf_infile_child_by_index (infile, i))) )
977 ret = process_star_office (src, 987 ret = process_star_office (src,
978 ec->proc, 988 ec->proc,
979 ec->cls); 989 ec->cls);
980 if (NULL != src) 990 if (NULL != src)
981 g_object_unref (G_OBJECT (src)); 991 g_object_unref (G_OBJECT (src));
982 } 992 }
983 if (0 != ret) 993 if (0 != ret)
984 goto CLEANUP; 994 goto CLEANUP;
985 995
986 if (lcb < 6) 996 if (lcb < 6)
987 goto CLEANUP; 997 goto CLEANUP;
988 for (i=0;i<gsf_infile_num_children (infile);i++) 998 for (i = 0; i<gsf_infile_num_children (infile); i++)
999 {
1000 if (ret != 0)
1001 break;
1002 if (NULL == (name = gsf_infile_name_by_index (infile, i)))
1003 continue;
1004 if ( ( (0 == strcmp (name, "1Table")) ||
1005 (0 == strcmp (name, "0Table")) ) &&
1006 (NULL != (src = gsf_infile_child_by_index (infile, i))) )
989 { 1007 {
990 if (ret != 0) 1008 ret = history_extract (src,
991 break; 1009 lcb,
992 if (NULL == (name = gsf_infile_name_by_index (infile, i))) 1010 fcb,
993 continue; 1011 ec->proc, ec->cls);
994 if ( ( (0 == strcmp (name, "1Table")) || 1012 g_object_unref (G_OBJECT (src));
995 (0 == strcmp (name, "0Table")) ) &&
996 (NULL != (src = gsf_infile_child_by_index (infile, i))) )
997 {
998 ret = history_extract (src,
999 lcb,
1000 fcb,
1001 ec->proc, ec->cls);
1002 g_object_unref (G_OBJECT (src));
1003 }
1004 } 1013 }
1005 CLEANUP: 1014 }
1015CLEANUP:
1006 g_object_unref (G_OBJECT (infile)); 1016 g_object_unref (G_OBJECT (infile));
1007 g_object_unref (G_OBJECT (input)); 1017 g_object_unref (G_OBJECT (input));
1008} 1018}
@@ -1031,18 +1041,18 @@ nolog (const gchar *log_domain,
1031 * gsf logging is disabled. 1041 * gsf logging is disabled.
1032 */ 1042 */
1033void __attribute__ ((constructor)) 1043void __attribute__ ((constructor))
1034ole2_ltdl_init() 1044ole2_ltdl_init ()
1035{ 1045{
1036#if !GLIB_CHECK_VERSION(2, 35, 0) 1046#if ! GLIB_CHECK_VERSION (2, 35, 0)
1037 g_type_init (); 1047 g_type_init ();
1038#endif 1048#endif
1039#ifdef HAVE_GSF_INIT 1049#ifdef HAVE_GSF_INIT
1040 gsf_init(); 1050 gsf_init ();
1041#endif 1051#endif
1042 /* disable logging -- thanks, Jody! */ 1052 /* disable logging -- thanks, Jody! */
1043 g_log_set_handler ("libgsf:msole", 1053 g_log_set_handler ("libgsf:msole",
1044 G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING, 1054 G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
1045 &nolog, NULL); 1055 &nolog, NULL);
1046} 1056}
1047 1057
1048 1058
@@ -1050,10 +1060,10 @@ ole2_ltdl_init()
1050 * OLE2 plugin destructor. Shutdown of gsf. 1060 * OLE2 plugin destructor. Shutdown of gsf.
1051 */ 1061 */
1052void __attribute__ ((destructor)) 1062void __attribute__ ((destructor))
1053ole2_ltdl_fini() 1063ole2_ltdl_fini ()
1054{ 1064{
1055#ifdef HAVE_GSF_INIT 1065#ifdef HAVE_GSF_INIT
1056 gsf_shutdown(); 1066 gsf_shutdown ();
1057#endif 1067#endif
1058} 1068}
1059 1069
diff --git a/src/plugins/pdf_extractor.c b/src/plugins/pdf_extractor.c
index da1f663..1bf3c84 100644
--- a/src/plugins/pdf_extractor.c
+++ b/src/plugins/pdf_extractor.c
@@ -80,8 +80,8 @@ static struct Matches tmap[] = {
80 */ 80 */
81static void 81static void
82process_stdout (FILE *fout, 82process_stdout (FILE *fout,
83 EXTRACTOR_MetaDataProcessor proc, 83 EXTRACTOR_MetaDataProcessor proc,
84 void *proc_cls) 84 void *proc_cls)
85{ 85{
86 unsigned int i; 86 unsigned int i;
87 char line[1025]; 87 char line[1025];
@@ -89,38 +89,38 @@ process_stdout (FILE *fout,
89 const char *colon; 89 const char *colon;
90 90
91 while (! feof (fout)) 91 while (! feof (fout))
92 {
93 if (NULL == fgets (line, sizeof (line) - 1, fout))
94 break;
95 if (0 == strlen (line))
96 continue;
97 if ('\n' == line[strlen (line) - 1])
98 line[strlen (line) - 1] = '\0';
99 colon = strchr (line, (int) ':');
100 if (NULL == colon)
101 break;
102 psuffix = colon + 1;
103 while (isblank ((unsigned char) psuffix[0]))
104 psuffix++;
105 if (0 == strlen (psuffix))
106 continue;
107 for (i = 0; NULL != tmap[i].text; i++)
92 { 108 {
93 if (NULL == fgets (line, sizeof (line) - 1, fout)) 109 if (0 != strncasecmp (line,
94 break; 110 tmap[i].text,
95 if (0 == strlen (line)) 111 colon - line))
96 continue;
97 if ('\n' == line[strlen(line)-1])
98 line[strlen(line)-1] = '\0';
99 colon = strchr (line, (int) ':');
100 if (NULL == colon)
101 break;
102 psuffix = colon + 1;
103 while (isblank ((unsigned char) psuffix[0]))
104 psuffix++;
105 if (0 == strlen (psuffix))
106 continue; 112 continue;
107 for (i = 0; NULL != tmap[i].text; i++) 113 if (0 != proc (proc_cls,
108 { 114 "pdf",
109 if (0 != strncasecmp (line, 115 tmap[i].type,
110 tmap[i].text, 116 EXTRACTOR_METAFORMAT_UTF8,
111 colon - line)) 117 "text/plain",
112 continue; 118 psuffix,
113 if (0 != proc (proc_cls, 119 strlen (psuffix) + 1))
114 "pdf", 120 return;
115 tmap[i].type, 121 break;
116 EXTRACTOR_METAFORMAT_UTF8,
117 "text/plain",
118 psuffix,
119 strlen(psuffix) + 1))
120 return;
121 break;
122 }
123 } 122 }
123 }
124} 124}
125 125
126 126
@@ -154,79 +154,79 @@ EXTRACTOR_pdf_extract_method (struct EXTRACTOR_ExtractContext *ec)
154 if (0 != pipe (in)) 154 if (0 != pipe (in))
155 return; 155 return;
156 if (0 != pipe (out)) 156 if (0 != pipe (out))
157 { 157 {
158 close (in[0]); 158 close (in[0]);
159 close (in[1]); 159 close (in[1]);
160 return; 160 return;
161 } 161 }
162 pid = fork (); 162 pid = fork ();
163 if (-1 == pid) 163 if (-1 == pid)
164 { 164 {
165 close (in[0]); 165 close (in[0]);
166 close (in[1]); 166 close (in[1]);
167 close (out[0]); 167 close (out[0]);
168 close (out[1]); 168 close (out[1]);
169 return; 169 return;
170 } 170 }
171 if (0 == pid) 171 if (0 == pid)
172 { 172 {
173 char *const args[] = { 173 char *const args[] = {
174 "pdfinfo", 174 "pdfinfo",
175 "-", 175 "-",
176 NULL 176 NULL
177 }; 177 };
178 /* am child, exec 'pdfinfo' */ 178 /* am child, exec 'pdfinfo' */
179 close (0); 179 close (0);
180 close (1); 180 close (1);
181 if ( (-1 == dup2 (in[0], 0)) || 181 if ( (-1 == dup2 (in[0], 0)) ||
182 (-1 == dup2 (out[1], 1)) ) 182 (-1 == dup2 (out[1], 1)) )
183 exit (1);
184 close (in[0]);
185 close (in[1]);
186 close (out[0]);
187 close (out[1]);
188 execvp ("pdfinfo", args);
189 exit (1); 183 exit (1);
190 } 184 close (in[0]);
185 close (in[1]);
186 close (out[0]);
187 close (out[1]);
188 execvp ("pdfinfo", args);
189 exit (1);
190 }
191 /* am parent, send file */ 191 /* am parent, send file */
192 close (in[0]); 192 close (in[0]);
193 close (out[1]); 193 close (out[1]);
194 fout = fdopen (out[0], "r"); 194 fout = fdopen (out[0], "r");
195 if (NULL == fout) 195 if (NULL == fout)
196 { 196 {
197 close (in[1]); 197 close (in[1]);
198 close (out[0]); 198 close (out[0]);
199 kill (pid, SIGKILL); 199 kill (pid, SIGKILL);
200 waitpid (pid, NULL, 0); 200 waitpid (pid, NULL, 0);
201 return; 201 return;
202 } 202 }
203 pos = 0; 203 pos = 0;
204 while (pos < fsize) 204 while (pos < fsize)
205 {
206 ssize_t got;
207 size_t wpos;
208
209 data = NULL;
210 got = ec->read (ec->cls,
211 &data,
212 fsize - pos);
213 if ( (-1 == got) ||
214 (NULL == data) )
215 break;
216 wpos = 0;
217 while (wpos < got)
205 { 218 {
206 ssize_t got; 219 ssize_t out;
207 size_t wpos; 220
208 221 out = write (in[1], data + wpos, got - wpos);
209 data = NULL; 222 if (out <= 0)
210 got = ec->read (ec->cls,
211 &data,
212 fsize - pos);
213 if ( (-1 == got) ||
214 (NULL == data) )
215 break;
216 wpos = 0;
217 while (wpos < got)
218 {
219 ssize_t out;
220
221 out = write (in[1], data + wpos, got - wpos);
222 if (out <= 0)
223 break;
224 wpos += out;
225 }
226 if (wpos < got)
227 break; 223 break;
228 pos += got; 224 wpos += out;
229 } 225 }
226 if (wpos < got)
227 break;
228 pos += got;
229 }
230 close (in[1]); 230 close (in[1]);
231 process_stdout (fout, ec->proc, ec->cls); 231 process_stdout (fout, ec->proc, ec->cls);
232 fclose (fout); 232 fclose (fout);
@@ -234,4 +234,5 @@ EXTRACTOR_pdf_extract_method (struct EXTRACTOR_ExtractContext *ec)
234 waitpid (pid, NULL, 0); 234 waitpid (pid, NULL, 0);
235} 235}
236 236
237
237/* end of pdf_extractor.c */ 238/* end of pdf_extractor.c */
diff --git a/src/plugins/png_extractor.c b/src/plugins/png_extractor.c
index add1fde..fec6c17 100644
--- a/src/plugins/png_extractor.c
+++ b/src/plugins/png_extractor.c
@@ -43,7 +43,7 @@
43 */ 43 */
44static char * 44static char *
45stndup (const char *str, 45stndup (const char *str,
46 size_t n) 46 size_t n)
47{ 47{
48 char *tmp; 48 char *tmp;
49 49
@@ -67,13 +67,13 @@ stndup (const char *str,
67 */ 67 */
68static size_t 68static size_t
69stnlen (const char *str, 69stnlen (const char *str,
70 size_t maxlen) 70 size_t maxlen)
71{ 71{
72 size_t ret; 72 size_t ret;
73 73
74 ret = 0; 74 ret = 0;
75 while ( (ret < maxlen) && 75 while ( (ret < maxlen) &&
76 ('\0' != str[ret]) ) 76 ('\0' != str[ret]) )
77 ret++; 77 ret++;
78 return ret; 78 return ret;
79} 79}
@@ -111,8 +111,7 @@ static struct
111 * Corresponding LE type. 111 * Corresponding LE type.
112 */ 112 */
113 enum EXTRACTOR_MetaType type; 113 enum EXTRACTOR_MetaType type;
114} tagmap[] = 114} tagmap[] = {
115{
116 { "Author", EXTRACTOR_METATYPE_AUTHOR_NAME }, 115 { "Author", EXTRACTOR_METATYPE_AUTHOR_NAME },
117 { "Description", EXTRACTOR_METATYPE_DESCRIPTION }, 116 { "Description", EXTRACTOR_METATYPE_DESCRIPTION },
118 { "Comment", EXTRACTOR_METATYPE_COMMENT }, 117 { "Comment", EXTRACTOR_METATYPE_COMMENT },
@@ -135,7 +134,11 @@ static struct
135 * @param t type of the metadata 134 * @param t type of the metadata
136 * @param s utf8 string with the metadata 135 * @param s utf8 string with the metadata
137 */ 136 */
138#define ADD(t,s) do { if (0 != (ret = ec->proc (ec->cls, "png", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen (s) + 1))) goto FINISH; } while (0) 137#define ADD(t,s) do { if (0 != (ret = ec->proc (ec->cls, "png", t, \
138 EXTRACTOR_METAFORMAT_UTF8, \
139 "text/plain", s, strlen (s) \
140 + 1))) goto FINISH; \
141} while (0)
139 142
140 143
141/** 144/**
@@ -145,7 +148,14 @@ static struct
145 * @param t type of the metadata 148 * @param t type of the metadata
146 * @param s utf8 string with the metadata, to be freed afterwards 149 * @param s utf8 string with the metadata, to be freed afterwards
147 */ 150 */
148#define ADDF(t,s) do { if ( (NULL != s) && (0 != (ret = ec->proc (ec->cls, "png", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen (s) + 1))) ) { free (s); goto FINISH; } if (NULL != s) free (s); } while (0) 151#define ADDF(t,s) do { if ( (NULL != s) && (0 != (ret = ec->proc (ec->cls, \
152 "png", t, \
153 EXTRACTOR_METAFORMAT_UTF8, \
154 "text/plain", \
155 s, strlen (s) \
156 + 1))) ) { \
157 free (s); goto FINISH; } if (NULL != s) free (s); \
158} while (0)
149 159
150 160
151/** 161/**
@@ -173,16 +183,16 @@ processtEXt (struct EXTRACTOR_ExtractContext *ec,
173 if (off >= length) 183 if (off >= length)
174 return 0; /* failed to find '\0' */ 184 return 0; /* failed to find '\0' */
175 if (NULL == (keyword = EXTRACTOR_common_convert_to_utf8 ((char*) &data[off], 185 if (NULL == (keyword = EXTRACTOR_common_convert_to_utf8 ((char*) &data[off],
176 length - off, 186 length - off,
177 "ISO-8859-1"))) 187 "ISO-8859-1")))
178 return 0; 188 return 0;
179 ret = 0; 189 ret = 0;
180 for (i = 0; NULL != tagmap[i].name; i++) 190 for (i = 0; NULL != tagmap[i].name; i++)
181 if (0 == strcmp (tagmap[i].name, (char*) data)) 191 if (0 == strcmp (tagmap[i].name, (char*) data))
182 { 192 {
183 ADDF (tagmap[i].type, keyword); 193 ADDF (tagmap[i].type, keyword);
184 return 0; 194 return 0;
185 } 195 }
186 ADDF (EXTRACTOR_METATYPE_KEYWORDS, keyword); 196 ADDF (EXTRACTOR_METATYPE_KEYWORDS, keyword);
187FINISH: 197FINISH:
188 return ret; 198 return ret;
@@ -242,50 +252,50 @@ processiTXt (struct EXTRACTOR_ExtractContext *ec,
242 return 0; 252 return 0;
243 253
244 if (compressed) 254 if (compressed)
255 {
256 bufLen = 1024 + 2 * (length - pos);
257 while (1)
245 { 258 {
246 bufLen = 1024 + 2 * (length - pos); 259 if (bufLen * 2 < bufLen)
247 while (1) 260 return 0;
248 { 261 bufLen *= 2;
249 if (bufLen * 2 < bufLen) 262 if (bufLen > 50 * (length - pos))
250 return 0; 263 {
251 bufLen *= 2; 264 /* printf("zlib problem"); */
252 if (bufLen > 50 * (length - pos)) 265 return 0;
253 { 266 }
254 /* printf("zlib problem"); */ 267 if (NULL == (buf = malloc (bufLen)))
255 return 0; 268 {
256 } 269 /* printf("out of memory"); */
257 if (NULL == (buf = malloc (bufLen))) 270 return 0; /* out of memory */
258 { 271 }
259 /* printf("out of memory"); */ 272 if (Z_OK ==
260 return 0; /* out of memory */ 273 (zret = uncompress ((Bytef *) buf,
261 } 274 &bufLen,
262 if (Z_OK == 275 (const Bytef *) &data[pos], length - pos)))
263 (zret = uncompress ((Bytef *) buf, 276 {
264 &bufLen, 277 /* printf("zlib ok"); */
265 (const Bytef *) &data[pos], length - pos))) 278 break;
266 { 279 }
267 /* printf("zlib ok"); */
268 break;
269 }
270 free (buf);
271 if (Z_BUF_ERROR != zret)
272 return 0; /* unknown error, abort */
273 }
274 keyword = stndup (buf, bufLen);
275 free (buf); 280 free (buf);
281 if (Z_BUF_ERROR != zret)
282 return 0; /* unknown error, abort */
276 } 283 }
284 keyword = stndup (buf, bufLen);
285 free (buf);
286 }
277 else 287 else
278 { 288 {
279 keyword = stndup ((char *) &data[pos], length - pos); 289 keyword = stndup ((char *) &data[pos], length - pos);
280 } 290 }
281 if (NULL == keyword) 291 if (NULL == keyword)
282 return ret; 292 return ret;
283 for (i = 0; NULL != tagmap[i].name; i++) 293 for (i = 0; NULL != tagmap[i].name; i++)
284 if (0 == strcmp (tagmap[i].name, (char*) data)) 294 if (0 == strcmp (tagmap[i].name, (char*) data))
285 { 295 {
286 ADDF (tagmap[i].type, keyword /* already in utf8 */); 296 ADDF (tagmap[i].type, keyword /* already in utf8 */);
287 return 0; 297 return 0;
288 } 298 }
289 ADDF (EXTRACTOR_METATYPE_COMMENT, keyword); 299 ADDF (EXTRACTOR_METATYPE_COMMENT, keyword);
290FINISH: 300FINISH:
291 return ret; 301 return ret;
@@ -357,43 +367,43 @@ processzTXt (struct EXTRACTOR_ExtractContext *ec,
357 ret = 0; 367 ret = 0;
358 bufLen = 1024 + 2 * (length - off); 368 bufLen = 1024 + 2 * (length - off);
359 while (1) 369 while (1)
370 {
371 if (bufLen * 2 < bufLen)
372 return 0;
373 bufLen *= 2;
374 if (bufLen > 50 * (length - off))
360 { 375 {
361 if (bufLen * 2 < bufLen) 376 /* printf("zlib problem"); */
362 return 0; 377 return 0;
363 bufLen *= 2; 378 }
364 if (bufLen > 50 * (length - off)) 379 if (NULL == (buf = malloc (bufLen)))
365 { 380 {
366 /* printf("zlib problem"); */ 381 /* printf("out of memory"); */
367 return 0; 382 return 0; /* out of memory */
368 } 383 }
369 if (NULL == (buf = malloc (bufLen))) 384 if (Z_OK ==
370 { 385 (zret = uncompress ((Bytef *) buf,
371 /* printf("out of memory"); */ 386 &bufLen,
372 return 0; /* out of memory */ 387 (const Bytef *) &data[off],
373 } 388 length - off)))
374 if (Z_OK == 389 {
375 (zret = uncompress ((Bytef *) buf, 390 /* printf("zlib ok"); */
376 &bufLen, 391 break;
377 (const Bytef *) &data[off],
378 length - off)))
379 {
380 /* printf("zlib ok"); */
381 break;
382 }
383 free (buf);
384 if (Z_BUF_ERROR != zret)
385 return 0; /* unknown error, abort */
386 } 392 }
393 free (buf);
394 if (Z_BUF_ERROR != zret)
395 return 0; /* unknown error, abort */
396 }
387 keyword = EXTRACTOR_common_convert_to_utf8 (buf, 397 keyword = EXTRACTOR_common_convert_to_utf8 (buf,
388 bufLen, 398 bufLen,
389 "ISO-8859-1"); 399 "ISO-8859-1");
390 free (buf); 400 free (buf);
391 for (i = 0; NULL != tagmap[i].name; i++) 401 for (i = 0; NULL != tagmap[i].name; i++)
392 if (0 == strcmp (tagmap[i].name, (char*) data)) 402 if (0 == strcmp (tagmap[i].name, (char*) data))
393 { 403 {
394 ADDF (tagmap[i].type, keyword); 404 ADDF (tagmap[i].type, keyword);
395 return 0; 405 return 0;
396 } 406 }
397 ADDF (EXTRACTOR_METATYPE_COMMENT, keyword); 407 ADDF (EXTRACTOR_METATYPE_COMMENT, keyword);
398FINISH: 408FINISH:
399 return ret; 409 return ret;
@@ -437,9 +447,9 @@ processtIME (struct EXTRACTOR_ExtractContext *ec,
437 m = (unsigned char) data[9]; 447 m = (unsigned char) data[9];
438 s = (unsigned char) data[10]; 448 s = (unsigned char) data[10];
439 snprintf (val, 449 snprintf (val,
440 sizeof (val), 450 sizeof (val),
441 "%04u-%02u-%02u %02d:%02d:%02d", 451 "%04u-%02u-%02u %02d:%02d:%02d",
442 year, mo, day, h, m, s); 452 year, mo, day, h, m, s);
443 ADD (EXTRACTOR_METATYPE_MODIFICATION_DATE, val); 453 ADD (EXTRACTOR_METATYPE_MODIFICATION_DATE, val);
444FINISH: 454FINISH:
445 return ret; 455 return ret;
@@ -468,32 +478,33 @@ EXTRACTOR_png_extract_method (struct EXTRACTOR_ExtractContext *ec)
468 ADD (EXTRACTOR_METATYPE_MIMETYPE, "image/png"); 478 ADD (EXTRACTOR_METATYPE_MIMETYPE, "image/png");
469 ret = 0; 479 ret = 0;
470 while (0 == ret) 480 while (0 == ret)
471 { 481 {
472 if (sizeof (uint32_t) + 4 != ec->read (ec->cls, 482 if (sizeof (uint32_t) + 4 != ec->read (ec->cls,
473 &data, 483 &data,
474 sizeof (uint32_t) + 4)) 484 sizeof (uint32_t) + 4))
475 break; 485 break;
476 length = get_int_at (data); 486 length = get_int_at (data);
477 if (0 > (pos = ec->seek (ec->cls, 0, SEEK_CUR))) 487 if (0 > (pos = ec->seek (ec->cls, 0, SEEK_CUR)))
478 break; 488 break;
479 pos += length + 4; /* Chunk type, data, crc */ 489 pos += length + 4; /* Chunk type, data, crc */
480 if (0 == strncmp ((char*) data + sizeof (uint32_t), "IHDR", 4)) 490 if (0 == strncmp ((char*) data + sizeof (uint32_t), "IHDR", 4))
481 ret = processIHDR (ec, length); 491 ret = processIHDR (ec, length);
482 if (0 == strncmp ((char*) data + sizeof (uint32_t), "iTXt", 4)) 492 if (0 == strncmp ((char*) data + sizeof (uint32_t), "iTXt", 4))
483 ret = processiTXt (ec, length); 493 ret = processiTXt (ec, length);
484 if (0 == strncmp ((char*) data + sizeof (uint32_t), "tEXt", 4)) 494 if (0 == strncmp ((char*) data + sizeof (uint32_t), "tEXt", 4))
485 ret = processtEXt (ec, length); 495 ret = processtEXt (ec, length);
486 if (0 == strncmp ((char*) data + sizeof (uint32_t), "zTXt", 4)) 496 if (0 == strncmp ((char*) data + sizeof (uint32_t), "zTXt", 4))
487 ret = processzTXt (ec, length); 497 ret = processzTXt (ec, length);
488 if (0 == strncmp ((char*) data + sizeof (uint32_t), "tIME", 4)) 498 if (0 == strncmp ((char*) data + sizeof (uint32_t), "tIME", 4))
489 ret = processtIME (ec, length); 499 ret = processtIME (ec, length);
490 if (ret != 0) 500 if (ret != 0)
491 break; 501 break;
492 if (pos != ec->seek (ec->cls, pos, SEEK_SET)) 502 if (pos != ec->seek (ec->cls, pos, SEEK_SET))
493 break; 503 break;
494 } 504 }
495FINISH: 505FINISH:
496 return; 506 return;
497} 507}
498 508
509
499/* end of png_extractor.c */ 510/* end of png_extractor.c */
diff --git a/src/plugins/previewopus_extractor.c b/src/plugins/previewopus_extractor.c
index 4e137ec..0b9ab0b 100644
--- a/src/plugins/previewopus_extractor.c
+++ b/src/plugins/previewopus_extractor.c
@@ -65,15 +65,10 @@
65#include <ffmpeg/swscale.h> 65#include <ffmpeg/swscale.h>
66#endif 66#endif
67 67
68//TODO: Check for ffmpeg 68// TODO: Check for ffmpeg
69#include <libavresample/avresample.h> 69#include <libavresample/avresample.h>
70 70
71 71
72
73
74
75
76
77/** 72/**
78 * Set to 1 to enable debug output. 73 * Set to 1 to enable debug output.
79 */ 74 */
@@ -85,16 +80,15 @@
85#define OUTPUT_FILE 0 80#define OUTPUT_FILE 0
86 81
87 82
88
89/** 83/**
90 * Maximum size in bytes for the preview. 84 * Maximum size in bytes for the preview.
91 */ 85 */
92#define MAX_SIZE (28*1024) 86#define MAX_SIZE (28 * 1024)
93 87
94/** 88/**
95 * HardLimit for file 89 * HardLimit for file
96 */ 90 */
97#define HARD_LIMIT_SIZE (50*1024) 91#define HARD_LIMIT_SIZE (50 * 1024)
98 92
99 93
100/** The output bit rate in kbit/s */ 94/** The output bit rate in kbit/s */
@@ -116,11 +110,12 @@ static int totalSize;
116 * @param error Error code to be converted 110 * @param error Error code to be converted
117 * @return Corresponding error text (not thread-safe) 111 * @return Corresponding error text (not thread-safe)
118 */ 112 */
119static char *const get_error_text(const int error) 113static char *const
114get_error_text (const int error)
120{ 115{
121 static char error_buffer[255]; 116 static char error_buffer[255];
122 av_strerror(error, error_buffer, sizeof(error_buffer)); 117 av_strerror (error, error_buffer, sizeof(error_buffer));
123 return error_buffer; 118 return error_buffer;
124} 119}
125 120
126 121
@@ -134,8 +129,8 @@ static char *const get_error_text(const int error)
134 */ 129 */
135static int 130static int
136read_cb (void *opaque, 131read_cb (void *opaque,
137 uint8_t *buf, 132 uint8_t *buf,
138 int buf_size) 133 int buf_size)
139{ 134{
140 struct EXTRACTOR_ExtractContext *ec = opaque; 135 struct EXTRACTOR_ExtractContext *ec = opaque;
141 void *data; 136 void *data;
@@ -159,8 +154,8 @@ read_cb (void *opaque,
159 */ 154 */
160static int64_t 155static int64_t
161seek_cb (void *opaque, 156seek_cb (void *opaque,
162 int64_t offset, 157 int64_t offset,
163 int whence) 158 int whence)
164{ 159{
165 struct EXTRACTOR_ExtractContext *ec = opaque; 160 struct EXTRACTOR_ExtractContext *ec = opaque;
166 161
@@ -185,7 +180,7 @@ writePacket (void *opaque,
185{ 180{
186 int sizeToCopy = pBufferSize; 181 int sizeToCopy = pBufferSize;
187 182
188 if( (totalSize + pBufferSize) > HARD_LIMIT_SIZE) 183 if ( (totalSize + pBufferSize) > HARD_LIMIT_SIZE)
189 sizeToCopy = HARD_LIMIT_SIZE - totalSize; 184 sizeToCopy = HARD_LIMIT_SIZE - totalSize;
190 185
191 memcpy (buffer + totalSize, pBuffer, sizeToCopy); 186 memcpy (buffer + totalSize, pBuffer, sizeToCopy);
@@ -199,10 +194,11 @@ writePacket (void *opaque,
199 * Also set some basic encoder parameters. 194 * Also set some basic encoder parameters.
200 * Some of these parameters are based on the input file's parameters. 195 * Some of these parameters are based on the input file's parameters.
201 */ 196 */
202static int open_output_file( 197static int
203 AVCodecContext *input_codec_context, 198open_output_file (
204 AVFormatContext **output_format_context, 199 AVCodecContext *input_codec_context,
205 AVCodecContext **output_codec_context) 200 AVFormatContext **output_format_context,
201 AVCodecContext **output_codec_context)
206{ 202{
207 AVStream *stream = NULL; 203 AVStream *stream = NULL;
208 AVCodec *output_codec = NULL; 204 AVCodec *output_codec = NULL;
@@ -213,50 +209,50 @@ static int open_output_file(
213 if (NULL == (iob = av_malloc (16 * 1024))) 209 if (NULL == (iob = av_malloc (16 * 1024)))
214 return AVERROR_EXIT; 210 return AVERROR_EXIT;
215 if (NULL == (io_ctx = avio_alloc_context (iob, 16 * 1024, 211 if (NULL == (io_ctx = avio_alloc_context (iob, 16 * 1024,
216 AVIO_FLAG_WRITE, NULL, 212 AVIO_FLAG_WRITE, NULL,
217 NULL, 213 NULL,
218 &writePacket /* no writing */, 214 &writePacket /* no writing */,
219 NULL))) 215 NULL)))
220 { 216 {
221 av_free (iob); 217 av_free (iob);
222 return AVERROR_EXIT; 218 return AVERROR_EXIT;
223 } 219 }
224 if (NULL == ((*output_format_context) = avformat_alloc_context ())) 220 if (NULL == ((*output_format_context) = avformat_alloc_context ()))
225 { 221 {
226 av_free (io_ctx); 222 av_free (io_ctx);
227 return AVERROR_EXIT; 223 return AVERROR_EXIT;
228 } 224 }
229 (*output_format_context)->pb = io_ctx; 225 (*output_format_context)->pb = io_ctx;
230 226
231 /** Guess the desired container format based on the file extension. */ 227 /** Guess the desired container format based on the file extension. */
232 if (!((*output_format_context)->oformat = av_guess_format (NULL, 228 if (! ((*output_format_context)->oformat = av_guess_format (NULL,
233 "file.ogg", 229 "file.ogg",
234 NULL))) 230 NULL)))
235 { 231 {
236#if DEBUG 232#if DEBUG
237 fprintf(stderr, "Could not find output file format\n"); 233 fprintf (stderr, "Could not find output file format\n");
238#endif 234#endif
239 goto cleanup; 235 goto cleanup;
240 } 236 }
241 237
242 /** Find the encoder to be used by its name. */ 238 /** Find the encoder to be used by its name. */
243 if (!(output_codec = avcodec_find_encoder(AV_CODEC_ID_OPUS))) 239 if (! (output_codec = avcodec_find_encoder (AV_CODEC_ID_OPUS)))
244 { 240 {
245#if DEBUG 241#if DEBUG
246 fprintf(stderr, "Could not find an OPUS encoder.\n"); 242 fprintf (stderr, "Could not find an OPUS encoder.\n");
247#endif 243#endif
248 goto cleanup; 244 goto cleanup;
249 } 245 }
250 246
251 /** Create a new audio stream in the output file container. */ 247 /** Create a new audio stream in the output file container. */
252 if (!(stream = avformat_new_stream(*output_format_context, output_codec))) 248 if (! (stream = avformat_new_stream (*output_format_context, output_codec)))
253 { 249 {
254#if DEBUG 250#if DEBUG
255 fprintf(stderr, "Could not create new stream\n"); 251 fprintf (stderr, "Could not create new stream\n");
256#endif 252#endif
257 error = AVERROR(ENOMEM); 253 error = AVERROR (ENOMEM);
258 goto cleanup; 254 goto cleanup;
259 } 255 }
260 256
261 /** Save the encoder context for easiert access later. */ 257 /** Save the encoder context for easiert access later. */
262 *output_codec_context = stream->codec; 258 *output_codec_context = stream->codec;
@@ -266,20 +262,21 @@ static int open_output_file(
266 * The input file's sample rate is used to avoid a sample rate conversion. 262 * The input file's sample rate is used to avoid a sample rate conversion.
267 */ 263 */
268 (*output_codec_context)->channels = OUTPUT_CHANNELS; 264 (*output_codec_context)->channels = OUTPUT_CHANNELS;
269 (*output_codec_context)->channel_layout = av_get_default_channel_layout(OUTPUT_CHANNELS); 265 (*output_codec_context)->channel_layout = av_get_default_channel_layout (
270 (*output_codec_context)->sample_rate = 48000; //Opus need 48000 266 OUTPUT_CHANNELS);
267 (*output_codec_context)->sample_rate = 48000; // Opus need 48000
271 (*output_codec_context)->sample_fmt = AV_SAMPLE_FMT_S16; 268 (*output_codec_context)->sample_fmt = AV_SAMPLE_FMT_S16;
272 (*output_codec_context)->bit_rate = OUTPUT_BIT_RATE; 269 (*output_codec_context)->bit_rate = OUTPUT_BIT_RATE;
273 270
274 /** Open the encoder for the audio stream to use it later. */ 271 /** Open the encoder for the audio stream to use it later. */
275 if ((error = avcodec_open2(*output_codec_context, output_codec, NULL)) < 0) 272 if ((error = avcodec_open2 (*output_codec_context, output_codec, NULL)) < 0)
276 { 273 {
277#if DEBUG 274#if DEBUG
278 fprintf(stderr, "Could not open output codec (error '%s')\n", 275 fprintf (stderr, "Could not open output codec (error '%s')\n",
279 get_error_text(error)); 276 get_error_text (error));
280#endif 277#endif
281 goto cleanup; 278 goto cleanup;
282 } 279 }
283 return 0; 280 return 0;
284 281
285cleanup: 282cleanup:
@@ -290,9 +287,9 @@ cleanup:
290 287
291/** Initialize one data packet for reading or writing. */ 288/** Initialize one data packet for reading or writing. */
292static void 289static void
293init_packet(AVPacket *packet) 290init_packet (AVPacket *packet)
294{ 291{
295 av_init_packet(packet); 292 av_init_packet (packet);
296 /** Set the packet data and size so that it is recognized as being empty. */ 293 /** Set the packet data and size so that it is recognized as being empty. */
297 packet->data = NULL; 294 packet->data = NULL;
298 packet->size = 0; 295 packet->size = 0;
@@ -301,20 +298,20 @@ init_packet(AVPacket *packet)
301 298
302/** Initialize one audio frame for reading from the input file */ 299/** Initialize one audio frame for reading from the input file */
303static int 300static int
304init_input_frame(AVFrame **frame) 301init_input_frame (AVFrame **frame)
305{ 302{
306#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 303#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
307 *frame = av_frame_alloc (); 304 *frame = av_frame_alloc ();
308#else 305#else
309 *frame = avcodec_alloc_frame(); 306 *frame = avcodec_alloc_frame ();
310#endif 307#endif
311 if (NULL == *frame) 308 if (NULL == *frame)
312 { 309 {
313#if DEBUG 310#if DEBUG
314 fprintf(stderr, "Could not allocate input frame\n"); 311 fprintf (stderr, "Could not allocate input frame\n");
315#endif 312#endif
316 return AVERROR(ENOMEM); 313 return AVERROR (ENOMEM);
317 } 314 }
318 return 0; 315 return 0;
319} 316}
320 317
@@ -329,527 +326,591 @@ init_resampler (AVCodecContext *input_codec_context,
329 AVCodecContext *output_codec_context, 326 AVCodecContext *output_codec_context,
330 AVAudioResampleContext **resample_context) 327 AVAudioResampleContext **resample_context)
331{ 328{
332 /** 329 /**
333 * Only initialize the resampler if it is necessary, i.e., 330 * Only initialize the resampler if it is necessary, i.e.,
334 * if and only if the sample formats differ. 331 * if and only if the sample formats differ.
335 */ 332 */
336 if (input_codec_context->sample_fmt != output_codec_context->sample_fmt || 333 if ((input_codec_context->sample_fmt != output_codec_context->sample_fmt) ||
337 input_codec_context->channels != output_codec_context->channels) { 334 (input_codec_context->channels != output_codec_context->channels) )
338 int error; 335 {
336 int error;
339 337
340 /** Create a resampler context for the conversion. */ 338 /** Create a resampler context for the conversion. */
341 if (!(*resample_context = avresample_alloc_context())) { 339 if (! (*resample_context = avresample_alloc_context ()))
340 {
342#if DEBUG 341#if DEBUG
343 fprintf(stderr, "Could not allocate resample context\n"); 342 fprintf (stderr, "Could not allocate resample context\n");
344#endif 343#endif
345 return AVERROR(ENOMEM); 344 return AVERROR (ENOMEM);
346 } 345 }
347 346
348 347
349 /** 348 /**
350 * Set the conversion parameters. 349 * Set the conversion parameters.
351 * Default channel layouts based on the number of channels 350 * Default channel layouts based on the number of channels
352 * are assumed for simplicity (they are sometimes not detected 351 * are assumed for simplicity (they are sometimes not detected
353 * properly by the demuxer and/or decoder). 352 * properly by the demuxer and/or decoder).
354 */ 353 */av_opt_set_int (*resample_context, "in_channel_layout",
355 av_opt_set_int(*resample_context, "in_channel_layout", 354 av_get_default_channel_layout (
356 av_get_default_channel_layout(input_codec_context->channels), 0); 355 input_codec_context->channels), 0);
357 av_opt_set_int(*resample_context, "out_channel_layout", 356 av_opt_set_int (*resample_context, "out_channel_layout",
358 av_get_default_channel_layout(output_codec_context->channels), 0); 357 av_get_default_channel_layout (
359 av_opt_set_int(*resample_context, "in_sample_rate", 358 output_codec_context->channels), 0);
360 input_codec_context->sample_rate, 0); 359 av_opt_set_int (*resample_context, "in_sample_rate",
361 av_opt_set_int(*resample_context, "out_sample_rate", 360 input_codec_context->sample_rate, 0);
362 output_codec_context->sample_rate, 0); 361 av_opt_set_int (*resample_context, "out_sample_rate",
363 av_opt_set_int(*resample_context, "in_sample_fmt", 362 output_codec_context->sample_rate, 0);
364 input_codec_context->sample_fmt, 0); 363 av_opt_set_int (*resample_context, "in_sample_fmt",
365 av_opt_set_int(*resample_context, "out_sample_fmt", 364 input_codec_context->sample_fmt, 0);
366 output_codec_context->sample_fmt, 0); 365 av_opt_set_int (*resample_context, "out_sample_fmt",
367 366 output_codec_context->sample_fmt, 0);
368 /** Open the resampler with the specified parameters. */ 367
369 if ((error = avresample_open(*resample_context)) < 0) { 368 /** Open the resampler with the specified parameters. */
369 if ((error = avresample_open (*resample_context)) < 0)
370 {
370#if DEBUG 371#if DEBUG
371 fprintf(stderr, "Could not open resample context\n"); 372 fprintf (stderr, "Could not open resample context\n");
372#endif 373#endif
373 avresample_free(resample_context); 374 avresample_free (resample_context);
374 return error; 375 return error;
375 }
376 } 376 }
377 return 0; 377 }
378 return 0;
378} 379}
379 380
381
380/** Initialize a FIFO buffer for the audio samples to be encoded. */ 382/** Initialize a FIFO buffer for the audio samples to be encoded. */
381static int init_fifo(AVAudioFifo **fifo) 383static int
384init_fifo (AVAudioFifo **fifo)
382{ 385{
383 /** Create the FIFO buffer based on the specified output sample format. */ 386 /** Create the FIFO buffer based on the specified output sample format. */
384 if (!(*fifo = av_audio_fifo_alloc(OUTPUT_SAMPLE_FORMAT, OUTPUT_CHANNELS, 1))) { 387 if (! (*fifo = av_audio_fifo_alloc (OUTPUT_SAMPLE_FORMAT, OUTPUT_CHANNELS,
388 1)))
389 {
385#if DEBUG 390#if DEBUG
386 fprintf(stderr, "Could not allocate FIFO\n"); 391 fprintf (stderr, "Could not allocate FIFO\n");
387#endif 392#endif
388 return AVERROR(ENOMEM); 393 return AVERROR (ENOMEM);
389 } 394 }
390 return 0; 395 return 0;
391} 396}
392 397
398
393/** Write the header of the output file container. */ 399/** Write the header of the output file container. */
394static int write_output_file_header(AVFormatContext *output_format_context) 400static int
401write_output_file_header (AVFormatContext *output_format_context)
395{ 402{
396 int error; 403 int error;
397 if ((error = avformat_write_header(output_format_context, NULL)) < 0) { 404 if ((error = avformat_write_header (output_format_context, NULL)) < 0)
405 {
398#if DEBUG 406#if DEBUG
399 fprintf(stderr, "Could not write output file header (error '%s')\n", 407 fprintf (stderr, "Could not write output file header (error '%s')\n",
400 get_error_text(error)); 408 get_error_text (error));
401#endif 409#endif
402 return error; 410 return error;
403 } 411 }
404 return 0; 412 return 0;
405} 413}
406 414
415
407/** Decode one audio frame from the input file. */ 416/** Decode one audio frame from the input file. */
408static int decode_audio_frame(AVFrame *frame, 417static int
409 AVFormatContext *input_format_context, 418decode_audio_frame (AVFrame *frame,
410 AVCodecContext *input_codec_context, int audio_stream_index, 419 AVFormatContext *input_format_context,
411 int *data_present, int *finished) 420 AVCodecContext *input_codec_context, int audio_stream_index,
421 int *data_present, int *finished)
412{ 422{
413 /** Packet used for temporary storage. */ 423 /** Packet used for temporary storage. */
414 AVPacket input_packet; 424 AVPacket input_packet;
415 int error; 425 int error;
416 init_packet(&input_packet); 426 init_packet (&input_packet);
417 427
418 /** Read one audio frame from the input file into a temporary packet. */ 428 /** Read one audio frame from the input file into a temporary packet. */
419 while(1){ 429 while (1)
420 if ((error = av_read_frame(input_format_context, &input_packet)) < 0) { 430 {
421 /** If we are the the end of the file, flush the decoder below. */ 431 if ((error = av_read_frame (input_format_context, &input_packet)) < 0)
422 if (error == AVERROR_EOF){ 432 {
433 /** If we are the the end of the file, flush the decoder below. */
434 if (error == AVERROR_EOF)
435 {
423#if DEBUG 436#if DEBUG
424 fprintf(stderr, "EOF in decode_audio\n"); 437 fprintf (stderr, "EOF in decode_audio\n");
425#endif 438#endif
426 *finished = 1; 439 *finished = 1;
427 } 440 }
428 else { 441 else
442 {
429#if DEBUG 443#if DEBUG
430 fprintf(stderr, "Could not read frame (error '%s')\n", 444 fprintf (stderr, "Could not read frame (error '%s')\n",
431 get_error_text(error)); 445 get_error_text (error));
432#endif 446#endif
433 return error; 447 return error;
434 } 448 }
435 } 449 }
436 450
437 if(input_packet.stream_index == audio_stream_index) 451 if (input_packet.stream_index == audio_stream_index)
438 break; 452 break;
439 } 453 }
440 454
441 /** 455 /**
442 * Decode the audio frame stored in the temporary packet. 456 * Decode the audio frame stored in the temporary packet.
443 * The input audio stream decoder is used to do this. 457 * The input audio stream decoder is used to do this.
444 * If we are at the end of the file, pass an empty packet to the decoder 458 * If we are at the end of the file, pass an empty packet to the decoder
445 * to flush it. 459 * to flush it.
446 */ 460 */if ((error = avcodec_decode_audio4 (input_codec_context, frame,
447 if ((error = avcodec_decode_audio4(input_codec_context, frame, 461 data_present, &input_packet)) < 0)
448 data_present, &input_packet)) < 0) { 462 {
449#if DEBUG 463#if DEBUG
450 fprintf(stderr, "Could not decode frame (error '%s')\n", 464 fprintf (stderr, "Could not decode frame (error '%s')\n",
451 get_error_text(error)); 465 get_error_text (error));
452#endif 466#endif
453 av_free_packet(&input_packet); 467 av_free_packet (&input_packet);
454 return error; 468 return error;
455 } 469 }
456 470
457 /** 471 /**
458 * If the decoder has not been flushed completely, we are not finished, 472 * If the decoder has not been flushed completely, we are not finished,
459 * so that this function has to be called again. 473 * so that this function has to be called again.
460 */ 474 */
461 if (*finished && *data_present) 475 if (*finished && *data_present)
462 *finished = 0; 476 *finished = 0;
463 av_free_packet(&input_packet); 477 av_free_packet (&input_packet);
464 return 0; 478 return 0;
465} 479}
466 480
481
467/** 482/**
468 * Initialize a temporary storage for the specified number of audio samples. 483 * Initialize a temporary storage for the specified number of audio samples.
469 * The conversion requires temporary storage due to the different format. 484 * The conversion requires temporary storage due to the different format.
470 * The number of audio samples to be allocated is specified in frame_size. 485 * The number of audio samples to be allocated is specified in frame_size.
471 */ 486 */
472static int init_converted_samples(uint8_t ***converted_input_samples, int* out_linesize, 487static int
473 AVCodecContext *output_codec_context, 488init_converted_samples (uint8_t ***converted_input_samples, int*out_linesize,
474 int frame_size) 489 AVCodecContext *output_codec_context,
490 int frame_size)
475{ 491{
476 int error; 492 int error;
477 493
478 /** 494 /**
479 * Allocate as many pointers as there are audio channels. 495 * Allocate as many pointers as there are audio channels.
480 * Each pointer will later point to the audio samples of the corresponding 496 * Each pointer will later point to the audio samples of the corresponding
481 * channels (although it may be NULL for interleaved formats). 497 * channels (although it may be NULL for interleaved formats).
482 */ 498 */if (! (*converted_input_samples = calloc (output_codec_context->channels,
483 if (!(*converted_input_samples = calloc(output_codec_context->channels, 499 sizeof(**converted_input_samples))))
484 sizeof(**converted_input_samples)))) { 500 {
485#if DEBUG 501#if DEBUG
486 fprintf(stderr, "Could not allocate converted input sample pointers\n"); 502 fprintf (stderr, "Could not allocate converted input sample pointers\n");
487#endif 503#endif
488 return AVERROR(ENOMEM); 504 return AVERROR (ENOMEM);
489 } 505 }
490 506
491 /** 507 /**
492 * Allocate memory for the samples of all channels in one consecutive 508 * Allocate memory for the samples of all channels in one consecutive
493 * block for convenience. 509 * block for convenience.
494 */ 510 */
495 if ((error = av_samples_alloc(*converted_input_samples, out_linesize, 511 if ((error = av_samples_alloc (*converted_input_samples, out_linesize,
496 output_codec_context->channels, 512 output_codec_context->channels,
497 frame_size, 513 frame_size,
498 output_codec_context->sample_fmt, 0)) < 0) { 514 output_codec_context->sample_fmt, 0)) < 0)
515 {
499#if DEBUG 516#if DEBUG
500 fprintf(stderr, 517 fprintf (stderr,
501 "Could not allocate converted input samples (error '%s')\n", 518 "Could not allocate converted input samples (error '%s')\n",
502 get_error_text(error)); 519 get_error_text (error));
503#endif 520#endif
504 av_freep(&(*converted_input_samples)[0]); 521 av_freep (&(*converted_input_samples)[0]);
505 free(*converted_input_samples); 522 free (*converted_input_samples);
506 return error; 523 return error;
507 } 524 }
508 return 0; 525 return 0;
509} 526}
510 527
528
511/** 529/**
512 * Convert the input audio samples into the output sample format. 530 * Convert the input audio samples into the output sample format.
513 * The conversion happens on a per-frame basis, the size of which is specified 531 * The conversion happens on a per-frame basis, the size of which is specified
514 * by frame_size. 532 * by frame_size.
515 */ 533 */
516static int convert_samples(uint8_t **input_data, 534static int
517 uint8_t **converted_data, const int in_sample, const int out_sample, const int out_linesize, 535convert_samples (uint8_t **input_data,
518 AVAudioResampleContext *resample_context) 536 uint8_t **converted_data, const int in_sample, const int
537 out_sample, const int out_linesize,
538 AVAudioResampleContext *resample_context)
519{ 539{
520 int error; 540 int error;
521 541
522 /** Convert the samples using the resampler. */ 542 /** Convert the samples using the resampler. */
523 if ((error = avresample_convert(resample_context, converted_data, out_linesize, 543 if ((error = avresample_convert (resample_context, converted_data,
524 out_sample, input_data, 0, in_sample)) < 0) { 544 out_linesize,
545 out_sample, input_data, 0, in_sample)) < 0)
546 {
525#if DEBUG 547#if DEBUG
526 fprintf(stderr, "Could not convert input samples (error '%s')\n", 548 fprintf (stderr, "Could not convert input samples (error '%s')\n",
527 get_error_text(error)); 549 get_error_text (error));
528#endif 550#endif
529 return error; 551 return error;
530 } 552 }
531 553
532 554
533 /** 555 /**
534 * Perform a sanity check so that the number of converted samples is 556 * Perform a sanity check so that the number of converted samples is
535 * not greater than the number of samples to be converted. 557 * not greater than the number of samples to be converted.
536 * If the sample rates differ, this case has to be handled differently 558 * If the sample rates differ, this case has to be handled differently
537 */ 559 */if (avresample_available (resample_context))
538 if (avresample_available(resample_context)) { 560 {
539#if DEBUG 561#if DEBUG
540 fprintf(stderr, "%i Converted samples left over\n",avresample_available(resample_context)); 562 fprintf (stderr, "%i Converted samples left over\n",avresample_available (
563 resample_context));
541#endif 564#endif
542 } 565 }
543 566
544 567
545 return 0; 568 return 0;
546} 569}
547 570
571
548/** Add converted input audio samples to the FIFO buffer for later processing. */ 572/** Add converted input audio samples to the FIFO buffer for later processing. */
549static int add_samples_to_fifo(AVAudioFifo *fifo, 573static int
550 uint8_t **converted_input_samples, 574add_samples_to_fifo (AVAudioFifo *fifo,
551 const int frame_size) 575 uint8_t **converted_input_samples,
576 const int frame_size)
552{ 577{
553 int error; 578 int error;
554 579
555 /** 580 /**
556 * Make the FIFO as large as it needs to be to hold both, 581 * Make the FIFO as large as it needs to be to hold both,
557 * the old and the new samples. 582 * the old and the new samples.
558 */ 583 */
559 if ((error = av_audio_fifo_realloc(fifo, av_audio_fifo_size(fifo) + frame_size)) < 0) { 584 if ((error = av_audio_fifo_realloc (fifo, av_audio_fifo_size (fifo)
585 + frame_size)) < 0)
586 {
560#if DEBUG 587#if DEBUG
561 fprintf(stderr, "Could not reallocate FIFO\n"); 588 fprintf (stderr, "Could not reallocate FIFO\n");
562#endif 589#endif
563 return error; 590 return error;
564 } 591 }
565 592
566 /** Store the new samples in the FIFO buffer. */ 593 /** Store the new samples in the FIFO buffer. */
567 if (av_audio_fifo_write(fifo, (void **)converted_input_samples, 594 if (av_audio_fifo_write (fifo, (void **) converted_input_samples,
568 frame_size) < frame_size) { 595 frame_size) < frame_size)
596 {
569#if DEBUG 597#if DEBUG
570 fprintf(stderr, "Could not write data to FIFO\n"); 598 fprintf (stderr, "Could not write data to FIFO\n");
571#endif 599#endif
572 return AVERROR_EXIT; 600 return AVERROR_EXIT;
573 } 601 }
574 return 0; 602 return 0;
575} 603}
576 604
605
577/** 606/**
578 * Read one audio frame from the input file, decodes, converts and stores 607 * Read one audio frame from the input file, decodes, converts and stores
579 * it in the FIFO buffer. 608 * it in the FIFO buffer.
580 */ 609 */
581static int read_decode_convert_and_store(AVAudioFifo *fifo, 610static int
582 AVFormatContext *input_format_context, 611read_decode_convert_and_store (AVAudioFifo *fifo,
583 AVCodecContext *input_codec_context, 612 AVFormatContext *input_format_context,
584 AVCodecContext *output_codec_context, 613 AVCodecContext *input_codec_context,
585 AVAudioResampleContext *resampler_context, int audio_stream_index, 614 AVCodecContext *output_codec_context,
586 int *finished) 615 AVAudioResampleContext *resampler_context, int
616 audio_stream_index,
617 int *finished)
587{ 618{
588 /** Temporary storage of the input samples of the frame read from the file. */ 619 /** Temporary storage of the input samples of the frame read from the file. */
589 AVFrame *input_frame = NULL; 620 AVFrame *input_frame = NULL;
590 /** Temporary storage for the converted input samples. */ 621 /** Temporary storage for the converted input samples. */
591 uint8_t **converted_input_samples = NULL; 622 uint8_t **converted_input_samples = NULL;
592 int data_present; 623 int data_present;
593 int ret = AVERROR_EXIT; 624 int ret = AVERROR_EXIT;
594 625
595 /** Initialize temporary storage for one input frame. */ 626 /** Initialize temporary storage for one input frame. */
596 if (init_input_frame(&input_frame)){ 627 if (init_input_frame (&input_frame))
628 {
597#if DEBUG 629#if DEBUG
598 fprintf(stderr, "Failed at init frame\n"); 630 fprintf (stderr, "Failed at init frame\n");
599#endif 631#endif
600 goto cleanup; 632 goto cleanup;
601 633
602 } 634 }
603 /** Decode one frame worth of audio samples. */ 635 /** Decode one frame worth of audio samples. */
604 if (decode_audio_frame(input_frame, input_format_context, 636 if (decode_audio_frame (input_frame, input_format_context,
605 input_codec_context, audio_stream_index, &data_present, finished)){ 637 input_codec_context, audio_stream_index,
638 &data_present, finished))
639 {
606#if DEBUG 640#if DEBUG
607 fprintf(stderr, "Failed at decode audio\n"); 641 fprintf (stderr, "Failed at decode audio\n");
608#endif 642#endif
609 643
610 goto cleanup; 644 goto cleanup;
611 645
612 } 646 }
613 /** 647 /**
614 * If we are at the end of the file and there are no more samples 648 * If we are at the end of the file and there are no more samples
615 * in the decoder which are delayed, we are actually finished. 649 * in the decoder which are delayed, we are actually finished.
616 * This must not be treated as an error. 650 * This must not be treated as an error.
617 */ 651 */if (*finished && ! data_present)
618 if (*finished && !data_present) { 652 {
619 ret = 0; 653 ret = 0;
620#if DEBUG 654#if DEBUG
621 fprintf(stderr, "Failed at finished or no data\n"); 655 fprintf (stderr, "Failed at finished or no data\n");
622#endif 656#endif
623 goto cleanup; 657 goto cleanup;
624 } 658 }
625 /** If there is decoded data, convert and store it */ 659 /** If there is decoded data, convert and store it */
626 if (data_present) { 660 if (data_present)
627 int out_linesize; 661 {
628 //FIX ME: I'm losing samples, but can't get it to work. 662 int out_linesize;
629 int out_samples = avresample_available(resampler_context) + avresample_get_delay(resampler_context) + input_frame->nb_samples; 663 // FIX ME: I'm losing samples, but can't get it to work.
664 int out_samples = avresample_available (resampler_context)
665 + avresample_get_delay (resampler_context)
666 + input_frame->nb_samples;
630 667
631 668
632 //fprintf(stderr, "Input nbsamples %i out_samples: %i \n",input_frame->nb_samples,out_samples); 669 // fprintf(stderr, "Input nbsamples %i out_samples: %i \n",input_frame->nb_samples,out_samples);
633 670
634 /** Initialize the temporary storage for the converted input samples. */ 671 /** Initialize the temporary storage for the converted input samples. */
635 if (init_converted_samples(&converted_input_samples, &out_linesize, output_codec_context, 672 if (init_converted_samples (&converted_input_samples, &out_linesize,
636 out_samples)){ 673 output_codec_context,
674 out_samples))
675 {
637#if DEBUG 676#if DEBUG
638 fprintf(stderr, "Failed at init_converted_samples\n"); 677 fprintf (stderr, "Failed at init_converted_samples\n");
639#endif 678#endif
640 goto cleanup; 679 goto cleanup;
641 } 680 }
642 681
643 /** 682 /**
644 * Convert the input samples to the desired output sample format. 683 * Convert the input samples to the desired output sample format.
645 * This requires a temporary storage provided by converted_input_samples. 684 * This requires a temporary storage provided by converted_input_samples.
646 */ 685 */
647 if (convert_samples(input_frame->extended_data, converted_input_samples, 686 if (convert_samples (input_frame->extended_data, converted_input_samples,
648 input_frame->nb_samples, out_samples, out_linesize ,resampler_context)){ 687 input_frame->nb_samples, out_samples, out_linesize,
688 resampler_context))
689 {
649 690
650 691
651#if DEBUG 692#if DEBUG
652 fprintf(stderr, "Failed at convert_samples, input frame %i \n",input_frame->nb_samples); 693 fprintf (stderr, "Failed at convert_samples, input frame %i \n",
694 input_frame->nb_samples);
653#endif 695#endif
654 goto cleanup; 696 goto cleanup;
655 } 697 }
656 /** Add the converted input samples to the FIFO buffer for later processing. */ 698 /** Add the converted input samples to the FIFO buffer for later processing. */
657 if (add_samples_to_fifo(fifo, converted_input_samples, 699 if (add_samples_to_fifo (fifo, converted_input_samples,
658 out_samples)){ 700 out_samples))
701 {
659#if DEBUG 702#if DEBUG
660 fprintf(stderr, "Failed at add_samples_to_fifo\n"); 703 fprintf (stderr, "Failed at add_samples_to_fifo\n");
661#endif 704#endif
662 goto cleanup; 705 goto cleanup;
663 }
664 ret = 0;
665 } 706 }
666 ret = 0; 707 ret = 0;
708 }
709 ret = 0;
667 710
668cleanup: 711cleanup:
669 if (converted_input_samples) { 712 if (converted_input_samples)
670 av_freep(&converted_input_samples[0]); 713 {
671 free(converted_input_samples); 714 av_freep (&converted_input_samples[0]);
672 } 715 free (converted_input_samples);
673#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 716 }
674 av_frame_free (&input_frame); 717#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
718 av_frame_free (&input_frame);
675#else 719#else
676 avcodec_free_frame(&input_frame); 720 avcodec_free_frame (&input_frame);
677#endif 721#endif
678 722
679 return ret; 723 return ret;
680} 724}
681 725
726
682/** 727/**
683 * Initialize one input frame for writing to the output file. 728 * Initialize one input frame for writing to the output file.
684 * The frame will be exactly frame_size samples large. 729 * The frame will be exactly frame_size samples large.
685 */ 730 */
686static int init_output_frame(AVFrame **frame, 731static int
687 AVCodecContext *output_codec_context, 732init_output_frame (AVFrame **frame,
688 int frame_size) 733 AVCodecContext *output_codec_context,
734 int frame_size)
689{ 735{
690 int error; 736 int error;
691 737
692 /** Create a new frame to store the audio samples. */ 738 /** Create a new frame to store the audio samples. */
693#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 739#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
694 *frame = av_frame_alloc (); 740 *frame = av_frame_alloc ();
695#else 741#else
696 *frame = avcodec_alloc_frame(); 742 *frame = avcodec_alloc_frame ();
697#endif 743#endif
698 if (NULL == *frame) { 744 if (NULL == *frame)
745 {
699#if DEBUG 746#if DEBUG
700 fprintf(stderr, "Could not allocate output frame\n"); 747 fprintf (stderr, "Could not allocate output frame\n");
701#endif 748#endif
702 return AVERROR_EXIT; 749 return AVERROR_EXIT;
703 } 750 }
704
705 /**
706 * Set the frame's parameters, especially its size and format.
707 * av_frame_get_buffer needs this to allocate memory for the
708 * audio samples of the frame.
709 * Default channel layouts based on the number of channels
710 * are assumed for simplicity.
711 */
712 (*frame)->nb_samples = frame_size;
713 (*frame)->channel_layout = output_codec_context->channel_layout;
714 (*frame)->format = output_codec_context->sample_fmt;
715 (*frame)->sample_rate = output_codec_context->sample_rate;
716 751
752 /**
753 * Set the frame's parameters, especially its size and format.
754 * av_frame_get_buffer needs this to allocate memory for the
755 * audio samples of the frame.
756 * Default channel layouts based on the number of channels
757 * are assumed for simplicity.
758 */(*frame)->nb_samples = frame_size;
759 (*frame)->channel_layout = output_codec_context->channel_layout;
760 (*frame)->format = output_codec_context->sample_fmt;
761 (*frame)->sample_rate = output_codec_context->sample_rate;
717 762
718 763
719 //fprintf(stderr, "%i %i \n",frame_size , (*frame)->format,(*frame)->sample_rate); 764 // fprintf(stderr, "%i %i \n",frame_size , (*frame)->format,(*frame)->sample_rate);
720 765
721 /** 766 /**
722 * Allocate the samples of the created frame. This call will make 767 * Allocate the samples of the created frame. This call will make
723 * sure that the audio frame can hold as many samples as specified. 768 * sure that the audio frame can hold as many samples as specified.
724 */ 769 */
725 if ((error = av_frame_get_buffer(*frame, 0)) < 0) { 770 if ((error = av_frame_get_buffer (*frame, 0)) < 0)
771 {
726#if DEBUG 772#if DEBUG
727 fprintf(stderr, "Could allocate output frame samples (error '%s')\n", get_error_text(error)); 773 fprintf (stderr, "Could allocate output frame samples (error '%s')\n",
774 get_error_text (error));
728#endif 775#endif
729#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 776#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
730 av_frame_free (frame); 777 av_frame_free (frame);
731#else 778#else
732 avcodec_free_frame(frame); 779 avcodec_free_frame (frame);
733#endif 780#endif
734 return error; 781 return error;
735 } 782 }
736 783
737 return 0; 784 return 0;
738} 785}
739 786
787
740/** Encode one frame worth of audio to the output file. */ 788/** Encode one frame worth of audio to the output file. */
741static int encode_audio_frame(AVFrame *frame, 789static int
742 AVFormatContext *output_format_context, 790encode_audio_frame (AVFrame *frame,
743 AVCodecContext *output_codec_context, 791 AVFormatContext *output_format_context,
744 int *data_present) 792 AVCodecContext *output_codec_context,
793 int *data_present)
745{ 794{
746 /** Packet used for temporary storage. */ 795 /** Packet used for temporary storage. */
747 AVPacket output_packet; 796 AVPacket output_packet;
748 int error; 797 int error;
749 init_packet(&output_packet); 798 init_packet (&output_packet);
750 799
751 /** 800 /**
752 * Encode the audio frame and store it in the temporary packet. 801 * Encode the audio frame and store it in the temporary packet.
753 * The output audio stream encoder is used to do this. 802 * The output audio stream encoder is used to do this.
754 */ 803 */
755 if ((error = avcodec_encode_audio2(output_codec_context, &output_packet, 804 if ((error = avcodec_encode_audio2 (output_codec_context, &output_packet,
756 frame, data_present)) < 0) { 805 frame, data_present)) < 0)
806 {
757#if DEBUG 807#if DEBUG
758 fprintf(stderr, "Could not encode frame (error '%s')\n", 808 fprintf (stderr, "Could not encode frame (error '%s')\n",
759 get_error_text(error)); 809 get_error_text (error));
760#endif 810#endif
761 av_free_packet(&output_packet); 811 av_free_packet (&output_packet);
762 return error; 812 return error;
763 } 813 }
764 814
765 /** Write one audio frame from the temporary packet to the output file. */ 815 /** Write one audio frame from the temporary packet to the output file. */
766 if (*data_present) { 816 if (*data_present)
767 if ((error = av_write_frame(output_format_context, &output_packet)) < 0) { 817 {
818 if ((error = av_write_frame (output_format_context, &output_packet)) < 0)
819 {
768#if DEBUG 820#if DEBUG
769 fprintf(stderr, "Could not write frame (error '%s')\n", 821 fprintf (stderr, "Could not write frame (error '%s')\n",
770 get_error_text(error)); 822 get_error_text (error));
771#endif 823#endif
772 824
773 av_free_packet(&output_packet); 825 av_free_packet (&output_packet);
774 return error; 826 return error;
775 }
776
777 av_free_packet(&output_packet);
778 } 827 }
779 828
780 return 0; 829 av_free_packet (&output_packet);
830 }
831
832 return 0;
781} 833}
782 834
835
783/** 836/**
784 * Load one audio frame from the FIFO buffer, encode and write it to the 837 * Load one audio frame from the FIFO buffer, encode and write it to the
785 * output file. 838 * output file.
786 */ 839 */
787static int load_encode_and_write(AVAudioFifo *fifo, 840static int
788 AVFormatContext *output_format_context, 841load_encode_and_write (AVAudioFifo *fifo,
789 AVCodecContext *output_codec_context) 842 AVFormatContext *output_format_context,
843 AVCodecContext *output_codec_context)
790{ 844{
791 /** Temporary storage of the output samples of the frame written to the file. */ 845 /** Temporary storage of the output samples of the frame written to the file. */
792 AVFrame *output_frame; 846 AVFrame *output_frame;
793 /** 847 /**
794 * Use the maximum number of possible samples per frame. 848 * Use the maximum number of possible samples per frame.
795 * If there is less than the maximum possible frame size in the FIFO 849 * If there is less than the maximum possible frame size in the FIFO
796 * buffer use this number. Otherwise, use the maximum possible frame size 850 * buffer use this number. Otherwise, use the maximum possible frame size
797 */ 851 */const int frame_size = FFMIN (av_audio_fifo_size (fifo),
798 const int frame_size = FFMIN(av_audio_fifo_size(fifo), 852 output_codec_context->frame_size);
799 output_codec_context->frame_size); 853 int data_written;
800 int data_written; 854
801 855 /** Initialize temporary storage for one output frame. */
802 /** Initialize temporary storage for one output frame. */ 856 if (init_output_frame (&output_frame, output_codec_context, frame_size))
803 if (init_output_frame(&output_frame, output_codec_context, frame_size)) 857 return AVERROR_EXIT;
804 return AVERROR_EXIT;
805 858
806 /** 859 /**
807 * Read as many samples from the FIFO buffer as required to fill the frame. 860 * Read as many samples from the FIFO buffer as required to fill the frame.
808 * The samples are stored in the frame temporarily. 861 * The samples are stored in the frame temporarily.
809 */ 862 */
810 if (av_audio_fifo_read(fifo, (void **)output_frame->data, frame_size) < frame_size) { 863 if (av_audio_fifo_read (fifo, (void **) output_frame->data, frame_size) <
864 frame_size)
865 {
811#if DEBUG 866#if DEBUG
812 fprintf(stderr, "Could not read data from FIFO\n"); 867 fprintf (stderr, "Could not read data from FIFO\n");
813#endif 868#endif
814#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 869#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
815 av_frame_free (&output_frame); 870 av_frame_free (&output_frame);
816#else 871#else
817 avcodec_free_frame(&output_frame); 872 avcodec_free_frame (&output_frame);
818#endif 873#endif
819 return AVERROR_EXIT; 874 return AVERROR_EXIT;
820 } 875 }
821 876
822 /** Encode one frame worth of audio samples. */ 877 /** Encode one frame worth of audio samples. */
823 if (encode_audio_frame(output_frame, output_format_context, 878 if (encode_audio_frame (output_frame, output_format_context,
824 output_codec_context, &data_written)) { 879 output_codec_context, &data_written))
825#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 880 {
826 av_frame_free (&output_frame); 881#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
882 av_frame_free (&output_frame);
827#else 883#else
828 avcodec_free_frame(&output_frame); 884 avcodec_free_frame (&output_frame);
829#endif 885#endif
830 return AVERROR_EXIT; 886 return AVERROR_EXIT;
831 } 887 }
832#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 888#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
833 av_frame_free (&output_frame); 889 av_frame_free (&output_frame);
834#else 890#else
835 avcodec_free_frame(&output_frame); 891 avcodec_free_frame (&output_frame);
836#endif 892#endif
837 return 0; 893 return 0;
838} 894}
895
896
839/** Write the trailer of the output file container. */ 897/** Write the trailer of the output file container. */
840static int write_output_file_trailer(AVFormatContext *output_format_context) 898static int
899write_output_file_trailer (AVFormatContext *output_format_context)
841{ 900{
842 int error; 901 int error;
843 if ((error = av_write_trailer(output_format_context)) < 0) { 902 if ((error = av_write_trailer (output_format_context)) < 0)
903 {
844#if DEBUG 904#if DEBUG
845 fprintf(stderr, "Could not write output file trailer (error '%s')\n", 905 fprintf (stderr, "Could not write output file trailer (error '%s')\n",
846 get_error_text(error)); 906 get_error_text (error));
847#endif 907#endif
848 return error; 908 return error;
849 } 909 }
850 return 0; 910 return 0;
851} 911}
852 912
913
853#define ENUM_CODEC_ID enum AVCodecID 914#define ENUM_CODEC_ID enum AVCodecID
854 915
855 916
@@ -868,7 +929,7 @@ extract_audio (struct EXTRACTOR_ExtractContext *ec)
868 AVCodec *codec; 929 AVCodec *codec;
869 AVDictionary *options; 930 AVDictionary *options;
870 AVFrame *frame; 931 AVFrame *frame;
871 AVCodecContext* output_codec_context = NULL; 932 AVCodecContext*output_codec_context = NULL;
872 AVAudioResampleContext *resample_context = NULL; 933 AVAudioResampleContext *resample_context = NULL;
873 AVAudioFifo *fifo = NULL; 934 AVAudioFifo *fifo = NULL;
874 935
@@ -879,95 +940,95 @@ extract_audio (struct EXTRACTOR_ExtractContext *ec)
879 unsigned char *iob; 940 unsigned char *iob;
880 941
881 942
882 totalSize =0; 943 totalSize = 0;
883 if (NULL == (iob = av_malloc (16 * 1024))) 944 if (NULL == (iob = av_malloc (16 * 1024)))
884 return; 945 return;
885 if (NULL == (io_ctx = avio_alloc_context (iob, 946 if (NULL == (io_ctx = avio_alloc_context (iob,
886 16 * 1024, 947 16 * 1024,
887 0, ec, 948 0, ec,
888 &read_cb, 949 &read_cb,
889 NULL /* no writing */, 950 NULL /* no writing */,
890 &seek_cb))) 951 &seek_cb)))
891 { 952 {
892 av_free (iob); 953 av_free (iob);
893 return; 954 return;
894 } 955 }
895 if (NULL == (format_ctx = avformat_alloc_context ())) 956 if (NULL == (format_ctx = avformat_alloc_context ()))
896 { 957 {
897 av_free (io_ctx); 958 av_free (io_ctx);
898 return; 959 return;
899 } 960 }
900 format_ctx->pb = io_ctx; 961 format_ctx->pb = io_ctx;
901 options = NULL; 962 options = NULL;
902 if (0 != avformat_open_input (&format_ctx, "<no file>", NULL, &options)) 963 if (0 != avformat_open_input (&format_ctx, "<no file>", NULL, &options))
903 { 964 {
904 av_free (io_ctx); 965 av_free (io_ctx);
905 return; 966 return;
906 } 967 }
907 av_dict_free (&options); 968 av_dict_free (&options);
908 if (0 > avformat_find_stream_info (format_ctx, NULL)) 969 if (0 > avformat_find_stream_info (format_ctx, NULL))
909 { 970 {
910#if DEBUG 971#if DEBUG
911 fprintf (stderr, 972 fprintf (stderr,
912 "Failed to read stream info\n"); 973 "Failed to read stream info\n");
913#endif 974#endif
914 avformat_close_input (&format_ctx); 975 avformat_close_input (&format_ctx);
915 av_free (io_ctx); 976 av_free (io_ctx);
916 return; 977 return;
917 } 978 }
918 codec = NULL; 979 codec = NULL;
919 codec_ctx = NULL; 980 codec_ctx = NULL;
920 audio_stream_index = -1; 981 audio_stream_index = -1;
921 for (i=0; i<format_ctx->nb_streams; i++) 982 for (i = 0; i<format_ctx->nb_streams; i++)
983 {
984 codec_ctx = format_ctx->streams[i]->codec;
985 if (AVMEDIA_TYPE_AUDIO != codec_ctx->codec_type)
986 continue;
987 if (NULL == (codec = avcodec_find_decoder (codec_ctx->codec_id)))
988 continue;
989 options = NULL;
990 if (0 != (err = avcodec_open2 (codec_ctx, codec, &options)))
922 { 991 {
923 codec_ctx = format_ctx->streams[i]->codec; 992 codec = NULL;
924 if (AVMEDIA_TYPE_AUDIO != codec_ctx->codec_type) 993 continue;
925 continue;
926 if (NULL == (codec = avcodec_find_decoder (codec_ctx->codec_id)))
927 continue;
928 options = NULL;
929 if (0 != (err = avcodec_open2 (codec_ctx, codec, &options)))
930 {
931 codec = NULL;
932 continue;
933 }
934 av_dict_free (&options);
935 audio_stream_index = i;
936 break;
937 } 994 }
995 av_dict_free (&options);
996 audio_stream_index = i;
997 break;
998 }
938 if ( (-1 == audio_stream_index) || 999 if ( (-1 == audio_stream_index) ||
939 (0 == codec_ctx->channels) ) 1000 (0 == codec_ctx->channels) )
940 { 1001 {
941#if DEBUG 1002#if DEBUG
942 fprintf (stderr, 1003 fprintf (stderr,
943 "No audio streams or no suitable codec found\n"); 1004 "No audio streams or no suitable codec found\n");
944#endif 1005#endif
945 if (NULL != codec) 1006 if (NULL != codec)
946 avcodec_close (codec_ctx); 1007 avcodec_close (codec_ctx);
947 avformat_close_input (&format_ctx); 1008 avformat_close_input (&format_ctx);
948 av_free (io_ctx); 1009 av_free (io_ctx);
949 return; 1010 return;
950 } 1011 }
951 1012
952#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 1013#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
953 frame = av_frame_alloc (); 1014 frame = av_frame_alloc ();
954#else 1015#else
955 frame = avcodec_alloc_frame(); 1016 frame = avcodec_alloc_frame ();
956#endif 1017#endif
957 if (NULL == frame) 1018 if (NULL == frame)
958 { 1019 {
959#if DEBUG 1020#if DEBUG
960 fprintf (stderr, 1021 fprintf (stderr,
961 "Failed to allocate frame\n"); 1022 "Failed to allocate frame\n");
962#endif 1023#endif
963 avcodec_close (codec_ctx); 1024 avcodec_close (codec_ctx);
964 avformat_close_input (&format_ctx); 1025 avformat_close_input (&format_ctx);
965 av_free (io_ctx); 1026 av_free (io_ctx);
966 return; 1027 return;
967 } 1028 }
968 1029
969 1030
970 if (! (buffer = malloc(HARD_LIMIT_SIZE))) 1031 if (! (buffer = malloc (HARD_LIMIT_SIZE)))
971 goto cleanup; 1032 goto cleanup;
972 1033
973 1034
@@ -982,37 +1043,37 @@ extract_audio (struct EXTRACTOR_ExtractContext *ec)
982 &resample_context)) 1043 &resample_context))
983 goto cleanup; 1044 goto cleanup;
984 /** Initialize the FIFO buffer to store audio samples to be encoded. */ 1045 /** Initialize the FIFO buffer to store audio samples to be encoded. */
985 if (init_fifo(&fifo)) 1046 if (init_fifo (&fifo))
986 goto cleanup; 1047 goto cleanup;
987 1048
988 /** Write the header of the output file container. */ 1049 /** Write the header of the output file container. */
989 if (write_output_file_header(output_format_context)) 1050 if (write_output_file_header (output_format_context))
990 goto cleanup; 1051 goto cleanup;
991 1052
992 1053
993 if (format_ctx->duration == AV_NOPTS_VALUE) 1054 if (format_ctx->duration == AV_NOPTS_VALUE)
994 { 1055 {
995 duration = -1; 1056 duration = -1;
996#if DEBUG 1057#if DEBUG
997 fprintf (stderr, 1058 fprintf (stderr,
998 "Duration unknown\n"); 1059 "Duration unknown\n");
999#endif 1060#endif
1000 } 1061 }
1001 else 1062 else
1002 { 1063 {
1003#if DEBUG 1064#if DEBUG
1004 duration = format_ctx->duration; 1065 duration = format_ctx->duration;
1005 fprintf (stderr, 1066 fprintf (stderr,
1006 "Duration: %lld\n", 1067 "Duration: %lld\n",
1007 format_ctx->duration); 1068 format_ctx->duration);
1008#endif 1069#endif
1009 } 1070 }
1010 1071
1011 /* if duration is known, seek to first tried, 1072 /* if duration is known, seek to first tried,
1012 * else use 10 sec into stream */ 1073 * else use 10 sec into stream */
1013 1074
1014 if(-1 != duration) 1075 if (-1 != duration)
1015 err = av_seek_frame (format_ctx, -1, (duration/3), 0); 1076 err = av_seek_frame (format_ctx, -1, (duration / 3), 0);
1016 else 1077 else
1017 err = av_seek_frame (format_ctx, -1, 10 * AV_TIME_BASE, 0); 1078 err = av_seek_frame (format_ctx, -1, 10 * AV_TIME_BASE, 0);
1018 1079
@@ -1026,86 +1087,82 @@ extract_audio (struct EXTRACTOR_ExtractContext *ec)
1026 * to write; abort as soon as we have neither. 1087 * to write; abort as soon as we have neither.
1027 */ 1088 */
1028 while (1) 1089 while (1)
1029 { 1090 {
1030 /** Use the encoder's desired frame size for processing. */ 1091 /** Use the encoder's desired frame size for processing. */
1031 const int output_frame_size = output_codec_context->frame_size; 1092 const int output_frame_size = output_codec_context->frame_size;
1032 int finished = 0; 1093 int finished = 0;
1033 1094
1095 /**
1096 * Make sure that there is one frame worth of samples in the FIFO
1097 * buffer so that the encoder can do its work.
1098 * Since the decoder's and the encoder's frame size may differ, we
1099 * need to FIFO buffer to store as many frames worth of input samples
1100 * that they make up at least one frame worth of output samples.
1101 */while ((av_audio_fifo_size (fifo) < output_frame_size))
1102 {
1034 /** 1103 /**
1035 * Make sure that there is one frame worth of samples in the FIFO 1104 * Decode one frame worth of audio samples, convert it to the
1036 * buffer so that the encoder can do its work. 1105 * output sample format and put it into the FIFO buffer.
1037 * Since the decoder's and the encoder's frame size may differ, we
1038 * need to FIFO buffer to store as many frames worth of input samples
1039 * that they make up at least one frame worth of output samples.
1040 */ 1106 */
1041 1107 if (read_decode_convert_and_store (fifo,
1042 while ((av_audio_fifo_size(fifo) < output_frame_size)) 1108 format_ctx,
1043 { 1109 codec_ctx,
1044 /** 1110 output_codec_context,
1045 * Decode one frame worth of audio samples, convert it to the 1111 resample_context,
1046 * output sample format and put it into the FIFO buffer. 1112 audio_stream_index,
1047 */ 1113 &finished))
1048 if (read_decode_convert_and_store (fifo, 1114 {
1049 format_ctx, 1115 goto cleanup;
1050 codec_ctx, 1116 }
1051 output_codec_context,
1052 resample_context,
1053 audio_stream_index,
1054 &finished))
1055 {
1056 goto cleanup;
1057 }
1058
1059 /**
1060 * If we are at the end of the input file, we continue
1061 * encoding the remaining audio samples to the output file.
1062 */
1063 if (finished)
1064 break;
1065 }
1066
1067 /* Already over our limit*/
1068 if (totalSize >= MAX_SIZE)
1069 finished = 1;
1070 1117
1071 /** 1118 /**
1072 * If we have enough samples for the encoder, we encode them. 1119 * If we are at the end of the input file, we continue
1073 * At the end of the file, we pass the remaining samples to 1120 * encoding the remaining audio samples to the output file.
1074 * the encoder.
1075 */ 1121 */
1122 if (finished)
1123 break;
1124 }
1076 1125
1077 while (av_audio_fifo_size(fifo) >= output_frame_size || 1126 /* Already over our limit*/
1078 (finished && av_audio_fifo_size(fifo) > 0)) 1127 if (totalSize >= MAX_SIZE)
1079 { 1128 finished = 1;
1080 /** 1129
1081 * Take one frame worth of audio samples from the FIFO buffer, 1130 /**
1082 * encode it and write it to the output file. 1131 * If we have enough samples for the encoder, we encode them.
1083 */ 1132 * At the end of the file, we pass the remaining samples to
1084 if (load_encode_and_write (fifo, 1133 * the encoder.
1085 output_format_context, 1134 */while (av_audio_fifo_size (fifo) >= output_frame_size ||
1086 output_codec_context)) 1135 (finished && av_audio_fifo_size (fifo) > 0))
1087 goto cleanup; 1136 {
1088 }
1089 /** 1137 /**
1090 * If we are at the end of the input file and have encoded 1138 * Take one frame worth of audio samples from the FIFO buffer,
1091 * all remaining samples, we can exit this loop and finish. 1139 * encode it and write it to the output file.
1092 */ 1140 */
1093 if (finished) 1141 if (load_encode_and_write (fifo,
1094 { 1142 output_format_context,
1095 int data_written; 1143 output_codec_context))
1096 /** Flush the encoder as it may have delayed frames. */ 1144 goto cleanup;
1097 do { 1145 }
1098 encode_audio_frame (NULL, 1146 /**
1099 output_format_context, 1147 * If we are at the end of the input file and have encoded
1100 output_codec_context, 1148 * all remaining samples, we can exit this loop and finish.
1101 &data_written); 1149 */
1102 } while (data_written); 1150 if (finished)
1103 break; 1151 {
1104 } 1152 int data_written;
1153 /** Flush the encoder as it may have delayed frames. */
1154 do {
1155 encode_audio_frame (NULL,
1156 output_format_context,
1157 output_codec_context,
1158 &data_written);
1159 } while (data_written);
1160 break;
1105 } 1161 }
1162 }
1106 1163
1107 /** Write the trailer of the output file container. */ 1164 /** Write the trailer of the output file container. */
1108 if (write_output_file_trailer(output_format_context)) 1165 if (write_output_file_trailer (output_format_context))
1109 goto cleanup; 1166 goto cleanup;
1110 ec->proc (ec->cls, 1167 ec->proc (ec->cls,
1111 "previewopus", 1168 "previewopus",
@@ -1120,34 +1177,34 @@ extract_audio (struct EXTRACTOR_ExtractContext *ec)
1120 FILE *f; 1177 FILE *f;
1121 1178
1122 f = fopen ("example.opus", "wb"); 1179 f = fopen ("example.opus", "wb");
1123 if (!f) 1180 if (! f)
1124 { 1181 {
1125 fprintf (stderr, "Could not open %s\n", "file"); 1182 fprintf (stderr, "Could not open %s\n", "file");
1126 exit(1); 1183 exit (1);
1127 } 1184 }
1128 fwrite (buffer, 1, totalSize, f); 1185 fwrite (buffer, 1, totalSize, f);
1129 fclose(f); 1186 fclose (f);
1130 } 1187 }
1131#endif 1188#endif
1132 1189
1133 cleanup: 1190cleanup:
1134 av_free (frame); 1191 av_free (frame);
1135 free (buffer); 1192 free (buffer);
1136 1193
1137 if (fifo) 1194 if (fifo)
1138 av_audio_fifo_free(fifo); 1195 av_audio_fifo_free (fifo);
1139 if (resample_context) 1196 if (resample_context)
1140 { 1197 {
1141 avresample_close(resample_context); 1198 avresample_close (resample_context);
1142 avresample_free(&resample_context); 1199 avresample_free (&resample_context);
1143 } 1200 }
1144 if (output_codec_context) 1201 if (output_codec_context)
1145 avcodec_close(output_codec_context); 1202 avcodec_close (output_codec_context);
1146 1203
1147 if (codec_ctx) 1204 if (codec_ctx)
1148 avcodec_close(codec_ctx); 1205 avcodec_close (codec_ctx);
1149 if (format_ctx) 1206 if (format_ctx)
1150 avformat_close_input(&format_ctx); 1207 avformat_close_input (&format_ctx);
1151 av_free (io_ctx); 1208 av_free (io_ctx);
1152} 1209}
1153 1210
@@ -1165,8 +1222,8 @@ EXTRACTOR_previewopus_extract_method (struct EXTRACTOR_ExtractContext *ec)
1165 1222
1166 1223
1167 if (-1 == (iret = ec->read (ec->cls, 1224 if (-1 == (iret = ec->read (ec->cls,
1168 &data, 1225 &data,
1169 16 * 1024))) 1226 16 * 1024)))
1170 return; 1227 return;
1171 1228
1172 if (0 != ec->seek (ec->cls, 0, SEEK_SET)) 1229 if (0 != ec->seek (ec->cls, 0, SEEK_SET))
@@ -1185,13 +1242,13 @@ EXTRACTOR_previewopus_extract_method (struct EXTRACTOR_ExtractContext *ec)
1185 * @param ap arguments for format 1242 * @param ap arguments for format
1186 */ 1243 */
1187static void 1244static void
1188previewopus_av_log_callback (void* ptr, 1245previewopus_av_log_callback (void*ptr,
1189 int level, 1246 int level,
1190 const char *format, 1247 const char *format,
1191 va_list ap) 1248 va_list ap)
1192{ 1249{
1193#if DEBUG 1250#if DEBUG
1194 vfprintf(stderr, format, ap); 1251 vfprintf (stderr, format, ap);
1195#endif 1252#endif
1196} 1253}
1197 1254
diff --git a/src/plugins/ps_extractor.c b/src/plugins/ps_extractor.c
index 3a7f26d..7b61410 100644
--- a/src/plugins/ps_extractor.c
+++ b/src/plugins/ps_extractor.c
@@ -137,81 +137,82 @@ EXTRACTOR_ps_extract_method (struct EXTRACTOR_ExtractContext *ec)
137 return; 137 return;
138 if ( (strlen (line) < strlen (PS_HEADER)) || 138 if ( (strlen (line) < strlen (PS_HEADER)) ||
139 (0 != memcmp (PS_HEADER, 139 (0 != memcmp (PS_HEADER,
140 line, 140 line,
141 strlen (PS_HEADER))) ) 141 strlen (PS_HEADER))) )
142 { 142 {
143 free (line); 143 free (line);
144 return; 144 return;
145 } 145 }
146 free (line); 146 free (line);
147 if (0 != ec->proc (ec->cls, 147 if (0 != ec->proc (ec->cls,
148 "ps", 148 "ps",
149 EXTRACTOR_METATYPE_MIMETYPE, 149 EXTRACTOR_METATYPE_MIMETYPE,
150 EXTRACTOR_METAFORMAT_UTF8, 150 EXTRACTOR_METAFORMAT_UTF8,
151 "text/plain", 151 "text/plain",
152 "application/postscript", 152 "application/postscript",
153 strlen ("application/postscript") + 1)) 153 strlen ("application/postscript") + 1))
154 return; 154 return;
155 155
156 line = NULL; 156 line = NULL;
157 next = readline (ec); 157 next = readline (ec);
158 while ( (NULL != next) && 158 while ( (NULL != next) &&
159 ('%' == next[0]) ) 159 ('%' == next[0]) )
160 {
161 line = next;
162 next = readline (ec);
163 for (i = 0; NULL != tests[i].prefix; i++)
160 { 164 {
161 line = next; 165 match = tests[i].prefix;
162 next = readline (ec); 166 if ( (strlen (line) < strlen (match)) ||
163 for (i = 0; NULL != tests[i].prefix; i++) 167 (0 != strncmp (line, match, strlen (match))) )
164 { 168 continue;
165 match = tests[i].prefix; 169 /* %%+ continues previous meta-data type... */
166 if ( (strlen (line) < strlen (match)) || 170 while ( (NULL != next) &&
167 (0 != strncmp (line, match, strlen (match))) ) 171 (0 == strncmp (next, "%%+", strlen ("%%+"))) )
168 continue; 172 {
169 /* %%+ continues previous meta-data type... */ 173 if (NULL == (acc = malloc (strlen (line) + strlen (next) - 1)))
170 while ( (NULL != next) && 174 break;
171 (0 == strncmp (next, "%%+", strlen ("%%+"))) ) 175 strcpy (acc, line);
172 { 176 strcat (acc, " ");
173 if (NULL == (acc = malloc (strlen (line) + strlen (next) - 1))) 177 strcat (acc, next + 3);
174 break; 178 free (line);
175 strcpy (acc, line); 179 line = acc;
176 strcat (acc, " "); 180 free (next);
177 strcat (acc, next + 3); 181 next = readline (ec);
178 free (line); 182 }
179 line = acc; 183 if ( (line[strlen (line) - 1] == ')') &&
180 free (next); 184 (line[strlen (match)] == '(') )
181 next = readline (ec); 185 {
182 } 186 acc = &line[strlen (match) + 1];
183 if ( (line[strlen (line) - 1] == ')') && 187 acc[strlen (acc) - 1] = '\0'; /* remove ")" */
184 (line[strlen (match)] == '(') ) 188 }
185 { 189 else
186 acc = &line[strlen (match) + 1]; 190 {
187 acc[strlen (acc) - 1] = '\0'; /* remove ")" */ 191 acc = &line[strlen (match)];
188 } 192 }
189 else 193 while (isspace ((unsigned char) acc[0]))
190 { 194 acc++;
191 acc = &line[strlen (match)]; 195 if ( (strlen (acc) > 0) &&
192 } 196 (0 != ec->proc (ec->cls,
193 while (isspace ((unsigned char) acc[0])) 197 "ps",
194 acc++; 198 tests[i].type,
195 if ( (strlen (acc) > 0) && 199 EXTRACTOR_METAFORMAT_UTF8,
196 (0 != ec->proc (ec->cls, 200 "text/plain",
197 "ps", 201 acc,
198 tests[i].type, 202 strlen (acc) + 1)) )
199 EXTRACTOR_METAFORMAT_UTF8, 203 {
200 "text/plain", 204 free (line);
201 acc, 205 if (NULL != next)
202 strlen (acc) + 1)) ) 206 free (next);
203 { 207 return;
204 free (line); 208 }
205 if (NULL != next) 209 break;
206 free (next);
207 return;
208 }
209 break;
210 }
211 free (line);
212 } 210 }
211 free (line);
212 }
213 if (NULL != next) 213 if (NULL != next)
214 free (next); 214 free (next);
215} 215}
216 216
217
217/* end of ps_extractor.c */ 218/* end of ps_extractor.c */
diff --git a/src/plugins/riff_extractor.c b/src/plugins/riff_extractor.c
index 9ff700a..c030617 100644
--- a/src/plugins/riff_extractor.c
+++ b/src/plugins/riff_extractor.c
@@ -76,15 +76,19 @@ round_double (double num)
76 * @param s 0-terminated UTF8 string value with the meta data 76 * @param s 0-terminated UTF8 string value with the meta data
77 * @param t libextractor type for the meta data 77 * @param t libextractor type for the meta data
78 */ 78 */
79#define ADD(s,t) do { if (0 != ec->proc (ec->cls, "riff", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen (s) + 1)) return; } while (0) 79#define ADD(s,t) do { if (0 != ec->proc (ec->cls, "riff", t, \
80 EXTRACTOR_METAFORMAT_UTF8, \
81 "text/plain", s, strlen (s) \
82 + 1)) return; \
83} while (0)
80 84
81 85
82/** 86/**
83 * Main entry method for the 'video/x-msvideo' extraction plugin. 87 * Main entry method for the 'video/x-msvideo' extraction plugin.
84 * 88 *
85 * @param ec extraction context provided to the plugin 89 * @param ec extraction context provided to the plugin
86 */ 90 */
87void 91void
88EXTRACTOR_riff_extract_method (struct EXTRACTOR_ExtractContext *ec) 92EXTRACTOR_riff_extract_method (struct EXTRACTOR_ExtractContext *ec)
89{ 93{
90 ssize_t xsize; 94 ssize_t xsize;
@@ -98,22 +102,22 @@ EXTRACTOR_riff_extract_method (struct EXTRACTOR_ExtractContext *ec)
98 uint32_t height; 102 uint32_t height;
99 char codec[5]; 103 char codec[5];
100 char format[256]; 104 char format[256];
101 105
102 /* read header */ 106 /* read header */
103 if (72 > (xsize = ec->read (ec->cls, &data, 72))) 107 if (72 > (xsize = ec->read (ec->cls, &data, 72)))
104 return; 108 return;
105 xdata = data; 109 xdata = data;
106 110
107 /* check magic values */ 111 /* check magic values */
108 if ( (0 != memcmp (&xdata[0], 112 if ( (0 != memcmp (&xdata[0],
109 "RIFF", 4)) || 113 "RIFF", 4)) ||
110 (0 != memcmp (&xdata[8], "AVI ", 4)) || 114 (0 != memcmp (&xdata[8], "AVI ", 4)) ||
111 (0 != memcmp (&xdata[12], "LIST", 4)) || 115 (0 != memcmp (&xdata[12], "LIST", 4)) ||
112 (0 != memcmp (&xdata[20], "hdrlavih", 8)) ) 116 (0 != memcmp (&xdata[20], "hdrlavih", 8)) )
113 return; 117 return;
114 118
115 blockLen = fread_le (&xdata[28]); 119 blockLen = fread_le (&xdata[28]);
116 120
117 /* begin of AVI header at 32 */ 121 /* begin of AVI header at 32 */
118 fps = (unsigned int) round_double ((double) 1.0e6 / fread_le (&xdata[32])); 122 fps = (unsigned int) round_double ((double) 1.0e6 / fread_le (&xdata[32]));
119 duration = (unsigned int) round_double ((double) fread_le (&xdata[48]) 123 duration = (unsigned int) round_double ((double) fread_le (&xdata[48])
@@ -126,7 +130,7 @@ EXTRACTOR_riff_extract_method (struct EXTRACTOR_ExtractContext *ec)
126 130
127 if (pos != 131 if (pos !=
128 ec->seek (ec->cls, pos, SEEK_SET)) 132 ec->seek (ec->cls, pos, SEEK_SET))
129 return; 133 return;
130 if (32 > ec->read (ec->cls, &data, 32)) 134 if (32 > ec->read (ec->cls, &data, 32))
131 return; 135 return;
132 xdata = data; 136 xdata = data;
@@ -141,17 +145,18 @@ EXTRACTOR_riff_extract_method (struct EXTRACTOR_ExtractContext *ec)
141 memcpy (codec, &xdata[24], 4); 145 memcpy (codec, &xdata[24], 4);
142 codec[4] = '\0'; 146 codec[4] = '\0';
143 snprintf (format, 147 snprintf (format,
144 sizeof (format), 148 sizeof (format),
145 _("codec: %s, %u fps, %u ms"), 149 _ ("codec: %s, %u fps, %u ms"),
146 codec, fps, duration); 150 codec, fps, duration);
147 ADD (format, EXTRACTOR_METATYPE_FORMAT); 151 ADD (format, EXTRACTOR_METATYPE_FORMAT);
148 snprintf (format, 152 snprintf (format,
149 sizeof (format), 153 sizeof (format),
150 "%ux%u", 154 "%ux%u",
151 (unsigned int) width, 155 (unsigned int) width,
152 (unsigned int) height); 156 (unsigned int) height);
153 ADD (format, EXTRACTOR_METATYPE_IMAGE_DIMENSIONS); 157 ADD (format, EXTRACTOR_METATYPE_IMAGE_DIMENSIONS);
154 ADD ("video/x-msvideo", EXTRACTOR_METATYPE_MIMETYPE); 158 ADD ("video/x-msvideo", EXTRACTOR_METATYPE_MIMETYPE);
155} 159}
156 160
161
157/* end of riff_extractor.c */ 162/* end of riff_extractor.c */
diff --git a/src/plugins/rpm_extractor.c b/src/plugins/rpm_extractor.c
index 21596d2..90c5892 100644
--- a/src/plugins/rpm_extractor.c
+++ b/src/plugins/rpm_extractor.c
@@ -79,7 +79,7 @@ struct PipeArgs
79 * @return NULL 79 * @return NULL
80 */ 80 */
81static void * 81static void *
82pipe_feeder (void * args) 82pipe_feeder (void *args)
83{ 83{
84 struct PipeArgs *p = args; 84 struct PipeArgs *p = args;
85 ssize_t rret; 85 ssize_t rret;
@@ -91,34 +91,34 @@ pipe_feeder (void * args)
91 /* buffer is heap-allocated as this is a thread and 91 /* buffer is heap-allocated as this is a thread and
92 large stack allocations might not be the best idea */ 92 large stack allocations might not be the best idea */
93 while (0 == p->shutdown) 93 while (0 == p->shutdown)
94 {
95 pthread_mutex_lock (&p->lock);
96 if (-1 == (rret = p->ec->read (p->ec->cls, &ptr, BUF_SIZE)))
94 { 97 {
95 pthread_mutex_lock (&p->lock);
96 if (-1 == (rret = p->ec->read (p->ec->cls, &ptr, BUF_SIZE)))
97 {
98 pthread_mutex_unlock (&p->lock);
99 break;
100 }
101 pthread_mutex_unlock (&p->lock); 98 pthread_mutex_unlock (&p->lock);
102 if (0 == rret) 99 break;
103 break; 100 }
104 buf = ptr; 101 pthread_mutex_unlock (&p->lock);
105 done = 0; 102 if (0 == rret)
106 while ( (0 == p->shutdown) && 103 break;
107 (done < rret) ) 104 buf = ptr;
108 { 105 done = 0;
109 if (-1 == (wret = WRITE (p->pi[1], 106 while ( (0 == p->shutdown) &&
110 &buf[done], 107 (done < rret) )
111 rret - done))) 108 {
112 { 109 if (-1 == (wret = WRITE (p->pi[1],
113 break; 110 &buf[done],
114 } 111 rret - done)))
115 if (0 == wret) 112 {
116 break; 113 break;
117 done += wret; 114 }
118 } 115 if (0 == wret)
119 if (done != rret) 116 break;
120 break; 117 done += wret;
121 } 118 }
119 if (done != rret)
120 break;
121 }
122 CLOSE (p->pi[1]); 122 CLOSE (p->pi[1]);
123 return NULL; 123 return NULL;
124} 124}
@@ -130,7 +130,7 @@ pipe_feeder (void * args)
130 */ 130 */
131static int 131static int
132discard_log_callback (rpmlogRec rec, 132discard_log_callback (rpmlogRec rec,
133 void *ctx) 133 void *ctx)
134{ 134{
135 /* do nothing! */ 135 /* do nothing! */
136 return 0; 136 return 0;
@@ -190,52 +190,52 @@ static struct Matches tests[] = {
190 190
191#if 0 191#if 0
192 /* FIXME: add support for some of these */ 192 /* FIXME: add support for some of these */
193 RPMTAG_GIF = 1012, /* x */ 193 RPMTAG_GIF = 1012, /* x */
194 RPMTAG_XPM = 1013, /* x */ 194 RPMTAG_XPM = 1013, /* x */
195 RPMTAG_SOURCE = 1018, /* s[] */ 195 RPMTAG_SOURCE = 1018, /* s[] */
196 RPMTAG_PATCH = 1019, /* s[] */ 196 RPMTAG_PATCH = 1019, /* s[] */
197 RPMTAG_PREIN = 1023, /* s */ 197 RPMTAG_PREIN = 1023, /* s */
198 RPMTAG_POSTIN = 1024, /* s */ 198 RPMTAG_POSTIN = 1024, /* s */
199 RPMTAG_PREUN = 1025, /* s */ 199 RPMTAG_PREUN = 1025, /* s */
200 RPMTAG_POSTUN = 1026, /* s */ 200 RPMTAG_POSTUN = 1026, /* s */
201 RPMTAG_ICON = 1043, /* x */ 201 RPMTAG_ICON = 1043, /* x */
202 RPMTAG_SOURCERPM = 1044, /* s */ 202 RPMTAG_SOURCERPM = 1044, /* s */
203 RPMTAG_PROVIDENAME = 1047, /* s[] */ 203 RPMTAG_PROVIDENAME = 1047, /* s[] */
204 RPMTAG_EXCLUDEARCH = 1059, /* s[] */ 204 RPMTAG_EXCLUDEARCH = 1059, /* s[] */
205 RPMTAG_EXCLUDEOS = 1060, /* s[] */ 205 RPMTAG_EXCLUDEOS = 1060, /* s[] */
206 RPMTAG_EXCLUSIVEARCH = 1061, /* s[] */ 206 RPMTAG_EXCLUSIVEARCH = 1061, /* s[] */
207 RPMTAG_EXCLUSIVEOS = 1062, /* s[] */ 207 RPMTAG_EXCLUSIVEOS = 1062, /* s[] */
208 RPMTAG_TRIGGERSCRIPTS = 1065, /* s[] */ 208 RPMTAG_TRIGGERSCRIPTS = 1065, /* s[] */
209 RPMTAG_TRIGGERNAME = 1066, /* s[] */ 209 RPMTAG_TRIGGERNAME = 1066, /* s[] */
210 RPMTAG_TRIGGERVERSION = 1067, /* s[] */ 210 RPMTAG_TRIGGERVERSION = 1067, /* s[] */
211 RPMTAG_VERIFYSCRIPT = 1079, /* s */ 211 RPMTAG_VERIFYSCRIPT = 1079, /* s */
212 RPMTAG_PREINPROG = 1085, /* s */ 212 RPMTAG_PREINPROG = 1085, /* s */
213 RPMTAG_POSTINPROG = 1086, /* s */ 213 RPMTAG_POSTINPROG = 1086, /* s */
214 RPMTAG_PREUNPROG = 1087, /* s */ 214 RPMTAG_PREUNPROG = 1087, /* s */
215 RPMTAG_POSTUNPROG = 1088, /* s */ 215 RPMTAG_POSTUNPROG = 1088, /* s */
216 RPMTAG_BUILDARCHS = 1089, /* s[] */ 216 RPMTAG_BUILDARCHS = 1089, /* s[] */
217 RPMTAG_OBSOLETENAME = 1090, /* s[] */ 217 RPMTAG_OBSOLETENAME = 1090, /* s[] */
218 RPMTAG_VERIFYSCRIPTPROG = 1091, /* s */ 218 RPMTAG_VERIFYSCRIPTPROG = 1091, /* s */
219 RPMTAG_TRIGGERSCRIPTPROG = 1092, /* s[] */ 219 RPMTAG_TRIGGERSCRIPTPROG = 1092, /* s[] */
220 RPMTAG_COOKIE = 1094, /* s */ 220 RPMTAG_COOKIE = 1094, /* s */
221 RPMTAG_FILELANGS = 1097, /* s[] */ 221 RPMTAG_FILELANGS = 1097, /* s[] */
222 RPMTAG_PREFIXES = 1098, /* s[] */ 222 RPMTAG_PREFIXES = 1098, /* s[] */
223 RPMTAG_INSTPREFIXES = 1099, /* s[] */ 223 RPMTAG_INSTPREFIXES = 1099, /* s[] */
224 RPMTAG_PROVIDEVERSION = 1113, /* s[] */ 224 RPMTAG_PROVIDEVERSION = 1113, /* s[] */
225 RPMTAG_OBSOLETEVERSION = 1115, /* s[] */ 225 RPMTAG_OBSOLETEVERSION = 1115, /* s[] */
226 RPMTAG_BASENAMES = 1117, /* s[] */ 226 RPMTAG_BASENAMES = 1117, /* s[] */
227 RPMTAG_DIRNAMES = 1118, /* s[] */ 227 RPMTAG_DIRNAMES = 1118, /* s[] */
228 RPMTAG_OPTFLAGS = 1122, /* s */ 228 RPMTAG_OPTFLAGS = 1122, /* s */
229 RPMTAG_PAYLOADFORMAT = 1124, /* s */ 229 RPMTAG_PAYLOADFORMAT = 1124, /* s */
230 RPMTAG_PAYLOADCOMPRESSOR = 1125, /* s */ 230 RPMTAG_PAYLOADCOMPRESSOR = 1125, /* s */
231 RPMTAG_PAYLOADFLAGS = 1126, /* s */ 231 RPMTAG_PAYLOADFLAGS = 1126, /* s */
232 RPMTAG_CLASSDICT = 1142, /* s[] */ 232 RPMTAG_CLASSDICT = 1142, /* s[] */
233 RPMTAG_SOURCEPKGID = 1146, /* x */ 233 RPMTAG_SOURCEPKGID = 1146, /* x */
234 RPMTAG_PRETRANS = 1151, /* s */ 234 RPMTAG_PRETRANS = 1151, /* s */
235 RPMTAG_POSTTRANS = 1152, /* s */ 235 RPMTAG_POSTTRANS = 1152, /* s */
236 RPMTAG_PRETRANSPROG = 1153, /* s */ 236 RPMTAG_PRETRANSPROG = 1153, /* s */
237 RPMTAG_POSTTRANSPROG = 1154, /* s */ 237 RPMTAG_POSTTRANSPROG = 1154, /* s */
238 RPMTAG_DISTTAG = 1155, /* s */ 238 RPMTAG_DISTTAG = 1155, /* s */
239#endif 239#endif
240 {0, 0} 240 {0, 0}
241}; 241};
@@ -271,142 +271,142 @@ EXTRACTOR_rpm_extract_method (struct EXTRACTOR_ExtractContext *ec)
271 if (0 != pipe (parg.pi)) 271 if (0 != pipe (parg.pi))
272 return; 272 return;
273 if (0 != pthread_mutex_init (&parg.lock, NULL)) 273 if (0 != pthread_mutex_init (&parg.lock, NULL))
274 { 274 {
275 CLOSE (parg.pi[0]); 275 CLOSE (parg.pi[0]);
276 CLOSE (parg.pi[1]); 276 CLOSE (parg.pi[1]);
277 return; 277 return;
278 } 278 }
279 if (0 != pthread_create (&pthr, 279 if (0 != pthread_create (&pthr,
280 NULL, 280 NULL,
281 &pipe_feeder, 281 &pipe_feeder,
282 &parg)) 282 &parg))
283 { 283 {
284 pthread_mutex_destroy (&parg.lock); 284 pthread_mutex_destroy (&parg.lock);
285 CLOSE (parg.pi[0]); 285 CLOSE (parg.pi[0]);
286 CLOSE (parg.pi[1]); 286 CLOSE (parg.pi[1]);
287 return; 287 return;
288 } 288 }
289 rpmlogSetCallback (&discard_log_callback, NULL); 289 rpmlogSetCallback (&discard_log_callback, NULL);
290 fdi = fdDup (parg.pi[0]); 290 fdi = fdDup (parg.pi[0]);
291 ts = rpmtsCreate(); 291 ts = rpmtsCreate ();
292 rc = rpmReadPackageFile (ts, fdi, "GNU libextractor", &hdr); 292 rc = rpmReadPackageFile (ts, fdi, "GNU libextractor", &hdr);
293 switch (rc) 293 switch (rc)
294 { 294 {
295 case RPMRC_OK: 295 case RPMRC_OK:
296 case RPMRC_NOKEY: 296 case RPMRC_NOKEY:
297 case RPMRC_NOTTRUSTED: 297 case RPMRC_NOTTRUSTED:
298 break; 298 break;
299 case RPMRC_NOTFOUND: 299 case RPMRC_NOTFOUND:
300 case RPMRC_FAIL: 300 case RPMRC_FAIL:
301 default: 301 default:
302 goto END; 302 goto END;
303 } 303 }
304 pthread_mutex_lock (&parg.lock); 304 pthread_mutex_lock (&parg.lock);
305 if (0 != ec->proc (ec->cls, 305 if (0 != ec->proc (ec->cls,
306 "rpm", 306 "rpm",
307 EXTRACTOR_METATYPE_MIMETYPE, 307 EXTRACTOR_METATYPE_MIMETYPE,
308 EXTRACTOR_METAFORMAT_UTF8, 308 EXTRACTOR_METAFORMAT_UTF8,
309 "text/plain", 309 "text/plain",
310 "application/x-rpm", 310 "application/x-rpm",
311 strlen ("application/x-rpm") +1)) 311 strlen ("application/x-rpm") + 1))
312 { 312 {
313 pthread_mutex_unlock (&parg.lock); 313 pthread_mutex_unlock (&parg.lock);
314 goto END; 314 goto END;
315 } 315 }
316 pthread_mutex_unlock (&parg.lock); 316 pthread_mutex_unlock (&parg.lock);
317 hi = headerInitIterator (hdr); 317 hi = headerInitIterator (hdr);
318 p = rpmtdNew (); 318 p = rpmtdNew ();
319 while (1 == headerNext (hi, p)) 319 while (1 == headerNext (hi, p))
320 for (i = 0; 0 != tests[i].rtype; i++) 320 for (i = 0; 0 != tests[i].rtype; i++)
321 {
322 if (tests[i].rtype != p->tag)
323 continue;
324 switch (p->type)
321 { 325 {
322 if (tests[i].rtype != p->tag) 326 case RPM_STRING_ARRAY_TYPE:
323 continue; 327 case RPM_I18NSTRING_TYPE:
324 switch (p->type) 328 case RPM_STRING_TYPE:
325 { 329 while (NULL != (str = rpmtdNextString (p)))
326 case RPM_STRING_ARRAY_TYPE: 330 {
327 case RPM_I18NSTRING_TYPE: 331 pthread_mutex_lock (&parg.lock);
328 case RPM_STRING_TYPE: 332 if (0 != ec->proc (ec->cls,
329 while (NULL != (str = rpmtdNextString (p))) 333 "rpm",
330 { 334 tests[i].type,
331 pthread_mutex_lock (&parg.lock); 335 EXTRACTOR_METAFORMAT_UTF8,
332 if (0 != ec->proc (ec->cls, 336 "text/plain",
333 "rpm", 337 str,
334 tests[i].type, 338 strlen (str) + 1))
335 EXTRACTOR_METAFORMAT_UTF8, 339
336 "text/plain", 340 {
337 str, 341 pthread_mutex_unlock (&parg.lock);
338 strlen (str) + 1)) 342 goto CLEANUP;
339 343 }
340 { 344 pthread_mutex_unlock (&parg.lock);
341 pthread_mutex_unlock (&parg.lock); 345 }
342 goto CLEANUP; 346 break;
343 } 347 case RPM_INT32_TYPE:
344 pthread_mutex_unlock (&parg.lock); 348 {
345 } 349 if (p->tag == RPMTAG_BUILDTIME)
346 break; 350 {
347 case RPM_INT32_TYPE: 351 char tmp[80];
348 { 352 uint32_t *v = rpmtdNextUint32 (p);
349 if (p->tag == RPMTAG_BUILDTIME) 353 time_t tp = (time_t) *v;
350 { 354
351 char tmp[80]; 355 if (NULL == ctime_r (&tp, tmp))
352 uint32_t *v = rpmtdNextUint32 (p); 356 break;
353 time_t tp = (time_t) *v; 357 if ( (strlen (tmp) > 0) &&
354 358 (isspace ((unsigned char) tmp[strlen (tmp) - 1])) )
355 if (NULL == ctime_r (&tp, tmp)) 359 tmp[strlen (tmp) - 1] = '\0'; /* eat linefeed */
356 break; 360 pthread_mutex_lock (&parg.lock);
357 if ( (strlen (tmp) > 0) && 361 if (0 != ec->proc (ec->cls,
358 (isspace ((unsigned char) tmp[strlen(tmp)-1])) ) 362 "rpm",
359 tmp[strlen (tmp) - 1] = '\0'; /* eat linefeed */ 363 tests[i].type,
360 pthread_mutex_lock (&parg.lock); 364 EXTRACTOR_METAFORMAT_UTF8,
361 if (0 != ec->proc (ec->cls, 365 "text/plain",
362 "rpm", 366 tmp,
363 tests[i].type, 367 strlen (tmp) + 1))
364 EXTRACTOR_METAFORMAT_UTF8, 368 {
365 "text/plain", 369 pthread_mutex_unlock (&parg.lock);
366 tmp, 370 goto CLEANUP;
367 strlen (tmp) + 1)) 371 }
368 { 372 pthread_mutex_unlock (&parg.lock);
369 pthread_mutex_unlock (&parg.lock); 373 }
370 goto CLEANUP; 374 else
371 } 375 {
372 pthread_mutex_unlock (&parg.lock); 376 char tmp[14];
373 } 377 uint32_t *s = rpmtdNextUint32 (p);
374 else 378
375 { 379 snprintf (tmp,
376 char tmp[14]; 380 sizeof (tmp),
377 uint32_t *s = rpmtdNextUint32 (p); 381 "%u",
378 382 (unsigned int) *s);
379 snprintf (tmp, 383 pthread_mutex_lock (&parg.lock);
380 sizeof (tmp), 384 if (0 != ec->proc (ec->cls,
381 "%u", 385 "rpm",
382 (unsigned int) *s); 386 tests[i].type,
383 pthread_mutex_lock (&parg.lock); 387 EXTRACTOR_METAFORMAT_UTF8,
384 if (0 != ec->proc (ec->cls, 388 "text/plain",
385 "rpm", 389 tmp,
386 tests[i].type, 390 strlen (tmp) + 1))
387 EXTRACTOR_METAFORMAT_UTF8, 391 {
388 "text/plain", 392 pthread_mutex_unlock (&parg.lock);
389 tmp, 393 goto CLEANUP;
390 strlen (tmp) + 1)) 394 }
391 { 395 pthread_mutex_unlock (&parg.lock);
392 pthread_mutex_unlock (&parg.lock); 396 }
393 goto CLEANUP; 397 break;
394 } 398 }
395 pthread_mutex_unlock (&parg.lock); 399 default:
396 } 400 break;
397 break;
398 }
399 default:
400 break;
401 }
402 } 401 }
403 CLEANUP: 402 }
403CLEANUP:
404 rpmtdFree (p); 404 rpmtdFree (p);
405 headerFreeIterator (hi); 405 headerFreeIterator (hi);
406 406
407 END: 407END:
408 headerFree (hdr); 408 headerFree (hdr);
409 rpmtsFree(ts); 409 rpmtsFree (ts);
410 410
411 /* make sure SIGALRM does not kill us, then use it to 411 /* make sure SIGALRM does not kill us, then use it to
412 kill the thread */ 412 kill the thread */
@@ -424,4 +424,5 @@ EXTRACTOR_rpm_extract_method (struct EXTRACTOR_ExtractContext *ec)
424 sigaction (SIGALRM, &old, &sig); 424 sigaction (SIGALRM, &old, &sig);
425} 425}
426 426
427
427/* end of rpm_extractor.c */ 428/* end of rpm_extractor.c */
diff --git a/src/plugins/s3m_extractor.c b/src/plugins/s3m_extractor.c
index c4789ce..9372110 100644
--- a/src/plugins/s3m_extractor.c
+++ b/src/plugins/s3m_extractor.c
@@ -61,7 +61,11 @@ LE_NETWORK_STRUCT_END
61 * @param t LE meta data type 61 * @param t LE meta data type
62 * @param s meta data to add 62 * @param s meta data to add
63 */ 63 */
64#define ADD(s, t) do { if (0 != ec->proc (ec->cls, "s3m", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen (s) + 1)) return; } while (0) 64#define ADD(s, t) do { if (0 != ec->proc (ec->cls, "s3m", t, \
65 EXTRACTOR_METAFORMAT_UTF8, \
66 "text/plain", s, strlen (s) \
67 + 1)) return; \
68} while (0)
65 69
66 70
67/** 71/**
@@ -82,8 +86,8 @@ EXTRACTOR_s3m_extract_method (struct EXTRACTOR_ExtractContext *ec)
82 86
83 if ((ssize_t) sizeof (header) > 87 if ((ssize_t) sizeof (header) >
84 ec->read (ec->cls, 88 ec->read (ec->cls,
85 &data, 89 &data,
86 sizeof (header))) 90 sizeof (header)))
87 return; 91 return;
88 memcpy (&header, data, sizeof (header)); 92 memcpy (&header, data, sizeof (header));
89 if ( (0x1A != header.byte_1A) || 93 if ( (0x1A != header.byte_1A) ||
@@ -105,4 +109,5 @@ EXTRACTOR_s3m_extract_method (struct EXTRACTOR_ExtractContext *ec)
105 */ 109 */
106} 110}
107 111
112
108/* end of s3m_extractor.c */ 113/* end of s3m_extractor.c */
diff --git a/src/plugins/sid_extractor.c b/src/plugins/sid_extractor.c
index dface42..58d4e5d 100644
--- a/src/plugins/sid_extractor.c
+++ b/src/plugins/sid_extractor.c
@@ -154,7 +154,11 @@ sidword (const sidwrd data)
154 * @param s metadata value as UTF8 154 * @param s metadata value as UTF8
155 * @param t metadata type to use 155 * @param t metadata type to use
156 */ 156 */
157#define ADD(s,t) do { if (0 != ec->proc (ec->cls, "sid", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen (s) + 1)) return; } while (0) 157#define ADD(s,t) do { if (0 != ec->proc (ec->cls, "sid", t, \
158 EXTRACTOR_METAFORMAT_UTF8, \
159 "text/plain", s, strlen (s) \
160 + 1)) return; \
161} while (0)
158 162
159 163
160/** 164/**
@@ -178,8 +182,8 @@ EXTRACTOR_sid_extract_method (struct EXTRACTOR_ExtractContext *ec)
178 182
179 if ((ssize_t) sizeof (struct header) > 183 if ((ssize_t) sizeof (struct header) >
180 ec->read (ec->cls, 184 ec->read (ec->cls,
181 &data, 185 &data,
182 sizeof (struct header))) 186 sizeof (struct header)))
183 return; 187 return;
184 head = data; 188 head = data;
185 189
@@ -194,22 +198,22 @@ EXTRACTOR_sid_extract_method (struct EXTRACTOR_ExtractContext *ec)
194 /* Version of SID format */ 198 /* Version of SID format */
195 version = sidword (head->sidversion); 199 version = sidword (head->sidversion);
196 snprintf (sidversion, 200 snprintf (sidversion,
197 sizeof (sidversion), 201 sizeof (sidversion),
198 "%d", 202 "%d",
199 version); 203 version);
200 ADD (sidversion, EXTRACTOR_METATYPE_FORMAT_VERSION); 204 ADD (sidversion, EXTRACTOR_METATYPE_FORMAT_VERSION);
201 205
202 /* Get song count */ 206 /* Get song count */
203 snprintf (songs, 207 snprintf (songs,
204 sizeof (songs), 208 sizeof (songs),
205 "%d", sidword (head->songs)); 209 "%d", sidword (head->songs));
206 ADD (songs, EXTRACTOR_METATYPE_SONG_COUNT); 210 ADD (songs, EXTRACTOR_METATYPE_SONG_COUNT);
207 211
208 /* Get number of the first song to be played */ 212 /* Get number of the first song to be played */
209 snprintf (startingsong, 213 snprintf (startingsong,
210 sizeof (startingsong), 214 sizeof (startingsong),
211 "%d", 215 "%d",
212 sidword (head->firstsong)); 216 sidword (head->firstsong));
213 ADD (startingsong, EXTRACTOR_METATYPE_STARTING_SONG); 217 ADD (startingsong, EXTRACTOR_METATYPE_STARTING_SONG);
214 218
215 /* name, artist, copyright fields */ 219 /* name, artist, copyright fields */
@@ -232,8 +236,7 @@ EXTRACTOR_sid_extract_method (struct EXTRACTOR_ExtractContext *ec)
232 * 236 *
233 * Note: Had some troubles understanding specification 237 * Note: Had some troubles understanding specification
234 * on the flags in version 2. I hope this is correct. 238 * on the flags in version 2. I hope this is correct.
235 */ 239 */flags = sidword (head->flags);
236 flags = sidword (head->flags);
237 /* MUS data */ 240 /* MUS data */
238 if (0 != (flags & MUSPLAYER_FLAG)) 241 if (0 != (flags & MUSPLAYER_FLAG))
239 ADD ("Compute!'s Sidplayer", EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE); 242 ADD ("Compute!'s Sidplayer", EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE);
@@ -256,4 +259,5 @@ EXTRACTOR_sid_extract_method (struct EXTRACTOR_ExtractContext *ec)
256 ADD ("MOS6581", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE); 259 ADD ("MOS6581", EXTRACTOR_METATYPE_TARGET_ARCHITECTURE);
257} 260}
258 261
262
259/* end of sid_extractor.c */ 263/* end of sid_extractor.c */
diff --git a/src/plugins/template_extractor.c b/src/plugins/template_extractor.c
index aad875e..9dad40d 100644
--- a/src/plugins/template_extractor.c
+++ b/src/plugins/template_extractor.c
@@ -46,13 +46,13 @@ EXTRACTOR_template_extract_method (struct EXTRACTOR_ExtractContext *ec)
46 return 1; 46 return 1;
47 47
48 /* initialize state here */ 48 /* initialize state here */
49 49
50 /* Call seek (plugin, POSITION, WHENCE) to seek (if you know where 50 /* Call seek (plugin, POSITION, WHENCE) to seek (if you know where
51 * data starts): 51 * data starts):
52 */ 52 */
53 // ec->seek (ec->cls, POSITION, SEEK_SET); 53 // ec->seek (ec->cls, POSITION, SEEK_SET);
54 54
55 /* Call read (plugin, &data, COUNT) to read COUNT bytes 55 /* Call read (plugin, &data, COUNT) to read COUNT bytes
56 */ 56 */
57 57
58 58
@@ -64,4 +64,5 @@ EXTRACTOR_template_extract_method (struct EXTRACTOR_ExtractContext *ec)
64 return; 64 return;
65} 65}
66 66
67
67/* end of template_extractor.c */ 68/* end of template_extractor.c */
diff --git a/src/plugins/test_archive.c b/src/plugins/test_archive.c
index a7a8c1d..a98c05e 100644
--- a/src/plugins/test_archive.c
+++ b/src/plugins/test_archive.c
@@ -36,41 +36,40 @@
36int 36int
37main (int argc, char *argv[]) 37main (int argc, char *argv[])
38{ 38{
39 struct SolutionData tar_archive_sol[] = 39 struct SolutionData tar_archive_sol[] = {
40 { 40 {
41 { 41 EXTRACTOR_METATYPE_FILENAME,
42 EXTRACTOR_METATYPE_FILENAME, 42 EXTRACTOR_METAFORMAT_UTF8,
43 EXTRACTOR_METAFORMAT_UTF8, 43 "text/plain",
44 "text/plain", 44 "test.html",
45 "test.html", 45 strlen ("test.html") + 1,
46 strlen ("test.html") + 1, 46 0
47 0 47 },
48 },
49 {
50 EXTRACTOR_METATYPE_FILENAME,
51 EXTRACTOR_METAFORMAT_UTF8,
52 "text/plain",
53 "test.jpg",
54 strlen ("test.jpg") + 1,
55 0
56 },
57 {
58 EXTRACTOR_METATYPE_FORMAT,
59 EXTRACTOR_METAFORMAT_UTF8,
60 "text/plain",
61 "GNU tar format",
62 strlen ("GNU tar format") + 1,
63 0
64 },
65 { 0, 0, NULL, NULL, 0, -1 }
66 };
67 struct ProblemSet ps[] =
68 { 48 {
69 { "testdata/archive_test.tar", 49 EXTRACTOR_METATYPE_FILENAME,
70 tar_archive_sol }, 50 EXTRACTOR_METAFORMAT_UTF8,
71 { NULL, NULL } 51 "text/plain",
72 }; 52 "test.jpg",
53 strlen ("test.jpg") + 1,
54 0
55 },
56 {
57 EXTRACTOR_METATYPE_FORMAT,
58 EXTRACTOR_METAFORMAT_UTF8,
59 "text/plain",
60 "GNU tar format",
61 strlen ("GNU tar format") + 1,
62 0
63 },
64 { 0, 0, NULL, NULL, 0, -1 }
65 };
66 struct ProblemSet ps[] = {
67 { "testdata/archive_test.tar",
68 tar_archive_sol },
69 { NULL, NULL }
70 };
73 return ET_main ("archive", ps); 71 return ET_main ("archive", ps);
74} 72}
75 73
74
76/* end of test_archive.c */ 75/* end of test_archive.c */
diff --git a/src/plugins/test_deb.c b/src/plugins/test_deb.c
index 0b7c653..767c34f 100644
--- a/src/plugins/test_deb.c
+++ b/src/plugins/test_deb.c
@@ -36,139 +36,138 @@
36int 36int
37main (int argc, char *argv[]) 37main (int argc, char *argv[])
38{ 38{
39 struct SolutionData deb_bzip2_sol[] = 39 struct SolutionData deb_bzip2_sol[] = {
40 { 40 {
41 { 41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METATYPE_MIMETYPE, 42 EXTRACTOR_METAFORMAT_UTF8,
43 EXTRACTOR_METAFORMAT_UTF8, 43 "text/plain",
44 "text/plain", 44 "application/x-debian-package",
45 "application/x-debian-package", 45 strlen ("application/x-debian-package") + 1,
46 strlen ("application/x-debian-package") + 1, 46 0
47 0 47 },
48 },
49 {
50 EXTRACTOR_METATYPE_PACKAGE_NAME,
51 EXTRACTOR_METAFORMAT_UTF8,
52 "text/plain",
53 "bzip2",
54 strlen ("bzip2") + 1,
55 0
56 },
57 {
58 EXTRACTOR_METATYPE_PACKAGE_VERSION,
59 EXTRACTOR_METAFORMAT_UTF8,
60 "text/plain",
61 "1.0.6-4",
62 strlen ("1.0.6-4") + 1,
63 0
64 },
65 {
66 EXTRACTOR_METATYPE_TARGET_ARCHITECTURE,
67 EXTRACTOR_METAFORMAT_UTF8,
68 "text/plain",
69 "i386",
70 strlen ("i386") + 1,
71 0
72 },
73 {
74 EXTRACTOR_METATYPE_PACKAGE_MAINTAINER,
75 EXTRACTOR_METAFORMAT_UTF8,
76 "text/plain",
77 "Anibal Monsalve Salazar <anibal@debian.org>",
78 strlen ("Anibal Monsalve Salazar <anibal@debian.org>") + 1,
79 0
80 },
81 {
82 EXTRACTOR_METATYPE_PACKAGE_INSTALLED_SIZE,
83 EXTRACTOR_METAFORMAT_UTF8,
84 "text/plain",
85 "113", /* FIXME: should this be 'kb'? */
86 strlen ("113") + 1,
87 0
88 },
89 {
90 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY,
91 EXTRACTOR_METAFORMAT_UTF8,
92 "text/plain",
93 "libbz2-1.0 (= 1.0.6-4), libc6 (>= 2.4)",
94 strlen ("libbz2-1.0 (= 1.0.6-4), libc6 (>= 2.4)") + 1,
95 0
96 },
97 {
98 EXTRACTOR_METATYPE_PACKAGE_SUGGESTS,
99 EXTRACTOR_METAFORMAT_UTF8,
100 "text/plain",
101 "bzip2-doc",
102 strlen ("bzip2-doc") + 1,
103 0
104 },
105 {
106 EXTRACTOR_METATYPE_PACKAGE_REPLACES,
107 EXTRACTOR_METAFORMAT_UTF8,
108 "text/plain",
109 "libbz2 (<< 0.9.5d-3)",
110 strlen ("libbz2 (<< 0.9.5d-3)") + 1,
111 0
112 },
113 {
114 EXTRACTOR_METATYPE_SECTION,
115 EXTRACTOR_METAFORMAT_UTF8,
116 "text/plain",
117 "utils",
118 strlen ("utils") + 1,
119 0
120 },
121 {
122 EXTRACTOR_METATYPE_UPLOAD_PRIORITY,
123 EXTRACTOR_METAFORMAT_UTF8,
124 "text/plain",
125 "standard",
126 strlen ("standard") + 1,
127 0
128 },
129 {
130 EXTRACTOR_METATYPE_DESCRIPTION,
131 EXTRACTOR_METAFORMAT_UTF8,
132 "text/plain",
133 "high-quality block-sorting file compressor - utilities\n"
134" bzip2 is a freely available, patent free, high-quality data compressor.\n"
135" It typically compresses files to within 10% to 15% of the best available\n"
136" techniques, whilst being around twice as fast at compression and six\n"
137" times faster at decompression.\n"
138" .\n"
139" bzip2 compresses files using the Burrows-Wheeler block-sorting text\n"
140" compression algorithm, and Huffman coding. Compression is generally\n"
141" considerably better than that achieved by more conventional\n"
142" LZ77/LZ78-based compressors, and approaches the performance of the PPM\n"
143" family of statistical compressors.\n"
144" .\n"
145" The archive file format of bzip2 (.bz2) is incompatible with that of its\n"
146" predecessor, bzip (.bz).",
147 strlen ("high-quality block-sorting file compressor - utilities\n"
148" bzip2 is a freely available, patent free, high-quality data compressor.\n"
149" It typically compresses files to within 10% to 15% of the best available\n"
150" techniques, whilst being around twice as fast at compression and six\n"
151" times faster at decompression.\n"
152" .\n"
153" bzip2 compresses files using the Burrows-Wheeler block-sorting text\n"
154" compression algorithm, and Huffman coding. Compression is generally\n"
155" considerably better than that achieved by more conventional\n"
156" LZ77/LZ78-based compressors, and approaches the performance of the PPM\n"
157" family of statistical compressors.\n"
158" .\n"
159" The archive file format of bzip2 (.bz2) is incompatible with that of its\n"
160" predecessor, bzip (.bz).") + 1,
161 0
162 },
163 { 0, 0, NULL, NULL, 0, -1 }
164 };
165 struct ProblemSet ps[] =
166 { 48 {
167 { "testdata/deb_bzip2.deb", 49 EXTRACTOR_METATYPE_PACKAGE_NAME,
168 deb_bzip2_sol }, 50 EXTRACTOR_METAFORMAT_UTF8,
169 { NULL, NULL } 51 "text/plain",
170 }; 52 "bzip2",
53 strlen ("bzip2") + 1,
54 0
55 },
56 {
57 EXTRACTOR_METATYPE_PACKAGE_VERSION,
58 EXTRACTOR_METAFORMAT_UTF8,
59 "text/plain",
60 "1.0.6-4",
61 strlen ("1.0.6-4") + 1,
62 0
63 },
64 {
65 EXTRACTOR_METATYPE_TARGET_ARCHITECTURE,
66 EXTRACTOR_METAFORMAT_UTF8,
67 "text/plain",
68 "i386",
69 strlen ("i386") + 1,
70 0
71 },
72 {
73 EXTRACTOR_METATYPE_PACKAGE_MAINTAINER,
74 EXTRACTOR_METAFORMAT_UTF8,
75 "text/plain",
76 "Anibal Monsalve Salazar <anibal@debian.org>",
77 strlen ("Anibal Monsalve Salazar <anibal@debian.org>") + 1,
78 0
79 },
80 {
81 EXTRACTOR_METATYPE_PACKAGE_INSTALLED_SIZE,
82 EXTRACTOR_METAFORMAT_UTF8,
83 "text/plain",
84 "113", /* FIXME: should this be 'kb'? */
85 strlen ("113") + 1,
86 0
87 },
88 {
89 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY,
90 EXTRACTOR_METAFORMAT_UTF8,
91 "text/plain",
92 "libbz2-1.0 (= 1.0.6-4), libc6 (>= 2.4)",
93 strlen ("libbz2-1.0 (= 1.0.6-4), libc6 (>= 2.4)") + 1,
94 0
95 },
96 {
97 EXTRACTOR_METATYPE_PACKAGE_SUGGESTS,
98 EXTRACTOR_METAFORMAT_UTF8,
99 "text/plain",
100 "bzip2-doc",
101 strlen ("bzip2-doc") + 1,
102 0
103 },
104 {
105 EXTRACTOR_METATYPE_PACKAGE_REPLACES,
106 EXTRACTOR_METAFORMAT_UTF8,
107 "text/plain",
108 "libbz2 (<< 0.9.5d-3)",
109 strlen ("libbz2 (<< 0.9.5d-3)") + 1,
110 0
111 },
112 {
113 EXTRACTOR_METATYPE_SECTION,
114 EXTRACTOR_METAFORMAT_UTF8,
115 "text/plain",
116 "utils",
117 strlen ("utils") + 1,
118 0
119 },
120 {
121 EXTRACTOR_METATYPE_UPLOAD_PRIORITY,
122 EXTRACTOR_METAFORMAT_UTF8,
123 "text/plain",
124 "standard",
125 strlen ("standard") + 1,
126 0
127 },
128 {
129 EXTRACTOR_METATYPE_DESCRIPTION,
130 EXTRACTOR_METAFORMAT_UTF8,
131 "text/plain",
132 "high-quality block-sorting file compressor - utilities\n"
133 " bzip2 is a freely available, patent free, high-quality data compressor.\n"
134 " It typically compresses files to within 10% to 15% of the best available\n"
135 " techniques, whilst being around twice as fast at compression and six\n"
136 " times faster at decompression.\n"
137 " .\n"
138 " bzip2 compresses files using the Burrows-Wheeler block-sorting text\n"
139 " compression algorithm, and Huffman coding. Compression is generally\n"
140 " considerably better than that achieved by more conventional\n"
141 " LZ77/LZ78-based compressors, and approaches the performance of the PPM\n"
142 " family of statistical compressors.\n"
143 " .\n"
144 " The archive file format of bzip2 (.bz2) is incompatible with that of its\n"
145 " predecessor, bzip (.bz).",
146 strlen ("high-quality block-sorting file compressor - utilities\n"
147 " bzip2 is a freely available, patent free, high-quality data compressor.\n"
148 " It typically compresses files to within 10% to 15% of the best available\n"
149 " techniques, whilst being around twice as fast at compression and six\n"
150 " times faster at decompression.\n"
151 " .\n"
152 " bzip2 compresses files using the Burrows-Wheeler block-sorting text\n"
153 " compression algorithm, and Huffman coding. Compression is generally\n"
154 " considerably better than that achieved by more conventional\n"
155 " LZ77/LZ78-based compressors, and approaches the performance of the PPM\n"
156 " family of statistical compressors.\n"
157 " .\n"
158 " The archive file format of bzip2 (.bz2) is incompatible with that of its\n"
159 " predecessor, bzip (.bz).") + 1,
160 0
161 },
162 { 0, 0, NULL, NULL, 0, -1 }
163 };
164 struct ProblemSet ps[] = {
165 { "testdata/deb_bzip2.deb",
166 deb_bzip2_sol },
167 { NULL, NULL }
168 };
171 return ET_main ("deb", ps); 169 return ET_main ("deb", ps);
172} 170}
173 171
172
174/* end of test_deb.c */ 173/* end of test_deb.c */
diff --git a/src/plugins/test_dvi.c b/src/plugins/test_dvi.c
index 9a5f27f..2ec364b 100644
--- a/src/plugins/test_dvi.c
+++ b/src/plugins/test_dvi.c
@@ -36,89 +36,94 @@
36int 36int
37main (int argc, char *argv[]) 37main (int argc, char *argv[])
38{ 38{
39 struct SolutionData dvi_ora_sol[] = 39 struct SolutionData dvi_ora_sol[] = {
40 { 40 {
41 { 41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METATYPE_MIMETYPE, 42 EXTRACTOR_METAFORMAT_UTF8,
43 EXTRACTOR_METAFORMAT_UTF8, 43 "text/plain",
44 "text/plain", 44 "application/x-dvi",
45 "application/x-dvi", 45 strlen ("application/x-dvi") + 1,
46 strlen ("application/x-dvi") + 1, 46 0
47 0 47 },
48 },
49 {
50 EXTRACTOR_METATYPE_PAGE_COUNT,
51 EXTRACTOR_METAFORMAT_UTF8,
52 "text/plain",
53 "10",
54 strlen ("10") + 1,
55 0
56 },
57 {
58 EXTRACTOR_METATYPE_TITLE,
59 EXTRACTOR_METAFORMAT_C_STRING,
60 "text/plain",
61 "Optimal Bitwise Register Allocation using Integer Linear Programming",
62 strlen ("Optimal Bitwise Register Allocation using Integer Linear Programming") + 1,
63 0
64 },
65 {
66 EXTRACTOR_METATYPE_SUBJECT,
67 EXTRACTOR_METAFORMAT_C_STRING,
68 "text/plain",
69 "Register Allocation",
70 strlen ("Register Allocation") + 1,
71 0
72 },
73 {
74 EXTRACTOR_METATYPE_COMMENT,
75 EXTRACTOR_METAFORMAT_C_STRING,
76 "text/plain",
77 " TeX output 2005.02.06:0725",
78 strlen (" TeX output 2005.02.06:0725") + 1,
79 0
80 },
81 {
82 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
83 EXTRACTOR_METAFORMAT_C_STRING,
84 "text/plain",
85 "LaTeX with hyperref package",
86 strlen ("LaTeX with hyperref package") + 1,
87 0
88 },
89 {
90 EXTRACTOR_METATYPE_AUTHOR_NAME,
91 EXTRACTOR_METAFORMAT_C_STRING,
92 "text/plain",
93 "Rajkishore Barik and Christian Grothoff and Rahul Gupta and Vinayaka Pandit and Raghavendra Udupa",
94 strlen ("Rajkishore Barik and Christian Grothoff and Rahul Gupta and Vinayaka Pandit and Raghavendra Udupa") + 1,
95 0
96 },
97 {
98 EXTRACTOR_METATYPE_PRODUCED_BY_SOFTWARE,
99 EXTRACTOR_METAFORMAT_C_STRING,
100 "text/plain",
101 "dvips + Distiller",
102 strlen ("dvips + Distiller") + 1,
103 0
104 },
105 {
106 EXTRACTOR_METATYPE_KEYWORDS,
107 EXTRACTOR_METAFORMAT_C_STRING,
108 "text/plain",
109 "register allocation integer linear programming bit-wise spilling coalesing rematerialization",
110 strlen ("register allocation integer linear programming bit-wise spilling coalesing rematerialization") + 1,
111 0
112 },
113 { 0, 0, NULL, NULL, 0, -1 }
114 };
115 struct ProblemSet ps[] =
116 { 48 {
117 { "testdata/dvi_ora.dvi", 49 EXTRACTOR_METATYPE_PAGE_COUNT,
118 dvi_ora_sol }, 50 EXTRACTOR_METAFORMAT_UTF8,
119 { NULL, NULL } 51 "text/plain",
120 }; 52 "10",
53 strlen ("10") + 1,
54 0
55 },
56 {
57 EXTRACTOR_METATYPE_TITLE,
58 EXTRACTOR_METAFORMAT_C_STRING,
59 "text/plain",
60 "Optimal Bitwise Register Allocation using Integer Linear Programming",
61 strlen (
62 "Optimal Bitwise Register Allocation using Integer Linear Programming")
63 + 1,
64 0
65 },
66 {
67 EXTRACTOR_METATYPE_SUBJECT,
68 EXTRACTOR_METAFORMAT_C_STRING,
69 "text/plain",
70 "Register Allocation",
71 strlen ("Register Allocation") + 1,
72 0
73 },
74 {
75 EXTRACTOR_METATYPE_COMMENT,
76 EXTRACTOR_METAFORMAT_C_STRING,
77 "text/plain",
78 " TeX output 2005.02.06:0725",
79 strlen (" TeX output 2005.02.06:0725") + 1,
80 0
81 },
82 {
83 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
84 EXTRACTOR_METAFORMAT_C_STRING,
85 "text/plain",
86 "LaTeX with hyperref package",
87 strlen ("LaTeX with hyperref package") + 1,
88 0
89 },
90 {
91 EXTRACTOR_METATYPE_AUTHOR_NAME,
92 EXTRACTOR_METAFORMAT_C_STRING,
93 "text/plain",
94 "Rajkishore Barik and Christian Grothoff and Rahul Gupta and Vinayaka Pandit and Raghavendra Udupa",
95 strlen (
96 "Rajkishore Barik and Christian Grothoff and Rahul Gupta and Vinayaka Pandit and Raghavendra Udupa")
97 + 1,
98 0
99 },
100 {
101 EXTRACTOR_METATYPE_PRODUCED_BY_SOFTWARE,
102 EXTRACTOR_METAFORMAT_C_STRING,
103 "text/plain",
104 "dvips + Distiller",
105 strlen ("dvips + Distiller") + 1,
106 0
107 },
108 {
109 EXTRACTOR_METATYPE_KEYWORDS,
110 EXTRACTOR_METAFORMAT_C_STRING,
111 "text/plain",
112 "register allocation integer linear programming bit-wise spilling coalesing rematerialization",
113 strlen (
114 "register allocation integer linear programming bit-wise spilling coalesing rematerialization")
115 + 1,
116 0
117 },
118 { 0, 0, NULL, NULL, 0, -1 }
119 };
120 struct ProblemSet ps[] = {
121 { "testdata/dvi_ora.dvi",
122 dvi_ora_sol },
123 { NULL, NULL }
124 };
121 return ET_main ("dvi", ps); 125 return ET_main ("dvi", ps);
122} 126}
123 127
128
124/* end of test_dvi.c */ 129/* end of test_dvi.c */
diff --git a/src/plugins/test_exiv2.c b/src/plugins/test_exiv2.c
index 292ea18..e4e5319 100644
--- a/src/plugins/test_exiv2.c
+++ b/src/plugins/test_exiv2.c
@@ -36,305 +36,306 @@
36int 36int
37main (int argc, char *argv[]) 37main (int argc, char *argv[])
38{ 38{
39 struct SolutionData exiv2_iptc_sol[] = 39 struct SolutionData exiv2_iptc_sol[] = {
40 { 40 {
41 { 41 EXTRACTOR_METATYPE_GPS_LATITUDE_REF,
42 EXTRACTOR_METATYPE_GPS_LATITUDE_REF, 42 EXTRACTOR_METAFORMAT_UTF8,
43 EXTRACTOR_METAFORMAT_UTF8, 43 "text/plain",
44 "text/plain", 44 "North",
45 "North", 45 strlen ("North") + 1,
46 strlen ("North") + 1, 46 0
47 0 47 },
48 }, 48 {
49 { 49 EXTRACTOR_METATYPE_GPS_LATITUDE,
50 EXTRACTOR_METATYPE_GPS_LATITUDE, 50 EXTRACTOR_METAFORMAT_UTF8,
51 EXTRACTOR_METAFORMAT_UTF8, 51 "text/plain",
52 "text/plain", 52 "28deg 8' 17.585\" ",
53 "28deg 8' 17.585\" ", 53 strlen ("28deg 8' 17.585\" ") + 1,
54 strlen ("28deg 8' 17.585\" ") + 1, 54 0
55 0 55 },
56 }, 56 {
57 { 57 EXTRACTOR_METATYPE_GPS_LONGITUDE_REF,
58 EXTRACTOR_METATYPE_GPS_LONGITUDE_REF, 58 EXTRACTOR_METAFORMAT_UTF8,
59 EXTRACTOR_METAFORMAT_UTF8, 59 "text/plain",
60 "text/plain", 60 "West",
61 "West", 61 strlen ("West") + 1,
62 strlen ("West") + 1, 62 0
63 0 63 },
64 }, 64 {
65 { 65 EXTRACTOR_METATYPE_GPS_LONGITUDE,
66 EXTRACTOR_METATYPE_GPS_LONGITUDE, 66 EXTRACTOR_METAFORMAT_UTF8,
67 EXTRACTOR_METAFORMAT_UTF8, 67 "text/plain",
68 "text/plain", 68 "14deg 14' 21.713\" ",
69 "14deg 14' 21.713\" ", 69 strlen ("14deg 14' 21.713\" ") + 1,
70 strlen ("14deg 14' 21.713\" ") + 1, 70 0
71 0 71 },
72 }, 72 {
73 { 73 EXTRACTOR_METATYPE_CAMERA_MAKE,
74 EXTRACTOR_METATYPE_CAMERA_MAKE, 74 EXTRACTOR_METAFORMAT_UTF8,
75 EXTRACTOR_METAFORMAT_UTF8, 75 "text/plain",
76 "text/plain", 76 "PENTAX Corporation",
77 "PENTAX Corporation", 77 strlen ("PENTAX Corporation") + 1,
78 strlen ("PENTAX Corporation") + 1, 78 0
79 0 79 },
80 }, 80 {
81 { 81 EXTRACTOR_METATYPE_CAMERA_MODEL,
82 EXTRACTOR_METATYPE_CAMERA_MODEL, 82 EXTRACTOR_METAFORMAT_UTF8,
83 EXTRACTOR_METAFORMAT_UTF8, 83 "text/plain",
84 "text/plain", 84 "PENTAX Optio W30",
85 "PENTAX Optio W30", 85 strlen ("PENTAX Optio W30") + 1,
86 strlen ("PENTAX Optio W30") + 1, 86 0
87 0 87 },
88 }, 88 {
89 { 89 EXTRACTOR_METATYPE_ORIENTATION,
90 EXTRACTOR_METATYPE_ORIENTATION, 90 EXTRACTOR_METAFORMAT_UTF8,
91 EXTRACTOR_METAFORMAT_UTF8, 91 "text/plain",
92 "text/plain", 92 "top, left",
93 "top, left", 93 strlen ("top, left") + 1,
94 strlen ("top, left") + 1, 94 0
95 0 95 },
96 }, 96 {
97 { 97 EXTRACTOR_METATYPE_CREATION_DATE,
98 EXTRACTOR_METATYPE_CREATION_DATE, 98 EXTRACTOR_METAFORMAT_UTF8,
99 EXTRACTOR_METAFORMAT_UTF8, 99 "text/plain",
100 "text/plain", 100 "2008:06:29 16:06:10",
101 "2008:06:29 16:06:10", 101 strlen ("2008:06:29 16:06:10") + 1,
102 strlen ("2008:06:29 16:06:10") + 1, 102 0
103 0 103 },
104 }, 104 {
105 { 105 EXTRACTOR_METATYPE_EXPOSURE_BIAS,
106 EXTRACTOR_METATYPE_EXPOSURE_BIAS, 106 EXTRACTOR_METAFORMAT_UTF8,
107 EXTRACTOR_METAFORMAT_UTF8, 107 "text/plain",
108 "text/plain", 108 "0 EV",
109 "0 EV", 109 strlen ("0 EV") + 1,
110 strlen ("0 EV") + 1, 110 0
111 0 111 },
112 }, 112 {
113 { 113 EXTRACTOR_METATYPE_FLASH,
114 EXTRACTOR_METATYPE_FLASH, 114 EXTRACTOR_METAFORMAT_UTF8,
115 EXTRACTOR_METAFORMAT_UTF8, 115 "text/plain",
116 "text/plain", 116 "No, compulsory",
117 "No, compulsory", 117 strlen ("No, compulsory") + 1,
118 strlen ("No, compulsory") + 1, 118 0
119 0 119 },
120 }, 120 {
121 { 121 EXTRACTOR_METATYPE_FOCAL_LENGTH,
122 EXTRACTOR_METATYPE_FOCAL_LENGTH, 122 EXTRACTOR_METAFORMAT_UTF8,
123 EXTRACTOR_METAFORMAT_UTF8, 123 "text/plain",
124 "text/plain", 124 "18.9 mm",
125 "18.9 mm", 125 strlen ("18.9 mm") + 1,
126 strlen ("18.9 mm") + 1, 126 0
127 0 127 },
128 }, 128 {
129 { 129 EXTRACTOR_METATYPE_FOCAL_LENGTH_35MM,
130 EXTRACTOR_METATYPE_FOCAL_LENGTH_35MM, 130 EXTRACTOR_METAFORMAT_UTF8,
131 EXTRACTOR_METAFORMAT_UTF8, 131 "text/plain",
132 "text/plain", 132 "114.0 mm",
133 "114.0 mm", 133 strlen ("114.0 mm") + 1,
134 strlen ("114.0 mm") + 1, 134 0
135 0 135 },
136 }, 136 {
137 { 137 EXTRACTOR_METATYPE_ISO_SPEED,
138 EXTRACTOR_METATYPE_ISO_SPEED, 138 EXTRACTOR_METAFORMAT_UTF8,
139 EXTRACTOR_METAFORMAT_UTF8, 139 "text/plain",
140 "text/plain", 140 "64",
141 "64", 141 strlen ("64") + 1,
142 strlen ("64") + 1, 142 0
143 0 143 },
144 }, 144 {
145 { 145 EXTRACTOR_METATYPE_METERING_MODE,
146 EXTRACTOR_METATYPE_METERING_MODE, 146 EXTRACTOR_METAFORMAT_UTF8,
147 EXTRACTOR_METAFORMAT_UTF8, 147 "text/plain",
148 "text/plain", 148 "Multi-segment",
149 "Multi-segment", 149 strlen ("Multi-segment") + 1,
150 strlen ("Multi-segment") + 1, 150 0
151 0 151 },
152 }, 152 {
153 { 153 EXTRACTOR_METATYPE_APERTURE,
154 EXTRACTOR_METATYPE_APERTURE, 154 EXTRACTOR_METAFORMAT_UTF8,
155 EXTRACTOR_METAFORMAT_UTF8, 155 "text/plain",
156 "text/plain", 156 "F8",
157 "F8", 157 strlen ("F8") + 1,
158 strlen ("F8") + 1, 158 0
159 0 159 },
160 }, 160 {
161 { 161 EXTRACTOR_METATYPE_EXPOSURE,
162 EXTRACTOR_METATYPE_EXPOSURE, 162 EXTRACTOR_METAFORMAT_UTF8,
163 EXTRACTOR_METAFORMAT_UTF8, 163 "text/plain",
164 "text/plain", 164 "1/320 s",
165 "1/320 s", 165 strlen ("1/320 s") + 1,
166 strlen ("1/320 s") + 1, 166 0
167 0 167 },
168 }, 168 {
169 { 169 EXTRACTOR_METATYPE_LOCATION_CITY,
170 EXTRACTOR_METATYPE_LOCATION_CITY, 170 EXTRACTOR_METAFORMAT_UTF8,
171 EXTRACTOR_METAFORMAT_UTF8, 171 "text/plain",
172 "text/plain", 172 "Los Verdes",
173 "Los Verdes", 173 strlen ("Los Verdes") + 1,
174 strlen ("Los Verdes") + 1, 174 0
175 0 175 },
176 }, 176 {
177 { 177 EXTRACTOR_METATYPE_LOCATION_CITY,
178 EXTRACTOR_METATYPE_LOCATION_CITY, 178 EXTRACTOR_METAFORMAT_UTF8,
179 EXTRACTOR_METAFORMAT_UTF8, 179 "text/plain",
180 "text/plain", 180 "Los Verdes",
181 "Los Verdes", 181 strlen ("Los Verdes") + 1,
182 strlen ("Los Verdes") + 1, 182 0
183 0 183 },
184 }, 184 {
185 { 185 EXTRACTOR_METATYPE_LOCATION_SUBLOCATION,
186 EXTRACTOR_METATYPE_LOCATION_SUBLOCATION, 186 EXTRACTOR_METAFORMAT_UTF8,
187 EXTRACTOR_METAFORMAT_UTF8, 187 "text/plain",
188 "text/plain", 188 "Fuerteventura",
189 "Fuerteventura", 189 strlen ("Fuerteventura") + 1,
190 strlen ("Fuerteventura") + 1, 190 0
191 0 191 },
192 }, 192 {
193 { 193 EXTRACTOR_METATYPE_LOCATION_COUNTRY,
194 EXTRACTOR_METATYPE_LOCATION_COUNTRY, 194 EXTRACTOR_METAFORMAT_UTF8,
195 EXTRACTOR_METAFORMAT_UTF8, 195 "text/plain",
196 "text/plain", 196 "Spain",
197 "Spain", 197 strlen ("Spain") + 1,
198 strlen ("Spain") + 1, 198 0
199 0 199 },
200 }, 200 {
201 { 201 EXTRACTOR_METATYPE_LOCATION_COUNTRY,
202 EXTRACTOR_METATYPE_LOCATION_COUNTRY, 202 EXTRACTOR_METAFORMAT_UTF8,
203 EXTRACTOR_METAFORMAT_UTF8, 203 "text/plain",
204 "text/plain", 204 "Spain",
205 "Spain", 205 strlen ("Spain") + 1,
206 strlen ("Spain") + 1, 206 0
207 0 207 },
208 }, 208 {
209 { 209 EXTRACTOR_METATYPE_KEYWORDS,
210 EXTRACTOR_METATYPE_KEYWORDS, 210 EXTRACTOR_METAFORMAT_UTF8,
211 EXTRACTOR_METAFORMAT_UTF8, 211 "text/plain",
212 "text/plain", 212 "Fuerteventura",
213 "Fuerteventura", 213 strlen ("Fuerteventura") + 1,
214 strlen ("Fuerteventura") + 1, 214 0
215 0 215 },
216 }, 216 {
217 { 217 EXTRACTOR_METATYPE_KEYWORDS,
218 EXTRACTOR_METATYPE_KEYWORDS, 218 EXTRACTOR_METAFORMAT_UTF8,
219 EXTRACTOR_METAFORMAT_UTF8, 219 "text/plain",
220 "text/plain", 220 "Landschaftsbild",
221 "Landschaftsbild", 221 strlen ("Landschaftsbild") + 1,
222 strlen ("Landschaftsbild") + 1, 222 0
223 0 223 },
224 }, 224 {
225 { 225 EXTRACTOR_METATYPE_KEYWORDS,
226 EXTRACTOR_METATYPE_KEYWORDS, 226 EXTRACTOR_METAFORMAT_UTF8,
227 EXTRACTOR_METAFORMAT_UTF8, 227 "text/plain",
228 "text/plain", 228 "ProCenter Rene Egli",
229 "ProCenter Rene Egli", 229 strlen ("ProCenter Rene Egli") + 1,
230 strlen ("ProCenter Rene Egli") + 1, 230 0
231 0 231 },
232 }, 232 {
233 { 233 EXTRACTOR_METATYPE_KEYWORDS,
234 EXTRACTOR_METATYPE_KEYWORDS, 234 EXTRACTOR_METAFORMAT_UTF8,
235 EXTRACTOR_METAFORMAT_UTF8, 235 "text/plain",
236 "text/plain", 236 "Sand",
237 "Sand", 237 strlen ("Sand") + 1,
238 strlen ("Sand") + 1, 238 0
239 0 239 },
240 }, 240 {
241 { 241 EXTRACTOR_METATYPE_KEYWORDS,
242 EXTRACTOR_METATYPE_KEYWORDS, 242 EXTRACTOR_METAFORMAT_UTF8,
243 EXTRACTOR_METAFORMAT_UTF8, 243 "text/plain",
244 "text/plain", 244 "Sport",
245 "Sport", 245 strlen ("Sport") + 1,
246 strlen ("Sport") + 1, 246 0
247 0 247 },
248 }, 248 {
249 { 249 EXTRACTOR_METATYPE_KEYWORDS,
250 EXTRACTOR_METATYPE_KEYWORDS, 250 EXTRACTOR_METAFORMAT_UTF8,
251 EXTRACTOR_METAFORMAT_UTF8, 251 "text/plain",
252 "text/plain", 252 "Urlaub",
253 "Urlaub", 253 strlen ("Urlaub") + 1,
254 strlen ("Urlaub") + 1, 254 0
255 0 255 },
256 }, 256 {
257 { 257 EXTRACTOR_METATYPE_KEYWORDS,
258 EXTRACTOR_METATYPE_KEYWORDS, 258 EXTRACTOR_METAFORMAT_UTF8,
259 EXTRACTOR_METAFORMAT_UTF8, 259 "text/plain",
260 "text/plain", 260 "Was?",
261 "Was?", 261 strlen ("Was?") + 1,
262 strlen ("Was?") + 1, 262 0
263 0 263 },
264 }, 264 {
265 { 265 EXTRACTOR_METATYPE_KEYWORDS,
266 EXTRACTOR_METATYPE_KEYWORDS, 266 EXTRACTOR_METAFORMAT_UTF8,
267 EXTRACTOR_METAFORMAT_UTF8, 267 "text/plain",
268 "text/plain", 268 "Wind",
269 "Wind", 269 strlen ("Wind") + 1,
270 strlen ("Wind") + 1, 270 0
271 0 271 },
272 }, 272 {
273 { 273 EXTRACTOR_METATYPE_KEYWORDS,
274 EXTRACTOR_METATYPE_KEYWORDS, 274 EXTRACTOR_METAFORMAT_UTF8,
275 EXTRACTOR_METAFORMAT_UTF8, 275 "text/plain",
276 "text/plain", 276 "Windsurfen",
277 "Windsurfen", 277 strlen ("Windsurfen") + 1,
278 strlen ("Windsurfen") + 1, 278 0
279 0 279 },
280 }, 280 {
281 { 281 EXTRACTOR_METATYPE_KEYWORDS,
282 EXTRACTOR_METATYPE_KEYWORDS, 282 EXTRACTOR_METAFORMAT_UTF8,
283 EXTRACTOR_METAFORMAT_UTF8, 283 "text/plain",
284 "text/plain", 284 "Wo?",
285 "Wo?", 285 strlen ("Wo?") + 1,
286 strlen ("Wo?") + 1, 286 0
287 0 287 },
288 }, 288 {
289 { 289 EXTRACTOR_METATYPE_RATING,
290 EXTRACTOR_METATYPE_RATING, 290 EXTRACTOR_METAFORMAT_UTF8,
291 EXTRACTOR_METAFORMAT_UTF8, 291 "text/plain",
292 "text/plain", 292 "3",
293 "3", 293 strlen ("3") + 1,
294 strlen ("3") + 1, 294 0
295 0 295 },
296 }, 296 {
297 { 297 EXTRACTOR_METATYPE_RATING,
298 EXTRACTOR_METATYPE_RATING, 298 EXTRACTOR_METAFORMAT_UTF8,
299 EXTRACTOR_METAFORMAT_UTF8, 299 "text/plain",
300 "text/plain", 300 "50",
301 "50", 301 strlen ("50") + 1,
302 strlen ("50") + 1, 302 0
303 0 303 },
304 }, 304 {
305 { 305 EXTRACTOR_METATYPE_LOCATION_COUNTRY_CODE,
306 EXTRACTOR_METATYPE_LOCATION_COUNTRY_CODE, 306 EXTRACTOR_METAFORMAT_UTF8,
307 EXTRACTOR_METAFORMAT_UTF8, 307 "text/plain",
308 "text/plain", 308 "ES",
309 "ES", 309 strlen ("ES") + 1,
310 strlen ("ES") + 1, 310 0
311 0 311 },
312 }, 312 {
313 { 313 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
314 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE, 314 EXTRACTOR_METAFORMAT_UTF8,
315 EXTRACTOR_METAFORMAT_UTF8, 315 "text/plain",
316 "text/plain", 316 "Optio W30 Ver 1.00",
317 "Optio W30 Ver 1.00", 317 strlen ("Optio W30 Ver 1.00") + 1,
318 strlen ("Optio W30 Ver 1.00") + 1, 318 0
319 0 319 },
320 }, 320 {
321 { 321 EXTRACTOR_METATYPE_SUBJECT,
322 EXTRACTOR_METATYPE_SUBJECT, 322 EXTRACTOR_METAFORMAT_UTF8,
323 EXTRACTOR_METAFORMAT_UTF8, 323 "text/plain",
324 "text/plain", 324 "Wo?, Wo?|Fuerteventura, Was?, Was?|Anlass]|Urlaub, Was?|Aufnahme]|Landschaftsbild, Was?|Natur]|Wind, Was?|Natur]|Sand, Wo?|Fuerteventura|ProCenter Rene Egli, Was?|Sport, Was?|Sport|Windsurfen",
325 "Wo?, Wo?|Fuerteventura, Was?, Was?|Anlass]|Urlaub, Was?|Aufnahme]|Landschaftsbild, Was?|Natur]|Wind, Was?|Natur]|Sand, Wo?|Fuerteventura|ProCenter Rene Egli, Was?|Sport, Was?|Sport|Windsurfen", 325 strlen (
326 strlen ("Wo?, Wo?|Fuerteventura, Was?, Was?|Anlass]|Urlaub, Was?|Aufnahme]|Landschaftsbild, Was?|Natur]|Wind, Was?|Natur]|Sand, Wo?|Fuerteventura|ProCenter Rene Egli, Was?|Sport, Was?|Sport|Windsurfen") + 1, 326 "Wo?, Wo?|Fuerteventura, Was?, Was?|Anlass]|Urlaub, Was?|Aufnahme]|Landschaftsbild, Was?|Natur]|Wind, Was?|Natur]|Sand, Wo?|Fuerteventura|ProCenter Rene Egli, Was?|Sport, Was?|Sport|Windsurfen")
327 0 327 + 1,
328 }, 328 0
329 { 0, 0, NULL, NULL, 0, -1 } 329 },
330 }; 330 { 0, 0, NULL, NULL, 0, -1 }
331 struct ProblemSet ps[] = 331 };
332 { 332 struct ProblemSet ps[] = {
333 { "testdata/exiv2_iptc.jpg", 333 { "testdata/exiv2_iptc.jpg",
334 exiv2_iptc_sol }, 334 exiv2_iptc_sol },
335 { NULL, NULL } 335 { NULL, NULL }
336 }; 336 };
337 return ET_main ("exiv2", ps); 337 return ET_main ("exiv2", ps);
338} 338}
339 339
340
340/* end of test_exiv2.c */ 341/* end of test_exiv2.c */
diff --git a/src/plugins/test_flac.c b/src/plugins/test_flac.c
index 1fa39f3..64a16b4 100644
--- a/src/plugins/test_flac.c
+++ b/src/plugins/test_flac.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the FLAC testcase. 30 * Main function for the FLAC testcase.
32 * 31 *
@@ -37,39 +36,37 @@
37int 36int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 struct SolutionData kraftwerk_sol[] = 39 struct SolutionData kraftwerk_sol[] = {
41 {
42 {
43 EXTRACTOR_METATYPE_RESOURCE_TYPE,
44 EXTRACTOR_METAFORMAT_UTF8,
45 "text/plain",
46 "44100 Hz, 2 channels",
47 strlen ("44100 Hz, 2 channels") + 1,
48 0
49 },
50 {
51 EXTRACTOR_METATYPE_TITLE,
52 EXTRACTOR_METAFORMAT_UTF8,
53 "text/plain",
54 "Test Title",
55 strlen ("Test Title") + 1,
56 0
57 },
58 { 0, 0, NULL, NULL, 0, -1 }
59 };
60 struct SolutionData alien_sol[] =
61 { 40 {
62 { 0, 0, NULL, NULL, 0, -1 } 41 EXTRACTOR_METATYPE_RESOURCE_TYPE,
63 }; 42 EXTRACTOR_METAFORMAT_UTF8,
64 struct ProblemSet ps[] = 43 "text/plain",
44 "44100 Hz, 2 channels",
45 strlen ("44100 Hz, 2 channels") + 1,
46 0
47 },
65 { 48 {
66 { "testdata/flac_kraftwerk.flac", 49 EXTRACTOR_METATYPE_TITLE,
67 kraftwerk_sol }, 50 EXTRACTOR_METAFORMAT_UTF8,
68 { "testdata/mpeg_alien.mpg", 51 "text/plain",
69 alien_sol }, 52 "Test Title",
70 { NULL, NULL } 53 strlen ("Test Title") + 1,
71 }; 54 0
55 },
56 { 0, 0, NULL, NULL, 0, -1 }
57 };
58 struct SolutionData alien_sol[] = {
59 { 0, 0, NULL, NULL, 0, -1 }
60 };
61 struct ProblemSet ps[] = {
62 { "testdata/flac_kraftwerk.flac",
63 kraftwerk_sol },
64 { "testdata/mpeg_alien.mpg",
65 alien_sol },
66 { NULL, NULL }
67 };
72 return ET_main ("flac", ps); 68 return ET_main ("flac", ps);
73} 69}
74 70
71
75/* end of test_flac.c */ 72/* end of test_flac.c */
diff --git a/src/plugins/test_gif.c b/src/plugins/test_gif.c
index e98f888..abe1e41 100644
--- a/src/plugins/test_gif.c
+++ b/src/plugins/test_gif.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the GIF testcase. 30 * Main function for the GIF testcase.
32 * 31 *
@@ -37,41 +36,40 @@
37int 36int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 struct SolutionData gif_image_sol[] = 39 struct SolutionData gif_image_sol[] = {
40 {
41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METAFORMAT_UTF8,
43 "text/plain",
44 "image/gif",
45 strlen ("image/gif") + 1,
46 0
47 },
41 { 48 {
42 { 49 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
43 EXTRACTOR_METATYPE_MIMETYPE, 50 EXTRACTOR_METAFORMAT_UTF8,
44 EXTRACTOR_METAFORMAT_UTF8, 51 "text/plain",
45 "text/plain", 52 "4x4",
46 "image/gif", 53 strlen ("4x4") + 1,
47 strlen ("image/gif") + 1, 54 0
48 0 55 },
49 },
50 {
51 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
52 EXTRACTOR_METAFORMAT_UTF8,
53 "text/plain",
54 "4x4",
55 strlen ("4x4") + 1,
56 0
57 },
58 {
59 EXTRACTOR_METATYPE_COMMENT,
60 EXTRACTOR_METAFORMAT_C_STRING,
61 "text/plain",
62 "Testing keyword extraction\n",
63 strlen ("Testing keyword extraction\n"),
64 0
65 },
66 { 0, 0, NULL, NULL, 0, -1 }
67 };
68 struct ProblemSet ps[] =
69 { 56 {
70 { "testdata/gif_image.gif", 57 EXTRACTOR_METATYPE_COMMENT,
71 gif_image_sol }, 58 EXTRACTOR_METAFORMAT_C_STRING,
72 { NULL, NULL } 59 "text/plain",
73 }; 60 "Testing keyword extraction\n",
61 strlen ("Testing keyword extraction\n"),
62 0
63 },
64 { 0, 0, NULL, NULL, 0, -1 }
65 };
66 struct ProblemSet ps[] = {
67 { "testdata/gif_image.gif",
68 gif_image_sol },
69 { NULL, NULL }
70 };
74 return ET_main ("gif", ps); 71 return ET_main ("gif", ps);
75} 72}
76 73
74
77/* end of test_gif.c */ 75/* end of test_gif.c */
diff --git a/src/plugins/test_gstreamer.c b/src/plugins/test_gstreamer.c
index 0f3d9ca..0210e54 100644
--- a/src/plugins/test_gstreamer.c
+++ b/src/plugins/test_gstreamer.c
@@ -42,67 +42,69 @@ discoverer_main (GstDiscoverer *dc, const char *filename)
42 GstDiscovererInfo *info; 42 GstDiscovererInfo *info;
43 GstDiscovererResult result; 43 GstDiscovererResult result;
44 44
45 if (! gst_uri_is_valid (filename)) 45 if (! gst_uri_is_valid (filename))
46 {
47 if (! g_path_is_absolute (filename))
46 { 48 {
47 if (! g_path_is_absolute (filename)) 49 gchar *cur_dir;
48 { 50
49 gchar *cur_dir; 51 cur_dir = g_get_current_dir ();
50 52 path = g_build_filename (cur_dir, filename, NULL);
51 cur_dir = g_get_current_dir (); 53 g_free (cur_dir);
52 path = g_build_filename (cur_dir, filename, NULL);
53 g_free (cur_dir);
54 }
55 else
56 {
57 path = g_strdup (filename);
58 }
59
60 uri = g_filename_to_uri (path, NULL, &err);
61 g_free (path);
62 path = NULL;
63
64 if (err)
65 {
66 g_warning ("Couldn't convert filename %s to URI: %s\n", filename, err->message);
67 g_error_free (err);
68 return GST_DISCOVERER_ERROR;
69 }
70 } 54 }
71 else 55 else
72 { 56 {
73 uri = g_strdup (filename); 57 path = g_strdup (filename);
74 } 58 }
75 info = gst_discoverer_discover_uri (dc, uri, &err); 59
76 result = gst_discoverer_info_get_result (info); 60 uri = g_filename_to_uri (path, NULL, &err);
77 switch (result) 61 g_free (path);
62 path = NULL;
63
64 if (err)
78 { 65 {
79 case GST_DISCOVERER_OK: 66 g_warning ("Couldn't convert filename %s to URI: %s\n", filename,
80 break; 67 err->message);
81 case GST_DISCOVERER_URI_INVALID: 68 g_error_free (err);
82 g_print ("URI %s is not valid\n", uri); 69 return GST_DISCOVERER_ERROR;
83 break; 70 }
84 case GST_DISCOVERER_ERROR: 71 }
85 g_print ("An error was encountered while discovering the file %s\n", filename); 72 else
86 g_print (" %s\n", err->message); 73 {
87 break; 74 uri = g_strdup (filename);
88 case GST_DISCOVERER_TIMEOUT: 75 }
89 g_print ("Analyzing URI %s timed out\n", uri); 76 info = gst_discoverer_discover_uri (dc, uri, &err);
90 break; 77 result = gst_discoverer_info_get_result (info);
91 case GST_DISCOVERER_BUSY: 78 switch (result)
92 g_print ("Discoverer was busy\n"); 79 {
93 break; 80 case GST_DISCOVERER_OK:
94 case GST_DISCOVERER_MISSING_PLUGINS: 81 break;
95 g_print ("Will skip %s: missing plugins\n", filename); 82 case GST_DISCOVERER_URI_INVALID:
96 break; 83 g_print ("URI %s is not valid\n", uri);
97 default: 84 break;
98 g_print ("Unexpected result %d\n", result); 85 case GST_DISCOVERER_ERROR:
99 break; 86 g_print ("An error was encountered while discovering the file %s\n",
100 } 87 filename);
88 g_print (" %s\n", err->message);
89 break;
90 case GST_DISCOVERER_TIMEOUT:
91 g_print ("Analyzing URI %s timed out\n", uri);
92 break;
93 case GST_DISCOVERER_BUSY:
94 g_print ("Discoverer was busy\n");
95 break;
96 case GST_DISCOVERER_MISSING_PLUGINS:
97 g_print ("Will skip %s: missing plugins\n", filename);
98 break;
99 default:
100 g_print ("Unexpected result %d\n", result);
101 break;
102 }
101 if (err) 103 if (err)
102 g_error_free (err); 104 g_error_free (err);
103 gst_discoverer_info_unref (info); 105 gst_discoverer_info_unref (info);
104 g_free (uri); 106 g_free (uri);
105 107
106 return result; 108 return result;
107} 109}
108 110
@@ -124,11 +126,11 @@ main (int argc, char *argv[])
124 126
125 gst_init (&argc, &argv); 127 gst_init (&argc, &argv);
126 dc = gst_discoverer_new (10 * GST_SECOND, &err); 128 dc = gst_discoverer_new (10 * GST_SECOND, &err);
127 if (NULL == dc) 129 if (NULL == dc)
128 { 130 {
129 g_print ("Error initializing: %s\n", err->message); 131 g_print ("Error initializing: %s\n", err->message);
130 return 0; 132 return 0;
131 } 133 }
132 if (NULL != err) 134 if (NULL != err)
133 g_error_free (err); 135 g_error_free (err);
134 136
@@ -136,171 +138,170 @@ main (int argc, char *argv[])
136 if (GST_DISCOVERER_MISSING_PLUGINS != pre_test) 138 if (GST_DISCOVERER_MISSING_PLUGINS != pre_test)
137 { 139 {
138 int test_result; 140 int test_result;
139 struct SolutionData thirty_and_thirtythree_sol[] = 141 struct SolutionData thirty_and_thirtythree_sol[] = {
140 { 142 {
141 { 143 EXTRACTOR_METATYPE_DURATION,
142 EXTRACTOR_METATYPE_DURATION, 144 EXTRACTOR_METAFORMAT_UTF8,
143 EXTRACTOR_METAFORMAT_UTF8, 145 "text/plain",
144 "text/plain", 146 "0:00:05.061000000",
145 "0:00:05.061000000", 147 strlen ("0:00:05.061000000") + 1,
146 strlen ("0:00:05.061000000") + 1, 148 0
147 0 149 },
148 }, 150 {
149 { 151 EXTRACTOR_METATYPE_TRACK_NUMBER,
150 EXTRACTOR_METATYPE_TRACK_NUMBER, 152 EXTRACTOR_METAFORMAT_UTF8,
151 EXTRACTOR_METAFORMAT_UTF8, 153 "text/plain",
152 "text/plain", 154 "21",
153 "21", 155 strlen ("21") + 1,
154 strlen ("21") + 1, 156 0
155 0 157 },
156 }, 158 {
157 { 159 EXTRACTOR_METATYPE_ALBUM,
158 EXTRACTOR_METATYPE_ALBUM, 160 EXTRACTOR_METAFORMAT_UTF8,
159 EXTRACTOR_METAFORMAT_UTF8, 161 "text/plain",
160 "text/plain", 162 "Zee Album",
161 "Zee Album", 163 strlen ("Zee Album") + 1,
162 strlen ("Zee Album") + 1, 164 0
163 0 165 },
164 }, 166 {
165 { 167 EXTRACTOR_METATYPE_CREATION_TIME,
166 EXTRACTOR_METATYPE_CREATION_TIME, 168 EXTRACTOR_METAFORMAT_UTF8,
167 EXTRACTOR_METAFORMAT_UTF8, 169 "text/plain",
168 "text/plain", 170 "9999",
169 "9999", 171 strlen ("9999") + 1,
170 strlen ("9999") + 1, 172 0
171 0 173 },
172 }, 174 {
173 { 175 EXTRACTOR_METATYPE_ARTIST,
174 EXTRACTOR_METATYPE_ARTIST, 176 EXTRACTOR_METAFORMAT_UTF8,
175 EXTRACTOR_METAFORMAT_UTF8, 177 "text/plain",
176 "text/plain", 178 "All performed by Nobody",
177 "All performed by Nobody", 179 strlen ("All performed by Nobody") + 1,
178 strlen ("All performed by Nobody") + 1, 180 0
179 0 181 },
180 }, 182 {
181 { 183 EXTRACTOR_METATYPE_ARTIST,
182 EXTRACTOR_METATYPE_ARTIST, 184 EXTRACTOR_METAFORMAT_UTF8,
183 EXTRACTOR_METAFORMAT_UTF8, 185 "text/plain",
184 "text/plain", 186 "This Artist Contributed",
185 "This Artist Contributed", 187 strlen ("This Artist Contributed") + 1,
186 strlen ("This Artist Contributed") + 1, 188 0
187 0 189 },
188 }, 190 {
189 { 191 EXTRACTOR_METATYPE_TITLE,
190 EXTRACTOR_METATYPE_TITLE, 192 EXTRACTOR_METAFORMAT_UTF8,
191 EXTRACTOR_METAFORMAT_UTF8, 193 "text/plain",
192 "text/plain", 194 "Some title",
193 "Some title", 195 strlen ("Some title") + 1,
194 strlen ("Some title") + 1, 196 0
195 0 197 },
196 }, 198 /* Suggest a fix to gst devs; should be a comment, not description */
197 /* Suggest a fix to gst devs; should be a comment, not description */ 199 {
198 { 200 EXTRACTOR_METATYPE_DESCRIPTION,
199 EXTRACTOR_METATYPE_DESCRIPTION, 201 EXTRACTOR_METAFORMAT_UTF8,
200 EXTRACTOR_METAFORMAT_UTF8, 202 "text/plain",
201 "text/plain", 203 "A witty comment",
202 "A witty comment", 204 strlen ("A witty comment") + 1,
203 strlen ("A witty comment") + 1, 205 0
204 0 206 },
205 }, 207 {
206 { 208 EXTRACTOR_METATYPE_CONTAINER_FORMAT,
207 EXTRACTOR_METATYPE_CONTAINER_FORMAT, 209 EXTRACTOR_METAFORMAT_UTF8,
208 EXTRACTOR_METAFORMAT_UTF8, 210 "text/plain",
209 "text/plain", 211 "ASF",
210 "ASF", 212 strlen ("ASF") + 1,
211 strlen ("ASF") + 1, 213 0
212 0 214 },
213 }, 215 {
214 { 216 EXTRACTOR_METATYPE_AUDIO_CODEC,
215 EXTRACTOR_METATYPE_AUDIO_CODEC, 217 EXTRACTOR_METAFORMAT_UTF8,
216 EXTRACTOR_METAFORMAT_UTF8, 218 "text/plain",
217 "text/plain", 219 "WMA Version 8",
218 "WMA Version 8", 220 strlen ("WMA Version 8") + 1,
219 strlen ("WMA Version 8") + 1, 221 0
220 0 222 },
221 }, 223 {
222 { 224 EXTRACTOR_METATYPE_MIMETYPE,
223 EXTRACTOR_METATYPE_MIMETYPE, 225 EXTRACTOR_METAFORMAT_UTF8,
224 EXTRACTOR_METAFORMAT_UTF8, 226 "text/plain",
225 "text/plain", 227 "video/x-ms-asf",
226 "video/x-ms-asf", 228 strlen ("video/x-ms-asf") + 1,
227 strlen ("video/x-ms-asf") + 1, 229 0
228 0 230 },
229 }, 231 {
230 { 232 EXTRACTOR_METATYPE_MIMETYPE,
231 EXTRACTOR_METATYPE_MIMETYPE, 233 EXTRACTOR_METAFORMAT_UTF8,
232 EXTRACTOR_METAFORMAT_UTF8, 234 "text/plain",
233 "text/plain", 235 "audio/x-wma",
234 "audio/x-wma", 236 strlen ("audio/x-wma") + 1,
235 strlen ("audio/x-wma") + 1, 237 0
236 0 238 },
237 }, 239 {
238 { 240 EXTRACTOR_METATYPE_UNKNOWN,
239 EXTRACTOR_METATYPE_UNKNOWN, 241 EXTRACTOR_METAFORMAT_UTF8,
240 EXTRACTOR_METAFORMAT_UTF8, 242 "text/plain",
241 "text/plain", 243 "wmaversion=2",
242 "wmaversion=2", 244 strlen ("wmaversion=2") + 1,
243 strlen ("wmaversion=2") + 1, 245 0
244 0 246 },
245 }, 247 {
246 { 248 EXTRACTOR_METATYPE_UNKNOWN,
247 EXTRACTOR_METATYPE_UNKNOWN, 249 EXTRACTOR_METAFORMAT_UTF8,
248 EXTRACTOR_METAFORMAT_UTF8, 250 "text/plain",
249 "text/plain", 251 "bitrate=96024",
250 "bitrate=96024", 252 strlen ("bitrate=96024") + 1,
251 strlen ("bitrate=96024") + 1, 253 0
252 0 254 },
253 }, 255 {
254 { 256 EXTRACTOR_METATYPE_UNKNOWN,
255 EXTRACTOR_METATYPE_UNKNOWN, 257 EXTRACTOR_METAFORMAT_UTF8,
256 EXTRACTOR_METAFORMAT_UTF8, 258 "text/plain",
257 "text/plain", 259 "block_align=4459",
258 "block_align=4459", 260 strlen ("block_align=4459") + 1,
259 strlen ("block_align=4459") + 1, 261 0
260 0 262 },
261 }, 263 {
262 { 264 EXTRACTOR_METATYPE_AUDIO_LANGUAGE,
263 EXTRACTOR_METATYPE_AUDIO_LANGUAGE, 265 EXTRACTOR_METAFORMAT_UTF8,
264 EXTRACTOR_METAFORMAT_UTF8, 266 "text/plain",
265 "text/plain", 267 "en",
266 "en", 268 strlen ("en") + 1,
267 strlen ("en") + 1, 269 0
268 0 270 },
269 }, 271 {
270 { 272 EXTRACTOR_METATYPE_CHANNELS,
271 EXTRACTOR_METATYPE_CHANNELS, 273 EXTRACTOR_METAFORMAT_UTF8,
272 EXTRACTOR_METAFORMAT_UTF8, 274 "text/plain",
273 "text/plain", 275 "2",
274 "2", 276 strlen ("2") + 1,
275 strlen ("2") + 1, 277 0
276 0 278 },
277 }, 279 {
278 { 280 EXTRACTOR_METATYPE_SAMPLE_RATE,
279 EXTRACTOR_METATYPE_SAMPLE_RATE, 281 EXTRACTOR_METAFORMAT_UTF8,
280 EXTRACTOR_METAFORMAT_UTF8, 282 "text/plain",
281 "text/plain", 283 "44100",
282 "44100", 284 strlen ("44100") + 1,
283 strlen ("44100") + 1, 285 0
284 0 286 },
285 }, 287 {
286 { 288 EXTRACTOR_METATYPE_AUDIO_DEPTH,
287 EXTRACTOR_METATYPE_AUDIO_DEPTH, 289 EXTRACTOR_METAFORMAT_UTF8,
288 EXTRACTOR_METAFORMAT_UTF8, 290 "text/plain",
289 "text/plain", 291 "16",
290 "16", 292 strlen ("16") + 1,
291 strlen ("16") + 1, 293 0
292 0 294 },
293 }, 295 { 0, 0, NULL, NULL, 0, -1 }
294 { 0, 0, NULL, NULL, 0, -1 } 296 };
295 }; 297 struct ProblemSet ps[] = {
296 struct ProblemSet ps[] = 298 { "testdata/gstreamer_30_and_33.asf", thirty_and_thirtythree_sol },
297 { 299 { NULL, NULL }
298 { "testdata/gstreamer_30_and_33.asf", thirty_and_thirtythree_sol }, 300 };
299 { NULL, NULL }
300 };
301 g_print ("Running asf test on GStreamer:\n"); 301 g_print ("Running asf test on GStreamer:\n");
302 test_result = (0 == ET_main ("gstreamer", ps) ? 0 : 1); 302 test_result = (0 == ET_main ("gstreamer", ps) ? 0 : 1);
303 g_print ("asf GStreamer test result: %s\n", test_result == 0 ? "OK" : "FAILED"); 303 g_print ("asf GStreamer test result: %s\n", test_result == 0 ? "OK" :
304 "FAILED");
304 result += test_result; 305 result += test_result;
305 } 306 }
306 307
@@ -308,401 +309,399 @@ main (int argc, char *argv[])
308 if (pre_test != GST_DISCOVERER_MISSING_PLUGINS) 309 if (pre_test != GST_DISCOVERER_MISSING_PLUGINS)
309 { 310 {
310 int test_result; 311 int test_result;
311 struct SolutionData barsandtone_sol[] = 312 struct SolutionData barsandtone_sol[] = {
312 { 313 {
313 { 314 EXTRACTOR_METATYPE_DURATION,
314 EXTRACTOR_METATYPE_DURATION, 315 EXTRACTOR_METAFORMAT_UTF8,
315 EXTRACTOR_METAFORMAT_UTF8, 316 "text/plain",
316 "text/plain", 317 "0:00:06.060000000",
317 "0:00:06.060000000", 318 strlen ("0:00:06.060000000") + 1,
318 strlen ("0:00:06.060000000") + 1, 319 0
319 0 320 },
320 }, 321 {
321 { 322 EXTRACTOR_METATYPE_MIMETYPE,
322 EXTRACTOR_METATYPE_MIMETYPE, 323 EXTRACTOR_METAFORMAT_UTF8,
323 EXTRACTOR_METAFORMAT_UTF8, 324 "text/plain",
324 "text/plain", 325 "video/x-flv",
325 "video/x-flv", 326 strlen ("video/x-flv") + 1,
326 strlen ("video/x-flv") + 1, 327 0
327 0 328 },
328 }, 329 {
329 { 330 EXTRACTOR_METATYPE_MIMETYPE,
330 EXTRACTOR_METATYPE_MIMETYPE, 331 EXTRACTOR_METAFORMAT_UTF8,
331 EXTRACTOR_METAFORMAT_UTF8, 332 "text/plain",
332 "text/plain", 333 "video/x-vp6-flash",
333 "video/x-vp6-flash", 334 strlen ("video/x-vp6-flash") + 1,
334 strlen ("video/x-vp6-flash") + 1, 335 0
335 0 336 },
336 }, 337 {
337 { 338 EXTRACTOR_METATYPE_VIDEO_DURATION,
338 EXTRACTOR_METATYPE_VIDEO_DURATION, 339 EXTRACTOR_METAFORMAT_UTF8,
339 EXTRACTOR_METAFORMAT_UTF8, 340 "text/plain",
340 "text/plain", 341 "0:00:06.000000000",
341 "0:00:06.000000000", 342 strlen ("0:00:06.000000000") + 1,
342 strlen ("0:00:06.000000000") + 1, 343 0
343 0 344 },
344 }, 345 {
345 { 346 EXTRACTOR_METATYPE_AUDIO_CODEC,
346 EXTRACTOR_METATYPE_AUDIO_CODEC, 347 EXTRACTOR_METAFORMAT_UTF8,
347 EXTRACTOR_METAFORMAT_UTF8, 348 "text/plain",
348 "text/plain", 349 "MPEG-1 Layer 3 (MP3)",
349 "MPEG-1 Layer 3 (MP3)", 350 strlen ("MPEG-1 Layer 3 (MP3)") + 1,
350 strlen ("MPEG-1 Layer 3 (MP3)") + 1, 351 0
351 0 352 },
352 }, 353 {
353 { 354 EXTRACTOR_METATYPE_VIDEO_CODEC,
354 EXTRACTOR_METATYPE_VIDEO_CODEC, 355 EXTRACTOR_METAFORMAT_UTF8,
355 EXTRACTOR_METAFORMAT_UTF8, 356 "text/plain",
356 "text/plain", 357 "On2 VP6/Flash",
357 "On2 VP6/Flash", 358 strlen ("On2 VP6/Flash") + 1,
358 strlen ("On2 VP6/Flash") + 1, 359 0
359 0 360 },
360 }, 361 {
361 { 362 EXTRACTOR_METATYPE_VIDEO_DIMENSIONS,
362 EXTRACTOR_METATYPE_VIDEO_DIMENSIONS, 363 EXTRACTOR_METAFORMAT_UTF8,
363 EXTRACTOR_METAFORMAT_UTF8, 364 "text/plain",
364 "text/plain", 365 "368x288",
365 "368x288", 366 strlen ("368x288") + 1,
366 strlen ("368x288") + 1, 367 0
367 0 368 },
368 }, 369 {
369 { 370 EXTRACTOR_METATYPE_FRAME_RATE,
370 EXTRACTOR_METATYPE_FRAME_RATE, 371 EXTRACTOR_METAFORMAT_UTF8,
371 EXTRACTOR_METAFORMAT_UTF8, 372 "text/plain",
372 "text/plain", 373 "10/1",
373 "10/1", 374 strlen ("10/1") + 1,
374 strlen ("10/1") + 1, 375 0
375 0 376 },
376 }, 377 {
377 { 378 EXTRACTOR_METATYPE_PIXEL_ASPECT_RATIO,
378 EXTRACTOR_METATYPE_PIXEL_ASPECT_RATIO, 379 EXTRACTOR_METAFORMAT_UTF8,
379 EXTRACTOR_METAFORMAT_UTF8, 380 "text/plain",
380 "text/plain", 381 "1/1",
381 "1/1", 382 strlen ("1/1") + 1,
382 strlen ("1/1") + 1, 383 0
383 0 384 },
384 }, 385 {
385 { 386 EXTRACTOR_METATYPE_MIMETYPE,
386 EXTRACTOR_METATYPE_MIMETYPE, 387 EXTRACTOR_METAFORMAT_UTF8,
387 EXTRACTOR_METAFORMAT_UTF8, 388 "text/plain",
388 "text/plain", 389 "audio/mpeg",
389 "audio/mpeg", 390 strlen ("audio/mpeg") + 1,
390 strlen ("audio/mpeg") + 1, 391 0
391 0 392 },
392 }, 393 {
393 { 394 EXTRACTOR_METATYPE_UNKNOWN,
394 EXTRACTOR_METATYPE_UNKNOWN, 395 EXTRACTOR_METAFORMAT_UTF8,
395 EXTRACTOR_METAFORMAT_UTF8, 396 "text/plain",
396 "text/plain", 397 "mpegversion=1",
397 "mpegversion=1", 398 strlen ("mpegversion=1") + 1,
398 strlen ("mpegversion=1") + 1, 399 0
399 0 400 },
400 }, 401 {
401 { 402 EXTRACTOR_METATYPE_UNKNOWN,
402 EXTRACTOR_METATYPE_UNKNOWN, 403 EXTRACTOR_METAFORMAT_UTF8,
403 EXTRACTOR_METAFORMAT_UTF8, 404 "text/plain",
404 "text/plain", 405 "mpegaudioversion=1",
405 "mpegaudioversion=1", 406 strlen ("mpegaudioversion=1") + 1,
406 strlen ("mpegaudioversion=1") + 1, 407 0
407 0 408 },
408 }, 409 {
409 { 410 EXTRACTOR_METATYPE_UNKNOWN,
410 EXTRACTOR_METATYPE_UNKNOWN, 411 EXTRACTOR_METAFORMAT_UTF8,
411 EXTRACTOR_METAFORMAT_UTF8, 412 "text/plain",
412 "text/plain", 413 "layer=3",
413 "layer=3", 414 strlen ("layer=3") + 1,
414 strlen ("layer=3") + 1, 415 0
415 0 416 },
416 }, 417 {
417 { 418 EXTRACTOR_METATYPE_UNKNOWN,
418 EXTRACTOR_METATYPE_UNKNOWN, 419 EXTRACTOR_METAFORMAT_UTF8,
419 EXTRACTOR_METAFORMAT_UTF8, 420 "text/plain",
420 "text/plain", 421 "parsed=true",
421 "parsed=true", 422 strlen ("parsed=true") + 1,
422 strlen ("parsed=true") + 1, 423 0
423 0 424 },
424 }, 425 {
425 { 426 EXTRACTOR_METATYPE_AUDIO_DURATION,
426 EXTRACTOR_METATYPE_AUDIO_DURATION, 427 EXTRACTOR_METAFORMAT_UTF8,
427 EXTRACTOR_METAFORMAT_UTF8, 428 "text/plain",
428 "text/plain", 429 "0:00:06.000000000",
429 "0:00:06.000000000", 430 strlen ("0:00:06.000000000") + 1,
430 strlen ("0:00:06.000000000") + 1, 431 0
431 0 432 },
432 }, 433 /* Yes, again. This seems to be a bug/feature of the element that
433 /* Yes, again. This seems to be a bug/feature of the element that 434 * gives us these streams; this doesn't happen when discovering
434 * gives us these streams; this doesn't happen when discovering 435 * Matroska files, for example. Or maybe file itself is made that way.
435 * Matroska files, for example. Or maybe file itself is made that way. 436 */
436 */ 437 {
437 { 438 EXTRACTOR_METATYPE_AUDIO_CODEC,
438 EXTRACTOR_METATYPE_AUDIO_CODEC, 439 EXTRACTOR_METAFORMAT_UTF8,
439 EXTRACTOR_METAFORMAT_UTF8, 440 "text/plain",
440 "text/plain", 441 "MPEG-1 Layer 3 (MP3)",
441 "MPEG-1 Layer 3 (MP3)", 442 strlen ("MPEG-1 Layer 3 (MP3)") + 1,
442 strlen ("MPEG-1 Layer 3 (MP3)") + 1, 443 0
443 0 444 },
444 }, 445 {
445 { 446 EXTRACTOR_METATYPE_VIDEO_CODEC,
446 EXTRACTOR_METATYPE_VIDEO_CODEC, 447 EXTRACTOR_METAFORMAT_UTF8,
447 EXTRACTOR_METAFORMAT_UTF8, 448 "text/plain",
448 "text/plain", 449 "On2 VP6/Flash",
449 "On2 VP6/Flash", 450 strlen ("On2 VP6/Flash") + 1,
450 strlen ("On2 VP6/Flash") + 1, 451 0
451 0 452 },
452 }, 453 {
453 { 454 EXTRACTOR_METATYPE_UNKNOWN,
454 EXTRACTOR_METATYPE_UNKNOWN, 455 EXTRACTOR_METAFORMAT_UTF8,
455 EXTRACTOR_METAFORMAT_UTF8, 456 "text/plain",
456 "text/plain", 457 "has-crc=false",
457 "has-crc=false", 458 strlen ("has-crc=false") + 1,
458 strlen ("has-crc=false") + 1, 459 0
459 0 460 },
460 }, 461 {
461 { 462 EXTRACTOR_METATYPE_UNKNOWN,
462 EXTRACTOR_METATYPE_UNKNOWN, 463 EXTRACTOR_METAFORMAT_UTF8,
463 EXTRACTOR_METAFORMAT_UTF8, 464 "text/plain",
464 "text/plain", 465 "channel-mode=joint-stereo",
465 "channel-mode=joint-stereo", 466 strlen ("channel-mode=joint-stereo") + 1,
466 strlen ("channel-mode=joint-stereo") + 1, 467 0
467 0 468 },
468 }, 469 {
469 { 470 EXTRACTOR_METATYPE_CHANNELS,
470 EXTRACTOR_METATYPE_CHANNELS, 471 EXTRACTOR_METAFORMAT_UTF8,
471 EXTRACTOR_METAFORMAT_UTF8, 472 "text/plain",
472 "text/plain", 473 "2",
473 "2", 474 strlen ("2") + 1,
474 strlen ("2") + 1, 475 0
475 0 476 },
476 }, 477 {
477 { 478 EXTRACTOR_METATYPE_SAMPLE_RATE,
478 EXTRACTOR_METATYPE_SAMPLE_RATE, 479 EXTRACTOR_METAFORMAT_UTF8,
479 EXTRACTOR_METAFORMAT_UTF8, 480 "text/plain",
480 "text/plain", 481 "44100",
481 "44100", 482 strlen ("44100") + 1,
482 strlen ("44100") + 1, 483 0
483 0 484 },
484 }, 485 {
485 { 486 EXTRACTOR_METATYPE_AUDIO_BITRATE,
486 EXTRACTOR_METATYPE_AUDIO_BITRATE, 487 EXTRACTOR_METAFORMAT_UTF8,
487 EXTRACTOR_METAFORMAT_UTF8, 488 "text/plain",
488 "text/plain", 489 "96000",
489 "96000", 490 strlen ("96000") + 1,
490 strlen ("96000") + 1, 491 0
491 0 492 },
492 }, 493 { 0, 0, NULL, NULL, 0, -1 }
493 { 0, 0, NULL, NULL, 0, -1 } 494 };
494 }; 495 struct ProblemSet ps[] = {
495 struct ProblemSet ps[] = 496 { "testdata/gstreamer_barsandtone.flv", barsandtone_sol },
496 { 497 { NULL, NULL }
497 { "testdata/gstreamer_barsandtone.flv", barsandtone_sol }, 498 };
498 { NULL, NULL }
499 };
500 g_print ("Running flv test on GStreamer:\n"); 499 g_print ("Running flv test on GStreamer:\n");
501 test_result = (0 == ET_main ("gstreamer", ps) ? 0 : 1); 500 test_result = (0 == ET_main ("gstreamer", ps) ? 0 : 1);
502 g_print ("flv GStreamer test result: %s\n", test_result == 0 ? "OK" : "FAILED"); 501 g_print ("flv GStreamer test result: %s\n", test_result == 0 ? "OK" :
502 "FAILED");
503 result += test_result; 503 result += test_result;
504 } 504 }
505 pre_test = discoverer_main (dc, "testdata/gstreamer_sample_sorenson.mov"); 505 pre_test = discoverer_main (dc, "testdata/gstreamer_sample_sorenson.mov");
506 if (pre_test != GST_DISCOVERER_MISSING_PLUGINS) 506 if (pre_test != GST_DISCOVERER_MISSING_PLUGINS)
507 { 507 {
508 int test_result; 508 int test_result;
509 struct SolutionData sample_sorenson_sol[] = 509 struct SolutionData sample_sorenson_sol[] = {
510 { 510 {
511 { 511 EXTRACTOR_METATYPE_DURATION,
512 EXTRACTOR_METATYPE_DURATION, 512 EXTRACTOR_METAFORMAT_UTF8,
513 EXTRACTOR_METAFORMAT_UTF8, 513 "text/plain",
514 "text/plain", 514 "0:00:05.000000000",
515 "0:00:05.000000000", 515 strlen ("0:00:05.000000000") + 1,
516 strlen ("0:00:05.000000000") + 1, 516 0
517 0 517 },
518 }, 518 {
519 { 519 EXTRACTOR_METATYPE_MIMETYPE,
520 EXTRACTOR_METATYPE_MIMETYPE, 520 EXTRACTOR_METAFORMAT_UTF8,
521 EXTRACTOR_METAFORMAT_UTF8, 521 "text/plain",
522 "text/plain", 522 "video/quicktime",
523 "video/quicktime", 523 strlen ("video/quicktime") + 1,
524 strlen ("video/quicktime") + 1, 524 0
525 0 525 },
526 }, 526 {
527 { 527 EXTRACTOR_METATYPE_MIMETYPE,
528 EXTRACTOR_METATYPE_MIMETYPE, 528 EXTRACTOR_METAFORMAT_UTF8,
529 EXTRACTOR_METAFORMAT_UTF8, 529 "text/plain",
530 "text/plain", 530 "audio/x-qdm2",
531 "audio/x-qdm2", 531 strlen ("audio/x-qdm2") + 1,
532 strlen ("audio/x-qdm2") + 1, 532 0
533 0 533 },
534 }, 534 {
535 { 535 EXTRACTOR_METATYPE_UNKNOWN,
536 EXTRACTOR_METATYPE_UNKNOWN, 536 EXTRACTOR_METAFORMAT_UTF8,
537 EXTRACTOR_METAFORMAT_UTF8, 537 "text/plain",
538 "text/plain", 538 "samplesize=16",
539 "samplesize=16", 539 strlen ("samplesize=16") + 1,
540 strlen ("samplesize=16") + 1, 540 0
541 0 541 },
542 }, 542 {
543 { 543 EXTRACTOR_METATYPE_AUDIO_CODEC,
544 EXTRACTOR_METATYPE_AUDIO_CODEC, 544 EXTRACTOR_METAFORMAT_UTF8,
545 EXTRACTOR_METAFORMAT_UTF8, 545 "text/plain",
546 "text/plain", 546 "QDesign Music v.2",
547 "QDesign Music v.2", 547 strlen ("QDesign Music v.2") + 1,
548 strlen ("QDesign Music v.2") + 1, 548 0
549 0 549 },
550 }, 550 {
551 { 551 EXTRACTOR_METATYPE_CREATION_TIME,
552 EXTRACTOR_METATYPE_CREATION_TIME, 552 EXTRACTOR_METAFORMAT_UTF8,
553 EXTRACTOR_METAFORMAT_UTF8, 553 "text/plain",
554 "text/plain", 554 "2001-02-19T16:45:54Z",
555 "2001-02-19T16:45:54Z", 555 strlen ("2001-02-19T16:45:54Z") + 1,
556 strlen ("2001-02-19T16:45:54Z") + 1, 556 0
557 0 557 },
558 }, 558 {
559 { 559 EXTRACTOR_METATYPE_TITLE,
560 EXTRACTOR_METATYPE_TITLE, 560 EXTRACTOR_METAFORMAT_UTF8,
561 EXTRACTOR_METAFORMAT_UTF8, 561 "text/plain",
562 "text/plain", 562 "QuickTime Sample Movie",
563 "QuickTime Sample Movie", 563 strlen ("QuickTime Sample Movie") + 1,
564 strlen ("QuickTime Sample Movie") + 1, 564 0
565 0 565 },
566 }, 566 {
567 { 567 EXTRACTOR_METATYPE_COPYRIGHT,
568 EXTRACTOR_METATYPE_COPYRIGHT, 568 EXTRACTOR_METAFORMAT_UTF8,
569 EXTRACTOR_METAFORMAT_UTF8, 569 "text/plain",
570 "text/plain", 570 "© Apple Computer, Inc. 2001",
571 "© Apple Computer, Inc. 2001", 571 strlen ("© Apple Computer, Inc. 2001") + 1,
572 strlen ("© Apple Computer, Inc. 2001") + 1, 572 0
573 0 573 },
574 }, 574 {
575 { 575 EXTRACTOR_METATYPE_CONTAINER_FORMAT,
576 EXTRACTOR_METATYPE_CONTAINER_FORMAT, 576 EXTRACTOR_METAFORMAT_UTF8,
577 EXTRACTOR_METAFORMAT_UTF8, 577 "text/plain",
578 "text/plain", 578 "ISO MP4/M4A",
579 "ISO MP4/M4A", 579 strlen ("ISO MP4/M4A") + 1,
580 strlen ("ISO MP4/M4A") + 1, 580 0
581 0 581 },
582 }, 582 {
583 { 583 EXTRACTOR_METATYPE_AUDIO_LANGUAGE,
584 EXTRACTOR_METATYPE_AUDIO_LANGUAGE, 584 EXTRACTOR_METAFORMAT_UTF8,
585 EXTRACTOR_METAFORMAT_UTF8, 585 "text/plain",
586 "text/plain", 586 "en",
587 "en", 587 strlen ("en") + 1,
588 strlen ("en") + 1, 588 0
589 0 589 },
590 }, 590 {
591 { 591 EXTRACTOR_METATYPE_CHANNELS,
592 EXTRACTOR_METATYPE_CHANNELS, 592 EXTRACTOR_METAFORMAT_UTF8,
593 EXTRACTOR_METAFORMAT_UTF8, 593 "text/plain",
594 "text/plain", 594 "2",
595 "2", 595 strlen ("2") + 1,
596 strlen ("2") + 1, 596 0
597 0 597 },
598 }, 598 {
599 { 599 EXTRACTOR_METATYPE_SAMPLE_RATE,
600 EXTRACTOR_METATYPE_SAMPLE_RATE, 600 EXTRACTOR_METAFORMAT_UTF8,
601 EXTRACTOR_METAFORMAT_UTF8, 601 "text/plain",
602 "text/plain", 602 "22050",
603 "22050", 603 strlen ("22050") + 1,
604 strlen ("22050") + 1, 604 0
605 0 605 },
606 }, 606 {
607 { 607 EXTRACTOR_METATYPE_MIMETYPE,
608 EXTRACTOR_METATYPE_MIMETYPE, 608 EXTRACTOR_METAFORMAT_UTF8,
609 EXTRACTOR_METAFORMAT_UTF8, 609 "text/plain",
610 "text/plain", 610 "video/x-svq",
611 "video/x-svq", 611 strlen ("video/x-svq") + 1,
612 strlen ("video/x-svq") + 1, 612 0
613 0 613 },
614 }, 614 {
615 { 615 EXTRACTOR_METATYPE_UNKNOWN,
616 EXTRACTOR_METATYPE_UNKNOWN, 616 EXTRACTOR_METAFORMAT_UTF8,
617 EXTRACTOR_METAFORMAT_UTF8, 617 "text/plain",
618 "text/plain", 618 "svqversion=1",
619 "svqversion=1", 619 strlen ("svqversion=1") + 1,
620 strlen ("svqversion=1") + 1, 620 0
621 0 621 },
622 }, 622 /* Yep, again... */
623 /* Yep, again... */ 623 {
624 { 624 EXTRACTOR_METATYPE_CREATION_TIME,
625 EXTRACTOR_METATYPE_CREATION_TIME, 625 EXTRACTOR_METAFORMAT_UTF8,
626 EXTRACTOR_METAFORMAT_UTF8, 626 "text/plain",
627 "text/plain", 627 "2001-02-19T16:45:54Z",
628 "2001-02-19T16:45:54Z", 628 strlen ("2001-02-19T16:45:54Z") + 1,
629 strlen ("2001-02-19T16:45:54Z") + 1, 629 0
630 0 630 },
631 }, 631 {
632 { 632 EXTRACTOR_METATYPE_TITLE,
633 EXTRACTOR_METATYPE_TITLE, 633 EXTRACTOR_METAFORMAT_UTF8,
634 EXTRACTOR_METAFORMAT_UTF8, 634 "text/plain",
635 "text/plain", 635 "QuickTime Sample Movie",
636 "QuickTime Sample Movie", 636 strlen ("QuickTime Sample Movie") + 1,
637 strlen ("QuickTime Sample Movie") + 1, 637 0
638 0 638 },
639 }, 639 {
640 { 640 EXTRACTOR_METATYPE_COPYRIGHT,
641 EXTRACTOR_METATYPE_COPYRIGHT, 641 EXTRACTOR_METAFORMAT_UTF8,
642 EXTRACTOR_METAFORMAT_UTF8, 642 "text/plain",
643 "text/plain", 643 "© Apple Computer, Inc. 2001",
644 "© Apple Computer, Inc. 2001", 644 strlen ("© Apple Computer, Inc. 2001") + 1,
645 strlen ("© Apple Computer, Inc. 2001") + 1, 645 0
646 0 646 },
647 }, 647 {
648 { 648 EXTRACTOR_METATYPE_CONTAINER_FORMAT,
649 EXTRACTOR_METATYPE_CONTAINER_FORMAT, 649 EXTRACTOR_METAFORMAT_UTF8,
650 EXTRACTOR_METAFORMAT_UTF8, 650 "text/plain",
651 "text/plain", 651 "ISO MP4/M4A",
652 "ISO MP4/M4A", 652 strlen ("ISO MP4/M4A") + 1,
653 strlen ("ISO MP4/M4A") + 1, 653 0
654 0 654 },
655 }, 655 {
656 { 656 EXTRACTOR_METATYPE_VIDEO_CODEC,
657 EXTRACTOR_METATYPE_VIDEO_CODEC, 657 EXTRACTOR_METAFORMAT_UTF8,
658 EXTRACTOR_METAFORMAT_UTF8, 658 "text/plain",
659 "text/plain", 659 "Sorensen video v.1",
660 "Sorensen video v.1", 660 strlen ("Sorensen video v.1") + 1,
661 strlen ("Sorensen video v.1") + 1, 661 0
662 0 662 },
663 }, 663 {
664 { 664 EXTRACTOR_METATYPE_VIDEO_LANGUAGE,
665 EXTRACTOR_METATYPE_VIDEO_LANGUAGE, 665 EXTRACTOR_METAFORMAT_UTF8,
666 EXTRACTOR_METAFORMAT_UTF8, 666 "text/plain",
667 "text/plain", 667 "en",
668 "en", 668 strlen ("en") + 1,
669 strlen ("en") + 1, 669 0
670 0 670 },
671 }, 671 {
672 { 672 EXTRACTOR_METATYPE_VIDEO_DIMENSIONS,
673 EXTRACTOR_METATYPE_VIDEO_DIMENSIONS, 673 EXTRACTOR_METAFORMAT_UTF8,
674 EXTRACTOR_METAFORMAT_UTF8, 674 "text/plain",
675 "text/plain", 675 "190x240",
676 "190x240", 676 strlen ("190x240") + 1,
677 strlen ("190x240") + 1, 677 0
678 0 678 },
679 }, 679 {
680 { 680 EXTRACTOR_METATYPE_FRAME_RATE,
681 EXTRACTOR_METATYPE_FRAME_RATE, 681 EXTRACTOR_METAFORMAT_UTF8,
682 EXTRACTOR_METAFORMAT_UTF8, 682 "text/plain",
683 "text/plain", 683 "12/1",
684 "12/1", 684 strlen ("12/1") + 1,
685 strlen ("12/1") + 1, 685 0
686 0 686 },
687 }, 687 {
688 { 688 EXTRACTOR_METATYPE_PIXEL_ASPECT_RATIO,
689 EXTRACTOR_METATYPE_PIXEL_ASPECT_RATIO, 689 EXTRACTOR_METAFORMAT_UTF8,
690 EXTRACTOR_METAFORMAT_UTF8, 690 "text/plain",
691 "text/plain", 691 "1/1",
692 "1/1", 692 strlen ("1/1") + 1,
693 strlen ("1/1") + 1, 693 0
694 0 694 },
695 }, 695 { 0, 0, NULL, NULL, 0, -1 }
696 { 0, 0, NULL, NULL, 0, -1 } 696 };
697 }; 697 struct ProblemSet ps[] = {
698 struct ProblemSet ps[] = 698 { "testdata/gstreamer_sample_sorenson.mov", sample_sorenson_sol },
699 { 699 { NULL, NULL }
700 { "testdata/gstreamer_sample_sorenson.mov", sample_sorenson_sol }, 700 };
701 { NULL, NULL }
702 };
703 g_print ("Running mov test on GStreamer:\n"); 701 g_print ("Running mov test on GStreamer:\n");
704 test_result = (0 == ET_main ("gstreamer", ps) ? 0 : 1); 702 test_result = (0 == ET_main ("gstreamer", ps) ? 0 : 1);
705 g_print ("mov GStreamer test result: %s\n", test_result == 0 ? "OK" : "FAILED"); 703 g_print ("mov GStreamer test result: %s\n", test_result == 0 ? "OK" :
704 "FAILED");
706 result += test_result; 705 result += test_result;
707 } 706 }
708 707
@@ -711,956 +710,957 @@ main (int argc, char *argv[])
711 { 710 {
712 int result_stock; 711 int result_stock;
713 int result_patched; 712 int result_patched;
714 struct SolutionData matroska_flame_stock_sol[] = 713 struct SolutionData matroska_flame_stock_sol[] = {
715 { 714 {
716 { 715 EXTRACTOR_METATYPE_DURATION,
717 EXTRACTOR_METATYPE_DURATION, 716 EXTRACTOR_METAFORMAT_UTF8,
718 EXTRACTOR_METAFORMAT_UTF8, 717 "text/plain",
719 "text/plain", 718 "0:00:03.143000000",
720 "0:00:03.143000000", 719 strlen ("0:00:03.143000000") + 1,
721 strlen ("0:00:03.143000000") + 1, 720 0
722 0 721 },
723 }, 722 {
724 { 723 EXTRACTOR_METATYPE_MIMETYPE,
725 EXTRACTOR_METATYPE_MIMETYPE, 724 EXTRACTOR_METAFORMAT_UTF8,
726 EXTRACTOR_METAFORMAT_UTF8, 725 "text/plain",
727 "text/plain", 726 "video/x-matroska",
728 "video/x-matroska", 727 strlen ("video/x-matroska") + 1,
729 strlen ("video/x-matroska") + 1, 728 0
730 0 729 },
731 }, 730 {
732 { 731 EXTRACTOR_METATYPE_MIMETYPE,
733 EXTRACTOR_METATYPE_MIMETYPE, 732 EXTRACTOR_METAFORMAT_UTF8,
734 EXTRACTOR_METAFORMAT_UTF8, 733 "text/plain",
735 "text/plain", 734 "video/x-indeo",
736 "video/x-indeo", 735 strlen ("video/x-indeo") + 1,
737 strlen ("video/x-indeo") + 1, 736 0
738 0 737 },
739 }, 738 {
740 { 739 EXTRACTOR_METATYPE_UNKNOWN,
741 EXTRACTOR_METATYPE_UNKNOWN, 740 EXTRACTOR_METAFORMAT_UTF8,
742 EXTRACTOR_METAFORMAT_UTF8, 741 "text/plain",
743 "text/plain", 742 "indeoversion=4",
744 "indeoversion=4", 743 strlen ("indeoversion=4") + 1,
745 strlen ("indeoversion=4") + 1, 744 0
746 0 745 },
747 }, 746 {
748 { 747 EXTRACTOR_METATYPE_TITLE,
749 EXTRACTOR_METATYPE_TITLE, 748 EXTRACTOR_METAFORMAT_UTF8,
750 EXTRACTOR_METAFORMAT_UTF8, 749 "text/plain",
751 "text/plain", 750 "filesegmenttitle",
752 "filesegmenttitle", 751 strlen ("filesegmenttitle") + 1,
753 strlen ("filesegmenttitle") + 1, 752 0
754 0 753 },
755 }, 754 {
756 { 755 EXTRACTOR_METATYPE_TITLE,
757 EXTRACTOR_METATYPE_TITLE, 756 EXTRACTOR_METAFORMAT_UTF8,
758 EXTRACTOR_METAFORMAT_UTF8, 757 "text/plain",
759 "text/plain", 758 "TITLE",
760 "TITLE", 759 strlen ("TITLE") + 1,
761 strlen ("TITLE") + 1, 760 0
762 0 761 },
763 }, 762 {
764 { 763 EXTRACTOR_METATYPE_ARTIST,
765 EXTRACTOR_METATYPE_ARTIST, 764 EXTRACTOR_METAFORMAT_UTF8,
766 EXTRACTOR_METAFORMAT_UTF8, 765 "text/plain",
767 "text/plain", 766 "ALBUM/ARTIST",
768 "ALBUM/ARTIST", 767 strlen ("ALBUM/ARTIST") + 1,
769 strlen ("ALBUM/ARTIST") + 1, 768 0
770 0 769 },
771 }, 770 {
772 { 771 EXTRACTOR_METATYPE_ARTIST,
773 EXTRACTOR_METATYPE_ARTIST, 772 EXTRACTOR_METAFORMAT_UTF8,
774 EXTRACTOR_METAFORMAT_UTF8, 773 "text/plain",
775 "text/plain", 774 "ARTIST",
776 "ARTIST", 775 strlen ("ARTIST") + 1,
777 strlen ("ARTIST") + 1, 776 0
778 0 777 },
779 }, 778 {
780 { 779 EXTRACTOR_METATYPE_COPYRIGHT,
781 EXTRACTOR_METATYPE_COPYRIGHT, 780 EXTRACTOR_METAFORMAT_UTF8,
782 EXTRACTOR_METAFORMAT_UTF8, 781 "text/plain",
783 "text/plain", 782 "COPYRIGHT",
784 "COPYRIGHT", 783 strlen ("COPYRIGHT") + 1,
785 strlen ("COPYRIGHT") + 1, 784 0
786 0 785 },
787 }, 786 {
788 { 787 EXTRACTOR_METATYPE_COMPOSER,
789 EXTRACTOR_METATYPE_COMPOSER, 788 EXTRACTOR_METAFORMAT_UTF8,
790 EXTRACTOR_METAFORMAT_UTF8, 789 "text/plain",
791 "text/plain", 790 "COMPOSER",
792 "COMPOSER", 791 strlen ("COMPOSER") + 1,
793 strlen ("COMPOSER") + 1, 792 0
794 0 793 },
795 }, 794 {
796 { 795 EXTRACTOR_METATYPE_GENRE,
797 EXTRACTOR_METATYPE_GENRE, 796 EXTRACTOR_METAFORMAT_UTF8,
798 EXTRACTOR_METAFORMAT_UTF8, 797 "text/plain",
799 "text/plain", 798 "GENRE",
800 "GENRE", 799 strlen ("GENRE") + 1,
801 strlen ("GENRE") + 1, 800 0
802 0 801 },
803 }, 802 {
804 { 803 EXTRACTOR_METATYPE_ENCODER,
805 EXTRACTOR_METATYPE_ENCODER, 804 EXTRACTOR_METAFORMAT_UTF8,
806 EXTRACTOR_METAFORMAT_UTF8, 805 "text/plain",
807 "text/plain", 806 "ENCODER",
808 "ENCODER", 807 strlen ("ENCODER") + 1,
809 strlen ("ENCODER") + 1, 808 0
810 0 809 },
811 }, 810 {
812 { 811 EXTRACTOR_METATYPE_ISRC,
813 EXTRACTOR_METATYPE_ISRC, 812 EXTRACTOR_METAFORMAT_UTF8,
814 EXTRACTOR_METAFORMAT_UTF8, 813 "text/plain",
815 "text/plain", 814 "ISRC",
816 "ISRC", 815 strlen ("ISRC") + 1,
817 strlen ("ISRC") + 1, 816 0
818 0 817 },
819 }, 818 {
820 { 819 EXTRACTOR_METATYPE_CONTAINER_FORMAT,
821 EXTRACTOR_METATYPE_CONTAINER_FORMAT, 820 EXTRACTOR_METAFORMAT_UTF8,
822 EXTRACTOR_METAFORMAT_UTF8, 821 "text/plain",
823 "text/plain", 822 "Matroska",
824 "Matroska", 823 strlen ("Matroska") + 1,
825 strlen ("Matroska") + 1, 824 0
826 0 825 },
827 }, 826 {
828 { 827 EXTRACTOR_METATYPE_VIDEO_CODEC,
829 EXTRACTOR_METATYPE_VIDEO_CODEC, 828 EXTRACTOR_METAFORMAT_UTF8,
830 EXTRACTOR_METAFORMAT_UTF8, 829 "text/plain",
831 "text/plain", 830 "Intel Video 4",
832 "Intel Video 4", 831 strlen ("Intel Video 4") + 1,
833 strlen ("Intel Video 4") + 1, 832 0
834 0 833 },
835 }, 834 {
836 { 835 EXTRACTOR_METATYPE_VIDEO_LANGUAGE,
837 EXTRACTOR_METATYPE_VIDEO_LANGUAGE, 836 EXTRACTOR_METAFORMAT_UTF8,
838 EXTRACTOR_METAFORMAT_UTF8, 837 "text/plain",
839 "text/plain", 838 "it",
840 "it", 839 strlen ("it") + 1,
841 strlen ("it") + 1, 840 0
842 0 841 },
843 }, 842 {
844 { 843 EXTRACTOR_METATYPE_VIDEO_DIMENSIONS,
845 EXTRACTOR_METATYPE_VIDEO_DIMENSIONS, 844 EXTRACTOR_METAFORMAT_UTF8,
846 EXTRACTOR_METAFORMAT_UTF8, 845 "text/plain",
847 "text/plain", 846 "256x240",
848 "256x240", 847 strlen ("256x240") + 1,
849 strlen ("256x240") + 1, 848 0
850 0 849 },
851 }, 850 {
852 { 851 EXTRACTOR_METATYPE_FRAME_RATE,
853 EXTRACTOR_METATYPE_FRAME_RATE, 852 EXTRACTOR_METAFORMAT_UTF8,
854 EXTRACTOR_METAFORMAT_UTF8, 853 "text/plain",
855 "text/plain", 854 "35/1",
856 "35/1", 855 strlen ("35/1") + 1,
857 strlen ("35/1") + 1, 856 0
858 0 857 },
859 }, 858 {
860 { 859 EXTRACTOR_METATYPE_PIXEL_ASPECT_RATIO,
861 EXTRACTOR_METATYPE_PIXEL_ASPECT_RATIO, 860 EXTRACTOR_METAFORMAT_UTF8,
862 EXTRACTOR_METAFORMAT_UTF8, 861 "text/plain",
863 "text/plain", 862 "1/1",
864 "1/1", 863 strlen ("1/1") + 1,
865 strlen ("1/1") + 1, 864 0
866 0 865 },
867 }, 866 { 0, 0, NULL, NULL, 0, -1 }
868 { 0, 0, NULL, NULL, 0, -1 } 867 };
869 }; 868 struct ProblemSet stock_ps[] = {
870 struct ProblemSet stock_ps[] = 869 { "testdata/matroska_flame.mkv", matroska_flame_stock_sol },
871 { 870 { NULL, NULL }
872 { "testdata/matroska_flame.mkv", matroska_flame_stock_sol }, 871 };
873 { NULL, NULL }
874 };
875 872
876 873
877 struct SolutionData matroska_flame_patched_sol[] = 874 struct SolutionData matroska_flame_patched_sol[] = {
878 { 875 {
879 { 876 EXTRACTOR_METATYPE_DURATION,
880 EXTRACTOR_METATYPE_DURATION, 877 EXTRACTOR_METAFORMAT_UTF8,
881 EXTRACTOR_METAFORMAT_UTF8, 878 "text/plain",
882 "text/plain", 879 "0:00:03.143000000",
883 "0:00:03.143000000", 880 strlen ("0:00:03.143000000") + 1,
884 strlen ("0:00:03.143000000") + 1, 881 0
885 0 882 },
886 }, 883 {
887 { 884 EXTRACTOR_METATYPE_MIMETYPE,
888 EXTRACTOR_METATYPE_MIMETYPE, 885 EXTRACTOR_METAFORMAT_UTF8,
889 EXTRACTOR_METAFORMAT_UTF8, 886 "text/plain",
890 "text/plain", 887 "video/x-matroska",
891 "video/x-matroska", 888 strlen ("video/x-matroska") + 1,
892 strlen ("video/x-matroska") + 1, 889 0
893 0 890 },
894 }, 891 {
895 { 892 EXTRACTOR_METATYPE_MIMETYPE,
896 EXTRACTOR_METATYPE_MIMETYPE, 893 EXTRACTOR_METAFORMAT_UTF8,
897 EXTRACTOR_METAFORMAT_UTF8, 894 "text/plain",
898 "text/plain", 895 "video/x-indeo",
899 "video/x-indeo", 896 strlen ("video/x-indeo") + 1,
900 strlen ("video/x-indeo") + 1, 897 0
901 0 898 },
902 }, 899 {
903 { 900 EXTRACTOR_METATYPE_UNKNOWN,
904 EXTRACTOR_METATYPE_UNKNOWN, 901 EXTRACTOR_METAFORMAT_UTF8,
905 EXTRACTOR_METAFORMAT_UTF8, 902 "text/plain",
906 "text/plain", 903 "indeoversion=4",
907 "indeoversion=4", 904 strlen ("indeoversion=4") + 1,
908 strlen ("indeoversion=4") + 1, 905 0
909 0 906 },
910 }, 907 {
911 { 908 EXTRACTOR_METATYPE_TITLE,
912 EXTRACTOR_METATYPE_TITLE, 909 EXTRACTOR_METAFORMAT_UTF8,
913 EXTRACTOR_METAFORMAT_UTF8, 910 "text/plain",
914 "text/plain", 911 "filesegmenttitle",
915 "filesegmenttitle", 912 strlen ("filesegmenttitle") + 1,
916 strlen ("filesegmenttitle") + 1, 913 0
917 0 914 },
918 }, 915 {
919 { 916 EXTRACTOR_METATYPE_ALBUM,
920 EXTRACTOR_METATYPE_ALBUM, 917 EXTRACTOR_METAFORMAT_UTF8,
921 EXTRACTOR_METAFORMAT_UTF8, 918 "text/plain",
922 "text/plain", 919 "ALBUM/TITLE",
923 "ALBUM/TITLE", 920 strlen ("ALBUM/TITLE") + 1,
924 strlen ("ALBUM/TITLE") + 1, 921 0
925 0 922 },
926 }, 923 {
927 { 924 EXTRACTOR_METATYPE_TITLE,
928 EXTRACTOR_METATYPE_TITLE, 925 EXTRACTOR_METAFORMAT_UTF8,
929 EXTRACTOR_METAFORMAT_UTF8, 926 "text/plain",
930 "text/plain", 927 "TITLE",
931 "TITLE", 928 strlen ("TITLE") + 1,
932 strlen ("TITLE") + 1, 929 0
933 0 930 },
934 }, 931 {
935 { 932 EXTRACTOR_METATYPE_TITLE,
936 EXTRACTOR_METATYPE_TITLE, 933 EXTRACTOR_METAFORMAT_UTF8,
937 EXTRACTOR_METAFORMAT_UTF8, 934 "text/plain",
938 "text/plain", 935 "SUBTITLE",
939 "SUBTITLE", 936 strlen ("SUBTITLE") + 1,
940 strlen ("SUBTITLE") + 1, 937 0
941 0 938 },
942 }, 939 {
943 { 940 EXTRACTOR_METATYPE_TITLE,
944 EXTRACTOR_METATYPE_TITLE, 941 EXTRACTOR_METAFORMAT_UTF8,
945 EXTRACTOR_METAFORMAT_UTF8, 942 "text/plain",
946 "text/plain", 943 "VIDEO/TITLE",
947 "VIDEO/TITLE", 944 strlen ("VIDEO/TITLE") + 1,
948 strlen ("VIDEO/TITLE") + 1, 945 0
949 0 946 },
950 }, 947 {
951 { 948 EXTRACTOR_METATYPE_ARTIST,
952 EXTRACTOR_METATYPE_ARTIST, 949 EXTRACTOR_METAFORMAT_UTF8,
953 EXTRACTOR_METAFORMAT_UTF8, 950 "text/plain",
954 "text/plain", 951 "ALBUM/ARTIST",
955 "ALBUM/ARTIST", 952 strlen ("ALBUM/ARTIST") + 1,
956 strlen ("ALBUM/ARTIST") + 1, 953 0
957 0 954 },
958 }, 955 {
959 { 956 EXTRACTOR_METATYPE_ARTIST,
960 EXTRACTOR_METATYPE_ARTIST, 957 EXTRACTOR_METAFORMAT_UTF8,
961 EXTRACTOR_METAFORMAT_UTF8, 958 "text/plain",
962 "text/plain", 959 "ARTIST",
963 "ARTIST", 960 strlen ("ARTIST") + 1,
964 strlen ("ARTIST") + 1, 961 0
965 0 962 },
966 }, 963 {
967 { 964 EXTRACTOR_METATYPE_SONG_COUNT,
968 EXTRACTOR_METATYPE_SONG_COUNT, 965 EXTRACTOR_METAFORMAT_UTF8,
969 EXTRACTOR_METAFORMAT_UTF8, 966 "text/plain",
970 "text/plain", 967 "20",
971 "20", 968 strlen ("20") + 1,
972 strlen ("20") + 1, 969 0
973 0 970 },
974 }, 971 {
975 { 972 EXTRACTOR_METATYPE_UNKNOWN,
976 EXTRACTOR_METATYPE_UNKNOWN, 973 EXTRACTOR_METAFORMAT_UTF8,
977 EXTRACTOR_METAFORMAT_UTF8, 974 "text/plain",
978 "text/plain", 975 "PART_OFFSET=5",
979 "PART_OFFSET=5", 976 strlen ("PART_OFFSET=5") + 1,
980 strlen ("PART_OFFSET=5") + 1, 977 0
981 0 978 },
982 }, 979 {
983 { 980 EXTRACTOR_METATYPE_UNKNOWN,
984 EXTRACTOR_METATYPE_UNKNOWN, 981 EXTRACTOR_METAFORMAT_UTF8,
985 EXTRACTOR_METAFORMAT_UTF8, 982 "text/plain",
986 "text/plain", 983 "ARTIST/INSTRUMENTS=ARTIST/INSTRUMENTS",
987 "ARTIST/INSTRUMENTS=ARTIST/INSTRUMENTS", 984 strlen ("ARTIST/INSTRUMENTS=ARTIST/INSTRUMENTS") + 1,
988 strlen ("ARTIST/INSTRUMENTS=ARTIST/INSTRUMENTS") + 1, 985 0
989 0 986 },
990 }, 987 {
991 { 988 EXTRACTOR_METATYPE_UNKNOWN,
992 EXTRACTOR_METATYPE_UNKNOWN, 989 EXTRACTOR_METAFORMAT_UTF8,
993 EXTRACTOR_METAFORMAT_UTF8, 990 "text/plain",
994 "text/plain", 991 "LEAD_PERFORMER=LEAD_PERFORMER",
995 "LEAD_PERFORMER=LEAD_PERFORMER", 992 strlen ("LEAD_PERFORMER=LEAD_PERFORMER") + 1,
996 strlen ("LEAD_PERFORMER=LEAD_PERFORMER") + 1, 993 0
997 0 994 },
998 }, 995 {
999 { 996 EXTRACTOR_METATYPE_UNKNOWN,
1000 EXTRACTOR_METATYPE_UNKNOWN, 997 EXTRACTOR_METAFORMAT_UTF8,
1001 EXTRACTOR_METAFORMAT_UTF8, 998 "text/plain",
1002 "text/plain", 999 "ARRANGER=ARRANGER",
1003 "ARRANGER=ARRANGER", 1000 strlen ("ARRANGER=ARRANGER") + 1,
1004 strlen ("ARRANGER=ARRANGER") + 1, 1001 0
1005 0 1002 },
1006 }, 1003 {
1007 { 1004 EXTRACTOR_METATYPE_UNKNOWN,
1008 EXTRACTOR_METATYPE_UNKNOWN, 1005 EXTRACTOR_METAFORMAT_UTF8,
1009 EXTRACTOR_METAFORMAT_UTF8, 1006 "text/plain",
1010 "text/plain", 1007 "LYRICIST=LYRICIST",
1011 "LYRICIST=LYRICIST", 1008 strlen ("LYRICIST=LYRICIST") + 1,
1012 strlen ("LYRICIST=LYRICIST") + 1, 1009 0
1013 0 1010 },
1014 }, 1011 {
1015 { 1012 EXTRACTOR_METATYPE_MOVIE_DIRECTOR,
1016 EXTRACTOR_METATYPE_MOVIE_DIRECTOR, 1013 EXTRACTOR_METAFORMAT_UTF8,
1017 EXTRACTOR_METAFORMAT_UTF8, 1014 "text/plain",
1018 "text/plain", 1015 "DIRECTOR",
1019 "DIRECTOR", 1016 strlen ("DIRECTOR") + 1,
1020 strlen ("DIRECTOR") + 1, 1017 0
1021 0 1018 },
1022 }, 1019 {
1023 { 1020 EXTRACTOR_METATYPE_UNKNOWN,
1024 EXTRACTOR_METATYPE_UNKNOWN, 1021 EXTRACTOR_METAFORMAT_UTF8,
1025 EXTRACTOR_METAFORMAT_UTF8, 1022 "text/plain",
1026 "text/plain", 1023 "ASSISTANT_DIRECTOR=ASSISTANT_DIRECTOR",
1027 "ASSISTANT_DIRECTOR=ASSISTANT_DIRECTOR", 1024 strlen ("ASSISTANT_DIRECTOR=ASSISTANT_DIRECTOR") + 1,
1028 strlen ("ASSISTANT_DIRECTOR=ASSISTANT_DIRECTOR") + 1, 1025 0
1029 0 1026 },
1030 }, 1027 {
1031 { 1028 EXTRACTOR_METATYPE_UNKNOWN,
1032 EXTRACTOR_METATYPE_UNKNOWN, 1029 EXTRACTOR_METAFORMAT_UTF8,
1033 EXTRACTOR_METAFORMAT_UTF8, 1030 "text/plain",
1034 "text/plain", 1031 "DIRECTOR_OF_PHOTOGRAPHY=DIRECTOR_OF_PHOTOGRAPHY",
1035 "DIRECTOR_OF_PHOTOGRAPHY=DIRECTOR_OF_PHOTOGRAPHY", 1032 strlen ("DIRECTOR_OF_PHOTOGRAPHY=DIRECTOR_OF_PHOTOGRAPHY") + 1,
1036 strlen ("DIRECTOR_OF_PHOTOGRAPHY=DIRECTOR_OF_PHOTOGRAPHY") + 1, 1033 0
1037 0 1034 },
1038 }, 1035 {
1039 { 1036 EXTRACTOR_METATYPE_UNKNOWN,
1040 EXTRACTOR_METATYPE_UNKNOWN, 1037 EXTRACTOR_METAFORMAT_UTF8,
1041 EXTRACTOR_METAFORMAT_UTF8, 1038 "text/plain",
1042 "text/plain", 1039 "SOUND_ENGINEER=SOUND_ENGINEER",
1043 "SOUND_ENGINEER=SOUND_ENGINEER", 1040 strlen ("SOUND_ENGINEER=SOUND_ENGINEER") + 1,
1044 strlen ("SOUND_ENGINEER=SOUND_ENGINEER") + 1, 1041 0
1045 0 1042 },
1046 }, 1043 {
1047 { 1044 EXTRACTOR_METATYPE_UNKNOWN,
1048 EXTRACTOR_METATYPE_UNKNOWN, 1045 EXTRACTOR_METAFORMAT_UTF8,
1049 EXTRACTOR_METAFORMAT_UTF8, 1046 "text/plain",
1050 "text/plain", 1047 "ART_DIRECTOR=ART_DIRECTOR",
1051 "ART_DIRECTOR=ART_DIRECTOR", 1048 strlen ("ART_DIRECTOR=ART_DIRECTOR") + 1,
1052 strlen ("ART_DIRECTOR=ART_DIRECTOR") + 1, 1049 0
1053 0 1050 },
1054 }, 1051 {
1055 { 1052 EXTRACTOR_METATYPE_UNKNOWN,
1056 EXTRACTOR_METATYPE_UNKNOWN, 1053 EXTRACTOR_METAFORMAT_UTF8,
1057 EXTRACTOR_METAFORMAT_UTF8, 1054 "text/plain",
1058 "text/plain", 1055 "PRODUCTION_DESIGNER=PRODUCTION_DESIGNER",
1059 "PRODUCTION_DESIGNER=PRODUCTION_DESIGNER", 1056 strlen ("PRODUCTION_DESIGNER=PRODUCTION_DESIGNER") + 1,
1060 strlen ("PRODUCTION_DESIGNER=PRODUCTION_DESIGNER") + 1, 1057 0
1061 0 1058 },
1062 }, 1059 {
1063 { 1060 EXTRACTOR_METATYPE_UNKNOWN,
1064 EXTRACTOR_METATYPE_UNKNOWN, 1061 EXTRACTOR_METAFORMAT_UTF8,
1065 EXTRACTOR_METAFORMAT_UTF8, 1062 "text/plain",
1066 "text/plain", 1063 "CHOREGRAPHER=CHOREGRAPHER",
1067 "CHOREGRAPHER=CHOREGRAPHER", 1064 strlen ("CHOREGRAPHER=CHOREGRAPHER") + 1,
1068 strlen ("CHOREGRAPHER=CHOREGRAPHER") + 1, 1065 0
1069 0 1066 },
1070 }, 1067 {
1071 { 1068 EXTRACTOR_METATYPE_UNKNOWN,
1072 EXTRACTOR_METATYPE_UNKNOWN, 1069 EXTRACTOR_METAFORMAT_UTF8,
1073 EXTRACTOR_METAFORMAT_UTF8, 1070 "text/plain",
1074 "text/plain", 1071 "COSTUME_DESIGNER=COSTUME_DESIGNER",
1075 "COSTUME_DESIGNER=COSTUME_DESIGNER", 1072 strlen ("COSTUME_DESIGNER=COSTUME_DESIGNER") + 1,
1076 strlen ("COSTUME_DESIGNER=COSTUME_DESIGNER") + 1, 1073 0
1077 0 1074 },
1078 }, 1075 {
1079 { 1076 EXTRACTOR_METATYPE_UNKNOWN,
1080 EXTRACTOR_METATYPE_UNKNOWN, 1077 EXTRACTOR_METAFORMAT_UTF8,
1081 EXTRACTOR_METAFORMAT_UTF8, 1078 "text/plain",
1082 "text/plain", 1079 "ACTOR=ACTOR",
1083 "ACTOR=ACTOR", 1080 strlen ("ACTOR=ACTOR") + 1,
1084 strlen ("ACTOR=ACTOR") + 1, 1081 0
1085 0 1082 },
1086 }, 1083 {
1087 { 1084 EXTRACTOR_METATYPE_UNKNOWN,
1088 EXTRACTOR_METATYPE_UNKNOWN, 1085 EXTRACTOR_METAFORMAT_UTF8,
1089 EXTRACTOR_METAFORMAT_UTF8, 1086 "text/plain",
1090 "text/plain", 1087 "CHARACTER=CHARACTER",
1091 "CHARACTER=CHARACTER", 1088 strlen ("CHARACTER=CHARACTER") + 1,
1092 strlen ("CHARACTER=CHARACTER") + 1, 1089 0
1093 0 1090 },
1094 }, 1091 {
1095 { 1092 EXTRACTOR_METATYPE_WRITER,
1096 EXTRACTOR_METATYPE_WRITER, 1093 EXTRACTOR_METAFORMAT_UTF8,
1097 EXTRACTOR_METAFORMAT_UTF8, 1094 "text/plain",
1098 "text/plain", 1095 "WRITTEN_BY",
1099 "WRITTEN_BY", 1096 strlen ("WRITTEN_BY") + 1,
1100 strlen ("WRITTEN_BY") + 1, 1097 0
1101 0 1098 },
1102 }, 1099 {
1103 { 1100 EXTRACTOR_METATYPE_UNKNOWN,
1104 EXTRACTOR_METATYPE_UNKNOWN, 1101 EXTRACTOR_METAFORMAT_UTF8,
1105 EXTRACTOR_METAFORMAT_UTF8, 1102 "text/plain",
1106 "text/plain", 1103 "SCREENPLAY_BY=SCREENPLAY_BY",
1107 "SCREENPLAY_BY=SCREENPLAY_BY", 1104 strlen ("SCREENPLAY_BY=SCREENPLAY_BY") + 1,
1108 strlen ("SCREENPLAY_BY=SCREENPLAY_BY") + 1, 1105 0
1109 0 1106 },
1110 }, 1107 {
1111 { 1108 EXTRACTOR_METATYPE_UNKNOWN,
1112 EXTRACTOR_METATYPE_UNKNOWN, 1109 EXTRACTOR_METAFORMAT_UTF8,
1113 EXTRACTOR_METAFORMAT_UTF8, 1110 "text/plain",
1114 "text/plain", 1111 "EDITED_BY=EDITED_BY",
1115 "EDITED_BY=EDITED_BY", 1112 strlen ("EDITED_BY=EDITED_BY") + 1,
1116 strlen ("EDITED_BY=EDITED_BY") + 1, 1113 0
1117 0 1114 },
1118 }, 1115 {
1119 { 1116 EXTRACTOR_METATYPE_PRODUCER,
1120 EXTRACTOR_METATYPE_PRODUCER, 1117 EXTRACTOR_METAFORMAT_UTF8,
1121 EXTRACTOR_METAFORMAT_UTF8, 1118 "text/plain",
1122 "text/plain", 1119 "PRODUCER",
1123 "PRODUCER", 1120 strlen ("PRODUCER") + 1,
1124 strlen ("PRODUCER") + 1, 1121 0
1125 0 1122 },
1126 }, 1123 {
1127 { 1124 EXTRACTOR_METATYPE_UNKNOWN,
1128 EXTRACTOR_METATYPE_UNKNOWN, 1125 EXTRACTOR_METAFORMAT_UTF8,
1129 EXTRACTOR_METAFORMAT_UTF8, 1126 "text/plain",
1130 "text/plain", 1127 "COPRODUCER=COPRODUCER",
1131 "COPRODUCER=COPRODUCER", 1128 strlen ("COPRODUCER=COPRODUCER") + 1,
1132 strlen ("COPRODUCER=COPRODUCER") + 1, 1129 0
1133 0 1130 },
1134 }, 1131 {
1135 { 1132 EXTRACTOR_METATYPE_UNKNOWN,
1136 EXTRACTOR_METATYPE_UNKNOWN, 1133 EXTRACTOR_METAFORMAT_UTF8,
1137 EXTRACTOR_METAFORMAT_UTF8, 1134 "text/plain",
1138 "text/plain", 1135 "EXECUTIVE_PRODUCER=EXECUTIVE_PRODUCER",
1139 "EXECUTIVE_PRODUCER=EXECUTIVE_PRODUCER", 1136 strlen ("EXECUTIVE_PRODUCER=EXECUTIVE_PRODUCER") + 1,
1140 strlen ("EXECUTIVE_PRODUCER=EXECUTIVE_PRODUCER") + 1, 1137 0
1141 0 1138 },
1142 }, 1139 {
1143 { 1140 EXTRACTOR_METATYPE_UNKNOWN,
1144 EXTRACTOR_METATYPE_UNKNOWN, 1141 EXTRACTOR_METAFORMAT_UTF8,
1145 EXTRACTOR_METAFORMAT_UTF8, 1142 "text/plain",
1146 "text/plain", 1143 "DISTRIBUTED_BY=DISTRIBUTED_BY",
1147 "DISTRIBUTED_BY=DISTRIBUTED_BY", 1144 strlen ("DISTRIBUTED_BY=DISTRIBUTED_BY") + 1,
1148 strlen ("DISTRIBUTED_BY=DISTRIBUTED_BY") + 1, 1145 0
1149 0 1146 },
1150 }, 1147 {
1151 { 1148 EXTRACTOR_METATYPE_UNKNOWN,
1152 EXTRACTOR_METATYPE_UNKNOWN, 1149 EXTRACTOR_METAFORMAT_UTF8,
1153 EXTRACTOR_METAFORMAT_UTF8, 1150 "text/plain",
1154 "text/plain", 1151 "MASTERED_BY=MASTERED_BY",
1155 "MASTERED_BY=MASTERED_BY", 1152 strlen ("MASTERED_BY=MASTERED_BY") + 1,
1156 strlen ("MASTERED_BY=MASTERED_BY") + 1, 1153 0
1157 0 1154 },
1158 }, 1155 {
1159 { 1156 EXTRACTOR_METATYPE_UNKNOWN,
1160 EXTRACTOR_METATYPE_UNKNOWN, 1157 EXTRACTOR_METAFORMAT_UTF8,
1161 EXTRACTOR_METAFORMAT_UTF8, 1158 "text/plain",
1162 "text/plain", 1159 "MIXED_BY=MIXED_BY",
1163 "MIXED_BY=MIXED_BY", 1160 strlen ("MIXED_BY=MIXED_BY") + 1,
1164 strlen ("MIXED_BY=MIXED_BY") + 1, 1161 0
1165 0 1162 },
1166 }, 1163 {
1167 { 1164 EXTRACTOR_METATYPE_UNKNOWN,
1168 EXTRACTOR_METATYPE_UNKNOWN, 1165 EXTRACTOR_METAFORMAT_UTF8,
1169 EXTRACTOR_METAFORMAT_UTF8, 1166 "text/plain",
1170 "text/plain", 1167 "REMIXED_BY=REMIXED_BY",
1171 "REMIXED_BY=REMIXED_BY", 1168 strlen ("REMIXED_BY=REMIXED_BY") + 1,
1172 strlen ("REMIXED_BY=REMIXED_BY") + 1, 1169 0
1173 0 1170 },
1174 }, 1171 {
1175 { 1172 EXTRACTOR_METATYPE_UNKNOWN,
1176 EXTRACTOR_METATYPE_UNKNOWN, 1173 EXTRACTOR_METAFORMAT_UTF8,
1177 EXTRACTOR_METAFORMAT_UTF8, 1174 "text/plain",
1178 "text/plain", 1175 "PRODUCTION_STUDIO=PRODUCTION_STUDIO",
1179 "PRODUCTION_STUDIO=PRODUCTION_STUDIO", 1176 strlen ("PRODUCTION_STUDIO=PRODUCTION_STUDIO") + 1,
1180 strlen ("PRODUCTION_STUDIO=PRODUCTION_STUDIO") + 1, 1177 0
1181 0 1178 },
1182 }, 1179 {
1183 { 1180 EXTRACTOR_METATYPE_UNKNOWN,
1184 EXTRACTOR_METATYPE_UNKNOWN, 1181 EXTRACTOR_METAFORMAT_UTF8,
1185 EXTRACTOR_METAFORMAT_UTF8, 1182 "text/plain",
1186 "text/plain", 1183 "THANKS_TO=THANKS_TO",
1187 "THANKS_TO=THANKS_TO", 1184 strlen ("THANKS_TO=THANKS_TO") + 1,
1188 strlen ("THANKS_TO=THANKS_TO") + 1, 1185 0
1189 0 1186 },
1190 }, 1187 {
1191 { 1188 EXTRACTOR_METATYPE_PUBLISHER,
1192 EXTRACTOR_METATYPE_PUBLISHER, 1189 EXTRACTOR_METAFORMAT_UTF8,
1193 EXTRACTOR_METAFORMAT_UTF8, 1190 "text/plain",
1194 "text/plain", 1191 "PUBLISHER",
1195 "PUBLISHER", 1192 strlen ("PUBLISHER") + 1,
1196 strlen ("PUBLISHER") + 1, 1193 0
1197 0 1194 },
1198 }, 1195 {
1199 { 1196 EXTRACTOR_METATYPE_UNKNOWN,
1200 EXTRACTOR_METATYPE_UNKNOWN, 1197 EXTRACTOR_METAFORMAT_UTF8,
1201 EXTRACTOR_METAFORMAT_UTF8, 1198 "text/plain",
1202 "text/plain", 1199 "LABEL=LABEL",
1203 "LABEL=LABEL", 1200 strlen ("LABEL=LABEL") + 1,
1204 strlen ("LABEL=LABEL") + 1, 1201 0
1205 0 1202 },
1206 }, 1203 {
1207 { 1204 EXTRACTOR_METATYPE_MOOD,
1208 EXTRACTOR_METATYPE_MOOD, 1205 EXTRACTOR_METAFORMAT_UTF8,
1209 EXTRACTOR_METAFORMAT_UTF8, 1206 "text/plain",
1210 "text/plain", 1207 "MOOD",
1211 "MOOD", 1208 strlen ("MOOD") + 1,
1212 strlen ("MOOD") + 1, 1209 0
1213 0 1210 },
1214 }, 1211 {
1215 { 1212 EXTRACTOR_METATYPE_UNKNOWN,
1216 EXTRACTOR_METATYPE_UNKNOWN, 1213 EXTRACTOR_METAFORMAT_UTF8,
1217 EXTRACTOR_METAFORMAT_UTF8, 1214 "text/plain",
1218 "text/plain", 1215 "ORIGINAL_MEDIA_TYPE=ORIGINAL_MEDIA_TYPE",
1219 "ORIGINAL_MEDIA_TYPE=ORIGINAL_MEDIA_TYPE", 1216 strlen ("ORIGINAL_MEDIA_TYPE=ORIGINAL_MEDIA_TYPE") + 1,
1220 strlen ("ORIGINAL_MEDIA_TYPE=ORIGINAL_MEDIA_TYPE") + 1, 1217 0
1221 0 1218 },
1222 }, 1219 {
1223 { 1220 EXTRACTOR_METATYPE_UNKNOWN,
1224 EXTRACTOR_METATYPE_UNKNOWN, 1221 EXTRACTOR_METAFORMAT_UTF8,
1225 EXTRACTOR_METAFORMAT_UTF8, 1222 "text/plain",
1226 "text/plain", 1223 "CONTENT_TYPE=CONTENT_TYPE",
1227 "CONTENT_TYPE=CONTENT_TYPE", 1224 strlen ("CONTENT_TYPE=CONTENT_TYPE") + 1,
1228 strlen ("CONTENT_TYPE=CONTENT_TYPE") + 1, 1225 0
1229 0 1226 },
1230 }, 1227 {
1231 { 1228 EXTRACTOR_METATYPE_SUBJECT,
1232 EXTRACTOR_METATYPE_SUBJECT, 1229 EXTRACTOR_METAFORMAT_UTF8,
1233 EXTRACTOR_METAFORMAT_UTF8, 1230 "text/plain",
1234 "text/plain", 1231 "SUBJECT",
1235 "SUBJECT", 1232 strlen ("SUBJECT") + 1,
1236 strlen ("SUBJECT") + 1, 1233 0
1237 0 1234 },
1238 }, 1235 {
1239 { 1236 EXTRACTOR_METATYPE_SUMMARY,
1240 EXTRACTOR_METATYPE_SUMMARY, 1237 EXTRACTOR_METAFORMAT_UTF8,
1241 EXTRACTOR_METAFORMAT_UTF8, 1238 "text/plain",
1242 "text/plain", 1239 "SUMMARY",
1243 "SUMMARY", 1240 strlen ("SUMMARY") + 1,
1244 strlen ("SUMMARY") + 1, 1241 0
1245 0 1242 },
1246 }, 1243 {
1247 { 1244 EXTRACTOR_METATYPE_UNKNOWN,
1248 EXTRACTOR_METATYPE_UNKNOWN, 1245 EXTRACTOR_METAFORMAT_UTF8,
1249 EXTRACTOR_METAFORMAT_UTF8, 1246 "text/plain",
1250 "text/plain", 1247 "SYNOPSIS=SYNOPSIS",
1251 "SYNOPSIS=SYNOPSIS", 1248 strlen ("SYNOPSIS=SYNOPSIS") + 1,
1252 strlen ("SYNOPSIS=SYNOPSIS") + 1, 1249 0
1253 0 1250 },
1254 }, 1251 {
1255 { 1252 EXTRACTOR_METATYPE_UNKNOWN,
1256 EXTRACTOR_METATYPE_UNKNOWN, 1253 EXTRACTOR_METAFORMAT_UTF8,
1257 EXTRACTOR_METAFORMAT_UTF8, 1254 "text/plain",
1258 "text/plain", 1255 "INITIAL_KEY=INITIAL_KEY",
1259 "INITIAL_KEY=INITIAL_KEY", 1256 strlen ("INITIAL_KEY=INITIAL_KEY") + 1,
1260 strlen ("INITIAL_KEY=INITIAL_KEY") + 1, 1257 0
1261 0 1258 },
1262 }, 1259 {
1263 { 1260 EXTRACTOR_METATYPE_UNKNOWN,
1264 EXTRACTOR_METATYPE_UNKNOWN, 1261 EXTRACTOR_METAFORMAT_UTF8,
1265 EXTRACTOR_METAFORMAT_UTF8, 1262 "text/plain",
1266 "text/plain", 1263 "PERIOD=PERIOD",
1267 "PERIOD=PERIOD", 1264 strlen ("PERIOD=PERIOD") + 1,
1268 strlen ("PERIOD=PERIOD") + 1, 1265 0
1269 0 1266 },
1270 }, 1267 {
1271 { 1268 EXTRACTOR_METATYPE_UNKNOWN,
1272 EXTRACTOR_METATYPE_UNKNOWN, 1269 EXTRACTOR_METAFORMAT_UTF8,
1273 EXTRACTOR_METAFORMAT_UTF8, 1270 "text/plain",
1274 "text/plain", 1271 "LAW_RATING=LAW_RATING",
1275 "LAW_RATING=LAW_RATING", 1272 strlen ("LAW_RATING=LAW_RATING") + 1,
1276 strlen ("LAW_RATING=LAW_RATING") + 1, 1273 0
1277 0 1274 },
1278 }, 1275 {
1279 { 1276 EXTRACTOR_METATYPE_UNKNOWN,
1280 EXTRACTOR_METATYPE_UNKNOWN, 1277 EXTRACTOR_METAFORMAT_UTF8,
1281 EXTRACTOR_METAFORMAT_UTF8, 1278 "text/plain",
1282 "text/plain", 1279 "COMPOSITION_LOCATION=COMPOSITION_LOCATION",
1283 "COMPOSITION_LOCATION=COMPOSITION_LOCATION", 1280 strlen ("COMPOSITION_LOCATION=COMPOSITION_LOCATION") + 1,
1284 strlen ("COMPOSITION_LOCATION=COMPOSITION_LOCATION") + 1, 1281 0
1285 0 1282 },
1286 }, 1283 {
1287 { 1284 EXTRACTOR_METATYPE_UNKNOWN,
1288 EXTRACTOR_METATYPE_UNKNOWN, 1285 EXTRACTOR_METAFORMAT_UTF8,
1289 EXTRACTOR_METAFORMAT_UTF8, 1286 "text/plain",
1290 "text/plain", 1287 "COMPOSER_NATIONALITY=COMPOSER_NATIONALITY",
1291 "COMPOSER_NATIONALITY=COMPOSER_NATIONALITY", 1288 strlen ("COMPOSER_NATIONALITY=COMPOSER_NATIONALITY") + 1,
1292 strlen ("COMPOSER_NATIONALITY=COMPOSER_NATIONALITY") + 1, 1289 0
1293 0 1290 },
1294 }, 1291 {
1295 { 1292 EXTRACTOR_METATYPE_PLAY_COUNTER,
1296 EXTRACTOR_METATYPE_PLAY_COUNTER, 1293 EXTRACTOR_METAFORMAT_UTF8,
1297 EXTRACTOR_METAFORMAT_UTF8, 1294 "text/plain",
1298 "text/plain", 1295 "PLAY_COUNTER",
1299 "PLAY_COUNTER", 1296 strlen ("PLAY_COUNTER") + 1,
1300 strlen ("PLAY_COUNTER") + 1, 1297 0
1301 0 1298 },
1302 }, 1299 {
1303 { 1300 EXTRACTOR_METATYPE_RATING,
1304 EXTRACTOR_METATYPE_RATING, 1301 EXTRACTOR_METAFORMAT_UTF8,
1305 EXTRACTOR_METAFORMAT_UTF8, 1302 "text/plain",
1306 "text/plain", 1303 "RATING",
1307 "RATING", 1304 strlen ("RATING") + 1,
1308 strlen ("RATING") + 1, 1305 0
1309 0 1306 },
1310 }, 1307 {
1311 { 1308 EXTRACTOR_METATYPE_UNKNOWN,
1312 EXTRACTOR_METATYPE_UNKNOWN, 1309 EXTRACTOR_METAFORMAT_UTF8,
1313 EXTRACTOR_METAFORMAT_UTF8, 1310 "text/plain",
1314 "text/plain", 1311 "ENCODER_SETTINGS=ENCODER_SETTINGS",
1315 "ENCODER_SETTINGS=ENCODER_SETTINGS", 1312 strlen ("ENCODER_SETTINGS=ENCODER_SETTINGS") + 1,
1316 strlen ("ENCODER_SETTINGS=ENCODER_SETTINGS") + 1, 1313 0
1317 0 1314 },
1318 }, 1315 {
1319 { 1316 EXTRACTOR_METATYPE_FRAME_RATE,
1320 EXTRACTOR_METATYPE_FRAME_RATE, 1317 EXTRACTOR_METAFORMAT_UTF8,
1321 EXTRACTOR_METAFORMAT_UTF8, 1318 "text/plain",
1322 "text/plain", 1319 "FPS",
1323 "FPS", 1320 strlen ("FPS") + 1,
1324 strlen ("FPS") + 1, 1321 0
1325 0 1322 },
1326 }, 1323 {
1327 { 1324 EXTRACTOR_METATYPE_UNKNOWN,
1328 EXTRACTOR_METATYPE_UNKNOWN, 1325 EXTRACTOR_METAFORMAT_UTF8,
1329 EXTRACTOR_METAFORMAT_UTF8, 1326 "text/plain",
1330 "text/plain", 1327 "MEASURE=MEASURE",
1331 "MEASURE=MEASURE", 1328 strlen ("MEASURE=MEASURE") + 1,
1332 strlen ("MEASURE=MEASURE") + 1, 1329 0
1333 0 1330 },
1334 }, 1331 {
1335 { 1332 EXTRACTOR_METATYPE_UNKNOWN,
1336 EXTRACTOR_METATYPE_UNKNOWN, 1333 EXTRACTOR_METAFORMAT_UTF8,
1337 EXTRACTOR_METAFORMAT_UTF8, 1334 "text/plain",
1338 "text/plain", 1335 "TUNING=TUNING",
1339 "TUNING=TUNING", 1336 strlen ("TUNING=TUNING") + 1,
1340 strlen ("TUNING=TUNING") + 1, 1337 0
1341 0 1338 },
1342 }, 1339 {
1343 { 1340 EXTRACTOR_METATYPE_UNKNOWN,
1344 EXTRACTOR_METATYPE_UNKNOWN, 1341 EXTRACTOR_METAFORMAT_UTF8,
1345 EXTRACTOR_METAFORMAT_UTF8, 1342 "text/plain",
1346 "text/plain", 1343 "ISBN=ISBN",
1347 "ISBN=ISBN", 1344 strlen ("ISBN=ISBN") + 1,
1348 strlen ("ISBN=ISBN") + 1, 1345 0
1349 0 1346 },
1350 }, 1347 {
1351 { 1348 EXTRACTOR_METATYPE_UNKNOWN,
1352 EXTRACTOR_METATYPE_UNKNOWN, 1349 EXTRACTOR_METAFORMAT_UTF8,
1353 EXTRACTOR_METAFORMAT_UTF8, 1350 "text/plain",
1354 "text/plain", 1351 "BARCODE=BARCODE",
1355 "BARCODE=BARCODE", 1352 strlen ("BARCODE=BARCODE") + 1,
1356 strlen ("BARCODE=BARCODE") + 1, 1353 0
1357 0 1354 },
1358 }, 1355 {
1359 { 1356 EXTRACTOR_METATYPE_UNKNOWN,
1360 EXTRACTOR_METATYPE_UNKNOWN, 1357 EXTRACTOR_METAFORMAT_UTF8,
1361 EXTRACTOR_METAFORMAT_UTF8, 1358 "text/plain",
1362 "text/plain", 1359 "CATALOG_NUMBER=CATALOG_NUMBER",
1363 "CATALOG_NUMBER=CATALOG_NUMBER", 1360 strlen ("CATALOG_NUMBER=CATALOG_NUMBER") + 1,
1364 strlen ("CATALOG_NUMBER=CATALOG_NUMBER") + 1, 1361 0
1365 0 1362 },
1366 }, 1363 {
1367 { 1364 EXTRACTOR_METATYPE_UNKNOWN,
1368 EXTRACTOR_METATYPE_UNKNOWN, 1365 EXTRACTOR_METAFORMAT_UTF8,
1369 EXTRACTOR_METAFORMAT_UTF8, 1366 "text/plain",
1370 "text/plain", 1367 "LABEL_CODE=LABEL_CODE",
1371 "LABEL_CODE=LABEL_CODE", 1368 strlen ("LABEL_CODE=LABEL_CODE") + 1,
1372 strlen ("LABEL_CODE=LABEL_CODE") + 1, 1369 0
1373 0 1370 },
1374 }, 1371 {
1375 { 1372 EXTRACTOR_METATYPE_UNKNOWN,
1376 EXTRACTOR_METATYPE_UNKNOWN, 1373 EXTRACTOR_METAFORMAT_UTF8,
1377 EXTRACTOR_METAFORMAT_UTF8, 1374 "text/plain",
1378 "text/plain", 1375 "LCCN=LCCN",
1379 "LCCN=LCCN", 1376 strlen ("LCCN=LCCN") + 1,
1380 strlen ("LCCN=LCCN") + 1, 1377 0
1381 0 1378 },
1382 }, 1379 {
1383 { 1380 EXTRACTOR_METATYPE_UNKNOWN,
1384 EXTRACTOR_METATYPE_UNKNOWN, 1381 EXTRACTOR_METAFORMAT_UTF8,
1385 EXTRACTOR_METAFORMAT_UTF8, 1382 "text/plain",
1386 "text/plain", 1383 "PURCHASE_ITEM=PURCHASE_ITEM",
1387 "PURCHASE_ITEM=PURCHASE_ITEM", 1384 strlen ("PURCHASE_ITEM=PURCHASE_ITEM") + 1,
1388 strlen ("PURCHASE_ITEM=PURCHASE_ITEM") + 1, 1385 0
1389 0 1386 },
1390 }, 1387 {
1391 { 1388 EXTRACTOR_METATYPE_UNKNOWN,
1392 EXTRACTOR_METATYPE_UNKNOWN, 1389 EXTRACTOR_METAFORMAT_UTF8,
1393 EXTRACTOR_METAFORMAT_UTF8, 1390 "text/plain",
1394 "text/plain", 1391 "PURCHASE_INFO=PURCHASE_INFO",
1395 "PURCHASE_INFO=PURCHASE_INFO", 1392 strlen ("PURCHASE_INFO=PURCHASE_INFO") + 1,
1396 strlen ("PURCHASE_INFO=PURCHASE_INFO") + 1, 1393 0
1397 0 1394 },
1398 }, 1395 {
1399 { 1396 EXTRACTOR_METATYPE_UNKNOWN,
1400 EXTRACTOR_METATYPE_UNKNOWN, 1397 EXTRACTOR_METAFORMAT_UTF8,
1401 EXTRACTOR_METAFORMAT_UTF8, 1398 "text/plain",
1402 "text/plain", 1399 "PURCHASE_OWNER=PURCHASE_OWNER",
1403 "PURCHASE_OWNER=PURCHASE_OWNER", 1400 strlen ("PURCHASE_OWNER=PURCHASE_OWNER") + 1,
1404 strlen ("PURCHASE_OWNER=PURCHASE_OWNER") + 1, 1401 0
1405 0 1402 },
1406 }, 1403 {
1407 { 1404 EXTRACTOR_METATYPE_UNKNOWN,
1408 EXTRACTOR_METATYPE_UNKNOWN, 1405 EXTRACTOR_METAFORMAT_UTF8,
1409 EXTRACTOR_METAFORMAT_UTF8, 1406 "text/plain",
1410 "text/plain", 1407 "PURCHASE_PRICE=PURCHASE_PRICE",
1411 "PURCHASE_PRICE=PURCHASE_PRICE", 1408 strlen ("PURCHASE_PRICE=PURCHASE_PRICE") + 1,
1412 strlen ("PURCHASE_PRICE=PURCHASE_PRICE") + 1, 1409 0
1413 0 1410 },
1414 }, 1411 {
1415 { 1412 EXTRACTOR_METATYPE_UNKNOWN,
1416 EXTRACTOR_METATYPE_UNKNOWN, 1413 EXTRACTOR_METAFORMAT_UTF8,
1417 EXTRACTOR_METAFORMAT_UTF8, 1414 "text/plain",
1418 "text/plain", 1415 "PURCHASE_CURRENCY=PURCHASE_CURRENCY",
1419 "PURCHASE_CURRENCY=PURCHASE_CURRENCY", 1416 strlen ("PURCHASE_CURRENCY=PURCHASE_CURRENCY") + 1,
1420 strlen ("PURCHASE_CURRENCY=PURCHASE_CURRENCY") + 1, 1417 0
1421 0 1418 },
1422 }, 1419 {
1423 { 1420 EXTRACTOR_METATYPE_ORIGINAL_TITLE,
1424 EXTRACTOR_METATYPE_ORIGINAL_TITLE, 1421 EXTRACTOR_METAFORMAT_UTF8,
1425 EXTRACTOR_METAFORMAT_UTF8, 1422 "text/plain",
1426 "text/plain", 1423 "ORIGINAL/TITLE",
1427 "ORIGINAL/TITLE", 1424 strlen ("ORIGINAL/TITLE") + 1,
1428 strlen ("ORIGINAL/TITLE") + 1, 1425 0
1429 0 1426 },
1430 }, 1427 {
1431 { 1428 EXTRACTOR_METATYPE_UNKNOWN,
1432 EXTRACTOR_METATYPE_UNKNOWN, 1429 EXTRACTOR_METAFORMAT_UTF8,
1433 EXTRACTOR_METAFORMAT_UTF8, 1430 "text/plain",
1434 "text/plain", 1431 "ORIGINAL/ARTIST/SORT_WITH=ORIGINAL/ARTIST/SORT_WITH",
1435 "ORIGINAL/ARTIST/SORT_WITH=ORIGINAL/ARTIST/SORT_WITH", 1432 strlen ("ORIGINAL/ARTIST/SORT_WITH=ORIGINAL/ARTIST/SORT_WITH") + 1,
1436 strlen ("ORIGINAL/ARTIST/SORT_WITH=ORIGINAL/ARTIST/SORT_WITH") + 1, 1433 0
1437 0 1434 },
1438 }, 1435 {
1439 { 1436 EXTRACTOR_METATYPE_ORIGINAL_ARTIST,
1440 EXTRACTOR_METATYPE_ORIGINAL_ARTIST, 1437 EXTRACTOR_METAFORMAT_UTF8,
1441 EXTRACTOR_METAFORMAT_UTF8, 1438 "text/plain",
1442 "text/plain", 1439 "ORIGINAL/ARTIST",
1443 "ORIGINAL/ARTIST", 1440 strlen ("ORIGINAL/ARTIST") + 1,
1444 strlen ("ORIGINAL/ARTIST") + 1, 1441 0
1445 0 1442 },
1446 }, 1443 {
1447 { 1444 EXTRACTOR_METATYPE_TRACK_NUMBER,
1448 EXTRACTOR_METATYPE_TRACK_NUMBER, 1445 EXTRACTOR_METAFORMAT_UTF8,
1449 EXTRACTOR_METAFORMAT_UTF8, 1446 "text/plain",
1450 "text/plain", 1447 "10",
1451 "10", 1448 strlen ("10") + 1,
1452 strlen ("10") + 1, 1449 0
1453 0 1450 },
1454 }, 1451 {
1455 { 1452 EXTRACTOR_METATYPE_COPYRIGHT,
1456 EXTRACTOR_METATYPE_COPYRIGHT, 1453 EXTRACTOR_METAFORMAT_UTF8,
1457 EXTRACTOR_METAFORMAT_UTF8, 1454 "text/plain",
1458 "text/plain", 1455 "COPYRIGHT",
1459 "COPYRIGHT", 1456 strlen ("COPYRIGHT") + 1,
1460 strlen ("COPYRIGHT") + 1, 1457 0
1461 0 1458 },
1462 }, 1459 {
1463 { 1460 EXTRACTOR_METATYPE_CONTACT_INFORMATION,
1464 EXTRACTOR_METATYPE_CONTACT_INFORMATION, 1461 EXTRACTOR_METAFORMAT_UTF8,
1465 EXTRACTOR_METAFORMAT_UTF8, 1462 "text/plain",
1466 "text/plain", 1463 "COPYRIGHT/EMAIL",
1467 "COPYRIGHT/EMAIL", 1464 strlen ("COPYRIGHT/EMAIL") + 1,
1468 strlen ("COPYRIGHT/EMAIL") + 1, 1465 0
1469 0 1466 },
1470 }, 1467 {
1471 { 1468 EXTRACTOR_METATYPE_CONTACT_INFORMATION,
1472 EXTRACTOR_METATYPE_CONTACT_INFORMATION, 1469 EXTRACTOR_METAFORMAT_UTF8,
1473 EXTRACTOR_METAFORMAT_UTF8, 1470 "text/plain",
1474 "text/plain", 1471 "COPYRIGHT/ADDRESS",
1475 "COPYRIGHT/ADDRESS", 1472 strlen ("COPYRIGHT/ADDRESS") + 1,
1476 strlen ("COPYRIGHT/ADDRESS") + 1, 1473 0
1477 0 1474 },
1478 }, 1475 {
1479 { 1476 EXTRACTOR_METATYPE_CREATION_TIME,
1480 EXTRACTOR_METATYPE_CREATION_TIME, 1477 EXTRACTOR_METAFORMAT_UTF8,
1481 EXTRACTOR_METAFORMAT_UTF8, 1478 "text/plain",
1482 "text/plain", 1479 "1999-01-01",
1483 "1999-01-01", 1480 strlen ("1999-01-01") + 1,
1484 strlen ("1999-01-01") + 1, 1481 0
1485 0 1482 },
1486 }, 1483 {
1487 { 1484 EXTRACTOR_METATYPE_COMMENT,
1488 EXTRACTOR_METATYPE_COMMENT, 1485 EXTRACTOR_METAFORMAT_UTF8,
1489 EXTRACTOR_METAFORMAT_UTF8, 1486 "text/plain",
1490 "text/plain", 1487 "The purpose of this file is to hold as many examples of Matroska tags as possible.",
1491 "The purpose of this file is to hold as many examples of Matroska tags as possible.", 1488 strlen (
1492 strlen ("The purpose of this file is to hold as many examples of Matroska tags as possible.") + 1, 1489 "The purpose of this file is to hold as many examples of Matroska tags as possible.")
1493 0 1490 + 1,
1494 }, 1491 0
1495 { 1492 },
1496 EXTRACTOR_METATYPE_COMPOSER, 1493 {
1497 EXTRACTOR_METAFORMAT_UTF8, 1494 EXTRACTOR_METATYPE_COMPOSER,
1498 "text/plain", 1495 EXTRACTOR_METAFORMAT_UTF8,
1499 "COMPOSER", 1496 "text/plain",
1500 strlen ("COMPOSER") + 1, 1497 "COMPOSER",
1501 0 1498 strlen ("COMPOSER") + 1,
1502 }, 1499 0
1503 { 1500 },
1504 EXTRACTOR_METATYPE_PERFORMER, 1501 {
1505 EXTRACTOR_METAFORMAT_UTF8, 1502 EXTRACTOR_METATYPE_PERFORMER,
1506 "text/plain", 1503 EXTRACTOR_METAFORMAT_UTF8,
1507 "ACCOMPANIMENT", 1504 "text/plain",
1508 strlen ("ACCOMPANIMENT") + 1, 1505 "ACCOMPANIMENT",
1509 0 1506 strlen ("ACCOMPANIMENT") + 1,
1510 }, 1507 0
1511 { 1508 },
1512 EXTRACTOR_METATYPE_PERFORMER, 1509 {
1513 EXTRACTOR_METAFORMAT_UTF8, 1510 EXTRACTOR_METATYPE_PERFORMER,
1514 "text/plain", 1511 EXTRACTOR_METAFORMAT_UTF8,
1515 "CONDUCTOR", 1512 "text/plain",
1516 strlen ("CONDUCTOR") + 1, 1513 "CONDUCTOR",
1517 0 1514 strlen ("CONDUCTOR") + 1,
1518 }, 1515 0
1519 { 1516 },
1520 EXTRACTOR_METATYPE_LYRICS, 1517 {
1521 EXTRACTOR_METAFORMAT_UTF8, 1518 EXTRACTOR_METATYPE_LYRICS,
1522 "text/plain", 1519 EXTRACTOR_METAFORMAT_UTF8,
1523 "LYRICS", 1520 "text/plain",
1524 strlen ("LYRICS") + 1, 1521 "LYRICS",
1525 0 1522 strlen ("LYRICS") + 1,
1526 }, 1523 0
1527 { 1524 },
1528 EXTRACTOR_METATYPE_ENCODED_BY, 1525 {
1529 EXTRACTOR_METAFORMAT_UTF8, 1526 EXTRACTOR_METATYPE_ENCODED_BY,
1530 "text/plain", 1527 EXTRACTOR_METAFORMAT_UTF8,
1531 "ENCODED_BY", 1528 "text/plain",
1532 strlen ("ENCODED_BY") + 1, 1529 "ENCODED_BY",
1533 0 1530 strlen ("ENCODED_BY") + 1,
1534 }, 1531 0
1535 { 1532 },
1536 EXTRACTOR_METATYPE_GENRE, 1533 {
1537 EXTRACTOR_METAFORMAT_UTF8, 1534 EXTRACTOR_METATYPE_GENRE,
1538 "text/plain", 1535 EXTRACTOR_METAFORMAT_UTF8,
1539 "GENRE", 1536 "text/plain",
1540 strlen ("GENRE") + 1, 1537 "GENRE",
1541 0 1538 strlen ("GENRE") + 1,
1542 }, 1539 0
1543 { 1540 },
1544 EXTRACTOR_METATYPE_DESCRIPTION, 1541 {
1545 EXTRACTOR_METAFORMAT_UTF8, 1542 EXTRACTOR_METATYPE_DESCRIPTION,
1546 "text/plain", 1543 EXTRACTOR_METAFORMAT_UTF8,
1547 "DESCRIPTION", 1544 "text/plain",
1548 strlen ("DESCRIPTION") + 1, 1545 "DESCRIPTION",
1549 0 1546 strlen ("DESCRIPTION") + 1,
1550 }, 1547 0
1551 { 1548 },
1552 EXTRACTOR_METATYPE_KEYWORDS, 1549 {
1553 EXTRACTOR_METAFORMAT_UTF8, 1550 EXTRACTOR_METATYPE_KEYWORDS,
1554 "text/plain", 1551 EXTRACTOR_METAFORMAT_UTF8,
1555 "KEYWORDS", 1552 "text/plain",
1556 strlen ("KEYWORDS") + 1, 1553 "KEYWORDS",
1557 0 1554 strlen ("KEYWORDS") + 1,
1558 }, 1555 0
1559 { 1556 },
1560 EXTRACTOR_METATYPE_LOCATION_NAME, 1557 {
1561 EXTRACTOR_METAFORMAT_UTF8, 1558 EXTRACTOR_METATYPE_LOCATION_NAME,
1562 "text/plain", 1559 EXTRACTOR_METAFORMAT_UTF8,
1563 "RECORDING_LOCATION", 1560 "text/plain",
1564 strlen ("RECORDING_LOCATION") + 1, 1561 "RECORDING_LOCATION",
1565 0 1562 strlen ("RECORDING_LOCATION") + 1,
1566 }, 1563 0
1567 { 1564 },
1568 EXTRACTOR_METATYPE_ENCODER, 1565 {
1569 EXTRACTOR_METAFORMAT_UTF8, 1566 EXTRACTOR_METATYPE_ENCODER,
1570 "text/plain", 1567 EXTRACTOR_METAFORMAT_UTF8,
1571 "ENCODER", 1568 "text/plain",
1572 strlen ("ENCODER") + 1, 1569 "ENCODER",
1573 0 1570 strlen ("ENCODER") + 1,
1574 }, 1571 0
1575 { 1572 },
1576 EXTRACTOR_METATYPE_ISRC, 1573 {
1577 EXTRACTOR_METAFORMAT_UTF8, 1574 EXTRACTOR_METATYPE_ISRC,
1578 "text/plain", 1575 EXTRACTOR_METAFORMAT_UTF8,
1579 "ISRC", 1576 "text/plain",
1580 strlen ("ISRC") + 1, 1577 "ISRC",
1581 0 1578 strlen ("ISRC") + 1,
1582 }, 1579 0
1583 { 1580 },
1584 EXTRACTOR_METATYPE_LICENSE, 1581 {
1585 EXTRACTOR_METAFORMAT_UTF8, 1582 EXTRACTOR_METATYPE_LICENSE,
1586 "text/plain", 1583 EXTRACTOR_METAFORMAT_UTF8,
1587 "LICENSE", 1584 "text/plain",
1588 strlen ("LICENSE") + 1, 1585 "LICENSE",
1589 0 1586 strlen ("LICENSE") + 1,
1590 }, 1587 0
1591 { 1588 },
1592 EXTRACTOR_METATYPE_CONTAINER_FORMAT, 1589 {
1593 EXTRACTOR_METAFORMAT_UTF8, 1590 EXTRACTOR_METATYPE_CONTAINER_FORMAT,
1594 "text/plain", 1591 EXTRACTOR_METAFORMAT_UTF8,
1595 "Matroska", 1592 "text/plain",
1596 strlen ("Matroska") + 1, 1593 "Matroska",
1597 0 1594 strlen ("Matroska") + 1,
1598 }, 1595 0
1599 { 1596 },
1600 EXTRACTOR_METATYPE_VIDEO_CODEC, 1597 {
1601 EXTRACTOR_METAFORMAT_UTF8, 1598 EXTRACTOR_METATYPE_VIDEO_CODEC,
1602 "text/plain", 1599 EXTRACTOR_METAFORMAT_UTF8,
1603 "Intel Video 4", 1600 "text/plain",
1604 strlen ("Intel Video 4") + 1, 1601 "Intel Video 4",
1605 0 1602 strlen ("Intel Video 4") + 1,
1606 }, 1603 0
1607 { 1604 },
1608 EXTRACTOR_METATYPE_VIDEO_LANGUAGE, 1605 {
1609 EXTRACTOR_METAFORMAT_UTF8, 1606 EXTRACTOR_METATYPE_VIDEO_LANGUAGE,
1610 "text/plain", 1607 EXTRACTOR_METAFORMAT_UTF8,
1611 "it", 1608 "text/plain",
1612 strlen ("it") + 1, 1609 "it",
1613 0 1610 strlen ("it") + 1,
1614 }, 1611 0
1615 { 1612 },
1616 EXTRACTOR_METATYPE_VIDEO_DIMENSIONS, 1613 {
1617 EXTRACTOR_METAFORMAT_UTF8, 1614 EXTRACTOR_METATYPE_VIDEO_DIMENSIONS,
1618 "text/plain", 1615 EXTRACTOR_METAFORMAT_UTF8,
1619 "256x240", 1616 "text/plain",
1620 strlen ("256x240") + 1, 1617 "256x240",
1621 0 1618 strlen ("256x240") + 1,
1622 }, 1619 0
1623 { 1620 },
1624 EXTRACTOR_METATYPE_FRAME_RATE, 1621 {
1625 EXTRACTOR_METAFORMAT_UTF8, 1622 EXTRACTOR_METATYPE_FRAME_RATE,
1626 "text/plain", 1623 EXTRACTOR_METAFORMAT_UTF8,
1627 "35/1", 1624 "text/plain",
1628 strlen ("35/1") + 1, 1625 "35/1",
1629 0 1626 strlen ("35/1") + 1,
1630 }, 1627 0
1631 { 1628 },
1632 EXTRACTOR_METATYPE_PIXEL_ASPECT_RATIO, 1629 {
1633 EXTRACTOR_METAFORMAT_UTF8, 1630 EXTRACTOR_METATYPE_PIXEL_ASPECT_RATIO,
1634 "text/plain", 1631 EXTRACTOR_METAFORMAT_UTF8,
1635 "1/1", 1632 "text/plain",
1636 strlen ("1/1") + 1, 1633 "1/1",
1637 0 1634 strlen ("1/1") + 1,
1638 }, 1635 0
1639 { 0, 0, NULL, NULL, 0, -1 } 1636 },
1640 }; 1637 { 0, 0, NULL, NULL, 0, -1 }
1641 struct ProblemSet patched_ps[] = 1638 };
1642 { 1639 struct ProblemSet patched_ps[] = {
1643 { "testdata/matroska_flame.mkv", matroska_flame_patched_sol }, 1640 { "testdata/matroska_flame.mkv", matroska_flame_patched_sol },
1644 { NULL, NULL } 1641 { NULL, NULL }
1645 }; 1642 };
1646 g_print ("Running mkv test on GStreamer, assuming old version:\n"); 1643 g_print ("Running mkv test on GStreamer, assuming old version:\n");
1647 result_stock = (0 == ET_main ("gstreamer", stock_ps)); 1644 result_stock = (0 == ET_main ("gstreamer", stock_ps));
1648 g_print ("Old GStreamer test result: %s\n", result_stock == 0 ? "OK" : "FAILED"); 1645 g_print ("Old GStreamer test result: %s\n", result_stock == 0 ? "OK" :
1646 "FAILED");
1649 g_print ("Running mkv test on GStreamer, assuming new version:\n"); 1647 g_print ("Running mkv test on GStreamer, assuming new version:\n");
1650 result_patched = (0 == ET_main ("gstreamer", patched_ps)); 1648 result_patched = (0 == ET_main ("gstreamer", patched_ps));
1651 g_print ("New GStreamer test result: %s\n", result_patched == 0 ? "OK" : "FAILED"); 1649 g_print ("New GStreamer test result: %s\n", result_patched == 0 ? "OK" :
1650 "FAILED");
1652 if ((! result_stock) && (! result_patched)) 1651 if ((! result_stock) && (! result_patched))
1653 result++; 1652 result++;
1654 } 1653 }
1655 g_object_unref (dc); 1654 g_object_unref (dc);
1656 if (0 != result) 1655 if (0 != result)
1657 { 1656 {
1658 fprintf (stderr, 1657 fprintf (stderr,
1659 "gstreamer library did not work perfectly --- consider updating it.\n"); 1658 "gstreamer library did not work perfectly --- consider updating it.\n");
1660 /* do not fail hard, as we know many users have outdated gstreamer packages */ 1659 /* do not fail hard, as we know many users have outdated gstreamer packages */
1661 result = 0; 1660 result = 0;
1662 } 1661 }
1663 return result; 1662 return result;
1664} 1663}
1665 1664
1665
1666/* end of test_gstreamer.c */ 1666/* end of test_gstreamer.c */
diff --git a/src/plugins/test_html.c b/src/plugins/test_html.c
index e459eec..80d4a37 100644
--- a/src/plugins/test_html.c
+++ b/src/plugins/test_html.c
@@ -36,89 +36,88 @@
36int 36int
37main (int argc, char *argv[]) 37main (int argc, char *argv[])
38{ 38{
39 struct SolutionData html_grothoff_sol[] = 39 struct SolutionData html_grothoff_sol[] = {
40 { 40 {
41 { 41 EXTRACTOR_METATYPE_TITLE,
42 EXTRACTOR_METATYPE_TITLE, 42 EXTRACTOR_METAFORMAT_UTF8,
43 EXTRACTOR_METAFORMAT_UTF8, 43 "text/plain",
44 "text/plain", 44 "Christian Grothoff",
45 "Christian Grothoff", 45 strlen ("Christian Grothoff") + 1,
46 strlen ("Christian Grothoff") + 1, 46 0
47 0 47 },
48 },
49 {
50 EXTRACTOR_METATYPE_DESCRIPTION,
51 EXTRACTOR_METAFORMAT_UTF8,
52 "text/plain",
53 "Homepage of Christian Grothoff",
54 strlen ("Homepage of Christian Grothoff") + 1,
55 0
56 },
57 {
58 EXTRACTOR_METATYPE_AUTHOR_NAME,
59 EXTRACTOR_METAFORMAT_UTF8,
60 "text/plain",
61 "Christian Grothoff",
62 strlen ("Christian Grothoff") + 1,
63 0
64 },
65 {
66 EXTRACTOR_METATYPE_KEYWORDS,
67 EXTRACTOR_METAFORMAT_UTF8,
68 "text/plain",
69 "Christian,Grothoff",
70 strlen ("Christian,Grothoff") + 1,
71 0
72 },
73 {
74 EXTRACTOR_METATYPE_TITLE,
75 EXTRACTOR_METAFORMAT_UTF8,
76 "text/plain",
77 "Welcome to Christian Grothoff",
78 strlen ("Welcome to Christian Grothoff") + 1,
79 0
80 },
81 {
82 EXTRACTOR_METATYPE_LANGUAGE,
83 EXTRACTOR_METAFORMAT_UTF8,
84 "text/plain",
85 "en",
86 strlen ("en") + 1,
87 0
88 },
89 {
90 EXTRACTOR_METATYPE_PUBLISHER,
91 EXTRACTOR_METAFORMAT_UTF8,
92 "text/plain",
93 "Christian Grothoff",
94 strlen ("Christian Grothoff") + 1,
95 0
96 },
97 {
98 EXTRACTOR_METATYPE_UNKNOWN_DATE,
99 EXTRACTOR_METAFORMAT_UTF8,
100 "text/plain",
101 "2000-08-20",
102 strlen ("2000-08-20") + 1,
103 0
104 },
105 {
106 EXTRACTOR_METATYPE_RIGHTS,
107 EXTRACTOR_METAFORMAT_UTF8,
108 "text/plain",
109 "(C) 2000 by Christian Grothoff",
110 strlen ("(C) 2000 by Christian Grothoff") + 1,
111 0
112 },
113 { 0, 0, NULL, NULL, 0, -1 }
114 };
115 struct ProblemSet ps[] =
116 { 48 {
117 { "testdata/html_grothoff.html", 49 EXTRACTOR_METATYPE_DESCRIPTION,
118 html_grothoff_sol }, 50 EXTRACTOR_METAFORMAT_UTF8,
119 { NULL, NULL } 51 "text/plain",
120 }; 52 "Homepage of Christian Grothoff",
53 strlen ("Homepage of Christian Grothoff") + 1,
54 0
55 },
56 {
57 EXTRACTOR_METATYPE_AUTHOR_NAME,
58 EXTRACTOR_METAFORMAT_UTF8,
59 "text/plain",
60 "Christian Grothoff",
61 strlen ("Christian Grothoff") + 1,
62 0
63 },
64 {
65 EXTRACTOR_METATYPE_KEYWORDS,
66 EXTRACTOR_METAFORMAT_UTF8,
67 "text/plain",
68 "Christian,Grothoff",
69 strlen ("Christian,Grothoff") + 1,
70 0
71 },
72 {
73 EXTRACTOR_METATYPE_TITLE,
74 EXTRACTOR_METAFORMAT_UTF8,
75 "text/plain",
76 "Welcome to Christian Grothoff",
77 strlen ("Welcome to Christian Grothoff") + 1,
78 0
79 },
80 {
81 EXTRACTOR_METATYPE_LANGUAGE,
82 EXTRACTOR_METAFORMAT_UTF8,
83 "text/plain",
84 "en",
85 strlen ("en") + 1,
86 0
87 },
88 {
89 EXTRACTOR_METATYPE_PUBLISHER,
90 EXTRACTOR_METAFORMAT_UTF8,
91 "text/plain",
92 "Christian Grothoff",
93 strlen ("Christian Grothoff") + 1,
94 0
95 },
96 {
97 EXTRACTOR_METATYPE_UNKNOWN_DATE,
98 EXTRACTOR_METAFORMAT_UTF8,
99 "text/plain",
100 "2000-08-20",
101 strlen ("2000-08-20") + 1,
102 0
103 },
104 {
105 EXTRACTOR_METATYPE_RIGHTS,
106 EXTRACTOR_METAFORMAT_UTF8,
107 "text/plain",
108 "(C) 2000 by Christian Grothoff",
109 strlen ("(C) 2000 by Christian Grothoff") + 1,
110 0
111 },
112 { 0, 0, NULL, NULL, 0, -1 }
113 };
114 struct ProblemSet ps[] = {
115 { "testdata/html_grothoff.html",
116 html_grothoff_sol },
117 { NULL, NULL }
118 };
121 return ET_main ("html", ps); 119 return ET_main ("html", ps);
122} 120}
123 121
122
124/* end of test_html.c */ 123/* end of test_html.c */
diff --git a/src/plugins/test_it.c b/src/plugins/test_it.c
index c729a9a..408b009 100644
--- a/src/plugins/test_it.c
+++ b/src/plugins/test_it.c
@@ -36,41 +36,40 @@
36int 36int
37main (int argc, char *argv[]) 37main (int argc, char *argv[])
38{ 38{
39 struct SolutionData it_dawn_sol[] = 39 struct SolutionData it_dawn_sol[] = {
40 { 40 {
41 { 41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METATYPE_MIMETYPE, 42 EXTRACTOR_METAFORMAT_UTF8,
43 EXTRACTOR_METAFORMAT_UTF8, 43 "text/plain",
44 "text/plain", 44 "audio/x-mod",
45 "audio/x-mod", 45 strlen ("audio/x-mod") + 1,
46 strlen ("audio/x-mod") + 1, 46 0
47 0 47 },
48 },
49 {
50 EXTRACTOR_METATYPE_TITLE,
51 EXTRACTOR_METAFORMAT_C_STRING,
52 "text/plain",
53 "Dawn",
54 strlen ("Dawn") + 1,
55 0
56 },
57 {
58 EXTRACTOR_METATYPE_FORMAT_VERSION,
59 EXTRACTOR_METAFORMAT_C_STRING,
60 "text/plain",
61 "1.2",
62 strlen ("1.2") + 1,
63 0
64 },
65 { 0, 0, NULL, NULL, 0, -1 }
66 };
67 struct ProblemSet ps[] =
68 { 48 {
69 { "testdata/it_dawn.it", 49 EXTRACTOR_METATYPE_TITLE,
70 it_dawn_sol }, 50 EXTRACTOR_METAFORMAT_C_STRING,
71 { NULL, NULL } 51 "text/plain",
72 }; 52 "Dawn",
53 strlen ("Dawn") + 1,
54 0
55 },
56 {
57 EXTRACTOR_METATYPE_FORMAT_VERSION,
58 EXTRACTOR_METAFORMAT_C_STRING,
59 "text/plain",
60 "1.2",
61 strlen ("1.2") + 1,
62 0
63 },
64 { 0, 0, NULL, NULL, 0, -1 }
65 };
66 struct ProblemSet ps[] = {
67 { "testdata/it_dawn.it",
68 it_dawn_sol },
69 { NULL, NULL }
70 };
73 return ET_main ("it", ps); 71 return ET_main ("it", ps);
74} 72}
75 73
74
76/* end of test_it.c */ 75/* end of test_it.c */
diff --git a/src/plugins/test_jpeg.c b/src/plugins/test_jpeg.c
index f36c7ed..a8d693e 100644
--- a/src/plugins/test_jpeg.c
+++ b/src/plugins/test_jpeg.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the JPEG testcase. 30 * Main function for the JPEG testcase.
32 * 31 *
@@ -37,41 +36,40 @@
37int 36int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 struct SolutionData jpeg_image_sol[] = 39 struct SolutionData jpeg_image_sol[] = {
40 {
41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METAFORMAT_UTF8,
43 "text/plain",
44 "image/jpeg",
45 strlen ("image/jpeg") + 1,
46 0
47 },
41 { 48 {
42 { 49 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
43 EXTRACTOR_METATYPE_MIMETYPE, 50 EXTRACTOR_METAFORMAT_UTF8,
44 EXTRACTOR_METAFORMAT_UTF8, 51 "text/plain",
45 "text/plain", 52 "3x3",
46 "image/jpeg", 53 strlen ("3x3") + 1,
47 strlen ("image/jpeg") + 1, 54 0
48 0 55 },
49 },
50 {
51 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
52 EXTRACTOR_METAFORMAT_UTF8,
53 "text/plain",
54 "3x3",
55 strlen ("3x3") + 1,
56 0
57 },
58 {
59 EXTRACTOR_METATYPE_COMMENT,
60 EXTRACTOR_METAFORMAT_C_STRING,
61 "text/plain",
62 "(C) 2001 by Christian Grothoff, using gimp 1.2 1",
63 strlen ("(C) 2001 by Christian Grothoff, using gimp 1.2 1"),
64 0
65 },
66 { 0, 0, NULL, NULL, 0, -1 }
67 };
68 struct ProblemSet ps[] =
69 { 56 {
70 { "testdata/jpeg_image.jpg", 57 EXTRACTOR_METATYPE_COMMENT,
71 jpeg_image_sol }, 58 EXTRACTOR_METAFORMAT_C_STRING,
72 { NULL, NULL } 59 "text/plain",
73 }; 60 "(C) 2001 by Christian Grothoff, using gimp 1.2 1",
61 strlen ("(C) 2001 by Christian Grothoff, using gimp 1.2 1"),
62 0
63 },
64 { 0, 0, NULL, NULL, 0, -1 }
65 };
66 struct ProblemSet ps[] = {
67 { "testdata/jpeg_image.jpg",
68 jpeg_image_sol },
69 { NULL, NULL }
70 };
74 return ET_main ("jpeg", ps); 71 return ET_main ("jpeg", ps);
75} 72}
76 73
74
77/* end of test_jpeg.c */ 75/* end of test_jpeg.c */
diff --git a/src/plugins/test_lib.c b/src/plugins/test_lib.c
index ebc8f04..efbe2cf 100644
--- a/src/plugins/test_lib.c
+++ b/src/plugins/test_lib.c
@@ -38,56 +38,56 @@
38 * @param data hello world or good bye 38 * @param data hello world or good bye
39 * @param data_len number of bytes in data 39 * @param data_len number of bytes in data
40 * @return 0 (always) 40 * @return 0 (always)
41 */ 41 */
42static int 42static int
43process_replies (void *cls, 43process_replies (void *cls,
44 const char *plugin_name, 44 const char *plugin_name,
45 enum EXTRACTOR_MetaType type, 45 enum EXTRACTOR_MetaType type,
46 enum EXTRACTOR_MetaFormat format, 46 enum EXTRACTOR_MetaFormat format,
47 const char *data_mime_type, 47 const char *data_mime_type,
48 const char *data, 48 const char *data,
49 size_t data_len) 49 size_t data_len)
50{ 50{
51 struct SolutionData *sd = cls; 51 struct SolutionData *sd = cls;
52 unsigned int i; 52 unsigned int i;
53 53
54 for (i=0; -1 != sd[i].solved; i++) 54 for (i = 0; -1 != sd[i].solved; i++)
55 {
56 if ( (0 != sd[i].solved) ||
57 (sd[i].type != type) ||
58 (sd[i].format != format) )
59 continue;
60 if ( (EXTRACTOR_METAFORMAT_BINARY != format) &&
61 ( (sd[i].data_len != data_len) ||
62 (0 != memcmp (sd[i].data, data, data_len)) ) )
63 continue;
64 if ( (EXTRACTOR_METAFORMAT_BINARY == format) &&
65 ( (sd[i].data_len > data_len) ||
66 (0 != memcmp (sd[i].data, data, sd[i].data_len)) ) )
67 continue;
68
69 if (NULL != sd[i].data_mime_type)
55 { 70 {
56 if ( (0 != sd[i].solved) || 71 if (NULL == data_mime_type)
57 (sd[i].type != type) || 72 continue;
58 (sd[i].format != format) ) 73 if (0 != strcmp (sd[i].data_mime_type, data_mime_type))
59 continue; 74 continue;
60 if ( (EXTRACTOR_METAFORMAT_BINARY != format) &&
61 ( (sd[i].data_len != data_len) ||
62 (0 != memcmp (sd[i].data, data, data_len)) ) )
63 continue;
64 if ( (EXTRACTOR_METAFORMAT_BINARY == format) &&
65 ( (sd[i].data_len > data_len) ||
66 (0 != memcmp (sd[i].data, data, sd[i].data_len)) ) )
67 continue;
68
69 if (NULL != sd[i].data_mime_type)
70 {
71 if (NULL == data_mime_type)
72 continue;
73 if (0 != strcmp (sd[i].data_mime_type, data_mime_type))
74 continue;
75 }
76 else
77 {
78 if (NULL != data_mime_type)
79 continue;
80 }
81 sd[i].solved = 1;
82 return 0;
83 } 75 }
84 fprintf (stderr, 76 else
85 "Got additional meta data of type %d and format %d with value `%.*s' from plugin `%s'\n", 77 {
86 type, 78 if (NULL != data_mime_type)
87 format, 79 continue;
88 (int) data_len, 80 }
89 data, 81 sd[i].solved = 1;
90 plugin_name); 82 return 0;
83 }
84 fprintf (stderr,
85 "Got additional meta data of type %d and format %d with value `%.*s' from plugin `%s'\n",
86 type,
87 format,
88 (int) data_len,
89 data,
90 plugin_name);
91 return 0; 91 return 0;
92} 92}
93 93
@@ -97,11 +97,11 @@ process_replies (void *cls,
97 * 97 *
98 * @param plugin_name name of the plugin to load 98 * @param plugin_name name of the plugin to load
99 * @param ps array of problems the plugin should solve; 99 * @param ps array of problems the plugin should solve;
100 * NULL in filename terminates the array. 100 * NULL in filename terminates the array.
101 * @param opt options to use for loading the plugin 101 * @param opt options to use for loading the plugin
102 * @return 0 on success, 1 on failure 102 * @return 0 on success, 1 on failure
103 */ 103 */
104static int 104static int
105run (const char *plugin_name, 105run (const char *plugin_name,
106 struct ProblemSet *ps, 106 struct ProblemSet *ps,
107 enum EXTRACTOR_Options opt) 107 enum EXTRACTOR_Options opt)
@@ -111,32 +111,33 @@ run (const char *plugin_name,
111 unsigned int j; 111 unsigned int j;
112 int ret; 112 int ret;
113 113
114 pl = EXTRACTOR_plugin_add_config (NULL, 114 pl = EXTRACTOR_plugin_add_config (NULL,
115 plugin_name, 115 plugin_name,
116 opt); 116 opt);
117 for (i=0; NULL != ps[i].filename; i++) 117 for (i = 0; NULL != ps[i].filename; i++)
118 EXTRACTOR_extract (pl, 118 EXTRACTOR_extract (pl,
119 ps[i].filename, 119 ps[i].filename,
120 NULL, 0, 120 NULL, 0,
121 &process_replies, 121 &process_replies,
122 ps[i].solution); 122 ps[i].solution);
123 EXTRACTOR_plugin_remove_all (pl); 123 EXTRACTOR_plugin_remove_all (pl);
124 ret = 0; 124 ret = 0;
125 for (i=0; NULL != ps[i].filename; i++) 125 for (i = 0; NULL != ps[i].filename; i++)
126 for (j=0; -1 != ps[i].solution[j].solved; j++) 126 for (j = 0; -1 != ps[i].solution[j].solved; j++)
127 if (0 == ps[i].solution[j].solved) 127 if (0 == ps[i].solution[j].solved)
128 { 128 {
129 ret = 1; 129 ret = 1;
130 fprintf (stderr, 130 fprintf (stderr,
131 "Did not get expected meta data of type %d and format %d with value `%.*s' from plugin `%s'\n", 131 "Did not get expected meta data of type %d and format %d with value `%.*s' from plugin `%s'\n",
132 ps[i].solution[j].type, 132 ps[i].solution[j].type,
133 ps[i].solution[j].format, 133 ps[i].solution[j].format,
134 (int) ps[i].solution[j].data_len, 134 (int) ps[i].solution[j].data_len,
135 ps[i].solution[j].data, 135 ps[i].solution[j].data,
136 plugin_name); 136 plugin_name);
137 } 137 }
138 else 138 else
139 ps[i].solution[j].solved = 0; /* reset for next round */ 139 ps[i].solution[j].solved = 0;
140 /* reset for next round */
140 return ret; 141 return ret;
141} 142}
142 143
@@ -146,22 +147,22 @@ run (const char *plugin_name,
146 * 147 *
147 * @param plugin_name name of the plugin to load 148 * @param plugin_name name of the plugin to load
148 * @param ps array of problems the plugin should solve; 149 * @param ps array of problems the plugin should solve;
149 * NULL in filename terminates the array. 150 * NULL in filename terminates the array.
150 * @return 0 on success, 1 on failure 151 * @return 0 on success, 1 on failure
151 */ 152 */
152int 153int
153ET_main (const char *plugin_name, 154ET_main (const char *plugin_name,
154 struct ProblemSet *ps) 155 struct ProblemSet *ps)
155{ 156{
156 int ret; 157 int ret;
157 158
158 /* change environment to find plugins which may not yet be 159 /* change environment to find plugins which may not yet be
159 not installed but should be in the current directory (or .libs) 160 not installed but should be in the current directory (or .libs)
160 on 'make check' */ 161 on 'make check' */
161 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/")) 162 if (0 != putenv ("LIBEXTRACTOR_PREFIX=." PATH_SEPARATOR_STR ".libs/"))
162 fprintf (stderr, 163 fprintf (stderr,
163 "Failed to update my environment, plugin loading may fail: %s\n", 164 "Failed to update my environment, plugin loading may fail: %s\n",
164 strerror (errno)); 165 strerror (errno));
165 ret = run (plugin_name, ps, EXTRACTOR_OPTION_DEFAULT_POLICY); 166 ret = run (plugin_name, ps, EXTRACTOR_OPTION_DEFAULT_POLICY);
166 if (0 != ret) 167 if (0 != ret)
167 return ret; 168 return ret;
diff --git a/src/plugins/test_lib.h b/src/plugins/test_lib.h
index 05bf35d..9400314 100644
--- a/src/plugins/test_lib.h
+++ b/src/plugins/test_lib.h
@@ -67,7 +67,7 @@ struct SolutionData
67 67
68 68
69/** 69/**
70 * Set of problems 70 * Set of problems
71 */ 71 */
72struct ProblemSet 72struct ProblemSet
73{ 73{
@@ -90,11 +90,11 @@ struct ProblemSet
90 * 90 *
91 * @param plugin_name name of the plugin to load 91 * @param plugin_name name of the plugin to load
92 * @param ps array of problems the plugin should solve; 92 * @param ps array of problems the plugin should solve;
93 * NULL in filename terminates the array. 93 * NULL in filename terminates the array.
94 * @return 0 on success, 1 on failure 94 * @return 0 on success, 1 on failure
95 */ 95 */
96int 96int
97ET_main (const char *plugin_name, 97ET_main (const char *plugin_name,
98 struct ProblemSet *ps); 98 struct ProblemSet *ps);
99 99
100#endif 100#endif
diff --git a/src/plugins/test_man.c b/src/plugins/test_man.c
index 026a6ce..73b02fc 100644
--- a/src/plugins/test_man.c
+++ b/src/plugins/test_man.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the MAN testcase. 30 * Main function for the MAN testcase.
32 * 31 *
@@ -37,49 +36,48 @@
37int 36int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 struct SolutionData man_extract_sol[] = 39 struct SolutionData man_extract_sol[] = {
40 {
41 EXTRACTOR_METATYPE_TITLE,
42 EXTRACTOR_METAFORMAT_UTF8,
43 "text/plain",
44 "EXTRACT",
45 strlen ("EXTRACT") + 1,
46 0
47 },
41 { 48 {
42 { 49 EXTRACTOR_METATYPE_SECTION,
43 EXTRACTOR_METATYPE_TITLE, 50 EXTRACTOR_METAFORMAT_UTF8,
44 EXTRACTOR_METAFORMAT_UTF8, 51 "text/plain",
45 "text/plain", 52 _ ("Commands"),
46 "EXTRACT", 53 strlen (_ ("Commands")) + 1,
47 strlen ("EXTRACT") + 1, 54 0
48 0 55 },
49 },
50 {
51 EXTRACTOR_METATYPE_SECTION,
52 EXTRACTOR_METAFORMAT_UTF8,
53 "text/plain",
54 _("Commands"),
55 strlen (_("Commands")) + 1,
56 0
57 },
58 {
59 EXTRACTOR_METATYPE_MODIFICATION_DATE,
60 EXTRACTOR_METAFORMAT_UTF8,
61 "text/plain",
62 "Aug 7, 2012",
63 strlen ("Aug 7, 2012") + 1,
64 0
65 },
66 {
67 EXTRACTOR_METATYPE_SOURCE,
68 EXTRACTOR_METAFORMAT_UTF8,
69 "text/plain",
70 _("libextractor 0.7.0"),
71 strlen (_("libextractor 0.7.0")) + 1,
72 0
73 },
74 { 0, 0, NULL, NULL, 0, -1 }
75 };
76 struct ProblemSet ps[] =
77 { 56 {
78 { "testdata/man_extract.1", 57 EXTRACTOR_METATYPE_MODIFICATION_DATE,
79 man_extract_sol }, 58 EXTRACTOR_METAFORMAT_UTF8,
80 { NULL, NULL } 59 "text/plain",
81 }; 60 "Aug 7, 2012",
61 strlen ("Aug 7, 2012") + 1,
62 0
63 },
64 {
65 EXTRACTOR_METATYPE_SOURCE,
66 EXTRACTOR_METAFORMAT_UTF8,
67 "text/plain",
68 _ ("libextractor 0.7.0"),
69 strlen (_ ("libextractor 0.7.0")) + 1,
70 0
71 },
72 { 0, 0, NULL, NULL, 0, -1 }
73 };
74 struct ProblemSet ps[] = {
75 { "testdata/man_extract.1",
76 man_extract_sol },
77 { NULL, NULL }
78 };
82 return ET_main ("man", ps); 79 return ET_main ("man", ps);
83} 80}
84 81
82
85/* end of test_man.c */ 83/* end of test_man.c */
diff --git a/src/plugins/test_midi.c b/src/plugins/test_midi.c
index 4191f96..61438ab 100644
--- a/src/plugins/test_midi.c
+++ b/src/plugins/test_midi.c
@@ -36,57 +36,56 @@
36int 36int
37main (int argc, char *argv[]) 37main (int argc, char *argv[])
38{ 38{
39 struct SolutionData midi_dth_sol[] = 39 struct SolutionData midi_dth_sol[] = {
40 { 40 {
41 { 41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METATYPE_MIMETYPE, 42 EXTRACTOR_METAFORMAT_UTF8,
43 EXTRACTOR_METAFORMAT_UTF8, 43 "text/plain",
44 "text/plain", 44 "audio/midi",
45 "audio/midi", 45 strlen ("audio/midi") + 1,
46 strlen ("audio/midi") + 1, 46 0
47 0 47 },
48 },
49 {
50 EXTRACTOR_METATYPE_COPYRIGHT,
51 EXTRACTOR_METAFORMAT_UTF8,
52 "text/plain",
53 "(c) 2012 d-o-o",
54 strlen ("(c) 2012 d-o-o"),
55 0
56 },
57 {
58 EXTRACTOR_METATYPE_TITLE,
59 EXTRACTOR_METAFORMAT_UTF8,
60 "text/plain",
61 "Tage wie diese T2",
62 strlen ("Tage wie diese T2"),
63 0
64 },
65 {
66 EXTRACTOR_METATYPE_COMMENT,
67 EXTRACTOR_METAFORMAT_UTF8,
68 "text/plain",
69 "XFhd:::Rock:8 Beat:1:m1:-:-:-:-:DD",
70 strlen ("XFhd:::Rock:8 Beat:1:m1:-:-:-:-:DD"),
71 0
72 },
73 {
74 EXTRACTOR_METATYPE_COMMENT,
75 EXTRACTOR_METAFORMAT_UTF8,
76 "text/plain",
77 "XFln:L1:Tage wie diese:von Holst:von Holst:-:Toten Hosen:DD",
78 strlen ("XFln:L1:Tage wie diese:von Holst:von Holst:-:Toten Hosen:DD"),
79 0
80 },
81 { 0, 0, NULL, NULL, 0, -1 }
82 };
83 struct ProblemSet ps[] =
84 { 48 {
85 { "testdata/midi_dth.mid", 49 EXTRACTOR_METATYPE_COPYRIGHT,
86 midi_dth_sol }, 50 EXTRACTOR_METAFORMAT_UTF8,
87 { NULL, NULL } 51 "text/plain",
88 }; 52 "(c) 2012 d-o-o",
53 strlen ("(c) 2012 d-o-o"),
54 0
55 },
56 {
57 EXTRACTOR_METATYPE_TITLE,
58 EXTRACTOR_METAFORMAT_UTF8,
59 "text/plain",
60 "Tage wie diese T2",
61 strlen ("Tage wie diese T2"),
62 0
63 },
64 {
65 EXTRACTOR_METATYPE_COMMENT,
66 EXTRACTOR_METAFORMAT_UTF8,
67 "text/plain",
68 "XFhd:::Rock:8 Beat:1:m1:-:-:-:-:DD",
69 strlen ("XFhd:::Rock:8 Beat:1:m1:-:-:-:-:DD"),
70 0
71 },
72 {
73 EXTRACTOR_METATYPE_COMMENT,
74 EXTRACTOR_METAFORMAT_UTF8,
75 "text/plain",
76 "XFln:L1:Tage wie diese:von Holst:von Holst:-:Toten Hosen:DD",
77 strlen ("XFln:L1:Tage wie diese:von Holst:von Holst:-:Toten Hosen:DD"),
78 0
79 },
80 { 0, 0, NULL, NULL, 0, -1 }
81 };
82 struct ProblemSet ps[] = {
83 { "testdata/midi_dth.mid",
84 midi_dth_sol },
85 { NULL, NULL }
86 };
89 return ET_main ("midi", ps); 87 return ET_main ("midi", ps);
90} 88}
91 89
90
92/* end of test_midi.c */ 91/* end of test_midi.c */
diff --git a/src/plugins/test_mime.c b/src/plugins/test_mime.c
index e55b153..98e0586 100644
--- a/src/plugins/test_mime.c
+++ b/src/plugins/test_mime.c
@@ -40,70 +40,64 @@ main (int argc, char *argv[])
40 int result = 0; 40 int result = 0;
41 int test_result; 41 int test_result;
42 int test_result_around_19, test_result_around_22; 42 int test_result_around_19, test_result_around_22;
43 struct SolutionData courseclear_file_around_19_sol[] = 43 struct SolutionData courseclear_file_around_19_sol[] = {
44 { 44 {
45 { 45 EXTRACTOR_METATYPE_MIMETYPE,
46 EXTRACTOR_METATYPE_MIMETYPE, 46 EXTRACTOR_METAFORMAT_UTF8,
47 EXTRACTOR_METAFORMAT_UTF8, 47 "text/plain",
48 "text/plain", 48 /* not sure which is the exact version, but old ones do
49 /* not sure which is the exact version, but old ones do 49 not even define MAGIC_VERSION, so this is approximately
50 not even define MAGIC_VERSION, so this is approximately 50 right. Users where this tests fail should report
51 right. Users where this tests fail should report 51 their version number from "magic.h" so we can adjust
52 their version number from "magic.h" so we can adjust 52 if necessary. */
53 if necessary. */
54#ifdef MAGIC_VERSION 53#ifdef MAGIC_VERSION
55 "audio/ogg", 54 "audio/ogg",
56 strlen ("audio/ogg") + 1, 55 strlen ("audio/ogg") + 1,
57#else 56#else
58 "application/ogg", 57 "application/ogg",
59 strlen ("application/ogg") + 1, 58 strlen ("application/ogg") + 1,
60#endif 59#endif
61 0 60 0
62 }, 61 },
63 { 0, 0, NULL, NULL, 0, -1 } 62 { 0, 0, NULL, NULL, 0, -1 }
64 }; 63 };
65 struct SolutionData courseclear_file_around_22_sol[] = 64 struct SolutionData courseclear_file_around_22_sol[] = {
66 { 65 {
67 { 66 EXTRACTOR_METATYPE_MIMETYPE,
68 EXTRACTOR_METATYPE_MIMETYPE, 67 EXTRACTOR_METAFORMAT_UTF8,
69 EXTRACTOR_METAFORMAT_UTF8, 68 "text/plain",
70 "text/plain", 69 "audio/ogg",
71 "audio/ogg", 70 strlen ("audio/ogg") + 1,
72 strlen ("audio/ogg") + 1, 71 0
73 0 72 },
74 }, 73 { 0, 0, NULL, NULL, 0, -1 }
75 { 0, 0, NULL, NULL, 0, -1 } 74 };
76 }; 75 struct SolutionData gif_image_sol[] = {
77 struct SolutionData gif_image_sol[] =
78 { 76 {
79 { 77 EXTRACTOR_METATYPE_MIMETYPE,
80 EXTRACTOR_METATYPE_MIMETYPE, 78 EXTRACTOR_METAFORMAT_UTF8,
81 EXTRACTOR_METAFORMAT_UTF8, 79 "text/plain",
82 "text/plain", 80 "image/gif",
83 "image/gif", 81 strlen ("image/gif") + 1,
84 strlen ("image/gif") + 1, 82 0
85 0 83 },
86 }, 84 { 0, 0, NULL, NULL, 0, -1 }
87 { 0, 0, NULL, NULL, 0, -1 } 85 };
88 }; 86 struct ProblemSet ps_gif[] = {
89 struct ProblemSet ps_gif[] = 87 { "testdata/gif_image.gif",
90 { 88 gif_image_sol },
91 { "testdata/gif_image.gif", 89 { NULL, NULL }
92 gif_image_sol }, 90 };
93 { NULL, NULL } 91 struct ProblemSet ps_ogg_around_19[] = {
94 }; 92 { "testdata/ogg_courseclear.ogg",
95 struct ProblemSet ps_ogg_around_19[] = 93 courseclear_file_around_19_sol },
96 { 94 { NULL, NULL }
97 { "testdata/ogg_courseclear.ogg", 95 };
98 courseclear_file_around_19_sol }, 96 struct ProblemSet ps_ogg_around_22[] = {
99 { NULL, NULL } 97 { "testdata/ogg_courseclear.ogg",
100 }; 98 courseclear_file_around_22_sol },
101 struct ProblemSet ps_ogg_around_22[] = 99 { NULL, NULL }
102 { 100 };
103 { "testdata/ogg_courseclear.ogg",
104 courseclear_file_around_22_sol },
105 { NULL, NULL }
106 };
107 printf ("Running gif test on libmagic:\n"); 101 printf ("Running gif test on libmagic:\n");
108 test_result = (0 == ET_main ("mime", ps_gif) ? 0 : 1); 102 test_result = (0 == ET_main ("mime", ps_gif) ? 0 : 1);
109 printf ("gif libmagic test result: %s\n", test_result == 0 ? "OK" : "FAILED"); 103 printf ("gif libmagic test result: %s\n", test_result == 0 ? "OK" : "FAILED");
@@ -111,15 +105,18 @@ main (int argc, char *argv[])
111 105
112 printf ("Running ogg test on libmagic, assuming version ~5.19:\n"); 106 printf ("Running ogg test on libmagic, assuming version ~5.19:\n");
113 test_result_around_19 = (0 == ET_main ("mime", ps_ogg_around_19) ? 0 : 1); 107 test_result_around_19 = (0 == ET_main ("mime", ps_ogg_around_19) ? 0 : 1);
114 printf ("ogg libmagic test result: %s\n", test_result_around_19 == 0 ? "OK" : "FAILED"); 108 printf ("ogg libmagic test result: %s\n", test_result_around_19 == 0 ? "OK" :
109 "FAILED");
115 110
116 printf ("Running ogg test on libmagic, assuming version ~5.22:\n"); 111 printf ("Running ogg test on libmagic, assuming version ~5.22:\n");
117 test_result_around_22 = (0 == ET_main ("mime", ps_ogg_around_22) ? 0 : 1); 112 test_result_around_22 = (0 == ET_main ("mime", ps_ogg_around_22) ? 0 : 1);
118 printf ("ogg libmagic test result: %s\n", test_result_around_22 == 0 ? "OK" : "FAILED"); 113 printf ("ogg libmagic test result: %s\n", test_result_around_22 == 0 ? "OK" :
114 "FAILED");
119 115
120 if ((test_result_around_19 != 0) && (test_result_around_22 != 0)) 116 if ((test_result_around_19 != 0) && (test_result_around_22 != 0))
121 result++; 117 result++;
122 return result; 118 return result;
123} 119}
124 120
121
125/* end of test_mime.c */ 122/* end of test_mime.c */
diff --git a/src/plugins/test_mpeg.c b/src/plugins/test_mpeg.c
index cd306c3..ce12722 100644
--- a/src/plugins/test_mpeg.c
+++ b/src/plugins/test_mpeg.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the MPEG testcase. 30 * Main function for the MPEG testcase.
32 * 31 *
@@ -37,79 +36,77 @@
37int 36int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 struct SolutionData melt_sol[] = 39 struct SolutionData melt_sol[] = {
40 {
41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METAFORMAT_UTF8,
43 "text/plain",
44 "video/mpeg",
45 strlen ("video/mpeg") + 1,
46 0
47 },
48 {
49 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
50 EXTRACTOR_METAFORMAT_UTF8,
51 "text/plain",
52 "320x208",
53 strlen ("320x208") + 1,
54 0
55 },
41 { 56 {
42 { 57 EXTRACTOR_METATYPE_FORMAT_VERSION,
43 EXTRACTOR_METATYPE_MIMETYPE, 58 EXTRACTOR_METAFORMAT_UTF8,
44 EXTRACTOR_METAFORMAT_UTF8, 59 "text/plain",
45 "text/plain", 60 "MPEG1",
46 "video/mpeg", 61 strlen ("MPEG1") + 1,
47 strlen ("video/mpeg") + 1, 62 0
48 0 63 },
49 },
50 {
51 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
52 EXTRACTOR_METAFORMAT_UTF8,
53 "text/plain",
54 "320x208",
55 strlen ("320x208") + 1,
56 0
57 },
58 {
59 EXTRACTOR_METATYPE_FORMAT_VERSION,
60 EXTRACTOR_METAFORMAT_UTF8,
61 "text/plain",
62 "MPEG1",
63 strlen ("MPEG1") + 1,
64 0
65 },
66 {
67 EXTRACTOR_METATYPE_DURATION,
68 EXTRACTOR_METAFORMAT_UTF8,
69 "text/plain",
70 "00:00:03 (22 frames)",
71 strlen ("00:00:03 (22 frames)") + 1,
72 0
73 },
74 { 0, 0, NULL, NULL, 0, -1 }
75 };
76 struct SolutionData alien_sol[] =
77 { 64 {
78 { 65 EXTRACTOR_METATYPE_DURATION,
79 EXTRACTOR_METATYPE_MIMETYPE, 66 EXTRACTOR_METAFORMAT_UTF8,
80 EXTRACTOR_METAFORMAT_UTF8, 67 "text/plain",
81 "text/plain", 68 "00:00:03 (22 frames)",
82 "video/mpeg", 69 strlen ("00:00:03 (22 frames)") + 1,
83 strlen ("video/mpeg") + 1, 70 0
84 0 71 },
85 }, 72 { 0, 0, NULL, NULL, 0, -1 }
86 { 73 };
87 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, 74 struct SolutionData alien_sol[] = {
88 EXTRACTOR_METAFORMAT_UTF8,
89 "text/plain",
90 "320x240",
91 strlen ("320x240") + 1,
92 0
93 },
94 {
95 EXTRACTOR_METATYPE_FORMAT_VERSION,
96 EXTRACTOR_METAFORMAT_UTF8,
97 "text/plain",
98 "MPEG1",
99 strlen ("MPEG1") + 1,
100 0
101 },
102 { 0, 0, NULL, NULL, 0, -1 }
103 };
104 struct ProblemSet ps[] =
105 { 75 {
106 { "testdata/mpeg_melt.mpg", 76 EXTRACTOR_METATYPE_MIMETYPE,
107 melt_sol }, 77 EXTRACTOR_METAFORMAT_UTF8,
108 { "testdata/mpeg_alien.mpg", 78 "text/plain",
109 alien_sol }, 79 "video/mpeg",
110 { NULL, NULL } 80 strlen ("video/mpeg") + 1,
111 }; 81 0
82 },
83 {
84 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
85 EXTRACTOR_METAFORMAT_UTF8,
86 "text/plain",
87 "320x240",
88 strlen ("320x240") + 1,
89 0
90 },
91 {
92 EXTRACTOR_METATYPE_FORMAT_VERSION,
93 EXTRACTOR_METAFORMAT_UTF8,
94 "text/plain",
95 "MPEG1",
96 strlen ("MPEG1") + 1,
97 0
98 },
99 { 0, 0, NULL, NULL, 0, -1 }
100 };
101 struct ProblemSet ps[] = {
102 { "testdata/mpeg_melt.mpg",
103 melt_sol },
104 { "testdata/mpeg_alien.mpg",
105 alien_sol },
106 { NULL, NULL }
107 };
112 return ET_main ("mpeg", ps); 108 return ET_main ("mpeg", ps);
113} 109}
114 110
111
115/* end of test_mpeg.c */ 112/* end of test_mpeg.c */
diff --git a/src/plugins/test_nsf.c b/src/plugins/test_nsf.c
index ca10c75..fe022cd 100644
--- a/src/plugins/test_nsf.c
+++ b/src/plugins/test_nsf.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the NSF testcase. 30 * Main function for the NSF testcase.
32 * 31 *
@@ -37,81 +36,80 @@
37int 36int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 struct SolutionData nsf_arkanoid_sol[] = 39 struct SolutionData nsf_arkanoid_sol[] = {
40 {
41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METAFORMAT_UTF8,
43 "text/plain",
44 "audio/x-nsf",
45 strlen ("audio/x-nsf") + 1,
46 0
47 },
48 {
49 EXTRACTOR_METATYPE_FORMAT_VERSION,
50 EXTRACTOR_METAFORMAT_UTF8,
51 "text/plain",
52 "1",
53 strlen ("1") + 1,
54 0
55 },
56 {
57 EXTRACTOR_METATYPE_SONG_COUNT,
58 EXTRACTOR_METAFORMAT_UTF8,
59 "text/plain",
60 "26",
61 strlen ("26") + 1,
62 0
63 },
41 { 64 {
42 { 65 EXTRACTOR_METATYPE_STARTING_SONG,
43 EXTRACTOR_METATYPE_MIMETYPE, 66 EXTRACTOR_METAFORMAT_UTF8,
44 EXTRACTOR_METAFORMAT_UTF8, 67 "text/plain",
45 "text/plain", 68 "1",
46 "audio/x-nsf", 69 strlen ("1") + 1,
47 strlen ("audio/x-nsf") + 1, 70 0
48 0 71 },
49 },
50 {
51 EXTRACTOR_METATYPE_FORMAT_VERSION,
52 EXTRACTOR_METAFORMAT_UTF8,
53 "text/plain",
54 "1",
55 strlen ("1") + 1,
56 0
57 },
58 {
59 EXTRACTOR_METATYPE_SONG_COUNT,
60 EXTRACTOR_METAFORMAT_UTF8,
61 "text/plain",
62 "26",
63 strlen ("26") + 1,
64 0
65 },
66 {
67 EXTRACTOR_METATYPE_STARTING_SONG,
68 EXTRACTOR_METAFORMAT_UTF8,
69 "text/plain",
70 "1",
71 strlen ("1") + 1,
72 0
73 },
74 {
75 EXTRACTOR_METATYPE_ALBUM,
76 EXTRACTOR_METAFORMAT_UTF8,
77 "text/plain",
78 "Arkanoid II - Revenge of Doh",
79 strlen ("Arkanoid II - Revenge of Doh") + 1,
80 0
81 },
82 {
83 EXTRACTOR_METATYPE_ARTIST,
84 EXTRACTOR_METAFORMAT_UTF8,
85 "text/plain",
86 "<?>",
87 strlen ("<?>") + 1,
88 0
89 },
90 {
91 EXTRACTOR_METATYPE_COPYRIGHT,
92 EXTRACTOR_METAFORMAT_UTF8,
93 "text/plain",
94 "1988 Taito",
95 strlen ("1988 Taito") + 1,
96 0
97 },
98 {
99 EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM,
100 EXTRACTOR_METAFORMAT_UTF8,
101 "text/plain",
102 "NTSC",
103 strlen ("NTSC") + 1,
104 0
105 },
106 { 0, 0, NULL, NULL, 0, -1 }
107 };
108 struct ProblemSet ps[] =
109 { 72 {
110 { "testdata/nsf_arkanoid.nsf", 73 EXTRACTOR_METATYPE_ALBUM,
111 nsf_arkanoid_sol }, 74 EXTRACTOR_METAFORMAT_UTF8,
112 { NULL, NULL } 75 "text/plain",
113 }; 76 "Arkanoid II - Revenge of Doh",
77 strlen ("Arkanoid II - Revenge of Doh") + 1,
78 0
79 },
80 {
81 EXTRACTOR_METATYPE_ARTIST,
82 EXTRACTOR_METAFORMAT_UTF8,
83 "text/plain",
84 "<?>",
85 strlen ("<?>") + 1,
86 0
87 },
88 {
89 EXTRACTOR_METATYPE_COPYRIGHT,
90 EXTRACTOR_METAFORMAT_UTF8,
91 "text/plain",
92 "1988 Taito",
93 strlen ("1988 Taito") + 1,
94 0
95 },
96 {
97 EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM,
98 EXTRACTOR_METAFORMAT_UTF8,
99 "text/plain",
100 "NTSC",
101 strlen ("NTSC") + 1,
102 0
103 },
104 { 0, 0, NULL, NULL, 0, -1 }
105 };
106 struct ProblemSet ps[] = {
107 { "testdata/nsf_arkanoid.nsf",
108 nsf_arkanoid_sol },
109 { NULL, NULL }
110 };
114 return ET_main ("nsf", ps); 111 return ET_main ("nsf", ps);
115} 112}
116 113
114
117/* end of test_nsf.c */ 115/* end of test_nsf.c */
diff --git a/src/plugins/test_nsfe.c b/src/plugins/test_nsfe.c
index a28f1ea..358dd7f 100644
--- a/src/plugins/test_nsfe.c
+++ b/src/plugins/test_nsfe.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the NSFE testcase. 30 * Main function for the NSFE testcase.
32 * 31 *
@@ -37,97 +36,96 @@
37int 36int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 struct SolutionData nsfe_classics_sol[] = 39 struct SolutionData nsfe_classics_sol[] = {
40 {
41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METAFORMAT_UTF8,
43 "text/plain",
44 "audio/x-nsfe",
45 strlen ("audio/x-nsfe") + 1,
46 0
47 },
48 {
49 EXTRACTOR_METATYPE_SONG_COUNT,
50 EXTRACTOR_METAFORMAT_UTF8,
51 "text/plain",
52 "2",
53 strlen ("2") + 1,
54 0
55 },
56 {
57 EXTRACTOR_METATYPE_STARTING_SONG,
58 EXTRACTOR_METAFORMAT_UTF8,
59 "text/plain",
60 "0",
61 strlen ("0") + 1,
62 0
63 },
64 {
65 EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM,
66 EXTRACTOR_METAFORMAT_UTF8,
67 "text/plain",
68 "PAL",
69 strlen ("PAL") + 1,
70 0
71 },
41 { 72 {
42 { 73 EXTRACTOR_METATYPE_ALBUM,
43 EXTRACTOR_METATYPE_MIMETYPE, 74 EXTRACTOR_METAFORMAT_UTF8,
44 EXTRACTOR_METAFORMAT_UTF8, 75 "text/plain",
45 "text/plain", 76 "Adventures of Dr. Franken,The",
46 "audio/x-nsfe", 77 strlen ("Adventures of Dr. Franken,The") + 1,
47 strlen ("audio/x-nsfe") + 1, 78 0
48 0 79 },
49 },
50 {
51 EXTRACTOR_METATYPE_SONG_COUNT,
52 EXTRACTOR_METAFORMAT_UTF8,
53 "text/plain",
54 "2",
55 strlen ("2") + 1,
56 0
57 },
58 {
59 EXTRACTOR_METATYPE_STARTING_SONG,
60 EXTRACTOR_METAFORMAT_UTF8,
61 "text/plain",
62 "0",
63 strlen ("0") + 1,
64 0
65 },
66 {
67 EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM,
68 EXTRACTOR_METAFORMAT_UTF8,
69 "text/plain",
70 "PAL",
71 strlen ("PAL") + 1,
72 0
73 },
74 {
75 EXTRACTOR_METATYPE_ALBUM,
76 EXTRACTOR_METAFORMAT_UTF8,
77 "text/plain",
78 "Adventures of Dr. Franken,The",
79 strlen ("Adventures of Dr. Franken,The") + 1,
80 0
81 },
82 {
83 EXTRACTOR_METATYPE_ARTIST,
84 EXTRACTOR_METAFORMAT_UTF8,
85 "text/plain",
86 "Mark Cooksey",
87 strlen ("Mark Cooksey") + 1,
88 0
89 },
90 {
91 EXTRACTOR_METATYPE_COPYRIGHT,
92 EXTRACTOR_METAFORMAT_UTF8,
93 "text/plain",
94 "1993 Motivetime LTD.",
95 strlen ("1993 Motivetime LTD.") + 1,
96 0
97 },
98 {
99 EXTRACTOR_METATYPE_RIPPER,
100 EXTRACTOR_METAFORMAT_UTF8,
101 "text/plain",
102 "Gil_Galad",
103 strlen ("Gil_Galad") + 1,
104 0
105 },
106 {
107 EXTRACTOR_METATYPE_TITLE,
108 EXTRACTOR_METAFORMAT_UTF8,
109 "text/plain",
110 "Bach: Prelude & Fugue In C Minor",
111 strlen ("Bach: Prelude & Fugue In C Minor") + 1,
112 0
113 },
114 {
115 EXTRACTOR_METATYPE_TITLE,
116 EXTRACTOR_METAFORMAT_UTF8,
117 "text/plain",
118 "Beethoven: Moonlight Sonata",
119 strlen ("Beethoven: Moonlight Sonata") + 1,
120 0
121 },
122 { 0, 0, NULL, NULL, 0, -1 }
123 };
124 struct ProblemSet ps[] =
125 { 80 {
126 { "testdata/nsfe_classics.nsfe", 81 EXTRACTOR_METATYPE_ARTIST,
127 nsfe_classics_sol }, 82 EXTRACTOR_METAFORMAT_UTF8,
128 { NULL, NULL } 83 "text/plain",
129 }; 84 "Mark Cooksey",
85 strlen ("Mark Cooksey") + 1,
86 0
87 },
88 {
89 EXTRACTOR_METATYPE_COPYRIGHT,
90 EXTRACTOR_METAFORMAT_UTF8,
91 "text/plain",
92 "1993 Motivetime LTD.",
93 strlen ("1993 Motivetime LTD.") + 1,
94 0
95 },
96 {
97 EXTRACTOR_METATYPE_RIPPER,
98 EXTRACTOR_METAFORMAT_UTF8,
99 "text/plain",
100 "Gil_Galad",
101 strlen ("Gil_Galad") + 1,
102 0
103 },
104 {
105 EXTRACTOR_METATYPE_TITLE,
106 EXTRACTOR_METAFORMAT_UTF8,
107 "text/plain",
108 "Bach: Prelude & Fugue In C Minor",
109 strlen ("Bach: Prelude & Fugue In C Minor") + 1,
110 0
111 },
112 {
113 EXTRACTOR_METATYPE_TITLE,
114 EXTRACTOR_METAFORMAT_UTF8,
115 "text/plain",
116 "Beethoven: Moonlight Sonata",
117 strlen ("Beethoven: Moonlight Sonata") + 1,
118 0
119 },
120 { 0, 0, NULL, NULL, 0, -1 }
121 };
122 struct ProblemSet ps[] = {
123 { "testdata/nsfe_classics.nsfe",
124 nsfe_classics_sol },
125 { NULL, NULL }
126 };
130 return ET_main ("nsfe", ps); 127 return ET_main ("nsfe", ps);
131} 128}
132 129
130
133/* end of test_nsfe.c */ 131/* end of test_nsfe.c */
diff --git a/src/plugins/test_odf.c b/src/plugins/test_odf.c
index 0d95dbf..cc1447a 100644
--- a/src/plugins/test_odf.c
+++ b/src/plugins/test_odf.c
@@ -36,65 +36,65 @@
36int 36int
37main (int argc, char *argv[]) 37main (int argc, char *argv[])
38{ 38{
39 struct SolutionData odf_cg_sol[] = 39 struct SolutionData odf_cg_sol[] = {
40 { 40 {
41 { 41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METATYPE_MIMETYPE, 42 EXTRACTOR_METAFORMAT_UTF8,
43 EXTRACTOR_METAFORMAT_UTF8, 43 "text/plain",
44 "text/plain", 44 "application/vnd.oasis.opendocument.text",
45 "application/vnd.oasis.opendocument.text", 45 strlen ("application/vnd.oasis.opendocument.text") + 1,
46 strlen ("application/vnd.oasis.opendocument.text") + 1, 46 0
47 0 47 },
48 },
49 {
50 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
51 EXTRACTOR_METAFORMAT_UTF8,
52 "text/plain",
53 "OpenOffice.org/3.2$Unix OpenOffice.org_project/320m12$Build-9483",
54 strlen ("OpenOffice.org/3.2$Unix OpenOffice.org_project/320m12$Build-9483") + 1,
55 0
56 },
57 {
58 EXTRACTOR_METATYPE_PAGE_COUNT,
59 EXTRACTOR_METAFORMAT_UTF8,
60 "text/plain",
61 "1",
62 strlen ("1") + 1,
63 0
64 },
65 {
66 EXTRACTOR_METATYPE_CREATION_DATE,
67 EXTRACTOR_METAFORMAT_UTF8,
68 "text/plain",
69 "2005-11-22T11:44:00",
70 strlen ("2005-11-22T11:44:00") + 1,
71 0
72 },
73 {
74 EXTRACTOR_METATYPE_UNKNOWN_DATE,
75 EXTRACTOR_METAFORMAT_UTF8,
76 "text/plain",
77 "2010-06-09T13:09:34",
78 strlen ("2010-06-09T13:09:34") + 1,
79 0
80 },
81 {
82 EXTRACTOR_METATYPE_TITLE,
83 EXTRACTOR_METAFORMAT_UTF8,
84 "text/plain",
85 "Anhang 1: Profile der beteiligten Wissenschaftler",
86 strlen ("Anhang 1: Profile der beteiligten Wissenschaftler") + 1,
87 0
88 },
89 { 0, 0, NULL, NULL, 0, -1 }
90 };
91 struct ProblemSet ps[] =
92 { 48 {
93 { "testdata/odf_cg.odt", 49 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
94 odf_cg_sol }, 50 EXTRACTOR_METAFORMAT_UTF8,
95 { NULL, NULL } 51 "text/plain",
96 }; 52 "OpenOffice.org/3.2$Unix OpenOffice.org_project/320m12$Build-9483",
53 strlen (
54 "OpenOffice.org/3.2$Unix OpenOffice.org_project/320m12$Build-9483") + 1,
55 0
56 },
57 {
58 EXTRACTOR_METATYPE_PAGE_COUNT,
59 EXTRACTOR_METAFORMAT_UTF8,
60 "text/plain",
61 "1",
62 strlen ("1") + 1,
63 0
64 },
65 {
66 EXTRACTOR_METATYPE_CREATION_DATE,
67 EXTRACTOR_METAFORMAT_UTF8,
68 "text/plain",
69 "2005-11-22T11:44:00",
70 strlen ("2005-11-22T11:44:00") + 1,
71 0
72 },
73 {
74 EXTRACTOR_METATYPE_UNKNOWN_DATE,
75 EXTRACTOR_METAFORMAT_UTF8,
76 "text/plain",
77 "2010-06-09T13:09:34",
78 strlen ("2010-06-09T13:09:34") + 1,
79 0
80 },
81 {
82 EXTRACTOR_METATYPE_TITLE,
83 EXTRACTOR_METAFORMAT_UTF8,
84 "text/plain",
85 "Anhang 1: Profile der beteiligten Wissenschaftler",
86 strlen ("Anhang 1: Profile der beteiligten Wissenschaftler") + 1,
87 0
88 },
89 { 0, 0, NULL, NULL, 0, -1 }
90 };
91 struct ProblemSet ps[] = {
92 { "testdata/odf_cg.odt",
93 odf_cg_sol },
94 { NULL, NULL }
95 };
97 return ET_main ("odf", ps); 96 return ET_main ("odf", ps);
98} 97}
99 98
99
100/* end of test_odf.c */ 100/* end of test_odf.c */
diff --git a/src/plugins/test_ogg.c b/src/plugins/test_ogg.c
index 418f192..d82f80f 100644
--- a/src/plugins/test_ogg.c
+++ b/src/plugins/test_ogg.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the OGG testcase. 30 * Main function for the OGG testcase.
32 * 31 *
@@ -37,57 +36,56 @@
37int 36int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 struct SolutionData courseclear_sol[] = 39 struct SolutionData courseclear_sol[] = {
40 {
41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METAFORMAT_UTF8,
43 "text/plain",
44 "application/ogg",
45 strlen ("application/ogg") + 1,
46 0
47 },
48 {
49 EXTRACTOR_METATYPE_VENDOR,
50 EXTRACTOR_METAFORMAT_UTF8,
51 "text/plain",
52 "Xiphophorus libVorbis I 20010813",
53 strlen ("Xiphophorus libVorbis I 20010813") + 1,
54 0
55 },
41 { 56 {
42 { 57 EXTRACTOR_METATYPE_TITLE,
43 EXTRACTOR_METATYPE_MIMETYPE, 58 EXTRACTOR_METAFORMAT_UTF8,
44 EXTRACTOR_METAFORMAT_UTF8, 59 "text/plain",
45 "text/plain", 60 "xoc_SMW_06_courseclear",
46 "application/ogg", 61 strlen ("xoc_SMW_06_courseclear") + 1,
47 strlen ("application/ogg") + 1, 62 0
48 0 63 },
49 },
50 {
51 EXTRACTOR_METATYPE_VENDOR,
52 EXTRACTOR_METAFORMAT_UTF8,
53 "text/plain",
54 "Xiphophorus libVorbis I 20010813",
55 strlen ("Xiphophorus libVorbis I 20010813") + 1,
56 0
57 },
58 {
59 EXTRACTOR_METATYPE_TITLE,
60 EXTRACTOR_METAFORMAT_UTF8,
61 "text/plain",
62 "xoc_SMW_06_courseclear",
63 strlen ("xoc_SMW_06_courseclear") + 1,
64 0
65 },
66 {
67 EXTRACTOR_METATYPE_ARTIST,
68 EXTRACTOR_METAFORMAT_UTF8,
69 "text/plain",
70 "XOC",
71 strlen ("XOC") + 1,
72 0
73 },
74 {
75 EXTRACTOR_METATYPE_TRACK_NUMBER,
76 EXTRACTOR_METAFORMAT_UTF8,
77 "text/plain",
78 "6",
79 strlen ("6") + 1,
80 0
81 },
82 { 0, 0, NULL, NULL, 0, -1 }
83 };
84 struct ProblemSet ps[] =
85 { 64 {
86 { "testdata/ogg_courseclear.ogg", 65 EXTRACTOR_METATYPE_ARTIST,
87 courseclear_sol }, 66 EXTRACTOR_METAFORMAT_UTF8,
88 { NULL, NULL } 67 "text/plain",
89 }; 68 "XOC",
69 strlen ("XOC") + 1,
70 0
71 },
72 {
73 EXTRACTOR_METATYPE_TRACK_NUMBER,
74 EXTRACTOR_METAFORMAT_UTF8,
75 "text/plain",
76 "6",
77 strlen ("6") + 1,
78 0
79 },
80 { 0, 0, NULL, NULL, 0, -1 }
81 };
82 struct ProblemSet ps[] = {
83 { "testdata/ogg_courseclear.ogg",
84 courseclear_sol },
85 { NULL, NULL }
86 };
90 return ET_main ("ogg", ps); 87 return ET_main ("ogg", ps);
91} 88}
92 89
90
93/* end of test_ogg.c */ 91/* end of test_ogg.c */
diff --git a/src/plugins/test_ole2.c b/src/plugins/test_ole2.c
index 2859bb4..2870050 100644
--- a/src/plugins/test_ole2.c
+++ b/src/plugins/test_ole2.c
@@ -36,457 +36,476 @@
36int 36int
37main (int argc, char *argv[]) 37main (int argc, char *argv[])
38{ 38{
39 struct SolutionData ole2_msword_sol[] = 39 struct SolutionData ole2_msword_sol[] = {
40 { 40 {
41 { 41 EXTRACTOR_METATYPE_CREATOR,
42 EXTRACTOR_METATYPE_CREATOR, 42 EXTRACTOR_METAFORMAT_UTF8,
43 EXTRACTOR_METAFORMAT_UTF8, 43 "text/plain",
44 "text/plain", 44 "Nils Durner",
45 "Nils Durner", 45 strlen ("Nils Durner") + 1,
46 strlen ("Nils Durner") + 1, 46 0
47 0 47 },
48 }, 48 {
49 { 49 EXTRACTOR_METATYPE_UNKNOWN_DATE,
50 EXTRACTOR_METATYPE_UNKNOWN_DATE, 50 EXTRACTOR_METAFORMAT_UTF8,
51 EXTRACTOR_METAFORMAT_UTF8, 51 "text/plain",
52 "text/plain", 52 "2005-03-21T06:11:12Z",
53 "2005-03-21T06:11:12Z", 53 strlen ("2005-03-21T06:11:12Z") + 1,
54 strlen ("2005-03-21T06:11:12Z") + 1, 54 0
55 0 55 },
56 }, 56 {
57 { 57 EXTRACTOR_METATYPE_DESCRIPTION,
58 EXTRACTOR_METATYPE_DESCRIPTION, 58 EXTRACTOR_METAFORMAT_UTF8,
59 EXTRACTOR_METAFORMAT_UTF8, 59 "text/plain",
60 "text/plain", 60 "This is a small document to test meta data extraction by GNU libextractor.",
61 "This is a small document to test meta data extraction by GNU libextractor.", 61 strlen (
62 strlen ("This is a small document to test meta data extraction by GNU libextractor.") + 1, 62 "This is a small document to test meta data extraction by GNU libextractor.")
63 0 63 + 1,
64 }, 64 0
65 { 65 },
66 EXTRACTOR_METATYPE_KEYWORDS, 66 {
67 EXTRACTOR_METAFORMAT_UTF8, 67 EXTRACTOR_METATYPE_KEYWORDS,
68 "text/plain", 68 EXTRACTOR_METAFORMAT_UTF8,
69 "ole ole2 eole2extractor", 69 "text/plain",
70 strlen ("ole ole2 eole2extractor") + 1, 70 "ole ole2 eole2extractor",
71 0 71 strlen ("ole ole2 eole2extractor") + 1,
72 }, 72 0
73 { 73 },
74 EXTRACTOR_METATYPE_SUBJECT, 74 {
75 EXTRACTOR_METAFORMAT_UTF8, 75 EXTRACTOR_METATYPE_SUBJECT,
76 "text/plain", 76 EXTRACTOR_METAFORMAT_UTF8,
77 "GNU libextractor", 77 "text/plain",
78 strlen ("GNU libextractor") + 1, 78 "GNU libextractor",
79 0 79 strlen ("GNU libextractor") + 1,
80 }, 80 0
81 { 81 },
82 EXTRACTOR_METATYPE_TITLE, 82 {
83 EXTRACTOR_METAFORMAT_UTF8, 83 EXTRACTOR_METATYPE_TITLE,
84 "text/plain", 84 EXTRACTOR_METAFORMAT_UTF8,
85 "Testcase for the ole2 extractor", 85 "text/plain",
86 strlen ("Testcase for the ole2 extractor") + 1, 86 "Testcase for the ole2 extractor",
87 0 87 strlen ("Testcase for the ole2 extractor") + 1,
88 }, 88 0
89 { 89 },
90 EXTRACTOR_METATYPE_LAST_SAVED_BY, 90 {
91 EXTRACTOR_METAFORMAT_UTF8, 91 EXTRACTOR_METATYPE_LAST_SAVED_BY,
92 "text/plain", 92 EXTRACTOR_METAFORMAT_UTF8,
93 "Nils Durner", 93 "text/plain",
94 strlen ("Nils Durner") + 1, 94 "Nils Durner",
95 0 95 strlen ("Nils Durner") + 1,
96 }, 96 0
97 { 97 },
98 EXTRACTOR_METATYPE_CREATION_DATE, 98 {
99 EXTRACTOR_METAFORMAT_UTF8, 99 EXTRACTOR_METATYPE_CREATION_DATE,
100 "text/plain", 100 EXTRACTOR_METAFORMAT_UTF8,
101 "2005-03-21T06:10:19Z", 101 "text/plain",
102 strlen ("2005-03-21T06:10:19Z") + 1, 102 "2005-03-21T06:10:19Z",
103 0 103 strlen ("2005-03-21T06:10:19Z") + 1,
104 }, 104 0
105 { 105 },
106 EXTRACTOR_METATYPE_EDITING_CYCLES, 106 {
107 EXTRACTOR_METAFORMAT_UTF8, 107 EXTRACTOR_METATYPE_EDITING_CYCLES,
108 "text/plain", 108 EXTRACTOR_METAFORMAT_UTF8,
109 "2", 109 "text/plain",
110 strlen ("2") + 1, 110 "2",
111 0 111 strlen ("2") + 1,
112 }, 112 0
113 { 0, 0, NULL, NULL, 0, -1 } 113 },
114 }; 114 { 0, 0, NULL, NULL, 0, -1 }
115 };
115 116
116 struct SolutionData ole2_starwriter_sol[] = 117 struct SolutionData ole2_starwriter_sol[] = {
117 { 118 {
118 { 119 EXTRACTOR_METATYPE_CREATOR,
119 EXTRACTOR_METATYPE_CREATOR, 120 EXTRACTOR_METAFORMAT_UTF8,
120 EXTRACTOR_METAFORMAT_UTF8, 121 "text/plain",
121 "text/plain", 122 "Christian Grothoff",
122 "Christian Grothoff", 123 strlen ("Christian Grothoff") + 1,
123 strlen ("Christian Grothoff") + 1, 124 0
124 0 125 },
125 }, 126 {
126 { 127 EXTRACTOR_METATYPE_UNKNOWN_DATE,
127 EXTRACTOR_METATYPE_UNKNOWN_DATE, 128 EXTRACTOR_METAFORMAT_UTF8,
128 EXTRACTOR_METAFORMAT_UTF8, 129 "text/plain",
129 "text/plain", 130 "2004-09-24T02:54:31Z",
130 "2004-09-24T02:54:31Z", 131 strlen ("2004-09-24T02:54:31Z") + 1,
131 strlen ("2004-09-24T02:54:31Z") + 1, 132 0
132 0 133 },
133 }, 134 {
134 { 135 EXTRACTOR_METATYPE_DESCRIPTION,
135 EXTRACTOR_METATYPE_DESCRIPTION, 136 EXTRACTOR_METAFORMAT_UTF8,
136 EXTRACTOR_METAFORMAT_UTF8, 137 "text/plain",
137 "text/plain", 138 "The comments",
138 "The comments", 139 strlen ("The comments") + 1,
139 strlen ("The comments") + 1, 140 0
140 0 141 },
141 }, 142 {
142 { 143 EXTRACTOR_METATYPE_KEYWORDS,
143 EXTRACTOR_METATYPE_KEYWORDS, 144 EXTRACTOR_METAFORMAT_UTF8,
144 EXTRACTOR_METAFORMAT_UTF8, 145 "text/plain",
145 "text/plain", 146 "The Keywords",
146 "The Keywords", 147 strlen ("The Keywords") + 1,
147 strlen ("The Keywords") + 1, 148 0
148 0 149 },
149 }, 150 {
150 { 151 EXTRACTOR_METATYPE_SUBJECT,
151 EXTRACTOR_METATYPE_SUBJECT, 152 EXTRACTOR_METAFORMAT_UTF8,
152 EXTRACTOR_METAFORMAT_UTF8, 153 "text/plain",
153 "text/plain", 154 "The Subject",
154 "The Subject", 155 strlen ("The Subject") + 1,
155 strlen ("The Subject") + 1, 156 0
156 0 157 },
157 }, 158 {
158 { 159 EXTRACTOR_METATYPE_TITLE,
159 EXTRACTOR_METATYPE_TITLE, 160 EXTRACTOR_METAFORMAT_UTF8,
160 EXTRACTOR_METAFORMAT_UTF8, 161 "text/plain",
161 "text/plain", 162 "The Title",
162 "The Title", 163 strlen ("The Title") + 1,
163 strlen ("The Title") + 1, 164 0
164 0 165 },
165 }, 166 {
166 { 167 EXTRACTOR_METATYPE_LAST_SAVED_BY,
167 EXTRACTOR_METATYPE_LAST_SAVED_BY, 168 EXTRACTOR_METAFORMAT_UTF8,
168 EXTRACTOR_METAFORMAT_UTF8, 169 "text/plain",
169 "text/plain", 170 "Christian Grothoff",
170 "Christian Grothoff", 171 strlen ("Christian Grothoff") + 1,
171 strlen ("Christian Grothoff") + 1, 172 0
172 0 173 },
173 }, 174 {
174 { 175 EXTRACTOR_METATYPE_CREATION_DATE,
175 EXTRACTOR_METATYPE_CREATION_DATE, 176 EXTRACTOR_METAFORMAT_UTF8,
176 EXTRACTOR_METAFORMAT_UTF8, 177 "text/plain",
177 "text/plain", 178 "2004-09-24T02:53:15Z",
178 "2004-09-24T02:53:15Z", 179 strlen ("2004-09-24T02:53:15Z") + 1,
179 strlen ("2004-09-24T02:53:15Z") + 1, 180 0
180 0 181 },
181 }, 182 {
182 { 183 EXTRACTOR_METATYPE_EDITING_CYCLES,
183 EXTRACTOR_METATYPE_EDITING_CYCLES, 184 EXTRACTOR_METAFORMAT_UTF8,
184 EXTRACTOR_METAFORMAT_UTF8, 185 "text/plain",
185 "text/plain", 186 "4",
186 "4", 187 strlen ("4") + 1,
187 strlen ("4") + 1, 188 0
188 0 189 },
189 }, 190 {
190 { 191 EXTRACTOR_METATYPE_TITLE,
191 EXTRACTOR_METATYPE_TITLE, 192 EXTRACTOR_METAFORMAT_UTF8,
192 EXTRACTOR_METAFORMAT_UTF8, 193 "text/plain",
193 "text/plain", 194 "The Title",
194 "The Title", 195 strlen ("The Title") + 1,
195 strlen ("The Title") + 1, 196 0
196 0 197 },
197 }, 198 {
198 { 199 EXTRACTOR_METATYPE_SUBJECT,
199 EXTRACTOR_METATYPE_SUBJECT, 200 EXTRACTOR_METAFORMAT_UTF8,
200 EXTRACTOR_METAFORMAT_UTF8, 201 "text/plain",
201 "text/plain", 202 "The Subject",
202 "The Subject", 203 strlen ("The Subject") + 1,
203 strlen ("The Subject") + 1, 204 0
204 0 205 },
205 }, 206 {
206 { 207 EXTRACTOR_METATYPE_COMMENT,
207 EXTRACTOR_METATYPE_COMMENT, 208 EXTRACTOR_METAFORMAT_UTF8,
208 EXTRACTOR_METAFORMAT_UTF8, 209 "text/plain",
209 "text/plain", 210 "The comments",
210 "The comments", 211 strlen ("The comments") + 1,
211 strlen ("The comments") + 1, 212 0
212 0 213 },
213 }, 214 {
214 { 215 EXTRACTOR_METATYPE_KEYWORDS,
215 EXTRACTOR_METATYPE_KEYWORDS, 216 EXTRACTOR_METAFORMAT_UTF8,
216 EXTRACTOR_METAFORMAT_UTF8, 217 "text/plain",
217 "text/plain", 218 "The Keywords",
218 "The Keywords", 219 strlen ("The Keywords") + 1,
219 strlen ("The Keywords") + 1, 220 0
220 0 221 },
221 }, 222 { 0, 0, NULL, NULL, 0, -1 }
222 { 0, 0, NULL, NULL, 0, -1 } 223 };
223 };
224#if HAVE_ICONV 224#if HAVE_ICONV
225 struct SolutionData ole2_blair_sol[] = 225 struct SolutionData ole2_blair_sol[] = {
226 { 226 {
227 { 227 EXTRACTOR_METATYPE_LANGUAGE,
228 EXTRACTOR_METATYPE_LANGUAGE, 228 EXTRACTOR_METAFORMAT_UTF8,
229 EXTRACTOR_METAFORMAT_UTF8, 229 "text/plain",
230 "text/plain", 230 "U.S. English",
231 "U.S. English", 231 strlen ("U.S. English") + 1,
232 strlen ("U.S. English") + 1, 232 0
233 0 233 },
234 }, 234 {
235 { 235 EXTRACTOR_METATYPE_CREATOR,
236 EXTRACTOR_METATYPE_CREATOR, 236 EXTRACTOR_METAFORMAT_UTF8,
237 EXTRACTOR_METAFORMAT_UTF8, 237 "text/plain",
238 "text/plain", 238 "default",
239 "default", 239 strlen ("default") + 1,
240 strlen ("default") + 1, 240 0
241 0 241 },
242 }, 242 {
243 { 243 EXTRACTOR_METATYPE_UNKNOWN_DATE,
244 EXTRACTOR_METATYPE_UNKNOWN_DATE, 244 EXTRACTOR_METAFORMAT_UTF8,
245 EXTRACTOR_METAFORMAT_UTF8, 245 "text/plain",
246 "text/plain", 246 "2003-02-03T11:18:00Z",
247 "2003-02-03T11:18:00Z", 247 strlen ("2003-02-03T11:18:00Z") + 1,
248 strlen ("2003-02-03T11:18:00Z") + 1, 248 0
249 0 249 },
250 }, 250 {
251 { 251 EXTRACTOR_METATYPE_TITLE,
252 EXTRACTOR_METATYPE_TITLE, 252 EXTRACTOR_METAFORMAT_UTF8,
253 EXTRACTOR_METAFORMAT_UTF8, 253 "text/plain",
254 "text/plain", 254 "Iraq- ITS INFRASTRUCTURE OF CONCEALMENT, DECEPTION AND INTIMIDATION",
255 "Iraq- ITS INFRASTRUCTURE OF CONCEALMENT, DECEPTION AND INTIMIDATION", 255 strlen (
256 strlen ("Iraq- ITS INFRASTRUCTURE OF CONCEALMENT, DECEPTION AND INTIMIDATION") + 1, 256 "Iraq- ITS INFRASTRUCTURE OF CONCEALMENT, DECEPTION AND INTIMIDATION")
257 0 257 + 1,
258 }, 258 0
259 { 259 },
260 EXTRACTOR_METATYPE_CHARACTER_COUNT, 260 {
261 EXTRACTOR_METAFORMAT_UTF8, 261 EXTRACTOR_METATYPE_CHARACTER_COUNT,
262 "text/plain", 262 EXTRACTOR_METAFORMAT_UTF8,
263 "22090", 263 "text/plain",
264 strlen ("22090") + 1, 264 "22090",
265 0 265 strlen ("22090") + 1,
266 }, 266 0
267 { 267 },
268 EXTRACTOR_METATYPE_LAST_SAVED_BY, 268 {
269 EXTRACTOR_METAFORMAT_UTF8, 269 EXTRACTOR_METATYPE_LAST_SAVED_BY,
270 "text/plain", 270 EXTRACTOR_METAFORMAT_UTF8,
271 "MKhan", 271 "text/plain",
272 strlen ("MKhan") + 1, 272 "MKhan",
273 0 273 strlen ("MKhan") + 1,
274 }, 274 0
275 { 275 },
276 EXTRACTOR_METATYPE_PAGE_COUNT, 276 {
277 EXTRACTOR_METAFORMAT_UTF8, 277 EXTRACTOR_METATYPE_PAGE_COUNT,
278 "text/plain", 278 EXTRACTOR_METAFORMAT_UTF8,
279 "1", 279 "text/plain",
280 strlen ("1") + 1, 280 "1",
281 0 281 strlen ("1") + 1,
282 }, 282 0
283 { 283 },
284 EXTRACTOR_METATYPE_WORD_COUNT, 284 {
285 EXTRACTOR_METAFORMAT_UTF8, 285 EXTRACTOR_METATYPE_WORD_COUNT,
286 "text/plain", 286 EXTRACTOR_METAFORMAT_UTF8,
287 "3875", 287 "text/plain",
288 strlen ("3875") + 1, 288 "3875",
289 0 289 strlen ("3875") + 1,
290 }, 290 0
291 { 291 },
292 EXTRACTOR_METATYPE_CREATION_DATE, 292 {
293 EXTRACTOR_METAFORMAT_UTF8, 293 EXTRACTOR_METATYPE_CREATION_DATE,
294 "text/plain", 294 EXTRACTOR_METAFORMAT_UTF8,
295 "2003-02-03T09:31:00Z", 295 "text/plain",
296 strlen ("2003-02-03T09:31:00Z") + 1, 296 "2003-02-03T09:31:00Z",
297 0 297 strlen ("2003-02-03T09:31:00Z") + 1,
298 }, 298 0
299 { 299 },
300 EXTRACTOR_METATYPE_EDITING_CYCLES, 300 {
301 EXTRACTOR_METAFORMAT_UTF8, 301 EXTRACTOR_METATYPE_EDITING_CYCLES,
302 "text/plain", 302 EXTRACTOR_METAFORMAT_UTF8,
303 "4", 303 "text/plain",
304 strlen ("4") + 1, 304 "4",
305 0 305 strlen ("4") + 1,
306 }, 306 0
307 { 307 },
308 EXTRACTOR_METATYPE_MIMETYPE, 308 {
309 EXTRACTOR_METAFORMAT_UTF8, 309 EXTRACTOR_METATYPE_MIMETYPE,
310 "text/plain", 310 EXTRACTOR_METAFORMAT_UTF8,
311 "application/vnd.ms-files", 311 "text/plain",
312 strlen ("application/vnd.ms-files") + 1, 312 "application/vnd.ms-files",
313 0 313 strlen ("application/vnd.ms-files") + 1,
314 }, 314 0
315 { 315 },
316 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE, 316 {
317 EXTRACTOR_METAFORMAT_UTF8, 317 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
318 "text/plain", 318 EXTRACTOR_METAFORMAT_UTF8,
319 "Microsoft Word 8.0", 319 "text/plain",
320 strlen ("Microsoft Word 8.0") + 1, 320 "Microsoft Word 8.0",
321 0 321 strlen ("Microsoft Word 8.0") + 1,
322 }, 322 0
323 { 323 },
324 EXTRACTOR_METATYPE_TEMPLATE, 324 {
325 EXTRACTOR_METAFORMAT_UTF8, 325 EXTRACTOR_METATYPE_TEMPLATE,
326 "text/plain", 326 EXTRACTOR_METAFORMAT_UTF8,
327 "Normal.dot", 327 "text/plain",
328 strlen ("Normal.dot") + 1, 328 "Normal.dot",
329 0 329 strlen ("Normal.dot") + 1,
330 }, 330 0
331 { 331 },
332 EXTRACTOR_METATYPE_LINE_COUNT, 332 {
333 EXTRACTOR_METAFORMAT_UTF8, 333 EXTRACTOR_METATYPE_LINE_COUNT,
334 "text/plain", 334 EXTRACTOR_METAFORMAT_UTF8,
335 "184", 335 "text/plain",
336 strlen ("184") + 1, 336 "184",
337 0 337 strlen ("184") + 1,
338 }, 338 0
339 { 339 },
340 EXTRACTOR_METATYPE_PARAGRAPH_COUNT, 340 {
341 EXTRACTOR_METAFORMAT_UTF8, 341 EXTRACTOR_METATYPE_PARAGRAPH_COUNT,
342 "text/plain", 342 EXTRACTOR_METAFORMAT_UTF8,
343 "44", 343 "text/plain",
344 strlen ("44") + 1, 344 "44",
345 0 345 strlen ("44") + 1,
346 }, 346 0
347 { 347 },
348 EXTRACTOR_METATYPE_REVISION_HISTORY, 348 {
349 EXTRACTOR_METAFORMAT_UTF8, 349 EXTRACTOR_METATYPE_REVISION_HISTORY,
350 "text/plain", 350 EXTRACTOR_METAFORMAT_UTF8,
351 "Revision #0: Author `cic22' worked on `C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd'", 351 "text/plain",
352 strlen ("Revision #0: Author `cic22' worked on `C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd'") + 1, 352 "Revision #0: Author `cic22' worked on `C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd'",
353 0 353 strlen (
354 }, 354 "Revision #0: Author `cic22' worked on `C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd'")
355 { 355 + 1,
356 EXTRACTOR_METATYPE_REVISION_HISTORY, 356 0
357 EXTRACTOR_METAFORMAT_UTF8, 357 },
358 "text/plain", 358 {
359 "Revision #1: Author `cic22' worked on `C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd'", 359 EXTRACTOR_METATYPE_REVISION_HISTORY,
360 strlen ("Revision #1: Author `cic22' worked on `C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd'") + 1, 360 EXTRACTOR_METAFORMAT_UTF8,
361 0 361 "text/plain",
362 }, 362 "Revision #1: Author `cic22' worked on `C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd'",
363 { 363 strlen (
364 EXTRACTOR_METATYPE_REVISION_HISTORY, 364 "Revision #1: Author `cic22' worked on `C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd'")
365 EXTRACTOR_METAFORMAT_UTF8, 365 + 1,
366 "text/plain", 366 0
367 "Revision #2: Author `cic22' worked on `C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd'", 367 },
368 strlen ("Revision #2: Author `cic22' worked on `C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd'") + 1, 368 {
369 0 369 EXTRACTOR_METATYPE_REVISION_HISTORY,
370 }, 370 EXTRACTOR_METAFORMAT_UTF8,
371 { 371 "text/plain",
372 EXTRACTOR_METATYPE_REVISION_HISTORY, 372 "Revision #2: Author `cic22' worked on `C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd'",
373 EXTRACTOR_METAFORMAT_UTF8, 373 strlen (
374 "text/plain", 374 "Revision #2: Author `cic22' worked on `C:\\DOCUME~1\\phamill\\LOCALS~1\\Temp\\AutoRecovery save of Iraq - security.asd'")
375 "Revision #3: Author `JPratt' worked on `C:\\TEMP\\Iraq - security.doc'", 375 + 1,
376 strlen ("Revision #3: Author `JPratt' worked on `C:\\TEMP\\Iraq - security.doc'") + 1, 376 0
377 0 377 },
378 }, 378 {
379 { 379 EXTRACTOR_METATYPE_REVISION_HISTORY,
380 EXTRACTOR_METATYPE_REVISION_HISTORY, 380 EXTRACTOR_METAFORMAT_UTF8,
381 EXTRACTOR_METAFORMAT_UTF8, 381 "text/plain",
382 "text/plain", 382 "Revision #3: Author `JPratt' worked on `C:\\TEMP\\Iraq - security.doc'",
383 "Revision #4: Author `JPratt' worked on `A:\\Iraq - security.doc'", 383 strlen (
384 strlen ("Revision #4: Author `JPratt' worked on `A:\\Iraq - security.doc'") + 1, 384 "Revision #3: Author `JPratt' worked on `C:\\TEMP\\Iraq - security.doc'")
385 0 385 + 1,
386 }, 386 0
387 { 387 },
388 EXTRACTOR_METATYPE_REVISION_HISTORY, 388 {
389 EXTRACTOR_METAFORMAT_UTF8, 389 EXTRACTOR_METATYPE_REVISION_HISTORY,
390 "text/plain", 390 EXTRACTOR_METAFORMAT_UTF8,
391 "Revision #5: Author `ablackshaw' worked on `C:\\ABlackshaw\\Iraq - security.doc'", 391 "text/plain",
392 strlen ("Revision #5: Author `ablackshaw' worked on `C:\\ABlackshaw\\Iraq - security.doc'") + 1, 392 "Revision #4: Author `JPratt' worked on `A:\\Iraq - security.doc'",
393 0 393 strlen (
394 }, 394 "Revision #4: Author `JPratt' worked on `A:\\Iraq - security.doc'") + 1,
395 { 395 0
396 EXTRACTOR_METATYPE_REVISION_HISTORY, 396 },
397 EXTRACTOR_METAFORMAT_UTF8, 397 {
398 "text/plain", 398 EXTRACTOR_METATYPE_REVISION_HISTORY,
399 "Revision #6: Author `ablackshaw' worked on `C:\\ABlackshaw\\A;Iraq - security.doc'", 399 EXTRACTOR_METAFORMAT_UTF8,
400 strlen ("Revision #6: Author `ablackshaw' worked on `C:\\ABlackshaw\\A;Iraq - security.doc'") + 1, 400 "text/plain",
401 0 401 "Revision #5: Author `ablackshaw' worked on `C:\\ABlackshaw\\Iraq - security.doc'",
402 }, 402 strlen (
403 { 403 "Revision #5: Author `ablackshaw' worked on `C:\\ABlackshaw\\Iraq - security.doc'")
404 EXTRACTOR_METATYPE_REVISION_HISTORY, 404 + 1,
405 EXTRACTOR_METAFORMAT_UTF8, 405 0
406 "text/plain", 406 },
407 "Revision #7: Author `ablackshaw' worked on `A:\\Iraq - security.doc'", 407 {
408 strlen ("Revision #7: Author `ablackshaw' worked on `A:\\Iraq - security.doc'") + 1, 408 EXTRACTOR_METATYPE_REVISION_HISTORY,
409 0 409 EXTRACTOR_METAFORMAT_UTF8,
410 }, 410 "text/plain",
411 { 411 "Revision #6: Author `ablackshaw' worked on `C:\\ABlackshaw\\A;Iraq - security.doc'",
412 EXTRACTOR_METATYPE_REVISION_HISTORY, 412 strlen (
413 EXTRACTOR_METAFORMAT_UTF8, 413 "Revision #6: Author `ablackshaw' worked on `C:\\ABlackshaw\\A;Iraq - security.doc'")
414 "text/plain", 414 + 1,
415 "Revision #8: Author `MKhan' worked on `C:\\TEMP\\Iraq - security.doc'", 415 0
416 strlen ("Revision #8: Author `MKhan' worked on `C:\\TEMP\\Iraq - security.doc'") + 1, 416 },
417 0 417 {
418 }, 418 EXTRACTOR_METATYPE_REVISION_HISTORY,
419 { 419 EXTRACTOR_METAFORMAT_UTF8,
420 EXTRACTOR_METATYPE_REVISION_HISTORY, 420 "text/plain",
421 EXTRACTOR_METAFORMAT_UTF8, 421 "Revision #7: Author `ablackshaw' worked on `A:\\Iraq - security.doc'",
422 "text/plain", 422 strlen (
423 "Revision #9: Author `MKhan' worked on `C:\\WINNT\\Profiles\\mkhan\\Desktop\\Iraq.doc'", 423 "Revision #7: Author `ablackshaw' worked on `A:\\Iraq - security.doc'")
424 strlen ("Revision #9: Author `MKhan' worked on `C:\\WINNT\\Profiles\\mkhan\\Desktop\\Iraq.doc'") + 1, 424 + 1,
425 0 425 0
426 }, 426 },
427 { 0, 0, NULL, NULL, 0, -1 } 427 {
428 }; 428 EXTRACTOR_METATYPE_REVISION_HISTORY,
429 EXTRACTOR_METAFORMAT_UTF8,
430 "text/plain",
431 "Revision #8: Author `MKhan' worked on `C:\\TEMP\\Iraq - security.doc'",
432 strlen (
433 "Revision #8: Author `MKhan' worked on `C:\\TEMP\\Iraq - security.doc'")
434 + 1,
435 0
436 },
437 {
438 EXTRACTOR_METATYPE_REVISION_HISTORY,
439 EXTRACTOR_METAFORMAT_UTF8,
440 "text/plain",
441 "Revision #9: Author `MKhan' worked on `C:\\WINNT\\Profiles\\mkhan\\Desktop\\Iraq.doc'",
442 strlen (
443 "Revision #9: Author `MKhan' worked on `C:\\WINNT\\Profiles\\mkhan\\Desktop\\Iraq.doc'")
444 + 1,
445 0
446 },
447 { 0, 0, NULL, NULL, 0, -1 }
448 };
429#endif 449#endif
430 struct SolutionData ole2_excel_sol[] = 450 struct SolutionData ole2_excel_sol[] = {
431 {
432 {
433 EXTRACTOR_METATYPE_CREATOR,
434 EXTRACTOR_METAFORMAT_UTF8,
435 "text/plain",
436 "JV",
437 strlen ("JV") + 1,
438 0
439 },
440 {
441 EXTRACTOR_METATYPE_LAST_SAVED_BY,
442 EXTRACTOR_METAFORMAT_UTF8,
443 "text/plain",
444 "JV",
445 strlen ("JV") + 1,
446 0
447 },
448 {
449 EXTRACTOR_METATYPE_CREATION_DATE,
450 EXTRACTOR_METAFORMAT_UTF8,
451 "text/plain",
452 "2002-03-20T21:26:28Z",
453 strlen ("2002-03-20T21:26:28Z") + 1,
454 0
455 },
456 {
457 EXTRACTOR_METATYPE_MIMETYPE,
458 EXTRACTOR_METAFORMAT_UTF8,
459 "text/plain",
460 "application/vnd.ms-files",
461 strlen ("application/vnd.ms-files") + 1,
462 0
463 },
464 {
465 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
466 EXTRACTOR_METAFORMAT_UTF8,
467 "text/plain",
468 "Microsoft Excel",
469 strlen ("Microsoft Excel") + 1,
470 0
471 },
472 { 0, 0, NULL, NULL, 0, -1 }
473 };
474
475 struct ProblemSet ps[] =
476 { 451 {
477 { "testdata/ole2_msword.doc", 452 EXTRACTOR_METATYPE_CREATOR,
478 ole2_msword_sol }, 453 EXTRACTOR_METAFORMAT_UTF8,
479 { "testdata/ole2_starwriter40.sdw", 454 "text/plain",
480 ole2_starwriter_sol }, 455 "JV",
456 strlen ("JV") + 1,
457 0
458 },
459 {
460 EXTRACTOR_METATYPE_LAST_SAVED_BY,
461 EXTRACTOR_METAFORMAT_UTF8,
462 "text/plain",
463 "JV",
464 strlen ("JV") + 1,
465 0
466 },
467 {
468 EXTRACTOR_METATYPE_CREATION_DATE,
469 EXTRACTOR_METAFORMAT_UTF8,
470 "text/plain",
471 "2002-03-20T21:26:28Z",
472 strlen ("2002-03-20T21:26:28Z") + 1,
473 0
474 },
475 {
476 EXTRACTOR_METATYPE_MIMETYPE,
477 EXTRACTOR_METAFORMAT_UTF8,
478 "text/plain",
479 "application/vnd.ms-files",
480 strlen ("application/vnd.ms-files") + 1,
481 0
482 },
483 {
484 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
485 EXTRACTOR_METAFORMAT_UTF8,
486 "text/plain",
487 "Microsoft Excel",
488 strlen ("Microsoft Excel") + 1,
489 0
490 },
491 { 0, 0, NULL, NULL, 0, -1 }
492 };
493
494 struct ProblemSet ps[] = {
495 { "testdata/ole2_msword.doc",
496 ole2_msword_sol },
497 { "testdata/ole2_starwriter40.sdw",
498 ole2_starwriter_sol },
481#if HAVE_ICONV 499#if HAVE_ICONV
482 { "testdata/ole2_blair.doc", 500 { "testdata/ole2_blair.doc",
483 ole2_blair_sol }, 501 ole2_blair_sol },
484#endif 502#endif
485 { "testdata/ole2_excel.xls", 503 { "testdata/ole2_excel.xls",
486 ole2_excel_sol }, 504 ole2_excel_sol },
487 { NULL, NULL } 505 { NULL, NULL }
488 }; 506 };
489 return ET_main ("ole2", ps); 507 return ET_main ("ole2", ps);
490} 508}
491 509
510
492/* end of test_ole2.c */ 511/* end of test_ole2.c */
diff --git a/src/plugins/test_png.c b/src/plugins/test_png.c
index 323865a..01be527 100644
--- a/src/plugins/test_png.c
+++ b/src/plugins/test_png.c
@@ -36,49 +36,48 @@
36int 36int
37main (int argc, char *argv[]) 37main (int argc, char *argv[])
38{ 38{
39 struct SolutionData png_image_sol[] = 39 struct SolutionData png_image_sol[] = {
40 { 40 {
41 { 41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METATYPE_MIMETYPE, 42 EXTRACTOR_METAFORMAT_UTF8,
43 EXTRACTOR_METAFORMAT_UTF8, 43 "text/plain",
44 "text/plain", 44 "image/png",
45 "image/png", 45 strlen ("image/png") + 1,
46 strlen ("image/png") + 1, 46 0
47 0 47 },
48 },
49 {
50 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
51 EXTRACTOR_METAFORMAT_UTF8,
52 "text/plain",
53 "4x4",
54 strlen ("4x4") + 1,
55 0
56 },
57 {
58 EXTRACTOR_METATYPE_COMMENT,
59 EXTRACTOR_METAFORMAT_UTF8,
60 "text/plain",
61 "Testing keyword extraction\n",
62 strlen ("Testing keyword extraction\n") + 1,
63 0
64 },
65 {
66 EXTRACTOR_METATYPE_UNKNOWN,
67 EXTRACTOR_METAFORMAT_UTF8,
68 "text/plain",
69 "dc6c58c971715e8043baef058b675eec",
70 strlen ("dc6c58c971715e8043baef058b675eec") + 1,
71 0
72 },
73 { 0, 0, NULL, NULL, 0, -1 }
74 };
75 struct ProblemSet ps[] =
76 { 48 {
77 { "testdata/png_image.png", 49 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
78 png_image_sol }, 50 EXTRACTOR_METAFORMAT_UTF8,
79 { NULL, NULL } 51 "text/plain",
80 }; 52 "4x4",
53 strlen ("4x4") + 1,
54 0
55 },
56 {
57 EXTRACTOR_METATYPE_COMMENT,
58 EXTRACTOR_METAFORMAT_UTF8,
59 "text/plain",
60 "Testing keyword extraction\n",
61 strlen ("Testing keyword extraction\n") + 1,
62 0
63 },
64 {
65 EXTRACTOR_METATYPE_UNKNOWN,
66 EXTRACTOR_METAFORMAT_UTF8,
67 "text/plain",
68 "dc6c58c971715e8043baef058b675eec",
69 strlen ("dc6c58c971715e8043baef058b675eec") + 1,
70 0
71 },
72 { 0, 0, NULL, NULL, 0, -1 }
73 };
74 struct ProblemSet ps[] = {
75 { "testdata/png_image.png",
76 png_image_sol },
77 { NULL, NULL }
78 };
81 return ET_main ("png", ps); 79 return ET_main ("png", ps);
82} 80}
83 81
82
84/* end of test_png.c */ 83/* end of test_png.c */
diff --git a/src/plugins/test_previewopus.c b/src/plugins/test_previewopus.c
index 6178d19..6b0b1b8 100644
--- a/src/plugins/test_previewopus.c
+++ b/src/plugins/test_previewopus.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the previewopus testcase. 30 * Main function for the previewopus testcase.
32 * 31 *
@@ -37,18 +36,17 @@
37int 36int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 struct SolutionData previewopus_audio_sol[] = 39 struct SolutionData previewopus_audio_sol[] = {
41 { 40 // TODO. Can't test as it depends on the encoder.
42 //TODO. Can't test as it depends on the encoder. 41 { 0, 0, NULL, NULL, 0, -1 }
43 { 0, 0, NULL, NULL, 0, -1 } 42 };
44 }; 43 struct ProblemSet ps[] = {
45 struct ProblemSet ps[] = 44 { "testdata/mpeg_alien.mpg",
46 { 45 previewopus_audio_sol },
47 { "testdata/mpeg_alien.mpg", 46 { NULL, NULL }
48 previewopus_audio_sol }, 47 };
49 { NULL, NULL }
50 };
51 return ET_main ("previewopus", ps); 48 return ET_main ("previewopus", ps);
52} 49}
53 50
51
54/* end of test_thumbnailffmpeg.c */ 52/* end of test_thumbnailffmpeg.c */
diff --git a/src/plugins/test_ps.c b/src/plugins/test_ps.c
index 6fc66bb..73167fa 100644
--- a/src/plugins/test_ps.c
+++ b/src/plugins/test_ps.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the PS testcase. 30 * Main function for the PS testcase.
32 * 31 *
@@ -37,103 +36,105 @@
37int 36int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 struct SolutionData ps_bloomfilter_sol[] = 39 struct SolutionData ps_bloomfilter_sol[] = {
40 {
41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METAFORMAT_UTF8,
43 "text/plain",
44 "application/postscript",
45 strlen ("application/postscript") + 1,
46 0
47 },
48 {
49 EXTRACTOR_METATYPE_TITLE,
50 EXTRACTOR_METAFORMAT_UTF8,
51 "text/plain",
52 "A Quick Introduction to Bloom Filters",
53 strlen ("A Quick Introduction to Bloom Filters") + 1,
54 0
55 },
56 {
57 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
58 EXTRACTOR_METAFORMAT_UTF8,
59 "text/plain",
60 "dvips(k) 5.92b Copyright 2002 Radical Eye Software",
61 strlen ("dvips(k) 5.92b Copyright 2002 Radical Eye Software") + 1,
62 0
63 },
64 {
65 EXTRACTOR_METATYPE_PAGE_COUNT,
66 EXTRACTOR_METAFORMAT_UTF8,
67 "text/plain",
68 "1",
69 strlen ("1") + 1,
70 0
71 },
41 { 72 {
42 { 73 EXTRACTOR_METATYPE_PAGE_ORDER,
43 EXTRACTOR_METATYPE_MIMETYPE, 74 EXTRACTOR_METAFORMAT_UTF8,
44 EXTRACTOR_METAFORMAT_UTF8, 75 "text/plain",
45 "text/plain", 76 "Ascend",
46 "application/postscript", 77 strlen ("Ascend") + 1,
47 strlen ("application/postscript") + 1, 78 0
48 0 79 },
49 }, 80 { 0, 0, NULL, NULL, 0, -1 }
50 { 81 };
51 EXTRACTOR_METATYPE_TITLE, 82 struct SolutionData ps_wallace_sol[] = {
52 EXTRACTOR_METAFORMAT_UTF8,
53 "text/plain",
54 "A Quick Introduction to Bloom Filters",
55 strlen ("A Quick Introduction to Bloom Filters") + 1,
56 0
57 },
58 {
59 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
60 EXTRACTOR_METAFORMAT_UTF8,
61 "text/plain",
62 "dvips(k) 5.92b Copyright 2002 Radical Eye Software",
63 strlen ("dvips(k) 5.92b Copyright 2002 Radical Eye Software") + 1,
64 0
65 },
66 {
67 EXTRACTOR_METATYPE_PAGE_COUNT,
68 EXTRACTOR_METAFORMAT_UTF8,
69 "text/plain",
70 "1",
71 strlen ("1") + 1,
72 0
73 },
74 {
75 EXTRACTOR_METATYPE_PAGE_ORDER,
76 EXTRACTOR_METAFORMAT_UTF8,
77 "text/plain",
78 "Ascend",
79 strlen ("Ascend") + 1,
80 0
81 },
82 { 0, 0, NULL, NULL, 0, -1 }
83 };
84 struct SolutionData ps_wallace_sol[] =
85 { 83 {
86 { 84 EXTRACTOR_METATYPE_MIMETYPE,
87 EXTRACTOR_METATYPE_MIMETYPE, 85 EXTRACTOR_METAFORMAT_UTF8,
88 EXTRACTOR_METAFORMAT_UTF8, 86 "text/plain",
89 "text/plain", 87 "application/postscript",
90 "application/postscript", 88 strlen ("application/postscript") + 1,
91 strlen ("application/postscript") + 1, 89 0
92 0 90 },
93 },
94 {
95 EXTRACTOR_METATYPE_SUBJECT,
96 EXTRACTOR_METAFORMAT_UTF8,
97 "text/plain",
98 "PS preprint of JPEG article submitted to IEEE Trans on Consum. Elect",
99 strlen ("PS preprint of JPEG article submitted to IEEE Trans on Consum. Elect") + 1,
100 0
101 },
102 {
103 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
104 EXTRACTOR_METAFORMAT_UTF8,
105 "text/plain",
106 "DECwrite V1.1 Copyright (c) 1990 DIGITAL EQUIPMENT CORPORATION. All Rights Reserved.",
107 strlen ("DECwrite V1.1 Copyright (c) 1990 DIGITAL EQUIPMENT CORPORATION. All Rights Reserved.") + 1,
108 0
109 },
110 {
111 EXTRACTOR_METATYPE_AUTHOR_NAME,
112 EXTRACTOR_METAFORMAT_UTF8,
113 "text/plain",
114 "Greg Wallace",
115 strlen ("Greg Wallace") + 1,
116 0
117 },
118 {
119 EXTRACTOR_METATYPE_UNKNOWN_DATE,
120 EXTRACTOR_METAFORMAT_UTF8,
121 "text/plain",
122 "Tue, 17 Dec 91 14:49:50 PST",
123 strlen ("Tue, 17 Dec 91 14:49:50 PST") + 1,
124 0
125 },
126 { 0, 0, NULL, NULL, 0, -1 }
127 };
128 struct ProblemSet ps[] =
129 { 91 {
130 { "testdata/ps_bloomfilter.ps", 92 EXTRACTOR_METATYPE_SUBJECT,
131 ps_bloomfilter_sol }, 93 EXTRACTOR_METAFORMAT_UTF8,
132 { "testdata/ps_wallace.ps", 94 "text/plain",
133 ps_wallace_sol }, 95 "PS preprint of JPEG article submitted to IEEE Trans on Consum. Elect",
134 { NULL, NULL } 96 strlen (
135 }; 97 "PS preprint of JPEG article submitted to IEEE Trans on Consum. Elect")
98 + 1,
99 0
100 },
101 {
102 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
103 EXTRACTOR_METAFORMAT_UTF8,
104 "text/plain",
105 "DECwrite V1.1 Copyright (c) 1990 DIGITAL EQUIPMENT CORPORATION. All Rights Reserved.",
106 strlen (
107 "DECwrite V1.1 Copyright (c) 1990 DIGITAL EQUIPMENT CORPORATION. All Rights Reserved.")
108 + 1,
109 0
110 },
111 {
112 EXTRACTOR_METATYPE_AUTHOR_NAME,
113 EXTRACTOR_METAFORMAT_UTF8,
114 "text/plain",
115 "Greg Wallace",
116 strlen ("Greg Wallace") + 1,
117 0
118 },
119 {
120 EXTRACTOR_METATYPE_UNKNOWN_DATE,
121 EXTRACTOR_METAFORMAT_UTF8,
122 "text/plain",
123 "Tue, 17 Dec 91 14:49:50 PST",
124 strlen ("Tue, 17 Dec 91 14:49:50 PST") + 1,
125 0
126 },
127 { 0, 0, NULL, NULL, 0, -1 }
128 };
129 struct ProblemSet ps[] = {
130 { "testdata/ps_bloomfilter.ps",
131 ps_bloomfilter_sol },
132 { "testdata/ps_wallace.ps",
133 ps_wallace_sol },
134 { NULL, NULL }
135 };
136 return ET_main ("ps", ps); 136 return ET_main ("ps", ps);
137} 137}
138 138
139
139/* end of test_ps.c */ 140/* end of test_ps.c */
diff --git a/src/plugins/test_riff.c b/src/plugins/test_riff.c
index 2838a08..6993b2c 100644
--- a/src/plugins/test_riff.c
+++ b/src/plugins/test_riff.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the RIFF testcase. 30 * Main function for the RIFF testcase.
32 * 31 *
@@ -37,41 +36,40 @@
37int 36int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 struct SolutionData riff_flame_sol[] = 39 struct SolutionData riff_flame_sol[] = {
40 {
41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METAFORMAT_UTF8,
43 "text/plain",
44 "video/x-msvideo",
45 strlen ("video/x-msvideo") + 1,
46 0
47 },
41 { 48 {
42 { 49 EXTRACTOR_METATYPE_FORMAT,
43 EXTRACTOR_METATYPE_MIMETYPE, 50 EXTRACTOR_METAFORMAT_UTF8,
44 EXTRACTOR_METAFORMAT_UTF8, 51 "text/plain",
45 "text/plain", 52 "codec: cvid, 35 fps, 3143 ms",
46 "video/x-msvideo", 53 strlen ("codec: cvid, 35 fps, 3143 ms") + 1,
47 strlen ("video/x-msvideo") + 1, 54 0
48 0 55 },
49 },
50 {
51 EXTRACTOR_METATYPE_FORMAT,
52 EXTRACTOR_METAFORMAT_UTF8,
53 "text/plain",
54 "codec: cvid, 35 fps, 3143 ms",
55 strlen ("codec: cvid, 35 fps, 3143 ms") + 1,
56 0
57 },
58 {
59 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
60 EXTRACTOR_METAFORMAT_UTF8,
61 "text/plain",
62 "256x240",
63 strlen ("256x240") + 1,
64 0
65 },
66 { 0, 0, NULL, NULL, 0, -1 }
67 };
68 struct ProblemSet ps[] =
69 { 56 {
70 { "testdata/riff_flame.avi", 57 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
71 riff_flame_sol }, 58 EXTRACTOR_METAFORMAT_UTF8,
72 { NULL, NULL } 59 "text/plain",
73 }; 60 "256x240",
61 strlen ("256x240") + 1,
62 0
63 },
64 { 0, 0, NULL, NULL, 0, -1 }
65 };
66 struct ProblemSet ps[] = {
67 { "testdata/riff_flame.avi",
68 riff_flame_sol },
69 { NULL, NULL }
70 };
74 return ET_main ("riff", ps); 71 return ET_main ("riff", ps);
75} 72}
76 73
74
77/* end of test_riff.c */ 75/* end of test_riff.c */
diff --git a/src/plugins/test_rpm.c b/src/plugins/test_rpm.c
index 95affa5..e9fbfc6 100644
--- a/src/plugins/test_rpm.c
+++ b/src/plugins/test_rpm.c
@@ -34,12 +34,13 @@
34/** 34/**
35 * Expected package description text. 35 * Expected package description text.
36 */ 36 */
37#define DESCRIPTION "The libtool package contains the GNU libtool, a set of shell scripts\n"\ 37#define DESCRIPTION \
38 "which automatically configure UNIX and UNIX-like architectures to\n" \ 38 "The libtool package contains the GNU libtool, a set of shell scripts\n" \
39 "which automatically configure UNIX and UNIX-like architectures to\n" \
39 "generically build shared libraries. Libtool provides a consistent,\n" \ 40 "generically build shared libraries. Libtool provides a consistent,\n" \
40 "portable interface which simplifies the process of using shared\n" \ 41 "portable interface which simplifies the process of using shared\n" \
41 "libraries.\n" \ 42 "libraries.\n" \
42 "\n" \ 43 "\n" \
43 "If you are developing programs which will use shared libraries, you\n" \ 44 "If you are developing programs which will use shared libraries, you\n" \
44 "should install libtool." 45 "should install libtool."
45 46
@@ -54,273 +55,272 @@
54int 55int
55main (int argc, char *argv[]) 56main (int argc, char *argv[])
56{ 57{
57 struct SolutionData rpm_test_sol[] = 58 struct SolutionData rpm_test_sol[] = {
58 { 59 {
59 { 60 EXTRACTOR_METATYPE_MIMETYPE,
60 EXTRACTOR_METATYPE_MIMETYPE, 61 EXTRACTOR_METAFORMAT_UTF8,
61 EXTRACTOR_METAFORMAT_UTF8, 62 "text/plain",
62 "text/plain", 63 "application/x-rpm",
63 "application/x-rpm", 64 strlen ("application/x-rpm") + 1,
64 strlen ("application/x-rpm") + 1, 65 0
65 0 66 },
66 }, 67 {
67 { 68 EXTRACTOR_METATYPE_PACKAGE_NAME,
68 EXTRACTOR_METATYPE_PACKAGE_NAME, 69 EXTRACTOR_METAFORMAT_UTF8,
69 EXTRACTOR_METAFORMAT_UTF8, 70 "text/plain",
70 "text/plain", 71 "libtool",
71 "libtool", 72 strlen ("libtool") + 1,
72 strlen ("libtool") + 1, 73 0
73 0 74 },
74 }, 75 {
75 { 76 EXTRACTOR_METATYPE_SOFTWARE_VERSION,
76 EXTRACTOR_METATYPE_SOFTWARE_VERSION, 77 EXTRACTOR_METAFORMAT_UTF8,
77 EXTRACTOR_METAFORMAT_UTF8, 78 "text/plain",
78 "text/plain", 79 "1.5",
79 "1.5", 80 strlen ("1.5") + 1,
80 strlen ("1.5") + 1, 81 0
81 0 82 },
82 }, 83 {
83 { 84 EXTRACTOR_METATYPE_PACKAGE_VERSION,
84 EXTRACTOR_METATYPE_PACKAGE_VERSION, 85 EXTRACTOR_METAFORMAT_UTF8,
85 EXTRACTOR_METAFORMAT_UTF8, 86 "text/plain",
86 "text/plain", 87 "6",
87 "6", 88 strlen ("6") + 1,
88 strlen ("6") + 1, 89 0
89 0 90 },
90 }, 91 {
91 { 92 EXTRACTOR_METATYPE_SUMMARY,
92 EXTRACTOR_METATYPE_SUMMARY, 93 EXTRACTOR_METAFORMAT_UTF8,
93 EXTRACTOR_METAFORMAT_UTF8, 94 "text/plain",
94 "text/plain", 95 SUMMARY,
95 SUMMARY, 96 strlen (SUMMARY) + 1,
96 strlen (SUMMARY) + 1, 97 0
97 0 98 },
98 }, 99 {
99 { 100 EXTRACTOR_METATYPE_DESCRIPTION,
100 EXTRACTOR_METATYPE_DESCRIPTION, 101 EXTRACTOR_METAFORMAT_UTF8,
101 EXTRACTOR_METAFORMAT_UTF8, 102 "text/plain",
102 "text/plain", 103 DESCRIPTION,
103 DESCRIPTION, 104 strlen (DESCRIPTION) + 1,
104 strlen (DESCRIPTION) + 1, 105 0
105 0 106 },
106 }, 107 {
107 { 108 EXTRACTOR_METATYPE_CREATION_DATE,
108 EXTRACTOR_METATYPE_CREATION_DATE, 109 EXTRACTOR_METAFORMAT_UTF8,
109 EXTRACTOR_METAFORMAT_UTF8, 110 "text/plain",
110 "text/plain", 111 "Thu Oct 2 11:44:33 2003",
111 "Thu Oct 2 11:44:33 2003", 112 strlen ("Thu Oct 2 11:44:33 2003") + 1,
112 strlen ("Thu Oct 2 11:44:33 2003") + 1, 113 0
113 0 114 },
114 }, 115 {
115 { 116 EXTRACTOR_METATYPE_BUILDHOST,
116 EXTRACTOR_METATYPE_BUILDHOST, 117 EXTRACTOR_METAFORMAT_UTF8,
117 EXTRACTOR_METAFORMAT_UTF8, 118 "text/plain",
118 "text/plain", 119 "bullwinkle.devel.redhat.com",
119 "bullwinkle.devel.redhat.com", 120 strlen ("bullwinkle.devel.redhat.com") + 1,
120 strlen ("bullwinkle.devel.redhat.com") + 1, 121 0
121 0 122 },
122 }, 123 {
123 { 124 EXTRACTOR_METATYPE_PACKAGE_INSTALLED_SIZE,
124 EXTRACTOR_METATYPE_PACKAGE_INSTALLED_SIZE, 125 EXTRACTOR_METAFORMAT_UTF8,
125 EXTRACTOR_METAFORMAT_UTF8, 126 "text/plain",
126 "text/plain", 127 "2623621",
127 "2623621", 128 strlen ("2623621") + 1,
128 strlen ("2623621") + 1, 129 0
129 0 130 },
130 }, 131 {
131 { 132 EXTRACTOR_METATYPE_PACKAGE_DISTRIBUTION,
132 EXTRACTOR_METATYPE_PACKAGE_DISTRIBUTION, 133 EXTRACTOR_METAFORMAT_UTF8,
133 EXTRACTOR_METAFORMAT_UTF8, 134 "text/plain",
134 "text/plain", 135 "Red Hat Linux",
135 "Red Hat Linux", 136 strlen ("Red Hat Linux") + 1,
136 strlen ("Red Hat Linux") + 1, 137 0
137 0 138 },
138 }, 139 {
139 { 140 EXTRACTOR_METATYPE_VENDOR,
140 EXTRACTOR_METATYPE_VENDOR, 141 EXTRACTOR_METAFORMAT_UTF8,
141 EXTRACTOR_METAFORMAT_UTF8, 142 "text/plain",
142 "text/plain", 143 "Red Hat, Inc.",
143 "Red Hat, Inc.", 144 strlen ("Red Hat, Inc.") + 1,
144 strlen ("Red Hat, Inc.") + 1, 145 0
145 0 146 },
146 }, 147 {
147 { 148 EXTRACTOR_METATYPE_LICENSE,
148 EXTRACTOR_METATYPE_LICENSE, 149 EXTRACTOR_METAFORMAT_UTF8,
149 EXTRACTOR_METAFORMAT_UTF8, 150 "text/plain",
150 "text/plain", 151 "GPL",
151 "GPL", 152 strlen ("GPL") + 1,
152 strlen ("GPL") + 1, 153 0
153 0 154 },
154 }, 155 {
155 { 156 EXTRACTOR_METATYPE_PACKAGE_MAINTAINER,
156 EXTRACTOR_METATYPE_PACKAGE_MAINTAINER, 157 EXTRACTOR_METAFORMAT_UTF8,
157 EXTRACTOR_METAFORMAT_UTF8, 158 "text/plain",
158 "text/plain", 159 "Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>",
159 "Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>", 160 strlen ("Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>") + 1,
160 strlen ("Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>") + 1, 161 0
161 0 162 },
162 }, 163 {
163 { 164 EXTRACTOR_METATYPE_SECTION,
164 EXTRACTOR_METATYPE_SECTION, 165 EXTRACTOR_METAFORMAT_UTF8,
165 EXTRACTOR_METAFORMAT_UTF8, 166 "text/plain",
166 "text/plain", 167 "Development/Tools",
167 "Development/Tools", 168 strlen ("Development/Tools") + 1,
168 strlen ("Development/Tools") + 1, 169 0
169 0 170 },
170 }, 171 {
171 { 172 EXTRACTOR_METATYPE_URL,
172 EXTRACTOR_METATYPE_URL, 173 EXTRACTOR_METAFORMAT_UTF8,
173 EXTRACTOR_METAFORMAT_UTF8, 174 "text/plain",
174 "text/plain", 175 "http://www.gnu.org/software/libtool/",
175 "http://www.gnu.org/software/libtool/", 176 strlen ("http://www.gnu.org/software/libtool/") + 1,
176 strlen ("http://www.gnu.org/software/libtool/") + 1, 177 0
177 0 178 },
178 }, 179 {
179 { 180 EXTRACTOR_METATYPE_TARGET_OS,
180 EXTRACTOR_METATYPE_TARGET_OS, 181 EXTRACTOR_METAFORMAT_UTF8,
181 EXTRACTOR_METAFORMAT_UTF8, 182 "text/plain",
182 "text/plain", 183 "linux",
183 "linux", 184 strlen ("linux") + 1,
184 strlen ("linux") + 1, 185 0
185 0 186 },
186 }, 187 {
187 { 188 EXTRACTOR_METATYPE_TARGET_ARCHITECTURE,
188 EXTRACTOR_METATYPE_TARGET_ARCHITECTURE, 189 EXTRACTOR_METAFORMAT_UTF8,
189 EXTRACTOR_METAFORMAT_UTF8, 190 "text/plain",
190 "text/plain", 191 "ia64",
191 "ia64", 192 strlen ("ia64") + 1,
192 strlen ("ia64") + 1, 193 0
193 0 194 },
194 }, 195 {
195 { 196 EXTRACTOR_METATYPE_PACKAGE_PROVIDES,
196 EXTRACTOR_METATYPE_PACKAGE_PROVIDES, 197 EXTRACTOR_METAFORMAT_UTF8,
197 EXTRACTOR_METAFORMAT_UTF8, 198 "text/plain",
198 "text/plain", 199 "libtool",
199 "libtool", 200 strlen ("libtool") + 1,
200 strlen ("libtool") + 1, 201 0
201 0 202 },
202 }, 203 {
203 { 204 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY,
204 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, 205 EXTRACTOR_METAFORMAT_UTF8,
205 EXTRACTOR_METAFORMAT_UTF8, 206 "text/plain",
206 "text/plain", 207 "/bin/sh",
207 "/bin/sh", 208 strlen ("/bin/sh") + 1,
208 strlen ("/bin/sh") + 1, 209 0
209 0 210 },
210 }, 211 {
211 { 212 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY,
212 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, 213 EXTRACTOR_METAFORMAT_UTF8,
213 EXTRACTOR_METAFORMAT_UTF8, 214 "text/plain",
214 "text/plain", 215 "/bin/sh",
215 "/bin/sh", 216 strlen ("/bin/sh") + 1,
216 strlen ("/bin/sh") + 1, 217 0
217 0 218 },
218 }, 219 {
219 { 220 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY,
220 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, 221 EXTRACTOR_METAFORMAT_UTF8,
221 EXTRACTOR_METAFORMAT_UTF8, 222 "text/plain",
222 "text/plain", 223 "/bin/sh",
223 "/bin/sh", 224 strlen ("/bin/sh") + 1,
224 strlen ("/bin/sh") + 1, 225 0
225 0 226 },
226 }, 227 {
227 { 228 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY,
228 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, 229 EXTRACTOR_METAFORMAT_UTF8,
229 EXTRACTOR_METAFORMAT_UTF8, 230 "text/plain",
230 "text/plain", 231 "/sbin/install-info",
231 "/sbin/install-info", 232 strlen ("/sbin/install-info") + 1,
232 strlen ("/sbin/install-info") + 1, 233 0
233 0 234 },
234 }, 235 {
235 { 236 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY,
236 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, 237 EXTRACTOR_METAFORMAT_UTF8,
237 EXTRACTOR_METAFORMAT_UTF8, 238 "text/plain",
238 "text/plain", 239 "autoconf",
239 "autoconf", 240 strlen ("autoconf") + 1,
240 strlen ("autoconf") + 1, 241 0
241 0 242 },
242 }, 243 {
243 { 244 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY,
244 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, 245 EXTRACTOR_METAFORMAT_UTF8,
245 EXTRACTOR_METAFORMAT_UTF8, 246 "text/plain",
246 "text/plain", 247 "automake",
247 "automake", 248 strlen ("automake") + 1,
248 strlen ("automake") + 1, 249 0
249 0 250 },
250 }, 251 {
251 { 252 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY,
252 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, 253 EXTRACTOR_METAFORMAT_UTF8,
253 EXTRACTOR_METAFORMAT_UTF8, 254 "text/plain",
254 "text/plain", 255 "libtool-libs",
255 "libtool-libs", 256 strlen ("libtool-libs") + 1,
256 strlen ("libtool-libs") + 1, 257 0
257 0 258 },
258 }, 259 {
259 { 260 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY,
260 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, 261 EXTRACTOR_METAFORMAT_UTF8,
261 EXTRACTOR_METAFORMAT_UTF8, 262 "text/plain",
262 "text/plain", 263 "m4",
263 "m4", 264 strlen ("m4") + 1,
264 strlen ("m4") + 1, 265 0
265 0 266 },
266 }, 267 {
267 { 268 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY,
268 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, 269 EXTRACTOR_METAFORMAT_UTF8,
269 EXTRACTOR_METAFORMAT_UTF8, 270 "text/plain",
270 "text/plain", 271 "mktemp",
271 "mktemp", 272 strlen ("mktemp") + 1,
272 strlen ("mktemp") + 1, 273 0
273 0 274 },
274 }, 275 {
275 { 276 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY,
276 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, 277 EXTRACTOR_METAFORMAT_UTF8,
277 EXTRACTOR_METAFORMAT_UTF8, 278 "text/plain",
278 "text/plain", 279 "perl",
279 "perl", 280 strlen ("perl") + 1,
280 strlen ("perl") + 1, 281 0
281 0 282 },
282 }, 283 {
283 { 284 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY,
284 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, 285 EXTRACTOR_METAFORMAT_UTF8,
285 EXTRACTOR_METAFORMAT_UTF8, 286 "text/plain",
286 "text/plain", 287 "rpmlib(CompressedFileNames)",
287 "rpmlib(CompressedFileNames)", 288 strlen ("rpmlib(CompressedFileNames)") + 1,
288 strlen ("rpmlib(CompressedFileNames)") + 1, 289 0
289 0 290 },
290 }, 291 {
291 { 292 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY,
292 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, 293 EXTRACTOR_METAFORMAT_UTF8,
293 EXTRACTOR_METAFORMAT_UTF8, 294 "text/plain",
294 "text/plain", 295 "rpmlib(PayloadFilesHavePrefix)",
295 "rpmlib(PayloadFilesHavePrefix)", 296 strlen ("rpmlib(PayloadFilesHavePrefix)") + 1,
296 strlen ("rpmlib(PayloadFilesHavePrefix)") + 1, 297 0
297 0 298 },
298 }, 299 {
299 { 300 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY,
300 EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, 301 EXTRACTOR_METAFORMAT_UTF8,
301 EXTRACTOR_METAFORMAT_UTF8, 302 "text/plain",
302 "text/plain", 303 "rpmlib(VersionedDependencies)",
303 "rpmlib(VersionedDependencies)", 304 strlen ("rpmlib(VersionedDependencies)") + 1,
304 strlen ("rpmlib(VersionedDependencies)") + 1, 305 0
305 0 306 },
306 }, 307 {
307 { 308 EXTRACTOR_METATYPE_TARGET_PLATFORM,
308 EXTRACTOR_METATYPE_TARGET_PLATFORM, 309 EXTRACTOR_METAFORMAT_UTF8,
309 EXTRACTOR_METAFORMAT_UTF8, 310 "text/plain",
310 "text/plain", 311 "ia64-redhat-linux-gnu",
311 "ia64-redhat-linux-gnu", 312 strlen ("ia64-redhat-linux-gnu") + 1,
312 strlen ("ia64-redhat-linux-gnu") + 1, 313 0
313 0 314 },
314 }, 315 { 0, 0, NULL, NULL, 0, -1 }
315 { 0, 0, NULL, NULL, 0, -1 } 316 };
316 }; 317 struct ProblemSet ps[] = {
317 struct ProblemSet ps[] = 318 { "testdata/rpm_test.rpm",
318 { 319 rpm_test_sol },
319 { "testdata/rpm_test.rpm", 320 { NULL, NULL }
320 rpm_test_sol }, 321 };
321 { NULL, NULL }
322 };
323 return ET_main ("rpm", ps); 322 return ET_main ("rpm", ps);
324} 323}
325 324
325
326/* end of test_rpm.c */ 326/* end of test_rpm.c */
diff --git a/src/plugins/test_s3m.c b/src/plugins/test_s3m.c
index 1487daf..af99df2 100644
--- a/src/plugins/test_s3m.c
+++ b/src/plugins/test_s3m.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the S3M testcase. 30 * Main function for the S3M testcase.
32 * 31 *
@@ -37,33 +36,32 @@
37int 36int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 struct SolutionData s3m_2ndpm_sol[] = 39 struct SolutionData s3m_2ndpm_sol[] = {
41 { 40 {
42 { 41 EXTRACTOR_METATYPE_MIMETYPE,
43 EXTRACTOR_METATYPE_MIMETYPE, 42 EXTRACTOR_METAFORMAT_UTF8,
44 EXTRACTOR_METAFORMAT_UTF8, 43 "text/plain",
45 "text/plain", 44 "audio/x-s3m",
46 "audio/x-s3m", 45 strlen ("audio/x-s3m") + 1,
47 strlen ("audio/x-s3m") + 1, 46 0
48 0 47 },
49 },
50 {
51 EXTRACTOR_METATYPE_TITLE,
52 EXTRACTOR_METAFORMAT_UTF8,
53 "text/plain",
54 "UnreaL ][ / PM ",
55 strlen ("UnreaL ][ / PM ") + 1,
56 0
57 },
58 { 0, 0, NULL, NULL, 0, -1 }
59 };
60 struct ProblemSet ps[] =
61 { 48 {
62 { "testdata/s3m_2nd_pm.s3m", 49 EXTRACTOR_METATYPE_TITLE,
63 s3m_2ndpm_sol }, 50 EXTRACTOR_METAFORMAT_UTF8,
64 { NULL, NULL } 51 "text/plain",
65 }; 52 "UnreaL ][ / PM ",
53 strlen ("UnreaL ][ / PM ") + 1,
54 0
55 },
56 { 0, 0, NULL, NULL, 0, -1 }
57 };
58 struct ProblemSet ps[] = {
59 { "testdata/s3m_2nd_pm.s3m",
60 s3m_2ndpm_sol },
61 { NULL, NULL }
62 };
66 return ET_main ("s3m", ps); 63 return ET_main ("s3m", ps);
67} 64}
68 65
66
69/* end of test_s3m.c */ 67/* end of test_s3m.c */
diff --git a/src/plugins/test_sid.c b/src/plugins/test_sid.c
index cab6c0a..0591626 100644
--- a/src/plugins/test_sid.c
+++ b/src/plugins/test_sid.c
@@ -36,89 +36,88 @@
36int 36int
37main (int argc, char *argv[]) 37main (int argc, char *argv[])
38{ 38{
39 struct SolutionData sid_wizball_sol[] = 39 struct SolutionData sid_wizball_sol[] = {
40 { 40 {
41 { 41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METATYPE_MIMETYPE, 42 EXTRACTOR_METAFORMAT_UTF8,
43 EXTRACTOR_METAFORMAT_UTF8, 43 "text/plain",
44 "text/plain", 44 "audio/prs.sid",
45 "audio/prs.sid", 45 strlen ("audio/prs.sid") + 1,
46 strlen ("audio/prs.sid") + 1, 46 0
47 0 47 },
48 },
49 {
50 EXTRACTOR_METATYPE_FORMAT_VERSION,
51 EXTRACTOR_METAFORMAT_UTF8,
52 "text/plain",
53 "2",
54 strlen ("2") + 1,
55 0
56 },
57 {
58 EXTRACTOR_METATYPE_SONG_COUNT,
59 EXTRACTOR_METAFORMAT_UTF8,
60 "text/plain",
61 "9",
62 strlen ("9") + 1,
63 0
64 },
65 {
66 EXTRACTOR_METATYPE_STARTING_SONG,
67 EXTRACTOR_METAFORMAT_UTF8,
68 "text/plain",
69 "4",
70 strlen ("4") + 1,
71 0
72 },
73 {
74 EXTRACTOR_METATYPE_ALBUM,
75 EXTRACTOR_METAFORMAT_UTF8,
76 "text/plain",
77 "Wizball",
78 strlen ("Wizball") + 1,
79 0
80 },
81 {
82 EXTRACTOR_METATYPE_ARTIST,
83 EXTRACTOR_METAFORMAT_UTF8,
84 "text/plain",
85 "Martin Galway",
86 strlen ("Martin Galway") + 1,
87 0
88 },
89 {
90 EXTRACTOR_METATYPE_COPYRIGHT,
91 EXTRACTOR_METAFORMAT_UTF8,
92 "text/plain",
93 "1987 Ocean",
94 strlen ("1987 Ocean") + 1,
95 0
96 },
97 {
98 EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM,
99 EXTRACTOR_METAFORMAT_UTF8,
100 "text/plain",
101 "PAL",
102 strlen ("PAL") + 1,
103 0
104 },
105 {
106 EXTRACTOR_METATYPE_TARGET_ARCHITECTURE,
107 EXTRACTOR_METAFORMAT_UTF8,
108 "text/plain",
109 "MOS6581",
110 strlen ("MOS6581") + 1,
111 0
112 },
113 { 0, 0, NULL, NULL, 0, -1 }
114 };
115 struct ProblemSet ps[] =
116 { 48 {
117 { "testdata/sid_wizball.sid", 49 EXTRACTOR_METATYPE_FORMAT_VERSION,
118 sid_wizball_sol }, 50 EXTRACTOR_METAFORMAT_UTF8,
119 { NULL, NULL } 51 "text/plain",
120 }; 52 "2",
53 strlen ("2") + 1,
54 0
55 },
56 {
57 EXTRACTOR_METATYPE_SONG_COUNT,
58 EXTRACTOR_METAFORMAT_UTF8,
59 "text/plain",
60 "9",
61 strlen ("9") + 1,
62 0
63 },
64 {
65 EXTRACTOR_METATYPE_STARTING_SONG,
66 EXTRACTOR_METAFORMAT_UTF8,
67 "text/plain",
68 "4",
69 strlen ("4") + 1,
70 0
71 },
72 {
73 EXTRACTOR_METATYPE_ALBUM,
74 EXTRACTOR_METAFORMAT_UTF8,
75 "text/plain",
76 "Wizball",
77 strlen ("Wizball") + 1,
78 0
79 },
80 {
81 EXTRACTOR_METATYPE_ARTIST,
82 EXTRACTOR_METAFORMAT_UTF8,
83 "text/plain",
84 "Martin Galway",
85 strlen ("Martin Galway") + 1,
86 0
87 },
88 {
89 EXTRACTOR_METATYPE_COPYRIGHT,
90 EXTRACTOR_METAFORMAT_UTF8,
91 "text/plain",
92 "1987 Ocean",
93 strlen ("1987 Ocean") + 1,
94 0
95 },
96 {
97 EXTRACTOR_METATYPE_BROADCAST_TELEVISION_SYSTEM,
98 EXTRACTOR_METAFORMAT_UTF8,
99 "text/plain",
100 "PAL",
101 strlen ("PAL") + 1,
102 0
103 },
104 {
105 EXTRACTOR_METATYPE_TARGET_ARCHITECTURE,
106 EXTRACTOR_METAFORMAT_UTF8,
107 "text/plain",
108 "MOS6581",
109 strlen ("MOS6581") + 1,
110 0
111 },
112 { 0, 0, NULL, NULL, 0, -1 }
113 };
114 struct ProblemSet ps[] = {
115 { "testdata/sid_wizball.sid",
116 sid_wizball_sol },
117 { NULL, NULL }
118 };
121 return ET_main ("sid", ps); 119 return ET_main ("sid", ps);
122} 120}
123 121
122
124/* end of test_sid.c */ 123/* end of test_sid.c */
diff --git a/src/plugins/test_thumbnailffmpeg.c b/src/plugins/test_thumbnailffmpeg.c
index b7ad9c5..3efd69b 100644
--- a/src/plugins/test_thumbnailffmpeg.c
+++ b/src/plugins/test_thumbnailffmpeg.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the THUMBNAILFFMPEG testcase. 30 * Main function for the THUMBNAILFFMPEG testcase.
32 * 31 *
@@ -37,17 +36,16 @@
37int 36int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 struct SolutionData thumbnailffmpeg_video_sol[] = 39 struct SolutionData thumbnailffmpeg_video_sol[] = {
41 { 40 { 0, 0, NULL, NULL, 0, -1 }
42 { 0, 0, NULL, NULL, 0, -1 } 41 };
43 }; 42 struct ProblemSet ps[] = {
44 struct ProblemSet ps[] = 43 { "testdata/thumbnailffmpeg_video.mov",
45 { 44 thumbnailffmpeg_video_sol },
46 { "testdata/thumbnailffmpeg_video.mov", 45 { NULL, NULL }
47 thumbnailffmpeg_video_sol }, 46 };
48 { NULL, NULL }
49 };
50 return ET_main ("thumbnailffmpeg", ps); 47 return ET_main ("thumbnailffmpeg", ps);
51} 48}
52 49
50
53/* end of test_thumbnailffmpeg.c */ 51/* end of test_thumbnailffmpeg.c */
diff --git a/src/plugins/test_thumbnailgtk.c b/src/plugins/test_thumbnailgtk.c
index 53edb19..4970af7 100644
--- a/src/plugins/test_thumbnailgtk.c
+++ b/src/plugins/test_thumbnailgtk.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the THUMBNAILGTKJ testcase. 30 * Main function for the THUMBNAILGTKJ testcase.
32 * 31 *
@@ -38,33 +37,32 @@ int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 uint8_t thumbnail_data[] = { 137, 80, 78, 71 /* rest omitted */ }; 39 uint8_t thumbnail_data[] = { 137, 80, 78, 71 /* rest omitted */ };
41 struct SolutionData thumbnail_torsten_sol[] = 40 struct SolutionData thumbnail_torsten_sol[] = {
42 { 41 {
43 { 42 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
44 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, 43 EXTRACTOR_METAFORMAT_UTF8,
45 EXTRACTOR_METAFORMAT_UTF8, 44 "text/plain",
46 "text/plain", 45 "1600x1200",
47 "1600x1200", 46 strlen ("1600x1200") + 1,
48 strlen ("1600x1200") + 1, 47 0
49 0 48 },
50 },
51 {
52 EXTRACTOR_METATYPE_THUMBNAIL,
53 EXTRACTOR_METAFORMAT_BINARY,
54 "image/png",
55 (void *) thumbnail_data,
56 sizeof (thumbnail_data),
57 0
58 },
59 { 0, 0, NULL, NULL, 0, -1 }
60 };
61 struct ProblemSet ps[] =
62 { 49 {
63 { "testdata/thumbnail_torsten.jpg", 50 EXTRACTOR_METATYPE_THUMBNAIL,
64 thumbnail_torsten_sol }, 51 EXTRACTOR_METAFORMAT_BINARY,
65 { NULL, NULL } 52 "image/png",
66 }; 53 (void *) thumbnail_data,
54 sizeof (thumbnail_data),
55 0
56 },
57 { 0, 0, NULL, NULL, 0, -1 }
58 };
59 struct ProblemSet ps[] = {
60 { "testdata/thumbnail_torsten.jpg",
61 thumbnail_torsten_sol },
62 { NULL, NULL }
63 };
67 return ET_main ("thumbnailgtk", ps); 64 return ET_main ("thumbnailgtk", ps);
68} 65}
69 66
67
70/* end of test_thumbnailgtk.c */ 68/* end of test_thumbnailgtk.c */
diff --git a/src/plugins/test_tiff.c b/src/plugins/test_tiff.c
index 1d0ae5f..6d20610 100644
--- a/src/plugins/test_tiff.c
+++ b/src/plugins/test_tiff.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the TIFF testcase. 30 * Main function for the TIFF testcase.
32 * 31 *
@@ -37,85 +36,84 @@
37int 36int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 struct SolutionData tiff_haute_sol[] = 39 struct SolutionData tiff_haute_sol[] = {
40 {
41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METAFORMAT_UTF8,
43 "text/plain",
44 "image/tiff",
45 strlen ("image/tiff") + 1,
46 0
47 },
48 {
49 EXTRACTOR_METATYPE_ARTIST,
50 EXTRACTOR_METAFORMAT_UTF8,
51 "text/plain",
52 "Anders Espersen",
53 strlen ("Anders Espersen") + 1,
54 0
55 },
56 {
57 EXTRACTOR_METATYPE_CREATION_DATE,
58 EXTRACTOR_METAFORMAT_UTF8,
59 "text/plain",
60 "2012:05:15 10:51:47",
61 strlen ("2012:05:15 10:51:47") + 1,
62 0
63 },
41 { 64 {
42 { 65 EXTRACTOR_METATYPE_COPYRIGHT,
43 EXTRACTOR_METATYPE_MIMETYPE, 66 EXTRACTOR_METAFORMAT_UTF8,
44 EXTRACTOR_METAFORMAT_UTF8, 67 "text/plain",
45 "text/plain", 68 "© Anders Espersen",
46 "image/tiff", 69 strlen ("© Anders Espersen") + 1,
47 strlen ("image/tiff") + 1, 70 0
48 0 71 },
49 },
50 {
51 EXTRACTOR_METATYPE_ARTIST,
52 EXTRACTOR_METAFORMAT_UTF8,
53 "text/plain",
54 "Anders Espersen",
55 strlen ("Anders Espersen") + 1,
56 0
57 },
58 {
59 EXTRACTOR_METATYPE_CREATION_DATE,
60 EXTRACTOR_METAFORMAT_UTF8,
61 "text/plain",
62 "2012:05:15 10:51:47",
63 strlen ("2012:05:15 10:51:47") + 1,
64 0
65 },
66 {
67 EXTRACTOR_METATYPE_COPYRIGHT,
68 EXTRACTOR_METAFORMAT_UTF8,
69 "text/plain",
70 "© Anders Espersen",
71 strlen ("© Anders Espersen") + 1,
72 0
73 },
74 {
75 EXTRACTOR_METATYPE_CAMERA_MAKE,
76 EXTRACTOR_METAFORMAT_UTF8,
77 "text/plain",
78 "Hasselblad",
79 strlen ("Hasselblad") + 1,
80 0
81 },
82 {
83 EXTRACTOR_METATYPE_CAMERA_MODEL,
84 EXTRACTOR_METAFORMAT_UTF8,
85 "text/plain",
86 "Hasselblad H4D-31",
87 strlen ("Hasselblad H4D-31") + 1,
88 0
89 },
90 {
91 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
92 EXTRACTOR_METAFORMAT_UTF8,
93 "text/plain",
94 "Adobe Photoshop CS5 Macintosh",
95 strlen ("Adobe Photoshop CS5 Macintosh") + 1,
96 0
97 },
98 {
99 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
100 EXTRACTOR_METAFORMAT_UTF8,
101 "text/plain",
102 "4872x6496",
103 strlen ("4872x6496") + 1,
104 0
105 },
106 { 0, 0, NULL, NULL, 0, -1 }
107 };
108 struct ProblemSet ps[] =
109 { 72 {
110 /* note that the original test image was almost 73 EXTRACTOR_METATYPE_CAMERA_MAKE,
111 100 MB large; so for SVN it was cut down to 74 EXTRACTOR_METAFORMAT_UTF8,
112 only contain the first 64 KB, which still parse 75 "text/plain",
113 fine and give use the meta data */ 76 "Hasselblad",
114 { "testdata/tiff_haute.tiff", 77 strlen ("Hasselblad") + 1,
115 tiff_haute_sol }, 78 0
116 { NULL, NULL } 79 },
117 }; 80 {
81 EXTRACTOR_METATYPE_CAMERA_MODEL,
82 EXTRACTOR_METAFORMAT_UTF8,
83 "text/plain",
84 "Hasselblad H4D-31",
85 strlen ("Hasselblad H4D-31") + 1,
86 0
87 },
88 {
89 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
90 EXTRACTOR_METAFORMAT_UTF8,
91 "text/plain",
92 "Adobe Photoshop CS5 Macintosh",
93 strlen ("Adobe Photoshop CS5 Macintosh") + 1,
94 0
95 },
96 {
97 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
98 EXTRACTOR_METAFORMAT_UTF8,
99 "text/plain",
100 "4872x6496",
101 strlen ("4872x6496") + 1,
102 0
103 },
104 { 0, 0, NULL, NULL, 0, -1 }
105 };
106 struct ProblemSet ps[] = {
107 /* note that the original test image was almost
108 100 MB large; so for SVN it was cut down to
109 only contain the first 64 KB, which still parse
110 fine and give use the meta data */
111 { "testdata/tiff_haute.tiff",
112 tiff_haute_sol },
113 { NULL, NULL }
114 };
118 return ET_main ("tiff", ps); 115 return ET_main ("tiff", ps);
119} 116}
120 117
118
121/* end of test_tiff.c */ 119/* end of test_tiff.c */
diff --git a/src/plugins/test_wav.c b/src/plugins/test_wav.c
index dc4f6fe..3325386 100644
--- a/src/plugins/test_wav.c
+++ b/src/plugins/test_wav.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the WAV testcase. 30 * Main function for the WAV testcase.
32 * 31 *
@@ -37,55 +36,53 @@
37int 36int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 struct SolutionData wav_noise_sol[] = 39 struct SolutionData wav_noise_sol[] = {
40 {
41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METAFORMAT_UTF8,
43 "text/plain",
44 "audio/x-wav",
45 strlen ("audio/x-wav") + 1,
46 0
47 },
41 { 48 {
42 { 49 EXTRACTOR_METATYPE_RESOURCE_TYPE,
43 EXTRACTOR_METATYPE_MIMETYPE, 50 EXTRACTOR_METAFORMAT_UTF8,
44 EXTRACTOR_METAFORMAT_UTF8, 51 "text/plain",
45 "text/plain", 52 "1000 ms, 48000 Hz, mono",
46 "audio/x-wav", 53 strlen ("1000 ms, 48000 Hz, mono") + 1,
47 strlen ("audio/x-wav") + 1, 54 0
48 0 55 },
49 }, 56 { 0, 0, NULL, NULL, 0, -1 }
50 { 57 };
51 EXTRACTOR_METATYPE_RESOURCE_TYPE, 58 struct SolutionData wav_alert_sol[] = {
52 EXTRACTOR_METAFORMAT_UTF8,
53 "text/plain",
54 "1000 ms, 48000 Hz, mono",
55 strlen ("1000 ms, 48000 Hz, mono") + 1,
56 0
57 },
58 { 0, 0, NULL, NULL, 0, -1 }
59 };
60 struct SolutionData wav_alert_sol[] =
61 { 59 {
62 { 60 EXTRACTOR_METATYPE_MIMETYPE,
63 EXTRACTOR_METATYPE_MIMETYPE, 61 EXTRACTOR_METAFORMAT_UTF8,
64 EXTRACTOR_METAFORMAT_UTF8, 62 "text/plain",
65 "text/plain", 63 "audio/x-wav",
66 "audio/x-wav", 64 strlen ("audio/x-wav") + 1,
67 strlen ("audio/x-wav") + 1, 65 0
68 0 66 },
69 },
70 {
71 EXTRACTOR_METATYPE_RESOURCE_TYPE,
72 EXTRACTOR_METAFORMAT_UTF8,
73 "text/plain",
74 "525 ms, 22050 Hz, mono",
75 strlen ("525 ms, 22050 Hz, mono") + 1,
76 0
77 },
78 { 0, 0, NULL, NULL, 0, -1 }
79 };
80 struct ProblemSet ps[] =
81 { 67 {
82 { "testdata/wav_noise.wav", 68 EXTRACTOR_METATYPE_RESOURCE_TYPE,
83 wav_noise_sol }, 69 EXTRACTOR_METAFORMAT_UTF8,
84 { "testdata/wav_alert.wav", 70 "text/plain",
85 wav_alert_sol }, 71 "525 ms, 22050 Hz, mono",
86 { NULL, NULL } 72 strlen ("525 ms, 22050 Hz, mono") + 1,
87 }; 73 0
74 },
75 { 0, 0, NULL, NULL, 0, -1 }
76 };
77 struct ProblemSet ps[] = {
78 { "testdata/wav_noise.wav",
79 wav_noise_sol },
80 { "testdata/wav_alert.wav",
81 wav_alert_sol },
82 { NULL, NULL }
83 };
88 return ET_main ("wav", ps); 84 return ET_main ("wav", ps);
89} 85}
90 86
87
91/* end of test_wav.c */ 88/* end of test_wav.c */
diff --git a/src/plugins/test_xm.c b/src/plugins/test_xm.c
index c4a6c27..776bb20 100644
--- a/src/plugins/test_xm.c
+++ b/src/plugins/test_xm.c
@@ -26,7 +26,6 @@
26#include "test_lib.h" 26#include "test_lib.h"
27 27
28 28
29
30/** 29/**
31 * Main function for the XM testcase. 30 * Main function for the XM testcase.
32 * 31 *
@@ -37,49 +36,48 @@
37int 36int
38main (int argc, char *argv[]) 37main (int argc, char *argv[])
39{ 38{
40 struct SolutionData xm_diesel_sol[] = 39 struct SolutionData xm_diesel_sol[] = {
40 {
41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METAFORMAT_UTF8,
43 "text/plain",
44 "audio/x-xm",
45 strlen ("audio/x-xm") + 1,
46 0
47 },
41 { 48 {
42 { 49 EXTRACTOR_METATYPE_FORMAT_VERSION,
43 EXTRACTOR_METATYPE_MIMETYPE, 50 EXTRACTOR_METAFORMAT_UTF8,
44 EXTRACTOR_METAFORMAT_UTF8, 51 "text/plain",
45 "text/plain", 52 "1.4",
46 "audio/x-xm", 53 strlen ("1.4") + 1,
47 strlen ("audio/x-xm") + 1, 54 0
48 0 55 },
49 },
50 {
51 EXTRACTOR_METATYPE_FORMAT_VERSION,
52 EXTRACTOR_METAFORMAT_UTF8,
53 "text/plain",
54 "1.4",
55 strlen ("1.4") + 1,
56 0
57 },
58 {
59 EXTRACTOR_METATYPE_TITLE,
60 EXTRACTOR_METAFORMAT_UTF8,
61 "text/plain",
62 "diesel",
63 strlen ("diesel") + 1,
64 0
65 },
66 {
67 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
68 EXTRACTOR_METAFORMAT_UTF8,
69 "text/plain",
70 "FastTracker v2.00",
71 strlen ("FastTracker v2.00") + 1,
72 0
73 },
74 { 0, 0, NULL, NULL, 0, -1 }
75 };
76 struct ProblemSet ps[] =
77 { 56 {
78 { "testdata/xm_diesel.xm", 57 EXTRACTOR_METATYPE_TITLE,
79 xm_diesel_sol }, 58 EXTRACTOR_METAFORMAT_UTF8,
80 { NULL, NULL } 59 "text/plain",
81 }; 60 "diesel",
61 strlen ("diesel") + 1,
62 0
63 },
64 {
65 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE,
66 EXTRACTOR_METAFORMAT_UTF8,
67 "text/plain",
68 "FastTracker v2.00",
69 strlen ("FastTracker v2.00") + 1,
70 0
71 },
72 { 0, 0, NULL, NULL, 0, -1 }
73 };
74 struct ProblemSet ps[] = {
75 { "testdata/xm_diesel.xm",
76 xm_diesel_sol },
77 { NULL, NULL }
78 };
82 return ET_main ("xm", ps); 79 return ET_main ("xm", ps);
83} 80}
84 81
82
85/* end of test_xm.c */ 83/* end of test_xm.c */
diff --git a/src/plugins/test_zip.c b/src/plugins/test_zip.c
index 92e94c9..1ef52d9 100644
--- a/src/plugins/test_zip.c
+++ b/src/plugins/test_zip.c
@@ -36,73 +36,72 @@
36int 36int
37main (int argc, char *argv[]) 37main (int argc, char *argv[])
38{ 38{
39 struct SolutionData zip_test_sol[] = 39 struct SolutionData zip_test_sol[] = {
40 { 40 {
41 { 41 EXTRACTOR_METATYPE_MIMETYPE,
42 EXTRACTOR_METATYPE_MIMETYPE, 42 EXTRACTOR_METAFORMAT_UTF8,
43 EXTRACTOR_METAFORMAT_UTF8, 43 "text/plain",
44 "text/plain", 44 "application/zip",
45 "application/zip", 45 strlen ("application/zip") + 1,
46 strlen ("application/zip") + 1, 46 0
47 0 47 },
48 },
49 {
50 EXTRACTOR_METATYPE_COMMENT,
51 EXTRACTOR_METAFORMAT_C_STRING,
52 "text/plain",
53 "global zipfile comment",
54 strlen ("global zipfile comment") + 1,
55 0
56 },
57 {
58 EXTRACTOR_METATYPE_FILENAME,
59 EXTRACTOR_METAFORMAT_C_STRING,
60 "text/plain",
61 "ChangeLog",
62 strlen ("ChangeLog") + 1,
63 0
64 },
65 {
66 EXTRACTOR_METATYPE_FILENAME,
67 EXTRACTOR_METAFORMAT_C_STRING,
68 "text/plain",
69 "test.png",
70 strlen ("test.png") + 1,
71 0
72 },
73 {
74 EXTRACTOR_METATYPE_COMMENT,
75 EXTRACTOR_METAFORMAT_C_STRING,
76 "text/plain",
77 "comment for test.png",
78 strlen ("comment for test.png") + 1,
79 0
80 },
81 {
82 EXTRACTOR_METATYPE_FILENAME,
83 EXTRACTOR_METAFORMAT_C_STRING,
84 "text/plain",
85 "test.jpg",
86 strlen ("test.jpg") + 1,
87 0
88 },
89 {
90 EXTRACTOR_METATYPE_COMMENT,
91 EXTRACTOR_METAFORMAT_C_STRING,
92 "text/plain",
93 "comment for test.jpg",
94 strlen ("comment for test.jpg") + 1,
95 0
96 },
97 { 0, 0, NULL, NULL, 0, -1 }
98 };
99 struct ProblemSet ps[] =
100 { 48 {
101 { "testdata/zip_test.zip", 49 EXTRACTOR_METATYPE_COMMENT,
102 zip_test_sol }, 50 EXTRACTOR_METAFORMAT_C_STRING,
103 { NULL, NULL } 51 "text/plain",
104 }; 52 "global zipfile comment",
53 strlen ("global zipfile comment") + 1,
54 0
55 },
56 {
57 EXTRACTOR_METATYPE_FILENAME,
58 EXTRACTOR_METAFORMAT_C_STRING,
59 "text/plain",
60 "ChangeLog",
61 strlen ("ChangeLog") + 1,
62 0
63 },
64 {
65 EXTRACTOR_METATYPE_FILENAME,
66 EXTRACTOR_METAFORMAT_C_STRING,
67 "text/plain",
68 "test.png",
69 strlen ("test.png") + 1,
70 0
71 },
72 {
73 EXTRACTOR_METATYPE_COMMENT,
74 EXTRACTOR_METAFORMAT_C_STRING,
75 "text/plain",
76 "comment for test.png",
77 strlen ("comment for test.png") + 1,
78 0
79 },
80 {
81 EXTRACTOR_METATYPE_FILENAME,
82 EXTRACTOR_METAFORMAT_C_STRING,
83 "text/plain",
84 "test.jpg",
85 strlen ("test.jpg") + 1,
86 0
87 },
88 {
89 EXTRACTOR_METATYPE_COMMENT,
90 EXTRACTOR_METAFORMAT_C_STRING,
91 "text/plain",
92 "comment for test.jpg",
93 strlen ("comment for test.jpg") + 1,
94 0
95 },
96 { 0, 0, NULL, NULL, 0, -1 }
97 };
98 struct ProblemSet ps[] = {
99 { "testdata/zip_test.zip",
100 zip_test_sol },
101 { NULL, NULL }
102 };
105 return ET_main ("zip", ps); 103 return ET_main ("zip", ps);
106} 104}
107 105
106
108/* end of test_zip.c */ 107/* end of test_zip.c */
diff --git a/src/plugins/thumbnailffmpeg_extractor.c b/src/plugins/thumbnailffmpeg_extractor.c
index 72af79f..72f0137 100644
--- a/src/plugins/thumbnailffmpeg_extractor.c
+++ b/src/plugins/thumbnailffmpeg_extractor.c
@@ -97,7 +97,7 @@
97/** 97/**
98 * Maximum size in bytes for the thumbnail. 98 * Maximum size in bytes for the thumbnail.
99 */ 99 */
100#define MAX_THUMB_BYTES (100*1024) 100#define MAX_THUMB_BYTES (100 * 1024)
101 101
102/** 102/**
103 * Number of bytes to feed to libav in one go. 103 * Number of bytes to feed to libav in one go.
@@ -135,8 +135,8 @@ static magic_t magic;
135 */ 135 */
136static int 136static int
137read_cb (void *opaque, 137read_cb (void *opaque,
138 uint8_t *buf, 138 uint8_t *buf,
139 int buf_size) 139 int buf_size)
140{ 140{
141 struct EXTRACTOR_ExtractContext *ec = opaque; 141 struct EXTRACTOR_ExtractContext *ec = opaque;
142 void *data; 142 void *data;
@@ -160,8 +160,8 @@ read_cb (void *opaque,
160 */ 160 */
161static int64_t 161static int64_t
162seek_cb (void *opaque, 162seek_cb (void *opaque,
163 int64_t offset, 163 int64_t offset,
164 int whence) 164 int whence)
165{ 165{
166 struct EXTRACTOR_ExtractContext *ec = opaque; 166 struct EXTRACTOR_ExtractContext *ec = opaque;
167 167
@@ -187,12 +187,12 @@ seek_cb (void *opaque,
187 */ 187 */
188static size_t 188static size_t
189create_thumbnail (AVCodecContext *pCodecCtx, int src_width, int src_height, 189create_thumbnail (AVCodecContext *pCodecCtx, int src_width, int src_height,
190 int src_stride[], 190 int src_stride[],
191 enum AVPixelFormat src_pixfmt, 191 enum AVPixelFormat src_pixfmt,
192 const uint8_t * const src_data[], 192 const uint8_t *const src_data[],
193 int dst_width, int dst_height, 193 int dst_width, int dst_height,
194 uint8_t **output_data, 194 uint8_t **output_data,
195 size_t output_max_size) 195 size_t output_max_size)
196{ 196{
197 AVCodecContext *encoder_codec_ctx; 197 AVCodecContext *encoder_codec_ctx;
198 AVDictionary *opts; 198 AVDictionary *opts;
@@ -205,73 +205,73 @@ create_thumbnail (AVCodecContext *pCodecCtx, int src_width, int src_height,
205 int err; 205 int err;
206 206
207 AVPacket pkt; 207 AVPacket pkt;
208 av_init_packet(&pkt); 208 av_init_packet (&pkt);
209 pkt.data = NULL; 209 pkt.data = NULL;
210 pkt.size = 0; 210 pkt.size = 0;
211 int gotPacket; 211 int gotPacket;
212#if USE_JPEG 212#if USE_JPEG
213 #if LIBAVCODEC_BUILD >= AV_VERSION_INT(54,25,0) 213 #if LIBAVCODEC_BUILD >= AV_VERSION_INT (54,25,0)
214 if (NULL == (encoder_codec = avcodec_find_encoder ( AV_CODEC_ID_MJPEG ))) 214 if (NULL == (encoder_codec = avcodec_find_encoder (AV_CODEC_ID_MJPEG)))
215 #else 215 #else
216 if (NULL == (encoder_codec = avcodec_find_encoder ( CODEC_ID_MJPEG ))) 216 if (NULL == (encoder_codec = avcodec_find_encoder (CODEC_ID_MJPEG)))
217 #endif 217 #endif
218 #else 218 #else
219 if (NULL == (encoder_codec = avcodec_find_encoder_by_name ("png"))) 219 if (NULL == (encoder_codec = avcodec_find_encoder_by_name ("png")))
220 #endif 220 #endif
221 { 221 {
222#if DEBUG 222#if DEBUG
223 fprintf (stderr, 223 fprintf (stderr,
224 "Couldn't find a encoder\n"); 224 "Couldn't find a encoder\n");
225#endif 225#endif
226 return 0; 226 return 0;
227 } 227 }
228 228
229 /* NOTE: the scaler will be used even if the src and dst image dimensions 229 /* NOTE: the scaler will be used even if the src and dst image dimensions
230 * match, because the scaler will also perform colour space conversion */ 230 * match, because the scaler will also perform colour space conversion */
231 if (NULL == 231 if (NULL ==
232 (scaler_ctx = 232 (scaler_ctx =
233 sws_getContext (src_width, src_height, src_pixfmt, 233 sws_getContext (src_width, src_height, src_pixfmt,
234 dst_width, dst_height, 234 dst_width, dst_height,
235 PIX_OUTPUT_FORMAT, 235 PIX_OUTPUT_FORMAT,
236 SWS_BILINEAR, NULL, NULL, NULL))) 236 SWS_BILINEAR, NULL, NULL, NULL)))
237 { 237 {
238#if DEBUG 238#if DEBUG
239 fprintf (stderr, 239 fprintf (stderr,
240 "Failed to get a scaler context\n"); 240 "Failed to get a scaler context\n");
241#endif 241#endif
242 return 0; 242 return 0;
243 } 243 }
244 244
245#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 245#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
246 dst_frame = av_frame_alloc (); 246 dst_frame = av_frame_alloc ();
247#else 247#else
248 dst_frame = avcodec_alloc_frame(); 248 dst_frame = avcodec_alloc_frame ();
249#endif 249#endif
250 if (NULL == dst_frame) 250 if (NULL == dst_frame)
251 { 251 {
252#if DEBUG 252#if DEBUG
253 fprintf (stderr, 253 fprintf (stderr,
254 "Failed to allocate the destination image frame\n"); 254 "Failed to allocate the destination image frame\n");
255#endif 255#endif
256 sws_freeContext (scaler_ctx); 256 sws_freeContext (scaler_ctx);
257 return 0; 257 return 0;
258 } 258 }
259 if (NULL == (dst_buffer = 259 if (NULL == (dst_buffer =
260 av_malloc (avpicture_get_size (PIX_OUTPUT_FORMAT, 260 av_malloc (avpicture_get_size (PIX_OUTPUT_FORMAT,
261 dst_width, dst_height)))) 261 dst_width, dst_height))))
262 { 262 {
263#if DEBUG 263#if DEBUG
264 fprintf (stderr, 264 fprintf (stderr,
265 "Failed to allocate the destination image buffer\n"); 265 "Failed to allocate the destination image buffer\n");
266#endif 266#endif
267#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 267#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
268 av_frame_free (&dst_frame); 268 av_frame_free (&dst_frame);
269#else 269#else
270 avcodec_free_frame (&dst_frame); 270 avcodec_free_frame (&dst_frame);
271#endif 271#endif
272 sws_freeContext (scaler_ctx); 272 sws_freeContext (scaler_ctx);
273 return 0; 273 return 0;
274 } 274 }
275 avpicture_fill ((AVPicture *) dst_frame, dst_buffer, 275 avpicture_fill ((AVPicture *) dst_frame, dst_buffer,
276 PIX_OUTPUT_FORMAT, 276 PIX_OUTPUT_FORMAT,
277 dst_width, dst_height); 277 dst_width, dst_height);
@@ -284,47 +284,47 @@ create_thumbnail (AVCodecContext *pCodecCtx, int src_width, int src_height,
284 284
285 encoder_output_buffer_size = output_max_size; 285 encoder_output_buffer_size = output_max_size;
286 if (NULL == (encoder_output_buffer = av_malloc (encoder_output_buffer_size))) 286 if (NULL == (encoder_output_buffer = av_malloc (encoder_output_buffer_size)))
287 { 287 {
288#if DEBUG 288#if DEBUG
289 fprintf (stderr, 289 fprintf (stderr,
290 "Failed to allocate the encoder output buffer\n"); 290 "Failed to allocate the encoder output buffer\n");
291#endif 291#endif
292 av_free (dst_buffer); 292 av_free (dst_buffer);
293#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 293#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
294 av_frame_free (&dst_frame); 294 av_frame_free (&dst_frame);
295#else 295#else
296 avcodec_free_frame (&dst_frame); 296 avcodec_free_frame (&dst_frame);
297#endif 297#endif
298 sws_freeContext (scaler_ctx); 298 sws_freeContext (scaler_ctx);
299 return 0; 299 return 0;
300 } 300 }
301 301
302 if (NULL == (encoder_codec_ctx = avcodec_alloc_context3 (encoder_codec))) 302 if (NULL == (encoder_codec_ctx = avcodec_alloc_context3 (encoder_codec)))
303 { 303 {
304#if DEBUG 304#if DEBUG
305 fprintf (stderr, 305 fprintf (stderr,
306 "Failed to allocate the encoder codec context\n"); 306 "Failed to allocate the encoder codec context\n");
307#endif 307#endif
308 av_free (encoder_output_buffer); 308 av_free (encoder_output_buffer);
309 av_free (dst_buffer); 309 av_free (dst_buffer);
310#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 310#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
311 av_frame_free (&dst_frame); 311 av_frame_free (&dst_frame);
312#else 312#else
313 avcodec_free_frame (&dst_frame); 313 avcodec_free_frame (&dst_frame);
314#endif 314#endif
315 sws_freeContext (scaler_ctx); 315 sws_freeContext (scaler_ctx);
316 return 0; 316 return 0;
317 } 317 }
318 encoder_codec_ctx->width = dst_width; 318 encoder_codec_ctx->width = dst_width;
319 encoder_codec_ctx->height = dst_height; 319 encoder_codec_ctx->height = dst_height;
320#if USE_JPEG 320#if USE_JPEG
321 encoder_codec_ctx->bit_rate = pCodecCtx->bit_rate; 321 encoder_codec_ctx->bit_rate = pCodecCtx->bit_rate;
322#if LIBAVCODEC_BUILD >= AV_VERSION_INT(54,25,0) 322#if LIBAVCODEC_BUILD >= AV_VERSION_INT (54,25,0)
323 encoder_codec_ctx->codec_id = AV_CODEC_ID_MJPEG; 323 encoder_codec_ctx->codec_id = AV_CODEC_ID_MJPEG;
324#else 324#else
325 encoder_codec_ctx->codec_id = CODEC_ID_MJPEG; 325 encoder_codec_ctx->codec_id = CODEC_ID_MJPEG;
326#endif 326#endif
327#if LIBAVCODEC_BUILD >= AV_VERSION_INT(53,35,0) 327#if LIBAVCODEC_BUILD >= AV_VERSION_INT (53,35,0)
328 encoder_codec_ctx->codec_type = AVMEDIA_TYPE_VIDEO; 328 encoder_codec_ctx->codec_type = AVMEDIA_TYPE_VIDEO;
329#else 329#else
330 encoder_codec_ctx->codec_type = CODEC_TYPE_VIDEO; 330 encoder_codec_ctx->codec_type = CODEC_TYPE_VIDEO;
@@ -338,51 +338,52 @@ create_thumbnail (AVCodecContext *pCodecCtx, int src_width, int src_height,
338 338
339 opts = NULL; 339 opts = NULL;
340 if (avcodec_open2 (encoder_codec_ctx, encoder_codec, &opts) < 0) 340 if (avcodec_open2 (encoder_codec_ctx, encoder_codec, &opts) < 0)
341 { 341 {
342#if DEBUG 342#if DEBUG
343 fprintf (stderr, 343 fprintf (stderr,
344 "Failed to open the encoder\n"); 344 "Failed to open the encoder\n");
345#endif 345#endif
346 avcodec_free_context (&encoder_codec_ctx); 346 avcodec_free_context (&encoder_codec_ctx);
347 av_free (encoder_output_buffer); 347 av_free (encoder_output_buffer);
348 av_free (dst_buffer); 348 av_free (dst_buffer);
349#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 349#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
350 av_frame_free (&dst_frame); 350 av_frame_free (&dst_frame);
351#else 351#else
352 avcodec_free_frame (&dst_frame); 352 avcodec_free_frame (&dst_frame);
353#endif 353#endif
354 sws_freeContext (scaler_ctx); 354 sws_freeContext (scaler_ctx);
355 return 0; 355 return 0;
356 } 356 }
357
358 357
359 358
360#ifdef USE_JPEG 359#ifdef USE_JPEG
361#if FF_API_MPV_OPT 360#if FF_API_MPV_OPT
362 encoder_codec_ctx->mb_lmin = encoder_codec_ctx->lmin = encoder_codec_ctx->qmin * FF_QP2LAMBDA; 361 encoder_codec_ctx->mb_lmin = encoder_codec_ctx->lmin =
363 encoder_codec_ctx->mb_lmax = encoder_codec_ctx->lmax = encoder_codec_ctx->qmax * FF_QP2LAMBDA; 362 encoder_codec_ctx->qmin * FF_QP2LAMBDA;
363 encoder_codec_ctx->mb_lmax = encoder_codec_ctx->lmax =
364 encoder_codec_ctx->qmax * FF_QP2LAMBDA;
364#else 365#else
365 encoder_codec_ctx->mb_lmin = encoder_codec_ctx->qmin * FF_QP2LAMBDA; 366 encoder_codec_ctx->mb_lmin = encoder_codec_ctx->qmin * FF_QP2LAMBDA;
366 encoder_codec_ctx->mb_lmax = encoder_codec_ctx->qmax * FF_QP2LAMBDA; 367 encoder_codec_ctx->mb_lmax = encoder_codec_ctx->qmax * FF_QP2LAMBDA;
367#endif 368#endif
368 encoder_codec_ctx->flags = AV_CODEC_FLAG_QSCALE; 369 encoder_codec_ctx->flags = AV_CODEC_FLAG_QSCALE;
369 encoder_codec_ctx->global_quality = encoder_codec_ctx->qmin * FF_QP2LAMBDA; 370 encoder_codec_ctx->global_quality = encoder_codec_ctx->qmin * FF_QP2LAMBDA;
370 371
371 dst_frame->pts = 1; 372 dst_frame->pts = 1;
372 dst_frame->quality = encoder_codec_ctx->global_quality; 373 dst_frame->quality = encoder_codec_ctx->global_quality;
373#endif 374#endif
374 375
375#if LIBAVCODEC_BUILD >= AV_VERSION_INT(54,25,0) 376#if LIBAVCODEC_BUILD >= AV_VERSION_INT (54,25,0)
376 err = avcodec_encode_video2 (encoder_codec_ctx, 377 err = avcodec_encode_video2 (encoder_codec_ctx,
377 &pkt, 378 &pkt,
378 dst_frame, &gotPacket); 379 dst_frame, &gotPacket);
379 380
380 if(err < 0) 381 if (err < 0)
381 goto cleanup; 382 goto cleanup;
382 err = pkt.size; 383 err = pkt.size;
383 memcpy(encoder_output_buffer,pkt.data, pkt.size); 384 memcpy (encoder_output_buffer,pkt.data, pkt.size);
384 385
385 av_free_packet(&pkt); 386 av_free_packet (&pkt);
386 387
387 388
388#else 389#else
@@ -396,7 +397,7 @@ cleanup:
396 avcodec_close (encoder_codec_ctx); 397 avcodec_close (encoder_codec_ctx);
397 avcodec_free_context (&encoder_codec_ctx); 398 avcodec_free_context (&encoder_codec_ctx);
398 av_free (dst_buffer); 399 av_free (dst_buffer);
399#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 400#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
400 av_frame_free (&dst_frame); 401 av_frame_free (&dst_frame);
401#else 402#else
402 avcodec_free_frame (&dst_frame); 403 avcodec_free_frame (&dst_frame);
@@ -408,7 +409,6 @@ cleanup:
408} 409}
409 410
410 411
411
412/** 412/**
413 * calculate the thumbnail dimensions, taking pixel aspect into account 413 * calculate the thumbnail dimensions, taking pixel aspect into account
414 * 414 *
@@ -421,30 +421,30 @@ cleanup:
421 */ 421 */
422static void 422static void
423calculate_thumbnail_dimensions (int src_width, 423calculate_thumbnail_dimensions (int src_width,
424 int src_height, 424 int src_height,
425 int src_sar_num, 425 int src_sar_num,
426 int src_sar_den, 426 int src_sar_den,
427 int *dst_width, 427 int *dst_width,
428 int *dst_height) 428 int *dst_height)
429{ 429{
430 if ( (src_sar_num <= 0) || (src_sar_den <= 0) ) 430 if ( (src_sar_num <= 0) || (src_sar_den <= 0) )
431 { 431 {
432 src_sar_num = 1; 432 src_sar_num = 1;
433 src_sar_den = 1; 433 src_sar_den = 1;
434 } 434 }
435 if ((src_width * src_sar_num) / src_sar_den > src_height) 435 if ((src_width * src_sar_num) / src_sar_den > src_height)
436 { 436 {
437 *dst_width = MAX_THUMB_DIMENSION; 437 *dst_width = MAX_THUMB_DIMENSION;
438 *dst_height = (*dst_width * src_height) / 438 *dst_height = (*dst_width * src_height)
439 ((src_width * src_sar_num) / src_sar_den); 439 / ((src_width * src_sar_num) / src_sar_den);
440 } 440 }
441 else 441 else
442 { 442 {
443 *dst_height = MAX_THUMB_DIMENSION; 443 *dst_height = MAX_THUMB_DIMENSION;
444 *dst_width = (*dst_height * 444 *dst_width = (*dst_height
445 ((src_width * src_sar_num) / src_sar_den)) / 445 * ((src_width * src_sar_num) / src_sar_den))
446 src_height; 446 / src_height;
447 } 447 }
448 if (*dst_width < 8) 448 if (*dst_width < 8)
449 *dst_width = 8; 449 *dst_width = 8;
450 if (*dst_height < 1) 450 if (*dst_height < 1)
@@ -456,10 +456,11 @@ calculate_thumbnail_dimensions (int src_width,
456#endif 456#endif
457} 457}
458 458
459#if LIBAVCODEC_BUILD >= AV_VERSION_INT(54,25,0) 459
460 #define ENUM_CODEC_ID enum AVCodecID 460#if LIBAVCODEC_BUILD >= AV_VERSION_INT (54,25,0)
461 #define ENUM_CODEC_ID enum AVCodecID
461#else 462#else
462 #define ENUM_CODEC_ID enum CodecID 463 #define ENUM_CODEC_ID enum CodecID
463#endif 464#endif
464 465
465/** 466/**
@@ -487,77 +488,77 @@ extract_image (ENUM_CODEC_ID image_codec_id,
487 unsigned char padded_data[PADDED_BUFFER_SIZE]; 488 unsigned char padded_data[PADDED_BUFFER_SIZE];
488 489
489 if (NULL == (codec = avcodec_find_decoder (image_codec_id))) 490 if (NULL == (codec = avcodec_find_decoder (image_codec_id)))
490 { 491 {
491#if DEBUG 492#if DEBUG
492 fprintf (stderr, 493 fprintf (stderr,
493 "No suitable codec found\n"); 494 "No suitable codec found\n");
494#endif 495#endif
495 return; 496 return;
496 } 497 }
497 if (NULL == (codec_ctx = avcodec_alloc_context3 (codec))) 498 if (NULL == (codec_ctx = avcodec_alloc_context3 (codec)))
498 { 499 {
499#if DEBUG 500#if DEBUG
500 fprintf (stderr, 501 fprintf (stderr,
501 "Failed to allocate codec context\n"); 502 "Failed to allocate codec context\n");
502#endif 503#endif
503 return; 504 return;
504 } 505 }
505 opts = NULL; 506 opts = NULL;
506 if (0 != avcodec_open2 (codec_ctx, codec, &opts)) 507 if (0 != avcodec_open2 (codec_ctx, codec, &opts))
507 { 508 {
508#if DEBUG 509#if DEBUG
509 fprintf (stderr, 510 fprintf (stderr,
510 "Failed to open image codec\n"); 511 "Failed to open image codec\n");
511#endif 512#endif
512 avcodec_free_context (&codec_ctx); 513 avcodec_free_context (&codec_ctx);
513 return; 514 return;
514 } 515 }
515 av_dict_free (&opts); 516 av_dict_free (&opts);
516#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 517#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
517 frame = av_frame_alloc (); 518 frame = av_frame_alloc ();
518#else 519#else
519 frame = avcodec_alloc_frame(); 520 frame = avcodec_alloc_frame ();
520#endif 521#endif
521 if (NULL == frame) 522 if (NULL == frame)
522 { 523 {
523#if DEBUG 524#if DEBUG
524 fprintf (stderr, 525 fprintf (stderr,
525 "Failed to allocate frame\n"); 526 "Failed to allocate frame\n");
526#endif 527#endif
527 avcodec_close (codec_ctx); 528 avcodec_close (codec_ctx);
528 avcodec_free_context (&codec_ctx); 529 avcodec_free_context (&codec_ctx);
529 return; 530 return;
530 } 531 }
531 532
532 frame_finished = 0; 533 frame_finished = 0;
533 while (! frame_finished) 534 while (! frame_finished)
534 { 535 {
535 if (0 >= (iret = ec->read (ec->cls, 536 if (0 >= (iret = ec->read (ec->cls,
536 &data, 537 &data,
537 BUFFER_SIZE))) 538 BUFFER_SIZE)))
538 break; 539 break;
539 memcpy (padded_data, data, iret); 540 memcpy (padded_data, data, iret);
540 memset (&padded_data[iret], 0, PADDED_BUFFER_SIZE - iret); 541 memset (&padded_data[iret], 0, PADDED_BUFFER_SIZE - iret);
541 av_init_packet (&avpkt); 542 av_init_packet (&avpkt);
542 avpkt.data = padded_data; 543 avpkt.data = padded_data;
543 avpkt.size = iret; 544 avpkt.size = iret;
544 avcodec_decode_video2 (codec_ctx, frame, &frame_finished, &avpkt); 545 avcodec_decode_video2 (codec_ctx, frame, &frame_finished, &avpkt);
545 } 546 }
546 if (! frame_finished) 547 if (! frame_finished)
547 { 548 {
548#if DEBUG 549#if DEBUG
549 fprintf (stderr, 550 fprintf (stderr,
550 "Failed to decode a complete frame\n"); 551 "Failed to decode a complete frame\n");
551#endif 552#endif
552#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 553#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
553 av_frame_free (&frame); 554 av_frame_free (&frame);
554#else 555#else
555 avcodec_free_frame (&frame); 556 avcodec_free_frame (&frame);
556#endif 557#endif
557 avcodec_close (codec_ctx); 558 avcodec_close (codec_ctx);
558 avcodec_free_context (&codec_ctx); 559 avcodec_free_context (&codec_ctx);
559 return; 560 return;
560 } 561 }
561 calculate_thumbnail_dimensions (codec_ctx->width, codec_ctx->height, 562 calculate_thumbnail_dimensions (codec_ctx->width, codec_ctx->height,
562 codec_ctx->sample_aspect_ratio.num, 563 codec_ctx->sample_aspect_ratio.num,
563 codec_ctx->sample_aspect_ratio.den, 564 codec_ctx->sample_aspect_ratio.den,
@@ -565,40 +566,41 @@ extract_image (ENUM_CODEC_ID image_codec_id,
565 566
566 err = create_thumbnail (codec_ctx, codec_ctx->width, codec_ctx->height, 567 err = create_thumbnail (codec_ctx, codec_ctx->width, codec_ctx->height,
567 frame->linesize, codec_ctx->pix_fmt, 568 frame->linesize, codec_ctx->pix_fmt,
568 (const uint8_t * const*) frame->data, 569 (const uint8_t *const*) frame->data,
569 thumb_width, thumb_height, 570 thumb_width, thumb_height,
570 &encoded_thumbnail, MAX_THUMB_BYTES); 571 &encoded_thumbnail, MAX_THUMB_BYTES);
571 if (err > 0) 572 if (err > 0)
573 {
574 ec->proc (ec->cls,
575 "thumbnailffmpeg",
576 EXTRACTOR_METATYPE_THUMBNAIL,
577 EXTRACTOR_METAFORMAT_BINARY,
578 "image/png",
579 (const char*) encoded_thumbnail,
580 err);
581
582 #if OUTPUT_FILE
583 FILE *f;
584 #ifdef USE_JPEG
585 f = fopen ("thumb.jpg", "wb");
586 #else
587 f = fopen ("thumb.png", "wb");
588 #endif
589 if (! f)
572 { 590 {
573 ec->proc (ec->cls, 591 fprintf (stderr, "Could not open %s\n", "file");
574 "thumbnailffmpeg", 592 exit (1);
575 EXTRACTOR_METATYPE_THUMBNAIL, 593 }
576 EXTRACTOR_METAFORMAT_BINARY, 594
577 "image/png", 595 fwrite (encoded_thumbnail, 1, err, f);
578 (const char*) encoded_thumbnail, 596 fclose (f);
579 err);
580
581 #if OUTPUT_FILE
582 FILE *f;
583 #ifdef USE_JPEG
584 f = fopen("thumb.jpg", "wb");
585 #else
586 f = fopen("thumb.png", "wb");
587 #endif
588 if (!f) {
589 fprintf(stderr, "Could not open %s\n", "file");
590 exit(1);
591 }
592
593 fwrite(encoded_thumbnail, 1, err, f);
594 fclose(f);
595 597
596 #endif 598 #endif
597 599
598 600
599 av_free (encoded_thumbnail); 601 av_free (encoded_thumbnail);
600 } 602 }
601#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 603#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
602 av_frame_free (&frame); 604 av_frame_free (&frame);
603#else 605#else
604 avcodec_free_frame (&frame); 606 avcodec_free_frame (&frame);
@@ -637,107 +639,107 @@ extract_video (struct EXTRACTOR_ExtractContext *ec)
637 return; 639 return;
638 if (NULL == (io_ctx = avio_alloc_context (iob, 640 if (NULL == (io_ctx = avio_alloc_context (iob,
639 16 * 1024, 641 16 * 1024,
640 0, ec, 642 0, ec,
641 &read_cb, 643 &read_cb,
642 NULL /* no writing */, 644 NULL /* no writing */,
643 &seek_cb))) 645 &seek_cb)))
644 { 646 {
645 av_free (iob); 647 av_free (iob);
646 return; 648 return;
647 } 649 }
648 if (NULL == (format_ctx = avformat_alloc_context ())) 650 if (NULL == (format_ctx = avformat_alloc_context ()))
649 { 651 {
650 av_free (io_ctx); 652 av_free (io_ctx);
651 return; 653 return;
652 } 654 }
653 format_ctx->pb = io_ctx; 655 format_ctx->pb = io_ctx;
654 options = NULL; 656 options = NULL;
655 if (0 != avformat_open_input (&format_ctx, "<no file>", NULL, &options)) 657 if (0 != avformat_open_input (&format_ctx, "<no file>", NULL, &options))
656 { 658 {
657 av_free (io_ctx); 659 av_free (io_ctx);
658 return; 660 return;
659 } 661 }
660 av_dict_free (&options); 662 av_dict_free (&options);
661 if (0 > avformat_find_stream_info (format_ctx, NULL)) 663 if (0 > avformat_find_stream_info (format_ctx, NULL))
662 { 664 {
663#if DEBUG 665#if DEBUG
664 fprintf (stderr, 666 fprintf (stderr,
665 "Failed to read stream info\n"); 667 "Failed to read stream info\n");
666#endif 668#endif
667 avformat_close_input (&format_ctx); 669 avformat_close_input (&format_ctx);
668 av_free (io_ctx); 670 av_free (io_ctx);
669 return; 671 return;
670 } 672 }
671 codec = NULL; 673 codec = NULL;
672 codec_ctx = NULL; 674 codec_ctx = NULL;
673 video_stream_index = -1; 675 video_stream_index = -1;
674 for (i=0; i<format_ctx->nb_streams; i++) 676 for (i = 0; i<format_ctx->nb_streams; i++)
677 {
678 codec_ctx = format_ctx->streams[i]->codec;
679 if (AVMEDIA_TYPE_VIDEO != codec_ctx->codec_type)
680 continue;
681 if (NULL == (codec = avcodec_find_decoder (codec_ctx->codec_id)))
682 continue;
683 options = NULL;
684 if (0 != (err = avcodec_open2 (codec_ctx, codec, &options)))
675 { 685 {
676 codec_ctx = format_ctx->streams[i]->codec; 686 codec = NULL;
677 if (AVMEDIA_TYPE_VIDEO != codec_ctx->codec_type) 687 continue;
678 continue;
679 if (NULL == (codec = avcodec_find_decoder (codec_ctx->codec_id)))
680 continue;
681 options = NULL;
682 if (0 != (err = avcodec_open2 (codec_ctx, codec, &options)))
683 {
684 codec = NULL;
685 continue;
686 }
687 av_dict_free (&options);
688 video_stream_index = i;
689 break;
690 } 688 }
689 av_dict_free (&options);
690 video_stream_index = i;
691 break;
692 }
691 if ( (-1 == video_stream_index) || 693 if ( (-1 == video_stream_index) ||
692 (0 == codec_ctx->width) || 694 (0 == codec_ctx->width) ||
693 (0 == codec_ctx->height) ) 695 (0 == codec_ctx->height) )
694 { 696 {
695#if DEBUG 697#if DEBUG
696 fprintf (stderr, 698 fprintf (stderr,
697 "No video streams or no suitable codec found\n"); 699 "No video streams or no suitable codec found\n");
698#endif 700#endif
699 if (NULL != codec) 701 if (NULL != codec)
700 avcodec_close (codec_ctx); 702 avcodec_close (codec_ctx);
701 avformat_close_input (&format_ctx); 703 avformat_close_input (&format_ctx);
702 av_free (io_ctx); 704 av_free (io_ctx);
703 return; 705 return;
704 } 706 }
705 707
706#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 708#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
707 frame = av_frame_alloc (); 709 frame = av_frame_alloc ();
708#else 710#else
709 frame = avcodec_alloc_frame(); 711 frame = avcodec_alloc_frame ();
710#endif 712#endif
711 if (NULL == frame) 713 if (NULL == frame)
712 { 714 {
713#if DEBUG 715#if DEBUG
714 fprintf (stderr, 716 fprintf (stderr,
715 "Failed to allocate frame\n"); 717 "Failed to allocate frame\n");
716#endif 718#endif
717 avcodec_close (codec_ctx); 719 avcodec_close (codec_ctx);
718 avformat_close_input (&format_ctx); 720 avformat_close_input (&format_ctx);
719 av_free (io_ctx); 721 av_free (io_ctx);
720 return; 722 return;
721 } 723 }
722 724
723 if (format_ctx->duration == AV_NOPTS_VALUE) 725 if (format_ctx->duration == AV_NOPTS_VALUE)
724 { 726 {
725 duration = -1; 727 duration = -1;
726#if DEBUG 728#if DEBUG
727 fprintf (stderr, 729 fprintf (stderr,
728 "Duration unknown\n"); 730 "Duration unknown\n");
729#endif 731#endif
730 } 732 }
731 else 733 else
732 { 734 {
733 duration = format_ctx->duration; 735 duration = format_ctx->duration;
734 } 736 }
735 737
736 /* if duration is known, seek to first tried, 738 /* if duration is known, seek to first tried,
737 * else use 10 sec into stream */ 739 * else use 10 sec into stream */
738 740
739 if(-1 != duration) 741 if (-1 != duration)
740 err = av_seek_frame (format_ctx, -1, (duration/3), 0); 742 err = av_seek_frame (format_ctx, -1, (duration / 3), 0);
741 else 743 else
742 err = av_seek_frame (format_ctx, -1, 10 * AV_TIME_BASE, 0); 744 err = av_seek_frame (format_ctx, -1, 10 * AV_TIME_BASE, 0);
743 745
@@ -746,41 +748,41 @@ extract_video (struct EXTRACTOR_ExtractContext *ec)
746 frame_finished = 0; 748 frame_finished = 0;
747 749
748 while (1) 750 while (1)
751 {
752 err = av_read_frame (format_ctx, &packet);
753 if (err < 0)
754 break;
755 if (packet.stream_index == video_stream_index)
749 { 756 {
750 err = av_read_frame (format_ctx, &packet); 757 avcodec_decode_video2 (codec_ctx,
751 if (err < 0) 758 frame,
759 &frame_finished,
760 &packet);
761 if (frame_finished && frame->key_frame)
762 {
763 av_free_packet (&packet);
752 break; 764 break;
753 if (packet.stream_index == video_stream_index) 765 }
754 {
755 avcodec_decode_video2 (codec_ctx,
756 frame,
757 &frame_finished,
758 &packet);
759 if (frame_finished && frame->key_frame)
760 {
761 av_free_packet (&packet);
762 break;
763 }
764 }
765 av_free_packet (&packet);
766 } 766 }
767 av_free_packet (&packet);
768 }
767 769
768 if (! frame_finished) 770 if (! frame_finished)
769 { 771 {
770#if DEBUG 772#if DEBUG
771 fprintf (stderr, 773 fprintf (stderr,
772 "Failed to decode a complete frame\n"); 774 "Failed to decode a complete frame\n");
773#endif 775#endif
774#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 776#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
775 av_frame_free (&frame); 777 av_frame_free (&frame);
776#else 778#else
777 avcodec_free_frame (&frame); 779 avcodec_free_frame (&frame);
778#endif 780#endif
779 avcodec_close (codec_ctx); 781 avcodec_close (codec_ctx);
780 avformat_close_input (&format_ctx); 782 avformat_close_input (&format_ctx);
781 av_free (io_ctx); 783 av_free (io_ctx);
782 return; 784 return;
783 } 785 }
784 calculate_thumbnail_dimensions (codec_ctx->width, codec_ctx->height, 786 calculate_thumbnail_dimensions (codec_ctx->width, codec_ctx->height,
785 codec_ctx->sample_aspect_ratio.num, 787 codec_ctx->sample_aspect_ratio.num,
786 codec_ctx->sample_aspect_ratio.den, 788 codec_ctx->sample_aspect_ratio.den,
@@ -788,37 +790,37 @@ extract_video (struct EXTRACTOR_ExtractContext *ec)
788 790
789 err = create_thumbnail (codec_ctx, codec_ctx->width, codec_ctx->height, 791 err = create_thumbnail (codec_ctx, codec_ctx->width, codec_ctx->height,
790 frame->linesize, codec_ctx->pix_fmt, 792 frame->linesize, codec_ctx->pix_fmt,
791 (const uint8_t* const *) frame->data, 793 (const uint8_t*const *) frame->data,
792 thumb_width, thumb_height, 794 thumb_width, thumb_height,
793 &encoded_thumbnail, MAX_THUMB_BYTES); 795 &encoded_thumbnail, MAX_THUMB_BYTES);
794 if (err > 0) 796 if (err > 0)
795 { 797 {
796 ec->proc (ec->cls, 798 ec->proc (ec->cls,
797 "thumbnailffmpeg", 799 "thumbnailffmpeg",
798 EXTRACTOR_METATYPE_THUMBNAIL, 800 EXTRACTOR_METATYPE_THUMBNAIL,
799 EXTRACTOR_METAFORMAT_BINARY, 801 EXTRACTOR_METAFORMAT_BINARY,
800 "image/png", 802 "image/png",
801 (const char*) encoded_thumbnail, 803 (const char*) encoded_thumbnail,
802 err); 804 err);
803#if OUTPUT_FILE 805#if OUTPUT_FILE
804 FILE *f; 806 FILE *f;
805#ifdef USE_JPEG 807#ifdef USE_JPEG
806 f = fopen("thumb.jpg", "wb"); 808 f = fopen ("thumb.jpg", "wb");
807#else 809#else
808 f = fopen("thumb.png", "wb"); 810 f = fopen ("thumb.png", "wb");
809#endif 811#endif
810 if (!f) 812 if (! f)
811 { 813 {
812 fprintf(stderr, "Could not open %s\n", "file"); 814 fprintf (stderr, "Could not open %s\n", "file");
813 exit(1); 815 exit (1);
814 } 816 }
815 817
816 fwrite(encoded_thumbnail, 1, err, f); 818 fwrite (encoded_thumbnail, 1, err, f);
817 fclose(f); 819 fclose (f);
818#endif 820#endif
819 av_free (encoded_thumbnail); 821 av_free (encoded_thumbnail);
820 } 822 }
821#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) 823#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55,28,1)
822 av_frame_free (&frame); 824 av_frame_free (&frame);
823#else 825#else
824 avcodec_free_frame (&frame); 826 avcodec_free_frame (&frame);
@@ -849,28 +851,27 @@ struct MIMEToDecoderMapping
849/** 851/**
850 * map MIME image types to an ffmpeg decoder 852 * map MIME image types to an ffmpeg decoder
851 */ 853 */
852static const struct MIMEToDecoderMapping m2d_map[] = 854static const struct MIMEToDecoderMapping m2d_map[] = {
853 { 855
854 856#if LIBAVCODEC_BUILD >= AV_VERSION_INT (54,25,0)
855#if LIBAVCODEC_BUILD >= AV_VERSION_INT(54,25,0) 857 { "image/x-bmp", AV_CODEC_ID_BMP },
856 { "image/x-bmp", AV_CODEC_ID_BMP }, 858 { "image/gif", AV_CODEC_ID_GIF },
857 { "image/gif", AV_CODEC_ID_GIF }, 859 { "image/jpeg", AV_CODEC_ID_MJPEG },
858 { "image/jpeg", AV_CODEC_ID_MJPEG }, 860 { "image/png", AV_CODEC_ID_PNG },
859 { "image/png", AV_CODEC_ID_PNG }, 861 { "image/x-png", AV_CODEC_ID_PNG },
860 { "image/x-png", AV_CODEC_ID_PNG }, 862 { "image/x-portable-pixmap", AV_CODEC_ID_PPM },
861 { "image/x-portable-pixmap", AV_CODEC_ID_PPM }, 863 { NULL, AV_CODEC_ID_NONE }
862 { NULL, AV_CODEC_ID_NONE }
863#else 864#else
864 { "image/x-bmp", CODEC_ID_BMP }, 865 { "image/x-bmp", CODEC_ID_BMP },
865 { "image/gif", CODEC_ID_GIF }, 866 { "image/gif", CODEC_ID_GIF },
866 { "image/jpeg", CODEC_ID_MJPEG }, 867 { "image/jpeg", CODEC_ID_MJPEG },
867 { "image/png", CODEC_ID_PNG }, 868 { "image/png", CODEC_ID_PNG },
868 { "image/x-png", CODEC_ID_PNG }, 869 { "image/x-png", CODEC_ID_PNG },
869 { "image/x-portable-pixmap", CODEC_ID_PPM }, 870 { "image/x-portable-pixmap", CODEC_ID_PPM },
870 { NULL, CODEC_ID_NONE } 871 { NULL, CODEC_ID_NONE }
871#endif 872#endif
872 873
873 }; 874};
874 875
875 876
876/** 877/**
@@ -887,8 +888,8 @@ EXTRACTOR_thumbnailffmpeg_extract_method (struct EXTRACTOR_ExtractContext *ec)
887 const char *mime; 888 const char *mime;
888 889
889 if (-1 == (iret = ec->read (ec->cls, 890 if (-1 == (iret = ec->read (ec->cls,
890 &data, 891 &data,
891 16 * 1024))) 892 16 * 1024)))
892 return; 893 return;
893 if (NULL == (mime = magic_buffer (magic, data, iret))) 894 if (NULL == (mime = magic_buffer (magic, data, iret)))
894 return; 895 return;
@@ -896,10 +897,10 @@ EXTRACTOR_thumbnailffmpeg_extract_method (struct EXTRACTOR_ExtractContext *ec)
896 return; 897 return;
897 for (i = 0; NULL != m2d_map[i].mime_type; i++) 898 for (i = 0; NULL != m2d_map[i].mime_type; i++)
898 if (0 == strcmp (m2d_map[i].mime_type, mime)) 899 if (0 == strcmp (m2d_map[i].mime_type, mime))
899 { 900 {
900 extract_image (m2d_map[i].codec_id, ec); 901 extract_image (m2d_map[i].codec_id, ec);
901 return; 902 return;
902 } 903 }
903 extract_video (ec); 904 extract_video (ec);
904} 905}
905 906
@@ -926,13 +927,13 @@ EXTRACTOR_thumbnail_extract_method (struct EXTRACTOR_ExtractContext *ec)
926 * @param ap arguments for format 927 * @param ap arguments for format
927 */ 928 */
928static void 929static void
929thumbnailffmpeg_av_log_callback (void* ptr, 930thumbnailffmpeg_av_log_callback (void*ptr,
930 int level, 931 int level,
931 const char *format, 932 const char *format,
932 va_list ap) 933 va_list ap)
933{ 934{
934#if DEBUG 935#if DEBUG
935 vfprintf(stderr, format, ap); 936 vfprintf (stderr, format, ap);
936#endif 937#endif
937} 938}
938 939
@@ -947,9 +948,9 @@ thumbnailffmpeg_lib_init (void)
947 av_register_all (); 948 av_register_all ();
948 magic = magic_open (MAGIC_MIME_TYPE); 949 magic = magic_open (MAGIC_MIME_TYPE);
949 if (0 != magic_load (magic, NULL)) 950 if (0 != magic_load (magic, NULL))
950 { 951 {
951 /* FIXME: how to deal with errors? */ 952 /* FIXME: how to deal with errors? */
952 } 953 }
953} 954}
954 955
955 956
@@ -960,10 +961,10 @@ void __attribute__ ((destructor))
960thumbnailffmpeg_ltdl_fini () 961thumbnailffmpeg_ltdl_fini ()
961{ 962{
962 if (NULL != magic) 963 if (NULL != magic)
963 { 964 {
964 magic_close (magic); 965 magic_close (magic);
965 magic = NULL; 966 magic = NULL;
966 } 967 }
967} 968}
968 969
969 970
diff --git a/src/plugins/thumbnailgtk_extractor.c b/src/plugins/thumbnailgtk_extractor.c
index 8df7079..8775de3 100644
--- a/src/plugins/thumbnailgtk_extractor.c
+++ b/src/plugins/thumbnailgtk_extractor.c
@@ -75,14 +75,14 @@ EXTRACTOR_thumbnailgtk_extract_method (struct EXTRACTOR_ExtractContext *ec)
75 const char *mime; 75 const char *mime;
76 76
77 if (-1 == (iret = ec->read (ec->cls, 77 if (-1 == (iret = ec->read (ec->cls,
78 &data, 78 &data,
79 16 * 1024))) 79 16 * 1024)))
80 return; 80 return;
81 if (NULL == (mime = magic_buffer (magic, data, iret))) 81 if (NULL == (mime = magic_buffer (magic, data, iret)))
82 return; 82 return;
83 if (0 != strncmp (mime, 83 if (0 != strncmp (mime,
84 "image/", 84 "image/",
85 strlen ("image/"))) 85 strlen ("image/")))
86 return; /* not an image */ 86 return; /* not an image */
87 87
88 /* read entire image into memory */ 88 /* read entire image into memory */
@@ -98,95 +98,95 @@ EXTRACTOR_thumbnailgtk_extract_method (struct EXTRACTOR_ExtractContext *ec)
98 memcpy (buf, data, iret); 98 memcpy (buf, data, iret);
99 off = iret; 99 off = iret;
100 while (off < size) 100 while (off < size)
101 {
102 iret = ec->read (ec->cls, &data, size - off);
103 if (iret <= 0)
101 { 104 {
102 iret = ec->read (ec->cls, &data, size - off); 105 /* io error */
103 if (iret <= 0) 106 free (buf);
104 { 107 return;
105 /* io error */
106 free (buf);
107 return;
108 }
109 memcpy (buf + off, data, iret);
110 off += iret;
111 } 108 }
109 memcpy (buf + off, data, iret);
110 off += iret;
111 }
112 112
113 loader = gdk_pixbuf_loader_new (); 113 loader = gdk_pixbuf_loader_new ();
114 gdk_pixbuf_loader_write (loader, 114 gdk_pixbuf_loader_write (loader,
115 buf, 115 buf,
116 size, NULL); 116 size, NULL);
117 free (buf); 117 free (buf);
118 in = gdk_pixbuf_loader_get_pixbuf (loader); 118 in = gdk_pixbuf_loader_get_pixbuf (loader);
119 gdk_pixbuf_loader_close (loader, NULL); 119 gdk_pixbuf_loader_close (loader, NULL);
120 if (NULL == in) 120 if (NULL == in)
121 { 121 {
122 g_object_unref (loader); 122 g_object_unref (loader);
123 return; 123 return;
124 } 124 }
125 g_object_ref (in); 125 g_object_ref (in);
126 g_object_unref (loader); 126 g_object_unref (loader);
127 height = gdk_pixbuf_get_height (in); 127 height = gdk_pixbuf_get_height (in);
128 width = gdk_pixbuf_get_width (in); 128 width = gdk_pixbuf_get_width (in);
129 snprintf (format, 129 snprintf (format,
130 sizeof (format), 130 sizeof (format),
131 "%ux%u", 131 "%ux%u",
132 (unsigned int) width, 132 (unsigned int) width,
133 (unsigned int) height); 133 (unsigned int) height);
134 if (0 != ec->proc (ec->cls, 134 if (0 != ec->proc (ec->cls,
135 "thumbnailgtk", 135 "thumbnailgtk",
136 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, 136 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
137 EXTRACTOR_METAFORMAT_UTF8, 137 EXTRACTOR_METAFORMAT_UTF8,
138 "text/plain", 138 "text/plain",
139 format, 139 format,
140 strlen (format) + 1)) 140 strlen (format) + 1))
141 { 141 {
142 g_object_unref (in); 142 g_object_unref (in);
143 return; 143 return;
144 } 144 }
145 if ((height <= THUMBSIZE) && (width <= THUMBSIZE)) 145 if ((height <= THUMBSIZE) && (width <= THUMBSIZE))
146 { 146 {
147 g_object_unref (in); 147 g_object_unref (in);
148 return; 148 return;
149 } 149 }
150 if (height > THUMBSIZE) 150 if (height > THUMBSIZE)
151 { 151 {
152 width = width * THUMBSIZE / height; 152 width = width * THUMBSIZE / height;
153 height = THUMBSIZE; 153 height = THUMBSIZE;
154 } 154 }
155 if (width > THUMBSIZE) 155 if (width > THUMBSIZE)
156 { 156 {
157 height = height * THUMBSIZE / width; 157 height = height * THUMBSIZE / width;
158 width = THUMBSIZE; 158 width = THUMBSIZE;
159 } 159 }
160 if ( (0 == height) || (0 == width) ) 160 if ( (0 == height) || (0 == width) )
161 { 161 {
162 g_object_unref (in); 162 g_object_unref (in);
163 return; 163 return;
164 } 164 }
165 out = gdk_pixbuf_scale_simple (in, width, height, 165 out = gdk_pixbuf_scale_simple (in, width, height,
166 GDK_INTERP_BILINEAR); 166 GDK_INTERP_BILINEAR);
167 g_object_unref (in); 167 g_object_unref (in);
168 thumb = NULL; 168 thumb = NULL;
169 length = 0; 169 length = 0;
170 if (NULL == out) 170 if (NULL == out)
171 return; 171 return;
172 if (! gdk_pixbuf_save_to_buffer (out, &thumb, 172 if (! gdk_pixbuf_save_to_buffer (out, &thumb,
173 &length, 173 &length,
174 "png", NULL, 174 "png", NULL,
175 "compression", "9", 175 "compression", "9",
176 NULL)) 176 NULL))
177 { 177 {
178 g_object_unref (out); 178 g_object_unref (out);
179 return; 179 return;
180 } 180 }
181 g_object_unref (out); 181 g_object_unref (out);
182 if (NULL == thumb) 182 if (NULL == thumb)
183 return; 183 return;
184 ec->proc (ec->cls, 184 ec->proc (ec->cls,
185 "thumbnailgtk", 185 "thumbnailgtk",
186 EXTRACTOR_METATYPE_THUMBNAIL, 186 EXTRACTOR_METATYPE_THUMBNAIL,
187 EXTRACTOR_METAFORMAT_BINARY, 187 EXTRACTOR_METAFORMAT_BINARY,
188 "image/png", 188 "image/png",
189 thumb, length); 189 thumb, length);
190 free (thumb); 190 free (thumb);
191} 191}
192 192
@@ -207,31 +207,32 @@ EXTRACTOR_thumbnail_extract_method (struct EXTRACTOR_ExtractContext *ec)
207/** 207/**
208 * Initialize glib and load magic file. 208 * Initialize glib and load magic file.
209 */ 209 */
210void __attribute__ ((constructor)) 210void __attribute__ ((constructor))
211thumbnailgtk_gobject_init () 211thumbnailgtk_gobject_init ()
212{ 212{
213#if !GLIB_CHECK_VERSION(2, 35, 0) 213#if ! GLIB_CHECK_VERSION (2, 35, 0)
214 g_type_init (); 214 g_type_init ();
215#endif 215#endif
216 magic = magic_open (MAGIC_MIME_TYPE); 216 magic = magic_open (MAGIC_MIME_TYPE);
217 if (0 != magic_load (magic, NULL)) 217 if (0 != magic_load (magic, NULL))
218 { 218 {
219 /* FIXME: how to deal with errors? */ 219 /* FIXME: how to deal with errors? */
220 } 220 }
221} 221}
222 222
223 223
224/** 224/**
225 * Destructor for the library, cleans up. 225 * Destructor for the library, cleans up.
226 */ 226 */
227void __attribute__ ((destructor)) 227void __attribute__ ((destructor))
228thumbnailgtk_ltdl_fini () 228thumbnailgtk_ltdl_fini ()
229{ 229{
230 if (NULL != magic) 230 if (NULL != magic)
231 { 231 {
232 magic_close (magic); 232 magic_close (magic);
233 magic = NULL; 233 magic = NULL;
234 } 234 }
235} 235}
236 236
237
237/* end of thumbnailgtk_extractor.c */ 238/* end of thumbnailgtk_extractor.c */
diff --git a/src/plugins/tiff_extractor.c b/src/plugins/tiff_extractor.c
index 82ba94f..163bd80 100644
--- a/src/plugins/tiff_extractor.c
+++ b/src/plugins/tiff_extractor.c
@@ -36,8 +36,8 @@
36 */ 36 */
37static void 37static void
38error_cb (const char *module, 38error_cb (const char *module,
39 const char *fmt, 39 const char *fmt,
40 va_list ap) 40 va_list ap)
41{ 41{
42 /* do nothing */ 42 /* do nothing */
43} 43}
@@ -53,13 +53,13 @@ error_cb (const char *module,
53 */ 53 */
54static tsize_t 54static tsize_t
55read_cb (thandle_t ctx, 55read_cb (thandle_t ctx,
56 tdata_t data, 56 tdata_t data,
57 tsize_t size) 57 tsize_t size)
58{ 58{
59 struct EXTRACTOR_ExtractContext *ec = ctx; 59 struct EXTRACTOR_ExtractContext *ec = ctx;
60 void *ptr; 60 void *ptr;
61 ssize_t ret; 61 ssize_t ret;
62 62
63 ret = ec->read (ec->cls, &ptr, size); 63 ret = ec->read (ec->cls, &ptr, size);
64 if (ret > 0) 64 if (ret > 0)
65 memcpy (data, ptr, ret); 65 memcpy (data, ptr, ret);
@@ -77,8 +77,8 @@ read_cb (thandle_t ctx,
77 */ 77 */
78static tsize_t 78static tsize_t
79write_cb (thandle_t ctx, 79write_cb (thandle_t ctx,
80 tdata_t data, 80 tdata_t data,
81 tsize_t size) 81 tsize_t size)
82{ 82{
83 return -1; 83 return -1;
84} 84}
@@ -94,8 +94,8 @@ write_cb (thandle_t ctx,
94 */ 94 */
95static toff_t 95static toff_t
96seek_cb (thandle_t ctx, 96seek_cb (thandle_t ctx,
97 toff_t offset, 97 toff_t offset,
98 int whence) 98 int whence)
99{ 99{
100 struct EXTRACTOR_ExtractContext *ec = ctx; 100 struct EXTRACTOR_ExtractContext *ec = ctx;
101 101
@@ -168,77 +168,78 @@ static struct Matches tmap[] = {
168 168
169 169
170/** 170/**
171 * Main entry method for the 'image/tiff' extraction plugin. 171 * Main entry method for the 'image/tiff' extraction plugin.
172 * 172 *
173 * @param ec extraction context provided to the plugin 173 * @param ec extraction context provided to the plugin
174 */ 174 */
175void 175void
176EXTRACTOR_tiff_extract_method (struct EXTRACTOR_ExtractContext *ec) 176EXTRACTOR_tiff_extract_method (struct EXTRACTOR_ExtractContext *ec)
177{ 177{
178 TIFF *tiff; 178 TIFF *tiff;
179 unsigned int i; 179 unsigned int i;
180 char *meta; 180 char *meta;
181 char format[128]; 181 char format[128];
182 uint32_t width; 182 uint32_t width;
183 uint32_t height; 183 uint32_t height;
184 184
185 TIFFSetErrorHandler (&error_cb); 185 TIFFSetErrorHandler (&error_cb);
186 TIFFSetWarningHandler (&error_cb); 186 TIFFSetWarningHandler (&error_cb);
187 tiff = TIFFClientOpen ("<no filename>", 187 tiff = TIFFClientOpen ("<no filename>",
188 "rm", /* read-only, no mmap */ 188 "rm", /* read-only, no mmap */
189 ec, 189 ec,
190 &read_cb, 190 &read_cb,
191 &write_cb, 191 &write_cb,
192 &seek_cb, 192 &seek_cb,
193 &close_cb, 193 &close_cb,
194 &size_cb, 194 &size_cb,
195 NULL, NULL); 195 NULL, NULL);
196 if (NULL == tiff) 196 if (NULL == tiff)
197 return; 197 return;
198 for (i = 0; 0 != tmap[i].tag; i++) 198 for (i = 0; 0 != tmap[i].tag; i++)
199 if ( (1 == 199 if ( (1 ==
200 TIFFGetField (tiff, tmap[i].tag, &meta)) && 200 TIFFGetField (tiff, tmap[i].tag, &meta)) &&
201 (0 != 201 (0 !=
202 ec->proc (ec->cls, 202 ec->proc (ec->cls,
203 "tiff", 203 "tiff",
204 tmap[i].type, 204 tmap[i].type,
205 EXTRACTOR_METAFORMAT_UTF8, 205 EXTRACTOR_METAFORMAT_UTF8,
206 "text/plain", 206 "text/plain",
207 meta, 207 meta,
208 strlen (meta) + 1)) ) 208 strlen (meta) + 1)) )
209 goto CLEANUP; 209 goto CLEANUP;
210 if ( (1 == 210 if ( (1 ==
211 TIFFGetField (tiff, TIFFTAG_IMAGEWIDTH, &width)) && 211 TIFFGetField (tiff, TIFFTAG_IMAGEWIDTH, &width)) &&
212 (1 == 212 (1 ==
213 TIFFGetField (tiff, TIFFTAG_IMAGELENGTH, &height)) ) 213 TIFFGetField (tiff, TIFFTAG_IMAGELENGTH, &height)) )
214 { 214 {
215 snprintf (format, 215 snprintf (format,
216 sizeof (format), 216 sizeof (format),
217 "%ux%u", 217 "%ux%u",
218 (unsigned int) width, 218 (unsigned int) width,
219 (unsigned int) height); 219 (unsigned int) height);
220 if (0 != 220 if (0 !=
221 ec->proc (ec->cls, 221 ec->proc (ec->cls,
222 "tiff", 222 "tiff",
223 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, 223 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS,
224 EXTRACTOR_METAFORMAT_UTF8, 224 EXTRACTOR_METAFORMAT_UTF8,
225 "text/plain", 225 "text/plain",
226 format, 226 format,
227 strlen (format) + 1)) 227 strlen (format) + 1))
228 goto CLEANUP; 228 goto CLEANUP;
229 if (0 != 229 if (0 !=
230 ec->proc (ec->cls, 230 ec->proc (ec->cls,
231 "tiff", 231 "tiff",
232 EXTRACTOR_METATYPE_MIMETYPE, 232 EXTRACTOR_METATYPE_MIMETYPE,
233 EXTRACTOR_METAFORMAT_UTF8, 233 EXTRACTOR_METAFORMAT_UTF8,
234 "text/plain", 234 "text/plain",
235 "image/tiff", 235 "image/tiff",
236 strlen ("image/tiff") + 1)) 236 strlen ("image/tiff") + 1))
237 goto CLEANUP; 237 goto CLEANUP;
238 } 238 }
239 239
240 CLEANUP: 240CLEANUP:
241 TIFFClose (tiff); 241 TIFFClose (tiff);
242} 242}
243 243
244
244/* end of tiff_extractor.c */ 245/* end of tiff_extractor.c */
diff --git a/src/plugins/wav_extractor.c b/src/plugins/wav_extractor.c
index dae8890..5a7793b 100644
--- a/src/plugins/wav_extractor.c
+++ b/src/plugins/wav_extractor.c
@@ -49,9 +49,11 @@ little_endian_to_host32 (uint32_t in)
49{ 49{
50 unsigned char *ptr = (unsigned char *) &in; 50 unsigned char *ptr = (unsigned char *) &in;
51 51
52 return ((ptr[3] & 0xFF) << 24) | ((ptr[2] & 0xFF) << 16) | 52 return ((ptr[3] & 0xFF) << 24) | ((ptr[2] & 0xFF) << 16)
53 ((ptr[1] & 0xFF) << 8) | (ptr[0] & 0xFF); 53 | ((ptr[1] & 0xFF) << 8) | (ptr[0] & 0xFF);
54} 54}
55
56
55#endif 57#endif
56 58
57 59
@@ -85,11 +87,12 @@ EXTRACTOR_wav_extract_method (struct EXTRACTOR_ExtractContext *ec)
85 ec->read (ec->cls, &data, 44)) 87 ec->read (ec->cls, &data, 44))
86 return; 88 return;
87 buf = data; 89 buf = data;
88 if ((buf[0] != 'R' || buf[1] != 'I' || 90 if (((buf[0] != 'R') || (buf[1] != 'I') ||
89 buf[2] != 'F' || buf[3] != 'F' || 91 (buf[2] != 'F') || (buf[3] != 'F') ||
90 buf[8] != 'W' || buf[9] != 'A' || 92 (buf[8] != 'W') || (buf[9] != 'A') ||
91 buf[10] != 'V' || buf[11] != 'E' || 93 (buf[10] != 'V') || (buf[11] != 'E') ||
92 buf[12] != 'f' || buf[13] != 'm' || buf[14] != 't' || buf[15] != ' ')) 94 (buf[12] != 'f') || (buf[13] != 'm') || (buf[14] != 't') || (buf[15] !=
95 ' ') ))
93 return; /* not a WAV file */ 96 return; /* not a WAV file */
94 97
95 channels = *((uint16_t *) &buf[22]); 98 channels = *((uint16_t *) &buf[22]);
@@ -119,23 +122,24 @@ EXTRACTOR_wav_extract_method (struct EXTRACTOR_ExtractContext *ec)
119 (samples < sample_rate) 122 (samples < sample_rate)
120 ? (samples * 1000 / sample_rate) 123 ? (samples * 1000 / sample_rate)
121 : (samples / sample_rate) * 1000, 124 : (samples / sample_rate) * 1000,
122 sample_rate, (1 == channels) ? _("mono") : _("stereo")); 125 sample_rate, (1 == channels) ? _ ("mono") : _ ("stereo"));
123 if (0 != ec->proc (ec->cls, 126 if (0 != ec->proc (ec->cls,
124 "wav", 127 "wav",
125 EXTRACTOR_METATYPE_RESOURCE_TYPE, 128 EXTRACTOR_METATYPE_RESOURCE_TYPE,
126 EXTRACTOR_METAFORMAT_UTF8, 129 EXTRACTOR_METAFORMAT_UTF8,
127 "text/plain", 130 "text/plain",
128 scratch, 131 scratch,
129 strlen (scratch) + 1)) 132 strlen (scratch) + 1))
130 return; 133 return;
131 if (0 != ec->proc (ec->cls, 134 if (0 != ec->proc (ec->cls,
132 "wav", 135 "wav",
133 EXTRACTOR_METATYPE_MIMETYPE, 136 EXTRACTOR_METATYPE_MIMETYPE,
134 EXTRACTOR_METAFORMAT_UTF8, 137 EXTRACTOR_METAFORMAT_UTF8,
135 "text/plain", 138 "text/plain",
136 "audio/x-wav", 139 "audio/x-wav",
137 strlen ("audio/x-wav") +1 )) 140 strlen ("audio/x-wav") + 1))
138 return; 141 return;
139} 142}
140 143
144
141/* end of wav_extractor.c */ 145/* end of wav_extractor.c */
diff --git a/src/plugins/xm_extractor.c b/src/plugins/xm_extractor.c
index 854ff15..91b014b 100644
--- a/src/plugins/xm_extractor.c
+++ b/src/plugins/xm_extractor.c
@@ -47,7 +47,11 @@ struct Header
47 * @param s utf-8 string meta data value 47 * @param s utf-8 string meta data value
48 * @param t type of the meta data 48 * @param t type of the meta data
49 */ 49 */
50#define ADD(s,t) do { if (0 != ec->proc (ec->cls, "xm", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen (s) + 1)) return; } while (0) 50#define ADD(s,t) do { if (0 != ec->proc (ec->cls, "xm", t, \
51 EXTRACTOR_METAFORMAT_UTF8, \
52 "text/plain", s, strlen (s) \
53 + 1)) return; \
54} while (0)
51 55
52 56
53/** 57/**
@@ -72,20 +76,20 @@ EXTRACTOR_xm_extract_method (struct EXTRACTOR_ExtractContext *ec)
72 76
73 if ((ssize_t) sizeof (struct Header) > 77 if ((ssize_t) sizeof (struct Header) >
74 ec->read (ec->cls, 78 ec->read (ec->cls,
75 &data, 79 &data,
76 sizeof (struct Header))) 80 sizeof (struct Header)))
77 return; 81 return;
78 head = data; 82 head = data;
79 /* Check "magic" id bytes */ 83 /* Check "magic" id bytes */
80 if (memcmp (head->magicid, "Extended Module: ", 17)) 84 if (memcmp (head->magicid, "Extended Module: ", 17))
81 return; 85 return;
82 ADD("audio/x-xm", EXTRACTOR_METATYPE_MIMETYPE); 86 ADD ("audio/x-xm", EXTRACTOR_METATYPE_MIMETYPE);
83 /* Version of Tracker */ 87 /* Version of Tracker */
84 snprintf (xmversion, 88 snprintf (xmversion,
85 sizeof (xmversion), 89 sizeof (xmversion),
86 "%u.%u", 90 "%u.%u",
87 head->version[1], 91 head->version[1],
88 head->version[0]); 92 head->version[0]);
89 ADD (xmversion, EXTRACTOR_METATYPE_FORMAT_VERSION); 93 ADD (xmversion, EXTRACTOR_METATYPE_FORMAT_VERSION);
90 /* Song title */ 94 /* Song title */
91 memcpy (&title, head->title, 20); 95 memcpy (&title, head->title, 20);
@@ -104,4 +108,5 @@ EXTRACTOR_xm_extract_method (struct EXTRACTOR_ExtractContext *ec)
104 return; 108 return;
105} 109}
106 110
111
107/* end of xm_extractor.c */ 112/* end of xm_extractor.c */
diff --git a/src/plugins/zip_extractor.c b/src/plugins/zip_extractor.c
index 717d76d..1ffa5f6 100644
--- a/src/plugins/zip_extractor.c
+++ b/src/plugins/zip_extractor.c
@@ -44,86 +44,87 @@ EXTRACTOR_zip_extract_method (struct EXTRACTOR_ExtractContext *ec)
44 if (NULL == (uf = EXTRACTOR_common_unzip_open (ec))) 44 if (NULL == (uf = EXTRACTOR_common_unzip_open (ec)))
45 return; 45 return;
46 if ( (EXTRACTOR_UNZIP_OK == 46 if ( (EXTRACTOR_UNZIP_OK ==
47 EXTRACTOR_common_unzip_go_find_local_file (uf, 47 EXTRACTOR_common_unzip_go_find_local_file (uf,
48 "meta.xml", 48 "meta.xml",
49 2)) || 49 2)) ||
50 (EXTRACTOR_UNZIP_OK == 50 (EXTRACTOR_UNZIP_OK ==
51 EXTRACTOR_common_unzip_go_find_local_file (uf, 51 EXTRACTOR_common_unzip_go_find_local_file (uf,
52 "META-INF/MANIFEST.MF", 52 "META-INF/MANIFEST.MF",
53 2)) ) 53 2)) )
54 { 54 {
55 /* not a normal zip, might be odf, jar, etc. */ 55 /* not a normal zip, might be odf, jar, etc. */
56 goto CLEANUP; 56 goto CLEANUP;
57 } 57 }
58 if (EXTRACTOR_UNZIP_OK != 58 if (EXTRACTOR_UNZIP_OK !=
59 EXTRACTOR_common_unzip_go_to_first_file (uf)) 59 EXTRACTOR_common_unzip_go_to_first_file (uf))
60 { 60 {
61 /* zip malformed? */ 61 /* zip malformed? */
62 goto CLEANUP; 62 goto CLEANUP;
63 } 63 }
64 if (0 != 64 if (0 !=
65 ec->proc (ec->cls, 65 ec->proc (ec->cls,
66 "zip", 66 "zip",
67 EXTRACTOR_METATYPE_MIMETYPE, 67 EXTRACTOR_METATYPE_MIMETYPE,
68 EXTRACTOR_METAFORMAT_UTF8, 68 EXTRACTOR_METAFORMAT_UTF8,
69 "text/plain", 69 "text/plain",
70 "application/zip", 70 "application/zip",
71 strlen ("application/zip") + 1)) 71 strlen ("application/zip") + 1))
72 goto CLEANUP; 72 goto CLEANUP;
73 if (EXTRACTOR_UNZIP_OK == 73 if (EXTRACTOR_UNZIP_OK ==
74 EXTRACTOR_common_unzip_get_global_comment (uf, 74 EXTRACTOR_common_unzip_get_global_comment (uf,
75 fcomment, 75 fcomment,
76 sizeof (fcomment))) 76 sizeof (fcomment)))
77 { 77 {
78 if ( (0 != strlen (fcomment)) && 78 if ( (0 != strlen (fcomment)) &&
79 (0 != 79 (0 !=
80 ec->proc (ec->cls, 80 ec->proc (ec->cls,
81 "zip", 81 "zip",
82 EXTRACTOR_METATYPE_COMMENT, 82 EXTRACTOR_METATYPE_COMMENT,
83 EXTRACTOR_METAFORMAT_C_STRING, 83 EXTRACTOR_METAFORMAT_C_STRING,
84 "text/plain", 84 "text/plain",
85 fcomment, 85 fcomment,
86 strlen (fcomment) + 1))) 86 strlen (fcomment) + 1)))
87 goto CLEANUP; 87 goto CLEANUP;
88 } 88 }
89 do 89 do
90 {
91 if (EXTRACTOR_UNZIP_OK ==
92 EXTRACTOR_common_unzip_get_current_file_info (uf,
93 &fi,
94 fname,
95 sizeof (fname),
96 NULL, 0,
97 fcomment,
98 sizeof (fcomment)))
90 { 99 {
91 if (EXTRACTOR_UNZIP_OK == 100 if ( (0 != strlen (fname)) &&
92 EXTRACTOR_common_unzip_get_current_file_info (uf, 101 (0 !=
93 &fi, 102 ec->proc (ec->cls,
94 fname, 103 "zip",
95 sizeof (fname), 104 EXTRACTOR_METATYPE_FILENAME,
96 NULL, 0, 105 EXTRACTOR_METAFORMAT_C_STRING,
97 fcomment, 106 "text/plain",
98 sizeof (fcomment))) 107 fname,
99 { 108 strlen (fname) + 1)))
100 if ( (0 != strlen (fname)) && 109 goto CLEANUP;
101 (0 != 110 if ( (0 != strlen (fcomment)) &&
102 ec->proc (ec->cls, 111 (0 !=
103 "zip", 112 ec->proc (ec->cls,
104 EXTRACTOR_METATYPE_FILENAME, 113 "zip",
105 EXTRACTOR_METAFORMAT_C_STRING, 114 EXTRACTOR_METATYPE_COMMENT,
106 "text/plain", 115 EXTRACTOR_METAFORMAT_C_STRING,
107 fname, 116 "text/plain",
108 strlen (fname) + 1))) 117 fcomment,
109 goto CLEANUP; 118 strlen (fcomment) + 1)))
110 if ( (0 != strlen (fcomment)) && 119 goto CLEANUP;
111 (0 !=
112 ec->proc (ec->cls,
113 "zip",
114 EXTRACTOR_METATYPE_COMMENT,
115 EXTRACTOR_METAFORMAT_C_STRING,
116 "text/plain",
117 fcomment,
118 strlen (fcomment) + 1)))
119 goto CLEANUP;
120 }
121 } 120 }
121 }
122 while (EXTRACTOR_UNZIP_OK == 122 while (EXTRACTOR_UNZIP_OK ==
123 EXTRACTOR_common_unzip_go_to_next_file (uf)); 123 EXTRACTOR_common_unzip_go_to_next_file (uf));
124 124
125CLEANUP: 125CLEANUP:
126 (void) EXTRACTOR_common_unzip_close (uf); 126 (void) EXTRACTOR_common_unzip_close (uf);
127} 127}
128 128
129
129/* end of zip_extractor.c */ 130/* end of zip_extractor.c */