From 9f444ffef3c11201d0a460b14b6234d3319ce861 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 1 Oct 2010 10:20:38 +0000 Subject: add QPDF::processMemoryFile and API additions to support it git-svn-id: svn+q:///qpdf/trunk@1034 71b93d88-0707-0410-a8cf-f5a4172ac649 --- libqpdf/QPDF.cc | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'libqpdf/QPDF.cc') diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index bf9beac5..3ea0f813 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -159,7 +159,8 @@ QPDF::FileInputSource::unreadCh(char ch) } QPDF::BufferInputSource::BufferInputSource(std::string const& description, - Buffer* buf) : + Buffer* buf, bool own_memory) : + own_memory(own_memory), description(description), buf(buf), cur_offset(0) @@ -168,6 +169,10 @@ QPDF::BufferInputSource::BufferInputSource(std::string const& description, QPDF::BufferInputSource::~BufferInputSource() { + if (own_memory) + { + delete this->buf; + } } std::string const& @@ -192,7 +197,7 @@ QPDF::BufferInputSource::seek(off_t offset, int whence) break; case SEEK_END: - this->cur_offset = this->buf->getSize() - offset; + this->cur_offset = this->buf->getSize() + offset; break; case SEEK_CUR: @@ -306,11 +311,19 @@ QPDF::processFile(char const* filename, char const* password) FileInputSource* fi = new FileInputSource(); this->file = fi; fi->setFilename(filename); - if (password) - { - this->provided_password = password; - } - parse(); + parse(password); +} + +void +QPDF::processMemoryFile(char const* description, + char const* buf, size_t length, + char const* password) +{ + this->file = + new BufferInputSource(description, + new Buffer((unsigned char*)buf, length), + true); + parse(password); } void @@ -340,11 +353,16 @@ QPDF::getWarnings() } void -QPDF::parse() +QPDF::parse(char const* password) { static PCRE header_re("^%PDF-(1.\\d+)\\b"); static PCRE eof_re("(?s:startxref\\s+(\\d+)\\s+%%EOF\\b)"); + if (password) + { + this->provided_password = password; + } + std::string line = this->file->readLine(); PCRE::Match m1 = header_re.match(line.c_str()); if (m1) -- cgit v1.2.3-54-g00ecf