summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/qpdf/QPDF.hh62
-rw-r--r--include/qpdf/QPDFObjGen.hh28
-rw-r--r--include/qpdf/QPDFObjectHandle.hh29
3 files changed, 54 insertions, 65 deletions
diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh
index f0c9f6b4..a80ddcd5 100644
--- a/include/qpdf/QPDF.hh
+++ b/include/qpdf/QPDF.hh
@@ -815,9 +815,9 @@ class QPDF
private:
static std::shared_ptr<QPDFObject>
- resolve(QPDF* qpdf, int objid, int generation)
+ resolve(QPDF* qpdf, QPDFObjGen const& og)
{
- return qpdf->resolve(objid, generation);
+ return qpdf->resolve(og);
}
static bool
objectChanged(
@@ -879,8 +879,7 @@ class QPDF
static bool
pipeStreamData(
QPDF* qpdf,
- int objid,
- int generation,
+ QPDFObjGen const& og,
qpdf_offset_t offset,
size_t length,
QPDFObjectHandle dict,
@@ -889,8 +888,7 @@ class QPDF
bool will_retry)
{
return qpdf->pipeStreamData(
- objid,
- generation,
+ og,
offset,
length,
dict,
@@ -959,8 +957,7 @@ class QPDF
std::string user_password;
std::string encryption_key;
std::string cached_object_encryption_key;
- int cached_key_objid;
- int cached_key_generation;
+ QPDFObjGen cached_key_og;
bool user_password_matched;
bool owner_password_matched;
};
@@ -973,8 +970,7 @@ class QPDF
ForeignStreamData(
std::shared_ptr<EncryptionParameters> encp,
std::shared_ptr<InputSource> file,
- int foreign_objid,
- int foreign_generation,
+ QPDFObjGen const& foreign_og,
qpdf_offset_t offset,
size_t length,
QPDFObjectHandle local_dict);
@@ -982,8 +978,7 @@ class QPDF
private:
std::shared_ptr<EncryptionParameters> encp;
std::shared_ptr<InputSource> file;
- int foreign_objid;
- int foreign_generation;
+ QPDFObjGen foreign_og;
qpdf_offset_t offset;
size_t length;
QPDFObjectHandle local_dict;
@@ -995,8 +990,7 @@ class QPDF
CopiedStreamDataProvider(QPDF& destination_qpdf);
virtual ~CopiedStreamDataProvider() = default;
virtual bool provideStreamData(
- int objid,
- int generation,
+ QPDFObjGen const& og,
Pipeline* pipeline,
bool suppress_warnings,
bool will_retry) override;
@@ -1017,14 +1011,13 @@ class QPDF
friend class QPDF;
public:
- StringDecrypter(QPDF* qpdf, int objid, int gen);
+ StringDecrypter(QPDF* qpdf, QPDFObjGen const& og);
virtual ~StringDecrypter() = default;
virtual void decryptString(std::string& val);
private:
QPDF* qpdf;
- int objid;
- int gen;
+ QPDFObjGen og;
};
class ResolveRecorder
@@ -1127,17 +1120,15 @@ class QPDF
void insertXrefEntry(
int obj, int f0, qpdf_offset_t f1, int f2, bool overwrite = false);
void setLastObjectDescription(
- std::string const& description, int objid, int generation);
+ std::string const& description, QPDFObjGen const& og);
QPDFObjectHandle readObject(
std::shared_ptr<InputSource>,
std::string const& description,
- int objid,
- int generation,
+ QPDFObjGen const& og,
bool in_object_stream);
size_t recoverStreamLength(
std::shared_ptr<InputSource> input,
- int objid,
- int generation,
+ QPDFObjGen const& og,
qpdf_offset_t stream_offset);
QPDFTokenizer::Token
readToken(std::shared_ptr<InputSource>, size_t max_len = 0);
@@ -1146,21 +1137,18 @@ class QPDF
bool attempt_recovery,
qpdf_offset_t offset,
std::string const& description,
- int exp_objid,
- int exp_generation,
- int& act_objid,
- int& act_generation);
+ QPDFObjGen const& exp_og,
+ QPDFObjGen& og);
bool objectChanged(QPDFObjGen const& og, std::shared_ptr<QPDFObject>& oph);
- std::shared_ptr<QPDFObject> resolve(int objid, int generation);
+ std::shared_ptr<QPDFObject> resolve(QPDFObjGen const& og);
void resolveObjectsInStream(int obj_stream_number);
void stopOnError(std::string const& message);
- QPDFObjectHandle reserveObjectIfNotExists(int objid, int gen);
- QPDFObjectHandle reserveStream(int objid, int gen);
+ QPDFObjectHandle reserveObjectIfNotExists(QPDFObjGen const& og);
+ QPDFObjectHandle reserveStream(QPDFObjGen const& og);
// Calls finish() on the pipeline when done but does not delete it
bool pipeStreamData(
- int objid,
- int generation,
+ QPDFObjGen const& og,
qpdf_offset_t offset,
size_t length,
QPDFObjectHandle dict,
@@ -1176,8 +1164,7 @@ class QPDF
std::shared_ptr<QPDF::EncryptionParameters> encp,
std::shared_ptr<InputSource> file,
QPDF& qpdf_for_warning,
- int objid,
- int generation,
+ QPDFObjGen const& og,
qpdf_offset_t offset,
size_t length,
QPDFObjectHandle dict,
@@ -1230,10 +1217,9 @@ class QPDF
void initializeEncryption();
static std::string getKeyForObject(
std::shared_ptr<EncryptionParameters> encp,
- int objid,
- int generation,
+ QPDFObjGen const& og,
bool use_aes);
- void decryptString(std::string&, int objid, int generation);
+ void decryptString(std::string&, QPDFObjGen const& og);
static std::string compute_encryption_key_from_password(
std::string const& password, EncryptionData const& data);
static std::string recover_encryption_key_with_password(
@@ -1247,8 +1233,7 @@ class QPDF
std::shared_ptr<InputSource> file,
QPDF& qpdf_for_warning,
Pipeline*& pipeline,
- int objid,
- int generation,
+ QPDFObjGen const& og,
QPDFObjectHandle& stream_dict,
std::vector<std::shared_ptr<Pipeline>>& heap);
@@ -1571,7 +1556,6 @@ class QPDF
void dumpHSharedObject();
void dumpHGeneric(HGeneric&);
qpdf_offset_t adjusted_offset(qpdf_offset_t offset);
- QPDFObjectHandle objGenToIndirect(QPDFObjGen const&);
void
calculateLinearizationData(std::map<int, int> const& object_stream_data);
void pushOutlinesToPart(
diff --git a/include/qpdf/QPDFObjGen.hh b/include/qpdf/QPDFObjGen.hh
index ba6e169d..df9ef737 100644
--- a/include/qpdf/QPDFObjGen.hh
+++ b/include/qpdf/QPDFObjGen.hh
@@ -23,7 +23,6 @@
#define QPDFOBJGEN_HH
#include <qpdf/DLL.h>
-#include <qpdf/QUtil.hh>
#include <iostream>
// This class represents an object ID and generation pair. It is
@@ -39,7 +38,7 @@ class QPDFObjGen
{
}
QPDF_DLL
- QPDFObjGen(int obj, int gen) :
+ explicit QPDFObjGen(int obj, int gen) :
obj(obj),
gen(gen)
{
@@ -48,13 +47,19 @@ class QPDFObjGen
bool
operator<(QPDFObjGen const& rhs) const
{
- return ((obj < rhs.obj) || ((obj == rhs.obj) && (gen < rhs.gen)));
+ return (obj < rhs.obj) || ((obj == rhs.obj) && (gen < rhs.gen));
}
QPDF_DLL
bool
operator==(QPDFObjGen const& rhs) const
{
- return ((obj == rhs.obj) && (gen == rhs.gen));
+ return (obj == rhs.obj) && (gen == rhs.gen);
+ }
+ QPDF_DLL
+ bool
+ operator!=(QPDFObjGen const& rhs) const
+ {
+ return (obj != rhs.obj) || (gen != rhs.gen);
}
QPDF_DLL
int
@@ -69,18 +74,15 @@ class QPDFObjGen
return gen;
}
QPDF_DLL
- std::string
- unparse() const
+ bool
+ isIndirect() const
{
- return QUtil::int_to_string(obj) + "," + QUtil::int_to_string(gen);
+ return obj != 0;
}
QPDF_DLL
- friend std::ostream&
- operator<<(std::ostream& os, const QPDFObjGen& og)
- {
- os << og.obj << "," << og.gen;
- return os;
- }
+ std::string unparse(char separator = ',') const;
+ QPDF_DLL
+ friend std::ostream& operator<<(std::ostream& os, const QPDFObjGen& og);
private:
// This class does not use the Members pattern to avoid a memory
diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh
index 292397d4..790acccd 100644
--- a/include/qpdf/QPDFObjectHandle.hh
+++ b/include/qpdf/QPDFObjectHandle.hh
@@ -116,9 +116,16 @@ class QPDFObjectHandle
// indicating whether it ran without errors.
QPDF_DLL
virtual void
- provideStreamData(int objid, int generation, Pipeline* pipeline);
+ provideStreamData(QPDFObjGen const& og, Pipeline* pipeline);
QPDF_DLL
virtual bool provideStreamData(
+ QPDFObjGen const& og,
+ Pipeline* pipeline,
+ bool suppress_warnings,
+ bool will_retry);
+ QPDF_DLL virtual void
+ provideStreamData(int objid, int generation, Pipeline* pipeline);
+ QPDF_DLL virtual bool provideStreamData(
int objid,
int generation,
Pipeline* pipeline,
@@ -1429,21 +1436,20 @@ class QPDFObjectHandle
private:
static QPDFObjectHandle
- newIndirect(QPDF* qpdf, int objid, int generation)
+ newIndirect(QPDF* qpdf, QPDFObjGen const& og)
{
- return QPDFObjectHandle::newIndirect(qpdf, objid, generation);
+ return QPDFObjectHandle::newIndirect(qpdf, og);
}
static QPDFObjectHandle
newStream(
QPDF* qpdf,
- int objid,
- int generation,
+ QPDFObjGen const& og,
QPDFObjectHandle stream_dict,
qpdf_offset_t offset,
size_t length)
{
return QPDFObjectHandle::newStream(
- qpdf, objid, generation, stream_dict, offset, length);
+ qpdf, og, stream_dict, offset, length);
}
// Reserve an object with a specific ID
static QPDFObjectHandle
@@ -1550,7 +1556,7 @@ class QPDFObjectHandle
bool isImage(bool exclude_imagemask = true);
private:
- QPDFObjectHandle(QPDF*, int objid, int generation);
+ QPDFObjectHandle(QPDF*, QPDFObjGen const& og);
QPDFObjectHandle(std::shared_ptr<QPDFObject> const&);
enum parser_state_e {
@@ -1563,11 +1569,10 @@ class QPDFObjectHandle
};
// Private object factory methods
- static QPDFObjectHandle newIndirect(QPDF*, int objid, int generation);
+ static QPDFObjectHandle newIndirect(QPDF*, QPDFObjGen const& og);
static QPDFObjectHandle newStream(
QPDF* qpdf,
- int objid,
- int generation,
+ QPDFObjGen const& og,
QPDFObjectHandle stream_dict,
qpdf_offset_t offset,
size_t length);
@@ -1584,7 +1589,6 @@ class QPDFObjectHandle
bool stop_at_streams);
void shallowCopyInternal(QPDFObjectHandle& oh, bool first_level_only);
void releaseResolved();
- std::string getObjGenAsStr() const;
static void setObjectDescriptionFromInput(
QPDFObjectHandle,
QPDF*,
@@ -1618,8 +1622,7 @@ class QPDFObjectHandle
// a substantial performance penalty since QPDFObjectHandle
// objects are copied around so frequently.
QPDF* qpdf;
- int objid; // 0 for direct object
- int generation;
+ QPDFObjGen og;
std::shared_ptr<QPDFObject> obj;
bool reserved;
};