1 /* 2 * Copyright (C) 2021-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 CONSTANT_H 17 #define CONSTANT_H 18 19 namespace OHOS::Request::Download { 20 enum NetworkType { 21 NETWORK_INVALID = 0x00000000, 22 NETWORK_MOBILE = 0x00000001, 23 NETWORK_WIFI = 0x00010000, 24 NETWORK_MASK = 0x00010001, 25 }; 26 27 enum ErrorCode { 28 ERROR_CANNOT_RESUME, 29 ERROR_DEVICE_NOT_FOUND, 30 ERROR_FILE_ALREADY_EXISTS, 31 ERROR_FILE_ERROR, 32 ERROR_HTTP_DATA_ERROR, 33 ERROR_INSUFFICIENT_SPACE, 34 ERROR_TOO_MANY_REDIRECTS, 35 ERROR_UNHANDLED_HTTP_CODE, 36 ERROR_UNKNOWN, 37 ERROR_OFFLINE, 38 ERROR_UNSUPPORTED_NETWORK_TYPE, 39 }; 40 41 enum PausedReason { 42 PAUSED_QUEUED_FOR_WIFI, 43 PAUSED_WAITING_FOR_NETWORK, 44 PAUSED_WAITING_TO_RETRY, 45 PAUSED_BY_USER, 46 PAUSED_UNKNOWN, 47 }; 48 49 enum DownloadStatus { 50 SESSION_SUCCESS, 51 SESSION_RUNNING, 52 SESSION_PENDING, 53 SESSION_PAUSED, 54 SESSION_FAILED, 55 SESSION_UNKNOWN, 56 }; 57 58 enum HttpErrorCode { 59 HTTP_OK = 200, 60 HTTP_PARIAL_FILE = 206, 61 }; 62 enum ExceptionErrorCode : uint32_t { 63 EXCEPTION_OK = 0, 64 EXCEPTION_PERMISSION = 201, 65 EXCEPTION_PARAMETER_CHECK = 401, 66 EXCEPTION_UNSUPPORTED = 801, 67 EXCEPTION_FILE_IO = 13400001, 68 EXCEPTION_FILE_PATH = 13400002, 69 EXCEPTION_SERVICE_ERROR = 13400003, 70 EXCEPTION_OTHER = 13499999, 71 }; 72 73 struct ExceptionError { 74 ExceptionErrorCode code; 75 std::string errInfo; 76 }; 77 78 const uint32_t DEFAULT_READ_TIMEOUT = 60; 79 const uint32_t DEFAULT_CONNECT_TIMEOUT = 60; 80 const uint32_t HTTP_FORCE_STOP = 1; 81 const uint32_t DEFAULT_LOW_SPEED_LIMIT = 30; 82 83 static constexpr const char *HTTP_METHOD_GET = "GET"; 84 static constexpr const char *HTTP_URL_PARAM_START = "?"; 85 static constexpr const char *HTTP_URL_PARAM_SEPARATOR = "&"; 86 static constexpr const char *HTTP_URL_NAME_VALUE_SEPARATOR = "="; 87 static constexpr const char *HTTP_HEADER_SEPARATOR = ":"; 88 static constexpr const char *HTTP_LINE_SEPARATOR = "\r\n"; 89 90 static constexpr const char *HTTP_DEFAULT_USER_AGENT = "libcurl-agent/1.0"; 91 static constexpr const char *HTTP_DEFAULT_CA_PATH = "/etc/ssl/certs/cacert.pem"; 92 93 static constexpr const char *HTTP_CONTENT_TYPE = "Content-Type"; 94 95 static constexpr const char *EXCEPTION_OK_INFO = "check succeeded"; 96 static constexpr const char *EXCEPTION_PERMISSION_INFO = "the permissions check fails"; 97 static constexpr const char *EXCEPTION_PARAMETER_CHECK_INFO = "the parameters check fails"; 98 static constexpr const char *EXCEPTION_UNSUPPORTED_INFO = "call unsupported api"; 99 static constexpr const char *EXCEPTION_FILE_IO_INFO = " file operation error"; 100 static constexpr const char *EXCEPTION_FILE_PATH_INFO = "bad file path"; 101 static constexpr const char *EXCEPTION_SERVICE_ERROR_INFO = "task service ability error"; 102 static constexpr const char *EXCEPTION_OTHER_INFO = "other error"; 103 104 static constexpr const char *FUNCTION_PAUSE = "pause"; 105 static constexpr const char *FUNCTION_QUERY = "query"; 106 static constexpr const char *FUNCTION_QUERY_MIME_TYPE = "queryMimeType"; 107 static constexpr const char *FUNCTION_REMOVE = "remove"; 108 static constexpr const char *FUNCTION_RESUME = "resume"; 109 110 static constexpr const char *FUNCTION_SUSPEND = "suspend"; 111 static constexpr const char *FUNCTION_GET_TASK_INFO = "getTaskInfo"; 112 static constexpr const char *FUNCTION_GET_TASK_MIME_TYPE = "getTaskMimeType"; 113 static constexpr const char *FUNCTION_DELETE = "delete"; 114 static constexpr const char *FUNCTION_RESTORE = "restore"; 115 116 static const std::string tlsVersion = "X-TLS-Version"; 117 static const std::string cipherList = "X-Cipher-List"; 118 static const std::string TLS_VERSION = "CURL_SSLVERSION_TLSv1_2"; 119 static const std::string TLS_CIPHER = "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384," 120 "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256,TLS_DSS_RSA_WITH_AES_256_GCM_SHA384," 121 "TLS_PSK_WITH_AES_256_GCM_SHA384,TLS_DHE_PSK_WITH_AES_128_GCM_SHA256," 122 "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384," 123 "TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256," 124 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256," 125 "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384," 126 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384," 127 "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256," 128 "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256," 129 "TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256,TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384," 130 "TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256," 131 "TLS_DHE_RSA_WITH_AES_128_CCM,TLS_DHE_RSA_WITH_AES_256_CCM," 132 "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256,TLS_PSK_WITH_AES_256_CCM," 133 "TLS_DHE_PSK_WITH_AES_128_CCM,TLS_DHE_PSK_WITH_AES_256_CCM," 134 "TLS_ECDHE_ECDSA_WITH_AES_128_CCM,TLS_ECDHE_ECDSA_WITH_AES_256_CCM," 135 "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,TLS_AES_128_GCM_SHA256," 136 "TLS_AES_256_GCM_SHA384,TLS_CHACHA20_POLY1305_SHA256,TLS_AES_128_CCM_SHA256," 137 "TLS_SM4_GCM_SM3,TLS_SM4_CCM_SM3"; 138 139 static constexpr int RDB_EXECUTE_OK = 0; 140 static constexpr int RDB_EXECUTE_FAIL = -1; 141 static constexpr int OPERATION_OK = 0; 142 static constexpr int OPERATION_ERROR = -1; 143 144 static constexpr int RDB_OBJECT_EMPTY = -1; 145 static constexpr int PARAMETER_EMPTY = -1; 146 147 static constexpr int TRANSACTION_COUNT = 100; 148 149 constexpr int DOWNLOAD_INFO = 10000; 150 151 constexpr int REQUEST_PARAMS_NUM = 2; 152 constexpr size_t MIN_HEADER_LENGTH = sizeof(std::string) * 2; 153 154 static constexpr const char *EVENT_PROGRESS = "progress"; 155 static constexpr const char *EVENT_COMPLETE = "complete"; 156 static constexpr const char *EVENT_FAIL = "fail"; 157 static constexpr size_t ASYNC_DEFAULT_POS = -1; 158 } // namespace OHOS::Request::Download 159 160 #endif // CONSTANT_H 161