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 }
76 }
77
SetFileName(std::string fileName)78 void MmsContentParam::SetFileName(std::string fileName)
79 {
80 if (fileName.empty()) {
81 return;
82 }
83 uint8_t fieldCode = static_cast<uint8_t>(ContentParam::CT_P_NAME);
84 textMap_.insert(std::make_pair(fieldCode, fileName));
85 }
86
GetStart(std::string & start)87 void MmsContentParam::GetStart(std::string &start)
88 {
89 start = "";
90 uint8_t fieldCode = static_cast<uint8_t>(ContentParam::CT_P_START);
91 if (textMap_.find(fieldCode) != textMap_.end()) {
92 start = textMap_[fieldCode];
93 }
94 }
95
SetStart(std::string start)96 void MmsContentParam::SetStart(std::string start)
97 {
98 if (start.empty()) {
99 return;
100 }
101 uint8_t fieldCode = static_cast<uint8_t>(ContentParam::CT_P_START);
102 textMap_.insert(std::make_pair(fieldCode, start));
103 }
104
AddNormalField(uint8_t field,std::string value)105 bool MmsContentParam::AddNormalField(uint8_t field, std::string value)
106 {
107 if (textMap_.find(field) != textMap_.end()) {
108 TELEPHONY_LOGE(" add normal fail.");
109 return false;
110 }
111 textMap_.insert(std::make_pair(field, value));
112 return true;
113 }
114
GetNormalField(uint8_t field,std::string & value)115 bool MmsContentParam::GetNormalField(uint8_t field, std::string &value)
116 {
117 value = "";
118 if (textMap_.find(field) != textMap_.end()) {
119 value = textMap_[field];
120 }
121 return true;
122 }
123
GetParamMap()124 std::map<uint8_t, std::string> &MmsContentParam::GetParamMap()
125 {
126 return textMap_;
127 }
128 } // namespace Telephony
129 } // namespace OHOS
130