mirror of
https://github.com/simon987/libscan.git
synced 2025-04-21 11:16:46 +00:00
Compare commits
1 Commits
097580eb40
...
babd6b6d13
Author | SHA1 | Date | |
---|---|---|---|
babd6b6d13 |
@ -47,25 +47,19 @@ int arc_read(struct vfile *f, void *buf, size_t size) {
|
|||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
int arc_open(scan_arc_ctx_t *ctx, vfile_t *f, struct archive **a, arc_data_t *arc_data, int allow_recurse) {
|
int arc_open(vfile_t *f, struct archive **a, arc_data_t *arc_data, int allow_recurse) {
|
||||||
arc_data->f = f;
|
arc_data->f = f;
|
||||||
|
|
||||||
if (f->is_fs_file) {
|
if (f->is_fs_file) {
|
||||||
*a = archive_read_new();
|
*a = archive_read_new();
|
||||||
archive_read_support_filter_all(*a);
|
archive_read_support_filter_all(*a);
|
||||||
archive_read_support_format_all(*a);
|
archive_read_support_format_all(*a);
|
||||||
if (ctx->passphrase[0] != 0) {
|
|
||||||
archive_read_add_passphrase(*a, ctx->passphrase);
|
|
||||||
}
|
|
||||||
|
|
||||||
return archive_read_open_filename(*a, f->filepath, ARC_BUF_SIZE);
|
return archive_read_open_filename(*a, f->filepath, ARC_BUF_SIZE);
|
||||||
} else if (allow_recurse) {
|
} else if (allow_recurse) {
|
||||||
*a = archive_read_new();
|
*a = archive_read_new();
|
||||||
archive_read_support_filter_all(*a);
|
archive_read_support_filter_all(*a);
|
||||||
archive_read_support_format_all(*a);
|
archive_read_support_format_all(*a);
|
||||||
if (ctx->passphrase[0] != 0) {
|
|
||||||
archive_read_add_passphrase(*a, ctx->passphrase);
|
|
||||||
}
|
|
||||||
|
|
||||||
return archive_read_open(
|
return archive_read_open(
|
||||||
*a, arc_data,
|
*a, arc_data,
|
||||||
@ -86,7 +80,7 @@ scan_code_t parse_archive(scan_arc_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
|||||||
arc_data_t arc_data;
|
arc_data_t arc_data;
|
||||||
arc_data.f = f;
|
arc_data.f = f;
|
||||||
|
|
||||||
int ret = arc_open(ctx, f, &a, &arc_data, ctx->mode == ARC_MODE_RECURSE);
|
int ret = arc_open(f, &a, &arc_data, ctx->mode == ARC_MODE_RECURSE);
|
||||||
if (ret == ARC_SKIPPED) {
|
if (ret == ARC_SKIPPED) {
|
||||||
return SCAN_OK;
|
return SCAN_OK;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ typedef struct {
|
|||||||
log_callback_t log;
|
log_callback_t log;
|
||||||
logf_callback_t logf;
|
logf_callback_t logf;
|
||||||
store_callback_t store;
|
store_callback_t store;
|
||||||
char passphrase[4096];
|
|
||||||
} scan_arc_ctx_t;
|
} scan_arc_ctx_t;
|
||||||
|
|
||||||
#define ARC_BUF_SIZE 8192
|
#define ARC_BUF_SIZE 8192
|
||||||
@ -57,7 +56,7 @@ static int vfile_close_callback(struct archive *a, void *user_data) {
|
|||||||
return ARCHIVE_OK;
|
return ARCHIVE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int arc_open(scan_arc_ctx_t *ctx, vfile_t *f, struct archive **a, arc_data_t *arc_data, int allow_recurse);
|
int arc_open(vfile_t *f, struct archive **a, arc_data_t *arc_data, int allow_recurse);
|
||||||
|
|
||||||
int should_parse_filtered_file(const char *filepath, int ext);
|
int should_parse_filtered_file(const char *filepath, int ext);
|
||||||
|
|
||||||
|
@ -5,14 +5,13 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <archive.h>
|
#include <archive.h>
|
||||||
|
|
||||||
static scan_arc_ctx_t arc_ctx = (scan_arc_ctx_t) {.passphrase = {0,}};
|
|
||||||
|
|
||||||
void parse_comic(scan_comic_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
void parse_comic(scan_comic_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||||
struct archive *a = NULL;
|
struct archive *a = NULL;
|
||||||
struct archive_entry *entry = NULL;
|
struct archive_entry *entry = NULL;
|
||||||
arc_data_t arc_data;
|
arc_data_t arc_data;
|
||||||
|
|
||||||
int ret = arc_open(&arc_ctx, f, &a, &arc_data, TRUE);
|
int ret = arc_open(f, &a, &arc_data, TRUE);
|
||||||
if (ret != ARCHIVE_OK) {
|
if (ret != ARCHIVE_OK) {
|
||||||
CTX_LOG_ERRORF(f->filepath, "(cbr.c) [%d] %s", ret, archive_error_string(a))
|
CTX_LOG_ERRORF(f->filepath, "(cbr.c) [%d] %s", ret, archive_error_string(a))
|
||||||
archive_read_free(a);
|
archive_read_free(a);
|
||||||
|
@ -255,7 +255,7 @@ void fill_image(fz_context *fzctx, UNUSED(fz_device *dev),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_ebook_mem(scan_ebook_ctx_t *ctx, void *buf, size_t buf_len, const char *mime_str, document_t *doc, int tn_only) {
|
void parse_ebook_mem(scan_ebook_ctx_t *ctx, void *buf, size_t buf_len, const char *mime_str, document_t *doc) {
|
||||||
|
|
||||||
fz_context *fzctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
|
fz_context *fzctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
|
||||||
thread_ctx = *ctx;
|
thread_ctx = *ctx;
|
||||||
@ -285,6 +285,26 @@ void parse_ebook_mem(scan_ebook_ctx_t *ctx, void *buf, size_t buf_len, const cha
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char title[8192] = {'\0',};
|
||||||
|
fz_try(fzctx)
|
||||||
|
fz_lookup_metadata(fzctx, fzdoc, FZ_META_INFO_TITLE, title, sizeof(title));
|
||||||
|
fz_catch(fzctx)
|
||||||
|
;
|
||||||
|
|
||||||
|
if (strlen(title) > 0) {
|
||||||
|
APPEND_UTF8_META(doc, MetaTitle, title)
|
||||||
|
}
|
||||||
|
|
||||||
|
char author[4096] = {'\0',};
|
||||||
|
fz_try(fzctx)
|
||||||
|
fz_lookup_metadata(fzctx, fzdoc, FZ_META_INFO_AUTHOR, author, sizeof(author));
|
||||||
|
fz_catch(fzctx)
|
||||||
|
;
|
||||||
|
|
||||||
|
if (strlen(author) > 0) {
|
||||||
|
APPEND_UTF8_META(doc, MetaAuthor, author)
|
||||||
|
}
|
||||||
|
|
||||||
int page_count = -1;
|
int page_count = -1;
|
||||||
fz_var(err);
|
fz_var(err);
|
||||||
fz_try(fzctx)
|
fz_try(fzctx)
|
||||||
@ -311,33 +331,6 @@ void parse_ebook_mem(scan_ebook_ctx_t *ctx, void *buf, size_t buf_len, const cha
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tn_only) {
|
|
||||||
fz_drop_stream(fzctx, stream);
|
|
||||||
fz_drop_document(fzctx, fzdoc);
|
|
||||||
fz_drop_context(fzctx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char title[8192] = {'\0',};
|
|
||||||
fz_try(fzctx)
|
|
||||||
fz_lookup_metadata(fzctx, fzdoc, FZ_META_INFO_TITLE, title, sizeof(title));
|
|
||||||
fz_catch(fzctx)
|
|
||||||
;
|
|
||||||
|
|
||||||
if (strlen(title) > 0) {
|
|
||||||
APPEND_UTF8_META(doc, MetaTitle, title)
|
|
||||||
}
|
|
||||||
|
|
||||||
char author[4096] = {'\0',};
|
|
||||||
fz_try(fzctx)
|
|
||||||
fz_lookup_metadata(fzctx, fzdoc, FZ_META_INFO_AUTHOR, author, sizeof(author));
|
|
||||||
fz_catch(fzctx)
|
|
||||||
;
|
|
||||||
|
|
||||||
if (strlen(author) > 0) {
|
|
||||||
APPEND_UTF8_META(doc, MetaAuthor, author)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (ctx->content_size > 0) {
|
if (ctx->content_size > 0) {
|
||||||
fz_stext_options opts = {0};
|
fz_stext_options opts = {0};
|
||||||
@ -432,6 +425,6 @@ void parse_ebook(scan_ebook_ctx_t *ctx, vfile_t *f, const char *mime_str, docume
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_ebook_mem(ctx, buf, buf_len, mime_str, doc, FALSE);
|
parse_ebook_mem(ctx, buf, buf_len, mime_str, doc);
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,6 @@ typedef struct {
|
|||||||
} scan_ebook_ctx_t;
|
} scan_ebook_ctx_t;
|
||||||
|
|
||||||
void parse_ebook(scan_ebook_ctx_t *ctx, vfile_t *f, const char* mime_str, document_t *doc);
|
void parse_ebook(scan_ebook_ctx_t *ctx, vfile_t *f, const char* mime_str, document_t *doc);
|
||||||
void parse_ebook_mem(scan_ebook_ctx_t *ctx, void *buf, size_t buf_len, const char *mime_str, document_t *doc, int tn_only);
|
void parse_ebook_mem(scan_ebook_ctx_t *ctx, void* buf, size_t buf_len, const char* mime_str, document_t *doc);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -357,13 +357,8 @@ void parse_media_format_ctx(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subtitle_stream != -1 && ctx->read_subtitles) {
|
if (subtitle_stream != -1) {
|
||||||
read_subtitles(ctx, pFormatCtx, subtitle_stream, doc);
|
read_subtitles(ctx, pFormatCtx, subtitle_stream, doc);
|
||||||
|
|
||||||
// Reset stream
|
|
||||||
if (video_stream != -1) {
|
|
||||||
av_seek_frame(pFormatCtx, video_stream, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (video_stream != -1 && ctx->tn_size > 0) {
|
if (video_stream != -1 && ctx->tn_size > 0) {
|
||||||
|
@ -22,6 +22,7 @@ void parse_msdoc_text(scan_msdoc_ctx_t *ctx, document_t *doc, FILE *file_in, voi
|
|||||||
|
|
||||||
int doc_word_version = iGuessVersionNumber(file_in, buf_len);
|
int doc_word_version = iGuessVersionNumber(file_in, buf_len);
|
||||||
if (doc_word_version < 0 || doc_word_version == 3) {
|
if (doc_word_version < 0 || doc_word_version == 3) {
|
||||||
|
fclose(file_in);
|
||||||
free(buf);
|
free(buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -67,6 +68,7 @@ void parse_msdoc_text(scan_msdoc_ctx_t *ctx, document_t *doc, FILE *file_in, voi
|
|||||||
text_buffer_destroy(&tex);
|
text_buffer_destroy(&tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fclose(file_in);
|
||||||
free(buf);
|
free(buf);
|
||||||
free(out_buf);
|
free(out_buf);
|
||||||
}
|
}
|
||||||
@ -82,19 +84,21 @@ void parse_msdoc_pdf(scan_msdoc_ctx_t *ctx, document_t *doc, FILE *file, void* b
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Open word doc
|
// Open word doc
|
||||||
|
|
||||||
options_type *opts = direct_vGetOptions();
|
options_type *opts = direct_vGetOptions();
|
||||||
opts->iParagraphBreak = 74;
|
opts->iParagraphBreak = 74;
|
||||||
opts->eConversionType = conversion_pdf;
|
opts->eConversionType = conversion_pdf;
|
||||||
opts->bHideHiddenText = 1;
|
opts->bHideHiddenText = 1;
|
||||||
opts->bRemoveRemovedText = 1;
|
opts->bRemoveRemovedText = 1;
|
||||||
opts->bUseLandscape = 0;
|
opts->bUseLandscape = 0;
|
||||||
opts->eEncoding = encoding_latin_1;
|
opts->eEncoding = encoding_latin_2;
|
||||||
opts->iPageHeight = 842; // A4
|
opts->iPageHeight = 842; // A4
|
||||||
opts->iPageWidth = 595;
|
opts->iPageWidth = 595;
|
||||||
opts->eImageLevel = level_ps_3;
|
opts->eImageLevel = level_ps_3;
|
||||||
|
|
||||||
int doc_word_version = iGuessVersionNumber(file, buf_len);
|
int doc_word_version = iGuessVersionNumber(file, buf_len);
|
||||||
if (doc_word_version < 0 || doc_word_version == 3) {
|
if (doc_word_version < 0 || doc_word_version == 3) {
|
||||||
|
fclose(file);
|
||||||
free(buf);
|
free(buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -107,6 +111,7 @@ void parse_msdoc_pdf(scan_msdoc_ctx_t *ctx, document_t *doc, FILE *file, void* b
|
|||||||
|
|
||||||
diagram_type *diag = pCreateDiagram("antiword", NULL, file_out);
|
diagram_type *diag = pCreateDiagram("antiword", NULL, file_out);
|
||||||
if (diag == NULL) {
|
if (diag == NULL) {
|
||||||
|
fclose(file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,8 +120,9 @@ void parse_msdoc_pdf(scan_msdoc_ctx_t *ctx, document_t *doc, FILE *file, void* b
|
|||||||
|
|
||||||
fclose(file_out);
|
fclose(file_out);
|
||||||
|
|
||||||
parse_ebook_mem(&ebook_ctx, out_buf, out_len, "application/pdf", doc, TRUE);
|
parse_ebook_mem(&ebook_ctx, out_buf, out_len, "application/pdf", doc);
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
free(buf);
|
free(buf);
|
||||||
free(out_buf);
|
free(out_buf);
|
||||||
}
|
}
|
||||||
@ -138,10 +144,8 @@ void parse_msdoc(scan_msdoc_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->tn_size > 0) {
|
if (ctx->tn_size > 0) {
|
||||||
char *buf_pdf = malloc(buf_len);
|
parse_msdoc_pdf(ctx, doc, file, buf, buf_len);
|
||||||
memcpy(buf_pdf, buf, buf_len);
|
} else {
|
||||||
parse_msdoc_pdf(ctx, doc, file, buf_pdf, buf_len);
|
|
||||||
}
|
|
||||||
parse_msdoc_text(ctx, doc, file, buf, buf_len);
|
parse_msdoc_text(ctx, doc, file, buf, buf_len);
|
||||||
fclose(file);
|
}
|
||||||
}
|
}
|
||||||
|
@ -595,23 +595,6 @@ TEST(Arc, Utf8) {
|
|||||||
cleanup(&doc, &f);
|
cleanup(&doc, &f);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Arc, EncryptedZip) {
|
|
||||||
vfile_t f;
|
|
||||||
document_t doc;
|
|
||||||
load_doc_file("libscan-test-files/test_files/arc/encrypted.zip", &f, &doc);
|
|
||||||
|
|
||||||
size_t size_before = store_size;
|
|
||||||
|
|
||||||
strcpy(arc_recurse_media_ctx.passphrase, "sist2");
|
|
||||||
parse_archive(&arc_recurse_media_ctx, &f, &doc);
|
|
||||||
|
|
||||||
arc_recurse_media_ctx.passphrase[0] = '\0';
|
|
||||||
|
|
||||||
ASSERT_NE(size_before, store_size);
|
|
||||||
|
|
||||||
cleanup(&doc, &f);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* RAW */
|
/* RAW */
|
||||||
TEST(RAW, Panasonic) {
|
TEST(RAW, Panasonic) {
|
||||||
vfile_t f;
|
vfile_t f;
|
||||||
@ -803,34 +786,6 @@ TEST(Msdoc, Test4Pdf) {
|
|||||||
cleanup(&doc, &f);
|
cleanup(&doc, &f);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Msdoc, TestUtf8Pdf) {
|
|
||||||
vfile_t f;
|
|
||||||
document_t doc;
|
|
||||||
load_doc_file("libscan-test-files/test_files/msdoc/japanese.doc", &f, &doc);
|
|
||||||
|
|
||||||
size_t size_before = store_size;
|
|
||||||
|
|
||||||
parse_msdoc(&msdoc_ctx, &f, &doc);
|
|
||||||
|
|
||||||
ASSERT_NE(get_meta(&doc, MetaContent), nullptr);
|
|
||||||
ASSERT_TRUE(strstr(get_meta(&doc, MetaContent)->str_val, "调查项目 A questionnaire") != nullptr);
|
|
||||||
ASSERT_NE(size_before, store_size);
|
|
||||||
|
|
||||||
cleanup(&doc, &f);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Msdoc, TestUtf8Text) {
|
|
||||||
vfile_t f;
|
|
||||||
document_t doc;
|
|
||||||
load_doc_file("libscan-test-files/test_files/msdoc/japanese.doc", &f, &doc);
|
|
||||||
|
|
||||||
parse_msdoc(&msdoc_text_ctx, &f, &doc);
|
|
||||||
|
|
||||||
ASSERT_TRUE(strstr(get_meta(&doc, MetaContent)->str_val, "调查项目 A questionnaire") != nullptr);
|
|
||||||
|
|
||||||
cleanup(&doc, &f);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(Msdoc, TestFuzz1) {
|
TEST(Msdoc, TestFuzz1) {
|
||||||
vfile_t f;
|
vfile_t f;
|
||||||
document_t doc;
|
document_t doc;
|
||||||
|
2
third-party/antiword
vendored
2
third-party/antiword
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 62ae66db99e9dd88dfa31999f516f71bb8bdc8b2
|
Subproject commit eb8d737eea2866bfb45e50423a1fd6c51454c2f6
|
2
third-party/utf8.h
vendored
2
third-party/utf8.h
vendored
@ -1 +1 @@
|
|||||||
Subproject commit ee5a7d4beb7755da13e4d4ec3eccfb65a0530456
|
Subproject commit a67acc78fd0fc272ad45362b828efdcb24874e64
|
Loading…
x
Reference in New Issue
Block a user