From 20202687fb1596d532911bcf7e44d9bf53d69922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=9B=E4=B8=96=E7=BA=AA=E8=BE=B9=E7=BC=98?= Date: Fri, 25 Feb 2022 09:48:34 +0000 Subject: [PATCH 1/2] =?UTF-8?q?Json=20Add=20url=20In=20results=20Descripti?= =?UTF-8?q?on:Json=20Add=20url=20In=20results=20Sig:update=20Feature=20or?= =?UTF-8?q?=20Bugfix:Feature=20Binary=20Source:No=20Signed-off-by:=20?= =?UTF-8?q?=E7=8E=8B=E7=90=AA=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- engine/include/update_service.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/engine/include/update_service.h b/engine/include/update_service.h index 950e3ef6..630f035a 100755 --- a/engine/include/update_service.h +++ b/engine/include/update_service.h @@ -60,8 +60,8 @@ public: int32_t RebootAndClean(const std::string &miscFile, const std::string &cmd) override; int32_t RebootAndInstall(const std::string &miscFile, const std::string &packageName) override; - static int32_t ParseJsonFile(const std::vector &buffer, VersionInfo &info); - static int32_t ReadCheckVersionResult(const cJSON* results, VersionInfo &info); + static int32_t ParseJsonFile(const std::vector &buffer, VersionInfo &info, std::string &url); + static int32_t ReadCheckVersionResult(const cJSON* results, VersionInfo &info, std::string &url); static int32_t ReadCheckVersiondescriptInfo(const cJSON *descriptInfo, VersionInfo &info); #ifndef UPDATER_UT protected: @@ -93,6 +93,7 @@ private: sptr updateCallback_ { nullptr }; DownloadThread *downloadThread_ { nullptr }; UpdateContext updateContext_ {}; + std::string downloadUrl_; }; } } // namespace OHOS -- Gitee From eedeb0af1152a244f77e2536a09bc37d82eaa306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=9B=E4=B8=96=E7=BA=AA=E8=BE=B9=E7=BC=98?= Date: Fri, 25 Feb 2022 09:51:37 +0000 Subject: [PATCH 2/2] =?UTF-8?q?Json=20Add=20url=20In=20results=20Descripti?= =?UTF-8?q?on:Json=20Add=20url=20In=20results=20Sig:update=20Feature=20or?= =?UTF-8?q?=20Bugfix:Feature=20Binary=20Source:No=20Signed-off-by:=20?= =?UTF-8?q?=E7=8E=8B=E7=90=AA=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- engine/src/update_service.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/engine/src/update_service.cpp b/engine/src/update_service.cpp index 3d397c64..109837f7 100644 --- a/engine/src/update_service.cpp +++ b/engine/src/update_service.cpp @@ -297,7 +297,7 @@ void UpdateService::ReadDataFromSSL(int32_t engineSocket) int32_t ret = SSL_connect(ssl); if (ret != -1) { int32_t len = SSL_read(ssl, buffer.data(), JSON_MAX_SIZE); - if (len > 0 && ParseJsonFile(buffer, versionInfo_) == 0) { + if (len > 0 && ParseJsonFile(buffer, versionInfo_, downloadUrl_) == 0) { result = HAS_NEW_VERSION; errMsg = ""; } else { @@ -317,7 +317,7 @@ void UpdateService::ReadDataFromSSL(int32_t engineSocket) return; } -int32_t UpdateService::ParseJsonFile(const std::vector &buffer, VersionInfo &info) +int32_t UpdateService::ParseJsonFile(const std::vector &buffer, VersionInfo &info, std::string &url) { ENGINE_CHECK(buffer.size() > 0, return -1, "JsonFile length must > 0"); cJSON *root = cJSON_Parse(buffer.data()); @@ -333,7 +333,7 @@ int32_t UpdateService::ParseJsonFile(const std::vector &buffer, VersionInf cJSON *results = cJSON_GetObjectItem(root, "checkResults"); ENGINE_CHECK(results != nullptr, cJSON_Delete(root); return -1, "Error get checkResults"); - int32_t ret = ReadCheckVersionResult(results, info); + int32_t ret = ReadCheckVersionResult(results, info, url); ENGINE_CHECK(ret == 0, cJSON_Delete(root); return -1, "Error get checkResults"); cJSON *descriptInfo = cJSON_GetObjectItem(root, "descriptInfo"); @@ -350,7 +350,7 @@ int32_t UpdateService::ParseJsonFile(const std::vector &buffer, VersionInf return 0; } -int32_t UpdateService::ReadCheckVersionResult(const cJSON* results, VersionInfo &info) +int32_t UpdateService::ReadCheckVersionResult(const cJSON* results, VersionInfo &info, std::string &url) { size_t number = cJSON_GetArraySize(results); for (size_t i = 0; i < number && i < sizeof(info.result) / sizeof(info.result[0]); i++) { @@ -377,6 +377,10 @@ int32_t UpdateService::ReadCheckVersionResult(const cJSON* results, VersionInfo ENGINE_CHECK(item != nullptr, return -1, "Error get packageType"); info.result[i].packageType = (PackageType)(item->valueint); + item = cJSON_GetObjectItem(result, "url"); + ENGINE_CHECK(item != nullptr, return -1, "Error get url"); + url = item->valuestring; + item = cJSON_GetObjectItem(result, "descriptPackageId"); ENGINE_CHECK(item != nullptr, return -1, "Error get descriptPackageId"); info.result[i].descriptPackageId = item->valuestring; @@ -430,13 +434,7 @@ bool UpdateService::VerifyDownloadPkg(const std::string &pkgName, Progress &prog std::string UpdateService::GetDownloadServerUrl() const { - std::string serverIp = OHOS::system::GetParameter(PARAM_NAME_FOR_DOWNLOAD, DEFAULT_SERVER_IP); - ENGINE_LOGI("GetDownloadServerUrl serverIp: %s ", serverIp.c_str()); - std::string url = "http://"; - url += serverIp; - url += "/"; - url += versionInfo_.result[0].descriptPackageId; - return url; + return downloadUrl_; } int32_t UpdateService::Cancel(int32_t service) -- Gitee