1 /*
2 * Copyright (C) 2023 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 #include "mms_network_client.h"
17
18 #include <curl/curl.h>
19 #include <curl/easy.h>
20
21 #include "core_manager_inner.h"
22 #include "http_client.h"
23 #include "http_client_constant.h"
24 #include "http_client_error.h"
25 #include "http_client_request.h"
26 #include "http_client_response.h"
27 #include "mms_apn_info.h"
28 #include "mms_persist_helper.h"
29 #include "net_conn_client.h"
30 #include "net_handle.h"
31 #include "net_link_info.h"
32 #include "securec.h"
33 #include "sms_constants_utils.h"
34 #include "telephony_common_utils.h"
35 #include "telephony_errors.h"
36 #include "telephony_log_wrapper.h"
37 #include "string_utils.h"
38 #include "mms_codec_type.h"
39
40 namespace OHOS {
41 namespace Telephony {
42 using namespace NetManagerStandard;
43 using namespace NetStack::HttpClient;
44 std::string METHOD_POST = "POST";
45 std::string METHOD_GET = "GET";
46 constexpr const char *SIMID_IDENT_PREFIX = "simId";
47 const bool STORE_MMS_PDU_TO_FILE = false;
48 constexpr static const int32_t WAIT_TIME_SECOND = 10 * 60;
49 constexpr static const unsigned int HTTP_TIME_MICRO_SECOND = WAIT_TIME_SECOND * 1000;
50 constexpr static const uint8_t SEND_CONF_RESPONSE_STATUS_OK = 0x80;
51 constexpr static const uint32_t SEND_CONF_MAX_SIZE = 500;
52 constexpr static const uint8_t MAX_RETRY_TIMES = 3;
53 constexpr static const int32_t ONE_HUNDRED = 100;
54 constexpr static const int32_t VALID_RESPONSECODE_FIRST_NUM = 2;
55
56
MmsNetworkClient(int32_t slotId)57 MmsNetworkClient::MmsNetworkClient(int32_t slotId)
58 {
59 slotId_ = slotId;
60 }
61
~MmsNetworkClient()62 MmsNetworkClient::~MmsNetworkClient() {}
63
Execute(const std::string & method,const std::string & mmsc,std::string & data,const std::string & ua,const std::string & uaprof)64 int32_t MmsNetworkClient::Execute(const std::string &method, const std::string &mmsc, std::string &data,
65 const std::string &ua, const std::string &uaprof)
66 {
67 int32_t ret = TELEPHONY_ERR_FAIL;
68 if (METHOD_POST.compare(method) == 0) {
69 ret = PostUrl(mmsc, data, ua, uaprof);
70 std::unique_lock<std::mutex> lck(clientCts_);
71 responseData_ = "";
72 return ret;
73 } else if (METHOD_GET.compare(method) == 0) {
74 ret = GetUrl(mmsc, data, ua, uaprof);
75 std::unique_lock<std::mutex> lck(clientCts_);
76 responseData_ = "";
77 return ret;
78 }
79 TELEPHONY_LOGI("mms http request fail");
80 return ret;
81 }
82
GetMmscFromDb(const std::string & mmsc)83 int32_t MmsNetworkClient::GetMmscFromDb(const std::string &mmsc)
84 {
85 std::shared_ptr<MmsApnInfo> mmsApnInfo = std::make_shared<MmsApnInfo>(slotId_);
86 if (mmsApnInfo == nullptr) {
87 TELEPHONY_LOGE("mmsApnInfo is nullptr");
88 return TELEPHONY_ERR_MMS_FAIL_APN_INVALID;
89 }
90 std::string mmscFromDataBase = mmsApnInfo->getMmscUrl();
91 if (mmsc != mmscFromDataBase) {
92 TELEPHONY_LOGE("mmsc is invalid");
93 return TELEPHONY_ERR_ARGUMENT_INVALID;
94 }
95
96 return TELEPHONY_SUCCESS;
97 }
98
GetMmsDataBuf(std::string & strBuf,const std::string & fileName)99 int32_t MmsNetworkClient::GetMmsDataBuf(std::string &strBuf, const std::string &fileName)
100 {
101 if (STORE_MMS_PDU_TO_FILE) {
102 if (!GetMmsPduFromFile(fileName, strBuf)) {
103 TELEPHONY_LOGE("Get MmsPdu from file fail");
104 return TELEPHONY_ERR_READ_DATA_FAIL;
105 }
106 } else {
107 if (!GetMmsPduFromDataBase(fileName, strBuf)) {
108 TELEPHONY_LOGE("Get MmsPdu from data base fail");
109 return TELEPHONY_ERR_DATABASE_READ_FAIL;
110 }
111 }
112 return TELEPHONY_SUCCESS;
113 }
114
GetMmsApnPorxy(NetStack::HttpClient::HttpProxy & httpProxy)115 int32_t MmsNetworkClient::GetMmsApnPorxy(NetStack::HttpClient::HttpProxy &httpProxy)
116 {
117 std::shared_ptr<MmsApnInfo> mmsApnInfo = std::make_shared<MmsApnInfo>(slotId_);
118 if (mmsApnInfo == nullptr) {
119 TELEPHONY_LOGE("mmsApnInfo is nullptr");
120 return TELEPHONY_ERR_MMS_FAIL_APN_INVALID;
121 }
122 std::string proxy = mmsApnInfo->getMmsProxyAddressAndProxyPort();
123 if (proxy.empty()) {
124 TELEPHONY_LOGE("proxy empty");
125 return TELEPHONY_ERR_MMS_FAIL_APN_INVALID;
126 }
127 size_t locate = proxy.find(":");
128 if (locate == 0 || locate == std::string::npos || static_cast<size_t>(locate + 1) == proxy.size()) {
129 TELEPHONY_LOGE("mms apn error");
130 return TELEPHONY_ERR_MMS_FAIL_APN_INVALID;
131 }
132
133 httpProxy.host = proxy.substr(0, locate);
134 std::string port = proxy.substr(locate + 1);
135 if (!IsValidDecValue(port)) {
136 TELEPHONY_LOGE("port not decimal");
137 return TELEPHONY_ERR_MMS_FAIL_APN_INVALID;
138 }
139 httpProxy.port = std::stoi(port);
140 return TELEPHONY_SUCCESS;
141 }
142
PostUrl(const std::string & mmsc,const std::string & fileName,const std::string & ua,const std::string & uaprof)143 int32_t MmsNetworkClient::PostUrl(const std::string &mmsc, const std::string &fileName, const std::string &ua,
144 const std::string &uaprof)
145 {
146 int32_t ret = GetMmscFromDb(mmsc);
147 if (ret != TELEPHONY_SUCCESS) {
148 TELEPHONY_LOGE("post request fail");
149 return ret;
150 }
151 std::unique_lock<std::mutex> lck(clientCts_);
152 std::string strBuf;
153 ret = GetMmsDataBuf(strBuf, fileName);
154 if (ret != TELEPHONY_SUCCESS) {
155 TELEPHONY_LOGE("post request fail");
156 return ret;
157 }
158 for (retryTimes_ = 0; retryTimes_ <= MAX_RETRY_TIMES; retryTimes_++) {
159 ret = HttpRequest(METHOD_POST, mmsc, strBuf, ua, uaprof);
160 if (ret != TELEPHONY_ERR_SUCCESS) {
161 TELEPHONY_LOGE("http fail error");
162 return ret;
163 }
164 httpFinish_ = false;
165 httpSuccess_ = false;
166 while (!httpFinish_) {
167 TELEPHONY_LOGI("wait(), networkReady = false");
168 if (clientCv_.wait_for(lck, std::chrono::seconds(WAIT_TIME_SECOND)) == std::cv_status::timeout) {
169 TELEPHONY_LOGE("wait networkready timeout");
170 return TELEPHONY_ERR_MMS_FAIL_HTTP_ERROR;
171 }
172 }
173 if (!httpSuccess_ || responseCode_ / ONE_HUNDRED != VALID_RESPONSECODE_FIRST_NUM) {
174 TELEPHONY_LOGE("http post task is not success, task responseCode is %{public}d", responseCode_);
175 responseData_ = "";
176 responseCode_ = 0;
177 continue;
178 }
179 if (!CheckSendConf()) {
180 TELEPHONY_LOGE("send mms failed due to send-conf decode fail");
181 responseData_ = "";
182 continue;
183 }
184 break;
185 }
186 if (!STORE_MMS_PDU_TO_FILE) {
187 DeleteMmsPdu(fileName);
188 }
189 if (retryTimes_ > MAX_RETRY_TIMES) {
190 TELEPHONY_LOGE("send mms retry times over 3, send mms failed");
191 return TELEPHONY_ERR_MMS_FAIL_HTTP_ERROR;
192 }
193 return TELEPHONY_ERR_SUCCESS;
194 }
195
CheckSendConf()196 bool MmsNetworkClient::CheckSendConf()
197 {
198 uint32_t length = responseData_.size();
199 if (length > SEND_CONF_MAX_SIZE || length == 0) {
200 TELEPHONY_LOGE("send mms response length invalid");
201 return true;
202 }
203 std::unique_ptr<char[]> sendMmsResponse = std::make_unique<char[]>(length);
204 if (memset_s(sendMmsResponse.get(), length, 0x00, length) != EOK) {
205 TELEPHONY_LOGE("memset_s error");
206 return true;
207 }
208 if (memcpy_s(sendMmsResponse.get(), length, &responseData_[0], length) != EOK) {
209 TELEPHONY_LOGE("memcpy_s error");
210 return true;
211 }
212 MmsDecodeBuffer sendMmsResponseBuffer;
213 if (!sendMmsResponseBuffer.WriteDataBuffer(std::move(sendMmsResponse), length)) {
214 TELEPHONY_LOGE("write buffer error");
215 return true;
216 }
217 if (!mmsHeader_.DecodeMmsHeader(sendMmsResponseBuffer)) {
218 TELEPHONY_LOGE("decode send mms response error");
219 return true;
220 }
221 uint8_t value = 0;
222 if (!mmsHeader_.GetOctetValue(MmsFieldCode::MMS_RESPONSE_STATUS, value)) {
223 TELEPHONY_LOGE("get response status error");
224 return true;
225 }
226 if (value != SEND_CONF_RESPONSE_STATUS_OK) {
227 TELEPHONY_LOGE("sendconf response status is not OK, the value is %{public}02X", value);
228 return false;
229 }
230 return true;
231 }
232
GetCoverUrl(std::string str)233 void MmsNetworkClient::GetCoverUrl(std::string str)
234 {
235 if (str.size() == 0) {
236 TELEPHONY_LOGI("url is empty");
237 return;
238 }
239 int32_t stride = 2;
240 for (uint8_t i = 0; i < str.size(); i = i + stride) {
241 str[i] = '*';
242 }
243 TELEPHONY_LOGI("decode result is: %{public}s", str.c_str());
244 }
245
HttpRequest(const std::string & method,const std::string & url,const std::string & data,const std::string & ua,const std::string & uaprof)246 int32_t MmsNetworkClient::HttpRequest(const std::string &method, const std::string &url, const std::string &data,
247 const std::string &ua, const std::string &uaprof)
248 {
249 HttpClientRequest httpReq;
250 httpReq.SetURL(url);
251 NetStack::HttpClient::HttpProxy httpProxy;
252 int32_t ret = GetMmsApnPorxy(httpProxy);
253 if (ret == TELEPHONY_SUCCESS) {
254 httpReq.SetHttpProxyType(HttpProxyType::USE_SPECIFIED);
255 httpReq.SetHttpProxy(httpProxy);
256 } else {
257 TELEPHONY_LOGE("get mms apn error");
258 }
259 httpReq.SetConnectTimeout(HTTP_TIME_MICRO_SECOND);
260 httpReq.SetTimeout(HTTP_TIME_MICRO_SECOND);
261 if (method.compare(METHOD_POST) == 0) {
262 httpReq.SetBody(data.c_str(), data.size());
263 httpReq.SetMethod(HttpConstant::HTTP_METHOD_POST);
264 httpReq.SetHeader("content-type", "application/vnd.wap.mms-message");
265 } else {
266 httpReq.SetMethod(HttpConstant::HTTP_METHOD_GET);
267 }
268 httpReq.SetHeader("User-Agent", ua);
269 httpReq.SetHeader("x-wap-profile", uaprof);
270 httpReq.SetHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
271 std::string host = StringUtils::GetHostnameWithPortFromURL(url);
272 httpReq.SetHeader("Host", host);
273
274 HttpSession &session = HttpSession::GetInstance();
275 auto task = session.CreateTask(httpReq);
276 if (task == nullptr || task->GetCurlHandle() == nullptr) {
277 TELEPHONY_LOGE("task nullptr error");
278 return TELEPHONY_ERR_MMS_FAIL_HTTP_ERROR;
279 }
280
281 if (GetIfaceName().empty()) {
282 TELEPHONY_LOGE("Ifacename empty");
283 return TELEPHONY_ERR_MMS_FAIL_HTTP_ERROR;
284 }
285 CURLcode errCode = CURLE_OK;
286 errCode = curl_easy_setopt(task->GetCurlHandle(), CURLOPT_INTERFACE, GetIfaceName().c_str());
287 if (errCode != CURLE_OK) {
288 TELEPHONY_LOGE("CURLOPT_INTERFACE failed errCode:%{public}d", errCode);
289 return TELEPHONY_ERR_MMS_FAIL_HTTP_ERROR;
290 }
291 errCode = curl_easy_setopt(task->GetCurlHandle(), CURLOPT_MMS_RESERVED_DEFAULT_PORT, 1L);
292 if (errCode != CURLE_OK) {
293 TELEPHONY_LOGE("CURLOPT_MMS_RESERVED_DEFAULT_PORT failed errCode:%{public}d", errCode);
294 }
295
296 HttpCallBack(task);
297 task->Start();
298 return TELEPHONY_ERR_SUCCESS;
299 }
300
GetUrl(const std::string & mmsc,std::string & storeDirName,const std::string & ua,const std::string & uaprof)301 int32_t MmsNetworkClient::GetUrl(const std::string &mmsc, std::string &storeDirName, const std::string &ua,
302 const std::string &uaprof)
303 {
304 std::unique_lock<std::mutex> lck(clientCts_);
305 for (retryTimes_ = 0; retryTimes_ <= MAX_RETRY_TIMES; retryTimes_++) {
306 std::string strData = "";
307 if (HttpRequest(METHOD_GET, mmsc, strData, ua, uaprof) != TELEPHONY_ERR_SUCCESS) {
308 TELEPHONY_LOGE("http fail error");
309 return TELEPHONY_ERR_MMS_FAIL_HTTP_ERROR;
310 }
311 httpFinish_ = false;
312 httpSuccess_ = false;
313 while (!httpFinish_) {
314 TELEPHONY_LOGI("wait(), networkReady = false");
315 if (clientCv_.wait_for(lck, std::chrono::seconds(WAIT_TIME_SECOND)) == std::cv_status::timeout) {
316 TELEPHONY_LOGE("wait networkready timeout");
317 return TELEPHONY_ERR_MMS_FAIL_HTTP_ERROR;
318 }
319 }
320 if (!httpSuccess_) {
321 TELEPHONY_LOGE("http get task is not success");
322 responseData_ = "";
323 responseCode_ = 0;
324 continue;
325 }
326 if (responseCode_ / ONE_HUNDRED != VALID_RESPONSECODE_FIRST_NUM) {
327 TELEPHONY_LOGE("get task responseCode is not success:%{public}d", responseCode_);
328 responseData_ = "";
329 responseCode_ = 0;
330 continue;
331 }
332 break;
333 }
334 if (retryTimes_ > MAX_RETRY_TIMES) {
335 TELEPHONY_LOGE("download mms retry times over 3, download mms failed");
336 return TELEPHONY_ERR_MMS_FAIL_HTTP_ERROR;
337 }
338 TELEPHONY_LOGI("responseData_ len: %{public}d", static_cast<uint32_t>(responseData_.size()));
339 if (responseData_.size() == 0) {
340 GetCoverUrl(mmsc);
341 }
342 return UpdateMmsPduToStorage(storeDirName);
343 }
344
UpdateMmsPduToStorage(std::string & storeDirName)345 int32_t MmsNetworkClient::UpdateMmsPduToStorage(std::string &storeDirName)
346 {
347 uint32_t len = responseData_.size();
348 if (len > MMS_PDU_MAX_SIZE || len == 0) {
349 TELEPHONY_LOGE("MMS pdu length invalid");
350 return TELEPHONY_ERR_LOCAL_PTR_NULL;
351 }
352 if (STORE_MMS_PDU_TO_FILE) {
353 std::unique_ptr<char[]> resultResponse = std::make_unique<char[]>(len);
354 if (memset_s(resultResponse.get(), len, 0x00, len) != EOK) {
355 TELEPHONY_LOGE("memset_s error");
356 return TELEPHONY_ERR_MEMSET_FAIL;
357 }
358 if (memcpy_s(resultResponse.get(), len, &responseData_[0], len) != EOK) {
359 TELEPHONY_LOGE("memcpy_s error");
360 return TELEPHONY_ERR_MEMCPY_FAIL;
361 }
362 if (!WriteBufferToFile(std::move(resultResponse), len, storeDirName)) {
363 TELEPHONY_LOGE("write to file error");
364 return TELEPHONY_ERR_WRITE_DATA_FAIL;
365 }
366 return TELEPHONY_ERR_SUCCESS;
367 } else {
368 std::shared_ptr<MmsPersistHelper> mmsPduObj = std::make_shared<MmsPersistHelper>();
369 if (mmsPduObj == nullptr) {
370 TELEPHONY_LOGE("mmsPduObj nullptr");
371 return TELEPHONY_ERR_LOCAL_PTR_NULL;
372 }
373 bool ret = mmsPduObj->InsertMmsPdu(responseData_, storeDirName);
374 TELEPHONY_LOGI("ret:%{public}d, length:%{public}d", ret, len);
375 return ret ? TELEPHONY_ERR_SUCCESS : TELEPHONY_ERR_FAIL;
376 }
377 }
378
GetMmsPduFromFile(const std::string & fileName,std::string & strBuf)379 bool MmsNetworkClient::GetMmsPduFromFile(const std::string &fileName, std::string &strBuf)
380 {
381 FILE *pFile = nullptr;
382 char realPath[PATH_MAX] = { 0 };
383 if (fileName.empty() || realpath(fileName.c_str(), realPath) == nullptr) {
384 TELEPHONY_LOGE("path or realPath is nullptr");
385 return false;
386 }
387
388 pFile = fopen(realPath, "rb");
389 if (pFile == nullptr) {
390 TELEPHONY_LOGE("openFile Error");
391 return false;
392 }
393
394 (void)fseek(pFile, 0, SEEK_END);
395 long fileLen = ftell(pFile);
396 if (fileLen <= 0 || fileLen > static_cast<long>(MMS_PDU_MAX_SIZE)) {
397 (void)fclose(pFile);
398 TELEPHONY_LOGE("Mms Over Long Error");
399 return false;
400 }
401
402 std::unique_ptr<char[]> pduBuffer = std::make_unique<char[]>(fileLen);
403 if (!pduBuffer) {
404 (void)fclose(pFile);
405 TELEPHONY_LOGE("make unique pduBuffer nullptr Error");
406 return false;
407 }
408 (void)fseek(pFile, 0, SEEK_SET);
409 int32_t totolLength = static_cast<int32_t>(fread(pduBuffer.get(), 1, MMS_PDU_MAX_SIZE, pFile));
410 TELEPHONY_LOGI("sendMms totolLength:%{public}d", totolLength);
411 (void)fclose(pFile);
412
413 long i = 0;
414 while (i < fileLen) {
415 strBuf += pduBuffer[i];
416 i++;
417 }
418 return true;
419 }
420
GetMmsPduFromDataBase(const std::string & dbUrl,std::string & strBuf)421 bool MmsNetworkClient::GetMmsPduFromDataBase(const std::string &dbUrl, std::string &strBuf)
422 {
423 if (dbUrl.empty()) {
424 TELEPHONY_LOGE("dbUrl is empty");
425 return false;
426 }
427 std::shared_ptr<MmsPersistHelper> mmsPdu = std::make_shared<MmsPersistHelper>();
428 if (mmsPdu == nullptr) {
429 TELEPHONY_LOGE("mmsPdu nullptr");
430 return false;
431 }
432 strBuf = mmsPdu->GetMmsPdu(dbUrl);
433 if (strBuf.empty()) {
434 TELEPHONY_LOGE("strBuf is empty");
435 return false;
436 }
437 return true;
438 }
439
DeleteMmsPdu(const std::string & dbUrl)440 void MmsNetworkClient::DeleteMmsPdu(const std::string &dbUrl)
441 {
442 std::shared_ptr<MmsPersistHelper> mmsPdu = std::make_shared<MmsPersistHelper>();
443 if (mmsPdu == nullptr) {
444 TELEPHONY_LOGE("mmsPdu is nullptr");
445 return;
446 }
447 mmsPdu->DeleteMmsPdu(dbUrl);
448 }
449
GetIfaceName()450 std::string MmsNetworkClient::GetIfaceName()
451 {
452 int32_t simId = CoreManagerInner::GetInstance().GetSimId(slotId_);
453 std::list<int32_t> netIdList;
454 int32_t ret =
455 NetConnClient::GetInstance().GetNetIdByIdentifier(SIMID_IDENT_PREFIX + std::to_string(simId), netIdList);
456 std::string ifaceName;
457 if (ret != NETMANAGER_SUCCESS) {
458 TELEPHONY_LOGE("get netIdList by identifier fail, ret = %{public}d", ret);
459 return ifaceName;
460 }
461 std::list<sptr<NetHandle>> netList;
462 int32_t result = NetConnClient::GetInstance().GetAllNets(netList);
463 if (result != NETMANAGER_SUCCESS) {
464 TELEPHONY_LOGE("get all nets fail, ret = %{public}d", result);
465 return ifaceName;
466 }
467 for (sptr<NetHandle> netHandle : netList) {
468 for (auto netId : netIdList) {
469 if (netId != netHandle->GetNetId()) {
470 continue;
471 }
472 NetAllCapabilities capabilities;
473 NetConnClient::GetInstance().GetNetCapabilities(*netHandle, capabilities);
474 auto search = capabilities.netCaps_.find(NetCap::NET_CAPABILITY_MMS);
475 if (search == capabilities.netCaps_.end()) {
476 continue;
477 }
478 NetLinkInfo info;
479 NetConnClient::GetInstance().GetConnectionProperties(*netHandle, info);
480 ifaceName = info.ifaceName_;
481 TELEPHONY_LOGI("data is connected ifaceName = %{public}s", ifaceName.c_str());
482 return ifaceName;
483 }
484 }
485 TELEPHONY_LOGI("slot = %{public}d data is not connected for this slot", slotId_);
486 return ifaceName;
487 }
488
WriteBufferToFile(const std::unique_ptr<char[]> & buff,uint32_t len,std::string & strPathName) const489 bool MmsNetworkClient::WriteBufferToFile(
490 const std::unique_ptr<char[]> &buff, uint32_t len, std::string &strPathName) const
491 {
492 if (buff == nullptr) {
493 TELEPHONY_LOGE("buff nullptr");
494 return false;
495 }
496 char realPath[PATH_MAX] = { 0 };
497 if (strPathName.empty() || realpath(strPathName.c_str(), realPath) == nullptr) {
498 TELEPHONY_LOGE("path or realPath is nullptr");
499 return false;
500 }
501 FILE *pFile = nullptr;
502 pFile = fopen(realPath, "wb");
503 if (!pFile) {
504 TELEPHONY_LOGE("open file fail");
505 return false;
506 }
507 uint32_t fileLen = fwrite(buff.get(), len, 1, pFile);
508 if (fileLen == 0) {
509 TELEPHONY_LOGI("write mms buffer to file error");
510 (void)fclose(pFile);
511 return false;
512 }
513 (void)fclose(pFile);
514 return true;
515 }
516
HttpCallBack(std::shared_ptr<HttpClientTask> task)517 void MmsNetworkClient::HttpCallBack(std::shared_ptr<HttpClientTask> task)
518 {
519 task->OnSuccess([task, this](const HttpClientRequest &request, const HttpClientResponse &response) {
520 TELEPHONY_LOGI("OnSuccess");
521 httpFinish_ = true;
522 httpSuccess_ = true;
523 responseCode_ = response.GetResponseCode();
524 clientCv_.notify_one();
525 });
526 task->OnCancel([this](const HttpClientRequest &request, const HttpClientResponse &response) {
527 TELEPHONY_LOGI("OnCancel, responseCode:%{public}d", response.GetResponseCode());
528 httpFinish_ = true;
529 clientCv_.notify_one();
530 });
531 task->OnFail(
532 [this](const HttpClientRequest &request, const HttpClientResponse &response, const HttpClientError &error) {
533 TELEPHONY_LOGE("OnFailed, errorCode:%{public}d", error.GetErrorCode());
534 httpFinish_ = true;
535 clientCv_.notify_one();
536 });
537 task->OnDataReceive([this](const HttpClientRequest &request, const uint8_t *data, size_t length) {
538 if (data == nullptr || length == 0) {
539 return;
540 }
541 responseData_.insert(responseData_.size(), reinterpret_cast<const char *>(data), length);
542 });
543 task->OnProgress(
544 [](const HttpClientRequest &request, u_long dltotal, u_long dlnow, u_long ultotal, u_long ulnow) {});
545 }
546 } // namespace Telephony
547 } // namespace OHOS
548