Separate functions that use podofo 93/263393/5 accepted/tizen_6.5_unified tizen_6.5 accepted/tizen/6.5/unified/20211028.115503 accepted/tizen/unified/20210903.083033 submit/tizen/20210903.013438 submit/tizen/20211210.040928 submit/tizen/20220103.220317 submit/tizen_6.5/20211028.162401 tizen_6.5.m2_release
authorMinje Ahn <minje.ahn@samsung.com>
Wed, 1 Sep 2021 23:59:16 +0000 (08:59 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Thu, 2 Sep 2021 23:37:25 +0000 (08:37 +0900)
It took a lot of time to read podofo, so split it with dlopen.

Change-Id: I57b49f062019311ba8aa3b26094c9a0c0fcd4ae4
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
CMakeLists.txt
packaging/libmedia-service.spec
plugin/media-ebook-plugin.cpp [moved from src/common/media-svc-util-ebook.cpp with 88% similarity]
src/common/media-svc-util.c
src/include/common/media-svc-util-ebook.h [deleted file]

index 39191b2..738a8d7 100644 (file)
@@ -6,13 +6,13 @@ SET(VERSION "${VERSION_MAJOR}.0.0")
 SET(MEDIASERVICE-LIB "media-service")
 SET(MEDIASERVICE-HASH-LIB "media-svc-hash")
 SET(MEDIACONTENT-PLUGIN-LIB "media-content-plugin")
-SET(SRCS 
+SET(MEDIAEBOOK-PLUGIN-LIB "media-ebook-plugin")
+SET(SRCS
        src/common/media-svc.c
        src/common/media-svc-media.c
        src/common/media-svc-album.c
        src/common/media-svc-media-folder.c
        src/common/media-svc-db-utils.c
-       src/common/media-svc-util-ebook.cpp
        src/common/media-svc-util.c
        src/common/media-svc-noti.c
        src/common/media-svc-storage.c
@@ -24,8 +24,8 @@ SET(HASH_SRCS
        md5/media-svc-hash.c
        )
 
-SET(PLUGIN_SRCS
-       plugin/media-svc-plugin.c
+SET(EBOOKPLUGIN_SRCS
+       plugin/media-ebook-plugin.cpp
        )
 SET(CONTENTPLUGIN_SRCS
        plugin/media-content-plugin.c
@@ -97,10 +97,12 @@ ADD_LIBRARY(${MEDIACONTENT-PLUGIN-LIB} SHARED ${CONTENTPLUGIN_SRCS})
 TARGET_LINK_LIBRARIES(${MEDIACONTENT-PLUGIN-LIB} ${MEDIASERVICE-LIB})
 SET_TARGET_PROPERTIES(${MEDIACONTENT-PLUGIN-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
 SET_TARGET_PROPERTIES(${MEDIACONTENT-PLUGIN-LIB} PROPERTIES VERSION ${VERSION})
+ADD_LIBRARY(${MEDIAEBOOK-PLUGIN-LIB} SHARED ${EBOOKPLUGIN_SRCS})
+TARGET_LINK_LIBRARIES(${MEDIAEBOOK-PLUGIN-LIB} ${pkgs_LDFLAGS})
 
 INSTALL(TARGETS ${MEDIASERVICE-LIB} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
 INSTALL(TARGETS ${MEDIASERVICE-HASH-LIB} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
 INSTALL(TARGETS ${MEDIACONTENT-PLUGIN-LIB} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
-#INSTALL(TARGETS ${MEDIACONTENT-PLUGIN-LIB} LIBRARY DESTINATION /usr/lib)
+INSTALL(TARGETS ${MEDIAEBOOK-PLUGIN-LIB} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
 
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/media-svc.h DESTINATION include/media-service/)
index d29d25d..523e17e 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmedia-service
 Summary:    Media information service library for multimedia applications
-Version:    0.4.20
+Version:    0.4.21
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0 and PD
@@ -48,7 +48,7 @@ This package is a library that provides the media information service for the mu
 cp %{SOURCE1001} .
 
 %build
-export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE -DSYSCONFDIR=\\\"%{_sysconfdir}\\\""
+export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE -DSYSCONFDIR=\\\"%{_sysconfdir}\\\" -DPATH_LIBDIR=\\\"%{_libdir}\\\""
 %cmake . -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0}
 make %{?jobs:-j%jobs}
 
@@ -66,6 +66,7 @@ rm -rf %{buildroot}
 %{_libdir}/libmedia-svc-hash.so.*
 %{_libdir}/libmedia-content-plugin.so
 %{_libdir}/libmedia-content-plugin.so.*
+%{_libdir}/libmedia-ebook-plugin.so
 %if 0%{?gtests:1}
 %{_bindir}/gtest*
 %endif
similarity index 88%
rename from src/common/media-svc-util-ebook.cpp
rename to plugin/media-ebook-plugin.cpp
index 9007265..49ea76b 100644 (file)
  */
 #include <podofo/podofo.h>
 #include <stack>
-#include <media-svc-util-ebook.h>
-#include <media-svc-debug.h>
+#include <memory>
+#include <dlog.h>
 #include <glib.h>
+#include <stdbool.h>
 
 #include <zip.h>
 #include <libxml/xmlmemory.h>
 
 #include <regex>
 
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "MEDIA_SERVICE"
+
 class TextFinderInterface
 {
 public:
@@ -55,17 +62,17 @@ private:
 PdfTextFinder::PdfTextFinder(const char *path)
 {
        if (!path) {
-               media_svc_error("invalid path");
+               LOGE("invalid path");
                return;
        }
 
-       media_svc_debug("%s", path);
+       LOGD("%s", path);
 
        try {
                pdf.Load(path);
                loaded = true;
        } catch (const PoDoFo::PdfError& e) {
-               media_svc_error("Initialization failed : %s", e.what());
+               LOGE("Initialization failed : %s", e.what());
        }
 }
 
@@ -74,7 +81,10 @@ bool PdfTextFinder::find(const char *keyword)
        if (!loaded)
                return false;
 
-       media_svc_retvm_if(!keyword, false, "Invalid keyword");
+       if (!keyword) {
+               LOGE("Invalid keyword");
+               return false;
+       }
 
        for (int n = 0; n < pdf.GetPageCount(); ++n) {
                auto text = parseTextFromPage(n);
@@ -99,7 +109,8 @@ std::string PdfTextFinder::parseTextFromPage(unsigned int index)
        PoDoFo::PdfArray array;
 
        PoDoFo::PdfPage* page = pdf.GetPage(index);
-       media_svc_retv_if(!page, fullText);
+       if (!page)
+               return fullText;
 
        PoDoFo::PdfContentsTokenizer tokenizer(page);
 
@@ -165,7 +176,8 @@ std::string PdfTextFinder::parseTextFromPage(unsigned int index)
 /* ToDo : match can be passed to EbookText */
 bool PdfTextFinder::match(std::string& text, const char *keyword)
 {
-       media_svc_retv_if(!keyword, false);
+       if (!keyword)
+               return false;
 
        if (text.empty())
                return false;
@@ -173,7 +185,7 @@ bool PdfTextFinder::match(std::string& text, const char *keyword)
        std::regex re(keyword, std::regex::icase);
 
        if (std::regex_search(text, re)) {
-               media_svc_debug("Found [%s]", keyword);
+               LOGD("Found [%s]", keyword);
                return true;
        }
 
@@ -201,16 +213,16 @@ private:
 EpubTextFinder::EpubTextFinder(const char *path)
 {
        if (!path) {
-               media_svc_error("invalid path");
+               LOGE("invalid path");
                return;
        }
 
-       media_svc_debug("%s", path);
+       LOGD("%s", path);
 
        int err = 0;
        z = zip_open(path, ZIP_RDONLY, &err);
        if (err != 0)
-               media_svc_error("zip_open failed");
+               LOGE("zip_open failed");
 }
 
 EpubTextFinder::~EpubTextFinder()
@@ -226,7 +238,10 @@ bool EpubTextFinder::find(const char *keyword)
 {
        zip_stat_t sb = {0, };
 
-       media_svc_retvm_if(!keyword, false, "Invalid keyword");
+       if (!keyword) {
+               LOGE("Invalid keyword");
+               return false;
+       }
 
        int entry_len = zip_get_num_entries(z, ZIP_FL_UNCHANGED);
        for (int i = 0; i < entry_len; i++) {
@@ -256,14 +271,16 @@ bool EpubTextFinder::find(const char *keyword)
 
 bool EpubTextFinder::match(const char *text, const char *keyword)
 {
-       media_svc_retv_if(!keyword, false);
+       if (!keyword)
+               return false;
+
        if (!text)
                return false;
 
        std::regex re(keyword, std::regex::icase);
 
        if (std::regex_search(text, re)) {
-               media_svc_debug("Found [%s]", keyword);
+               LOGD("Found [%s]", keyword);
                return true;
        }
 
@@ -287,7 +304,11 @@ bool EpubTextFinder::htmlFind(const char *html_buf, int buf_size, const char *ke
 {
        htmlDocPtr doc = htmlReadMemory(html_buf, buf_size, "/", NULL,
                                                                        HTML_PARSE_NOBLANKS | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | HTML_PARSE_NONET);
-       media_svc_retvm_if(!doc, false, "htmlReadMemory failed");
+
+       if (!doc) {
+               LOGE("htmlReadMemory failed");
+               return false;
+       }
 
        bool result = htmlNodeFindRecursive(xmlDocGetRootElement(doc), keyword);
 
@@ -296,7 +317,7 @@ bool EpubTextFinder::htmlFind(const char *html_buf, int buf_size, const char *ke
        return result;
 }
 
-bool _media_svc_pdf_is_keyword_included(const char *path, const char *keyword)
+extern "C" bool media_svc_pdf_is_keyword_included(const char *path, const char *keyword)
 {
        /* ToDo: factory pattern */
        std::unique_ptr<TextFinderInterface> ebookText = std::make_unique<PdfTextFinder>(path);
@@ -304,7 +325,7 @@ bool _media_svc_pdf_is_keyword_included(const char *path, const char *keyword)
        return ebookText->find(keyword);
 }
 
-bool _media_svc_epub_is_keyword_included(const char *path, const char *keyword)
+extern "C" bool media_svc_epub_is_keyword_included(const char *path, const char *keyword)
 {
        /* ToDo: factory pattern */
        std::unique_ptr<TextFinderInterface> ebookText = std::make_unique<EpubTextFinder>(path);
index 46746c6..829d892 100644 (file)
 #include "media-svc-hash.h"
 #include "media-svc-album.h"
 #include "media-svc-localize_ch.h"
-#include "media-svc-util-ebook.h"
 /*For ebook metadata */
 #include <zip.h>
 #include <libxml/xmlmemory.h>
 #include <libxml/parser.h>
 #include <libxml/HTMLparser.h>
+#include <dlfcn.h>
 
 #define MEDIA_SVC_FILE_EXT_LEN_MAX                             6                       /**< Maximum file ext lenth*/
 
@@ -79,6 +79,8 @@
 #define MEDIA_SVC_PDF_TAG_TAIL_LEN 12
 #define MEDIA_SVC_PDF_BUF_SIZE 256
 
+#define PATH_PLUGIN_LIB                                PATH_LIBDIR"/libmedia-ebook-plugin.so"
+
 enum Exif_Orientation {
        NOT_AVAILABLE = 0,
        NORMAL = 1,
@@ -1578,11 +1580,29 @@ bool _media_svc_is_valid_storage_type(ms_user_storage_type_e storage_type)
 
 bool _media_svc_is_keyword_included(const char *path, const char *keyword)
 {
+       bool ret = false;
+       void *handle = NULL;
+       bool (*svc_search) (const char *, const char *);
+
        media_svc_retvm_if(!path, false, "Invalid path");
        media_svc_retvm_if(!keyword, false, "Invalid keyword");
 
+       handle = dlopen(PATH_PLUGIN_LIB, RTLD_LAZY);
+       media_svc_retvm_if(!handle, false, "dlopen failed");
+
        if (g_str_has_suffix(path, "epub") || g_str_has_suffix(path, "EPUB"))
-               return _media_svc_epub_is_keyword_included(path, keyword);
+               svc_search = dlsym(handle, "media_svc_epub_is_keyword_included");
        else
-               return _media_svc_pdf_is_keyword_included(path, keyword);
+               svc_search = dlsym(handle, "media_svc_pdf_is_keyword_included");
+
+       if (!svc_search) {
+               media_svc_error("dlsym failed - %s", dlerror());
+               dlclose(handle);
+               return false;
+       }
+
+       ret = svc_search(path, keyword);
+       dlclose(handle);
+
+       return ret;
 }
diff --git a/src/include/common/media-svc-util-ebook.h b/src/include/common/media-svc-util-ebook.h
deleted file mode 100644 (file)
index 23b6748..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * libmedia-service
- *
- * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-
-#ifndef _MEDIA_SVC_UTIL_EBOOK_H_
-#define _MEDIA_SVC_UTIL_EBOOK_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-bool _media_svc_pdf_is_keyword_included(const char *path, const char *keyword);
-bool _media_svc_epub_is_keyword_included(const char *path, const char *keyword);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_MEDIA_SVC_UTIL_EBOOK_H_*/