#include "media-svc-hash.h"
#include "media-svc-album.h"
#include "media-svc-localize_ch.h"
-/*For ebook*/
+#include "media-svc-util-pdf.h"
+#include "media-svc-util-epub.h"
+/*For ebook metadata */
#include <zip.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
{
gchar *buf = NULL;
gchar *tmp_buf = NULL;
- int len = 0;
xmlDocPtr doc = NULL;
xmlNodePtr node = NULL;
media_svc_retvm_if(!z, FALSE, "z is NULL");
media_svc_retvm_if(!opf_file, FALSE, "opf_file is NULL");
- tmp_buf = __media_svc_get_zipfile_data(z, "META-INF/container.xml");
- media_svc_retvm_if(!tmp_buf, FALSE, "tmp_buf is NULL");
+ buf = __media_svc_get_zipfile_data(z, "META-INF/container.xml");
+ media_svc_retvm_if(!buf, FALSE, "buf is NULL");
- len = strlen(tmp_buf);
- while (0 < len) {
- len--;
-
- if (tmp_buf[len] == '>')
- break;
- }
-
- buf = g_strndup(tmp_buf, len + 1);
- g_free(tmp_buf);
+ tmp_buf = g_strrstr(buf, ">");
+ if (tmp_buf)
+ *(tmp_buf + 1) = '\0';
doc = xmlParseDoc((const xmlChar *)buf);
g_free(buf);
meta_buf = g_malloc0(end_pos - start_pos + 1);
- if (read(fd, meta_buf, end_pos - start_pos) != end_pos - start_pos) {
- g_free(meta_buf);
- goto NEXT;
- }
-
- if (__media_svc_get_xml_metadata((const xmlChar *)meta_buf, TRUE, content_info)) {
- g_free(meta_buf);
- break;
+ if (read(fd, meta_buf, end_pos - start_pos) == end_pos - start_pos) {
+ if (__media_svc_get_xml_metadata((const xmlChar *)meta_buf, TRUE, content_info)) {
+ g_free(meta_buf);
+ break;
+ }
}
g_free(meta_buf);
- meta_buf = NULL;
-NEXT:
+
start_pos = 0;
end_pos = 0;
}
return false;
}
}
+
+bool _media_svc_is_keyword_included(const char *path, const char *keyword)
+{
+ media_svc_retvm_if(!path, false, "Invalid path");
+ media_svc_retvm_if(!keyword, false, "Invalid keyword");
+
+ if (g_str_has_suffix(path, "epub") || g_str_has_suffix(path, "EPUB"))
+ return _media_svc_epub_is_keyword_included(path, keyword);
+ else
+ return _media_svc_pdf_is_keyword_included(path, keyword);
+}