Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict resolved full request for update Radium SDK to support LCP implementation #219

Merged
merged 17 commits into from
Nov 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Platform/Android/jni/epub3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ Java_org_readium_sdk_android_EPub3_openBook(JNIEnv* env, jobject thiz, jstring p
}
catch (const std::invalid_argument& ex) {
LOGD("OpenContainer() EXCEPTION: %s\n", ex.what());
return nullptr;
}

LOGD("EPub3.openBook(): _container OK, version: %s\n", _container->Version().c_str());
Expand Down
5 changes: 5 additions & 0 deletions Platform/Apple/RDServices/Main/RDContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
*/
- (void)containerRegisterContentFilters:(RDContainer *)container;

/**
* You can implement this to register content modules.
*/
- (void)containerRegisterContentModules:(RDContainer *)container;

@end

@class RDPackage;
Expand Down
5 changes: 5 additions & 0 deletions Platform/Apple/RDServices/Main/RDContainer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ - (instancetype)initWithDelegate:(id <RDContainerDelegate>)delegate path:(NSStri
if ([delegate respondsToSelector:@selector(containerRegisterContentFilters:)]) {
[delegate containerRegisterContentFilters:self];
}

//Content Modules for each DRM library, if any, should be registered in the function.
if ([delegate respondsToSelector:@selector(containerRegisterContentModules:)]) {
[delegate containerRegisterContentModules:self];
}

m_path = path;
m_container = ePub3::Container::OpenContainer(path.UTF8String);
Expand Down
15 changes: 15 additions & 0 deletions ePub3/ThirdParty/libzip/zip_fseek.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,26 @@ int _zip_fseek_bytes(struct zip_file* zf, off_t abspos, off_t flen)
else if (abspos >= flen) {
zf->flags |= ZIP_ZF_EOF;
zf->bytes_left = 0;

/* added by DRM inside, C.H. Yu on 2015-04-13 */
// Without following added codes, uncompressed EPUB media content would not be properly random accessed,
// such as bad index access error
zf->fpos = _zip_file_get_offset_safe(zf->za, zf->file_index);
zf->fpos += flen;
zf->cbytes_left = 0;
/* adding end */
}
/* not at or past EOF? ensure EOF is unset and update bytes_left */
else {
zf->flags &= ~ZIP_ZF_EOF;
zf->bytes_left = flen - abspos;

/* added by DRM inside, C.H. Yu on 2015-04-13 */
// Without following added codes, uncompressed EPUB media content would not be properly random accessed,
// such as bad index access error
zf->fpos += (abspos - zf->file_fpos);
zf->cbytes_left = zf->bytes_left;
/* adding end */
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nleme the code above has been merged to develop, so I wonder if this issue and associated PR is still valid?
#177
https://github.com/readium/readium-sdk/pull/179/files

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And just a reminder of the pending zip lib update PR (not sure how this zip_fseek patch will survive / need to be adjusted):
#191 (comment)

zf->file_fpos = abspos;
return 0;
Expand Down
16 changes: 16 additions & 0 deletions ePub3/ePub/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,31 @@ ContainerPtr Container::OpenContainer(const string &path)
auto future = ContentModuleManager::Instance()->LoadContentAtPath(path, launch::any);
ContainerPtr result;

// Added by DRM inside H.S. Lee on 2015-03-15
// Without following code part, program crash happens on some situations
if (future.__future_ == nullptr)
{
// There are registered modules, but
//1-1 no proper content module
//1-2 canceled by users
//1-3 Signature error (currently, throwing error)
//1-4 Password error (currently, throwing error)

//2, plain content
return OpenContainerForContentModule(path);
}

// see if it's complete with a nil value
if (future.wait_for(std::chrono::system_clock::duration(0)) == future_status::ready)
{
result = future.get();
if (!bool(result))
//No registered content module
return OpenContainerForContentModule(path);
}

if (!bool(result))
//There is a proper registered content module to handle the encrypted EPUB
result = future.get();

return result;
Expand Down
2 changes: 2 additions & 0 deletions ePub3/ePub/content_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class ContentModule : public std::enable_shared_from_this<ContentModule>
async_result<bool>
ApproveUserAction(const UserAction& action) = 0;

virtual string GetModuleName() = 0;

};

EPUB3_END_NAMESPACE
Expand Down
31 changes: 31 additions & 0 deletions ePub3/ePub/content_module_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ ContentModuleManager::LoadContentAtPath(const string& path, launch policy)
}

future<ContainerPtr> result;
bool found = false;
for (auto& item : _known_modules)
{
auto modulePtr = item.second;
Expand All @@ -84,6 +85,14 @@ ContentModuleManager::LoadContentAtPath(const string& path, launch policy)
// check the state of the future -- has it already been set?
future_status status = result.wait_for(std::chrono::system_clock::duration(0));

/*
Following 'if-else' clauses which have 'result.then' make a malfunction
while Content Module processing for DRM implementation.
But there is no problem to handle both plain and encrypted resources
with next clauses which are detouring result.then
*/

/*
// if it's ready, the call to get() will never block
if (status == future_status::ready) {
// unpack the future
Expand Down Expand Up @@ -111,6 +120,28 @@ ContentModuleManager::LoadContentAtPath(const string& path, launch policy)
});
break;
}
*/

if (status == future_status::ready) {
ContainerPtr container = result.get();

if (bool(container)) {
modulePtr->RegisterContentFilters();
found = true;
break;
} else {
continue;
}
} else {
modulePtr->RegisterContentFilters();
found = true;
break;
}
}

if ( !found && result.__future_ == nullptr )
{
throw std::invalid_argument("Unsupported DRM EPUB");
}

return result;
Expand Down
28 changes: 28 additions & 0 deletions ePub3/ePub/credential_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ std::size_t CredentialRequest::AddButton(const string& title, ButtonHandler&& ha
{
std::size_t result = m_components.size();
m_components.emplace_back(Type::Button, title);

//hslee
if(handler != nullptr)
m_components.back().m_btnHandler = handler;

return result;
}
CredentialRequest::Type CredentialRequest::GetItemType(std::size_t idx) const
Expand All @@ -56,4 +61,27 @@ const string& CredentialRequest::GetItemTitle(std::size_t idx) const
return m_components[idx].m_title;
}

/* added by hslee 15/04/13 */
void CredentialRequest::SetCredentialItem(string title, string input)
{
m_credentials.insert(std::make_pair(title, input));
}

string& CredentialRequest::GetDefaultValue(std::size_t idx)
{
if (idx >= m_components.size())
throw std::out_of_range("CredentialRequest::GetItemTitle");
return m_components[idx].m_default;
}

CredentialRequest::ButtonHandler
CredentialRequest::GetButtonHandler(std::size_t idx)
{
if (idx >= m_components.size())
throw std::out_of_range("CredentialRequest::GetItemTitle");
return m_components[idx].m_btnHandler;
}
/* end added */


EPUB3_END_NAMESPACE
35 changes: 30 additions & 5 deletions ePub3/ePub/credential_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class CredentialRequest
CredentialRequest(const string& title,
const string& message);
CredentialRequest(const CredentialRequest& o)
: m_components(o.m_components), m_credentials(), m_promise()
: m_components(o.m_components), m_credentials(), m_promise(), m_pressedButtonIndex(0)
{}
CredentialRequest(CredentialRequest&& o)
: m_components(std::move(o.m_components)), m_credentials(std::move(o.m_credentials)), m_promise(std::move(o.m_promise))
: m_components(std::move(o.m_components)), m_credentials(std::move(o.m_credentials)), m_promise(std::move(o.m_promise)), m_pressedButtonIndex(std::move(o.m_pressedButtonIndex))
{}
virtual ~CredentialRequest()
{}
Expand All @@ -63,13 +63,15 @@ class CredentialRequest
m_components = o.m_components;
m_credentials = o.m_credentials;
m_promise = promise<Credentials>();
m_pressedButtonIndex = o.m_pressedButtonIndex;
return *this;
}
CredentialRequest& operator=(CredentialRequest&& o)
{
m_components.swap(o.m_components);
m_credentials.swap(o.m_credentials);
m_promise.swap(o.m_promise);
m_pressedButtonIndex = o.m_pressedButtonIndex;
return *this;
}

Expand Down Expand Up @@ -111,13 +113,13 @@ class CredentialRequest
{
public:
Component(Type type, const string& title)
: m_type(type), m_title(title), m_secret(type == Type::MaskedInput), m_default()
: m_type(type), m_title(title), m_secret(type == Type::MaskedInput), m_default(), m_btnHandler()
{}
Component(Type type, string&& title)
: m_type(type), m_title(title), m_secret(type == Type::MaskedInput), m_default()
: m_type(type), m_title(title), m_secret(type == Type::MaskedInput), m_default(), m_btnHandler()
{}
Component(const Component& o)
: m_type(o.m_type), m_title(o.m_title), m_secret(o.m_secret), m_default(o.m_default)
: m_type(o.m_type), m_title(o.m_title), m_secret(o.m_secret), m_default(o.m_default), m_btnHandler(o.m_btnHandler)
{}
~Component() {}

Expand All @@ -126,6 +128,9 @@ class CredentialRequest
string m_title;
bool m_secret;
string m_default;
/* added by hslee 15/04/28 */
ButtonHandler m_btnHandler;
/* end added*/

friend class CredentialRequest;

Expand All @@ -134,6 +139,26 @@ class CredentialRequest
std::vector<Component> m_components;
Credentials m_credentials;
promised_result<Credentials> m_promise;

/* added by hslee 15/04/13 */
/* modified by hslee 15/04/28 */
std::size_t m_pressedButtonIndex;
public:
std::size_t GetComponentCount() { return m_components.size(); }

void SetCredentialItem(string title, string input);

future<Credentials> GetSignal() { return m_promise.get_future(); }

string& GetDefaultValue(std::size_t idx);

ButtonHandler GetButtonHandler(std::size_t idx);

std::size_t GetPressedButtonIndex(){ return m_pressedButtonIndex; }

void SetPressedButtonIndex(std::size_t idx){ m_pressedButtonIndex = idx; }
/* end added */

};

EPUB3_END_NAMESPACE
Expand Down
35 changes: 34 additions & 1 deletion ePub3/ePub/encryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@

EPUB3_BEGIN_NAMESPACE

// Added by T.H. Kim on 2015-04-15
#define ReadiumURI "http://readium.org/2015/01/lcp#extendedProperty"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be consistent with the LCP server! See: readium/readium-lcp-server#24
and w3c/epub-specs#646 (comment)
(I am filing a separate issue in readium-sdk)

bool EncryptionInfo::ParseXML(shared_ptr<xml::Node> node)
{
// Modified by T.H. Kim on 2015-04-15
// To add ReadiumURI namespace to process the addition information

#if EPUB_COMPILER_SUPPORTS(CXX_INITIALIZER_LISTS)
XPathWrangler xpath(node->Document(), {{"enc", XMLENCNamespaceURI}, {"dsig", XMLDSigNamespaceURI}});
XPathWrangler xpath(node->Document(), {{"enc", XMLENCNamespaceURI}, {"dsig", XMLDSigNamespaceURI} , { "ep", ReadiumURI }});
#else
XPathWrangler::NamespaceList nsList;
nsList["enc"] = XMLENCNamespaceURI;
nsList["dsig"] = XMLDSigNamespaceURI;
nsList["ep"] = ReadiumURI;
XPathWrangler xpath(node->doc, nsList);
#endif

Expand All @@ -45,6 +52,32 @@ bool EncryptionInfo::ParseXML(shared_ptr<xml::Node> node)
return false;

_path = strings[0];

// Added by DRM inside, T.H. Kim on 2015-04-15
// To get additional information for the compressed and encrypted contents
strings = xpath.Strings("./enc:EncryptionProperties/enc:EncryptionProperty/ep:compression/@method", node);
if (!strings.empty())
{
if (strings[0] == "0" || strings[0] == "8")
_compression_method = strings[0];
else
return false;

}
else if (strings.empty())
_compression_method = "0";

strings = xpath.Strings("./enc:EncryptionProperties/enc:EncryptionProperty/ep:compression/@sourceSize", node);
if (!strings.empty())
{
for ( int i = 0 ; i < strings[0].size() ; i++)
if (strings[0][i] < '0' || strings[0][i] > '9' )
return false;

_uncompressed_size = strings[0];
}
/////////////////////////////////////////////////////////////////////////////

return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following discussion, we might want to consider Compression (upper case) and method + originalLength attribute names (instead of size). To be proposed to IDPF OCF specification as fix (EPUB31 revision?).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up - see IDPF EPUB3 issue: w3c/epub-specs#646

}

Expand Down
17 changes: 14 additions & 3 deletions ePub3/ePub/encryption.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ class EncryptionInfo : public PointerType<EncryptionInfo>, public OwnedBy<Contai
typedef string algorithm_type;

public:
/// Modified by T.H. Kim on 2015-04-15
///
/// Creates a new EncryptionInfo with no details filled in.
EncryptionInfo(ContainerPtr owner) : OwnedBy(owner), _algorithm(), _path() {}
EncryptionInfo(ContainerPtr owner) : OwnedBy(owner), _algorithm(), _path(), _compression_method(), _uncompressed_size() {}
///
/// Copy constructor.
EncryptionInfo(const EncryptionInfo& o) : OwnedBy(o), _algorithm(o._algorithm), _path(o._path) {}
EncryptionInfo(const EncryptionInfo& o) : OwnedBy(o), _algorithm(o._algorithm), _path(o._path), _compression_method(o._compression_method), _uncompressed_size(o._uncompressed_size) {}
///
/// Move constructor.
EncryptionInfo(EncryptionInfo&& o) : OwnedBy(std::move(o)), _algorithm(std::move(o._algorithm)), _path(std::move(o._path)) {}
EncryptionInfo(EncryptionInfo&& o) : OwnedBy(std::move(o)), _algorithm(std::move(o._algorithm)), _path(std::move(o._path)), _compression_method(std::move(o._compression_method)), _uncompressed_size(std::move(o._uncompressed_size)) {}
virtual ~EncryptionInfo() {}


Expand Down Expand Up @@ -93,10 +94,20 @@ class EncryptionInfo : public PointerType<EncryptionInfo>, public OwnedBy<Contai
virtual void SetPath(const string& path) { _path = path; }
virtual void SetPath(string&& path) { _path = path; }

// Added by DRM inside T.H. Kim on 2015-04-15
// Return additional information for the compressed and encrypted contents
virtual const string& CompressionMethod() const { return _compression_method; }
virtual const string& UnCompressedSize() const { return _uncompressed_size;}

protected:
algorithm_type _algorithm; ///< The algorithm identifier, as per XML-ENC or OCF.
string _path; ///< The Container-relative path to an encrypted resource.

// Added by DRM inside T.H. Kim on 2015-04-15
// To get additional information for the compressed and encrypted contents
string _compression_method; // Compression method : 0(no compression), 8(deflated)
string _uncompressed_size; // Uncompressed size of the content

};

EPUB3_END_NAMESPACE
Expand Down