mirror of
https://github.com/simon987/sist2.git
synced 2025-12-10 22:18:54 +00:00
Fixes and cleanup
This commit is contained in:
8
third-party/libscan/libscan/arc/arc.c
vendored
8
third-party/libscan/libscan/arc/arc.c
vendored
@@ -147,7 +147,7 @@ scan_code_t parse_archive(scan_arc_ctx_t *ctx, vfile_t *f, document_t *doc, pcre
|
||||
}
|
||||
|
||||
if (ret != ARCHIVE_OK) {
|
||||
CTX_LOG_ERRORF(f->filepath, "(arc.c) [%d] %s", ret, archive_error_string(a))
|
||||
CTX_LOG_ERRORF(f->filepath, "(arc.c) [%d] %s", ret, archive_error_string(a));
|
||||
archive_read_free(a);
|
||||
return SCAN_ERR_READ;
|
||||
}
|
||||
@@ -169,7 +169,7 @@ scan_code_t parse_archive(scan_arc_ctx_t *ctx, vfile_t *f, document_t *doc, pcre
|
||||
meta_line_t *meta_list = malloc(sizeof(meta_line_t) + buf.cur);
|
||||
meta_list->key = MetaContent;
|
||||
strcpy(meta_list->str_val, buf.buf);
|
||||
APPEND_META(doc, meta_list)
|
||||
APPEND_META(doc, meta_list);
|
||||
dyn_buffer_destroy(&buf);
|
||||
|
||||
} else {
|
||||
@@ -212,13 +212,13 @@ scan_code_t parse_archive(scan_arc_ctx_t *ctx, vfile_t *f, document_t *doc, pcre
|
||||
double decompressed_size_ratio = (double) sub_job->vfile.st_size / (double) f->st_size;
|
||||
if (decompressed_size_ratio > MAX_DECOMPRESSED_SIZE_RATIO) {
|
||||
CTX_LOG_DEBUGF("arc.c", "Skipped %s, possible zip bomb (decompressed_size_ratio=%f)", sub_job->filepath,
|
||||
decompressed_size_ratio)
|
||||
decompressed_size_ratio);
|
||||
break;
|
||||
}
|
||||
|
||||
// Handle excludes
|
||||
if (exclude != NULL && EXCLUDED(sub_job->filepath)) {
|
||||
CTX_LOG_DEBUGF("arc.c", "Excluded: %s", sub_job->filepath)
|
||||
CTX_LOG_DEBUGF("arc.c", "Excluded: %s", sub_job->filepath);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
4
third-party/libscan/libscan/comic/comic.c
vendored
4
third-party/libscan/libscan/comic/comic.c
vendored
@@ -18,7 +18,7 @@ void parse_comic(scan_comic_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
|
||||
int ret = arc_open(&arc_ctx, f, &a, &arc_data, TRUE);
|
||||
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);
|
||||
return;
|
||||
}
|
||||
@@ -38,7 +38,7 @@ void parse_comic(scan_comic_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
if (read != entry_size) {
|
||||
const char *err_str = archive_error_string(a);
|
||||
if (err_str) {
|
||||
CTX_LOG_ERRORF("comic.c", "Error while reading entry: %s", err_str)
|
||||
CTX_LOG_ERRORF("comic.c", "Error while reading entry: %s", err_str);
|
||||
}
|
||||
free(buf);
|
||||
break;
|
||||
|
||||
38
third-party/libscan/libscan/ebook/ebook.c
vendored
38
third-party/libscan/libscan/ebook/ebook.c
vendored
@@ -54,7 +54,7 @@ load_pixmap(scan_ebook_ctx_t *ctx, int page, fz_context *fzctx, fz_document *fzd
|
||||
fz_catch(fzctx)err = 1;
|
||||
|
||||
if (err != 0) {
|
||||
CTX_LOG_WARNINGF(doc->filepath, "fz_load_page() returned error code [%d] %s", err, fzctx->error.message)
|
||||
CTX_LOG_WARNINGF(doc->filepath, "fz_load_page() returned error code [%d] %s", err, fzctx->error.message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -86,14 +86,14 @@ load_pixmap(scan_ebook_ctx_t *ctx, int page, fz_context *fzctx, fz_document *fzd
|
||||
} fz_catch(fzctx)err = fzctx->error.errcode;
|
||||
|
||||
if (err != 0) {
|
||||
CTX_LOG_WARNINGF(doc->filepath, "fz_run_page() returned error code [%d] %s", err, fzctx->error.message)
|
||||
CTX_LOG_WARNINGF(doc->filepath, "fz_run_page() returned error code [%d] %s", err, fzctx->error.message);
|
||||
fz_drop_page(fzctx, *cover);
|
||||
fz_drop_pixmap(fzctx, pixmap);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pixmap->n != 3) {
|
||||
CTX_LOG_ERRORF(doc->filepath, "Got unexpected pixmap depth: %d", pixmap->n)
|
||||
CTX_LOG_ERRORF(doc->filepath, "Got unexpected pixmap depth: %d", pixmap->n);
|
||||
fz_drop_page(fzctx, *cover);
|
||||
fz_drop_pixmap(fzctx, pixmap);
|
||||
return NULL;
|
||||
@@ -113,7 +113,7 @@ int render_cover(scan_ebook_ctx_t *ctx, fz_context *fzctx, document_t *doc, fz_d
|
||||
if (pixmap_is_blank(pixmap)) {
|
||||
fz_drop_page(fzctx, cover);
|
||||
fz_drop_pixmap(fzctx, pixmap);
|
||||
CTX_LOG_DEBUG(doc->filepath, "Cover page is blank, using page 1 instead")
|
||||
CTX_LOG_DEBUG(doc->filepath, "Cover page is blank, using page 1 instead");
|
||||
pixmap = load_pixmap(ctx, 1, fzctx, fzdoc, doc, &cover);
|
||||
if (pixmap == NULL) {
|
||||
return FALSE;
|
||||
@@ -161,7 +161,7 @@ int render_cover(scan_ebook_ctx_t *ctx, fz_context *fzctx, document_t *doc, fz_d
|
||||
av_init_packet(&jpeg_packet);
|
||||
avcodec_receive_packet(jpeg_encoder, &jpeg_packet);
|
||||
|
||||
APPEND_LONG_META(doc, MetaThumbnail, 1)
|
||||
APPEND_LONG_META(doc, MetaThumbnail, 1);
|
||||
ctx->store(doc->doc_id, 0, (char *) jpeg_packet.data, jpeg_packet.size);
|
||||
|
||||
free(samples);
|
||||
@@ -180,14 +180,14 @@ void fz_err_callback(void *user, const char *message) {
|
||||
document_t *doc = (document_t *) user;
|
||||
|
||||
const scan_ebook_ctx_t *ctx = &thread_ctx;
|
||||
CTX_LOG_WARNINGF(doc->filepath, "FZ: %s", message)
|
||||
CTX_LOG_WARNINGF(doc->filepath, "FZ: %s", message);
|
||||
}
|
||||
|
||||
void fz_warn_callback(void *user, const char *message) {
|
||||
document_t *doc = (document_t *) user;
|
||||
|
||||
const scan_ebook_ctx_t *ctx = &thread_ctx;
|
||||
CTX_LOG_DEBUGF(doc->filepath, "FZ: %s", message)
|
||||
CTX_LOG_DEBUGF(doc->filepath, "FZ: %s", message);
|
||||
}
|
||||
|
||||
static void init_fzctx(fz_context *fzctx, document_t *doc) {
|
||||
@@ -243,7 +243,7 @@ void fill_image(fz_context *fzctx, UNUSED(fz_device *dev),
|
||||
|
||||
if (img->w >= MIN_OCR_WIDTH && img->h >= MIN_OCR_HEIGHT && OCR_IS_VALID_BPP(img->n)) {
|
||||
fz_pixmap *pix = img->get_pixmap(fzctx, img, NULL, img->w, img->h, &l2factor);
|
||||
ocr_extract_text(thread_ctx.tesseract_path, thread_ctx.tesseract_lang, pix->samples, pix->w, pix->h, pix->n, pix->stride, pix->xres, fill_image_ocr_cb);
|
||||
ocr_extract_text(thread_ctx.tesseract_path, thread_ctx.tesseract_lang, pix->samples, pix->w, pix->h, pix->n, (int)pix->stride, pix->xres, fill_image_ocr_cb);
|
||||
fz_drop_pixmap(fzctx, pix);
|
||||
}
|
||||
}
|
||||
@@ -282,14 +282,14 @@ parse_ebook_mem(scan_ebook_ctx_t *ctx, void *buf, size_t buf_len, const char *mi
|
||||
fz_catch(fzctx)err = fzctx->error.errcode;
|
||||
|
||||
if (err) {
|
||||
CTX_LOG_WARNINGF(doc->filepath, "fz_count_pages() returned error code [%d] %s", err, fzctx->error.message)
|
||||
CTX_LOG_WARNINGF(doc->filepath, "fz_count_pages() returned error code [%d] %s", err, fzctx->error.message);
|
||||
fz_drop_stream(fzctx, stream);
|
||||
fz_drop_document(fzctx, fzdoc);
|
||||
fz_drop_context(fzctx);
|
||||
return;
|
||||
}
|
||||
|
||||
APPEND_LONG_META(doc, MetaPages, page_count)
|
||||
APPEND_LONG_META(doc, MetaPages, page_count);
|
||||
|
||||
if (ctx->enable_tn) {
|
||||
if (render_cover(ctx, fzctx, doc, fzdoc) == FALSE) {
|
||||
@@ -312,7 +312,7 @@ parse_ebook_mem(scan_ebook_ctx_t *ctx, void *buf, size_t buf_len, const char *mi
|
||||
fz_catch(fzctx);
|
||||
|
||||
if (strlen(title) > 0) {
|
||||
APPEND_UTF8_META(doc, MetaTitle, title)
|
||||
APPEND_UTF8_META(doc, MetaTitle, title);
|
||||
}
|
||||
|
||||
char author[4096] = {'\0',};
|
||||
@@ -320,7 +320,7 @@ parse_ebook_mem(scan_ebook_ctx_t *ctx, void *buf, size_t buf_len, const char *mi
|
||||
fz_catch(fzctx);
|
||||
|
||||
if (strlen(author) > 0) {
|
||||
APPEND_UTF8_META(doc, MetaAuthor, author)
|
||||
APPEND_UTF8_META(doc, MetaAuthor, author);
|
||||
}
|
||||
|
||||
|
||||
@@ -334,7 +334,7 @@ parse_ebook_mem(scan_ebook_ctx_t *ctx, void *buf, size_t buf_len, const char *mi
|
||||
fz_try(fzctx)page = fz_load_page(fzctx, fzdoc, current_page);
|
||||
fz_catch(fzctx)err = fzctx->error.errcode;
|
||||
if (err != 0) {
|
||||
CTX_LOG_WARNINGF(doc->filepath, "fz_load_page() returned error code [%d] %s", err, fzctx->error.message)
|
||||
CTX_LOG_WARNINGF(doc->filepath, "fz_load_page() returned error code [%d] %s", err, fzctx->error.message);
|
||||
text_buffer_destroy(&thread_buffer);
|
||||
fz_drop_page(fzctx, page);
|
||||
fz_drop_stream(fzctx, stream);
|
||||
@@ -363,7 +363,7 @@ parse_ebook_mem(scan_ebook_ctx_t *ctx, void *buf, size_t buf_len, const char *mi
|
||||
} fz_catch(fzctx)err = fzctx->error.errcode;
|
||||
|
||||
if (err != 0) {
|
||||
CTX_LOG_WARNINGF(doc->filepath, "fz_run_page() returned error code [%d] %s", err, fzctx->error.message)
|
||||
CTX_LOG_WARNINGF(doc->filepath, "fz_run_page() returned error code [%d] %s", err, fzctx->error.message);
|
||||
text_buffer_destroy(&thread_buffer);
|
||||
fz_drop_page(fzctx, page);
|
||||
fz_drop_stext_page(fzctx, stext);
|
||||
@@ -393,7 +393,7 @@ parse_ebook_mem(scan_ebook_ctx_t *ctx, void *buf, size_t buf_len, const char *mi
|
||||
meta_line_t *meta_content = malloc(sizeof(meta_line_t) + thread_buffer.dyn_buffer.cur);
|
||||
meta_content->key = MetaContent;
|
||||
memcpy(meta_content->str_val, thread_buffer.dyn_buffer.buf, thread_buffer.dyn_buffer.cur);
|
||||
APPEND_META(doc, meta_content)
|
||||
APPEND_META(doc, meta_content);
|
||||
|
||||
text_buffer_destroy(&thread_buffer);
|
||||
}
|
||||
@@ -418,7 +418,7 @@ void parse_epub_fast(scan_ebook_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
|
||||
int ret = arc_open(&arc_ctx, f, &a, &arc_data, TRUE);
|
||||
if (ret != ARCHIVE_OK) {
|
||||
CTX_LOG_ERRORF(f->filepath, "(ebook.c) [%d] %s", ret, archive_error_string(a))
|
||||
CTX_LOG_ERRORF(f->filepath, "(ebook.c) [%d] %s", ret, archive_error_string(a));
|
||||
archive_read_free(a);
|
||||
return;
|
||||
}
|
||||
@@ -439,7 +439,7 @@ void parse_epub_fast(scan_ebook_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
if (read != entry_size) {
|
||||
const char *err_str = archive_error_string(a);
|
||||
if (err_str) {
|
||||
CTX_LOG_ERRORF("ebook.c", "Error while reading entry: %s", err_str)
|
||||
CTX_LOG_ERRORF("ebook.c", "Error while reading entry: %s", err_str);
|
||||
}
|
||||
free(buf);
|
||||
break;
|
||||
@@ -460,7 +460,7 @@ void parse_epub_fast(scan_ebook_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
meta_line_t *meta_content = malloc(sizeof(meta_line_t) + content_buffer.dyn_buffer.cur);
|
||||
meta_content->key = MetaContent;
|
||||
memcpy(meta_content->str_val, content_buffer.dyn_buffer.buf, content_buffer.dyn_buffer.cur);
|
||||
APPEND_META(doc, meta_content)
|
||||
APPEND_META(doc, meta_content);
|
||||
|
||||
text_buffer_destroy(&content_buffer);
|
||||
|
||||
@@ -477,7 +477,7 @@ void parse_ebook(scan_ebook_ctx_t *ctx, vfile_t *f, const char *mime_str, docume
|
||||
size_t buf_len;
|
||||
void *buf = read_all(f, &buf_len);
|
||||
if (buf == NULL) {
|
||||
CTX_LOG_ERROR(f->filepath, "read_all() failed")
|
||||
CTX_LOG_ERROR(f->filepath, "read_all() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
12
third-party/libscan/libscan/font/font.c
vendored
12
third-party/libscan/libscan/font/font.c
vendored
@@ -146,7 +146,7 @@ void parse_font(scan_font_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
size_t buf_len = 0;
|
||||
void *buf = read_all(f, &buf_len);
|
||||
if (buf == NULL) {
|
||||
CTX_LOG_ERROR(f->filepath, "read_all() failed")
|
||||
CTX_LOG_ERROR(f->filepath, "read_all() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ void parse_font(scan_font_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
FT_Error err = FT_New_Memory_Face(ft_lib, (unsigned char *) buf, (int) buf_len, 0, &face);
|
||||
if (err != 0) {
|
||||
CTX_LOG_ERRORF(doc->filepath, "(font.c) FT_New_Memory_Face() returned error code [%d] %s", err,
|
||||
FT_Error_String(err))
|
||||
FT_Error_String(err));
|
||||
free(buf);
|
||||
return;
|
||||
}
|
||||
@@ -174,7 +174,7 @@ void parse_font(scan_font_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
meta_line_t *meta_name = malloc(sizeof(meta_line_t) + strlen(font_name));
|
||||
meta_name->key = MetaFontName;
|
||||
strcpy(meta_name->str_val, font_name);
|
||||
APPEND_META(doc, meta_name)
|
||||
APPEND_META(doc, meta_name);
|
||||
|
||||
if (!ctx->enable_tn) {
|
||||
FT_Done_Face(face);
|
||||
@@ -188,7 +188,7 @@ void parse_font(scan_font_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
err = FT_Set_Pixel_Sizes(face, 0, pixel);
|
||||
if (err != 0) {
|
||||
CTX_LOG_WARNINGF(doc->filepath, "(font.c) FT_Set_Pixel_Sizes() returned error code [%d] %s", err,
|
||||
FT_Error_String(err))
|
||||
FT_Error_String(err));
|
||||
FT_Done_Face(face);
|
||||
free(buf);
|
||||
return;
|
||||
@@ -210,7 +210,7 @@ void parse_font(scan_font_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
err = FT_Load_Char(face, c, FT_LOAD_NO_HINTING | FT_LOAD_RENDER);
|
||||
if (err != 0) {
|
||||
CTX_LOG_WARNINGF(doc->filepath, "(font.c) FT_Load_Char() returned error code [%d] %s", err,
|
||||
FT_Error_String(err))
|
||||
FT_Error_String(err));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -231,7 +231,7 @@ void parse_font(scan_font_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
dyn_buffer_t bmp_data = dyn_buffer_create();
|
||||
bmp_format(&bmp_data, dimensions, bitmap);
|
||||
|
||||
APPEND_LONG_META(doc, MetaThumbnail, 1)
|
||||
APPEND_LONG_META(doc, MetaThumbnail, 1);
|
||||
ctx->store(doc->doc_id, 0, bmp_data.buf, bmp_data.cur);
|
||||
|
||||
dyn_buffer_destroy(&bmp_data);
|
||||
|
||||
2
third-party/libscan/libscan/json/json.c
vendored
2
third-party/libscan/libscan/json/json.c
vendored
@@ -33,7 +33,7 @@ int json_extract_text(cJSON *json, text_buffer_t *tex) {
|
||||
scan_code_t parse_json(scan_json_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
|
||||
if (f->st_size > JSON_MAX_FILE_SIZE) {
|
||||
CTX_LOG_WARNINGF("json.c", "File larger than maximum allowed [%s]", f->filepath)
|
||||
CTX_LOG_WARNINGF("json.c", "File larger than maximum allowed [%s]", f->filepath);
|
||||
return SCAN_ERR_SKIP;
|
||||
}
|
||||
|
||||
|
||||
16
third-party/libscan/libscan/macros.h
vendored
16
third-party/libscan/libscan/macros.h
vendored
@@ -25,20 +25,20 @@
|
||||
#define SHA1_STR_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
|
||||
#define MD5_STR_LENGTH (MD5_DIGEST_LENGTH * 2 + 1)
|
||||
|
||||
#define APPEND_STR_META(doc, keyname, value) \
|
||||
#define APPEND_STR_META(doc, keyname, value) do {\
|
||||
{meta_line_t *meta_str = malloc(sizeof(meta_line_t) + strlen(value)); \
|
||||
meta_str->key = keyname; \
|
||||
strcpy(meta_str->str_val, value); \
|
||||
APPEND_META(doc, meta_str)}
|
||||
APPEND_META(doc, meta_str);}} while(0)
|
||||
|
||||
#define APPEND_LONG_META(doc, keyname, value) \
|
||||
#define APPEND_LONG_META(doc, keyname, value) do{\
|
||||
{meta_line_t *meta_long = malloc(sizeof(meta_line_t)); \
|
||||
meta_long->key = keyname; \
|
||||
meta_long->long_val = value; \
|
||||
APPEND_META(doc, meta_long)}
|
||||
APPEND_META(doc, meta_long);}} while(0)
|
||||
|
||||
|
||||
#define APPEND_META(doc, meta) \
|
||||
#define APPEND_META(doc, meta) do {\
|
||||
meta->next = NULL;\
|
||||
if (doc->meta_head == NULL) {\
|
||||
doc->meta_head = meta;\
|
||||
@@ -46,7 +46,7 @@
|
||||
} else {\
|
||||
doc->meta_tail->next = meta;\
|
||||
doc->meta_tail = meta;\
|
||||
}
|
||||
}}while(0)
|
||||
|
||||
#define APPEND_UTF8_META(doc, keyname, str) \
|
||||
text_buffer_t tex = text_buffer_create(-1); \
|
||||
@@ -55,5 +55,5 @@
|
||||
meta_line_t *meta_tag = malloc(sizeof(meta_line_t) + tex.dyn_buffer.cur); \
|
||||
meta_tag->key = keyname; \
|
||||
strcpy(meta_tag->str_val, tex.dyn_buffer.buf); \
|
||||
APPEND_META(doc, meta_tag) \
|
||||
text_buffer_destroy(&tex);
|
||||
APPEND_META(doc, meta_tag); \
|
||||
text_buffer_destroy(&tex)
|
||||
|
||||
92
third-party/libscan/libscan/media/media.c
vendored
92
third-party/libscan/libscan/media/media.c
vendored
@@ -163,7 +163,7 @@ static void read_subtitles(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx, i
|
||||
|
||||
text_buffer_terminate_string(&tex);
|
||||
|
||||
APPEND_STR_META(doc, MetaContent, tex.dyn_buffer.buf)
|
||||
APPEND_STR_META(doc, MetaContent, tex.dyn_buffer.buf);
|
||||
text_buffer_destroy(&tex);
|
||||
avcodec_free_context(&decoder);
|
||||
}
|
||||
@@ -190,7 +190,7 @@ read_frame(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx, AVCodecContext *d
|
||||
CTX_LOG_WARNINGF(doc->filepath,
|
||||
"(media.c) avcodec_read_frame() returned error code [%d] %s",
|
||||
read_frame_ret, av_err2str(read_frame_ret)
|
||||
)
|
||||
);
|
||||
}
|
||||
frame_and_packet_free(result);
|
||||
return NULL;
|
||||
@@ -210,7 +210,7 @@ read_frame(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx, AVCodecContext *d
|
||||
CTX_LOG_ERRORF(doc->filepath,
|
||||
"(media.c) avcodec_send_packet() returned error code [%d] %s",
|
||||
decode_ret, av_err2str(decode_ret)
|
||||
)
|
||||
);
|
||||
frame_and_packet_free(result);
|
||||
return NULL;
|
||||
}
|
||||
@@ -230,7 +230,7 @@ void append_tag_meta_if_not_exists(scan_media_ctx_t *ctx, document_t *doc, AVDic
|
||||
while (meta != NULL) {
|
||||
if (meta->key == key) {
|
||||
CTX_LOG_DEBUGF(doc->filepath, "Ignoring duplicate tag: '%02x=%s' and '%02x=%s'",
|
||||
key, meta->str_val, key, tag->value)
|
||||
key, meta->str_val, key, tag->value);
|
||||
return;
|
||||
}
|
||||
meta = meta->next;
|
||||
@@ -243,7 +243,7 @@ void append_tag_meta_if_not_exists(scan_media_ctx_t *ctx, document_t *doc, AVDic
|
||||
meta_tag->key = key;
|
||||
strcpy(meta_tag->str_val, tex.dyn_buffer.buf);
|
||||
|
||||
APPEND_META(doc, meta_tag)
|
||||
APPEND_META(doc, meta_tag);
|
||||
text_buffer_destroy(&tex);
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ void append_tag_meta_if_not_exists(scan_media_ctx_t *ctx, document_t *doc, AVDic
|
||||
#define STRCPY_TOLOWER(dst, str) \
|
||||
strncpy(dst, str, sizeof(dst)); \
|
||||
char *ptr = dst; \
|
||||
for (; *ptr; ++ptr) *ptr = (char) tolower(*ptr);
|
||||
for (; *ptr; ++ptr) *ptr = (char) tolower(*ptr)
|
||||
|
||||
__always_inline
|
||||
static void append_audio_meta(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx, document_t *doc) {
|
||||
@@ -261,18 +261,18 @@ static void append_audio_meta(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx
|
||||
AVDictionaryEntry *tag = NULL;
|
||||
while ((tag = av_dict_get(pFormatCtx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
|
||||
char key[256];
|
||||
STRCPY_TOLOWER(key, tag->key)
|
||||
STRCPY_TOLOWER(key, tag->key);
|
||||
|
||||
if (strcmp(key, "artist") == 0) {
|
||||
APPEND_TAG_META(MetaArtist)
|
||||
APPEND_TAG_META(MetaArtist);
|
||||
} else if (strcmp(key, "genre") == 0) {
|
||||
APPEND_TAG_META(MetaGenre)
|
||||
APPEND_TAG_META(MetaGenre);
|
||||
} else if (strcmp(key, "title") == 0) {
|
||||
APPEND_TAG_META(MetaTitle)
|
||||
APPEND_TAG_META(MetaTitle);
|
||||
} else if (strcmp(key, "album_artist") == 0) {
|
||||
APPEND_TAG_META(MetaAlbumArtist)
|
||||
APPEND_TAG_META(MetaAlbumArtist);
|
||||
} else if (strcmp(key, "album") == 0) {
|
||||
APPEND_TAG_META(MetaAlbum)
|
||||
APPEND_TAG_META(MetaAlbum);
|
||||
} else if (strcmp(key, "comment") == 0) {
|
||||
append_tag_meta_if_not_exists(ctx, doc, tag, MetaContent);
|
||||
}
|
||||
@@ -291,14 +291,14 @@ append_video_meta(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx, AVFrame *f
|
||||
if (meta_duration->long_val > INT32_MAX) {
|
||||
meta_duration->long_val = 0;
|
||||
}
|
||||
APPEND_META(doc, meta_duration)
|
||||
APPEND_META(doc, meta_duration);
|
||||
}
|
||||
|
||||
if (pFormatCtx->bit_rate != 0) {
|
||||
meta_line_t *meta_bitrate = malloc(sizeof(meta_line_t));
|
||||
meta_bitrate->key = MetaMediaBitrate;
|
||||
meta_bitrate->long_val = pFormatCtx->bit_rate;
|
||||
APPEND_META(doc, meta_bitrate)
|
||||
APPEND_META(doc, meta_bitrate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ append_video_meta(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx, AVFrame *f
|
||||
if (is_video) {
|
||||
while ((tag = av_dict_get(pFormatCtx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
|
||||
char key[256];
|
||||
STRCPY_TOLOWER(key, tag->key)
|
||||
STRCPY_TOLOWER(key, tag->key);
|
||||
|
||||
if (strcmp(key, "title") == 0) {
|
||||
append_tag_meta_if_not_exists(ctx, doc, tag, MetaTitle);
|
||||
@@ -320,38 +320,38 @@ append_video_meta(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx, AVFrame *f
|
||||
// EXIF metadata
|
||||
while ((tag = av_dict_get(frame->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
|
||||
char key[256];
|
||||
STRCPY_TOLOWER(key, tag->key)
|
||||
STRCPY_TOLOWER(key, tag->key);
|
||||
|
||||
if (strcmp(key, "artist") == 0) {
|
||||
append_tag_meta_if_not_exists(ctx, doc, tag, MetaArtist);
|
||||
} else if (strcmp(key, "imagedescription") == 0) {
|
||||
append_tag_meta_if_not_exists(ctx, doc, tag, MetaContent);
|
||||
} else if (strcmp(key, "make") == 0) {
|
||||
APPEND_TAG_META(MetaExifMake)
|
||||
APPEND_TAG_META(MetaExifMake);
|
||||
} else if (strcmp(key, "model") == 0) {
|
||||
APPEND_TAG_META(MetaExifModel)
|
||||
APPEND_TAG_META(MetaExifModel);
|
||||
} else if (strcmp(key, "software") == 0) {
|
||||
APPEND_TAG_META(MetaExifSoftware)
|
||||
APPEND_TAG_META(MetaExifSoftware);
|
||||
} else if (strcmp(key, "fnumber") == 0) {
|
||||
APPEND_TAG_META(MetaExifFNumber)
|
||||
APPEND_TAG_META(MetaExifFNumber);
|
||||
} else if (strcmp(key, "focallength") == 0) {
|
||||
APPEND_TAG_META(MetaExifFocalLength)
|
||||
APPEND_TAG_META(MetaExifFocalLength);
|
||||
} else if (strcmp(key, "usercomment") == 0) {
|
||||
APPEND_TAG_META(MetaExifUserComment)
|
||||
APPEND_TAG_META(MetaExifUserComment);
|
||||
} else if (strcmp(key, "isospeedratings") == 0) {
|
||||
APPEND_TAG_META(MetaExifIsoSpeedRatings)
|
||||
APPEND_TAG_META(MetaExifIsoSpeedRatings);
|
||||
} else if (strcmp(key, "exposuretime") == 0) {
|
||||
APPEND_TAG_META(MetaExifExposureTime)
|
||||
APPEND_TAG_META(MetaExifExposureTime);
|
||||
} else if (strcmp(key, "datetime") == 0) {
|
||||
APPEND_TAG_META(MetaExifDateTime)
|
||||
APPEND_TAG_META(MetaExifDateTime);
|
||||
} else if (strcmp(key, "gpslatitude") == 0) {
|
||||
APPEND_TAG_META(MetaExifGpsLatitudeDMS)
|
||||
APPEND_TAG_META(MetaExifGpsLatitudeDMS);
|
||||
} else if (strcmp(key, "gpslatituderef") == 0) {
|
||||
APPEND_TAG_META(MetaExifGpsLatitudeRef)
|
||||
APPEND_TAG_META(MetaExifGpsLatitudeRef);
|
||||
} else if (strcmp(key, "gpslongitude") == 0) {
|
||||
APPEND_TAG_META(MetaExifGpsLongitudeDMS)
|
||||
APPEND_TAG_META(MetaExifGpsLongitudeDMS);
|
||||
} else if (strcmp(key, "gpslongituderef") == 0) {
|
||||
APPEND_TAG_META(MetaExifGpsLongitudeRef)
|
||||
APPEND_TAG_META(MetaExifGpsLongitudeRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -432,11 +432,11 @@ int decode_frame_and_save_thumbnail(scan_media_ctx_t *ctx, AVFormatContext *pFor
|
||||
CTX_LOG_DEBUGF(
|
||||
doc->filepath,
|
||||
"(media.c) Could not seek media file: %s", av_err2str(seek_ret)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (seek_ok == FALSE && thumbnail_index != 0) {
|
||||
CTX_LOG_WARNING(doc->filepath, "(media.c) Could not seek media file. Can't generate additional thumbnails.")
|
||||
CTX_LOG_WARNING(doc->filepath, "(media.c) Could not seek media file. Can't generate additional thumbnails.");
|
||||
return SAVE_THUMBNAIL_FAILED;
|
||||
}
|
||||
}
|
||||
@@ -522,7 +522,7 @@ void parse_media_format_ctx(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx,
|
||||
const AVCodecDescriptor *desc = avcodec_descriptor_get(stream->codecpar->codec_id);
|
||||
|
||||
if (desc != NULL) {
|
||||
APPEND_STR_META(doc, MetaMediaAudioCodec, desc->name)
|
||||
APPEND_STR_META(doc, MetaMediaAudioCodec, desc->name);
|
||||
}
|
||||
|
||||
audio_stream = i;
|
||||
@@ -533,18 +533,18 @@ void parse_media_format_ctx(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx,
|
||||
const AVCodecDescriptor *desc = avcodec_descriptor_get(stream->codecpar->codec_id);
|
||||
|
||||
if (desc != NULL) {
|
||||
APPEND_STR_META(doc, MetaMediaVideoCodec, desc->name)
|
||||
APPEND_STR_META(doc, MetaMediaVideoCodec, desc->name);
|
||||
}
|
||||
|
||||
meta_line_t *meta_w = malloc(sizeof(meta_line_t));
|
||||
meta_w->key = MetaWidth;
|
||||
meta_w->long_val = stream->codecpar->width;
|
||||
APPEND_META(doc, meta_w)
|
||||
APPEND_META(doc, meta_w);
|
||||
|
||||
meta_line_t *meta_h = malloc(sizeof(meta_line_t));
|
||||
meta_h->key = MetaHeight;
|
||||
meta_h->long_val = stream->codecpar->height;
|
||||
APPEND_META(doc, meta_h)
|
||||
APPEND_META(doc, meta_h);
|
||||
|
||||
video_stream = i;
|
||||
}
|
||||
@@ -611,7 +611,7 @@ void parse_media_format_ctx(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx,
|
||||
}
|
||||
|
||||
if (number_of_thumbnails_generated > 0) {
|
||||
APPEND_LONG_META(doc, MetaThumbnail, number_of_thumbnails_generated)
|
||||
APPEND_LONG_META(doc, MetaThumbnail, number_of_thumbnails_generated);
|
||||
}
|
||||
|
||||
avcodec_free_context(&decoder);
|
||||
@@ -625,12 +625,12 @@ void parse_media_filename(scan_media_ctx_t *ctx, const char *filepath, document_
|
||||
|
||||
AVFormatContext *pFormatCtx = avformat_alloc_context();
|
||||
if (pFormatCtx == NULL) {
|
||||
CTX_LOG_ERROR(doc->filepath, "(media.c) Could not allocate context with avformat_alloc_context()")
|
||||
CTX_LOG_ERROR(doc->filepath, "(media.c) Could not allocate context with avformat_alloc_context()");
|
||||
return;
|
||||
}
|
||||
int res = avformat_open_input(&pFormatCtx, filepath, NULL, NULL);
|
||||
if (res < 0) {
|
||||
CTX_LOG_ERRORF(doc->filepath, "(media.c) avformat_open_input() returned [%d] %s", res, av_err2str(res))
|
||||
CTX_LOG_ERRORF(doc->filepath, "(media.c) avformat_open_input() returned [%d] %s", res, av_err2str(res));
|
||||
avformat_close_input(&pFormatCtx);
|
||||
avformat_free_context(pFormatCtx);
|
||||
return;
|
||||
@@ -724,7 +724,7 @@ void parse_media_vfile(scan_media_ctx_t *ctx, struct vfile *f, document_t *doc,
|
||||
|
||||
AVFormatContext *pFormatCtx = avformat_alloc_context();
|
||||
if (pFormatCtx == NULL) {
|
||||
CTX_LOG_ERROR(doc->filepath, "(media.c) Could not allocate context with avformat_alloc_context()")
|
||||
CTX_LOG_ERROR(doc->filepath, "(media.c) Could not allocate context with avformat_alloc_context()");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -737,13 +737,13 @@ void parse_media_vfile(scan_media_ctx_t *ctx, struct vfile *f, document_t *doc,
|
||||
if (f->st_size <= ctx->max_media_buffer) {
|
||||
int ret = memfile_open(f, &memfile);
|
||||
if (ret == 0) {
|
||||
CTX_LOG_DEBUGF(f->filepath, "Loading media file in memory (%ldB)", f->st_size)
|
||||
CTX_LOG_DEBUGF(f->filepath, "Loading media file in memory (%ldB)", f->st_size);
|
||||
io_ctx = avio_alloc_context(buffer, AVIO_BUF_SIZE, 0, &memfile, memfile_read, NULL, memfile_seek);
|
||||
}
|
||||
}
|
||||
|
||||
if (io_ctx == NULL) {
|
||||
CTX_LOG_DEBUGF(f->filepath, "Reading media file without seek support", f->st_size)
|
||||
CTX_LOG_DEBUGF(f->filepath, "Reading media file without seek support", f->st_size);
|
||||
io_ctx = avio_alloc_context(buffer, AVIO_BUF_SIZE, 0, f, vfile_read, NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -752,7 +752,7 @@ void parse_media_vfile(scan_media_ctx_t *ctx, struct vfile *f, document_t *doc,
|
||||
int res = avformat_open_input(&pFormatCtx, filepath, NULL, NULL);
|
||||
if (res < 0) {
|
||||
if (res != -5) {
|
||||
CTX_LOG_ERRORF(doc->filepath, "(media.c) avformat_open_input() returned [%d] %s", res, av_err2str(res))
|
||||
CTX_LOG_ERRORF(doc->filepath, "(media.c) avformat_open_input() returned [%d] %s", res, av_err2str(res));
|
||||
}
|
||||
av_free(io_ctx->buffer);
|
||||
memfile_close(&memfile);
|
||||
@@ -787,7 +787,7 @@ int store_image_thumbnail(scan_media_ctx_t *ctx, void *buf, size_t buf_len, docu
|
||||
|
||||
AVFormatContext *pFormatCtx = avformat_alloc_context();
|
||||
if (pFormatCtx == NULL) {
|
||||
CTX_LOG_ERROR(doc->filepath, "(media.c) Could not allocate context with avformat_alloc_context()")
|
||||
CTX_LOG_ERROR(doc->filepath, "(media.c) Could not allocate context with avformat_alloc_context()");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -795,7 +795,7 @@ int store_image_thumbnail(scan_media_ctx_t *ctx, void *buf, size_t buf_len, docu
|
||||
|
||||
int ret = memfile_open_buf(buf, buf_len, &memfile);
|
||||
if (ret == 0) {
|
||||
CTX_LOG_DEBUGF(doc->filepath, "Loading media file in memory (%ldB)", buf_len)
|
||||
CTX_LOG_DEBUGF(doc->filepath, "Loading media file in memory (%ldB)", buf_len);
|
||||
io_ctx = avio_alloc_context(buffer, AVIO_BUF_SIZE, 0, &memfile, memfile_read, NULL, memfile_seek);
|
||||
} else {
|
||||
avformat_close_input(&pFormatCtx);
|
||||
@@ -850,7 +850,7 @@ int store_image_thumbnail(scan_media_ctx_t *ctx, void *buf, size_t buf_len, docu
|
||||
}
|
||||
|
||||
if (scaled_frame == STORE_AS_IS) {
|
||||
APPEND_LONG_META(doc, MetaThumbnail, 1)
|
||||
APPEND_LONG_META(doc, MetaThumbnail, 1);
|
||||
ctx->store(doc->doc_id, 0, frame_and_packet->packet->data, frame_and_packet->packet->size);
|
||||
} else {
|
||||
// Encode frame to jpeg
|
||||
@@ -863,7 +863,7 @@ int store_image_thumbnail(scan_media_ctx_t *ctx, void *buf, size_t buf_len, docu
|
||||
avcodec_receive_packet(jpeg_encoder, &jpeg_packet);
|
||||
|
||||
// Save thumbnail
|
||||
APPEND_LONG_META(doc, MetaThumbnail, 1)
|
||||
APPEND_LONG_META(doc, MetaThumbnail, 1);
|
||||
ctx->store(doc->doc_id, 0, jpeg_packet.data, jpeg_packet.size);
|
||||
|
||||
av_packet_unref(&jpeg_packet);
|
||||
|
||||
18
third-party/libscan/libscan/mobi/scan_mobi.c
vendored
18
third-party/libscan/libscan/mobi/scan_mobi.c
vendored
@@ -8,7 +8,7 @@ void parse_mobi(scan_mobi_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
|
||||
MOBIData *m = mobi_init();
|
||||
if (m == NULL) {
|
||||
CTX_LOG_ERROR(f->filepath, "mobi_init() failed")
|
||||
CTX_LOG_ERROR(f->filepath, "mobi_init() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ void parse_mobi(scan_mobi_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
char* buf = read_all(f, &buf_len);
|
||||
if (buf == NULL) {
|
||||
mobi_free(m);
|
||||
CTX_LOG_ERROR(f->filepath, "read_all() failed")
|
||||
CTX_LOG_ERROR(f->filepath, "read_all() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ void parse_mobi(scan_mobi_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
if (file == NULL) {
|
||||
mobi_free(m);
|
||||
free(buf);
|
||||
CTX_LOG_ERRORF(f->filepath, "fmemopen() failed (%d)", errno)
|
||||
CTX_LOG_ERRORF(f->filepath, "fmemopen() failed (%d)", errno);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,25 +33,25 @@ void parse_mobi(scan_mobi_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
if (mobi_ret != MOBI_SUCCESS) {
|
||||
mobi_free(m);
|
||||
free(buf);
|
||||
CTX_LOG_ERRORF(f->filepath, "mobi_laod_file() returned error code [%d]", mobi_ret)
|
||||
CTX_LOG_ERRORF(f->filepath, "mobi_laod_file() returned error code [%d]", mobi_ret);
|
||||
return;
|
||||
}
|
||||
|
||||
char *author = mobi_meta_get_author(m);
|
||||
if (author != NULL) {
|
||||
APPEND_STR_META(doc, MetaAuthor, author)
|
||||
APPEND_STR_META(doc, MetaAuthor, author);
|
||||
free(author);
|
||||
}
|
||||
char *title = mobi_meta_get_title(m);
|
||||
if (title != NULL) {
|
||||
APPEND_STR_META(doc, MetaTitle, title)
|
||||
APPEND_STR_META(doc, MetaTitle, title);
|
||||
free(title);
|
||||
}
|
||||
|
||||
const size_t maxlen = mobi_get_text_maxsize(m);
|
||||
if (maxlen == MOBI_NOTSET) {
|
||||
free(buf);
|
||||
CTX_LOG_DEBUGF("%s", "Invalid text maxsize: %zu", maxlen)
|
||||
CTX_LOG_DEBUGF("%s", "Invalid text maxsize: %zu", maxlen);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ void parse_mobi(scan_mobi_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
mobi_free(m);
|
||||
free(content_str);
|
||||
free(buf);
|
||||
CTX_LOG_ERRORF(f->filepath, "mobi_get_rawml() returned error code [%d]", mobi_ret)
|
||||
CTX_LOG_ERRORF(f->filepath, "mobi_get_rawml() returned error code [%d]", mobi_ret);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ void parse_mobi(scan_mobi_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
text_buffer_append_markup(&tex, content_str);
|
||||
text_buffer_terminate_string(&tex);
|
||||
|
||||
APPEND_STR_META(doc, MetaContent, tex.dyn_buffer.buf)
|
||||
APPEND_STR_META(doc, MetaContent, tex.dyn_buffer.buf);
|
||||
|
||||
free(content_str);
|
||||
free(buf);
|
||||
|
||||
10
third-party/libscan/libscan/msdoc/msdoc.c
vendored
10
third-party/libscan/libscan/msdoc/msdoc.c
vendored
@@ -39,12 +39,12 @@ void parse_msdoc_text(scan_msdoc_ctx_t *ctx, document_t *doc, FILE *file_in, voi
|
||||
iInitDocument(file_in, (int) buf_len);
|
||||
const char *author = szGetAuthor();
|
||||
if (author != NULL) {
|
||||
APPEND_UTF8_META(doc, MetaAuthor, author)
|
||||
APPEND_UTF8_META(doc, MetaAuthor, author);
|
||||
}
|
||||
|
||||
const char *title = szGetTitle();
|
||||
if (title != NULL) {
|
||||
APPEND_UTF8_META(doc, MetaTitle, title)
|
||||
APPEND_UTF8_META(doc, MetaTitle, title);
|
||||
}
|
||||
vFreeDocument();
|
||||
|
||||
@@ -60,7 +60,7 @@ void parse_msdoc_text(scan_msdoc_ctx_t *ctx, document_t *doc, FILE *file_in, voi
|
||||
meta_line_t *meta_content = malloc(sizeof(meta_line_t) + tex.dyn_buffer.cur);
|
||||
meta_content->key = MetaContent;
|
||||
memcpy(meta_content->str_val, tex.dyn_buffer.buf, tex.dyn_buffer.cur);
|
||||
APPEND_META(doc, meta_content)
|
||||
APPEND_META(doc, meta_content);
|
||||
|
||||
text_buffer_destroy(&tex);
|
||||
}
|
||||
@@ -74,14 +74,14 @@ void parse_msdoc(scan_msdoc_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
size_t buf_len;
|
||||
char *buf = read_all(f, &buf_len);
|
||||
if (buf == NULL) {
|
||||
CTX_LOG_ERROR(f->filepath, "read_all() failed")
|
||||
CTX_LOG_ERROR(f->filepath, "read_all() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
FILE *file = fmemopen(buf, buf_len, "rb");
|
||||
if (file == NULL) {
|
||||
free(buf);
|
||||
CTX_LOG_ERRORF(f->filepath, "fmemopen() failed (%d)", errno)
|
||||
CTX_LOG_ERRORF(f->filepath, "fmemopen() failed (%d)", errno);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
30
third-party/libscan/libscan/ooxml/ooxml.c
vendored
30
third-party/libscan/libscan/ooxml/ooxml.c
vendored
@@ -39,7 +39,7 @@ int extract_text(scan_ooxml_ctx_t *ctx, xmlDoc *xml, xmlNode *node, text_buffer_
|
||||
xmlErrorPtr err = xmlGetLastError();
|
||||
if (err != NULL) {
|
||||
if (err->level == XML_ERR_FATAL) {
|
||||
CTX_LOG_ERRORF("ooxml.c", "Got fatal XML error while parsing document: %s", err->message)
|
||||
CTX_LOG_ERRORF("ooxml.c", "Got fatal XML error while parsing document: %s", err->message);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -85,13 +85,13 @@ static int read_part(scan_ooxml_ctx_t *ctx, struct archive *a, text_buffer_t *bu
|
||||
XML_PARSE_RECOVER | XML_PARSE_NOWARNING | XML_PARSE_NOERROR | XML_PARSE_NONET);
|
||||
|
||||
if (xml == NULL) {
|
||||
CTX_LOG_ERROR(doc->filepath, "Could not parse XML")
|
||||
CTX_LOG_ERROR(doc->filepath, "Could not parse XML");
|
||||
return READ_PART_ERR;
|
||||
}
|
||||
|
||||
xmlNode *root = xmlDocGetRootElement(xml);
|
||||
if (root == NULL) {
|
||||
CTX_LOG_ERROR(doc->filepath, "Empty document")
|
||||
CTX_LOG_ERROR(doc->filepath, "Empty document");
|
||||
xmlFreeDoc(xml);
|
||||
return READ_PART_ERR;
|
||||
}
|
||||
@@ -108,13 +108,13 @@ static int read_doc_props_app(scan_ooxml_ctx_t *ctx, struct archive *a, document
|
||||
XML_PARSE_RECOVER | XML_PARSE_NOWARNING | XML_PARSE_NOERROR | XML_PARSE_NONET);
|
||||
|
||||
if (xml == NULL) {
|
||||
CTX_LOG_ERROR(doc->filepath, "Could not parse XML")
|
||||
CTX_LOG_ERROR(doc->filepath, "Could not parse XML");
|
||||
return -1;
|
||||
}
|
||||
|
||||
xmlNode *root = xmlDocGetRootElement(xml);
|
||||
if (root == NULL) {
|
||||
CTX_LOG_ERROR(doc->filepath, "Empty document")
|
||||
CTX_LOG_ERROR(doc->filepath, "Empty document");
|
||||
xmlFreeDoc(xml);
|
||||
return -1;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ static int read_doc_props_app(scan_ooxml_ctx_t *ctx, struct archive *a, document
|
||||
}
|
||||
|
||||
if (xmlStrEqual(child->name, _X("Pages"))) {
|
||||
APPEND_LONG_META(doc, MetaPages, strtol((char *) text, NULL, 10))
|
||||
APPEND_LONG_META(doc, MetaPages, strtol((char *) text, NULL, 10));
|
||||
}
|
||||
|
||||
xmlFree(text);
|
||||
@@ -144,13 +144,13 @@ static int read_doc_props(scan_ooxml_ctx_t *ctx, struct archive *a, document_t *
|
||||
XML_PARSE_RECOVER | XML_PARSE_NOWARNING | XML_PARSE_NOERROR | XML_PARSE_NONET);
|
||||
|
||||
if (xml == NULL) {
|
||||
CTX_LOG_ERROR(doc->filepath, "Could not parse XML")
|
||||
CTX_LOG_ERROR(doc->filepath, "Could not parse XML");
|
||||
return -1;
|
||||
}
|
||||
|
||||
xmlNode *root = xmlDocGetRootElement(xml);
|
||||
if (root == NULL) {
|
||||
CTX_LOG_ERROR(doc->filepath, "Empty document")
|
||||
CTX_LOG_ERROR(doc->filepath, "Empty document");
|
||||
xmlFreeDoc(xml);
|
||||
return -1;
|
||||
}
|
||||
@@ -163,11 +163,11 @@ static int read_doc_props(scan_ooxml_ctx_t *ctx, struct archive *a, document_t *
|
||||
}
|
||||
|
||||
if (xmlStrEqual(child->name, _X("title"))) {
|
||||
APPEND_STR_META(doc, MetaTitle, (char *) text)
|
||||
APPEND_STR_META(doc, MetaTitle, (char *) text);
|
||||
} else if (xmlStrEqual(child->name, _X("creator"))) {
|
||||
APPEND_STR_META(doc, MetaAuthor, (char *) text)
|
||||
APPEND_STR_META(doc, MetaAuthor, (char *) text);
|
||||
} else if (xmlStrEqual(child->name, _X("lastModifiedBy"))) {
|
||||
APPEND_STR_META(doc, MetaModifiedBy, (char *) text)
|
||||
APPEND_STR_META(doc, MetaModifiedBy, (char *) text);
|
||||
}
|
||||
|
||||
xmlFree(text);
|
||||
@@ -190,7 +190,7 @@ void read_thumbnail(scan_ooxml_ctx_t *ctx, document_t *doc, struct archive *a, s
|
||||
char *buf = malloc(entry_size);
|
||||
archive_read_data(a, buf, entry_size);
|
||||
|
||||
APPEND_LONG_META(doc, MetaThumbnail, 1)
|
||||
APPEND_LONG_META(doc, MetaThumbnail, 1);
|
||||
ctx->store(doc->doc_id, 1, buf, entry_size);
|
||||
free(buf);
|
||||
}
|
||||
@@ -200,7 +200,7 @@ void parse_ooxml(scan_ooxml_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
size_t buf_len;
|
||||
void *buf = read_all(f, &buf_len);
|
||||
if (buf == NULL) {
|
||||
CTX_LOG_ERROR(f->filepath, "read_all() failed")
|
||||
CTX_LOG_ERROR(f->filepath, "read_all() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ void parse_ooxml(scan_ooxml_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
|
||||
int ret = archive_read_open_memory(a, buf, buf_len);
|
||||
if (ret != ARCHIVE_OK) {
|
||||
CTX_LOG_ERRORF(doc->filepath, "Could not read archive: %s", archive_error_string(a))
|
||||
CTX_LOG_ERRORF(doc->filepath, "Could not read archive: %s", archive_error_string(a));
|
||||
archive_read_free(a);
|
||||
free(buf);
|
||||
return;
|
||||
@@ -250,7 +250,7 @@ void parse_ooxml(scan_ooxml_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
meta_line_t *meta = malloc(sizeof(meta_line_t) + tex.dyn_buffer.cur);
|
||||
meta->key = MetaContent;
|
||||
strcpy(meta->str_val, tex.dyn_buffer.buf);
|
||||
APPEND_META(doc, meta)
|
||||
APPEND_META(doc, meta);
|
||||
}
|
||||
|
||||
archive_read_close(a);
|
||||
|
||||
42
third-party/libscan/libscan/raw/raw.c
vendored
42
third-party/libscan/libscan/raw/raw.c
vendored
@@ -83,7 +83,7 @@ int store_thumbnail_rgb24(scan_raw_ctx_t *ctx, libraw_processed_image_t *img, do
|
||||
av_init_packet(&jpeg_packet);
|
||||
avcodec_receive_packet(jpeg_encoder, &jpeg_packet);
|
||||
|
||||
APPEND_LONG_META(doc, MetaThumbnail, 1)
|
||||
APPEND_LONG_META(doc, MetaThumbnail, 1);
|
||||
ctx->store((char *) doc->doc_id, sizeof(doc->doc_id), (char *) jpeg_packet.data, jpeg_packet.size);
|
||||
|
||||
av_packet_unref(&jpeg_packet);
|
||||
@@ -100,76 +100,76 @@ void parse_raw(scan_raw_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
libraw_data_t *libraw_lib = libraw_init(0);
|
||||
|
||||
if (!libraw_lib) {
|
||||
CTX_LOG_ERROR("raw.c", "Cannot create libraw handle")
|
||||
CTX_LOG_ERROR("raw.c", "Cannot create libraw handle");
|
||||
return;
|
||||
}
|
||||
|
||||
size_t buf_len = 0;
|
||||
void *buf = read_all(f, &buf_len);
|
||||
if (buf == NULL) {
|
||||
CTX_LOG_ERROR(f->filepath, "read_all() failed")
|
||||
CTX_LOG_ERROR(f->filepath, "read_all() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = libraw_open_buffer(libraw_lib, buf, buf_len);
|
||||
if (ret != 0) {
|
||||
CTX_LOG_ERROR(f->filepath, "Could not open raw file")
|
||||
CTX_LOG_ERROR(f->filepath, "Could not open raw file");
|
||||
free(buf);
|
||||
libraw_close(libraw_lib);
|
||||
return;
|
||||
}
|
||||
|
||||
if (*libraw_lib->idata.model != '\0') {
|
||||
APPEND_STR_META(doc, MetaExifModel, libraw_lib->idata.model)
|
||||
APPEND_STR_META(doc, MetaExifModel, libraw_lib->idata.model);
|
||||
}
|
||||
if (*libraw_lib->idata.make != '\0') {
|
||||
APPEND_STR_META(doc, MetaExifMake, libraw_lib->idata.make)
|
||||
APPEND_STR_META(doc, MetaExifMake, libraw_lib->idata.make);
|
||||
}
|
||||
if (*libraw_lib->idata.software != '\0') {
|
||||
APPEND_STR_META(doc, MetaExifSoftware, libraw_lib->idata.software)
|
||||
APPEND_STR_META(doc, MetaExifSoftware, libraw_lib->idata.software);
|
||||
}
|
||||
APPEND_LONG_META(doc, MetaWidth, libraw_lib->sizes.width)
|
||||
APPEND_LONG_META(doc, MetaHeight, libraw_lib->sizes.height)
|
||||
APPEND_LONG_META(doc, MetaWidth, libraw_lib->sizes.width);
|
||||
APPEND_LONG_META(doc, MetaHeight, libraw_lib->sizes.height);
|
||||
char tmp[1024];
|
||||
snprintf(tmp, sizeof(tmp), "%g", libraw_lib->other.iso_speed);
|
||||
APPEND_STR_META(doc, MetaExifIsoSpeedRatings, tmp)
|
||||
APPEND_STR_META(doc, MetaExifIsoSpeedRatings, tmp);
|
||||
|
||||
if (*libraw_lib->other.desc != '\0') {
|
||||
APPEND_STR_META(doc, MetaContent, libraw_lib->other.desc)
|
||||
APPEND_STR_META(doc, MetaContent, libraw_lib->other.desc);
|
||||
}
|
||||
if (*libraw_lib->other.artist != '\0') {
|
||||
APPEND_STR_META(doc, MetaArtist, libraw_lib->other.artist)
|
||||
APPEND_STR_META(doc, MetaArtist, libraw_lib->other.artist);
|
||||
}
|
||||
|
||||
struct tm *time = localtime(&libraw_lib->other.timestamp);
|
||||
strftime(tmp, sizeof(tmp), "%Y:%m:%d %H:%M:%S", time);
|
||||
APPEND_STR_META(doc, MetaExifDateTime, tmp)
|
||||
APPEND_STR_META(doc, MetaExifDateTime, tmp);
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "%.1f", libraw_lib->other.focal_len);
|
||||
APPEND_STR_META(doc, MetaExifFocalLength, tmp)
|
||||
APPEND_STR_META(doc, MetaExifFocalLength, tmp);
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "%.1f", libraw_lib->other.aperture);
|
||||
APPEND_STR_META(doc, MetaExifFNumber, tmp)
|
||||
APPEND_STR_META(doc, MetaExifFNumber, tmp);
|
||||
|
||||
int denominator = (int) roundf(1 / libraw_lib->other.shutter);
|
||||
snprintf(tmp, sizeof(tmp), "1/%d", denominator);
|
||||
APPEND_STR_META(doc, MetaExifExposureTime, tmp)
|
||||
APPEND_STR_META(doc, MetaExifExposureTime, tmp);
|
||||
|
||||
libraw_gps_info_t gps = libraw_lib->other.parsed_gps;
|
||||
double gps_longitude_dec =
|
||||
(gps.longitude[0] + gps.longitude[1] / 60 + gps.longitude[2] / 3600) * DMS_REF(gps.longref);
|
||||
snprintf(tmp, sizeof(tmp), "%.15f", gps_longitude_dec);
|
||||
if (gps_longitude_dec != 0.0) {
|
||||
APPEND_STR_META(doc, MetaExifGpsLongitudeDec, tmp)
|
||||
APPEND_STR_META(doc, MetaExifGpsLongitudeDec, tmp);
|
||||
}
|
||||
|
||||
double gps_latitude_dec = (gps.latitude[0] + gps.latitude[1] / 60 + gps.latitude[2] / 3600) * DMS_REF(gps.latref);
|
||||
snprintf(tmp, sizeof(tmp), "%.15f", gps_latitude_dec);
|
||||
if (gps_latitude_dec != 0.0) {
|
||||
APPEND_STR_META(doc, MetaExifGpsLatitudeDec, tmp)
|
||||
APPEND_STR_META(doc, MetaExifGpsLatitudeDec, tmp);
|
||||
}
|
||||
|
||||
APPEND_STR_META(doc, MetaMediaVideoCodec, "raw")
|
||||
APPEND_STR_META(doc, MetaMediaVideoCodec, "raw");
|
||||
|
||||
if (!ctx->enable_tn) {
|
||||
free(buf);
|
||||
@@ -179,7 +179,7 @@ void parse_raw(scan_raw_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
|
||||
int unpack_ret = libraw_unpack_thumb(libraw_lib);
|
||||
if (unpack_ret != 0) {
|
||||
CTX_LOG_ERRORF(f->filepath, "libraw_unpack_thumb returned error code %d", unpack_ret)
|
||||
CTX_LOG_ERRORF(f->filepath, "libraw_unpack_thumb returned error code %d", unpack_ret);
|
||||
free(buf);
|
||||
libraw_close(libraw_lib);
|
||||
return;
|
||||
@@ -212,7 +212,7 @@ void parse_raw(scan_raw_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
|
||||
ret = libraw_unpack(libraw_lib);
|
||||
if (ret != 0) {
|
||||
CTX_LOG_ERROR(f->filepath, "Could not unpack raw file")
|
||||
CTX_LOG_ERROR(f->filepath, "Could not unpack raw file");
|
||||
free(buf);
|
||||
libraw_close(libraw_lib);
|
||||
return;
|
||||
|
||||
20
third-party/libscan/libscan/scan.h
vendored
20
third-party/libscan/libscan/scan.h
vendored
@@ -34,20 +34,20 @@ typedef int scan_code_t;
|
||||
#define LEVEL_ERROR 3
|
||||
#define LEVEL_FATAL 4
|
||||
|
||||
#define CTX_LOG_DEBUGF(filepath, fmt, ...) ctx->logf(filepath, LEVEL_DEBUG, fmt, __VA_ARGS__);
|
||||
#define CTX_LOG_DEBUG(filepath, str) ctx->log(filepath, LEVEL_DEBUG, str);
|
||||
#define CTX_LOG_DEBUGF(filepath, fmt, ...) ctx->logf(filepath, LEVEL_DEBUG, fmt, __VA_ARGS__)
|
||||
#define CTX_LOG_DEBUG(filepath, str) ctx->log(filepath, LEVEL_DEBUG, str)
|
||||
|
||||
#define CTX_LOG_INFOF(filepath, fmt, ...) ctx->logf(filepath, LEVEL_INFO, fmt, __VA_ARGS__);
|
||||
#define CTX_LOG_INFO(filepath, str) ctx->log(filepath, LEVEL_INFO, str);
|
||||
#define CTX_LOG_INFOF(filepath, fmt, ...) ctx->logf(filepath, LEVEL_INFO, fmt, __VA_ARGS__)
|
||||
#define CTX_LOG_INFO(filepath, str) ctx->log(filepath, LEVEL_INFO, str)
|
||||
|
||||
#define CTX_LOG_WARNINGF(filepath, fmt, ...) ctx->logf(filepath, LEVEL_WARNING, fmt, __VA_ARGS__);
|
||||
#define CTX_LOG_WARNING(filepath, str) ctx->log(filepath, LEVEL_WARNING, str);
|
||||
#define CTX_LOG_WARNINGF(filepath, fmt, ...) ctx->logf(filepath, LEVEL_WARNING, fmt, __VA_ARGS__)
|
||||
#define CTX_LOG_WARNING(filepath, str) ctx->log(filepath, LEVEL_WARNING, str)
|
||||
|
||||
#define CTX_LOG_ERRORF(filepath, fmt, ...) ctx->logf(filepath, LEVEL_ERROR, fmt, __VA_ARGS__);
|
||||
#define CTX_LOG_ERROR(filepath, str) ctx->log(filepath, LEVEL_ERROR, str);
|
||||
#define CTX_LOG_ERRORF(filepath, fmt, ...) ctx->logf(filepath, LEVEL_ERROR, fmt, __VA_ARGS__)
|
||||
#define CTX_LOG_ERROR(filepath, str) ctx->log(filepath, LEVEL_ERROR, str)
|
||||
|
||||
#define CTX_LOG_FATALF(filepath, fmt, ...) ctx->logf(filepath, LEVEL_FATAL, fmt, __VA_ARGS__); exit(-1);
|
||||
#define CTX_LOG_FATAL(filepath, str) ctx->log(filepath, LEVEL_FATAL, str); exit(-1);
|
||||
#define CTX_LOG_FATALF(filepath, fmt, ...) ctx->logf(filepath, LEVEL_FATAL, fmt, __VA_ARGS__); exit(-1)
|
||||
#define CTX_LOG_FATAL(filepath, str) ctx->log(filepath, LEVEL_FATAL, str); exit(-1)
|
||||
|
||||
#define SIST_DOC_ID_LEN MD5_STR_LENGTH
|
||||
#define SIST_INDEX_ID_LEN MD5_STR_LENGTH
|
||||
|
||||
12
third-party/libscan/libscan/text/text.c
vendored
12
third-party/libscan/libscan/text/text.c
vendored
@@ -2,6 +2,10 @@
|
||||
|
||||
scan_code_t parse_text(scan_text_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
|
||||
if (ctx->content_size <= 0) {
|
||||
return SCAN_OK;
|
||||
}
|
||||
|
||||
int to_read = MIN(ctx->content_size, f->st_size);
|
||||
|
||||
if (to_read <= 2) {
|
||||
@@ -11,7 +15,7 @@ scan_code_t parse_text(scan_text_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
char *buf = malloc(to_read);
|
||||
int ret = f->read(f, buf, to_read);
|
||||
if (ret < 0) {
|
||||
CTX_LOG_ERRORF(doc->filepath, "read() returned error code: [%d]", ret)
|
||||
CTX_LOG_ERRORF(doc->filepath, "read() returned error code: [%d]", ret);
|
||||
free(buf);
|
||||
return SCAN_ERR_READ;
|
||||
}
|
||||
@@ -39,12 +43,16 @@ scan_code_t parse_text(scan_text_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
|
||||
scan_code_t parse_markup(scan_text_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
|
||||
if (ctx->content_size <= 0) {
|
||||
return SCAN_OK;
|
||||
}
|
||||
|
||||
int to_read = MIN(MAX_MARKUP_SIZE, f->st_size);
|
||||
|
||||
char *buf = malloc(to_read + 1);
|
||||
int ret = f->read(f, buf, to_read);
|
||||
if (ret < 0) {
|
||||
CTX_LOG_ERRORF(doc->filepath, "read() returned error code: [%d]", ret)
|
||||
CTX_LOG_ERRORF(doc->filepath, "read() returned error code: [%d]", ret);
|
||||
free(buf);
|
||||
return SCAN_ERR_READ;
|
||||
}
|
||||
|
||||
8
third-party/libscan/libscan/wpd/wpd.c
vendored
8
third-party/libscan/libscan/wpd/wpd.c
vendored
@@ -10,14 +10,14 @@ scan_code_t parse_wpd(scan_wpd_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
wpd_confidence_t conf = wpd_is_file_format_supported(stream);
|
||||
|
||||
if (conf == C_WPD_CONFIDENCE_SUPPORTED_ENCRYPTION || conf == C_WPD_CONFIDENCE_UNSUPPORTED_ENCRYPTION) {
|
||||
CTX_LOG_DEBUGF("wpd.c", "File is encrypted! Password-protected WPD files are not supported yet (conf=%d)", conf)
|
||||
CTX_LOG_DEBUGF("wpd.c", "File is encrypted! Password-protected WPD files are not supported yet (conf=%d)", conf);
|
||||
wpd_memory_stream_destroy(stream);
|
||||
free(buf);
|
||||
return SCAN_ERR_READ;
|
||||
}
|
||||
|
||||
if (conf != C_WPD_CONFIDENCE_EXCELLENT) {
|
||||
CTX_LOG_ERRORF("wpd.c", "Unsupported file format! [%s] (conf=%d)", doc->filepath, conf)
|
||||
CTX_LOG_ERRORF("wpd.c", "Unsupported file format! [%s] (conf=%d)", doc->filepath, conf);
|
||||
wpd_memory_stream_destroy(stream);
|
||||
free(buf);
|
||||
return SCAN_ERR_READ;
|
||||
@@ -28,11 +28,11 @@ scan_code_t parse_wpd(scan_wpd_ctx_t *ctx, vfile_t *f, document_t *doc) {
|
||||
|
||||
if (res != C_WPD_OK) {
|
||||
CTX_LOG_ERRORF("wpd.c", "Error while parsing WPD file [%s] (%d)",
|
||||
doc->filepath, res)
|
||||
doc->filepath, res);
|
||||
}
|
||||
|
||||
if (tex.dyn_buffer.cur != 0) {
|
||||
APPEND_STR_META(doc, MetaContent, tex.dyn_buffer.buf)
|
||||
APPEND_STR_META(doc, MetaContent, tex.dyn_buffer.buf);
|
||||
}
|
||||
|
||||
text_buffer_destroy(&tex);
|
||||
|
||||
Reference in New Issue
Block a user