summaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2010-10-01 12:20:38 +0200
committerJay Berkenbilt <ejb@ql.org>2010-10-01 12:20:38 +0200
commit9f444ffef3c11201d0a460b14b6234d3319ce861 (patch)
treee9d89e8e9bc440b0ea2df3963833158d6dfdf866 /libqpdf/QPDF.cc
parent359999a59cc1befdc94115d3cd17cb95a0ebdb49 (diff)
downloadqpdf-9f444ffef3c11201d0a460b14b6234d3319ce861.tar.zst
add QPDF::processMemoryFile and API additions to support it
git-svn-id: svn+q:///qpdf/trunk@1034 71b93d88-0707-0410-a8cf-f5a4172ac649
Diffstat (limited to 'libqpdf/QPDF.cc')
-rw-r--r--libqpdf/QPDF.cc34
1 files changed, 26 insertions, 8 deletions
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)