• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
59     bool DecodeMmsMsgType(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len);
60     bool DecodeFieldAddressModelValue(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len);
61     bool DecodeFieldOctetValue(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len);
62     bool DecodeFieldLongValue(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len);
63     bool DecodeFieldIntegerValue(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len);
64     bool DecodeFieldTextStringValue(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len);
65     bool DecodeFieldEncodedStringValue(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len);
66     bool DecodeFromValue(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len);
67     bool DecodeMmsMsgUnKnownField(MmsDecodeBuffer &decodeBuffer);
68     bool DecodeMmsContentType(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len);
69     bool DecodeFieldDate(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len);
70     bool DecodeFieldPreviouslySentDate(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len);
71     bool DecodeFieldMBox(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len);
72     bool DecodeFieldMMFlag(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len);
73 
74     // encode value length feild
75     bool EncodeFieldExpriyValue(MmsEncodeBuffer &buff, int64_t value);
76     bool EncodeFieldFromValue(MmsEncodeBuffer &buff, std::vector<MmsAddress> &addr);
77     bool EcondeFieldMessageClassValue(MmsEncodeBuffer &buff);
78     // end
79 
80     bool EncodeCommontFieldValue(MmsEncodeBuffer &buff);
81     bool EncodeMultipleAddressValue(MmsEncodeBuffer &buff, uint8_t fieldId, std::vector<MmsAddress> &addrs);
82 
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 
93     void TrimString(std::string &str);  // trim string two side <>
94     bool EncodeOctetValue(MmsEncodeBuffer &buff, uint8_t fieldId, uint8_t value);
95     bool EncodeTextStringValue(MmsEncodeBuffer &buff, uint8_t fieldId, std::string value);
96     bool EncodeEncodeStringValue(MmsEncodeBuffer &buff, uint8_t fieldId, MmsEncodeString value);
97     bool EncodeShortIntegerValue(MmsEncodeBuffer &buff, uint8_t fieldId, int64_t value);
98     bool EncodeLongIntergerValue(MmsEncodeBuffer &buff, uint8_t fieldId, int64_t value);
99 
100     bool EncodeOctetValueFromMap(MmsEncodeBuffer &buff, uint8_t fieldId);
101     bool EncodeTextStringValueFromMap(MmsEncodeBuffer &buff, uint8_t fieldId);
102     bool EnocdeEncodeStringValueFromMap(MmsEncodeBuffer &buff, uint8_t fieldId);
103     bool EnocdeShortIntegerValueFromMap(MmsEncodeBuffer &buff, uint8_t fieldId);
104     bool EncodeLongIntergerValueFromMap(MmsEncodeBuffer &buff, uint8_t fieldId);
105 
106     bool IsHaveTransactionId(uint8_t messageType);
107     bool CheckResponseStatus(uint8_t value);
108     bool CheckRetrieveStatus(uint8_t value);
109     bool CheckStoreStatus(uint8_t value);
110     bool CheckBooleanValue(uint8_t fieldId, uint8_t value);
111 
112     using Func = bool (MmsHeader::*)(uint8_t fieldId, MmsDecodeBuffer &buff, int32_t &len);
113     std::map<uint8_t, Func> memberFuncMap_;
114 
115 private:
116     std::map<uint8_t, uint8_t> octetValueMap_;
117     std::map<uint8_t, int64_t> longValueMap_;
118     std::map<uint8_t, std::string> textValueMap_;
119     std::map<uint8_t, MmsEncodeString> encodeStringsMap_;
120     std::map<uint8_t, std::vector<MmsAddress>> addressMap_;
121     MmsContentType mmsContentType_;
122     MmsHeaderCateg mmsHaderCateg_;
123 };
124 } // namespace Telephony
125 } // namespace OHOS
126 #endif
127