Changed: Save cookies from image request

--HG--
branch : develop
hg/compatibility-develop
Nimetu 8 years ago
parent 3d48368de6
commit 3d09dd2094

@ -821,13 +821,13 @@ namespace NLGUI
{
public:
CDataDownload(const std::string &u, const std::string &d, TDataType t, CViewBase *i, const std::string &s, const std::string &m, const CStyleParams &style = CStyleParams())
: curl(NULL), fp(NULL), url(u), dest(d), type(t), luaScript(s), md5sum(m)
: data(NULL), fp(NULL), url(u), dest(d), type(t), luaScript(s), md5sum(m)
{
if (t == ImgType) imgs.push_back(CDataImageDownload(i, style));
}
public:
CURL *curl;
CCurlWWWData *data;
std::string url;
std::string dest;
std::string luaScript;

@ -312,7 +312,7 @@ namespace NLGUI
return false;
}
download.curl = curl;
download.data = new CCurlWWWData(curl, download.url);
download.fp = fp;
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_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;
curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str());
@ -369,7 +373,7 @@ namespace NLGUI
RunningCurls++;
#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
{
@ -443,7 +447,7 @@ namespace NLGUI
}
RunningCurls++;
#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
{
@ -580,18 +584,18 @@ namespace NLGUI
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;
long r;
curl_easy_getinfo(it->curl, CURLINFO_RESPONSE_CODE, &r);
curl_easy_getinfo(it->data->Request, CURLINFO_RESPONSE_CODE, &r);
fclose(it->fp);
receiveCookies(it->data->Request, _DocumentDomain, _TrustedDomain);
#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
curl_multi_remove_handle(MultiCurl, it->curl);
curl_easy_cleanup(it->curl);
curl_multi_remove_handle(MultiCurl, it->data->Request);
string tmpfile = it->dest + ".tmp";
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);
break;
}
@ -656,7 +663,7 @@ namespace NLGUI
{
for (vector<CDataDownload>::iterator it=Curls.begin(); it<Curls.end(); it++)
{
if (it->curl == NULL) {
if (it->data == NULL) {
#ifdef LOG_DL
nlwarning("(%s) starting new download '%s'", _Id.c_str(), it->url.c_str());
#endif
@ -4575,7 +4582,7 @@ namespace NLGUI
// remove download that are still queued
for (vector<CDataDownload>::iterator it=Curls.begin(); it<Curls.end(); )
{
if (it->curl == NULL) {
if (it->data == NULL) {
#ifdef LOG_DL
nlwarning("Remove waiting curl download (%s)", it->url.c_str());
#endif

Loading…
Cancel
Save