]> git.lizzy.rs Git - minetest.git/blobdiff - src/convert_json.cpp
Fix uninitialized variable Player::local_animation_speed
[minetest.git] / src / convert_json.cpp
index e8eede0b1edb435d2d6a7d92bfb7afd3c7c5f094..cea0896239d7b1ed9322abeeedb8252d0f52c003 100644 (file)
@@ -27,77 +27,41 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "log.h"
 #include "main.h" // for g_settings
 #include "settings.h"
-#include "version.h"
+#include "httpfetch.h"
+#include "porting.h"
 
-#if USE_CURL
-#include <curl/curl.h>
-
-static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
+Json::Value fetchJsonValue(const std::string &url,
+               std::vector<std::string> *extra_headers)
 {
-    ((std::string*)userp)->append((char*)contents, size * nmemb);
-    return size * nmemb;
-}
+       HTTPFetchRequest fetch_request;
+       HTTPFetchResult fetch_result;
+       fetch_request.url = url;
+       fetch_request.caller = HTTPFETCH_SYNC;
 
-#endif
-
-Json::Value                 fetchJsonValue(const std::string url,
-                                                                                                       struct curl_slist *chunk) {
-#if USE_CURL
-       std::string liststring;
-       CURL *curl;
-
-       curl = curl_easy_init();
-       if (curl)
-       {
-               CURLcode res;
-
-               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, &liststring);
-               curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, g_settings->getS32("curl_timeout"));
-               curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, g_settings->getS32("curl_timeout"));
-               curl_easy_setopt(curl, CURLOPT_USERAGENT, (std::string("Minetest ")+minetest_version_hash).c_str());
-
-               if (chunk != 0)
-                       curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
-
-               res = curl_easy_perform(curl);
-               if (res != CURLE_OK)
-                       errorstream<<"Jsonreader: "<< url <<" not found (" << curl_easy_strerror(res) << ")" <<std::endl;
-               curl_easy_cleanup(curl);
-       }
+       if (extra_headers != NULL)
+               fetch_request.extra_headers = *extra_headers;
 
-       Json::Value root;
-       Json::Reader reader;
-       std::istringstream stream(liststring);
-       if (!liststring.size()) {
+       httpfetch_sync(fetch_request, fetch_result);
+
+       if (!fetch_result.succeeded) {
                return Json::Value();
        }
+       Json::Value root;
+       Json::Reader reader;
+       std::istringstream stream(fetch_result.data);
 
-       if (!reader.parse( stream, root ) )
-       {
+       if (!reader.parse(stream, root)) {
                errorstream << "URL: " << url << std::endl;
                errorstream << "Failed to parse json data " << reader.getFormattedErrorMessages();
-               errorstream << "data: \"" << liststring << "\"" << std::endl;
+               errorstream << "data: \"" << fetch_result.data << "\"" << std::endl;
                return Json::Value();
        }
 
-       if (root.isArray()) {
-               return root;
-       }
-       if ((root["list"].isArray())) {
-               return root["list"];
-       }
-       else {
-               return root;
-       }
-#endif
-       return Json::Value();
+       return root;
 }
 
 std::vector<ModStoreMod>    readModStoreList(Json::Value& modlist) {
-       std::vector<ModStoreMod> retval;
+               std::vector<ModStoreMod> retval;
 
        if (modlist.isArray()) {
                for (unsigned int i = 0; i < modlist.size(); i++)
@@ -210,7 +174,7 @@ ModStoreModDetails          readModStoreModDetails(Json::Value& details) {
        }
 
        if (retval.versions.size() < 1) {
-               errorstream << "readModStoreModDetails: not a single version specified!" << std::endl;
+               infostream << "readModStoreModDetails: not a single version specified!" << std::endl;
                retval.valid = false;
        }