• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #ifndef OHOS_WIFI_P2P_DNS_SD_SERVICE_RESPONSE_H
16 #define OHOS_WIFI_P2P_DNS_SD_SERVICE_RESPONSE_H
17 
18 #include <sstream>
19 #include <iostream>
20 #include <string>
21 #include <map>
22 #include "wifi_p2p_msg.h"
23 #include "p2p_macro.h"
24 
25 namespace OHOS {
26 namespace Wifi {
27 class WifiP2pDnsSdServiceResponse : public WifiP2pServiceResponse {
28     FRIEND_GTEST(WifiP2pDnsSdServiceResponse);
29 public:
30     /**
31      * @Description Construct a new WifiP2pDnsSdServiceResponse object.
32      *
33      * @param status - service status
34      * @param tranId - transmission ID
35      * @param data - detailed data of the service response
36      */
37     WifiP2pDnsSdServiceResponse(
38         P2pServiceStatus status, int tranId, const std::vector<unsigned char> &data);
39 
40     /**
41      * @Description Construct a new WifiP2pDnsSdServiceResponse object.
42      *
43      * @param resp - base class object of the DNS service response
44      */
45     explicit WifiP2pDnsSdServiceResponse(const WifiP2pServiceResponse &resp);
46 
47     /**
48      * @Description Destroy the WifiP2pDnsSdServiceResponse object.
49      *
50      */
51     ~WifiP2pDnsSdServiceResponse() = default;
52 
53     /**
54      * @Description Parses the data in the service discovery response.
55      *
56      * @return true - parses success
57      * @return false - parses failed
58      */
59     bool ParseData();
60 
61     /**
62      * @Description Get the dnsQueryName object.
63      *
64      * @return const std::string&
65      */
66     const std::string &GetQueryName() const;
67 
68     /**
69      * @Description Get the instanceName object.
70      *
71      * @return const std::string&
72      */
73     const std::string &GetInstanceName() const;
74 
75     /**
76      * @Description Get the dnsType object.
77      *
78      * @return int
79      */
80     int GetDnsType() const;
81 
82     /**
83      * @Description Get the version object.
84      *
85      * @return int
86      */
87     int GetVersion() const;
88 
89     /**
90      * @Description Get the txtRecord object.
91      *
92      * @return const std::map<std::string, std::string>&
93      */
94     const std::map<std::string, std::string> &GetTxtRecord() const;
95 private:
96     /**
97      * @Description Resolve DNS name data.
98      *
99      * @param istream - stream instance of service discovery response content
100      * @param dnsName - instance of saving DNS name resolution
101      * @return true - success
102      * @return false - failed
103      */
104     bool FetchDnsName(std::istringstream &istream, std::string &dnsName);
105 
106     /**
107      * @Description Parsing TXT data.
108      *
109      * @param istream - stream instance of service discovery response content
110      * @return true - success
111      * @return false - failed
112      */
113     bool FetchTxtData(std::istringstream &istream);
114 
115     /**
116      * @Description Initialization.
117      *
118      */
119     void Init();
120 
121     std::string dnsQueryName;
122     std::string instanceName;
123     int dnsType;
124     int version;
125     std::map<std::string, std::string> txtRecord;
126     std::map<unsigned char, std::string> sVmpack;
127 };
128 
129 } // namespace Wifi
130 } // namespace OHOS
131 
132 #endif /* OHOS_WIFI_P2P_DNS_SD_SERVICE_RESPONSE_H */