4 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include <security-server.h>
26 #include "MsgCppTypes.h"
27 #include "MsgException.h"
28 #include "MsgUtilFile.h"
29 #include "MsgGconfWrapper.h"
30 #include "MsgProxyListener.h"
31 #include "MsgHandle.h"
33 /*==================================================================================================
34 IMPLEMENTATION OF MsgHandle - Control Member Functions
35 ==================================================================================================*/
36 MsgHandle::MsgHandle() : mCounter(0), mClientSock()
38 memset(mConnectionId, 0x00, sizeof(mConnectionId));
39 memset(mCookie, 0x00, sizeof(mCookie));
43 MsgHandle::~MsgHandle()
49 void MsgHandle::openHandle()
56 // server is currently booting and service is not available until the end of booting
57 MsgSettingGetBool(VCONFKEY_MSG_SERVER_READY, &bReady);
59 if (bReady == false) {
60 THROW(MsgException::SERVER_READY_ERROR, "Msg Server is not ready !!!!!");
62 MSG_DEBUG("Msg Server is ready !!!!!");
66 // cookieSize = security_server_get_cookie_size();
68 // MSG_DEBUG("cookie size : [%d]", cookieSize);
71 // ret = security_server_request_cookie(mCookie, cookieSize);
74 // MSG_DEBUG("security_server_request_cookie() error!! [%d]", ret);
83 void MsgHandle::closeHandle(MsgHandle* pHandle)
87 //Remove CB List of closing Handle
88 MsgProxyListener* eventListener = MsgProxyListener::instance();
90 eventListener->clearListOfClosedHandle(pHandle);
91 //eventListener->stop();
100 void MsgHandle::connectSocket()
102 mClientSock.connect(MSG_SOCKET_PATH);
106 void MsgHandle::disconnectSocket()
112 void MsgHandle::write(const char *pCmdData, int cmdSize, char **ppEvent)
114 if (pCmdData == NULL || ppEvent == NULL) {
115 THROW(MsgException::INVALID_PARAM, "Param is NULL");
120 // Send Command to MSG FW
121 ret = mClientSock.write(pCmdData, cmdSize);
123 THROW(MsgException::IPC_ERROR, "IPC write error");
125 // Receive Result from MSG FW
128 if (*ppEvent == NULL) {
129 THROW(MsgException::INVALID_RESULT, "event is NULL");
135 void MsgHandle::read(char **ppEvent)
137 unsigned int dataSize = 0;
139 dataSize = mClientSock.read(ppEvent, &dataSize);
142 THROW(MsgException::IPC_ERROR, "Server closed connection");
147 void MsgHandle::convertMsgStruct(const MSG_MESSAGE_HIDDEN_S *pSrc, MSG_MESSAGE_INFO_S *pDest)
151 pDest->msgId = pSrc->msgId;
152 pDest->threadId = pSrc->threadId;
153 pDest->folderId = pSrc->folderId;
154 pDest->msgType.mainType = pSrc->mainType;
155 pDest->msgType.subType = pSrc->subType;
156 pDest->msgType.classType= pSrc->classType;
157 pDest->storageId = pSrc->storageId;
159 msg_struct_list_s *addr_info_s = pSrc->addr_list;
162 msg_struct_s *addr_info = NULL;
163 MSG_ADDRESS_INFO_S *address = NULL;
165 pDest->nAddressCnt = addr_info_s->nCount;
167 for (int i = 0; i < addr_info_s->nCount; i++)
169 addr_info = (msg_struct_s *)addr_info_s->msg_struct_info[i];
170 address = (MSG_ADDRESS_INFO_S *)addr_info->data;
172 pDest->addressList[i].addressType = address->addressType;
173 pDest->addressList[i].recipientType = address->recipientType;
174 pDest->addressList[i].contactId = address->contactId;
175 strncpy(pDest->addressList[i].addressVal, address->addressVal, MAX_ADDRESS_VAL_LEN);
176 strncpy(pDest->addressList[i].displayName, address->displayName, MAX_DISPLAY_NAME_LEN);
177 pDest->addressList[i].displayName[MAX_DISPLAY_NAME_LEN] = '\0';
181 strncpy(pDest->replyAddress, pSrc->replyAddress, MAX_PHONE_NUMBER_LEN);
182 strncpy(pDest->subject, pSrc->subject, MAX_SUBJECT_LEN);
184 pDest->displayTime = pSrc->displayTime;
185 pDest->networkStatus = pSrc->networkStatus;
186 pDest->encodeType = pSrc->encodeType;
187 pDest->bRead = pSrc->bRead;
188 pDest->bProtected = pSrc->bProtected;
189 pDest->bBackup = pSrc->bBackup;
190 pDest->priority = pSrc->priority;
191 pDest->direction = pSrc->direction;
194 pDest->msgPort.valid = pSrc->bPortValid;
196 if (pDest->msgPort.valid == true) {
197 pDest->msgPort.dstPort = pSrc->dstPort;
198 pDest->msgPort.srcPort = pSrc->srcPort;
201 MSG_DEBUG("nSize = %d", pSrc->dataSize);
203 if (pSrc->mainType == MSG_SMS_TYPE){
204 pDest->bTextSms = true;
205 pDest->dataSize = pSrc->dataSize;
207 memset(pDest->msgText, 0x00, sizeof(pDest->msgText));
209 if (pSrc->dataSize > MAX_MSG_TEXT_LEN) {
210 // Save Message Data into File
211 char fileName[MSG_FILENAME_LEN_MAX+1];
212 memset(fileName, 0x00, sizeof(fileName));
214 if(MsgCreateFileName(fileName) == false)
215 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
217 MSG_DEBUG("Save pSrc->pData into file : size[%d] name[%s]", pDest->dataSize, fileName);
219 if (MsgWriteIpcFile(fileName, (char*)pSrc->pData, pSrc->dataSize) == false)
220 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
222 memset(pDest->msgData, 0x00, sizeof(pDest->msgData));
223 strncpy(pDest->msgData, fileName, MAX_MSG_DATA_LEN);
225 pDest->bTextSms = false;
228 if (pDest->encodeType == MSG_ENCODE_8BIT)
229 memcpy(pDest->msgText, pSrc->pData, pSrc->dataSize);
231 strncpy(pDest->msgText, (char*)pSrc->pData, pSrc->dataSize);
234 MSG_DEBUG("pData = %s", pSrc->pData);
235 MSG_DEBUG("msgText = %s", pDest->msgText);
236 } else if (pSrc->mainType == MSG_MMS_TYPE) {
238 pDest->bTextSms = false;
239 pDest->dataSize = pSrc->dataSize;
241 if(pSrc->subType == MSG_READREPLY_MMS) {
242 memset(pDest->msgData, 0x00, sizeof(pDest->msgData));
244 if (pSrc->mmsDataSize < MAX_MSG_DATA_LEN)
245 memcpy(pDest->msgData, pSrc->pMmsData, pSrc->mmsDataSize);
247 memcpy(pDest->msgData, pSrc->pMmsData, MAX_MSG_DATA_LEN);
250 // Save Message Data into File
251 char fileName[MSG_FILENAME_LEN_MAX+1];
252 memset(fileName, 0x00, sizeof(fileName));
254 if(MsgCreateFileName(fileName) == false)
255 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
257 // change file extension in case of java MMS msg
258 if (pSrc->subType == MSG_SENDREQ_JAVA_MMS) {
260 pFileNameExt = strstr(fileName,"DATA");
261 strncpy(pFileNameExt,"JAVA", MSG_FILENAME_LEN_MAX);
264 MSG_DEBUG("Save Message Data into file : size[%d] name[%s]", pSrc->mmsDataSize, fileName);
265 if (MsgWriteIpcFile(fileName, (char*)pSrc->pMmsData, pSrc->mmsDataSize) == false)
266 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
268 memset(pDest->msgData, 0x00, sizeof(pDest->msgData));
269 strncpy(pDest->msgData, fileName, MAX_MSG_DATA_LEN);
271 strncpy(pDest->msgText, (char*)pSrc->pData, MAX_MSG_TEXT_LEN);
274 if (strlen(pSrc->thumbPath) > 0) {
275 memset(pDest->thumbPath, 0x00, sizeof(pDest->thumbPath));
276 memcpy(pDest->thumbPath, pSrc->thumbPath, sizeof(pDest->thumbPath));
285 void MsgHandle::convertMsgStruct(const MSG_MESSAGE_INFO_S *pSrc, MSG_MESSAGE_HIDDEN_S *pDest)
289 pDest->msgId = pSrc->msgId;
290 pDest->threadId = pSrc->threadId;
291 pDest->folderId = pSrc->folderId;
292 pDest->mainType = pSrc->msgType.mainType;
293 pDest->subType = pSrc->msgType.subType;
294 pDest->storageId = pSrc->storageId;
296 strncpy(pDest->replyAddress, pSrc->replyAddress, MAX_PHONE_NUMBER_LEN);
297 strncpy(pDest->subject, pSrc->subject, MAX_SUBJECT_LEN);
299 pDest->displayTime = pSrc->displayTime;
300 pDest->networkStatus = pSrc->networkStatus;
301 pDest->encodeType = pSrc->encodeType;
302 pDest->bRead = pSrc->bRead;
303 pDest->bProtected = pSrc->bProtected;
304 pDest->bBackup = pSrc->bBackup;
305 pDest->priority = pSrc->priority;
306 pDest->direction = pSrc->direction;
309 pDest->bPortValid = pSrc->msgPort.valid;
311 if (pDest->bPortValid == true) {
312 pDest->dstPort = pSrc->msgPort.dstPort;
313 pDest->srcPort = pSrc->msgPort.srcPort;
316 if(pSrc->thumbPath[0] != '\0')
317 strncpy(pDest->thumbPath, pSrc->thumbPath, MSG_FILEPATH_LEN_MAX);
319 pDest->addr_list->nCount = pSrc->nAddressCnt;
321 msg_struct_s *addr_info_s = NULL;
322 MSG_ADDRESS_INFO_S *addr_info = NULL;
324 for (int i = 0; i < pDest->addr_list->nCount; i++)
326 addr_info_s = (msg_struct_s *)pDest->addr_list->msg_struct_info[i];
327 addr_info = (MSG_ADDRESS_INFO_S *)addr_info_s->data;
329 addr_info->addressType = pSrc->addressList[i].addressType;
330 addr_info->recipientType = pSrc->addressList[i].recipientType;
331 addr_info->contactId = pSrc->addressList[i].contactId;
332 strncpy(addr_info->addressVal, pSrc->addressList[i].addressVal, MAX_ADDRESS_VAL_LEN);
333 strncpy(addr_info->displayName, pSrc->addressList[i].displayName, MAX_DISPLAY_NAME_LEN);
334 addr_info->displayName[MAX_DISPLAY_NAME_LEN] = '\0';
338 if (pSrc->bTextSms == false) {
341 char* pFileData = NULL;
342 AutoPtr<char> buf(&pFileData);
344 pDest->dataSize = pSrc->dataSize;
346 // Get Message Data from File
347 if (pSrc->networkStatus != MSG_NETWORK_RETRIEVE_FAIL) {
349 if (MsgOpenAndReadFile(pSrc->msgData, &pFileData, &fileSize) == false)
350 THROW(MsgException::FILE_ERROR, "MsgOpenAndReadFile error");
352 if (pSrc->msgType.mainType == MSG_SMS_TYPE) {
353 if (pDest->encodeType == MSG_ENCODE_8BIT) {
354 pDest->pData = (void*)new char[fileSize];
355 memset(pDest->pData, 0x00, fileSize);
356 memcpy(pDest->pData, pFileData, fileSize);
358 pDest->pData = (void*)new char[fileSize+1];
359 memset(pDest->pData, 0x00, fileSize+1);
360 strncpy((char*)pDest->pData, pFileData, fileSize);
363 if (pSrc->msgText[0] != '\0') {
364 pDest->pData = (void*)new char[strlen(pSrc->msgText)+1];
365 memset(pDest->pData, 0x00, strlen(pSrc->msgText)+1);
366 strncpy((char*)pDest->pData, pSrc->msgText, strlen(pSrc->msgText));
368 pDest->mmsDataSize = fileSize;
369 pDest->pMmsData = (void*)new char[fileSize];
370 memset(pDest->pMmsData, 0x00, fileSize);
371 memcpy(pDest->pMmsData, pFileData, fileSize);
372 MSG_DEBUG("Get Message Data from file : size[%d] name[%s]", pDest->mmsDataSize, pSrc->msgData);
376 pDest->dataSize = pSrc->dataSize;
378 if (pSrc->msgType.mainType == MSG_SMS_TYPE) {
379 if (pDest->encodeType == MSG_ENCODE_8BIT || pSrc->msgType.subType == MSG_ETWS_SMS) {
380 pDest->pData = (void*)new char[pDest->dataSize];
381 memset(pDest->pData, 0x00, pDest->dataSize);
382 memcpy(pDest->pData, pSrc->msgText, pDest->dataSize);
384 pDest->pData = (void*)new char[pDest->dataSize+1];
385 memset(pDest->pData, 0x00, pDest->dataSize+1);
386 strncpy((char*)pDest->pData, pSrc->msgText, pDest->dataSize);
389 if (pSrc->msgText[0] != '\0') {
390 pDest->pData = (void*)new char[strlen(pSrc->msgText)+1];
391 memset(pDest->pData, 0x00, strlen(pSrc->msgText)+1);
392 strncpy((char*)pDest->pData, pSrc->msgText, strlen(pSrc->msgText));
395 pDest->mmsDataSize = pDest->dataSize;
396 pDest->pMmsData = (void*)new char[pDest->dataSize];
397 memset(pDest->pMmsData, 0x00, pDest->dataSize);
398 memcpy(pDest->pMmsData, pSrc->msgData, pDest->dataSize);
406 void MsgHandle::convertSendOptStruct(const MSG_SENDINGOPT_S* pSrc, MSG_SENDINGOPT_INFO_S* pDest, MSG_MESSAGE_TYPE_S msgType)
410 pDest->bSetting = pSrc->bSetting;
412 if (pSrc->bSetting == false) {
413 MSG_DEBUG("No Sending Option");
417 pDest->bDeliverReq = pSrc->bDeliverReq;
418 pDest->bKeepCopy = pSrc->bKeepCopy;
420 MSG_DEBUG("pDest->bSetting = %d", pDest->bSetting);
421 MSG_DEBUG("pDest->bDeliverReq = %d", pDest->bDeliverReq);
422 MSG_DEBUG("pDest->bKeepCopy = %d", pDest->bKeepCopy);
424 if (msgType.mainType == MSG_SMS_TYPE) {
425 msg_struct_s *pStruct = (msg_struct_s *)pSrc->smsSendOpt;
428 SMS_SENDINGOPT_S *pSms = (SMS_SENDINGOPT_S *)pStruct->data;
431 pDest->option.smsSendOptInfo.bReplyPath = pSms->bReplyPath;
434 } else if (msgType.mainType == MSG_MMS_TYPE) {
435 msg_struct_s *pStruct = (msg_struct_s *)pSrc->mmsSendOpt;
438 MMS_SENDINGOPT_S *pMms = (MMS_SENDINGOPT_S *)pStruct->data;
441 pDest->option.mmsSendOptInfo.priority = pMms->priority;
442 pDest->option.mmsSendOptInfo.bReadReq = pMms->bReadReq;
444 MSG_DEBUG("pDest->option.mmsSendOpt.priority = %d", pMms->priority);
445 MSG_DEBUG("pDest->option.mmsSendOpt.bReadReq = %d", pMms->bReadReq);
447 if (pMms->expiryTime == 0) {
448 pDest->option.mmsSendOptInfo.expiryTime.type = MMS_TIMETYPE_NONE;
449 pDest->option.mmsSendOptInfo.expiryTime.time = pMms->expiryTime;
451 pDest->option.mmsSendOptInfo.expiryTime.type = MMS_TIMETYPE_RELATIVE;
452 pDest->option.mmsSendOptInfo.expiryTime.time = pMms->expiryTime;
455 if (pMms->bUseDeliveryCustomTime == true) {
456 pDest->option.mmsSendOptInfo.bUseDeliveryCustomTime = true;
458 pDest->option.mmsSendOptInfo.bUseDeliveryCustomTime = false;
460 pDest->option.mmsSendOptInfo.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
461 pDest->option.mmsSendOptInfo.deliveryTime.time = pMms->deliveryTime;
463 MSG_DEBUG("pDest->option.mmsSendOpt.expiryTime = %d", pDest->option.mmsSendOptInfo.expiryTime.time);
472 void MsgHandle::convertSendOptStruct(const MSG_SENDINGOPT_INFO_S* pSrc, MSG_SENDINGOPT_S* pDest, MSG_MESSAGE_TYPE_S msgType)
476 pDest->bDeliverReq = pSrc->bDeliverReq;
477 pDest->bKeepCopy = pSrc->bKeepCopy;
479 MSG_DEBUG("pDest->bDeliverReq = %d", pDest->bDeliverReq);
480 MSG_DEBUG("pDest->bKeepCopy = %d", pDest->bKeepCopy);
482 if (msgType.mainType == MSG_SMS_TYPE) {
483 msg_struct_s *pStruct = (msg_struct_s *)pDest->smsSendOpt;
484 SMS_SENDINGOPT_S *pSms = (SMS_SENDINGOPT_S *)pStruct->data;
485 pSms->bReplyPath = pSrc->option.smsSendOptInfo.bReplyPath;
486 } else if (msgType.mainType == MSG_MMS_TYPE) {
487 msg_struct_s *pStruct = (msg_struct_s *)pDest->mmsSendOpt;
488 MMS_SENDINGOPT_S *pMms = (MMS_SENDINGOPT_S *)pStruct->data;
489 pMms->priority = pSrc->option.mmsSendOptInfo.priority;
490 pMms->bReadReq = pSrc->option.mmsSendOptInfo.bReadReq;
491 pMms->expiryTime = pSrc->option.mmsSendOptInfo.expiryTime.time;
492 pMms->deliveryTime = pSrc->option.mmsSendOptInfo.deliveryTime.time;
494 MSG_DEBUG("pDest->option.mmsSendOpt.priority = %d", pMms->priority);
495 MSG_DEBUG("pDest->option.mmsSendOpt.bReadReq = %d", pMms->bReadReq);
496 MSG_DEBUG("pDest->option.mmsSendOpt.expiryTime = %d", pMms->expiryTime);
503 int MsgHandle::getSettingCmdSize(MSG_OPTION_TYPE_T optionType)
505 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_OPTION_TYPE_T);
509 case MSG_GENERAL_OPT :
510 cmdSize += sizeof(MSG_GENERAL_OPT_S);
512 case MSG_SMS_SENDOPT :
513 cmdSize += sizeof(MSG_SMS_SENDOPT_S);
516 cmdSize += sizeof(MSG_SMSC_LIST_S);
518 case MSG_MMS_SENDOPT :
519 cmdSize += sizeof(MSG_MMS_SENDOPT_S);
521 case MSG_MMS_RECVOPT :
522 cmdSize += sizeof(MSG_MMS_RECVOPT_S);
524 case MSG_MMS_STYLEOPT :
525 cmdSize += sizeof(MSG_MMS_STYLEOPT_S);
527 case MSG_PUSHMSG_OPT :
528 cmdSize += sizeof(MSG_PUSHMSG_OPT_S);
531 cmdSize += sizeof(MSG_CBMSG_OPT_S);
533 case MSG_VOICEMAIL_OPT :
534 cmdSize += sizeof(MSG_VOICEMAIL_OPT_S);
536 case MSG_MSGSIZE_OPT :
537 cmdSize += sizeof(MSG_MSGSIZE_OPT_S);
545 bool MsgHandle::CheckEventData(char *pEventData)
547 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
549 switch (pEvent->eventType)
551 case MSG_EVENT_PLG_SENT_STATUS_CNF :
552 case MSG_EVENT_PLG_INCOMING_MSG_IND :
553 case MSG_EVENT_PLG_INCOMING_MMS_CONF :
554 case MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND :
555 case MSG_EVENT_PLG_INCOMING_LBS_MSG_IND :
556 case MSG_EVENT_SYNCML_OPERATION :
557 case MSG_EVENT_PLG_STORAGE_CHANGE_IND :
558 case MSG_EVENT_PLG_INCOMING_CB_MSG_IND :
559 case MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND :