This commit is contained in:
simon987 2020-12-22 13:30:56 -05:00
parent 6b47b4dfbb
commit cc89c21b87
9 changed files with 22 additions and 28 deletions

View File

@ -5,8 +5,6 @@
#include <string.h> #include <string.h>
#include <fcntl.h> #include <fcntl.h>
#define MAX_SUBFILE_SIZE (long)(10000000000)
int should_parse_filtered_file(const char *filepath, int ext) { int should_parse_filtered_file(const char *filepath, int ext) {
char tmp[PATH_MAX * 2]; char tmp[PATH_MAX * 2];
@ -110,7 +108,7 @@ scan_code_t parse_archive(scan_arc_ctx_t *ctx, vfile_t *f, document_t *doc) {
meta_line_t *meta_list = malloc(sizeof(meta_line_t) + buf.cur); meta_line_t *meta_list = malloc(sizeof(meta_line_t) + buf.cur);
meta_list->key = MetaContent; meta_list->key = MetaContent;
strcpy(meta_list->str_val, buf.buf); strcpy(meta_list->str_val, buf.buf);
APPEND_META(doc, meta_list); APPEND_META(doc, meta_list)
dyn_buffer_destroy(&buf); dyn_buffer_destroy(&buf);
} else { } else {

View File

@ -157,7 +157,7 @@ int render_cover(scan_ebook_ctx_t *ctx, fz_context *fzctx, document_t *doc, fz_d
avcodec_receive_packet(jpeg_encoder, &jpeg_packet); avcodec_receive_packet(jpeg_encoder, &jpeg_packet);
APPEND_TN_META(doc, pixmap->w, pixmap->h) APPEND_TN_META(doc, pixmap->w, pixmap->h)
ctx->store((char *) doc->uuid, sizeof(doc->uuid), (char *) jpeg_packet.data, jpeg_packet.size); ctx->store((char *) doc->path_md5, sizeof(doc->path_md5), (char *) jpeg_packet.data, jpeg_packet.size);
av_packet_unref(&jpeg_packet); av_packet_unref(&jpeg_packet);
av_free(*scaled_frame->data); av_free(*scaled_frame->data);
@ -174,14 +174,14 @@ void fz_err_callback(void *user, const char *message) {
document_t *doc = (document_t *) user; document_t *doc = (document_t *) user;
const scan_ebook_ctx_t *ctx = &thread_ctx; 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) { void fz_warn_callback(void *user, const char *message) {
document_t *doc = (document_t *) user; document_t *doc = (document_t *) user;
const scan_ebook_ctx_t *ctx = &thread_ctx; 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) { static void init_fzctx(fz_context *fzctx, document_t *doc) {

View File

@ -229,7 +229,7 @@ void parse_font(scan_font_ctx_t *ctx, vfile_t *f, document_t *doc) {
bmp_format(&bmp_data, dimensions, bitmap); bmp_format(&bmp_data, dimensions, bitmap);
APPEND_TN_META(doc, dimensions.width, dimensions.height) APPEND_TN_META(doc, dimensions.width, dimensions.height)
ctx->store((char *) doc->uuid, sizeof(doc->uuid), (char *) bmp_data.buf, bmp_data.cur); ctx->store((char *) doc->path_md5, sizeof(doc->path_md5), (char *) bmp_data.buf, bmp_data.cur);
dyn_buffer_destroy(&bmp_data); dyn_buffer_destroy(&bmp_data);
free(bitmap); free(bitmap);

View File

@ -1,8 +1,4 @@
#include "media.h" #include "media.h"
#include "../util.h"
#include <ctype.h> #include <ctype.h>
#define MIN_SIZE 32 #define MIN_SIZE 32
@ -323,7 +319,7 @@ void parse_media_format_ctx(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx,
//Seek //Seek
if (stream->nb_frames > 1 && stream->codecpar->codec_id != AV_CODEC_ID_GIF) { if (stream->nb_frames > 1 && stream->codecpar->codec_id != AV_CODEC_ID_GIF) {
int seek_ret = 0; int seek_ret;
for (int i = 20; i >= 0; i--) { for (int i = 20; i >= 0; i--) {
seek_ret = av_seek_frame(pFormatCtx, video_stream, seek_ret = av_seek_frame(pFormatCtx, video_stream,
stream->duration * 0.10, 0); stream->duration * 0.10, 0);
@ -356,7 +352,7 @@ void parse_media_format_ctx(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx,
if (scaled_frame == STORE_AS_IS) { if (scaled_frame == STORE_AS_IS) {
APPEND_TN_META(doc, frame_and_packet->frame->width, frame_and_packet->frame->height) APPEND_TN_META(doc, frame_and_packet->frame->width, frame_and_packet->frame->height)
ctx->store((char *) doc->uuid, sizeof(doc->uuid), (char *) frame_and_packet->packet->data, frame_and_packet->packet->size); ctx->store((char *) doc->path_md5, sizeof(doc->path_md5), (char *) frame_and_packet->packet->data, frame_and_packet->packet->size);
} else { } else {
// Encode frame to jpeg // Encode frame to jpeg
AVCodecContext *jpeg_encoder = alloc_jpeg_encoder(scaled_frame->width, scaled_frame->height, AVCodecContext *jpeg_encoder = alloc_jpeg_encoder(scaled_frame->width, scaled_frame->height,
@ -369,7 +365,7 @@ void parse_media_format_ctx(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx,
// Save thumbnail // Save thumbnail
APPEND_TN_META(doc, scaled_frame->width, scaled_frame->height) APPEND_TN_META(doc, scaled_frame->width, scaled_frame->height)
ctx->store((char *) doc->uuid, sizeof(doc->uuid), (char *) jpeg_packet.data, jpeg_packet.size); ctx->store((char *) doc->path_md5, sizeof(doc->path_md5), (char *) jpeg_packet.data, jpeg_packet.size);
avcodec_free_context(&jpeg_encoder); avcodec_free_context(&jpeg_encoder);
av_packet_unref(&jpeg_packet); av_packet_unref(&jpeg_packet);
@ -608,7 +604,7 @@ int store_image_thumbnail(scan_media_ctx_t *ctx, void* buf, size_t buf_len, docu
if (scaled_frame == STORE_AS_IS) { if (scaled_frame == STORE_AS_IS) {
APPEND_TN_META(doc, frame_and_packet->frame->width, frame_and_packet->frame->height) APPEND_TN_META(doc, frame_and_packet->frame->width, frame_and_packet->frame->height)
ctx->store((char *) doc->uuid, sizeof(doc->uuid), (char *) frame_and_packet->packet->data, frame_and_packet->packet->size); ctx->store((char *) doc->path_md5, sizeof(doc->path_md5), (char *) frame_and_packet->packet->data, frame_and_packet->packet->size);
} else { } else {
// Encode frame to jpeg // Encode frame to jpeg
AVCodecContext *jpeg_encoder = alloc_jpeg_encoder(scaled_frame->width, scaled_frame->height, AVCodecContext *jpeg_encoder = alloc_jpeg_encoder(scaled_frame->width, scaled_frame->height,
@ -621,7 +617,7 @@ int store_image_thumbnail(scan_media_ctx_t *ctx, void* buf, size_t buf_len, docu
// Save thumbnail // Save thumbnail
APPEND_TN_META(doc, scaled_frame->width, scaled_frame->height) APPEND_TN_META(doc, scaled_frame->width, scaled_frame->height)
ctx->store((char *) doc->uuid, sizeof(doc->uuid), (char *) jpeg_packet.data, jpeg_packet.size); ctx->store((char *) doc->path_md5, sizeof(doc->path_md5), (char *) jpeg_packet.data, jpeg_packet.size);
av_packet_unref(&jpeg_packet); av_packet_unref(&jpeg_packet);
avcodec_free_context(&jpeg_encoder); avcodec_free_context(&jpeg_encoder);

View File

@ -6,7 +6,7 @@
#include "../ebook/ebook.h" #include "../ebook/ebook.h"
void parse_msdoc_text(scan_msdoc_ctx_t *ctx, vfile_t *f, document_t *doc, FILE *file_in, void* buf, size_t buf_len) { void parse_msdoc_text(scan_msdoc_ctx_t *ctx, document_t *doc, FILE *file_in, void* buf, size_t buf_len) {
// Open word doc // Open word doc
options_type *opts = direct_vGetOptions(); options_type *opts = direct_vGetOptions();
@ -73,7 +73,7 @@ void parse_msdoc_text(scan_msdoc_ctx_t *ctx, vfile_t *f, document_t *doc, FILE *
free(out_buf); free(out_buf);
} }
void parse_msdoc_pdf(scan_msdoc_ctx_t *ctx, vfile_t *f, document_t *doc, FILE *file, void* buf, size_t buf_len) { void parse_msdoc_pdf(scan_msdoc_ctx_t *ctx, document_t *doc, FILE *file, void* buf, size_t buf_len) {
scan_ebook_ctx_t ebook_ctx = { scan_ebook_ctx_t ebook_ctx = {
.content_size = ctx->content_size, .content_size = ctx->content_size,
@ -115,7 +115,7 @@ void parse_msdoc_pdf(scan_msdoc_ctx_t *ctx, vfile_t *f, document_t *doc, FILE *f
return; return;
} }
int ret = bWordDecryptor(file, buf_len, diag); bWordDecryptor(file, buf_len, diag);
vDestroyDiagram(diag); vDestroyDiagram(diag);
fclose(file_out); fclose(file_out);
@ -144,8 +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) {
parse_msdoc_pdf(ctx, f, doc, file, buf, buf_len); parse_msdoc_pdf(ctx, doc, file, buf, buf_len);
} else { } else {
parse_msdoc_text(ctx, f, doc, file, buf, buf_len); parse_msdoc_text(ctx, doc, file, buf, buf_len);
} }
} }

View File

@ -19,6 +19,6 @@ static int is_msdoc(scan_msdoc_ctx_t *ctx, unsigned int mime) {
void parse_msdoc(scan_msdoc_ctx_t *ctx, vfile_t *f, document_t *doc); void parse_msdoc(scan_msdoc_ctx_t *ctx, vfile_t *f, document_t *doc);
void parse_msdoc_text(scan_msdoc_ctx_t *ctx, vfile_t *f, document_t *doc, FILE *file_in, void* buf, size_t buf_len); void parse_msdoc_text(scan_msdoc_ctx_t *ctx, document_t *doc, FILE *file_in, void* buf, size_t buf_len);
#endif #endif

View File

@ -1,6 +1,5 @@
#include "ooxml.h" #include "ooxml.h"
#include "../util.h"
#include <archive.h> #include <archive.h>
#include <archive_entry.h> #include <archive_entry.h>
#include <libxml/xmlstring.h> #include <libxml/xmlstring.h>
@ -106,7 +105,7 @@ static int read_part(scan_ooxml_ctx_t *ctx, struct archive *a, text_buffer_t *bu
} }
__always_inline __always_inline
static int read_doc_props(scan_ooxml_ctx_t *ctx, struct archive *a, text_buffer_t *buf, document_t *doc) { static int read_doc_props(scan_ooxml_ctx_t *ctx, struct archive *a, document_t *doc) {
xmlDoc *xml = xmlReadIO(xml_io_read, xml_io_close, a, "/", NULL, xmlDoc *xml = xmlReadIO(xml_io_read, xml_io_close, a, "/", NULL,
XML_PARSE_RECOVER | XML_PARSE_NOWARNING | XML_PARSE_NOERROR | XML_PARSE_NONET); XML_PARSE_RECOVER | XML_PARSE_NOWARNING | XML_PARSE_NOERROR | XML_PARSE_NONET);
@ -158,7 +157,7 @@ void read_thumbnail(scan_ooxml_ctx_t *ctx, document_t *doc, struct archive *a, s
archive_read_data(a, buf, entry_size); archive_read_data(a, buf, entry_size);
APPEND_TN_META(doc, 1, 1) // Size unknown APPEND_TN_META(doc, 1, 1) // Size unknown
ctx->store((char *) doc->uuid, sizeof(doc->uuid), buf, entry_size); ctx->store((char *) doc->path_md5, sizeof(doc->path_md5), buf, entry_size);
free(buf); free(buf);
} }
@ -198,7 +197,7 @@ void parse_ooxml(scan_ooxml_ctx_t *ctx, vfile_t *f, document_t *doc) {
buffer_full = TRUE; buffer_full = TRUE;
} }
} else if (strcmp(path, "docProps/core.xml") == 0) { } else if (strcmp(path, "docProps/core.xml") == 0) {
if (read_doc_props(ctx, a, &tex, doc) != 0) { if (read_doc_props(ctx, a, doc) != 0) {
break; break;
} }
} else if (strcmp(path, "docProps/thumbnail.jpeg") == 0) { } else if (strcmp(path, "docProps/thumbnail.jpeg") == 0) {

View File

@ -2,7 +2,6 @@
#include <libraw/libraw.h> #include <libraw/libraw.h>
#include "../media/media.h" #include "../media/media.h"
#include <fcntl.h>
#include <unistd.h> #include <unistd.h>
@ -71,7 +70,7 @@ int store_thumbnail_rgb24(scan_raw_ctx_t *ctx, libraw_processed_image_t *img, do
avcodec_receive_packet(jpeg_encoder, &jpeg_packet); avcodec_receive_packet(jpeg_encoder, &jpeg_packet);
APPEND_TN_META(doc, scaled_frame->width, scaled_frame->height) APPEND_TN_META(doc, scaled_frame->width, scaled_frame->height)
ctx->store((char *) doc->uuid, sizeof(doc->uuid), (char *) jpeg_packet.data, jpeg_packet.size); ctx->store((char *) doc->path_md5, sizeof(doc->path_md5), (char *) jpeg_packet.data, jpeg_packet.size);
av_packet_unref(&jpeg_packet); av_packet_unref(&jpeg_packet);
av_free(*scaled_frame->data); av_free(*scaled_frame->data);

View File

@ -8,6 +8,7 @@
#include <stdio.h> #include <stdio.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <uuid/uuid.h> #include <uuid/uuid.h>
#include <openssl/md5.h>
#include "macros.h" #include "macros.h"
@ -106,6 +107,7 @@ typedef struct document {
int mtime; int mtime;
short base; short base;
short ext; short ext;
unsigned char path_md5[MD5_DIGEST_LENGTH];
meta_line_t *meta_head; meta_line_t *meta_head;
meta_line_t *meta_tail; meta_line_t *meta_tail;
char *filepath; char *filepath;