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 #include "mms_content_param.h"
16
17 #include "telephony_log_wrapper.h"
18
19 #include "mms_content_type.h"
20 #include "mms_decode_buffer.h"
21 #include "mms_charset.h"
22
23 namespace OHOS {
24 namespace Telephony {
DumpContentParam()25 void MmsContentParam::DumpContentParam()
26 {
27 std::string charSetString;
28 auto charSet = DelayedSingleton<MmsCharSet>::GetInstance();
29 if (charSet == nullptr || (!charSet->GetCharSetStrFromInt(charSetString, charset_))) {
30 charSetString = "UTF-8";
31 }
32 TELEPHONY_LOGI("Param Charset: %{public}s", charSetString.c_str());
33 TELEPHONY_LOGI("Param Type: %{public}s", type_.c_str());
34 for (auto it = textMap_.begin(); it != textMap_.end(); it++) {
35 TELEPHONY_LOGI("Param textMap : %{public}s", it->second.c_str());
36 }
37 }
38
operator =(const MmsContentParam & srcContentParam)39 MmsContentParam &MmsContentParam::operator=(const MmsContentParam &srcContentParam)
40 {
41 if (this != &srcContentParam) {
42 charset_ = srcContentParam.charset_;
43 type_ = srcContentParam.type_;
44 textMap_ = srcContentParam.textMap_;
45 }
46 return *this;
47 }
48
SetCharSet(uint32_t charset)49 void MmsContentParam::SetCharSet(uint32_t charset)
50 {
51 charset_ = charset;
52 }
53
SetType(std::string type)54 void MmsContentParam::SetType(std::string type)
55 {
56 type_ = type;
57 }
58
GetCharSet()59 uint32_t MmsContentParam::GetCharSet()
60 {
61 return charset_;
62 }
63
GetType()64 std::string MmsContentParam::GetType()
65 {
66 return type_;
67 }
68
GetFileName(std::string & fileName)69 void MmsContentParam::GetFileName(std::string &fileName)
70 {
71 fileName = "";
72 uint8_t fieldCode = static_cast<uint8_t>(ContentParam::CT_P_NAME);
73 if (textMap_.find(fieldCode) != textMap_.end()) {
74 fileName = textMap_[fieldCode];
75 return;
76 }
77 fieldCode = static_cast<uint8_t>(ContentParam::CT_P_NAME_VALUE);
78 if (textMap_.find(fieldCode) != textMap_.end()) {
79 fileName = textMap_[fieldCode];
80 return;
81 }
82 fieldCode = static_cast<uint8_t>(ContentParam::CT_P_FILENAME);
83 if (textMap_.find(fieldCode) != textMap_.end()) {
84 fileName = textMap_[fieldCode];
85 return;
86 }
87 fieldCode = static_cast<uint8_t>(ContentParam::CT_P_FILENAME_VALUE);
88 if (textMap_.find(fieldCode) != textMap_.end()) {
89 fileName = textMap_[fieldCode];
90 }
91 }
92
SetFileName(std::string fileName)93 void MmsContentParam::SetFileName(std::string fileName)
94 {
95 if (fileName.empty()) {
96 return;
97 }
98 uint8_t fieldCode = static_cast<uint8_t>(ContentParam::CT_P_NAME);
99 textMap_.insert(std::make_pair(fieldCode, fileName));
100 }
101
GetStart(std::string & start)102 void MmsContentParam::GetStart(std::string &start)
103 {
104 start = "";
105 uint8_t fieldCode = static_cast<uint8_t>(ContentParam::CT_P_START);
106 if (textMap_.find(fieldCode) != textMap_.end()) {
107 start = textMap_[fieldCode];
108 }
109 }
110
SetStart(std::string start)111 void MmsContentParam::SetStart(std::string start)
112 {
113 if (start.empty()) {
114 return;
115 }
116 uint8_t fieldCode = static_cast<uint8_t>(ContentParam::CT_P_START);
117 textMap_.insert(std::make_pair(fieldCode, start));
118 }
119
AddNormalField(uint8_t field,std::string value)120 bool MmsContentParam::AddNormalField(uint8_t field, std::string value)
121 {
122 if (textMap_.find(field) != textMap_.end()) {
123 TELEPHONY_LOGE(" add normal fail.");
124 return false;
125 }
126 textMap_.insert(std::make_pair(field, value));
127 return true;
128 }
129
GetNormalField(uint8_t field,std::string & value)130 bool MmsContentParam::GetNormalField(uint8_t field, std::string &value)
131 {
132 value = "";
133 if (textMap_.find(field) != textMap_.end()) {
134 value = textMap_[field];
135 }
136 return true;
137 }
138
GetParamMap()139 std::map<uint8_t, std::string> &MmsContentParam::GetParamMap()
140 {
141 return textMap_;
142 }
143 } // namespace Telephony
144 } // namespace OHOS
145