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 #ifndef MMS_NETWORK_CLIENT_H
17 #define MMS_NETWORK_CLIENT_H
18 
19 #include <cinttypes>
20 #include <cmath>
21 #include <memory>
22 #include <string>
23 
24 #include "http_client_task.h"
25 #include "mms_header.h"
26 #include "mms_decode_buffer.h"
27 
28 namespace OHOS {
29 namespace Telephony {
30 class MmsNetworkClient {
31 public:
32     explicit MmsNetworkClient(int32_t slotId);
33     virtual ~MmsNetworkClient();
34     int32_t Execute(const std::string &method, const std::string &mmsc, std::string &data, const std::string &ua,
35         const std::string &uaprof);
36 
37 private:
38     std::string GetIfaceName();
39     int32_t PostUrl(const std::string &mmsc, const std::string &filename, const std::string &ua,
40         const std::string &uaprof);
41     int32_t GetMmscFromDb(const std::string &mmsc);
42     int32_t GetMmsDataBuf(std::string &strBuf, const std::string &fileName);
43     int32_t GetUrl(const std::string &mmsc, std::string &storeDirName, const std::string &ua,
44         const std::string &uaprof);
45     int32_t HttpRequest(const std::string &method, const std::string &url, const std::string &data,
46         const std::string &ua, const std::string &uaprof);
47     int32_t GetMmsApnPorxy(NetStack::HttpClient::HttpProxy &httpProxy);
48     bool WriteBufferToFile(const std::unique_ptr<char[]> &buff, uint32_t len, std::string &strPathName) const;
49     void DeleteMmsPdu(const std::string &dbUrl);
50     bool GetMmsPduFromFile(const std::string &fileName, std::string &strBuf);
51     bool GetMmsPduFromDataBase(const std::string &dbUrl, std::string &strBuf);
52     void HttpCallBack(std::shared_ptr<NetStack::HttpClient::HttpClientTask> task);
53     int32_t UpdateMmsPduToStorage(std::string &storeDirName);
54     bool CheckSendConf();
55     void GetCoverUrl(std::string str);
56 
57 public:
58     bool httpFinish_ = false;
59     bool httpSuccess_ = false;
60     int32_t responseCode_ = 0;
61     uint8_t retryTimes_ = 0;
62     std::mutex clientCts_;
63     std::condition_variable clientCv_;
64     std::string responseData_;
65 
66 private:
67     int32_t slotId_ = -1;
68     MmsHeader mmsHeader_;
69 };
70 } // namespace Telephony
71 } // namespace OHOS
72 #endif