summaryrefslogtreecommitdiff
path: root/poppler
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <mpg@redhat.com>2005-09-16 19:33:05 +0000
committerMarco Pesenti Gritti <mpg@redhat.com>2005-09-16 19:33:05 +0000
commitdb62e07fcf57f45951b21f8aab44b0d943efe5d0 (patch)
treeab286075a07a425f0fd1a662485e165ad78ecedf /poppler
parent3acc7be594712fd0ce7ac07b7188d5b38b382782 (diff)
2005-09-16 Marco Pesenti Gritti <mpg@redhat.com>
* poppler/PDFDoc.cc: * poppler/PDFDoc.h: * poppler/XRef.cc: * poppler/XRef.h: Merge more from 3.01
Diffstat (limited to 'poppler')
-rw-r--r--poppler/PDFDoc.cc20
-rw-r--r--poppler/PDFDoc.h19
-rw-r--r--poppler/XRef.cc13
-rw-r--r--poppler/XRef.h7
4 files changed, 41 insertions, 18 deletions
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 6803e27a..03a47814 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -46,13 +46,15 @@
//------------------------------------------------------------------------
PDFDoc::PDFDoc(GooString *fileNameA, GooString *ownerPassword,
- GooString *userPassword) {
+ GooString *userPassword, void *guiDataA) {
Object obj;
GooString *fileName1, *fileName2;
ok = gFalse;
errCode = errNone;
+ guiData = guiDataA;
+
file = NULL;
str = NULL;
xref = NULL;
@@ -99,9 +101,10 @@ PDFDoc::PDFDoc(GooString *fileNameA, GooString *ownerPassword,
}
PDFDoc::PDFDoc(BaseStream *strA, GooString *ownerPassword,
- GooString *userPassword) {
+ GooString *userPassword, void *guiDataA) {
ok = gFalse;
errCode = errNone;
+ guiData = guiDataA;
fileName = NULL;
file = NULL;
str = strA;
@@ -124,13 +127,19 @@ GBool PDFDoc::setup(GooString *ownerPassword, GooString *userPassword) {
checkHeader();
// read xref table
- xref = new XRef(str, ownerPassword, userPassword);
+ xref = new XRef(str);
if (!xref->isOk()) {
error(-1, "Couldn't read xref table");
errCode = xref->getErrorCode();
return gFalse;
}
+ // check for encryption
+ if (!checkEncryption(ownerPassword, userPassword)) {
+ errCode = errEncrypted;
+ return gFalse;
+ }
+
// read catalog
catalog = new Catalog(xref);
if (!catalog->isOk()) {
@@ -232,7 +241,10 @@ void PDFDoc::checkHeader() {
return;
}
str->moveStart(i);
- p = strtok(&hdrBuf[i+5], " \t\n\r");
+ if (!(p = strtok(&hdrBuf[i+5], " \t\n\r"))) {
+ error(-1, "May not be a PDF file (continuing anyway)");
+ return;
+ }
{
char *theLocale = setlocale(LC_NUMERIC, "C");
pdfVersion = atof(p);
diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h
index 8ca8852c..758a3811 100644
--- a/poppler/PDFDoc.h
+++ b/poppler/PDFDoc.h
@@ -15,7 +15,6 @@
#include <stdio.h>
#include "XRef.h"
-#include "Link.h"
#include "Catalog.h"
#include "Page.h"
#include "Annot.h"
@@ -36,9 +35,9 @@ class PDFDoc {
public:
PDFDoc(GooString *fileNameA, GooString *ownerPassword = NULL,
- GooString *userPassword = NULL);
+ GooString *userPassword = NULL, void *guiDataA = NULL);
PDFDoc(BaseStream *strA, GooString *ownerPassword = NULL,
- GooString *userPassword = NULL);
+ GooString *userPassword = NULL, void *guiDataA = NULL);
~PDFDoc();
// Was PDF document successfully opened?
@@ -108,13 +107,9 @@ public:
// not found.
int findPage(int num, int gen) { return catalog->findPage(num, gen); }
- // If point <x>,<y> is in a link, return the associated action;
- // else return NULL.
- LinkAction *findLink(double x, double y)
- { return links ? links->find(x, y) : (LinkAction *)NULL; }
-
- // Return true if <x>,<y> is in a link.
- GBool onLink(double x, double y) { return links->onLink(x, y); }
+ // Returns the links for the current page, transferring ownership to
+ // the caller.
+ Links *takeLinks();
// Find a named destination. Returns the link destination, or
// NULL if <name> is not a destination.
@@ -161,6 +156,9 @@ public:
// Save this file with another name.
GBool saveAs(GooString *name);
+ // Return a pointer to the GUI (XPDFCore or WinPDFCore object).
+ void *getGUIData() { return guiData; }
+
private:
GBool setup(GooString *ownerPassword, GooString *userPassword);
@@ -172,6 +170,7 @@ private:
GooString *fileName;
FILE *file;
BaseStream *str;
+ void *guiData;
double pdfVersion;
XRef *xref;
Catalog *catalog;
diff --git a/poppler/XRef.cc b/poppler/XRef.cc
index 4b836301..2dc7867f 100644
--- a/poppler/XRef.cc
+++ b/poppler/XRef.cc
@@ -201,7 +201,7 @@ Object *ObjectStream::getObject(int objIdx, int objNum, Object *obj) {
// XRef
//------------------------------------------------------------------------
-XRef::XRef(BaseStream *strA, GooString *ownerPassword, GooString *userPassword) {
+XRef::XRef(BaseStream *strA) {
Guint pos;
Object obj;
@@ -217,6 +217,10 @@ XRef::XRef(BaseStream *strA, GooString *ownerPassword, GooString *userPassword)
permFlags = defPermFlags;
ownerPasswordOk = gFalse;
+ encrypted = gFalse;
+ permFlags = defPermFlags;
+ ownerPasswordOk = gFalse;
+
// read the trailer
str = strA;
start = str->getStart();
@@ -466,6 +470,7 @@ GBool XRef::readXRefTable(Parser *parser, Guint *pos) {
pos2 = (Guint)obj2.getInt();
readXRef(&pos2);
if (!ok) {
+ obj2.free();
goto err1;
}
}
@@ -686,7 +691,7 @@ GBool XRef::constructXRef() {
obj.initNull();
parser = new Parser(NULL,
new Lexer(NULL,
- str->makeSubStream(start + pos + 7, gFalse, 0, &obj)));
+ str->makeSubStream(pos + 7, gFalse, 0, &obj)));
parser->getObj(&newTrailerDict);
if (newTrailerDict.isDict()) {
newTrailerDict.dictLookupNF("Root", &obj);
@@ -865,6 +870,10 @@ Object *XRef::fetch(int num, int gen, Object *obj) {
if (!obj1.isInt() || obj1.getInt() != num ||
!obj2.isInt() || obj2.getInt() != gen ||
!obj3.isCmd("obj")) {
+ obj1.free();
+ obj2.free();
+ obj3.free();
+ delete parser;
goto err;
}
parser->getObj(obj, encrypted ? fileKey : (Guchar *)NULL, keyLength,
diff --git a/poppler/XRef.h b/poppler/XRef.h
index d2e9e729..b1382b2a 100644
--- a/poppler/XRef.h
+++ b/poppler/XRef.h
@@ -41,7 +41,7 @@ class XRef {
public:
// Constructor. Read xref table from stream.
- XRef(BaseStream *strA, GooString *ownerPassword, GooString *userPassword);
+ XRef(BaseStream *strA);
// Destructor.
~XRef();
@@ -57,6 +57,10 @@ public:
Guchar *fileKeyA, int keyLengthA,
int encVersionA, int encRevisionA);
+ // Set the encryption parameters.
+ void setEncryption(int permFlagsA, GBool ownerPasswordOkA,
+ Guchar *fileKeyA, int keyLengthA, int encVersionA);
+
// Is the file encrypted?
GBool isEncrypted() { return encrypted; }
@@ -129,7 +133,6 @@ private:
GBool readXRefStreamSection(Stream *xrefStr, int *w, int first, int n);
GBool readXRefStream(Stream *xrefStr, Guint *pos);
GBool constructXRef();
- GBool checkEncrypted(GooString *ownerPassword, GooString *userPassword);
Guint strToUnsigned(char *s);
};