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