[evince/wip/chpe/xmp: 10/11] libdocument: Make XMP parser take data length
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/chpe/xmp: 10/11] libdocument: Make XMP parser take data length
- Date: Sat, 4 Dec 2021 00:45:51 +0000 (UTC)
commit c18a7023fe06fc29b136e8af89673c41767b8c94
Author: Christian Persch <chpe src gnome org>
Date: Sat Dec 4 01:45:44 2021 +0100
libdocument: Make XMP parser take data length
backend/djvu/djvu-document.c | 2 +-
backend/pdf/ev-poppler.c | 3 +--
libdocument/ev-document-info.c | 8 +++++---
libdocument/ev-document-info.h | 3 ++-
libdocument/ev-xmp.c | 8 +++++---
libdocument/ev-xmp.h | 1 +
6 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/backend/djvu/djvu-document.c b/backend/djvu/djvu-document.c
index e72508130..078aaa692 100644
--- a/backend/djvu/djvu-document.c
+++ b/backend/djvu/djvu-document.c
@@ -540,7 +540,7 @@ djvu_document_get_info (EvDocument *document)
xmp = ddjvu_anno_get_xmp (anno);
if (xmp != NULL) {
- ev_document_info_set_from_xmp (info, xmp);
+ ev_document_info_set_from_xmp (info, xmp, -1);
}
ddjvu_miniexp_release (djvu_document->d_document, anno);
diff --git a/backend/pdf/ev-poppler.c b/backend/pdf/ev-poppler.c
index b13517c29..0c46984f1 100644
--- a/backend/pdf/ev-poppler.c
+++ b/backend/pdf/ev-poppler.c
@@ -1,4 +1,3 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
/* this file is part of evince, a gnome document viewer
*
* Copyright (C) 2018, Evangelos Rigas <erigas rnd2 org>
@@ -608,7 +607,7 @@ pdf_document_get_info (EvDocument *document)
ev_document_info_take_modified_datetime (info, modified_datetime);
if (metadata != NULL) {
- ev_document_info_set_from_xmp (info, metadata);
+ ev_document_info_set_from_xmp (info, metadata, -1);
g_free (metadata);
}
diff --git a/libdocument/ev-document-info.c b/libdocument/ev-document-info.c
index 5b2362069..84466c0a5 100644
--- a/libdocument/ev-document-info.c
+++ b/libdocument/ev-document-info.c
@@ -227,7 +227,8 @@ ev_document_info_get_modified_datetime (const EvDocumentInfo *info)
/*
* ev_document_info_set_from_xmp:
* @info: a #EvDocumentInfo
- * @xmp: a string containing an XMP document
+ * @xmp: a XMP document
+ * @size: the size of @xmp in bytes, or -1 if @xmp is a NUL-terminated string
*
* Parses the XMP document and sets @info from it.
*
@@ -235,9 +236,10 @@ ev_document_info_get_modified_datetime (const EvDocumentInfo *info)
*/
gboolean
ev_document_info_set_from_xmp (EvDocumentInfo *info,
- const char *xmp)
+ const char *xmp,
+ gssize size)
{
- return ev_xmp_parse (xmp, info);
+ return ev_xmp_parse (xmp, size != -1 ? size : strlen (xmp), info);
}
/* EvDocumentLicense */
diff --git a/libdocument/ev-document-info.h b/libdocument/ev-document-info.h
index 7d3d2a878..5bdd8805c 100644
--- a/libdocument/ev-document-info.h
+++ b/libdocument/ev-document-info.h
@@ -164,7 +164,8 @@ void ev_document_info_take_modified_datetime (EvDocumentInfo *info,
GDateTime *datetime);
EV_PRIVATE
gboolean ev_document_info_set_from_xmp (EvDocumentInfo *info,
- const char *xmp);
+ const char *xmp,
+ gssize size);
/* EvDocumentLicense */
#define EV_TYPE_DOCUMENT_LICENSE (ev_document_license_get_type())
diff --git a/libdocument/ev-xmp.c b/libdocument/ev-xmp.c
index 83ff88327..a19f74f58 100644
--- a/libdocument/ev-xmp.c
+++ b/libdocument/ev-xmp.c
@@ -383,13 +383,15 @@ xmp_get_license (xmlXPathContextPtr xpathCtx)
/*
* ev_xmp_parse:
- * @metadata: a XMP document as a string
+ * @metadata: XMP document data
+ * @size: size of @metadata in bytes
* @info: a #EvDocumentInfo
*
* Returns: %TRUE iff @metadata could be successfully parsed
*/
gboolean
-ev_xmp_parse (const gchar *metadata,
+ev_xmp_parse (const char *metadata,
+ gsize size,
EvDocumentInfo *info)
{
xmlDocPtr doc;
@@ -405,7 +407,7 @@ ev_xmp_parse (const gchar *metadata,
GDateTime *metadata_datetime = NULL;
GDateTime *datetime;
- doc = xmlParseMemory (metadata, strlen (metadata));
+ doc = xmlParseMemory (metadata, size);
if (doc == NULL)
return FALSE; /* invalid xml metadata */
diff --git a/libdocument/ev-xmp.h b/libdocument/ev-xmp.h
index ae59ba14c..43ed3aef0 100644
--- a/libdocument/ev-xmp.h
+++ b/libdocument/ev-xmp.h
@@ -27,6 +27,7 @@
G_BEGIN_DECLS
gboolean ev_xmp_parse (const char *xmp,
+ gsize size,
EvDocumentInfo *info);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]