8 Commits

Author SHA1 Message Date
Grégory Soutadé
55ab41613e Update inflate/deflate with right flag (Z_FINISH, no Z_SYNC_FLUSH) 2021-11-29 15:38:56 +01:00
Grégory Soutadé
8129ec4423 Update version 2021-11-29 09:31:18 +01:00
Grégory Soutadé
9ab66ddba9 Bugfix : rework inflate/deflate that makes produce data 2021-11-29 08:40:12 +01:00
Grégory Soutadé
e5697378e9 Update version 2021-11-27 10:29:22 +01:00
Grégory Soutadé
fd8ce841eb Fix a nasty bug : fulfill reply data must be copied, not just referenced 2021-11-26 20:01:49 +01:00
Grégory Soutadé
8413b844db Forgot to add libgourou.a as a dependency in utils Makefile 2021-11-26 20:01:21 +01:00
Grégory Soutadé
dd6001805f Remove invalid characters from filename before writing a file 2021-11-26 20:00:36 +01:00
Grégory Soutadé
1f6e0ecdc8 Check for application/pdf as a substring and not as a full string for Content-Type and metadata in order to determine downloaded file type 2021-11-26 19:59:57 +01:00
8 changed files with 52 additions and 22 deletions

View File

@@ -34,6 +34,12 @@ namespace gourou
class FulfillmentItem class FulfillmentItem
{ {
public: public:
/**
* @brief Main constructor. Not to be called by user
*
* @param doc Fulfill reply
* @param user User pointer
*/
FulfillmentItem(pugi::xml_document& doc, User* user); FulfillmentItem(pugi::xml_document& doc, User* user);
/** /**
@@ -59,6 +65,7 @@ namespace gourou
std::string getResource(); std::string getResource();
private: private:
pugi::xml_document fulfillDoc;
pugi::xml_node metadatas; pugi::xml_node metadatas;
pugi::xml_document rights; pugi::xml_document rights;
std::string downloadURL; std::string downloadURL;

View File

@@ -40,7 +40,7 @@
#define ACS_SERVER "http://adeactivate.adobe.com/adept" #define ACS_SERVER "http://adeactivate.adobe.com/adept"
#endif #endif
#define LIBGOUROU_VERSION "0.4.2" #define LIBGOUROU_VERSION "0.4.4"
namespace gourou namespace gourou
{ {

View File

@@ -24,9 +24,11 @@
namespace gourou namespace gourou
{ {
FulfillmentItem::FulfillmentItem(pugi::xml_document& doc, User* user) FulfillmentItem::FulfillmentItem(pugi::xml_document& doc, User* user)
: fulfillDoc()
{ {
metadatas = doc.select_node("//metadata").node(); fulfillDoc.reset(doc); /* We must keep a copy */
metadatas = fulfillDoc.select_node("//metadata").node();
if (!metadatas) if (!metadatas)
EXCEPTION(FFI_INVALID_FULFILLMENT_DATA, "No metadata tag in document"); EXCEPTION(FFI_INVALID_FULFILLMENT_DATA, "No metadata tag in document");
@@ -49,7 +51,7 @@ namespace gourou
buildRights(licenseToken, user); buildRights(licenseToken, user);
} }
void FulfillmentItem::buildRights(const pugi::xml_node& licenseToken, User* user) void FulfillmentItem::buildRights(const pugi::xml_node& licenseToken, User* user)
{ {
pugi::xml_node decl = rights.append_child(pugi::node_declaration); pugi::xml_node decl = rights.append_child(pugi::node_declaration);

View File

@@ -599,9 +599,13 @@ namespace gourou
std::string rightsStr = item->getRights(); std::string rightsStr = item->getRights();
if (headers.count("Content-Type") && headers["Content-Type"] == "application/pdf") if (item->getMetadata("format").find("application/pdf") != std::string::npos)
res = PDF; res = PDF;
if (headers.count("Content-Type") &&
headers["Content-Type"].find("application/pdf") != std::string::npos)
res = PDF;
if (res == EPUB) if (res == EPUB)
{ {
void* handler = client->zipOpen(path); void* handler = client->zipOpen(path);

View File

@@ -3,9 +3,11 @@ TARGETS=acsmdownloader adept_activate
CXXFLAGS=-Wall `pkg-config --cflags Qt5Core Qt5Network` -fPIC -I$(ROOT)/include -I$(ROOT)/lib/pugixml/src/ CXXFLAGS=-Wall `pkg-config --cflags Qt5Core Qt5Network` -fPIC -I$(ROOT)/include -I$(ROOT)/lib/pugixml/src/
STATIC_DEP=
LDFLAGS=`pkg-config --libs Qt5Core Qt5Network` -L$(ROOT) -lcrypto -lzip -lz LDFLAGS=`pkg-config --libs Qt5Core Qt5Network` -L$(ROOT) -lcrypto -lzip -lz
ifneq ($(STATIC_UTILS),) ifneq ($(STATIC_UTILS),)
LDFLAGS += $(ROOT)/libgourou.a STATIC_DEP = $(ROOT)/libgourou.a
else else
LDFLAGS += -lgourou LDFLAGS += -lgourou
endif endif
@@ -18,10 +20,10 @@ endif
all: $(TARGETS) all: $(TARGETS)
acsmdownloader: drmprocessorclientimpl.cpp acsmdownloader.cpp acsmdownloader: drmprocessorclientimpl.cpp acsmdownloader.cpp $(STATIC_DEP)
$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@ $(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@
adept_activate: drmprocessorclientimpl.cpp adept_activate.cpp adept_activate: drmprocessorclientimpl.cpp adept_activate.cpp $(STATIC_DEP)
$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@ $(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@
clean: clean:

View File

@@ -105,6 +105,11 @@ public:
filename = item->getMetadata("title"); filename = item->getMetadata("title");
if (filename == "") if (filename == "")
filename = "output"; filename = "output";
else
{
// Remove invalid characters
std::replace(filename.begin(), filename.end(), '/', '_');
}
} }
else else
filename = outputFile; filename = outputFile;

View File

@@ -152,7 +152,7 @@ static void usage(const char* cmd)
std::cout << " " << "-H|--hobbes-version" << "\t"<< "Force RMSDK version to a specific value (default: version of current librmsdk)" << std::endl; std::cout << " " << "-H|--hobbes-version" << "\t"<< "Force RMSDK version to a specific value (default: version of current librmsdk)" << std::endl;
std::cout << " " << "-r|--random-serial" << "\t"<< "Generate a random device serial (if not set, it will be dependent of your current configuration)" << std::endl; std::cout << " " << "-r|--random-serial" << "\t"<< "Generate a random device serial (if not set, it will be dependent of your current configuration)" << std::endl;
std::cout << " " << "-v|--verbose" << "\t\t" << "Increase verbosity, can be set multiple times" << std::endl; std::cout << " " << "-v|--verbose" << "\t\t" << "Increase verbosity, can be set multiple times" << std::endl;
std::cout << " " << "-V|--version" << "\t\t" << "Display libgourou version" << std::endl; std::cout << " " << "-V|--version" << "\t\t" << "Display libgourou version" << std::endl;
std::cout << " " << "-h|--help" << "\t\t" << "This help" << std::endl; std::cout << " " << "-h|--help" << "\t\t" << "This help" << std::endl;
std::cout << std::endl; std::cout << std::endl;
@@ -184,7 +184,7 @@ int main(int argc, char** argv)
{"hobbes-version",required_argument, 0, 'H' }, {"hobbes-version",required_argument, 0, 'H' },
{"random-serial", no_argument, 0, 'r' }, {"random-serial", no_argument, 0, 'r' },
{"verbose", no_argument, 0, 'v' }, {"verbose", no_argument, 0, 'v' },
{"version", no_argument, 0, 'V' }, {"version", no_argument, 0, 'V' },
{"help", no_argument, 0, 'h' }, {"help", no_argument, 0, 'h' },
{0, 0, 0, 0 } {0, 0, 0, 0 }
}; };

View File

@@ -441,26 +441,31 @@ void DRMProcessorClientImpl::inflate(std::string data, gourou::ByteArray& result
int ret = inflateInit2(&infstream, wbits); int ret = inflateInit2(&infstream, wbits);
ret = ::inflate(&infstream, Z_SYNC_FLUSH); if (ret != Z_OK)
EXCEPTION(gourou::CLIENT_ZIP_ERROR, infstream.msg);
ret = ::inflate(&infstream, Z_FINISH);
while (ret == Z_OK || ret == Z_STREAM_END) while (ret == Z_OK || ret == Z_STREAM_END)
{ {
result.append(buffer, dataSize-infstream.avail_out); result.append(buffer, dataSize-infstream.avail_out);
if (ret == Z_STREAM_END) break; if ((ret == Z_OK && infstream.avail_out != 0) || ret == Z_STREAM_END)
break;
infstream.avail_out = (uInt)dataSize; // size of output infstream.avail_out = (uInt)dataSize; // size of output
infstream.next_out = (Bytef *)buffer; // output char array infstream.next_out = (Bytef *)buffer; // output char array
ret = ::inflate(&infstream, Z_SYNC_FLUSH); ret = ::inflate(&infstream, Z_FINISH);
} }
inflateEnd(&infstream); if (ret == Z_STREAM_END)
ret = deflateEnd(&infstream);
delete[] buffer; delete[] buffer;
if (ret != Z_OK && ret != Z_STREAM_END && ret != Z_BUF_ERROR) if (ret != Z_OK && ret != Z_STREAM_END)
EXCEPTION(gourou::CLIENT_ZIP_ERROR, zError(ret)); EXCEPTION(gourou::CLIENT_ZIP_ERROR, zError(ret));
} }
void DRMProcessorClientImpl::deflate(std::string data, gourou::ByteArray& result, void DRMProcessorClientImpl::deflate(std::string data, gourou::ByteArray& result,
int wbits, int compressionLevel) int wbits, int compressionLevel)
{ {
unsigned int dataSize = data.size(); unsigned int dataSize = data.size();
unsigned char* buffer = new unsigned char[dataSize]; unsigned char* buffer = new unsigned char[dataSize];
@@ -479,20 +484,25 @@ void DRMProcessorClientImpl::deflate(std::string data, gourou::ByteArray& result
int ret = deflateInit2(&defstream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, wbits, int ret = deflateInit2(&defstream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, wbits,
compressionLevel, Z_DEFAULT_STRATEGY); compressionLevel, Z_DEFAULT_STRATEGY);
ret = ::deflate(&defstream, Z_SYNC_FLUSH); if (ret != Z_OK)
EXCEPTION(gourou::CLIENT_ZIP_ERROR, defstream.msg);
ret = ::deflate(&defstream, Z_FINISH);
while (ret == Z_OK || ret == Z_STREAM_END) while (ret == Z_OK || ret == Z_STREAM_END)
{ {
result.append(buffer, dataSize-defstream.avail_out); result.append(buffer, dataSize-defstream.avail_out);
if (ret == Z_STREAM_END) break; if ((ret == Z_OK && defstream.avail_out != 0) || ret == Z_STREAM_END)
break;
defstream.avail_out = (uInt)dataSize; // size of output defstream.avail_out = (uInt)dataSize; // size of output
defstream.next_out = (Bytef *)buffer; // output char array defstream.next_out = (Bytef *)buffer; // output char array
ret = ::deflate(&defstream, Z_SYNC_FLUSH); ret = ::deflate(&defstream, Z_FINISH);
} }
deflateEnd(&defstream); if (ret == Z_STREAM_END)
ret = deflateEnd(&defstream);
delete[] buffer; delete[] buffer;
if (ret != Z_OK && ret != Z_STREAM_END && ret != Z_BUF_ERROR) if (ret != Z_OK && ret != Z_STREAM_END)
EXCEPTION(gourou::CLIENT_ZIP_ERROR, zError(ret)); EXCEPTION(gourou::CLIENT_ZIP_ERROR, zError(ret));
} }