summaryrefslogtreecommitdiff
path: root/src/guiEngine.cpp
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2013-11-09 22:49:27 +0100
committerKahrl <kahrl@gmx.net>2013-12-13 18:05:46 +0100
commit0d990bd189881a9a6c829e1c9ec17b2dc5ac12c8 (patch)
tree90474ffb3ca64934aaefaaba92d85f6ff56b9574 /src/guiEngine.cpp
parentb03135548bbd9bcb73d14b067b96ec913404dd5f (diff)
downloadminetest-0d990bd189881a9a6c829e1c9ec17b2dc5ac12c8.tar.gz
minetest-0d990bd189881a9a6c829e1c9ec17b2dc5ac12c8.tar.bz2
minetest-0d990bd189881a9a6c829e1c9ec17b2dc5ac12c8.zip
Replace any direct curl usage by httpfetch
Diffstat (limited to 'src/guiEngine.cpp')
-rw-r--r--src/guiEngine.cpp55
1 files changed, 22 insertions, 33 deletions
diff --git a/src/guiEngine.cpp b/src/guiEngine.cpp
index d008b2568..0ec68e3ae 100644
--- a/src/guiEngine.cpp
+++ b/src/guiEngine.cpp
@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "sound.h"
#include "sound_openal.h"
#include "clouds.h"
+#include "httpfetch.h"
#include <IGUIStaticText.h>
#include <ICameraSceneNode.h>
@@ -507,51 +508,39 @@ bool GUIEngine::setTexture(texture_layer layer,std::string texturepath) {
}
/******************************************************************************/
-#if USE_CURL
-static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
-{
- FILE* targetfile = (FILE*) userp;
- fwrite(contents,size,nmemb,targetfile);
- return size * nmemb;
-}
-#endif
bool GUIEngine::downloadFile(std::string url,std::string target) {
#if USE_CURL
- //download file via curl
- CURL *curl;
+ bool retval = true;
- curl = curl_easy_init();
+ FILE* targetfile = fopen(target.c_str(),"wb");
- if (curl)
- {
- CURLcode res;
- bool retval = true;
-
- FILE* targetfile = fopen(target.c_str(),"wb");
-
- if (targetfile) {
- curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
- curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, targetfile);
- curl_easy_setopt(curl, CURLOPT_USERAGENT, (std::string("Minetest ")+minetest_version_hash).c_str());
- res = curl_easy_perform(curl);
- if (res != CURLE_OK) {
- errorstream << "File at url \"" << url
- <<"\" not found (" << curl_easy_strerror(res) << ")" <<std::endl;
+ if (targetfile) {
+ HTTPFetchRequest fetchrequest;
+ HTTPFetchResult fetchresult;
+ fetchrequest.url = url;
+ fetchrequest.useragent = std::string("Minetest ")+minetest_version_hash;
+ fetchrequest.timeout = g_settings->getS32("curl_timeout");
+ fetchrequest.caller = HTTPFETCH_SYNC;
+ httpfetch_sync(fetchrequest,fetchresult);
+
+ if (fetchresult.succeeded) {
+ if (fwrite(fetchresult.data.c_str(),1,fetchresult.data.size(),targetfile) != fetchresult.data.size()) {
retval = false;
}
- fclose(targetfile);
}
else {
retval = false;
}
-
- curl_easy_cleanup(curl);
- return retval;
+ fclose(targetfile);
}
-#endif
+ else {
+ retval = false;
+ }
+
+ return retval;
+#else
return false;
+#endif
}
/******************************************************************************/