Add permission check for open handle
[platform/core/messaging/msg-service.git] / proxy / MsgHandleControl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15 */
16
17 #include <errno.h>
18 #include <stdlib.h>
19
20 #include "MsgDebug.h"
21 #include "MsgCppTypes.h"
22 #include "MsgException.h"
23 #include "MsgUtilFile.h"
24 #include "MsgGconfWrapper.h"
25 #include "MsgProxyContact.h"
26 #include "MsgProxyListener.h"
27 #include "MsgHandle.h"
28 #include "MsgSqliteWrapper.h"
29
30 /*==================================================================================================
31                                      IMPLEMENTATION OF MsgHandle - Control Member Functions
32 ==================================================================================================*/
33 MsgHandle::MsgHandle() : mCounter(0), mClientSock()
34 {
35         memset(mConnectionId, 0x00, sizeof(mConnectionId));
36         memset(mCookie, 0x00, sizeof(mCookie));
37 }
38
39
40 MsgHandle::~MsgHandle()
41 {
42 }
43
44
45 void MsgHandle::openHandle()
46 {
47         bool bReady = false;
48
49         MsgProxyListener::instance()->insertOpenHandleSet(this);
50
51         /* server is currently booting and service is not available until the end of booting */
52         if (MsgSettingGetBool(VCONFKEY_MSG_SERVER_READY, &bReady) != MSG_SUCCESS)
53                 MSG_INFO("MsgSettingGetBool() is failed");
54
55         if (bReady == false) {
56                 THROW(MsgException::SERVER_READY_ERROR, "Msg Server is not ready !!!!!");
57         } else {
58                 MSG_INFO("Msg Server is ready !!!!!");
59         }
60
61         /* Open Socket IPC */
62         connectSocket();
63
64         /* Check cynara permission */
65         if (checkPermission() == MSG_ERR_PERMISSION_DENIED) {
66                 THROW(MsgException::SECURITY_ERROR, "Client doesn't have permission");
67         }
68 }
69
70
71 void MsgHandle::closeHandle(MsgHandle* pHandle)
72 {
73         MSG_BEGIN();
74
75         /* Remove CB List of closing Handle */
76         MsgProxyListener* eventListener = MsgProxyListener::instance();
77
78         eventListener->clearListOfClosedHandle(pHandle);
79         /* eventListener->stop(); */
80
81         /* Close Socket IPC */
82         disconnectSocket();
83
84 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
85         /* Close Contact Service */
86         if (MsgCloseContactSvc() != MSG_SUCCESS) {
87                 MSG_WARN("Fail to close contact service.");
88         }
89 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
90         removeDbHandle(); /* unregister db handler */
91
92         MSG_END();
93 }
94
95
96 void MsgHandle::connectSocket()
97 {
98         mClientSock.connect(MSG_SOCKET_PATH);
99 }
100
101
102 void MsgHandle::disconnectSocket()
103 {
104         mClientSock.close();
105 }
106
107
108 void MsgHandle::write(const char *pCmdData, int cmdSize, char **ppEvent)
109 {
110         if (pCmdData == NULL || ppEvent == NULL) {
111                 THROW(MsgException::INVALID_PARAM, "Param is NULL");
112         }
113
114         int ret = 0;
115
116         /* Send Command to MSG FW */
117         MsgMutexLocker lock(mx);
118         ret = mClientSock.write(pCmdData, cmdSize);
119         if (ret < 0)
120                 THROW(MsgException::IPC_ERROR, "IPC write error");
121
122         char *tmpEvent = NULL;
123
124         while (1) {
125                 /* Receive Result from MSG FW */
126                 read(&tmpEvent);
127
128                 if (tmpEvent == NULL) {
129                         MSG_DEBUG("Event Data is NULL!!");
130                         break;
131                 }
132
133                 if (!checkEventData(tmpEvent)) {
134                         delete [] tmpEvent;
135                         tmpEvent = NULL;
136                 } else {
137                         *ppEvent = tmpEvent;
138                         break;
139                 }
140         }
141 }
142
143
144 void MsgHandle::read(char **ppEvent)
145 {
146         unsigned int dataSize = 0;
147
148         int ret = mClientSock.read(ppEvent, &dataSize);
149
150         if (ret == CLOSE_CONNECTION_BY_SIGNAL) {
151                 THROW(MsgException::IPC_ERROR, "Server closed connection");
152         }
153 }
154
155
156 void MsgHandle::convertMsgStruct(const MSG_MESSAGE_HIDDEN_S *pSrc, MSG_MESSAGE_INFO_S *pDest)
157 {
158         MSG_BEGIN();
159
160         pDest->msgId = pSrc->msgId;
161         pDest->threadId = pSrc->threadId;
162         pDest->folderId = pSrc->folderId;
163         pDest->msgType.mainType = pSrc->mainType;
164         pDest->msgType.subType = pSrc->subType;
165         pDest->msgType.classType = pSrc->classType;
166         pDest->storageId = pSrc->storageId;
167
168         if (g_list_length(pSrc->addressList) > 0) {
169                 msg_struct_s *addr_info = NULL;
170                 MSG_ADDRESS_INFO_S *address = NULL;
171
172                 pDest->nAddressCnt = g_list_length(pSrc->addressList);
173                 pDest->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * pDest->nAddressCnt];
174                 memset(pDest->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * pDest->nAddressCnt);
175
176                 for (int i = 0; i < pDest->nAddressCnt; i++) {
177                         addr_info = (msg_struct_s *)g_list_nth_data(pSrc->addressList, (guint)i);
178                         address = (MSG_ADDRESS_INFO_S *)addr_info->data;
179
180                         pDest->addressList[i].addressType = address->addressType;
181                         pDest->addressList[i].recipientType = address->recipientType;
182                         pDest->addressList[i].contactId = address->contactId;
183                         strncpy(pDest->addressList[i].addressVal, address->addressVal, MAX_ADDRESS_VAL_LEN);
184                         strncpy(pDest->addressList[i].displayName, address->displayName, MAX_DISPLAY_NAME_LEN);
185                 }
186         } else {
187                 msg_struct_list_s *addr_info_s = pSrc->addr_list;
188
189                 if (addr_info_s && (addr_info_s->nCount > 0)) {
190                         msg_struct_s *addr_info = NULL;
191                         MSG_ADDRESS_INFO_S *address = NULL;
192
193                         pDest->nAddressCnt = addr_info_s->nCount;
194
195                         pDest->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S) * addr_info_s->nCount];
196                         memset(pDest->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S) * addr_info_s->nCount);
197
198                         for (int i = 0; i < addr_info_s->nCount; i++) {
199                                 addr_info = (msg_struct_s *)addr_info_s->msg_struct_info[i];
200
201                                 address = (MSG_ADDRESS_INFO_S *)addr_info->data;
202
203                                 pDest->addressList[i].addressType = address->addressType;
204                                 pDest->addressList[i].recipientType = address->recipientType;
205                                 pDest->addressList[i].contactId = address->contactId;
206                                 strncpy(pDest->addressList[i].addressVal, address->addressVal, MAX_ADDRESS_VAL_LEN);
207                                 strncpy(pDest->addressList[i].displayName, address->displayName, MAX_DISPLAY_NAME_LEN);
208                         }
209                 }
210         }
211
212         strncpy(pDest->replyAddress, pSrc->replyAddress, MAX_PHONE_NUMBER_LEN);
213         strncpy(pDest->subject, pSrc->subject, MAX_SUBJECT_LEN);
214
215         pDest->displayTime = pSrc->displayTime;
216         pDest->networkStatus = pSrc->networkStatus;
217         pDest->encodeType = pSrc->encodeType;
218         pDest->bRead = pSrc->bRead;
219         pDest->bProtected = pSrc->bProtected;
220         pDest->bBackup = pSrc->bBackup;
221         pDest->priority = pSrc->priority;
222         pDest->direction = pSrc->direction;
223
224         /* Set Port Info. */
225         pDest->msgPort.valid = pSrc->bPortValid;
226
227         if (pDest->msgPort.valid == true) {
228                 pDest->msgPort.dstPort = pSrc->dstPort;
229                 pDest->msgPort.srcPort = pSrc->srcPort;
230         }
231
232         MSG_DEBUG("nSize = %d",  pSrc->dataSize);
233         MSG_DEBUG("mainType = %d",  pSrc->mainType);
234
235         if (pSrc->mainType == MSG_SMS_TYPE) {
236                 if (pSrc->pData != NULL) {
237                         pDest->bTextSms = true;
238                         pDest->dataSize = pSrc->dataSize;
239
240                         memset(pDest->msgText, 0x00, sizeof(pDest->msgText));
241
242                         if (pSrc->dataSize > MAX_MSG_TEXT_LEN) {
243                                 /* Save Message Data into File */
244                                 char fileName[MSG_FILENAME_LEN_MAX+1];
245                                 memset(fileName, 0x00, sizeof(fileName));
246
247                                 if (MsgCreateFileName(fileName) == false)
248                                         THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
249
250                                 MSG_SEC_DEBUG("Save pSrc->pData into file : size[%d] name[%s]", pDest->dataSize, fileName);
251
252                                 if (MsgWriteIpcFile(fileName, (char*)pSrc->pData, pSrc->dataSize) == false)
253                                         THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
254
255                                 memset(pDest->msgData, 0x00, sizeof(pDest->msgData));
256                                 strncpy(pDest->msgData, fileName, MAX_MSG_DATA_LEN);
257
258                                 pDest->bTextSms = false;
259
260                         } else {
261                                 if (pDest->encodeType == MSG_ENCODE_8BIT)
262                                         memcpy(pDest->msgText, pSrc->pData, pSrc->dataSize);
263                                 else
264                                         strncpy(pDest->msgText, (char*)pSrc->pData, pSrc->dataSize);
265                         }
266
267                         MSG_DEBUG("pData = %s", pSrc->pData);
268                 } else {
269                         MSG_DEBUG("pSrc->pData is NULL.");
270                         pDest->bTextSms = true;
271                         pDest->dataSize = 0;
272                 }
273
274                 MSG_SEC_DEBUG("msgText = %s", pDest->msgText);
275         } else if (pSrc->mainType == MSG_MMS_TYPE) {
276                 pDest->bTextSms = false;
277                 pDest->dataSize = pSrc->dataSize;
278
279                 if (pSrc->subType == MSG_READREPLY_MMS) {
280                         memset(pDest->msgData, 0x00, sizeof(pDest->msgData));
281
282                         if (pSrc->mmsDataSize < MAX_MSG_DATA_LEN)
283                                 memcpy(pDest->msgData, pSrc->pMmsData, pSrc->mmsDataSize);
284                         else
285                                 memcpy(pDest->msgData, pSrc->pMmsData, MAX_MSG_DATA_LEN);
286
287                 } else {
288                         /* Save Message Data into File */
289                         char fileName[MSG_FILENAME_LEN_MAX+1];
290                         memset(fileName, 0x00, sizeof(fileName));
291
292                         if (MsgCreateFileName(fileName) == false)
293                                 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
294
295                         /* change file extension in case of java MMS msg */
296                         if (pSrc->subType == MSG_SENDREQ_JAVA_MMS) {
297                                 char* pFileNameExt = NULL;
298                                 pFileNameExt = strstr(fileName, "DATA");
299                                 if (pFileNameExt)
300                                         snprintf(pFileNameExt, strlen("JAVA")+1, "JAVA");
301                         }
302
303                         MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]", pSrc->mmsDataSize, fileName);
304                         if (MsgWriteIpcFile(fileName, (char*)pSrc->pMmsData, pSrc->mmsDataSize) == false)
305                                 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
306
307                         memset(pDest->msgData, 0x00, sizeof(pDest->msgData));
308                         strncpy(pDest->msgData, fileName, MAX_MSG_DATA_LEN);
309                         if (pSrc->pData) {
310                                 strncpy(pDest->msgText, (char*)pSrc->pData, MAX_MSG_TEXT_LEN);
311                         }
312
313                         if (strlen(pSrc->thumbPath) > 0) {
314                                 memset(pDest->thumbPath, 0x00, sizeof(pDest->thumbPath));
315                                 memcpy(pDest->thumbPath, pSrc->thumbPath, sizeof(pDest->thumbPath));
316                         }
317                 }
318         }
319
320         pDest->sim_idx = pSrc->simIndex;
321
322         MSG_END();
323 }
324
325
326 void MsgHandle::convertMsgStruct(const MSG_MESSAGE_INFO_S *pSrc, MSG_MESSAGE_HIDDEN_S *pDest)
327 {
328         MSG_BEGIN();
329
330         pDest->msgId = pSrc->msgId;
331         pDest->threadId = pSrc->threadId;
332         pDest->folderId = pSrc->folderId;
333         pDest->mainType = pSrc->msgType.mainType;
334         pDest->subType = pSrc->msgType.subType;
335         pDest->storageId = pSrc->storageId;
336
337         strncpy(pDest->replyAddress, pSrc->replyAddress, MAX_PHONE_NUMBER_LEN);
338         strncpy(pDest->subject, pSrc->subject, MAX_SUBJECT_LEN);
339
340         pDest->displayTime = pSrc->displayTime;
341         pDest->networkStatus = pSrc->networkStatus;
342         pDest->encodeType = pSrc->encodeType;
343         pDest->bRead = pSrc->bRead;
344         pDest->bProtected = pSrc->bProtected;
345         pDest->bBackup = pSrc->bBackup;
346         pDest->priority = pSrc->priority;
347         pDest->direction = pSrc->direction;
348         pDest->simIndex = pSrc->sim_idx;
349
350         /* Set Port Info. */
351         pDest->bPortValid = pSrc->msgPort.valid;
352
353         if (pDest->bPortValid == true) {
354                 pDest->dstPort = pSrc->msgPort.dstPort;
355                 pDest->srcPort = pSrc->msgPort.srcPort;
356         }
357
358         if (pSrc->thumbPath[0] != '\0')
359                 strncpy(pDest->thumbPath, pSrc->thumbPath, MSG_FILEPATH_LEN_MAX);
360
361         int maxCnt = (pSrc->nAddressCnt > 10)? MAX_TO_ADDRESS_CNT: pSrc->nAddressCnt;
362
363         pDest->addr_list->nCount = maxCnt;
364
365         msg_struct_s *addr_info_s = NULL;
366         MSG_ADDRESS_INFO_S *addr_info = NULL;
367
368         for (int i = 0; i < maxCnt; i++) {
369                 addr_info_s = (msg_struct_s *)pDest->addr_list->msg_struct_info[i];
370                 addr_info = (MSG_ADDRESS_INFO_S *)addr_info_s->data;
371
372                 addr_info->addressType = pSrc->addressList[i].addressType;
373                 addr_info->recipientType = pSrc->addressList[i].recipientType;
374                 addr_info->contactId = pSrc->addressList[i].contactId;
375                 strncpy(addr_info->addressVal, pSrc->addressList[i].addressVal, MAX_ADDRESS_VAL_LEN);
376                 strncpy(addr_info->displayName, pSrc->addressList[i].displayName, MAX_DISPLAY_NAME_LEN);
377                 addr_info->displayName[MAX_DISPLAY_NAME_LEN] = '\0';
378         }
379
380         for (int i = 0; i < pSrc->nAddressCnt; i++) {
381                 addr_info_s = new msg_struct_s;
382                 memset(addr_info_s, 0x00, sizeof(msg_struct_s));
383
384                 addr_info_s->type = MSG_STRUCT_ADDRESS_INFO;
385                 addr_info_s->data = new MSG_ADDRESS_INFO_S;
386                 memset(addr_info_s->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
387
388                 addr_info = (MSG_ADDRESS_INFO_S *)addr_info_s->data;
389
390                 addr_info->addressType = pSrc->addressList[i].addressType;
391                 addr_info->recipientType = pSrc->addressList[i].recipientType;
392                 addr_info->contactId = pSrc->addressList[i].contactId;
393                 strncpy(addr_info->addressVal, pSrc->addressList[i].addressVal, MAX_ADDRESS_VAL_LEN);
394                 strncpy(addr_info->displayName, pSrc->addressList[i].displayName, MAX_DISPLAY_NAME_LEN);
395                 addr_info->displayName[MAX_DISPLAY_NAME_LEN] = '\0';
396
397                 pDest->addressList = g_list_append(pDest->addressList, addr_info_s);
398         }
399
400
401         if (pSrc->bTextSms == false) {
402                 int fileSize = 0;
403
404                 char* pFileData = NULL;
405                 unique_ptr<char*, void(*)(char**)> buf(&pFileData, unique_ptr_deleter);
406
407                 pDest->dataSize = pSrc->dataSize;
408
409                 /* Get Message Data from File */
410                 if (MsgOpenAndReadFile(pSrc->msgData, &pFileData, &fileSize) == false)
411                         THROW(MsgException::FILE_ERROR, "MsgOpenAndReadFile error");
412
413                 if (pSrc->msgType.mainType == MSG_SMS_TYPE) {
414                         if (pDest->encodeType == MSG_ENCODE_8BIT) {
415                                 pDest->pData = (void*)new char[fileSize];
416                                 memset(pDest->pData, 0x00, fileSize);
417                                 memcpy(pDest->pData, pFileData, fileSize);
418                         } else {
419                                 pDest->pData = (void*)new char[fileSize+1];
420                                 memset(pDest->pData, 0x00, fileSize+1);
421                                 strncpy((char*)pDest->pData, pFileData, fileSize);
422                         }
423                 } else {
424                         if (pSrc->msgText[0] != '\0') {
425                                 pDest->pData = (void*)new char[strlen(pSrc->msgText)+1];
426                                 memset(pDest->pData, 0x00, strlen(pSrc->msgText)+1);
427                                 strncpy((char*)pDest->pData, pSrc->msgText, strlen(pSrc->msgText));
428                         }
429                         pDest->mmsDataSize = fileSize;
430                         pDest->pMmsData = (void*)new char[fileSize];
431                         memset(pDest->pMmsData, 0x00, fileSize);
432                         memcpy(pDest->pMmsData, pFileData, fileSize);
433                         MSG_SEC_DEBUG("Get Message Data from file : size[%d] name[%s]", pDest->mmsDataSize, pSrc->msgData);
434                 }
435
436         } else {
437                 pDest->dataSize = pSrc->dataSize;
438
439                 if (pSrc->msgType.mainType == MSG_SMS_TYPE) {
440                         if (pDest->encodeType == MSG_ENCODE_8BIT || pSrc->msgType.subType == MSG_ETWS_SMS) {
441                                 pDest->pData = (void*)new char[pDest->dataSize];
442                                 memset(pDest->pData, 0x00, pDest->dataSize);
443                                 memcpy(pDest->pData, pSrc->msgText, pDest->dataSize);
444                         } else {
445                                 pDest->pData = (void*)new char[pDest->dataSize+1];
446                                 memset(pDest->pData, 0x00, pDest->dataSize+1);
447                                 strncpy((char*)pDest->pData, pSrc->msgText, pDest->dataSize);
448                         }
449                 } else {
450                         if (pSrc->msgText[0] != '\0') {
451                                 pDest->pData = (void*)new char[strlen(pSrc->msgText)+1];
452                                 memset(pDest->pData, 0x00, strlen(pSrc->msgText)+1);
453                                 strncpy((char*)pDest->pData, pSrc->msgText, strlen(pSrc->msgText));
454                         }
455
456                         pDest->mmsDataSize = pDest->dataSize;
457                         pDest->pMmsData = (void*)new char[pDest->dataSize];
458                         memset(pDest->pMmsData, 0x00, pDest->dataSize);
459                         memcpy(pDest->pMmsData, pSrc->msgData, pDest->dataSize);
460                 }
461         }
462
463         MSG_END();
464 }
465
466
467 void MsgHandle::convertSendOptStruct(const MSG_SENDINGOPT_S* pSrc, MSG_SENDINGOPT_INFO_S* pDest, MSG_MESSAGE_TYPE_S msgType)
468 {
469         MSG_BEGIN();
470
471         pDest->bSetting = pSrc->bSetting;
472
473         if (pSrc->bSetting == false) {
474                 MSG_DEBUG("No Sending Option");
475                 return;
476         }
477
478         pDest->bDeliverReq = pSrc->bDeliverReq;
479         pDest->bKeepCopy = pSrc->bKeepCopy;
480
481         MSG_DEBUG("pDest->bSetting = %d", pDest->bSetting);
482         MSG_DEBUG("pDest->bDeliverReq = %d", pDest->bDeliverReq);
483         MSG_DEBUG("pDest->bKeepCopy = %d", pDest->bKeepCopy);
484
485         if (msgType.mainType == MSG_SMS_TYPE) {
486                 msg_struct_s *pStruct = (msg_struct_s *)pSrc->smsSendOpt;
487                 if (pStruct) {
488                         SMS_SENDINGOPT_S *pSms = (SMS_SENDINGOPT_S *)pStruct->data;
489                         if (pSms) {
490                                 pDest->option.smsSendOptInfo.bReplyPath = pSms->bReplyPath;
491                         }
492                 }
493         } else if (msgType.mainType == MSG_MMS_TYPE) {
494                 msg_struct_s *pStruct = (msg_struct_s *)pSrc->mmsSendOpt;
495                 if (pStruct) {
496                         MMS_SENDINGOPT_S *pMms = (MMS_SENDINGOPT_S *)pStruct->data;
497                         if (pMms) {
498                                 pDest->option.mmsSendOptInfo.priority = pMms->priority;
499                                 pDest->option.mmsSendOptInfo.bReadReq = pMms->bReadReq;
500
501                                 MSG_DEBUG("pDest->option.mmsSendOpt.priority = %d", pMms->priority);
502                                 MSG_DEBUG("pDest->option.mmsSendOpt.bReadReq = %d", pMms->bReadReq);
503
504                                 if (pMms->expiryTime == 0) {
505                                         pDest->option.mmsSendOptInfo.expiryTime.type = MMS_TIMETYPE_NONE;
506                                         pDest->option.mmsSendOptInfo.expiryTime.time = pMms->expiryTime;
507                                 } else {
508                                         pDest->option.mmsSendOptInfo.expiryTime.type = MMS_TIMETYPE_RELATIVE;
509                                         pDest->option.mmsSendOptInfo.expiryTime.time = pMms->expiryTime;
510                                 }
511
512                                 if (pMms->bUseDeliveryCustomTime == true) {
513                                         pDest->option.mmsSendOptInfo.bUseDeliveryCustomTime = true;
514                                 } else {
515                                         pDest->option.mmsSendOptInfo.bUseDeliveryCustomTime = false;
516                                 }
517                                 pDest->option.mmsSendOptInfo.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
518                                 pDest->option.mmsSendOptInfo.deliveryTime.time = pMms->deliveryTime;
519
520                                 MSG_DEBUG("pDest->option.mmsSendOpt.expiryTime = %d", pDest->option.mmsSendOptInfo.expiryTime.time);
521                         }
522                 }
523         }
524
525         MSG_END();
526 }
527
528
529 void MsgHandle::convertSendOptStruct(const MSG_SENDINGOPT_INFO_S* pSrc, MSG_SENDINGOPT_S* pDest, MSG_MESSAGE_TYPE_S msgType)
530 {
531         MSG_BEGIN();
532
533         pDest->bDeliverReq = pSrc->bDeliverReq;
534         pDest->bKeepCopy = pSrc->bKeepCopy;
535
536         MSG_DEBUG("pDest->bDeliverReq = %d", pDest->bDeliverReq);
537         MSG_DEBUG("pDest->bKeepCopy = %d", pDest->bKeepCopy);
538
539         if (msgType.mainType == MSG_SMS_TYPE) {
540                 msg_struct_s *pStruct = (msg_struct_s *)pDest->smsSendOpt;
541                 SMS_SENDINGOPT_S *pSms = (SMS_SENDINGOPT_S *)pStruct->data;
542                 pSms->bReplyPath = pSrc->option.smsSendOptInfo.bReplyPath;
543         } else if (msgType.mainType == MSG_MMS_TYPE) {
544                 msg_struct_s *pStruct = (msg_struct_s *)pDest->mmsSendOpt;
545                 MMS_SENDINGOPT_S *pMms = (MMS_SENDINGOPT_S *)pStruct->data;
546                 pMms->priority = pSrc->option.mmsSendOptInfo.priority;
547                 pMms->bReadReq = pSrc->option.mmsSendOptInfo.bReadReq;
548                 pMms->expiryTime = pSrc->option.mmsSendOptInfo.expiryTime.time;
549                 pMms->deliveryTime = pSrc->option.mmsSendOptInfo.deliveryTime.time;
550
551                 MSG_DEBUG("pDest->option.mmsSendOpt.priority = %d", pMms->priority);
552                 MSG_DEBUG("pDest->option.mmsSendOpt.bReadReq = %d", pMms->bReadReq);
553                 MSG_DEBUG("pDest->option.mmsSendOpt.expiryTime = %d", pMms->expiryTime);
554         }
555
556         MSG_END();
557 }
558
559
560 int MsgHandle::getSettingCmdSize(MSG_OPTION_TYPE_T optionType)
561 {
562         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_OPTION_TYPE_T);
563
564         switch (optionType) {
565         case MSG_GENERAL_OPT:
566                 cmdSize += sizeof(MSG_GENERAL_OPT_S);
567         break;
568         case MSG_SMS_SENDOPT:
569                 cmdSize += sizeof(MSG_SMS_SENDOPT_S);
570         break;
571         case MSG_SMSC_LIST:
572                 cmdSize += sizeof(MSG_SMSC_LIST_S);
573         break;
574         case MSG_MMS_SENDOPT:
575                 cmdSize += sizeof(MSG_MMS_SENDOPT_S);
576         break;
577         case MSG_MMS_RECVOPT:
578                 cmdSize += sizeof(MSG_MMS_RECVOPT_S);
579         break;
580         case MSG_MMS_STYLEOPT:
581                 cmdSize += sizeof(MSG_MMS_STYLEOPT_S);
582         break;
583         case MSG_PUSHMSG_OPT:
584                 cmdSize += sizeof(MSG_PUSHMSG_OPT_S);
585         break;
586         case MSG_CBMSG_OPT:
587                 cmdSize += sizeof(MSG_CBMSG_OPT_S);
588         break;
589         case MSG_VOICEMAIL_OPT:
590                 cmdSize += sizeof(MSG_VOICEMAIL_OPT_S);
591         break;
592         case MSG_MSGSIZE_OPT:
593                 cmdSize += sizeof(MSG_MSGSIZE_OPT_S);
594         break;
595         }
596
597         return cmdSize;
598 }
599
600
601 bool MsgHandle::checkEventData(char *pEventData)
602 {
603         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
604
605         switch (pEvent->eventType) {
606         case MSG_EVENT_PLG_SENT_STATUS_CNF:
607         case MSG_EVENT_PLG_INCOMING_MSG_IND:
608         case MSG_EVENT_PLG_INCOMING_MMS_CONF:
609         case MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND:
610         case MSG_EVENT_PLG_INCOMING_LBS_MSG_IND:
611         case MSG_EVENT_PLG_STORAGE_CHANGE_IND:
612         case MSG_EVENT_PLG_INCOMING_CB_MSG_IND:
613         case MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND:
614         case MSG_EVENT_PLG_REPORT_MSG_INCOMING_IND:
615                 return false;
616                 break;
617         default :
618                 return true;
619                 break;
620         }
621
622         return true;
623 }
624
625 msg_error_t MsgHandle::checkPermission(void)
626 {
627         /* Allocate Memory to Command Data */
628         int cmdSize = sizeof(MSG_CMD_S);
629
630         char cmdBuf[cmdSize];
631         bzero(cmdBuf, cmdSize);
632         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
633
634         /* Set Command Parameters */
635         pCmd->cmdType = MSG_CMD_CHECK_PERMISSION;
636
637         /* Send Command to Messaging FW */
638         char* pEventData = NULL;
639         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
640
641         write((char*)pCmd, cmdSize, &pEventData);
642
643         /* Get Return Data */
644         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
645
646         if (pEvent == NULL)
647                 THROW(MsgException::INVALID_RESULT, "Event is NULL");
648
649         if (pEvent->eventType != MSG_EVENT_CHECK_PERMISSION) {
650                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
651         }
652
653         return pEvent->result;
654 }