2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "MsgUtilFile.h"
19 #include "MsgCppTypes.h"
20 #include "MsgException.h"
21 #include "MsgUtilFunction.h"
22 #include "MsgProxyListener.h"
23 #include "MsgHandle.h"
25 #include "MsgContact.h"
26 #include "MsgVMessage.h"
27 /*==================================================================================================
28 IMPLEMENTATION OF MsgHandle - Storage Member Functions
29 ==================================================================================================*/
30 int MsgHandle::addMessage(MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pSendOpt)
32 MSG_MESSAGE_INFO_S msgInfo = {0, };
33 MSG_SENDINGOPT_INFO_S sendOptInfo = {0, };
35 msgInfo.addressList = NULL;
36 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
38 /* Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S */
39 convertMsgStruct(pMsg, &msgInfo);
41 /* Covert MSG_SENDINGOPT_S to MSG_SENDINGOPT_INFO_S */
42 MSG_MESSAGE_TYPE_S msgType = {0, };
44 msgType.mainType = pMsg->mainType;
45 msgType.subType = pMsg->subType;
46 msgType.classType = pMsg->classType;
48 convertSendOptStruct(pSendOpt, &sendOptInfo, msgType);
50 /* Allocate Memory to Command Data */
51 char* encodedData = NULL;
52 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
53 int dataSize = MsgEncodeMsgInfo(&msgInfo, &sendOptInfo, &encodedData);
55 int cmdSize = sizeof(MSG_CMD_S) + dataSize;
58 bzero(cmdBuf, cmdSize);
59 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
61 /* Set Command Parameters */
62 pCmd->cmdType = MSG_CMD_ADD_MSG;
65 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
67 /* Copy Command Data */
68 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), encodedData, dataSize);
70 /* Send Command to Messaging FW */
71 char* pEventData = NULL;
72 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
74 write((char*)pCmd, cmdSize, &pEventData);
77 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
80 THROW(MsgException::INVALID_RESULT, "Event is NULL");
82 if (pEvent->eventType != MSG_EVENT_ADD_MSG) {
83 THROW(MsgException::INVALID_RESULT, "Event Data Error");
86 if (pEvent->result != MSG_SUCCESS)
87 return pEvent->result;
89 msg_message_id_t msgId = 0;
91 /* Decode Return Data */
92 MsgDecodeMsgId(pEvent->data, &msgId);
98 msg_error_t MsgHandle::addSyncMLMessage(const MSG_SYNCML_MESSAGE_S *pSyncMLMsg)
100 MSG_MESSAGE_INFO_S msgInfo;
101 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
103 msgInfo.addressList = NULL;
104 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
106 /* Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S */
107 msg_struct_s *msg = (msg_struct_s *)pSyncMLMsg->msg;
108 convertMsgStruct((MSG_MESSAGE_HIDDEN_S *)msg->data, &msgInfo);
110 /* Allocate Memory to Command Data */
111 char* encodedData = NULL;
112 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
113 int dataSize = MsgEncodeMsgInfo(&msgInfo, &encodedData);
115 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + sizeof(int) + dataSize;
117 char cmdBuf[cmdSize];
118 bzero(cmdBuf, cmdSize);
119 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
121 /* Set Command Parameters */
122 pCmd->cmdType = MSG_CMD_ADD_SYNCML_MSG;
125 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
127 /* Copy Command Data */
128 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &pSyncMLMsg->extId, sizeof(int));
129 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)), &pSyncMLMsg->pinCode, sizeof(int));
130 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+sizeof(int)), encodedData, dataSize);
132 /* Send Command to Messaging FW */
133 char* pEventData = NULL;
134 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
137 write((char*)pCmd, cmdSize, &pEventData);
139 /* Get Return Data */
140 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
143 THROW(MsgException::INVALID_RESULT, "Event is NULL");
145 if (pEvent->eventType != MSG_EVENT_ADD_SYNCML_MSG) {
146 THROW(MsgException::INVALID_RESULT, "Event Data Error");
149 msg_message_id_t msgId = 0;
151 /* Decode Return Data */
152 MsgDecodeMsgId(pEvent->data, &msgId);
154 ((MSG_MESSAGE_HIDDEN_S *)msg->data)->msgId = msgId;
156 return pEvent->result;
160 msg_error_t MsgHandle::updateMessage(const MSG_MESSAGE_HIDDEN_S *pMsg, const MSG_SENDINGOPT_S *pSendOpt)
162 MSG_MESSAGE_INFO_S msgInfo = {0, };
163 MSG_SENDINGOPT_INFO_S sendOptInfo = {0, };
165 msgInfo.addressList = NULL;
166 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
168 /* Covert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S */
169 convertMsgStruct(pMsg, &msgInfo);
171 if (pSendOpt != NULL) {
172 MSG_MESSAGE_TYPE_S msgType = {0, };
174 msgType.mainType = pMsg->mainType;
175 msgType.subType = pMsg->subType;
176 msgType.classType = pMsg->classType;
178 convertSendOptStruct(pSendOpt, &sendOptInfo, msgType);
181 /* Allocate Memory to Command Data */
182 char* encodedData = NULL;
183 unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
184 int dataSize = MsgEncodeMsgInfo(&msgInfo, &sendOptInfo, &encodedData);
186 int cmdSize = sizeof(MSG_CMD_S) + dataSize;
188 char cmdBuf[cmdSize];
189 bzero(cmdBuf, cmdSize);
190 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
192 /* Set Command Parameters */
193 pCmd->cmdType = MSG_CMD_UPDATE_MSG;
196 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
198 /* Copy Command Data */
199 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), encodedData, dataSize);
201 /* Send Command to Messaging FW */
202 char* pEventData = NULL;
203 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
205 write((char*)pCmd, cmdSize, &pEventData);
207 /* Get Return Data */
208 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
211 THROW(MsgException::INVALID_RESULT, "Event is NULL");
213 if (pEvent->eventType != MSG_EVENT_UPDATE_MSG) {
214 THROW(MsgException::INVALID_RESULT, "Event Data Error");
217 return pEvent->result;
221 msg_error_t MsgHandle::updateReadStatus(msg_message_id_t MsgId, bool bRead)
223 /* Allocate Memory to Command Data */
224 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(bool);
226 char cmdBuf[cmdSize];
227 bzero(cmdBuf, cmdSize);
228 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
230 /* Set Command Parameters */
231 pCmd->cmdType = MSG_CMD_UPDATE_READ;
234 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
236 /* Copy Command Data */
237 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
238 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &bRead, sizeof(bool));
240 /* Send Command to Messaging FW */
241 char* pEventData = NULL;
242 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
244 write((char*)pCmd, cmdSize, &pEventData);
246 /* Get Return Data */
247 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
250 THROW(MsgException::INVALID_RESULT, "Event is NULL");
252 if (pEvent->eventType != MSG_EVENT_UPDATE_READ) {
253 THROW(MsgException::INVALID_RESULT, "Event Data Error");
256 return pEvent->result;
260 msg_error_t MsgHandle::setConversationToRead(msg_thread_id_t ThreadId)
262 /* Allocate Memory to Command Data */
263 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t);
265 char cmdBuf[cmdSize];
266 bzero(cmdBuf, cmdSize);
267 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
269 /* Set Command Parameters */
270 pCmd->cmdType = MSG_CMD_UPDATE_THREAD_READ;
273 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
275 /* Copy Command Data */
276 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(msg_thread_id_t));
278 /* Send Command to Messaging FW */
279 char* pEventData = NULL;
280 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
282 write((char*)pCmd, cmdSize, &pEventData);
284 /* Get Return Data */
285 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
288 THROW(MsgException::INVALID_RESULT, "Event is NULL");
290 if (pEvent->eventType != MSG_EVENT_UPDATE_THREAD_READ) {
291 THROW(MsgException::INVALID_RESULT, "Event Data Error");
294 return pEvent->result;
298 msg_error_t MsgHandle::updateProtectedStatus(msg_message_id_t MsgId, bool bProtected)
300 /* Allocate Memory to Command Data */
301 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(bool);
303 char cmdBuf[cmdSize];
304 bzero(cmdBuf, cmdSize);
305 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
307 /* Set Command Parameters */
308 pCmd->cmdType = MSG_CMD_UPDATE_PROTECTED;
311 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
313 /* Copy Command Data */
314 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
315 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &bProtected, sizeof(bool));
317 /* Send Command to Messaging FW */
318 char* pEventData = NULL;
319 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
321 write((char*)pCmd, cmdSize, &pEventData);
323 /* Get Return Data */
324 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
327 THROW(MsgException::INVALID_RESULT, "Event is NULL");
329 if (pEvent->eventType != MSG_EVENT_UPDATE_PROTECTED) {
330 THROW(MsgException::INVALID_RESULT, "Event Data Error");
333 return pEvent->result;
337 msg_error_t MsgHandle::deleteMessage(msg_message_id_t MsgId)
339 /* Allocate Memory to Command Data */
340 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
342 char cmdBuf[cmdSize];
343 bzero(cmdBuf, cmdSize);
344 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
346 /* Set Command Parameters */
347 pCmd->cmdType = MSG_CMD_DELETE_MSG;
350 memcpy((void*)pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
352 /* Copy Command Data */
353 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
355 /* Send Command to Messaging FW */
356 char* pEventData = NULL;
357 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
359 write((char*)pCmd, cmdSize, &pEventData);
361 /* Get Return Data */
362 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
365 THROW(MsgException::INVALID_RESULT, "Event is NULL");
367 if (pEvent->eventType != MSG_EVENT_DELETE_MSG) {
368 THROW(MsgException::INVALID_RESULT, "Event Data Error");
371 return pEvent->result;
375 msg_error_t MsgHandle::deleteAllMessagesInFolder(msg_folder_id_t FolderId, bool bOnlyDB)
377 /* Allocate Memory to Command Data */
378 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
380 char cmdBuf[cmdSize];
381 bzero(cmdBuf, cmdSize);
382 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
384 /* Set Command Parameters */
385 pCmd->cmdType = MSG_CMD_DELALL_MSGINFOLDER;
388 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
390 /* Copy Command Data */
391 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
392 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_folder_id_t)), &bOnlyDB, sizeof(bool));
394 /* Send Command to Messaging FW */
395 char* pEventData = NULL;
396 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
398 write((char*)pCmd, cmdSize, &pEventData);
400 /* Get Return Data */
401 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
404 THROW(MsgException::INVALID_RESULT, "Event is NULL");
406 if (pEvent->eventType != MSG_EVENT_DELALL_MSGINFOLDER) {
407 THROW(MsgException::INVALID_RESULT, "Event Data Error");
410 return pEvent->result;
414 msg_error_t MsgHandle::deleteMessagesByList(msg_id_list_s *pMsgIdList)
416 /* Allocate Memory to Command Data */
417 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + (sizeof(int)*pMsgIdList->nCount);
419 char cmdBuf[cmdSize];
420 bzero(cmdBuf, cmdSize);
421 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
423 /* Set Command Parameters */
424 pCmd->cmdType = MSG_CMD_DELETE_MESSAGE_BY_LIST;
427 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
429 /* Copy Command Data */
430 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &(pMsgIdList->nCount), sizeof(int));
431 for (int i = 0; i < pMsgIdList->nCount; i++) {
432 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)+(sizeof(int)*i)), &(pMsgIdList->msgIdList[i]), sizeof(int));
435 /* Send Command to Messaging FW */
436 char* pEventData = NULL;
437 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
439 write((char*)pCmd, cmdSize, &pEventData);
441 /* Get Return Data */
442 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
445 THROW(MsgException::INVALID_RESULT, "Event is NULL");
447 if (pEvent->eventType != MSG_EVENT_DELETE_MESSAGE_BY_LIST) {
448 THROW(MsgException::INVALID_RESULT, "Event Data Error");
451 return pEvent->result;
455 msg_error_t MsgHandle::moveMessageToFolder(msg_message_id_t MsgId, msg_folder_id_t DestFolderId)
457 /* Allocate Memory to Command Data */
458 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(msg_folder_id_t);
460 char cmdBuf[cmdSize];
461 bzero(cmdBuf, cmdSize);
462 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
464 /* Set Command Parameters */
465 pCmd->cmdType = MSG_CMD_MOVE_MSGTOFOLDER;
468 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
470 /* Copy Command Data */
471 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
472 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+sizeof(msg_message_id_t)+MAX_COOKIE_LEN), &DestFolderId, sizeof(msg_folder_id_t));
474 /* Send Command to Messaging FW */
475 char* pEventData = NULL;
476 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
478 write((char*)pCmd, cmdSize, &pEventData);
480 /* Get Return Data */
481 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
484 THROW(MsgException::INVALID_RESULT, "Event is NULL");
486 if (pEvent->eventType != MSG_EVENT_MOVE_MSGTOFOLDER) {
487 THROW(MsgException::INVALID_RESULT, "Event Data Error");
490 return pEvent->result;
494 msg_error_t MsgHandle::moveMessageToStorage(msg_message_id_t MsgId, msg_storage_id_t DestStorageId)
496 /* Allocate Memory to Command Data */
497 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t) + sizeof(msg_storage_id_t);
499 char cmdBuf[cmdSize];
500 bzero(cmdBuf, cmdSize);
501 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
503 /* Set Command Parameters */
504 pCmd->cmdType = MSG_CMD_MOVE_MSGTOSTORAGE;
507 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
509 /* Copy Command Data */
510 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
511 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_id_t)), &DestStorageId, sizeof(msg_storage_id_t));
513 /* Send Command to Messaging FW */
514 char* pEventData = NULL;
515 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
517 write((char*)pCmd, cmdSize, &pEventData);
519 /* Get Return Data */
520 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
523 THROW(MsgException::INVALID_RESULT, "Event is NULL");
525 if (pEvent->eventType != MSG_EVENT_MOVE_MSGTOSTORAGE) {
526 THROW(MsgException::INVALID_RESULT, "Event Data Error");
529 return pEvent->result;
533 msg_error_t MsgHandle::countMessage(msg_folder_id_t FolderId, MSG_COUNT_INFO_S *pCountInfo)
535 /* Allocate Memory to Command Data */
536 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
538 char cmdBuf[cmdSize];
539 bzero(cmdBuf, cmdSize);
540 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
542 /* Set Command Parameters */
543 pCmd->cmdType = MSG_CMD_COUNT_MSG;
546 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
548 /* Copy Command Data */
549 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
551 /* Send Command to Messaging FW */
552 char* pEventData = NULL;
553 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
555 write((char*)pCmd, cmdSize, &pEventData);
557 /* Get Return Data */
558 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
561 THROW(MsgException::INVALID_RESULT, "Event is NULL");
563 if (pEvent->eventType != MSG_EVENT_COUNT_MSG) {
564 THROW(MsgException::INVALID_RESULT, "Event Data Error");
567 if (pEvent->result != MSG_SUCCESS)
568 return pEvent->result;
570 /* Decode Return Data */
571 MsgDecodeCountInfo(pEvent->data, pCountInfo);
577 msg_error_t MsgHandle::countMsgByType(const MSG_MESSAGE_TYPE_S *pMsgType, int *pMsgCount)
579 /* Allocate Memory to Command Data */
580 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_TYPE_S);
582 char cmdBuf[cmdSize];
583 bzero(cmdBuf, cmdSize);
584 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
586 /* Set Command Parameters */
587 pCmd->cmdType = MSG_CMD_COUNT_BY_MSGTYPE;
590 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
592 /* Copy Command Data */
593 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pMsgType, sizeof(MSG_MESSAGE_TYPE_S));
595 /* Send Command to Messaging FW */
596 char* pEventData = NULL;
597 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
599 write((char*)pCmd, cmdSize, &pEventData);
601 /* Get Return Data */
602 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
605 THROW(MsgException::INVALID_RESULT, "Event is NULL");
607 if (pEvent->eventType != MSG_EVENT_COUNT_BY_MSGTYPE) {
608 THROW(MsgException::INVALID_RESULT, "Event Data Error");
611 if (pEvent->result != MSG_SUCCESS)
612 return pEvent->result;
614 /* Decode Return Data */
615 memcpy(pMsgCount, (void*)((char*)pEvent+sizeof(MSG_EVENT_TYPE_T)+sizeof(msg_error_t)), sizeof(int));
621 msg_error_t MsgHandle::countMsgByContact(const MSG_THREAD_LIST_INDEX_INFO_S *pAddrInfo, MSG_THREAD_COUNT_INFO_S *pMsgThreadCountList)
623 /* Allocate Memory to Command Data */
624 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_THREAD_LIST_INDEX_S);
626 char cmdBuf[cmdSize];
627 bzero(cmdBuf, cmdSize);
628 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
630 /* Set Command Parameters */
631 pCmd->cmdType = MSG_CMD_GET_CONTACT_COUNT;
634 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
636 /* Copy Command Data */
637 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pAddrInfo, sizeof(msg_contact_id_t));
638 msg_struct_s *pAddr = (msg_struct_s *)pAddrInfo->msgAddrInfo;
640 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN + sizeof(msg_contact_id_t)), pAddr->data, sizeof(MSG_ADDRESS_INFO_S));
641 /* Send Command to Messaging FW */
642 char* pEventData = NULL;
643 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
645 write((char*)pCmd, cmdSize, &pEventData);
647 /* Get Return Data */
648 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
651 THROW(MsgException::INVALID_RESULT, "Event is NULL");
653 if (pEvent->eventType != MSG_EVENT_GET_CONTACT_COUNT) {
654 THROW(MsgException::INVALID_RESULT, "Event Data Error");
657 if (pEvent->result != MSG_SUCCESS)
658 return pEvent->result;
660 /* Decode Return Data */
661 MsgDecodeContactCount(pEvent->data, pMsgThreadCountList);
667 msg_error_t MsgHandle::getMessage(msg_message_id_t MsgId, MSG_MESSAGE_HIDDEN_S *pMsg, MSG_SENDINGOPT_S *pSendOpt)
669 /* Allocate Memory to Command Data */
670 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
672 char cmdBuf[cmdSize];
673 bzero(cmdBuf, cmdSize);
674 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
676 /* Set Command Parameters */
677 pCmd->cmdType = MSG_CMD_GET_MSG;
680 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
682 /* Copy Command Data */
683 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
685 /* Send Command to Messaging FW */
686 char* pEventData = NULL;
687 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
690 write((char*)pCmd, cmdSize, &pEventData);
692 /* Get Return Data */
693 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
696 THROW(MsgException::INVALID_RESULT, "Event is NULL");
698 if (pEvent->eventType != MSG_EVENT_GET_MSG) {
699 THROW(MsgException::INVALID_RESULT, "Event Data Error");
702 if (pEvent->result != MSG_SUCCESS)
703 return pEvent->result;
705 /* Decode Return Data */
706 MSG_MESSAGE_INFO_S msgInfo;
707 MSG_SENDINGOPT_INFO_S sendOptInfo;
709 msgInfo.addressList = NULL;
710 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
712 MsgDecodeMsgInfo(pEvent->data, &msgInfo, &sendOptInfo);
714 /* Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_HIDDEN_S */
715 convertMsgStruct(&msgInfo, pMsg);
717 if (pSendOpt != NULL) {
718 MSG_MESSAGE_TYPE_S msgType = {0, };
720 msgType.mainType = pMsg->mainType;
721 msgType.subType = pMsg->subType;
722 msgType.classType = pMsg->classType;
724 convertSendOptStruct(&sendOptInfo, pSendOpt, msgType);
727 /* Delete Temp File */
728 if (msgInfo.bTextSms == false) {
729 /* Delete Temp File */
730 MsgDeleteFile(msgInfo.msgData); /* ipc */
737 msg_error_t MsgHandle::addFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
739 /* Allocate Memory to Command Data */
740 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
742 char cmdBuf[cmdSize];
743 bzero(cmdBuf, cmdSize);
744 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
746 /* Set Command Parameters */
747 pCmd->cmdType = MSG_CMD_ADD_FOLDER;
750 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
752 /* Copy Command Data */
753 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
755 /* Send Command to Messaging FW */
756 char* pEventData = NULL;
757 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
759 write((char*)pCmd, cmdSize, &pEventData);
761 /* Get Return Data */
762 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
765 THROW(MsgException::INVALID_RESULT, "Event is NULL");
767 if (pEvent->eventType != MSG_EVENT_ADD_FOLDER) {
768 THROW(MsgException::INVALID_RESULT, "Event Data Error");
771 return pEvent->result;
775 msg_error_t MsgHandle::updateFolder(const MSG_FOLDER_INFO_S *pFolderInfo)
777 /* Allocate Memory to Command Data */
778 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_FOLDER_INFO_S);
780 char cmdBuf[cmdSize];
781 bzero(cmdBuf, cmdSize);
782 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
784 /* Set Command Parameters */
785 pCmd->cmdType = MSG_CMD_UPDATE_FOLDER;
788 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
790 /* Copy Command Data */
791 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pFolderInfo, sizeof(MSG_FOLDER_INFO_S));
793 /* Send Command to Messaging FW */
794 char* pEventData = NULL;
795 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
797 write((char*)pCmd, cmdSize, &pEventData);
799 /* Get Return Data */
800 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
803 THROW(MsgException::INVALID_RESULT, "Event is NULL");
805 if (pEvent->eventType != MSG_EVENT_UPDATE_FOLDER) {
806 THROW(MsgException::INVALID_RESULT, "Event Data Error");
809 return pEvent->result;
813 msg_error_t MsgHandle::deleteFolder(msg_folder_id_t FolderId)
815 /* Allocate Memory to Command Data */
816 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_folder_id_t);
818 char cmdBuf[cmdSize];
819 bzero(cmdBuf, cmdSize);
820 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
822 /* Set Command Parameters */
823 pCmd->cmdType = MSG_CMD_DELETE_FOLDER;
826 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
828 /* Copy Command Data */
829 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &FolderId, sizeof(msg_folder_id_t));
831 /* Send Command to Messaging FW */
832 char* pEventData = NULL;
833 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
835 write((char*)pCmd, cmdSize, &pEventData);
837 /* Get Return Data */
838 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
841 THROW(MsgException::INVALID_RESULT, "Event is NULL");
843 if (pEvent->eventType != MSG_EVENT_DELETE_FOLDER) {
844 THROW(MsgException::INVALID_RESULT, "Event Data Error");
847 return pEvent->result;
851 msg_error_t MsgHandle::getFolderList(msg_struct_list_s *pFolderList)
853 /* Allocate Memory to Command Data */
854 int cmdSize = sizeof(MSG_CMD_S);
856 char cmdBuf[cmdSize];
857 bzero(cmdBuf, cmdSize);
858 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
860 /* Set Command Parameters */
861 pCmd->cmdType = MSG_CMD_GET_FOLDERLIST;
864 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
866 /* Send Command to Messaging FW */
867 char* pEventData = NULL;
868 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
870 write((char*)pCmd, cmdSize, &pEventData);
872 /* Get Return Data */
873 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
876 THROW(MsgException::INVALID_RESULT, "Event is NULL");
878 if (pEvent->eventType != MSG_EVENT_GET_FOLDERLIST) {
879 THROW(MsgException::INVALID_RESULT, "Event Data Error");
882 if (pEvent->result != MSG_SUCCESS)
883 return pEvent->result;
885 /* Decode Return Data */
886 MsgDecodeFolderList(pEvent->data, pFolderList);
892 msg_error_t MsgHandle::getThreadViewList(const MSG_SORT_RULE_S *pSortRule, const MSG_LIST_CONDITION_S *pListCond, msg_struct_list_s *pThreadViewList)
894 msg_error_t err = MSG_SUCCESS;
896 if (checkPermission() == MSG_ERR_PERMISSION_DENIED) {
897 MSG_ERR("Client doesn't have permission");
898 return MSG_ERR_PERMISSION_DENIED;
901 err = MsgStoGetThreadViewListWithCondition(pSortRule, pListCond, pThreadViewList);
902 if (err != MSG_SUCCESS) {
903 MSG_ERR("MsgStoGetThreadViewListWithCondition() Error!!");
908 /* Allocate Memory to Command Data */
909 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_SORT_RULE_S);
911 char cmdBuf[cmdSize];
912 bzero(cmdBuf, cmdSize);
913 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
915 /* Set Command Parameters */
916 pCmd->cmdType = MSG_CMD_GET_THREADVIEWLIST;
918 /* Copy Command Data */
919 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)), pSortRule, sizeof(MSG_SORT_RULE_S));
921 /* Send Command to Messaging FW */
922 char* pEventData = NULL;
923 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
925 write((char*)pCmd, cmdSize, &pEventData);
927 /* Get Return Data */
928 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
931 THROW(MsgException::INVALID_RESULT, "Event is NULL");
933 if (pEvent->eventType != MSG_EVENT_GET_THREADVIEWLIST) {
934 THROW(MsgException::INVALID_RESULT, "Event Data Error");
937 if (pEvent->result != MSG_SUCCESS)
938 return pEvent->result;
940 /* Decode Return Data */
941 MsgDecodeThreadViewList(pEvent->data, pMsgThreadViewList);
947 msg_error_t MsgHandle::getConversationViewItem(msg_message_id_t MsgId, MSG_CONVERSATION_VIEW_S *pConv)
951 msg_error_t err = MSG_SUCCESS;
953 if (checkPermission() == MSG_ERR_PERMISSION_DENIED) {
954 MSG_ERR("Client doesn't have permission");
955 return MSG_ERR_PERMISSION_DENIED;
958 err = MsgStoGetConversationViewItem(MsgId, pConv);
963 msg_error_t MsgHandle::getConversationViewList(msg_thread_id_t ThreadId, msg_struct_list_s *pConvViewList)
967 msg_error_t err = MSG_SUCCESS;
969 if (checkPermission() == MSG_ERR_PERMISSION_DENIED) {
970 MSG_ERR("Client doesn't have permission");
971 return MSG_ERR_PERMISSION_DENIED;
974 err = MsgStoGetConversationViewList(ThreadId, pConvViewList);
982 msg_error_t MsgHandle::deleteThreadMessageList(msg_thread_id_t ThreadId, bool include_protected_msg)
984 /* Allocate Memory to Command Data */
985 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t) + sizeof(bool);
987 char cmdBuf[cmdSize];
988 bzero(cmdBuf, cmdSize);
989 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
991 /* Set Command Parameters */
992 pCmd->cmdType = MSG_CMD_DELETE_THREADMESSAGELIST;
995 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
997 /* Copy Command Data */
998 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &ThreadId, sizeof(msg_thread_id_t));
999 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_thread_id_t)), &include_protected_msg, sizeof(bool));
1001 /* Send Command to Messaging FW */
1002 char* pEventData = NULL;
1003 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1005 write((char*)pCmd, cmdSize, &pEventData);
1007 /* Get Return Data */
1008 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1011 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1013 if (pEvent->eventType != MSG_EVENT_DELETE_THREADMESSAGELIST) {
1014 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1017 if (pEvent->result != MSG_SUCCESS)
1018 return pEvent->result;
1024 msg_error_t MsgHandle::getQuickPanelData(msg_quickpanel_type_t Type, MSG_MESSAGE_HIDDEN_S *pMsg)
1026 /* Allocate Memory to Command Data */
1027 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_quickpanel_type_t);
1029 char cmdBuf[cmdSize];
1030 bzero(cmdBuf, cmdSize);
1031 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1033 /* Set Command Parameters */
1034 pCmd->cmdType = MSG_CMD_GET_QUICKPANEL_DATA;
1037 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1039 /* Copy Command Data */
1040 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &Type, sizeof(msg_quickpanel_type_t));
1042 /* Send Command to Messaging FW */
1043 char* pEventData = NULL;
1044 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1046 write((char*)pCmd, cmdSize, &pEventData);
1048 /* Get Return Data */
1049 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1052 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1054 if (pEvent->eventType != MSG_EVENT_GET_QUICKPANEL_DATA) {
1055 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1058 if (pEvent->result != MSG_SUCCESS)
1059 return pEvent->result;
1061 /* Decode Return Data */
1062 MSG_MESSAGE_INFO_S msgInfo;
1064 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1066 msgInfo.addressList = NULL;
1067 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1069 MsgDecodeMsgInfo((char *)pEvent->data, &msgInfo);
1071 /* Covert MSG_MESSAGE_INFO_S to MSG_MESSAGE_S */
1072 convertMsgStruct(&msgInfo, pMsg);
1074 /* Delete Temp File */
1075 if (msgInfo.bTextSms == false) {
1076 /* Delete Temp File */
1077 MsgDeleteFile(msgInfo.msgData); /* ipc */
1084 msg_error_t MsgHandle::resetDatabase()
1086 /* Allocate Memory to Command Data */
1087 int cmdSize = sizeof(MSG_CMD_S);
1089 char cmdBuf[cmdSize];
1090 bzero(cmdBuf, cmdSize);
1091 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1093 /* Set Command Parameters */
1094 pCmd->cmdType = MSG_CMD_RESET_DB;
1097 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1099 /* Send Command to Messaging FW */
1100 char* pEventData = NULL;
1101 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1103 write((char*)pCmd, cmdSize, &pEventData);
1105 /* Get Return Data */
1106 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1109 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1111 if (pEvent->eventType != MSG_EVENT_RESET_DB) {
1112 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1115 return pEvent->result;
1119 msg_error_t MsgHandle::getMemSize(unsigned int* memsize)
1121 /* Allocate Memory to Command Data */
1122 int cmdSize = sizeof(MSG_CMD_S);
1124 char cmdBuf[cmdSize];
1125 bzero(cmdBuf, cmdSize);
1126 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1128 /* Set Command Parameters */
1129 pCmd->cmdType = MSG_CMD_GET_MEMSIZE;
1132 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1134 /* Send Command to Messaging FW */
1135 char* pEventData = NULL;
1136 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1138 write((char*)pCmd, cmdSize, &pEventData);
1140 /* Get Return Data */
1141 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1144 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1146 if (pEvent->eventType != MSG_EVENT_GET_MEMSIZE) {
1147 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1150 if (pEvent->result != MSG_SUCCESS)
1151 return pEvent->result;
1153 /* Decode Return Data */
1154 MsgDecodeMemSize(pEvent->data, memsize);
1160 msg_error_t MsgHandle::backupMessage(msg_message_backup_type_t type, const char *backup_filepath)
1162 if (backup_filepath == NULL)
1163 return MSG_ERR_NULL_POINTER;
1165 /* Create an empty file for writing. */
1166 /* If a file with the same name already exists its content is erased */
1167 /* and the file is treated as a new empty file. */
1169 FILE *pFile = MsgOpenFile(backup_filepath, "w");
1170 if (pFile == NULL) {
1171 MSG_DEBUG("File Open error");
1172 return MSG_ERR_STORAGE_ERROR;
1174 MsgCloseFile(pFile);
1176 char path[MSG_FILEPATH_LEN_MAX+1] = {0, };
1177 strncpy(path, backup_filepath, MSG_FILEPATH_LEN_MAX);
1179 /* Allocate Memory to Command Data */
1180 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_backup_type_t) + sizeof(path);
1182 char cmdBuf[cmdSize];
1183 bzero(cmdBuf, cmdSize);
1184 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1186 /* Set Command Parameters */
1187 pCmd->cmdType = MSG_CMD_BACKUP_MESSAGE;
1190 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1191 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &type, sizeof(msg_message_backup_type_t));
1192 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_message_backup_type_t)), (char *)path, sizeof(path));
1194 /* Send Command to Messaging FW */
1195 char* pEventData = NULL;
1196 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1198 write((char*)pCmd, cmdSize, &pEventData);
1200 /* Get Return Data */
1201 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1204 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1206 if (pEvent->eventType != MSG_EVENT_BACKUP_MESSAGE) {
1207 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1210 return pEvent->result;
1214 msg_error_t MsgHandle::restoreMessage(const char *backup_filepath)
1216 if (backup_filepath == NULL)
1217 return MSG_ERR_NULL_POINTER;
1219 if (MsgAccessFile(backup_filepath, R_OK) == false) {
1220 MSG_DEBUG("File access error");
1221 return MSG_ERR_UNKNOWN;
1224 char path[MSG_FILEPATH_LEN_MAX+1] = {0, };
1225 strncpy(path, backup_filepath, MSG_FILEPATH_LEN_MAX);
1227 /* Allocate Memory to Command Data */
1228 int cmdSize = sizeof(MSG_CMD_S) + sizeof(path);
1230 char cmdBuf[cmdSize];
1231 bzero(cmdBuf, cmdSize);
1232 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1234 /* Set Command Parameters */
1235 pCmd->cmdType = MSG_CMD_RESTORE_MESSAGE;
1238 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1239 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), (char *)path, sizeof(path));
1241 /* Send Command to Messaging FW */
1242 char* pEventData = NULL;
1243 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1245 write((char*)pCmd, cmdSize, &pEventData);
1247 /* Get Return Data */
1248 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1251 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1253 if (pEvent->eventType != MSG_EVENT_RESTORE_MESSAGE) {
1254 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1257 return pEvent->result;
1261 msg_error_t MsgHandle::searchMessage(const char *pSearchString, msg_struct_list_s *pThreadViewList)
1263 msg_error_t err = MSG_SUCCESS;
1265 if (checkPermission() == MSG_ERR_PERMISSION_DENIED) {
1266 MSG_ERR("Client doesn't have permission");
1267 return MSG_ERR_PERMISSION_DENIED;
1272 MSG_ADDRESS_INFO_S *pAddrInfo = NULL;
1273 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> buf(&pAddrInfo, unique_ptr_deleter);
1275 /* get contact search list */
1276 if (MsgGetContactSearchList(pSearchString, &pAddrInfo, &count) != MSG_SUCCESS) {
1277 MSG_DEBUG("MsgGetContactSearchList fail.");
1282 /* Allocate Memory to Command Data */
1283 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + sizeof(MSG_ADDRESS_INFO_S) * count;
1285 char cmdBuf[cmdSize];
1286 bzero(cmdBuf, cmdSize);
1287 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1289 /* Set Command Parameters */
1290 pCmd->cmdType = MSG_CMD_SET_TEMP_ADDRESS_TABLE;
1293 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1295 /* Copy Command Data */
1296 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &count, sizeof(int));
1297 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)), pAddrInfo, sizeof(MSG_ADDRESS_INFO_S) * count);
1299 /* Send Command to Messaging FW */
1300 char* pEventData = NULL;
1301 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1303 write((char*)pCmd, cmdSize, &pEventData);
1305 /* Get Return Data */
1306 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1309 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1311 if (pEvent->eventType != MSG_EVENT_SET_TEMP_ADDRESS_TABLE)
1312 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1314 if (pEvent->result != MSG_SUCCESS)
1318 err = MsgStoSearchMessage(pSearchString, pThreadViewList, count);
1320 if (err != MSG_SUCCESS) {
1321 MSG_DEBUG("MsgStoSearchMessage() Error!!");
1325 /* MsgStoDisconnectDB(); */
1331 msg_error_t MsgHandle::getRejectMsgList(const char *pNumber, msg_struct_list_s *pRejectMsgList)
1333 msg_error_t err = MSG_SUCCESS;
1335 if (checkPermission() == MSG_ERR_PERMISSION_DENIED) {
1336 MSG_ERR("Client doesn't have permission");
1337 return MSG_ERR_PERMISSION_DENIED;
1340 err = MsgStoGetRejectMsgList(pNumber, pRejectMsgList);
1342 if (err != MSG_SUCCESS) {
1343 MSG_DEBUG("MsgStoGetRejectMsgList() Error!!");
1351 msg_error_t MsgHandle::regStorageChangeCallback(msg_storage_change_cb onStorageChange, void *pUserParam)
1353 if (!onStorageChange)
1354 THROW(MsgException::INVALID_PARAM, "onStorageChange is null");
1356 MsgProxyListener* eventListener = MsgProxyListener::instance();
1358 eventListener->start(this);
1360 int remoteFd = eventListener->getRemoteFd(); /* fd that is reserved to the "listener thread" by msgfw daemon */
1362 if (remoteFd == -1 ) {
1363 eventListener->stop();
1364 return MSG_ERR_INVALID_MSGHANDLE;
1367 if (eventListener->regStorageChangeEventCB(this, remoteFd, onStorageChange, pUserParam) == false) {
1368 eventListener->stop();
1369 return MSG_ERR_INVALID_PARAMETER;
1372 /* Allocate Memory to Command Data */
1373 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); /* cmd type, listenerFd */
1374 char cmdBuf[cmdSize];
1375 bzero(cmdBuf, cmdSize);
1376 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
1378 /* Set Command Parameters */
1379 pCmd->cmdType = MSG_CMD_REG_STORAGE_CHANGE_CB;
1382 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1384 MSG_DEBUG("remote fd %d", remoteFd);
1386 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
1388 MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
1390 /* Send Command to Messaging FW */
1391 char* pEventData = NULL;
1392 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1394 write((char*)pCmd, cmdSize, &pEventData);
1396 /* Get Return Data */
1397 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1400 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1402 if (pEvent->eventType != MSG_EVENT_REG_STORAGE_CHANGE_CB) {
1403 THROW(MsgException::INVALID_PARAM, "Event Data Error");
1406 return pEvent->result;
1410 msg_error_t MsgHandle::regThreadChangeCallback(msg_thread_change_cb onThreadChange, void *pUserParam)
1412 if (!onThreadChange)
1413 THROW(MsgException::INVALID_PARAM, "onThreadChange is null");
1415 MsgProxyListener* eventListener = MsgProxyListener::instance();
1417 eventListener->start(this);
1419 int remoteFd = eventListener->getRemoteFd(); /* fd that is reserved to the "listener thread" by msgfw daemon */
1421 if (remoteFd == -1 ) {
1422 eventListener->stop();
1423 return MSG_ERR_INVALID_MSGHANDLE;
1426 if (eventListener->regThreadChangeEventCB(this, remoteFd, onThreadChange, pUserParam) == false) {
1427 eventListener->stop();
1428 return MSG_ERR_INVALID_PARAMETER;
1431 /* Allocate Memory to Command Data */
1432 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); /* cmd type, listenerFd */
1433 char cmdBuf[cmdSize];
1434 bzero(cmdBuf, cmdSize);
1435 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
1437 /* Set Command Parameters */
1438 pCmd->cmdType = MSG_CMD_REG_THREAD_CHANGE_CB;
1441 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1443 MSG_DEBUG("remote fd %d", remoteFd);
1445 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
1447 MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
1449 /* Send Command to Messaging FW */
1450 char* pEventData = NULL;
1451 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1453 write((char*)pCmd, cmdSize, &pEventData);
1455 /* Get Return Data */
1456 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1459 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1461 if (pEvent->eventType != MSG_EVENT_REG_THREAD_CHANGE_CB) {
1462 THROW(MsgException::INVALID_PARAM, "Event Data Error");
1465 return pEvent->result;
1469 msg_error_t MsgHandle::getReportStatus(msg_message_id_t msg_id, msg_struct_list_s *report_list)
1471 /* Allocate Memory to Command Data */
1472 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
1474 char cmdBuf[cmdSize];
1475 bzero(cmdBuf, cmdSize);
1476 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1478 report_list->nCount = 0;
1479 report_list->msg_struct_info = NULL;
1481 /* Set Command Parameters */
1482 pCmd->cmdType = MSG_CMD_GET_REPORT_STATUS;
1485 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1487 /* Copy Command Data */
1488 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msg_id, sizeof(msg_message_id_t));
1490 /* Send Command to Messaging FW */
1491 char* pEventData = NULL;
1492 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1494 write((char*)pCmd, cmdSize, &pEventData);
1496 /* Get Return Data */
1497 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1500 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1502 if (pEvent->eventType != MSG_EVENT_GET_REPORT_STATUS) {
1503 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1506 if (pEvent->result != MSG_SUCCESS)
1507 return pEvent->result;
1509 /* Decode Return Data */
1510 MsgDecodeReportStatus(pEvent->data, report_list);
1516 msg_error_t MsgHandle::getAddressList(const msg_thread_id_t threadId, msg_struct_list_s *pAddrList)
1518 msg_error_t err = MSG_SUCCESS;
1520 if (checkPermission() == MSG_ERR_PERMISSION_DENIED) {
1521 MSG_ERR("Client doesn't have permission");
1522 return MSG_ERR_PERMISSION_DENIED;
1525 err = MsgStoGetAddressList(threadId, (msg_struct_list_s *)pAddrList);
1527 if (err != MSG_SUCCESS) {
1528 MSG_DEBUG("MsgStoGetThreadViewList() Error!!");
1536 msg_error_t MsgHandle::getThreadIdByAddress(msg_struct_list_s *pAddrList, msg_thread_id_t *pThreadId)
1538 /* Allocate Memory to Command Data */
1539 int cmdSize = sizeof(MSG_CMD_S) + sizeof(pAddrList->nCount) + (sizeof(MSG_ADDRESS_INFO_S)*pAddrList->nCount);
1541 char cmdBuf[cmdSize];
1542 bzero(cmdBuf, cmdSize);
1543 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1545 /* Set Command Parameters */
1546 pCmd->cmdType = MSG_CMD_GET_THREAD_ID_BY_ADDRESS;
1549 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1551 /* Copy Command Data */
1552 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &pAddrList->nCount, sizeof(pAddrList->nCount));
1553 int addSize = sizeof(MSG_ADDRESS_INFO_S);
1554 for (int i = 0; i < pAddrList->nCount; i++) {
1555 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+sizeof(pAddrList->nCount)+(addSize*i)+MAX_COOKIE_LEN), ((msg_struct_s *)(pAddrList->msg_struct_info[i]))->data, sizeof(MSG_ADDRESS_INFO_S));
1558 /* Send Command to Messaging FW */
1559 char* pEventData = NULL;
1560 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1562 write((char*)pCmd, cmdSize, &pEventData);
1564 /* Get Return Data */
1565 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1568 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1570 if (pEvent->eventType != MSG_EVENT_GET_THREAD_ID_BY_ADDRESS) {
1571 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1574 if (pEvent->result != MSG_SUCCESS)
1575 return pEvent->result;
1577 /* Decode Return Data */
1578 MsgDecodeThreadId(pEvent->data, pThreadId);
1584 msg_error_t MsgHandle::getThreadIdByAddress(msg_list_handle_t msg_address_list, msg_thread_id_t *pThreadId)
1586 int addrCnt = (int)g_list_length((GList *)msg_address_list);
1588 /* Allocate Memory to Command Data */
1589 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + (sizeof(MSG_ADDRESS_INFO_S)*addrCnt);
1591 char cmdBuf[cmdSize];
1592 bzero(cmdBuf, cmdSize);
1593 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1595 /* Set Command Parameters */
1596 pCmd->cmdType = MSG_CMD_GET_THREAD_ID_BY_ADDRESS;
1599 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1601 /* Copy Command Data */
1602 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &addrCnt, sizeof(int));
1603 int addSize = sizeof(MSG_ADDRESS_INFO_S);
1604 for (int i = 0; i < addrCnt; i++) {
1605 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+sizeof(addrCnt)+(addSize*i)+MAX_COOKIE_LEN), ((msg_struct_s *)(g_list_nth_data((GList *)msg_address_list, (guint)i)))->data, sizeof(MSG_ADDRESS_INFO_S));
1608 /* Send Command to Messaging FW */
1609 char* pEventData = NULL;
1610 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1612 write((char*)pCmd, cmdSize, &pEventData);
1614 /* Get Return Data */
1615 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1618 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1620 if (pEvent->eventType != MSG_EVENT_GET_THREAD_ID_BY_ADDRESS) {
1621 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1624 if (pEvent->result != MSG_SUCCESS)
1625 return pEvent->result;
1627 /* Decode Return Data */
1628 MsgDecodeThreadId(pEvent->data, pThreadId);
1634 msg_error_t MsgHandle::getThread(msg_thread_id_t threadId, MSG_THREAD_VIEW_S* pThreadInfo)
1636 /* Allocate Memory to Command Data */
1637 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_thread_id_t);
1639 char cmdBuf[cmdSize];
1640 bzero(cmdBuf, cmdSize);
1641 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1643 /* Set Command Parameters */
1644 pCmd->cmdType = MSG_CMD_GET_THREAD_INFO;
1647 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1649 /* Copy Command Data */
1650 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &threadId, sizeof(msg_thread_id_t));
1652 /* Send Command to Messaging FW */
1653 char* pEventData = NULL;
1654 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1656 write((char*)pCmd, cmdSize, &pEventData);
1658 /* Get Return Data */
1659 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1662 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1664 if (pEvent->eventType != MSG_EVENT_GET_THREAD_INFO) {
1665 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1668 /* Decode Return Data */
1669 MsgDecodeThreadInfo(pEvent->data, pThreadInfo);
1675 msg_error_t MsgHandle::getMessageList(const MSG_LIST_CONDITION_S *pListCond, msg_struct_list_s *pMsgList)
1677 msg_error_t err = MSG_SUCCESS;
1679 if (checkPermission() == MSG_ERR_PERMISSION_DENIED) {
1680 MSG_ERR("Client doesn't have permission");
1681 return MSG_ERR_PERMISSION_DENIED;
1686 if (pListCond->pAddressVal) {
1687 MSG_ADDRESS_INFO_S *pAddrInfo = NULL;
1688 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> buf(&pAddrInfo, unique_ptr_deleter);
1690 /* get contact search list */
1691 if (MsgGetContactSearchList(pListCond->pAddressVal, &pAddrInfo, &count) != MSG_SUCCESS) {
1692 MSG_DEBUG("MsgGetContactSearchList fail.");
1697 /* Allocate Memory to Command Data */
1698 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int) + sizeof(MSG_ADDRESS_INFO_S) * count;
1700 char cmdBuf[cmdSize];
1701 bzero(cmdBuf, cmdSize);
1702 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1704 /* Set Command Parameters */
1705 pCmd->cmdType = MSG_CMD_SET_TEMP_ADDRESS_TABLE;
1708 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1710 /* Copy Command Data */
1711 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &count, sizeof(int));
1712 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(int)), pAddrInfo, sizeof(MSG_ADDRESS_INFO_S) * count);
1714 /* Send Command to Messaging FW */
1715 char* pEventData = NULL;
1716 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1718 write((char*)pCmd, cmdSize, &pEventData);
1720 /* Get Return Data */
1721 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1724 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1726 if (pEvent->eventType != MSG_EVENT_SET_TEMP_ADDRESS_TABLE)
1727 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1729 if (pEvent->result != MSG_SUCCESS)
1734 err = MsgStoGetMessageList(pListCond, pMsgList, count);
1736 if (err != MSG_SUCCESS) {
1737 MSG_DEBUG("MsgStoGetMessageList() Error!!");
1745 msg_error_t MsgHandle::getMediaList(const msg_thread_id_t thread_id, msg_list_handle_t *pMediaList)
1747 msg_error_t err = MSG_SUCCESS;
1749 if (checkPermission() == MSG_ERR_PERMISSION_DENIED) {
1750 MSG_ERR("Client doesn't have permission");
1751 return MSG_ERR_PERMISSION_DENIED;
1754 err = MsgStoGetMediaList(thread_id, pMediaList);
1756 if (err != MSG_SUCCESS) {
1757 MSG_DEBUG("MsgStoGetFmMediaList() Error!!");
1765 int MsgHandle::addPushEvent(MSG_PUSH_EVENT_INFO_S *pPushEvent)
1767 /* Allocate Memory to Command Data */
1768 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_PUSH_EVENT_INFO_S);
1770 char cmdBuf[cmdSize];
1771 bzero(cmdBuf, cmdSize);
1772 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1774 /* Set Command Parameters */
1775 pCmd->cmdType = MSG_CMD_ADD_PUSH_EVENT;
1778 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1780 /* Copy Command Data */
1781 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pPushEvent, sizeof(MSG_PUSH_EVENT_INFO_S));
1783 /* Send Command to Messaging FW */
1784 char* pEventData = NULL;
1785 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1787 write((char*)pCmd, cmdSize, &pEventData);
1789 /* Get Return Data */
1790 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1793 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1795 if (pEvent->eventType != MSG_EVENT_ADD_PUSH_EVENT) {
1796 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1799 return pEvent->result;
1803 int MsgHandle::deletePushEvent(MSG_PUSH_EVENT_INFO_S *pPushEvent)
1805 /* Allocate Memory to Command Data */
1806 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_PUSH_EVENT_INFO_S);
1808 char cmdBuf[cmdSize];
1809 bzero(cmdBuf, cmdSize);
1810 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1812 /* Set Command Parameters */
1813 pCmd->cmdType = MSG_CMD_DELETE_PUSH_EVENT;
1816 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1818 /* Copy Command Data */
1819 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pPushEvent, sizeof(MSG_PUSH_EVENT_INFO_S));
1821 /* Send Command to Messaging FW */
1822 char* pEventData = NULL;
1823 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1825 write((char*)pCmd, cmdSize, &pEventData);
1827 /* Get Return Data */
1828 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1831 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1833 if (pEvent->eventType != MSG_EVENT_DELETE_PUSH_EVENT) {
1834 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1837 return pEvent->result;
1841 int MsgHandle::updatePushEvent(MSG_PUSH_EVENT_INFO_S *pSrc, MSG_PUSH_EVENT_INFO_S *pDst)
1843 /* Allocate Memory to Command Data */
1844 int cmdSize = sizeof(MSG_CMD_S) + 2 * sizeof(MSG_PUSH_EVENT_INFO_S);
1846 char cmdBuf[cmdSize];
1847 bzero(cmdBuf, cmdSize);
1848 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1850 /* Set Command Parameters */
1851 pCmd->cmdType = MSG_CMD_UPDATE_PUSH_EVENT;
1854 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1856 /* Copy Command Data */
1857 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pSrc, sizeof(MSG_PUSH_EVENT_INFO_S));
1858 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_PUSH_EVENT_INFO_S)), pDst, sizeof(MSG_PUSH_EVENT_INFO_S));
1860 /* Send Command to Messaging FW */
1861 char* pEventData = NULL;
1862 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1864 write((char*)pCmd, cmdSize, &pEventData);
1866 /* Get Return Data */
1867 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1870 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1872 if (pEvent->eventType != MSG_EVENT_UPDATE_PUSH_EVENT) {
1873 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1876 return pEvent->result;
1880 msg_error_t MsgHandle::getVobject(msg_message_id_t MsgId, void** encodedData)
1882 /* Allocate Memory to Command Data */
1883 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
1884 char *encode_data = NULL;
1885 char cmdBuf[cmdSize];
1886 bzero(cmdBuf, cmdSize);
1887 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1889 /* Set Command Parameters */
1890 pCmd->cmdType = MSG_CMD_GET_MSG;
1893 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1895 /* Copy Command Data */
1896 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
1898 /* Send Command to Messaging FW */
1899 char* pEventData = NULL;
1900 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1903 write((char*)pCmd, cmdSize, &pEventData);
1905 /* Get Return Data */
1906 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
1909 THROW(MsgException::INVALID_RESULT, "Event is NULL");
1911 if (pEvent->eventType != MSG_EVENT_GET_MSG) {
1912 THROW(MsgException::INVALID_RESULT, "Event Data Error");
1915 if (pEvent->result != MSG_SUCCESS)
1916 return pEvent->result;
1918 /* Decode Return Data */
1919 MSG_MESSAGE_INFO_S msgInfo = {0, };
1920 MSG_SENDINGOPT_INFO_S sendOptInfo = {0, };
1922 msgInfo.addressList = NULL;
1923 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1925 MsgDecodeMsgInfo(pEvent->data, &msgInfo, &sendOptInfo);
1927 /*Convert MSG_MESSAGE_INFO_S to */
1928 encode_data = MsgVMessageEncode(&msgInfo);
1930 *encodedData = (void*)encode_data;
1932 MSG_DEBUG("Error Encode data");
1933 *encodedData = NULL;
1936 /* Delete Temp File */
1937 if (msgInfo.bTextSms == false) {
1938 /* Delete Temp File */
1939 MsgDeleteFile(msgInfo.msgData); /* ipc */
1946 msg_error_t MsgHandle::dbSelectWithQuery(const char *query, char ***db_res, int *row_count, int *col_count)
1948 msg_error_t err = MSG_SUCCESS;
1950 if (checkPermission() == MSG_ERR_PERMISSION_DENIED) {
1951 MSG_ERR("Client doesn't have permission");
1952 return MSG_ERR_PERMISSION_DENIED;
1955 err = MsgStoDbSelectWithQuery(query, db_res, row_count, col_count);
1957 if (err != MSG_SUCCESS)
1966 void MsgHandle::dbFree(char **db_res)
1968 MsgStoDbFree(db_res);
1973 msg_error_t MsgHandle::allowTcsMessage(msg_message_id_t MsgId)
1976 int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
1978 char cmdBuf[cmdSize];
1979 bzero(cmdBuf, cmdSize);
1980 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
1982 /* Set Command Parameters */
1983 pCmd->cmdType = MSG_CMD_ALLOW_TCS_MESSAGE;
1986 memcpy((void*)pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
1988 /* Copy Command Data */
1989 memcpy((void*)((char*)pCmd + sizeof(MSG_CMD_TYPE_T) + MAX_COOKIE_LEN), &MsgId, sizeof(msg_message_id_t));
1991 /* Send Command to Messaging FW */
1992 char* pEventData = NULL;
1993 unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
1995 write((char*)pCmd, cmdSize, &pEventData);
1997 /* Get Return Data */
1998 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
2000 if (pEvent == NULL) {
2001 THROW(MsgException::INVALID_RESULT, "Event is NULL");
2004 if (pEvent->eventType != MSG_EVENT_ALLOW_TCS_MESSAGE) {
2005 THROW(MsgException::INVALID_RESULT, "Event Data Error");
2008 return pEvent->result;