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_header_categ.h" 23 #include "mms_content_type.h" 24 #include "mms_decode_buffer.h" 25 #include "mms_encode_string.h" 26 #include "mms_address.h" 27 28 namespace OHOS { 29 namespace Telephony { 30 class MmsHeader { 31 public: 32 MmsHeader(); 33 void DumpMmsHeader(); 34 bool DecodeMmsHeader(MmsDecodeBuffer &decodeBuffer); 35 bool EncodeMmsHeader(MmsEncodeBuffer &encodeBuffer); 36 bool GetOctetValue(uint8_t fieldId, uint8_t &value) const; 37 bool SetOctetValue(uint8_t fieldId, uint8_t value); 38 bool GetLongValue(uint8_t fieldId, int64_t &value) const; 39 bool SetLongValue(uint8_t fieldId, int64_t value); 40 bool GetTextValue(uint8_t fieldId, std::string &value) const; 41 bool SetTextValue(uint8_t fieldId, std::string value); 42 bool GetEncodeStringValue(uint8_t fieldId, MmsEncodeString &value) const; 43 bool SetEncodeStringValue(uint8_t fieldId, uint32_t charset, const std::string &value); 44 bool AddHeaderAddressValue(uint8_t fieldId, MmsAddress &address); 45 bool GetHeaderAllAddressValue(uint8_t fieldId, std::vector<MmsAddress> &addressValue); 46 bool GetStringValue(uint8_t fieldId, std::string &value) const; 47 MmsContentType &GetHeaderContentType(); 48 bool GetSmilFileName(std::string &smileFileName); 49 bool IsHaveBody(); 50 private: 51 void InitOctetHandleFun(); 52 void InitLongHandleFun(); 53 void InitStringHandleFun(); 54 void InitTextStringHandleFun(); 55 std::string MakeTransactionId(uint32_t len); 56 bool FindHeaderFieldName(const uint8_t fieldId, std::string &fieldName); 57 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 73 // encode value length feild 74 bool EncodeFieldExpriyValue(MmsEncodeBuffer &buff, int64_t value); 75 bool EncodeFieldFromValue(MmsEncodeBuffer &buff, std::vector<MmsAddress> &addr); 76 bool EcondeFieldMessageClassValue(MmsEncodeBuffer &buff); 77 // end 78 79 bool EncodeCommontFieldValue(MmsEncodeBuffer &buff); 80 bool EncodeMultipleAddressValue(MmsEncodeBuffer &buff, uint8_t fieldId, std::vector<MmsAddress> &addrs); 81 82 bool EncodeMmsSendReq(MmsEncodeBuffer &buff); 83 bool EncodeMmsSendConf(MmsEncodeBuffer &buff); 84 bool EncodeMmsNotificationInd(MmsEncodeBuffer &buff); 85 bool EnocdeMmsNotifyRespInd(MmsEncodeBuffer &buff); 86 bool EnocdeMmsRetrieveConf(MmsEncodeBuffer &buff); 87 bool EnocdeMmsAcknowledgeInd(MmsEncodeBuffer &buff); 88 bool EnocdeMmsDeliveryInd(MmsEncodeBuffer &buff); 89 bool EncodeMmsReadRecInd(MmsEncodeBuffer &buff); 90 bool EncodeMmsReadOrigInd(MmsEncodeBuffer &buff); 91 92 void TrimString(std::string &str); // trim string two side <> 93 bool EncodeOctetValue(MmsEncodeBuffer &buff, uint8_t fieldId, uint8_t value); 94 bool EncodeTextStringValue(MmsEncodeBuffer &buff, uint8_t fieldId, std::string value); 95 bool EncodeEncodeStringValue(MmsEncodeBuffer &buff, uint8_t fieldId, MmsEncodeString value); 96 bool EncodeShortIntegerValue(MmsEncodeBuffer &buff, uint8_t fieldId, int64_t value); 97 bool EncodeLongIntergerValue(MmsEncodeBuffer &buff, uint8_t fieldId, int64_t value); 98 99 bool EncodeOctetValueFromMap(MmsEncodeBuffer &buff, uint8_t fieldId); 100 bool EncodeTextStringValueFromMap(MmsEncodeBuffer &buff, uint8_t fieldId); 101 bool EnocdeEncodeStringValueFromMap(MmsEncodeBuffer &buff, uint8_t fieldId); 102 bool EnocdeShortIntegerValueFromMap(MmsEncodeBuffer &buff, uint8_t fieldId); 103 bool EncodeLongIntergerValueFromMap(MmsEncodeBuffer &buff, uint8_t fieldId); 104 105 bool IsHaveTransactionId(uint8_t messageType); 106 bool CheckResponseStatus(uint8_t value); 107 bool CheckRetrieveStatus(uint8_t value); 108 bool CheckStoreStatus(uint8_t value); 109 bool CheckBooleanValue(uint8_t fieldId, uint8_t value); 110 111 using Func = bool (MmsHeader::*)(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len); 112 std::map<uint8_t, Func> memberFuncMap_; 113 114 std::map<uint8_t, uint8_t> octetValueMap_; 115 std::map<uint8_t, int64_t> longValueMap_; 116 std::map<uint8_t, std::string> textValueMap_; 117 std::map<uint8_t, MmsEncodeString> encodeStringsMap_; 118 std::map<uint8_t, std::vector<MmsAddress>> addressMap_; 119 private: 120 MmsContentType mmsContentType_; 121 MmsHeaderCateg mmsHaderCateg_; 122 }; 123 } // namespace Telephony 124 } // namespace OHOS 125 #endif 126