mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 16:13:46 +01:00
Remove ugly curl struct pointer from jsonFetchValue signature
This commit is contained in:
parent
9a39848ba9
commit
8af44f8163
@ -32,20 +32,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "porting.h"
|
#include "porting.h"
|
||||||
|
|
||||||
Json::Value fetchJsonValue(const std::string &url,
|
Json::Value fetchJsonValue(const std::string &url,
|
||||||
struct curl_slist *chunk) {
|
std::vector<std::string> *extra_headers) {
|
||||||
|
|
||||||
HTTPFetchRequest fetchrequest;
|
HTTPFetchRequest fetchrequest;
|
||||||
HTTPFetchResult fetchresult;
|
HTTPFetchResult fetchresult;
|
||||||
fetchrequest.url = url;
|
fetchrequest.url = url;
|
||||||
fetchrequest.caller = HTTPFETCH_SYNC;
|
fetchrequest.caller = HTTPFETCH_SYNC;
|
||||||
|
|
||||||
#if USE_CURL
|
if (extra_headers != NULL)
|
||||||
struct curl_slist* runptr = chunk;
|
fetchrequest.extra_headers = *extra_headers;
|
||||||
while(runptr) {
|
|
||||||
fetchrequest.extra_headers.push_back(runptr->data);
|
|
||||||
runptr = runptr->next;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
httpfetch_sync(fetchrequest,fetchresult);
|
httpfetch_sync(fetchrequest,fetchresult);
|
||||||
|
|
||||||
if (!fetchresult.succeeded) {
|
if (!fetchresult.succeeded) {
|
||||||
|
@ -29,6 +29,6 @@ std::vector<ModStoreMod> readModStoreList(Json::Value& modlist);
|
|||||||
ModStoreModDetails readModStoreModDetails(Json::Value& details);
|
ModStoreModDetails readModStoreModDetails(Json::Value& details);
|
||||||
|
|
||||||
Json::Value fetchJsonValue(const std::string &url,
|
Json::Value fetchJsonValue(const std::string &url,
|
||||||
struct curl_slist *chunk);
|
std::vector<std::string> *extra_headers);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -36,10 +36,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include <IGUIStaticText.h>
|
#include <IGUIStaticText.h>
|
||||||
#include <ICameraSceneNode.h>
|
#include <ICameraSceneNode.h>
|
||||||
|
|
||||||
#if USE_CURL
|
|
||||||
#include <curl/curl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/** TextDestGuiEngine */
|
/** TextDestGuiEngine */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -297,7 +293,7 @@ GUIEngine::~GUIEngine()
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete m_texture_source;
|
delete m_texture_source;
|
||||||
|
|
||||||
if (m_cloud.clouds)
|
if (m_cloud.clouds)
|
||||||
m_cloud.clouds->drop();
|
m_cloud.clouds->drop();
|
||||||
}
|
}
|
||||||
|
36
src/mods.cpp
36
src/mods.cpp
@ -113,11 +113,11 @@ std::map<std::string, ModSpec> flattenModTree(std::map<std::string, ModSpec> mod
|
|||||||
ModSpec mod = (*it).second;
|
ModSpec mod = (*it).second;
|
||||||
if(mod.is_modpack)
|
if(mod.is_modpack)
|
||||||
{
|
{
|
||||||
std::map<std::string, ModSpec> content =
|
std::map<std::string, ModSpec> content =
|
||||||
flattenModTree(mod.modpack_content);
|
flattenModTree(mod.modpack_content);
|
||||||
result.insert(content.begin(),content.end());
|
result.insert(content.begin(),content.end());
|
||||||
result.insert(std::make_pair(mod.name,mod));
|
result.insert(std::make_pair(mod.name,mod));
|
||||||
}
|
}
|
||||||
else //not a modpack
|
else //not a modpack
|
||||||
{
|
{
|
||||||
result.insert(std::make_pair(mod.name,mod));
|
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);
|
std::vector<ModSpec> content = flattenMods(mod.modpack_content);
|
||||||
result.reserve(result.size() + content.size());
|
result.reserve(result.size() + content.size());
|
||||||
result.insert(result.end(),content.begin(),content.end());
|
result.insert(result.end(),content.begin(),content.end());
|
||||||
|
|
||||||
}
|
}
|
||||||
else //not a modpack
|
else //not a modpack
|
||||||
{
|
{
|
||||||
result.push_back(mod);
|
result.push_back(mod);
|
||||||
@ -163,10 +163,10 @@ ModConfiguration::ModConfiguration(std::string worldpath)
|
|||||||
worldmt_settings.readConfigFile(worldmt.c_str());
|
worldmt_settings.readConfigFile(worldmt.c_str());
|
||||||
std::vector<std::string> names = worldmt_settings.getNames();
|
std::vector<std::string> names = worldmt_settings.getNames();
|
||||||
std::set<std::string> include_mod_names;
|
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)
|
it != names.end(); ++it)
|
||||||
{
|
{
|
||||||
std::string name = *it;
|
std::string name = *it;
|
||||||
// for backwards compatibility: exclude only mods which are
|
// for backwards compatibility: exclude only mods which are
|
||||||
// explicitely excluded. if mod is not mentioned at all, it is
|
// explicitely excluded. if mod is not mentioned at all, it is
|
||||||
// enabled. So by default, all installed mods are enabled.
|
// 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
|
// Add all the mods that come from modpacks
|
||||||
// Second iteration:
|
// Second iteration:
|
||||||
// Add all the mods that didn't come from modpacks
|
// Add all the mods that didn't come from modpacks
|
||||||
|
|
||||||
std::set<std::string> seen_this_iteration;
|
std::set<std::string> seen_this_iteration;
|
||||||
|
|
||||||
for(std::vector<ModSpec>::const_iterator it = new_mods.begin();
|
for(std::vector<ModSpec>::const_iterator it = new_mods.begin();
|
||||||
@ -325,7 +325,7 @@ void ModConfiguration::resolveDependencies()
|
|||||||
else{
|
else{
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 4: write back list of unsatisfied mods
|
// Step 4: write back list of unsatisfied mods
|
||||||
@ -335,7 +335,7 @@ void ModConfiguration::resolveDependencies()
|
|||||||
#if USE_CURL
|
#if USE_CURL
|
||||||
Json::Value getModstoreUrl(std::string url)
|
Json::Value getModstoreUrl(std::string url)
|
||||||
{
|
{
|
||||||
struct curl_slist *chunk = NULL;
|
std::vector<std::string> extra_headers;
|
||||||
|
|
||||||
bool special_http_header = true;
|
bool special_http_header = true;
|
||||||
|
|
||||||
@ -345,15 +345,13 @@ Json::Value getModstoreUrl(std::string url)
|
|||||||
catch(SettingNotFoundException &e) {
|
catch(SettingNotFoundException &e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (special_http_header)
|
if (special_http_header) {
|
||||||
chunk = curl_slist_append(chunk, "Accept: application/vnd.minetest.mmdb-v1+json");
|
extra_headers.push_back("Accept: application/vnd.minetest.mmdb-v1+json");
|
||||||
|
return fetchJsonValue(url, &extra_headers);
|
||||||
Json::Value retval = fetchJsonValue(url,chunk);
|
}
|
||||||
|
else {
|
||||||
if (chunk != NULL)
|
return fetchJsonValue(url, NULL);
|
||||||
curl_slist_free_all(chunk);
|
}
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,10 +30,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "json/json.h"
|
#include "json/json.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#if USE_CURL
|
|
||||||
#include <curl/curl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MODNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_"
|
#define MODNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_"
|
||||||
|
|
||||||
class ModError : public std::exception
|
class ModError : public std::exception
|
||||||
@ -104,7 +100,7 @@ public:
|
|||||||
m_name_conflicts()
|
m_name_conflicts()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
ModConfiguration(std::string worldpath);
|
ModConfiguration(std::string worldpath);
|
||||||
|
|
||||||
// checks if all dependencies are fullfilled.
|
// checks if all dependencies are fullfilled.
|
||||||
|
@ -70,7 +70,7 @@ std::vector<ServerListSpec> getLocal()
|
|||||||
|
|
||||||
std::vector<ServerListSpec> getOnline()
|
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;
|
std::vector<ServerListSpec> serverlist;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user