RSA sync with private
[platform/core/messaging/msg-service.git] / framework / plugin-manager / MsgPluginManager.cpp
1 /*
2 * Copyright 2012  Samsung Electronics Co., Ltd
3 *
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
7 *
8 *    http://www.tizenopensource.org/license
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 <stdio.h>
18 #include <dlfcn.h>
19
20 #include "MsgDebug.h"
21 #include "MsgUtilFile.h"
22 #include "MsgException.h"
23 #include "MsgIpcSocket.h"
24 #include "MsgCmdTypes.h"
25 #include "MsgGconfWrapper.h"
26 #include "MsgPluginManager.h"
27 #include "MsgMmsTypes.h"
28
29
30 /*==================================================================================================
31                                      FUNCTION IMPLEMENTATION
32 ==================================================================================================*/
33 void MsgSentStatusListener(MSG_SENT_STATUS_S *pSentStatus)
34 {
35         MSG_BEGIN();
36
37         MSG_DEBUG("SENT STATUS %d, %d", pSentStatus->reqId, pSentStatus->status);
38
39         // establish connection to msgfw daemon
40         MsgIpcClientSocket client;
41         client.connect(MSG_SOCKET_PATH);
42
43         // composing command
44         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_SENT_STATUS_S); // cmd type, MSG_SENT_STATUS
45
46         char cmdBuf[cmdSize];
47         bzero(cmdBuf, cmdSize);
48
49         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
50
51         // Set Command Parameters
52         pCmd->cmdType = MSG_CMD_PLG_SENT_STATUS_CNF;
53
54         memset(pCmd->cmdCookie, 0x00, MAX_COOKIE_LEN);
55
56         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pSentStatus, sizeof(MSG_SENT_STATUS_S));
57
58         // Send Command to Transaction Manager
59         client.write(cmdBuf, cmdSize);
60
61         // Receive result from Transaction Manager
62         MSG_DEBUG("Waiting result for SENT STATUS");
63
64         char *temp = NULL;
65         AutoPtr<char> wrap(&temp);
66         unsigned int len;
67         client.read(&temp, &len);
68
69         // close connection to msgfw daemon
70         client.close();
71
72         MSG_END();
73 }
74
75
76 void MsgStorageChangeListener(msg_storage_change_type_t storageChangeType, MSG_MESSAGE_INFO_S *pMsgInfo)
77 {
78         MSG_BEGIN();
79
80         MSG_DEBUG("StorageChangeType : [%d], msg ID : [%d]", storageChangeType, pMsgInfo->msgId);
81
82         // establish connection to msgfw daemon
83         MsgIpcClientSocket client;
84         client.connect(MSG_SOCKET_PATH);
85
86         // composing command
87         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_INFO_S) + sizeof(msg_storage_change_type_t);
88
89         char cmdBuf[cmdSize];
90         bzero(cmdBuf, cmdSize);
91
92         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
93
94         // Set Command Parameters
95         pCmd->cmdType = MSG_CMD_PLG_STORAGE_CHANGE_IND;
96
97         memset(pCmd->cmdCookie, 0x00, MAX_COOKIE_LEN);
98
99         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
100         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_INFO_S)), &storageChangeType, sizeof(msg_storage_change_type_t));
101
102         // Send Command to Transaction Manager
103         client.write(cmdBuf, cmdSize);
104
105         // Receive result from Transaction Manager
106         MSG_DEBUG("Waiting result for STORAGE CHANGE");
107
108         char *temp = NULL;
109         AutoPtr<char> wrap(&temp);
110         unsigned int len;
111         client.read(&temp, &len);
112
113         // close connection to msgfw daemon
114         client.close();
115
116         MSG_END();
117 }
118
119
120 msg_error_t MsgIncomingMessageListener(MSG_MESSAGE_INFO_S *pMsg)
121 {
122         MSG_BEGIN();
123
124         // establish connection to msgfw daemon
125         MsgIpcClientSocket client;
126         client.connect(MSG_SOCKET_PATH);
127
128         // Check Invalid Message Structure
129         if (pMsg == NULL)
130         {
131                 MSG_DEBUG("pMsg is NULL !!");
132
133                 return MSG_ERR_NULL_MESSAGE;
134         }
135
136         // composing command
137         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_INFO_S); // cmd type, MSG_MESSAGE_INFO_S
138
139         MSG_DEBUG("cmdSize: %d", cmdSize);
140
141         char cmdBuf[cmdSize];
142         bzero(cmdBuf, cmdSize);
143
144         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
145
146         // Set Command Parameters
147         pCmd->cmdType = MSG_CMD_PLG_INCOMING_MSG_IND;
148
149         memset(pCmd->cmdCookie, 0x00, MAX_COOKIE_LEN);
150
151         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pMsg, sizeof(MSG_MESSAGE_INFO_S));
152
153         // Send Command to Messaging FW
154         client.write(cmdBuf, cmdSize);
155
156         char* retBuf = NULL;
157         AutoPtr<char> wrap(&retBuf);
158         unsigned int retSize;
159
160         client.read(&retBuf, &retSize);
161
162         // close connection to msgfw daemon
163         client.close();
164
165         // Decoding the result from FW and Returning it to plugin
166         // the result is used for making delivery report
167         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)retBuf;
168
169         if (pEvent->eventType != MSG_EVENT_PLG_INCOMING_MSG_IND)
170                 THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
171
172         MSG_END();
173
174         return (pEvent->result);
175 }
176
177
178 msg_error_t MsgIncomingSyncMLMessageListener(MSG_SYNCML_MESSAGE_DATA_S *pSyncMLData)
179 {
180         MSG_BEGIN();
181
182         // establish connection to msgfw daemon
183         MsgIpcClientSocket client;
184         client.connect(MSG_SOCKET_PATH);
185
186         // composing command
187         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_SYNCML_MESSAGE_DATA_S); // cmd type, MSG_SYNCML_MESSAGE_DATA_S
188
189         MSG_DEBUG("cmdSize: %d", cmdSize);
190
191         char cmdBuf[cmdSize];
192         bzero(cmdBuf, cmdSize);
193         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
194
195         // Set Command Parameters
196         pCmd->cmdType = MSG_CMD_PLG_INCOMING_SYNCML_IND;
197
198         memset(pCmd->cmdCookie, 0x00, MAX_COOKIE_LEN);
199
200         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pSyncMLData, sizeof(MSG_SYNCML_MESSAGE_DATA_S));
201
202         // Send Command to Messaging FW
203         client.write(cmdBuf, cmdSize);
204
205         // Receive result from Transaction Manager
206         char* retBuf = NULL;
207         AutoPtr<char> wrap(&retBuf);
208         unsigned int retSize;
209         client.read(&retBuf, &retSize);
210
211         // close connection to msgfw daemon
212         client.close();
213
214         // Decoding the result from FW and Returning it to plugin
215         // the result is used for making delivery report
216         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)retBuf;
217
218         if (pEvent->eventType != MSG_EVENT_PLG_INCOMING_SYNCML_MSG_IND)
219                 THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
220
221         MSG_END();
222
223         return (pEvent->result);
224 }
225
226 msg_error_t MsgIncomingPushMessageListener(MSG_PUSH_MESSAGE_DATA_S *pPushData)
227 {
228         MSG_BEGIN();
229
230         // establish connection to msgfw daemon
231         MsgIpcClientSocket client;
232         client.connect(MSG_SOCKET_PATH);
233
234         // composing command
235         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_PUSH_MESSAGE_DATA_S); // cmd type, MSG_SYNCML_MESSAGE_DATA_S
236
237         MSG_DEBUG("cmdSize: %d", cmdSize);
238
239         char cmdBuf[cmdSize];
240         bzero(cmdBuf, cmdSize);
241         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
242
243         // Set Command Parameters
244         pCmd->cmdType = MSG_CMD_PLG_INCOMING_PUSH_IND;
245
246         memset(pCmd->cmdCookie, 0x00, MAX_COOKIE_LEN);
247
248         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pPushData, sizeof(MSG_PUSH_MESSAGE_DATA_S));
249
250         // Send Command to Messaging FW
251         client.write(cmdBuf, cmdSize);
252
253         // Receive result from Transaction Manager
254         char* retBuf = NULL;
255         AutoPtr<char> wrap(&retBuf);
256         unsigned int retSize;
257         client.read(&retBuf, &retSize);
258
259         // close connection to msgfw daemon
260         client.close();
261
262         // Decoding the result from FW and Returning it to plugin
263         // the result is used for making delivery report
264         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)retBuf;
265
266         if (pEvent->eventType != MSG_EVENT_PLG_INCOMING_PUSH_MSG_IND)
267                 THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
268
269         MSG_END();
270
271         return (pEvent->result);
272 }
273
274
275 msg_error_t MsgIncomingCBMessageListener(MSG_CB_MSG_S *pCbMsg)
276 {
277         MSG_BEGIN();
278
279         // establish connection to msgfw daemon
280         MsgIpcClientSocket client;
281         client.connect(MSG_SOCKET_PATH);
282
283         // Check Invalid Message Structure
284         if (pCbMsg == NULL)
285         {
286                 MSG_DEBUG("pMsg is NULL !!");
287
288                 return MSG_ERR_NULL_MESSAGE;
289         }
290
291         // composing command
292         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_CB_MSG_S); // cmd type, MSG_CB_MSG_S
293
294         MSG_DEBUG("cmdSize: %d", cmdSize);
295
296         char cmdBuf[cmdSize];
297         bzero(cmdBuf, cmdSize);
298
299         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
300
301         // Set Command Parameters
302         pCmd->cmdType = MSG_CMD_PLG_INCOMING_CB_IND;
303
304         memset(pCmd->cmdCookie, 0x00, MAX_COOKIE_LEN);
305
306         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pCbMsg, sizeof(MSG_CB_MSG_S));
307
308         // Send Command to Messaging FW
309         client.write(cmdBuf, cmdSize);
310
311         char* retBuf = NULL;
312         AutoPtr<char> wrap(&retBuf);
313         unsigned int retSize;
314
315         client.read(&retBuf, &retSize);
316
317         // close connection to msgfw daemon
318         client.close();
319
320         // Decoding the result from FW and Returning it to plugin
321         // the result is used for making delivery report
322         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)retBuf;
323
324         if (pEvent->eventType != MSG_EVENT_PLG_INCOMING_CB_MSG_IND)
325                 THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
326
327         MSG_END();
328
329         return (pEvent->result);
330 }
331
332
333 msg_error_t MsgIncomingLBSMessageListener(MSG_LBS_MESSAGE_DATA_S *pLBSData)
334 {
335         MSG_BEGIN();
336
337         // establish connection to msgfw daemon
338         MsgIpcClientSocket client;
339         client.connect(MSG_SOCKET_PATH);
340
341         // composing command
342         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_LBS_MESSAGE_DATA_S); // cmd type, MSG_LBS_MESSAGE_DATA_S
343
344         MSG_DEBUG("cmdSize: %d", cmdSize);
345
346         char cmdBuf[cmdSize];
347         bzero(cmdBuf, cmdSize);
348         MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
349
350         // Set Command Parameters
351         pCmd->cmdType = MSG_CMD_PLG_INCOMING_LBS_IND;
352
353         memset(pCmd->cmdCookie, 0x00, MAX_COOKIE_LEN);
354
355         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pLBSData, sizeof(MSG_LBS_MESSAGE_DATA_S));
356
357         // Send Command to Messaging FW
358         client.write(cmdBuf, cmdSize);
359
360         // Receive result from Transaction Manager
361         char* retBuf = NULL;
362         AutoPtr<char> wrap(&retBuf);
363         unsigned int retSize;
364         client.read(&retBuf, &retSize);
365
366         // close connection to msgfw daemon
367         client.close();
368
369         // Decoding the result from FW and Returning it to plugin
370         // the result is used for making delivery report
371         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)retBuf;
372
373         if (pEvent->eventType != MSG_EVENT_PLG_INCOMING_LBS_MSG_IND)
374                 THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
375
376         MSG_END();
377
378         return (pEvent->result);
379 }
380
381
382 msg_error_t MsgInitSimBySatListener()
383 {
384         MSG_BEGIN();
385
386         // establish connection to msgfw daemon
387         MsgIpcClientSocket client;
388         client.connect(MSG_SOCKET_PATH);
389
390         // composing command
391         int cmdSize = sizeof(MSG_CMD_S);
392
393         char cmdBuf[cmdSize];
394         bzero(cmdBuf, cmdSize);
395
396         MSG_CMD_S* pCmd = (MSG_CMD_S*)cmdBuf;
397
398         // Set Command Parameters
399         pCmd->cmdType = MSG_CMD_PLG_INIT_SIM_BY_SAT;
400
401         // Send Command to Transaction Manager
402         client.write(cmdBuf, cmdSize);
403
404         // Receive result from Transaction Manager
405         char* retBuf = NULL;
406         AutoPtr<char> wrap(&retBuf);
407         unsigned int retSize;
408         client.read(&retBuf, &retSize);
409
410         // close connection to msgfw daemon
411         client.close();
412
413         // Decoding the result from FW and Returning it to plugin
414         MSG_EVENT_S* pEvent = (MSG_EVENT_S*)retBuf;
415
416         if (pEvent->eventType != MSG_EVENT_PLG_INIT_SIM_BY_SAT)
417                 THROW(MsgException::INVALID_RESULT, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
418
419         MSG_END();
420
421         return (pEvent->result);
422 }
423
424 /* MMS_Incoming_listener */
425 msg_error_t MsgMmsConfIncomingListener(MSG_MESSAGE_INFO_S *pMsg, msg_request_id_t *pReqId)
426 {
427         MSG_BEGIN();
428         MSG_DEBUG("pMsg = %s, pReqId = %d ", pMsg->msgData, *pReqId);
429
430         // establish connection to msgfw daemon
431         MsgIpcClientSocket client;
432         client.connect(MSG_SOCKET_PATH);
433
434         // composing command
435         int cmdSize = sizeof(MSG_CMD_S) + sizeof(MSG_MESSAGE_INFO_S) + sizeof(msg_request_id_t); // cmd type, MSG_MESSAGE_INFO_S, msg_request_id_t
436         MSG_DEBUG("cmdSize : %d", cmdSize);
437
438         char cmdBuf[cmdSize];
439         bzero(cmdBuf, cmdSize);
440
441         MSG_CMD_S *pCmd = (MSG_CMD_S *)cmdBuf;
442
443         // Set Command Parameters
444         pCmd->cmdType = MSG_CMD_PLG_INCOMING_MMS_CONF; // cmd type
445
446         memset(pCmd->cmdCookie, 0x00, MAX_COOKIE_LEN); // cmd cookie
447
448         // cmd data
449         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN), pMsg, sizeof(MSG_MESSAGE_INFO_S));
450         memcpy((void*)((char*)pCmd+sizeof(MSG_CMD_TYPE_T)+MAX_COOKIE_LEN+sizeof(MSG_MESSAGE_INFO_S)), pReqId, sizeof(msg_request_id_t));
451
452         // Send Command to Messaging FW
453         client.write(cmdBuf, cmdSize);
454
455         // Receive result from Transaction Manager
456         char *retBuf = NULL;
457         AutoPtr<char> wrap(&retBuf);
458         unsigned int retSize = 0;
459         client.read(&retBuf, &retSize);
460
461         // close connection to msgfw daemon
462         client.close();
463
464         //Decoding the result from FW and Returning it to plugin
465         // the result is used for making delivery report
466         MSG_EVENT_S *pEvent = (MSG_EVENT_S *)retBuf;
467
468         if(pEvent->eventType != MSG_EVENT_PLG_INCOMING_MMS_CONF && pEvent->eventType != MSG_EVENT_PLG_SENT_STATUS_CNF)
469                 THROW(MsgException::INCOMING_MSG_ERROR, "Wrong result(evt type %d : %s) received", pEvent->eventType, MsgDbgEvtStr(pEvent->eventType));
470
471         MSG_END();
472
473         return (pEvent->result);
474 }
475
476 /*==================================================================================================
477                                      IMPLEMENTATION OF MsgPlugin - Member Functions
478 ==================================================================================================*/
479 MsgPlugin::MsgPlugin(MSG_MAIN_TYPE_T mainType, const char *libPath): mSupportedMsg(mainType)
480 {
481         MSG_DEBUG("msg type : [%d] library path : [%s]", mainType, libPath);
482
483         bzero(&mPlgHandler, sizeof(mPlgHandler));
484
485         if (libPath == NULL)
486                 THROW(MsgException::INVALID_PARAM, "libPath NULL");
487
488         mLibHandler = NULL;
489
490         mLibHandler = dlopen(libPath, RTLD_NOW);
491
492         if (!mLibHandler)
493                 THROW(MsgException::PLUGIN_ERROR, "ERROR dlopen library : [%s] [%s]", libPath, dlerror());
494
495         // Clear Error
496         dlerror();
497
498         // assign the c function pointers
499         msg_error_t(*pFunc)(MSG_PLUGIN_HANDLER_S*) = NULL;
500
501         pFunc = (msg_error_t(*)(MSG_PLUGIN_HANDLER_S*))dlsym(mLibHandler, "MsgPlgCreateHandle");
502
503         char *error = dlerror();
504
505         if (error != NULL)
506                 THROW(MsgException::PLUGIN_ERROR, "ERROR dlsym library : [%s]", dlerror());
507
508         if ((*pFunc)(&mPlgHandler) != MSG_SUCCESS)
509                 THROW(MsgException::PLUGIN_ERROR, "ERROR to create plugin handle");
510
511         // Initialize Plug-in
512         if (initialize() != MSG_SUCCESS)
513                 THROW(MsgException::PLUGIN_ERROR, "ERROR to initialize plugin");
514
515         MSG_PLUGIN_LISTENER_S fwListener = {0};
516         fwListener.pfSentStatusCb                       = &MsgSentStatusListener;
517         fwListener.pfStorageChangeCb            = &MsgStorageChangeListener;
518         fwListener.pfMsgIncomingCb              = &MsgIncomingMessageListener;
519         fwListener.pfInitSimBySatCb                     = &MsgInitSimBySatListener;
520         fwListener.pfSyncMLMsgIncomingCb        = &MsgIncomingSyncMLMessageListener;
521         fwListener.pfLBSMsgIncomingCb           = &MsgIncomingLBSMessageListener;
522         fwListener.pfMmsConfIncomingCb = &MsgMmsConfIncomingListener;
523         fwListener.pfPushMsgIncomingCb          = &MsgIncomingPushMessageListener;
524         fwListener.pfCBMsgIncomingCb            = &MsgIncomingCBMessageListener;
525
526         if (registerListener(&fwListener) != MSG_SUCCESS)
527                 THROW(MsgException::PLUGIN_ERROR, "ERROR to register listener");
528
529 }
530
531
532 MsgPlugin::~MsgPlugin()
533 {
534         this->finalize();
535         // close mLibHandler.
536         if (mLibHandler != NULL)
537                 dlclose(mLibHandler);
538 }
539
540
541 msg_error_t MsgPlugin::initialize()
542 {
543         if ( mPlgHandler.pfInitialize != NULL)
544                 return mPlgHandler.pfInitialize();
545         else
546                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
547 }
548
549
550 void MsgPlugin::finalize()
551 {
552         if (mPlgHandler.pfFinalize != NULL)
553                 mPlgHandler.pfFinalize();
554 }
555
556
557 msg_error_t MsgPlugin::submitReq(MSG_REQUEST_INFO_S *pReqInfo)
558 {
559         if (mPlgHandler.pfSubmitRequest != NULL)
560                 return mPlgHandler.pfSubmitRequest(pReqInfo);
561         else
562                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
563 }
564
565
566 msg_error_t MsgPlugin::registerListener(MSG_PLUGIN_LISTENER_S *pListener)
567 {
568         if (mPlgHandler.pfRegisterListener != NULL)
569                 return mPlgHandler.pfRegisterListener(pListener);
570         else
571                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
572 }
573
574
575 msg_error_t MsgPlugin::checkSimStatus(MSG_SIM_STATUS_T *pStatus)
576 {
577         if (mPlgHandler.pfRegisterListener != NULL)
578                 return mPlgHandler.pfCheckSimStatus(pStatus);
579         else
580                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
581 }
582
583
584 msg_error_t MsgPlugin::checkDeviceStatus()
585 {
586         if (mPlgHandler.pfRegisterListener != NULL)
587                 return mPlgHandler.pfCheckDeviceStatus();
588         else
589                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
590 }
591
592
593 msg_error_t MsgPlugin::initSimMessage()
594 {
595         if (mPlgHandler.pfInitSimMessage != NULL)
596                 return mPlgHandler.pfInitSimMessage();
597         else
598                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
599 }
600
601
602 msg_error_t MsgPlugin::saveSimMessage(MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_LIST_S *pSimIdList)
603 {
604         if (mPlgHandler.pfSaveSimMessage != NULL)
605                 return mPlgHandler.pfSaveSimMessage(pMsgInfo, pSimIdList);
606         else
607                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
608 }
609
610
611 msg_error_t MsgPlugin::deleteSimMessage(msg_sim_id_t SimMsgId)
612 {
613         if (mPlgHandler.pfDeleteSimMessage != NULL)
614                 return mPlgHandler.pfDeleteSimMessage(SimMsgId);
615         else
616                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
617 }
618
619
620 msg_error_t MsgPlugin::setReadStatus(msg_sim_id_t SimMsgId)
621 {
622         if (mPlgHandler.pfSetReadStatus != NULL)
623                 return mPlgHandler.pfSetReadStatus(SimMsgId);
624         else
625                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
626 }
627
628
629 msg_error_t MsgPlugin::setMemoryStatus(msg_error_t Error)
630 {
631         if (mPlgHandler.pfSetMemoryStatus != NULL)
632                 return mPlgHandler.pfSetMemoryStatus(Error);
633         else
634                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
635 }
636
637
638 msg_error_t MsgPlugin::initConfigData(MSG_SIM_STATUS_T SimStatus)
639 {
640         if (mPlgHandler.pfInitConfigData != NULL)
641                 return mPlgHandler.pfInitConfigData(SimStatus);
642         else
643                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
644 }
645
646
647 msg_error_t MsgPlugin::setConfigData(const MSG_SETTING_S *pSetting)
648 {
649         if (mPlgHandler.pfSetConfigData != NULL)
650                 return mPlgHandler.pfSetConfigData(pSetting);
651         else
652                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
653 }
654
655
656 msg_error_t MsgPlugin::getConfigData(MSG_SETTING_S *pSetting)
657 {
658         if (mPlgHandler.pfGetConfigData != NULL)
659                 return mPlgHandler.pfGetConfigData(pSetting);
660         else
661                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
662 }
663
664 msg_error_t MsgPlugin::addMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData)
665 {
666         if (mPlgHandler.pfAddMessage != NULL) {
667                 return mPlgHandler.pfAddMessage(pMsgInfo, pSendOptInfo, pFileData);
668         } else {
669                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
670         }
671 }
672
673 msg_error_t MsgPlugin::updateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData)
674 {
675         if (mPlgHandler.pfUpdateMessage != NULL) {
676                 return mPlgHandler.pfUpdateMessage(pMsgInfo, pSendOptInfo, pFileData);
677         } else {
678                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
679         }
680 }
681
682
683 msg_error_t MsgPlugin::processReceivedInd(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_REQUEST_INFO_S *pRequest, bool *bReject)
684 {
685         if (mPlgHandler.pfProcessReceivedInd != NULL) {
686                 return mPlgHandler.pfProcessReceivedInd(pMsgInfo, pRequest, bReject);
687         } else {
688                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
689         }
690 }
691
692
693 msg_error_t MsgPlugin::getMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo,  MMS_MESSAGE_DATA_S *pMmsMsg, char **pDestMsg)
694 {
695         if (mPlgHandler.pfGetMmsMessage != NULL) {
696                 return mPlgHandler.pfGetMmsMessage(pMsg, pSendOptInfo, pMmsMsg, pDestMsg);
697         } else {
698                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
699         }
700 }
701
702
703 msg_error_t MsgPlugin::updateRejectStatus(MSG_MESSAGE_INFO_S *pMsgInfo)
704 {
705         if (mPlgHandler.pfUpdateRejectStatus != NULL) {
706                 return mPlgHandler.pfUpdateRejectStatus(pMsgInfo);
707         } else {
708                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
709         }
710 }
711
712
713 msg_error_t MsgPlugin::composeReadReport(MSG_MESSAGE_INFO_S *pMsgInfo)
714 {
715         if (mPlgHandler.pfComposeReadReport != NULL) {
716                 return mPlgHandler.pfComposeReadReport(pMsgInfo);
717         } else {
718                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
719         }
720 }
721
722
723 msg_error_t MsgPlugin::restoreMsg(MSG_MESSAGE_INFO_S *pMsgInfo, char* pRecvBody, int rcvdBodyLen, char* filePath)
724 {
725         if (mPlgHandler.pfRestoreMsg != NULL)
726                 return mPlgHandler.pfRestoreMsg(pMsgInfo,pRecvBody, rcvdBodyLen, filePath);
727         else
728                 return MSG_ERR_INVALID_PLUGIN_HANDLE;
729 }
730
731
732 /*==================================================================================================
733                                      IMPLEMENTATION OF MsgPluginManager - Member Functions
734 ==================================================================================================*/
735 MsgPluginManager* MsgPluginManager::pInstance = NULL;
736
737
738 MsgPluginManager* MsgPluginManager::instance()
739 {
740         if (pInstance == NULL)
741                 pInstance = new MsgPluginManager();
742
743         return pInstance;
744 }
745
746
747 MsgPluginManager::MsgPluginManager()
748 {
749
750 }
751
752
753 void MsgPluginManager::initialize()
754 {
755         char path[64];
756
757         memset(path, 0x00, sizeof(path));
758         snprintf(path, sizeof(path), "%s%s", MSG_PLUGIN_CFG_PATH, MSG_PLUGIN_CFG_NAME);
759
760         loadPlugins(path);
761 }
762
763
764 void MsgPluginManager::finalize()
765 {
766         MsgPluginMap::iterator it;
767
768         for (it = plgMap.begin(); it != plgMap.end(); it++)
769         {
770                 MsgPlugin *temp = it->second;
771                 delete temp;
772         }
773
774         plgMap.clear();
775 }
776
777
778 void MsgPluginManager::loadPlugins(const char* path)
779 {
780         /* read plugins from configuration file */
781         FILE* fp = MsgOpenFile(path, "rt");
782
783         MsgPlgConfig plgConf = MsgPlgConfig(fp);
784
785         for (int i=0; i < plgConf.titleCount(); i++)
786         {
787                 MsgPlgToken tok;
788
789                 plgConf.token(i, 0, tok);
790                 const char* content = tok.getVal();
791
792                 MSG_MAIN_TYPE_T mainType = strstr(content,"sms")? MSG_SMS_TYPE:
793                                                         (strstr(content,"mms")? MSG_MMS_TYPE: MSG_UNKNOWN_TYPE);
794
795                 plgConf.token(i, 1, tok);
796                 const char* libPath = tok.getVal();
797
798                 MsgPlugin* pDupPlgCheck = getPlugin(mainType);
799
800                 if (pDupPlgCheck)
801                         THROW(MsgException::PLUGIN_ERROR, "Plugin for type %d is duplicated", mainType);
802
803                 MsgPlugin *newPlg = new MsgPlugin(mainType, libPath);
804
805                 plgMap.insert(make_pair(mainType, newPlg));
806         }
807
808         MsgCloseFile(fp);
809 }
810
811
812 MsgPlugin* MsgPluginManager::getPlugin(MSG_MAIN_TYPE_T mainType)
813 {
814         /* Implementing the content */
815         MsgPluginMap::iterator it = plgMap.find(mainType);
816
817         if (it == plgMap.end())
818                 return NULL;
819
820         return it->second;
821 }
822