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

Readium sdk for lcp #216

Merged
merged 11 commits into from
Nov 23, 2015
14 changes: 14 additions & 0 deletions Platform/Apple/RDServices/Main/RDContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@

- (BOOL)container:(RDContainer *)container handleSdkError:(NSString *)message isSevereEpubError:(BOOL)isSevereEpubError;

@optional

/**
* Called just after the container populated the default filters into
* the filter manager.
* You can implement this to register custom filters.
*/
- (void)containerRegisterContentFilters:(RDContainer *)container;

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

@end

@class RDPackage;
Expand Down
12 changes: 9 additions & 3 deletions Platform/Apple/RDServices/Main/RDContainer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#import <ePub3/initialization.h>
#import <ePub3/utilities/error_handler.h>
#import "RDPackage.h"
#include <lcp/initialization.h>


@interface RDContainer () {
@private std::shared_ptr<ePub3::Container> m_container;
Expand Down Expand Up @@ -85,8 +85,14 @@ - (instancetype)initWithDelegate:(id <RDContainerDelegate>)delegate path:(NSStri
ePub3::InitializeSdk();
ePub3::PopulateFilterManager();

// LCP content module and authentication handerl ininitialization
lcp::Initialize();
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
47 changes: 33 additions & 14 deletions ePub3/ePub/content_module_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,36 +85,55 @@ 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
ContainerPtr container = result.get();

if (bool(container)) {
// we have a valid container already
/* modified by hslee 15/03/18 */
// result = make_ready_future(container);
// result = result.then([modulePtr](future<ContainerPtr> fut) {
// ContainerPtr ptr = fut.get();
result = make_ready_future(container);
result = result.then([modulePtr](future<ContainerPtr> fut) {
ContainerPtr ptr = fut.get();
modulePtr->RegisterContentFilters();
// return ptr;
// });
/* end modified */
found = true;
return ptr;
});
break;
} else {
continue; // no container, so try the next module
}
} else {
/* modified by hslee 15/03/18 */
// it must be 'timeout' or 'deferred', which means the module is attempting to process the file
// we take this to mean that we stop looking and return the result
// result = result.then([modulePtr](future<ContainerPtr> fut) {
// ContainerPtr ptr = fut.get();
result = result.then([modulePtr](future<ContainerPtr> fut) {
ContainerPtr ptr = fut.get();
modulePtr->RegisterContentFilters();
// return ptr;
// });
/* end modified */
return ptr;
});
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;
}
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
6 changes: 4 additions & 2 deletions ePub3/ePub/encryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ bool EncryptionInfo::ParseXML(shared_ptr<xml::Node> node)
// 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.empty())
{
if (strings[0] == "0" || strings[0] == "8")
_compression_method = strings[0];
else
Expand All @@ -67,7 +68,8 @@ bool EncryptionInfo::ParseXML(shared_ptr<xml::Node> node)
_compression_method = "0";

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