Remove ugly curl struct pointer from jsonFetchValue signature

This commit is contained in:
sapier 2014-06-19 20:58:22 +02:00
parent 9a39848ba9
commit 8af44f8163
6 changed files with 25 additions and 39 deletions

View 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) {

View 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

View 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 */
/******************************************************************************/

View File

@ -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

View 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

View 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;