1/*
2 * Copyright (C) 2024 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 NDEF_HAR_DATA_PARSER_H
16#define NDEF_HAR_DATA_PARSER_H
17
18#include <string>
19#include "ndef_message.h"
20#include "ndef_har_dispatch.h"
21#include "inci_tag_interface.h"
22#include "taginfo.h"
23
24namespace OHOS {
25namespace NFC {
26namespace TAG {
27using namespace OHOS::NFC::KITS;
28
29class NdefHarDataParser {
30public:
31    NdefHarDataParser(std::weak_ptr<NCI::INciTagInterface> nciTagProxy);
32    ~NdefHarDataParser() {}
33    bool TryNdef(const std::string& msg, std::shared_ptr<KITS::TagInfo> tagInfo);
34
35private:
36    std::string IsWebUri(std::shared_ptr<NdefRecord> record);
37    std::string GetUriPayload(std::shared_ptr<NdefRecord> record);
38    std::string GetUriPayload(std::shared_ptr<NdefRecord> record, bool isSmartPoster);
39    bool ParseWebLink(std::vector<std::shared_ptr<NdefRecord>> records);
40    bool ParseHarPackage(
41        std::vector<std::string> harPackages, std::shared_ptr<KITS::TagInfo> tagInfo, const std::string &mimeType,
42        const std::string &uri);
43    bool ParseUriLink(std::vector<std::shared_ptr<NdefRecord>> records);
44    bool ParseOtherType(std::vector<std::shared_ptr<NdefRecord>> records, std::shared_ptr<KITS::TagInfo> tagInfo);
45    std::string ToMimeType(std::shared_ptr<NdefRecord> record);
46    std::vector<std::string> ExtractHarPackages(std::vector<std::shared_ptr<NdefRecord>> records);
47    std::string CheckForHar(std::shared_ptr<NdefRecord> record);
48    bool IsOtherPlatformAppType(const std::string &appType);
49
50    std::shared_ptr<NdefHarDispatch> ndefHarDispatch_ {nullptr};
51    std::weak_ptr<NCI::INciTagInterface> nciTagProxy_ {};
52};
53} // namespace TAG
54} // namespace NFC
55} // namespace OHOS
56#endif // NDEF_HAR_DATA_PARSER_H