diff options
author | vng <viktor.govako@gmail.com> | 2012-06-06 05:09:33 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:39:30 +0300 |
commit | 74a22a60ada2362bc76d7053b52a80346b8590e5 (patch) | |
tree | 82f4d0664e5f4c13fcf6dcb85d847f9cd15db8fc /platform/servers_list.cpp | |
parent | 98efcc314a8b5f1345a58615843f905c4135a39c (diff) |
[downloader] Fix issue when url download failed. Use default server urls.
Diffstat (limited to 'platform/servers_list.cpp')
-rw-r--r-- | platform/servers_list.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/platform/servers_list.cpp b/platform/servers_list.cpp new file mode 100644 index 0000000000..44d326c536 --- /dev/null +++ b/platform/servers_list.cpp @@ -0,0 +1,54 @@ +#include "servers_list.hpp" +#include "http_request.hpp" +#include "settings.hpp" +#include "platform.hpp" + +#include "../base/logging.hpp" +#include "../base/assert.hpp" + +#include "../3party/jansson/myjansson.hpp" + + +#define SETTINGS_SERVERS_KEY "LastBaseUrls" + + +namespace downloader +{ + +bool ParseServerList(string const & jsonStr, vector<string> & outUrls) +{ + outUrls.clear(); + try + { + my::Json root(jsonStr.c_str()); + for (size_t i = 0; i < json_array_size(root); ++i) + { + char const * url = json_string_value(json_array_get(root, i)); + if (url) + outUrls.push_back(url); + } + } + catch (std::exception const & e) + { + LOG(LERROR, ("Can't parse server list json", e.what(), jsonStr)); + } + return !outUrls.empty(); +} + +void GetServerListFromRequest(HttpRequest const & request, vector<string> & urls) +{ + if (request.Status() == HttpRequest::ECompleted && + ParseServerList(request.Data(), urls)) + { + Settings::Set(SETTINGS_SERVERS_KEY, request.Data()); + } + else + { + string serverList; + if (!Settings::Get(SETTINGS_SERVERS_KEY, serverList)) + serverList = GetPlatform().DefaultUrlsJSON(); + VERIFY ( ParseServerList(serverList, urls), () ); + } +} + +} |