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 /**
17 * @addtogroup bluetooth
18 * @{
19 *
20 * @brief
21 *
22 */
23
24 /**
25 * @file map_mce_data_analyse.c
26 *
27 * @brief Defines map client service request data analyse object.
28 *
29 */
30 #include "map_mce_data_analyse.h"
31 #include <codecvt>
32 #include <cstring>
33 #include <fstream>
34 #include <iostream>
35 #include <locale>
36 #include <string>
37 #include "log.h"
38 #include "map_mce_xml.h"
39
40 namespace OHOS {
41 namespace bluetooth {
MceSplitString(const std::string & target,const std::string & filter)42 MceSplitString::MceSplitString(const std::string &target, const std::string &filter)
43 {
44 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
45 targetString_ = target;
46 filterString_ = filter;
47 count_ = 0;
48 maxCount_ = targetString_.size();
49 }
50
~MceSplitString()51 MceSplitString::~MceSplitString()
52 {
53 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
54 }
55
NextWord()56 std::string MceSplitString::NextWord()
57 {
58 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
59 int begin = count_;
60 for (; count_ < maxCount_; count_++) {
61 if (filterString_.find(targetString_[count_]) != std::string::npos) {
62 if (begin == count_) {
63 begin++;
64 } else {
65 break;
66 }
67 }
68 }
69 return targetString_.substr(begin, count_ - begin);
70 }
71
MceCombineNode()72 MceCombineNode::MceCombineNode()
73 {
74 stream_.str("");
75 }
76
~MceCombineNode()77 MceCombineNode::~MceCombineNode()
78 {
79 stream_.str("");
80 }
81
NodeBegin(std::string nodeName)82 void MceCombineNode::NodeBegin(std::string nodeName)
83 {
84 nodeNameList_.push_back(nodeName);
85 stream_ << "BEGIN:" << nodeName << "\r\n";
86 }
87
NodeEnd()88 void MceCombineNode::NodeEnd()
89 {
90 if (nodeNameList_.size() != 0) {
91 std::string nodeName = nodeNameList_.back();
92 stream_ << "END:" << nodeName << "\r\n";
93 nodeNameList_.pop_back();
94 }
95 }
96
AddParamStr(const std::string & param,const std::string & value)97 void MceCombineNode::AddParamStr(const std::string ¶m, const std::string &value)
98 {
99 stream_ << param << value << "\r\n";
100 }
101
AddText(const std::string & text)102 void MceCombineNode::AddText(const std::string &text)
103 {
104 stream_ << text << "\r\n";
105 }
106
GetCombineString() const107 std::string MceCombineNode::GetCombineString() const
108 {
109 return stream_.str();
110 }
111
MceBMessageNode()112 MceBMessageNode::MceBMessageNode()
113 {
114 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
115 }
116
MceBMessageNode(const std::list<std::string> & list,const std::string & name)117 MceBMessageNode::MceBMessageNode(const std::list<std::string> &list, const std::string &name)
118 {
119 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
120 MceConstructNode(list, name);
121 }
122
MceConstructNode(const std::list<std::string> & list,const std::string & name)123 void MceBMessageNode::MceConstructNode(const std::list<std::string> &list, const std::string &name)
124 {
125 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
126 wordList_ = list;
127 name_ = name;
128 }
129
~MceBMessageNode()130 MceBMessageNode::~MceBMessageNode()
131 {
132 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
133 }
134
GetNextChild()135 MceBMessageNode MceBMessageNode::GetNextChild()
136 {
137 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
138 std::list<std::string> nextNode;
139 std::string nextName = "";
140 std::string begin;
141 int beginNum;
142 int beginLength = strlen("BEGIN:");
143 int endLength = strlen("END:");
144
145 while (wordList_.size() != 0) {
146 begin = wordList_.front();
147 wordList_.pop_front();
148
149 if ((begin.size() >= static_cast<std::size_t>(beginLength)) &&
150 (begin.substr(0, static_cast<std::size_t>(beginLength)) == "BEGIN:")) {
151 nextName = begin.substr(beginLength);
152 break;
153 }
154 }
155
156 std::string end;
157 beginNum = 0;
158 MceBMessageNode node;
159 if (nextName == "") {
160 return node;
161 }
162 while (wordList_.size() != 0) {
163 end = wordList_.front();
164 wordList_.pop_front();
165 if ((end.size() >= static_cast<std::size_t>(beginLength)) &&
166 (end.substr(0, static_cast<std::size_t>(beginLength)) == "BEGIN:")) {
167 beginNum++;
168 }
169 if ((end.size() >= static_cast<std::size_t>(endLength)) &&
170 (end.substr(0, static_cast<std::size_t>(endLength)) == "END:")) {
171 if (beginNum == 0) {
172 node.MceConstructNode(nextNode, nextName);
173 break;
174 } else {
175 beginNum--;
176 }
177 }
178 nextNode.push_back(end); // do not put "BEGIN:" or "END:" to the list
179 }
180 return node;
181 }
182
GetNodeName() const183 std::string MceBMessageNode::GetNodeName() const
184 {
185 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
186 return name_;
187 }
188
GetNodeValue() const189 std::string MceBMessageNode::GetNodeValue() const
190 {
191 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
192 return value_;
193 }
194
GetParamValue(std::string param) const195 std::string MceBMessageNode::GetParamValue(std::string param) const
196 {
197 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
198 std::string value;
199 std::string curWold;
200 int beginNum;
201 std::string beginEnd;
202 int beginLength = strlen("BEGIN:");
203 int endLength = strlen("END:");
204
205 beginNum = 0;
206 for (auto it = wordList_.begin(); it != wordList_.end(); it++) {
207 curWold = *it;
208 if ((beginEnd.size() >= (std::size_t)beginLength) &&
209 (beginEnd.substr(0, (std::size_t)beginLength) == "BEGIN:")) {
210 beginNum++;
211 }
212 if ((beginEnd.size() >= (std::size_t)endLength) && (beginEnd.substr(0, (std::size_t)endLength) == "END:")) {
213 if (beginNum == 0) {
214 break;
215 } else {
216 beginNum--;
217 }
218 }
219 // not in the sub node
220 if ((beginNum == 0) && (curWold.size() >= param.size()) && (param == curWold.substr(0, param.size()))) {
221 value = curWold.substr(param.size());
222 break;
223 }
224 }
225 return value;
226 }
227
GetParamValueList(std::string param) const228 std::vector<std::string> MceBMessageNode::GetParamValueList(std::string param) const
229 {
230 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
231 std::string cWord;
232 std::string beginEnd;
233 std::string value;
234 std::vector<std::string> retValue;
235 int bNum = 0;
236 int eLength = strlen("END:");
237 int bLength = strlen("BEGIN:");
238 for (auto it = wordList_.begin(); it != wordList_.end(); it++) {
239 cWord = *it;
240 if ((beginEnd.size() >= (std::size_t)bLength) && (beginEnd.substr(0, (std::size_t)bLength) == "BEGIN:")) {
241 bNum++;
242 }
243 if ((beginEnd.size() >= (std::size_t)eLength) && (beginEnd.substr(0, (std::size_t)eLength) == "END:")) {
244 if (bNum == 0) {
245 break;
246 } else {
247 bNum--;
248 }
249 }
250 // not in the sub node
251 if ((bNum == 0) && (cWord.size() >= param.size()) && (param == cWord.substr(0, param.size()))) {
252 value = cWord.substr(param.size());
253 retValue.push_back(value);
254 }
255 }
256 return retValue;
257 }
258
GetSize() const259 int MceBMessageNode::GetSize() const
260 {
261 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
262 return wordList_.size();
263 }
264
MceBmessageParamMakeStringObject(const IProfileBMessageStruct & param)265 MceBmessageParamMakeStringObject::MceBmessageParamMakeStringObject(const IProfileBMessageStruct ¶m)
266 :msgParam_(param)
267 {
268 combineNode_.NodeBegin("BMSG");
269 MakeBMessageProperty();
270 if (msgParam_.originator_.size() > 0) {
271 MakeVcard(msgParam_.originator_);
272 }
273 if (param.envelope_.maxLevelOfEnvelope_ > 0) {
274 MakeRecipientLevel1();
275 }
276 combineNode_.NodeEnd(); // BMSG
277 }
278
~MceBmessageParamMakeStringObject()279 MceBmessageParamMakeStringObject::~MceBmessageParamMakeStringObject()
280 {}
281
GetStringObject() const282 std::string MceBmessageParamMakeStringObject::GetStringObject() const
283 {
284 return combineNode_.GetCombineString();
285 }
286
MakeBMessageProperty()287 void MceBmessageParamMakeStringObject::MakeBMessageProperty()
288 {
289 combineNode_.AddParamStr("VERSION:", msgParam_.version_property);
290 switch (msgParam_.readstatus_property) {
291 case MapMessageStatus::READ:
292 combineNode_.AddParamStr("STATUS:", "READ");
293 break;
294 case MapMessageStatus::UNREAD:
295 combineNode_.AddParamStr("STATUS:", "UNREAD");
296 break;
297 default:
298 combineNode_.AddParamStr("STATUS:", "");
299 break;
300 }
301 switch (msgParam_.type_property) {
302 case MapMessageType::EMAIL:
303 combineNode_.AddParamStr("TYPE:", "EMAIL");
304 break;
305 case MapMessageType::SMS_GSM:
306 combineNode_.AddParamStr("TYPE:", "SMS_GSM");
307 break;
308 case MapMessageType::SMS_CDMA:
309 combineNode_.AddParamStr("TYPE:", "SMS_CDMA");
310 break;
311 case MapMessageType::MMS:
312 combineNode_.AddParamStr("TYPE:", "MMS");
313 break;
314 case MapMessageType::IM:
315 combineNode_.AddParamStr("TYPE:", "IM");
316 break;
317 default:
318 combineNode_.AddParamStr("TYPE:", "");
319 break;
320 }
321
322 if (msgParam_.folder_property != u"") {
323 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
324 std::string utf8Handle = converter.to_bytes(msgParam_.folder_property);
325 combineNode_.AddParamStr("FOLDER:", utf8Handle);
326 }
327 if ((msgParam_.version_property == "1.1") && (msgParam_.extendeddata_property != "")) {
328 combineNode_.AddParamStr("EXTENDEDDATA:", msgParam_.extendeddata_property); // extended data only V1.1
329 }
330 }
331
MakeRecipientLevel1()332 void MceBmessageParamMakeStringObject::MakeRecipientLevel1()
333 {
334 combineNode_.NodeBegin("BENV");
335 if (msgParam_.envelope_.recipientLevel1_.size() != 0) {
336 MakeVcard(msgParam_.envelope_.recipientLevel1_);
337 }
338
339 if (msgParam_.envelope_.maxLevelOfEnvelope_ > 1) {
340 MakeRecipientLevel2();
341 } else {
342 MakeMsgBodyProperty();
343 }
344 combineNode_.NodeEnd(); // BENV
345 }
346
MakeRecipientLevel2()347 void MceBmessageParamMakeStringObject::MakeRecipientLevel2()
348 {
349 combineNode_.NodeBegin("BENV");
350 if (msgParam_.envelope_.recipientLevel2_.size() != 0) {
351 MakeVcard(msgParam_.envelope_.recipientLevel2_);
352 }
353 if (msgParam_.envelope_.maxLevelOfEnvelope_ > MCE_RECIPIENT_LEVEL2) {
354 MakeRecipientLevel3();
355 } else {
356 MakeMsgBodyProperty();
357 }
358 combineNode_.NodeEnd(); // BENV
359 }
360
MakeRecipientLevel3()361 void MceBmessageParamMakeStringObject::MakeRecipientLevel3()
362 {
363 combineNode_.NodeBegin("BENV");
364 if (msgParam_.envelope_.recipientLevel3_.size() != 0) {
365 MakeVcard(msgParam_.envelope_.recipientLevel3_);
366 }
367 MakeMsgBodyProperty();
368 combineNode_.NodeEnd(); // BENV
369 }
370
MakeMsgBodyProperty()371 void MceBmessageParamMakeStringObject::MakeMsgBodyProperty()
372 {
373 combineNode_.NodeBegin("BBODY");
374 if (msgParam_.envelope_.msgBody_.bodyPartID != "") {
375 combineNode_.AddParamStr("PARTID:", msgParam_.envelope_.msgBody_.bodyPartID);
376 }
377 if (msgParam_.envelope_.msgBody_.body_encoding != "") {
378 combineNode_.AddParamStr("ENCODING:", msgParam_.envelope_.msgBody_.body_encoding);
379 }
380 if (msgParam_.envelope_.msgBody_.body_charset != "") {
381 combineNode_.AddParamStr("CHARSET:", msgParam_.envelope_.msgBody_.body_charset);
382 }
383 if (msgParam_.envelope_.msgBody_.body_language != "") {
384 combineNode_.AddParamStr("LANGUAGE:", msgParam_.envelope_.msgBody_.body_language);
385 }
386 combineNode_.AddParamStr("LENGTH:", std::to_string(msgParam_.envelope_.msgBody_.body_content_length));
387 MakeMsgBodyText();
388 combineNode_.NodeEnd(); // BBODY
389 }
390
MakeMsgBodyText()391 void MceBmessageParamMakeStringObject::MakeMsgBodyText()
392 {
393 combineNode_.NodeBegin("MSG");
394 // <bmessage-body-content>
395 combineNode_.AddText(msgParam_.envelope_.msgBody_.body_content);
396 combineNode_.NodeEnd(); // MSG
397 }
398
MakeVcard(std::vector<IProfileMapVcard> vcard)399 void MceBmessageParamMakeStringObject::MakeVcard(std::vector<IProfileMapVcard> vcard)
400 {
401 IProfileMapVcard data;
402 for (auto it = vcard.begin(); it != vcard.end(); it++) {
403 data = *it;
404 combineNode_.NodeBegin("VCARD");
405 combineNode_.AddParamStr("VERSION:", data.VERSION);
406 if (data.N != "") {
407 combineNode_.AddParamStr("N:", data.N);
408 }
409 if (data.VERSION == "3.0") {
410 if (data.FN != "") {
411 combineNode_.AddParamStr("FN:", data.FN);
412 }
413 }
414 if (data.TEL.size() != 0) {
415 for (auto itTel = data.TEL.begin(); itTel != data.TEL.end(); itTel++) {
416 combineNode_.AddParamStr("TEL:", *itTel);
417 }
418 }
419 if (data.EMAIL.size() != 0) {
420 for (auto itEmail = data.EMAIL.begin(); itEmail != data.EMAIL.end(); itEmail++) {
421 combineNode_.AddParamStr("EMAIL:", *itEmail);
422 }
423 }
424 if ((msgParam_.version_property == "1.1") && (data.X_BT_UID.size() != 0)) {
425 for (auto itUid = data.X_BT_UID.begin(); itUid != data.X_BT_UID.end(); itUid++) {
426 combineNode_.AddParamStr("X-BT-UID:", *itUid);
427 }
428 }
429 if ((msgParam_.version_property == "1.1") && (data.X_BT_UCI.size() != 0)) {
430 for (auto itUci = data.X_BT_UCI.begin(); itUci != data.X_BT_UCI.end(); itUci++) {
431 combineNode_.AddParamStr("X-BT-UCI:", *itUci);
432 }
433 }
434 combineNode_.NodeEnd();
435 }
436 }
437
MceBmessageParamAnalyser(const std::string & object)438 MceBmessageParamAnalyser::MceBmessageParamAnalyser(const std::string &object)
439 {
440 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
441 msgStr_ = object;
442 }
443
StartAnalyse()444 void MceBmessageParamAnalyser::StartAnalyse()
445 {
446 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
447 MceBMessageNode nodeLevel1;
448 MceBMessageNode nodeLevel2;
449 MceBMessageNode nodeLevel3;
450
451 // init
452 bMsgParamStruct_.originator_.clear();
453 bMsgParamStruct_.envelope_.recipientLevel1_.clear();
454 bMsgParamStruct_.envelope_.recipientLevel2_.clear();
455 bMsgParamStruct_.envelope_.recipientLevel3_.clear();
456 bMsgParamStruct_.envelope_.msgBody_.body_content = "";
457
458 MakeWordList();
459 MceBMessageNode rootNode(wordList_, "BMSG");
460 PickUpBMessageProperty(rootNode);
461
462 nodeLevel1 = rootNode.GetNextChild();
463 while (int(nodeLevel1.GetSize()) != 0) {
464 if (nodeLevel1.GetNodeName() == "VCARD") {
465 PickUpBMessagePropertyOriginator(nodeLevel1);
466 } else if (nodeLevel1.GetNodeName() == "BENV") {
467 nodeLevel2 = PickUpRecipientLevel1(nodeLevel1);
468 } else {
469 // error
470 LOG_ERROR("%{public}s BMessage format error!", __PRETTY_FUNCTION__);
471 }
472 nodeLevel1 = rootNode.GetNextChild();
473 }
474
475 if (nodeLevel2.GetSize() != 0) {
476 nodeLevel3 = PickUpRecipientLevel2(nodeLevel2);
477 }
478
479 if (nodeLevel3.GetSize() != 0) {
480 PickUpRecipientLevel3(nodeLevel3);
481 }
482
483 PickUpMsgBodyProperty();
484 PickUpMsgBodyText();
485 }
486
MakeWordList()487 void MceBmessageParamAnalyser::MakeWordList()
488 {
489 std::string filter("\r\n");
490 MceSplitString stringData(msgStr_, filter);
491 std::string word = stringData.NextWord();
492
493 wordList_.clear();
494
495 // make word list
496 if (word == "BEGIN:BMSG") {
497 word = stringData.NextWord();
498 while (word != "END:BMSG") {
499 if (word != "") {
500 wordList_.push_back(word);
501 word = stringData.NextWord();
502 } else {
503 // format error clear list
504 wordList_.clear();
505 LOG_ERROR("%{public}s not find END:BMSG", __PRETTY_FUNCTION__);
506 break;
507 }
508 }
509 } else {
510 LOG_ERROR("%{public}s not find BEGIN:BMSG", __PRETTY_FUNCTION__);
511 }
512 }
513
~MceBmessageParamAnalyser()514 MceBmessageParamAnalyser::~MceBmessageParamAnalyser()
515 {
516 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
517 }
518
GetMsgStruct() const519 IProfileBMessageStruct MceBmessageParamAnalyser::GetMsgStruct() const
520 {
521 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
522 return bMsgParamStruct_;
523 }
524
GetFirstChildNode()525 MceBMessageNode MceBmessageParamAnalyser::GetFirstChildNode()
526 {
527 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
528 MakeWordList();
529 MceBMessageNode fistNode(wordList_, "BMSG");
530 return fistNode;
531 }
532
GetSize() const533 int MceBmessageParamAnalyser::GetSize() const
534 {
535 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
536 return wordList_.size();
537 }
538
GetMsgText()539 std::string MceBmessageParamAnalyser::GetMsgText()
540 {
541 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
542 PickUpMsgBodyText();
543 return bMsgParamStruct_.envelope_.msgBody_.body_content;
544 }
545
PickUpBMessageProperty(const MceBMessageNode & node)546 void MceBmessageParamAnalyser::PickUpBMessageProperty(const MceBMessageNode &node)
547 {
548 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
549 std::string tempStr;
550
551 bMsgParamStruct_.version_property = node.GetParamValue("VERSION:");
552 bMsgParamStruct_.readstatus_property =
553 MceUtilityConvertFormat::ConvertStringToMapMessageStatus(node.GetParamValue("STATUS:"));
554 bMsgParamStruct_.extendeddata_property = node.GetParamValue("EXTENDEDDATA:");
555 // "FOLDER:"
556 tempStr = node.GetParamValue("FOLDER:");
557 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
558 bMsgParamStruct_.folder_property = converter.from_bytes(tempStr);
559 // "TYPE:"
560 tempStr = node.GetParamValue("TYPE:");
561 bMsgParamStruct_.type_property = MceUtilityConvertFormat::ConvertStringToMessageType(tempStr);
562 }
563
PickUpBMessagePropertyOriginator(const MceBMessageNode & node)564 void MceBmessageParamAnalyser::PickUpBMessagePropertyOriginator(const MceBMessageNode &node)
565 {
566 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
567 IProfileMapVcard vcard;
568 vcard.VERSION = node.GetParamValue("VERSION:"); // shall be included
569 vcard.N = node.GetParamValue("N:"); // shall be included
570 vcard.TEL = node.GetParamValueList("TEL:"); // may be used
571 vcard.EMAIL = node.GetParamValueList("EMAIL:"); // may be used
572 vcard.X_BT_UID = node.GetParamValueList("X-BT-UID:"); // bmsg V1.1
573 vcard.X_BT_UCI = node.GetParamValueList("X-BT-UCI:"); // bmsg V1.1
574 vcard.FN = node.GetParamValue("FN:"); // vcard 3.0 , shall be included
575
576 if (bMsgParamStruct_.originator_.size() == 0) {
577 bMsgParamStruct_.originator_.push_back(vcard);
578 } else {
579 // error , only one originator_
580 LOG_ERROR("%{public}s execute", __PRETTY_FUNCTION__);
581 }
582 }
583
PickUpRecipientLevel1(MceBMessageNode & node)584 MceBMessageNode MceBmessageParamAnalyser::PickUpRecipientLevel1(MceBMessageNode &node)
585 {
586 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
587 MceBMessageNode nodeLevelXPlus1;
588 MceBMessageNode nexLevelRecipient;
589 IProfileMapVcard vcard1;
590
591 if (node.GetNodeName() != "BENV") {
592 return nexLevelRecipient;
593 }
594
595 bMsgParamStruct_.envelope_.maxLevelOfEnvelope_ = MCE_RECIPIENT_LEVEL1;
596 nodeLevelXPlus1 = node.GetNextChild();
597 while (int(nodeLevelXPlus1.GetSize()) != 0) {
598 if (nodeLevelXPlus1.GetNodeName() == "VCARD") {
599 vcard1.VERSION = nodeLevelXPlus1.GetParamValue("VERSION:"); // shall be included
600 vcard1.N = nodeLevelXPlus1.GetParamValue("N:"); // shall be included
601 vcard1.TEL = nodeLevelXPlus1.GetParamValueList("TEL:"); // may be used
602 vcard1.EMAIL = nodeLevelXPlus1.GetParamValueList("EMAIL:"); // may be used
603 vcard1.X_BT_UID = nodeLevelXPlus1.GetParamValueList("X-BT-UID:"); // bmsg V1.1
604 vcard1.X_BT_UCI = nodeLevelXPlus1.GetParamValueList("X-BT-UCI:"); // bmsg V1.1
605 vcard1.FN = nodeLevelXPlus1.GetParamValue("FN:"); // vcard 3.0 , shall be included
606 bMsgParamStruct_.envelope_.recipientLevel1_.push_back(vcard1);
607 }
608 if ((nodeLevelXPlus1.GetNodeName() == "BBODY") && (msgNode_.GetSize() == 0)) {
609 msgNode_ = nodeLevelXPlus1;
610 }
611 if ((nodeLevelXPlus1.GetNodeName() == "BENV") && (nexLevelRecipient.GetSize() == 0)) {
612 nexLevelRecipient = nodeLevelXPlus1;
613 }
614 nodeLevelXPlus1 = node.GetNextChild();
615 }
616 return nexLevelRecipient;
617 }
618
PickUpRecipientLevel2(MceBMessageNode & node)619 MceBMessageNode MceBmessageParamAnalyser::PickUpRecipientLevel2(MceBMessageNode &node)
620 {
621 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
622 MceBMessageNode nodeLevelXPlus2;
623 MceBMessageNode nexLevelRecipient;
624 IProfileMapVcard vcard2;
625
626 if (node.GetNodeName() != "BENV") {
627 return nexLevelRecipient;
628 }
629
630 bMsgParamStruct_.envelope_.maxLevelOfEnvelope_ = MCE_RECIPIENT_LEVEL2;
631 nodeLevelXPlus2 = node.GetNextChild();
632 while (int(nodeLevelXPlus2.GetSize()) != 0) {
633 if (nodeLevelXPlus2.GetNodeName() == "VCARD") {
634 vcard2.VERSION = nodeLevelXPlus2.GetParamValue("VERSION:"); // shall be included
635 vcard2.N = nodeLevelXPlus2.GetParamValue("N:"); // shall be included
636 vcard2.TEL = nodeLevelXPlus2.GetParamValueList("TEL:"); // may be used
637 vcard2.EMAIL = nodeLevelXPlus2.GetParamValueList("EMAIL:"); // may be used
638 vcard2.X_BT_UID = nodeLevelXPlus2.GetParamValueList("X-BT-UID:"); // bmsg V1.1
639 vcard2.X_BT_UCI = nodeLevelXPlus2.GetParamValueList("X-BT-UCI:"); // bmsg V1.1
640 vcard2.FN = nodeLevelXPlus2.GetParamValue("FN:"); // vcard 3.0 , shall be included
641 bMsgParamStruct_.envelope_.recipientLevel2_.push_back(vcard2);
642 }
643 if ((nodeLevelXPlus2.GetNodeName() == "BBODY") && (msgNode_.GetSize() == 0)) {
644 msgNode_ = nodeLevelXPlus2;
645 }
646 if ((nodeLevelXPlus2.GetNodeName() == "BENV") && (nexLevelRecipient.GetSize() == 0)) {
647 nexLevelRecipient = nodeLevelXPlus2;
648 }
649 nodeLevelXPlus2 = node.GetNextChild();
650 }
651 return nexLevelRecipient;
652 }
653
PickUpRecipientLevel3(MceBMessageNode & node)654 void MceBmessageParamAnalyser::PickUpRecipientLevel3(MceBMessageNode &node)
655 {
656 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
657 MceBMessageNode nodeLevelXPlus3;
658 IProfileMapVcard vcard3;
659
660 if (node.GetNodeName() != "BENV") {
661 return;
662 }
663
664 bMsgParamStruct_.envelope_.maxLevelOfEnvelope_ = MCE_RECIPIENT_LEVEL3;
665 nodeLevelXPlus3 = node.GetNextChild();
666 while (int(nodeLevelXPlus3.GetSize()) != 0) {
667 if (nodeLevelXPlus3.GetNodeName() == "VCARD") {
668 vcard3.VERSION = nodeLevelXPlus3.GetParamValue("VERSION:"); // shall be included
669 vcard3.N = nodeLevelXPlus3.GetParamValue("N:"); // shall be included
670 vcard3.TEL = nodeLevelXPlus3.GetParamValueList("TEL:"); // may be used
671 vcard3.EMAIL = nodeLevelXPlus3.GetParamValueList("EMAIL:"); // may be used
672 vcard3.X_BT_UID = nodeLevelXPlus3.GetParamValueList("X-BT-UID:"); // bmsg V1.1
673 vcard3.X_BT_UCI = nodeLevelXPlus3.GetParamValueList("X-BT-UCI:"); // bmsg V1.1
674 vcard3.FN = nodeLevelXPlus3.GetParamValue("FN:"); // vcard 3.0 , shall be included
675 bMsgParamStruct_.envelope_.recipientLevel3_.push_back(vcard3);
676 }
677 if (nodeLevelXPlus3.GetNodeName() == "BBODY") {
678 msgNode_ = nodeLevelXPlus3;
679 }
680 nodeLevelXPlus3 = node.GetNextChild();
681 }
682 }
683
PickUpMsgBodyProperty()684 void MceBmessageParamAnalyser::PickUpMsgBodyProperty()
685 {
686 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
687 if (msgNode_.GetSize() != 0) {
688 bMsgParamStruct_.envelope_.msgBody_.bodyPartID = msgNode_.GetParamValue("PARTID:");
689 bMsgParamStruct_.envelope_.msgBody_.body_encoding = msgNode_.GetParamValue("ENCODING:");
690 bMsgParamStruct_.envelope_.msgBody_.body_charset = msgNode_.GetParamValue("CHARSET:");
691 bMsgParamStruct_.envelope_.msgBody_.body_language = msgNode_.GetParamValue("LANGUAGE:");
692 std::string tempStr = msgNode_.GetParamValue("LENGTH:");
693 bMsgParamStruct_.envelope_.msgBody_.body_content_length = atoi(tempStr.c_str());
694 }
695 }
696
PickUpMsgBodyText()697 void MceBmessageParamAnalyser::PickUpMsgBodyText()
698 {
699 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
700 int next = 1;
701 int msgBegin = 0;
702 int msgEnd = 0;
703 int endMsgLength = strlen("END:MSG");
704 int beginMsgLength = strlen("BEGIN:MSG");
705
706 // pickup the msg text
707 for (int i = 0; i < int(msgStr_.size()); i++) {
708 if (msgBegin == 0) {
709 if (msgStr_.substr(i, beginMsgLength) == "BEGIN:MSG") {
710 i = i + beginMsgLength + 1;
711 msgBegin = i;
712 }
713 if ((msgBegin != 0) && ((msgStr_.substr(i, 1) == "\r") || (msgStr_.substr(i, 1) == "\n"))) {
714 i++;
715 msgBegin = i;
716 }
717 continue;
718 }
719 if (msgStr_.substr(i, endMsgLength) == "END:MSG") {
720 next = 1;
721 if ((msgStr_.substr(i - next - 1, 1) == "\r") || (msgStr_.substr(i - next - 1, 1) == "\n")) {
722 next++;
723 }
724 msgEnd = i - next;
725 if (msgEnd > msgBegin) {
726 bMsgParamStruct_.envelope_.msgBody_.body_content = msgStr_.substr(msgBegin, msgEnd - msgBegin);
727 } else {
728 bMsgParamStruct_.envelope_.msgBody_.body_content = "";
729 }
730 break;
731 }
732 }
733 }
734
PickUpParticipant(IProfileParticipant & data,const MceXmlNode & node)735 void MceTypesConversationListing::PickUpParticipant(IProfileParticipant &data, const MceXmlNode &node)
736 {
737 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
738 data.uci = node.Attribute("uci").AsString();
739 data.display_name = node.Attribute("display_name").AsString();
740 data.chat_state = node.Attribute("chat_state").AsString();
741 data.last_activity = node.Attribute("last_activity").AsString();
742 data.x_bt_uid = node.Attribute("x_bt_uid").AsString();
743 data.name = node.Attribute("name").AsString();
744 data.presence_availability = node.Attribute("presence_availability").AsString();
745 data.presence_text = node.Attribute("presence_text").AsString();
746 data.priority = node.Attribute("priority").AsString();
747 }
748
PickUpConversation(IProfileConversation & data,const MceXmlNode & node)749 void MceTypesConversationListing::PickUpConversation(IProfileConversation &data, const MceXmlNode &node)
750 {
751 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
752 IProfileParticipant participants;
753
754 data.id = node.Attribute("id").AsString();
755 data.name = node.Attribute("name").AsString();
756 data.last_activity = node.Attribute("last_activity").AsString();
757 data.read_status = node.Attribute("read_status").AsString();
758 data.version_counter = node.Attribute("version_counter").AsString();
759 data.summary = node.Attribute("summary").AsString();
760
761 for (MceXmlNode covNode = node.FirstChild(); !covNode.Empty(); covNode = covNode.NextSibling()) {
762 std::string checkName(covNode.Name());
763 if (checkName == "participant") {
764 PickUpParticipant(participants, covNode);
765 // push to vector list
766 data.participantList_.push_back(participants);
767 }
768 }
769 }
770
BuildObjectData(const IProfileConversationListingParamStruct & stringParam,const std::string & stringObject)771 int MceTypesConversationListing::BuildObjectData(
772 const IProfileConversationListingParamStruct &stringParam, const std::string &stringObject)
773 {
774 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
775 int ret = RET_NO_ERROR;
776 conversationListingParam_ = stringParam;
777 conversationListingObject_ = stringObject;
778 IProfileConversation converOutline;
779
780 MceXmlDoc xmlDoc {};
781 xmlDoc.LoadString(conversationListingObject_.c_str());
782 MceXmlNode rootNode = xmlDoc.Child("MAP-convo-listing");
783
784 // init
785 conversationList_.clear();
786
787 if (!rootNode.Empty()) {
788 // version
789 conversationListingParam_.Version = rootNode.Attribute("version").AsString();
790
791 for (MceXmlNode covNode = rootNode.FirstChild(); !covNode.Empty(); covNode = covNode.NextSibling()) {
792 std::string checkName(covNode.Name());
793 if (checkName == "conversation") {
794 converOutline.participantList_.clear();
795 PickUpConversation(converOutline, covNode);
796 // push to vector list
797 conversationList_.push_back(converOutline);
798 }
799 }
800 }
801 return ret;
802 }
803
GetList() const804 std::vector<IProfileConversation> MceTypesConversationListing::GetList() const
805 {
806 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
807 return conversationList_;
808 }
809
GetParam() const810 IProfileConversationListingParamStruct MceTypesConversationListing::GetParam() const
811 {
812 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
813 return conversationListingParam_;
814 }
815
GetStringObject() const816 std::string MceTypesConversationListing::GetStringObject() const
817 {
818 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
819 return conversationListingObject_;
820 }
821
PickupOutlineParam(IProfileMessageOutline & msgOutline,const MceXmlNode & msgNode)822 void MceTypesMessagesListing::PickupOutlineParam(IProfileMessageOutline &msgOutline, const MceXmlNode &msgNode)
823 {
824 // Attribute
825 msgOutline.handle = msgNode.Attribute("handle").AsString();
826 msgOutline.subject = msgNode.Attribute("subject").AsString();
827 msgOutline.datetime = msgNode.Attribute("datetime").AsString();
828 msgOutline.sender_name = msgNode.Attribute("sender_name").AsString();
829 msgOutline.sender_addressing = msgNode.Attribute("sender_addressing").AsString();
830 msgOutline.replyto_addressing = msgNode.Attribute("replyto_addressing").AsString();
831 msgOutline.recipient_name = msgNode.Attribute("recipient_name").AsString();
832 msgOutline.recipient_addressing = msgNode.Attribute("recipient_addressing").AsString();
833
834 // "Type"
835 std::string tempStr = msgNode.Attribute("type").AsString();
836 msgOutline.type = MceUtilityConvertFormat::ConvertStringToMessageType(tempStr);
837
838 // "receptionStatus"
839 tempStr = msgNode.Attribute("receptionStatus").AsString();
840 msgOutline.receptionStatus = MceUtilityConvertFormat::ConvertStringToMsgReceptionStatus(tempStr);
841
842 msgOutline.size = msgNode.Attribute("size").AsInt();
843 msgOutline.attachment_size = msgNode.Attribute("attachment_size").AsInt();
844 msgOutline.text = MceUtilityConvertFormat::ConvertStringToMapBoolType(msgNode.Attribute("text").AsString());
845 msgOutline.read =
846 MceUtilityConvertFormat::ConvertYesNoStringToMapMessageStatus(msgNode.Attribute("read").AsString());
847 msgOutline.sent = MceUtilityConvertFormat::ConvertStringToMapBoolType(msgNode.Attribute("sent").AsString());
848 msgOutline.protected_ =
849 MceUtilityConvertFormat::ConvertStringToMapBoolType(msgNode.Attribute("protected").AsString());
850 msgOutline.priority = MceUtilityConvertFormat::ConvertStringToMapBoolType(msgNode.Attribute("priority").AsString());
851 // "delivery_status" V1.1
852 tempStr = msgNode.Attribute("delivery_status").AsString();
853 msgOutline.delivery_status = MceUtilityConvertFormat::ConvertStringToMsgDeliveryStatus(tempStr);
854
855 msgOutline.conversation_id = msgNode.Attribute("conversation_id").AsString();
856 msgOutline.conversation_name = msgNode.Attribute("conversation_name").AsString();
857
858 // "direction" V1.1
859 tempStr = msgNode.Attribute("direction").AsString();
860 msgOutline.direction = MceUtilityConvertFormat::ConvertStringToMsgDirection(tempStr);
861
862 // mime types
863 msgOutline.attachment_mime_types = msgNode.Attribute("attachment_mime_types").AsString();
864 }
865
BuildObjectData(const IProfileMessagesListingParamStruct & stringParam,const std::string & stringObject)866 int MceTypesMessagesListing::BuildObjectData(
867 const IProfileMessagesListingParamStruct &stringParam, const std::string &stringObject)
868 {
869 LOG_INFO("%{public}s enter", __PRETTY_FUNCTION__);
870 int ret = RET_NO_ERROR;
871 IProfileMessageOutline msgOutline;
872 std::string tempStr;
873 messagesListingParam_ = stringParam;
874 MessagesListingObject_ = stringObject;
875 MceXmlDoc xmlDoc {};
876 xmlDoc.LoadString(MessagesListingObject_.c_str());
877 MceXmlNode rootNode = xmlDoc.Child("MAP-msg-listing");
878 if (!rootNode.Empty()) {
879 messagesListingParam_.Version = rootNode.Attribute("version").AsString(); // version
880 for (MceXmlNode msgNode = rootNode.FirstChild(); !msgNode.Empty(); msgNode = msgNode.NextSibling()) {
881 PickupOutlineParam(msgOutline, msgNode);
882 // push to vector list
883 messageList_.push_back(msgOutline);
884 }
885 }
886 LOG_INFO("%{public}s end, msglist size = %{public}d", __PRETTY_FUNCTION__, int(messageList_.size()));
887 return ret;
888 }
889
GetList() const890 std::vector<IProfileMessageOutline> MceTypesMessagesListing::GetList() const
891 {
892 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
893 return messageList_;
894 }
895
GetParam() const896 IProfileMessagesListingParamStruct MceTypesMessagesListing::GetParam() const
897 {
898 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
899 return messagesListingParam_;
900 }
901
GetStringObject() const902 std::string MceTypesMessagesListing::GetStringObject() const
903 {
904 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
905 return MessagesListingObject_;
906 }
907
BuildObjectData(const std::string & stringObject)908 int MceTypesBMessage::BuildObjectData(const std::string &stringObject)
909 {
910 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
911 int ret = RET_NO_ERROR;
912 bMessageObject_ = stringObject;
913 MceBmessageParamAnalyser analyser(stringObject);
914 analyser.StartAnalyse();
915 bMessageData_ = analyser.GetMsgStruct();
916 return ret;
917 }
918
SetFractionDeliver(MapFractionDeliverType value)919 int MceTypesBMessage::SetFractionDeliver(MapFractionDeliverType value)
920 {
921 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
922 FractionDeliver = value;
923 return RET_NO_ERROR;
924 }
925
GetFractionDeliver() const926 MapFractionDeliverType MceTypesBMessage::GetFractionDeliver() const
927 {
928 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
929 return FractionDeliver;
930 }
931
GetBMessageData() const932 IProfileBMessageStruct MceTypesBMessage::GetBMessageData() const
933 {
934 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
935 return bMessageData_;
936 }
937
GetBmessageObject() const938 std::string MceTypesBMessage::GetBmessageObject() const
939 {
940 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
941 return bMessageObject_;
942 }
943
BuildObjectData(const uint8_t & masInstanceId,const std::string & stringObject)944 int MceTypesEventReport::BuildObjectData(const uint8_t &masInstanceId, const std::string &stringObject)
945 {
946 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
947 eventReportParam_.eventReportStringObject_ = stringObject;
948 eventReportParam_.masInstanceId_ = masInstanceId;
949
950 MceXmlDoc xmlDoc {};
951 xmlDoc.LoadString(eventReportParam_.eventReportStringObject_.c_str());
952 MceXmlNode rootNode = xmlDoc.Child("MAP-event-report");
953 if (!rootNode.Empty()) {
954 eventReportParam_.version = rootNode.Attribute("version").AsString(); // version
955 MceXmlNode eventNode = rootNode.FirstChild();
956 if (!eventNode.Empty()) {
957 if (eventNode.Name() == "event") {
958 std::string tempStr;
959 eventReportParam_.type = eventNode.Attribute("type").AsString();
960 eventReportParam_.handle = eventNode.Attribute("handle").AsString();
961 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
962 eventReportParam_.folder = converter.from_bytes(eventNode.Attribute("folder").AsString());
963 eventReportParam_.old_folder = converter.from_bytes(eventNode.Attribute("old_folder").AsString());
964 // "Type"
965 tempStr = eventNode.Attribute("msg_type").AsString();
966 eventReportParam_.msg_type = MceUtilityConvertFormat::ConvertStringToMessageType(tempStr);
967 eventReportParam_.datetime = eventNode.Attribute("datetime").AsString();
968 eventReportParam_.subject = eventNode.Attribute("subject").AsString();
969 eventReportParam_.sender_name = eventNode.Attribute("sender_name").AsString();
970 // Value "yes" is high priority; "no" is not of high priority.
971 eventReportParam_.priority =
972 MceUtilityConvertFormat::ConvertStringToMapBoolType(eventNode.Attribute("priority").AsString());
973 eventReportParam_.conversation_name = eventNode.Attribute("conversation_name").AsString();
974 eventReportParam_.conversation_id = eventNode.Attribute("conversation_id").AsString();
975 eventReportParam_.presence_availability = eventNode.Attribute("presence_availability").AsString();
976 eventReportParam_.presence_text = eventNode.Attribute("presence_text").AsString();
977 eventReportParam_.last_activity = eventNode.Attribute("last_activity").AsString();
978 eventReportParam_.chat_state = eventNode.Attribute("chat_state").AsString();
979 // Shall be used only if the event “type” is “NewMessage” or “ReadStatusChanged”.
980 eventReportParam_.read_status = MceUtilityConvertFormat::ConvertYesNoStringToMapMessageStatus(
981 eventNode.Attribute("read_status").AsString());
982 // be used only if the event “type” is “MessageExtendedDataChanged”.
983 eventReportParam_.extended_data = eventNode.Attribute("extended_data").AsString();
984 eventReportParam_.participant_uci = eventNode.Attribute("participant_uci").AsString();
985 eventReportParam_.contact_uid = eventNode.Attribute("contact_uid").AsString();
986 }
987 }
988 }
989 return RET_NO_ERROR;
990 }
991
GetParam() const992 IProfileMapEventReport MceTypesEventReport::GetParam() const
993 {
994 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
995 return eventReportParam_;
996 }
997
GetStringObject() const998 std::string MceTypesEventReport::GetStringObject() const
999 {
1000 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1001 return eventReportParam_.eventReportStringObject_;
1002 }
1003
BuildObjectData(const std::string & stringObject)1004 int MceTypesFolderListing::BuildObjectData(const std::string &stringObject)
1005 {
1006 LOG_INFO("%{public}s execute", __PRETTY_FUNCTION__);
1007
1008 MceXmlDoc xmlDoc {};
1009 xmlDoc.LoadString(stringObject.c_str());
1010 MceXmlNode rootNode = xmlDoc.Child("folder-listing");
1011 if (!rootNode.Empty()) {
1012 version_ = rootNode.Attribute("version").AsString(); // version
1013 std::string folderName;
1014 for (MceXmlNode msgNode = rootNode.FirstChild(); !msgNode.Empty(); msgNode = msgNode.NextSibling()) {
1015 if (msgNode.Name() == "folder") {
1016 folderName = msgNode.Attribute("name").AsString();
1017 // push to vector list
1018 folderNameList_.push_back(folderName);
1019 }
1020 }
1021 }
1022
1023 return RET_NO_ERROR;
1024 }
1025
GetList() const1026 std::vector<std::string> MceTypesFolderListing::GetList() const
1027 {
1028 return folderNameList_;
1029 }
1030
GetVersion() const1031 std::string MceTypesFolderListing::GetVersion() const
1032 {
1033 return version_;
1034 }
1035
ConvertStringToMessageType(const std::string & str)1036 MapMessageType MceUtilityConvertFormat::ConvertStringToMessageType(const std::string &str)
1037 {
1038 MapMessageType type;
1039
1040 if (str == "SMS_GSM") {
1041 type = MapMessageType::SMS_GSM;
1042 } else if (str == "SMS_CDMA") {
1043 type = MapMessageType::SMS_CDMA;
1044 } else if (str == "MMS") {
1045 type = MapMessageType::MMS;
1046 } else if (str == "EMAIL") {
1047 type = MapMessageType::EMAIL;
1048 } else if (str == "IM") {
1049 type = MapMessageType::IM;
1050 } else {
1051 // error
1052 type = MapMessageType::INVALID;
1053 LOG_INFO("%{public}s INVALID", __PRETTY_FUNCTION__);
1054 }
1055 return type;
1056 }
1057
ConvertStringToMsgDirection(const std::string & str)1058 MapMsgDirection MceUtilityConvertFormat::ConvertStringToMsgDirection(const std::string &str)
1059 {
1060 MapMsgDirection type;
1061
1062 if (str == "incoming") {
1063 type = MapMsgDirection::INCOMING;
1064 } else if (str == "outgoing") {
1065 type = MapMsgDirection::OUTGOING;
1066 } else if (str == "outgoingdraft") {
1067 type = MapMsgDirection::OUTGOINGDRAFT;
1068 } else if (str == "outgoingpending") {
1069 type = MapMsgDirection::OUTGOINGPENDING;
1070 } else {
1071 // error
1072 type = MapMsgDirection::INVALID;
1073 LOG_INFO("%{public}s INVALID", __PRETTY_FUNCTION__);
1074 }
1075 return type;
1076 }
1077
ConvertStringToMsgDeliveryStatus(const std::string & str)1078 MapMsgDeliveryStatus MceUtilityConvertFormat::ConvertStringToMsgDeliveryStatus(const std::string &str)
1079 {
1080 MapMsgDeliveryStatus type;
1081 if (str == "delivered") {
1082 type = MapMsgDeliveryStatus::DELIVERED;
1083 } else if (str == "sent") {
1084 type = MapMsgDeliveryStatus::SENT;
1085 } else if (str == "unknown") {
1086 type = MapMsgDeliveryStatus::UNKNOWN;
1087 } else {
1088 // error
1089 type = MapMsgDeliveryStatus::INVALID;
1090 LOG_INFO("%{public}s INVALID", __PRETTY_FUNCTION__);
1091 }
1092 return type;
1093 }
1094
ConvertStringToMsgReceptionStatus(const std::string & str)1095 MapMsgReceptionStatus MceUtilityConvertFormat::ConvertStringToMsgReceptionStatus(const std::string &str)
1096 {
1097 MapMsgReceptionStatus type;
1098
1099 if (str == "complete") {
1100 type = MapMsgReceptionStatus::COMPLETE;
1101 } else if (str == "fractioned") {
1102 type = MapMsgReceptionStatus::FRACTIONED;
1103 } else if (str == "notification") {
1104 type = MapMsgReceptionStatus::NOTIFICATION;
1105 } else {
1106 // error
1107 type = MapMsgReceptionStatus::INVALID;
1108 LOG_INFO("%{public}s INVALID", __PRETTY_FUNCTION__);
1109 }
1110 return type;
1111 }
1112
ConvertYesNoStringToMapMessageStatus(const std::string & str)1113 MapMessageStatus MceUtilityConvertFormat::ConvertYesNoStringToMapMessageStatus(const std::string &str)
1114 {
1115 MapMessageStatus type;
1116 if (str == "yes") {
1117 type = MapMessageStatus::READ;
1118 } else if (str == "no") {
1119 type = MapMessageStatus::UNREAD;
1120 } else {
1121 // error
1122 type = MapMessageStatus::INVALID;
1123 LOG_INFO("%{public}s INVALID", __PRETTY_FUNCTION__);
1124 }
1125 return type;
1126 }
1127
ConvertStringToMapMessageStatus(const std::string & str)1128 MapMessageStatus MceUtilityConvertFormat::ConvertStringToMapMessageStatus(const std::string &str)
1129 {
1130 MapMessageStatus type;
1131 if (str == "READ") {
1132 type = MapMessageStatus::READ;
1133 } else if (str == "UNREAD") {
1134 type = MapMessageStatus::UNREAD;
1135 } else {
1136 // error
1137 type = MapMessageStatus::INVALID;
1138 LOG_INFO("%{public}s INVALID", __PRETTY_FUNCTION__);
1139 }
1140 return type;
1141 }
1142
ConvertStringToMapBoolType(const std::string & str)1143 MapBoolType MceUtilityConvertFormat::ConvertStringToMapBoolType(const std::string &str)
1144 {
1145 MapBoolType type;
1146 if (str == "yes") {
1147 type = MapBoolType::YES;
1148 } else if (str == "no") {
1149 type = MapBoolType::NO;
1150 } else {
1151 // error
1152 type = MapBoolType::INVALID;
1153 LOG_INFO("%{public}s INVALID", __PRETTY_FUNCTION__);
1154 }
1155 return type;
1156 }
1157 } // namespace bluetooth
1158 } // namespace OHOS
1159