Remove ugly curl struct pointer from jsonFetchValue signature 1393/head
authorsapier <Sapier at GMX dot net>
Thu, 19 Jun 2014 18:58:22 +0000 (20:58 +0200)
committersapier <Sapier at GMX dot net>
Thu, 19 Jun 2014 19:24:53 +0000 (21:24 +0200)
src/convert_json.cpp
src/convert_json.h
src/guiEngine.cpp
src/mods.cpp
src/mods.h
src/serverlist.cpp

index a6107aa64a7fec1790e9d133c9fabb6c95a2178b..e79103a16c88d9e01170ba61e57f0eb7e1b04ca0 100644 (file)
@@ -32,20 +32,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "porting.h"
 
 Json::Value                 fetchJsonValue(const std::string &url,
-               struct curl_slist *chunk) {
+               std::vector<std::string> *extra_headers) {
 
        HTTPFetchRequest fetchrequest;
        HTTPFetchResult fetchresult;
        fetchrequest.url = url;
        fetchrequest.caller = HTTPFETCH_SYNC;
 
-#if USE_CURL
-       struct curl_slist* runptr = chunk;
-       while(runptr) {
-               fetchrequest.extra_headers.push_back(runptr->data);
-               runptr = runptr->next;
-       }
-#endif
+       if (extra_headers != NULL)
+               fetchrequest.extra_headers = *extra_headers;
+
        httpfetch_sync(fetchrequest,fetchresult);
 
        if (!fetchresult.succeeded) {
index ea9bafb799a4afcd6507d81d889dc07b474f955f..6732fcfa3148b52a078f5e4f2e95da9b9f9b9d2b 100644 (file)
@@ -29,6 +29,6 @@ std::vector<ModStoreMod>    readModStoreList(Json::Value& modlist);
 ModStoreModDetails          readModStoreModDetails(Json::Value& details);
 
 Json::Value                 fetchJsonValue(const std::string &url,
-                                           struct curl_slist *chunk);
+                                           std::vector<std::string> *extra_headers);
 
 #endif
index f71c6a515b8d1d7cf0e3df7c20c15e3d6d90598b..671f0c574dbd91fd7ac31e65744a1bc1329f272d 100644 (file)
@@ -36,10 +36,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <IGUIStaticText.h>
 #include <ICameraSceneNode.h>
 
-#if USE_CURL
-#include <curl/curl.h>
-#endif
-
 /******************************************************************************/
 /** TextDestGuiEngine                                                         */
 /******************************************************************************/
@@ -297,7 +293,7 @@ GUIEngine::~GUIEngine()
        }
 
        delete m_texture_source;
-       
+
        if (m_cloud.clouds)
                m_cloud.clouds->drop();
 }
index 90feee307b93b56634078d2ff8745d0664d34cc5..b4e075b1eae52b8d5202e1369ba7c274eb6c342e 100644 (file)
@@ -113,11 +113,11 @@ std::map<std::string, ModSpec> flattenModTree(std::map<std::string, ModSpec> mod
                ModSpec mod = (*it).second;
                if(mod.is_modpack)
                {
-                       std::map<std::string, ModSpec> content = 
+                       std::map<std::string, ModSpec> content =
                                flattenModTree(mod.modpack_content);
                        result.insert(content.begin(),content.end());
                        result.insert(std::make_pair(mod.name,mod));
-               } 
+               }
                else //not a modpack
                {
                        result.insert(std::make_pair(mod.name,mod));
@@ -138,8 +138,8 @@ std::vector<ModSpec> flattenMods(std::map<std::string, ModSpec> mods)
                        std::vector<ModSpec> content = flattenMods(mod.modpack_content);
                        result.reserve(result.size() + content.size());
                        result.insert(result.end(),content.begin(),content.end());
-                       
-               } 
+
+               }
                else //not a modpack
                {
                        result.push_back(mod);
@@ -163,10 +163,10 @@ ModConfiguration::ModConfiguration(std::string worldpath)
        worldmt_settings.readConfigFile(worldmt.c_str());
        std::vector<std::string> names = worldmt_settings.getNames();
        std::set<std::string> include_mod_names;
-       for(std::vector<std::string>::iterator it = names.begin(); 
+       for(std::vector<std::string>::iterator it = names.begin();
                it != names.end(); ++it)
-       {       
-               std::string name = *it;  
+       {
+               std::string name = *it;
                // for backwards compatibility: exclude only mods which are
                // explicitely excluded. if mod is not mentioned at all, it is
                // enabled. So by default, all installed mods are enabled.
@@ -234,7 +234,7 @@ void ModConfiguration::addMods(std::vector<ModSpec> new_mods)
                // Add all the mods that come from modpacks
                // Second iteration:
                // Add all the mods that didn't come from modpacks
-               
+
                std::set<std::string> seen_this_iteration;
 
                for(std::vector<ModSpec>::const_iterator it = new_mods.begin();
@@ -325,7 +325,7 @@ void ModConfiguration::resolveDependencies()
                        else{
                                ++it;
                        }
-               }       
+               }
        }
 
        // Step 4: write back list of unsatisfied mods
@@ -335,7 +335,7 @@ void ModConfiguration::resolveDependencies()
 #if USE_CURL
 Json::Value getModstoreUrl(std::string url)
 {
-       struct curl_slist *chunk = NULL;
+       std::vector<std::string> extra_headers;
 
        bool special_http_header = true;
 
@@ -345,15 +345,13 @@ Json::Value getModstoreUrl(std::string url)
        catch(SettingNotFoundException &e) {
        }
 
-       if (special_http_header)
-               chunk = curl_slist_append(chunk, "Accept: application/vnd.minetest.mmdb-v1+json");
-
-       Json::Value retval = fetchJsonValue(url,chunk);
-
-       if (chunk != NULL)
-               curl_slist_free_all(chunk);
-
-       return retval;
+       if (special_http_header) {
+               extra_headers.push_back("Accept: application/vnd.minetest.mmdb-v1+json");
+               return fetchJsonValue(url, &extra_headers);
+       }
+       else {
+               return fetchJsonValue(url, NULL);
+       }
 }
 
 #endif
index f11401a1587d6e2aa1636472811b5bb6cdd758cf..f35bd18dba0b5e01c8046c1d6d423f1171d08a04 100644 (file)
@@ -30,10 +30,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "json/json.h"
 #include "config.h"
 
-#if USE_CURL
-#include <curl/curl.h>
-#endif
-
 #define MODNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_"
 
 class ModError : public std::exception
@@ -104,7 +100,7 @@ public:
                m_name_conflicts()
        {}
 
-               
+
        ModConfiguration(std::string worldpath);
 
        // checks if all dependencies are fullfilled.
index 00b5f2deeb1d0ee7e4025287beadc13e0eb16f18..8a85b33b3d5511a83d755eaa3b6a48bdf83c14fa 100644 (file)
@@ -70,7 +70,7 @@ std::vector<ServerListSpec> getLocal()
 
 std::vector<ServerListSpec> getOnline()
 {
-       Json::Value root = fetchJsonValue((g_settings->get("serverlist_url")+"/list").c_str(),0);
+       Json::Value root = fetchJsonValue((g_settings->get("serverlist_url")+"/list").c_str(), NULL);
 
        std::vector<ServerListSpec> serverlist;