RSA sync with private
[platform/core/messaging/msg-service.git] / plugin / sms_plugin / SmsPluginStorage.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 <errno.h>
18
19 #include "MsgDebug.h"
20 #include "MsgCppTypes.h"
21 #include "MsgException.h"
22 #include "MsgContact.h"
23 #include "MsgUtilFile.h"
24 #include "MsgUtilStorage.h"
25 #include "MsgGconfWrapper.h"
26 #include "MsgNotificationWrapper.h"
27 #include "SmsPluginMain.h"
28 #include "SmsPluginSimMsg.h"
29 #include "SmsPluginStorage.h"
30
31
32 /*==================================================================================================
33                                      IMPLEMENTATION OF SmsPluginStorage - Member Functions
34 ==================================================================================================*/
35 SmsPluginStorage* SmsPluginStorage::pInstance = NULL;
36
37
38 SmsPluginStorage::SmsPluginStorage()
39 {
40 /*** No need to connect DB anymore.
41         if (dbHandle.connect() != MSG_SUCCESS) {
42                 MSG_DEBUG("DB Connect Fail");
43         }
44 ***/
45 }
46
47
48 SmsPluginStorage::~SmsPluginStorage()
49 {
50         if (dbHandle.disconnect() != MSG_SUCCESS) {
51                 MSG_DEBUG("DB Disconnect Fail");
52         }
53 }
54
55
56 SmsPluginStorage* SmsPluginStorage::instance()
57 {
58         if (!pInstance) {
59                 MSG_DEBUG("pInstance is NULL. Now creating instance.");
60                 pInstance = new SmsPluginStorage();
61         }
62
63         return pInstance;
64 }
65
66
67 msg_error_t SmsPluginStorage::updateSentMsg(MSG_MESSAGE_INFO_S *pMsgInfo, msg_network_status_t status)
68 {
69         MSG_BEGIN();
70
71 /***  Comment below line to not save the time value after sent status (it could be used later.)
72         time_t curTime = time(NULL);
73 ***/
74         char sqlQuery[MAX_QUERY_LEN+1];
75
76         memset(sqlQuery, 0x00, sizeof(sqlQuery));
77
78         MSG_DEBUG("Update Msg ID : [%d], Network Status : [%d] ", pMsgInfo->msgId, status);
79
80         /** Move Msg to SENTBOX */
81         if (status == MSG_NETWORK_SEND_SUCCESS) {
82                 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET NETWORK_STATUS = %d, FOLDER_ID = %d WHERE MSG_ID = %d;",
83                                         MSGFW_MESSAGE_TABLE_NAME, status, MSG_SENTBOX_ID, pMsgInfo->msgId);
84         } else {
85                 snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET NETWORK_STATUS = %d WHERE MSG_ID = %d;",
86                                         MSGFW_MESSAGE_TABLE_NAME, status, pMsgInfo->msgId);
87         }
88
89         if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
90                 MSG_DEBUG("MsgExecQuery() : [%s]", sqlQuery);
91                 return MSG_ERR_DB_EXEC;
92         }
93
94         if (status == MSG_NETWORK_SEND_SUCCESS) {
95                 MSG_DEBUG("MsgAddPhoneLog() : folderId [%d]", pMsgInfo->folderId);
96                 MsgAddPhoneLog(pMsgInfo);
97         }
98
99
100         MSG_END();
101
102         return MSG_SUCCESS;
103 }
104
105 #ifdef SMS_REPORT_OPERATION
106 msg_error_t SmsPluginStorage::updateMsgRef(msg_message_id_t MsgId, unsigned char MsgRef)
107 {
108         MSG_BEGIN();
109
110         char sqlQuery[MAX_QUERY_LEN+1];
111
112         memset(sqlQuery, 0x00, sizeof(sqlQuery));
113
114         snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MSG_REF = %d WHERE MSG_ID = %d;",
115                                 MSGFW_REPORT_TABLE_NAME, (int)MsgRef, MsgId);
116
117         if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
118                 MSG_DEBUG("Query Failed : [%s]", sqlQuery);
119                 return MSG_ERR_DB_EXEC;
120         }
121
122         /** Set Message Reference for updating report table */
123         tmpMsgRef = MsgRef;
124
125         MSG_DEBUG("MsgRef : %d", MsgRef);
126
127         MSG_END();
128
129         return MSG_SUCCESS;
130 }
131
132
133 msg_error_t SmsPluginStorage::updateStatusReport(unsigned char MsgRef, msg_delivery_report_status_t Status, time_t DeliveryTime)
134 {
135         MSG_BEGIN();
136
137         MSG_DEBUG("tmpMsgRef : %d", tmpMsgRef);
138
139         char sqlQuery[MAX_QUERY_LEN+1];
140
141         /** Get Msg Id for Quickpanel Noti */
142         msg_message_id_t msgId = 0;
143
144         memset(sqlQuery, 0x00, sizeof(sqlQuery));
145         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE MSG_REF = %d;",
146                                         MSGFW_REPORT_TABLE_NAME, (int)tmpMsgRef);
147
148         if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
149                 return MSG_ERR_DB_PREPARE;
150
151         if (dbHandle.stepQuery() == MSG_ERR_DB_ROW)
152                 msgId = dbHandle.columnInt(0);
153
154         dbHandle.finalizeQuery();
155
156         /** Update Status */
157         memset(sqlQuery, 0x00, sizeof(sqlQuery));
158         snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET MSG_REF = -1, DELIVERY_REPORT_STATUS = %d, DELIVERY_REPORT_TIME = %lu WHERE MSG_REF = %d;",
159                                         MSGFW_REPORT_TABLE_NAME, Status, DeliveryTime, (int)tmpMsgRef);
160
161         if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
162                 MSG_DEBUG("Query Failed : [%s]", sqlQuery);
163                 return MSG_ERR_DB_EXEC;
164         }
165
166         /** Insert Quickpanel Noti */
167         msg_error_t ret = MSG_SUCCESS;
168
169         ret = MsgInsertSmsNotiToQuickpanel(&dbHandle, msgId, Status);
170
171         if (ret != MSG_SUCCESS) {
172                 MSG_DEBUG("MsgInsertSmsNotiToQuickpanel() Failed : [%d]", ret);
173                 return ret;
174         }
175
176         MSG_END();
177
178         return MSG_SUCCESS;
179 }
180 #endif
181
182 msg_error_t SmsPluginStorage::addSimMessage(MSG_MESSAGE_INFO_S *pSimMsgInfo)
183 {
184         msg_error_t err = MSG_SUCCESS;
185
186         msg_message_id_t msgId = 0;
187         msg_thread_id_t convId = 0;
188         unsigned int simId = 0;
189
190         char sqlQuery[MAX_QUERY_LEN+1];
191
192         dbHandle.beginTrans();
193
194         err = MsgStoAddAddress(&dbHandle, pSimMsgInfo, &convId);
195
196         if (err != MSG_SUCCESS) {
197                 dbHandle.endTrans(false);
198                 return err;
199         }
200
201         pSimMsgInfo->threadId = convId;
202
203         err = dbHandle.getRowId(MSGFW_MESSAGE_TABLE_NAME, &msgId);
204
205         if (err != MSG_SUCCESS) {
206                 dbHandle.endTrans(false);
207                 return err;
208         }
209
210         simId = pSimMsgInfo->msgId;
211         pSimMsgInfo->msgId = msgId;
212
213         SMS_CONCAT_SIM_MSG_S concatSimMsg = {0};
214
215         /** Get Data from Concat SIM Msg */
216         if (pSimMsgInfo->msgType.subType == MSG_CONCAT_SIM_SMS && pSimMsgInfo->bTextSms == false) {
217
218                 int fileSize = 0;
219
220                 char* pFileData = NULL;
221                 AutoPtr<char> buf(&pFileData);
222
223                 if (MsgOpenAndReadFile(pSimMsgInfo->msgData, &pFileData, &fileSize) == false) {
224                         dbHandle.endTrans(false);
225                         return MSG_ERR_STORAGE_ERROR;
226                 }
227
228
229                 memcpy(&concatSimMsg, (SMS_CONCAT_SIM_MSG_S*)pFileData, fileSize);
230
231                 /** Delete temporary file */
232                 MsgDeleteFile(pSimMsgInfo->msgData); /** ipc */
233
234                 MSG_DEBUG("SIM ID [%d], MSG DATA [%s]", concatSimMsg.simIdCnt, concatSimMsg.msgData);
235         }
236
237         /**  Add Message */
238         memset(sqlQuery, 0x00, sizeof(sqlQuery));
239
240         snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, %d, %d, %ld, %d, %d, %d, %d, %d, %d, %ld, %d, ?, '', '', ?, 0, 0, 0);",
241                         MSGFW_MESSAGE_TABLE_NAME, msgId, convId, pSimMsgInfo->folderId, pSimMsgInfo->storageId,
242                         pSimMsgInfo->msgType.mainType, pSimMsgInfo->msgType.subType, pSimMsgInfo->displayTime, pSimMsgInfo->dataSize,
243                         pSimMsgInfo->networkStatus, pSimMsgInfo->bRead, pSimMsgInfo->bProtected, pSimMsgInfo->priority,
244                         pSimMsgInfo->direction, 0, pSimMsgInfo->bBackup);
245
246         MSG_DEBUG("QUERY : %s", sqlQuery);
247
248         if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
249                 dbHandle.endTrans(false);
250                 return MSG_ERR_DB_PREPARE;
251         }
252
253         dbHandle.bindText(pSimMsgInfo->subject, 1);
254
255         if (pSimMsgInfo->msgType.subType == MSG_CONCAT_SIM_SMS && pSimMsgInfo->bTextSms == false)
256                 dbHandle.bindText(concatSimMsg.msgData, 2);
257         else
258                 dbHandle.bindText(pSimMsgInfo->msgText, 2);
259
260         if (dbHandle.stepQuery() != MSG_ERR_DB_DONE) {
261                 dbHandle.endTrans(false);
262                 return MSG_ERR_DB_STEP;
263         }
264
265         dbHandle.finalizeQuery();
266
267         /** Insert to Sim table */
268         if (pSimMsgInfo->msgType.subType == MSG_CONCAT_SIM_SMS && pSimMsgInfo->bTextSms == false) {
269
270                 MSG_DEBUG("sim count : %d", concatSimMsg.simIdCnt);
271
272                 for (unsigned int i = 0; i < concatSimMsg.simIdCnt; i++) {
273                         memset(sqlQuery, 0x00, sizeof(sqlQuery));
274                         snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d);",
275                                         MSGFW_SIM_MSG_TABLE_NAME, msgId, concatSimMsg.simIdList[i]);
276
277                         MSG_DEBUG("QUERY : %s", sqlQuery);
278
279                         if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
280                                 dbHandle.endTrans(false);
281                                 return MSG_ERR_DB_EXEC;
282                         }
283                 }
284         } else {
285                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
286                 snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d);",
287                                 MSGFW_SIM_MSG_TABLE_NAME, msgId, simId);
288
289                 MSG_DEBUG("QUERY : %s", sqlQuery);
290
291                 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
292                         dbHandle.endTrans(false);
293                         return MSG_ERR_DB_EXEC;
294                 }
295         }
296
297         /**  Update conversation table. */
298         if (MsgStoUpdateConversation(&dbHandle, convId) != MSG_SUCCESS) {
299                 dbHandle.endTrans(false);
300                 return MSG_ERR_STORAGE_ERROR;
301         }
302
303         dbHandle.endTrans(true);
304
305         return err;
306 }
307
308
309 msg_error_t SmsPluginStorage::addMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
310 {
311         MSG_BEGIN();
312
313         msg_error_t err = MSG_SUCCESS;
314
315         /**  Check whether storage is full or not */
316         err = checkStorageStatus(pMsgInfo);
317
318         if (err != MSG_SUCCESS) {
319                 if (pMsgInfo->msgType.classType == MSG_CLASS_0) {
320                         pMsgInfo->folderId = 0;
321                         if (addSmsMessage(pMsgInfo) != MSG_SUCCESS) {
322                                 MSG_DEBUG("addSmsMessage is failed!");
323                         }
324                 }
325                 return err;
326         }
327
328         if (pMsgInfo->msgType.subType == MSG_NORMAL_SMS || pMsgInfo->msgType.subType == MSG_REJECT_SMS) {
329
330                 MSG_DEBUG("Add Normal SMS");
331
332                 if (pMsgInfo->msgType.classType == MSG_CLASS_2) {
333                         err = SmsPluginSimMsg::instance()->saveClass2Message(pMsgInfo);
334
335                         if (err == MSG_SUCCESS) {
336                                 MSG_DEBUG("Success to saveSimMessage.");
337                         } else {
338                                 MSG_DEBUG("Fail to saveSimMessage : [%d]", err);
339                         }
340                 } else {
341                         /** Class 0 Msg should be saved in hidden folder */
342                         if (pMsgInfo->msgType.classType == MSG_CLASS_0) {
343                                 pMsgInfo->folderId = 0;
344                         }
345
346                         /**  Add into DB */
347                         err = addSmsMessage(pMsgInfo);
348                 }
349
350         } else if ((pMsgInfo->msgType.subType == MSG_CB_SMS) || (pMsgInfo->msgType.subType == MSG_JAVACB_SMS)) {
351                 /** check add message option */
352                 bool bSave = false;
353                 MsgSettingGetBool(CB_SAVE, &bSave);
354                 if(bSave) {
355                         MSG_DEBUG("Add CB Message");
356                         err = addCbMessage(pMsgInfo);
357                 }
358         } else if ((pMsgInfo->msgType.subType >= MSG_REPLACE_TYPE1_SMS) && (pMsgInfo->msgType.subType <= MSG_REPLACE_TYPE7_SMS)) {
359                 MSG_DEBUG("Add Replace SM Type [%d]", pMsgInfo->msgType.subType-3);
360                 err = addReplaceTypeMsg(pMsgInfo);
361         } else if ((pMsgInfo->msgType.subType >= MSG_MWI_VOICE_SMS) && (pMsgInfo->msgType.subType <= MSG_MWI_OTHER_SMS)) {
362                 if (pMsgInfo->bStore == true) {
363                         MSG_DEBUG("Add MWI Message");
364                         err = addSmsMessage(pMsgInfo);
365                 }
366         } else if ((pMsgInfo->msgType.subType == MSG_WAP_SI_SMS) || (pMsgInfo->msgType.subType == MSG_WAP_CO_SMS)) {
367                 MSG_DEBUG("Add WAP Push Message");
368                 switch (pMsgInfo->msgType.subType)
369                 {
370                         case MSG_WAP_SI_SMS:
371                         {
372                                 // save push message information
373                                 err = addWAPMessage(pMsgInfo);
374                         }
375                         break;
376
377                         case MSG_WAP_CO_SMS:
378                         {
379                                 err = handleCOWAPMessage(pMsgInfo);
380                         }
381                         break;
382                 }
383         } else if (pMsgInfo->msgType.subType == MSG_STATUS_REPORT_SMS) {
384                 MSG_DEBUG("Add Status Report");
385                 err = addSmsMessage(pMsgInfo);
386         }
387
388         if (err == MSG_SUCCESS) {
389                 MSG_DEBUG("Success to add message !!");
390         } else {
391                 MSG_DEBUG("fail to add message !! : [%d]", err);
392         }
393
394         return err;
395 }
396
397
398 msg_error_t SmsPluginStorage::addSmsMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
399 {
400         msg_error_t err = MSG_SUCCESS;
401
402         unsigned int rowId = 0;
403         msg_thread_id_t convId = 0;
404
405         dbHandle.beginTrans();
406
407         if (pMsgInfo->nAddressCnt > 0) {
408
409                 err = MsgStoAddAddress(&dbHandle, pMsgInfo, &convId);
410
411                 if (err != MSG_SUCCESS) {
412                         dbHandle.endTrans(false);
413                         return err;
414                 }
415
416                 pMsgInfo->threadId = convId;
417         }
418
419         /**  Add Message Table */
420         rowId = MsgStoAddMessageTable(&dbHandle, pMsgInfo);
421
422         if (rowId <= 0) {
423                 dbHandle.endTrans(false);
424                 return MSG_ERR_DB_ROW;
425         }
426
427         /** Update conversation table */
428         err = MsgStoUpdateConversation(&dbHandle, convId);
429
430         if (err != MSG_SUCCESS) {
431                 dbHandle.endTrans(false);
432                 return err;
433         }
434
435         dbHandle.endTrans(true);
436
437         pMsgInfo->msgId = (msg_message_id_t)rowId;
438
439         MSG_END();
440
441         return MSG_SUCCESS;
442 }
443
444
445 msg_error_t SmsPluginStorage::updateSmsMessage(MSG_MESSAGE_INFO_S *pMsg)
446 {
447         msg_error_t err = MSG_SUCCESS;
448
449         char sqlQuery[MAX_QUERY_LEN+1];
450
451         msg_thread_id_t convId = 0;
452
453         dbHandle.beginTrans();
454
455         if (pMsg->nAddressCnt > 0) {
456
457                 err = MsgStoAddAddress(&dbHandle, pMsg, &convId);
458
459                 if (err != MSG_SUCCESS) {
460                         dbHandle.endTrans(false);
461                         return err;
462                 }
463         }
464
465         int fileSize = 0;
466
467         char* pFileData = NULL;
468         AutoPtr<char> buf(&pFileData);
469
470         /**  Get File Data */
471         if (pMsg->bTextSms == false) {
472                 if (MsgOpenAndReadFile(pMsg->msgData, &pFileData, &fileSize) == false) {
473                         dbHandle.endTrans(false);
474                         return MSG_ERR_STORAGE_ERROR;
475                 }
476         }
477
478         /**  Update Message */
479         memset(sqlQuery, 0x00, sizeof(sqlQuery));
480
481         snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET CONV_ID = %d, FOLDER_ID = %d, STORAGE_ID = %d, MAIN_TYPE = %d, SUB_TYPE = %d, \
482                         DISPLAY_TIME = %lu, DATA_SIZE = %d, NETWORK_STATUS = %d, READ_STATUS = %d, PROTECTED = %d, PRIORITY = %d, MSG_DIRECTION = %d, \
483                         BACKUP = %d, SUBJECT = ?, MSG_DATA = ?, THUMB_PATH = ?, MSG_TEXT = ? WHERE MSG_ID = %d;",
484                                 MSGFW_MESSAGE_TABLE_NAME, convId, pMsg->folderId, pMsg->storageId, pMsg->msgType.mainType, pMsg->msgType.subType, pMsg->displayTime, pMsg->dataSize,
485                                 pMsg->networkStatus, pMsg->bRead, pMsg->bProtected, pMsg->priority, pMsg->direction, pMsg->bBackup, pMsg->msgId);
486
487         if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
488                 dbHandle.endTrans(false);
489                 return MSG_ERR_DB_EXEC;
490         }
491
492         dbHandle.bindText(pMsg->subject, 1);
493
494         dbHandle.bindText(pMsg->msgData, 2);
495
496         dbHandle.bindText(pMsg->thumbPath, 3);
497
498         if (pMsg->msgType.mainType == MSG_SMS_TYPE && pMsg->bTextSms == false)
499                 dbHandle.bindText(pFileData, 4);
500         else
501                 dbHandle.bindText(pMsg->msgText, 4);
502
503         MSG_DEBUG("%s", sqlQuery);
504
505         if (dbHandle.stepQuery() != MSG_ERR_DB_DONE) {
506                 dbHandle.endTrans(false);
507                 return MSG_ERR_DB_EXEC;
508         }
509
510         dbHandle.finalizeQuery();
511
512         err = MsgStoUpdateConversation(&dbHandle, convId);
513
514         if (err != MSG_SUCCESS) {
515                 dbHandle.endTrans(false);
516                 return MSG_ERR_STORAGE_ERROR;
517         }
518
519         err = MsgStoClearConversationTable(&dbHandle);
520
521         if (err != MSG_SUCCESS) {
522                 dbHandle.endTrans(false);
523                 return MSG_ERR_STORAGE_ERROR;
524         }
525
526         dbHandle.endTrans(true);
527
528         return MSG_SUCCESS;
529 }
530
531
532 msg_error_t SmsPluginStorage::deleteSmsMessage(msg_message_id_t msgId)
533 {
534         MSG_BEGIN();
535
536         char sqlQuery[MAX_QUERY_LEN+1];
537
538          /**  Get SUB_TYPE, STORAGE_ID */
539         memset(sqlQuery, 0x00, sizeof(sqlQuery));
540         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MAIN_TYPE, SUB_TYPE, FOLDER_ID, ADDRESS_ID \
541                         FROM %s WHERE MSG_ID = %d;",
542                         MSGFW_MESSAGE_TABLE_NAME, msgId);
543
544         if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
545                 return MSG_ERR_DB_PREPARE;
546
547         MSG_MESSAGE_TYPE_S msgType;
548         msg_folder_id_t folderId;
549
550         msg_thread_id_t convId;
551
552         if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
553                 msgType.mainType = dbHandle.columnInt(0);
554                 msgType.subType = dbHandle.columnInt(1);
555                 folderId = dbHandle.columnInt(2);
556                 convId = dbHandle.columnInt(3);
557
558                 MSG_DEBUG("Main Type:[%d] SubType:[%d] FolderId:[%d] ConversationId:[%d]", msgType.mainType, msgType.subType, folderId, convId);
559         } else {
560                 MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
561                 dbHandle.finalizeQuery();
562                 return MSG_ERR_DB_STEP;
563         }
564
565         dbHandle.finalizeQuery();
566
567         dbHandle.beginTrans();
568
569         memset(sqlQuery, 0x00, sizeof(sqlQuery));
570         snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_SMS_SENDOPT_TABLE_NAME, msgId);
571
572         /**  Delete SMS Send Option */
573         if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
574                 dbHandle.endTrans(false);
575                 return MSG_ERR_DB_EXEC;
576         }
577
578         if (msgType.subType == MSG_CB_SMS || msgType.subType == MSG_JAVACB_SMS) {
579                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
580                 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_CB_MSG_TABLE_NAME, msgId);
581
582                 /** Delete Push Message from push table */
583                 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
584                         dbHandle.endTrans(false);
585                         return MSG_ERR_DB_EXEC;
586                 }
587         } else if (msgType.subType >= MSG_WAP_SI_SMS && msgType.subType <= MSG_WAP_CO_SMS) {
588                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
589                 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_PUSH_MSG_TABLE_NAME, msgId);
590
591                 /**  Delete Push Message from push table */
592                 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
593                         dbHandle.endTrans(false);
594                         return MSG_ERR_DB_EXEC;
595                 }
596         } else if (msgType.subType == MSG_SYNCML_CP) {
597                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
598                 snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_SYNCML_MSG_TABLE_NAME, msgId);
599
600                 /**  Delete SyncML Message from syncML table */
601                 if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
602                         dbHandle.endTrans(false);
603                         return MSG_ERR_DB_EXEC;
604                 }
605         }
606
607         memset(sqlQuery, 0x00, sizeof(sqlQuery));
608         snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgId);
609
610         /** Delete Message from msg table */
611         if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
612                 dbHandle.endTrans(false);
613                 return MSG_ERR_DB_EXEC;
614         }
615
616         /**  Clear Conversation table */
617         if (MsgStoClearConversationTable(&dbHandle) != MSG_SUCCESS) {
618                 dbHandle.endTrans(false);
619                 return MSG_ERR_DB_EXEC;
620         }
621
622         /**  Update conversation table.*/
623         if (MsgStoUpdateConversation(&dbHandle, convId) != MSG_SUCCESS) {
624                 dbHandle.endTrans(false);
625                 return MSG_ERR_STORAGE_ERROR;
626         }
627
628         dbHandle.endTrans(true);
629
630         if (folderId == MSG_INBOX_ID) {
631                 msgType.classType = MSG_CLASS_NONE;
632
633                 /**  Set memory status in SIM */
634                 if (MsgStoCheckMsgCntFull(&dbHandle, &msgType, folderId) == MSG_SUCCESS) {
635                         MSG_DEBUG("Set Memory Status");
636                         SmsPlgSetMemoryStatus(MSG_SUCCESS);
637                 }
638         }
639
640         int smsCnt = 0, mmsCnt = 0;
641
642         smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
643         mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
644
645         MsgSettingHandleNewMsg(smsCnt, mmsCnt);
646 //      MsgDeleteNotiByMsgId(msgId);
647         MsgRefreshNoti();
648
649         return MSG_SUCCESS;
650 }
651
652
653 msg_error_t SmsPluginStorage::addCbMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
654 {
655         msg_error_t err = MSG_SUCCESS;
656
657         unsigned int rowId = 0;
658         msg_thread_id_t convId = 0;
659
660         char sqlQuery[MAX_QUERY_LEN+1];
661
662         dbHandle.beginTrans();
663
664         if (pMsgInfo->nAddressCnt > 0) {
665                 err = MsgStoAddAddress(&dbHandle, pMsgInfo, &convId);
666
667                 if (err != MSG_SUCCESS) {
668                         dbHandle.endTrans(false);
669                         return err;
670                 }
671
672                 pMsgInfo->threadId = convId;
673         }
674
675         /**  Add Message Table */
676         rowId = MsgStoAddMessageTable(&dbHandle, pMsgInfo);
677
678         if (rowId <= 0) {
679                 dbHandle.endTrans(false);
680                 return MSG_ERR_DB_ROW;
681         }
682
683         /**  Get CB Msg ID */
684         unsigned short cbMsgId = (unsigned short)pMsgInfo->msgId;
685
686         /** Add CB Msg in MSG_CBMSG_TABLE */
687         memset(sqlQuery, 0x00, sizeof(sqlQuery));
688
689         sprintf(sqlQuery, "INSERT INTO %s VALUES (%d, %d);",
690                         MSGFW_CB_MSG_TABLE_NAME, rowId, cbMsgId);
691
692         if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
693                 dbHandle.endTrans(false);
694                 return MSG_ERR_DB_EXEC;
695         }
696
697         /**  Update conversation table. */
698         if (MsgStoUpdateConversation(&dbHandle, convId) != MSG_SUCCESS) {
699                 dbHandle.endTrans(false);
700                 return MSG_ERR_STORAGE_ERROR;
701         }
702
703         dbHandle.endTrans(true);
704
705         /** Assign Msg ID */
706         pMsgInfo->msgId = (msg_message_id_t)rowId;
707
708         return err;
709 }
710
711
712 msg_error_t SmsPluginStorage::addReplaceTypeMsg(MSG_MESSAGE_INFO_S *pMsgInfo)
713 {
714         msg_error_t err = MSG_SUCCESS;
715
716         char sqlQuery[MAX_QUERY_LEN+1];
717
718         unsigned int retCnt = 0;
719         msg_thread_id_t convId = 0;
720
721         /** Check if new address or not */
722         if (MsgExistAddress(&dbHandle, pMsgInfo, &convId) == true) {
723                 MSG_DEBUG("Address Info. exists [%d]", convId);
724
725                 /**  Find Replace Type Msg : Same Replace Type, Same Origin Address */
726                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
727                 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT COUNT(*), MSG_ID FROM %s WHERE SUB_TYPE = %d AND CONV_ID = %d;",
728                                 MSGFW_MESSAGE_TABLE_NAME, pMsgInfo->msgType.subType, convId);
729
730                 if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
731                         return MSG_ERR_DB_PREPARE;
732
733                 if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
734                         retCnt = dbHandle.columnInt(0);
735                         pMsgInfo->msgId = dbHandle.columnInt(1);
736                 } else {
737                         dbHandle.finalizeQuery();
738                         return MSG_ERR_DB_STEP;
739                 }
740
741                 dbHandle.finalizeQuery();
742         }
743
744         /** Update New Replace Type Msg */
745         if (retCnt == 0) { /** Insert New Replace Type Msg */
746                 MSG_DEBUG("Insert Replace Type Msg");
747                 err = addSmsMessage(pMsgInfo);
748         } else {
749                 MSG_DEBUG("Update Replace Type Msg");
750                 err = updateSmsMessage(pMsgInfo);
751         }
752
753         return err;
754 }
755
756
757 msg_error_t SmsPluginStorage::addWAPMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
758 {
759         msg_error_t err = MSG_SUCCESS;
760
761         MSG_PUSH_MESSAGE_S pushMsg = {};
762
763         char sqlQuery[MAX_QUERY_LEN+1];
764         memset(sqlQuery, 0x00, sizeof(sqlQuery));
765
766         int fileSize = 0;
767
768         char* pFileData = NULL;
769         AutoPtr<char> buf(&pFileData);
770
771         if (MsgOpenAndReadFile(pMsgInfo->msgData, &pFileData, &fileSize) == false)
772                 return MSG_ERR_STORAGE_ERROR;
773
774         MSG_DEBUG("fileSize : %d", fileSize);
775
776         memcpy(&pushMsg, pFileData, fileSize);
777
778         /** Delete temporary file */
779         MsgDeleteFile(pMsgInfo->msgData);
780
781         /** check pPushMsg data */
782
783         MSG_DEBUG("check pushMsg data");
784         MSG_DEBUG("pushMsg.action : [%d]", pushMsg.action);
785         MSG_DEBUG("pushMsg.received : [%d]", pushMsg.received);
786         MSG_DEBUG("pushMsg.created : [%d]", pushMsg.created);
787         MSG_DEBUG("pushMsg.expires : [%d]", pushMsg.expires);
788         MSG_DEBUG("pushMsg.id : [%s]", pushMsg.id);
789         MSG_DEBUG("pushMsg.href : [%s]", pushMsg.href);
790         MSG_DEBUG("pushMsg.contents : [%s]", pushMsg.contents);
791
792         bool bProceed = true;
793
794         /**  check validation of contents */
795         if (checkPushMsgValidation(&pushMsg, &bProceed) != MSG_SUCCESS) {
796                 MSG_DEBUG("Fail to check Push Message validation.");
797         }
798
799         /**  if validation check value is false */
800         /** return and drop message. */
801         if (bProceed == false)
802                 return MSG_ERR_INVALID_MESSAGE;
803
804 #if 0
805         /**  update subject */
806         int len = strlen(pushMsg.contents);
807
808         if (len > MAX_SUBJECT_LEN) {
809                 memcpy(pMsgInfo->subject, pushMsg.contents, MAX_SUBJECT_LEN);
810                 pMsgInfo->subject[MAX_SUBJECT_LEN] = '\0';
811         } else {
812                 strncpy(pMsgInfo->subject, pushMsg.contents, MAX_SUBJECT_LEN);
813         }
814 #endif
815
816         /**  Update Msg Text - remove */
817         strncpy(pMsgInfo->msgText, pushMsg.href, MAX_MSG_TEXT_LEN);
818
819         if (pushMsg.contents[0] != '\0') {
820                 strncat(pMsgInfo->msgText, " ", MAX_MSG_TEXT_LEN - strlen(pMsgInfo->msgText));
821                 strncat(pMsgInfo->msgText, pushMsg.contents, MAX_MSG_TEXT_LEN - strlen(pMsgInfo->msgText));
822         }
823
824         pMsgInfo->dataSize = strlen(pMsgInfo->msgText);
825
826         pMsgInfo->bTextSms = true;
827         pMsgInfo->folderId = MSG_INBOX_ID;
828         pMsgInfo->storageId = MSG_STORAGE_PHONE;
829
830         msg_thread_id_t convId = 0;
831
832         dbHandle.beginTrans();
833
834         if (pMsgInfo->nAddressCnt > 0) {
835
836                 err = MsgStoAddAddress(&dbHandle, pMsgInfo, &convId);
837
838                 if (err != MSG_SUCCESS) {
839                         dbHandle.endTrans(false);
840                         return err;
841                 }
842
843                 pMsgInfo->threadId = convId;
844         }
845
846         /**  get last row count for Message id */
847         unsigned int rowId = 0;
848
849         /** Add Message Table */
850         rowId = MsgStoAddMessageTable(&dbHandle, pMsgInfo);
851
852         if (rowId <= 0) {
853                 dbHandle.endTrans(false);
854                 return MSG_ERR_DB_ROW;
855         }
856
857         /**  add msg_push_table */
858         snprintf (sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %lu, %lu, ?, ?, ?)",
859                         MSGFW_PUSH_MSG_TABLE_NAME, pMsgInfo->msgId, pushMsg.action, pushMsg.created, pushMsg.expires);
860
861         if ((err = dbHandle.prepareQuery(sqlQuery)) != MSG_SUCCESS) {
862                 dbHandle.endTrans(false);
863                 return err;
864         }
865
866         dbHandle.bindText(pushMsg.id, 1);
867
868         dbHandle.bindText(pushMsg.href, 2);
869
870         dbHandle.bindText(pushMsg.contents, 3);
871
872         if ((err = dbHandle.stepQuery()) != MSG_ERR_DB_DONE) {
873                 dbHandle.endTrans(false);
874                 return err;
875         }
876
877         /** Update conversation table. */
878         if (MsgStoUpdateConversation(&dbHandle, convId) != MSG_SUCCESS) {
879                 dbHandle.endTrans(false);
880                 return MSG_ERR_STORAGE_ERROR;
881         }
882
883         dbHandle.endTrans(true);
884
885         pMsgInfo->msgId = (msg_message_id_t)rowId;
886
887         return MSG_SUCCESS;
888 }
889
890
891 msg_error_t SmsPluginStorage::handleCOWAPMessage(MSG_MESSAGE_INFO_S *pMsgInfo)
892 {
893         msg_error_t err = MSG_SUCCESS;
894
895         char href[MAX_PUSH_CACHEOP_MAX_URL_LEN+1];
896         char sqlQuery[MAX_QUERY_LEN+1];
897
898         int fileSize = 0;
899
900         char* pFileData = NULL;
901         AutoPtr<char> buf(&pFileData);
902
903         if (MsgOpenAndReadFile(pMsgInfo->msgData, &pFileData, &fileSize) == false)
904                 return MSG_ERR_STORAGE_ERROR;
905
906         MSG_PUSH_CACHEOP_S *pPushMsg;
907
908         pPushMsg = (MSG_PUSH_CACHEOP_S*)pFileData;
909
910         for (int i = 0; i < pPushMsg->invalObjectCnt; i++) {
911
912                 int msgid = -1;
913
914                 memset(href, 0x00, sizeof(href));
915                 strncpy(href, &(pPushMsg->invalObjectUrl[i][0]), MAX_PUSH_CACHEOP_MAX_URL_LEN);
916
917                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
918                 snprintf (sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE HREF LIKE '%%%s%%';", MSGFW_PUSH_MSG_TABLE_NAME, href);
919
920                 dbHandle.beginTrans();
921
922                 err = dbHandle.prepareQuery(sqlQuery);
923
924                 if ((dbHandle.stepQuery() == MSG_ERR_DB_ROW) && err == MSG_SUCCESS) {
925
926                         msgid = dbHandle.getColumnToInt(1);
927
928                         memset(sqlQuery, 0x00, sizeof(sqlQuery));
929                         snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID= %d;", MSGFW_PUSH_MSG_TABLE_NAME, msgid);
930
931                         /** Delete Message from Push table */
932                         if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
933                                 dbHandle.finalizeQuery();
934                                 dbHandle.endTrans(false);
935                                 continue;
936                         }
937
938                         memset(sqlQuery, 0x00, sizeof(sqlQuery));
939                         snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgid);
940
941                         /** Delete Message from msg table */
942                         if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
943                                 dbHandle.finalizeQuery();
944                                 dbHandle.endTrans(false);
945                                 continue;
946                         }
947
948                         /** Update all Address */
949                         if (updateAllAddress() != MSG_SUCCESS) {
950                                 dbHandle.finalizeQuery();
951                                 dbHandle.endTrans(false);
952                                 continue;
953                         }
954
955                         /** Clear Conversation table */
956                         if (MsgStoClearConversationTable(&dbHandle) != MSG_SUCCESS) {
957                                 dbHandle.finalizeQuery();
958                                 dbHandle.endTrans(false);
959                                 continue;
960                         }
961                 }
962
963                 dbHandle.finalizeQuery();
964
965                 dbHandle.endTrans(true);
966         }
967
968         for (int i = 0; i < pPushMsg->invalServiceCnt; i++) {
969
970                 int msgid = -1;
971
972                 memset(href, 0x00, sizeof(href));
973                 strncpy(href, &(pPushMsg->invalObjectUrl[i][0]), MAX_PUSH_CACHEOP_MAX_URL_LEN);
974
975                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
976                 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE HREF LIKE '%%%s%%'", MSGFW_PUSH_MSG_TABLE_NAME, href);
977
978                 dbHandle.beginTrans();
979
980                 err = dbHandle.prepareQuery(sqlQuery);
981
982                 if ((dbHandle.stepQuery() == MSG_ERR_DB_ROW) && err == MSG_SUCCESS) {
983
984                         msgid = dbHandle.getColumnToInt(1);
985
986                         memset(sqlQuery, 0x00, sizeof(sqlQuery));
987                         sprintf(sqlQuery, "DELETE FROM %s WHERE MSG_ID='%d'", MSGFW_PUSH_MSG_TABLE_NAME, msgid);
988
989                         /** Delete Message from Push table */
990                         if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
991                                 dbHandle.finalizeQuery();
992                                 dbHandle.endTrans(false);
993                                 continue;
994                         }
995
996                         memset(sqlQuery, 0x00, sizeof(sqlQuery));
997                         snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID = %d;", MSGFW_MESSAGE_TABLE_NAME, msgid);
998
999                         /** Delete Message from msg table */
1000                         if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS) {
1001                                 dbHandle.finalizeQuery();
1002                                 dbHandle.endTrans(false);
1003                                 continue;
1004                         }
1005
1006                         /**  Update all Address */
1007                         if (updateAllAddress() != MSG_SUCCESS) {
1008                                 dbHandle.finalizeQuery();
1009                                 dbHandle.endTrans(false);
1010                                 continue;
1011                         }
1012
1013                         /** Clear Address table */
1014                         if (MsgStoClearConversationTable(&dbHandle) != MSG_SUCCESS) {
1015                                 dbHandle.finalizeQuery();
1016                                 dbHandle.endTrans(false);
1017                                 continue;
1018                         }
1019                 }
1020
1021                 dbHandle.finalizeQuery();
1022
1023                 dbHandle.endTrans(true);
1024         }
1025
1026         /** delete temporary file */
1027         MsgDeleteFile(pMsgInfo->msgData);
1028
1029         return MSG_SUCCESS;
1030 }
1031
1032
1033 msg_error_t SmsPluginStorage::checkPushMsgValidation(MSG_PUSH_MESSAGE_S *pPushMsg, bool *pbProceed)
1034 {
1035         msg_error_t err = MSG_SUCCESS;
1036
1037         unsigned long oldExpireTime = 0;
1038         int rowCnt = 0;
1039
1040         char sqlQuery[MAX_QUERY_LEN+1];
1041
1042         /**  is push message is expired?? */
1043         if (pPushMsg->received > pPushMsg->expires) {
1044                 MSG_DEBUG("Push Message is expired.");
1045                 pbProceed = false;
1046                 return err;
1047         }
1048
1049
1050         if (pPushMsg->action == MSG_PUSH_SL_ACTION_EXECUTE_LOW) {
1051                 memset(sqlQuery, 0x00, sizeof(sqlQuery));
1052                 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT EXPIRES FROM %s WHERE ID = '%s' AND ACTION = %d",
1053                                 MSGFW_PUSH_MSG_TABLE_NAME, pPushMsg->id, pPushMsg->action);
1054         } else {
1055                 snprintf(sqlQuery, sizeof(sqlQuery), "SELECT EXPIRES FROM %s WHERE ID = '%s'",
1056                                 MSGFW_PUSH_MSG_TABLE_NAME, pPushMsg->id);
1057         }
1058
1059         err = dbHandle.getTable(sqlQuery, &rowCnt);
1060
1061         if (rowCnt < 1) {
1062                 dbHandle.freeTable();
1063                 return MSG_SUCCESS;
1064         }
1065
1066         oldExpireTime = dbHandle.getColumnToInt(1);
1067
1068         dbHandle.freeTable();
1069
1070         if (pPushMsg->created < oldExpireTime) {
1071                 MSG_DEBUG("Push Message is expired.");
1072                 pbProceed = false;
1073                 return err;
1074         }
1075
1076         return err;
1077 }
1078
1079
1080 msg_error_t SmsPluginStorage::checkStorageStatus(MSG_MESSAGE_INFO_S *pMsgInfo)
1081 {
1082         msg_error_t err = MSG_SUCCESS;
1083
1084         err = MsgStoCheckMsgCntFull(&dbHandle, &(pMsgInfo->msgType), pMsgInfo->folderId);
1085
1086         if (err != MSG_SUCCESS) {
1087
1088                 if (err == MSG_ERR_MESSAGE_COUNT_FULL) {
1089                         bool bAutoErase = false;
1090
1091                         MsgSettingGetBool(MSG_AUTO_ERASE, &bAutoErase);
1092
1093                         MSG_DEBUG("bAutoErase: %d", bAutoErase);
1094
1095                         if (bAutoErase == true) {
1096                                 msg_message_id_t msgId;
1097
1098                                 /** Find the oldest message's msgId */
1099                                 err = MsgStoGetOldestMessage(&dbHandle, pMsgInfo, &msgId);
1100
1101                                 if (err != MSG_SUCCESS)
1102                                         return err;
1103
1104                                 /** Delete the corresponding message. */
1105                                 err = deleteSmsMessage(msgId);
1106                         }
1107                 }
1108
1109                 return err;
1110         }
1111
1112         return err;
1113 }
1114
1115
1116 msg_error_t SmsPluginStorage::updateAllAddress()
1117 {
1118         msg_error_t err = MSG_SUCCESS;
1119
1120         int rowCnt = 0, index = 1;
1121         char sqlQuery[MAX_QUERY_LEN+1];
1122
1123         memset(sqlQuery, 0x00, sizeof(sqlQuery));
1124
1125         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT ADDRESS_ID FROM %s", MSGFW_ADDRESS_TABLE_NAME);
1126
1127         err = dbHandle.getTable(sqlQuery, &rowCnt);
1128
1129         if (err == MSG_ERR_DB_NORECORD) {
1130                 dbHandle.freeTable();
1131                 return MSG_SUCCESS;
1132         } else if ( err != MSG_SUCCESS) {
1133                 dbHandle.freeTable();
1134                 return err;
1135         }
1136
1137
1138         for (int i = 0; i < rowCnt; i++) {
1139
1140                 err = MsgStoUpdateConversation(&dbHandle, index++);
1141
1142                 if (err != MSG_SUCCESS)
1143                         break;
1144         }
1145
1146         dbHandle.freeTable();
1147
1148         return err;
1149 }
1150
1151
1152 msg_error_t SmsPluginStorage::getRegisteredPushEvent(char* pPushHeader, int *count, char *application_id)
1153 {
1154         msg_error_t err = MSG_SUCCESS;
1155
1156         int rowCnt = 0, index = 3;
1157
1158         char sqlQuery[MAX_QUERY_LEN+1] = {0, };
1159
1160         memset(sqlQuery, 0x00, sizeof(sqlQuery));
1161
1162         snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CONTENT_TYPE, APP_ID, APPCODE FROM %s", MSGFW_PUSH_CONFIG_TABLE_NAME);
1163
1164         err = dbHandle.getTable(sqlQuery, &rowCnt);
1165         MSG_DEBUG("rowCnt: %d", rowCnt);
1166
1167         if (err == MSG_ERR_DB_NORECORD) {
1168                 dbHandle.freeTable();
1169                 return MSG_SUCCESS;
1170         }
1171         else if ( err != MSG_SUCCESS) {
1172                 dbHandle.freeTable();
1173                 return err;
1174         }
1175
1176         char content_type[MAX_WAPPUSH_CONTENT_TYPE_LEN + 1];
1177         char app_id[MAX_WAPPUSH_ID_LEN + 1];
1178         int appcode = 0, default_appcode = 0;
1179         bool found = false;
1180         char *_content_type = NULL, *_app_id = NULL;
1181         *count = 0;
1182
1183
1184         for (int i = 0; i < rowCnt; i++) {
1185                 memset(content_type, 0, MAX_WAPPUSH_CONTENT_TYPE_LEN);
1186                 memset(app_id, 0, MAX_WAPPUSH_ID_LEN);
1187
1188                 dbHandle.getColumnToString(index++, MAX_WAPPUSH_CONTENT_TYPE_LEN + 1, content_type);
1189                 dbHandle.getColumnToString(index++, MAX_WAPPUSH_ID_LEN + 1, app_id);
1190                 appcode = dbHandle.getColumnToInt(index++);
1191
1192                 //MSG_DEBUG("content_type: %s, app_id: %s", content_type, app_id);
1193                 _content_type = strcasestr(pPushHeader, content_type);
1194                 if(_content_type) {
1195                         _app_id = strcasestr(pPushHeader, app_id);
1196                         if(appcode)
1197                                 default_appcode = appcode;
1198
1199                         if(_app_id) {
1200                                 PUSH_APPLICATION_INFO_S pInfo = {0, };
1201                                 pInfo.appcode = appcode;
1202                                 MSG_DEBUG("appcode: %d, app_id: %s", pInfo.appcode, app_id);
1203                                 strcpy(application_id, app_id);
1204                                 pushAppInfoList.push_back(pInfo);
1205                                 (*count)++;
1206                                 found = true;
1207                         }
1208                 }
1209         }
1210
1211         if(!found)
1212         {
1213                 // perform default action.
1214                 PUSH_APPLICATION_INFO_S pInfo = {0, };
1215                 pInfo.appcode = default_appcode;
1216                 strcpy(application_id, app_id);
1217                 pushAppInfoList.push_back(pInfo);
1218                 *count = 1;
1219         }
1220         dbHandle.freeTable();
1221
1222         return err;
1223 }
1224
1225
1226 msg_error_t SmsPluginStorage::getnthPushEvent(int index, int *appcode)
1227 {
1228         msg_error_t err = MSG_SUCCESS;
1229         if((unsigned int)index > pushAppInfoList.size() - 1)
1230                 return MSG_ERR_INVALID_PARAMETER;
1231
1232         std::list<PUSH_APPLICATION_INFO_S>::iterator it = pushAppInfoList.begin();
1233         int count = 0;
1234         for (; it != pushAppInfoList.end(); it++)
1235         {
1236                 if(index == count){
1237                         *appcode = it->appcode;
1238                         break;
1239                 }
1240                 count++;
1241         }
1242
1243         return err;
1244 }
1245
1246
1247 msg_error_t SmsPluginStorage::releasePushEvent()
1248 {
1249         msg_error_t err = MSG_SUCCESS;
1250         std::list<PUSH_APPLICATION_INFO_S>::iterator it = pushAppInfoList.begin();
1251
1252         for (; it != pushAppInfoList.end(); it++)
1253                 it = pushAppInfoList.erase(it);
1254
1255         return err;
1256 }