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