diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-07-29 20:43:34 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-07-29 20:43:34 +0000 |
commit | 832c37b6370780395554aebef1384f11594bc98f (patch) | |
tree | 7456d603e1aff1a26cbdeb15ec8aaa388bd343e5 | |
parent | 89d94a0e97e113eb8115f6131e557777d163c97a (diff) | |
download | libextractor-832c37b6370780395554aebef1384f11594bc98f.tar.gz libextractor-832c37b6370780395554aebef1384f11594bc98f.zip |
-towards compiling main again
-rw-r--r-- | src/main/Makefile.am | 1 | ||||
-rw-r--r-- | src/main/extractor.c | 8 | ||||
-rw-r--r-- | src/main/extractor_datasource.c | 114 |
3 files changed, 74 insertions, 49 deletions
diff --git a/src/main/Makefile.am b/src/main/Makefile.am index 2e190b6..207fda2 100644 --- a/src/main/Makefile.am +++ b/src/main/Makefile.am | |||
@@ -43,6 +43,7 @@ libextractor_la_SOURCES = \ | |||
43 | extractor_metatypes.c \ | 43 | extractor_metatypes.c \ |
44 | extractor_print.c \ | 44 | extractor_print.c \ |
45 | extractor_common.c extractor_common.h \ | 45 | extractor_common.c extractor_common.h \ |
46 | extractor_datasource.c extractor_datasource.h \ | ||
46 | extractor_plugpath.c extractor_plugpath.h \ | 47 | extractor_plugpath.c extractor_plugpath.h \ |
47 | extractor_plugins.c extractor_plugins.h \ | 48 | extractor_plugins.c extractor_plugins.h \ |
48 | $(EXTRACTOR_IPC) extractor_ipc.c extractor_ipc.h \ | 49 | $(EXTRACTOR_IPC) extractor_ipc.c extractor_ipc.h \ |
diff --git a/src/main/extractor.c b/src/main/extractor.c index 3faa897..2019fdd 100644 --- a/src/main/extractor.c +++ b/src/main/extractor.c | |||
@@ -125,7 +125,7 @@ process_plugin_reply (void *cls, | |||
125 | const void *value, | 125 | const void *value, |
126 | const char *mime) | 126 | const char *mime) |
127 | { | 127 | { |
128 | struct PluginReplyProcessor *prp = cls; | 128 | // struct PluginReplyProcessor *prp = cls; |
129 | 129 | ||
130 | // FIXME... | 130 | // FIXME... |
131 | } | 131 | } |
@@ -205,8 +205,10 @@ do_extract (struct EXTRACTOR_PluginList *plugins, | |||
205 | plugin_count = 0; | 205 | plugin_count = 0; |
206 | for (pos = plugins; NULL != pos; pos = pos->next) | 206 | for (pos = plugins; NULL != pos; pos = pos->next) |
207 | { | 207 | { |
208 | channel = channels[plugin_count]; | 208 | if (NULL != (channel = channels[plugin_count])) |
209 | // ... FIXME ... | 209 | { |
210 | // ... FIXME ... | ||
211 | } | ||
210 | plugin_count++; | 212 | plugin_count++; |
211 | } | 213 | } |
212 | // FIXME: need to terminate once all plugins are done... | 214 | // FIXME: need to terminate once all plugins are done... |
diff --git a/src/main/extractor_datasource.c b/src/main/extractor_datasource.c index a55679d..2338a1e 100644 --- a/src/main/extractor_datasource.c +++ b/src/main/extractor_datasource.c | |||
@@ -22,7 +22,6 @@ | |||
22 | * @brief random access and possibly decompression of data from buffer in memory or file on disk | 22 | * @brief random access and possibly decompression of data from buffer in memory or file on disk |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | */ | 24 | */ |
25 | |||
26 | #include "platform.h" | 25 | #include "platform.h" |
27 | #include "extractor_datasource.h" | 26 | #include "extractor_datasource.h" |
28 | 27 | ||
@@ -313,7 +312,7 @@ bfds_seek (struct BufferedFileDataSource *bfds, | |||
313 | if (bfds->fpos + bfds->buffer_pos + pos > bfds->fsize) | 312 | if (bfds->fpos + bfds->buffer_pos + pos > bfds->fsize) |
314 | return -1; | 313 | return -1; |
315 | if ( (NULL == bfds->buffer) || | 314 | if ( (NULL == bfds->buffer) || |
316 | ( (bfds->buffer_pos + pos < pos->buffer_bytes) && | 315 | ( (bfds->buffer_pos + pos < bfds->buffer_bytes) && |
317 | (bfds->buffer_pos + pos >= 0) ) ) | 316 | (bfds->buffer_pos + pos >= 0) ) ) |
318 | { | 317 | { |
319 | bfds->buffer_pos += pos; | 318 | bfds->buffer_pos += pos; |
@@ -337,7 +336,7 @@ bfds_seek (struct BufferedFileDataSource *bfds, | |||
337 | return -1; | 336 | return -1; |
338 | if ( (NULL == bfds->buffer) || | 337 | if ( (NULL == bfds->buffer) || |
339 | ( (bfds->buffer_pos <= pos) && | 338 | ( (bfds->buffer_pos <= pos) && |
340 | (bfds->buffer_pos + pos->buffer_bytes > pos) ) ) | 339 | (bfds->buffer_pos + bfds->buffer_bytes > pos) ) ) |
341 | { | 340 | { |
342 | bfds->buffer_pos = pos; | 341 | bfds->buffer_pos = pos; |
343 | return bfds->buffer_pos; | 342 | return bfds->buffer_pos; |
@@ -391,7 +390,7 @@ bfds_read (struct BufferedFileDataSource *bfds, | |||
391 | avail = count; | 390 | avail = count; |
392 | if (0 == avail) | 391 | if (0 == avail) |
393 | abort (); /* must not happen */ | 392 | abort (); /* must not happen */ |
394 | memcpy (&cbuf[ret], &bfds->data[bfds->buffer_pos], avail); | 393 | memcpy (&cbuf[ret], bfds->data + bfds->buffer_pos, avail); |
395 | bfds->buffer_pos += avail; | 394 | bfds->buffer_pos += avail; |
396 | count -= avail; | 395 | count -= avail; |
397 | ret += avail; | 396 | ret += avail; |
@@ -401,18 +400,6 @@ bfds_read (struct BufferedFileDataSource *bfds, | |||
401 | 400 | ||
402 | 401 | ||
403 | /** | 402 | /** |
404 | * Release resources of a compressed data source. | ||
405 | * | ||
406 | * @param cfs compressed data source to free | ||
407 | */ | ||
408 | static void | ||
409 | cfs_delete (struct CompressedFileSource *cfs) | ||
410 | { | ||
411 | free (cfs); | ||
412 | } | ||
413 | |||
414 | |||
415 | /** | ||
416 | * Reset gz-compressed data stream to the beginning. | 403 | * Reset gz-compressed data stream to the beginning. |
417 | * | 404 | * |
418 | * @return 1 on success, 0 to terminate extraction, | 405 | * @return 1 on success, 0 to terminate extraction, |
@@ -449,8 +436,6 @@ cfs_reset_stream_zlib (struct CompressedFileSource *cfs) | |||
449 | return -1; | 436 | return -1; |
450 | } | 437 | } |
451 | cfs->fpos = 0; | 438 | cfs->fpos = 0; |
452 | cfs->shm_pos = 0; | ||
453 | cfs->shm_buf_size = 0; | ||
454 | return 1; | 439 | return 1; |
455 | } | 440 | } |
456 | 441 | ||
@@ -739,10 +724,10 @@ cfs_read_zlib (struct CompressedFileSource *cfs, | |||
739 | if (cfs->fpos == cfs->uncompressed_size) | 724 | if (cfs->fpos == cfs->uncompressed_size) |
740 | return 0; | 725 | return 0; |
741 | rc = 0; | 726 | rc = 0; |
742 | if (strm.avail_out > 0) | 727 | if (cfs->strm.avail_out > 0) |
743 | { | 728 | { |
744 | /* got left-over decompressed data from previous round! */ | 729 | /* got left-over decompressed data from previous round! */ |
745 | in = strm.avail_out; | 730 | in = cfs->strm.avail_out; |
746 | if (in > size) | 731 | if (in > size) |
747 | in = size; | 732 | in = size; |
748 | memcpy (&dst[rc], &cfs->result[cfs->result_pos], in); | 733 | memcpy (&dst[rc], &cfs->result[cfs->result_pos], in); |
@@ -758,9 +743,9 @@ cfs_read_zlib (struct CompressedFileSource *cfs, | |||
758 | buf, sizeof (buf)); | 743 | buf, sizeof (buf)); |
759 | if (in <= 0) | 744 | if (in <= 0) |
760 | return -1; /* unexpected EOF */ | 745 | return -1; /* unexpected EOF */ |
761 | cfs->strm.next_in = buf; | 746 | cfs->strm.next_in = (unsigned char *) buf; |
762 | cfs->strm.avail_in = (uInt) count; | 747 | cfs->strm.avail_in = (uInt) in; |
763 | cfs->strm.next_out = cfs->result; | 748 | cfs->strm.next_out = (unsigned char *) cfs->result; |
764 | cfs->strm.avail_out = COM_CHUNK_SIZE; | 749 | cfs->strm.avail_out = COM_CHUNK_SIZE; |
765 | cfs->result_pos = 0; | 750 | cfs->result_pos = 0; |
766 | ret = inflate (&cfs->strm, Z_SYNC_FLUSH); | 751 | ret = inflate (&cfs->strm, Z_SYNC_FLUSH); |
@@ -821,9 +806,9 @@ cfs_read (struct CompressedFileSource *cfs, | |||
821 | switch (cfs->compression_type) | 806 | switch (cfs->compression_type) |
822 | { | 807 | { |
823 | case COMP_TYPE_ZLIB: | 808 | case COMP_TYPE_ZLIB: |
824 | return cfs_read_zlib (cfs, preserve); | 809 | return cfs_read_zlib (cfs, data, size); |
825 | case COMP_TYPE_BZ2: | 810 | case COMP_TYPE_BZ2: |
826 | return cfs_read_bz2 (cfs, preserve); | 811 | return cfs_read_bz2 (cfs, data, size); |
827 | default: | 812 | default: |
828 | return -1; | 813 | return -1; |
829 | } | 814 | } |
@@ -837,27 +822,64 @@ cfs_read (struct CompressedFileSource *cfs, | |||
837 | * | 822 | * |
838 | * @param cfs cfs to seek on | 823 | * @param cfs cfs to seek on |
839 | * @param position new starting point for the buffer | 824 | * @param position new starting point for the buffer |
825 | * @param whence one of the seek constants (SEEK_CUR, SEEK_SET, SEEK_END) | ||
840 | * @return new absolute buffer position, -1 on error or EOS | 826 | * @return new absolute buffer position, -1 on error or EOS |
841 | */ | 827 | */ |
842 | static int64_t | 828 | static int64_t |
843 | cfs_seek (struct CompressedFileSource *cfs, | 829 | cfs_seek (struct CompressedFileSource *cfs, |
844 | uint64_t position) | 830 | uint64_t position, |
831 | int whence) | ||
845 | { | 832 | { |
833 | uint64_t nposition; | ||
846 | int64_t delta; | 834 | int64_t delta; |
835 | |||
836 | switch (whence) | ||
837 | { | ||
838 | case SEEK_CUR: | ||
839 | if (cfs->fpos + position < 0) | ||
840 | return -1; | ||
841 | if ( (-1 != cfs->uncompressed_size) && | ||
842 | (cfs->fpos + position > cfs->uncompressed_size) ) | ||
843 | return -1; | ||
844 | nposition = cfs->fpos + position; | ||
845 | break; | ||
846 | case SEEK_END: | ||
847 | if (-1 == cfs->uncompressed_size) | ||
848 | { | ||
849 | /* yuck, need to first find end of file! */ | ||
850 | return -1; // FIXME: not implemented | ||
851 | } | ||
852 | if (position > 0) | ||
853 | return -1; | ||
854 | if (cfs->uncompressed_size < - position) | ||
855 | return -1; | ||
856 | nposition = cfs->uncompressed_size + position; | ||
857 | break; | ||
858 | case SEEK_SET: | ||
859 | if (position < 0) | ||
860 | return -1; | ||
861 | if ( (-1 != cfs->uncompressed_size) && | ||
862 | (cfs->uncompressed_size < position ) ) | ||
863 | return -1; | ||
864 | nposition = (uint64_t) position; | ||
865 | break; | ||
866 | default: | ||
867 | return -1; | ||
868 | } | ||
847 | 869 | ||
848 | delta = position - cfs->fpos; | 870 | delta = nposition - cfs->fpos; |
849 | if (delta < 0) | 871 | if (delta < 0) |
850 | { | 872 | { |
851 | if (result_pos >= - delta) | 873 | if (cfs->result_pos >= - delta) |
852 | { | 874 | { |
853 | result_pos += delta; | 875 | cfs->result_pos += delta; |
854 | delta = 0; | 876 | delta = 0; |
855 | } | 877 | } |
856 | else | 878 | else |
857 | { | 879 | { |
858 | if (-1 == cfs_reset_stream (cfs)) | 880 | if (-1 == cfs_reset_stream (cfs)) |
859 | return -1; | 881 | return -1; |
860 | delta = position; | 882 | delta = nposition; |
861 | } | 883 | } |
862 | } | 884 | } |
863 | while (delta > 0) | 885 | while (delta > 0) |
@@ -896,17 +918,17 @@ get_compression_type (struct BufferedFileDataSource *bfds) | |||
896 | return COMP_TYPE_UNDEFINED; | 918 | return COMP_TYPE_UNDEFINED; |
897 | 919 | ||
898 | #if HAVE_ZLIB | 920 | #if HAVE_ZLIB |
899 | if ( (bdfs->fsize >= MIN_ZLIB_HEADER) && | 921 | if ( (bfds->fsize >= MIN_ZLIB_HEADER) && |
900 | (data[0] == 0x1f) && | 922 | (read_data[0] == 0x1f) && |
901 | (data[1] == 0x8b) && | 923 | (read_data[1] == 0x8b) && |
902 | (data[2] == 0x08) ) | 924 | (read_data[2] == 0x08) ) |
903 | return COMP_TYPE_ZLIB; | 925 | return COMP_TYPE_ZLIB; |
904 | #endif | 926 | #endif |
905 | #if HAVE_LIBBZ2 | 927 | #if HAVE_LIBBZ2 |
906 | if ( (bdfs->fsize >= MIN_BZ2_HEADER) && | 928 | if ( (bfds->fsize >= MIN_BZ2_HEADER) && |
907 | (data[0] == 'B') && | 929 | (read_data[0] == 'B') && |
908 | (data[1] == 'Z') && | 930 | (read_data[1] == 'Z') && |
909 | (data[2] == 'h')) | 931 | (read_data[2] == 'h')) |
910 | return COMP_TYPE_BZ2; | 932 | return COMP_TYPE_BZ2; |
911 | #endif | 933 | #endif |
912 | return COMP_TYPE_INVALID; | 934 | return COMP_TYPE_INVALID; |
@@ -959,7 +981,7 @@ EXTRACTOR_datasource_create_from_file_ (const char *filename, | |||
959 | if (-1 == (fd = open (filename, O_RDONLY | O_LARGEFILE))) | 981 | if (-1 == (fd = open (filename, O_RDONLY | O_LARGEFILE))) |
960 | return NULL; | 982 | return NULL; |
961 | if ( (0 != fstat (fd, &sb)) || | 983 | if ( (0 != fstat (fd, &sb)) || |
962 | (S_ISDIR (fstatbuf.st_mode)) ) | 984 | (S_ISDIR (sb.st_mode)) ) |
963 | { | 985 | { |
964 | (void) close (fd); | 986 | (void) close (fd); |
965 | return NULL; | 987 | return NULL; |
@@ -982,7 +1004,7 @@ EXTRACTOR_datasource_create_from_file_ (const char *filename, | |||
982 | return NULL; | 1004 | return NULL; |
983 | } | 1005 | } |
984 | ds->bfds = bfds; | 1006 | ds->bfds = bfds; |
985 | ds->fd; | 1007 | ds->fd = fd; |
986 | ct = get_compression_type (bfds); | 1008 | ct = get_compression_type (bfds); |
987 | if ( (COMP_TYPE_ZLIB == ct) || | 1009 | if ( (COMP_TYPE_ZLIB == ct) || |
988 | (COMP_TYPE_BZ2 == ct) ) | 1010 | (COMP_TYPE_BZ2 == ct) ) |
@@ -1026,11 +1048,11 @@ EXTRACTOR_datasource_create_from_buffer_ (const char *buf, | |||
1026 | return NULL; | 1048 | return NULL; |
1027 | } | 1049 | } |
1028 | ds->bfds = bfds; | 1050 | ds->bfds = bfds; |
1029 | ds->fd; | 1051 | ds->fd = -1; |
1030 | ct = get_compression_type (bfds); | 1052 | ct = get_compression_type (bfds); |
1031 | if ( (COMP_TYPE_ZLIB == ct) || | 1053 | if ( (COMP_TYPE_ZLIB == ct) || |
1032 | (COMP_TYPE_BZ2 == ct) ) | 1054 | (COMP_TYPE_BZ2 == ct) ) |
1033 | ds->cfs = cfs_new (bfds, fsize, ct, proc, proc_cls); | 1055 | ds->cfs = cfs_new (bfds, size, ct, proc, proc_cls); |
1034 | if (NULL == ds->cfs) | 1056 | if (NULL == ds->cfs) |
1035 | { | 1057 | { |
1036 | bfds_delete (bfds); | 1058 | bfds_delete (bfds); |
@@ -1076,7 +1098,7 @@ EXTRACTOR_datasource_read_ (void *cls, | |||
1076 | 1098 | ||
1077 | if (NULL != ds->cfs) | 1099 | if (NULL != ds->cfs) |
1078 | return cfs_read (ds->cfs, data, size); | 1100 | return cfs_read (ds->cfs, data, size); |
1079 | return bdfs_read (ds->bdfs, data, size); | 1101 | return bfds_read (ds->bfds, data, size); |
1080 | } | 1102 | } |
1081 | 1103 | ||
1082 | 1104 | ||
@@ -1099,7 +1121,7 @@ EXTRACTOR_datasource_seek_ (void *cls, | |||
1099 | 1121 | ||
1100 | if (NULL != ds->cfs) | 1122 | if (NULL != ds->cfs) |
1101 | return cfs_seek (ds->cfs, pos, whence); | 1123 | return cfs_seek (ds->cfs, pos, whence); |
1102 | return bdfs_seek (ds->bdfs, pos, whence); | 1124 | return bfds_seek (ds->bfds, pos, whence); |
1103 | } | 1125 | } |
1104 | 1126 | ||
1105 | 1127 | ||
@@ -1115,8 +1137,8 @@ EXTRACTOR_datasource_get_size_ (void *cls) | |||
1115 | struct EXTRACTOR_Datasource *ds = cls; | 1137 | struct EXTRACTOR_Datasource *ds = cls; |
1116 | 1138 | ||
1117 | if (NULL != ds->cfs) | 1139 | if (NULL != ds->cfs) |
1118 | return cfs_seek (ds->cfs, pos, whence); | 1140 | return ds->cfs->uncompressed_size; |
1119 | return bdfs_seek (ds->bdfs, pos, whence); | 1141 | return ds->bfds->fsize; |
1120 | } | 1142 | } |
1121 | 1143 | ||
1122 | 1144 | ||