mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 02:09:35 +02:00
encryption type is visible from java code
This commit is contained in:
parent
480d3d1398
commit
2f75bb15d6
12 changed files with 76 additions and 19 deletions
|
@ -130,6 +130,17 @@ JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
JNIEXPORT jstring JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readEncryptionType(JNIEnv* env, jobject thiz, jobject javaBook) {
|
||||||
|
shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz);
|
||||||
|
if (plugin.isNull()) {
|
||||||
|
return AndroidUtil::createJavaString(env, FormatPlugin::EncryptionType::UNKNOWN);
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<Book> book = Book::loadFromJavaBook(env, javaBook);
|
||||||
|
return AndroidUtil::createJavaString(env, plugin->readEncryptionType(*book));
|
||||||
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
JNIEXPORT void JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readUidsNative(JNIEnv* env, jobject thiz, jobject javaBook) {
|
JNIEXPORT void JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readUidsNative(JNIEnv* env, jobject thiz, jobject javaBook) {
|
||||||
shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz);
|
shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz);
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
|
|
||||||
#include "../library/Book.h"
|
#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) {
|
bool FormatPlugin::detectEncodingAndLanguage(Book &book, ZLInputStream &stream, bool force) {
|
||||||
std::string language = book.language();
|
std::string language = book.language();
|
||||||
std::string encoding = book.encoding();
|
std::string encoding = book.encoding();
|
||||||
|
@ -99,6 +103,10 @@ const std::string &FormatPlugin::tryOpen(const ZLFile&) const {
|
||||||
return EMPTY;
|
return EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string &FormatPlugin::readEncryptionType(Book &book) const {
|
||||||
|
return EncryptionType::NONE;
|
||||||
|
}
|
||||||
|
|
||||||
shared_ptr<const ZLImage> FormatPlugin::coverImage(const ZLFile &file) const {
|
shared_ptr<const ZLImage> FormatPlugin::coverImage(const ZLFile &file) const {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,15 @@ public:
|
||||||
|
|
||||||
class FormatPlugin {
|
class FormatPlugin {
|
||||||
|
|
||||||
|
public:
|
||||||
|
class EncryptionType {
|
||||||
|
|
||||||
|
public:
|
||||||
|
static const std::string NONE;
|
||||||
|
static const std::string UNKNOWN;
|
||||||
|
static const std::string MARLIN;
|
||||||
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FormatPlugin();
|
FormatPlugin();
|
||||||
|
|
||||||
|
@ -58,6 +67,7 @@ public:
|
||||||
|
|
||||||
virtual const std::string &tryOpen(const ZLFile &file) const;
|
virtual const std::string &tryOpen(const ZLFile &file) const;
|
||||||
virtual bool readMetaInfo(Book &book) const = 0;
|
virtual bool readMetaInfo(Book &book) const = 0;
|
||||||
|
virtual const std::string &readEncryptionType(Book &book) const;
|
||||||
virtual bool readUids(Book &book) const = 0;
|
virtual bool readUids(Book &book) const = 0;
|
||||||
virtual bool readLanguageAndEncoding(Book &book) const = 0;
|
virtual bool readLanguageAndEncoding(Book &book) const = 0;
|
||||||
virtual bool readModel(BookModel &model) const = 0;
|
virtual bool readModel(BookModel &model) const = 0;
|
||||||
|
|
|
@ -21,28 +21,31 @@
|
||||||
#include <ZLLogger.h>
|
#include <ZLLogger.h>
|
||||||
#include <ZLXMLNamespace.h>
|
#include <ZLXMLNamespace.h>
|
||||||
|
|
||||||
|
#include "../FormatPlugin.h"
|
||||||
#include "OEBEncryptionReader.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<ZLDir> epubDir = epubFile.directory();
|
shared_ptr<ZLDir> epubDir = epubFile.directory();
|
||||||
if (!epubDir.isNull()) {
|
if (epubDir.isNull()) {
|
||||||
const ZLFile rightsFile(epubDir->itemPath("META-INF/rights.xml"));
|
return FormatPlugin::EncryptionType::UNKNOWN;
|
||||||
if (rightsFile.exists()) {
|
}
|
||||||
readDocument(rightsFile);
|
|
||||||
} else {
|
const ZLFile rightsFile(epubDir->itemPath("META-INF/rights.xml"));
|
||||||
myType = "none";
|
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) {
|
void OEBEncryptionReader::startElementHandler(const char *tag, const char **attributes) {
|
||||||
if (testTag(ZLXMLNamespace::MarlinEpub, "Marlin", tag)) {
|
myIsMarlin = testTag(ZLXMLNamespace::MarlinEpub, "Marlin", tag);
|
||||||
myType = "marlin";
|
|
||||||
}
|
|
||||||
interrupt();
|
interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,14 +29,14 @@ class OEBEncryptionReader : public ZLXMLReader {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OEBEncryptionReader();
|
OEBEncryptionReader();
|
||||||
std::string readEncryptionInfo(const ZLFile &file);
|
const std::string &readEncryptionInfo(const ZLFile &file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void startElementHandler(const char *tag, const char **attributes);
|
void startElementHandler(const char *tag, const char **attributes);
|
||||||
bool processNamespaces() const;
|
bool processNamespaces() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string myType;
|
bool myIsMarlin;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __OEBENCRYPTIONREADER_H__ */
|
#endif /* __OEBENCRYPTIONREADER_H__ */
|
||||||
|
|
|
@ -129,7 +129,7 @@ bool OEBPlugin::readMetaInfo(Book &book) const {
|
||||||
return OEBMetaInfoReader(book).readMetaInfo(opfFile(file));
|
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()));
|
return OEBEncryptionReader().readEncryptionInfo(epubFile(book.file()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,8 +139,6 @@ bool OEBPlugin::readUids(Book &book) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OEBPlugin::readModel(BookModel &model) 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();
|
const ZLFile &file = model.book()->file();
|
||||||
return OEBBookReader(model).readBook(opfFile(file));
|
return OEBBookReader(model).readBook(opfFile(file));
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
bool providesMetaInfo() const;
|
bool providesMetaInfo() const;
|
||||||
const std::string supportedFileType() const;
|
const std::string supportedFileType() const;
|
||||||
bool readMetaInfo(Book &book) 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 readUids(Book &book) const;
|
||||||
bool readLanguageAndEncoding(Book &book) const;
|
bool readLanguageAndEncoding(Book &book) const;
|
||||||
bool readModel(BookModel &model) const;
|
bool readModel(BookModel &model) const;
|
||||||
|
|
|
@ -28,6 +28,12 @@ import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||||
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||||
|
|
||||||
public abstract class FormatPlugin {
|
public abstract class FormatPlugin {
|
||||||
|
public interface EncryptionType {
|
||||||
|
String NONE = "none";
|
||||||
|
String UNKNOWN = "unknown";
|
||||||
|
String MARLIN = "marlin";
|
||||||
|
}
|
||||||
|
|
||||||
private final String myFileType;
|
private final String myFileType;
|
||||||
|
|
||||||
protected FormatPlugin(String fileType) {
|
protected FormatPlugin(String fileType) {
|
||||||
|
@ -42,6 +48,7 @@ public abstract class FormatPlugin {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
public abstract void readMetaInfo(Book book) throws BookReadingException;
|
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 readUids(Book book) throws BookReadingException;
|
||||||
public abstract void readModel(BookModel model) throws BookReadingException;
|
public abstract void readModel(BookModel model) throws BookReadingException;
|
||||||
public abstract void detectLanguageAndEncoding(Book book) throws BookReadingException;
|
public abstract void detectLanguageAndEncoding(Book book) throws BookReadingException;
|
||||||
|
|
|
@ -60,6 +60,10 @@ public class NativeFormatPlugin extends FormatPlugin {
|
||||||
|
|
||||||
private native int readMetaInfoNative(Book book);
|
private native int readMetaInfoNative(Book book);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public native String readEncryptionType(Book book);
|
||||||
|
|
||||||
|
@Override
|
||||||
synchronized public void readUids(Book book) throws BookReadingException {
|
synchronized public void readUids(Book book) throws BookReadingException {
|
||||||
readUidsNative(book);
|
readUidsNative(book);
|
||||||
if (book.uids().isEmpty()) {
|
if (book.uids().isEmpty()) {
|
||||||
|
@ -79,6 +83,7 @@ public class NativeFormatPlugin extends FormatPlugin {
|
||||||
@Override
|
@Override
|
||||||
synchronized public void readModel(BookModel model) throws BookReadingException {
|
synchronized public void readModel(BookModel model) throws BookReadingException {
|
||||||
final int code = readModelNative(model);
|
final int code = readModelNative(model);
|
||||||
|
System.err.println("ENCRYPTION TYPE = " + readEncryptionType(model.Book));
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
throw new BookReadingException(
|
throw new BookReadingException(
|
||||||
"nativeCodeFailure",
|
"nativeCodeFailure",
|
||||||
|
|
|
@ -47,6 +47,11 @@ public class FB2Plugin extends JavaFormatPlugin {
|
||||||
new FB2MetaInfoReader(book).readMetaInfo();
|
new FB2MetaInfoReader(book).readMetaInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String readEncryptionType(Book book) {
|
||||||
|
return EncryptionType.NONE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readUids(Book book) throws BookReadingException {
|
public void readUids(Book book) throws BookReadingException {
|
||||||
// this method does nothing, we expect it will be never called
|
// this method does nothing, we expect it will be never called
|
||||||
|
|
|
@ -61,6 +61,11 @@ public class OEBPlugin extends JavaFormatPlugin {
|
||||||
new OEBMetaInfoReader(book).readMetaInfo(getOpfFile(book.File));
|
new OEBMetaInfoReader(book).readMetaInfo(getOpfFile(book.File));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String readEncryptionType(Book book) {
|
||||||
|
return EncryptionType.NONE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readUids(Book book) throws BookReadingException {
|
public void readUids(Book book) throws BookReadingException {
|
||||||
// this method does nothing, we expect it will be never called
|
// this method does nothing, we expect it will be never called
|
||||||
|
|
|
@ -123,6 +123,11 @@ public class MobipocketPlugin extends JavaFormatPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String readEncryptionType(Book book) {
|
||||||
|
return EncryptionType.NONE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readUids(Book book) throws BookReadingException {
|
public void readUids(Book book) throws BookReadingException {
|
||||||
if (book.uids().isEmpty()) {
|
if (book.uids().isEmpty()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue