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.
35 #include "MsgCppTypes.h"
36 #include "MsgException.h"
37 #include "MsgProxyListener.h"
38 #include "MsgHandle.h"
41 /*==================================================================================================
42 IMPLEMENTATION OF MsgHandle - Transport Member Functions
43 ==================================================================================================*/
44 MSG_ERROR_T MsgHandle::submitReq(MSG_REQUEST_S* pReq)
49 THROW(MsgException::INVALID_PARAM, "pReq is NULL");
51 MSG_REQUEST_INFO_S reqInfo = {0};
52 char trId[MMS_TR_ID_LEN+1] = {0};
54 MSG_MESSAGE_S *reqmsg = (MSG_MESSAGE_S*) pReq->msg;
56 if (reqmsg->msgType.subType != MSG_SENDREQ_JAVA_MMS) {
57 // In case MMS read report, get address value later.
58 if(reqmsg->msgType.subType != MSG_READREPLY_MMS) {
59 if ((reqmsg->nAddressCnt == 0) || (reqmsg->nAddressCnt > MAX_TO_ADDRESS_CNT)) {
60 MSG_DEBUG("Recipient address count error [%d]", reqmsg->nAddressCnt );
61 return MSG_ERR_INVALID_MESSAGE;
65 /* Begin: Setting default values for submit request */
66 // pReq->msg.msgId = 0; // Set Request ID: internal use
67 // pReq->msg.folderId = MSG_OUTBOX_ID; // Set Folder ID
68 if (reqmsg->msgType.subType == MSG_RETRIEVE_MMS) {
69 reqmsg->networkStatus = MSG_NETWORK_RETRIEVING;
71 reqmsg->networkStatus = MSG_NETWORK_SENDING;
74 reqmsg->bRead = false;
75 reqmsg->bProtected = false;
76 reqmsg->priority = MSG_MESSAGE_PRIORITY_NORMAL;
77 reqmsg->direction = MSG_DIRECTION_TYPE_MO;
78 reqmsg->storageId = MSG_STORAGE_PHONE;
80 time_t curTime = time(NULL);
83 THROW(MsgException::INVALID_RESULT, "time error : %s", strerror(errno));
85 reqmsg->displayTime = curTime;
86 /* End : Setting default values for submit request */
88 //in case of JAVA MMS msg, parse mms transaction id from pMmsData
89 reqmsg->networkStatus = MSG_NETWORK_SENDING;
90 strncpy(trId, (char*)reqmsg->pMmsData+3,MMS_TR_ID_LEN);
91 MSG_DEBUG("JavaMMS transaction Id:%s ",trId);
94 // Convert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
95 convertMsgStruct(reqmsg, &(reqInfo.msgInfo));
97 convertSendOptStruct(&(pReq->sendOpt), &(reqInfo.sendOptInfo), reqmsg->msgType);
101 /* Register proxy info used for receiving sent status */
102 MSG_PROXY_INFO_S chInfo = {0};
104 chInfo.listenerFd = MsgProxyListener::instance()->getRemoteFd();
106 chInfo.handleAddr = (unsigned int) this;
108 /* Allocate Memory to Command Data */
109 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_REQUEST_INFO_S) + sizeof(MSG_PROXY_INFO_S);
111 // In case of JAVA MMS msg, add trId
112 if (reqmsg->msgType.subType == MSG_SENDREQ_JAVA_MMS)
113 cmdSize += sizeof(trId);
115 char cmdBuf[cmdSize];
116 bzero(cmdBuf, cmdSize);
118 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
120 // Set Command Parameters
121 pCmd->cmdType = MSG_CMD_SUBMIT_REQ;
124 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
127 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &reqInfo, sizeof(MSG_REQUEST_INFO_S));
128 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_REQUEST_INFO_S)), &chInfo, sizeof(MSG_PROXY_INFO_S));
130 // In case of JAVA MMS msg, add trId
131 if (reqmsg->msgType.subType == MSG_SENDREQ_JAVA_MMS)
132 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_REQUEST_INFO_S)+sizeof(MSG_PROXY_INFO_S)), &trId, sizeof(trId));
134 // Send Command to Messaging FW
135 char* pEventData = NULL;
136 AutoPtr<char> eventBuf(&pEventData);
138 write((char*)pCmd, cmdSize, &pEventData);
141 MSG_EVENT_S* pEvent = (MSG_EVENT_S*) pEventData;
143 int* pReqId = (int*) pEvent->data;
144 pReq->reqId = *pReqId;
145 MSG_DEBUG("SENT_REQ_ID: %d", pReq->reqId);
147 if (pEvent->eventType != MSG_EVENT_SUBMIT_REQ)
149 THROW(MsgException::INVALID_RESULT, "Event Data Error");
154 return pEvent->result;
158 MSG_ERROR_T MsgHandle::cancelReq(MSG_REQUEST_ID_T reqId)
160 // Allocate Memory to Command Data
161 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_REQUEST_ID_T);
163 char cmdBuf[cmdSize];
164 bzero(cmdBuf, cmdSize);
166 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
168 // Set Command Parameters
169 pCmd->cmdType = MSG_CMD_CANCEL_REQ;
172 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
175 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &reqId, sizeof(MSG_REQUEST_ID_T));
177 // Send Command to Messaging FW
178 char* pEventData = NULL;
179 AutoPtr<char> eventBuf(&pEventData);
182 write((char*)pCmd, cmdSize, &pEventData);
185 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
187 if (pEvent->eventType != MSG_EVENT_CANCEL_REQ)
189 THROW(MsgException::INVALID_RESULT, "Event Data Error");
192 return pEvent->result;
196 MSG_ERROR_T MsgHandle::regSentStatusCallback(msg_sent_status_cb onStatusChanged, void *pUserParam)
198 if (!onStatusChanged)
199 THROW(MsgException::INVALID_PARAM, "onStatusChanged is null");
201 MsgProxyListener* eventListener = MsgProxyListener::instance();
203 eventListener->start();
205 if (eventListener->regSentStatusEventCB(this, onStatusChanged, pUserParam) == false) // callback was already registered, just return SUCCESS
208 // Allocate Memory to Command Data
209 int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
210 char cmdBuf[cmdSize];
211 bzero(cmdBuf, cmdSize);
212 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
214 // Set Command Parameters
215 pCmd->cmdType = MSG_CMD_REG_SENT_STATUS_CB;
218 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
220 int listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
222 MSG_DEBUG("remote fd %d", listenerFd);
224 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &listenerFd, sizeof(listenerFd));
226 MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), listenerFd);
228 // Send Command to Messaging FW
229 char* pEventData = NULL;
230 AutoPtr<char> eventBuf(&pEventData);
232 write((char*)pCmd, cmdSize, &pEventData);
235 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
237 if (pEvent->eventType != MSG_EVENT_REG_SENT_STATUS_CB)
239 THROW(MsgException::INVALID_PARAM, "Event Data Error");
242 return pEvent->result;
246 MSG_ERROR_T MsgHandle::regSmsMessageCallback(msg_sms_incoming_cb onMsgIncoming, unsigned short port, void *pUserParam)
248 if( (!onMsgIncoming) )
249 THROW(MsgException::INVALID_PARAM, "Param %p", onMsgIncoming);
251 MsgProxyListener* eventListener = MsgProxyListener::instance();
253 eventListener->start();
255 if (eventListener->regMessageIncomingEventCB(this, onMsgIncoming, port, pUserParam) == false) // callback was already registered, just return SUCCESS
258 // Allocate Memory to Command Data
259 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
261 char cmdBuf[cmdSize];
262 bzero(cmdBuf, cmdSize);
264 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
266 // Set Command Parameters
267 pCmd->cmdType = MSG_CMD_REG_INCOMING_MSG_CB;
270 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
272 MSG_CMD_REG_INCOMING_MSG_CB_S cmdParam = {0};
274 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
275 cmdParam.msgType = MSG_SMS_TYPE;
276 cmdParam.port = port;
278 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
280 MSG_DEBUG("reg new msg [%s], fd %d, port %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, cmdParam.port);
282 // Send Command to Messaging FW
283 char* pEventData = NULL;
284 AutoPtr<char> eventBuf(&pEventData);
287 write((char*)pCmd, cmdSize, &pEventData);
290 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
292 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_MSG_CB)
294 THROW(MsgException::INVALID_RESULT, "Event Data Error");
297 return pEvent->result;
301 MSG_ERROR_T MsgHandle::regMmsConfMessageCallback(msg_mms_conf_msg_incoming_cb onMMSConfMsgIncoming, const char *pAppId, void *pUserParam)
303 if( (!onMMSConfMsgIncoming) )
304 THROW(MsgException::INVALID_PARAM, "Param %p", onMMSConfMsgIncoming);
306 MsgProxyListener* eventListener = MsgProxyListener::instance();
308 eventListener->start();
310 if (eventListener->regMMSConfMessageIncomingEventCB(this, onMMSConfMsgIncoming, pAppId, pUserParam) == false) // callback was already registered, just return SUCCESS
313 // Allocate Memory to Command Data
314 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S);
316 char cmdBuf[cmdSize];
317 bzero(cmdBuf, cmdSize);
319 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
321 // Set Command Parameters
322 pCmd->cmdType = MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB;
325 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
327 MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S cmdParam = {0};
329 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
330 cmdParam.msgType = MSG_MMS_TYPE;
333 strncpy(cmdParam.appId, pAppId, MAX_MMS_JAVA_APPID_LEN);
335 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
337 MSG_DEBUG("reg new msg [%s], fd:%d, appId:%s", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, (pAppId)? cmdParam.appId:"NULL" );
339 // Send Command to Messaging FW
340 char* pEventData = NULL;
341 AutoPtr<char> eventBuf(&pEventData);
344 write((char*)pCmd, cmdSize, &pEventData);
347 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
349 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_MMS_CONF_MSG_CB)
351 THROW(MsgException::INVALID_RESULT, "Event Data Error");
354 return pEvent->result;
358 MSG_ERROR_T MsgHandle::regSyncMLMessageCallback(msg_syncml_msg_incoming_cb onSyncMLMsgIncoming, void *pUserParam)
360 if( (!onSyncMLMsgIncoming) )
361 THROW(MsgException::INVALID_PARAM, "Param %p", onSyncMLMsgIncoming);
363 MsgProxyListener* eventListener = MsgProxyListener::instance();
365 eventListener->start();
367 if (eventListener->regSyncMLMessageIncomingEventCB(this, onSyncMLMsgIncoming, pUserParam) == false) // callback was already registered, just return SUCCESS
370 // Allocate Memory to Command Data
371 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
373 char cmdBuf[cmdSize];
374 bzero(cmdBuf, cmdSize);
376 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
378 // Set Command Parameters
379 pCmd->cmdType = MSG_CMD_REG_INCOMING_SYNCML_MSG_CB;
382 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
384 MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S cmdParam = {0};
386 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
387 cmdParam.msgType = MSG_SMS_TYPE;
389 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
391 MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
393 // Send Command to Messaging FW
394 char* pEventData = NULL;
395 AutoPtr<char> eventBuf(&pEventData);
397 write((char*)pCmd, cmdSize, &pEventData);
400 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
402 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_SYNCML_MSG_CB)
404 THROW(MsgException::INVALID_RESULT, "Event Data Error");
407 return pEvent->result;
411 MSG_ERROR_T MsgHandle::regLBSMessageCallback(msg_lbs_msg_incoming_cb onLBSMsgIncoming, void *pUserParam)
413 if( (!onLBSMsgIncoming) )
414 THROW(MsgException::INVALID_PARAM, "Param %p", onLBSMsgIncoming);
416 MsgProxyListener* eventListener = MsgProxyListener::instance();
418 eventListener->start();
420 if (eventListener->regLBSMessageIncomingEventCB(this, onLBSMsgIncoming, pUserParam) == false) // callback was already registered, just return SUCCESS
423 // Allocate Memory to Command Data
424 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_LBS_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
425 char cmdBuf[cmdSize];
426 bzero(cmdBuf, cmdSize);
427 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
429 // Set Command Parameters
430 pCmd->cmdType = MSG_CMD_REG_INCOMING_LBS_MSG_CB;
433 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
435 MSG_CMD_REG_INCOMING_LBS_MSG_CB_S cmdParam = {0};
437 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
438 cmdParam.msgType = MSG_SMS_TYPE;
440 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
442 MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
444 // Send Command to Messaging FW
445 char* pEventData = NULL;
446 AutoPtr<char> eventBuf(&pEventData);
449 write((char*)pCmd, cmdSize, &pEventData);
452 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
454 if (pEvent->eventType != MSG_EVENT_REG_INCOMING_LBS_MSG_CB)
456 THROW(MsgException::INVALID_RESULT, "Event Data Error");
459 return pEvent->result;
463 MSG_ERROR_T MsgHandle::regSyncMLMessageOperationCallback(msg_syncml_msg_operation_cb onSyncMLMsgOperation, void *pUserParam)
465 if( (!onSyncMLMsgOperation) )
466 THROW(MsgException::INVALID_PARAM, "Param %p", onSyncMLMsgOperation);
468 MsgProxyListener* eventListener = MsgProxyListener::instance();
470 eventListener->start();
472 if (eventListener->regSyncMLMessageOperationEventCB(this, onSyncMLMsgOperation, pUserParam) == false) // callback was already registered, just return SUCCESS
475 // Allocate Memory to Command Data
476 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
478 char cmdBuf[cmdSize];
479 bzero(cmdBuf, cmdSize);
481 MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
483 // Set Command Parameters
484 pCmd->cmdType = MSG_CMD_REG_SYNCML_MSG_OPERATION_CB;
487 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
489 MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S cmdParam = {0};
491 cmdParam.listenerFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
492 cmdParam.msgType = MSG_SMS_TYPE;
494 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
496 MSG_DEBUG("register syncML msg operation callback [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
498 // Send Command to Messaging FW
499 char* pEventData = NULL;
500 AutoPtr<char> eventBuf(&pEventData);
503 write((char*)pCmd, cmdSize, &pEventData);
506 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
508 if (pEvent->eventType != MSG_EVENT_REG_SYNCML_MSG_OPERATION_CB)
510 THROW(MsgException::INVALID_RESULT, "Event Data Error");
513 return pEvent->result;
517 MSG_ERROR_T MsgHandle::operateSyncMLMessage(MSG_MESSAGE_ID_T msgId)
520 THROW(MsgException::INVALID_PARAM, "Param msgId %d", msgId);
522 // Allocate Memory to Command Data
523 int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_ID_T);
525 char cmdBuf[cmdSize];
526 bzero(cmdBuf, cmdSize);
527 MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
529 // Set Command Parameters
530 pCmd->cmdType = MSG_CMD_SYNCML_OPERATION;
533 memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
536 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msgId, sizeof(MSG_MESSAGE_ID_T));
538 // Send Command to Messaging FW
539 char* pEventData = NULL;
540 AutoPtr<char> eventBuf(&pEventData);
543 write((char*)pCmd, cmdSize, &pEventData);
546 MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
548 if (pEvent->eventType != MSG_EVENT_SYNCML_OPERATION)
550 THROW(MsgException::INVALID_RESULT, "Event Data Error");
553 return pEvent->result;