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; charset=utf-8");
265 httpReq.SetHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
266 } else {
267 httpReq.SetMethod(HttpConstant::HTTP_METHOD_GET);
268 }
269 httpReq.SetHeader("User-Agent", ua);
270 httpReq.SetHeader("x-wap-profile", uaprof);
271 HttpSession &session = HttpSession::GetInstance();
272 auto task = session.CreateTask(httpReq);
273 if (task == nullptr || task->GetCurlHandle() == nullptr) {
274 TELEPHONY_LOGE("task nullptr error");
275 return TELEPHONY_ERR_MMS_FAIL_HTTP_ERROR;
276 }
277
278 if (GetIfaceName().empty()) {
279 TELEPHONY_LOGE("Ifacename empty");
280 return TELEPHONY_ERR_MMS_FAIL_HTTP_ERROR;
281 }
282 CURLcode errCode = CURLE_OK;
283 errCode = curl_easy_setopt(task->GetCurlHandle(), CURLOPT_INTERFACE, GetIfaceName().c_str());
284 if (errCode != CURLE_OK) {
285 TELEPHONY_LOGE("CURLOPT_INTERFACE failed errCode:%{public}d", errCode);
286 return TELEPHONY_ERR_MMS_FAIL_HTTP_ERROR;
287 }
288 HttpCallBack(task);
289 task->Start();
290 return TELEPHONY_ERR_SUCCESS;
291 }
292
GetUrl(const std::string & mmsc,std::string & storeDirName,const std::string & ua,const std::string & uaprof)293 int32_t MmsNetworkClient::GetUrl(const std::string &mmsc, std::string &storeDirName, const std::string &ua,
294 const std::string &uaprof)
295 {
296 std::unique_lock<std::mutex> lck(clientCts_);
297 for (retryTimes_ = 0; retryTimes_ <= MAX_RETRY_TIMES; retryTimes_++) {
298 std::string strData = "";
299 if (HttpRequest(METHOD_GET, mmsc, strData, ua, uaprof) != TELEPHONY_ERR_SUCCESS) {
300 TELEPHONY_LOGE("http fail error");
301 return TELEPHONY_ERR_MMS_FAIL_HTTP_ERROR;
302 }
303 httpFinish_ = false;
304 httpSuccess_ = false;
305 while (!httpFinish_) {
306 TELEPHONY_LOGI("wait(), networkReady = false");
307 if (clientCv_.wait_for(lck, std::chrono::seconds(WAIT_TIME_SECOND)) == std::cv_status::timeout) {
308 TELEPHONY_LOGE("wait networkready timeout");
309 return TELEPHONY_ERR_MMS_FAIL_HTTP_ERROR;
310 }
311 }
312 if (!httpSuccess_) {
313 TELEPHONY_LOGE("http get task is not success");
314 responseData_ = "";
315 responseCode_ = 0;
316 continue;
317 }
318 if (responseCode_ / ONE_HUNDRED != VALID_RESPONSECODE_FIRST_NUM) {
319 TELEPHONY_LOGE("get task responseCode is not success:%{public}d", responseCode_);
320 responseData_ = "";
321 responseCode_ = 0;
322 continue;
323 }
324 break;
325 }
326 if (retryTimes_ > MAX_RETRY_TIMES) {
327 TELEPHONY_LOGE("download mms retry times over 3, download mms failed");
328 return TELEPHONY_ERR_MMS_FAIL_HTTP_ERROR;
329 }
330 TELEPHONY_LOGI("responseData_ len: %{public}d", static_cast<uint32_t>(responseData_.size()));
331 if (responseData_.size() == 0) {
332 GetCoverUrl(mmsc);
333 }
334 return UpdateMmsPduToStorage(storeDirName);
335 }
336
UpdateMmsPduToStorage(std::string & storeDirName)337 int32_t MmsNetworkClient::UpdateMmsPduToStorage(std::string &storeDirName)
338 {
339 uint32_t len = responseData_.size();
340 if (len > MMS_PDU_MAX_SIZE || len == 0) {
341 TELEPHONY_LOGE("MMS pdu length invalid");
342 return TELEPHONY_ERR_LOCAL_PTR_NULL;
343 }
344 if (STORE_MMS_PDU_TO_FILE) {
345 std::unique_ptr<char[]> resultResponse = std::make_unique<char[]>(len);
346 if (memset_s(resultResponse.get(), len, 0x00, len) != EOK) {
347 TELEPHONY_LOGE("memset_s error");
348 return TELEPHONY_ERR_MEMSET_FAIL;
349 }
350 if (memcpy_s(resultResponse.get(), len, &responseData_[0], len) != EOK) {
351 TELEPHONY_LOGE("memcpy_s error");
352 return TELEPHONY_ERR_MEMCPY_FAIL;
353 }
354 if (!WriteBufferToFile(std::move(resultResponse), len, storeDirName)) {
355 TELEPHONY_LOGE("write to file error");
356 return TELEPHONY_ERR_WRITE_DATA_FAIL;
357 }
358 return TELEPHONY_ERR_SUCCESS;
359 } else {
360 std::shared_ptr<MmsPersistHelper> mmsPduObj = std::make_shared<MmsPersistHelper>();
361 if (mmsPduObj == nullptr) {
362 TELEPHONY_LOGE("mmsPduObj nullptr");
363 return TELEPHONY_ERR_LOCAL_PTR_NULL;
364 }
365 bool ret = mmsPduObj->InsertMmsPdu(responseData_, storeDirName);
366 TELEPHONY_LOGI("ret:%{public}d, length:%{public}d", ret, len);
367 return ret ? TELEPHONY_ERR_SUCCESS : TELEPHONY_ERR_FAIL;
368 }
369 }
370
GetMmsPduFromFile(const std::string & fileName,std::string & strBuf)371 bool MmsNetworkClient::GetMmsPduFromFile(const std::string &fileName, std::string &strBuf)
372 {
373 FILE *pFile = nullptr;
374 char realPath[PATH_MAX] = { 0 };
375 if (fileName.empty() || realpath(fileName.c_str(), realPath) == nullptr) {
376 TELEPHONY_LOGE("path or realPath is nullptr");
377 return false;
378 }
379
380 pFile = fopen(realPath, "rb");
381 if (pFile == nullptr) {
382 TELEPHONY_LOGE("openFile Error");
383 return false;
384 }
385
386 (void)fseek(pFile, 0, SEEK_END);
387 long fileLen = ftell(pFile);
388 if (fileLen <= 0 || fileLen > static_cast<long>(MMS_PDU_MAX_SIZE)) {
389 (void)fclose(pFile);
390 TELEPHONY_LOGE("Mms Over Long Error");
391 return false;
392 }
393
394 std::unique_ptr<char[]> pduBuffer = std::make_unique<char[]>(fileLen);
395 if (!pduBuffer) {
396 (void)fclose(pFile);
397 TELEPHONY_LOGE("make unique pduBuffer nullptr Error");
398 return false;
399 }
400 (void)fseek(pFile, 0, SEEK_SET);
401 int32_t totolLength = static_cast<int32_t>(fread(pduBuffer.get(), 1, MMS_PDU_MAX_SIZE, pFile));
402 TELEPHONY_LOGI("sendMms totolLength:%{public}d", totolLength);
403 (void)fclose(pFile);
404
405 long i = 0;
406 while (i < fileLen) {
407 strBuf += pduBuffer[i];
408 i++;
409 }
410 return true;
411 }
412
GetMmsPduFromDataBase(const std::string & dbUrl,std::string & strBuf)413 bool MmsNetworkClient::GetMmsPduFromDataBase(const std::string &dbUrl, std::string &strBuf)
414 {
415 if (dbUrl.empty()) {
416 TELEPHONY_LOGE("dbUrl is empty");
417 return false;
418 }
419 std::shared_ptr<MmsPersistHelper> mmsPdu = std::make_shared<MmsPersistHelper>();
420 if (mmsPdu == nullptr) {
421 TELEPHONY_LOGE("mmsPdu nullptr");
422 return false;
423 }
424 strBuf = mmsPdu->GetMmsPdu(dbUrl);
425 if (strBuf.empty()) {
426 TELEPHONY_LOGE("strBuf is empty");
427 return false;
428 }
429 return true;
430 }
431
DeleteMmsPdu(const std::string & dbUrl)432 void MmsNetworkClient::DeleteMmsPdu(const std::string &dbUrl)
433 {
434 std::shared_ptr<MmsPersistHelper> mmsPdu = std::make_shared<MmsPersistHelper>();
435 if (mmsPdu == nullptr) {
436 TELEPHONY_LOGE("mmsPdu is nullptr");
437 return;
438 }
439 mmsPdu->DeleteMmsPdu(dbUrl);
440 }
441
GetIfaceName()442 std::string MmsNetworkClient::GetIfaceName()
443 {
444 int32_t simId = CoreManagerInner::GetInstance().GetSimId(slotId_);
445 std::list<int32_t> netIdList;
446 int32_t ret =
447 NetConnClient::GetInstance().GetNetIdByIdentifier(SIMID_IDENT_PREFIX + std::to_string(simId), netIdList);
448 std::string ifaceName;
449 if (ret != NETMANAGER_SUCCESS) {
450 TELEPHONY_LOGE("get netIdList by identifier fail, ret = %{public}d", ret);
451 return ifaceName;
452 }
453 std::list<sptr<NetHandle>> netList;
454 int32_t result = NetConnClient::GetInstance().GetAllNets(netList);
455 if (result != NETMANAGER_SUCCESS) {
456 TELEPHONY_LOGE("get all nets fail, ret = %{public}d", result);
457 return ifaceName;
458 }
459 for (sptr<NetHandle> netHandle : netList) {
460 for (auto netId : netIdList) {
461 if (netId != netHandle->GetNetId()) {
462 continue;
463 }
464 NetAllCapabilities capabilities;
465 NetConnClient::GetInstance().GetNetCapabilities(*netHandle, capabilities);
466 auto search = capabilities.netCaps_.find(NetCap::NET_CAPABILITY_MMS);
467 if (search == capabilities.netCaps_.end()) {
468 continue;
469 }
470 NetLinkInfo info;
471 NetConnClient::GetInstance().GetConnectionProperties(*netHandle, info);
472 ifaceName = info.ifaceName_;
473 TELEPHONY_LOGI("data is connected ifaceName = %{public}s", ifaceName.c_str());
474 return ifaceName;
475 }
476 }
477 TELEPHONY_LOGI("slot = %{public}d data is not connected for this slot", slotId_);
478 return ifaceName;
479 }
480
WriteBufferToFile(const std::unique_ptr<char[]> & buff,uint32_t len,std::string & strPathName) const481 bool MmsNetworkClient::WriteBufferToFile(
482 const std::unique_ptr<char[]> &buff, uint32_t len, std::string &strPathName) const
483 {
484 if (buff == nullptr) {
485 TELEPHONY_LOGE("buff nullptr");
486 return false;
487 }
488 char realPath[PATH_MAX] = { 0 };
489 if (strPathName.empty() || realpath(strPathName.c_str(), realPath) == nullptr) {
490 TELEPHONY_LOGE("path or realPath is nullptr");
491 return false;
492 }
493 FILE *pFile = nullptr;
494 pFile = fopen(realPath, "wb");
495 if (!pFile) {
496 TELEPHONY_LOGE("open file fail");
497 return false;
498 }
499 uint32_t fileLen = fwrite(buff.get(), len, 1, pFile);
500 if (fileLen == 0) {
501 TELEPHONY_LOGI("write mms buffer to file error");
502 (void)fclose(pFile);
503 return false;
504 }
505 (void)fclose(pFile);
506 return true;
507 }
508
HttpCallBack(std::shared_ptr<HttpClientTask> task)509 void MmsNetworkClient::HttpCallBack(std::shared_ptr<HttpClientTask> task)
510 {
511 task->OnSuccess([task, this](const HttpClientRequest &request, const HttpClientResponse &response) {
512 TELEPHONY_LOGI("OnSuccess");
513 httpFinish_ = true;
514 httpSuccess_ = true;
515 responseCode_ = response.GetResponseCode();
516 clientCv_.notify_one();
517 });
518 task->OnCancel([this](const HttpClientRequest &request, const HttpClientResponse &response) {
519 TELEPHONY_LOGI("OnCancel, responseCode:%{public}d", response.GetResponseCode());
520 httpFinish_ = true;
521 clientCv_.notify_one();
522 });
523 task->OnFail(
524 [this](const HttpClientRequest &request, const HttpClientResponse &response, const HttpClientError &error) {
525 TELEPHONY_LOGE("OnFailed, errorCode:%{public}d", error.GetErrorCode());
526 httpFinish_ = true;
527 clientCv_.notify_one();
528 });
529 task->OnDataReceive([this](const HttpClientRequest &request, const uint8_t *data, size_t length) {
530 if (data == nullptr || length == 0) {
531 return;
532 }
533 responseData_.insert(responseData_.size(), reinterpret_cast<const char *>(data), length);
534 });
535 task->OnProgress(
536 [](const HttpClientRequest &request, u_long dltotal, u_long dlnow, u_long ultotal, u_long ulnow) {});
537 }
538 } // namespace Telephony
539 } // namespace OHOS
540