Fix types for 64bit
[platform/core/messaging/msg-service.git] / proxy / MsgHandleTransport.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 <time.h>
18 #include <errno.h>
19
20 #include "MsgDebug.h"
21 #include "MsgCppTypes.h"
22 #include "MsgException.h"
23 #include "MsgUtilFunction.h"
24 #include "MsgProxyListener.h"
25 #include "MsgHandle.h"
26
27
28 /*==================================================================================================
29                                      IMPLEMENTATION OF MsgHandle - Transport Member Functions
30 ==================================================================================================*/
31 msg_error_t MsgHandle::submitReq(MSG_REQUEST_S* pReq)
32 {
33         MSG_BEGIN();
34
35         if (pReq == NULL)
36                 THROW(MsgException::INVALID_PARAM, "pReq is NULL");
37
38 #ifdef CHECK_SENT_STATUS_CALLBACK
39         if (MsgProxyListener::instance()->getSentStatusCbCnt() <= 0)
40                 THROW(MsgException::SENT_STATUS_ERROR,"Register sent status callback");
41 #endif
42
43         MSG_REQUEST_INFO_S reqInfo = {0};
44         char trId[MMS_TR_ID_LEN+1] = {0};
45
46         reqInfo.msgInfo.addressList = NULL;
47         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&reqInfo.msgInfo.addressList, unique_ptr_deleter);
48
49         msg_struct_s *msg_s = (msg_struct_s *)pReq->msg;
50
51         MSG_MESSAGE_HIDDEN_S *reqmsg = (MSG_MESSAGE_HIDDEN_S*)msg_s->data;
52
53         if (reqmsg->simIndex <= 0) {
54                 MSG_DEBUG("Wrong SIM Index [%d]", reqmsg->simIndex);
55                 return MSG_ERR_INVALID_PARAMETER;
56         }
57
58         if (reqmsg->subType != MSG_SENDREQ_JAVA_MMS) {
59                 // In case MMS read report, get address value later.
60                 if(reqmsg->subType != MSG_READREPLY_MMS) {
61                         if (reqmsg->addr_list && (reqmsg->addr_list->nCount > 0) && (reqmsg->addr_list->nCount <= MAX_TO_ADDRESS_CNT)) {
62                                 MSG_DEBUG("Recipient address count [%d]", reqmsg->addr_list->nCount );
63                         } else if (g_list_length(reqmsg->addressList) > 0) {
64                                 MSG_DEBUG("Recipient address count [%d]", g_list_length(reqmsg->addressList) );
65                         } else {
66                                 MSG_DEBUG("Address count is invalid.");
67                                 return MSG_ERR_INVALID_MESSAGE;
68                         }
69                 }
70
71                 /* Begin: Setting default values for submit request */
72         //      pReq->msg.msgId = 0;    // Set Request ID: internal use
73         //      pReq->msg.folderId = MSG_OUTBOX_ID;     // Set Folder ID
74                 if (reqmsg->subType == MSG_RETRIEVE_MMS) {
75                         reqmsg->networkStatus = MSG_NETWORK_RETRIEVING;
76                 } else {
77                         reqmsg->networkStatus = MSG_NETWORK_SENDING;
78                 }
79
80                 reqmsg->bRead = false;
81                 //reqmsg->bProtected = false;
82                 reqmsg->priority = MSG_MESSAGE_PRIORITY_NORMAL;
83                 reqmsg->direction = MSG_DIRECTION_TYPE_MO;
84                 reqmsg->storageId = MSG_STORAGE_PHONE;
85
86                 time_t curTime = time(NULL);
87
88                 if (curTime < 0)
89                         THROW(MsgException::INVALID_RESULT, "time error : %s", g_strerror(errno));
90
91                 reqmsg->displayTime = curTime;
92                 /* End : Setting default values for submit request */
93         } else {
94                 //in case of JAVA MMS msg, parse mms transaction id from pMmsData
95                 reqmsg->networkStatus = MSG_NETWORK_SENDING;
96                 strncpy(trId, (char*)reqmsg->pMmsData+3,MMS_TR_ID_LEN);
97                 MSG_SEC_DEBUG("JavaMMS transaction Id:%s ",trId);
98         }
99
100         // Convert MSG_MESSAGE_S to MSG_MESSAGE_INFO_S
101         convertMsgStruct(reqmsg, &(reqInfo.msgInfo));
102
103         MSG_MESSAGE_TYPE_S msgType = {0,};
104
105         msgType.mainType = reqmsg->mainType;
106         msgType.subType = reqmsg->subType;
107         msgType.classType = reqmsg->classType;
108
109         msg_struct_s *send_opt_s = (msg_struct_s *)pReq->sendOpt;
110         MSG_SENDINGOPT_S *send_opt = (MSG_SENDINGOPT_S *)send_opt_s->data;
111
112         convertSendOptStruct((const MSG_SENDINGOPT_S *)send_opt, &(reqInfo.sendOptInfo), msgType);
113
114         reqInfo.reqId = 0;
115
116         /* Register proxy info used for receiving sent status */
117         MSG_PROXY_INFO_S chInfo = {0};
118
119         chInfo.listenerFd = MsgProxyListener::instance()->getRemoteFd();
120
121         chInfo.handleAddr = (unsigned long) this;
122
123         /* Allocate Memory to Command Data */
124         char* encodedData = NULL;
125         unique_ptr<char*, void(*)(char**)> buf(&encodedData, unique_ptr_deleter);
126         int dataSize = MsgEncodeMsgInfo(&reqInfo.msgInfo, &reqInfo.sendOptInfo, &encodedData);
127
128         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_request_id_t) + dataSize + sizeof(MSG_PROXY_INFO_S);
129
130         // In case of JAVA MMS msg, add trId
131         if (reqmsg->subType == MSG_SENDREQ_JAVA_MMS)
132                 cmdSize += sizeof(trId);
133
134         char cmdBuf[cmdSize];
135         bzero(cmdBuf, cmdSize);
136
137         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
138
139         // Set Command Parameters
140         pCmd->cmdType = MSG_CMD_SUBMIT_REQ;
141
142         // Copy Cookie
143         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
144
145         // Copy Command Data
146         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &reqInfo.reqId, sizeof(msg_request_id_t));
147         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t)), &chInfo, sizeof(MSG_PROXY_INFO_S));
148         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t)+sizeof(MSG_PROXY_INFO_S)), encodedData, dataSize);
149
150         // In case of JAVA MMS msg, add trId
151         if (reqmsg->subType == MSG_SENDREQ_JAVA_MMS)
152                 memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(msg_request_id_t)+sizeof(MSG_PROXY_INFO_S)+dataSize), &trId, sizeof(trId));
153
154         // Send Command to Messaging FW
155         char* pEventData = NULL;
156         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
157
158         write((char*)pCmd, cmdSize, &pEventData);
159
160         // Get Return Data
161         MSG_EVENT_S* pEvent = (MSG_EVENT_S*) pEventData;
162
163         int* pReqId = (int*) pEvent->data;
164         pReq->reqId = *pReqId;
165         MSG_DEBUG("SENT_REQ_ID: %d", pReq->reqId);
166
167         if (pEvent->eventType != MSG_EVENT_SUBMIT_REQ)
168         {
169                 THROW(MsgException::INVALID_RESULT, "Event Data Error:%d", pEvent->eventType);
170         }
171
172         MSG_END();
173
174         return pEvent->result;
175 }
176
177
178 msg_error_t MsgHandle::regSentStatusCallback(msg_sent_status_cb onStatusChanged, void *pUserParam)
179 {
180         if (!onStatusChanged)
181                 THROW(MsgException::INVALID_PARAM, "onStatusChanged is null");
182
183         MsgProxyListener* eventListener = MsgProxyListener::instance();
184
185         eventListener->start(this);
186
187         int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
188
189         if(remoteFd == -1 )
190                 return MSG_ERR_INVALID_MSGHANDLE;
191
192         if (eventListener->regSentStatusEventCB(this, onStatusChanged, pUserParam) == false)
193                 return MSG_ERR_INVALID_PARAMETER;
194
195         // Allocate Memory to Command Data
196         int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
197         char cmdBuf[cmdSize];
198         bzero(cmdBuf, cmdSize);
199         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
200
201         // Set Command Parameters
202         pCmd->cmdType = MSG_CMD_REG_SENT_STATUS_CB;
203
204         // Copy Cookie
205         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
206
207         MSG_DEBUG("remote fd %d", remoteFd);
208
209         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
210
211         MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
212
213         // Send Command to Messaging FW
214         char* pEventData = NULL;
215         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
216
217         write((char*)pCmd, cmdSize, &pEventData);
218
219         // Get Return Data
220         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
221
222         if (pEvent->eventType != MSG_EVENT_REG_SENT_STATUS_CB)
223         {
224                 THROW(MsgException::INVALID_PARAM, "Event Data Error");
225         }
226
227         return pEvent->result;
228 }
229
230
231 msg_error_t MsgHandle::regSmsMessageCallback(msg_sms_incoming_cb onMsgIncoming, unsigned short port, void *pUserParam)
232 {
233         if( (!onMsgIncoming) )
234                 THROW(MsgException::INVALID_PARAM, "Param %p", onMsgIncoming);
235
236         MsgProxyListener* eventListener = MsgProxyListener::instance();
237
238         eventListener->start(this);
239
240         int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
241
242         if(remoteFd == -1 )
243                 return MSG_ERR_INVALID_MSGHANDLE;
244
245         if (eventListener->regMessageIncomingEventCB(this, onMsgIncoming, port, pUserParam) == false)
246                 return MSG_ERR_INVALID_PARAMETER;
247
248         // Allocate Memory to Command Data
249         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
250
251         char cmdBuf[cmdSize];
252         bzero(cmdBuf, cmdSize);
253
254         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
255
256         // Set Command Parameters
257         pCmd->cmdType = MSG_CMD_REG_INCOMING_MSG_CB;
258
259         // Copy Cookie
260         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
261
262         MSG_CMD_REG_INCOMING_MSG_CB_S cmdParam = {0};
263
264         cmdParam.listenerFd = remoteFd;
265         cmdParam.msgType = MSG_SMS_TYPE;
266         cmdParam.port = port;
267
268         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
269
270         MSG_DEBUG("reg new msg [%s], fd %d, port %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, cmdParam.port);
271
272         // Send Command to Messaging FW
273         char* pEventData = NULL;
274         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
275
276
277         write((char*)pCmd, cmdSize, &pEventData);
278
279         // Get Return Data
280         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
281
282         if (pEvent->eventType != MSG_EVENT_REG_INCOMING_MSG_CB)
283         {
284                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
285         }
286
287         return pEvent->result;
288 }
289
290
291 msg_error_t MsgHandle::regMmsConfMessageCallback(msg_mms_conf_msg_incoming_cb onMMSConfMsgIncoming, const char *pAppId, void *pUserParam)
292 {
293         if( (!onMMSConfMsgIncoming) )
294                 THROW(MsgException::INVALID_PARAM, "Param %p", onMMSConfMsgIncoming);
295
296         MsgProxyListener* eventListener = MsgProxyListener::instance();
297
298         eventListener->start(this);
299
300         int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
301
302         if(remoteFd == -1 )
303                 return MSG_ERR_INVALID_MSGHANDLE;
304
305         if (eventListener->regMMSConfMessageIncomingEventCB(this, onMMSConfMsgIncoming, pAppId, pUserParam) == false)
306                 return MSG_ERR_INVALID_PARAMETER;
307
308         // Allocate Memory to Command Data
309         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S);
310
311         char cmdBuf[cmdSize];
312         bzero(cmdBuf, cmdSize);
313
314         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
315
316         // Set Command Parameters
317         pCmd->cmdType = MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB;
318
319         // Copy Cookie
320         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
321
322         MSG_CMD_REG_INCOMING_MMS_CONF_MSG_CB_S cmdParam = {0};
323
324         cmdParam.listenerFd = remoteFd;
325         cmdParam.msgType = MSG_MMS_TYPE;
326
327         if (pAppId)
328                 strncpy(cmdParam.appId, pAppId, MAX_MMS_JAVA_APPID_LEN);
329
330         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
331
332         MSG_DEBUG("reg new msg [%s], fd:%d, appId:%s", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd,  (pAppId)? cmdParam.appId:"NULL" );
333
334         // Send Command to Messaging FW
335         char* pEventData = NULL;
336         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
337
338
339         write((char*)pCmd, cmdSize, &pEventData);
340
341         // Get Return Data
342         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
343
344         if (pEvent->eventType != MSG_EVENT_REG_INCOMING_MMS_CONF_MSG_CB)
345         {
346                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
347         }
348
349         return pEvent->result;
350 }
351
352
353 msg_error_t MsgHandle::regSyncMLMessageCallback(msg_syncml_msg_incoming_cb onSyncMLMsgIncoming, void *pUserParam)
354 {
355         if( (!onSyncMLMsgIncoming) )
356                 THROW(MsgException::INVALID_PARAM, "Param %p", onSyncMLMsgIncoming);
357
358         MsgProxyListener* eventListener = MsgProxyListener::instance();
359
360         eventListener->start(this);
361
362         int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
363
364         if(remoteFd == -1 )
365                 return MSG_ERR_INVALID_MSGHANDLE;
366
367         if (eventListener->regSyncMLMessageIncomingEventCB(this, onSyncMLMsgIncoming, pUserParam) == false)
368                 return MSG_ERR_INVALID_PARAMETER;
369
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
372
373         char cmdBuf[cmdSize];
374         bzero(cmdBuf, cmdSize);
375
376         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
377
378         // Set Command Parameters
379         pCmd->cmdType = MSG_CMD_REG_INCOMING_SYNCML_MSG_CB;
380
381         // Copy Cookie
382         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
383
384         MSG_CMD_REG_INCOMING_SYNCML_MSG_CB_S cmdParam = {0};
385
386         cmdParam.listenerFd = remoteFd;
387         cmdParam.msgType = MSG_SMS_TYPE;
388
389         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
390
391         MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
392
393         // Send Command to Messaging FW
394         char* pEventData = NULL;
395         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
396
397         write((char*)pCmd, cmdSize, &pEventData);
398
399         // Get Return Data
400         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
401
402         if (pEvent->eventType != MSG_EVENT_REG_INCOMING_SYNCML_MSG_CB)
403         {
404                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
405         }
406
407         return pEvent->result;
408 }
409
410
411 msg_error_t MsgHandle::regLBSMessageCallback(msg_lbs_msg_incoming_cb onLBSMsgIncoming, void *pUserParam)
412 {
413         if( (!onLBSMsgIncoming) )
414                 THROW(MsgException::INVALID_PARAM, "Param %p", onLBSMsgIncoming);
415
416         MsgProxyListener* eventListener = MsgProxyListener::instance();
417
418         eventListener->start(this);
419
420         int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
421
422         if(remoteFd == -1 )
423                 return MSG_ERR_INVALID_MSGHANDLE;
424
425         if (eventListener->regLBSMessageIncomingEventCB(this, onLBSMsgIncoming, pUserParam) == false)
426                 return MSG_ERR_INVALID_PARAMETER;
427
428         // Allocate Memory to Command Data
429         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_LBS_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
430         char cmdBuf[cmdSize];
431         bzero(cmdBuf, cmdSize);
432         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
433
434         // Set Command Parameters
435         pCmd->cmdType = MSG_CMD_REG_INCOMING_LBS_MSG_CB;
436
437         // Copy Cookie
438         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
439
440         MSG_CMD_REG_INCOMING_LBS_MSG_CB_S cmdParam = {0};
441
442         cmdParam.listenerFd = remoteFd;
443         cmdParam.msgType = MSG_SMS_TYPE;
444
445         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
446
447         MSG_DEBUG("reg new msg [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
448
449         // Send Command to Messaging FW
450         char* pEventData = NULL;
451         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
452
453
454         write((char*)pCmd, cmdSize, &pEventData);
455
456         // Get Return Data
457         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
458
459         if (pEvent->eventType != MSG_EVENT_REG_INCOMING_LBS_MSG_CB)
460         {
461                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
462         }
463
464         return pEvent->result;
465 }
466
467
468 msg_error_t MsgHandle::regSyncMLMessageOperationCallback(msg_syncml_msg_operation_cb onSyncMLMsgOperation, void *pUserParam)
469 {
470         if( (!onSyncMLMsgOperation) )
471                 THROW(MsgException::INVALID_PARAM, "Param %p", onSyncMLMsgOperation);
472
473         MsgProxyListener* eventListener = MsgProxyListener::instance();
474
475         eventListener->start(this);
476
477         int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
478
479         if(remoteFd == -1 )
480                 return MSG_ERR_INVALID_MSGHANDLE;
481
482         if (eventListener->regSyncMLMessageOperationEventCB(this, onSyncMLMsgOperation, pUserParam) == false)
483                 return MSG_ERR_INVALID_PARAMETER;
484
485         // Allocate Memory to Command Data
486         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
487
488         char cmdBuf[cmdSize];
489         bzero(cmdBuf, cmdSize);
490
491         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
492
493         // Set Command Parameters
494         pCmd->cmdType = MSG_CMD_REG_SYNCML_MSG_OPERATION_CB;
495
496         // Copy Cookie
497         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
498
499         MSG_CMD_REG_SYNCML_MSG_OPERATION_CB_S cmdParam = {0};
500
501         cmdParam.listenerFd = remoteFd;
502         cmdParam.msgType = MSG_SMS_TYPE;
503
504         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
505
506         MSG_DEBUG("register syncML msg operation callback [%s], fd %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd);
507
508         // Send Command to Messaging FW
509         char* pEventData = NULL;
510         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
511
512
513         write((char*)pCmd, cmdSize, &pEventData);
514
515         // Get Return Data
516         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
517
518         if (pEvent->eventType != MSG_EVENT_REG_SYNCML_MSG_OPERATION_CB)
519         {
520                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
521         }
522
523         return pEvent->result;
524 }
525
526 msg_error_t MsgHandle::regPushMessageCallback(msg_push_msg_incoming_cb onPushMsgIncoming, const char *pAppId, void *pUserParam)
527 {
528         if( (!onPushMsgIncoming) )
529                 THROW(MsgException::INVALID_PARAM, "Param %p", onPushMsgIncoming);
530
531         MsgProxyListener* eventListener = MsgProxyListener::instance();
532
533         eventListener->start(this);
534
535         int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
536
537         if(remoteFd == -1 )
538                 return MSG_ERR_INVALID_MSGHANDLE;
539
540         if (eventListener->regPushMessageIncomingEventCB(this, onPushMsgIncoming, pAppId, pUserParam) == false)
541                 return MSG_ERR_INVALID_PARAMETER;
542
543         // Allocate Memory to Command Data
544         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S);
545
546         char cmdBuf[cmdSize];
547         bzero(cmdBuf, cmdSize);
548
549         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
550
551         // Set Command Parameters
552         pCmd->cmdType = MSG_CMD_REG_INCOMING_PUSH_MSG_CB;
553
554         // Copy Cookie
555         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
556
557         MSG_CMD_REG_INCOMING_PUSH_MSG_CB_S cmdParam = {0};
558
559         cmdParam.listenerFd = remoteFd;
560         cmdParam.msgType = MSG_SMS_TYPE;
561
562         if (pAppId)
563                 strncpy(cmdParam.appId, pAppId, MAX_WAPPUSH_ID_LEN);
564
565         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
566
567         MSG_DEBUG("reg new msg [%s], fd:%d, appId:%s", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd,  (pAppId)? cmdParam.appId:"NULL" );
568
569         // Send Command to Messaging FW
570         char* pEventData = NULL;
571         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
572
573
574         write((char*)pCmd, cmdSize, &pEventData);
575
576         // Get Return Data
577         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
578
579         if (pEvent->eventType != MSG_EVENT_REG_INCOMING_PUSH_MSG_CB)
580         {
581                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
582         }
583
584         return pEvent->result;
585 }
586
587 msg_error_t MsgHandle::regCBMessageCallback(msg_cb_incoming_cb onCBIncoming, bool bSave, void *pUserParam)
588 {
589         if( (!onCBIncoming) )
590                 THROW(MsgException::INVALID_PARAM, "Param %p", onCBIncoming);
591
592         MsgProxyListener* eventListener = MsgProxyListener::instance();
593
594         eventListener->start(this);
595
596         int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
597
598         if(remoteFd == -1 )
599                 return MSG_ERR_INVALID_MSGHANDLE;
600
601         if (eventListener->regCBMessageIncomingEventCB(this, onCBIncoming, bSave, pUserParam) == false)
602                 return MSG_SUCCESS;
603
604         // Allocate Memory to Command Data
605         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CMD_REG_INCOMING_CB_MSG_CB_S); //sizeof(int) + sizeof; // cmd type, listener fd
606
607         char cmdBuf[cmdSize];
608         bzero(cmdBuf, cmdSize);
609
610         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
611
612         // Set Command Parameters
613         pCmd->cmdType = MSG_CMD_REG_INCOMING_CB_MSG_CB;
614
615         // Copy Cookie
616         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
617
618         MSG_CMD_REG_CB_INCOMING_MSG_CB_S cmdParam = {0};
619
620         cmdParam.listenerFd = remoteFd;
621         cmdParam.msgType = MSG_SMS_TYPE;
622         cmdParam.bsave = bSave;
623
624         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &cmdParam, sizeof(cmdParam));
625
626         MSG_DEBUG("reg new msg [%s], fd: %d, bSave: %d", MsgDbgCmdStr(pCmd->cmdType), cmdParam.listenerFd, cmdParam.bsave);
627
628         // Send Command to Messaging FW
629         char* pEventData = NULL;
630         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
631
632
633         write((char*)pCmd, cmdSize, &pEventData);
634
635         // Get Return Data
636         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
637
638         if (pEvent->eventType != MSG_EVENT_REG_INCOMING_CB_MSG_CB)
639         {
640                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
641         }
642
643         return pEvent->result;
644 }
645
646
647 msg_error_t MsgHandle::regReportMessageCallback(msg_report_msg_incoming_cb onReportMsgCB, void *pUserParam)
648 {
649         if (!onReportMsgCB)
650                 THROW(MsgException::INVALID_PARAM, "onReportMsgCB is null");
651
652         MsgProxyListener* eventListener = MsgProxyListener::instance();
653
654         eventListener->start(this);
655
656         int remoteFd = eventListener->getRemoteFd(); // fd that is reserved to the "listener thread" by msgfw daemon
657
658         if(remoteFd == -1 )
659                 return MSG_ERR_INVALID_MSGHANDLE;
660
661         if (eventListener->regReportMsgIncomingCB(this, onReportMsgCB, pUserParam) == false)
662                 return MSG_ERR_INVALID_PARAMETER;
663
664         // Allocate Memory to Command Data
665         int cmdSize = sizeof(MSG_CMD_S) + sizeof(int); // cmd type, listenerFd
666         char cmdBuf[cmdSize];
667         bzero(cmdBuf, cmdSize);
668         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
669
670         // Set Command Parameters
671         pCmd->cmdType = MSG_CMD_REG_REPORT_MSG_INCOMING_CB;
672
673         // Copy Cookie
674         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
675
676         MSG_DEBUG("remote fd %d", remoteFd);
677
678         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &remoteFd, sizeof(remoteFd));
679
680         MSG_DEBUG("reg status [%d : %s], %d", pCmd->cmdType, MsgDbgCmdStr(pCmd->cmdType), remoteFd);
681
682         // Send Command to Messaging FW
683         char* pEventData = NULL;
684         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
685
686         write((char*)pCmd, cmdSize, &pEventData);
687
688         // Get Return Data
689         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
690
691         if (pEvent->eventType != MSG_EVENT_REG_REPORT_MSG_INCOMING_CB)
692         {
693                 THROW(MsgException::INVALID_PARAM, "Event Data Error");
694         }
695
696         return pEvent->result;
697 }
698
699
700 msg_error_t MsgHandle::operateSyncMLMessage(msg_message_id_t msgId)
701 {
702         if( msgId < 1)
703                 THROW(MsgException::INVALID_PARAM, "Param msgId %d", msgId);
704
705         // Allocate Memory to Command Data
706         int cmdSize = sizeof(MSG_CMD_S) + sizeof(msg_message_id_t);
707
708         char cmdBuf[cmdSize];
709         bzero(cmdBuf, cmdSize);
710         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
711
712         // Set Command Parameters
713         pCmd->cmdType = MSG_CMD_SYNCML_OPERATION;
714
715         // Copy Cookie
716         memcpy(pCmd->cmdCookie, mCookie, MAX_COOKIE_LEN);
717
718         // Copy Command Data
719         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), &msgId, sizeof(msg_message_id_t));
720
721         // Send Command to Messaging FW
722         char* pEventData = NULL;
723         unique_ptr<char*, void(*)(char**)> eventBuf(&pEventData, unique_ptr_deleter);
724
725
726         write((char*)pCmd, cmdSize, &pEventData);
727
728         // Get Return Data
729         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)pEventData;
730
731         if (pEvent->eventType != MSG_EVENT_SYNCML_OPERATION)
732         {
733                 THROW(MsgException::INVALID_RESULT, "Event Data Error");
734         }
735
736         return pEvent->result;
737 }