2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-02-07 06:08:26 +00:00

go back to function-based DLL_EXPORT rather than class-based to avoid creation of export files with executables under msvc

git-svn-id: svn+q:///qpdf/trunk@849 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
Jay Berkenbilt 2009-10-21 00:27:24 +00:00
parent eff113fa68
commit 748ab301d4
26 changed files with 266 additions and 26 deletions

View File

@ -68,6 +68,12 @@ and then
make
NOTE: automated dependencies are not generated with the msvc build.
If you're planning on making modifications, you should probably work
with mingw. If there is a need, I can add dependency information to
the msvc build, but since I only use it for generating release
versions, I haven't bothered.
The -DHAVE_VSNPRINTF is really only required for things that include
zutil.h from zlib. You don't have to worry about this when compiling
against qpdf with MSVC -- only when building zlib. It's harmless to

View File

@ -10,16 +10,24 @@
#include <qpdf/DLL.h>
class DLL_EXPORT Buffer
class Buffer
{
public:
DLL_EXPORT
Buffer();
DLL_EXPORT
Buffer(unsigned long size);
DLL_EXPORT
Buffer(Buffer const&);
DLL_EXPORT
Buffer& operator=(Buffer const&);
DLL_EXPORT
~Buffer();
DLL_EXPORT
unsigned long getSize() const;
DLL_EXPORT
unsigned char const* getBuffer() const;
DLL_EXPORT
unsigned char* getBuffer();
private:

View File

@ -33,20 +33,25 @@
#include <qpdf/DLL.h>
#include <string>
class DLL_EXPORT Pipeline
class Pipeline
{
public:
DLL_EXPORT
Pipeline(char const* identifier, Pipeline* next);
DLL_EXPORT
virtual ~Pipeline();
// Subclasses should implement write and finish to do their jobs
// and then, if they are not end-of-line pipelines, call
// getNext()->write or getNext()->finish.
DLL_EXPORT
virtual void write(unsigned char* data, int len) = 0;
DLL_EXPORT
virtual void finish() = 0;
protected:
DLL_EXPORT
Pipeline* getNext(bool allow_null = false);
std::string identifier;

View File

@ -24,17 +24,22 @@
#include <qpdf/Buffer.hh>
#include <list>
class DLL_EXPORT Pl_Buffer: public Pipeline
class Pl_Buffer: public Pipeline
{
public:
DLL_EXPORT
Pl_Buffer(char const* identifier, Pipeline* next = 0);
DLL_EXPORT
virtual ~Pl_Buffer();
DLL_EXPORT
virtual void write(unsigned char*, int);
DLL_EXPORT
virtual void finish();
// Each call to getBuffer() resets this object -- see notes above.
// The caller is responsible for deleting the returned Buffer
// object.
DLL_EXPORT
Buffer* getBuffer();
private:

View File

@ -13,17 +13,24 @@
#include <qpdf/Pipeline.hh>
class DLL_EXPORT Pl_Count: public Pipeline
class Pl_Count: public Pipeline
{
public:
DLL_EXPORT
Pl_Count(char const* identifier, Pipeline* next);
DLL_EXPORT
virtual ~Pl_Count();
DLL_EXPORT
virtual void write(unsigned char*, int);
DLL_EXPORT
virtual void finish();
DLL_EXPORT
// Returns the number of bytes written
DLL_EXPORT
int getCount() const;
// Returns the last character written, or '\0' if no characters
// have been written (in which case getCount() returns 0)
DLL_EXPORT
unsigned char getLastChar() const;
private:

View File

@ -16,12 +16,16 @@
#include <qpdf/Pipeline.hh>
class DLL_EXPORT Pl_Discard: public Pipeline
class Pl_Discard: public Pipeline
{
public:
DLL_EXPORT
Pl_Discard();
DLL_EXPORT
virtual ~Pl_Discard();
DLL_EXPORT
virtual void write(unsigned char*, int);
DLL_EXPORT
virtual void finish();
};

View File

@ -12,18 +12,22 @@
#include <zlib.h>
class DLL_EXPORT Pl_Flate: public Pipeline
class Pl_Flate: public Pipeline
{
public:
static int const def_bufsize = 65536;
enum action_e { a_inflate, a_deflate };
DLL_EXPORT
Pl_Flate(char const* identifier, Pipeline* next,
action_e action, int out_bufsize = def_bufsize);
DLL_EXPORT
virtual ~Pl_Flate();
DLL_EXPORT
virtual void write(unsigned char* data, int len);
DLL_EXPORT
virtual void finish();
private:

View File

@ -18,15 +18,19 @@
// This pipeline is reusable.
//
class DLL_EXPORT Pl_StdioFile: public Pipeline
class Pl_StdioFile: public Pipeline
{
public:
// f is externally maintained; this class just writes to and
// flushes it. It does not close it.
DLL_EXPORT
Pl_StdioFile(char const* identifier, FILE* f);
DLL_EXPORT
virtual ~Pl_StdioFile();
DLL_EXPORT
virtual void write(unsigned char* buf, int len);
DLL_EXPORT
virtual void finish();
private:

View File

@ -25,10 +25,12 @@ class BitStream;
class BitWriter;
class QPDFExc;
class DLL_EXPORT QPDF
class QPDF
{
public:
DLL_EXPORT
QPDF();
DLL_EXPORT
~QPDF();
// Associate a file with a QPDF object and do initial parsing of
@ -41,6 +43,7 @@ class DLL_EXPORT QPDF
// encrypted,either a null password or an empty password can be
// used. If the file is encrypted, either the user password or
// the owner password may be supplied.
DLL_EXPORT
void processFile(char const* filename, char const* password = 0);
// Parameter settings
@ -49,18 +52,21 @@ class DLL_EXPORT QPDF
// (one that contains both cross-reference streams and
// cross-reference tables). This can be useful for testing to
// ensure that a hybrid file would work with an older reader.
DLL_EXPORT
void setIgnoreXRefStreams(bool);
// By default, any warnings are issued to stderr as they are
// encountered. If this is called with a true value, reporting of
// warnings is suppressed. You may still retrieve warnings by
// calling getWarnings.
DLL_EXPORT
void setSuppressWarnings(bool);
// By default, QPDF will try to recover if it finds certain types
// of errors in PDF files. If turned off, it will throw an
// exception on the first such problem it finds without attempting
// recovery.
DLL_EXPORT
void setAttemptRecovery(bool);
// Other public methods
@ -70,19 +76,26 @@ class DLL_EXPORT QPDF
// throws an exception. Note that if setSuppressWarnings was not
// called or was called with a false value, any warnings retrieved
// here will have already been issued to stderr.
DLL_EXPORT
std::vector<QPDFExc> getWarnings();
DLL_EXPORT
std::string getFilename() const;
DLL_EXPORT
std::string getPDFVersion() const;
DLL_EXPORT
QPDFObjectHandle getTrailer();
DLL_EXPORT
QPDFObjectHandle getRoot();
// Install this object handle as an indirect object and return an
// indirect reference to it.
DLL_EXPORT
QPDFObjectHandle makeIndirectObject(QPDFObjectHandle);
// Retrieve an object by object ID and generation. Returns an
// indirect reference to it.
DLL_EXPORT
QPDFObjectHandle getObjectByID(int objid, int generation);
// Encryption support
@ -115,31 +128,46 @@ class DLL_EXPORT QPDF
bool encrypt_metadata;
};
DLL_EXPORT
bool isEncrypted() const;
DLL_EXPORT
bool isEncrypted(int& R, int& P);
// Encryption permissions -- not enforced by QPDF
DLL_EXPORT
bool allowAccessibility();
DLL_EXPORT
bool allowExtractAll();
DLL_EXPORT
bool allowPrintLowRes();
DLL_EXPORT
bool allowPrintHighRes();
DLL_EXPORT
bool allowModifyAssembly();
DLL_EXPORT
bool allowModifyForm();
DLL_EXPORT
bool allowModifyAnnotation();
DLL_EXPORT
bool allowModifyOther();
DLL_EXPORT
bool allowModifyAll();
// Helper function to trim padding from user password. Calling
// trim_user_password on the result of getPaddedUserPassword gives
// getTrimmedUserPassword's result.
DLL_EXPORT
static void trim_user_password(std::string& user_password);
DLL_EXPORT
static std::string compute_data_key(
std::string const& encryption_key, int objid, int generation,
bool use_aes);
DLL_EXPORT
static std::string compute_encryption_key(
std::string const& password, EncryptionData const& data);
DLL_EXPORT
static void compute_encryption_O_U(
char const* user_password, char const* owner_password,
int V, int R, int key_len, int P, bool encrypt_metadata,
@ -148,19 +176,23 @@ class DLL_EXPORT QPDF
// Return the full user password as stored in the PDF file. If
// you are attempting to recover the user password in a
// user-presentable form, call getTrimmedUserPassword() instead.
DLL_EXPORT
std::string const& getPaddedUserPassword() const;
// Return human-readable form of user password.
DLL_EXPORT
std::string getTrimmedUserPassword() const;
// Linearization support
// Returns true iff the file starts with a linearization parameter
// dictionary. Does no additional validation.
DLL_EXPORT
bool isLinearized();
// Performs various sanity checks on a linearized file. Return
// true if no errors or warnings. Otherwise, return false and
// output errors and warnings to stdout.
DLL_EXPORT
bool checkLinearization();
// Calls checkLinearization() and, if possible, prints normalized
@ -168,9 +200,11 @@ class DLL_EXPORT QPDF
// includes adding min values to delta values and adjusting
// offsets based on the location and size of the primary hint
// stream.
DLL_EXPORT
void showLinearizationData();
// Shows the contents of the cross-reference table
DLL_EXPORT
void showXRefTable();
// Optimization support -- see doc/optimization. Implemented in
@ -184,26 +218,31 @@ class DLL_EXPORT QPDF
// This is available so that the test suite can make sure that a
// linearized file is already optimized. When called in this way,
// optimize() still populates the object <-> user maps
DLL_EXPORT
void optimize(std::map<int, int> const& object_stream_data,
bool allow_changes = true);
// Replace all references to indirect objects that are "scalars"
// (i.e., things that don't have children: not arrays, streams, or
// dictionaries) with direct objects.
DLL_EXPORT
void flattenScalarReferences();
// Decode all streams, discarding the output. Used to check
// correctness of stream encoding.
DLL_EXPORT
void decodeStreams();
// For QPDFWriter:
// Remove /ID, /Encrypt, and /Prev keys from the trailer
// dictionary since these are regenerated during write.
DLL_EXPORT
void trimTrailerForWrite();
// Get lists of all objects in order according to the part of a
// linearized file that they belong to.
DLL_EXPORT
void getLinearizedParts(
std::map<int, int> const& object_stream_data,
std::vector<QPDFObjectHandle>& part4,
@ -212,6 +251,7 @@ class DLL_EXPORT QPDF
std::vector<QPDFObjectHandle>& part8,
std::vector<QPDFObjectHandle>& part9);
DLL_EXPORT
void generateHintStream(std::map<int, QPDFXRefEntry> const& xref,
std::map<int, size_t> const& lengths,
std::map<int, int> const& obj_renumber,
@ -219,15 +259,18 @@ class DLL_EXPORT QPDF
int& S, int& O);
// Map object to object stream that contains it
DLL_EXPORT
void getObjectStreamData(std::map<int, int>&);
// Get a list of objects that would be permitted in an object
// stream
DLL_EXPORT
std::vector<int> getCompressibleObjects();
// Convenience routines for common functions. See also
// QPDFObjectHandle.hh for additional convenience routines.
// Traverse page tree return all /Page objects.
DLL_EXPORT
std::vector<QPDFObjectHandle> const& getAllPages();
// Resolver class is restricted to QPDFObjectHandle so that only

View File

@ -12,14 +12,16 @@
#include <qpdf/Constants.h>
#include <stdexcept>
class DLL_EXPORT QPDFExc: public std::runtime_error
class QPDFExc: public std::runtime_error
{
public:
DLL_EXPORT
QPDFExc(qpdf_error_code_e error_code,
std::string const& filename,
std::string const& object,
off_t offset,
std::string const& message);
DLL_EXPORT
virtual ~QPDFExc() throw ();
// To get a complete error string, call what(), provided by
@ -32,10 +34,15 @@ class DLL_EXPORT QPDFExc: public std::runtime_error
// the underlying issue, but it is more programmer-friendly than
// trying to parse a string that is subject to change.
DLL_EXPORT
qpdf_error_code_e getErrorCode() const;
DLL_EXPORT
std::string const& getFilename() const;
DLL_EXPORT
std::string const& getObject() const;
DLL_EXPORT
off_t getFilePosition() const;
DLL_EXPORT
std::string const& getMessageDetail() const;
private:

View File

@ -12,7 +12,7 @@
#include <string>
class DLL_EXPORT QPDFObject
class QPDFObject
{
public:
virtual ~QPDFObject() {}

View File

@ -23,40 +23,61 @@
class Pipeline;
class QPDF;
class DLL_EXPORT QPDFObjectHandle
class QPDFObjectHandle
{
public:
DLL_EXPORT
QPDFObjectHandle();
DLL_EXPORT
bool isInitialized() const;
// Exactly one of these will return true for any object.
DLL_EXPORT
bool isBool();
DLL_EXPORT
bool isNull();
DLL_EXPORT
bool isInteger();
DLL_EXPORT
bool isReal();
DLL_EXPORT
bool isName();
DLL_EXPORT
bool isString();
DLL_EXPORT
bool isArray();
DLL_EXPORT
bool isDictionary();
DLL_EXPORT
bool isStream();
// This returns true in addition to the query for the specific
// type for indirect objects.
DLL_EXPORT
bool isIndirect();
// True for everything except array, dictionary, and stream
DLL_EXPORT
bool isScalar();
// Public factory methods
DLL_EXPORT
static QPDFObjectHandle newNull();
DLL_EXPORT
static QPDFObjectHandle newBool(bool value);
DLL_EXPORT
static QPDFObjectHandle newInteger(int value);
DLL_EXPORT
static QPDFObjectHandle newReal(std::string const& value);
DLL_EXPORT
static QPDFObjectHandle newName(std::string const& name);
DLL_EXPORT
static QPDFObjectHandle newString(std::string const& str);
DLL_EXPORT
static QPDFObjectHandle newArray(
std::vector<QPDFObjectHandle> const& items);
DLL_EXPORT
static QPDFObjectHandle newDictionary(
std::map<std::string, QPDFObjectHandle> const& items);
@ -65,58 +86,78 @@ class DLL_EXPORT QPDFObjectHandle
// type, an exception is thrown.
// Methods for bool objects
DLL_EXPORT
bool getBoolValue();
// Methods for integer objects
DLL_EXPORT
int getIntValue();
// Methods for real objects
DLL_EXPORT
std::string getRealValue();
// Methods that work for both integer and real objects
DLL_EXPORT
bool isNumber();
DLL_EXPORT
double getNumericValue();
// Methods for name objects; see also name and array objects
DLL_EXPORT
std::string getName();
// Methods for string objects
DLL_EXPORT
std::string getStringValue();
DLL_EXPORT
std::string getUTF8Value();
// Methods for array objects; see also name and array objects
DLL_EXPORT
int getArrayNItems();
DLL_EXPORT
QPDFObjectHandle getArrayItem(int n);
// Methods for dictionary objects
DLL_EXPORT
bool hasKey(std::string const&);
DLL_EXPORT
QPDFObjectHandle getKey(std::string const&);
DLL_EXPORT
std::set<std::string> getKeys();
// Methods for name and array objects
DLL_EXPORT
bool isOrHasName(std::string const&);
// Mutator methods. Use with caution.
// Recursively copy this object, making it direct. Throws an
// exception if a loop is detected or any sub-object is a stream.
DLL_EXPORT
void makeDirect();
// Mutator methods for array objects
DLL_EXPORT
void setArrayItem(int, QPDFObjectHandle const&);
// Mutator methods for dictionary objects
// Replace value of key, adding it if it does not exist
DLL_EXPORT
void replaceKey(std::string const& key, QPDFObjectHandle const&);
// Remove key, doing nothing if key does not exist
DLL_EXPORT
void removeKey(std::string const& key);
// Methods for stream objects
DLL_EXPORT
QPDFObjectHandle getDict();
// Returns filtered (uncompressed) stream data. Throws an
// exception if the stream is filtered and we can't decode it.
DLL_EXPORT
PointerHolder<Buffer> getStreamData();
// Write stream data through the given pipeline. A null pipeline
@ -136,14 +177,19 @@ class DLL_EXPORT QPDFObjectHandle
// value of this function to determine whether or not the /Filter
// and /DecodeParms keys in the stream dictionary should be
// replaced if writing a new stream object.
DLL_EXPORT
bool pipeStreamData(Pipeline*, bool filter,
bool normalize, bool compress);
// return 0 for direct objects
DLL_EXPORT
int getObjectID() const;
DLL_EXPORT
int getGeneration() const;
DLL_EXPORT
std::string unparse();
DLL_EXPORT
std::string unparseResolved();
// Convenience routines for commonly performed functions
@ -153,6 +199,7 @@ class DLL_EXPORT QPDFObjectHandle
// function does not presently support inherited resources. See
// comment in the source for details. Return value is a map from
// XObject name to the image object, which is always a stream.
DLL_EXPORT
std::map<std::string, QPDFObjectHandle> getPageImages();
// Throws an exception if this is not a Page object. Returns a
@ -160,6 +207,7 @@ class DLL_EXPORT QPDFObjectHandle
// the given page. This routine allows the caller to not care
// whether there are one or more than one content streams for a
// page.
DLL_EXPORT
std::vector<QPDFObjectHandle> getPageContents();
// Initializers for objects. This Factory class gives the QPDF

View File

@ -13,7 +13,7 @@
#include <string>
#include <stdio.h>
class DLL_EXPORT QPDFTokenizer
class QPDFTokenizer
{
public:
enum token_type_e
@ -84,6 +84,7 @@ class DLL_EXPORT QPDFTokenizer
std::string error_message;
};
DLL_EXPORT
QPDFTokenizer();
// PDF files with version < 1.2 allowed the pound character
@ -91,6 +92,7 @@ class DLL_EXPORT QPDFTokenizer
// character was allowed only when followed by two hexadecimal
// digits. This method should be called when parsing a PDF file
// whose version is older than 1.2.
DLL_EXPORT
void allowPoundAnywhereInName();
// Mode of operation:
@ -101,19 +103,23 @@ class DLL_EXPORT QPDFTokenizer
// It these are called when a token is available, an exception
// will be thrown.
DLL_EXPORT
void presentCharacter(char ch);
DLL_EXPORT
void presentEOF();
// If a token is available, return true and initialize token with
// the token, unread_char with whether or not we have to unread
// the last character, and if unread_char, ch with the character
// to unread.
DLL_EXPORT
bool getToken(Token& token, bool& unread_char, char& ch);
// This function returns true of the current character is between
// tokens (i.e., white space that is not part of a string) or is
// part of a comment. A tokenizing filter can call this to
// determine whether to output the character.
DLL_EXPORT
bool betweenTokens();
private:

View File

@ -32,7 +32,7 @@ class QPDF;
class QPDFObjectHandle;
class Pl_Count;
class DLL_EXPORT QPDFWriter
class QPDFWriter
{
public:
// Passing null as filename means write to stdout. QPDFWriter
@ -42,7 +42,9 @@ class DLL_EXPORT QPDFWriter
// useful for tracking down problems. If your application doesn't
// want the partially written file to be left behind, you should
// delete it the eventual call to write fails.
DLL_EXPORT
QPDFWriter(QPDF& pdf, char const* filename);
DLL_EXPORT
~QPDFWriter();
// Set the value of object stream mode. In disable mode, we never
@ -52,6 +54,7 @@ class DLL_EXPORT QPDFWriter
// generate a conventional cross-reference table if there are no
// object streams and a cross-reference stream if there are object
// streams. The default is o_preserve.
DLL_EXPORT
void setObjectStreamMode(qpdf_object_stream_e);
// Set value of stream data mode. In uncompress mode, we attempt
@ -59,6 +62,7 @@ class DLL_EXPORT QPDFWriter
// preserve any filtering applied to streams. In compress mode,
// if we can apply all filters and the stream is not already
// optimally compressed, recompress the stream.
DLL_EXPORT
void setStreamDataMode(qpdf_stream_data_e);
// Set value of content stream normalization. The default is
@ -68,6 +72,7 @@ class DLL_EXPORT QPDFWriter
// damage the content stream. This flag should be used only for
// debugging and experimenting with PDF content streams. Never
// use it for production files.
DLL_EXPORT
void setContentNormalization(bool);
// Set QDF mode. QDF mode causes special "pretty printing" of
@ -75,6 +80,7 @@ class DLL_EXPORT QPDFWriter
// Resulting PDF files can be edited in a text editor and then run
// through fix-qdf to update cross reference tables and stream
// lengths.
DLL_EXPORT
void setQDFMode(bool);
// Set the minimum PDF version. If the PDF version of the input
@ -86,6 +92,7 @@ class DLL_EXPORT QPDFWriter
// QPDFWriter automatically sets the minimum version to 1.4 when
// R3 encryption parameters are used, and to 1.5 when object
// streams are used.
DLL_EXPORT
void setMinimumPDFVersion(std::string const&);
// Force the PDF version of the output file to be a given version.
@ -103,27 +110,32 @@ class DLL_EXPORT QPDFWriter
// that type of encryption will explicitly disable decryption.
// Additionally, forcing to a version below 1.5 will disable
// object streams.
DLL_EXPORT
void forcePDFVersion(std::string const&);
// Cause a static /ID value to be generated. Use only in test
// suites.
DLL_EXPORT
void setStaticID(bool);
// Use a fixed initialization vector for AES-CBC encryption. This
// is not secure. It should be used only in test suites for
// creating predictable encrypted output.
DLL_EXPORT
void setStaticAesIV(bool);
// Suppress inclusion of comments indicating original object IDs
// when writing QDF files. This can also be useful for testing,
// particularly when using comparison of two qdf files to
// determine whether two PDF files have identical content.
DLL_EXPORT
void setSuppressOriginalObjectIDs(bool);
// Preserve encryption. The default is true unless prefilering,
// content normalization, or qdf mode has been selected in which
// case encryption is never preserved. Encryption is also not
// preserved if we explicitly set encryption parameters.
DLL_EXPORT
void setPreserveEncryption(bool);
// Set up for encrypted output. Disables stream prefiltering and
@ -132,14 +144,17 @@ class DLL_EXPORT QPDFWriter
// encryption parameters pushes the PDF version number to at least
// 1.4, and setting R4 parameters pushes the version to at least
// 1.5, or if AES is used, 1.6.
DLL_EXPORT
void setR2EncryptionParameters(
char const* user_password, char const* owner_password,
bool allow_print, bool allow_modify,
bool allow_extract, bool allow_annotate);
DLL_EXPORT
void setR3EncryptionParameters(
char const* user_password, char const* owner_password,
bool allow_accessibility, bool allow_extract,
qpdf_r3_print_e print, qpdf_r3_modify_e modify);
DLL_EXPORT
void setR4EncryptionParameters(
char const* user_password, char const* owner_password,
bool allow_accessibility, bool allow_extract,
@ -148,11 +163,16 @@ class DLL_EXPORT QPDFWriter
// Create linearized output. Disables qdf mode, content
// normalization, and stream prefiltering.
DLL_EXPORT
void setLinearization(bool);
DLL_EXPORT
void write();
private:
QPDFWriter(QPDFWriter const&);
QPDFWriter& operator=(QPDFWriter const&);
// flags used by unparseObject
static int const f_stream = 1 << 0;
static int const f_filtered = 1 << 1;

View File

@ -10,7 +10,7 @@
#include <qpdf/DLL.h>
class DLL_EXPORT QPDFXRefEntry
class QPDFXRefEntry
{
public:
// Type constants are from the PDF spec section
@ -19,12 +19,18 @@ class DLL_EXPORT QPDFXRefEntry
// 1 = "uncompressed"; field 1 = offset
// 2 = "compressed"; field 1 = object stream number, field 2 = index
DLL_EXPORT
QPDFXRefEntry();
DLL_EXPORT
QPDFXRefEntry(int type, int field1, int field2);
DLL_EXPORT
int getType() const;
DLL_EXPORT
int getOffset() const; // only for type 1
DLL_EXPORT
int getObjStreamNumber() const; // only for type 2
DLL_EXPORT
int getObjStreamIndex() const; // only for type 2
private:

View File

@ -5,12 +5,16 @@
#include <qpdf/DLL.h>
class DLL_EXPORT BitStream
class BitStream
{
public:
DLL_EXPORT
BitStream(unsigned char const* p, int nbytes);
DLL_EXPORT
void reset();
DLL_EXPORT
unsigned long getBits(int nbits);
DLL_EXPORT
void skipToNextByte();
private:

View File

@ -7,14 +7,17 @@
class Pipeline;
class DLL_EXPORT BitWriter
class BitWriter
{
public:
// Write bits to the pipeline. It is the caller's responsibility
// to eventually call finish on the pipeline.
DLL_EXPORT
BitWriter(Pipeline* pl);
DLL_EXPORT
void writeBits(unsigned long val, int bits);
// Force any partial byte to be written to the pipeline.
DLL_EXPORT
void flush();
private:

View File

@ -8,41 +8,55 @@
# include <inttypes.h>
#endif
class DLL_EXPORT MD5
class MD5
{
public:
typedef unsigned char Digest[16];
DLL_EXPORT
MD5();
DLL_EXPORT
void reset();
// encodes string and finalizes
DLL_EXPORT
void encodeString(char const* input_string);
// encodes file and finalizes
DLL_EXPORT
void encodeFile(char const* filename, int up_to_size = -1);
// appends string to current md5 object
DLL_EXPORT
void appendString(char const* input_string);
// appends arbitrary data to current md5 object
DLL_EXPORT
void encodeDataIncrementally(char const* input_data, int len);
// computes a raw digest
DLL_EXPORT
void digest(Digest);
// prints the digest to stdout terminated with \r\n (primarily for
// testing)
DLL_EXPORT
void print();
// returns the digest as a hexadecimal string
DLL_EXPORT
std::string unparse();
// Convenience functions
DLL_EXPORT
static std::string getDataChecksum(char const* buf, int len);
static std::string getFileChecksum(char const* filename, int up_to_size = -1);
DLL_EXPORT
static std::string getFileChecksum(char const* filename,
int up_to_size = -1);
DLL_EXPORT
static bool checkDataChecksum(char const* const checksum,
char const* buf, int len);
DLL_EXPORT
static bool checkFileChecksum(char const* const checksum,
char const* filename, int up_to_size = -1);

View File

@ -17,7 +17,7 @@
// Note: this class does not encapsulate all features of the PCRE
// package -- only those that I actually need right now are here.
class DLL_EXPORT PCRE
class PCRE
{
public:
// This is thrown when an attempt is made to access a non-existent
@ -25,6 +25,7 @@ class DLL_EXPORT PCRE
class NoBackref: public std::logic_error
{
public:
DLL_EXPORT
NoBackref();
virtual ~NoBackref() throw() {}
};
@ -33,10 +34,15 @@ class DLL_EXPORT PCRE
{
friend class PCRE;
public:
DLL_EXPORT
Match(int nbackrefs, char const* subject);
DLL_EXPORT
Match(Match const&);
DLL_EXPORT
Match& operator=(Match const&);
DLL_EXPORT
~Match();
DLL_EXPORT
operator bool();
// All the back reference accessing routines may throw the
@ -48,9 +54,13 @@ class DLL_EXPORT PCRE
// and not matching at all.
// see getMatch flags below
DLL_EXPORT
std::string getMatch(int n, int flags = 0);
DLL_EXPORT
void getOffsetLength(int n, int& offset, int& length);
DLL_EXPORT
int getOffset(int n);
DLL_EXPORT
int getLength(int n);
// nMatches returns the number of available matches including
@ -60,6 +70,7 @@ class DLL_EXPORT PCRE
// will return the whole string, getMatch(1) will return the
// text that matched the backreference, and getMatch(2) will
// throw an exception because it is out of range.
DLL_EXPORT
int nMatches() const;
// Flags for getMatch
@ -82,12 +93,16 @@ class DLL_EXPORT PCRE
// The value passed in as options is passed to pcre_exec. See man
// pcreapi for details.
DLL_EXPORT
PCRE(char const* pattern, int options = 0);
DLL_EXPORT
~PCRE();
DLL_EXPORT
Match match(char const* subject, int options = 0, int startoffset = 0,
int size = -1);
DLL_EXPORT
static void test(int n = 0);
private:

View File

@ -7,21 +7,27 @@
// This pipeline implements AES-128 with CBC and block padding as
// specified in the PDF specification.
class DLL_EXPORT Pl_AES_PDF: public Pipeline
class Pl_AES_PDF: public Pipeline
{
public:
// key_data should be a pointer to key_size bytes of data
static unsigned int const key_size = 16;
DLL_EXPORT
Pl_AES_PDF(char const* identifier, Pipeline* next,
bool encrypt, unsigned char const key[key_size]);
DLL_EXPORT
virtual ~Pl_AES_PDF();
DLL_EXPORT
virtual void write(unsigned char* data, int len);
DLL_EXPORT
virtual void finish();
// For testing only; PDF always uses CBC
DLL_EXPORT
void disableCBC();
// For testing only: use a fixed initialization vector for CBC
DLL_EXPORT
static void useStaticIV();
private:

View File

@ -3,12 +3,16 @@
#include <qpdf/Pipeline.hh>
class DLL_EXPORT Pl_ASCII85Decoder: public Pipeline
class Pl_ASCII85Decoder: public Pipeline
{
public:
DLL_EXPORT
Pl_ASCII85Decoder(char const* identifier, Pipeline* next);
DLL_EXPORT
virtual ~Pl_ASCII85Decoder();
DLL_EXPORT
virtual void write(unsigned char* buf, int len);
DLL_EXPORT
virtual void finish();
private:

View File

@ -3,12 +3,16 @@
#include <qpdf/Pipeline.hh>
class DLL_EXPORT Pl_ASCIIHexDecoder: public Pipeline
class Pl_ASCIIHexDecoder: public Pipeline
{
public:
DLL_EXPORT
Pl_ASCIIHexDecoder(char const* identifier, Pipeline* next);
DLL_EXPORT
virtual ~Pl_ASCIIHexDecoder();
DLL_EXPORT
virtual void write(unsigned char* buf, int len);
DLL_EXPORT
virtual void finish();
private:

View File

@ -6,13 +6,17 @@
#include <qpdf/Buffer.hh>
#include <vector>
class DLL_EXPORT Pl_LZWDecoder: public Pipeline
class Pl_LZWDecoder: public Pipeline
{
public:
DLL_EXPORT
Pl_LZWDecoder(char const* identifier, Pipeline* next,
bool early_code_change);
DLL_EXPORT
virtual ~Pl_LZWDecoder();
DLL_EXPORT
virtual void write(unsigned char* buf, int len);
DLL_EXPORT
virtual void finish();
private:

View File

@ -12,13 +12,18 @@
#include <qpdf/Pipeline.hh>
#include <qpdf/MD5.hh>
class DLL_EXPORT Pl_MD5: public Pipeline
class Pl_MD5: public Pipeline
{
public:
DLL_EXPORT
Pl_MD5(char const* identifier, Pipeline* next);
DLL_EXPORT
virtual ~Pl_MD5();
DLL_EXPORT
virtual void write(unsigned char*, int);
DLL_EXPORT
virtual void finish();
DLL_EXPORT
std::string getHexDigest();
private:

View File

@ -16,18 +16,22 @@
#include <qpdf/Pipeline.hh>
class DLL_EXPORT Pl_PNGFilter: public Pipeline
class Pl_PNGFilter: public Pipeline
{
public:
// Encoding is not presently supported
enum action_e { a_encode, a_decode };
DLL_EXPORT
Pl_PNGFilter(char const* identifier, Pipeline* next,
action_e action, unsigned int columns,
unsigned int bytes_per_pixel);
DLL_EXPORT
virtual ~Pl_PNGFilter();
DLL_EXPORT
virtual void write(unsigned char* data, int len);
DLL_EXPORT
virtual void finish();
private:

View File

@ -5,18 +5,22 @@
#include <qpdf/RC4.hh>
class DLL_EXPORT Pl_RC4: public Pipeline
class Pl_RC4: public Pipeline
{
public:
static int const def_bufsize = 65536;
// key_len of -1 means treat key_data as a null-terminated string
DLL_EXPORT
Pl_RC4(char const* identifier, Pipeline* next,
unsigned char const* key_data, int key_len = -1,
int out_bufsize = def_bufsize);
DLL_EXPORT
virtual ~Pl_RC4();
DLL_EXPORT
virtual void write(unsigned char* data, int len);
DLL_EXPORT
virtual void finish();
private: