mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
Encryption info usage (in progress)
This commit is contained in:
parent
6902f72b31
commit
746f19b874
5 changed files with 29 additions and 30 deletions
|
@ -19,14 +19,16 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
//#include <ZLLogger.h>
|
#include <ZLLogger.h>
|
||||||
#include <ZLStringUtil.h>
|
#include <ZLStringUtil.h>
|
||||||
#include <ZLUnicodeUtil.h>
|
#include <ZLUnicodeUtil.h>
|
||||||
#include <ZLFile.h>
|
#include <ZLFile.h>
|
||||||
#include <ZLFileImage.h>
|
#include <ZLFileImage.h>
|
||||||
#include <ZLXMLNamespace.h>
|
#include <ZLXMLNamespace.h>
|
||||||
|
|
||||||
|
#include "../EncryptionInfo.h"
|
||||||
#include "OEBBookReader.h"
|
#include "OEBBookReader.h"
|
||||||
|
#include "OEBEncryptionReader.h"
|
||||||
#include "XHTMLImageFinder.h"
|
#include "XHTMLImageFinder.h"
|
||||||
#include "NCXReader.h"
|
#include "NCXReader.h"
|
||||||
#include "../xhtml/XHTMLReader.h"
|
#include "../xhtml/XHTMLReader.h"
|
||||||
|
@ -185,6 +187,16 @@ void OEBBookReader::endElementHandler(const char *tag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OEBBookReader::readBook(const ZLFile &file) {
|
bool OEBBookReader::readBook(const ZLFile &file) {
|
||||||
|
ZLLogger::Instance().registerClass("MARLIN");
|
||||||
|
ZLLogger::Instance().println("MARLIN", "opf file = " + file.path());
|
||||||
|
const ZLFile epub = file.getContainerArchive();
|
||||||
|
epub.forceArchiveType(ZLFile::ZIP);
|
||||||
|
const std::vector<shared_ptr<EncryptionInfo> > encodingInfos =
|
||||||
|
OEBEncryptionReader().readEncryptionInfos(epub);
|
||||||
|
for (std::vector<shared_ptr<EncryptionInfo> >::const_iterator it = encodingInfos.begin(); it != encodingInfos.end(); ++it) {
|
||||||
|
ZLLogger::Instance().println("MARLIN", std::string("INFO: ") + (*it)->Uri + " :: " + (*it)->Algorithm + " :: " + (*it)->ContentId);
|
||||||
|
}
|
||||||
|
|
||||||
myFilePrefix = MiscUtil::htmlDirectoryPrefix(file.path());
|
myFilePrefix = MiscUtil::htmlDirectoryPrefix(file.path());
|
||||||
|
|
||||||
myIdToHref.clear();
|
myIdToHref.clear();
|
||||||
|
@ -222,7 +234,8 @@ bool OEBBookReader::readBook(const ZLFile &file) {
|
||||||
myModelReader.insertEndOfSectionParagraph();
|
myModelReader.insertEndOfSectionParagraph();
|
||||||
}
|
}
|
||||||
//ZLLogger::Instance().println("oeb", "start " + xhtmlFile.path());
|
//ZLLogger::Instance().println("oeb", "start " + xhtmlFile.path());
|
||||||
xhtmlReader.readFile(xhtmlFile, *it);
|
shared_ptr<EncryptionInfo> encryptionInfo;
|
||||||
|
xhtmlReader.readFile(xhtmlFile, *it, encryptionInfo);
|
||||||
//ZLLogger::Instance().println("oeb", "end " + xhtmlFile.path());
|
//ZLLogger::Instance().println("oeb", "end " + xhtmlFile.path());
|
||||||
//std::string debug = "para count = ";
|
//std::string debug = "para count = ";
|
||||||
//ZLStringUtil::appendNumber(debug, myModelReader.model().bookTextModel()->paragraphsNumber());
|
//ZLStringUtil::appendNumber(debug, myModelReader.model().bookTextModel()->paragraphsNumber());
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <ZLXMLReader.h>
|
#include <ZLXMLReader.h>
|
||||||
|
|
||||||
#include "../FormatPlugin.h"
|
#include "../FormatPlugin.h"
|
||||||
|
#include "../EncryptionInfo.h"
|
||||||
#include "OEBEncryptionReader.h"
|
#include "OEBEncryptionReader.h"
|
||||||
|
|
||||||
class EpubRightsFileReader : public ZLXMLReader {
|
class EpubRightsFileReader : public ZLXMLReader {
|
||||||
|
@ -44,7 +45,7 @@ class EpubEncryptionFileReader : public ZLXMLReader {
|
||||||
public:
|
public:
|
||||||
EpubEncryptionFileReader();
|
EpubEncryptionFileReader();
|
||||||
|
|
||||||
const std::vector<EncryptionInfo> &infos() const;
|
const std::vector<shared_ptr<EncryptionInfo> > &infos() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void startElementHandler(const char *tag, const char **attributes);
|
void startElementHandler(const char *tag, const char **attributes);
|
||||||
|
@ -64,7 +65,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<EncryptionInfo> myInfos;
|
std::vector<shared_ptr<EncryptionInfo> > myInfos;
|
||||||
|
|
||||||
State myState;
|
State myState;
|
||||||
std::string myAlgorithm;
|
std::string myAlgorithm;
|
||||||
|
@ -92,7 +93,7 @@ std::string OEBEncryptionReader::readEncryptionMethod(const ZLFile &epubFile) {
|
||||||
return reader.method();
|
return reader.method();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<EncryptionInfo> OEBEncryptionReader::readEncryptionInfo(const ZLFile &epubFile) {
|
std::vector<shared_ptr<EncryptionInfo> > OEBEncryptionReader::readEncryptionInfos(const ZLFile &epubFile) {
|
||||||
const std::string method = readEncryptionMethod(epubFile);
|
const std::string method = readEncryptionMethod(epubFile);
|
||||||
if (method == FormatPlugin::EncryptionMethod::MARLIN) {
|
if (method == FormatPlugin::EncryptionMethod::MARLIN) {
|
||||||
shared_ptr<ZLDir> epubDir = epubFile.directory();
|
shared_ptr<ZLDir> epubDir = epubFile.directory();
|
||||||
|
@ -103,7 +104,7 @@ std::vector<EncryptionInfo> OEBEncryptionReader::readEncryptionInfo(const ZLFile
|
||||||
return reader.infos();
|
return reader.infos();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return std::vector<EncryptionInfo>();
|
return std::vector<shared_ptr<EncryptionInfo> >();
|
||||||
}
|
}
|
||||||
|
|
||||||
EpubRightsFileReader::EpubRightsFileReader() : myMethod(FormatPlugin::EncryptionMethod::UNSUPPORTED) {
|
EpubRightsFileReader::EpubRightsFileReader() : myMethod(FormatPlugin::EncryptionMethod::UNSUPPORTED) {
|
||||||
|
@ -124,17 +125,10 @@ bool EpubRightsFileReader::processNamespaces() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
EncryptionInfo::EncryptionInfo(const std::string &uri, const std::string &algorithm, const std::string &contentId) : Uri(uri), Algorithm(algorithm), ContentId(contentId) {
|
|
||||||
}
|
|
||||||
|
|
||||||
EpubEncryptionFileReader::EpubEncryptionFileReader() : myState(READ_NONE) {
|
EpubEncryptionFileReader::EpubEncryptionFileReader() : myState(READ_NONE) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<EncryptionInfo> &EpubEncryptionFileReader::infos() const {
|
const std::vector<shared_ptr<EncryptionInfo> > &EpubEncryptionFileReader::infos() const {
|
||||||
//ZLLogger::Instance().registerClass("MARLIN");
|
|
||||||
//for (std::vector<EncryptionInfo>::const_iterator it = myInfos.begin(); it != myInfos.end(); ++it) {
|
|
||||||
// ZLLogger::Instance().println("MARLIN", std::string("INFO: ") + it->Uri + " :: " + it->Algorithm + " :: " + it->ContentId);
|
|
||||||
//}
|
|
||||||
return myInfos;
|
return myInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +204,7 @@ void EpubEncryptionFileReader::endElementHandler(const char *tag) {
|
||||||
break;
|
break;
|
||||||
case READ_ENCRYPTED_DATA:
|
case READ_ENCRYPTED_DATA:
|
||||||
if (testTag(ZLXMLNamespace::XMLEncryption, "EncryptedData", tag)) {
|
if (testTag(ZLXMLNamespace::XMLEncryption, "EncryptedData", tag)) {
|
||||||
myInfos.push_back(EncryptionInfo(myUri, myAlgorithm, myKeyName));
|
myInfos.push_back(new EncryptionInfo(myUri, myAlgorithm, myKeyName));
|
||||||
myState = READ_ENCRYPTION;
|
myState = READ_ENCRYPTION;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -23,25 +23,15 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <shared_ptr.h>
|
||||||
#include <ZLFile.h>
|
#include <ZLFile.h>
|
||||||
|
|
||||||
class EncryptionInfo {
|
class EncryptionInfo;
|
||||||
|
|
||||||
public:
|
|
||||||
EncryptionInfo(const std::string &uri, const std::string &algorithm, const std::string &contentId);
|
|
||||||
|
|
||||||
public:
|
|
||||||
const std::string Uri;
|
|
||||||
const std::string Algorithm;
|
|
||||||
const std::string ContentId;
|
|
||||||
|
|
||||||
friend class OEBEncryptionReader;
|
|
||||||
};
|
|
||||||
|
|
||||||
class OEBEncryptionReader {
|
class OEBEncryptionReader {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<EncryptionInfo> readEncryptionInfo(const ZLFile &file);
|
std::vector<shared_ptr<EncryptionInfo> > readEncryptionInfos(const ZLFile &file);
|
||||||
std::string readEncryptionMethod(const ZLFile &file);
|
std::string readEncryptionMethod(const ZLFile &file);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -530,7 +530,7 @@ void XHTMLReader::setMarkFirstImageAsCover() {
|
||||||
myMarkNextImageAsCover = true;
|
myMarkNextImageAsCover = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XHTMLReader::readFile(const ZLFile &file, const std::string &referenceName) {
|
bool XHTMLReader::readFile(const ZLFile &file, const std::string &referenceName, shared_ptr<EncryptionInfo> encryptionInfo) {
|
||||||
fillTagTable();
|
fillTagTable();
|
||||||
|
|
||||||
myPathPrefix = MiscUtil::htmlDirectoryPrefix(file.path());
|
myPathPrefix = MiscUtil::htmlDirectoryPrefix(file.path());
|
||||||
|
|
|
@ -34,6 +34,8 @@ class ZLFile;
|
||||||
class BookReader;
|
class BookReader;
|
||||||
class XHTMLReader;
|
class XHTMLReader;
|
||||||
|
|
||||||
|
class EncryptionInfo;
|
||||||
|
|
||||||
class XHTMLTagAction {
|
class XHTMLTagAction {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -62,7 +64,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
XHTMLReader(BookReader &modelReader);
|
XHTMLReader(BookReader &modelReader);
|
||||||
bool readFile(const ZLFile &file, const std::string &referenceName);
|
bool readFile(const ZLFile &file, const std::string &referenceName, shared_ptr<EncryptionInfo> encryptionInfo);
|
||||||
const std::string &fileAlias(const std::string &fileName) const;
|
const std::string &fileAlias(const std::string &fileName) const;
|
||||||
const std::string normalizedReference(const std::string &reference) const;
|
const std::string normalizedReference(const std::string &reference) const;
|
||||||
void setMarkFirstImageAsCover();
|
void setMarkFirstImageAsCover();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue