diff --git a/jni/NativeFormats/JavaNativeFormatPlugin.cpp b/jni/NativeFormats/JavaNativeFormatPlugin.cpp index 17bc3d928..8fb67de3b 100644 --- a/jni/NativeFormats/JavaNativeFormatPlugin.cpp +++ b/jni/NativeFormats/JavaNativeFormatPlugin.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "fbreader/src/bookmodel/BookModel.h" #include "fbreader/src/formats/FormatPlugin.h" @@ -134,7 +135,7 @@ extern "C" JNIEXPORT jstring JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readEncryptionMethod(JNIEnv* env, jobject thiz, jobject javaBook) { shared_ptr plugin = findCppPlugin(thiz); if (plugin.isNull()) { - return AndroidUtil::createJavaString(env, FormatPlugin::EncryptionMethod::UNSUPPORTED); + return AndroidUtil::createJavaString(env, EncryptionMethod::UNSUPPORTED); } shared_ptr book = Book::loadFromJavaBook(env, javaBook); diff --git a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp index 834adae5d..702a6af01 100644 --- a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp +++ b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp @@ -28,10 +28,6 @@ #include "../library/Book.h" -const std::string FormatPlugin::EncryptionMethod::NONE = "none"; -const std::string FormatPlugin::EncryptionMethod::UNSUPPORTED = "unsupported"; -const std::string FormatPlugin::EncryptionMethod::MARLIN = "marlin"; - bool FormatPlugin::detectEncodingAndLanguage(Book &book, ZLInputStream &stream, bool force) { std::string language = book.language(); std::string encoding = book.encoding(); diff --git a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h index 74abf926d..c0966818b 100644 --- a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h +++ b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.h @@ -46,15 +46,6 @@ public: class FormatPlugin { -public: - class EncryptionMethod { - - public: - static const std::string NONE; - static const std::string UNSUPPORTED; - static const std::string MARLIN; - }; - protected: FormatPlugin(); diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/OEBEncryptionReader.cpp b/jni/NativeFormats/fbreader/src/formats/oeb/OEBEncryptionReader.cpp index 4080a492c..9994b0bf6 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/OEBEncryptionReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/oeb/OEBEncryptionReader.cpp @@ -75,16 +75,16 @@ private: std::string OEBEncryptionReader::readEncryptionMethod(const ZLFile &epubFile) { shared_ptr epubDir = epubFile.directory(); if (epubDir.isNull()) { - return FormatPlugin::EncryptionMethod::UNSUPPORTED; + return EncryptionMethod::UNSUPPORTED; } const ZLFile rightsFile(epubDir->itemPath("META-INF/rights.xml")); const ZLFile encryptionFile(epubDir->itemPath("META-INF/encryption.xml")); if (!rightsFile.exists() && !encryptionFile.exists()) { - return FormatPlugin::EncryptionMethod::NONE; + return EncryptionMethod::NONE; } if (!rightsFile.exists() || !encryptionFile.exists()) { - return FormatPlugin::EncryptionMethod::UNSUPPORTED; + return EncryptionMethod::UNSUPPORTED; } EpubRightsFileReader reader; @@ -94,7 +94,7 @@ std::string OEBEncryptionReader::readEncryptionMethod(const ZLFile &epubFile) { std::vector > OEBEncryptionReader::readEncryptionInfos(const ZLFile &epubFile) { const std::string method = readEncryptionMethod(epubFile); - if (method == FormatPlugin::EncryptionMethod::MARLIN) { + if (method == EncryptionMethod::MARLIN) { shared_ptr epubDir = epubFile.directory(); if (!epubDir.isNull()) { const ZLFile encryptionFile(epubDir->itemPath("META-INF/encryption.xml")); @@ -106,7 +106,7 @@ std::vector > OEBEncryptionReader::readEncryption return std::vector >(); } -EpubRightsFileReader::EpubRightsFileReader() : myMethod(FormatPlugin::EncryptionMethod::UNSUPPORTED) { +EpubRightsFileReader::EpubRightsFileReader() : myMethod(EncryptionMethod::UNSUPPORTED) { } std::string EpubRightsFileReader::method() const { @@ -115,7 +115,7 @@ std::string EpubRightsFileReader::method() const { void EpubRightsFileReader::startElementHandler(const char *tag, const char **attributes) { if (testTag(ZLXMLNamespace::MarlinEpub, "Marlin", tag)) { - myMethod = FormatPlugin::EncryptionMethod::MARLIN; + myMethod = EncryptionMethod::MARLIN; } interrupt(); } @@ -203,7 +203,7 @@ void EpubEncryptionFileReader::endElementHandler(const char *tag) { break; case READ_ENCRYPTED_DATA: if (testTag(ZLXMLNamespace::XMLEncryption, "EncryptedData", tag)) { - myInfos.push_back(new FileEncryptionInfo(myUri, myAlgorithm, myKeyName)); + myInfos.push_back(new FileEncryptionInfo(myUri, EncryptionMethod::MARLIN, myAlgorithm, myKeyName)); myState = READ_ENCRYPTION; } break; diff --git a/jni/NativeFormats/zlibrary/core/src/encryption/FileEncryptionInfo.cpp b/jni/NativeFormats/zlibrary/core/src/encryption/FileEncryptionInfo.cpp index 959a64240..ae33c2484 100644 --- a/jni/NativeFormats/zlibrary/core/src/encryption/FileEncryptionInfo.cpp +++ b/jni/NativeFormats/zlibrary/core/src/encryption/FileEncryptionInfo.cpp @@ -21,7 +21,11 @@ #include "FileEncryptionInfo.h" -FileEncryptionInfo::FileEncryptionInfo(const std::string &uri, const std::string &algorithm, const std::string &contentId) : Uri(uri), Algorithm(algorithm), ContentId(contentId) { +const std::string EncryptionMethod::NONE = "none"; +const std::string EncryptionMethod::UNSUPPORTED = "unsupported"; +const std::string EncryptionMethod::MARLIN = "marlin"; + +FileEncryptionInfo::FileEncryptionInfo(const std::string &uri, const std::string &method, const std::string &algorithm, const std::string &contentId) : Uri(uri), Method(method), Algorithm(algorithm), ContentId(contentId) { } void EncryptionMap::addInfo(const ZLDir &dir, shared_ptr info) { diff --git a/jni/NativeFormats/zlibrary/core/src/encryption/FileEncryptionInfo.h b/jni/NativeFormats/zlibrary/core/src/encryption/FileEncryptionInfo.h index 33d92e783..c3d0275f1 100644 --- a/jni/NativeFormats/zlibrary/core/src/encryption/FileEncryptionInfo.h +++ b/jni/NativeFormats/zlibrary/core/src/encryption/FileEncryptionInfo.h @@ -26,13 +26,22 @@ #include #include +class EncryptionMethod { + +public: + static const std::string NONE; + static const std::string UNSUPPORTED; + static const std::string MARLIN; +}; + class FileEncryptionInfo { public: - FileEncryptionInfo(const std::string &uri, const std::string &algorithm, const std::string &contentId); + FileEncryptionInfo(const std::string &uri, const std::string &method, const std::string &algorithm, const std::string &contentId); public: const std::string Uri; + const std::string Method; const std::string Algorithm; const std::string ContentId; }; diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp index 592fff512..e95824df0 100644 --- a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp @@ -100,6 +100,9 @@ shared_ptr ZLFile::inputStream(shared_ptr encrypti shared_ptr encryptionInfo = encryptionMap.isNull() ? 0 : encryptionMap->info(myPath); ZLLogger::Instance().println("MARLIN", myPath + " :: " + (encryptionInfo.isNull() ? "not encrypted" : "encrypted")); + if (!encryptionInfo.isNull()) { + return 0; + } shared_ptr stream; diff --git a/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java b/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java index 91a5f4fa5..0ae0779ea 100644 --- a/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java +++ b/src/org/geometerplus/fbreader/fbreader/FBReaderApp.java @@ -22,6 +22,7 @@ package org.geometerplus.fbreader.fbreader; import java.util.*; import org.geometerplus.zlibrary.core.application.*; +import org.geometerplus.zlibrary.core.drm.EncryptionMethod; import org.geometerplus.zlibrary.core.library.ZLibrary; import org.geometerplus.zlibrary.core.options.*; import org.geometerplus.zlibrary.core.resources.ZLResource; @@ -282,7 +283,7 @@ public final class FBReaderApp extends ZLApplication { try { final String method = book.getPlugin().readEncryptionMethod(book); - if (!FormatPlugin.EncryptionMethod.NONE.equals(method)) { + if (!EncryptionMethod.NONE.equals(method)) { System.err.println("UNSUPPORTED ALGORITHM: " + method); /* UIUtil.showErrorMessage( diff --git a/src/org/geometerplus/fbreader/formats/FormatPlugin.java b/src/org/geometerplus/fbreader/formats/FormatPlugin.java index e4e0cf383..994497fd2 100644 --- a/src/org/geometerplus/fbreader/formats/FormatPlugin.java +++ b/src/org/geometerplus/fbreader/formats/FormatPlugin.java @@ -28,12 +28,6 @@ import org.geometerplus.fbreader.bookmodel.BookModel; import org.geometerplus.fbreader.bookmodel.BookReadingException; public abstract class FormatPlugin { - public interface EncryptionMethod { - String NONE = "none"; - String UNSUPPORTED = "unsupported"; - String MARLIN = "marlin"; - } - private final String myFileType; protected FormatPlugin(String fileType) { diff --git a/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java b/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java index 291bcabf1..b0a2808d0 100644 --- a/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java +++ b/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java @@ -19,6 +19,7 @@ package org.geometerplus.fbreader.formats.fb2; +import org.geometerplus.zlibrary.core.drm.EncryptionMethod; import org.geometerplus.zlibrary.core.filesystem.ZLFile; import org.geometerplus.zlibrary.core.encodings.AutoEncodingCollection; import org.geometerplus.zlibrary.core.image.ZLImage; diff --git a/src/org/geometerplus/fbreader/formats/oeb/OEBPlugin.java b/src/org/geometerplus/fbreader/formats/oeb/OEBPlugin.java index 1c7639f4b..755d45d76 100644 --- a/src/org/geometerplus/fbreader/formats/oeb/OEBPlugin.java +++ b/src/org/geometerplus/fbreader/formats/oeb/OEBPlugin.java @@ -19,6 +19,7 @@ package org.geometerplus.fbreader.formats.oeb; +import org.geometerplus.zlibrary.core.drm.EncryptionMethod; import org.geometerplus.zlibrary.core.filesystem.*; import org.geometerplus.zlibrary.core.encodings.AutoEncodingCollection; import org.geometerplus.zlibrary.core.image.ZLImage; diff --git a/src/org/geometerplus/fbreader/formats/pdb/MobipocketPlugin.java b/src/org/geometerplus/fbreader/formats/pdb/MobipocketPlugin.java index 964031fc2..4f85a75eb 100644 --- a/src/org/geometerplus/fbreader/formats/pdb/MobipocketPlugin.java +++ b/src/org/geometerplus/fbreader/formats/pdb/MobipocketPlugin.java @@ -21,6 +21,7 @@ package org.geometerplus.fbreader.formats.pdb; import java.io.*; +import org.geometerplus.zlibrary.core.drm.EncryptionMethod; import org.geometerplus.zlibrary.core.filesystem.ZLFile; import org.geometerplus.zlibrary.core.image.*; import org.geometerplus.zlibrary.core.encodings.Encoding; diff --git a/src/org/geometerplus/zlibrary/core/drm/EncryptionMethod.java b/src/org/geometerplus/zlibrary/core/drm/EncryptionMethod.java new file mode 100644 index 000000000..f35493630 --- /dev/null +++ b/src/org/geometerplus/zlibrary/core/drm/EncryptionMethod.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2007-2014 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +package org.geometerplus.zlibrary.core.drm; + +public interface EncryptionMethod { + String NONE = "none"; + String UNSUPPORTED = "unsupported"; + String MARLIN = "marlin"; +}