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_MSG_H 17 #define MMS_MSG_H 18 19 #include <vector> 20 21 #include "mms_header.h" 22 #include "mms_body.h" 23 #include "mms_body_part.h" 24 #include "mms_content_param.h" 25 #include "mms_decode_buffer.h" 26 #include "mms_attachment.h" 27 #include "mms_address.h" 28 29 namespace OHOS { 30 namespace Telephony { 31 class MmsMsg { 32 public: 33 MmsMsg() = default; 34 ~MmsMsg() = default; 35 36 /** 37 * @brief Dump the mms Message, printf Mms Message Infomations. 38 */ 39 void DumpMms(); 40 41 /** 42 * @brief Get Mms Header Protocol Version. 43 * 44 * @return returns Mms Header Protocol Version. 45 */ 46 uint16_t GetMmsVersion(); 47 48 /** 49 * @brief Set Mms Header Protocol Version. 50 * 51 * @param value the Mms Header Protocol Version. 52 * @return true if set successfully, false otherwise. 53 */ 54 bool SetMmsVersion(uint16_t value); 55 56 /** 57 * @brief Get the Mms Message Type. 58 * 59 * @return uint8_t returns Mms Header Message Type. 60 */ 61 uint8_t GetMmsMessageType(); 62 63 /** 64 * @brief Set the Mms Message Type. 65 * 66 * @param value Mms Header Message Type. 67 * @return true if set successfully, false otherwise. 68 */ 69 bool SetMmsMessageType(uint8_t value); 70 71 /** 72 * @brief Get the Mms Transaction Id From Header, a unique identifier for the PDU. 73 * 74 * @return std::string returns the Mms Transaction Id. 75 */ 76 std::string GetMmsTransactionId(); 77 78 /** 79 * @brief Set the Mms Transaction Id To Header, a unique identifier for the PDU. 80 * 81 * @param value the Mms Transaction Id. 82 * @return true if set successfully, false otherwise. 83 */ 84 bool SetMmsTransactionId(std::string value); 85 86 /** 87 * @brief Get the Mms Date From Header. 88 * 89 * @return int64_t return the Mms Message Header Date Infomations. 90 */ 91 int64_t GetMmsDate(); 92 93 /** 94 * @brief Set the Mms Date To Header. 95 * 96 * @param value the Mms Message Header Date Infomations. 97 * @return true if set successfully, false otherwise. 98 */ 99 bool SetMmsDate(int64_t value); 100 101 /** 102 * @brief Get the Mms Subject From Header. 103 * 104 * @return std::string Mms Message Header SubJect Infomations. 105 */ 106 std::string GetMmsSubject(); 107 108 /** 109 * @brief Set Mms Message Header Subject Infomations. 110 * 111 * @param value Mms Message Header Subject Infomations. 112 * @return true if set successfully, false otherwise. 113 */ 114 bool SetMmsSubject(std::string value); 115 116 /** 117 * @brief Get Mms Message Header From Address Infomations. 118 * 119 * @return returns a MmsAddress object, contains the address, address type .etc 120 */ 121 MmsAddress GetMmsFrom(); 122 123 /** 124 * @brief Set Mms Message Header From Address Infomations. 125 * 126 * @param address the MmsAddress object, contains the address, address type .etc 127 * @return true if set successfully, false otherwise. 128 */ 129 bool SetMmsFrom(MmsAddress address); 130 131 /** 132 * @brief Set the Mms To Address in Header, support multiple address. 133 * 134 * @param toAddrs a list of MmsAddress objects. 135 * @return true if set successfully, false otherwise. 136 */ 137 bool SetMmsTo(std::vector<MmsAddress>& toAddrs); 138 139 /** 140 * @brief Get the Mms Msg to address from the header, support multiple address. 141 * 142 * @param toAddrs a list of MmsAddress objects. 143 * @return true if get successfully, false otherwise. 144 */ 145 bool GetMmsTo(std::vector<MmsAddress>& toAddrs); 146 147 /** 148 * @brief Get Octet Type Value From the Header. 149 * This is Generic methods to Get Mms Message Header. 150 * 151 * @param fieldId the Header Field Assigned Number {@link MmsFieldCode}. 152 * @return uint8_t returns the Octet Type Value. 153 */ 154 uint8_t GetHeaderOctetValue(uint8_t fieldId); 155 156 /** 157 * @brief Set the Header Octet Value To Header. 158 * This is Generic methods to Set Mms Message Header. 159 * 160 * @param fieldId the Header Field Assigned Number {@link MmsFieldCode}. 161 * @param value the Header Octet Value. 162 * @return true if set successfully, false otherwise. 163 */ 164 bool SetHeaderOctetValue(uint8_t fieldId, uint8_t value); 165 166 /** 167 * @brief Get the Header Integer Value From Header. 168 * This is Generic methods to Get Mms Message Header. 169 * 170 * @param fieldId the Header Field Assigned Number {@link MmsFieldCode}. 171 * @return int32_t return the Header Octet Value. 172 */ 173 int32_t GetHeaderIntegerValue(uint8_t fieldId); 174 175 /** 176 * @brief Set the Header Integer Value To Header. 177 * This is Generic methods to Set Mms Message Header. 178 * 179 * @param fieldId the Header Field Assigned Number {@link MmsFieldCode}. 180 * @param value the Header Integer Value. 181 * @return true if set successfully, false otherwise. 182 */ 183 bool SetHeaderIntegerValue(uint8_t fieldId, int32_t value); 184 185 /** 186 * @brief Get Long Type Value From the Header. 187 * This is Generic methods to Get Mms Message Header. 188 * 189 * @param fieldId the Header Field Assigned Number {@link MmsFieldCode}. 190 * @return int64_t return the Long Type Value. 191 */ 192 int64_t GetHeaderLongValue(uint8_t fieldId); 193 194 /** 195 * @brief Set the Header Long Value To Header 196 * This is Generic methods to Set Mms Message Header. 197 * 198 * @param fieldId the Header Field Assigned Number {@link MmsFieldCode} 199 * @param value the Field Long Value 200 * @return true if set successfully, false otherwise 201 */ 202 bool SetHeaderLongValue(uint8_t fieldId, int64_t value); 203 204 /** 205 * @brief Get String or Encode String Type Value From the Header. 206 * This is Generic methods to Get Mms Message Header. 207 * 208 * @param fieldId the Header Field Assigned Number {@link MmsFieldCode}. 209 * @return std::string return Field Text Value Or EncondeString with UTF_8. 210 */ 211 std::string GetHeaderStringValue(uint8_t fieldId); 212 213 /** 214 * @brief Set the Header String Value To Header. 215 * This is Generic methods to Set Mms Message Header. 216 * 217 * @param fieldId the Header Field Assigned Number {@link MmsFieldCode}. 218 * @param value Field Text Value. 219 * @return true if set successfully, false otherwise. 220 */ 221 bool SetHeaderStringValue(uint8_t fieldId, std::string &value); 222 223 /** 224 * @brief Set the Header Encoded String Value From Header. 225 * This is Generic methods to Set Mms Message Header. 226 * 227 * @param fieldId the Header Field Assigned Number {@link MmsFieldCode}. 228 * @param value the Field EncondeString Value. 229 * @param charset the charset type. 230 * @return true if set successfully, false otherwise. 231 */ 232 bool SetHeaderEncodedStringValue(uint8_t fieldId, const std::string &value, uint32_t charset); 233 234 /** 235 * @brief AddHeaderAddressValue, for example: To / Cc / Bcc. 236 * 237 * @param fieldId the Header Field Assigned Number {@link MmsFieldCode}. 238 * @param address the MmsAddress object, contains the address, address type .etc 239 * @return true if add successfully, false otherwise. 240 */ 241 bool AddHeaderAddressValue(uint8_t fieldId, MmsAddress &address); 242 243 /** 244 * @brief Get the Header All Address Value From Header, 245 * for example: To / Cc / Bcc. 246 * 247 * @param fieldId the Header Field Assigned Number {@link MmsFieldCode}. 248 * @param addressValue a list of MmsAddress Objects. 249 * @return true if get successfully, false otherwise. 250 */ 251 bool GetHeaderAllAddressValue(uint8_t fieldId, std::vector<MmsAddress> &addressValue); 252 253 /** 254 * @brief Set the Content Type. 255 * 256 * @param strType the content type. 257 * @return true if set successfully, false otherwise. 258 */ 259 bool SetHeaderContentType(std::string strType); 260 261 /** 262 * @brief Get the Content Type. 263 * 264 * @return std::string return the header content type. 265 */ 266 std::string GetHeaderContentType(); 267 268 /** 269 * @brief Get the Content Type start parameter. 270 * 271 * @return std::string return the Content Type start parameter. 272 */ 273 std::string GetHeaderContentTypeStart(); 274 275 /** 276 * @brief add attachment to mms message if attachment is smil file must to add first. 277 * 278 * @param attachment the MmsAttachment object, indicates the attachment 279 * detail information for the MMS message. 280 * @return returns true if add successfully, false otherwise. 281 */ 282 bool AddAttachment(MmsAttachment &attachment); 283 284 /** 285 * @brief Get the All Attachments from mms message. 286 * 287 * @param attachments a list of MmsAttachment objects, indicates the attachment 288 * detail information for the MMS message. 289 * @return returns true if get successfully, false otherwise. 290 */ 291 bool GetAllAttachment(std::vector<MmsAttachment> &attachments); 292 293 /** 294 * @brief DecodeMsg from a mms file. 295 * 296 * @param mmsFilePathName the path of mms file. 297 * @return true if decode successfully, false otherwise. 298 */ 299 bool DecodeMsg(std::string mmsFilePathName); 300 301 /** 302 * @brief DecodeMsg from a mms from buff. 303 * 304 * @param inBuff the mms buffer. 305 * @param inLen the mms buffer length. 306 * @return true if decode successfully, false otherwise. 307 */ 308 bool DecodeMsg(std::unique_ptr<char[]> inBuff, uint32_t inLen); 309 310 /** 311 * @brief EncodeMsg form MmsMsg. 312 * 313 * @param outLen the result message length limit. 314 * @return return eoncode MmsMsg result data buff. 315 */ 316 std::unique_ptr<char[]> EncodeMsg(uint32_t &outLen); 317 318 MmsHeader &GetHeader(); 319 private: 320 MmsHeader mmsHeader_; 321 MmsBody mmsBody_; 322 }; 323 } // namespace Telephony 324 } // namespace OHOS 325 #endif 326