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 MMS_HEADER_H 17 #define MMS_HEADER_H 18 19 #include <map> 20 #include <vector> 21 22 #include "mms_address.h" 23 #include "mms_content_type.h" 24 #include "mms_decode_buffer.h" 25 #include "mms_encode_string.h" 26 #include "mms_header_categ.h" 27 28 namespace OHOS { 29 namespace Telephony { 30 class MmsHeader { 31 public: 32 MmsHeader(); 33 ~MmsHeader() = default; 34 void DumpMmsHeader(); 35 bool DecodeMmsHeader(MmsDecodeBuffer &decodeBuffer); 36 bool EncodeMmsHeader(MmsEncodeBuffer &encodeBuffer); 37 bool GetOctetValue(uint8_t fieldId, uint8_t &value) const; 38 bool SetOctetValue(uint8_t fieldId, uint8_t value); 39 bool GetLongValue(uint8_t fieldId, int64_t &value) const; 40 bool SetLongValue(uint8_t fieldId, int64_t value); 41 bool GetTextValue(uint8_t fieldId, std::string &value) const; 42 bool SetTextValue(uint8_t fieldId, std::string value); 43 bool GetEncodeStringValue(uint8_t fieldId, MmsEncodeString &value) const; 44 bool SetEncodeStringValue(uint8_t fieldId, uint32_t charset, const std::string &value); 45 bool AddHeaderAddressValue(uint8_t fieldId, MmsAddress &address); 46 bool GetHeaderAllAddressValue(uint8_t fieldId, std::vector<MmsAddress> &addressValue); 47 bool GetStringValue(uint8_t fieldId, std::string &value) const; 48 MmsContentType &GetHeaderContentType(); 49 bool GetSmilFileName(std::string &smileFileName); 50 bool IsHaveBody(); 51 private: 52 void InitOctetHandleFun(); 53 void InitLongHandleFun(); 54 void InitStringHandleFun(); 55 void InitTextStringHandleFun(); 56 std::string MakeTransactionId(uint32_t len); 57 bool FindHeaderFieldName(const uint8_t fieldId, std::string &fieldName); 58 bool DecodeMmsMsgType(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len); 59 bool DecodeFieldAddressModelValue(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len); 60 bool DecodeFieldOctetValue(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len); 61 bool DecodeFieldLongValue(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len); 62 bool DecodeFieldIntegerValue(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len); 63 bool DecodeFieldTextStringValue(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len); 64 bool DecodeFieldEncodedStringValue(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len); 65 bool DecodeFromValue(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len); 66 bool DecodeMmsMsgUnKnownField(MmsDecodeBuffer &decodeBuffer); 67 bool DecodeMmsContentType(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len); 68 bool DecodeFieldDate(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len); 69 bool DecodeFieldPreviouslySentDate(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len); 70 bool DecodeFieldMBox(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len); 71 bool DecodeFieldMMFlag(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len); 72 bool SetOctetValuePartData(uint8_t fieldId, uint8_t value, bool &match); 73 bool SetOctetValuePortionData(uint8_t fieldId, uint8_t value, bool &match); 74 75 // encode value length feild 76 bool EncodeFieldExpriyValue(MmsEncodeBuffer &buff, int64_t value); 77 bool EncodeFieldFromValue(MmsEncodeBuffer &buff, std::vector<MmsAddress> &addr); 78 bool EcondeFieldMessageClassValue(MmsEncodeBuffer &buff); 79 // end 80 81 bool EncodeCommontFieldValue(MmsEncodeBuffer &buff); 82 bool EncodeMultipleAddressValue(MmsEncodeBuffer &buff, uint8_t fieldId, std::vector<MmsAddress> &addrs); 83 bool EncodeMmsSendReq(MmsEncodeBuffer &buff); 84 bool EncodeMmsSendConf(MmsEncodeBuffer &buff); 85 bool EncodeMmsNotificationInd(MmsEncodeBuffer &buff); 86 bool EnocdeMmsNotifyRespInd(MmsEncodeBuffer &buff); 87 bool EnocdeMmsRetrieveConf(MmsEncodeBuffer &buff); 88 bool EnocdeMmsAcknowledgeInd(MmsEncodeBuffer &buff); 89 bool EnocdeMmsDeliveryInd(MmsEncodeBuffer &buff); 90 bool EncodeMmsReadRecInd(MmsEncodeBuffer &buff); 91 bool EncodeMmsReadOrigInd(MmsEncodeBuffer &buff); 92 bool EncodeOctetValue(MmsEncodeBuffer &buff, uint8_t fieldId, uint8_t value); 93 bool EncodeTextStringValue(MmsEncodeBuffer &buff, uint8_t fieldId, std::string value); 94 bool EncodeEncodeStringValue(MmsEncodeBuffer &buff, uint8_t fieldId, MmsEncodeString value); 95 bool EncodeShortIntegerValue(MmsEncodeBuffer &buff, uint8_t fieldId, int64_t value); 96 bool EncodeLongIntergerValue(MmsEncodeBuffer &buff, uint8_t fieldId, int64_t value); 97 bool EncodeOctetValueFromMap(MmsEncodeBuffer &buff, uint8_t fieldId); 98 bool EncodeTextStringValueFromMap(MmsEncodeBuffer &buff, uint8_t fieldId); 99 bool EnocdeEncodeStringValueFromMap(MmsEncodeBuffer &buff, uint8_t fieldId); 100 bool EncodeLongIntergerValueFromMap(MmsEncodeBuffer &buff, uint8_t fieldId); 101 bool IsHaveTransactionId(uint8_t messageType); 102 bool CheckResponseStatus(uint8_t value); 103 bool CheckRetrieveStatus(uint8_t value); 104 bool CheckStoreStatus(uint8_t value); 105 bool CheckBooleanValue(uint8_t fieldId, uint8_t value); 106 107 using Func = std::function<bool(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len)>; 108 std::map<uint8_t, Func> memberFuncMap_; 109 110 private: 111 std::map<uint8_t, uint8_t> octetValueMap_; 112 std::map<uint8_t, int64_t> longValueMap_; 113 std::map<uint8_t, std::string> textValueMap_; 114 std::map<uint8_t, MmsEncodeString> encodeStringsMap_; 115 std::map<uint8_t, std::vector<MmsAddress>> addressMap_; 116 MmsContentType mmsContentType_; 117 MmsHeaderCateg mmsHaderCateg_; 118 }; 119 } // namespace Telephony 120 } // namespace OHOS 121 #endif 122