From e05639c09d7d5a0c26ee20857fef1d53bd0ca1cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sat, 6 Jan 2024 09:23:50 +0100 Subject: [PATCH] Support HTTP error codes != 200 (exception) and cookies in drmprocessorclientimpl --- include/libgourou_common.h | 1 + utils/drmprocessorclientimpl.cpp | 20 +++++++++++++++++++- utils/drmprocessorclientimpl.h | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/libgourou_common.h b/include/libgourou_common.h index a6f2a91..72f3915 100644 --- a/include/libgourou_common.h +++ b/include/libgourou_common.h @@ -120,6 +120,7 @@ namespace gourou CLIENT_OSSL_ERROR, CLIENT_CRYPT_ERROR, CLIENT_DIGEST_ERROR, + CLIENT_HTTP_ERROR }; enum DRM_REMOVAL_ERROR { diff --git a/utils/drmprocessorclientimpl.cpp b/utils/drmprocessorclientimpl.cpp index d451834..1019eaf 100644 --- a/utils/drmprocessorclientimpl.cpp +++ b/utils/drmprocessorclientimpl.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #define OPENSSL_NO_DEPRECATED 1 @@ -60,6 +61,14 @@ DRMProcessorClientImpl::DRMProcessorClientImpl(): if (!deflt) EXCEPTION(gourou::CLIENT_OSSL_ERROR, "Error, OpenSSL default provider not available"); #endif + +#ifdef WIN32 + strcpy(cookiejar, "C:\\temp\\libgourou_cookie_jar_XXXXXX"); +#else + strcpy(cookiejar, "/tmp/libgourou_cookie_jar_XXXXXX"); +#endif + + mkstemp(cookiejar); } DRMProcessorClientImpl::~DRMProcessorClientImpl() @@ -71,6 +80,8 @@ DRMProcessorClientImpl::~DRMProcessorClientImpl() if (deflt) OSSL_PROVIDER_unload(deflt); #endif + + unlink(cookiejar); } /* Digest interface */ @@ -227,6 +238,7 @@ std::string DRMProcessorClientImpl::sendHTTPRequest(const std::string& URL, cons } curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list); + curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookiejar); if (POSTData.size()) { @@ -290,7 +302,13 @@ std::string DRMProcessorClientImpl::sendHTTPRequest(const std::string& URL, cons if (res != CURLE_OK) EXCEPTION(gourou::CLIENT_NETWORK_ERROR, "Error " << curl_easy_strerror(res)); - + + long http_code = 400; + curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code); + + if (http_code >= 400) + EXCEPTION(gourou::CLIENT_HTTP_ERROR, "HTTP Error code " << http_code); + if ((downloadedBytes >= DISPLAY_THRESHOLD || replyData.size() >= DISPLAY_THRESHOLD) && gourou::logLevel >= gourou::LG_LOG_WARN) std::cout << std::endl; diff --git a/utils/drmprocessorclientimpl.h b/utils/drmprocessorclientimpl.h index c2198c6..cec1a22 100644 --- a/utils/drmprocessorclientimpl.h +++ b/utils/drmprocessorclientimpl.h @@ -136,6 +136,8 @@ private: #else void *legacy, *deflt; #endif + + char cookiejar[64]; }; #endif