diff --git a/include/libgourou_common.h b/include/libgourou_common.h index 2328208..2f7b098 100644 --- a/include/libgourou_common.h +++ b/include/libgourou_common.h @@ -140,7 +140,7 @@ namespace gourou std::stringstream msg; msg << "Exception code : 0x" << std::setbase(16) << code << std::endl; msg << "Message : " << message << std::endl; - if (logLevel >= DEBUG) + if (logLevel >= LG_LOG_DEBUG) msg << "File : " << file << ":" << std::setbase(10) << line << std::endl; fullmessage = strdup(msg.str().c_str()); } diff --git a/include/libgourou_log.h b/include/libgourou_log.h index 3aa342a..0d98300 100644 --- a/include/libgourou_log.h +++ b/include/libgourou_log.h @@ -24,16 +24,16 @@ namespace gourou { enum GOUROU_LOG_LEVEL { - ERROR, - WARN, - INFO, - DEBUG, - TRACE + LG_LOG_ERROR, + LG_LOG_WARN, + LG_LOG_INFO, + LG_LOG_DEBUG, + LG_LOG_TRACE }; extern GOUROU_LOG_LEVEL logLevel; -#define GOUROU_LOG(__lvl, __msg) if (__lvl <= gourou::logLevel) {std::cout << __msg << std::endl << std::flush;} +#define GOUROU_LOG(__lvl, __msg) if (gourou::LG_LOG_##__lvl <= gourou::logLevel) {std::cout << __msg << std::endl << std::flush;} #define GOUROU_LOG_FUNC() GOUROU_LOG(TRACE, __FUNCTION__ << "() @ " << __FILE__ << ":" << __LINE__) /** diff --git a/src/libgourou.cpp b/src/libgourou.cpp index d0f22ae..148e8af 100644 --- a/src/libgourou.cpp +++ b/src/libgourou.cpp @@ -37,7 +37,7 @@ namespace gourou { - GOUROU_LOG_LEVEL logLevel = WARN; + GOUROU_LOG_LEVEL logLevel = LG_LOG_WARN; const std::string DRMProcessor::VERSION = LIBGOUROU_VERSION; DRMProcessor::DRMProcessor(DRMProcessorClient* client):client(client), device(0), user(0) @@ -89,7 +89,7 @@ namespace gourou uint16_t nlength = htons(length); char c; - if (logLevel >= TRACE) + if (logLevel >= LG_LOG_TRACE) printf("%02x %02x ", ((uint8_t*)&nlength)[0], ((uint8_t*)&nlength)[1]); client->digestUpdate(sha_ctx, (unsigned char*)&nlength, sizeof(nlength)); @@ -98,17 +98,17 @@ namespace gourou { c = string[i]; client->digestUpdate(sha_ctx, (unsigned char*)&c, 1); - if (logLevel >= TRACE) + if (logLevel >= LG_LOG_TRACE) printf("%c", c); } - if (logLevel >= TRACE) + if (logLevel >= LG_LOG_TRACE) printf("\n"); } void DRMProcessor::pushTag(void* sha_ctx, uint8_t tag) { client->digestUpdate(sha_ctx, &tag, sizeof(tag)); - if (logLevel >= TRACE) + if (logLevel >= LG_LOG_TRACE) printf("%02x ", tag); } @@ -226,7 +226,7 @@ namespace gourou client->digestFinalize(sha_ctx, sha_out); - if (logLevel >= DEBUG) + if (logLevel >= LG_LOG_DEBUG) { printf("\nSHA OUT : "); for(int i=0; i<(int)SHA1_LEN; i++) @@ -252,7 +252,7 @@ namespace gourou client->RSAPrivateEncrypt(privateRSAKey.data(), privateRSAKey.length(), RSAInterface::RSA_KEY_PKCS12, deviceKey.toBase64().data(), sha_out, sizeof(sha_out), res); - if (logLevel >= DEBUG) + if (logLevel >= LG_LOG_DEBUG) { printf("Sig : "); for(int i=0; i<(int)sizeof(res); i++) diff --git a/utils/drmprocessorclientimpl.cpp b/utils/drmprocessorclientimpl.cpp index 2edc25f..555e5ee 100644 --- a/utils/drmprocessorclientimpl.cpp +++ b/utils/drmprocessorclientimpl.cpp @@ -124,7 +124,7 @@ static int downloadProgress(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) { // For "big" files only - if (dltotal >= DISPLAY_THRESHOLD && gourou::logLevel >= gourou::WARN) + if (dltotal >= DISPLAY_THRESHOLD && gourou::logLevel >= gourou::LG_LOG_WARN) { int percent = 0; if (dltotal) @@ -174,7 +174,7 @@ static size_t curlHeaders(char *buffer, size_t size, size_t nitems, void *userda (*responseHeaders)[key] = value; - if (gourou::logLevel >= gourou::DEBUG) + if (gourou::logLevel >= gourou::LG_LOG_DEBUG) std::cout << key << " : " << value << std::endl; } @@ -189,10 +189,10 @@ std::string DRMProcessorClientImpl::sendHTTPRequest(const std::string& URL, cons if (!responseHeaders) responseHeaders = &localHeaders; - GOUROU_LOG(gourou::INFO, "Send request to " << URL); + GOUROU_LOG(INFO, "Send request to " << URL); if (POSTData.size()) { - GOUROU_LOG(gourou::DEBUG, "<<< " << std::endl << POSTData); + GOUROU_LOG(DEBUG, "<<< " << std::endl << POSTData); } unsigned prevDownloadedBytes; @@ -202,11 +202,11 @@ std::string DRMProcessorClientImpl::sendHTTPRequest(const std::string& URL, cons struct stat _stat; if (!fstat(fd, &_stat)) { - GOUROU_LOG(gourou::WARN, "Resume download @ " << _stat.st_size << " bytes"); + GOUROU_LOG(WARN, "Resume download @ " << _stat.st_size << " bytes"); downloadedBytes = _stat.st_size; } else - GOUROU_LOG(gourou::WARN, "Want to resume, but fstat failed"); + GOUROU_LOG(WARN, "Want to resume, but fstat failed"); } CURL *curl = curl_easy_init(); @@ -262,7 +262,7 @@ std::string DRMProcessorClientImpl::sendHTTPRequest(const std::string& URL, cons // Connexion failed, wait & retry if (res == CURLE_COULDNT_CONNECT) { - GOUROU_LOG(gourou::WARN, "\nConnection failed, attempt " << (i+1) << "/" << HTTP_REQ_MAX_RETRY); + GOUROU_LOG(WARN, "\nConnection failed, attempt " << (i+1) << "/" << HTTP_REQ_MAX_RETRY); } // Transfer failed but some data has been received // --> try again without incrementing tries @@ -270,11 +270,11 @@ std::string DRMProcessorClientImpl::sendHTTPRequest(const std::string& URL, cons { if (prevDownloadedBytes != downloadedBytes) { - GOUROU_LOG(gourou::WARN, "\nConnection broken, but data received, try again"); + GOUROU_LOG(WARN, "\nConnection broken, but data received, try again"); i--; } else - GOUROU_LOG(gourou::WARN, "\nConnection broken and no data received, attempt " << (i+1) << "/" << HTTP_REQ_MAX_RETRY); + GOUROU_LOG(WARN, "\nConnection broken and no data received, attempt " << (i+1) << "/" << HTTP_REQ_MAX_RETRY); } // Other error --> fail else @@ -291,12 +291,12 @@ std::string DRMProcessorClientImpl::sendHTTPRequest(const std::string& URL, cons EXCEPTION(gourou::CLIENT_NETWORK_ERROR, "Error " << curl_easy_strerror(res)); if ((downloadedBytes >= DISPLAY_THRESHOLD || replyData.size() >= DISPLAY_THRESHOLD) && - gourou::logLevel >= gourou::WARN) + gourou::logLevel >= gourou::LG_LOG_WARN) std::cout << std::endl; if ((*responseHeaders)["Content-Type"] == "application/vnd.adobe.adept+xml") { - GOUROU_LOG(gourou::DEBUG, ">>> " << std::endl << replyData.data()); + GOUROU_LOG(DEBUG, ">>> " << std::endl << replyData.data()); } return std::string((char*)replyData.data(), replyData.length()); @@ -360,7 +360,7 @@ void DRMProcessorClientImpl::RSAPrivateDecrypt(const unsigned char* RSAKey, unsi if (ret < 0) EXCEPTION(gourou::CLIENT_RSA_ERROR, ERR_error_string(ERR_get_error(), NULL)); - if (gourou::logLevel >= gourou::DEBUG) + if (gourou::logLevel >= gourou::LG_LOG_DEBUG) { printf("Decrypted : "); for(int i=0; i