diff --git a/jni/NativeFormats/JavaNativeFormatPlugin.cpp b/jni/NativeFormats/JavaNativeFormatPlugin.cpp index b7fb3915d..659c5f108 100644 --- a/jni/NativeFormats/JavaNativeFormatPlugin.cpp +++ b/jni/NativeFormats/JavaNativeFormatPlugin.cpp @@ -130,6 +130,17 @@ JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin return 0; } +extern "C" +JNIEXPORT jstring JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readEncryptionType(JNIEnv* env, jobject thiz, jobject javaBook) { + shared_ptr plugin = findCppPlugin(thiz); + if (plugin.isNull()) { + return AndroidUtil::createJavaString(env, FormatPlugin::EncryptionType::UNKNOWN); + } + + shared_ptr book = Book::loadFromJavaBook(env, javaBook); + return AndroidUtil::createJavaString(env, plugin->readEncryptionType(*book)); +} + extern "C" JNIEXPORT void JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readUidsNative(JNIEnv* env, jobject thiz, jobject javaBook) { shared_ptr plugin = findCppPlugin(thiz); diff --git a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp index 6e9768c97..1084107ed 100644 --- a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp +++ b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp @@ -28,6 +28,10 @@ #include "../library/Book.h" +const std::string FormatPlugin::EncryptionType::NONE = "none"; +const std::string FormatPlugin::EncryptionType::UNKNOWN = "unknown"; +const std::string FormatPlugin::EncryptionType::MARLIN = "marlin"; + bool FormatPlugin::detectEncodingAndLanguage(Book &book, ZLInputStream &stream, bool force) { std::string language = book.language(); std::string encoding = book.encoding(); @@ -99,6 +103,10 @@ const std::string &FormatPlugin::tryOpen(const ZLFile&) const { return EMPTY; } +const std::string &FormatPlugin::readEncryptionType(Book &book) const { + return EncryptionType::NONE; +} + shared_ptr FormatPlugin::coverImage(const ZLFile &file) const { return 0; } diff --git a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h index e32d0d31c..e0ebb7f40 100644 --- a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h +++ b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h @@ -46,6 +46,15 @@ public: class FormatPlugin { +public: + class EncryptionType { + + public: + static const std::string NONE; + static const std::string UNKNOWN; + static const std::string MARLIN; + }; + protected: FormatPlugin(); @@ -58,6 +67,7 @@ public: virtual const std::string &tryOpen(const ZLFile &file) const; virtual bool readMetaInfo(Book &book) const = 0; + virtual const std::string &readEncryptionType(Book &book) const; virtual bool readUids(Book &book) const = 0; virtual bool readLanguageAndEncoding(Book &book) const = 0; virtual bool readModel(BookModel &model) const = 0; diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/OEBEncryptionReader.cpp b/jni/NativeFormats/fbreader/src/formats/oeb/OEBEncryptionReader.cpp index 360c5cfcb..3b4bbe9ea 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/OEBEncryptionReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/oeb/OEBEncryptionReader.cpp @@ -21,28 +21,31 @@ #include #include +#include "../FormatPlugin.h" #include "OEBEncryptionReader.h" -OEBEncryptionReader::OEBEncryptionReader() : myType("unknown") { +OEBEncryptionReader::OEBEncryptionReader() : myIsMarlin(false) { } -std::string OEBEncryptionReader::readEncryptionInfo(const ZLFile &epubFile) { +const std::string &OEBEncryptionReader::readEncryptionInfo(const ZLFile &epubFile) { shared_ptr epubDir = epubFile.directory(); - if (!epubDir.isNull()) { - const ZLFile rightsFile(epubDir->itemPath("META-INF/rights.xml")); - if (rightsFile.exists()) { - readDocument(rightsFile); - } else { - myType = "none"; - } + if (epubDir.isNull()) { + return FormatPlugin::EncryptionType::UNKNOWN; + } + + const ZLFile rightsFile(epubDir->itemPath("META-INF/rights.xml")); + if (rightsFile.exists()) { + readDocument(rightsFile); + return myIsMarlin + ? FormatPlugin::EncryptionType::MARLIN + : FormatPlugin::EncryptionType::UNKNOWN; + } else { + return FormatPlugin::EncryptionType::NONE; } - return myType; } void OEBEncryptionReader::startElementHandler(const char *tag, const char **attributes) { - if (testTag(ZLXMLNamespace::MarlinEpub, "Marlin", tag)) { - myType = "marlin"; - } + myIsMarlin = testTag(ZLXMLNamespace::MarlinEpub, "Marlin", tag); interrupt(); } diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/OEBEncryptionReader.h b/jni/NativeFormats/fbreader/src/formats/oeb/OEBEncryptionReader.h index e271f638d..f0da79b6a 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/OEBEncryptionReader.h +++ b/jni/NativeFormats/fbreader/src/formats/oeb/OEBEncryptionReader.h @@ -29,14 +29,14 @@ class OEBEncryptionReader : public ZLXMLReader { public: OEBEncryptionReader(); - std::string readEncryptionInfo(const ZLFile &file); + const std::string &readEncryptionInfo(const ZLFile &file); private: void startElementHandler(const char *tag, const char **attributes); bool processNamespaces() const; private: - std::string myType; + bool myIsMarlin; }; #endif /* __OEBENCRYPTIONREADER_H__ */ diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.cpp b/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.cpp index 06dd6b75a..39cea990b 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.cpp +++ b/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.cpp @@ -129,7 +129,7 @@ bool OEBPlugin::readMetaInfo(Book &book) const { return OEBMetaInfoReader(book).readMetaInfo(opfFile(file)); } -std::string OEBPlugin::readEncryptionType(Book &book) const { +const std::string &OEBPlugin::readEncryptionType(Book &book) const { return OEBEncryptionReader().readEncryptionInfo(epubFile(book.file())); } @@ -139,8 +139,6 @@ bool OEBPlugin::readUids(Book &book) const { } bool OEBPlugin::readModel(BookModel &model) const { - ZLLogger::Instance().registerClass("encryption"); - ZLLogger::Instance().println("encryption", "ENCRYPTION TYPE = " + readEncryptionType(*model.book())); const ZLFile &file = model.book()->file(); return OEBBookReader(model).readBook(opfFile(file)); } diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.h b/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.h index 66b55faf4..4cb7f738a 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.h +++ b/jni/NativeFormats/fbreader/src/formats/oeb/OEBPlugin.h @@ -33,7 +33,7 @@ public: bool providesMetaInfo() const; const std::string supportedFileType() const; bool readMetaInfo(Book &book) const; - std::string readEncryptionType(Book &book) const; + const std::string &readEncryptionType(Book &book) const; bool readUids(Book &book) const; bool readLanguageAndEncoding(Book &book) const; bool readModel(BookModel &model) const; diff --git a/src/org/geometerplus/fbreader/formats/FormatPlugin.java b/src/org/geometerplus/fbreader/formats/FormatPlugin.java index 3d99364d9..edc442f4d 100644 --- a/src/org/geometerplus/fbreader/formats/FormatPlugin.java +++ b/src/org/geometerplus/fbreader/formats/FormatPlugin.java @@ -28,6 +28,12 @@ import org.geometerplus.fbreader.bookmodel.BookModel; import org.geometerplus.fbreader.bookmodel.BookReadingException; public abstract class FormatPlugin { + public interface EncryptionType { + String NONE = "none"; + String UNKNOWN = "unknown"; + String MARLIN = "marlin"; + } + private final String myFileType; protected FormatPlugin(String fileType) { @@ -42,6 +48,7 @@ public abstract class FormatPlugin { return file; } public abstract void readMetaInfo(Book book) throws BookReadingException; + public abstract String readEncryptionType(Book book); public abstract void readUids(Book book) throws BookReadingException; public abstract void readModel(BookModel model) throws BookReadingException; public abstract void detectLanguageAndEncoding(Book book) throws BookReadingException; diff --git a/src/org/geometerplus/fbreader/formats/NativeFormatPlugin.java b/src/org/geometerplus/fbreader/formats/NativeFormatPlugin.java index de778c9cc..a8902653c 100644 --- a/src/org/geometerplus/fbreader/formats/NativeFormatPlugin.java +++ b/src/org/geometerplus/fbreader/formats/NativeFormatPlugin.java @@ -60,6 +60,10 @@ public class NativeFormatPlugin extends FormatPlugin { private native int readMetaInfoNative(Book book); + @Override + public native String readEncryptionType(Book book); + + @Override synchronized public void readUids(Book book) throws BookReadingException { readUidsNative(book); if (book.uids().isEmpty()) { @@ -79,6 +83,7 @@ public class NativeFormatPlugin extends FormatPlugin { @Override synchronized public void readModel(BookModel model) throws BookReadingException { final int code = readModelNative(model); + System.err.println("ENCRYPTION TYPE = " + readEncryptionType(model.Book)); if (code != 0) { throw new BookReadingException( "nativeCodeFailure", diff --git a/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java b/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java index f1f349837..fb45f3de3 100644 --- a/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java +++ b/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java @@ -47,6 +47,11 @@ public class FB2Plugin extends JavaFormatPlugin { new FB2MetaInfoReader(book).readMetaInfo(); } + @Override + public String readEncryptionType(Book book) { + return EncryptionType.NONE; + } + @Override public void readUids(Book book) throws BookReadingException { // this method does nothing, we expect it will be never called diff --git a/src/org/geometerplus/fbreader/formats/oeb/OEBPlugin.java b/src/org/geometerplus/fbreader/formats/oeb/OEBPlugin.java index 46e6a0acd..f019d4ada 100644 --- a/src/org/geometerplus/fbreader/formats/oeb/OEBPlugin.java +++ b/src/org/geometerplus/fbreader/formats/oeb/OEBPlugin.java @@ -61,6 +61,11 @@ public class OEBPlugin extends JavaFormatPlugin { new OEBMetaInfoReader(book).readMetaInfo(getOpfFile(book.File)); } + @Override + public String readEncryptionType(Book book) { + return EncryptionType.NONE; + } + @Override public void readUids(Book book) throws BookReadingException { // this method does nothing, we expect it will be never called diff --git a/src/org/geometerplus/fbreader/formats/pdb/MobipocketPlugin.java b/src/org/geometerplus/fbreader/formats/pdb/MobipocketPlugin.java index 880a2aa1d..db60c3857 100644 --- a/src/org/geometerplus/fbreader/formats/pdb/MobipocketPlugin.java +++ b/src/org/geometerplus/fbreader/formats/pdb/MobipocketPlugin.java @@ -123,6 +123,11 @@ public class MobipocketPlugin extends JavaFormatPlugin { } } + @Override + public String readEncryptionType(Book book) { + return EncryptionType.NONE; + } + @Override public void readUids(Book book) throws BookReadingException { if (book.uids().isEmpty()) {