@ -312,7 +312,7 @@ namespace NLGUI
return false ;
return false ;
}
}
download . curl = curl ;
download . data = new CCurlWWWData ( curl , download . url ) ;
download . fp = fp ;
download . fp = fp ;
curl_easy_setopt ( curl , CURLOPT_NOPROGRESS , true ) ;
curl_easy_setopt ( curl , CURLOPT_NOPROGRESS , true ) ;
@ -322,6 +322,10 @@ namespace NLGUI
curl_easy_setopt ( curl , CURLOPT_PROTOCOLS , CURLPROTO_HTTP | CURLPROTO_HTTPS ) ;
curl_easy_setopt ( curl , CURLOPT_PROTOCOLS , CURLPROTO_HTTP | CURLPROTO_HTTPS ) ;
curl_easy_setopt ( curl , CURLOPT_REDIR_PROTOCOLS , CURLPROTO_HTTP | CURLPROTO_HTTPS ) ;
curl_easy_setopt ( curl , CURLOPT_REDIR_PROTOCOLS , CURLPROTO_HTTP | CURLPROTO_HTTPS ) ;
// catch headers
curl_easy_setopt ( curl , CURLOPT_HEADERFUNCTION , curlHeaderCallback ) ;
curl_easy_setopt ( curl , CURLOPT_WRITEHEADER , download . data ) ;
std : : string userAgent = options . appName + " / " + options . appVersion ;
std : : string userAgent = options . appName + " / " + options . appVersion ;
curl_easy_setopt ( curl , CURLOPT_USERAGENT , userAgent . c_str ( ) ) ;
curl_easy_setopt ( curl , CURLOPT_USERAGENT , userAgent . c_str ( ) ) ;
@ -369,7 +373,7 @@ namespace NLGUI
RunningCurls + + ;
RunningCurls + + ;
# ifdef LOG_DL
# ifdef LOG_DL
nlwarning ( " (%s) adding handle %x, %d curls " , _Id . c_str ( ) , Curls . back ( ) . curl , Curls . size ( ) ) ;
nlwarning ( " (%s) adding handle %x, %d curls " , _Id . c_str ( ) , Curls . back ( ) . data- > Request , Curls . size ( ) ) ;
}
}
else
else
{
{
@ -443,7 +447,7 @@ namespace NLGUI
}
}
RunningCurls + + ;
RunningCurls + + ;
# ifdef LOG_DL
# ifdef LOG_DL
nlwarning ( " (%s) adding handle %x, %d curls " , _Id . c_str ( ) , Curls . back ( ) . curl , Curls . size ( ) ) ;
nlwarning ( " (%s) adding handle %x, %d curls " , _Id . c_str ( ) , Curls . back ( ) . data- > Request , Curls . size ( ) ) ;
}
}
else
else
{
{
@ -580,18 +584,18 @@ namespace NLGUI
for ( vector < CDataDownload > : : iterator it = Curls . begin ( ) ; it < Curls . end ( ) ; it + + )
for ( vector < CDataDownload > : : iterator it = Curls . begin ( ) ; it < Curls . end ( ) ; it + + )
{
{
if ( msg- > easy_handle = = it - > curl )
if ( it- > data & & it - > data - > Request = = msg - > easy_handle )
{
{
CURLcode res = msg - > data . result ;
CURLcode res = msg - > data . result ;
long r ;
long r ;
curl_easy_getinfo ( it - > curl , CURLINFO_RESPONSE_CODE , & r ) ;
curl_easy_getinfo ( it - > data- > Request , CURLINFO_RESPONSE_CODE , & r ) ;
fclose ( it - > fp ) ;
fclose ( it - > fp ) ;
receiveCookies ( it - > data - > Request , _DocumentDomain , _TrustedDomain ) ;
# ifdef LOG_DL
# ifdef LOG_DL
nlwarning ( " (%s) transfer '%p' completed with status %d, http %d, url (len %d) '%s' " , _Id . c_str ( ) , it - > curl , res , r , it - > url . size ( ) , it - > url . c_str ( ) ) ;
nlwarning ( " (%s) transfer '%p' completed with status %d, http %d, url (len %d) '%s' " , _Id . c_str ( ) , it - > data- > Request , res , r , it - > url . size ( ) , it - > url . c_str ( ) ) ;
# endif
# endif
curl_multi_remove_handle ( MultiCurl , it - > curl ) ;
curl_multi_remove_handle ( MultiCurl , it - > data - > Request ) ;
curl_easy_cleanup ( it - > curl ) ;
string tmpfile = it - > dest + " .tmp " ;
string tmpfile = it - > dest + " .tmp " ;
if ( res ! = CURLE_OK | | r < 200 | | r > = 300 | | ( ! it - > md5sum . empty ( ) & & ( it - > md5sum ! = getMD5 ( tmpfile ) . toString ( ) ) ) )
if ( res ! = CURLE_OK | | r < 200 | | r > = 300 | | ( ! it - > md5sum . empty ( ) & & ( it - > md5sum ! = getMD5 ( tmpfile ) . toString ( ) ) ) )
@ -642,6 +646,9 @@ namespace NLGUI
}
}
}
}
// release CCurlWWWData
delete it - > data ;
Curls . erase ( it ) ;
Curls . erase ( it ) ;
break ;
break ;
}
}
@ -656,7 +663,7 @@ namespace NLGUI
{
{
for ( vector < CDataDownload > : : iterator it = Curls . begin ( ) ; it < Curls . end ( ) ; it + + )
for ( vector < CDataDownload > : : iterator it = Curls . begin ( ) ; it < Curls . end ( ) ; it + + )
{
{
if ( it - > curl = = NULL ) {
if ( it - > data = = NULL ) {
# ifdef LOG_DL
# ifdef LOG_DL
nlwarning ( " (%s) starting new download '%s' " , _Id . c_str ( ) , it - > url . c_str ( ) ) ;
nlwarning ( " (%s) starting new download '%s' " , _Id . c_str ( ) , it - > url . c_str ( ) ) ;
# endif
# endif
@ -4575,7 +4582,7 @@ namespace NLGUI
// remove download that are still queued
// remove download that are still queued
for ( vector < CDataDownload > : : iterator it = Curls . begin ( ) ; it < Curls . end ( ) ; )
for ( vector < CDataDownload > : : iterator it = Curls . begin ( ) ; it < Curls . end ( ) ; )
{
{
if ( it - > curl = = NULL ) {
if ( it - > data = = NULL ) {
# ifdef LOG_DL
# ifdef LOG_DL
nlwarning ( " Remove waiting curl download (%s) " , it - > url . c_str ( ) ) ;
nlwarning ( " Remove waiting curl download (%s) " , it - > url . c_str ( ) ) ;
# endif
# endif