From a6cf9730be31220a3ecd1ee218c261c88fe05e0c Mon Sep 17 00:00:00 2001 From: Nimetu Date: Mon, 20 Apr 2015 20:50:56 +0300 Subject: [PATCH 1/4] Fix possible curl handle leak --HG-- branch : develop --- code/nel/src/gui/group_html.cpp | 40 ++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index 9cfdc1ef0..1a893d0d9 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -192,10 +192,6 @@ namespace NLGUI } } - CURL *curl = curl_easy_init(); - curl_easy_setopt(curl, CURLOPT_NOPROGRESS, true); - curl_easy_setopt(curl, CURLOPT_URL, finalUrl.c_str()); - // use requested url for local name string dest = localImageName(url); string tmpdest = localImageName(url)+".tmp"; @@ -209,13 +205,30 @@ namespace NLGUI if (!NLMISC::CFile::fileExists(dest)) { + if (!MultiCurl) + { + nlwarning("Invalid MultiCurl handle, unable to download '%s'", finalUrl.c_str()); + return; + } + + CURL *curl = curl_easy_init(); + if (!curl) + { + nlwarning("Creating cURL handle failed, unable to download '%s'", finalUrl.c_str()); + return; + } FILE *fp = fopen (tmpdest.c_str(), "wb"); if (fp == NULL) { + curl_easy_cleanup(curl); + nlwarning("Can't open file '%s' for writing: code=%d '%s'", tmpdest.c_str (), errno, strerror(errno)); return; } + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, true); + curl_easy_setopt(curl, CURLOPT_URL, finalUrl.c_str()); + curl_easy_setopt(curl, CURLOPT_FILE, fp); curl_multi_add_handle(MultiCurl, curl); @@ -298,19 +311,30 @@ namespace NLGUI } if (action != "delete") { - CURL *curl = curl_easy_init(); - if (!MultiCurl || !curl) + if (!MultiCurl) + { + nlwarning("Invalid MultiCurl handle, unable to download '%s'", url.c_str()); return false; + } - curl_easy_setopt(curl, CURLOPT_NOPROGRESS, true); - curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); + CURL *curl = curl_easy_init(); + if (!curl) + { + nlwarning("Creating cURL handle failed, unable to download '%s'", url.c_str()); + return false; + } FILE *fp = fopen (tmpdest.c_str(), "wb"); if (fp == NULL) { + curl_easy_cleanup(curl); nlwarning("Can't open file '%s' for writing: code=%d '%s'", tmpdest.c_str (), errno, strerror(errno)); return false; } + + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, true); + curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); + curl_easy_setopt(curl, CURLOPT_FILE, fp); curl_multi_add_handle(MultiCurl, curl); From ce4cb9c4f1460bcfd462721301d6e2818b2759b4 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Mon, 20 Apr 2015 20:51:00 +0300 Subject: [PATCH 2/4] Fix sending and receiving cookies --HG-- branch : develop --- code/nel/src/gui/group_html.cpp | 6 ++++-- code/nel/src/gui/libwww.cpp | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index 1a893d0d9..024d9b88e 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -416,6 +416,8 @@ namespace NLGUI } else { + receiveCookies(_CurlWWW->Request, HTTPCurrentDomain, _TrustedDomain); + // redirect, get the location and try browse again // we cant use curl redirection because 'addHTTPGetParams()' must be called on new destination std::string location(_CurlWWW->getLocationHeader()); @@ -441,6 +443,8 @@ namespace NLGUI } else { + receiveCookies(_CurlWWW->Request, HTTPCurrentDomain, _TrustedDomain); + _RedirectsRemaining = DEFAULT_RYZOM_REDIRECT_LIMIT; if ( (code < 200 || code >= 300) ) @@ -449,8 +453,6 @@ namespace NLGUI } else { - receiveCookies(_CurlWWW->Request, HTTPCurrentDomain, _TrustedDomain); - char *ch; std::string contentType; res = curl_easy_getinfo(_CurlWWW->Request, CURLINFO_CONTENT_TYPE, &ch); diff --git a/code/nel/src/gui/libwww.cpp b/code/nel/src/gui/libwww.cpp index ff73bb59a..88c6f38c4 100644 --- a/code/nel/src/gui/libwww.cpp +++ b/code/nel/src/gui/libwww.cpp @@ -387,6 +387,9 @@ namespace NLGUI // add all cookies for domain to curl handle void sendCookies(CURL *curl, const std::string &domain, bool trusted) { + // enable curl cookie engine + curl_easy_setopt(curl, CURLOPT_COOKIELIST, ""); + if (domain.empty()) return; From c58e10f1734856f405c31a0cf942099292a8a0f1 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Tue, 21 Apr 2015 18:54:08 +0300 Subject: [PATCH 3/4] Add "select_shortcut_bar_2" action handler (issue 222) --HG-- branch : develop --- .../data/gamedev/interfaces_v3/actions.xml | 14 ++++++++++++++ .../src/interface_v3/action_handler_phrase.cpp | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/code/ryzom/client/data/gamedev/interfaces_v3/actions.xml b/code/ryzom/client/data/gamedev/interfaces_v3/actions.xml index 3486e0298..8696de32a 100644 --- a/code/ryzom/client/data/gamedev/interfaces_v3/actions.xml +++ b/code/ryzom/client/data/gamedev/interfaces_v3/actions.xml @@ -205,6 +205,20 @@ + + + + + + + + + + + + + + diff --git a/code/ryzom/client/src/interface_v3/action_handler_phrase.cpp b/code/ryzom/client/src/interface_v3/action_handler_phrase.cpp index 67f798cb8..81fa09ef0 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_phrase.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_phrase.cpp @@ -1620,6 +1620,23 @@ public: }; REGISTER_ACTION_HANDLER(CHandlerPhraseSelectShortcutBar, "select_shortcut_bar"); +// *************************************************************************** +class CHandlerPhraseSelectShortcutBar2 : public IActionHandler +{ +public: + virtual void execute(CCtrlBase * /* pCaller */, const string &Params) + { + CInterfaceManager *pIM= CInterfaceManager::getInstance(); + CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp("UI:PHRASE:SELECT_MEMORY_2", false); + if(node) + { + sint32 val; + fromString(Params, val); + node->setValue32(val); + } + } +}; +REGISTER_ACTION_HANDLER(CHandlerPhraseSelectShortcutBar2, "select_shortcut_bar_2"); // *************************************************************************** // *************************************************************************** From 11ca61be547773ef61b3acd78c8dc1af344f7d42 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Wed, 22 Apr 2015 13:44:21 +0300 Subject: [PATCH 4/4] Fix compiling on 32bit linux --HG-- branch : develop --- code/nel/src/gui/group_html.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index 024d9b88e..c06daeead 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -449,7 +449,7 @@ namespace NLGUI if ( (code < 200 || code >= 300) ) { - browseError(string("Connection failed (curl code " + toString((sint32)res) + "), http code " + toString(code) + ") : " + _CurlWWW->Url).c_str()); + browseError(string("Connection failed (curl code " + toString((sint32)res) + "), http code " + toString((sint32)code) + ") : " + _CurlWWW->Url).c_str()); } else {