3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
5 * This file is part of msg-service.
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 * Sangkoo Kim <sangkoo.kim@samsung.com>
9 * Seunghwan Lee <sh.cat.lee@samsung.com>
10 * SoonMin Jung <sm0415.jung@samsung.com>
11 * Jae-Young Lee <jy4710.lee@samsung.com>
12 * KeeBum Kim <keebum.kim@samsung.com>
14 * PROPRIETARY/CONFIDENTIAL
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
34 #include <security-server.h>
37 #include "MsgCppTypes.h"
38 #include "MsgException.h"
39 #include "MsgUtilFile.h"
40 #include "MsgGconfWrapper.h"
41 #include "MsgProxyListener.h"
42 #include "MsgHandle.h"
44 /*==================================================================================================
45 IMPLEMENTATION OF MsgHandle - Control Member Functions
46 ==================================================================================================*/
47 MsgHandle::MsgHandle() : mCounter(0), mClientSock()
49 memset(mConnectionId, 0x00, sizeof(mConnectionId));
53 MsgHandle::~MsgHandle()
59 void MsgHandle::openHandle()
66 // server is currently booting and service is not available until the end of booting
67 MsgSettingGetBool(VCONFKEY_MSG_SERVER_READY, &bReady);
69 if (bReady == false) {
70 THROW(MsgException::SERVER_READY_ERROR, "Msg Server is not ready !!!!!");
72 MSG_DEBUG("Msg Server is ready !!!!!");
76 cookieSize = security_server_get_cookie_size();
78 MSG_DEBUG("cookie size : [%d]", cookieSize);
81 ret = security_server_request_cookie(mCookie, cookieSize);
85 MSG_DEBUG("security_server_request_cookie() error!! [%d]", ret);
94 void MsgHandle::closeHandle(MsgHandle* pHandle)
98 //Remove CB List of closing Handle
99 MsgProxyListener* eventListener = MsgProxyListener::instance();
101 eventListener->clearListOfClosedHandle(pHandle);
102 //eventListener->stop();
111 void MsgHandle::connectSocket()
113 mClientSock.connect(MSG_SOCKET_PATH);
117 void MsgHandle::disconnectSocket()
123 void MsgHandle::write(const char *pCmdData, int cmdSize, char **ppEvent)
125 if (pCmdData == NULL || ppEvent == NULL) {
126 THROW(MsgException::INVALID_PARAM, "Param is NULL");
129 // Send Command to MSG FW
130 mClientSock.write(pCmdData, cmdSize);
132 // Receive Result from MSG FW
135 if (ppEvent == NULL) {
136 THROW(MsgException::INVALID_RESULT, "event is NULL");
141 void MsgHandle::read(char **ppEvent)
145 dataSize = mClientSock.read(ppEvent, &dataSize);
148 THROW(MsgException::IPC_ERROR, "Server closed connection");
149 } else if(dataSize < 0) {
150 THROW(MsgException::IPC_ERROR, "negative length??? %d", dataSize);
155 void MsgHandle::convertMsgStruct(const MSG_MESSAGE_S *pSrc, MSG_MESSAGE_INFO_S *pDest)
159 pDest->msgId = pSrc->msgId;
160 pDest->folderId = pSrc->folderId;
161 pDest->referenceId = pSrc->referenceId;
162 pDest->msgType.mainType = pSrc->msgType.mainType;
163 pDest->msgType.subType = pSrc->msgType.subType;
164 pDest->msgType.classType= pSrc->msgType.classType;
165 pDest->storageId = pSrc->storageId;
167 pDest->nAddressCnt = pSrc->nAddressCnt;
169 for (int i = 0; i < pSrc->nAddressCnt; i++)
171 pDest->addressList[i].threadId = pSrc->addressList[i].threadId;
172 pDest->addressList[i].addressType = pSrc->addressList[i].addressType;
173 pDest->addressList[i].recipientType = pSrc->addressList[i].recipientType;
174 pDest->addressList[i].contactId = pSrc->addressList[i].contactId;
175 strncpy(pDest->addressList[i].addressVal, pSrc->addressList[i].addressVal, MAX_ADDRESS_VAL_LEN);
176 strncpy(pDest->addressList[i].displayName, pSrc->addressList[i].displayName, MAX_DISPLAY_NAME_LEN);
177 pDest->addressList[i].displayName[MAX_DISPLAY_NAME_LEN] = '\0';
180 strncpy(pDest->replyAddress, pSrc->replyAddress, MAX_PHONE_NUMBER_LEN);
181 strncpy(pDest->subject, pSrc->subject, MAX_SUBJECT_LEN);
183 pDest->scheduledTime = pSrc->scheduledTime;
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->msgPort.valid;
196 if (pDest->msgPort.valid == true) {
197 pDest->msgPort.dstPort = pSrc->msgPort.dstPort;
198 pDest->msgPort.srcPort = pSrc->msgPort.srcPort;
201 MSG_DEBUG("nSize = %d", pSrc->dataSize);
203 if (pSrc->msgType.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[MAX_COMMON_INFO_SIZE+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->msgType.mainType == MSG_MMS_TYPE) {
238 pDest->bTextSms = false;
239 pDest->dataSize = pSrc->dataSize;
241 if(pSrc->msgType.subType == MSG_READREPLY_MMS) {
242 memset(pDest->msgData, 0x00, sizeof(pDest->msgData));
243 memcpy(pDest->msgData, pSrc->pMmsData, pSrc->dataSize);
245 // Save Message Data into File
246 char fileName[MAX_COMMON_INFO_SIZE+1];
247 memset(fileName, 0x00, sizeof(fileName));
249 if(MsgCreateFileName(fileName) == false)
250 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
252 // change file extension in case of java MMS msg
253 if (pSrc->msgType.subType == MSG_SENDREQ_JAVA_MMS) {
255 pFileNameExt = strstr(fileName,"DATA");
256 strncpy(pFileNameExt,"JAVA", MAX_COMMON_INFO_SIZE);
259 MSG_DEBUG("Save Message Data into file : size[%d] name[%s]", pDest->dataSize, fileName);
261 if (MsgWriteIpcFile(fileName, (char*)pSrc->pMmsData, pSrc->dataSize) == false)
262 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
264 memset(pDest->msgData, 0x00, sizeof(pDest->msgData));
265 strncpy(pDest->msgData, fileName, MAX_MSG_DATA_LEN);
273 void MsgHandle::convertMsgStruct(const MSG_MESSAGE_INFO_S *pSrc, MSG_MESSAGE_S *pDest)
277 pDest->msgId = pSrc->msgId;
278 pDest->folderId = pSrc->folderId;
279 pDest->referenceId = pSrc->referenceId;
280 pDest->msgType.mainType = pSrc->msgType.mainType;
281 pDest->msgType.subType = pSrc->msgType.subType;
282 pDest->storageId = pSrc->storageId;
284 pDest->nAddressCnt = pSrc->nAddressCnt;
286 for (int i = 0; i < pSrc->nAddressCnt; i++)
288 pDest->addressList[i].threadId = pSrc->addressList[i].threadId;
289 pDest->addressList[i].addressType = pSrc->addressList[i].addressType;
290 pDest->addressList[i].recipientType = pSrc->addressList[i].recipientType;
291 pDest->addressList[i].contactId = pSrc->addressList[i].contactId;
292 strncpy(pDest->addressList[i].addressVal, pSrc->addressList[i].addressVal, MAX_ADDRESS_VAL_LEN);
293 strncpy(pDest->addressList[i].displayName, pSrc->addressList[i].displayName, MAX_DISPLAY_NAME_LEN);
294 pDest->addressList[i].displayName[MAX_DISPLAY_NAME_LEN] = '\0';
297 strncpy(pDest->replyAddress, pSrc->replyAddress, MAX_PHONE_NUMBER_LEN);
298 strncpy(pDest->subject, pSrc->subject, MAX_SUBJECT_LEN);
300 pDest->displayTime = pSrc->displayTime;
301 pDest->scheduledTime = pSrc->scheduledTime;
302 pDest->networkStatus = pSrc->networkStatus;
303 pDest->encodeType = pSrc->encodeType;
304 pDest->bRead = pSrc->bRead;
305 pDest->bProtected = pSrc->bProtected;
306 pDest->bBackup = pSrc->bBackup;
307 pDest->priority = pSrc->priority;
308 pDest->direction = pSrc->direction;
311 pDest->msgPort.valid = pSrc->msgPort.valid;
313 if (pDest->msgPort.valid == true) {
314 pDest->msgPort.dstPort = pSrc->msgPort.dstPort;
315 pDest->msgPort.srcPort = pSrc->msgPort.srcPort;
318 if(pSrc->thumbPath[0] != '\0')
319 strncpy(pDest->thumbPath, pSrc->thumbPath, MSG_FILEPATH_LEN_MAX);
321 if (pSrc->bTextSms == false) {
324 char* pFileData = NULL;
325 AutoPtr<char> buf(&pFileData);
327 pDest->dataSize = pSrc->dataSize;
329 // Get Message Data from File
330 if (pSrc->networkStatus != MSG_NETWORK_RETRIEVE_FAIL) {
331 MSG_DEBUG("Get Message Data from file : size[%d] name[%s]\n", pDest->dataSize, pSrc->msgData);
332 if (MsgOpenAndReadFile(pSrc->msgData, &pFileData, &fileSize) == false)
333 THROW(MsgException::FILE_ERROR, "MsgOpenAndReadFile error");
335 if (pSrc->msgType.mainType == MSG_SMS_TYPE) {
336 if (pDest->encodeType == MSG_ENCODE_8BIT) {
337 pDest->pData = (void*)new char[fileSize];
338 memset(pDest->pData, 0x00, fileSize);
339 memcpy(pDest->pData, pFileData, fileSize);
341 pDest->pData = (void*)new char[fileSize+1];
342 memset(pDest->pData, 0x00, fileSize+1);
343 strncpy((char*)pDest->pData, pFileData, fileSize);
346 if (pSrc->msgText[0] != '\0') {
347 pDest->pData = (void*)new char[strlen(pSrc->msgText)+1];
348 memset(pDest->pData, 0x00, strlen(pSrc->msgText)+1);
349 strncpy((char*)pDest->pData, pSrc->msgText, strlen(pSrc->msgText));
351 pDest->pMmsData = (void*)new char[fileSize];
352 memset(pDest->pMmsData, 0x00, fileSize);
353 memcpy(pDest->pMmsData, pFileData, fileSize);
357 pDest->dataSize = pSrc->dataSize;
359 if (pSrc->msgType.mainType == MSG_SMS_TYPE) {
360 if (pDest->encodeType == MSG_ENCODE_8BIT) {
361 pDest->pData = (void*)new char[pDest->dataSize];
362 memset(pDest->pData, 0x00, pDest->dataSize);
363 memcpy(pDest->pData, pSrc->msgText, pDest->dataSize);
365 pDest->pData = (void*)new char[pDest->dataSize+1];
366 memset(pDest->pData, 0x00, pDest->dataSize+1);
367 strncpy((char*)pDest->pData, pSrc->msgText, pDest->dataSize);
370 if (pSrc->msgText[0] != '\0') {
371 pDest->pData = (void*)new char[strlen(pSrc->msgText)+1];
372 memset(pDest->pData, 0x00, strlen(pSrc->msgText)+1);
373 strncpy((char*)pDest->pData, pSrc->msgText, strlen(pSrc->msgText));
376 pDest->pMmsData = (void*)new char[pDest->dataSize];
377 memset(pDest->pMmsData, 0x00, pDest->dataSize);
378 memcpy(pDest->pMmsData, pSrc->msgData, pDest->dataSize);
386 void MsgHandle::convertSendOptStruct(const MSG_SENDINGOPT_S* pSrc, MSG_SENDINGOPT_INFO_S* pDest, MSG_MESSAGE_TYPE_S msgType)
390 pDest->bSetting = pSrc->bSetting;
392 if (pDest->bSetting == false) {
393 MSG_DEBUG("No Sending Option");
397 pDest->bDeliverReq = pSrc->bDeliverReq;
398 pDest->bKeepCopy = pSrc->bKeepCopy;
400 MSG_DEBUG("pDest->bSetting = %d", pDest->bSetting);
401 MSG_DEBUG("pDest->bDeliverReq = %d", pDest->bDeliverReq);
402 MSG_DEBUG("pDest->bKeepCopy = %d", pDest->bKeepCopy);
404 if (msgType.mainType == MSG_SMS_TYPE) {
405 pDest->option.smsSendOptInfo.bReplyPath = pSrc->option.smsSendOpt.bReplyPath;
406 } else if (msgType.mainType == MSG_MMS_TYPE) {
407 pDest->option.mmsSendOptInfo.priority = pSrc->option.mmsSendOpt.priority;
408 pDest->option.mmsSendOptInfo.bReadReq = pSrc->option.mmsSendOpt.bReadReq;
410 MSG_DEBUG("pDest->option.mmsSendOpt.priority = %d", pDest->option.mmsSendOptInfo.priority);
411 MSG_DEBUG("pDest->option.mmsSendOpt.bReadReq = %d", pDest->option.mmsSendOptInfo.bReadReq);
413 if (pSrc->option.mmsSendOpt.expiryTime == 0) {
414 pDest->option.mmsSendOptInfo.expiryTime.type = MMS_TIMETYPE_NONE;
415 pDest->option.mmsSendOptInfo.expiryTime.time = pSrc->option.mmsSendOpt.expiryTime;
417 pDest->option.mmsSendOptInfo.expiryTime.type = MMS_TIMETYPE_RELATIVE;
418 pDest->option.mmsSendOptInfo.expiryTime.time = pSrc->option.mmsSendOpt.expiryTime;
421 if (pSrc->option.mmsSendOpt.bUseDeliveryCustomTime == true) {
422 pDest->option.mmsSendOptInfo.bUseDeliveryCustomTime = true;
424 pDest->option.mmsSendOptInfo.bUseDeliveryCustomTime = false;
426 pDest->option.mmsSendOptInfo.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
427 pDest->option.mmsSendOptInfo.deliveryTime.time = pSrc->option.mmsSendOpt.deliveryTime;
429 MSG_DEBUG("pDest->option.mmsSendOpt.expiryTime = %d", pDest->option.mmsSendOptInfo.expiryTime.time);
436 void MsgHandle::convertSendOptStruct(const MSG_SENDINGOPT_INFO_S* pSrc, MSG_SENDINGOPT_S* pDest, MSG_MESSAGE_TYPE_S msgType)
440 pDest->bDeliverReq = pSrc->bDeliverReq;
441 pDest->bKeepCopy = pSrc->bKeepCopy;
443 MSG_DEBUG("pDest->bDeliverReq = %d", pDest->bDeliverReq);
444 MSG_DEBUG("pDest->bKeepCopy = %d", pDest->bKeepCopy);
446 if (msgType.mainType == MSG_SMS_TYPE) {
447 pDest->option.smsSendOpt.bReplyPath = pSrc->option.smsSendOptInfo.bReplyPath;
448 } else if (msgType.mainType == MSG_MMS_TYPE) {
449 pDest->option.mmsSendOpt.priority = pSrc->option.mmsSendOptInfo.priority;
450 pDest->option.mmsSendOpt.bReadReq = pSrc->option.mmsSendOptInfo.bReadReq;
451 pDest->option.mmsSendOpt.expiryTime = pSrc->option.mmsSendOptInfo.expiryTime.time;
452 pDest->option.mmsSendOpt.deliveryTime = pSrc->option.mmsSendOptInfo.deliveryTime.time;
454 MSG_DEBUG("pDest->option.mmsSendOpt.priority = %d", pDest->option.mmsSendOpt.priority);
455 MSG_DEBUG("pDest->option.mmsSendOpt.bReadReq = %d", pDest->option.mmsSendOpt.bReadReq);
456 MSG_DEBUG("pDest->option.mmsSendOpt.expiryTime = %d", pDest->option.mmsSendOpt.expiryTime);
463 int MsgHandle::getSettingCmdSize(MSG_OPTION_TYPE_T optionType)
465 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_OPTION_TYPE_T);
469 case MSG_GENERAL_OPT :
470 cmdSize += sizeof(MSG_GENERAL_OPT_S);
472 case MSG_SMS_SENDOPT :
473 cmdSize += sizeof(MSG_SMS_SENDOPT_S);
476 cmdSize += sizeof(MSG_SMSC_LIST_S);
478 case MSG_MMS_SENDOPT :
479 cmdSize += sizeof(MSG_MMS_SENDOPT_S);
481 case MSG_MMS_RECVOPT :
482 cmdSize += sizeof(MSG_MMS_RECVOPT_S);
484 case MSG_MMS_STYLEOPT :
485 cmdSize += sizeof(MSG_MMS_STYLEOPT_S);
487 case MSG_PUSHMSG_OPT :
488 cmdSize += sizeof(MSG_PUSHMSG_OPT_S);
491 cmdSize += sizeof(MSG_CBMSG_OPT_S);
493 case MSG_VOICEMAIL_OPT :
494 cmdSize += sizeof(MSG_VOICEMAIL_OPT_S);
496 case MSG_MSGSIZE_OPT :
497 cmdSize += sizeof(MSG_MSGSIZE_OPT_S);