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 16 #ifndef MAP_MSE_BMSG_H 17 #define MAP_MSE_BMSG_H 18 19 #include <cstdint> 20 #include <fstream> 21 #include <string> 22 #include <vector> 23 #include "bt_def.h" 24 #include "log.h" 25 #include "map_mse_types.h" 26 #include "map_mse_vcard.h" 27 28 namespace OHOS { 29 namespace bluetooth { 30 class MapMseBmsg { 31 public: 32 explicit MapMseBmsg(); 33 virtual ~MapMseBmsg(); 34 int Init(std::string body, const uint8_t charset); 35 MessageType GetType(void) const; 36 void SetMsgTypeName(const std::string &name); 37 std::string GetPartId(void) const; 38 void SetPartId(const int id); 39 std::string GetVersion(void) const; 40 void SetVersion(const std::string &version); 41 std::string GetExtendedData(void) const; 42 void SetExtendedData(const std::string &exdData); 43 std::string GetStatus(void) const; 44 std::string GetMsgBody(void) const; 45 void SetMsgBody(const std::string &body); 46 std::string GetEncoding(void) const; 47 void SetEncoding(const std::string &encoding); 48 std::string GetCharset(void) const; 49 void SetCharset(const std::string &charset); 50 std::string GetLanguage(void) const; 51 void SetLanguage(const std::string &language); 52 std::string GetBmsgLength(void) const; 53 void SetBmsgLength(const int length); 54 void SetStatus(const std::string &status); 55 void SetType(const MessageType &type); 56 std::vector<MapMseVcard> GetOriginators(void) const; 57 void SetOriginators(const std::vector<MapMseVcard> &originator); 58 std::vector<MapMseVcard> GetRecipients(void) const; 59 void SetRecipients(const std::vector<MapMseVcard> &recipient); 60 std::string GetFolder(void) const; 61 void SetFolder(const std::string &folder); 62 std::string ToBmessageString(void); 63 64 private: 65 static const std::string MAP_MSE_BMESSAGE_VERSION; 66 /* BMSG attributes */ 67 std::string version_ = ""; 68 std::string status_ = ""; 69 MessageType msgType_ = MessageType::NONE; 70 std::string msgTypeName_ = ""; 71 std::string folder_ = ""; 72 std::string extendedData_ = ""; 73 /* BBODY attributes */ 74 int partId_ = -1; 75 std::string encoding_ = ""; 76 std::string charset_ = ""; 77 std::string language_ = ""; 78 int bmsgLength_ = -1; 79 std::vector<MapMseVcard> originator_ {}; 80 std::vector<MapMseVcard> recipient_ {}; 81 std::string msgData_ = ""; 82 int ParseCheck(const std::vector<std::string> &src, size_t &pos, const uint8_t charset); 83 bool ParseProperty(const std::vector<std::string> &src, size_t &pos); 84 void ParseEnvelope(const std::vector<std::string> &src, size_t &pos, int level); 85 void ParseOrgEnve(const std::vector<std::string> &src, size_t &pos); 86 void ParseBody(const std::vector<std::string> &src, size_t &pos); 87 MapMseVcard ParseVCard(const std::vector<std::string> &src, size_t &pos, int level) const; 88 static void Split(const std::string &src, const std::string &separator, std::vector<std::string> &dest); 89 static std::string GetNodeValue(const std::string &src, std::string name); 90 void SetMessageType(const std::string &typeName); 91 void AddBbody(std::string &bmessage); 92 void AddRecipient(std::string &bmessage); 93 }; 94 } // namespace bluetooth 95 } // namespace OHOS 96 97 #endif // MAP_MSE_BMSG_H