2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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.
20 #include <security-server.h>
23 #include "MsgCppTypes.h"
24 #include "MsgException.h"
25 #include "MsgUtilFile.h"
26 #include "MsgGconfWrapper.h"
27 #include "MsgProxyListener.h"
28 #include "MsgHandle.h"
30 /*==================================================================================================
31 IMPLEMENTATION OF MsgHandle - Control Member Functions
32 ==================================================================================================*/
33 MsgHandle::MsgHandle() : mCounter(0), mClientSock()
35 memset(mConnectionId, 0x00, sizeof(mConnectionId));
39 MsgHandle::~MsgHandle()
45 void MsgHandle::openHandle()
52 // server is currently booting and service is not available until the end of booting
53 MsgSettingGetBool(VCONFKEY_MSG_SERVER_READY, &bReady);
55 if (bReady == false) {
56 THROW(MsgException::SERVER_READY_ERROR, "Msg Server is not ready !!!!!");
58 MSG_DEBUG("Msg Server is ready !!!!!");
62 cookieSize = security_server_get_cookie_size();
64 MSG_DEBUG("cookie size : [%d]", cookieSize);
67 ret = security_server_request_cookie(mCookie, cookieSize);
71 MSG_DEBUG("security_server_request_cookie() error!! [%d]", ret);
80 void MsgHandle::closeHandle(MsgHandle* pHandle)
84 //Remove CB List of closing Handle
85 MsgProxyListener* eventListener = MsgProxyListener::instance();
87 eventListener->clearListOfClosedHandle(pHandle);
88 //eventListener->stop();
97 void MsgHandle::connectSocket()
99 mClientSock.connect(MSG_SOCKET_PATH);
103 void MsgHandle::disconnectSocket()
109 void MsgHandle::write(const char *pCmdData, int cmdSize, char **ppEvent)
111 if (pCmdData == NULL || ppEvent == NULL) {
112 THROW(MsgException::INVALID_PARAM, "Param is NULL");
115 // Send Command to MSG FW
116 mClientSock.write(pCmdData, cmdSize);
118 // Receive Result from MSG FW
121 if (ppEvent == NULL) {
122 THROW(MsgException::INVALID_RESULT, "event is NULL");
127 void MsgHandle::read(char **ppEvent)
129 unsigned int dataSize = 0;
131 dataSize = mClientSock.read(ppEvent, &dataSize);
134 THROW(MsgException::IPC_ERROR, "Server closed connection");
135 } else if(dataSize < 0) {
136 THROW(MsgException::IPC_ERROR, "negative length??? %d", dataSize);
141 void MsgHandle::convertMsgStruct(const MSG_MESSAGE_HIDDEN_S *pSrc, MSG_MESSAGE_INFO_S *pDest)
145 pDest->msgId = pSrc->msgId;
146 pDest->threadId = pSrc->threadId;
147 pDest->folderId = pSrc->folderId;
148 pDest->msgType.mainType = pSrc->mainType;
149 pDest->msgType.subType = pSrc->subType;
150 pDest->msgType.classType= pSrc->classType;
151 pDest->storageId = pSrc->storageId;
153 msg_struct_list_s *addr_info_s = pSrc->addr_list;
156 msg_struct_s *addr_info = NULL;
157 MSG_ADDRESS_INFO_S *address = NULL;
159 pDest->nAddressCnt = addr_info_s->nCount;
161 for (int i = 0; i < addr_info_s->nCount; i++)
163 addr_info = (msg_struct_s *)addr_info_s->msg_struct_info[i];
164 address = (MSG_ADDRESS_INFO_S *)addr_info->data;
166 pDest->addressList[i].addressType = address->addressType;
167 pDest->addressList[i].recipientType = address->recipientType;
168 pDest->addressList[i].contactId = address->contactId;
169 strncpy(pDest->addressList[i].addressVal, address->addressVal, MAX_ADDRESS_VAL_LEN);
170 strncpy(pDest->addressList[i].displayName, address->displayName, MAX_DISPLAY_NAME_LEN);
171 pDest->addressList[i].displayName[MAX_DISPLAY_NAME_LEN] = '\0';
175 strncpy(pDest->replyAddress, pSrc->replyAddress, MAX_PHONE_NUMBER_LEN);
176 strncpy(pDest->subject, pSrc->subject, MAX_SUBJECT_LEN);
178 pDest->displayTime = pSrc->displayTime;
179 pDest->networkStatus = pSrc->networkStatus;
180 pDest->encodeType = pSrc->encodeType;
181 pDest->bRead = pSrc->bRead;
182 pDest->bProtected = pSrc->bProtected;
183 pDest->bBackup = pSrc->bBackup;
184 pDest->priority = pSrc->priority;
185 pDest->direction = pSrc->direction;
188 pDest->msgPort.valid = pSrc->bPortValid;
190 if (pDest->msgPort.valid == true) {
191 pDest->msgPort.dstPort = pSrc->dstPort;
192 pDest->msgPort.srcPort = pSrc->srcPort;
195 MSG_DEBUG("nSize = %d", pSrc->dataSize);
197 if (pSrc->mainType == MSG_SMS_TYPE){
198 pDest->bTextSms = true;
199 pDest->dataSize = pSrc->dataSize;
201 memset(pDest->msgText, 0x00, sizeof(pDest->msgText));
203 if (pSrc->dataSize > MAX_MSG_TEXT_LEN) {
204 // Save Message Data into File
205 char fileName[MAX_COMMON_INFO_SIZE+1];
206 memset(fileName, 0x00, sizeof(fileName));
208 if(MsgCreateFileName(fileName) == false)
209 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
211 MSG_DEBUG("Save pSrc->pData into file : size[%d] name[%s]", pDest->dataSize, fileName);
213 if (MsgWriteIpcFile(fileName, (char*)pSrc->pData, pSrc->dataSize) == false)
214 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
216 memset(pDest->msgData, 0x00, sizeof(pDest->msgData));
217 strncpy(pDest->msgData, fileName, MAX_MSG_DATA_LEN);
219 pDest->bTextSms = false;
222 if (pDest->encodeType == MSG_ENCODE_8BIT)
223 memcpy(pDest->msgText, pSrc->pData, pSrc->dataSize);
225 strncpy(pDest->msgText, (char*)pSrc->pData, pSrc->dataSize);
228 MSG_DEBUG("pData = %s", pSrc->pData);
229 MSG_DEBUG("msgText = %s", pDest->msgText);
230 } else if (pSrc->mainType == MSG_MMS_TYPE) {
232 pDest->bTextSms = false;
233 pDest->dataSize = pSrc->dataSize;
235 if(pSrc->subType == MSG_READREPLY_MMS) {
236 memset(pDest->msgData, 0x00, sizeof(pDest->msgData));
237 memcpy(pDest->msgData, pSrc->pMmsData, pSrc->dataSize);
239 // Save Message Data into File
240 char fileName[MAX_COMMON_INFO_SIZE+1];
241 memset(fileName, 0x00, sizeof(fileName));
243 if(MsgCreateFileName(fileName) == false)
244 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
246 // change file extension in case of java MMS msg
247 if (pSrc->subType == MSG_SENDREQ_JAVA_MMS) {
249 pFileNameExt = strstr(fileName,"DATA");
250 strncpy(pFileNameExt,"JAVA", MAX_COMMON_INFO_SIZE);
253 MSG_DEBUG("Save Message Data into file : size[%d] name[%s]", pDest->dataSize, fileName);
255 if (MsgWriteIpcFile(fileName, (char*)pSrc->pMmsData, pSrc->dataSize) == false)
256 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
258 memset(pDest->msgData, 0x00, sizeof(pDest->msgData));
259 strncpy(pDest->msgData, fileName, MAX_MSG_DATA_LEN);
261 strncpy(pDest->msgText, (char*)pSrc->pData, sizeof(pDest->msgText));
270 void MsgHandle::convertMsgStruct(const MSG_MESSAGE_INFO_S *pSrc, MSG_MESSAGE_HIDDEN_S *pDest)
274 pDest->msgId = pSrc->msgId;
275 pDest->threadId = pSrc->threadId;
276 pDest->folderId = pSrc->folderId;
277 pDest->mainType = pSrc->msgType.mainType;
278 pDest->subType = pSrc->msgType.subType;
279 pDest->storageId = pSrc->storageId;
281 strncpy(pDest->replyAddress, pSrc->replyAddress, MAX_PHONE_NUMBER_LEN);
282 strncpy(pDest->subject, pSrc->subject, MAX_SUBJECT_LEN);
284 pDest->displayTime = pSrc->displayTime;
285 pDest->networkStatus = pSrc->networkStatus;
286 pDest->encodeType = pSrc->encodeType;
287 pDest->bRead = pSrc->bRead;
288 pDest->bProtected = pSrc->bProtected;
289 pDest->bBackup = pSrc->bBackup;
290 pDest->priority = pSrc->priority;
291 pDest->direction = pSrc->direction;
294 pDest->bPortValid = pSrc->msgPort.valid;
296 if (pDest->bPortValid == true) {
297 pDest->dstPort = pSrc->msgPort.dstPort;
298 pDest->srcPort = pSrc->msgPort.srcPort;
301 if(pSrc->thumbPath[0] != '\0')
302 strncpy(pDest->thumbPath, pSrc->thumbPath, MSG_FILEPATH_LEN_MAX);
304 pDest->addr_list->nCount = pSrc->nAddressCnt;
306 msg_struct_s *addr_info_s = NULL;
307 MSG_ADDRESS_INFO_S *addr_info = NULL;
309 for (int i = 0; i < pDest->addr_list->nCount; i++)
311 addr_info_s = (msg_struct_s *)pDest->addr_list->msg_struct_info[i];
312 addr_info = (MSG_ADDRESS_INFO_S *)addr_info_s->data;
314 addr_info->addressType = pSrc->addressList[i].addressType;
315 addr_info->recipientType = pSrc->addressList[i].recipientType;
316 addr_info->contactId = pSrc->addressList[i].contactId;
317 strncpy(addr_info->addressVal, pSrc->addressList[i].addressVal, MAX_ADDRESS_VAL_LEN);
318 strncpy(addr_info->displayName, pSrc->addressList[i].displayName, MAX_DISPLAY_NAME_LEN);
319 addr_info->displayName[MAX_DISPLAY_NAME_LEN] = '\0';
323 if (pSrc->bTextSms == false) {
326 char* pFileData = NULL;
327 AutoPtr<char> buf(&pFileData);
329 pDest->dataSize = pSrc->dataSize;
331 // Get Message Data from File
332 if (pSrc->networkStatus != MSG_NETWORK_RETRIEVE_FAIL) {
333 MSG_DEBUG("Get Message Data from file : size[%d] name[%s]\n", pDest->dataSize, pSrc->msgData);
334 if (MsgOpenAndReadFile(pSrc->msgData, &pFileData, &fileSize) == false)
335 THROW(MsgException::FILE_ERROR, "MsgOpenAndReadFile error");
337 if (pSrc->msgType.mainType == MSG_SMS_TYPE) {
338 if (pDest->encodeType == MSG_ENCODE_8BIT) {
339 pDest->pData = (void*)new char[fileSize];
340 memset(pDest->pData, 0x00, fileSize);
341 memcpy(pDest->pData, pFileData, fileSize);
343 pDest->pData = (void*)new char[fileSize+1];
344 memset(pDest->pData, 0x00, fileSize+1);
345 strncpy((char*)pDest->pData, pFileData, fileSize);
348 if (pSrc->msgText[0] != '\0') {
349 pDest->pData = (void*)new char[strlen(pSrc->msgText)+1];
350 memset(pDest->pData, 0x00, strlen(pSrc->msgText)+1);
351 strncpy((char*)pDest->pData, pSrc->msgText, strlen(pSrc->msgText));
353 pDest->pMmsData = (void*)new char[fileSize];
354 memset(pDest->pMmsData, 0x00, fileSize);
355 memcpy(pDest->pMmsData, pFileData, fileSize);
359 pDest->dataSize = pSrc->dataSize;
361 if (pSrc->msgType.mainType == MSG_SMS_TYPE) {
362 if (pDest->encodeType == MSG_ENCODE_8BIT || pSrc->msgType.subType == MSG_ETWS_SMS) {
363 pDest->pData = (void*)new char[pDest->dataSize];
364 memset(pDest->pData, 0x00, pDest->dataSize);
365 memcpy(pDest->pData, pSrc->msgText, pDest->dataSize);
367 pDest->pData = (void*)new char[pDest->dataSize+1];
368 memset(pDest->pData, 0x00, pDest->dataSize+1);
369 strncpy((char*)pDest->pData, pSrc->msgText, pDest->dataSize);
372 if (pSrc->msgText[0] != '\0') {
373 pDest->pData = (void*)new char[strlen(pSrc->msgText)+1];
374 memset(pDest->pData, 0x00, strlen(pSrc->msgText)+1);
375 strncpy((char*)pDest->pData, pSrc->msgText, strlen(pSrc->msgText));
378 pDest->pMmsData = (void*)new char[pDest->dataSize];
379 memset(pDest->pMmsData, 0x00, pDest->dataSize);
380 memcpy(pDest->pMmsData, pSrc->msgData, pDest->dataSize);
388 void MsgHandle::convertSendOptStruct(const MSG_SENDINGOPT_S* pSrc, MSG_SENDINGOPT_INFO_S* pDest, MSG_MESSAGE_TYPE_S msgType)
392 pDest->bSetting = pSrc->bSetting;
394 if (pDest->bSetting == false) {
395 MSG_DEBUG("No Sending Option");
399 pDest->bDeliverReq = pSrc->bDeliverReq;
400 pDest->bKeepCopy = pSrc->bKeepCopy;
402 MSG_DEBUG("pDest->bSetting = %d", pDest->bSetting);
403 MSG_DEBUG("pDest->bDeliverReq = %d", pDest->bDeliverReq);
404 MSG_DEBUG("pDest->bKeepCopy = %d", pDest->bKeepCopy);
406 if (msgType.mainType == MSG_SMS_TYPE) {
407 msg_struct_s *pStruct = (msg_struct_s *)pSrc->smsSendOpt;
408 SMS_SENDINGOPT_S *pSms = (SMS_SENDINGOPT_S *)pStruct->data;
409 pDest->option.smsSendOptInfo.bReplyPath = pSms->bReplyPath;
410 } else if (msgType.mainType == MSG_MMS_TYPE) {
411 msg_struct_s *pStruct = (msg_struct_s *)pSrc->mmsSendOpt;
412 MMS_SENDINGOPT_S *pMms = (MMS_SENDINGOPT_S *)pStruct->data;
413 pDest->option.mmsSendOptInfo.priority = pMms->priority;
414 pDest->option.mmsSendOptInfo.bReadReq = pMms->bReadReq;
416 MSG_DEBUG("pDest->option.mmsSendOpt.priority = %d", pMms->priority);
417 MSG_DEBUG("pDest->option.mmsSendOpt.bReadReq = %d", pMms->bReadReq);
419 if (pMms->expiryTime == 0) {
420 pDest->option.mmsSendOptInfo.expiryTime.type = MMS_TIMETYPE_NONE;
421 pDest->option.mmsSendOptInfo.expiryTime.time = pMms->expiryTime;
423 pDest->option.mmsSendOptInfo.expiryTime.type = MMS_TIMETYPE_RELATIVE;
424 pDest->option.mmsSendOptInfo.expiryTime.time = pMms->expiryTime;
427 if (pMms->bUseDeliveryCustomTime == true) {
428 pDest->option.mmsSendOptInfo.bUseDeliveryCustomTime = true;
430 pDest->option.mmsSendOptInfo.bUseDeliveryCustomTime = false;
432 pDest->option.mmsSendOptInfo.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
433 pDest->option.mmsSendOptInfo.deliveryTime.time = pMms->deliveryTime;
435 MSG_DEBUG("pDest->option.mmsSendOpt.expiryTime = %d", pDest->option.mmsSendOptInfo.expiryTime.time);
442 void MsgHandle::convertSendOptStruct(const MSG_SENDINGOPT_INFO_S* pSrc, MSG_SENDINGOPT_S* pDest, MSG_MESSAGE_TYPE_S msgType)
446 pDest->bDeliverReq = pSrc->bDeliverReq;
447 pDest->bKeepCopy = pSrc->bKeepCopy;
449 MSG_DEBUG("pDest->bDeliverReq = %d", pDest->bDeliverReq);
450 MSG_DEBUG("pDest->bKeepCopy = %d", pDest->bKeepCopy);
452 if (msgType.mainType == MSG_SMS_TYPE) {
453 msg_struct_s *pStruct = (msg_struct_s *)pDest->smsSendOpt;
454 SMS_SENDINGOPT_S *pSms = (SMS_SENDINGOPT_S *)pStruct->data;
455 pSms->bReplyPath = pSrc->option.smsSendOptInfo.bReplyPath;
456 } else if (msgType.mainType == MSG_MMS_TYPE) {
457 msg_struct_s *pStruct = (msg_struct_s *)pDest->mmsSendOpt;
458 MMS_SENDINGOPT_S *pMms = (MMS_SENDINGOPT_S *)pStruct->data;
459 pMms->priority = pSrc->option.mmsSendOptInfo.priority;
460 pMms->bReadReq = pSrc->option.mmsSendOptInfo.bReadReq;
461 pMms->expiryTime = pSrc->option.mmsSendOptInfo.expiryTime.time;
462 pMms->deliveryTime = pSrc->option.mmsSendOptInfo.deliveryTime.time;
464 MSG_DEBUG("pDest->option.mmsSendOpt.priority = %d", pMms->priority);
465 MSG_DEBUG("pDest->option.mmsSendOpt.bReadReq = %d", pMms->bReadReq);
466 MSG_DEBUG("pDest->option.mmsSendOpt.expiryTime = %d", pMms->expiryTime);
473 int MsgHandle::getSettingCmdSize(MSG_OPTION_TYPE_T optionType)
475 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_OPTION_TYPE_T);
479 case MSG_GENERAL_OPT :
480 cmdSize += sizeof(MSG_GENERAL_OPT_S);
482 case MSG_SMS_SENDOPT :
483 cmdSize += sizeof(MSG_SMS_SENDOPT_S);
486 cmdSize += sizeof(MSG_SMSC_LIST_S);
488 case MSG_MMS_SENDOPT :
489 cmdSize += sizeof(MSG_MMS_SENDOPT_S);
491 case MSG_MMS_RECVOPT :
492 cmdSize += sizeof(MSG_MMS_RECVOPT_S);
494 case MSG_MMS_STYLEOPT :
495 cmdSize += sizeof(MSG_MMS_STYLEOPT_S);
497 case MSG_PUSHMSG_OPT :
498 cmdSize += sizeof(MSG_PUSHMSG_OPT_S);
501 cmdSize += sizeof(MSG_CBMSG_OPT_S);
503 case MSG_VOICEMAIL_OPT :
504 cmdSize += sizeof(MSG_VOICEMAIL_OPT_S);
506 case MSG_MSGSIZE_OPT :
507 cmdSize += sizeof(MSG_MSGSIZE_OPT_S);