1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef DOWNLOAD_INFO_H
17 #define DOWNLOAD_INFO_H
18 
19 #include <cstdio>
20 #include <map>
21 #include <string>
22 
23 #include "anonymous_utils.h"
24 
25 namespace OHOS {
26 namespace UpdateEngine {
27 struct DownloadInfo {
28 public:
29     DownloadInfo() = default;
30     ~DownloadInfo() = default;
31 
32     int32_t id;
33     std::string downloadId;
34     std::string versionId;
35     std::string taskId;
36     std::string url;
37     std::string reserveUrl;
38     std::string path;
39     std::string veriftInfo;
40     std::map<std::string, std::string> header;
41     std::string requestBody;
42     int32_t retryTimes = 0;
43     int64_t packageSize = 0;
44     int64_t downloadedSize = 0;
45     bool isNeedAutoResume = false;
46 
47     bool operator<(const DownloadInfo &downloadInfo) const
48     {
49         if (downloadId < downloadInfo.downloadId)
50             return true;
51         if (downloadId > downloadInfo.downloadId)
52             return false;
53         return false;
54     }
55 
ToStringDownloadInfo56     std::string ToString()
57     {
58         return std::string("DownloadInfo: ")
59         .append("id=").append(std::to_string(id)).append(",")
60         .append("taskId=").append(taskId).append(",")
61         .append("url=").append(AnonymousUtils::AnonymousUrl(url)).append(",")
62         .append("path=").append(path).append(",")
63         .append("veriftInfo=").append(veriftInfo).append(",")
64         .append("retryTimes=").append(std::to_string(retryTimes)).append(",")
65         .append("packageSize=").append(std::to_string(packageSize)).append(",")
66         .append("downloadedSize=").append(std::to_string(downloadedSize))
67         .append("isNeedAutoResume=").append(std::to_string(isNeedAutoResume));
68     }
69 };
70 } // namespace UpdateEngine
71 } // namespace OHOS
72 #endif // DOWNLOAD_INFO_H
73