Skip to content

Commit 8af44f8

Browse files
sapiersapier
authored andcommitted
Remove ugly curl struct pointer from jsonFetchValue signature
1 parent 9a39848 commit 8af44f8

File tree

6 files changed

+25
-39
lines changed

6 files changed

+25
-39
lines changed

src/convert_json.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3232
#include "porting.h"
3333

3434
Json::Value fetchJsonValue(const std::string &url,
35-
struct curl_slist *chunk) {
35+
std::vector<std::string> *extra_headers) {
3636

3737
HTTPFetchRequest fetchrequest;
3838
HTTPFetchResult fetchresult;
3939
fetchrequest.url = url;
4040
fetchrequest.caller = HTTPFETCH_SYNC;
4141

42-
#if USE_CURL
43-
struct curl_slist* runptr = chunk;
44-
while(runptr) {
45-
fetchrequest.extra_headers.push_back(runptr->data);
46-
runptr = runptr->next;
47-
}
48-
#endif
42+
if (extra_headers != NULL)
43+
fetchrequest.extra_headers = *extra_headers;
44+
4945
httpfetch_sync(fetchrequest,fetchresult);
5046

5147
if (!fetchresult.succeeded) {

src/convert_json.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ std::vector<ModStoreMod> readModStoreList(Json::Value& modlist);
2929
ModStoreModDetails readModStoreModDetails(Json::Value& details);
3030

3131
Json::Value fetchJsonValue(const std::string &url,
32-
struct curl_slist *chunk);
32+
std::vector<std::string> *extra_headers);
3333

3434
#endif

src/guiEngine.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3636
#include <IGUIStaticText.h>
3737
#include <ICameraSceneNode.h>
3838

39-
#if USE_CURL
40-
#include <curl/curl.h>
41-
#endif
42-
4339
/******************************************************************************/
4440
/** TextDestGuiEngine */
4541
/******************************************************************************/
@@ -297,7 +293,7 @@ GUIEngine::~GUIEngine()
297293
}
298294

299295
delete m_texture_source;
300-
296+
301297
if (m_cloud.clouds)
302298
m_cloud.clouds->drop();
303299
}

src/mods.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ std::map<std::string, ModSpec> flattenModTree(std::map<std::string, ModSpec> mod
113113
ModSpec mod = (*it).second;
114114
if(mod.is_modpack)
115115
{
116-
std::map<std::string, ModSpec> content =
116+
std::map<std::string, ModSpec> content =
117117
flattenModTree(mod.modpack_content);
118118
result.insert(content.begin(),content.end());
119119
result.insert(std::make_pair(mod.name,mod));
120-
}
120+
}
121121
else //not a modpack
122122
{
123123
result.insert(std::make_pair(mod.name,mod));
@@ -138,8 +138,8 @@ std::vector<ModSpec> flattenMods(std::map<std::string, ModSpec> mods)
138138
std::vector<ModSpec> content = flattenMods(mod.modpack_content);
139139
result.reserve(result.size() + content.size());
140140
result.insert(result.end(),content.begin(),content.end());
141-
142-
}
141+
142+
}
143143
else //not a modpack
144144
{
145145
result.push_back(mod);
@@ -163,10 +163,10 @@ ModConfiguration::ModConfiguration(std::string worldpath)
163163
worldmt_settings.readConfigFile(worldmt.c_str());
164164
std::vector<std::string> names = worldmt_settings.getNames();
165165
std::set<std::string> include_mod_names;
166-
for(std::vector<std::string>::iterator it = names.begin();
166+
for(std::vector<std::string>::iterator it = names.begin();
167167
it != names.end(); ++it)
168-
{
169-
std::string name = *it;
168+
{
169+
std::string name = *it;
170170
// for backwards compatibility: exclude only mods which are
171171
// explicitely excluded. if mod is not mentioned at all, it is
172172
// enabled. So by default, all installed mods are enabled.
@@ -234,7 +234,7 @@ void ModConfiguration::addMods(std::vector<ModSpec> new_mods)
234234
// Add all the mods that come from modpacks
235235
// Second iteration:
236236
// Add all the mods that didn't come from modpacks
237-
237+
238238
std::set<std::string> seen_this_iteration;
239239

240240
for(std::vector<ModSpec>::const_iterator it = new_mods.begin();
@@ -325,7 +325,7 @@ void ModConfiguration::resolveDependencies()
325325
else{
326326
++it;
327327
}
328-
}
328+
}
329329
}
330330

331331
// Step 4: write back list of unsatisfied mods
@@ -335,7 +335,7 @@ void ModConfiguration::resolveDependencies()
335335
#if USE_CURL
336336
Json::Value getModstoreUrl(std::string url)
337337
{
338-
struct curl_slist *chunk = NULL;
338+
std::vector<std::string> extra_headers;
339339

340340
bool special_http_header = true;
341341

@@ -345,15 +345,13 @@ Json::Value getModstoreUrl(std::string url)
345345
catch(SettingNotFoundException &e) {
346346
}
347347

348-
if (special_http_header)
349-
chunk = curl_slist_append(chunk, "Accept: application/vnd.minetest.mmdb-v1+json");
350-
351-
Json::Value retval = fetchJsonValue(url,chunk);
352-
353-
if (chunk != NULL)
354-
curl_slist_free_all(chunk);
355-
356-
return retval;
348+
if (special_http_header) {
349+
extra_headers.push_back("Accept: application/vnd.minetest.mmdb-v1+json");
350+
return fetchJsonValue(url, &extra_headers);
351+
}
352+
else {
353+
return fetchJsonValue(url, NULL);
354+
}
357355
}
358356

359357
#endif

src/mods.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3030
#include "json/json.h"
3131
#include "config.h"
3232

33-
#if USE_CURL
34-
#include <curl/curl.h>
35-
#endif
36-
3733
#define MODNAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyz0123456789_"
3834

3935
class ModError : public std::exception
@@ -104,7 +100,7 @@ class ModConfiguration
104100
m_name_conflicts()
105101
{}
106102

107-
103+
108104
ModConfiguration(std::string worldpath);
109105

110106
// checks if all dependencies are fullfilled.

src/serverlist.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ std::vector<ServerListSpec> getLocal()
7070

7171
std::vector<ServerListSpec> getOnline()
7272
{
73-
Json::Value root = fetchJsonValue((g_settings->get("serverlist_url")+"/list").c_str(),0);
73+
Json::Value root = fetchJsonValue((g_settings->get("serverlist_url")+"/list").c_str(), NULL);
7474

7575
std::vector<ServerListSpec> serverlist;
7676

0 commit comments

Comments
 (0)