summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2022-02-15 18:43:16 +0100
committerAlbert Astals Cid <tsdgeos@yahoo.es>2022-02-16 10:43:15 +0000
commit4f2abd3efa1ee013d7e672bad5a2fe58610cdc1d (patch)
treef5b7710467243a8bb16e2008ee2622caf25860c7
parent608c6eaf32252f3798ff0a91d3be5d52fdcdacc0 (diff)
PDFDoc: Make passwords std::optional instead of pointers
Makes it clearer that we're not taking ownership of them
-rw-r--r--cpp/poppler-document.cpp12
-rw-r--r--glib/poppler-document.cc52
-rw-r--r--poppler/CurlPDFDocBuilder.cc2
-rw-r--r--poppler/CurlPDFDocBuilder.h4
-rw-r--r--poppler/FDPDFDocBuilder.cc4
-rw-r--r--poppler/FDPDFDocBuilder.h4
-rw-r--r--poppler/Form.cc12
-rw-r--r--poppler/Form.h8
-rw-r--r--poppler/LocalPDFDocBuilder.cc2
-rw-r--r--poppler/LocalPDFDocBuilder.h4
-rw-r--r--poppler/PDFDoc.cc12
-rw-r--r--poppler/PDFDoc.h13
-rw-r--r--poppler/PDFDocBuilder.h4
-rw-r--r--poppler/PDFDocFactory.cc2
-rw-r--r--poppler/PDFDocFactory.h4
-rw-r--r--poppler/SecurityHandler.cc9
-rw-r--r--poppler/SecurityHandler.h10
-rw-r--r--qt5/src/poppler-document.cc14
-rw-r--r--qt5/src/poppler-form.cc9
-rw-r--r--qt5/src/poppler-pdf-converter.cc6
-rw-r--r--qt5/src/poppler-private.h13
-rw-r--r--qt6/src/poppler-document.cc14
-rw-r--r--qt6/src/poppler-form.cc9
-rw-r--r--qt6/src/poppler-pdf-converter.cc6
-rw-r--r--qt6/src/poppler-private.h13
-rw-r--r--test/image-embedding.cc3
-rw-r--r--test/pdf-fullrewrite.cc10
-rw-r--r--test/pdf-inspector.cc2
-rw-r--r--test/perf-test.cc4
-rw-r--r--utils/pdfattach.cc2
-rw-r--r--utils/pdfdetach.cc16
-rw-r--r--utils/pdffonts.cc10
-rw-r--r--utils/pdfimages.cc18
-rw-r--r--utils/pdfinfo.cc18
-rw-r--r--utils/pdfseparate.cc4
-rw-r--r--utils/pdfsig.cc10
-rw-r--r--utils/pdftocairo.cc16
-rw-r--r--utils/pdftohtml.cc18
-rw-r--r--utils/pdftoppm.cc19
-rw-r--r--utils/pdftops.cc18
-rw-r--r--utils/pdftotext.cc18
-rw-r--r--utils/pdfunite.cc2
42 files changed, 153 insertions, 277 deletions
diff --git a/cpp/poppler-document.cpp b/cpp/poppler-document.cpp
index c134c5f8..5b59c2f8 100644
--- a/cpp/poppler-document.cpp
+++ b/cpp/poppler-document.cpp
@@ -52,18 +52,14 @@ using namespace poppler;
document_private::document_private(std::unique_ptr<GooString> &&file_path, const std::string &owner_password, const std::string &user_password) : document_private()
{
- GooString goo_owner_password(owner_password.c_str());
- GooString goo_user_password(user_password.c_str());
- doc = new PDFDoc(std::move(file_path), &goo_owner_password, &goo_user_password);
+ doc = new PDFDoc(std::move(file_path), GooString(owner_password.c_str()), GooString(user_password.c_str()));
}
document_private::document_private(byte_array *file_data, const std::string &owner_password, const std::string &user_password) : document_private()
{
file_data->swap(doc_data);
MemStream *memstr = new MemStream(&doc_data[0], 0, doc_data.size(), Object(objNull));
- GooString goo_owner_password(owner_password.c_str());
- GooString goo_user_password(user_password.c_str());
- doc = new PDFDoc(memstr, &goo_owner_password, &goo_user_password);
+ doc = new PDFDoc(memstr, GooString(owner_password.c_str()), GooString(user_password.c_str()));
}
document_private::document_private(const char *file_data, int file_data_length, const std::string &owner_password, const std::string &user_password) : document_private()
@@ -71,9 +67,7 @@ document_private::document_private(const char *file_data, int file_data_length,
raw_doc_data = file_data;
raw_doc_data_length = file_data_length;
MemStream *memstr = new MemStream(const_cast<char *>(raw_doc_data), 0, raw_doc_data_length, Object(objNull));
- GooString goo_owner_password(owner_password.c_str());
- GooString goo_user_password(user_password.c_str());
- doc = new PDFDoc(memstr, &goo_owner_password, &goo_user_password);
+ doc = new PDFDoc(memstr, GooString(owner_password.c_str()), GooString(user_password.c_str()));
}
document_private::document_private() : GlobalParamsIniter(detail::error_function), doc(nullptr), raw_doc_data(nullptr), raw_doc_data_length(0), is_locked(false) { }
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index 00991937..7da76987 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -159,16 +159,15 @@ static PopplerDocument *_poppler_document_new_from_pdfdoc(std::unique_ptr<Global
return document;
}
-static GooString *poppler_password_to_latin1(const gchar *password)
+static std::optional<GooString> poppler_password_to_latin1(const gchar *password)
{
gchar *password_latin;
- GooString *password_g;
if (!password)
- return nullptr;
+ return {};
password_latin = g_convert(password, -1, "ISO-8859-1", "UTF-8", nullptr, nullptr, nullptr);
- password_g = new GooString(password_latin);
+ std::optional<GooString> password_g = GooString(password_latin);
g_free(password_latin);
return password_g;
@@ -189,7 +188,6 @@ static GooString *poppler_password_to_latin1(const gchar *password)
PopplerDocument *poppler_document_new_from_file(const char *uri, const char *password, GError **error)
{
PDFDoc *newDoc;
- GooString *password_g;
char *filename;
auto initer = std::make_unique<GlobalParamsIniter>(_poppler_error_cb);
@@ -198,7 +196,7 @@ PopplerDocument *poppler_document_new_from_file(const char *uri, const char *pas
if (!filename)
return nullptr;
- password_g = poppler_password_to_latin1(password);
+ const std::optional<GooString> password_g = poppler_password_to_latin1(password);
#ifdef G_OS_WIN32
wchar_t *filenameW;
@@ -216,9 +214,7 @@ PopplerDocument *poppler_document_new_from_file(const char *uri, const char *pas
if (!newDoc->isOk() && newDoc->getErrorCode() == errEncrypted && password) {
/* Try again with original password (which comes from GTK in UTF8) Issue #824 */
delete newDoc;
- delete password_g;
- password_g = new GooString(password);
- newDoc = new PDFDoc(filenameW, length, password_g, password_g);
+ newDoc = new PDFDoc(filenameW, length, GooString(password), GooString(password));
}
delete[] filenameW;
#else
@@ -226,15 +222,11 @@ PopplerDocument *poppler_document_new_from_file(const char *uri, const char *pas
if (!newDoc->isOk() && newDoc->getErrorCode() == errEncrypted && password) {
/* Try again with original password (which comes from GTK in UTF8) Issue #824 */
delete newDoc;
- delete password_g;
- password_g = new GooString(password);
- newDoc = new PDFDoc(std::make_unique<GooString>(filename), password_g, password_g);
+ newDoc = new PDFDoc(std::make_unique<GooString>(filename), GooString(password), GooString(password));
}
#endif
g_free(filename);
- delete password_g;
-
return _poppler_document_new_from_pdfdoc(std::move(initer), newDoc, error);
}
@@ -262,24 +254,20 @@ PopplerDocument *poppler_document_new_from_data(char *data, int length, const ch
{
PDFDoc *newDoc;
MemStream *str;
- GooString *password_g;
auto initer = std::make_unique<GlobalParamsIniter>(_poppler_error_cb);
// create stream
str = new MemStream(data, 0, length, Object(objNull));
- password_g = poppler_password_to_latin1(password);
+ const std::optional<GooString> password_g = poppler_password_to_latin1(password);
newDoc = new PDFDoc(str, password_g, password_g);
if (!newDoc->isOk() && newDoc->getErrorCode() == errEncrypted && password) {
/* Try again with original password (which comes from GTK in UTF8) Issue #824 */
str = dynamic_cast<MemStream *>(str->copy());
delete newDoc;
- delete password_g;
- password_g = new GooString(password);
- newDoc = new PDFDoc(str, password_g, password_g);
+ newDoc = new PDFDoc(str, GooString(password), GooString(password));
}
- delete password_g;
return _poppler_document_new_from_pdfdoc(std::move(initer), newDoc, error);
}
@@ -315,7 +303,6 @@ PopplerDocument *poppler_document_new_from_bytes(GBytes *bytes, const char *pass
{
PDFDoc *newDoc;
BytesStream *str;
- GooString *password_g;
g_return_val_if_fail(bytes != nullptr, nullptr);
g_return_val_if_fail(error == nullptr || *error == nullptr, nullptr);
@@ -325,17 +312,14 @@ PopplerDocument *poppler_document_new_from_bytes(GBytes *bytes, const char *pass
// create stream
str = new BytesStream(bytes, Object(objNull));
- password_g = poppler_password_to_latin1(password);
+ const std::optional<GooString> password_g = poppler_password_to_latin1(password);
newDoc = new PDFDoc(str, password_g, password_g);
if (!newDoc->isOk() && newDoc->getErrorCode() == errEncrypted && password) {
/* Try again with original password (which comes from GTK in UTF8) Issue #824 */
str = dynamic_cast<BytesStream *>(str->copy());
delete newDoc;
- delete password_g;
- password_g = new GooString(password);
- newDoc = new PDFDoc(str, password_g, password_g);
+ newDoc = new PDFDoc(str, GooString(password), GooString(password));
}
- delete password_g;
return _poppler_document_new_from_pdfdoc(std::move(initer), newDoc, error);
}
@@ -367,7 +351,6 @@ PopplerDocument *poppler_document_new_from_stream(GInputStream *stream, goffset
{
PDFDoc *newDoc;
BaseStream *str;
- GooString *password_g;
g_return_val_if_fail(G_IS_INPUT_STREAM(stream), NULL);
g_return_val_if_fail(length == (goffset)-1 || length > 0, NULL);
@@ -393,17 +376,14 @@ PopplerDocument *poppler_document_new_from_stream(GInputStream *stream, goffset
str = new CachedFileStream(cachedFile, 0, false, cachedFile->getLength(), Object(objNull));
}
- password_g = poppler_password_to_latin1(password);
+ const std::optional<GooString> password_g = poppler_password_to_latin1(password);
newDoc = new PDFDoc(str, password_g, password_g);
if (!newDoc->isOk() && newDoc->getErrorCode() == errEncrypted && password) {
/* Try again with original password (which comes from GTK in UTF8) Issue #824 */
str = str->copy();
delete newDoc;
- delete password_g;
- password_g = new GooString(password);
- newDoc = new PDFDoc(str, password_g, password_g);
+ newDoc = new PDFDoc(str, GooString(password), GooString(password));
}
- delete password_g;
return _poppler_document_new_from_pdfdoc(std::move(initer), newDoc, error);
}
@@ -476,7 +456,6 @@ PopplerDocument *poppler_document_new_from_fd(int fd, const char *password, GErr
int flags;
BaseStream *stream;
PDFDoc *newDoc;
- GooString *password_g;
g_return_val_if_fail(fd != -1, nullptr);
@@ -521,17 +500,14 @@ PopplerDocument *poppler_document_new_from_fd(int fd, const char *password, GErr
stream = new FileStream(file, 0, false, file->size(), Object(objNull));
}
- password_g = poppler_password_to_latin1(password);
+ const std::optional<GooString> password_g = poppler_password_to_latin1(password);
newDoc = new PDFDoc(stream, password_g, password_g);
if (!newDoc->isOk() && newDoc->getErrorCode() == errEncrypted && password) {
/* Try again with original password (which comes from GTK in UTF8) Issue #824 */
stream = stream->copy();
delete newDoc;
- delete password_g;
- password_g = new GooString(password);
- newDoc = new PDFDoc(stream, password_g, password_g);
+ newDoc = new PDFDoc(stream, GooString(password), GooString(password));
}
- delete password_g;
return _poppler_document_new_from_pdfdoc(std::move(initer), newDoc, error);
}
diff --git a/poppler/CurlPDFDocBuilder.cc b/poppler/CurlPDFDocBuilder.cc
index 70e5a703..491711ca 100644
--- a/poppler/CurlPDFDocBuilder.cc
+++ b/poppler/CurlPDFDocBuilder.cc
@@ -22,7 +22,7 @@
// CurlPDFDocBuilder
//------------------------------------------------------------------------
-std::unique_ptr<PDFDoc> CurlPDFDocBuilder::buildPDFDoc(const GooString &uri, GooString *ownerPassword, GooString *userPassword, void *guiDataA)
+std::unique_ptr<PDFDoc> CurlPDFDocBuilder::buildPDFDoc(const GooString &uri, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword, void *guiDataA)
{
CachedFile *cachedFile = new CachedFile(new CurlCachedFileLoader(), uri.copy());
diff --git a/poppler/CurlPDFDocBuilder.h b/poppler/CurlPDFDocBuilder.h
index 601f0304..f1106b35 100644
--- a/poppler/CurlPDFDocBuilder.h
+++ b/poppler/CurlPDFDocBuilder.h
@@ -5,7 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib@hiberis.nl>
-// Copyright 2010, 2018 Albert Astals Cid <aacid@kde.org>
+// Copyright 2010, 2018, 2022 Albert Astals Cid <aacid@kde.org>
// Copyright 2021 Oliver Sander <oliver.sander@tu-dresden.de>
//
//========================================================================
@@ -25,7 +25,7 @@ class CurlPDFDocBuilder : public PDFDocBuilder
{
public:
- std::unique_ptr<PDFDoc> buildPDFDoc(const GooString &uri, GooString *ownerPassword = nullptr, GooString *userPassword = nullptr, void *guiDataA = nullptr) override;
+ std::unique_ptr<PDFDoc> buildPDFDoc(const GooString &uri, const std::optional<GooString> &ownerPassword = {}, const std::optional<GooString> &userPassword = {}, void *guiDataA = nullptr) override;
bool supports(const GooString &uri) override;
};
diff --git a/poppler/FDPDFDocBuilder.cc b/poppler/FDPDFDocBuilder.cc
index a35e41af..dab95510 100644
--- a/poppler/FDPDFDocBuilder.cc
+++ b/poppler/FDPDFDocBuilder.cc
@@ -5,7 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib@hiberis.nl>
-// Copyright 2010, 2017, 2021 Albert Astals Cid <aacid@kde.org>
+// Copyright 2010, 2017, 2021, 2022 Albert Astals Cid <aacid@kde.org>
// Copyright 2021 Oliver Sander <oliver.sander@tu-dresden.de>
// Copyright 2021 Christian Persch <chpe@src.gnome.org>
//
@@ -33,7 +33,7 @@ int FileDescriptorPDFDocBuilder::parseFdFromUri(const GooString &uri)
return fd;
}
-std::unique_ptr<PDFDoc> FileDescriptorPDFDocBuilder::buildPDFDoc(const GooString &uri, GooString *ownerPassword, GooString *userPassword, void *guiDataA)
+std::unique_ptr<PDFDoc> FileDescriptorPDFDocBuilder::buildPDFDoc(const GooString &uri, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword, void *guiDataA)
{
const auto fd = parseFdFromUri(uri);
if (fd == -1)
diff --git a/poppler/FDPDFDocBuilder.h b/poppler/FDPDFDocBuilder.h
index d659e05f..42c0ff6b 100644
--- a/poppler/FDPDFDocBuilder.h
+++ b/poppler/FDPDFDocBuilder.h
@@ -5,7 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib@hiberis.nl>
-// Copyright 2010, 2018 Albert Astals Cid <aacid@kde.org>
+// Copyright 2010, 2018, 2022 Albert Astals Cid <aacid@kde.org>
// Copyright 2021 Oliver Sander <oliver.sander@tu-dresden.de>
// Copyright 2021 Christian Persch <chpe@src.gnome.org>
//
@@ -26,7 +26,7 @@ class FileDescriptorPDFDocBuilder : public PDFDocBuilder
{
public:
- std::unique_ptr<PDFDoc> buildPDFDoc(const GooString &uri, GooString *ownerPassword = nullptr, GooString *userPassword = nullptr, void *guiDataA = nullptr) override;
+ std::unique_ptr<PDFDoc> buildPDFDoc(const GooString &uri, const std::optional<GooString> &ownerPassword = {}, const std::optional<GooString> &userPassword = {}, void *guiDataA = nullptr) override;
bool supports(const GooString &uri) override;
private:
diff --git a/poppler/Form.cc b/poppler/Form.cc
index 139e9392..65e972c9 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -573,8 +573,8 @@ static bool hashFileRange(FILE *f, SignatureHandler *handler, Goffset start, Gof
}
#endif
-bool FormWidgetSignature::signDocument(const char *saveFilename, const char *certNickname, const char *digestName, const char *password, const GooString *reason, const GooString *location, const GooString *ownerPassword,
- const GooString *userPassword)
+bool FormWidgetSignature::signDocument(const char *saveFilename, const char *certNickname, const char *digestName, const char *password, const GooString *reason, const GooString *location, const std::optional<GooString> &ownerPassword,
+ const std::optional<GooString> &userPassword)
{
#ifdef ENABLE_NSS3
if (!certNickname) {
@@ -659,9 +659,9 @@ bool FormWidgetSignature::signDocument(const char *saveFilename, const char *cer
#endif
}
-bool FormWidgetSignature::signDocumentWithAppearance(const char *saveFilename, const char *certNickname, const char *digestName, const char *password, const GooString *reason, const GooString *location, const GooString *ownerPassword,
- const GooString *userPassword, const GooString &signatureText, const GooString &signatureTextLeft, double fontSize, std::unique_ptr<AnnotColor> &&fontColor, double borderWidth,
- std::unique_ptr<AnnotColor> &&borderColor, std::unique_ptr<AnnotColor> &&backgroundColor)
+bool FormWidgetSignature::signDocumentWithAppearance(const char *saveFilename, const char *certNickname, const char *digestName, const char *password, const GooString *reason, const GooString *location,
+ const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword, const GooString &signatureText, const GooString &signatureTextLeft, double fontSize,
+ std::unique_ptr<AnnotColor> &&fontColor, double borderWidth, std::unique_ptr<AnnotColor> &&borderColor, std::unique_ptr<AnnotColor> &&backgroundColor)
{
// Set the appearance
GooString *aux = getField()->getDefaultAppearance();
@@ -703,7 +703,7 @@ bool FormWidgetSignature::signDocumentWithAppearance(const char *saveFilename, c
}
// Get start and end file position of objNum in the PDF named filename.
-bool FormWidgetSignature::getObjectStartEnd(const GooString &filename, int objNum, Goffset *objStart, Goffset *objEnd, const GooString *ownerPassword, const GooString *userPassword)
+bool FormWidgetSignature::getObjectStartEnd(const GooString &filename, int objNum, Goffset *objStart, Goffset *objEnd, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword)
{
PDFDoc newDoc(std::unique_ptr<GooString>(filename.copy()), ownerPassword, userPassword);
if (!newDoc.isOk())
diff --git a/poppler/Form.h b/poppler/Form.h
index 5d3c931f..76ca9648 100644
--- a/poppler/Form.h
+++ b/poppler/Form.h
@@ -312,12 +312,12 @@ public:
// field "ByteRange" in the dictionary "V".
// Arguments reason and location are UTF-16 big endian strings with BOM. An empty string and nullptr are acceptable too.
// Returns success.
- bool signDocument(const char *filename, const char *certNickname, const char *digestName, const char *password, const GooString *reason = nullptr, const GooString *location = nullptr, const GooString *ownerPassword = nullptr,
- const GooString *userPassword = nullptr);
+ bool signDocument(const char *filename, const char *certNickname, const char *digestName, const char *password, const GooString *reason = nullptr, const GooString *location = nullptr, const std::optional<GooString> &ownerPassword = {},
+ const std::optional<GooString> &userPassword = {});
// Same as above but adds text, font color, etc.
bool signDocumentWithAppearance(const char *filename, const char *certNickname, const char *digestName, const char *password, const GooString *reason = nullptr, const GooString *location = nullptr,
- const GooString *ownerPassword = nullptr, const GooString *userPassword = nullptr, const GooString &signatureText = {}, const GooString &signatureTextLeft = {}, double fontSize = {},
+ const std::optional<GooString> &ownerPassword = {}, const std::optional<GooString> &userPassword = {}, const GooString &signatureText = {}, const GooString &signatureTextLeft = {}, double fontSize = {},
std::unique_ptr<AnnotColor> &&fontColor = {}, double borderWidth = {}, std::unique_ptr<AnnotColor> &&borderColor = {}, std::unique_ptr<AnnotColor> &&backgroundColor = {});
// checks the length encoding of the signature and returns the hex encoded signature
@@ -329,7 +329,7 @@ public:
private:
bool createSignature(Object &vObj, Ref vRef, const GooString &name, const GooString *signature, const GooString *reason = nullptr, const GooString *location = nullptr);
- bool getObjectStartEnd(const GooString &filename, int objNum, Goffset *objStart, Goffset *objEnd, const GooString *ownerPassword, const GooString *userPassword);
+ bool getObjectStartEnd(const GooString &filename, int objNum, Goffset *objStart, Goffset *objEnd, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword);
bool updateOffsets(FILE *f, Goffset objStart, Goffset objEnd, Goffset *sigStart, Goffset *sigEnd, Goffset *fileSize);
bool updateSignature(FILE *f, Goffset sigStart, Goffset sigEnd, const GooString *signature);
diff --git a/poppler/LocalPDFDocBuilder.cc b/poppler/LocalPDFDocBuilder.cc
index bd78041d..bf4856e2 100644
--- a/poppler/LocalPDFDocBuilder.cc
+++ b/poppler/LocalPDFDocBuilder.cc
@@ -18,7 +18,7 @@
// LocalPDFDocBuilder
//------------------------------------------------------------------------
-std::unique_ptr<PDFDoc> LocalPDFDocBuilder::buildPDFDoc(const GooString &uri, GooString *ownerPassword, GooString *userPassword, void *guiDataA)
+std::unique_ptr<PDFDoc> LocalPDFDocBuilder::buildPDFDoc(const GooString &uri, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword, void *guiDataA)
{
if (uri.cmpN("file://", 7) == 0) {
std::unique_ptr<GooString> fileName(uri.copy());
diff --git a/poppler/LocalPDFDocBuilder.h b/poppler/LocalPDFDocBuilder.h
index f82bdf63..0595d1e6 100644
--- a/poppler/LocalPDFDocBuilder.h
+++ b/poppler/LocalPDFDocBuilder.h
@@ -5,7 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib@hiberis.nl>
-// Copyright 2010, 2018 Albert Astals Cid <aacid@kde.org>
+// Copyright 2010, 2018, 2022 Albert Astals Cid <aacid@kde.org>
// Copyright 2021 Oliver Sander <oliver.sander@tu-dresden.de>
//
//========================================================================
@@ -25,7 +25,7 @@ class LocalPDFDocBuilder : public PDFDocBuilder
{
public:
- std::unique_ptr<PDFDoc> buildPDFDoc(const GooString &uri, GooString *ownerPassword = nullptr, GooString *userPassword = nullptr, void *guiDataA = nullptr) override;
+ std::unique_ptr<PDFDoc> buildPDFDoc(const GooString &uri, const std::optional<GooString> &ownerPassword = {}, const std::optional<GooString> &userPassword = {}, void *guiDataA = nullptr) override;
bool supports(const GooString &uri) override;
};
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 71d28603..a2d36ac1 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -121,7 +121,7 @@
PDFDoc::PDFDoc() { }
-PDFDoc::PDFDoc(std::unique_ptr<GooString> &&fileNameA, const GooString *ownerPassword, const GooString *userPassword, void *guiDataA, const std::function<void()> &xrefReconstructedCallback)
+PDFDoc::PDFDoc(std::unique_ptr<GooString> &&fileNameA, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword, void *guiDataA, const std::function<void()> &xrefReconstructedCallback)
: fileName(std::move(fileNameA)), guiData(guiDataA)
{
#ifdef _WIN32
@@ -156,7 +156,7 @@ PDFDoc::PDFDoc(std::unique_ptr<GooString> &&fileNameA, const GooString *ownerPas
}
#ifdef _WIN32
-PDFDoc::PDFDoc(wchar_t *fileNameA, int fileNameLen, GooString *ownerPassword, GooString *userPassword, void *guiDataA, const std::function<void()> &xrefReconstructedCallback) : guiData(guiDataA)
+PDFDoc::PDFDoc(wchar_t *fileNameA, int fileNameLen, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword, void *guiDataA, const std::function<void()> &xrefReconstructedCallback) : guiData(guiDataA)
{
OSVERSIONINFO version;
@@ -192,7 +192,7 @@ PDFDoc::PDFDoc(wchar_t *fileNameA, int fileNameLen, GooString *ownerPassword, Go
}
#endif
-PDFDoc::PDFDoc(BaseStream *strA, const GooString *ownerPassword, const GooString *userPassword, void *guiDataA, const std::function<void()> &xrefReconstructedCallback) : guiData(guiDataA)
+PDFDoc::PDFDoc(BaseStream *strA, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword, void *guiDataA, const std::function<void()> &xrefReconstructedCallback) : guiData(guiDataA)
{
if (strA->getFileName()) {
fileName.reset(strA->getFileName()->copy());
@@ -209,7 +209,7 @@ PDFDoc::PDFDoc(BaseStream *strA, const GooString *ownerPassword, const GooString
ok = setup(ownerPassword, userPassword, xrefReconstructedCallback);
}
-bool PDFDoc::setup(const GooString *ownerPassword, const GooString *userPassword, const std::function<void()> &xrefReconstructedCallback)
+bool PDFDoc::setup(const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword, const std::function<void()> &xrefReconstructedCallback)
{
pdfdocLocker();
@@ -384,7 +384,7 @@ void PDFDoc::checkHeader()
// We don't do the version check. Don't add it back in.
}
-bool PDFDoc::checkEncryption(const GooString *ownerPassword, const GooString *userPassword)
+bool PDFDoc::checkEncryption(const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword)
{
bool encrypted;
bool ret;
@@ -2078,7 +2078,7 @@ bool PDFDoc::hasJavascript()
bool PDFDoc::sign(const char *saveFilename, const char *certNickname, const char *password, GooString *partialFieldName, int page, const PDFRectangle &rect, const GooString &signatureText, const GooString &signatureTextLeft,
double fontSize, double leftFontSize, std::unique_ptr<AnnotColor> &&fontColor, double borderWidth, std::unique_ptr<AnnotColor> &&borderColor, std::unique_ptr<AnnotColor> &&backgroundColor, const GooString *reason,
- const GooString *location, const std::string &imagePath, const GooString *ownerPassword, const GooString *userPassword)
+ const GooString *location, const std::string &imagePath, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword)
{
::Page *destPage = getPage(page);
if (destPage == nullptr) {
diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h
index 5ca5b8da..5c9635d6 100644
--- a/poppler/PDFDoc.h
+++ b/poppler/PDFDoc.h
@@ -129,13 +129,14 @@ enum PDFSubtypeConformance
class POPPLER_PRIVATE_EXPORT PDFDoc
{
public:
- explicit PDFDoc(std::unique_ptr<GooString> &&fileNameA, const GooString *ownerPassword = nullptr, const GooString *userPassword = nullptr, void *guiDataA = nullptr, const std::function<void()> &xrefReconstructedCallback = {});
+ explicit PDFDoc(std::unique_ptr<GooString> &&fileNameA, const std::optional<GooString> &ownerPassword = {}, const std::optional<GooString> &userPassword = {}, void *guiDataA = nullptr,
+ const std::function<void()> &xrefReconstructedCallback = {});
#ifdef _WIN32
- PDFDoc(wchar_t *fileNameA, int fileNameLen, GooString *ownerPassword = nullptr, GooString *userPassword = nullptr, void *guiDataA = nullptr, const std::function<void()> &xrefReconstructedCallback = {});
+ PDFDoc(wchar_t *fileNameA, int fileNameLen, const std::optional<GooString> &ownerPassword = {}, const std::optional<GooString> &userPassword = {}, void *guiDataA = nullptr, const std::function<void()> &xrefReconstructedCallback = {});
#endif
- explicit PDFDoc(BaseStream *strA, const GooString *ownerPassword = nullptr, const GooString *userPassword = nullptr, void *guiDataA = nullptr, const std::function<void()> &xrefReconstructedCallback = {});
+ explicit PDFDoc(BaseStream *strA, const std::optional<GooString> &ownerPassword = {}, const std::optional<GooString> &userPassword = {}, void *guiDataA = nullptr, const std::function<void()> &xrefReconstructedCallback = {});
~PDFDoc();
PDFDoc(const PDFDoc &) = delete;
@@ -338,7 +339,7 @@ public:
// sign() takes ownership of partialFieldName.
bool sign(const char *saveFilename, const char *certNickname, const char *password, GooString *partialFieldName, int page, const PDFRectangle &rect, const GooString &signatureText, const GooString &signatureTextLeft, double fontSize,
double leftFontSize, std::unique_ptr<AnnotColor> &&fontColor, double borderWidth, std::unique_ptr<AnnotColor> &&borderColor, std::unique_ptr<AnnotColor> &&backgroundColor, const GooString *reason = nullptr,
- const GooString *location = nullptr, const std::string &imagePath = "", const GooString *ownerPassword = nullptr, const GooString *userPassword = nullptr);
+ const GooString *location = nullptr, const std::string &imagePath = "", const std::optional<GooString> &ownerPassword = {}, const std::optional<GooString> &userPassword = {});
private:
// insert referenced objects in XRef
@@ -368,10 +369,10 @@ private:
Hints *getHints();
PDFDoc();
- bool setup(const GooString *ownerPassword, const GooString *userPassword, const std::function<void()> &xrefReconstructedCallback);
+ bool setup(const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword, const std::function<void()> &xrefReconstructedCallback);
bool checkFooter();
void checkHeader();
- bool checkEncryption(const GooString *ownerPassword, const GooString *userPassword);
+ bool checkEncryption(const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword);
void extractPDFSubtype();
// Get the offset of the start xref table.
diff --git a/poppler/PDFDocBuilder.h b/poppler/PDFDocBuilder.h
index a9231f01..d0bd1ea6 100644
--- a/poppler/PDFDocBuilder.h
+++ b/poppler/PDFDocBuilder.h
@@ -5,7 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib@hiberis.nl>
-// Copyright 2010, 2018, 2020 Albert Astals Cid <aacid@kde.org>
+// Copyright 2010, 2018, 2020, 2022 Albert Astals Cid <aacid@kde.org>
// Copyright 2021 Oliver Sander <oliver.sander@tu-dresden.de>
//
//========================================================================
@@ -38,7 +38,7 @@ public:
// Builds a new PDFDoc. Returns a PDFDoc. You should check this PDFDoc
// with PDFDoc::isOk() for failures.
// The caller is responsible for deleting ownerPassword, userPassWord and guiData.
- virtual std::unique_ptr<PDFDoc> buildPDFDoc(const GooString &uri, GooString *ownerPassword = nullptr, GooString *userPassword = nullptr, void *guiDataA = nullptr) = 0;
+ virtual std::unique_ptr<PDFDoc> buildPDFDoc(const GooString &uri, const std::optional<GooString> &ownerPassword = {}, const std::optional<GooString> &userPassword = {}, void *guiDataA = nullptr) = 0;
// Returns true if the builder supports building a PDFDoc from the URI.
virtual bool supports(const GooString &uri) = 0;
diff --git a/poppler/PDFDocFactory.cc b/poppler/PDFDocFactory.cc
index 9e665977..e4db3e49 100644
--- a/poppler/PDFDocFactory.cc
+++ b/poppler/PDFDocFactory.cc
@@ -54,7 +54,7 @@ PDFDocFactory::~PDFDocFactory()
}
}
-std::unique_ptr<PDFDoc> PDFDocFactory::createPDFDoc(const GooString &uri, GooString *ownerPassword, GooString *userPassword, void *guiDataA)
+std::unique_ptr<PDFDoc> PDFDocFactory::createPDFDoc(const GooString &uri, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword, void *guiDataA)
{
for (int i = builders->size() - 1; i >= 0; i--) {
PDFDocBuilder *builder = (*builders)[i];
diff --git a/poppler/PDFDocFactory.h b/poppler/PDFDocFactory.h
index 30ce72ab..e84aca46 100644
--- a/poppler/PDFDocFactory.h
+++ b/poppler/PDFDocFactory.h
@@ -5,7 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib@hiberis.nl>
-// Copyright 2010, 2018, 2021 Albert Astals Cid <aacid@kde.org>
+// Copyright 2010, 2018, 2021, 2022 Albert Astals Cid <aacid@kde.org>
// Copyright 2019, 2021 Oliver Sander <oliver.sander@tu-dresden.de>
//
//========================================================================
@@ -46,7 +46,7 @@ public:
// Create a PDFDoc. Returns a PDFDoc. You should check this PDFDoc
// with PDFDoc::isOk() for failures.
// The caller is responsible for deleting ownerPassword, userPassWord and guiData.
- std::unique_ptr<PDFDoc> createPDFDoc(const GooString &uri, GooString *ownerPassword = nullptr, GooString *userPassword = nullptr, void *guiDataA = nullptr);
+ std::unique_ptr<PDFDoc> createPDFDoc(const GooString &uri, const std::optional<GooString> &ownerPassword = {}, const std::optional<GooString> &userPassword = {}, void *guiDataA = nullptr);
// Extend supported URIs with the ones from the PDFDocBuilder.
void registerPDFDocBuilder(PDFDocBuilder *pdfDocBuilder);
diff --git a/poppler/SecurityHandler.cc b/poppler/SecurityHandler.cc
index 91cf72c8..b4635119 100644
--- a/poppler/SecurityHandler.cc
+++ b/poppler/SecurityHandler.cc
@@ -13,7 +13,7 @@
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
-// Copyright (C) 2010, 2012, 2015, 2017, 2018, 2020, 2021 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2010, 2012, 2015, 2017, 2018, 2020-2022 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2013 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2014 Fabio D'Urso <fabiodurso@hotmail.it>
// Copyright (C) 2016 Alok Anand <alok4nand@gmail.com>
@@ -62,7 +62,7 @@ SecurityHandler::SecurityHandler(PDFDoc *docA)
SecurityHandler::~SecurityHandler() { }
-bool SecurityHandler::checkEncryption(const GooString *ownerPassword, const GooString *userPassword)
+bool SecurityHandler::checkEncryption(const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword)
{
void *authData;
@@ -77,8 +77,7 @@ bool SecurityHandler::checkEncryption(const GooString *ownerPassword, const GooS
}
if (!ok) {
if (!ownerPassword && !userPassword) {
- GooString dummy;
- return checkEncryption(&dummy, &dummy);
+ return checkEncryption(GooString(), GooString());
} else {
error(errCommandLine, -1, "Incorrect password");
}
@@ -291,7 +290,7 @@ bool StandardSecurityHandler::isUnencrypted() const
return encVersion == -1 && encRevision == -1;
}
-void *StandardSecurityHandler::makeAuthData(const GooString *ownerPassword, const GooString *userPassword)
+void *StandardSecurityHandler::makeAuthData(const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword)
{
return new StandardAuthData(ownerPassword ? ownerPassword->copy() : nullptr, userPassword ? userPassword->copy() : nullptr);
}
diff --git a/poppler/SecurityHandler.h b/poppler/SecurityHandler.h
index 42dc05d4..de10f23d 100644
--- a/poppler/SecurityHandler.h
+++ b/poppler/SecurityHandler.h
@@ -13,7 +13,7 @@
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
-// Copyright (C) 2012, 2018, 2020, 2021 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2012, 2018, 2020-2022 Albert Astals Cid <aacid@kde.org>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -27,6 +27,8 @@
#include "Object.h"
+#include <optional>
+
class GooString;
class PDFDoc;
@@ -57,12 +59,12 @@ public:
// document can be opened (if it's unencrypted, or if a correct
// password is obtained); false otherwise (encrypted and no correct
// password).
- bool checkEncryption(const GooString *ownerPassword, const GooString *userPassword);
+ bool checkEncryption(const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword);
// Create authorization data for the specified owner and user
// passwords. If the security handler doesn't support "batch" mode,
// this function should return NULL.
- virtual void *makeAuthData(const GooString *ownerPassword, const GooString *userPassword) = 0;
+ virtual void *makeAuthData(const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword) = 0;
// Free the authorization data returned by makeAuthData or
// getAuthData.
@@ -99,7 +101,7 @@ public:
~StandardSecurityHandler() override;
bool isUnencrypted() const override;
- void *makeAuthData(const GooString *ownerPassword, const GooString *userPassword) override;
+ void *makeAuthData(const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword) override;
void freeAuthData(void *authData) override;
bool authorize(void *authData) override;
int getPermissionFlags() const override { return permFlags; }
diff --git a/qt5/src/poppler-document.cc b/qt5/src/poppler-document.cc
index be4d7119..6ee0a474 100644
--- a/qt5/src/poppler-document.cc
+++ b/qt5/src/poppler-document.cc
@@ -1,7 +1,7 @@
/* poppler-document.cc: qt interface to poppler
* Copyright (C) 2005, Net Integration Technologies, Inc.
* Copyright (C) 2005, 2008, Brad Hards <bradh@frogmouth.net>
- * Copyright (C) 2005-2010, 2012, 2013, 2015, 2017-2021, Albert Astals Cid <aacid@kde.org>
+ * Copyright (C) 2005-2010, 2012, 2013, 2015, 2017-2022, Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2006-2010, Pino Toscano <pino@kde.org>
* Copyright (C) 2010, 2011 Hib Eris <hib@hiberis.nl>
* Copyright (C) 2012 Koji Otani <sho@bbr.jp>
@@ -67,20 +67,20 @@ namespace Poppler {
Document *Document::load(const QString &filePath, const QByteArray &ownerPassword, const QByteArray &userPassword)
{
- DocumentData *doc = new DocumentData(filePath, new GooString(ownerPassword.data()), new GooString(userPassword.data()));
+ DocumentData *doc = new DocumentData(filePath, GooString(ownerPassword.data()), GooString(userPassword.data()));
return DocumentData::checkDocument(doc);
}
Document *Document::load(QIODevice *device, const QByteArray &ownerPassword, const QByteArray &userPassword)
{
- DocumentData *doc = new DocumentData(device, new GooString(ownerPassword.data()), new GooString(userPassword.data()));
+ DocumentData *doc = new DocumentData(device, GooString(ownerPassword.data()), GooString(userPassword.data()));
return DocumentData::checkDocument(doc);
}
Document *Document::loadFromData(const QByteArray &fileContents, const QByteArray &ownerPassword, const QByteArray &userPassword)
{
// create stream
- DocumentData *doc = new DocumentData(fileContents, new GooString(ownerPassword.data()), new GooString(userPassword.data()));
+ DocumentData *doc = new DocumentData(fileContents, GooString(ownerPassword.data()), GooString(userPassword.data()));
return DocumentData::checkDocument(doc);
}
@@ -134,11 +134,11 @@ bool Document::unlock(const QByteArray &ownerPassword, const QByteArray &userPas
/* racier then it needs to be */
DocumentData *doc2;
if (!m_doc->fileContents.isEmpty()) {
- doc2 = new DocumentData(m_doc->fileContents, new GooString(ownerPassword.data()), new GooString(userPassword.data()));
+ doc2 = new DocumentData(m_doc->fileContents, GooString(ownerPassword.data()), GooString(userPassword.data()));
} else if (m_doc->m_device) {
- doc2 = new DocumentData(m_doc->m_device, new GooString(ownerPassword.data()), new GooString(userPassword.data()));
+ doc2 = new DocumentData(m_doc->m_device, GooString(ownerPassword.data()), GooString(userPassword.data()));
} else {
- doc2 = new DocumentData(m_doc->m_filePath, new GooString(ownerPassword.data()), new GooString(userPassword.data()));
+ doc2 = new DocumentData(m_doc->m_filePath, GooString(ownerPassword.data()), GooString(userPassword.data()));
}
if (!doc2->doc->isOk()) {
delete doc2;
diff --git a/qt5/src/poppler-form.cc b/qt5/src/poppler-form.cc
index 620663fe..37b60f45 100644
--- a/qt5/src/poppler-form.cc
+++ b/qt5/src/poppler-form.cc
@@ -1075,14 +1075,13 @@ FormFieldSignature::SigningResult FormFieldSignature::sign(const QString &output
}
const auto reason = std::unique_ptr<GooString>(data.reason().isEmpty() ? nullptr : QStringToUnicodeGooString(data.reason()));
const auto location = std::unique_ptr<GooString>(data.location().isEmpty() ? nullptr : QStringToUnicodeGooString(data.location()));
- const auto ownerPwd = std::make_unique<GooString>(data.documentOwnerPassword().constData());
- const auto userPwd = std::make_unique<GooString>(data.documentUserPassword().constData());
+ const auto ownerPwd = std::optional<GooString>(data.documentOwnerPassword().constData());
+ const auto userPwd = std::optional<GooString>(data.documentUserPassword().constData());
const auto gSignatureText = std::unique_ptr<GooString>(QStringToUnicodeGooString(data.signatureText()));
const auto gSignatureLeftText = std::unique_ptr<GooString>(QStringToUnicodeGooString(data.signatureLeftText()));
- const bool success =
- fws->signDocumentWithAppearance(outputFileName.toUtf8().constData(), data.certNickname().toUtf8().constData(), "SHA256", data.password().toUtf8().constData(), reason.get(), location.get(), ownerPwd.get(), userPwd.get(),
- *gSignatureText, *gSignatureLeftText, data.fontSize(), convertQColor(data.fontColor()), data.borderWidth(), convertQColor(data.borderColor()), convertQColor(data.backgroundColor()));
+ const bool success = fws->signDocumentWithAppearance(outputFileName.toUtf8().constData(), data.certNickname().toUtf8().constData(), "SHA256", data.password().toUtf8().constData(), reason.get(), location.get(), ownerPwd, userPwd,
+ *gSignatureText, *gSignatureLeftText, data.fontSize(), convertQColor(data.fontColor()), data.borderWidth(), convertQColor(data.borderColor()), convertQColor(data.backgroundColor()));
return success ? SigningSuccess : GenericSigningError;
}
diff --git a/qt5/src/poppler-pdf-converter.cc b/qt5/src/poppler-pdf-converter.cc
index d23a39a9..7195512b 100644
--- a/qt5/src/poppler-pdf-converter.cc
+++ b/qt5/src/poppler-pdf-converter.cc
@@ -136,11 +136,11 @@ bool PDFConverter::sign(const NewSignatureData &data)
std::unique_ptr<GooString> gSignatureLeftText = std::unique_ptr<GooString>(QStringToUnicodeGooString(data.signatureLeftText()));
const auto reason = std::unique_ptr<GooString>(data.reason().isEmpty() ? nullptr : QStringToUnicodeGooString(data.reason()));
const auto location = std::unique_ptr<GooString>(data.location().isEmpty() ? nullptr : QStringToUnicodeGooString(data.location()));
- const auto ownerPwd = std::make_unique<GooString>(data.documentOwnerPassword().constData());
- const auto userPwd = std::make_unique<GooString>(data.documentUserPassword().constData());
+ const auto ownerPwd = std::optional<GooString>(data.documentOwnerPassword().constData());
+ const auto userPwd = std::optional<GooString>(data.documentUserPassword().constData());
return doc->sign(d->outputFileName.toUtf8().constData(), data.certNickname().toUtf8().constData(), data.password().toUtf8().constData(), QStringToGooString(data.fieldPartialName()), data.page() + 1,
boundaryToPdfRectangle(destPage, data.boundingRectangle(), Annotation::FixedRotation), *gSignatureText, *gSignatureLeftText, data.fontSize(), data.leftFontSize(), convertQColor(data.fontColor()), data.borderWidth(),
- convertQColor(data.borderColor()), convertQColor(data.backgroundColor()), reason.get(), location.get(), data.imagePath().toStdString(), ownerPwd.get(), userPwd.get());
+ convertQColor(data.borderColor()), convertQColor(data.backgroundColor()), reason.get(), location.get(), data.imagePath().toStdString(), ownerPwd, userPwd);
}
struct PDFConverter::NewSignatureData::NewSignatureDataPrivate
diff --git a/qt5/src/poppler-private.h b/qt5/src/poppler-private.h
index 83940dcc..df8397bb 100644
--- a/qt5/src/poppler-private.h
+++ b/qt5/src/poppler-private.h
@@ -104,7 +104,7 @@ public:
class DocumentData : private GlobalParamsIniter
{
public:
- DocumentData(const QString &filePath, GooString *ownerPassword, GooString *userPassword) : GlobalParamsIniter(qt5ErrorFunction)
+ DocumentData(const QString &filePath, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword) : GlobalParamsIniter(qt5ErrorFunction)
{
init();
m_device = nullptr;
@@ -115,30 +115,23 @@ public:
#else
doc = new PDFDoc(std::make_unique<GooString>(QFile::encodeName(filePath).constData()), ownerPassword, userPassword, nullptr, std::bind(&DocumentData::noitfyXRefReconstructed, this));
#endif
-
- delete ownerPassword;
- delete userPassword;
}
- DocumentData(QIODevice *device, GooString *ownerPassword, GooString *userPassword) : GlobalParamsIniter(qt5ErrorFunction)
+ DocumentData(QIODevice *device, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword) : GlobalParamsIniter(qt5ErrorFunction)
{
m_device = device;
QIODeviceInStream *str = new QIODeviceInStream(device, 0, false, device->size(), Object(objNull));
init();
doc = new PDFDoc(str, ownerPassword, userPassword, nullptr, std::bind(&DocumentData::noitfyXRefReconstructed, this));
- delete ownerPassword;
- delete userPassword;
}
- DocumentData(const QByteArray &data, GooString *ownerPassword, GooString *userPassword) : GlobalParamsIniter(qt5ErrorFunction)
+ DocumentData(const QByteArray &data, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword) : GlobalParamsIniter(qt5ErrorFunction)
{
m_device = nullptr;
fileContents = data;
MemStream *str = new MemStream((char *)fileContents.data(), 0, fileContents.length(), Object(objNull));
init();
doc = new PDFDoc(str, ownerPassword, userPassword, nullptr, std::bind(&DocumentData::noitfyXRefReconstructed, this));
- delete ownerPassword;
- delete userPassword;
}
void init();
diff --git a/qt6/src/poppler-document.cc b/qt6/src/poppler-document.cc
index 41d3452f..b14adab9 100644
--- a/qt6/src/poppler-document.cc
+++ b/qt6/src/poppler-document.cc
@@ -1,7 +1,7 @@
/* poppler-document.cc: qt interface to poppler
* Copyright (C) 2005, Net Integration Technologies, Inc.
* Copyright (C) 2005, 2008, Brad Hards <bradh@frogmouth.net>
- * Copyright (C) 2005-2010, 2012, 2013, 2015, 2017-2021, Albert Astals Cid <aacid@kde.org>
+ * Copyright (C) 2005-2010, 2012, 2013, 2015, 2017-2022, Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2006-2010, Pino Toscano <pino@kde.org>
* Copyright (C) 2010, 2011 Hib Eris <hib@hiberis.nl>
* Copyright (C) 2012 Koji Otani <sho@bbr.jp>
@@ -67,20 +67,20 @@ namespace Poppler {
std::unique_ptr<Document> Document::load(const QString &filePath, const QByteArray &ownerPassword, const QByteArray &userPassword)
{
- DocumentData *doc = new DocumentData(filePath, new GooString(ownerPassword.data()), new GooString(userPassword.data()));
+ DocumentData *doc = new DocumentData(filePath, GooString(ownerPassword.data()), GooString(userPassword.data()));
return DocumentData::checkDocument(doc);
}
std::unique_ptr<Document> Document::load(QIODevice *device, const QByteArray &ownerPassword, const QByteArray &userPassword)
{
- DocumentData *doc = new DocumentData(device, new GooString(ownerPassword.data()), new GooString(userPassword.data()));
+ DocumentData *doc = new DocumentData(device, GooString(ownerPassword.data()), GooString(userPassword.data()));
return DocumentData::checkDocument(doc);
}
std::unique_ptr<Document> Document::loadFromData(const QByteArray &fileContents, const QByteArray &ownerPassword, const QByteArray &userPassword)
{
// create stream
- DocumentData *doc = new DocumentData(fileContents, new GooString(ownerPassword.data()), new GooString(userPassword.data()));
+ DocumentData *doc = new DocumentData(fileContents, GooString(ownerPassword.data()), GooString(userPassword.data()));
return DocumentData::checkDocument(doc);
}
@@ -133,11 +133,11 @@ bool Document::unlock(const QByteArray &ownerPassword, const QByteArray &userPas
/* racier then it needs to be */
DocumentData *doc2;
if (!m_doc->fileContents.isEmpty()) {
- doc2 = new DocumentData(m_doc->fileContents, new GooString(ownerPassword.data()), new GooString(userPassword.data()));
+ doc2 = new DocumentData(m_doc->fileContents, GooString(ownerPassword.data()), GooString(userPassword.data()));
} else if (m_doc->m_device) {
- doc2 = new DocumentData(m_doc->m_device, new GooString(ownerPassword.data()), new GooString(userPassword.data()));
+ doc2 = new DocumentData(m_doc->m_device, GooString(ownerPassword.data()), GooString(userPassword.data()));
} else {
- doc2 = new DocumentData(m_doc->m_filePath, new GooString(ownerPassword.data()), new GooString(userPassword.data()));
+ doc2 = new DocumentData(m_doc->m_filePath, GooString(ownerPassword.data()), GooString(userPassword.data()));
}
if (!doc2->doc->isOk()) {
delete doc2;
diff --git a/qt6/src/poppler-form.cc b/qt6/src/poppler-form.cc
index 28a1e565..879b46c0 100644
--- a/qt6/src/poppler-form.cc
+++ b/qt6/src/poppler-form.cc
@@ -1075,14 +1075,13 @@ FormFieldSignature::SigningResult FormFieldSignature::sign(const QString &output
}
const auto reason = std::unique_ptr<GooString>(data.reason().isEmpty() ? nullptr : QStringToUnicodeGooString(data.reason()));
const auto location = std::unique_ptr<GooString>(data.location().isEmpty() ? nullptr : QStringToUnicodeGooString(data.location()));
- const auto ownerPwd = std::make_unique<GooString>(data.documentOwnerPassword().constData());
- const auto userPwd = std::make_unique<GooString>(data.documentUserPassword().constData());
+ const auto ownerPwd = std::optional<GooString>(data.documentOwnerPassword().constData());
+ const auto userPwd = std::optional<GooString>(data.documentUserPassword().constData());
const auto gSignatureText = std::unique_ptr<GooString>(QStringToUnicodeGooString(data.signatureText()));
const auto gSignatureLeftText = std::unique_ptr<GooString>(QStringToUnicodeGooString(data.signatureLeftText()));
- const bool success =
- fws->signDocumentWithAppearance(outputFileName.toUtf8().constData(), data.certNickname().toUtf8().constData(), "SHA256", data.password().toUtf8().constData(), reason.get(), location.get(), ownerPwd.get(), userPwd.get(),
- *gSignatureText, *gSignatureLeftText, data.fontSize(), convertQColor(data.fontColor()), data.borderWidth(), convertQColor(data.borderColor()), convertQColor(data.backgroundColor()));
+ const bool success = fws->signDocumentWithAppearance(outputFileName.toUtf8().constData(), data.certNickname().toUtf8().constData(), "SHA256", data.password().toUtf8().constData(), reason.get(), location.get(), ownerPwd, userPwd,
+ *gSignatureText, *gSignatureLeftText, data.fontSize(), convertQColor(data.fontColor()), data.borderWidth(), convertQColor(data.borderColor()), convertQColor(data.backgroundColor()));
return success ? SigningSuccess : GenericSigningError;
}
diff --git a/qt6/src/poppler-pdf-converter.cc b/qt6/src/poppler-pdf-converter.cc
index 27c06c6f..02f6ca00 100644
--- a/qt6/src/poppler-pdf-converter.cc
+++ b/qt6/src/poppler-pdf-converter.cc
@@ -136,11 +136,11 @@ bool PDFConverter::sign(const NewSignatureData &data)
std::unique_ptr<GooString> gSignatureLeftText = std::unique_ptr<GooString>(QStringToUnicodeGooString(data.signatureLeftText()));
const auto reason = std::unique_ptr<GooString>(data.reason().isEmpty() ? nullptr : QStringToUnicodeGooString(data.reason()));
const auto location = std::unique_ptr<GooString>(data.location().isEmpty() ? nullptr : QStringToUnicodeGooString(data.location()));
- const auto ownerPwd = std::make_unique<GooString>(data.documentOwnerPassword().constData());
- const auto userPwd = std::make_unique<GooString>(data.documentUserPassword().constData());
+ const auto ownerPwd = std::optional<GooString>(data.documentOwnerPassword().constData());
+ const auto userPwd = std::optional<GooString>(data.documentUserPassword().constData());
return doc->sign(d->outputFileName.toUtf8().constData(), data.certNickname().toUtf8().constData(), data.password().toUtf8().constData(), QStringToGooString(data.fieldPartialName()), data.page() + 1,
boundaryToPdfRectangle(destPage, data.boundingRectangle(), Annotation::FixedRotation), *gSignatureText, *gSignatureLeftText, data.fontSize(), data.leftFontSize(), convertQColor(data.fontColor()), data.borderWidth(),
- convertQColor(data.borderColor()), convertQColor(data.backgroundColor()), reason.get(), location.get(), data.imagePath().toStdString(), ownerPwd.get(), userPwd.get());
+ convertQColor(data.borderColor()), convertQColor(data.backgroundColor()), reason.get(), location.get(), data.imagePath().toStdString(), ownerPwd, userPwd);
}
struct PDFConverter::NewSignatureData::NewSignatureDataPrivate
diff --git a/qt6/src/poppler-private.h b/qt6/src/poppler-private.h
index 1f1ebb17..412e4b5f 100644
--- a/qt6/src/poppler-private.h
+++ b/qt6/src/poppler-private.h
@@ -103,7 +103,7 @@ public:
class DocumentData : private GlobalParamsIniter
{
public:
- DocumentData(const QString &filePath, GooString *ownerPassword, GooString *userPassword) : GlobalParamsIniter(qt6ErrorFunction)
+ DocumentData(const QString &filePath, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword) : GlobalParamsIniter(qt6ErrorFunction)
{
init();
m_device = nullptr;
@@ -114,30 +114,23 @@ public:
#else
doc = new PDFDoc(std::make_unique<GooString>(QFile::encodeName(filePath).constData()), ownerPassword, userPassword, nullptr, std::bind(&DocumentData::noitfyXRefReconstructed, this));
#endif
-
- delete ownerPassword;
- delete userPassword;
}
- DocumentData(QIODevice *device, GooString *ownerPassword, GooString *userPassword) : GlobalParamsIniter(qt6ErrorFunction)
+ DocumentData(QIODevice *device, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword) : GlobalParamsIniter(qt6ErrorFunction)
{
m_device = device;
QIODeviceInStream *str = new QIODeviceInStream(device, 0, false, device->size(), Object(objNull));
init();
doc = new PDFDoc(str, ownerPassword, userPassword, nullptr, std::bind(&DocumentData::noitfyXRefReconstructed, this));
- delete ownerPassword;
- delete userPassword;
}
- DocumentData(const QByteArray &data, GooString *ownerPassword, GooString *userPassword) : GlobalParamsIniter(qt6ErrorFunction)
+ DocumentData(const QByteArray &data, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword) : GlobalParamsIniter(qt6ErrorFunction)
{
m_device = nullptr;
fileContents = data;
MemStream *str = new MemStream((char *)fileContents.data(), 0, fileContents.length(), Object(objNull));
init();
doc = new PDFDoc(str, ownerPassword, userPassword, nullptr, std::bind(&DocumentData::noitfyXRefReconstructed, this));
- delete ownerPassword;
- delete userPassword;
}
void init();
diff --git a/test/image-embedding.cc b/test/image-embedding.cc
index a028d186..873b87d2 100644
--- a/test/image-embedding.cc
+++ b/test/image-embedding.cc
@@ -6,6 +6,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright (C) 2021 Georgiy Sgibnev <georgiy@sgibnev.com>. Work sponsored by lab50.net.
+// Copyright (C) 2022 by Albert Astals Cid <aacid@kde.org>
//
//========================================================================
@@ -50,7 +51,7 @@ int main(int argc, char *argv[])
const GooString docPath(argv[1]);
const GooString imagePath(argv[2]);
- auto doc = std::unique_ptr<PDFDoc>(PDFDocFactory().createPDFDoc(docPath, nullptr, nullptr));
+ auto doc = std::unique_ptr<PDFDoc>(PDFDocFactory().createPDFDoc(docPath));
if (!doc->isOk()) {
fprintf(stderr, "Error opening input PDF file.\n");
return 1;
diff --git a/test/pdf-fullrewrite.cc b/test/pdf-fullrewrite.cc
index 4c8d9818..7f61d27f 100644
--- a/test/pdf-fullrewrite.cc
+++ b/test/pdf-fullrewrite.cc
@@ -39,8 +39,8 @@ int main(int argc, char *argv[])
{
PDFDoc *doc = nullptr;
PDFDoc *docOut = nullptr;
- GooString *ownerPW = nullptr;
- GooString *userPW = nullptr;
+ std::optional<GooString> ownerPW;
+ std::optional<GooString> userPW;
int res = 0;
// parse args
@@ -54,10 +54,10 @@ int main(int argc, char *argv[])
}
if (ownerPassword[0] != '\001') {
- ownerPW = new GooString(ownerPassword);
+ ownerPW = GooString(ownerPassword);
}
if (userPassword[0] != '\001') {
- userPW = new GooString(userPassword);
+ userPW = GooString(userPassword);
}
// load input document
@@ -91,8 +91,6 @@ int main(int argc, char *argv[])
done:
delete docOut;
delete doc;
- delete userPW;
- delete ownerPW;
return res;
}
diff --git a/test/pdf-inspector.cc b/test/pdf-inspector.cc
index f3034cf1..e06c4dee 100644
--- a/test/pdf-inspector.cc
+++ b/test/pdf-inspector.cc
@@ -222,7 +222,7 @@ void PdfInspector::load(const char *file_name)
// load the new file
if (file_name) {
- doc = new PDFDoc(std::make_unique<GooString>(file_name), nullptr, nullptr);
+ doc = new PDFDoc(std::make_unique<GooString>(file_name));
}
if (doc && !doc->isOk()) {
diff --git a/test/perf-test.cc b/test/perf-test.cc
index 1d577eb1..f949d3ba 100644
--- a/test/perf-test.cc
+++ b/test/perf-test.cc
@@ -383,7 +383,7 @@ bool PdfEnginePoppler::load(const char *fileName)
{
setFileName(fileName);
- _pdfDoc = new PDFDoc(std::make_unique<GooString>(fileName), nullptr, nullptr, nullptr);
+ _pdfDoc = new PDFDoc(std::make_unique<GooString>(fileName));
if (!_pdfDoc->isOk()) {
return false;
}
@@ -599,7 +599,7 @@ static void RenderPdfAsText(const char *fileName)
}
GooTimer msTimer;
- pdfDoc = new PDFDoc(std::make_unique<GooString>(fileName), nullptr, nullptr, nullptr);
+ pdfDoc = new PDFDoc(std::make_unique<GooString>(fileName));
if (!pdfDoc->isOk()) {
error(errIO, -1, "RenderPdfFile(): failed to open PDF file {0:s}\n", fileName);
goto Exit;
diff --git a/utils/pdfattach.cc b/utils/pdfattach.cc
index b839622f..dd16bed3 100644
--- a/utils/pdfattach.cc
+++ b/utils/pdfattach.cc
@@ -67,7 +67,7 @@ int main(int argc, char *argv[])
globalParams = std::make_unique<GlobalParams>();
// open PDF file
- std::unique_ptr<PDFDoc> doc(PDFDocFactory().createPDFDoc(pdfFileName, nullptr, nullptr));
+ std::unique_ptr<PDFDoc> doc(PDFDocFactory().createPDFDoc(pdfFileName, {}, {}));
if (!doc->isOk()) {
fprintf(stderr, "Couldn't open %s\n", pdfFileName.c_str());
diff --git a/utils/pdfdetach.cc b/utils/pdfdetach.cc
index 808263d9..be8aa6dd 100644
--- a/utils/pdfdetach.cc
+++ b/utils/pdfdetach.cc
@@ -75,7 +75,7 @@ int main(int argc, char *argv[])
std::unique_ptr<PDFDoc> doc;
GooString *fileName;
const UnicodeMap *uMap;
- GooString *ownerPW, *userPW;
+ std::optional<GooString> ownerPW, userPW;
char uBuf[8];
char path[1024];
char *p;
@@ -124,24 +124,14 @@ int main(int argc, char *argv[])
// open PDF file
if (ownerPassword[0] != '\001') {
- ownerPW = new GooString(ownerPassword);
- } else {
- ownerPW = nullptr;
+ ownerPW = GooString(ownerPassword);
}
if (userPassword[0] != '\001') {
- userPW = new GooString(userPassword);
- } else {
- userPW = nullptr;
+ userPW = GooString(userPassword);
}
doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
- if (userPW) {
- delete userPW;
- }
- if (ownerPW) {
- delete ownerPW;
- }
if (!doc->isOk()) {
return 1;
}
diff --git a/utils/pdffonts.cc b/utils/pdffonts.cc
index 3dcf5d92..adca2591 100644
--- a/utils/pdffonts.cc
+++ b/utils/pdffonts.cc
@@ -14,7 +14,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2006 Dominic Lachowicz <cinamod@hotmail.com>
-// Copyright (C) 2007-2008, 2010, 2018 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2007-2008, 2010, 2018, 2022 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2012, 2017 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2013 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>
@@ -68,7 +68,7 @@ static const ArgDesc argDesc[] = { { "-f", argInt, &firstPage, 0, "first page to
int main(int argc, char *argv[])
{
- std::unique_ptr<GooString> ownerPW, userPW;
+ std::optional<GooString> ownerPW, userPW;
bool ok;
Win32Console win32Console(&argc, &argv);
@@ -97,13 +97,13 @@ int main(int argc, char *argv[])
// open PDF file
if (ownerPassword[0] != '\001') {
- ownerPW = std::make_unique<GooString>(ownerPassword);
+ ownerPW = GooString(ownerPassword);
}
if (userPassword[0] != '\001') {
- userPW = std::make_unique<GooString>(userPassword);
+ userPW = GooString(userPassword);
}
- auto doc = std::unique_ptr<PDFDoc>(PDFDocFactory().createPDFDoc(GooString(fileName), ownerPW.get(), userPW.get()));
+ auto doc = std::unique_ptr<PDFDoc>(PDFDocFactory().createPDFDoc(GooString(fileName), ownerPW, userPW));
if (!doc->isOk()) {
return 1;
diff --git a/utils/pdfimages.cc b/utils/pdfimages.cc
index 2a524fa8..c18f4a4c 100644
--- a/utils/pdfimages.cc
+++ b/utils/pdfimages.cc
@@ -15,7 +15,7 @@
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
-// Copyright (C) 2007-2008, 2010, 2018 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2007-2008, 2010, 2018, 2022 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2010 Jakob Voss <jakob.voss@gbv.de>
// Copyright (C) 2012, 2013, 2017 Adrian Johnson <ajohnson@redneon.com>
@@ -98,7 +98,7 @@ int main(int argc, char *argv[])
{
GooString *fileName;
char *imgRoot = nullptr;
- GooString *ownerPW, *userPW;
+ std::optional<GooString> ownerPW, userPW;
ImageOutputDev *imgOut;
bool ok;
@@ -129,14 +129,10 @@ int main(int argc, char *argv[])
// open PDF file
if (ownerPassword[0] != '\001') {
- ownerPW = new GooString(ownerPassword);
- } else {
- ownerPW = nullptr;
+ ownerPW = GooString(ownerPassword);
}
if (userPassword[0] != '\001') {
- userPW = new GooString(userPassword);
- } else {
- userPW = nullptr;
+ userPW = GooString(userPassword);
}
if (fileName->cmp("-") == 0) {
delete fileName;
@@ -146,12 +142,6 @@ int main(int argc, char *argv[])
std::unique_ptr<PDFDoc> doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
delete fileName;
- if (userPW) {
- delete userPW;
- }
- if (ownerPW) {
- delete ownerPW;
- }
if (!doc->isOk()) {
return 1;
}
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc
index 9460ccb8..cff15950 100644
--- a/utils/pdfinfo.cc
+++ b/utils/pdfinfo.cc
@@ -15,7 +15,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2006 Dom Lachowicz <cinamod@hotmail.com>
-// Copyright (C) 2007-2010, 2012, 2016-2021 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2007-2010, 2012, 2016-2022 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2011 Vittal Aithal <vittal.aithal@cognidox.com>
// Copyright (C) 2012, 2013, 2016-2018, 2021 Adrian Johnson <ajohnson@redneon.com>
@@ -917,7 +917,7 @@ int main(int argc, char *argv[])
{
std::unique_ptr<PDFDoc> doc;
GooString *fileName;
- GooString *ownerPW, *userPW;
+ std::optional<GooString> ownerPW, userPW;
const UnicodeMap *uMap;
FILE *f;
bool ok;
@@ -968,14 +968,10 @@ int main(int argc, char *argv[])
// open PDF file
if (ownerPassword[0] != '\001') {
- ownerPW = new GooString(ownerPassword);
- } else {
- ownerPW = nullptr;
+ ownerPW = GooString(ownerPassword);
}
if (userPassword[0] != '\001') {
- userPW = new GooString(userPassword);
- } else {
- userPW = nullptr;
+ userPW = GooString(userPassword);
}
if (fileName->cmp("-") == 0) {
@@ -985,12 +981,6 @@ int main(int argc, char *argv[])
doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
- if (userPW) {
- delete userPW;
- }
- if (ownerPW) {
- delete ownerPW;
- }
if (!doc->isOk()) {
exitCode = 1;
goto err2;
diff --git a/utils/pdfseparate.cc b/utils/pdfseparate.cc
index 40afe530..3c604f5a 100644
--- a/utils/pdfseparate.cc
+++ b/utils/pdfseparate.cc
@@ -46,7 +46,7 @@ static const ArgDesc argDesc[] = { { "-f", argInt, &firstPage, 0, "first page to
static bool extractPages(const char *srcFileName, const char *destFileName)
{
char pathName[4096];
- PDFDoc *doc = new PDFDoc(std::make_unique<GooString>(srcFileName), nullptr, nullptr, nullptr);
+ PDFDoc *doc = new PDFDoc(std::make_unique<GooString>(srcFileName));
if (!doc->isOk()) {
error(errSyntaxError, -1, "Could not extract page(s) from damaged file ('{0:s}')", srcFileName);
@@ -117,7 +117,7 @@ static bool extractPages(const char *srcFileName, const char *destFileName)
for (int pageNo = firstPage; pageNo <= lastPage; pageNo++) {
snprintf(pathName, sizeof(pathName) - 1, destFileName, pageNo);
- PDFDoc *pagedoc = new PDFDoc(std::make_unique<GooString>(srcFileName), nullptr, nullptr, nullptr);
+ PDFDoc *pagedoc = new PDFDoc(std::make_unique<GooString>(srcFileName));
int errCode = pagedoc->savePageAs(GooString(pathName), pageNo);
if (errCode != errNone) {
delete doc;
diff --git a/utils/pdfsig.cc b/utils/pdfsig.cc
index ca70128c..2526a407 100644
--- a/utils/pdfsig.cc
+++ b/utils/pdfsig.cc
@@ -272,15 +272,15 @@ int main(int argc, char *argv[])
std::unique_ptr<GooString> fileName = std::make_unique<GooString>(argv[1]);
- std::unique_ptr<GooString> ownerPW, userPW;
+ std::optional<GooString> ownerPW, userPW;
if (ownerPassword[0] != '\001') {
- ownerPW = std::make_unique<GooString>(ownerPassword);
+ ownerPW = GooString(ownerPassword);
}
if (userPassword[0] != '\001') {
- userPW = std::make_unique<GooString>(userPassword);
+ userPW = GooString(userPassword);
}
// open PDF file
- std::unique_ptr<PDFDoc> doc(PDFDocFactory().createPDFDoc(*fileName, ownerPW.get(), userPW.get()));
+ std::unique_ptr<PDFDoc> doc(PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW));
if (!doc->isOk()) {
return 1;
@@ -345,7 +345,7 @@ int main(int argc, char *argv[])
// We don't provide a way to customize the UI from pdfsig for now
const bool success = doc->sign(argv[2], certNickname, pw, newSignatureFieldName.copy(), /*page*/ 1,
/*rect */ { 0, 0, 0, 0 }, /*signatureText*/ {}, /*signatureTextLeft*/ {}, /*fontSize */ 0, /*leftFontSize*/ 0,
- /*fontColor*/ {}, /*borderWidth*/ 0, /*borderColor*/ {}, /*backgroundColor*/ {}, rs.get(), /* location */ nullptr, /* image path */ "", ownerPW.get(), userPW.get());
+ /*fontColor*/ {}, /*borderWidth*/ 0, /*borderColor*/ {}, /*backgroundColor*/ {}, rs.get(), /* location */ nullptr, /* image path */ "", ownerPW, userPW);
return success ? 0 : 3;
}
diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc
index d6ba0e62..7037c4d8 100644
--- a/utils/pdftocairo.cc
+++ b/utils/pdftocairo.cc
@@ -18,7 +18,7 @@
// Copyright (C) 2009 Michael K. Johnson <a1237@danlj.org>
// Copyright (C) 2009 Shen Liang <shenzhuxi@gmail.com>
// Copyright (C) 2009 Stefan Thomas <thomas@eload24.com>
-// Copyright (C) 2009, 2010, 2017-2020 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2009, 2010, 2017-2020, 2022 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2010, 2011-2017 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2010, 2014 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2010 Jonathan Liu <net147@gmail.com>
@@ -875,7 +875,7 @@ int main(int argc, char *argv[])
GooString *outputName = nullptr;
GooString *outputFileName = nullptr;
GooString *imageFileName = nullptr;
- GooString *ownerPW, *userPW;
+ std::optional<GooString> ownerPW, userPW;
CairoOutputDev *cairoOut;
int pg, pg_num_len;
double pg_w, pg_h, tmp, output_w, output_h;
@@ -1027,14 +1027,10 @@ int main(int argc, char *argv[])
// open PDF file
if (ownerPassword[0]) {
- ownerPW = new GooString(ownerPassword);
- } else {
- ownerPW = nullptr;
+ ownerPW = GooString(ownerPassword);
}
if (userPassword[0]) {
- userPW = new GooString(userPassword);
- } else {
- userPW = nullptr;
+ userPW = GooString(userPassword);
}
fileName = new GooString(argv[1]);
@@ -1211,10 +1207,6 @@ int main(int argc, char *argv[])
delete outputFileName;
if (imageFileName)
delete imageFileName;
- if (ownerPW)
- delete ownerPW;
- if (userPW)
- delete userPW;
#ifdef USE_CMS
if (icc_data)
diff --git a/utils/pdftohtml.cc b/utils/pdftohtml.cc
index aaac8090..8a5d3284 100644
--- a/utils/pdftohtml.cc
+++ b/utils/pdftohtml.cc
@@ -13,7 +13,7 @@
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
-// Copyright (C) 2007-2008, 2010, 2012, 2015-2020 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2007-2008, 2010, 2012, 2015-2020, 2022 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2010 Mike Slegeir <tehpola@yahoo.com>
// Copyright (C) 2010, 2013 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>
@@ -165,7 +165,7 @@ int main(int argc, char *argv[])
SplashOutputDev *splashOut = nullptr;
bool doOutline;
bool ok;
- GooString *ownerPW, *userPW;
+ std::optional<GooString> ownerPW, userPW;
Object info;
int exit_status = EXIT_FAILURE;
@@ -206,14 +206,10 @@ int main(int argc, char *argv[])
// open PDF file
if (ownerPassword[0]) {
- ownerPW = new GooString(ownerPassword);
- } else {
- ownerPW = nullptr;
+ ownerPW = GooString(ownerPassword);
}
if (userPassword[0]) {
- userPW = new GooString(userPassword);
- } else {
- userPW = nullptr;
+ userPW = GooString(userPassword);
}
fileName = new GooString(argv[1]);
@@ -225,12 +221,6 @@ int main(int argc, char *argv[])
doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
- if (userPW) {
- delete userPW;
- }
- if (ownerPW) {
- delete ownerPW;
- }
if (!doc->isOk()) {
goto error;
}
diff --git a/utils/pdftoppm.cc b/utils/pdftoppm.cc
index b6df556b..337fd64c 100644
--- a/utils/pdftoppm.cc
+++ b/utils/pdftoppm.cc
@@ -18,7 +18,7 @@
// Copyright (C) 2009 Michael K. Johnson <a1237@danlj.org>
// Copyright (C) 2009 Shen Liang <shenzhuxi@gmail.com>
// Copyright (C) 2009 Stefan Thomas <thomas@eload24.com>
-// Copyright (C) 2009-2011, 2015, 2018-2021 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2009-2011, 2015, 2018-2022 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2010, 2012, 2017 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2010 Jonathan Liu <net147@gmail.com>
@@ -399,7 +399,7 @@ int main(int argc, char *argv[])
GooString *fileName = nullptr;
char *ppmRoot = nullptr;
char *ppmFile;
- GooString *ownerPW, *userPW;
+ std::optional<GooString> ownerPW, userPW;
SplashColor paperColor;
#ifndef UTILS_USE_PTHREADS
SplashOutputDev *splashOut;
@@ -481,14 +481,10 @@ int main(int argc, char *argv[])
// open PDF file
if (ownerPassword[0]) {
- ownerPW = new GooString(ownerPassword);
- } else {
- ownerPW = nullptr;
+ ownerPW = GooString(ownerPassword);
}
if (userPassword[0]) {
- userPW = new GooString(userPassword);
- } else {
- userPW = nullptr;
+ userPW = GooString(userPassword);
}
if (fileName == nullptr) {
@@ -500,13 +496,6 @@ int main(int argc, char *argv[])
}
std::unique_ptr<PDFDoc> doc(PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW));
delete fileName;
-
- if (userPW) {
- delete userPW;
- }
- if (ownerPW) {
- delete ownerPW;
- }
if (!doc->isOk()) {
return 1;
}
diff --git a/utils/pdftops.cc b/utils/pdftops.cc
index 4813a975..9c9c372e 100644
--- a/utils/pdftops.cc
+++ b/utils/pdftops.cc
@@ -16,7 +16,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2006 Kristian Høgsberg <krh@redhat.com>
-// Copyright (C) 2007-2008, 2010, 2015, 2017, 2018, 2020, 2021 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2007-2008, 2010, 2015, 2017, 2018, 2020-2022 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2009 Till Kamppeter <till.kamppeter@gmail.com>
// Copyright (C) 2009 Sanjoy Mahajan <sanjoy@mit.edu>
// Copyright (C) 2009, 2011, 2012, 2014-2016, 2020 William Bader <williambader@hotmail.com>
@@ -197,7 +197,7 @@ int main(int argc, char *argv[])
GooString *psFileName;
PSLevel level;
PSOutMode mode;
- GooString *ownerPW, *userPW;
+ std::optional<GooString> ownerPW, userPW;
PSOutputDev *psOut;
bool ok;
int exitCode;
@@ -362,14 +362,10 @@ int main(int argc, char *argv[])
// open PDF file
if (ownerPassword[0] != '\001') {
- ownerPW = new GooString(ownerPassword);
- } else {
- ownerPW = nullptr;
+ ownerPW = GooString(ownerPassword);
}
if (userPassword[0] != '\001') {
- userPW = new GooString(userPassword);
- } else {
- userPW = nullptr;
+ userPW = GooString(userPassword);
}
if (fileName->cmp("-") == 0) {
delete fileName;
@@ -378,12 +374,6 @@ int main(int argc, char *argv[])
doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
- if (userPW) {
- delete userPW;
- }
- if (ownerPW) {
- delete ownerPW;
- }
if (!doc->isOk()) {
exitCode = 1;
goto err1;
diff --git a/utils/pdftotext.cc b/utils/pdftotext.cc
index 0caca87f..92f59811 100644
--- a/utils/pdftotext.cc
+++ b/utils/pdftotext.cc
@@ -16,7 +16,7 @@
// under GPL version 2 or later
//
// Copyright (C) 2006 Dominic Lachowicz <cinamod@hotmail.com>
-// Copyright (C) 2007-2008, 2010, 2011, 2017-2021 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2007-2008, 2010, 2011, 2017-2022 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2009 Jan Jockusch <jan@jockusch.de>
// Copyright (C) 2010, 2013 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2010 Kenneth Berland <ken@hero.com>
@@ -161,7 +161,7 @@ int main(int argc, char *argv[])
std::unique_ptr<PDFDoc> doc;
GooString *fileName;
GooString *textFileName;
- GooString *ownerPW, *userPW;
+ std::optional<GooString> ownerPW, userPW;
TextOutputDev *textOut;
FILE *f;
const UnicodeMap *uMap;
@@ -238,14 +238,10 @@ int main(int argc, char *argv[])
// open PDF file
if (ownerPassword[0] != '\001') {
- ownerPW = new GooString(ownerPassword);
- } else {
- ownerPW = nullptr;
+ ownerPW = GooString(ownerPassword);
}
if (userPassword[0] != '\001') {
- userPW = new GooString(userPassword);
- } else {
- userPW = nullptr;
+ userPW = GooString(userPassword);
}
if (fileName->cmp("-") == 0) {
@@ -255,12 +251,6 @@ int main(int argc, char *argv[])
doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
- if (userPW) {
- delete userPW;
- }
- if (ownerPW) {
- delete ownerPW;
- }
if (!doc->isOk()) {
exitCode = 1;
goto err2;
diff --git a/utils/pdfunite.cc b/utils/pdfunite.cc
index 4731eed7..bce69770 100644
--- a/utils/pdfunite.cc
+++ b/utils/pdfunite.cc
@@ -154,7 +154,7 @@ int main(int argc, char *argv[])
globalParams = std::make_unique<GlobalParams>();
for (i = 1; i < argc - 1; i++) {
- PDFDoc *doc = new PDFDoc(std::make_unique<GooString>(argv[i]), nullptr, nullptr, nullptr);
+ PDFDoc *doc = new PDFDoc(std::make_unique<GooString>(argv[i]));
if (doc->isOk() && !doc->isEncrypted() && doc->getXRef()->getCatalog().isDict()) {
docs.push_back(doc);
if (doc->getPDFMajorVersion() > majorVersion) {