forked from soutade/libgourou
		
	Add optional fd parameter to sendHTTPRequest() in order to directly write received data in a buffer and not in an intermediate buffer
This commit is contained in:
		| @@ -137,6 +137,17 @@ static size_t curlRead(void *data, size_t size, size_t nmemb, void *userp) | ||||
|     return size*nmemb; | ||||
| } | ||||
|  | ||||
| static size_t curlReadFd(void *data, size_t size, size_t nmemb, void *userp) | ||||
| { | ||||
|     int fd = *(int*) userp; | ||||
|  | ||||
|     size_t res = write(fd, data, size*nmemb); | ||||
|  | ||||
|     downloadedBytes += res; | ||||
|  | ||||
|     return res; | ||||
| } | ||||
|  | ||||
| static size_t curlHeaders(char *buffer, size_t size, size_t nitems, void *userdata) | ||||
| { | ||||
|     std::map<std::string, std::string>* responseHeaders = (std::map<std::string, std::string>*)userdata; | ||||
| @@ -162,7 +173,7 @@ static size_t curlHeaders(char *buffer, size_t size, size_t nitems, void *userda | ||||
|     return size*nitems; | ||||
| } | ||||
|  | ||||
| std::string DRMProcessorClientImpl::sendHTTPRequest(const std::string& URL, const std::string& POSTData, const std::string& contentType, std::map<std::string, std::string>* responseHeaders) | ||||
| std::string DRMProcessorClientImpl::sendHTTPRequest(const std::string& URL, const std::string& POSTData, const std::string& contentType, std::map<std::string, std::string>* responseHeaders, int fd) | ||||
| { | ||||
|     gourou::ByteArray replyData; | ||||
|     std::map<std::string, std::string> localHeaders; | ||||
| @@ -201,9 +212,17 @@ std::string DRMProcessorClientImpl::sendHTTPRequest(const std::string& URL, cons | ||||
| 	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, POSTData.data()); | ||||
|     } | ||||
|  | ||||
|     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlRead); | ||||
|     curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&replyData); | ||||
|  | ||||
|     if (fd) | ||||
|     { | ||||
| 	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlReadFd); | ||||
| 	curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&fd); | ||||
|     } | ||||
|     else | ||||
|     { | ||||
| 	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlRead); | ||||
| 	curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&replyData); | ||||
|     } | ||||
|      | ||||
|     curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, curlHeaders); | ||||
|     curl_easy_setopt(curl, CURLOPT_HEADERDATA, (void*)responseHeaders); | ||||
|      | ||||
|   | ||||
| @@ -46,7 +46,7 @@ public: | ||||
|     virtual void randBytes(unsigned char* bytesOut, unsigned int length); | ||||
|  | ||||
|     /* HTTP interface */ | ||||
|     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); | ||||
|     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, int fd=0); | ||||
|  | ||||
|     virtual void RSAPrivateEncrypt(const unsigned char* RSAKey, unsigned int RSAKeyLength, | ||||
| 				   const RSA_KEY_TYPE keyType, const std::string& password, | ||||
|   | ||||
| @@ -106,7 +106,7 @@ void fileCopy(const char* in, const char* out) | ||||
|     if (!fdIn) | ||||
| 	EXCEPTION(gourou::CLIENT_FILE_ERROR, "Unable to open " << in); | ||||
|      | ||||
|     fdOut = open(out, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); | ||||
|     fdOut = gourou::createNewFile(out); | ||||
|      | ||||
|     if (!fdOut) | ||||
|     { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user