diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-08-05 20:01:02 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-08-05 20:01:02 +0000 |
commit | 2fbd84b9ecbc08f2a70944080c342184255b28f9 (patch) | |
tree | c222008d4a43ea909634a8cf5038c9c225152f4e /src/plugins | |
parent | 2bf60e0bcdfe66f789483986ebdb27050bd96e98 (diff) | |
download | libextractor-2fbd84b9ecbc08f2a70944080c342184255b28f9.tar.gz libextractor-2fbd84b9ecbc08f2a70944080c342184255b28f9.zip |
porting RPM to new API, fixing bugs with RPM's extracted INSTALLED_SIZE and BUILDTIME values
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Makefile.am | 28 | ||||
-rw-r--r-- | src/plugins/gif_extractor.c | 6 | ||||
-rw-r--r-- | src/plugins/mime_extractor.c | 6 | ||||
-rw-r--r-- | src/plugins/ogg_extractor.c | 5 | ||||
-rw-r--r-- | src/plugins/rpm_extractor.c | 374 | ||||
-rw-r--r-- | src/plugins/test_rpm.c | 326 | ||||
-rw-r--r-- | src/plugins/testdata/rpm_test.rpm | bin | 0 -> 692781 bytes |
7 files changed, 607 insertions, 138 deletions
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 454e5b9..fcc2d29 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am | |||
@@ -13,7 +13,8 @@ SUBDIRS = . | |||
13 | 13 | ||
14 | EXTRA_DIST = template_extractor.c \ | 14 | EXTRA_DIST = template_extractor.c \ |
15 | testdata/ogg_courseclear.ogg \ | 15 | testdata/ogg_courseclear.ogg \ |
16 | testdata/gif_image.gif | 16 | testdata/gif_image.gif \ |
17 | testdata/rpm_test.rpm | ||
17 | 18 | ||
18 | if HAVE_VORBISFILE | 19 | if HAVE_VORBISFILE |
19 | PLUGIN_OGG=libextractor_ogg.la | 20 | PLUGIN_OGG=libextractor_ogg.la |
@@ -30,10 +31,16 @@ PLUGIN_GIF=libextractor_gif.la | |||
30 | TEST_GIF=test_gif | 31 | TEST_GIF=test_gif |
31 | endif | 32 | endif |
32 | 33 | ||
34 | if HAVE_LIBRPM | ||
35 | PLUGIN_RPM=libextractor_rpm.la | ||
36 | TEST_RPM=test_rpm | ||
37 | endif | ||
38 | |||
33 | plugin_LTLIBRARIES = \ | 39 | plugin_LTLIBRARIES = \ |
34 | $(PLUGIN_OGG) \ | 40 | $(PLUGIN_OGG) \ |
35 | $(PLUGIN_MIME) \ | 41 | $(PLUGIN_MIME) \ |
36 | $(PLUGIN_GIF) | 42 | $(PLUGIN_GIF) \ |
43 | $(PLUGIN_RPM) | ||
37 | 44 | ||
38 | if HAVE_ZZUF | 45 | if HAVE_ZZUF |
39 | fuzz_tests=fuzz_default.sh | 46 | fuzz_tests=fuzz_default.sh |
@@ -42,7 +49,8 @@ endif | |||
42 | check_PROGRAMS = \ | 49 | check_PROGRAMS = \ |
43 | $(TEST_OGG) \ | 50 | $(TEST_OGG) \ |
44 | $(TEST_MIME) \ | 51 | $(TEST_MIME) \ |
45 | $(TEST_GIF) | 52 | $(TEST_GIF) \ |
53 | $(TEST_RPM) | ||
46 | 54 | ||
47 | TESTS = \ | 55 | TESTS = \ |
48 | $(fuzz_tests) \ | 56 | $(fuzz_tests) \ |
@@ -100,4 +108,18 @@ test_gif_LDADD = \ | |||
100 | $(top_builddir)/src/plugins/libtest.la | 108 | $(top_builddir)/src/plugins/libtest.la |
101 | 109 | ||
102 | 110 | ||
111 | libextractor_rpm_la_SOURCES = \ | ||
112 | rpm_extractor.c | ||
113 | libextractor_rpm_la_LDFLAGS = \ | ||
114 | $(PLUGINFLAGS) | ||
115 | libextractor_rpm_la_LIBADD = \ | ||
116 | $(top_builddir)/src/main/libextractor.la \ | ||
117 | -lrpm | ||
118 | |||
119 | test_rpm_SOURCES = \ | ||
120 | test_rpm.c | ||
121 | test_rpm_LDADD = \ | ||
122 | $(top_builddir)/src/plugins/libtest.la | ||
123 | |||
124 | |||
103 | 125 | ||
diff --git a/src/plugins/gif_extractor.c b/src/plugins/gif_extractor.c index a750449..f1c9d2d 100644 --- a/src/plugins/gif_extractor.c +++ b/src/plugins/gif_extractor.c | |||
@@ -17,7 +17,11 @@ | |||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | /** | |
21 | * @file plugins/gif_extractor.c | ||
22 | * @brief plugin to support GIF files | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
21 | #include "platform.h" | 25 | #include "platform.h" |
22 | #include "extractor.h" | 26 | #include "extractor.h" |
23 | #include <gif_lib.h> | 27 | #include <gif_lib.h> |
diff --git a/src/plugins/mime_extractor.c b/src/plugins/mime_extractor.c index 8e72988..ecf09dd 100644 --- a/src/plugins/mime_extractor.c +++ b/src/plugins/mime_extractor.c | |||
@@ -17,7 +17,11 @@ | |||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | /** | |
21 | * @file plugins/mime_extractor.c | ||
22 | * @brief plugin to determine mime types using libmagic (from 'file') | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
21 | #include "platform.h" | 25 | #include "platform.h" |
22 | #include "extractor.h" | 26 | #include "extractor.h" |
23 | #include <magic.h> | 27 | #include <magic.h> |
diff --git a/src/plugins/ogg_extractor.c b/src/plugins/ogg_extractor.c index c42bc01..c60e50d 100644 --- a/src/plugins/ogg_extractor.c +++ b/src/plugins/ogg_extractor.c | |||
@@ -17,6 +17,11 @@ | |||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | /** | ||
21 | * @file plugins/ogg_extractor.c | ||
22 | * @brief plugin to support OGG files | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
20 | #include "platform.h" | 25 | #include "platform.h" |
21 | #include "extractor.h" | 26 | #include "extractor.h" |
22 | #include "extractor_plugins.h" | 27 | #include "extractor_plugins.h" |
diff --git a/src/plugins/rpm_extractor.c b/src/plugins/rpm_extractor.c index f8ed431..adc08d8 100644 --- a/src/plugins/rpm_extractor.c +++ b/src/plugins/rpm_extractor.c | |||
@@ -1,10 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libextractor. | 2 | This file is part of libextractor. |
3 | (C) 2002, 2003, 2008, 2009 Vidyut Samanta and Christian Grothoff | 3 | (C) 2002, 2003, 2008, 2009, 2012 Vidyut Samanta and Christian Grothoff |
4 | 4 | ||
5 | libextractor is free software; you can redistribute it and/or modify | 5 | libextractor is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
7 | by the Free Software Foundation; either version 2, or (at your | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | libextractor is distributed in the hope that it will be useful, but | 10 | libextractor is distributed in the hope that it will be useful, but |
@@ -17,7 +17,11 @@ | |||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | /** | |
21 | * @file plugins/rpm_extractor.c | ||
22 | * @brief plugin to support RPM files | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
21 | #include "platform.h" | 25 | #include "platform.h" |
22 | #include "extractor.h" | 26 | #include "extractor.h" |
23 | #include <stdint.h> | 27 | #include <stdint.h> |
@@ -28,47 +32,128 @@ | |||
28 | #include <sys/types.h> | 32 | #include <sys/types.h> |
29 | #include <signal.h> | 33 | #include <signal.h> |
30 | 34 | ||
31 | /* ******************** pipe feeder ************************ */ | ||
32 | 35 | ||
33 | struct PipeArgs { | 36 | /** |
34 | const char * data; | 37 | * Closure for the 'pipe_feeder'. |
35 | size_t pos; | 38 | */ |
36 | size_t size; | 39 | struct PipeArgs |
40 | { | ||
41 | |||
42 | /** | ||
43 | * Context for reading data from. | ||
44 | */ | ||
45 | struct EXTRACTOR_ExtractContext *ec; | ||
46 | |||
47 | /** | ||
48 | * Lock for synchronizing access to 'ec'. | ||
49 | */ | ||
50 | pthread_mutex_t lock; | ||
51 | |||
52 | /** | ||
53 | * Pipe to write to at [1]. | ||
54 | */ | ||
37 | int pi[2]; | 55 | int pi[2]; |
56 | |||
57 | /** | ||
58 | * Set to 1 if we should stop writing to the pipe. | ||
59 | */ | ||
38 | int shutdown; | 60 | int shutdown; |
39 | }; | 61 | }; |
40 | 62 | ||
63 | |||
64 | /** | ||
65 | * Size of the buffer we use for reading. | ||
66 | */ | ||
67 | #define BUF_SIZE (16 * 1024) | ||
68 | |||
69 | |||
70 | /** | ||
71 | * Main function of a helper thread that passes the package data | ||
72 | * to librpm. | ||
73 | * | ||
74 | * @param args the 'struct PipeArgs*' | ||
75 | * @return NULL | ||
76 | */ | ||
41 | static void * | 77 | static void * |
42 | pipe_feeder(void * args) | 78 | pipe_feeder (void * args) |
43 | { | 79 | { |
44 | ssize_t ret; | 80 | struct PipeArgs *p = args; |
45 | struct PipeArgs * p = args; | 81 | ssize_t rret; |
82 | ssize_t wret; | ||
83 | ssize_t done; | ||
84 | void *ptr; | ||
85 | char *buf; | ||
46 | 86 | ||
47 | while ( (p->shutdown == 0) && | 87 | /* buffer is heap-allocated as this is a thread and |
48 | (0 < (ret = WRITE(p->pi[1], | 88 | large stack allocations might not be the best idea */ |
49 | &p->data[p->pos], | 89 | while (0 == p->shutdown) |
50 | p->size - p->pos))) ) | 90 | { |
51 | p->pos += ret; | 91 | pthread_mutex_lock (&p->lock); |
52 | CLOSE(p->pi[1]); | 92 | if (-1 == (rret = p->ec->read (p->ec->cls, &ptr, BUF_SIZE))) |
93 | { | ||
94 | pthread_mutex_unlock (&p->lock); | ||
95 | break; | ||
96 | } | ||
97 | pthread_mutex_unlock (&p->lock); | ||
98 | if (0 == rret) | ||
99 | break; | ||
100 | buf = ptr; | ||
101 | done = 0; | ||
102 | while ( (0 == p->shutdown) && | ||
103 | (done < rret) ) | ||
104 | { | ||
105 | if (-1 == (wret = WRITE (p->pi[1], | ||
106 | &buf[done], | ||
107 | rret - done))) | ||
108 | { | ||
109 | break; | ||
110 | } | ||
111 | if (0 == wret) | ||
112 | break; | ||
113 | done += wret; | ||
114 | } | ||
115 | if (done != rret) | ||
116 | break; | ||
117 | } | ||
118 | CLOSE (p->pi[1]); | ||
53 | return NULL; | 119 | return NULL; |
54 | } | 120 | } |
55 | 121 | ||
56 | static void | 122 | |
57 | sigalrmHandler (int sig) | 123 | /** |
124 | * LOG callback called by librpm. Does nothing, we | ||
125 | * just need this to override the default behavior. | ||
126 | */ | ||
127 | static int | ||
128 | discard_log_callback (rpmlogRec rec, | ||
129 | void *ctx) | ||
58 | { | 130 | { |
59 | /* do nothing */ | 131 | /* do nothing! */ |
132 | return 0; | ||
60 | } | 133 | } |
134 | |||
61 | 135 | ||
62 | 136 | /** | |
63 | /* *************** real libextractor stuff ***************** */ | 137 | * Mapping from RPM tags to LE types. |
64 | 138 | */ | |
65 | typedef struct | 139 | struct Matches |
66 | { | 140 | { |
141 | /** | ||
142 | * RPM tag. | ||
143 | */ | ||
67 | int32_t rtype; | 144 | int32_t rtype; |
145 | |||
146 | /** | ||
147 | * Corresponding LE type. | ||
148 | */ | ||
68 | enum EXTRACTOR_MetaType type; | 149 | enum EXTRACTOR_MetaType type; |
69 | } Matches; | 150 | }; |
70 | 151 | ||
71 | static Matches tests[] = { | 152 | |
153 | /** | ||
154 | * List of mappings from RPM tags to LE types. | ||
155 | */ | ||
156 | static struct Matches tests[] = { | ||
72 | {RPMTAG_NAME, EXTRACTOR_METATYPE_PACKAGE_NAME}, | 157 | {RPMTAG_NAME, EXTRACTOR_METATYPE_PACKAGE_NAME}, |
73 | {RPMTAG_VERSION, EXTRACTOR_METATYPE_SOFTWARE_VERSION}, | 158 | {RPMTAG_VERSION, EXTRACTOR_METATYPE_SOFTWARE_VERSION}, |
74 | {RPMTAG_GROUP, EXTRACTOR_METATYPE_SECTION}, | 159 | {RPMTAG_GROUP, EXTRACTOR_METATYPE_SECTION}, |
@@ -148,25 +233,21 @@ static Matches tests[] = { | |||
148 | RPMTAG_POSTTRANSPROG = 1154, /* s */ | 233 | RPMTAG_POSTTRANSPROG = 1154, /* s */ |
149 | RPMTAG_DISTTAG = 1155, /* s */ | 234 | RPMTAG_DISTTAG = 1155, /* s */ |
150 | #endif | 235 | #endif |
151 | {0, 0}, | 236 | {0, 0} |
152 | }; | 237 | }; |
153 | 238 | ||
154 | static int discardCB(rpmlogRec rec, void *ctx) { | ||
155 | /* do nothing! */ | ||
156 | return 0; | ||
157 | } | ||
158 | 239 | ||
159 | /* mimetype = application/x-rpm */ | 240 | /** |
160 | int | 241 | * Main entry method for the 'application/x-rpm' extraction plugin. |
161 | EXTRACTOR_rpm_extract (const char *data, | 242 | * |
162 | size_t size, | 243 | * @param ec extraction context provided to the plugin |
163 | EXTRACTOR_MetaDataProcessor proc, | 244 | */ |
164 | void *proc_cls, | 245 | void |
165 | const char *options) | 246 | EXTRACTOR_rpm_extract_method (struct EXTRACTOR_ExtractContext *ec) |
166 | { | 247 | { |
167 | struct PipeArgs parg; | 248 | struct PipeArgs parg; |
168 | pthread_t pthr; | 249 | pthread_t pthr; |
169 | void * unused; | 250 | void *unused; |
170 | const char *str; | 251 | const char *str; |
171 | Header hdr; | 252 | Header hdr; |
172 | HeaderIterator hi; | 253 | HeaderIterator hi; |
@@ -178,24 +259,28 @@ EXTRACTOR_rpm_extract (const char *data, | |||
178 | struct sigaction sig; | 259 | struct sigaction sig; |
179 | struct sigaction old; | 260 | struct sigaction old; |
180 | 261 | ||
181 | if (0 != pipe(parg.pi)) | 262 | parg.ec = ec; |
182 | return 0; | ||
183 | fdi = NULL; | ||
184 | parg.data = data; | ||
185 | parg.pos = 0; | ||
186 | parg.size = size; | ||
187 | parg.shutdown = 0; | 263 | parg.shutdown = 0; |
188 | if (0 != pthread_create(&pthr, | 264 | if (0 != pipe (parg.pi)) |
189 | NULL, | 265 | return; |
190 | &pipe_feeder, | 266 | if (0 != pthread_mutex_init (&parg.lock, NULL)) |
191 | &parg)) | 267 | { |
268 | CLOSE (parg.pi[0]); | ||
269 | CLOSE (parg.pi[1]); | ||
270 | return; | ||
271 | } | ||
272 | if (0 != pthread_create (&pthr, | ||
273 | NULL, | ||
274 | &pipe_feeder, | ||
275 | &parg)) | ||
192 | { | 276 | { |
193 | CLOSE(parg.pi[0]); | 277 | pthread_mutex_destroy (&parg.lock); |
194 | CLOSE(parg.pi[1]); | 278 | CLOSE (parg.pi[0]); |
195 | return 0; | 279 | CLOSE (parg.pi[1]); |
280 | return; | ||
196 | } | 281 | } |
197 | rpmlogSetCallback(&discardCB, NULL); | 282 | rpmlogSetCallback (&discard_log_callback, NULL); |
198 | fdi = fdDup(parg.pi[0]); | 283 | fdi = fdDup (parg.pi[0]); |
199 | ts = rpmtsCreate(); | 284 | ts = rpmtsCreate(); |
200 | rc = rpmReadPackageFile (ts, fdi, "GNU libextractor", &hdr); | 285 | rc = rpmReadPackageFile (ts, fdi, "GNU libextractor", &hdr); |
201 | switch (rc) | 286 | switch (rc) |
@@ -209,100 +294,123 @@ EXTRACTOR_rpm_extract (const char *data, | |||
209 | default: | 294 | default: |
210 | goto END; | 295 | goto END; |
211 | } | 296 | } |
212 | 297 | pthread_mutex_lock (&parg.lock); | |
213 | if (0 != proc (proc_cls, | 298 | if (0 != ec->proc (ec->cls, |
214 | "rpm", | 299 | "rpm", |
215 | EXTRACTOR_METATYPE_MIMETYPE, | 300 | EXTRACTOR_METATYPE_MIMETYPE, |
216 | EXTRACTOR_METAFORMAT_UTF8, | 301 | EXTRACTOR_METAFORMAT_UTF8, |
217 | "text/plain", | 302 | "text/plain", |
218 | "application/x-rpm", | 303 | "application/x-rpm", |
219 | strlen ("application/x-rpm") +1)) | 304 | strlen ("application/x-rpm") +1)) |
220 | return 1; | 305 | { |
306 | pthread_mutex_unlock (&parg.lock); | ||
307 | goto END; | ||
308 | } | ||
309 | pthread_mutex_unlock (&parg.lock); | ||
221 | hi = headerInitIterator (hdr); | 310 | hi = headerInitIterator (hdr); |
222 | p = rpmtdNew (); | 311 | p = rpmtdNew (); |
223 | while (1 == headerNext (hi, p)) | 312 | while (1 == headerNext (hi, p)) |
224 | { | 313 | for (i = 0; 0 != tests[i].rtype; i++) |
225 | i = 0; | 314 | { |
226 | while (tests[i].rtype != 0) | 315 | if (tests[i].rtype != p->tag) |
227 | { | 316 | continue; |
228 | if (tests[i].rtype == p->tag) | 317 | switch (p->type) |
229 | { | 318 | { |
230 | switch (p->type) | 319 | case RPM_STRING_ARRAY_TYPE: |
231 | { | 320 | case RPM_I18NSTRING_TYPE: |
232 | case RPM_STRING_ARRAY_TYPE: | 321 | case RPM_STRING_TYPE: |
233 | case RPM_I18NSTRING_TYPE: | 322 | while (NULL != (str = rpmtdNextString (p))) |
234 | case RPM_STRING_TYPE: | 323 | { |
235 | while (NULL != (str = rpmtdNextString (p))) | 324 | pthread_mutex_lock (&parg.lock); |
236 | { | 325 | if (0 != ec->proc (ec->cls, |
237 | if (0 != proc (proc_cls, | 326 | "rpm", |
238 | "rpm", | 327 | tests[i].type, |
239 | tests[i].type, | 328 | EXTRACTOR_METAFORMAT_UTF8, |
240 | EXTRACTOR_METAFORMAT_UTF8, | 329 | "text/plain", |
241 | "text/plain", | 330 | str, |
242 | str, | 331 | strlen (str) + 1)) |
243 | strlen (str) +1)) | 332 | |
244 | return 1; | 333 | { |
245 | } | 334 | pthread_mutex_unlock (&parg.lock); |
246 | break; | 335 | goto CLEANUP; |
247 | case RPM_INT32_TYPE: | 336 | } |
248 | { | 337 | pthread_mutex_unlock (&parg.lock); |
249 | if (p->tag == RPMTAG_BUILDTIME) | 338 | } |
250 | { | 339 | break; |
251 | char tmp[30]; | 340 | case RPM_INT32_TYPE: |
341 | { | ||
342 | if (p->tag == RPMTAG_BUILDTIME) | ||
343 | { | ||
344 | char tmp[30]; | ||
345 | uint32_t *v = rpmtdNextUint32 (p); | ||
346 | time_t tp = (time_t) *v; | ||
252 | 347 | ||
253 | ctime_r ((time_t *) p, tmp); | 348 | ctime_r (&tp, tmp); |
254 | tmp[strlen (tmp) - 1] = '\0'; /* eat linefeed */ | 349 | tmp[strlen (tmp) - 1] = '\0'; /* eat linefeed */ |
350 | pthread_mutex_lock (&parg.lock); | ||
351 | if (0 != ec->proc (ec->cls, | ||
352 | "rpm", | ||
353 | tests[i].type, | ||
354 | EXTRACTOR_METAFORMAT_UTF8, | ||
355 | "text/plain", | ||
356 | tmp, | ||
357 | strlen (tmp) + 1)) | ||
358 | { | ||
359 | pthread_mutex_unlock (&parg.lock); | ||
360 | goto CLEANUP; | ||
361 | } | ||
362 | pthread_mutex_unlock (&parg.lock); | ||
363 | } | ||
364 | else | ||
365 | { | ||
366 | char tmp[14]; | ||
367 | uint32_t *s = rpmtdNextUint32 (p); | ||
255 | 368 | ||
256 | if (0 != proc (proc_cls, | 369 | snprintf (tmp, |
257 | "rpm", | 370 | sizeof (tmp), |
258 | tests[i].type, | 371 | "%u", |
259 | EXTRACTOR_METAFORMAT_UTF8, | 372 | (unsigned int) *s); |
260 | "text/plain", | 373 | pthread_mutex_lock (&parg.lock); |
261 | tmp, | 374 | if (0 != ec->proc (ec->cls, |
262 | strlen (tmp) +1)) | 375 | "rpm", |
263 | return 1; | 376 | tests[i].type, |
264 | } | 377 | EXTRACTOR_METAFORMAT_UTF8, |
265 | else | 378 | "text/plain", |
266 | { | 379 | tmp, |
267 | char tmp[14]; | 380 | strlen (tmp) + 1)) |
268 | 381 | { | |
269 | sprintf (tmp, "%d", *(int *) p); | 382 | pthread_mutex_unlock (&parg.lock); |
270 | if (0 != proc (proc_cls, | 383 | goto CLEANUP; |
271 | "rpm", | 384 | } |
272 | tests[i].type, | 385 | pthread_mutex_unlock (&parg.lock); |
273 | EXTRACTOR_METAFORMAT_UTF8, | 386 | } |
274 | "text/plain", | 387 | break; |
275 | tmp, | 388 | } |
276 | strlen (tmp) +1)) | 389 | default: |
277 | return 1; | 390 | break; |
278 | } | 391 | } |
279 | break; | 392 | } |
280 | } | 393 | CLEANUP: |
281 | default: | ||
282 | break; | ||
283 | } | ||
284 | } | ||
285 | i++; | ||
286 | } | ||
287 | } | ||
288 | rpmtdFree (p); | 394 | rpmtdFree (p); |
289 | headerFreeIterator (hi); | 395 | headerFreeIterator (hi); |
290 | headerFree (hdr); | 396 | headerFree (hdr); |
291 | rpmtsFree(ts); | 397 | rpmtsFree(ts); |
292 | END: | 398 | |
293 | /* make sure SIGALRM does not kill us */ | 399 | END: |
400 | /* make sure SIGALRM does not kill us, then use it to | ||
401 | kill the thread */ | ||
294 | memset (&sig, 0, sizeof (struct sigaction)); | 402 | memset (&sig, 0, sizeof (struct sigaction)); |
295 | memset (&old, 0, sizeof (struct sigaction)); | 403 | memset (&old, 0, sizeof (struct sigaction)); |
296 | sig.sa_flags = SA_NODEFER; | 404 | sig.sa_flags = SA_NODEFER; |
297 | sig.sa_handler = &sigalrmHandler; | 405 | sig.sa_handler = SIG_IGN; |
298 | sigaction (SIGALRM, &sig, &old); | 406 | sigaction (SIGALRM, &sig, &old); |
299 | parg.shutdown = 1; | 407 | parg.shutdown = 1; |
300 | pthread_kill(pthr, SIGALRM); | 408 | CLOSE (parg.pi[0]); |
301 | pthread_join(pthr, &unused); | 409 | Fclose (fdi); |
410 | pthread_kill (pthr, SIGALRM); | ||
411 | pthread_join (pthr, &unused); | ||
412 | pthread_mutex_destroy (&parg.lock); | ||
302 | sigaction (SIGALRM, &old, &sig); | 413 | sigaction (SIGALRM, &old, &sig); |
303 | Fclose(fdi); | ||
304 | CLOSE(parg.pi[0]); | ||
305 | return 0; | ||
306 | } | 414 | } |
307 | 415 | ||
308 | /* end of rpm_extractor.c */ | 416 | /* end of rpm_extractor.c */ |
diff --git a/src/plugins/test_rpm.c b/src/plugins/test_rpm.c new file mode 100644 index 0000000..6ecc17a --- /dev/null +++ b/src/plugins/test_rpm.c | |||
@@ -0,0 +1,326 @@ | |||
1 | /* | ||
2 | This file is part of libextractor. | ||
3 | (C) 2012 Vidyut Samanta and Christian Grothoff | ||
4 | |||
5 | libextractor is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | libextractor is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with libextractor; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file plugins/test_rpm.c | ||
22 | * @brief testcase for ogg plugin | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "test_lib.h" | ||
27 | |||
28 | |||
29 | /** | ||
30 | * Expected package summary text. | ||
31 | */ | ||
32 | #define SUMMARY "The GNU libtool, which simplifies the use of shared libraries." | ||
33 | |||
34 | /** | ||
35 | * Expected package description text. | ||
36 | */ | ||
37 | #define DESCRIPTION "The libtool package contains the GNU libtool, a set of shell scripts\n"\ | ||
38 | "which automatically configure UNIX and UNIX-like architectures to\n" \ | ||
39 | "generically build shared libraries. Libtool provides a consistent,\n" \ | ||
40 | "portable interface which simplifies the process of using shared\n" \ | ||
41 | "libraries.\n" \ | ||
42 | "\n" \ | ||
43 | "If you are developing programs which will use shared libraries, you\n" \ | ||
44 | "should install libtool." | ||
45 | |||
46 | |||
47 | /** | ||
48 | * Main function for the RPM testcase. | ||
49 | * | ||
50 | * @param argc number of arguments (ignored) | ||
51 | * @param argv arguments (ignored) | ||
52 | * @return 0 on success | ||
53 | */ | ||
54 | int | ||
55 | main (int argc, char *argv[]) | ||
56 | { | ||
57 | struct SolutionData rpm_test_sol[] = | ||
58 | { | ||
59 | { | ||
60 | EXTRACTOR_METATYPE_MIMETYPE, | ||
61 | EXTRACTOR_METAFORMAT_UTF8, | ||
62 | "text/plain", | ||
63 | "application/x-rpm", | ||
64 | strlen ("application/x-rpm") + 1, | ||
65 | 0 | ||
66 | }, | ||
67 | { | ||
68 | EXTRACTOR_METATYPE_PACKAGE_NAME, | ||
69 | EXTRACTOR_METAFORMAT_UTF8, | ||
70 | "text/plain", | ||
71 | "libtool", | ||
72 | strlen ("libtool") + 1, | ||
73 | 0 | ||
74 | }, | ||
75 | { | ||
76 | EXTRACTOR_METATYPE_SOFTWARE_VERSION, | ||
77 | EXTRACTOR_METAFORMAT_UTF8, | ||
78 | "text/plain", | ||
79 | "1.5", | ||
80 | strlen ("1.5") + 1, | ||
81 | 0 | ||
82 | }, | ||
83 | { | ||
84 | EXTRACTOR_METATYPE_PACKAGE_VERSION, | ||
85 | EXTRACTOR_METAFORMAT_UTF8, | ||
86 | "text/plain", | ||
87 | "6", | ||
88 | strlen ("6") + 1, | ||
89 | 0 | ||
90 | }, | ||
91 | { | ||
92 | EXTRACTOR_METATYPE_SUMMARY, | ||
93 | EXTRACTOR_METAFORMAT_UTF8, | ||
94 | "text/plain", | ||
95 | SUMMARY, | ||
96 | strlen (SUMMARY) + 1, | ||
97 | 0 | ||
98 | }, | ||
99 | { | ||
100 | EXTRACTOR_METATYPE_DESCRIPTION, | ||
101 | EXTRACTOR_METAFORMAT_UTF8, | ||
102 | "text/plain", | ||
103 | DESCRIPTION, | ||
104 | strlen (DESCRIPTION) + 1, | ||
105 | 0 | ||
106 | }, | ||
107 | { | ||
108 | EXTRACTOR_METATYPE_CREATION_DATE, | ||
109 | EXTRACTOR_METAFORMAT_UTF8, | ||
110 | "text/plain", | ||
111 | "Thu Oct 2 11:44:33 2003", | ||
112 | strlen ("Thu Oct 2 11:44:33 2003") + 1, | ||
113 | 0 | ||
114 | }, | ||
115 | { | ||
116 | EXTRACTOR_METATYPE_BUILDHOST, | ||
117 | EXTRACTOR_METAFORMAT_UTF8, | ||
118 | "text/plain", | ||
119 | "bullwinkle.devel.redhat.com", | ||
120 | strlen ("bullwinkle.devel.redhat.com") + 1, | ||
121 | 0 | ||
122 | }, | ||
123 | { | ||
124 | EXTRACTOR_METATYPE_PACKAGE_INSTALLED_SIZE, | ||
125 | EXTRACTOR_METAFORMAT_UTF8, | ||
126 | "text/plain", | ||
127 | "2623621", | ||
128 | strlen ("2623621") + 1, | ||
129 | 0 | ||
130 | }, | ||
131 | { | ||
132 | EXTRACTOR_METATYPE_PACKAGE_DISTRIBUTION, | ||
133 | EXTRACTOR_METAFORMAT_UTF8, | ||
134 | "text/plain", | ||
135 | "Red Hat Linux", | ||
136 | strlen ("Red Hat Linux") + 1, | ||
137 | 0 | ||
138 | }, | ||
139 | { | ||
140 | EXTRACTOR_METATYPE_VENDOR, | ||
141 | EXTRACTOR_METAFORMAT_UTF8, | ||
142 | "text/plain", | ||
143 | "Red Hat, Inc.", | ||
144 | strlen ("Red Hat, Inc.") + 1, | ||
145 | 0 | ||
146 | }, | ||
147 | { | ||
148 | EXTRACTOR_METATYPE_LICENSE, | ||
149 | EXTRACTOR_METAFORMAT_UTF8, | ||
150 | "text/plain", | ||
151 | "GPL", | ||
152 | strlen ("GPL") + 1, | ||
153 | 0 | ||
154 | }, | ||
155 | { | ||
156 | EXTRACTOR_METATYPE_PACKAGE_MAINTAINER, | ||
157 | EXTRACTOR_METAFORMAT_UTF8, | ||
158 | "text/plain", | ||
159 | "Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>", | ||
160 | strlen ("Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>") + 1, | ||
161 | 0 | ||
162 | }, | ||
163 | { | ||
164 | EXTRACTOR_METATYPE_SECTION, | ||
165 | EXTRACTOR_METAFORMAT_UTF8, | ||
166 | "text/plain", | ||
167 | "Development/Tools", | ||
168 | strlen ("Development/Tools") + 1, | ||
169 | 0 | ||
170 | }, | ||
171 | { | ||
172 | EXTRACTOR_METATYPE_URL, | ||
173 | EXTRACTOR_METAFORMAT_UTF8, | ||
174 | "text/plain", | ||
175 | "http://www.gnu.org/software/libtool/", | ||
176 | strlen ("http://www.gnu.org/software/libtool/") + 1, | ||
177 | 0 | ||
178 | }, | ||
179 | { | ||
180 | EXTRACTOR_METATYPE_TARGET_OS, | ||
181 | EXTRACTOR_METAFORMAT_UTF8, | ||
182 | "text/plain", | ||
183 | "linux", | ||
184 | strlen ("linux") + 1, | ||
185 | 0 | ||
186 | }, | ||
187 | { | ||
188 | EXTRACTOR_METATYPE_TARGET_ARCHITECTURE, | ||
189 | EXTRACTOR_METAFORMAT_UTF8, | ||
190 | "text/plain", | ||
191 | "ia64", | ||
192 | strlen ("ia64") + 1, | ||
193 | 0 | ||
194 | }, | ||
195 | { | ||
196 | EXTRACTOR_METATYPE_PACKAGE_PROVIDES, | ||
197 | EXTRACTOR_METAFORMAT_UTF8, | ||
198 | "text/plain", | ||
199 | "libtool", | ||
200 | strlen ("libtool") + 1, | ||
201 | 0 | ||
202 | }, | ||
203 | { | ||
204 | EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, | ||
205 | EXTRACTOR_METAFORMAT_UTF8, | ||
206 | "text/plain", | ||
207 | "/bin/sh", | ||
208 | strlen ("/bin/sh") + 1, | ||
209 | 0 | ||
210 | }, | ||
211 | { | ||
212 | EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, | ||
213 | EXTRACTOR_METAFORMAT_UTF8, | ||
214 | "text/plain", | ||
215 | "/bin/sh", | ||
216 | strlen ("/bin/sh") + 1, | ||
217 | 0 | ||
218 | }, | ||
219 | { | ||
220 | EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, | ||
221 | EXTRACTOR_METAFORMAT_UTF8, | ||
222 | "text/plain", | ||
223 | "/bin/sh", | ||
224 | strlen ("/bin/sh") + 1, | ||
225 | 0 | ||
226 | }, | ||
227 | { | ||
228 | EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, | ||
229 | EXTRACTOR_METAFORMAT_UTF8, | ||
230 | "text/plain", | ||
231 | "/sbin/install-info", | ||
232 | strlen ("/sbin/install-info") + 1, | ||
233 | 0 | ||
234 | }, | ||
235 | { | ||
236 | EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, | ||
237 | EXTRACTOR_METAFORMAT_UTF8, | ||
238 | "text/plain", | ||
239 | "autoconf", | ||
240 | strlen ("autoconf") + 1, | ||
241 | 0 | ||
242 | }, | ||
243 | { | ||
244 | EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, | ||
245 | EXTRACTOR_METAFORMAT_UTF8, | ||
246 | "text/plain", | ||
247 | "automake", | ||
248 | strlen ("automake") + 1, | ||
249 | 0 | ||
250 | }, | ||
251 | { | ||
252 | EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, | ||
253 | EXTRACTOR_METAFORMAT_UTF8, | ||
254 | "text/plain", | ||
255 | "libtool-libs", | ||
256 | strlen ("libtool-libs") + 1, | ||
257 | 0 | ||
258 | }, | ||
259 | { | ||
260 | EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, | ||
261 | EXTRACTOR_METAFORMAT_UTF8, | ||
262 | "text/plain", | ||
263 | "m4", | ||
264 | strlen ("m4") + 1, | ||
265 | 0 | ||
266 | }, | ||
267 | { | ||
268 | EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, | ||
269 | EXTRACTOR_METAFORMAT_UTF8, | ||
270 | "text/plain", | ||
271 | "mktemp", | ||
272 | strlen ("mktemp") + 1, | ||
273 | 0 | ||
274 | }, | ||
275 | { | ||
276 | EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, | ||
277 | EXTRACTOR_METAFORMAT_UTF8, | ||
278 | "text/plain", | ||
279 | "perl", | ||
280 | strlen ("perl") + 1, | ||
281 | 0 | ||
282 | }, | ||
283 | { | ||
284 | EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, | ||
285 | EXTRACTOR_METAFORMAT_UTF8, | ||
286 | "text/plain", | ||
287 | "rpmlib(CompressedFileNames)", | ||
288 | strlen ("rpmlib(CompressedFileNames)") + 1, | ||
289 | 0 | ||
290 | }, | ||
291 | { | ||
292 | EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, | ||
293 | EXTRACTOR_METAFORMAT_UTF8, | ||
294 | "text/plain", | ||
295 | "rpmlib(PayloadFilesHavePrefix)", | ||
296 | strlen ("rpmlib(PayloadFilesHavePrefix)") + 1, | ||
297 | 0 | ||
298 | }, | ||
299 | { | ||
300 | EXTRACTOR_METATYPE_PACKAGE_DEPENDENCY, | ||
301 | EXTRACTOR_METAFORMAT_UTF8, | ||
302 | "text/plain", | ||
303 | "rpmlib(VersionedDependencies)", | ||
304 | strlen ("rpmlib(VersionedDependencies)") + 1, | ||
305 | 0 | ||
306 | }, | ||
307 | { | ||
308 | EXTRACTOR_METATYPE_TARGET_PLATFORM, | ||
309 | EXTRACTOR_METAFORMAT_UTF8, | ||
310 | "text/plain", | ||
311 | "ia64-redhat-linux-gnu", | ||
312 | strlen ("ia64-redhat-linux-gnu") + 1, | ||
313 | 0 | ||
314 | }, | ||
315 | { 0, 0, NULL, NULL, 0, -1 } | ||
316 | }; | ||
317 | struct ProblemSet ps[] = | ||
318 | { | ||
319 | { "testdata/rpm_test.rpm", | ||
320 | rpm_test_sol }, | ||
321 | { NULL, NULL } | ||
322 | }; | ||
323 | return ET_main ("rpm", ps); | ||
324 | } | ||
325 | |||
326 | /* end of test_rpm.c */ | ||
diff --git a/src/plugins/testdata/rpm_test.rpm b/src/plugins/testdata/rpm_test.rpm new file mode 100644 index 0000000..6a52e42 --- /dev/null +++ b/src/plugins/testdata/rpm_test.rpm | |||
Binary files differ | |||