mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39: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 <ZLLogger.h>
|
||||
#include <ZLLogger.h>
|
||||
#include <ZLStringUtil.h>
|
||||
#include <ZLUnicodeUtil.h>
|
||||
#include <ZLFile.h>
|
||||
#include <ZLFileImage.h>
|
||||
#include <ZLXMLNamespace.h>
|
||||
|
||||
#include "../EncryptionInfo.h"
|
||||
#include "OEBBookReader.h"
|
||||
#include "OEBEncryptionReader.h"
|
||||
#include "XHTMLImageFinder.h"
|
||||
#include "NCXReader.h"
|
||||
#include "../xhtml/XHTMLReader.h"
|
||||
|
@ -185,6 +187,16 @@ void OEBBookReader::endElementHandler(const char *tag) {
|
|||
}
|
||||
|
||||
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());
|
||||
|
||||
myIdToHref.clear();
|
||||
|
@ -222,7 +234,8 @@ bool OEBBookReader::readBook(const ZLFile &file) {
|
|||
myModelReader.insertEndOfSectionParagraph();
|
||||
}
|
||||
//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());
|
||||
//std::string debug = "para count = ";
|
||||
//ZLStringUtil::appendNumber(debug, myModelReader.model().bookTextModel()->paragraphsNumber());
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <ZLXMLReader.h>
|
||||
|
||||
#include "../FormatPlugin.h"
|
||||
#include "../EncryptionInfo.h"
|
||||
#include "OEBEncryptionReader.h"
|
||||
|
||||
class EpubRightsFileReader : public ZLXMLReader {
|
||||
|
@ -44,7 +45,7 @@ class EpubEncryptionFileReader : public ZLXMLReader {
|
|||
public:
|
||||
EpubEncryptionFileReader();
|
||||
|
||||
const std::vector<EncryptionInfo> &infos() const;
|
||||
const std::vector<shared_ptr<EncryptionInfo> > &infos() const;
|
||||
|
||||
private:
|
||||
void startElementHandler(const char *tag, const char **attributes);
|
||||
|
@ -64,7 +65,7 @@ private:
|
|||
};
|
||||
|
||||
private:
|
||||
std::vector<EncryptionInfo> myInfos;
|
||||
std::vector<shared_ptr<EncryptionInfo> > myInfos;
|
||||
|
||||
State myState;
|
||||
std::string myAlgorithm;
|
||||
|
@ -92,7 +93,7 @@ std::string OEBEncryptionReader::readEncryptionMethod(const ZLFile &epubFile) {
|
|||
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);
|
||||
if (method == FormatPlugin::EncryptionMethod::MARLIN) {
|
||||
shared_ptr<ZLDir> epubDir = epubFile.directory();
|
||||
|
@ -103,7 +104,7 @@ std::vector<EncryptionInfo> OEBEncryptionReader::readEncryptionInfo(const ZLFile
|
|||
return reader.infos();
|
||||
}
|
||||
}
|
||||
return std::vector<EncryptionInfo>();
|
||||
return std::vector<shared_ptr<EncryptionInfo> >();
|
||||
}
|
||||
|
||||
EpubRightsFileReader::EpubRightsFileReader() : myMethod(FormatPlugin::EncryptionMethod::UNSUPPORTED) {
|
||||
|
@ -124,17 +125,10 @@ bool EpubRightsFileReader::processNamespaces() const {
|
|||
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) {
|
||||
}
|
||||
|
||||
const std::vector<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);
|
||||
//}
|
||||
const std::vector<shared_ptr<EncryptionInfo> > &EpubEncryptionFileReader::infos() const {
|
||||
return myInfos;
|
||||
}
|
||||
|
||||
|
@ -210,7 +204,7 @@ void EpubEncryptionFileReader::endElementHandler(const char *tag) {
|
|||
break;
|
||||
case READ_ENCRYPTED_DATA:
|
||||
if (testTag(ZLXMLNamespace::XMLEncryption, "EncryptedData", tag)) {
|
||||
myInfos.push_back(EncryptionInfo(myUri, myAlgorithm, myKeyName));
|
||||
myInfos.push_back(new EncryptionInfo(myUri, myAlgorithm, myKeyName));
|
||||
myState = READ_ENCRYPTION;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -23,25 +23,15 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <shared_ptr.h>
|
||||
#include <ZLFile.h>
|
||||
|
||||
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 EncryptionInfo;
|
||||
|
||||
class OEBEncryptionReader {
|
||||
|
||||
public:
|
||||
std::vector<EncryptionInfo> readEncryptionInfo(const ZLFile &file);
|
||||
std::vector<shared_ptr<EncryptionInfo> > readEncryptionInfos(const ZLFile &file);
|
||||
std::string readEncryptionMethod(const ZLFile &file);
|
||||
};
|
||||
|
||||
|
|
|
@ -530,7 +530,7 @@ void XHTMLReader::setMarkFirstImageAsCover() {
|
|||
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();
|
||||
|
||||
myPathPrefix = MiscUtil::htmlDirectoryPrefix(file.path());
|
||||
|
|
|
@ -34,6 +34,8 @@ class ZLFile;
|
|||
class BookReader;
|
||||
class XHTMLReader;
|
||||
|
||||
class EncryptionInfo;
|
||||
|
||||
class XHTMLTagAction {
|
||||
|
||||
public:
|
||||
|
@ -62,7 +64,7 @@ private:
|
|||
|
||||
public:
|
||||
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 normalizedReference(const std::string &reference) const;
|
||||
void setMarkFirstImageAsCover();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue