Add support for PDF (needs uPDFParser library)

This commit is contained in:
2021-08-21 20:57:31 +02:00
parent 8bc346d139
commit 3d9e343734
13 changed files with 262 additions and 35 deletions

View File

@@ -21,6 +21,7 @@
#define _DRMPROCESSORCLIENT_H_
#include <string>
#include <bytearray.h>
namespace gourou
{
@@ -93,11 +94,14 @@ namespace gourou
/**
* @brief Send HTTP (GET or POST) request
*
* @param URL HTTP URL
* @param POSTData POST data if needed, if not set, a GET request is done
* @param contentType Optional content type of POST Data
* @param URL HTTP URL
* @param POSTData POST data if needed, if not set, a GET request is done
* @param contentType Optional content type of POST Data
* @param responseHeaders Optional Response headers of HTTP request
*
* @return data of HTTP response
*/
virtual std::string sendHTTPRequest(const std::string& URL, const std::string& POSTData=std::string(""), const std::string& contentType=std::string("")) = 0;
virtual std::string sendHTTPRequest(const std::string& URL, const std::string& POSTData=std::string(""), const std::string& contentType=std::string(""), std::map<std::string, std::string>* responseHeaders=0) = 0;
};
class RSAInterface
@@ -355,6 +359,27 @@ namespace gourou
* @param handler ZIP file handler
*/
virtual void zipClose(void* handler) = 0;
/**
* @brief Inflate algorithm
*
* @param data Data to inflate
* @param result Zipped data
* @param wbits Window bits value for libz
*/
virtual void inflate(std::string data, gourou::ByteArray& result,
int wbits=-15) = 0;
/**
* @brief Deflate algorithm
*
* @param data Data to deflate
* @param result Unzipped data
* @param wbits Window bits value for libz
* @param compressionLevel Compression level for libz
*/
virtual void deflate(std::string data, gourou::ByteArray& result,
int wbits=-15, int compressionLevel=8) = 0;
};
class DRMProcessorClient: public DigestInterface, public RandomInterface, public HTTPInterface, \

View File

@@ -53,10 +53,16 @@ namespace gourou
*/
std::string getDownloadURL();
/**
* @brief Return resource value
*/
std::string getResource();
private:
pugi::xml_node metadatas;
pugi::xml_document rights;
std::string downloadURL;
std::string resource;
void buildRights(const pugi::xml_node& licenseToken, User* user);
};

View File

@@ -40,7 +40,7 @@
#define ACS_SERVER "http://adeactivate.adobe.com/adept"
#endif
#define LIBGOUROU_VERSION "0.3.2"
#define LIBGOUROU_VERSION "0.4"
namespace gourou
{
@@ -53,6 +53,7 @@ namespace gourou
static const std::string VERSION;
enum ITEM_TYPE { EPUB=0, PDF };
/**
* @brief Main constructor. To be used once all is configured (user has signedIn, device is activated)
*
@@ -80,8 +81,10 @@ namespace gourou
*
* @param item Item from fulfill() method
* @param path Output file path
*
* @return Type of downloaded item
*/
void download(FulfillmentItem* item, std::string path);
ITEM_TYPE download(FulfillmentItem* item, std::string path);
/**
* @brief SignIn into ACS Server (required to activate device)
@@ -130,8 +133,11 @@ namespace gourou
* @param URL HTTP URL
* @param POSTData POST data if needed, if not set, a GET request is done
* @param contentType Optional content type of POST Data
* @param responseHeaders Optional Response headers of HTTP request
*
* @return data of HTTP response
*/
ByteArray sendRequest(const std::string& URL, const std::string& POSTData=std::string(), const char* contentType=0);
ByteArray sendRequest(const std::string& URL, const std::string& POSTData=std::string(), const char* contentType=0, std::map<std::string, std::string>* responseHeaders=0);
/**
* @brief Send HTTP POST request to URL with document as POSTData

View File

@@ -233,6 +233,32 @@ namespace gourou
return trim(res);
}
static inline std::string extractTextElem(const pugi::xml_node& doc, const char* tagName, bool throwOnNull=true)
{
pugi::xpath_node xpath_node = doc.select_node(tagName);
if (!xpath_node)
{
if (throwOnNull)
EXCEPTION(GOUROU_TAG_NOT_FOUND, "Tag " << tagName << " not found");
return "";
}
pugi::xml_node node = xpath_node.node().first_child();
if (!node)
{
if (throwOnNull)
EXCEPTION(GOUROU_TAG_NOT_FOUND, "Text element for tag " << tagName << " not found");
return "";
}
std::string res = node.value();
return trim(res);
}
/**
* @brief Append an element to root with a sub text element
*
@@ -267,7 +293,7 @@ namespace gourou
*/
static inline void writeFile(std::string path, ByteArray& data)
{
writeFile(path, data.data(), data.length());
writeFile(path, data.data(), data.length()-1);
}
/**