forked from soutade/libgourou
Manage loan tokens
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
namespace gourou
|
||||
{
|
||||
FulfillmentItem::FulfillmentItem(pugi::xml_document& doc, User* user)
|
||||
: fulfillDoc()
|
||||
: fulfillDoc(), loanToken(0)
|
||||
{
|
||||
fulfillDoc.reset(doc); /* We must keep a copy */
|
||||
metadatas = fulfillDoc.select_node("//metadata").node();
|
||||
@@ -50,8 +50,25 @@ namespace gourou
|
||||
EXCEPTION(FFI_INVALID_FULFILLMENT_DATA, "Any license token in document");
|
||||
|
||||
buildRights(licenseToken, user);
|
||||
|
||||
node = doc.select_node("/envelope/fulfillmentResult/returnable").node();
|
||||
try
|
||||
{
|
||||
if (node && node.first_child().value() == std::string("true"))
|
||||
loanToken = new LoanToken(doc);
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
GOUROU_LOG(ERROR, "Book is returnable, but contains invalid loan token");
|
||||
GOUROU_LOG(ERROR, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FulfillmentItem::~FulfillmentItem()
|
||||
{
|
||||
if (loanToken) delete loanToken;
|
||||
}
|
||||
|
||||
void FulfillmentItem::buildRights(const pugi::xml_node& licenseToken, User* user)
|
||||
{
|
||||
pugi::xml_node decl = rights.append_child(pugi::node_declaration);
|
||||
@@ -103,4 +120,9 @@ namespace gourou
|
||||
{
|
||||
return resource;
|
||||
}
|
||||
|
||||
LoanToken* FulfillmentItem::getLoanToken()
|
||||
{
|
||||
return loanToken;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -837,6 +837,33 @@ namespace gourou
|
||||
user->updateActivationFile(activationDoc);
|
||||
}
|
||||
|
||||
void DRMProcessor::buildReturnReq(pugi::xml_document& returnReq, const std::string& loanID, const std::string& operatorURL)
|
||||
{
|
||||
pugi::xml_node decl = returnReq.append_child(pugi::node_declaration);
|
||||
decl.append_attribute("version") = "1.0";
|
||||
|
||||
pugi::xml_node root = returnReq.append_child("adept:loanReturn");
|
||||
root.append_attribute("xmlns:adept") = ADOBE_ADEPT_NS;
|
||||
|
||||
appendTextElem(root, "adept:user", user->getUUID());
|
||||
appendTextElem(root, "adept:device", user->getDeviceUUID());
|
||||
appendTextElem(root, "adept:loan", loanID);
|
||||
|
||||
addNonce(root);
|
||||
signNode(root);
|
||||
}
|
||||
|
||||
void DRMProcessor::returnLoan(const std::string& loanID, const std::string& operatorURL)
|
||||
{
|
||||
pugi::xml_document returnReq;
|
||||
|
||||
GOUROU_LOG(INFO, "Return loan " << loanID);
|
||||
|
||||
buildReturnReq(returnReq, loanID, operatorURL);
|
||||
|
||||
sendRequest(returnReq, operatorURL + "/LoanReturn");
|
||||
}
|
||||
|
||||
ByteArray DRMProcessor::encryptWithDeviceKey(const unsigned char* data, unsigned int len)
|
||||
{
|
||||
const unsigned char* deviceKey = device->getDeviceKey();
|
||||
|
||||
77
src/loan_token.cpp
Normal file
77
src/loan_token.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
Copyright 2022 Grégory Soutadé
|
||||
|
||||
This file is part of libgourou.
|
||||
|
||||
libgourou is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
libgourou 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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with libgourou. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "libgourou_common.h"
|
||||
#include "loan_token.h"
|
||||
|
||||
namespace gourou
|
||||
{
|
||||
LoanToken::LoanToken(pugi::xml_document& doc)
|
||||
{
|
||||
pugi::xml_node node = doc.select_node("/envelope/loanToken").node();
|
||||
|
||||
if (!node)
|
||||
EXCEPTION(FFI_INVALID_LOAN_TOKEN, "No loanToken element in document");
|
||||
|
||||
node = doc.select_node("/envelope/loanToken/loan").node();
|
||||
|
||||
if (!node)
|
||||
EXCEPTION(FFI_INVALID_LOAN_TOKEN, "No loanToken/loan element in document");
|
||||
|
||||
properties["id"] = node.first_child().value();
|
||||
|
||||
node = doc.select_node("/envelope/loanToken/operatorURL").node();
|
||||
|
||||
if (!node)
|
||||
EXCEPTION(FFI_INVALID_LOAN_TOKEN, "No loanToken/operatorURL element in document");
|
||||
|
||||
properties["operatorURL"] = node.first_child().value();
|
||||
|
||||
node = doc.select_node("/envelope/fulfillmentResult/resourceItemInfo/licenseToken/permissions/display/until").node();
|
||||
|
||||
if (node)
|
||||
properties["validity"] = node.first_child().value();
|
||||
else
|
||||
{
|
||||
node = doc.select_node("/envelope/fulfillmentResult/resourceItemInfo/licenseToken/permissions/play/until").node();
|
||||
if (node)
|
||||
properties["validity"] = node.first_child().value();
|
||||
else
|
||||
EXCEPTION(FFI_INVALID_LOAN_TOKEN, "No loanToken/operatorURL element in document");
|
||||
}
|
||||
}
|
||||
|
||||
std::string LoanToken::getProperty(const std::string& property, const std::string& _default)
|
||||
{
|
||||
if (properties.find(property) == properties.end())
|
||||
{
|
||||
if (_default == "")
|
||||
EXCEPTION(GOUROU_INVALID_PROPERTY, "Invalid property " << property);
|
||||
|
||||
return _default;
|
||||
}
|
||||
|
||||
return properties[property];
|
||||
}
|
||||
|
||||
std::string LoanToken::operator[](const std::string& property)
|
||||
{
|
||||
return getProperty(property);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user