Sync with tizen_2.2 09/16509/1
authorSangkoo Kim <sangkoo.kim@samsung.com>
Tue, 18 Feb 2014 04:08:00 +0000 (13:08 +0900)
committerSangkoo Kim <sangkoo.kim@samsung.com>
Tue, 18 Feb 2014 04:58:23 +0000 (13:58 +0900)
Change-Id: I3acbde088f5dae01d5ac588fbde10cf27fcb3afa
Signed-off-by: Sangkoo Kim <sangkoo.kim@samsung.com>
40 files changed:
framework/storage-handler/MsgStorageFilter.cpp
framework/storage-handler/MsgStorageManager.cpp
framework/storage-handler/MsgStorageMessage.cpp
framework/storage-handler/MsgStorageMms.cpp
framework/transaction-manager/MsgCmdHandlerStorage.cpp
framework/transaction-manager/MsgCmdHandlerTransport.cpp
framework/transaction-manager/MsgTransManager.cpp
include/common/MsgCmdTypes.h
include/common/MsgQueue.h
include/common/MsgStorageTypes.h
include/framework/MsgCmdHandler.h
include/utils/MsgDebug.h
include/utils/MsgException.h
include/utils/MsgNotificationWrapper.h
include/utils/MsgSqliteWrapper.h
include/utils/MsgUtilStorage.h
mapi/msg_transport.cpp
packaging/msg-service.spec
plugin/mms_plugin/CMakeLists.txt
plugin/mms_plugin/MmsPluginConnManWrapper.cpp
plugin/mms_plugin/MmsPluginDecode.cpp
plugin/mms_plugin/MmsPluginHttp.cpp
plugin/mms_plugin/MmsPluginMain.cpp
plugin/mms_plugin/MmsPluginMessage.cpp
plugin/mms_plugin/MmsPluginStorage.cpp
plugin/mms_plugin/MmsPluginUserAgent.cpp
plugin/mms_plugin/include/MmsPluginConnManWrapper.h
plugin/mms_plugin/include/MmsPluginDecode.h
plugin/mms_plugin/include/MmsPluginHttp.h
plugin/sms_plugin/SmsPluginTransport.cpp
plugin/sms_plugin/SmsPluginWapPushHandler.cpp
utils/CMakeLists.txt
utils/MsgContact.cpp
utils/MsgDrmWrapper.cpp
utils/MsgGconfWrapper.cpp
utils/MsgNotificationWrapper.cpp
utils/MsgSoundPlayer.cpp
utils/MsgSqliteWrapper.cpp
utils/MsgUtilStorage.cpp
vobject-engine/VCard.c

index fc7a666..e38676a 100755 (executable)
@@ -33,25 +33,39 @@ msg_error_t MsgStoCheckDuplicatedFilter(const MSG_FILTER_S *pFilter)
        MSG_BEGIN();
 
        msg_error_t err = MSG_SUCCESS;
-       int rowCnt = 0;
 
+       char *filterStr = NULL;
        char sqlQuery[MAX_QUERY_LEN+1];
 
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       MsgConvertStrWithEscape(pFilter->filterValue, &filterStr);
 
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILTER_ID FROM %s WHERE FILTER_TYPE = %d AND FILTER_VALUE = '%s';",
-                       MSGFW_FILTER_TABLE_NAME, pFilter->filterType, pFilter->filterValue);
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILTER_ID FROM %s WHERE FILTER_TYPE = %d AND FILTER_VALUE = ?;",
+                       MSGFW_FILTER_TABLE_NAME, pFilter->filterType);
 
        MSG_DEBUG("sql : %s", sqlQuery);
 
-       err = dbHandle.getTable(sqlQuery, &rowCnt);
+       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
+       {
+               if (filterStr)
+                       free(filterStr);
+               return MSG_ERR_DB_EXEC;
+       }
 
-       if (err == MSG_SUCCESS)
+       dbHandle.bindText(filterStr, 1);
+
+       err = dbHandle.stepQuery();
+
+       if (err == MSG_ERR_DB_ROW) {
                err = MSG_ERR_FILTER_DUPLICATED;
-       else if (err == MSG_ERR_DB_NORECORD)
+       } else if (err == MSG_ERR_DB_DONE) {
                err = MSG_SUCCESS;
+       }
 
-       dbHandle.freeTable();
+       dbHandle.finalizeQuery();
+
+       if (filterStr)
+               free(filterStr);
 
        MSG_END();
 
index f5837d1..72d4c83 100755 (executable)
@@ -924,7 +924,8 @@ msg_error_t MsgStoUpdateMms(MSG_MESSAGE_INFO_S *pMsg)
                dbHandle.finalizeQuery();
                dbHandle.endTrans(true);
        } else {
-               MsgStoUpdateMMSMessage(pMsg);
+               if (MsgStoUpdateMMSMessage(pMsg) != MSG_SUCCESS)
+                       MSG_DEBUG("MsgStoUpdateMMSMessage is failed");
        }
        return MSG_SUCCESS;
 }
index d631c32..834ce08 100755 (executable)
@@ -167,8 +167,6 @@ msg_error_t MsgStoAddMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pS
                }
        }
 
-       dbHandle.endTrans(true);
-
        /* In the case of MMS Message, load the MMS plugin to save MMS PDU */
        if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
                MMS_MESSAGE_DATA_S mmsMsg;
@@ -179,21 +177,26 @@ msg_error_t MsgStoAddMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pS
 
                        err = plg->addMessage(pMsg, pSendOptInfo, pFileData);
 
-                       if (err != MSG_SUCCESS)
+                       if (err != MSG_SUCCESS) {
+                               dbHandle.endTrans(false);
                                return MSG_ERR_STORAGE_ERROR;
+                       }
 
                        if (pMsg->msgType.subType == MSG_SENDREQ_MMS) {
                                MSG_DEBUG("pMsg->msgText: %s, pMsg->thumbPath: %s ", pMsg->msgText, pMsg->thumbPath);
 
                                err = MsgStoUpdateMMSMessage(pMsg);
 
-                               if (err != MSG_SUCCESS)
+                               if (err != MSG_SUCCESS) {
+                                       dbHandle.endTrans(false);
                                        return MSG_ERR_STORAGE_ERROR;
-
+                               }
                        }
                }
        }
 
+       dbHandle.endTrans(true);
+
        MSG_END();
 
        return MSG_SUCCESS;
@@ -671,8 +674,8 @@ msg_error_t MsgStoDeleteMessage(msg_message_id_t msgId, bool bCheckIndication)
                }
        } else if (msgType.mainType == MSG_MMS_TYPE) {
 
-               char filePath[MSG_FILEPATH_LEN_MAX] = {0,};
-               char dirPath[MSG_FILEPATH_LEN_MAX]= {0,};
+               char filePath[MSG_FILEPATH_LEN_MAX+1] = {0,};
+               char dirPath[MSG_FILEPATH_LEN_MAX+1]= {0,};
 
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
                snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID = %d;",
@@ -1123,11 +1126,16 @@ FREE_MEMORY:
 msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList)
 {
        MSG_BEGIN();
+
        msg_error_t err = MSG_SUCCESS;
+       if (pMsgIdList->nCount < 1) {
+               MSG_DEBUG("pMsgIdList->nCount < 1");
+               return err;
+       }
+
+       MSG_DEBUG("pMsgIdList->nCount [%d]", pMsgIdList->nCount);
 
        char sqlQuery[MAX_QUERY_LEN+1];
-       char whereQuery[MAX_QUERY_LEN+1];
-       char sqlQuerySubset[(MAX_QUERY_LEN/5)+1];
 
        queue<msg_thread_id_t> threadList;
 
@@ -1139,36 +1147,47 @@ msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList)
        int listCnt = sizeof(tableList)/sizeof(char *);
        int rowCnt = 0;
 
-       memset(whereQuery, 0x00, sizeof(whereQuery));
-
-       if (pMsgIdList->nCount < 1) {
-               return MSG_SUCCESS;
-       } else {
-               for (int i=0; i < pMsgIdList->nCount; i++) {
-                       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
-                       if (i==0)
-                               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "(MSG_ID = %d ", pMsgIdList->msgIdList[i]);
-                       else
-                               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "OR MSG_ID = %d ", pMsgIdList->msgIdList[i]);
-                       strncat(whereQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(whereQuery));
-               }
+       // Clear tmp table
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", MSGFW_TMP_MSGID_TABLE_NAME);
+       err = dbHandle.execQuery(sqlQuery);
+       if (err != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to execQuery().");
+               return err;
+       }
+       // Insert tmp msg ids to delete.
+       dbHandle.beginTrans();
+       for (int i = 0; i < pMsgIdList->nCount; i++)
+       {
+               memset(sqlQuery, 0x00, sizeof(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d);",
+                               MSGFW_TMP_MSGID_TABLE_NAME, pMsgIdList->msgIdList[i]);
+               err = dbHandle.execQuery(sqlQuery);
+               if (err != MSG_SUCCESS) MSG_DEBUG("Fail to execQuery().");
+       }
+       err = dbHandle.endTrans(true);
+       if (err != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to endTrans(true).");
+               dbHandle.endTrans(false);
+               return err;
        }
-       strncat(whereQuery, ");", MAX_QUERY_LEN-strlen(whereQuery));
 
        // Get conversation ID from Folder
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE ", MSGFW_MESSAGE_TABLE_NAME);
-       strncat(sqlQuery, whereQuery, MAX_QUERY_LEN-strlen(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE MSG_ID IN (SELECT MSG_ID FROM %s);",
+                       MSGFW_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
 
        err = dbHandle.getTable(sqlQuery, &rowCnt);
 
        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
-               MSG_DEBUG("sql query is %s.", sqlQuery);
+               MSG_DEBUG("Fail to getTable().");
                dbHandle.freeTable();
                return err;
        }
 
-       if (rowCnt <= 0) {
+       MSG_DEBUG("rowCnt [%d]", rowCnt);
+
+       if (rowCnt < 1) {
                dbHandle.freeTable();
                return MSG_SUCCESS;
        }
@@ -1177,70 +1196,63 @@ msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList)
                MSG_DEBUG("thread ID : %d", dbHandle.getColumnToInt(i));
                threadList.push((msg_thread_id_t)dbHandle.getColumnToInt(i));
        }
-
        dbHandle.freeTable();
 
        /*** Delete Sim Message In Folder **/
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE STORAGE_ID = %d AND ", MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM);
-       strncat(sqlQuery, whereQuery, MAX_QUERY_LEN-strlen(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT MSG_ID FROM %s WHERE STORAGE_ID = %d AND MSG_ID IN (SELECT MSG_ID FROM %s);",
+                       MSGFW_MESSAGE_TABLE_NAME, MSG_STORAGE_SIM, MSGFW_TMP_MSGID_TABLE_NAME);
 
        rowCnt = 0;
 
        err = dbHandle.getTable(sqlQuery, &rowCnt);
 
        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
-               MSG_DEBUG("sql query is %s.", sqlQuery);
+               MSG_DEBUG("Fail to getTable().");
                dbHandle.freeTable();
-               return err;
+               rowCnt = 0;
        }
 
        for (int i = 1; i <= rowCnt; i++) {
                err = MsgStoDeleteMessage(dbHandle.getColumnToInt(i), false);
-
                if (err != MSG_SUCCESS) {
                        MSG_DEBUG("MsgStoDeleteMessage() Error!!!");
-                       dbHandle.freeTable();
-                       return err;
                }
        }
-
        dbHandle.freeTable();
        /*** **/
 
        dbHandle.beginTrans();
-
        for (int i = 0; i < listCnt; i++) {
                if (!strcmp(tableList[i], MMS_PLUGIN_MESSAGE_TABLE_NAME)) {
 
-                       int rowCnt = 0;
+                       char filePath[MSG_FILEPATH_LEN_MAX];
+                       char dirPath[MSG_FILEPATH_LEN_MAX];
 
-                       char filePath[MSG_FILEPATH_LEN_MAX] = {0,};
-                       char dirPath[MSG_FILEPATH_LEN_MAX] = {0,};
-//                     char thumbnailPath[MSG_FILEPATH_LEN_MAX] = {0,};
+                       rowCnt = 0;
 
-                       //get mms msg id list
+                       // MMS file path to delete.
                        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-                       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE ", MMS_PLUGIN_MESSAGE_TABLE_NAME);
-                       strncat(sqlQuery, whereQuery, MAX_QUERY_LEN-strlen(sqlQuery));
+                       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT FILE_PATH FROM %s WHERE MSG_ID IN (SELECT MSG_ID FROM %s);",
+                                       MMS_PLUGIN_MESSAGE_TABLE_NAME, MSGFW_TMP_MSGID_TABLE_NAME);
 
                        err = dbHandle.getTable(sqlQuery, &rowCnt);
-                       MSG_DEBUG("rowCnt %d", rowCnt);
 
                        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
-                               MSG_DEBUG("sqlQuery [%s]", sqlQuery);
-                               dbHandle.freeTable();
-                               dbHandle.endTrans(false);
-                               return err;
+                               MSG_DEBUG("Fail to getTable().");
+                               rowCnt = 0;
                        }
 
+                       MSG_DEBUG("rowCnt %d", rowCnt);
+
                        for (int i = 1; i <= rowCnt; i++) {
                                memset(filePath, 0x00, sizeof(filePath));
+                               memset(dirPath, 0x00, sizeof(dirPath));
                                dbHandle.getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
 
                                MSG_DEBUG("filePath [%s]", filePath);
 
-                               //delete raw file
+                               // Delete raw file.
                                snprintf(dirPath, sizeof(dirPath), "%s.dir", filePath);
 
                                if (remove(filePath) == -1)
@@ -1252,71 +1264,70 @@ msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList)
 
                                rmdir(dirPath);
                        }
-
                        dbHandle.freeTable();
+
                } else if (!strcmp(tableList[i], MSGFW_MMS_PREVIEW_TABLE_NAME)) {
+
                        char filePath[MSG_FILEPATH_LEN_MAX] = {0,};
+
+                       rowCnt = 0;
+
                        memset(sqlQuery, 0x00, sizeof(sqlQuery));
                        snprintf(sqlQuery, sizeof(sqlQuery),
                                        "SELECT VALUE FROM %s "
                                        "WHERE (TYPE=%d OR TYPE=%d) "
-                                       "AND ",
-                                       MSGFW_MMS_PREVIEW_TABLE_NAME, MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO);
+                                       "AND MSG_ID IN (SELECT MSG_ID FROM %s);",
+                                       MSGFW_MMS_PREVIEW_TABLE_NAME,
+                                       MSG_MMS_ITEM_TYPE_IMG, MSG_MMS_ITEM_TYPE_VIDEO,
+                                       MSGFW_TMP_MSGID_TABLE_NAME);
 
-                       strncat(sqlQuery, whereQuery, MAX_QUERY_LEN-strlen(sqlQuery));
+                       err = dbHandle.getTable(sqlQuery, &rowCnt);
 
-                       if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-                               dbHandle.endTrans(false);
-                               return MSG_ERR_DB_PREPARE;
+                       if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
+                               MSG_DEBUG("Fail to getTable().");
+                               rowCnt = 0;
                        }
 
-                       while (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-                               memset(filePath, 0x00, sizeof(filePath));
+                       MSG_DEBUG("rowCnt %d", rowCnt);
 
-                               strncpy(filePath, (char *)dbHandle.columnText(0), MSG_FILEPATH_LEN_MAX);
+                       for (int i = 1; i <= rowCnt; i++) {
+                               memset(filePath, 0x00, sizeof(filePath));
+                               dbHandle.getColumnToString(i, MSG_FILEPATH_LEN_MAX, filePath);
                                if (remove(filePath) == -1)
                                        MSG_DEBUG("Fail to delete file [%s]", filePath);
                                else
                                        MSG_DEBUG("Success to delete file [%s]", filePath);
                        }
-
-                       dbHandle.finalizeQuery();
+                       dbHandle.freeTable();
                }
 
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
-
-               snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE ", tableList[i]);
-               strncat(sqlQuery, whereQuery, MAX_QUERY_LEN-strlen(sqlQuery));
+               snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s WHERE MSG_ID IN (SELECT MSG_ID FROM %s);",
+                               tableList[i], MSGFW_TMP_MSGID_TABLE_NAME);
 
                // Delete Message in specific folder from table
                err = dbHandle.execQuery(sqlQuery);
                if (err != MSG_SUCCESS) {
-                       MSG_DEBUG("sqlQuery [%s]", sqlQuery);
-                       dbHandle.endTrans(false);
-                       return err;
+                       MSG_DEBUG("Fail to execQuery().");
                }
        }
 
        // Clear Conversation table
        err = MsgStoClearConversationTable(&dbHandle);
-       if (err != MSG_SUCCESS) {
-               dbHandle.endTrans(false);
-               return err;
-       }
+       if (err != MSG_SUCCESS) MSG_DEBUG("Fail to MsgStoClearConversationTable().");
 
        // Update Address
        while (!threadList.empty()) {
                err = MsgStoUpdateConversation(&dbHandle, threadList.front());
-
+               if (err != MSG_SUCCESS) MSG_DEBUG("Fail to MsgStoUpdateConversation().");
                threadList.pop();
-
-               if (err != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
-                       return err;
-               }
        }
-
-       dbHandle.endTrans(true);
+       err = dbHandle.endTrans(true);
+       if (err != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to endTrans(true).");
+               dbHandle.endTrans(false);
+               return err;
+       }
 
        int smsCnt = 0;
        int mmsCnt = 0;
@@ -1326,34 +1337,14 @@ msg_error_t MsgStoDeleteMessageByList(msg_id_list_s *pMsgIdList)
 
        MsgSettingSetIndicator(smsCnt, mmsCnt);
 
-#if 0
-/*** Create thread  for noti and phone log delete. **/
-       if (pMsgIdList->nCount > 0) {
-               msg_id_list_s *pToDeleteMsgIdListCpy = NULL;
-               pToDeleteMsgIdListCpy = (msg_id_list_s *)new char[sizeof(msg_id_list_s)];
-               memset(pToDeleteMsgIdListCpy, 0x00, sizeof(msg_id_list_s));
-               pToDeleteMsgIdListCpy->nCount = pMsgIdList->nCount;
-               pToDeleteMsgIdListCpy->msgIdList = (msg_message_id_t *)new char[sizeof(msg_message_id_t)*pMsgIdList->nCount];
-               memcpy(pToDeleteMsgIdListCpy->msgIdList, pMsgIdList->msgIdList, sizeof(msg_message_id_t)*pMsgIdList->nCount);
-
-               if (g_idle_add(startToDeletePhoneLog, (void *)pToDeleteMsgIdListCpy) == 0) {
-                       MSG_DEBUG("startToDeletePhoneLog not invoked: %s", strerror(errno));
-                       // memory free
-                       if (pToDeleteMsgIdListCpy != NULL) {
-                               //free peer info list
-                               if (pToDeleteMsgIdListCpy->msgIdList != NULL)
-                                       delete [] pToDeleteMsgIdListCpy->msgIdList;
-
-                               delete [] pToDeleteMsgIdListCpy;
-                       }
-                       err = MSG_ERR_UNKNOWN;
-               }
-       }
-/*** **/
-#endif
-
        MsgRefreshNoti(false);
 
+       // Clear tmp table
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery), "DELETE FROM %s;", MSGFW_TMP_MSGID_TABLE_NAME);
+       err = dbHandle.execQuery(sqlQuery);
+       if (err != MSG_SUCCESS) MSG_DEBUG("Fail to execQuery().");
+
        MSG_END();
        return MSG_SUCCESS;
 }
@@ -1398,6 +1389,19 @@ msg_error_t MsgStoMoveMessageToFolder(msg_message_id_t msgId, msg_folder_id_t de
        /* update conversation table */
        err = MsgStoUpdateConversation(&dbHandle, convId);
 
+
+       if (destFolderId == MSG_INBOX_ID) {
+               int smsCnt = 0;
+               int mmsCnt = 0;
+
+               smsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_SMS_TYPE);
+               mmsCnt = MsgStoGetUnreadCnt(&dbHandle, MSG_MMS_TYPE);
+
+               MsgSettingSetIndicator(smsCnt, mmsCnt);
+
+               MsgRefreshNoti(false);
+       }
+
        return err;
 }
 
@@ -2503,9 +2507,11 @@ msg_error_t MsgStoSearchMessage(const char *pSearchString, msg_struct_list_s *pT
        // Replace string for '%' and '_' character
        char *ext1_str = NULL;
        char *ext2_str = NULL;
+       char *ext3_str = NULL;
 
        ext1_str = MsgStoReplaceString(pSearchString, "_", "\\_");
        ext2_str = MsgStoReplaceString(ext1_str, "%", "\\%");
+       ext3_str = MsgStoReplaceString(ext2_str, "'", "''");
 
        // Search - Address, Name
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -2513,7 +2519,7 @@ msg_error_t MsgStoSearchMessage(const char *pSearchString, msg_struct_list_s *pT
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT CONV_ID, UNREAD_CNT, SMS_CNT, MMS_CNT, DISPLAY_NAME, \
                        MAIN_TYPE, SUB_TYPE, MSG_DIRECTION, DISPLAY_TIME, MSG_TEXT \
                        FROM %s WHERE DISPLAY_NAME LIKE '%%%s%%' ESCAPE '\\' ORDER BY DISPLAY_TIME DESC;",
-                       MSGFW_CONVERSATION_TABLE_NAME, ext2_str);
+                       MSGFW_CONVERSATION_TABLE_NAME, ext3_str);
 
        if (ext1_str) {
                free(ext1_str);
@@ -2525,6 +2531,11 @@ msg_error_t MsgStoSearchMessage(const char *pSearchString, msg_struct_list_s *pT
                ext2_str = NULL;
        }
 
+       if (ext3_str) {
+               free(ext3_str);
+               ext3_str = NULL;
+       }
+
        MSG_DEBUG("[%s]", sqlQuery);
 
        if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
@@ -2600,64 +2611,90 @@ msg_error_t MsgStoSearchMessage(const MSG_SEARCH_CONDITION_S *pSearchCon, int of
        pMsgList->msg_struct_info = NULL;
 
        int rowCnt = 0;
-       int index = 26; // numbers of index
+       int index = 19; // numbers of index
 
-       char sqlQuery[MAX_QUERY_LEN+1];
-       char sqlQuerySubset[(MAX_QUERY_LEN/5)+1];
+       unsigned int tmpSize = 0;
+
+       unsigned int searchValSize = 0;
+       unsigned int addrValSize = 0;
+
+       if (pSearchCon->pSearchVal)
+               searchValSize = strlen(pSearchCon->pSearchVal);
+
+       if (pSearchCon->pAddressVal)
+               addrValSize = strlen(pSearchCon->pAddressVal);
 
-       char firstName[MAX_DISPLAY_NAME_LEN+1], lastName[MAX_DISPLAY_NAME_LEN+1];
-       char displayName[MAX_DISPLAY_NAME_LEN+1];
+       MSG_DEBUG("searchValSize [%d]", searchValSize);
+       MSG_DEBUG("addrValSize [%d]", addrValSize);
+
+       unsigned int maxQuerySize = MAX_QUERY_LEN+(searchValSize*6)+addrValSize+1;
+
+       MSG_DEBUG("MAX_QUERY_LEN+(searchValSize*6)+addrValSize+1 [%d]", maxQuerySize);
+
+       char sqlQuery[maxQuerySize];
 
        char *ext1_str = NULL;
        char *ext2_str = NULL;
+       char *ext3_str = NULL;
 
        // Get Name Order
        int order = MsgGetContactNameOrder();
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.MSG_ID, A.CONV_ID, A.FOLDER_ID, A.STORAGE_ID, A.MAIN_TYPE, A.SUB_TYPE, "
-                       "A.DISPLAY_TIME, A.DATA_SIZE, A.NETWORK_STATUS, A.READ_STATUS, A.PROTECTED, A.BACKUP, A.PRIORITY, "
-                       "A.MSG_DIRECTION, A.SCHEDULED_TIME, A.SUBJECT, A.MSG_TEXT, B.ADDRESS_TYPE, B.RECIPIENT_TYPE, "
-                       "B.CONTACT_ID, B.ADDRESS_VAL, B.DISPLAY_NAME, B.FIRST_NAME, B.LAST_NAME, A.ATTACHMENT_COUNT, A.THUMB_PATH "
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT "
+                       "A.MSG_ID, "
+                       "A.CONV_ID, "
+                       "A.FOLDER_ID, "
+                       "A.STORAGE_ID, "
+                       "A.MAIN_TYPE, "
+                       "A.SUB_TYPE, "
+                       "A.DISPLAY_TIME, "
+                       "A.DATA_SIZE, "
+                       "A.NETWORK_STATUS, "
+                       "A.READ_STATUS, "
+                       "A.PROTECTED, "
+                       "A.BACKUP, "
+                       "A.PRIORITY, "
+                       "A.MSG_DIRECTION, "
+                       "A.SCHEDULED_TIME, "
+                       "A.SUBJECT, "
+                       "A.MSG_TEXT, "
+                       "A.ATTACHMENT_COUNT, "
+                       "A.THUMB_PATH "
                        "FROM %s A, %s B WHERE A.CONV_ID = B.CONV_ID AND B.ADDRESS_ID <> 0 ",
                        MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME);
 
-       //// folder
-       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
-
+       tmpSize = strlen(sqlQuery);
        if (pSearchCon->folderId == MSG_ALLBOX_ID)
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.FOLDER_ID > 0 AND A.FOLDER_ID < %d ", MSG_CBMSGBOX_ID);
+               snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND A.FOLDER_ID > 0 AND A.FOLDER_ID < %d ", MSG_CBMSGBOX_ID);
        else if (pSearchCon->folderId == MSG_IOSBOX_ID)
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.FOLDER_ID > 0 AND A.FOLDER_ID < %d ", MSG_DRAFT_ID);
+               snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND A.FOLDER_ID > 0 AND A.FOLDER_ID < %d ", MSG_DRAFT_ID);
        else
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.FOLDER_ID = %d ", pSearchCon->folderId);
-
-       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+               snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND A.FOLDER_ID = %d ", pSearchCon->folderId);
 
 
        //// msg type
-       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
-
+       tmpSize = strlen(sqlQuery);
        switch (pSearchCon->msgType) {
                case MSG_TYPE_SMS:
-                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.MAIN_TYPE = %d AND A.SUB_TYPE = %d ", MSG_SMS_TYPE, MSG_NORMAL_SMS);
+                       snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND A.MAIN_TYPE = %d AND A.SUB_TYPE = %d ", MSG_SMS_TYPE, MSG_NORMAL_SMS);
                        break;
 
                case MSG_TYPE_MMS:
-                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.MAIN_TYPE = %d ", MSG_MMS_TYPE);
+                       snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND A.MAIN_TYPE = %d ", MSG_MMS_TYPE);
                        break;
 
                case MSG_TYPE_MMS_JAVA:
-                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.MAIN_TYPE = %d AND A.SUB_TYPE = %d ", MSG_MMS_TYPE, MSG_SENDREQ_JAVA_MMS);
+                       snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND A.MAIN_TYPE = %d AND A.SUB_TYPE = %d ", MSG_MMS_TYPE, MSG_SENDREQ_JAVA_MMS);
                        break;
 
                case MSG_TYPE_SMS_SYNCML:
-                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.MAIN_TYPE = %d AND A.SUB_TYPE = %d ", MSG_SMS_TYPE, MSG_SYNCML_CP);
+                       snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND A.MAIN_TYPE = %d AND A.SUB_TYPE = %d ", MSG_SMS_TYPE, MSG_SYNCML_CP);
                        break;
 
                case MSG_TYPE_SMS_REJECT:
-                       snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND A.MAIN_TYPE = %d AND A.SUB_TYPE = %d ", MSG_SMS_TYPE, MSG_REJECT_SMS);
+                       snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND A.MAIN_TYPE = %d AND A.SUB_TYPE = %d ", MSG_SMS_TYPE, MSG_REJECT_SMS);
                        break;
 
                default:
@@ -2665,25 +2702,25 @@ msg_error_t MsgStoSearchMessage(const MSG_SEARCH_CONDITION_S *pSearchCon, int of
                        break;
        }
 
-       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
 
        /// string
        if (pSearchCon->pSearchVal != NULL) {
 
+               tmpSize = strlen(sqlQuery);
+
                // Replace string for '%' and '_' character
                ext1_str = MsgStoReplaceString(pSearchCon->pSearchVal, "_", "\\_");
                ext2_str = MsgStoReplaceString(ext1_str, "%", "\\%");
+               ext3_str = MsgStoReplaceString(ext2_str, "'", "''");
 
-               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset),
+               snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize,
                                "AND ( A.MSG_TEXT LIKE '%%%s%%' ESCAPE '\\' "
                                "OR A.SUBJECT LIKE '%%%s%%' ESCAPE '\\' "
                                "OR B.ADDRESS_VAL LIKE '%%%s%%' ESCAPE '\\' "
                                "OR B.DISPLAY_NAME LIKE '%%%s%%' ESCAPE '\\' "
                                "OR B.FIRST_NAME LIKE '%%%s%%' ESCAPE '\\' "
                                "OR B.LAST_NAME LIKE '%%%s%%' ESCAPE '\\') ",
-                               ext2_str, ext2_str, ext2_str, ext2_str, ext2_str, ext2_str);
-               strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+                               ext3_str, ext3_str, ext3_str, ext3_str, ext3_str, ext3_str);
 
                if (ext1_str) {
                        free(ext1_str);
@@ -2694,18 +2731,24 @@ msg_error_t MsgStoSearchMessage(const MSG_SEARCH_CONDITION_S *pSearchCon, int of
                        free(ext2_str);
                        ext2_str = NULL;
                }
+
+               if (ext3_str) {
+                       free(ext3_str);
+                       ext3_str = NULL;
+               }
        }
 
        /// address
        if (pSearchCon->pAddressVal != NULL) {
 
+               tmpSize = strlen(sqlQuery);
+
                // Replace string for '%' and '_' character
                ext1_str = MsgStoReplaceString(pSearchCon->pAddressVal, "_", "\\_");
                ext2_str = MsgStoReplaceString(ext1_str, "%", "\\%");
+               ext3_str = MsgStoReplaceString(ext2_str, "'", "''");
 
-               memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "AND B.ADDRESS_VAL LIKE '%%%s%%' ESCAPE '\\' ", ext2_str);
-               strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+               snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "AND B.ADDRESS_VAL LIKE '%%%s%%' ESCAPE '\\' ", ext3_str);
 
                if (ext1_str) {
                        free(ext1_str);
@@ -2716,17 +2759,19 @@ msg_error_t MsgStoSearchMessage(const MSG_SEARCH_CONDITION_S *pSearchCon, int of
                        free(ext2_str);
                        ext2_str = NULL;
                }
+
+               if (ext3_str) {
+                       free(ext3_str);
+                       ext3_str = NULL;
+               }
        }
 
        /// limit, offset
-       memset(sqlQuerySubset, 0x00, sizeof(sqlQuerySubset));
-
+       tmpSize = strlen(sqlQuery);
        if (offset >= 0 && limit > 0)
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "GROUP BY A.MSG_ID ORDER BY A.DISPLAY_TIME DESC LIMIT %d OFFSET %d;", limit, offset);
+               snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "GROUP BY A.MSG_ID ORDER BY A.DISPLAY_TIME DESC LIMIT %d OFFSET %d;", limit, offset);
        else
-               snprintf(sqlQuerySubset, sizeof(sqlQuerySubset), "GROUP BY A.MSG_ID ORDER BY A.DISPLAY_TIME DESC;");
-
-       strncat(sqlQuery, sqlQuerySubset, MAX_QUERY_LEN-strlen(sqlQuery));
+               snprintf(sqlQuery+tmpSize, maxQuerySize-tmpSize, "GROUP BY A.MSG_ID ORDER BY A.DISPLAY_TIME DESC;");
 
        msg_error_t err = dbHandle.getTable(sqlQuery, &rowCnt);
 
@@ -2797,64 +2842,8 @@ msg_error_t MsgStoSearchMessage(const MSG_SEARCH_CONDITION_S *pSearchCon, int of
                }
 
                msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
-               msg_struct_s *addr_info = NULL;
-               MSG_ADDRESS_INFO_S *address = NULL;
 
-               addr_list->nCount = 1;
-               addr_list->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t *)*MAX_TO_ADDRESS_CNT];
-
-               msg_struct_s *pTmpAddr = NULL;
-
-               for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
-                       addr_list->msg_struct_info[i] = (msg_struct_t)new char[sizeof(msg_struct_s)];
-                       pTmpAddr = (msg_struct_s *)addr_list->msg_struct_info[i];
-                       pTmpAddr->type = MSG_STRUCT_ADDRESS_INFO;
-                       pTmpAddr->data = new MSG_ADDRESS_INFO_S;
-                       memset(pTmpAddr->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
-
-                       addr_list->msg_struct_info[i] = (msg_struct_t)pTmpAddr;
-               }
-
-               addr_info = (msg_struct_s *)addr_list->msg_struct_info[0];
-               address = (MSG_ADDRESS_INFO_S *)addr_info->data;
-               address->addressType = dbHandle.getColumnToInt(index++);
-               address->recipientType = dbHandle.getColumnToInt(index++);
-               address->contactId = dbHandle.getColumnToInt(index++);
-
-               dbHandle.getColumnToString(index++, MAX_ADDRESS_VAL_LEN, address->addressVal);
-
-               memset(displayName, 0x00, sizeof(displayName));
-               dbHandle.getColumnToString(index++, MAX_DISPLAY_NAME_LEN, displayName);
-
-               memset(firstName, 0x00, sizeof(firstName));
-               dbHandle.getColumnToString(index++, MAX_DISPLAY_NAME_LEN, firstName);
-
-               memset(lastName, 0x00, sizeof(lastName));
-               dbHandle.getColumnToString(index++, MAX_DISPLAY_NAME_LEN, lastName);
-
-               if (strlen(displayName) <= 0) {
-                       if (order == 0) {
-                               if (firstName[0] != '\0') {
-                                       strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
-                               }
-
-                               if (lastName[0] != '\0') {
-                                       strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                                       strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                               }
-                       } else if (order == 1) {
-                               if (lastName[0] != '\0') {
-                                       strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
-                                       strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                               }
-
-                               if (firstName[0] != '\0') {
-                                       strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
-                               }
-                       }
-               }
-
-               strncpy(address->displayName, displayName, MAX_DISPLAY_NAME_LEN);
+               MsgStoGetAddressByMsgId(&dbHandle, pTmp->msgId, order, addr_list);
 
                pTmp->addr_list = addr_list;
 
index 9009984..2b19b07 100755 (executable)
@@ -74,8 +74,6 @@ msg_error_t MsgStoUpdateMMSMessage(MSG_MESSAGE_INFO_S *pMsg)
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       dbHandle.beginTrans();
-
        if(pMsg->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || pMsg->msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
                if( pMsg->networkStatus == MSG_NETWORK_RETRIEVE_SUCCESS ) {
                        snprintf(sqlQuery, sizeof(sqlQuery),
@@ -83,7 +81,6 @@ msg_error_t MsgStoUpdateMMSMessage(MSG_MESSAGE_INFO_S *pMsg)
                                        MSGFW_MESSAGE_TABLE_NAME, pMsg->msgType.mainType, pMsg->msgType.subType, pMsg->displayTime, pMsg->networkStatus, pMsg->thumbPath,  pMsg->dataSize, pMsg->msgId);
 
                        if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-                               dbHandle.endTrans(false);
                                return MSG_ERR_DB_PREPARE;
                        }
 
@@ -95,7 +92,6 @@ msg_error_t MsgStoUpdateMMSMessage(MSG_MESSAGE_INFO_S *pMsg)
                                        MSGFW_MESSAGE_TABLE_NAME, pMsg->msgType.mainType, pMsg->msgType.subType, pMsg->networkStatus, pMsg->thumbPath,  pMsg->msgId);
 
                        if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-                               dbHandle.endTrans(false);
                                return MSG_ERR_DB_PREPARE;
                        }
 
@@ -108,7 +104,6 @@ msg_error_t MsgStoUpdateMMSMessage(MSG_MESSAGE_INFO_S *pMsg)
                                MSGFW_MESSAGE_TABLE_NAME, pMsg->msgData, pMsg->thumbPath, pMsg->dataSize, pMsg->msgId);
 
                if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
                        return MSG_ERR_DB_PREPARE;
                }
 
@@ -119,14 +114,12 @@ msg_error_t MsgStoUpdateMMSMessage(MSG_MESSAGE_INFO_S *pMsg)
                                MSGFW_MESSAGE_TABLE_NAME, pMsg->msgType.mainType, pMsg->msgType.subType, pMsg->folderId, pMsg->networkStatus, pMsg->msgId);
 
                if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS) {
-                       dbHandle.endTrans(false);
                        return MSG_ERR_DB_PREPARE;
                }
        }
 
        if (dbHandle.stepQuery() != MSG_ERR_DB_DONE) {
                dbHandle.finalizeQuery();
-               dbHandle.endTrans(false);
                MSG_DEBUG("Update MMS Message. Fail [%s]", sqlQuery);
                return MSG_ERR_DB_STEP;
        }
@@ -143,7 +136,6 @@ msg_error_t MsgStoUpdateMMSMessage(MSG_MESSAGE_INFO_S *pMsg)
 
        if (dbHandle.getTable(sqlQuery, &row) != MSG_SUCCESS) {
                dbHandle.freeTable();
-               dbHandle.endTrans(false);
                return MSG_ERR_DB_PREPARE;
        }
 
@@ -155,20 +147,16 @@ msg_error_t MsgStoUpdateMMSMessage(MSG_MESSAGE_INFO_S *pMsg)
                if (MsgStoUpdateConversation(&dbHandle, convId) != MSG_SUCCESS) {
                        MSG_DEBUG("MsgStoUpdateConversation() Error");
                        dbHandle.freeTable();
-                       dbHandle.endTrans(false);
-
                        return MSG_ERR_STORAGE_ERROR;
                }
 
        } else {
                MSG_DEBUG("MsgStepQuery() Error [%s]", sqlQuery);
                dbHandle.freeTable();
-               dbHandle.endTrans(false);
                return MSG_ERR_DB_STEP;
        }
 
        dbHandle.freeTable();
-       dbHandle.endTrans(true);
 
        MSG_END();
 
index bc80ed8..5ba9191 100755 (executable)
@@ -25,6 +25,7 @@
 #include "MsgStorageHandler.h"
 #include "MsgPluginManager.h"
 #include "MsgTransManager.h"
+#include "MsgContact.h"
 #include "MsgCmdHandler.h"
 
 
@@ -1470,3 +1471,19 @@ int MsgUpdatePushEventHandler(const MSG_CMD_S *pCmd, char **ppEvent)
 
        return eventSize;
 }
+
+
+int MsgContactSyncEventHandler(const MSG_CMD_S *pCmd, char **ppEvent)
+{
+       msg_error_t err = MSG_SUCCESS;
+
+
+       int eventSize = 0;
+
+       MsgSyncContact();
+
+       // Make Event Data
+       eventSize = MsgMakeEvent(NULL, 0, MSG_EVNET_CONTACT_SYNC, err, (void**)ppEvent);
+
+       return eventSize;
+}
index 95474f7..694cbff 100755 (executable)
@@ -460,13 +460,14 @@ int MsgIncomingMMSConfMsgHandler(const MSG_CMD_S *pCmd, char **ppEvent)
        msgIds[0] = msgInfo.msgId;
        msgIdList.msgIdList = msgIds;
 
-       err = MsgStoGetAddrInfo(msgInfo.msgId, &(msgInfo.addressList[0]));
+       //err = MsgStoGetAddrInfo(msgInfo.msgId, &(msgInfo.addressList[0]));
+       err = MsgStoGetOrgAddressList(&msgInfo);
 
        if (err == MSG_SUCCESS) {
-               MSG_DEBUG("MmsStoGetAddrInfo() success.");
-               msgInfo.nAddressCnt = 1;
+               MSG_DEBUG("MsgStoGetOrgAddressList() success.");
+//             msgInfo.nAddressCnt = 1;
        } else {
-               MSG_DEBUG("MmsStoGetAddrInfo() fail.");
+               MSG_DEBUG("MsgStoGetOrgAddressList() fail.");
        }
 
        if(msgInfo.msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS || msgInfo.msgType.subType == MSG_RETRIEVE_MANUALCONF_MMS) {
index f4f5bda..59e9e5d 100755 (executable)
@@ -166,6 +166,8 @@ MsgTransactionManager::MsgTransactionManager() : running(false), mx(), cv()
        handlerMap[MSG_CMD_DELETE_PUSH_EVENT] = &MsgDeletePushEventHandler;
        handlerMap[MSG_CMD_UPDATE_PUSH_EVENT] = &MsgUpdatePushEventHandler;
        handlerMap[MSG_CMD_DELETE_MESSAGE_BY_LIST] = &MsgDeleteMessageByListHandler;
+
+       handlerMap[MSG_CMD_CONTACT_SYNC] = &MsgContactSyncEventHandler;
 }
 
 
index 9c4ba1a..a05eed1 100755 (executable)
@@ -170,6 +170,7 @@ enum _MSG_CMD_TYPE_E
        MSG_CMD_UPDATE_PUSH_EVENT,
        MSG_CMD_DELETE_MESSAGE_BY_LIST,
        MSG_CMD_SET_FILTER_ACTIVATION,
+       MSG_CMD_CONTACT_SYNC,
 
 // end of MSG_CMD; new CMD should be defined before MSG_CMD_NUM
        MSG_CMD_NUM
@@ -286,6 +287,7 @@ enum _MSG_EVENT_TYPE_E
        MSG_EVENT_UPDATE_PUSH_EVENT,
        MSG_EVENT_DELETE_MESSAGE_BY_LIST,
        MSG_EVENT_SET_FILTER_ACTIVATION,
+       MSG_EVNET_CONTACT_SYNC,
 
 // end of MSG_EVENT; new EVENT should be defined before MSG_EVENT_NUM
        MSG_EVENT_NUM
index 562994a..82ccfed 100755 (executable)
@@ -32,6 +32,7 @@ public:
        int size();
        bool empty();
        void clear();
+       bool checkExist(T const & qItem, bool(cmp)(T const &, T const &));
 private:
        Mutex mx;
        std::list <T> q;
@@ -94,5 +95,18 @@ template <typename T> void MsgThdSafeQ<T>::clear()
        q.clear();
 }
 
+template <typename T> bool MsgThdSafeQ<T>::checkExist(T const & qItem, bool(cmp)(T const &, T const &))
+{
+       MutexLocker lock(mx);
+
+       for(typename list<T>::iterator iterPos = q.begin(); iterPos != q.end(); ++iterPos)      {
+
+               if (cmp(qItem, *iterPos) == true)
+                       return true;
+       }
+
+       return false;
+}
+
 #endif // __MsgThdSafeQ_H__
 
index e1ddc60..bc0cd25 100755 (executable)
@@ -93,6 +93,7 @@ typedef struct
        msg_contact_id_t        contactId;                                                      /**< Indicates the unique contact ID. */
        char                            firstName[MAX_DISPLAY_NAME_LEN+1];              /**< Indicates the first name of contact. */
        char                            lastName[MAX_DISPLAY_NAME_LEN+1];               /**< Indicates the last name of contact. */
+       char                            displayName[MAX_DISPLAY_NAME_LEN+1];            /**< Indicates the display name of contact. */
        char                            imagePath[MAX_IMAGE_PATH_LEN+1];                /**< Indicates the image path of contact. */
 } MSG_CONTACT_INFO_S;
 
index 05e6a44..3525ecc 100755 (executable)
@@ -104,5 +104,7 @@ int MsgAddPushEventHandler(const MSG_CMD_S *pCmd, char **ppEvent);
 int MsgDeletePushEventHandler(const MSG_CMD_S *pCmd, char **ppEvent);
 int MsgUpdatePushEventHandler(const MSG_CMD_S *pCmd, char **ppEvent);
 
+int MsgContactSyncEventHandler(const MSG_CMD_S *pCmd, char **ppEvent);
+
 
 #endif // MSG_CMD_HANDLER_H
index f609cf7..98d44e7 100755 (executable)
@@ -78,8 +78,47 @@ int get_tid();
        do\
     {\
                SLOGD(" END   <<<<  \n\n");\
-    } \
-    while( 0 )
+    } while( 0 )
+
+#define MSG_INFO(fmt, args...)\
+       do\
+       {\
+               SLOGI("* Info * " fmt "\n\n", ##args);\
+       } while( 0 )
+
+#define MSG_WARN(fmt, args...)\
+       do {\
+               SLOGW("* Warning * " fmt "\n\n", ##args)\
+       } while( 0 )
+
+#define MSG_ERR(fmt, args...)\
+       do {\
+               SLOGE("* Error * " fmt "\n\n", ##args);\
+       } while( 0 )
+
+
+#define MSG_ERR_RET_VM(expr, val, fmt, arg...)\
+       do {\
+               if (expr) {\
+                       MSG_ERR(fmt, ##arg);\
+                       return (val);\
+               }\
+       } while (0)
+
+#define MSG_ERR_RET_M(expr, fmt, arg...)\
+       do {\
+               if (expr) {\
+                       MSG_ERR(fmt, ##arg);\
+                       return;\
+               }\
+       } while (0)
+
+#define MSG_WARN_M(expr, fmt, arg...)\
+       do {\
+               if (expr) {\
+                       MSG_WARN(fmt, ##arg);\
+               }\
+       } while (0)
 
 #define MSG_PROFILE_BEGIN(pfid) \
        unsigned int __prf_l1_##pfid = __LINE__;    \
index ad1ab20..23ef2c7 100755 (executable)
@@ -69,6 +69,7 @@ public:
                SECURITY_ERROR,
                SERVER_READY_ERROR = 13,
 
+               REQ_EXIST_ERROR,
                // dont erase NUM_ERRORS. place a new error code in ahead of NUM_ERRORS
                NUM_ERRORS
        };
index a5c7706..8642c4e 100755 (executable)
@@ -30,9 +30,6 @@
 #define MSG_APP_PACKAGE_NAME   "message"
 #define MSG_SYS_PACKAGE_NAME   "sys_string"
 #define NORMAL_MSG_ICON_PATH           "/opt/usr/apps/8r4r5ddzzn/shared/res/screen-density-xhigh/mainmenu.png"
-#define VOICE_MSG_ICON_PATH                    "/opt/usr/apps/8r4r5ddzzn/shared/res/screen-density-xhigh/mainmenu.png"
-#define CB_MSG_ICON_PATH                               "/opt/usr/apps/8r4r5ddzzn/shared/res/screen-density-xhigh/mainmenu.png"
-#define NOTI_MSG_ICON_PATH                     "/opt/usr/apps/8r4r5ddzzn/shared/res/screen-density-xhigh/mainmenu.png"
 
 #define MSG_APP_LOCALEDIR                      "/usr/apps/org.tizen.message/res/locale"
 
@@ -50,6 +47,8 @@
 #define MSG_SYS_LOCALEDIR      "/usr/share/locale"
 
 #define NOTIFICATION_PRIV_ID DEFAULT_SETTING_PATH"/notification_priv_id"
+#define VOICE_NOTI_ID_1 DEFAULT_SETTING_PATH"/voice_noti_id1"
+#define CB_NOTI_PRIV_ID DEFAULT_SETTING_PATH"/cb_noti_priv_id"
 
 /*==================================================================================================
                                      FUNCTION PROTOTYPES
@@ -59,9 +58,12 @@ msg_error_t MsgInsertNoti(MSG_MESSAGE_INFO_S* pMsg);
 msg_error_t MsgInsertMmsReportToNoti(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S* pMsg);
 
 msg_error_t MsgRefreshNoti(bool bWithTicker);
+msg_error_t MsgRefreshCBNoti(bool bWithTicker);
 msg_error_t MsgCleanAndResetNoti();
 
 msg_error_t MsgInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg);
 msg_error_t MsgInsertBadge(unsigned int unreadMsgCnt);
 
+msg_error_t MsgClearVoiceNoti(MSG_SUB_TYPE_T subType);
+
 #endif // MSG_QUICKPANEL_WRAPPER_H
index 08f8301..8f35985 100755 (executable)
 #define MSGFW_REPORT_TABLE_NAME                                "MSG_REPORT_TABLE"
 #define MSGFW_PUSH_CONFIG_TABLE_NAME                   "MSG_PUSHCFG_TABLE"
 #define MSGFW_MMS_PREVIEW_TABLE_NAME                   "MSG_MMS_PREVIEW_INFO_TABLE"
+
+#define MSGFW_TMP_MSGID_TABLE_NAME                     "MSG_TMP_MSGID_TABLE"
+
 #define MAX_QUERY_LEN                                  3072
 #define MAX_FOLDER_NAME_LEN            20
 #define MAX_ACCOUNT_NAME_LEN   51
 
+#define MSGFW_DB_ESCAPE_CHAR           '\\'
 
 /*==================================================================================================
                                      FUNCTION PROTOTYPES
 ==================================================================================================*/
 void   MsgReleaseMemoryDB();
-
+msg_error_t MsgConvertStrWithEscape(const char *input, char **output);
 
 /*==================================================================================================
                                      CLASS DEFINITIONS
index 3d8a1d1..de2b9d8 100755 (executable)
@@ -50,7 +50,7 @@ bool MsgExistAddress(MsgDbHandler *pDbHandle, const MSG_MESSAGE_INFO_S *pMsg, ms
 
 int MsgStoGetUnreadCnt(MsgDbHandler *pDbHandle, MSG_MAIN_TYPE_T MsgType);
 msg_error_t MsgStoAddContactInfo(MsgDbHandler *pDbHandle, MSG_CONTACT_INFO_S *pContactInfo, const char *pNumber);
-msg_error_t MsgStoClearContactInfo(MsgDbHandler *pDbHandle, int ContactId);
+msg_error_t MsgStoResetContactInfo(MsgDbHandler *pDbHandle, int ContactId);
 msg_error_t MsgStoClearContactInfo(MsgDbHandler *pDbHandle, int ContactId, const char *pNumber);
 msg_error_t MsgStoGetMmsRawFilePath(MsgDbHandler *pDbHandle, msg_message_id_t msgId, char *pFilePath);
 bool MsgStoCheckReadReportRequested(MsgDbHandler *pDbHandle, msg_message_id_t MsgId);
@@ -58,5 +58,6 @@ bool MsgStoCheckReadReportIsSent(MsgDbHandler *pDbHandle, msg_message_id_t MsgId
 msg_error_t MsgStoUpdateNetworkStatus(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S *pMsgInfo, msg_network_status_t status);
 char *MsgStoReplaceString(const char *org_str, const char *old_str, const char *new_str);
 void MsgConvertNumber(const char* pSrcNum, char* pDestNum);
+msg_error_t MsgStoRefreshConversationDisplayName();
 #endif // MSG_UTIL_STORAGE_H
 
index 880e168..8b27132 100755 (executable)
@@ -49,7 +49,11 @@ EXPORT_API int msg_submit_req(msg_handle_t handle, msg_struct_t req)
        catch (MsgException& e)
        {
                MSG_FATAL("%s", e.what());
-               return MSG_ERR_TRANSPORT_ERROR;
+
+               if ((e.errorCode() == MsgException::IPC_ERROR) || (e.errorCode() == MsgException::FILE_ERROR))
+                       return MSG_ERR_STORAGE_ERROR;
+               else
+                       return MSG_ERR_TRANSPORT_ERROR;
        }
 
        return err;
index c7f3108..f539136 100755 (executable)
@@ -1,7 +1,7 @@
 Name:           msg-service
-Version:        0.9.2
-Release:        3
-License:        Samsung
+Version:        0.9.3
+Release:        1
+License:        Flora-1.1
 Summary:        Messaging Framework Library
 Group:          System/Libraries
 Source0:        %{name}-%{version}.tar.gz
@@ -20,6 +20,7 @@ Requires(post): systemd
 Requires(postun): systemd
 BuildRequires: cmake
 BuildRequires: pkgconfig(alarm-service)
+BuildRequires: pkgconfig(appsvc)
 BuildRequires: pkgconfig(aul)
 BuildRequires: pkgconfig(capi-appfw-application)
 BuildRequires: pkgconfig(contacts-service2)
@@ -47,13 +48,14 @@ BuildRequires: pkgconfig(svi)
 BuildRequires: pkgconfig(tapi)
 BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(feedback)
+BuildRequires: pkgconfig(capi-network-connection)
 
 %description
 Description: Messaging Framework Library
 
 
 %package devel
-License:        Flora License v1.0
+License:        Flora License v1.1
 Summary:        Messaging Framework Library (development)
 Requires:       %{name} = %{version}-%{release}
 Group:          Development/Libraries
@@ -63,7 +65,7 @@ Description: Messaging Framework Library (development)
 
 
 %package tools
-License:        Flora License v1.0
+License:        Flora License v1.1
 Summary:        Messaging server application
 Requires:       %{name} = %{version}-%{release}
 Group:          TO_BU / FILL_IN
@@ -77,7 +79,7 @@ Description:  Messaging server application
 
 
 %package -n sms-plugin
-License:        Flora License v1.0
+License:        Flora License v1.1
 Summary:        SMS plugin library
 Requires:       %{name} = %{version}-%{release}
 Group:          System/Libraries
@@ -88,7 +90,7 @@ Requires(postun): /sbin/ldconfig
 Description: SMS plugin library
 
 %package -n mms-plugin
-License:        Flora License v1.0
+License:        Flora License v1.1
 Summary:        MMS plugin library
 Requires:       %{name} = %{version}-%{release}
 Group:          System/Libraries
@@ -298,6 +300,9 @@ then
        APPCODE INTEGER,
        SECURE INTEGER );
 
+       CREATE TABLE MSG_TMP_MSGID_TABLE (
+       MSG_ID INTEGER );
+
     CREATE INDEX MSG_CONVERSATION_INDEX ON MSG_CONVERSATION_TABLE(CONV_ID);
     CREATE INDEX MSG_FOLDER_INDEX ON MSG_FOLDER_TABLE(FOLDER_ID);
     CREATE INDEX MSG_MESSAGE_INDEX ON MSG_MESSAGE_TABLE(MSG_ID, CONV_ID, FOLDER_ID);
index ee1f975..a0f874a 100755 (executable)
@@ -45,7 +45,7 @@ INCLUDE_DIRECTORIES(
 )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(mms_plugin_pkgs REQUIRED glib-2.0 network libxml-2.0 drm-client libcurl mm-fileinfo mmutil-jpeg vconf dlog media-thumbnail)
+pkg_check_modules(mms_plugin_pkgs REQUIRED glib-2.0 network libxml-2.0 drm-client libcurl mm-fileinfo mmutil-jpeg vconf dlog media-thumbnail capi-network-connection)
 
 FOREACH(flag ${mms_plugin_pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index 3e26517..5dac38c 100755 (executable)
 #include <errno.h>
 #include "MmsPluginConnManWrapper.h"
 #include "MmsPluginDebug.h"
+#include "MmsPluginHttp.h"
+#include <glib.h>
+#include "net_connection.h"
 
-void network_print_profile(net_profile_info_t *ProfInfo)
+#define MMS_CONTEXT_INVOKE_WAIT_TIME   30
+#define MMS_CONNECTION_API_WAIT_TIME   50
+
+#define MMS_FREE(obj)\
+       if (obj){\
+               free(obj);\
+               obj = NULL;\
+       }
+
+
+static Mutex g_mx;
+static CndVar g_cv;
+static connection_h connection = NULL;
+
+void __connection_profile_print(connection_profile_h profile)
 {
-       int di = 0;
-
-       unsigned char *ipaddr;
-       unsigned char *netmaskaddr;
-       unsigned char *gwaddr;
-       net_dev_info_t *net_info;
-
-       if (ProfInfo->profile_type == NET_DEVICE_CELLULAR) {
-               ipaddr = (unsigned char *)&ProfInfo->ProfileInfo.Pdp.net_info.IpAddr.Data.Ipv4.s_addr;
-               netmaskaddr = (unsigned char *)&ProfInfo->ProfileInfo.Pdp.net_info.SubnetMask.Data.Ipv4.s_addr;
-               gwaddr = (unsigned char *)&ProfInfo->ProfileInfo.Pdp.net_info.GatewayAddr.Data.Ipv4.s_addr;
-               net_info = &(ProfInfo->ProfileInfo.Pdp.net_info);
+       int ret;
+       char *profile_id = NULL;
+       char *profile_name = NULL;
+       char *interface_name = NULL;
+       char *ip_address = NULL;
+       char *subnet_mask = NULL;
+       char *gateway_address = NULL;
+       char *dns_address = NULL;
+       char *proxy_address = NULL;
+       char *apn = NULL;
+       char *user_name = NULL;
+       char *password = NULL;
+       char *home_url = NULL;
+       bool is_roaming;
+
+       connection_profile_type_e profile_type;
+       connection_profile_state_e profile_state;
+       connection_ip_config_type_e ip_type = CONNECTION_IP_CONFIG_TYPE_NONE;
+       connection_proxy_type_e proxy_type;
+       connection_cellular_service_type_e service_type = CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN;
+       connection_cellular_auth_type_e auth_type = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
+
+       MSG_DEBUG("**************************************************************************************************");
+       ret = connection_profile_get_id(profile, &profile_id);
+       MSG_DEBUG("Profile Id = [%s]", profile_id);
+
+       ret = connection_profile_get_name(profile, &profile_name);
+       MSG_DEBUG("Profile Name = [%s]", profile_name);
+
+       ret = connection_profile_get_type(profile, &profile_type);
+
+       if (profile_type == CONNECTION_PROFILE_TYPE_CELLULAR) {
+               MSG_DEBUG("Profile Type = [CELLULAR]");
+       } else if (profile_type == CONNECTION_PROFILE_TYPE_WIFI) {
+               MSG_DEBUG("Profile Type = [WIFI]");
+       } else if (profile_type == CONNECTION_PROFILE_TYPE_ETHERNET) {
+               MSG_DEBUG("Profile Type = [ETHERNET]");
+       } else if (profile_type == CONNECTION_PROFILE_TYPE_BT) {
+               MSG_DEBUG("Profile Type = [BT]");
+       } else {
+               MSG_DEBUG("Profile Type = Unknown [%d]", profile_type);
+       }
+
+       ret = connection_profile_get_network_interface_name(profile, &interface_name);
+       MSG_DEBUG("Profile Interface Name = [%s]", interface_name);
+
+       ret = connection_profile_get_state(profile, &profile_state);
+       if (profile_state == CONNECTION_PROFILE_STATE_DISCONNECTED) {
+               MSG_DEBUG("Profile State = [DISCONNECTED]");
+       } else if (profile_state == CONNECTION_PROFILE_STATE_ASSOCIATION) {
+               MSG_DEBUG("Profile State = [ASSOCIATION]");
+       } else if (profile_state == CONNECTION_PROFILE_STATE_CONFIGURATION) {
+               MSG_DEBUG("Profile State = [CONFIGURATION]");
+       } else if (profile_state == CONNECTION_PROFILE_STATE_CONNECTED) {
+               MSG_DEBUG("Profile State = [CONNECTED]");
        } else {
-               MSG_DEBUG("Error!!! Invalid profile type\n");
-               return;
+               MSG_DEBUG("Profile State = Unknown [%d]", profile_state);
        }
 
+       ret = connection_profile_get_ip_config_type(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_type);
+       MSG_DEBUG("Profile Ip Config Type = [%d]", ip_type);
+
+       ret = connection_profile_get_ip_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_address);
+       MSG_DEBUG("Profile Ip Address = [%s]", ip_address);
+
+       ret = connection_profile_get_subnet_mask(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &subnet_mask);
+       MSG_DEBUG("Profile Subnet Mask = [%s]", subnet_mask);
+
+       ret = connection_profile_get_gateway_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &gateway_address);
+       MSG_DEBUG("Profile Gateway Address = [%s]", gateway_address);
+
+       ret = connection_profile_get_dns_address(profile, 1, CONNECTION_ADDRESS_FAMILY_IPV4, &dns_address);
+       MSG_DEBUG("Profile Dns Address = [%s]", dns_address);
+
+       ret = connection_profile_get_proxy_type(profile, &proxy_type);
+       MSG_DEBUG("Profile Proxy Type = [%d]", proxy_type);
+
+       ret = connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_address);
+       MSG_DEBUG("Profile Proxy Address = [%s]", proxy_address);
+
+       ret = connection_profile_get_cellular_service_type(profile, &service_type);
+       if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET) {
+               MSG_DEBUG("Profile Service Type = [INTERNET]");
+       } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_MMS) {
+               MSG_DEBUG("Profile Service Type = [MMS]");
+       } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET) {
+               MSG_DEBUG("Profile Service Type = [PREPAID_INTERNET]");
+       } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS) {
+               MSG_DEBUG("Profile Service Type = [PREPAID_MMS]");
+       } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING) {
+               MSG_DEBUG("Profile Service Type = [TETHERING]");
+       } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION) {
+               MSG_DEBUG("Profile Service Type = [APPLICATION]");
+       } else {
+               MSG_DEBUG("Profile Service Type = [Unknown][%d]", service_type);
+       }
+
+       ret = connection_profile_get_cellular_apn(profile, &apn);
+       MSG_DEBUG("Profile Apn = [%s]", apn);
+
+       ret = connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password);
+       MSG_DEBUG("Profile Auth Type = [%d]", &auth_type);
+       MSG_DEBUG("Profile Auth Name = [%s]", &user_name);
+       MSG_DEBUG("Profile Auth Passward = [%s]", &password);
+
+       ret = connection_profile_get_cellular_home_url(profile, &home_url);
+       MSG_DEBUG("Profile Home Url = [%s]", home_url);
+
+       ret = connection_profile_is_cellular_roaming(profile, &is_roaming);
+       MSG_DEBUG("Profile Roaming = [%d]", is_roaming);
        MSG_DEBUG("**************************************************************************************************");
 
-       MSG_DEBUG("Profile Name = [%s]\n", ProfInfo->ProfileName);
-
-       if (ProfInfo->ProfileState == NET_STATE_TYPE_IDLE)
-               MSG_DEBUG("Profile State = [idle]\n");
-       else if (ProfInfo->ProfileState == NET_STATE_TYPE_FAILURE)
-               MSG_DEBUG("Profile State = [failure]\n");
-       else if (ProfInfo->ProfileState == NET_STATE_TYPE_ASSOCIATION)
-               MSG_DEBUG("Profile State = [association]\n");
-       else if (ProfInfo->ProfileState == NET_STATE_TYPE_CONFIGURATION)
-               MSG_DEBUG("Profile State = [configuration]\n");
-       else if (ProfInfo->ProfileState == NET_STATE_TYPE_READY)
-               MSG_DEBUG("Profile State = [ready]\n");
-       else if (ProfInfo->ProfileState == NET_STATE_TYPE_ONLINE)
-               MSG_DEBUG("Profile State = [online]\n");
-       else if (ProfInfo->ProfileState == NET_STATE_TYPE_DISCONNECT)
-               MSG_DEBUG("Profile State = [disconnect]\n");
-       else
-               MSG_DEBUG("Profile State = [unknown]\n");
+       MMS_FREE(profile_id);
+       MMS_FREE(profile_name);
+       MMS_FREE(interface_name);
+       MMS_FREE(ip_address);
+       MMS_FREE(subnet_mask);
+       MMS_FREE(gateway_address);
+       MMS_FREE(dns_address);
+       MMS_FREE(proxy_address);
+       MMS_FREE(apn);
+       MMS_FREE(user_name);
+       MMS_FREE(password);
+       MMS_FREE(home_url);
+}
+
+static void __connection_type_changed_cb(connection_type_e type, void* user_data)
+{
+       MSG_DEBUG("Type changed callback, connection type : %d", type);
+}
+
+static void __connection_ip_changed_cb(const char* ipv4_address, const char* ipv6_address, void* user_data)
+{
+       MSG_DEBUG("IP changed callback, IPv4 address : %s, IPv6 address : %s",
+                       ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
+}
 
-               MSG_DEBUG("Profile Type = [pdp]\n");
+static void __connection_proxy_changed_cb(const char* ipv4_address, const char* ipv6_address, void* user_data)
+{
+       MSG_DEBUG("Proxy changed callback, IPv4 address : %s, IPv6 address : %s",
+                       ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
+}
 
-       if (ProfInfo->ProfileInfo.Pdp.ProtocolType == NET_PDP_TYPE_GPRS)
-               MSG_DEBUG("Profile Protocol Type = [GPRS]\n");
-       else if (ProfInfo->ProfileInfo.Pdp.ProtocolType == NET_PDP_TYPE_EDGE)
-               MSG_DEBUG("Profile Protocol Type = [EDGE]\n");
-       else if (ProfInfo->ProfileInfo.Pdp.ProtocolType == NET_PDP_TYPE_UMTS)
-               MSG_DEBUG("Profile Protocol Type = [UMTS]\n");
+static void __connection_profile_opened_cb(connection_error_e result, void* user_data)
+{
+       if (result == CONNECTION_ERROR_NONE || result == CONNECTION_ERROR_ALREADY_EXISTS)
+               MSG_DEBUG("Connection open Succeeded [%d]", result);
        else
-               MSG_DEBUG("Profile Protocol Type = [NONE]\n");
+               MSG_DEBUG("Connection open Failed, err : %d", result);
 
-       MSG_DEBUG("Profile APN = [%s]\n", ProfInfo->ProfileInfo.Pdp.Apn);
+       MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance();
 
-       if (ProfInfo->ProfileInfo.Pdp.AuthInfo.AuthType == NET_PDP_AUTH_PAP)
-               MSG_DEBUG("Profile Auth Type = [PAP]\n");
-       else if (ProfInfo->ProfileInfo.Pdp.AuthInfo.AuthType == NET_PDP_AUTH_CHAP)
-               MSG_DEBUG("Profile Auth Type = [CHAP]\n");
+       cmAgent->open_callback(result, user_data);
+}
+
+static void __connection_profile_closed_cb(connection_error_e result, void* user_data)
+{
+       if (result ==  CONNECTION_ERROR_NONE)
+               MSG_DEBUG("Connection close Succeeded");
        else
-               MSG_DEBUG("Profile Auth Type = [NONE]\n");
-
-       MSG_DEBUG("Profile Auth UserName = [%s]\n", ProfInfo->ProfileInfo.Pdp.AuthInfo.UserName);
-       MSG_DEBUG("Profile Auth Password = [%s]\n", ProfInfo->ProfileInfo.Pdp.AuthInfo.Password);
-       MSG_DEBUG("Profile Home URL = [%s]\n", ProfInfo->ProfileInfo.Pdp.HomeURL);
-       MSG_DEBUG("Profile MCC = [%s]\n", ProfInfo->ProfileInfo.Pdp.Mcc);
-       MSG_DEBUG("Profile MNC = [%s]\n", ProfInfo->ProfileInfo.Pdp.Mnc);
-       MSG_DEBUG("Profile Roaming = [%d]\n", (int)ProfInfo->ProfileInfo.Pdp.Roaming);
-       MSG_DEBUG("Profile Setup Required = [%d]\n", (int)ProfInfo->ProfileInfo.Pdp.SetupRequired);
-       MSG_DEBUG("Profile Favourite = [%d]\n", (int)ProfInfo->Favourite);
-       MSG_DEBUG("Profile Device Name = [%s]\n", net_info->DevName);
-       MSG_DEBUG("Profile DNS Count = [%d]\n", net_info->DnsCount);
-       for (di = 0; di < net_info->DnsCount; di++) {
-               unsigned char *dns = (unsigned char *)&net_info->DnsAddr[di].Data.Ipv4.s_addr;
-               MSG_DEBUG("Profile DNS Address %d = [%d.%d.%d.%d]\n", di+1, dns[0], dns[1], dns[2], dns[3]);
+               MSG_DEBUG("Connection close Failed, err : %d", result);
+
+       MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance();
+
+       cmAgent->close_callback(result, user_data);
+}
+
+static gboolean __connection_create(void *pVoid)
+{
+       MSG_BEGIN();
+
+       bool ret = false;
+       bool *ret_val = (bool *)pVoid;
+
+       if (connection) {
+               MSG_DEBUG("connection already exist");
+               ret = true;
+       } else {
+               int err = connection_create(&connection);
+
+               if (CONNECTION_ERROR_NONE == err) {
+                       connection_set_type_changed_cb(connection, __connection_type_changed_cb, NULL);
+                       connection_set_ip_address_changed_cb(connection, __connection_ip_changed_cb, NULL);
+                       connection_set_proxy_address_changed_cb(connection, __connection_proxy_changed_cb, NULL);
+                       ret = true;
+                       MSG_DEBUG("Client registration success [%p] ", connection);
+               } else {
+                       MSG_DEBUG("Client registration failed %d", err);
+               }
        }
 
-       if (net_info->IpConfigType == NET_IP_CONFIG_TYPE_DYNAMIC)
-               MSG_DEBUG("Profile IPv4 Method = [NET_IP_CONFIG_TYPE_DYNAMIC]\n");
-       else if (net_info->IpConfigType == NET_IP_CONFIG_TYPE_STATIC)
-               MSG_DEBUG("Profile IPv4 Method = [NET_IP_CONFIG_TYPE_STATIC]\n");
-       else if (net_info->IpConfigType == NET_IP_CONFIG_TYPE_FIXED)
-               MSG_DEBUG("Profile IPv4 Method = [NET_IP_CONFIG_TYPE_FIXED]\n");
-       else if (net_info->IpConfigType == NET_IP_CONFIG_TYPE_OFF)
-               MSG_DEBUG("Profile IPv4 Method = [NET_IP_CONFIG_TYPE_OFF]\n");
-       else
-               MSG_DEBUG("Profile IPv4 Method = [UNKNOWN]\n");
-
-       MSG_DEBUG("Profile IP Address = [%d.%d.%d.%d]\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
-       MSG_DEBUG("Profile Netmask = [%d.%d.%d.%d]\n", netmaskaddr[0], netmaskaddr[1], netmaskaddr[2], netmaskaddr[3]);
-       MSG_DEBUG("Profile Gateway = [%d.%d.%d.%d]\n", gwaddr[0], gwaddr[1], gwaddr[2], gwaddr[3]);
-
-       if (net_info->ProxyMethod == NET_PROXY_TYPE_DIRECT)
-               MSG_DEBUG("Proxy Method = [direct]\n");
-       else if (net_info->ProxyMethod == NET_PROXY_TYPE_AUTO)
-               MSG_DEBUG("Proxy Method = [auto]\n");
-       else if (net_info->ProxyMethod == NET_PROXY_TYPE_MANUAL)
-               MSG_DEBUG("Proxy Method = [manual]\n");
-       else
-               MSG_DEBUG("Proxy Method = [unknown]\n");
+       if (ret_val) {
+               *ret_val = ret;
+       }
+
+       MSG_END();
+       return FALSE;
+}
 
-       MSG_DEBUG("Profile Proxy = [%s]\n", net_info->ProxyAddr);
+static gboolean __connection_destroy(void *pVoid)
+{
+       MSG_BEGIN();
 
-       MSG_DEBUG("**************************************************************************************************");
+       int rv;
+       int netOpenResult = NET_ERR_NONE;
+
+       if (connection != NULL) {
+               rv = connection_destroy(connection);
+               connection = NULL;
+               MSG_DEBUG("connection destory !!");
+       } else {
+               MSG_DEBUG("Cannot connection destroy : Handle is NULL");
+               rv = CONNECTION_ERROR_INVALID_OPERATION;
+       }
+
+       MSG_END();
+       return FALSE;
 }
 
+static gboolean __connection_profile_open(void *pVoid)
+{
+       MSG_BEGIN();
+
+       int netOpenResult = NET_ERR_NONE;
+       int *ret_val = (int *)pVoid;
 
+       connection_profile_h profile;
+       int err;
 
-void network_evt_cb (net_event_info_t *event_cb, void *user_data)
+       err = connection_get_default_cellular_service_profile(connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profile);
+
+       if (err != CONNECTION_ERROR_NONE) {
+               MSG_DEBUG("connection_get_default_cellular_service_profile Failed!! [%d]", err);
+               netOpenResult = NET_ERR_UNKNOWN;
+       } else {
+
+               if (connection_open_profile(connection, profile, __connection_profile_opened_cb, NULL) != CONNECTION_ERROR_NONE) {
+                       MSG_DEBUG("Connection open Failed!!");
+                       netOpenResult = NET_ERR_UNKNOWN;
+               }
+       }
+
+       connection_profile_destroy(profile);
+
+       if (ret_val) {
+               *ret_val = netOpenResult;
+       }
+
+       MSG_END();
+
+       return FALSE;
+}
+
+static gboolean __connection_profile_close(void *pVoid)
 {
        MSG_BEGIN();
 
-       MmsPluginCmAgent::instance()->processCBdatas(event_cb, user_data);
+       int netOpenResult = NET_ERR_NONE;
+
+       int *ret_val = (int *)pVoid;
+
+       connection_profile_h profile;
+       int err;
+
+       err = connection_get_default_cellular_service_profile(connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profile);
+
+       if (err  != CONNECTION_ERROR_NONE) {
+               MSG_DEBUG("connection_get_default_cellular_service_profile Failed!! [%d]", err);
+               netOpenResult = NET_ERR_UNKNOWN;
+       } else {
+
+               if (connection_close_profile(connection, profile, __connection_profile_closed_cb, NULL) != CONNECTION_ERROR_NONE) {
+                       MSG_DEBUG("Connection close Failed!!");
+                       netOpenResult = NET_ERR_UNKNOWN;
+               }
+
+       }
+
+       connection_profile_destroy(profile);
+
+       if (ret_val) {
+               *ret_val = netOpenResult;
+       }
 
        MSG_END();
+
+       return FALSE;
+}
+
+
+void context_invoke_end_cb(gpointer data)
+{
+       g_mx.lock();
+
+       MSG_DEBUG("@@ SIGNAL @@");
+
+       g_cv.signal();
+
+       g_mx.unlock();
 }
 
+/*
+ * Network api should run at g_main_loop to receive callback
+ * */
+void context_invoke(GSourceFunc func, void *ret)
+{
+       MSG_BEGIN();
+
+       int time_ret = 0;
+
+       g_mx.lock();
+
+       g_main_context_invoke_full(NULL, G_PRIORITY_HIGH, func, ret,  context_invoke_end_cb);
+
+       MSG_DEBUG("@@ WAIT @@");
+
+       time_ret = g_cv.timedwait(g_mx.pMutex(), MMS_CONTEXT_INVOKE_WAIT_TIME);
+       g_mx.unlock();
+
+       if (time_ret == ETIMEDOUT) {
+               MSG_DEBUG("@@ WAKE by timeout@@");
+       } else {
+               MSG_DEBUG("@@ WAKE by signal@@");
+       }
+
+       MSG_END();
+}
 
 MmsPluginCmAgent *MmsPluginCmAgent::pInstance = NULL;
 
@@ -149,77 +380,77 @@ MmsPluginCmAgent::MmsPluginCmAgent()
        MSG_BEGIN();
 
        isCmOpened = false;
-       bzero(&mmsProfile, sizeof (net_profile_info_t));
 
+       isCmRegistered = false;
+
+       home_url = NULL;
+       interface_name = NULL;
+       proxy_address = NULL;
        MSG_END();
 }
 
 MmsPluginCmAgent::~MmsPluginCmAgent()
 {
-
+       MMS_FREE(home_url);
+       MMS_FREE(interface_name);
+       MMS_FREE(proxy_address);
 }
 
-bool MmsPluginCmAgent::registration()
+bool MmsPluginCmAgent::open()
 {
        MSG_BEGIN();
 
-       bool registResult = true;
+       int netOpenResult = NET_ERR_NONE;
 
-       if (net_register_client((net_event_cb_t) network_evt_cb, NULL) != NET_ERR_NONE) {
-               MSG_DEBUG("Error!! net_register_client() failed.\n");
-               registResult = false;
-       }
+       lock();
 
-       MSG_END();
+       if (isCmOpened == false) {
 
-       return registResult;
-}
+               isCmRegistered = false;
 
-bool MmsPluginCmAgent::open()
-{
-       MSG_BEGIN();
+               context_invoke(__connection_create, &isCmRegistered);
 
-       if (!isCmOpened) {
-               if (!registration())
-                       return false;
+               if (isCmRegistered == true) {
 
-               int netOpenResult = NET_ERR_NONE;
-               net_service_type_t service_type = NET_SERVICE_MMS;
+                       MSG_DEBUG("net_open_connection for MMS");
 
-               netOpenResult = net_open_connection_with_preference(service_type);
-               if (netOpenResult != NET_ERR_NONE) {
-                       MSG_DEBUG("Error!! net_open_connection_with_profile() failed. [%d]", netOpenResult);
-                       deregistration();
-                       return false;
-               }
+                       context_invoke(__connection_profile_open, &netOpenResult);
 
-               MSG_DEBUG("WAITING UNTIL Network Connection Open.");
+                       if (netOpenResult == NET_ERR_NONE) {
 
-               lock();
+                               MSG_DEBUG("## WAITING UNTIL Network Connection Open. ##");
 
-               int time_ret = 0;
-               time_ret = cv.timedwait(mx.pMutex(), 50);
+                               int time_ret = 0;
 
-               unlock();
+                               time_ret = cv.timedwait(mx.pMutex(), MMS_CONNECTION_API_WAIT_TIME); // isCmOpened will changed by processCBdatas
 
-               if (time_ret == ETIMEDOUT) {
-                       MSG_DEBUG("Network Connection Open Time Out.");
-                       deregistration();
-                       return false;
-               } else {
-                       if(!isCmOpened) {
-                               MSG_DEBUG("Network connection open failed");
-                               deregistration();
-                               return false;
+                               MSG_DEBUG("## WAKE ##");
+
+                               if (time_ret == ETIMEDOUT) {
+                                       MSG_DEBUG("Network Connection Open Time Out.");
+                               }
+
+                               if(!isCmOpened) {
+                                       MSG_DEBUG("Network Connection Open Failed");
+                               }
+
+                       } else { //error
+                               MSG_FATAL("Error!! net_open_connection_with_profile() failed. [%d]", netOpenResult);
                        }
+
+                       if (isCmOpened == false) {
+                               context_invoke( __connection_destroy, NULL);
+                       }
+
+               } else {
+                       MSG_FATAL("## Failed network callback registration ##");
                }
        } else {
                MSG_DEBUG("Network is already opened.");
-               return false;
        }
 
+       unlock();
        MSG_END();
-
        return isCmOpened;
 }
 
@@ -228,221 +459,142 @@ void MmsPluginCmAgent::close()
 {
        MSG_BEGIN();
 
+       lock();
+
        if (isCmOpened) {
                int netOpenResult = NET_ERR_NONE;
 
-               netOpenResult = net_close_connection(mmsProfile.ProfileName);
-               if (netOpenResult != NET_ERR_NONE) {
-                       MSG_DEBUG("Error!! net_close_connection() failed.\n");
-                       deregistration();
-                       return;
-               }
+               context_invoke(__connection_profile_close, &netOpenResult);
+
+               if (netOpenResult == NET_ERR_NONE) {
 
-               MSG_DEBUG("WAITING UNTIL Network Connection Close.");
+                       MSG_DEBUG("## WAITING UNTIL Network Connection Close. ##");
 
-               lock();
+                       int time_ret = 0;
 
-               int time_ret = 0;
-               time_ret = cv.timedwait(mx.pMutex(), 50);
+                       time_ret = cv.timedwait(mx.pMutex(), MMS_CONNECTION_API_WAIT_TIME);
 
-               unlock();
+                       MSG_DEBUG("## WAKE ##");
 
-               if (time_ret == ETIMEDOUT) {
-                       MSG_DEBUG("Network Connection Close Timed Out.");
+                       if (time_ret == ETIMEDOUT) {
+                               MSG_DEBUG("Network Connection Close Timed Out.");
+                       }
+
+               } else {
+                       MSG_DEBUG("Error!! net_close_connection() failed");
                }
 
-               deregistration();
                isCmOpened = false;
        } else {
                MSG_DEBUG ("Network Connection is not opened.");
-               return;
        }
-}
-
-
-void MmsPluginCmAgent::deregistration()
-{
-       MSG_BEGIN();
 
-       int netOpenResult = NET_ERR_NONE;
+       if (isCmRegistered == true) {
+               context_invoke(__connection_destroy, NULL);
+               isCmRegistered = false;
+       }
 
-       netOpenResult = net_deregister_client();
-       if (netOpenResult != NET_ERR_NONE)
-               MSG_DEBUG("Error!! net_deregister_client() failed. [%d]", netOpenResult);
-       else
-               MSG_DEBUG ("net_deregister_client() Success.");
+       unlock();
 
        MSG_END();
 }
 
-
-void MmsPluginCmAgent::processCBdatas(net_event_info_t *event_cb, void *user_data)
+void MmsPluginCmAgent::open_callback(connection_error_e result, void* user_data)
 {
-       MSG_BEGIN();
+       lock();
 
-       net_dev_info_t *dev_info = NULL;
-       net_profile_info_t *prof_info = NULL;
-
-       switch (event_cb->Event) {
-       case NET_EVENT_NET_CONFIGURE_RSP:
-               MSG_DEBUG("Received Network Configuration response: %d \n", event_cb->Error);
-               dev_info = (net_dev_info_t *)event_cb->Data;
-
-               /*Successful PDP Activation*/
-               if (event_cb->Error == NET_ERR_NONE) {
-                       char *ip = (char *)&dev_info->IpAddr.Data.Ipv4;
-                       char *netmask = (char *)&dev_info->SubnetMask.Data.Ipv4;
-                       char *gateway = (char *)&dev_info->GatewayAddr.Data.Ipv4;
-                       char *dns1 = (char *)&dev_info->DnsAddr[0].Data.Ipv4.s_addr;
-                       char *dns2 = (char *)&dev_info->DnsAddr[1].Data.Ipv4.s_addr;
-
-                       MSG_DEBUG("= IP address [%d.%d.%d.%d]\n",
-                                       (int)ip[0], ip[1], ip[2], ip[3]);
-                       MSG_DEBUG("= Netmask [%d.%d.%d.%d]\n",
-                                       (int)netmask[0], netmask[1], netmask[2], netmask[3]);
-                       MSG_DEBUG("= Gateway [%d.%d.%d.%d]\n",
-                                       (int)gateway[0], gateway[1], gateway[2], gateway[3]);
-                       MSG_DEBUG("= DNS address [%d.%d.%d.%d]\n",
-                                       (int)dns1[0], dns1[1], dns1[2], dns1[3]);
-                       MSG_DEBUG("= DNS2 address [%d.%d.%d.%d]\n",
-                                       (int)dns2[0], dns2[1], dns2[2], dns2[3]);
-                       MSG_DEBUG("= Device name [%s]\n", dev_info->DevName);
-                       MSG_DEBUG("= Profile name [%s]\n", dev_info->ProfileName);
-               } else {
-                       MSG_DEBUG("Error!!! Network Configuration Failed %d \n", event_cb->Error);
-               }
-               break;
+       connection_profile_h profile;
+       connection_cellular_state_e state;
+       int err;
 
-               /*Response from Datacom for PDP Activation Request*/
-       case NET_EVENT_OPEN_IND:
-               MSG_DEBUG("Got Open Indication\n");
-               MSG_DEBUG("Received ACTIVATION response: %d \n", event_cb->Error);
-               break;
-       case NET_EVENT_OPEN_RSP:
-               MSG_DEBUG("Got Open RSP\n");
-               MSG_DEBUG("Received ACTIVATION response: %d \n", event_cb->Error);
-               prof_info = (net_profile_info_t *)event_cb->Data;
+       if (result == CONNECTION_ERROR_NONE || result == CONNECTION_ERROR_ALREADY_EXISTS) {
 
-               /*Successful PDP Activation*/
-               if (event_cb->Error == NET_ERR_NONE || event_cb->Error == NET_ERR_ACTIVE_CONNECTION_EXISTS) {
-                       network_print_profile(prof_info);
+               err = connection_get_cellular_state(connection, &state);
 
-                       lock();
+               MSG_DEBUG("connection_get_cellular_state ret [%d], state [%d]", err, state);
 
-                       memcpy(&mmsProfile, prof_info, sizeof(net_profile_info_t));
+               err = connection_get_default_cellular_service_profile(connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profile);
+               if (err != CONNECTION_ERROR_NONE) {
+                       MSG_DEBUG("connection_get_default_cellular_service_profile Failed!! [%d]", err);
+               }
+
+               if (profile) {
                        isCmOpened = true;
-                       signal();
 
-                       unlock();
-               } else {
-                       MSG_DEBUG("Activation Failed %d \n", event_cb->Error); // open failed
-                       lock();
-                       isCmOpened = false;
-                       signal();
-                       unlock();
-               }
-               break;
+                       MMS_FREE(this->home_url);
+                       MMS_FREE(this->interface_name);
+                       MMS_FREE(this->proxy_address);
 
-       case NET_EVENT_CLOSE_RSP:
-               MSG_DEBUG("Got Close RSP\n");
+                       err = connection_profile_get_cellular_home_url(profile, &this->home_url);
+                       err = connection_profile_get_network_interface_name(profile, &this->interface_name);
+                       err = connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &this->proxy_address);
 
-               lock();
+                       __connection_profile_print(profile);
 
-               bzero(&mmsProfile, sizeof(net_profile_info_t));
-               isCmOpened = false;
-               signal();
-
-               unlock();
-               break;
-
-       case NET_EVENT_CLOSE_IND:
-               MSG_DEBUG("Got Close IND\n");
-               break;
-       case NET_EVENT_PROFILE_MODIFY_IND:
-               MSG_DEBUG("Received Profile modified Indication\n");
-               MSG_DEBUG("No. of profile [%d]\n", event_cb->Datalength);
-               break;
-       case NET_EVENT_NET_STATE_IND:
-               MSG_DEBUG("Received NET_EVENT_NET_STATE_IND\n");
-               break;
-       default :
-               MSG_DEBUG("Error! Unknown Event = %d\n\n", event_cb->Event);
-               break;
+                       connection_profile_destroy(profile);
+               }
+
+       } else {
+               MSG_DEBUG("connection open profile Failed!! [%d]", result);
        }
 
-       MSG_END();
-}
+       MSG_DEBUG("## SIGNAL ##");
+       signal();
 
+       unlock();
+}
 
-bool MmsPluginCmAgent::getDeviceName(char *deviceName)
+void MmsPluginCmAgent::close_callback(connection_error_e result, void* user_data)
 {
-       if (!isCmOpened)
-               return false;
+       lock();
 
-       int deviceNameLength = strlen(mmsProfile.ProfileInfo.Pdp.net_info.DevName);
+       MMS_FREE(this->home_url);
+       MMS_FREE(this->interface_name);
+       MMS_FREE(this->proxy_address);
 
-       if (deviceNameLength > 0) {
-               strncpy(deviceName, mmsProfile.ProfileInfo.Pdp.net_info.DevName, deviceNameLength);
-               deviceName[deviceNameLength] = '\0';
-               return true;
-       }
+       isCmOpened = false;
+       MSG_DEBUG("## SIGNAL ##");
+       signal();
 
-       return false;
+       unlock();
 }
 
-
-bool MmsPluginCmAgent::getHomeURL(char *homeURL)
+bool MmsPluginCmAgent::getInterfaceName(const char **deviceName)
 {
        if (!isCmOpened)
                return false;
 
-       int homeURLLength = strlen(mmsProfile.ProfileInfo.Pdp.HomeURL);
+       if (deviceName == NULL)
+               return false;
 
-       if (homeURLLength > 0) {
-               strncpy(homeURL, mmsProfile.ProfileInfo.Pdp.HomeURL, homeURLLength);
-               homeURL[homeURLLength] = '\0';
-               return true;
-       }
+       *deviceName = interface_name;
 
-       return false;
+       return true;
 }
 
-
-bool MmsPluginCmAgent::getProxyAddr(char *proxyAddr)
+bool MmsPluginCmAgent::getHomeUrl(const char **homeURL)
 {
        if (!isCmOpened)
                return false;
 
-       int proxyAddrLength = strlen(mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr);
-
-       if (proxyAddrLength > 0) {
-               if (strchr(mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr, ':') == NULL)
-                       return false;
+       if (homeURL == NULL)
+               return false;
 
-               proxyAddrLength = proxyAddrLength - strlen(strchr(mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr, ':'));
-               strncpy(proxyAddr, mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr, proxyAddrLength);
-               proxyAddr[proxyAddrLength] = '\0';
+       *homeURL = home_url;
 
-               return true;
-       }
-
-       return false;
+       return true;
 }
 
 
-int MmsPluginCmAgent::getProxyPort()
+bool MmsPluginCmAgent::getProxyAddr(const char **proxyAddr)
 {
        if (!isCmOpened)
-               return -1;
+               return false;
 
-       int proxyAddrLength = strlen(mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr);
+       if (proxyAddr == NULL)
+               return false;
 
-       if (proxyAddrLength > 0) {
-               char *pPort = strchr(mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr, ':') + 1;
-               /* pPort cannot be NULL */
-               return atoi(pPort);
-       }
+       *proxyAddr = proxy_address;
 
-       return -1;
+       return true;
 }
-
index 3b66c0a..b7851f9 100755 (executable)
@@ -130,7 +130,7 @@ static char *__MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue
 #ifndef        __SUPPORT_DRM__
 static bool __MsgMakeFileName(int iMsgType, char *szFileName, int nUntitleIndex);
 #else
-static bool __MsgMakeFileName(int iMsgType, char *szFileName, MsgDrmType drmType, int nUntitleIndex);
+static bool __MsgMakeFileName(int iMsgType, char *szFileName, MsgDrmType drmType, int nUntitleIndex, char *outBuf, int outBufLen);
 #endif
 
 static bool __MmsDebugPrintMulitpartEntry(MsgMultipart *pMultipart, int index);
@@ -147,7 +147,7 @@ static int gMmsDecodeBufLen = 0;            /* number of last read characters */
 static char *gpMmsDecodeBuf1 = NULL;
 static char *gpMmsDecodeBuf2 = NULL;
 
-MmsHeader      mmsHeader =
+__thread MmsHeader     mmsHeader =
 {
        false,                                                                  //bActive
        NULL,                                                                   //pszOwner
@@ -378,6 +378,7 @@ static bool __MmsBinaryDecodeCheckAndDecreaseLength(int *pLength, int valueLengt
  */
 bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
 {
+       MSG_BEGIN();
        UINT16 fieldCode = 0xffff;
        UINT16 fieldValue = 0xffff;
        UINT8 oneByte = 0xff;
@@ -397,14 +398,14 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
        char *pLimitData = NULL;
        int nRead = 0;
 
-       MSG_DEBUG("pFile=%d, total len=%d\n", pFile, totalLength);
+       MSG_DEBUG("pFile ptr : [%p], total len = [%d]", pFile, totalLength);
 
        __MmsCleanDecodeBuff();
 
        if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos,
                                                                   &gMmsDecodeCurOffset, gpMmsDecodeBuf1, gpMmsDecodeBuf2,
                                                                   gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-               MSG_DEBUG("fail to load to buffer \n");
+               MSG_FATAL("fail to load to buffer");
                goto __CATCH;
        }
 
@@ -415,7 +416,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                case MMS_CODE_RESPONSESTATUS:
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("responseStatus GetOneByte fail\n");
+                               MSG_DEBUG("responseStatus GetOneByte fail");
                                goto __CATCH;
                        }
 
@@ -427,34 +428,29 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                fieldValue = 0x0060;
                        }
 
-                       MSG_DEBUG("response status code = 0x%02x", oneByte);
-
                        fieldValue = MmsGetBinaryType(MmsCodeResponseStatus, (UINT16)(oneByte & 0x7F));
 
                        if (fieldValue == 0xFFFF) {
-                               MSG_DEBUG("responseStatus error\n");
+                               MSG_DEBUG("responseStatus error");
                                goto __CATCH;
                        }
 
                        mmsHeader.responseStatus = (MmsResponseStatus)fieldValue;
 
-                       MSG_DEBUG("response status text = %s\n", MmsDebugGetResponseStatus(mmsHeader.responseStatus));
-
+                       MSG_DEBUG("X-Mms-Response-Status = [0x%02x][%s]", oneByte, MmsDebugGetResponseStatus(mmsHeader.responseStatus));
                        break;
 
                case MMS_CODE_RETRIEVESTATUS:
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("retrieveStatus GetOneByte fail\n");
+                               MSG_DEBUG("retrieveStatus GetOneByte fail");
                                goto __CATCH;
                        }
 
-                       MSG_DEBUG("retrieve status code = 0x%02x", oneByte);
-
                        fieldValue = MmsGetBinaryType(MmsCodeRetrieveStatus, (UINT16)(oneByte & 0x7F));
 
                        if (fieldValue == 0xFFFF) {
-                               MSG_DEBUG("retrieveStatus error\n");
+                               MSG_DEBUG("retrieveStatus error");
                                goto __CATCH;
                        }
 
@@ -466,38 +462,38 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
 
                        mmsHeader.retrieveStatus = (MmsRetrieveStatus)fieldValue;
 
-                       MSG_DEBUG("retrieve status = %s\n", MmsDebugGetRetrieveStatus(mmsHeader.retrieveStatus));
+                       MSG_DEBUG("X-Mms-Retrieve-Status = [0x%02x][%s]", oneByte, MmsDebugGetRetrieveStatus(mmsHeader.retrieveStatus));
 
                        break;
 
                case MMS_CODE_RESPONSETEXT:
 
                        if (__MmsBinaryDecodeEncodedString(pFile, mmsHeader.szResponseText, MMS_LOCALE_RESP_TEXT_LEN + 1, totalLength) == false) {
-                               MSG_DEBUG("invalid MMS_CODE_RESPONSETEXT \n");
+                               MSG_DEBUG("invalid MMS_CODE_RESPONSETEXT");
                                goto __CATCH;
                        }
 
-                       MSG_DEBUG("response text = %s\n", mmsHeader.szResponseText);
+                       MSG_DEBUG("X-Mms-Response-Text = [%s]", mmsHeader.szResponseText);
                        break;
 
                case MMS_CODE_RETRIEVETEXT:
 
                        if (__MmsBinaryDecodeEncodedString(pFile, mmsHeader.szRetrieveText, MMS_LOCALE_RESP_TEXT_LEN + 1, totalLength) == false) {
-                               MSG_DEBUG("invalid MMS_CODE_RETRIEVETEXT \n");
+                               MSG_DEBUG("invalid MMS_CODE_RETRIEVETEXT");
                                goto __CATCH;
                        }
 
-                       MSG_DEBUG("retrieve text = %s\n", mmsHeader.szRetrieveText);
+                       MSG_DEBUG("X-Mms-Retrieve-Text = [%s]", mmsHeader.szRetrieveText);
                        break;
 
                case MMS_CODE_MSGID:
 
                        if (__MmsBinaryDecodeText(pFile, mmsHeader.szMsgID, MMS_MSG_ID_LEN + 1, totalLength) < 0) {
-                               MSG_DEBUG("MMS_CODE_MSGID is invalid\n");
+                               MSG_DEBUG("MMS_CODE_MSGID is invalid");
                                goto __CATCH;
                        }
 
-                       MSG_DEBUG("msg id = %s\n", mmsHeader.szMsgID);
+                       MSG_DEBUG("Message-ID =[%s]", mmsHeader.szMsgID);
 
                        if (MsgStrlen (mmsHeader.szMsgID) > 2)
                                __MsgMIMERemoveQuote (mmsHeader.szMsgID);
@@ -507,19 +503,19 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                case MMS_CODE_SUBJECT:
 
                        if (__MmsBinaryDecodeEncodedString(pFile, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN + 1, totalLength) == false) {
-                               MSG_DEBUG("invalid MMS_CODE_SUBJECT \n");
+                               MSG_DEBUG("invalid MMS_CODE_SUBJECT");
                                goto __CATCH;
                        }
 
                        pLimitData = (char *)malloc(MSG_LOCALE_SUBJ_LEN + 1);
 
                        if (pLimitData == NULL) {
-                               MSG_DEBUG("pLimitData malloc fail \n");
+                               MSG_DEBUG("pLimitData malloc fail");
                                goto __CATCH;
                        }
 
                        nRead = __MsgCutUTFString((unsigned char*)pLimitData, MSG_LOCALE_SUBJ_LEN + 1, (unsigned char*)mmsHeader.szSubject, MSG_SUBJ_LEN);
-                       MSG_DEBUG("Subject edit.. \n");
+                       MSG_DEBUG("Subject edit..");
 
                        if (nRead > MSG_LOCALE_SUBJ_LEN) {
                                memset(mmsHeader.szSubject, 0 , sizeof(mmsHeader.szSubject));
@@ -534,7 +530,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                pLimitData = NULL;
                        }
 
-                       MSG_DEBUG("subject = %s\n", mmsHeader.szSubject);
+                       MSG_DEBUG("Subject = [%s]", mmsHeader.szSubject);
                        break;
 
                case MMS_CODE_FROM:
@@ -542,12 +538,12 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                        /* Value-length (Address-present-token Encoded-string-value | Insert-address-token) */
 
                        if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
-                               MSG_DEBUG("MMS_CODE_FROM is invalid\n");
+                               MSG_DEBUG("MMS_CODE_FROM is invalid");
                                goto __CATCH;
                        }
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("MMS_CODE_FROM GetOneByte fail\n");
+                               MSG_DEBUG("MMS_CODE_FROM GetOneByte fail");
                                goto __CATCH;
                        }
 
@@ -559,7 +555,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                if (valueLength > 0) {
                                        mmsHeader.pFrom = __MmsDecodeEncodedAddress(pFile, totalLength);
                                        if (mmsHeader.pFrom == NULL) {
-                                               MSG_DEBUG("MMS_CODE_FROM __MmsDecodeEncodedAddress fail\n");
+                                               MSG_DEBUG("MMS_CODE_FROM __MmsDecodeEncodedAddress fail");
                                                goto __CATCH;
                                        }
                                } else {
@@ -578,14 +574,14 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                        mmsHeader.pFrom->pNext = NULL;
                                }
 
-                               MSG_DEBUG("from = %s\n", mmsHeader.pFrom->szAddr);
+                               MSG_DEBUG("From = [%s]", mmsHeader.pFrom->szAddr);
                                // DRM_TEMPLATE - end
                        } else if (oneByte == (MmsGetBinaryValue(MmsCodeAddressType, MMS_INSERT_ADDRESS_TOKEN)|0x80)) {
                                /* Present Token only */
-                               MSG_DEBUG("MMS_CODE_FROM insert token\n");
+                               MSG_DEBUG("From = [insert token]");
                        } else {
                                /* from data broken */
-                               MSG_DEBUG("from addr broken\n");
+                               MSG_DEBUG("from addr broken");
                                gCurMmsDecodeBuffPos--;
                                goto __CATCH;
                        }
@@ -595,7 +591,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
 
                        pAddr = __MmsDecodeEncodedAddress(pFile, totalLength);
                        if (pAddr == NULL) {
-                               MSG_DEBUG("MMS_CODE_TO __MmsDecodeEncodedAddress fail\n");
+                               MSG_DEBUG("MMS_CODE_TO __MmsDecodeEncodedAddress fail");
                                goto __CATCH;
                        }
 
@@ -608,14 +604,14 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                pLastTo = pAddr;
                        }
 
-                       MSG_DEBUG("to = %s\n", mmsHeader.pTo->szAddr);
+                       MSG_DEBUG("To = [%s]", mmsHeader.pTo->szAddr);
                        break;
 
                case MMS_CODE_BCC:
 
                        pAddr = __MmsDecodeEncodedAddress(pFile, totalLength);
                        if (pAddr == NULL) {
-                               MSG_DEBUG("MMS_CODE_BCC __MmsDecodeEncodedAddress fail\n");
+                               MSG_DEBUG("MMS_CODE_BCC __MmsDecodeEncodedAddress fail");
                                goto __CATCH;
                        }
 
@@ -628,14 +624,14 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                pLastBcc = pAddr;
                        }
 
-                       MSG_DEBUG("bcc = %s\n", mmsHeader.pBcc->szAddr);
+                       MSG_DEBUG("Bcc = [%s]", mmsHeader.pBcc->szAddr);
                        break;
 
                case MMS_CODE_CC:
 
                        pAddr = __MmsDecodeEncodedAddress(pFile, totalLength);
                        if (pAddr == NULL) {
-                               MSG_DEBUG("MMS_CODE_CC __MmsDecodeEncodedAddress fail\n");
+                               MSG_DEBUG("MMS_CODE_CC __MmsDecodeEncodedAddress fail");
                                goto __CATCH;
                        }
 
@@ -647,44 +643,45 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                        pLastCc->pNext = pAddr;
                                pLastCc = pAddr;
                        }
-                       MSG_DEBUG("cc = %s\n", mmsHeader.pCc->szAddr);
+                       MSG_DEBUG("Cc = [%s]", mmsHeader.pCc->szAddr);
                        break;
 
                case MMS_CODE_CONTENTLOCATION:
 
                        if (__MmsBinaryDecodeText(pFile, mmsHeader.szContentLocation, MMS_LOCATION_LEN + 1, totalLength) < 0) {
-                               MSG_DEBUG("MMS_CODE_CONTENTLOCATION is invalid\n");
+                               MSG_DEBUG("MMS_CODE_CONTENTLOCATION is invalid");
                                goto __CATCH;
                        }
-                       MSG_DEBUG("content location = %s\n", mmsHeader.szContentLocation);
+                       MSG_DEBUG("X-Mms-Content-Location = [%s]", mmsHeader.szContentLocation);
                        break;
 
                case MMS_CODE_DATE:
 
                        if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.date, totalLength) == false) {
-                               MSG_DEBUG("MMS_CODE_DATE is invalid\n");
+                               MSG_DEBUG("MMS_CODE_DATE is invalid");
                                goto __CATCH;
                        }
-                       MSG_DEBUG("date = %d\n", mmsHeader.date);
+
+                       MSG_DEBUG("Date = [%u]", mmsHeader.date);
                        break;
 
                case MMS_CODE_DELIVERYREPORT:
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("deliveryReport GetOneByte fail\n");
+                               MSG_DEBUG("deliveryReport GetOneByte fail");
                                goto __CATCH;
                        }
 
                        fieldValue = MmsGetBinaryType(MmsCodeDeliveryReport, (UINT16)(oneByte & 0x7F));
 
                        if (fieldValue == 0xFFFF) {
-                               MSG_DEBUG("deliveryReport error\n");
+                               MSG_DEBUG("deliveryReport error");
                                goto __CATCH;
                        }
 
                        mmsHeader.deliveryReport = (MmsReport)fieldValue;
 
-                       MSG_DEBUG("delivery report=%s\n", MmsDebugGetMmsReport(mmsHeader.deliveryReport));
+                       MSG_DEBUG("X-Mms-Delivery-Report =[0x%02x][%s]", oneByte, MmsDebugGetMmsReport(mmsHeader.deliveryReport));
                        break;
 
                case MMS_CODE_DELIVERYTIME:
@@ -692,12 +689,12 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                        /* value_length (absolute-token Long-integer | Relative-token Long-integer) */
 
                        if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
-                               MSG_DEBUG("invalid MMS_CODE_DELIVERYTIME \n");
+                               MSG_DEBUG("invalid MMS_CODE_DELIVERYTIME");
                                goto __CATCH;
                        }
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("delivery time GetOneByte fail\n");
+                               MSG_DEBUG("delivery time GetOneByte fail");
                                goto __CATCH;
                        }
 
@@ -709,7 +706,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
 
                                if (valueLength > 0) {
                                        if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.deliveryTime.time, totalLength) == false) {
-                                               MSG_DEBUG("invalid MMS_CODE_DELIVERYTIME\n");
+                                               MSG_DEBUG("invalid MMS_CODE_DELIVERYTIME");
                                                goto __CATCH;
                                        }
                                }
@@ -718,11 +715,11 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                mmsHeader.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
 
                                if (__MmsBinaryDecodeInteger(pFile, (UINT32*)&mmsHeader.deliveryTime.time, &tmpIntLen, totalLength) == false) {
-                                       MSG_DEBUG("__MmsBinaryDecodeInteger fail...\n");
+                                       MSG_DEBUG("__MmsBinaryDecodeInteger fail...");
                                        goto __CATCH;
                                }
                        }
-                       MSG_DEBUG("delivery type=%d, time=%d\n", mmsHeader.deliveryTime.type, mmsHeader.deliveryTime.time);
+                       MSG_DEBUG("X-Mms-Delivery-Time : type = [%d], time= [%u]", mmsHeader.deliveryTime.type, mmsHeader.deliveryTime.time);
                        break;
 
                case MMS_CODE_EXPIRYTIME:
@@ -730,12 +727,12 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                        /* value_length(absolute-token Long-integer | Relative-token Long-integer) */
 
                        if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
-                               MSG_DEBUG("invalid MMS_CODE_EXPIRYTIME \n");
+                               MSG_DEBUG("invalid MMS_CODE_EXPIRYTIME");
                                goto __CATCH;
                        }
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("expiry time GetOneByte fail\n");
+                               MSG_DEBUG("expiry time GetOneByte fail");
                                goto __CATCH;
                        }
 
@@ -747,7 +744,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
 
                                if (valueLength > 0) {
                                        if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.expiryTime.time, totalLength) == false) {
-                                               MSG_DEBUG("MMS_CODE_EXPIRYTIME is invalid\n");
+                                               MSG_DEBUG("MMS_CODE_EXPIRYTIME is invalid");
                                                goto __CATCH;
                                        }
                                }
@@ -756,11 +753,12 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                mmsHeader.expiryTime.type = MMS_TIMETYPE_RELATIVE;
 
                                if (__MmsBinaryDecodeInteger(pFile, (UINT32*)&mmsHeader.expiryTime.time, &tmpIntLen, totalLength) == false) {
-                                       MSG_DEBUG("__MmsBinaryDecodeInteger fail...\n");
+                                       MSG_DEBUG("__MmsBinaryDecodeInteger fail...");
                                        goto __CATCH;
                                }
                        }
-                       MSG_DEBUG("expiry = %d\n", mmsHeader.expiryTime.time);
+
+                       MSG_DEBUG("X-Mms-Expiry : type = [%d], time = [%u]", mmsHeader.expiryTime.type, mmsHeader.expiryTime.time);
                        break;
 
                case MMS_CODE_MSGCLASS:
@@ -768,7 +766,7 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                        /* Class-value = Class-identifier | Token Text */
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("msgClass GetOneByte fail\n");
+                               MSG_DEBUG("msgClass GetOneByte fail");
                                goto __CATCH;
                        }
 
@@ -777,101 +775,103 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                                mmsHeader.msgClass = (MmsMsgClass)MmsGetBinaryType(MmsCodeMsgClass, (UINT16)(oneByte & 0x7F));
                        } else {
                                if (__MmsBinaryDecodeText(pFile, szGarbageBuff, MSG_STDSTR_LONG, totalLength) < 0) {
-                                       MSG_DEBUG("1. __MmsBinaryDecodeText fail. (class)\n");
+                                       MSG_DEBUG("1. __MmsBinaryDecodeText fail. (class)");
                                        goto __CATCH;
                                }
                        }
-                       MSG_DEBUG("msg class=%s\n", MmsDebugGetMsgClass(mmsHeader.msgClass));
+
+                       MSG_DEBUG("X-Mms-Message-Class =[%s]", MmsDebugGetMsgClass(mmsHeader.msgClass));
                        break;
 
                case MMS_CODE_MSGSIZE:
 
                        if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.msgSize, totalLength) == false) {
-                               MSG_DEBUG("MMS_CODE_MSGSIZE is invalid\n");
+                               MSG_DEBUG("MMS_CODE_MSGSIZE is invalid");
                                goto __CATCH;
                        }
-                       MSG_DEBUG("msg size = %d\n", mmsHeader.msgSize);
+
+                       MSG_DEBUG("X-Mms-Message-Size = [%d]", mmsHeader.msgSize);
                        break;
 
                case MMS_CODE_MSGSTATUS:
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("msgStatus GetOneByte fail\n");
+                               MSG_DEBUG("msgStatus GetOneByte fail");
                                goto __CATCH;
                        }
 
                        mmsHeader.msgStatus =  (msg_delivery_report_status_t)MmsGetBinaryType(MmsCodeMsgStatus, (UINT16)(oneByte & 0x7F));
-                       MSG_DEBUG("msg status=%s \n", MmsDebugGetMsgStatus(mmsHeader.msgStatus)) ;
+                       MSG_DEBUG("X-Mms-Status = [%s]", MmsDebugGetMsgStatus(mmsHeader.msgStatus));
                        break;
 
                case MMS_CODE_MSGTYPE:
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("msgStatus GetOneByte fail\n");
+                               MSG_DEBUG("msgStatus GetOneByte fail");
                                goto __CATCH;
                        }
 
                        mmsHeader.type = (MmsMsgType)MmsGetBinaryType(MmsCodeMsgType, (UINT16)(oneByte & 0x7F));
-                       MSG_DEBUG("msg type=%s\n", MmsDebugGetMsgType(mmsHeader.type));
+                       MSG_DEBUG("X-Mms-Message-Type = [%s]", MmsDebugGetMsgType(mmsHeader.type));
                        break;
 
                case MMS_CODE_PRIORITY:
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("msgStatus GetOneByte fail\n");
+                               MSG_DEBUG("msgStatus GetOneByte fail");
                                goto __CATCH;
                        }
                        mmsHeader.priority = (MmsPriority)MmsGetBinaryType(MmsCodePriority, (UINT16)(oneByte & 0x7F));
-                       MSG_DEBUG("priority=%d\n", mmsHeader.priority);
+                       MSG_DEBUG("X-Mms-Priority = [%d]", mmsHeader.priority);
                        break;
 
                case MMS_CODE_READREPLY:
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("msgStatus GetOneByte fail\n");
+                               MSG_DEBUG("msgStatus GetOneByte fail");
                                goto __CATCH;
                        }
                        mmsHeader.readReply = (MmsReport)MmsGetBinaryType(MmsCodeReadReply, (UINT16)(oneByte & 0x7F));
-                       MSG_DEBUG("read reply=%s \n", MmsDebugGetMmsReport(mmsHeader.readReply));
+                       MSG_DEBUG("X-Mms-Read-Report = [0x%02x][%s]", oneByte, MmsDebugGetMmsReport(mmsHeader.readReply));
                        break;
 
                case MMS_CODE_REPORTALLOWED:
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("msgStatus GetOneByte fail\n");
+                               MSG_DEBUG("msgStatus GetOneByte fail");
                                goto __CATCH;
                        }
                        mmsHeader.reportAllowed =  (MmsReportAllowed)MmsGetBinaryType(MmsCodeReportAllowed, (UINT16)(oneByte & 0x7F));
-                       MSG_DEBUG("mmsHeader.reportAllowed=%d\n", MmsDebugGetMmsReportAllowed(mmsHeader.reportAllowed));
+                       MSG_DEBUG("X-Mms-Report-Allowed = [%d]", MmsDebugGetMmsReportAllowed(mmsHeader.reportAllowed));
                        break;
 
                case MMS_CODE_SENDERVISIBILLITY:
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("msgStatus GetOneByte fail\n");
+                               MSG_DEBUG("msgStatus GetOneByte fail");
                                goto __CATCH;
                        }
                        mmsHeader.hideAddress= (MmsSenderVisible)!(MmsGetBinaryType(MmsCodeSenderVisibility, (UINT16)(oneByte &0x7F)));
-                       MSG_DEBUG("sender visible=%d \n", mmsHeader.hideAddress);
+                       MSG_DEBUG("X-Mms-Sender-Visibility = [%d]", mmsHeader.hideAddress);
                        break;
 
                case MMS_CODE_TRID:
 
                        if (__MmsBinaryDecodeText(pFile, mmsHeader.szTrID, MMS_TR_ID_LEN + 1, totalLength) < 0) {
-                               MSG_DEBUG("Transaction ID Too Long \n");
+                               MSG_DEBUG("Transaction ID Too Long");
                                goto __CATCH;
                        }
-                       MSG_DEBUG("trID = %s\n", mmsHeader.szTrID);
+                       MSG_DEBUG("X-Mms-Transaction-Id = [%s]", mmsHeader.szTrID);
                        break;
 
                case MMS_CODE_VERSION:
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("msgStatus GetOneByte fail\n");
+                               MSG_DEBUG("msgStatus GetOneByte fail");
                                goto __CATCH;
                        }
                        mmsHeader.version = oneByte;
 
-                       MSG_DEBUG("ver = 0x%x\n", mmsHeader.version);
+                       MSG_DEBUG("X-Mms-MMS-Version = [0x%02x]", mmsHeader.version);
                        break;
 
                case MMS_CODE_CONTENTTYPE:
@@ -891,12 +891,12 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                        /* Read-status-value = Read | Deleted without being read */
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("msgStatus GetOneByte fail\n");
+                               MSG_DEBUG("msgStatus GetOneByte fail");
                                goto __CATCH;
                        }
 
                        mmsHeader.readStatus =  (msg_read_report_status_t)MmsGetBinaryType(MmsCodeReadStatus, (UINT16)(oneByte & 0x7F));
-                       MSG_DEBUG("read status=%s\n", MmsDebugGetMmsReadStatus(mmsHeader.readStatus));
+                       MSG_DEBUG("X-Mms-Read-Status = [%s]", MmsDebugGetMmsReadStatus(mmsHeader.readStatus));
                        break;
 
                case MMS_CODE_REPLYCHARGING:
@@ -904,12 +904,12 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                        /* Reply-charging-value = Requested | Requested text only | Accepted | Accepted text only */
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("msgStatus GetOneByte fail\n");
+                               MSG_DEBUG("msgStatus GetOneByte fail");
                                goto __CATCH;
                        }
 
                        mmsHeader.replyCharge.chargeType =  (MmsReplyChargeType)MmsGetBinaryType(MmsCodeReplyCharging, (UINT16)(oneByte & 0x7F));
-                       MSG_DEBUG("mmsHeader.reply charge=%d\n", mmsHeader.replyCharge.chargeType);
+                       MSG_DEBUG("X-Mms-Reply-Charging = [%d]", mmsHeader.replyCharge.chargeType);
                        break;
 
                case MMS_CODE_REPLYCHARGINGDEADLINE:
@@ -917,12 +917,12 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                        /* Reply-charging-deadline-value = Value-length (Absolute-token Date-value | Relative-token Delta-seconds-value) */
 
                        if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
-                               MSG_DEBUG("invalid MMS_CODE_REPLYCHARGINGDEADLINE \n");
+                               MSG_DEBUG("invalid MMS_CODE_REPLYCHARGINGDEADLINE");
                                goto __CATCH;
                        }
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("msgStatus GetOneByte fail\n");
+                               MSG_DEBUG("msgStatus GetOneByte fail");
                                goto __CATCH;
                        }
 
@@ -937,31 +937,33 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
 
                        if (valueLength > 0) {
                                if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.replyCharge.deadLine.time, totalLength) == false) {
-                                       MSG_DEBUG("MMS_CODE_REPLYCHARGINGDEADLINE is invalid\n");
+                                       MSG_DEBUG("MMS_CODE_REPLYCHARGINGDEADLINE is invalid");
                                        goto __CATCH;
                                }
                        }
+
+                       MSG_DEBUG("X-Mms-Reply-Charging-Deadline : type = [%d], time = [%u]", mmsHeader.replyCharge.deadLine.type, mmsHeader.replyCharge.deadLine.time);
                        // DRM_TEMPLATE - end
                        break;
 
                case MMS_CODE_REPLYCHARGINGID:
 
                        /* Reply-charging-ID-value = Text-string */
-
                        if (__MmsBinaryDecodeText(pFile, mmsHeader.replyCharge.szChargeID, MMS_MSG_ID_LEN + 1, totalLength) < 0) {
-                               MSG_DEBUG("1. __MmsBinaryDecodeText fail. (szReplyChargingID)\n");
+                               MSG_DEBUG("1. __MmsBinaryDecodeText fail. (szReplyChargingID)");
                                goto __CATCH;
                        }
+                       MSG_DEBUG("X-Mms-Reply-Charging-ID = [%s]", mmsHeader.replyCharge.szChargeID);
                        break;
 
                case MMS_CODE_REPLYCHARGINGSIZE:
 
                        /* Reply-charging-size-value = Long-integer */
-
                        if (__MmsDecodeLongInteger(pFile, (UINT32*)&mmsHeader.replyCharge.chargeSize, totalLength) == false) {
-                               MSG_DEBUG("MMS_CODE_REPLYCHARGINGSIZE is invalid\n");
+                               MSG_DEBUG("MMS_CODE_REPLYCHARGINGSIZE is invalid");
                                goto __CATCH;
                        }
+                       MSG_DEBUG("X-Mms-Reply-Charging-Size = [%d]", mmsHeader.replyCharge.chargeSize);
                        break;
 
                case MMS_CODE_PREVIOUSLYSENTBY:
@@ -978,17 +980,17 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                         */
 
                        if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
-                               MSG_DEBUG("1. invalid MMS_CODE_PREVIOUSLYSENTBY \n");
+                               MSG_DEBUG("1. invalid MMS_CODE_PREVIOUSLYSENTBY");
                                goto __CATCH;
                        }
 
                        if (__MmsBinaryDecodeInteger(pFile, &tmpInteger, &tmpIntLen, totalLength) == false) {
-                               MSG_DEBUG("2. invalid MMS_CODE_PREVIOUSLYSENTBY \n");
+                               MSG_DEBUG("2. invalid MMS_CODE_PREVIOUSLYSENTBY");
                                goto __CATCH;
                        }
 
                        if (__MmsBinaryDecodeEncodedString(pFile, szGarbageBuff, MSG_STDSTR_LONG, totalLength) == false) {
-                               MSG_DEBUG("invalid MMS_CODE_RETRIEVETEXT \n");
+                               MSG_DEBUG("invalid MMS_CODE_RETRIEVETEXT");
                                goto __CATCH;
                        }
                        break;
@@ -1007,17 +1009,17 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
                         */
 
                        if (__MmsDecodeValueLength(pFile, &valueLength, totalLength) <= 0) {
-                               MSG_DEBUG("1. invalid MMS_CODE_PREVIOUSLYSENTDATE \n");
+                               MSG_DEBUG("1. invalid MMS_CODE_PREVIOUSLYSENTDATE");
                                goto __CATCH;
                        }
 
                        if (__MmsBinaryDecodeInteger(pFile, &tmpInteger, &tmpIntLen, totalLength) == false) {
-                               MSG_DEBUG("2. invalid MS_CODE_PREVIOUSLYSENTDATE \n");
+                               MSG_DEBUG("2. invalid MS_CODE_PREVIOUSLYSENTDATE");
                                goto __CATCH;
                        }
 
                        if (__MmsDecodeLongInteger(pFile, (UINT32*)&tmpInteger, totalLength) == false) {
-                               MSG_DEBUG("3. invalid MMS_CODE_PREVIOUSLYSENTDATE \n");
+                               MSG_DEBUG("3. invalid MMS_CODE_PREVIOUSLYSENTDATE");
                                goto __CATCH;
                        }
                        break;
@@ -1047,11 +1049,11 @@ bool MmsBinaryDecodeMsgHeader(FILE *pFile, int totalLength)
 
                                while ((oneByte < 0x80) && (remainLength > 0)) {
                                        if (__MmsBinaryDecodeCheckAndDecreaseLength(&remainLength, 1) == false) {
-                                               MSG_DEBUG("__MmsBinaryDecodeCheckAndDecreaseLength fail\n");
+                                               MSG_DEBUG("__MmsBinaryDecodeCheckAndDecreaseLength fail");
                                                goto __CATCH;
                                        }
                                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                                               MSG_DEBUG("responseStatus GetOneByte fail\n");
+                                               MSG_DEBUG("responseStatus GetOneByte fail");
                                                goto __CATCH;
                                        }
                                }
@@ -1083,7 +1085,8 @@ __RETURN:
                free(pLastBcc);
        }
 
-       MSG_DEBUG("success\n");
+       MSG_DEBUG("## Decode Header Success ##");
+       MSG_END();
        return true;
 
 
@@ -1101,8 +1104,8 @@ __CATCH:
                free(pLastBcc);
        }
 
-       MSG_DEBUG("failed\n");
-
+       MSG_FATAL("## Decode Header Fail ##");
+       MSG_END();
        return false;
 }
 
@@ -1122,14 +1125,14 @@ bool MmsBinaryDecodeMsgBody(FILE *pFile, char *szFilePath, int totalLength)
        if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos,
                                                                        &gMmsDecodeCurOffset, gpMmsDecodeBuf1, gpMmsDecodeBuf2,
                                                                        gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-               MSG_DEBUG("fail to load to buffer \n");
+               MSG_DEBUG("fail to load to buffer");
                goto __CATCH;
        }
 
        // msg's type [ex] related, mixed, single part (jpg, amr and etc)
        length = __MmsBinaryDecodeContentType(pFile, &mmsHeader.msgType, totalLength);
        if (length == -1) {
-               MSG_DEBUG("MMS_CODE_CONTENTTYPE is fail\n");
+               MSG_DEBUG("MMS_CODE_CONTENTTYPE is fail");
                goto __CATCH;
        }
 
@@ -1148,14 +1151,14 @@ bool MmsBinaryDecodeMsgBody(FILE *pFile, char *szFilePath, int totalLength)
        case MIME_APPLICATION_VND_OMA_DRM_MESSAGE:
        case MIME_APPLICATION_VND_OMA_DRM_CONTENT:
 
-               MSG_DEBUG("Decode multipart\n");
+               MSG_DEBUG("Decode Multipart");
 
                offset = __MmsGetDecodeOffset();
                if (offset >= totalLength)
                        goto __RETURN;
 
                if (__MmsBinaryDecodeMultipart(pFile, szFilePath, &mmsHeader.msgType, &mmsHeader.msgBody, totalLength) == false) {
-                       MSG_DEBUG("MmsBinaryDecodeMultipart is fail.\n");
+                       MSG_DEBUG("MmsBinaryDecodeMultipart is fail.");
                        goto __CATCH;
                }
                break;
@@ -1163,15 +1166,14 @@ bool MmsBinaryDecodeMsgBody(FILE *pFile, char *szFilePath, int totalLength)
        default:
 
                /* Single part message ---------------------------------------------- */
-               if (szFilePath != NULL)
-                       strcpy(mmsHeader.msgBody.szOrgFilePath, szFilePath);
+               MSG_DEBUG("Decode Singlepart");
 
                offset = __MmsGetDecodeOffset();
                if (offset >= totalLength)
                        goto __RETURN;
 
                if (__MmsBinaryDecodePartBody(pFile, totalLength - mmsHeader.msgBody.offset, totalLength) == false) {
-                       MSG_DEBUG("MmsBinaryDecodePartBody is fail.(Single Part)\n");
+                       MSG_DEBUG("MmsBinaryDecodePartBody is fail.(Single Part)");
                        goto __CATCH;
                }
 
@@ -1195,6 +1197,7 @@ __CATCH:
 
 static bool __MmsBinaryDecodeParameter(FILE *pFile, MsgType *pMsgType, int valueLength, int totalLength)
 {
+       MSG_BEGIN();
        UINT8 oneByte = 0;
        int charSetLen = 0;
        char *szTypeString = NULL;
@@ -1210,11 +1213,9 @@ static bool __MmsBinaryDecodeParameter(FILE *pFile, MsgType *pMsgType, int value
         * WAP-230-WSP-20010118-p, Proposed Version 18 January 2001 (pp.107)
         */
 
-       MSG_BEGIN();
-
        while (valueLength > 0) {
                if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                       MSG_DEBUG("paramCode _MmsBinaryDecodeGetOneByte fail\n");
+                       MSG_DEBUG("paramCode _MmsBinaryDecodeGetOneByte fail");
                        goto __CATCH;
                }
 
@@ -1225,7 +1226,7 @@ static bool __MmsBinaryDecodeParameter(FILE *pFile, MsgType *pMsgType, int value
                case 0x81: // charset
 
                        if (__MmsBinaryDecodeCharset(pFile, (UINT32*)&(pMsgType->param.charset), &charSetLen, totalLength) == false) {
-                               MSG_DEBUG("MmsBinaryDecodeContentType : __MmsBinaryDecodeCharset fail.\n");
+                               MSG_DEBUG("__MmsBinaryDecodeCharset fail.");
                                goto __CATCH;
                        }
 
@@ -1241,7 +1242,7 @@ static bool __MmsBinaryDecodeParameter(FILE *pFile, MsgType *pMsgType, int value
                                                                                         MSG_FILENAME_LEN_MAX -5,               // MSG_LOCALE_FILENAME_LEN_MAX + 1, :  change @ 110(Ui code have to change for this instead of DM)
                                                                                         totalLength);
                        if (length < 0) {
-                               MSG_DEBUG("MmsBinaryDecodeContentType : __MmsDecodeGetFilename fail. (name parameter)\n");
+                               MSG_DEBUG("__MmsDecodeGetFilename fail. (name parameter)");
                                goto __CATCH;
                        }
 
@@ -1259,7 +1260,7 @@ static bool __MmsBinaryDecodeParameter(FILE *pFile, MsgType *pMsgType, int value
                        memset(pMsgType->param.szFileName, 0, sizeof(pMsgType->param.szFileName));
                        length = __MmsDecodeGetFilename(pFile, pMsgType->param.szFileName, MSG_FILENAME_LEN_MAX -5, totalLength);
                        if (length < 0) {
-                               MSG_DEBUG("MmsBinaryDecodeContentType : __MmsDecodeGetFilename fail. (filename parameter)\n");
+                               MSG_DEBUG("__MmsDecodeGetFilename fail. (filename parameter)");
                                goto __CATCH;
                        }
 
@@ -1275,7 +1276,7 @@ static bool __MmsBinaryDecodeParameter(FILE *pFile, MsgType *pMsgType, int value
                case 0x89: //type = Constrained-encoding = Extension-Media | Short-integer
 
                        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                               MSG_DEBUG("type _MmsBinaryDecodeGetOneByte fail\n");
+                               MSG_DEBUG("type _MmsBinaryDecodeGetOneByte fail");
                                goto __CATCH;
                        }
 
@@ -1341,7 +1342,7 @@ static bool __MmsBinaryDecodeParameter(FILE *pFile, MsgType *pMsgType, int value
                default:
 
                        if (paramCode > 0x7F) {
-                               MSG_DEBUG("Unsupported parameter\n");
+                               MSG_DEBUG("Unsupported parameter");
 
                                // In case of the last byte of Parameter field, it should be returned without decreasing the gCurMmsDecodeBuffPos value.
                                valueLength++;
@@ -1425,10 +1426,11 @@ __RETURN:
                szTypeString = NULL;
        }
 
+       MSG_END();
        return true;
 
 __CATCH:
-
+       MSG_END();
        return false;
 }
 
@@ -1441,6 +1443,7 @@ __CATCH:
  */
 static int __MmsBinaryDecodeContentType(FILE *pFile, MsgType *pMsgType, int totalLength)
 {
+       MSG_BEGIN();
        UINT8 oneByte = 0;
        char *szTypeString = NULL;
        int valueLength = 0;
@@ -1458,8 +1461,6 @@ static int __MmsBinaryDecodeContentType(FILE *pFile, MsgType *pMsgType, int tota
         * Media-type                   = (Well-known-media | Extension-Media) *(Parameter)
         */
 
-       MSG_DEBUG("decoding content type..\n");
-
        length = __MmsDecodeValueLength(pFile, (UINT32*)&valueLength, totalLength);
        if (length <= 0) {
                /*
@@ -1470,7 +1471,7 @@ static int __MmsBinaryDecodeContentType(FILE *pFile, MsgType *pMsgType, int tota
                 */
 
                if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                       MSG_DEBUG("Constrained-media _MmsBinaryDecodeGetOneByte fail\n");
+                       MSG_DEBUG("Constrained-media _MmsBinaryDecodeGetOneByte fail");
                        goto __CATCH;
                }
 
@@ -1513,7 +1514,7 @@ static int __MmsBinaryDecodeContentType(FILE *pFile, MsgType *pMsgType, int tota
                length += valueLength;
 
                if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                       MSG_DEBUG("Well-known-media _MmsBinaryDecodeGetOneByte fail\n");
+                       MSG_DEBUG("Well-known-media _MmsBinaryDecodeGetOneByte fail");
                        goto __CATCH;
                }
 
@@ -1536,18 +1537,19 @@ static int __MmsBinaryDecodeContentType(FILE *pFile, MsgType *pMsgType, int tota
                        }
                }
 
-               MSG_DEBUG("content type=%s\n", MmsDebugGetMimeType((MimeType)pMsgType->type));
-
+               MSG_DEBUG("Content-Type = [%s]", MmsDebugGetMimeType((MimeType)pMsgType->type));
 
                if (__MmsBinaryDecodeParameter(pFile, pMsgType, valueLength, totalLength) == false) {
-                       MSG_DEBUG("Content-Type parameter fail\n");
+                       MSG_DEBUG("Content-Type parameter fail");
                        goto __CATCH;
                }
        }
 
+       MSG_END();
        return length;
 
 __CATCH:
+       MSG_END();
        return -1;
 }
 
@@ -1582,7 +1584,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
 
        while (headerLen > 0) {
                if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                       MSG_DEBUG("field code GetOneByte fail\n");
+                       MSG_DEBUG("field code GetOneByte fail");
                        goto __CATCH;
                }
 
@@ -1604,7 +1606,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
 
                                length = __MmsBinaryDecodeText(pFile, pLatinBuff, MMS_CONTENT_ID_LEN + 1, totalLength);
                                if (length == -1) {
-                                       MSG_DEBUG("MmsBinaryDecodePartHeader : __MmsBinaryDecodeQuotedString fail.\n");
+                                       MSG_DEBUG("__MmsBinaryDecodeQuotedString fail.");
                                        goto __CATCH;
                                }
 
@@ -1619,7 +1621,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                                textLength = strlen(pLatinBuff);
 
                                if (__MsgLatin2UTF ((unsigned char*)pMsgType->szContentLocation, MMS_CONTENT_ID_LEN + 1, (unsigned char*)pLatinBuff, textLength) < 0) {
-                                       MSG_DEBUG("MsgLatin2UTF fail \n");
+                                       MSG_DEBUG("MsgLatin2UTF fail");
                                        goto __CATCH;
                                }
 
@@ -1642,7 +1644,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                                length = __MmsBinaryDecodeQuotedString(pFile, pLatinBuff, MMS_CONTENT_ID_LEN + 1, totalLength);
 
                                if (length == -1) {
-                                       MSG_DEBUG("MmsBinaryDecodePartHeader : Content-ID __MmsBinaryDecodeQuotedString fail.\n");
+                                       MSG_DEBUG("Content-ID __MmsBinaryDecodeQuotedString fail.");
                                        goto __CATCH;
                                }
 
@@ -1656,7 +1658,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
 
                                textLength = strlen(pLatinBuff);
                                if (__MsgLatin2UTF ((unsigned char*)szContentID, MMS_CONTENT_ID_LEN + 1, (unsigned char*)pLatinBuff, textLength) < 0) {
-                                       MSG_DEBUG("MsgLatin2UTF fail \n");
+                                       MSG_DEBUG("MsgLatin2UTF fail");
                                        goto __CATCH;
                                }
                                free(pLatinBuff);
@@ -1689,7 +1691,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                                }
 
                                if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                                       MSG_DEBUG("Disposition value GetOneByte fail\n");
+                                       MSG_DEBUG("Disposition value GetOneByte fail");
                                        goto __CATCH;
                                }
 
@@ -1700,7 +1702,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                                        pMsgType->disposition = MmsGetBinaryType(MmsCodeMsgDisposition, (UINT16)(oneByte & 0x7F));
 
                                        if (pMsgType->disposition == INVALID_HOBJ) {
-                                               MSG_DEBUG("MmsBinaryDecodePartHeader : Content-Disposition MmsGetBinaryType fail.\n");
+                                               MSG_DEBUG("Content-Disposition MmsGetBinaryType fail.");
                                                pMsgType->disposition = MSG_DISPOSITION_ATTACHMENT;             // default
                                        }
 
@@ -1708,7 +1710,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                                                goto __RETURN;
 
                                        if (__MmsBinaryDecodeParameter(pFile, pMsgType, valueLength, totalLength) == false) {
-                                               MSG_DEBUG("Disposition parameter fail\n");
+                                               MSG_DEBUG("Disposition parameter fail");
                                                goto __CATCH;
                                        }
 
@@ -1726,7 +1728,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
 
 
                                        if (textLength < 0) {
-                                               MSG_DEBUG("MmsBinaryDecodePartHeader : Content-Disposition decodingfail. \n");
+                                               MSG_DEBUG("Content-Disposition decodingfail.");
                                                goto __CATCH;
                                        }
                                        free(pLatinBuff);
@@ -1739,7 +1741,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
 
                                        if (__MmsBinaryDecodeParameter(pFile, pMsgType, valueLength, totalLength) == false)
                                        {
-                                               MSG_DEBUG("Disposition parameter fail\n");
+                                               MSG_DEBUG("Disposition parameter fail");
                                                goto __CATCH;
                                        }
 
@@ -1753,7 +1755,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                        case 0x0B:      //Content-Encoding
 
                                if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                                       MSG_DEBUG("Disposition value GetOneByte fail\n");
+                                       MSG_DEBUG("Disposition value GetOneByte fail");
                                        goto __CATCH;
                                }
 
@@ -1773,7 +1775,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                                        cTemp = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
 
                                        if (cTemp == NULL) {
-                                               MSG_DEBUG("MmsBinaryDecodePartHeader : __MmsBinaryDecodeText2 fail...\n");
+                                               MSG_DEBUG("__MmsBinaryDecodeText2 fail...");
                                                goto __CATCH;
                                        }
 
@@ -1793,7 +1795,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                        case 0x0D:      //Content-Length
 
                                if (__MmsBinaryDecodeInteger(pFile, (UINT32*)&tmpInt, &tmpIntLen, totalLength) == false) {
-                                       MSG_DEBUG("MmsBinaryDecodePartHeader : __MmsBinaryDecodeInteger fail...\n");
+                                       MSG_DEBUG("__MmsBinaryDecodeInteger fail...");
                                        goto __CATCH;
                                }
 
@@ -1804,7 +1806,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
 
                        case 0x30:      //X-Wap-Content-URI skip this value
 
-                               MSG_DEBUG("MmsBinaryDecodePartHeader : X-Wap-Content-URI header.\n");
+                               MSG_DEBUG("X-Wap-Content-URI header.");
                                pLatinBuff = (char *)malloc(MMS_TEXT_LEN);
                                if (pLatinBuff == NULL)
                                        goto __CATCH;
@@ -1812,18 +1814,18 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                                length = __MmsBinaryDecodeText(pFile, pLatinBuff, MMS_TEXT_LEN, totalLength);
 
                                if (length == -1) {
-                                       MSG_DEBUG("MmsBinaryDecodePartHeader : __MmsBinaryDecodeQuotedString fail.\n");
+                                       MSG_DEBUG(" __MmsBinaryDecodeQuotedString fail.");
                                        goto __CATCH;
                                }
 
-                               MSG_DEBUG("MmsBinaryDecodePartHeader : X-Wap-Content-URI header decoded. Value length %d\n", length);
+                               MSG_DEBUG("X-Wap-Content-URI header decoded. Value length %d\n", length);
                                free(pLatinBuff);
                                pLatinBuff = NULL;
 
                                if (__MmsBinaryDecodeCheckAndDecreaseLength(&headerLen, length) == false)
                                        goto __RETURN;
 
-                               MSG_DEBUG("MmsBinaryDecodePartHeader : X-Wap-Content-URI header skipped.\n");
+                               MSG_DEBUG("X-Wap-Content-URI header skipped.");
 
                                break;
 
@@ -1845,7 +1847,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                                        int     charset = 0;
                                        int charSetLen = 0;
 
-                                       MSG_DEBUG("MmsBinaryDecodePartHeader : Accept-charset. \n");
+                                       MSG_DEBUG("Accept-charset.");
 
                                        length = __MmsDecodeValueLength(pFile, &valueLength, totalLength);
                                        if (length > 0) {
@@ -1856,7 +1858,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
 
                                        if (__MmsBinaryDecodeInteger(pFile, (UINT32*)&charset, &charSetLen, totalLength) == false) {
                                                // We only support the well-known-charset format
-                                               MSG_DEBUG("MmsBinaryDecodePartHeader : __MmsBinaryDecodeInteger fail...\n");
+                                               MSG_DEBUG("__MmsBinaryDecodeInteger fail...");
                                                goto __CATCH;
                                        }
 
@@ -1873,11 +1875,11 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
 
                                /* Other Content-xxx headers : Have valueLength */
 
-                               MSG_DEBUG("MmsBinaryDecodePartHeader : unknown Value = 0x%x\n", oneByte);
+                               MSG_DEBUG("unknown Value = 0x%x\n", oneByte);
 
                                length = __MmsDecodeValueLength(pFile, &valueLength, totalLength);
                                if (length <= 0) {
-                                       MSG_DEBUG("MmsBinaryDecodePartHeader : 1. invalid MMS_CODE_PREVIOUSLYSENTDATE \n");
+                                       MSG_DEBUG("invalid MMS_CODE_PREVIOUSLYSENTDATE");
                                        goto __CATCH;
                                }
 
@@ -1889,7 +1891,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                                        goto __CATCH;
 
                                if (__MmsBinaryDecodeGetBytes(pFile, szTemp, valueLength, totalLength) == false) {
-                                       MSG_DEBUG("MmsBinaryDecodePartHeader : default _MmsBinaryDecodeGetBytes() fail\n");
+                                       MSG_DEBUG("default _MmsBinaryDecodeGetBytes() fail");
                                        if (szTemp) {
                                                free(szTemp);
                                                szTemp = NULL;
@@ -1908,7 +1910,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                         * Application-specific-value = Text-string
                         */
 
-                       MSG_DEBUG(" Application-header = Token-text Application-specific-value \n");
+                       MSG_DEBUG(" Application-header = Token-text Application-specific-value");
 
                        gCurMmsDecodeBuffPos--;
 
@@ -1917,7 +1919,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                        textLength = 0;
                        pCode = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
                        if (pCode == NULL) {
-                               MSG_DEBUG("pCode is null\n");
+                               MSG_DEBUG("pCode is null");
                                goto __CATCH;
                        }
 
@@ -1932,7 +1934,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                        textLength = 0;
                        pValue = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
                        if (pValue == NULL) {
-                               MSG_DEBUG("pValue is null\n");
+                               MSG_DEBUG("pValue is null");
                                goto __CATCH;
                        }
 
@@ -1966,7 +1968,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
                                length = strlen(pLatinBuff);
                                if (__MsgLatin2UTF ((unsigned char*)szContentID, MMS_CONTENT_ID_LEN + 1, (unsigned char*)pLatinBuff, length) < 0)
                                {
-                                       MSG_DEBUG("MsgLatin2UTF fail \n");
+                                       MSG_DEBUG("MsgLatin2UTF fail");
                                        goto __CATCH;
                                }
 
@@ -1986,7 +1988,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
 
                                length = strlen(pLatinBuff);
                                if (__MsgLatin2UTF ((unsigned char*)pMsgType->szContentLocation, MMS_CONTENT_ID_LEN + 1, (unsigned char*)pLatinBuff, length) < 0) {
-                                       MSG_DEBUG("MsgLatin2UTF fail \n");
+                                       MSG_DEBUG("MsgLatin2UTF fail");
                                        goto __CATCH;
                                }
 
@@ -2026,12 +2028,7 @@ static bool __MmsBinaryDecodePartHeader(FILE *pFile, MsgType *pMsgType, int head
        }       //while
 
 __RETURN:
-/* DEADCODE
-       if (pLatinBuff) {
-               free(pLatinBuff);
-               pLatinBuff = NULL;
-       }
-*/
+
        if (szTemp) {
                free(szTemp);
                szTemp = NULL;
@@ -2076,7 +2073,7 @@ static bool __MmsBinaryDecodeEntries(FILE *pFile, UINT32 *npEntries, int totalLe
                goto __CATCH;
        }
 
-       MSG_DEBUG("Number of Entries = %d\n", *npEntries);
+       MSG_DEBUG("Number of Entries = [%d]", *npEntries);
 
        return true;
 
@@ -2099,7 +2096,7 @@ static bool __MmsBinaryDecodePartBody(FILE *pFile, UINT32 bodyLength, int totalL
        offset += bodyLength;
 
        if (MsgFseek(pFile, offset, SEEK_SET) < 0) {
-               MSG_DEBUG("fail to seek file pointer \n");
+               MSG_DEBUG("fail to seek file pointer");
                goto __CATCH;
        }
 
@@ -2112,7 +2109,7 @@ static bool __MmsBinaryDecodePartBody(FILE *pFile, UINT32 bodyLength, int totalL
 
        if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
                                                                   gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-               MSG_DEBUG("fail to load to buffer \n");
+               MSG_DEBUG("fail to load to buffer");
                goto __CATCH;
        }
 
@@ -2131,7 +2128,7 @@ static bool __MmsBinaryDecodeMovePointer(FILE *pFile, int offset, int totalLengt
                goto __RETURN;
 
        if (MsgFseek(pFile, offset, SEEK_SET) < 0) {
-               MSG_DEBUG("fail to seek file pointer \n");
+               MSG_DEBUG("fail to seek file pointer");
                goto __CATCH;
        }
 
@@ -2144,7 +2141,7 @@ static bool __MmsBinaryDecodeMovePointer(FILE *pFile, int offset, int totalLengt
 
        if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
                                                                        gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-               MSG_DEBUG("fail to load to buffer \n");
+               MSG_DEBUG("fail to load to buffer");
                goto __CATCH;
        }
 
@@ -2167,33 +2164,33 @@ static bool __MmsBinaryDecodeMultipart(FILE *pFile, char *szFilePath, MsgType *p
        MsgPresentationFactor factor = MSG_PRESENTATION_NONE;
        MsgPresentaionInfo presentationInfo;
 
-       MSG_DEBUG("total length=%d\n", totalLength);
+       MSG_DEBUG("pdu length = [%d]", totalLength);
 
        presentationInfo.factor = MSG_PRESENTATION_NONE;
        presentationInfo.pCurPresentation = NULL;
        presentationInfo.pPrevPart = NULL;
 
        if (__MmsBinaryDecodeEntries(pFile, &nEntries, totalLength) == false) {
-               MSG_DEBUG("MmsBinaryDecodeEntries is fail.\n");
+               MSG_DEBUG("MmsBinaryDecodeEntries is fail.");
                goto __CATCH;
        }
 
        if (pMsgBody->body.pMultipart != NULL) {
                pLastMultipart = pMsgBody->body.pMultipart;
-               MSG_DEBUG("pMsgBody->body.pMultipart exist \n");
+               MSG_DEBUG("previous multipart exist [%p]", pMsgBody->body.pMultipart);
        } else {
-               MSG_DEBUG("pMsgBody->body.pMultipart == NULL\n");
+               MSG_DEBUG("first multipart");
        }
 
        while (nEntries) {
-               MSG_DEBUG("decoding %dth multipart\n", index);
+               MSG_DEBUG("decoding [%d]th multipart", index);
 
                offset = __MmsGetDecodeOffset();
                if (offset >= totalLength)
                        goto __RETURN;
 
                if ((pMultipart = __MsgAllocMultipart()) == NULL) {
-                       MSG_DEBUG("MsgAllocMultipart Fail \n");
+                       MSG_DEBUG("MsgAllocMultipart Fail");
                        goto __CATCH;
                }
 
@@ -2202,16 +2199,20 @@ static bool __MmsBinaryDecodeMultipart(FILE *pFile, char *szFilePath, MsgType *p
                        goto __CATCH;
                }
 
-               if (pMsgType->param.type == MIME_APPLICATION_SMIL) {
+               if (pMultipart->type.type == MIME_APPLICATION_SMIL) {
                        factor = __MsgIsPresentationEx(&(pMultipart->type), pMsgType->param.szStart, (MimeType)pMsgType->param.type);
+                       if (factor == MSG_PRESENTATION_NONE) {
+                               factor = MSG_PRESENTATION_TYPE_BASE;
+                       }
                } else {
                        factor = MSG_PRESENTATION_NONE;
                }
+
                // priority 1 : content type match, 2: content location, 3: type
                if (presentationInfo.factor < factor) {
                        // Presentation part
                        presentationInfo.factor = factor;
-                       presentationInfo.pPrevPart = pPreMultipart;
+                       presentationInfo.pPrevPart = pLastMultipart;
                        presentationInfo.pCurPresentation = pMultipart;
                }
 
@@ -2236,13 +2237,10 @@ static bool __MmsBinaryDecodeMultipart(FILE *pFile, char *szFilePath, MsgType *p
 
        pMsgBody->size = totalLength - pMsgBody->offset;
 
-#ifdef __SUPPORT_DRM__
-       if (MmsDrm2GetConvertState() != MMS_DRM2_CONVERT_REQUIRED)
-#endif
-               __MsgConfirmPresentationPart(pMsgType, pMsgBody, &presentationInfo);
+       __MsgConfirmPresentationPart(pMsgType, pMsgBody, &presentationInfo);
 
        if (__MsgResolveNestedMultipart(pMsgType, pMsgBody) == false) {
-               MSG_DEBUG("MmsBinaryDecodeMultipart : MsgResolveNestedMultipart failed \n");
+               MSG_DEBUG("MsgResolveNestedMultipart failed");
                goto __CATCH;
        }
 
@@ -2271,12 +2269,11 @@ static bool __MmsBinaryDecodeEachPart(FILE *pFile, char *szFilePath, MsgType *pM
        UINT32 bodyLength = 0;
        int offset = 0;
 
-       MSG_DEBUG("MmsBinaryDecodeEachPart: total length=%d\n", totalLength);
+       MSG_DEBUG("pdu length = [%d]", totalLength);
 
        /* header length */
-
        if (__MmsBinaryDecodeUintvar(pFile, &headerLength, totalLength) <= 0) {
-               MSG_DEBUG("MmsBinaryDecodeEachPart: Get header length fail \n");
+               MSG_DEBUG("Get header length fail");
                goto __CATCH;
        }
 
@@ -2284,20 +2281,16 @@ static bool __MmsBinaryDecodeEachPart(FILE *pFile, char *szFilePath, MsgType *pM
        if (offset >= totalLength)
                goto __RETURN;
 
-
        /* body length */
-
        if (__MmsBinaryDecodeUintvar(pFile, &bodyLength, totalLength) <= 0) {
-               MSG_DEBUG("MmsBinaryDecodeEachPart: Get body length fail\n");
+               MSG_DEBUG("Get body length fail");
                goto __CATCH;
        }
 
-
        offset = __MmsGetDecodeOffset();
        if (offset >= totalLength)
                goto __RETURN;
 
-
        /* Content Type */
        if (szFilePath != NULL)
                strncpy(pMsgType->szOrgFilePath, szFilePath, strlen(szFilePath));
@@ -2311,7 +2304,7 @@ static bool __MmsBinaryDecodeEachPart(FILE *pFile, char *szFilePath, MsgType *pM
 
        length = __MmsBinaryDecodeContentType(pFile, pMsgType, totalLength);
        if (length <= 0) {
-               MSG_DEBUG("MmsBinaryDecodeEachPart: Decode contentType Fail \n");
+               MSG_DEBUG("Decode contentType Fail");
                goto __CATCH;
        }
 
@@ -2323,7 +2316,7 @@ static bool __MmsBinaryDecodeEachPart(FILE *pFile, char *szFilePath, MsgType *pM
        /* Part Header */
 
        if (__MmsBinaryDecodePartHeader(pFile, pMsgType, headerLength - length, totalLength) == false) {
-               MSG_DEBUG("MmsBinaryDecodeEachPart: Decode contentHeader Fail \n");
+               MSG_DEBUG("Decode contentHeader Fail");
                goto __CATCH;
        }
 
@@ -2352,10 +2345,9 @@ static bool __MmsBinaryDecodeEachPart(FILE *pFile, char *szFilePath, MsgType *pM
        case MIME_MULTIPART_RELATED:
        case MIME_MULTIPART_ALTERNATIVE:
 
-               MSG_DEBUG("MmsBinaryDecodeEachPart: Decode multipart\n");
-
+               MSG_DEBUG("Multipart");
                if (__MmsBinaryDecodeMultipart(pFile, szFilePath, pMsgType, pMsgBody, totalLength) == false) {
-                       MSG_DEBUG("MmsBinaryDecodeEachPart: MmsBinaryDecodeMultipart is fail.\n");
+                       MSG_DEBUG("MmsBinaryDecodeMultipart is fail");
                        goto __CATCH;
                }
 
@@ -2369,21 +2361,11 @@ static bool __MmsBinaryDecodeEachPart(FILE *pFile, char *szFilePath, MsgType *pM
 #ifdef __SUPPORT_DRM__
 
        case MIME_APPLICATION_VND_OMA_DRM_MESSAGE: /* Contains forwardLock OR combined-delivery media part */
-               MSG_DEBUG("MmsBinaryDecodeEachPart: MIME_APPLICATION_VND_OMA_DRM_MESSAGE Part \n");
-
-               if (MmsDrm2GetConvertState() != MMS_DRM2_CONVERT_NOT_FIXED && MmsDrm2GetConvertState() != MMS_DRM2_CONVERT_REQUIRED) {
+               MSG_DEBUG("MIME_APPLICATION_VND_OMA_DRM_MESSAGE Part");
 
-                       if (__MmsBinaryDecodeDRMContent(pFile, szFilePath, pMsgType, pMsgBody, bodyLength, totalLength) == false)
-                               goto __CATCH;
-               } else {
-                       MmsDrm2SetConvertState(MMS_DRM2_CONVERT_REQUIRED);
+               if (__MmsBinaryDecodeDRMContent(pFile, szFilePath, pMsgType, pMsgBody, bodyLength, totalLength) == false)
+                       goto __CATCH;
 
-                       bSuccess = __MmsBinaryDecodePartBody(pFile, bodyLength, totalLength);
-                       if (bSuccess == false) {
-                               MSG_DEBUG("MmsBinaryDecodeEachPart: Decode contentBody Fail \n");
-                               goto __CATCH;
-                       }
-               }
                offset = __MmsGetDecodeOffset();
                if (offset >= totalLength)
                        goto __RETURN;
@@ -2392,7 +2374,7 @@ static bool __MmsBinaryDecodeEachPart(FILE *pFile, char *szFilePath, MsgType *pM
 
        case MIME_APPLICATION_VND_OMA_DRM_CONTENT: /* Contains seperate-delivery media part (DCF) */
 
-               MSG_DEBUG("MmsBinaryDecodeEachPart: MIME_APPLICATION_VND_OMA_DRM_CONTENT Part \n");
+               MSG_DEBUG("MIME_APPLICATION_VND_OMA_DRM_CONTENT Part");
 
                if (__MmsBinaryDecodeDRMContent(pFile, szFilePath, pMsgType, pMsgBody, bodyLength, totalLength) == false)
                        goto __CATCH;
@@ -2405,11 +2387,11 @@ static bool __MmsBinaryDecodeEachPart(FILE *pFile, char *szFilePath, MsgType *pM
 #endif
 
        default:
-               MSG_DEBUG("MmsBinaryDecodeEachPart: Other normal Part \n");
+               MSG_DEBUG("Normal Part");
 
                bSuccess = __MmsBinaryDecodePartBody(pFile, bodyLength, totalLength);
                if (bSuccess == false) {
-                       MSG_DEBUG("MmsBinaryDecodeEachPart: Decode contentBody Fail \n");
+                       MSG_DEBUG("Decode contentBody Fail");
                        goto __CATCH;
                }
 
@@ -2420,14 +2402,15 @@ static bool __MmsBinaryDecodeEachPart(FILE *pFile, char *szFilePath, MsgType *pM
                break;
        }
 
+       MSG_END();
        return true;
 
 __RETURN:
-
+       MSG_END();
        return true;
 
 __CATCH:
-
+       MSG_END();
        return false;
 }
 
@@ -2453,31 +2436,28 @@ static bool __MmsBinaryDecodeDRMContent(FILE *pFile, char *szFilePath, MsgType *
 
        pRawData = (char *)malloc(bodyLength);
        if (pRawData == NULL) {
-               MSG_DEBUG("pRawData alloc FAIL \n");
+               MSG_DEBUG("pRawData alloc FAIL");
                goto __CATCH;
        }
 
        if (MsgFseek(pFile, offset, SEEK_SET) < 0) {
-               MSG_DEBUG("MsgFseek() returns -1 \n");
+               MSG_DEBUG("MsgFseek() returns -1");
                goto __CATCH;
        }
        if (MsgReadFile(pRawData, sizeof(char), bodyLength, pFile) != (size_t)bodyLength) {
-               MSG_DEBUG("FmReadFile() returns false \n");
+               MSG_DEBUG("FmReadFile() returns false");
                goto __CATCH;
        }
        if (MsgOpenCreateAndOverwriteFile(szTempFilePath, pRawData, bodyLength) == false) {
-               MSG_DEBUG("MsgOpenCreateAndOverwriteFile() returns false \n");
+               MSG_DEBUG("MsgOpenCreateAndOverwriteFile() returns false");
                goto __CATCH;
        }
 
        isFileCreated = true;
-       MSG_DEBUG("MmsDrm2GetConvertState() [%d]", MmsDrm2GetConvertState());
 
-       if (pMsgType->type == MIME_APPLICATION_VND_OMA_DRM_MESSAGE && (MmsDrm2GetConvertState() != MMS_DRM2_CONVERT_FINISH)) {
-               MmsDrm2SetConvertState(MMS_DRM2_CONVERT_REQUIRED);
-       } else {
+       if (pMsgType->type == MIME_APPLICATION_VND_OMA_DRM_MESSAGE) {
                if (MsgDRM2GetDRMInfo(szTempFilePath, pMsgType) == false) {
-                       MSG_DEBUG("MsgDRM2GetDRMInfo() returns false \n");
+                       MSG_DEBUG("MsgDRM2GetDRMInfo() returns false");
                        goto __CATCH;
                }
        }
@@ -2576,7 +2556,7 @@ static int __MmsDrm2GetEntriesValueLength(FILE *pFile, int orgOffset)
        int j = 0;                      //j is the length of nEntries value
 
        if (MsgReadFile(szEntries, sizeof(char), 4, pFile) != (size_t)4) {
-               MSG_DEBUG("__MmsDrm2GetEntriesValueLength: FmReadFile() returns false \n");
+               MSG_DEBUG("FmReadFile() returns false");
                return false;
        }
 
@@ -2589,7 +2569,7 @@ static int __MmsDrm2GetEntriesValueLength(FILE *pFile, int orgOffset)
 
        //move file pointer to point nEntries
        if (MsgFseek(pFile, orgOffset, SEEK_SET) < 0) {
-               MSG_DEBUG("__MmsDrm2GetEntriesValueLength: fail to seek file pointer\n");
+               MSG_DEBUG("fail to seek file pointer");
                return false;
        }
 
@@ -2605,13 +2585,13 @@ static bool __MmsDrm2WriteDataToConvertedFile(FILE *pSrcFile, FILE *pDestination
 
                memset(pszMmsLoadTempBuf, 0, MMS_DRM2_CONVERT_BUFFER_MAX + 1);
 
-               if (MsgReadFile(pszMmsLoadTempBuf, sizeof(char), loadLen, pSrcFile) != (size_t)loadLen) {
-                       MSG_DEBUG("__MmsDrm2WriteDataToConvertedFile: FmReadFile() returns false \n");
-                       return false;
+               nRead = MsgReadFile(pszMmsLoadTempBuf, sizeof(char), loadLen, pSrcFile);
+               if (nRead != (size_t)loadLen) {
+                       MSG_DEBUG("FmReadFile() returns false, nRead = %d, loadLen = %d", nRead, loadLen);
                }
 
-               if (MsgWriteFile(pszMmsLoadTempBuf, sizeof(char), loadLen, pDestinationFile) != (size_t)loadLen) {
-                       MSG_DEBUG("__MmsDrm2WriteDataToConvertedFile: File Writing is failed.\n");
+               if (MsgWriteFile(pszMmsLoadTempBuf, sizeof(char), nRead, pDestinationFile) != (size_t)nRead) {
+                       MSG_DEBUG("File Writing is failed.");
                        return false;
                }
 
@@ -2642,23 +2622,23 @@ bool MmsDrm2ConvertMsgBody(char *szOriginFilePath)
        int bufLen = MMS_DRM2_CONVERT_BUFFER_MAX;
        int curOffset = 0;
 
-       MSG_DEBUG("start convert~~~~~~\n");
+       MSG_DEBUG("start convert~~~~~~");
 
        pFile = MsgOpenFile(szOriginFilePath, "rb");
        if (pFile == NULL) {
-               MSG_DEBUG("Open decode temporary file fail\n");
+               MSG_DEBUG("Open decode temporary file fail");
                goto __CATCH;
        }
 
        hConvertedFile = MsgOpenFile(MMS_DECODE_DRM_CONVERTED_TEMP_FILE, "wb+");
        if (hConvertedFile == NULL) {
-               MSG_DEBUG("Open decode temporary file fail\n");
+               MSG_DEBUG("Open decode temporary file fail");
                goto __CATCH;
        }
 
        pszMmsLoadTempBuf = (char*)malloc(MMS_DRM2_CONVERT_BUFFER_MAX + 1);
        if (pszMmsLoadTempBuf == NULL) {
-               MSG_DEBUG("malloc for pszMmsLoadTempBuf failed\n");
+               MSG_DEBUG("malloc for pszMmsLoadTempBuf failed");
                goto __CATCH;
        }
        memset(pszMmsLoadTempBuf, 0, MMS_DRM2_CONVERT_BUFFER_MAX + 1);
@@ -2666,7 +2646,7 @@ bool MmsDrm2ConvertMsgBody(char *szOriginFilePath)
        // MMS Header  copy
        length = mmsHeader.msgBody.offset;
        if (__MmsDrm2WriteDataToConvertedFile(pFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
-               MSG_DEBUG("Write header data fail\n");
+               MSG_DEBUG("Write header data fail");
                goto __CATCH;
        }
 
@@ -2679,7 +2659,7 @@ bool MmsDrm2ConvertMsgBody(char *szOriginFilePath)
                length = __MmsDrm2GetEntriesValueLength(pFile, curOffset);      // getting nEntries value's length
 
                if (__MmsDrm2WriteDataToConvertedFile(pFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
-                       MSG_DEBUG("Write nEntries fail\n");
+                       MSG_DEBUG("Write nEntries fail");
                        goto __CATCH;
                }
 
@@ -2697,19 +2677,19 @@ bool MmsDrm2ConvertMsgBody(char *szOriginFilePath)
 
                                pszOrgData = (char *)malloc(orgDataLen + 1);
                                if (pszOrgData == NULL) {
-                                       MSG_DEBUG("pszOrgData is NULL \n");
+                                       MSG_DEBUG("pszOrgData is NULL");
                                        goto __CATCH;
                                }
                                memset(pszOrgData, 0, orgDataLen + 1);
 
                                // move file pointer to data
                                if (MsgFseek(pFile, pMultipart->pBody->offset, SEEK_SET) < 0) {
-                                       MSG_DEBUG("fail to seek file pointer 1\n");
+                                       MSG_DEBUG("fail to seek file pointer 1");
                                        goto __CATCH;
                                }
 
                                if (MsgReadFile(pszOrgData, sizeof(char), orgDataLen, pFile) != (size_t)orgDataLen) {
-                                       MSG_DEBUG("FmReadFile() returns false for orgData\n");
+                                       MSG_DEBUG("FmReadFile() returns false for orgData");
                                        goto __CATCH;
                                }
 
@@ -2734,7 +2714,7 @@ bool MmsDrm2ConvertMsgBody(char *szOriginFilePath)
                                hFile = NULL;
 
                                // --> invoking drm agent api, converting data part start
-                               MSG_DEBUG("start data part convert by callling drm agent api\n");
+                               MSG_DEBUG("start data part convert by callling drm agent api");
 
                                int ret = 0;
                                ret = MsgDrmConvertDmtoDcfType(szTempFile, szTempFilePath);
@@ -2748,7 +2728,7 @@ bool MmsDrm2ConvertMsgBody(char *szOriginFilePath)
 
                                // move file pointer to the head of multipart
                                if (MsgFseek(pFile, curOffset, SEEK_SET) < 0) {
-                                       MSG_DEBUG("fail to seek file pointer 2\n");
+                                       MSG_DEBUG("fail to seek file pointer 2");
                                        goto __CATCH;
                                }
 
@@ -2756,7 +2736,7 @@ bool MmsDrm2ConvertMsgBody(char *szOriginFilePath)
                                length = pMultipart->type.offset - curOffset;
                                memset(pszMmsLoadTempBuf, 0, MMS_DRM2_CONVERT_BUFFER_MAX + 1);
                                if (MsgReadFile(pszMmsLoadTempBuf, sizeof(char), length, pFile) != (size_t)length) {
-                                       MSG_DEBUG("FmReadFile() returns false for headerLen, dataLen\n");
+                                       MSG_DEBUG("FmReadFile() returns false for headerLen, dataLen");
                                        goto __CATCH;
                                }
 
@@ -2783,7 +2763,7 @@ bool MmsDrm2ConvertMsgBody(char *szOriginFilePath)
                                        pszMmsLoadTempBuf[j+encodeLen] = '\0';
 
                                        if (MsgWriteFile(pszMmsLoadTempBuf, sizeof(char), length, hConvertedFile) != (size_t)length) {
-                                               MSG_DEBUG("Drm2WriteConvertData: FmWriteFile() returns false for dateLen\n");
+                                               MSG_DEBUG("FmWriteFile() returns false for dateLen");
                                                goto __CATCH;
                                        }
                                }
@@ -2792,7 +2772,7 @@ bool MmsDrm2ConvertMsgBody(char *szOriginFilePath)
                                length = pMultipart->pBody->offset - pMultipart->type.offset;
 
                                if (__MmsDrm2WriteDataToConvertedFile(pFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
-                                       MSG_DEBUG("Drm2WriteConvertData: Write content type, headers fail\n");
+                                       MSG_DEBUG("Write content type, headers fail");
                                        goto __CATCH;
                                }
 
@@ -2801,14 +2781,14 @@ bool MmsDrm2ConvertMsgBody(char *szOriginFilePath)
                                // write converted data
                                hTempFile = MsgOpenFile(szTempFilePath, "rb");
                                if (hTempFile == NULL) {
-                                       MSG_DEBUG("Open decode temporary file fail\n");
+                                       MSG_DEBUG("Open decode temporary file fail");
                                        goto __CATCH;
                                }
 
                                length = nSize;
 
                                if (__MmsDrm2WriteDataToConvertedFile(hTempFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
-                                       MSG_DEBUG("Write converted data fail\n");
+                                       MSG_DEBUG("Write converted data fail");
                                        goto __CATCH;
                                }
 
@@ -2821,16 +2801,16 @@ bool MmsDrm2ConvertMsgBody(char *szOriginFilePath)
 
                                // move file pointer to the head of multipart
                                if (MsgFseek(pFile, curOffset, SEEK_SET) < 0) {
-                                       MSG_DEBUG("fail to seek file pointer \n");
+                                       MSG_DEBUG("fail to seek file pointer");
                                        goto __CATCH;
                                }
                        } else {        // it doesn't need to convert if it is not CD or FL
-                               MSG_DEBUG("Write normal multipart data\n");
+                               MSG_DEBUG("Write normal multipart data");
 
                                length = pMultipart->pBody->offset + pMultipart->pBody->size - curOffset;
 
                                if (__MmsDrm2WriteDataToConvertedFile(pFile, hConvertedFile, pszMmsLoadTempBuf, length, bufLen) == false) {
-                                       MSG_DEBUG("Write multipart data fail \n");
+                                       MSG_DEBUG("Write multipart data fail");
                                        goto __CATCH;
                                }
 
@@ -2841,7 +2821,7 @@ bool MmsDrm2ConvertMsgBody(char *szOriginFilePath)
                }
        }
 
-       MSG_DEBUG("end convert~~~~~~\n");
+       MSG_DEBUG("end convert~~~~~~");
 
        if (pFile != NULL) {
                MsgCloseFile(pFile);
@@ -2928,7 +2908,7 @@ bool MmsDrm2ReadMsgConvertedBody(MSG_MESSAGE_INFO_S *pMsg, bool bSavePartsAsTemp
        MmsReleaseMsgBody(&pMmsMsg->msgBody, pMmsMsg->msgType.type);
 
        if (MmsReadMsgBody(pMsg->msgId, bSavePartsAsTempFiles, bRetrieved, retrievedPath) == false) {
-               MSG_DEBUG("MmsDrm2ReadMsgConvertedBody: _MmsReadMsgBody with converted file is failed\n");
+               MSG_DEBUG("_MmsReadMsgBody with converted file is failed");
                return false;
        }
 
@@ -2949,14 +2929,14 @@ bool __MmsBinaryDecodeGetOneByte(FILE *pFile, UINT8 *pOneByte, int totalLength)
 
        if (pFile == NULL || pOneByte == NULL)
        {
-               MSG_DEBUG("_MmsBinaryDecodeGetOneByte: invalid file or buffer\n");
+               MSG_DEBUG("invalid file or buffer");
                goto __CATCH;
        }
 
        if (length < 1) {
                if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
                                                                           gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-                       MSG_DEBUG("_MmsBinaryDecodeGetOneByte: fail to load to buffer \n");
+                       MSG_DEBUG("fail to load to buffer");
                        goto __CATCH;
                }
        }
@@ -2986,7 +2966,7 @@ bool __MmsBinaryDecodeGetBytes(FILE *pFile, char *szBuff, int bufLen, int totalL
        if (length < bufLen) {
                if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
                                                                           gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-                       MSG_DEBUG("_MmsBinaryDecodeGetBytes: fail to load to buffer \n");
+                       MSG_DEBUG("fail to load to buffer");
                        goto __CATCH;
                }
        }
@@ -3014,13 +2994,13 @@ bool __MmsBinaryDecodeGetLongBytes(FILE *pFile, char *szBuff, int bufLen, int to
 
        if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
                                                                   gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-               MSG_DEBUG("_MmsBinaryDecodeGetLongBytes: fail to load to buffer \n");
+               MSG_DEBUG("fail to load to buffer");
                goto __CATCH;
        }
 
        while ((bufLen - iPos) >= gMmsDecodeMaxLen) {
                if (__MmsBinaryDecodeGetBytes(pFile, szBuff + iPos, gMmsDecodeMaxLen, totalLength) == false) {
-                       MSG_DEBUG("_MmsBinaryDecodeGetLongBytes: 1. _MmsBinaryDecodeGetBytes fail \n");
+                       MSG_DEBUG("__MmsBinaryDecodeGetBytes fail");
                        goto __CATCH;
                }
 
@@ -3029,7 +3009,7 @@ bool __MmsBinaryDecodeGetLongBytes(FILE *pFile, char *szBuff, int bufLen, int to
 
        if ((bufLen - iPos) > 0) {
                if (__MmsBinaryDecodeGetBytes(pFile, szBuff + iPos, (bufLen - iPos), totalLength) == false) {
-                       MSG_DEBUG("_MmsBinaryDecodeGetLongBytes: 2. _MmsBinaryDecodeGetBytes fail \n");
+                       MSG_DEBUG("__MmsBinaryDecodeGetBytes fail");
                        goto __CATCH;
                }
 
@@ -3069,7 +3049,7 @@ static int __MmsBinaryDecodeUintvar(FILE *pFile, UINT32 *pUintVar, int totalLeng
        if (length < 5) {
                if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
                                                                           gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-                       MSG_DEBUG("__MmsBinaryDecodeUintvar: fail to load to buffer \n");
+                       MSG_DEBUG("fail to load to buffer");
                        goto __CATCH;
                }
        }
@@ -3086,7 +3066,7 @@ static int __MmsBinaryDecodeUintvar(FILE *pFile, UINT32 *pUintVar, int totalLeng
                }
 
                if (count > 4) {
-                       MSG_DEBUG("__MmsBinaryDecodeUintvar : legnth is too long\n");
+                       MSG_DEBUG("legnth is too long");
                        goto __CATCH;
                }
        }
@@ -3128,7 +3108,7 @@ static UINT32 __MmsHeaderDecodeIntegerByLength(FILE *pFile, UINT32 length, int t
        if (length == 1)
        {
                if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-                       MSG_DEBUG("__MmsHeaderDecodeIntegerByLength: _MmsBinaryDecodeGetOneByte fail\n");
+                       MSG_DEBUG("_MmsBinaryDecodeGetOneByte fail");
                        return oneByte;
                }
 
@@ -3144,13 +3124,13 @@ static UINT32 __MmsHeaderDecodeIntegerByLength(FILE *pFile, UINT32 length, int t
 
        pData = (char *)malloc(length + 1);
        if (pData == NULL) {
-               MSG_DEBUG("__MmsHeaderDecodeIntegerByLength: pData alloc fail\n");
+               MSG_DEBUG("pData alloc fail");
                goto __CATCH;
        }
        memset(pData, 0, length + 1);
 
        if (__MmsBinaryDecodeGetBytes(pFile, pData, length + 1, totalLength) == false) {
-               MSG_DEBUG("__MmsHeaderDecodeIntegerByLength: _MmsBinaryDecodeGetOneByte fail\n");
+               MSG_DEBUG("_MmsBinaryDecodeGetOneByte fail");
                goto __CATCH;
        }
 
@@ -3200,7 +3180,7 @@ static bool __MmsBinaryDecodeInteger(FILE *pFile, UINT32 *pInteger, int *pIntLen
        *pIntLen                 = 0;
 
        if (__MmsBinaryDecodeGetOneByte(pFile, &oneByte, totalLength) == false) {
-               MSG_DEBUG("__MmsBinaryDecodeInteger: GetOneByte fail\n");
+               MSG_DEBUG("GetOneByte fail");
                return false;
        }
 
@@ -3208,14 +3188,14 @@ static bool __MmsBinaryDecodeInteger(FILE *pFile, UINT32 *pInteger, int *pIntLen
        {
                pData = (char *)malloc(oneByte + 1);
                if (pData == NULL) {
-                       MSG_DEBUG("__MmsBinaryDecodeInteger: pData memalloc fail\n");
+                       MSG_DEBUG("pData memalloc fail");
                        goto __CATCH;
                }
                memset(pData, 0, oneByte + 1);
 
                // Even NULL is copied in the _MmsBinaryDecodeGetBytes
                if (__MmsBinaryDecodeGetBytes(pFile, pData, oneByte + 1, totalLength) == false) {
-                       MSG_DEBUG("__MmsBinaryDecodeInteger: GetBytes fail\n");
+                       MSG_DEBUG("GetBytes fail");
                        goto __CATCH;
                }
 
@@ -3300,13 +3280,13 @@ static int __MmsDecodeValueLength(FILE *pFile, UINT32 *pValueLength, int totalLe
 
                length = __MmsBinaryDecodeUintvar(pFile, &uintvar, totalLength);
                if (length == -1) {
-                       MSG_DEBUG("__MmsDecodeValueLength: __MmsBinaryDecodeUintvar fail..\n");
+                       MSG_DEBUG(" __MmsBinaryDecodeUintvar fail..");
                        goto __CATCH;
                }
                length ++;                                      // + length-quote
                *pValueLength = uintvar;
        } else {
-               MSG_DEBUG("__MmsDecodeValueLength: not a value length type data\n");
+               MSG_DEBUG("not a value length type data");
                gCurMmsDecodeBuffPos--;
                return 0;
        }
@@ -3314,7 +3294,7 @@ static int __MmsDecodeValueLength(FILE *pFile, UINT32 *pValueLength, int totalLe
        return length;
 
 __CATCH:
-       MSG_DEBUG("__MmsDecodeValueLength: getting data fail\n");
+       MSG_DEBUG("getting data fail");
        return -1;
 }
 
@@ -3358,13 +3338,13 @@ static int __MmsDecodeValueLength2(FILE *pFile, UINT32 *pValueLength, int totalL
 
                length = __MmsBinaryDecodeUintvar(pFile, &uintvar, totalLength);
                if (length == -1) {
-                       MSG_DEBUG("__MmsDecodeValueLength2: __MmsBinaryDecodeUintvar fail..\n");
+                       MSG_DEBUG("__MmsBinaryDecodeUintvar fail..");
                        goto __CATCH;
                }
                length ++;                                      // + length-quote
                *pValueLength = uintvar;
        } else {
-               MSG_DEBUG("__MmsDecodeValueLength2: there is not length-quote, consider it as short length.\n");
+               MSG_DEBUG("there is not length-quote, consider it as short length.");
                *pValueLength = oneByte;
                length = 1;
        }
@@ -3372,7 +3352,7 @@ static int __MmsDecodeValueLength2(FILE *pFile, UINT32 *pValueLength, int totalL
        return length;
 
 __CATCH:
-       MSG_DEBUG("__MmsDecodeValueLength2: getting data fail\n");
+       MSG_DEBUG("getting data fail");
        return -1;
 }
 
@@ -3404,7 +3384,7 @@ static int __MmsBinaryDecodeQuotedString(FILE *pFile, char *szBuff, int bufLen,
 
        if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
                                                                         gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-               MSG_DEBUG("__MmsBinaryDecodeQuotedString: 1. fail to load to buffer \n");
+               MSG_DEBUG("fail to load to buffer");
                goto __CATCH;
        }
 
@@ -3415,17 +3395,17 @@ static int __MmsBinaryDecodeQuotedString(FILE *pFile, char *szBuff, int bufLen,
 
        while (length > gMmsDecodeBufLen) {
                if (gMmsDecodeBufLen <= 0) {
-                       MSG_DEBUG("__MmsBinaryDecodeQuotedString: gMmsDecodeBufLen <= 0 \n");
-                       MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
+                       MSG_DEBUG("gMmsDecodeBufLen <= 0");
+                       MSG_DEBUG("%x %x %x %x %x",
                                                                                gpCurMmsDecodeBuff[0], gpCurMmsDecodeBuff[1], gpCurMmsDecodeBuff[2],
                                                                                gpCurMmsDecodeBuff[3], gpCurMmsDecodeBuff[4]);
-                       MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
+                       MSG_DEBUG("%x %x %x %x %x",
                                                                                gpCurMmsDecodeBuff[5], gpCurMmsDecodeBuff[6], gpCurMmsDecodeBuff[7],
                                                                                gpCurMmsDecodeBuff[8], gpCurMmsDecodeBuff[9]);
-                       MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
+                       MSG_DEBUG("%x %x %x %x %x",
                                                                                gpCurMmsDecodeBuff[10], gpCurMmsDecodeBuff[11], gpCurMmsDecodeBuff[12],
                                                                                gpCurMmsDecodeBuff[13], gpCurMmsDecodeBuff[14]);
-                       MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
+                       MSG_DEBUG("%x %x %x %x %x",
                                                                                gpCurMmsDecodeBuff[15], gpCurMmsDecodeBuff[16], gpCurMmsDecodeBuff[17],
                                                                                gpCurMmsDecodeBuff[18], gpCurMmsDecodeBuff[19]);
                        goto __CATCH;
@@ -3462,7 +3442,7 @@ static int __MmsBinaryDecodeQuotedString(FILE *pFile, char *szBuff, int bufLen,
 
                if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
                                                                                gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-                       MSG_DEBUG("__MmsBinaryDecodeText: 2. fail to load to buffer \n");
+                       MSG_DEBUG("fail to load to buffer");
                        goto __CATCH;
                }
                length = strlen(gpCurMmsDecodeBuff) + 1;        // + NULL
@@ -3550,7 +3530,7 @@ static int __MmsBinaryDecodeText(FILE *pFile, char *szBuff, int bufLen, int tota
 
        if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
                                                                        gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-               MSG_DEBUG("__MmsBinaryDecodeText: 1. fail to load to buffer \n");
+               MSG_DEBUG("fail to load to buffer");
                goto __CATCH;
        }
 
@@ -3561,14 +3541,14 @@ static int __MmsBinaryDecodeText(FILE *pFile, char *szBuff, int bufLen, int tota
 
        while (length > gMmsDecodeBufLen) {
                if (gMmsDecodeBufLen <= 0) {
-                       MSG_DEBUG("__MmsBinaryDecodeQuotedString: gMmsDecodeBufLen <= 0 \n");
-                       MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n", gpCurMmsDecodeBuff[0], gpCurMmsDecodeBuff[1], gpCurMmsDecodeBuff[2],
+                       MSG_DEBUG("gMmsDecodeBufLen <= 0");
+                       MSG_DEBUG("%x %x %x %x %x", gpCurMmsDecodeBuff[0], gpCurMmsDecodeBuff[1], gpCurMmsDecodeBuff[2],
                                                                                gpCurMmsDecodeBuff[3], gpCurMmsDecodeBuff[4]);
-                       MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n", gpCurMmsDecodeBuff[5], gpCurMmsDecodeBuff[6], gpCurMmsDecodeBuff[7],
+                       MSG_DEBUG("%x %x %x %x %x", gpCurMmsDecodeBuff[5], gpCurMmsDecodeBuff[6], gpCurMmsDecodeBuff[7],
                                                                                gpCurMmsDecodeBuff[8], gpCurMmsDecodeBuff[9]);
-                       MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n", gpCurMmsDecodeBuff[10], gpCurMmsDecodeBuff[11], gpCurMmsDecodeBuff[12],
+                       MSG_DEBUG("%x %x %x %x %x", gpCurMmsDecodeBuff[10], gpCurMmsDecodeBuff[11], gpCurMmsDecodeBuff[12],
                                                                                gpCurMmsDecodeBuff[13], gpCurMmsDecodeBuff[14]);
-                       MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n", gpCurMmsDecodeBuff[15], gpCurMmsDecodeBuff[16], gpCurMmsDecodeBuff[17],
+                       MSG_DEBUG("%x %x %x %x %x", gpCurMmsDecodeBuff[15], gpCurMmsDecodeBuff[16], gpCurMmsDecodeBuff[17],
                                                                                gpCurMmsDecodeBuff[18], gpCurMmsDecodeBuff[19]);
                        goto __CATCH;
                }
@@ -3605,7 +3585,7 @@ static int __MmsBinaryDecodeText(FILE *pFile, char *szBuff, int bufLen, int tota
 
                if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
                                                                           gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-                       MSG_DEBUG("__MmsBinaryDecodeText: 2. fail to load to buffer \n");
+                       MSG_DEBUG("fail to load to buffer");
                        goto __CATCH;
                }
                length = strlen(gpCurMmsDecodeBuff) + 1;        // + NULL
@@ -3692,7 +3672,7 @@ static char* __MmsBinaryDecodeText2(FILE *pFile, int totalLength, int *pLength)
 
        if (__MsgLoadDataToDecodeBuffer(pFile, &gpCurMmsDecodeBuff, &gCurMmsDecodeBuffPos, &gMmsDecodeCurOffset,
                                                                   gpMmsDecodeBuf1, gpMmsDecodeBuf2, gMmsDecodeMaxLen, &gMmsDecodeBufLen, totalLength) == false) {
-               MSG_DEBUG("__MmsBinaryDecodeTextLen: 1. fail to load to buffer \n");
+               MSG_DEBUG("fail to load to buffer");
                goto __CATCH;
        }
 
@@ -3703,17 +3683,17 @@ static char* __MmsBinaryDecodeText2(FILE *pFile, int totalLength, int *pLength)
 
        while (length > gMmsDecodeBufLen) {
                if (gMmsDecodeBufLen <= 0) {
-                       MSG_DEBUG("__MmsBinaryDecodeQuotedString: gMmsDecodeBufLen <= 0 \n");
-                       MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
+                       MSG_DEBUG("gMmsDecodeBufLen <= 0");
+                       MSG_DEBUG("%x %x %x %x %x",
                                                                                gpCurMmsDecodeBuff[0], gpCurMmsDecodeBuff[1], gpCurMmsDecodeBuff[2],
                                                                                gpCurMmsDecodeBuff[3], gpCurMmsDecodeBuff[4]);
-                       MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
+                       MSG_DEBUG("%x %x %x %x %x",
                                                                                gpCurMmsDecodeBuff[5], gpCurMmsDecodeBuff[6], gpCurMmsDecodeBuff[7],
                                                                                gpCurMmsDecodeBuff[8], gpCurMmsDecodeBuff[9]);
-                       MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
+                       MSG_DEBUG("%x %x %x %x %x",
                                                                                gpCurMmsDecodeBuff[10], gpCurMmsDecodeBuff[11], gpCurMmsDecodeBuff[12],
                                                                                gpCurMmsDecodeBuff[13], gpCurMmsDecodeBuff[14]);
-                       MSG_DEBUG("__MmsBinaryDecodeQuotedString: %x %x %x %x %x\n",
+                       MSG_DEBUG("%x %x %x %x %x\n",
                                                                                gpCurMmsDecodeBuff[15], gpCurMmsDecodeBuff[16], gpCurMmsDecodeBuff[17],
                                                                                gpCurMmsDecodeBuff[18], gpCurMmsDecodeBuff[19]);
                        goto __CATCH;
@@ -3773,7 +3753,7 @@ static char* __MmsBinaryDecodeText2(FILE *pFile, int totalLength, int *pLength)
                                                           &gMmsDecodeBufLen,
                                                           totalLength) == false)
                {
-                       MSG_DEBUG("__MmsBinaryDecodeText: 2. fail to load to buffer \n");
+                       MSG_DEBUG("fail to load to buffer");
                        goto __CATCH;
                }
                length = strlen(gpCurMmsDecodeBuff) + 1;
@@ -3875,7 +3855,7 @@ static bool __MmsBinaryDecodeCharset(FILE *pFile, UINT32 *nCharSet, int *pCharSe
                return false;
 
        if (__MmsBinaryDecodeInteger(pFile, &integer, pCharSetLen, totalLength) == false) {
-               MSG_DEBUG("__MmsBinaryDecodeCharset : __MmsBinaryDecodeInteger fail...\n");
+               MSG_DEBUG("__MmsBinaryDecodeInteger fail...");
                goto __CATCH;
        }
 
@@ -3888,7 +3868,7 @@ static bool __MmsBinaryDecodeCharset(FILE *pFile, UINT32 *nCharSet, int *pCharSe
        *nCharSet = MmsGetBinaryType(MmsCodeCharSet, (UINT16)integer);
 
        if (*nCharSet == MIME_UNKNOWN) {
-               MSG_DEBUG("__MmsBinaryDecodeCharset : MmsGetBinaryType fail..\n");
+               MSG_DEBUG("MmsGetBinaryType fail..");
                *nCharSet = MSG_CHARSET_UNKNOWN;
        }
 
@@ -3914,10 +3894,10 @@ static bool __MmsBinaryDecodeEncodedString(FILE *pFile, char *szBuff, int bufLen
        int nTemp = 0;
        char *pData = NULL;
 
-       MSG_DEBUG("__MmsBinaryDecodeEncodedString: decode string..\n");
+       MSG_DEBUG(" decode string..");
 
        if (pFile == NULL || szBuff == NULL || bufLen <= 0) {
-               MSG_DEBUG("__MmsBinaryDecodeEncodedString: invalid file or buffer\n");
+               MSG_DEBUG("invalid file or buffer");
                goto __CATCH;
        }
 
@@ -3938,7 +3918,7 @@ static bool __MmsBinaryDecodeEncodedString(FILE *pFile, char *szBuff, int bufLen
                /* Text-string = [Quote]*TEXT End-of-string */
 
                if (__MmsBinaryDecodeText(pFile, szBuff, bufLen, totalLength) < 0) {
-                       MSG_DEBUG("__MmsBinaryDecodeEncodedString : 1. __MmsBinaryDecodeText fail.\n");
+                       MSG_DEBUG("__MmsBinaryDecodeText fail.");
                        goto __CATCH;
                }
                break;
@@ -3948,7 +3928,7 @@ static bool __MmsBinaryDecodeEncodedString(FILE *pFile, char *szBuff, int bufLen
                /* Value-length Charset Text_string */
 
                if (__MmsBinaryDecodeCharset(pFile, &charSet, &charSetLen, totalLength) == false) {
-                       MSG_DEBUG("__MmsBinaryDecodeEncodedString : __MmsBinaryDecodeCharset error\n");
+                       MSG_DEBUG(" __MmsBinaryDecodeCharset error");
                        goto __CATCH;                   /* (valueLength + valueLengthLen) */
                }
 
@@ -3958,12 +3938,12 @@ static bool __MmsBinaryDecodeEncodedString(FILE *pFile, char *szBuff, int bufLen
 
                        pData = (char *)malloc(valueLength - charSetLen);
                        if (pData == NULL) {
-                               MSG_DEBUG("__MmsBinaryDecodeEncodedString : pData alloc fail.\n");
+                               MSG_DEBUG("pData alloc fail.");
                                goto __CATCH;
                        }
 
                        if (__MmsBinaryDecodeGetLongBytes(pFile, pData, valueLength - charSetLen, totalLength) == false) {
-                               MSG_DEBUG("__MmsBinaryDecodeEncodedString : _MmsBinaryDecodeGetLongBytes fail.\n");
+                               MSG_DEBUG("_MmsBinaryDecodeGetLongBytes fail.");
                                goto __CATCH;
                        }
 
@@ -3999,6 +3979,7 @@ static bool __MmsBinaryDecodeEncodedString(FILE *pFile, char *szBuff, int bufLen
                                snprintf(szBuff, destLen, "%s", pDest);
                        }
                }
+               break;
        }
 
        if (pData) {
@@ -4036,10 +4017,10 @@ MsgHeaderAddress *__MmsDecodeEncodedAddress(FILE *pFile, int totalLength)
        char *pAddrStr  = NULL;
        MsgHeaderAddress *pAddr = NULL;
 
-       MSG_DEBUG("__MmsDecodeEncodedAddress: decoding address..\n");
+       MSG_DEBUG("decoding address..");
 
        if (pFile == NULL) {
-               MSG_DEBUG("__MmsDecodeEncodedAddress: invalid file or buffer\n");
+               MSG_DEBUG("invalid file or buffer");
                goto __CATCH;
        }
 
@@ -4060,7 +4041,7 @@ MsgHeaderAddress *__MmsDecodeEncodedAddress(FILE *pFile, int totalLength)
                textLength = 0;
                pAddrStr   = __MmsBinaryDecodeText2(pFile, totalLength, &textLength);
                if (pAddrStr == NULL) {
-                       MSG_DEBUG("__MmsDecodeEncodedAddress : 1. __MmsBinaryDecodeText2 fail.\n");
+                       MSG_DEBUG(" __MmsBinaryDecodeText2 fail.");
                        goto __CATCH;
                }
                break;
@@ -4070,7 +4051,7 @@ MsgHeaderAddress *__MmsDecodeEncodedAddress(FILE *pFile, int totalLength)
                /* Value-length Charset Text_string */
 
                if (__MmsBinaryDecodeCharset(pFile, &charSet, &charSetLen, totalLength) == false) {
-                       MSG_DEBUG("__MmsDecodeEncodedAddress : __MmsBinaryDecodeCharset error\n");
+                       MSG_DEBUG(" __MmsBinaryDecodeCharset error");
                        goto __CATCH;
                }
 
@@ -4081,12 +4062,12 @@ MsgHeaderAddress *__MmsDecodeEncodedAddress(FILE *pFile, int totalLength)
 
                        pAddrStr = (char *)malloc(valueLength - charSetLen);
                        if (pAddrStr == NULL) {
-                               MSG_DEBUG("__MmsDecodeEncodedAddress : pData alloc fail.\n");
+                               MSG_DEBUG("pData alloc fail.");
                                goto __CATCH;
                        }
 
                        if (__MmsBinaryDecodeGetLongBytes(pFile, pAddrStr, valueLength - charSetLen, totalLength) == false) {
-                               MSG_DEBUG("__MmsDecodeEncodedAddress : _MmsBinaryDecodeGetLongBytes fail.\n");
+                               MSG_DEBUG(" _MmsBinaryDecodeGetLongBytes fail.");
                                goto __CATCH;
                        }
                }
@@ -4203,12 +4184,12 @@ static int __MmsDecodeGetFilename(FILE *pFile, char *szBuff, int bufLen, int tot
 
                        pUTF8Buff = (char *)malloc(utf8BufSize + 1);
                        if (pUTF8Buff == NULL) {
-                               MSG_DEBUG("__MmsDecodeGetFilename: pUTF8Buff alloc fail \n");
+                               MSG_DEBUG("pUTF8Buff alloc fail");
                                goto __CATCH;
                        }
 
                        if (__MsgLatin2UTF ((unsigned char*)pUTF8Buff, utf8BufSize + 1, (unsigned char*)pLatinBuff, length) < 0) {
-                               MSG_DEBUG("__MmsDecodeGetFilename: MsgLatin2UTF fail \n");
+                               MSG_DEBUG("MsgLatin2UTF fail");
                                goto __CATCH;
                        }
                        free(pLatinBuff);
@@ -4272,10 +4253,8 @@ bool MmsReadMsgBody(msg_message_id_t msgID, bool bSavePartsAsTempFiles, bool bRe
        int nSize = 0;
        char szFullPath[MSG_FILEPATH_LEN_MAX] = {0, };
        char szTempMediaDir[MSG_FILEPATH_LEN_MAX] = {0, };
-       int attachmax = MSG_ATTACH_MAX;
 
        MSG_BEGIN();
-       MSG_DEBUG("msg id : %d", msgID);
 
        MmsPluginStorage::instance()->getMmsMessage(&pMsg);
        memset(pMsg, 0, sizeof(MmsMsg));
@@ -4293,44 +4272,32 @@ bool MmsReadMsgBody(msg_message_id_t msgID, bool bSavePartsAsTempFiles, bool bRe
        /*      read from MMS raw file  */
        strncpy(pMsg->szFileName, szFullPath + strlen(MSG_DATA_PATH), strlen(szFullPath + strlen(MSG_DATA_PATH)));
 
-       MSG_DEBUG("szFullPath = (%s)", szFullPath);
+       MSG_DEBUG("msg_id = [%d]", msgID);
+       MSG_DEBUG("raw file path = [%s]", szFullPath);
 
        if (MsgGetFileSize(szFullPath, &nSize) == false) {
-               MSG_DEBUG("MsgGetFileSize: failed");
+               MSG_FATAL("Fail MsgGetFileSize");
                goto __CATCH;
        }
 
        pFile = MsgOpenFile(szFullPath, "rb");
-
        if (pFile == NULL) {
-               MSG_DEBUG("_MmsReadMsgBody: invalid mailbox\n");
+               MSG_DEBUG("Fail MsgOpenFile [%s]", szFullPath);
                goto __CATCH;
        }
 
        MmsRegisterDecodeBuffer();
 
        if (MmsBinaryDecodeMsgHeader(pFile, nSize) == false) {
-               MSG_DEBUG("_MmsReadMsgBody: MmsBinaryDecodeMsgHeader fail...\n");
+               MSG_FATAL("Fail to MmsBinaryDecodeMsgHeader");
                goto __CATCH;
        }
 
-#ifdef __SUPPORT_DRM__
-       if (MmsDrm2GetConvertState() != MMS_DRM2_CONVERT_FINISH)
-               MmsDrm2SetConvertState(MMS_DRM2_CONVERT_NONE);  //initialize convertState
-#endif
-
        if (MmsBinaryDecodeMsgBody(pFile, szFullPath, nSize) == false) {
-               MSG_DEBUG("_MmsReadMsgBody: MmsBinaryDecodeMsgBody fail\n");
+               MSG_FATAL("Fail to MmsBinaryDecodeMsgBody");
                goto __CATCH;
        }
 
-#ifdef __SUPPORT_DRM__
-       if (MmsDrm2GetConvertState() == MMS_DRM2_CONVERT_REQUIRED) {
-               MSG_DEBUG("_MmsReadMsgBody: MmsDrm2GetConvertState returns MMS_DRM2_CONVERT_REQUIRED.\n");
-               goto RETURN;
-       }
-#endif
-
        /* Set mmsHeader.msgType & msgBody to pMsg ----------- */
 
        memcpy(&(pMsg->msgType), &(mmsHeader.msgType), sizeof(MsgType));
@@ -4394,7 +4361,6 @@ bool MmsReadMsgBody(msg_message_id_t msgID, bool bSavePartsAsTempFiles, bool bRe
 
        MsgCloseFile(pFile);
        pFile = NULL;
-
        /* nPartCount */
        pMsg->nPartCount = 0;
 
@@ -4402,23 +4368,6 @@ bool MmsReadMsgBody(msg_message_id_t msgID, bool bSavePartsAsTempFiles, bool bRe
                pMultipart = pMsg->msgBody.body.pMultipart;
                while (pMultipart) {
                        pMsg->nPartCount++;
-
-                       if (pMultipart->type.type == MIME_TEXT_PLAIN)
-                               attachmax++;
-
-                       if ((mmsHeader.msgType.type == MIME_APPLICATION_VND_WAP_MULTIPART_MIXED)||(mmsHeader.msgType.type == MIME_MULTIPART_MIXED)) {
-                               if ((pMsg->nPartCount >= attachmax)&&(pMultipart->pNext != NULL)) {
-                                       MmsReleaseMsgBody(pMultipart->pNext->pBody, pMultipart->pNext->type.type);
-
-                                       free(pMultipart->pNext->pBody);
-                                       pMultipart->pNext->pBody= NULL;
-
-                                       free(pMultipart->pNext);
-
-                                       pMultipart->pNext = NULL;
-                                       break;
-                               }
-                       }
                        pMultipart = pMultipart->pNext;
                }
        } else {
@@ -4436,11 +4385,13 @@ bool MmsReadMsgBody(msg_message_id_t msgID, bool bSavePartsAsTempFiles, bool bRe
                if (bSavePartsAsTempFiles) {
                        if (mkdir(szTempMediaDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
                                if (errno == EEXIST) {
-                                       MSG_DEBUG("The %s already exists", szTempMediaDir);
+                                       MSG_DEBUG("exist dir : [%s]", szTempMediaDir);
                                } else {
                                        MSG_DEBUG("Fail to Create Dir [%s]", szTempMediaDir);
                                        goto __CATCH;
                                }
+                       } else {
+                               MSG_DEBUG("make dir : [%s]", szTempMediaDir);
                        }
                }
 
@@ -4466,35 +4417,25 @@ bool MmsReadMsgBody(msg_message_id_t msgID, bool bSavePartsAsTempFiles, bool bRe
                        if (bSavePartsAsTempFiles) {
                                if (mkdir(szTempMediaDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
                                        if (errno == EEXIST) {
-                                               MSG_DEBUG("The %s already exists", szTempMediaDir);
+                                               MSG_DEBUG("exist dir : [%s]", szTempMediaDir);
                                        } else {
                                                MSG_DEBUG("Fail to Create Dir [%s]", szTempMediaDir);
                                                goto __CATCH;
                                        }
+                               } else {
+                                       MSG_DEBUG("make dir : [%s]", szTempMediaDir);
                                }
                        }
 
-                       if (__MmsMultipartSaveAsTempFile( &pMsg->msgType, &pMsg->msgBody,
+                       if (__MmsMultipartSaveAsTempFile(&pMsg->msgType, &pMsg->msgBody,
                                                                                        (char*)MSG_DATA_PATH, pMsg->szFileName, 0, bSavePartsAsTempFiles) == false)
                                goto __CATCH;
                }
        }
-       MSG_DEBUG("****   _MmsReadMsgBody:  E  N  D   (Success)  ***\n");
+       MSG_DEBUG("### Success ###");
+       MSG_END();
        return true;
 
-#ifdef __SUPPORT_DRM__
-
-RETURN:
-
-       if (pFile != NULL) {
-               MsgCloseFile(pFile);
-               pFile = NULL;
-       }
-
-       return false;
-
-#endif
-
 __CATCH:
 
        MmsInitHeader();
@@ -4510,8 +4451,9 @@ __CATCH:
 #endif
 
        MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
-       MSG_DEBUG("_MmsReadMsgBody:    E  N  D    (fail)    ******************** \n");
 
+       MSG_DEBUG("### Fail ###");
+       MSG_END();
        return false;
 }
 
@@ -4578,12 +4520,12 @@ static char *__MsgGetStringUntilDelimiter(char *pszString, char delimiter)
        int     bufLength = 0;
 
        if (!pszString) {
-               MSG_DEBUG("_MsgGetStringUntilDelimiter: pszString == NULL \n");
+               MSG_DEBUG("pszString == NULL");
                return NULL;
        }
 
        if ((pszStrDelimiter = strchr(pszString, delimiter)) == NULL) {
-               MSG_DEBUG("_MsgGetStringUntilDelimiter: There is no %c in %s. \n", delimiter, pszString);
+               MSG_DEBUG("There is no %c in %s. \n", delimiter, pszString);
                return NULL;
        }
 
@@ -4706,7 +4648,7 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
 
                                memset (pType->param.szBoundary, 0, MSG_BOUNDARY_LEN + 1);
                                strncpy(pType->param.szBoundary, pDec, MSG_BOUNDARY_LEN);
-                               MSG_DEBUG("_MsgParseParameter: szBoundary = %s \n", pType->param.szBoundary);
+                               MSG_DEBUG("szBoundary = [%s]", pType->param.szBoundary);
                                break;
 
                        case MSG_PARAM_CHARSET:
@@ -4715,7 +4657,7 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
                                if (pType->param.charset == INVALID_HOBJ)
                                        pType->param.charset = MSG_CHARSET_UNKNOWN;
 
-                               MSG_DEBUG("_MsgParseParameter: type = %d    [charset] = %d \n", pType->type, pType->param.charset);
+                               MSG_DEBUG("type = %d    [charset] = %d", pType->type, pType->param.charset);
                                break;
 
                        case MSG_PARAM_NAME:
@@ -4753,10 +4695,10 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
                                        // Remvoe '/', ex) Content-Type: image/gif; name="images/vf7.gif"
                                        __MsgRemoveFilePath(pType->param.szName);
                                } else {
-                                       MSG_DEBUG("_MsgParseParameter: MsgConvertLatin2UTF8FileName(%s) return NULL\n", pDec);
+                                       MSG_DEBUG("MsgConvertLatin2UTF8FileName(%s) return NULL", pDec);
                                }
 
-                               MSG_DEBUG("_MsgParseParameter: szName = %s \n", pType->param.szName);
+                               MSG_DEBUG("szName = %s", pType->param.szName);
                                break;
 
                        case MSG_PARAM_FILENAME:
@@ -4792,10 +4734,10 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
                                        // Remvoe '/', ex) Content-Type: image/gif; name="images/vf7.gif"
                                        __MsgRemoveFilePath(pType->param.szFileName);
                                } else {
-                                       MSG_DEBUG("_MsgParseParameter: MsgConvertLatin2UTF8FileName(%s) return NULL\n", pDec);
+                                       MSG_DEBUG("MsgConvertLatin2UTF8FileName(%s) return NULL", pDec);
                                }
 
-                               MSG_DEBUG("_MsgParseParameter: szFileName = %s \n", pType->param.szFileName);
+                               MSG_DEBUG("szFileName = %s", pType->param.szFileName);
 
                                break;
 
@@ -4804,7 +4746,7 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
                                /* type/subtype of root. Only if content-type is multipart/related */
 
                                pType->param.type = _MsgGetCode(MSG_TYPE, pDec);
-                               MSG_DEBUG("_MsgParseParameter: type = %d \n", pType->param.type);
+                               MSG_DEBUG("type = %d", pType->param.type);
 
                                break;
 
@@ -4815,7 +4757,7 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
                                memset (pType->param.szStart, 0, MSG_MSG_ID_LEN + 1);
                                strncpy(pType->param.szStart, pDec, MSG_MSG_ID_LEN);
 
-                               MSG_DEBUG("_MsgParseParameter: szStart = %s \n", pType->param.szStart);
+                               MSG_DEBUG("szStart = %s", pType->param.szStart);
 
                                break;
 
@@ -4826,7 +4768,7 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
                                memset (pType->param.szStartInfo, 0, MSG_MSG_ID_LEN + 1);
                                strncpy(pType->param.szStartInfo, pDec, MSG_MSG_ID_LEN);
 
-                               MSG_DEBUG("_MsgParseParameter: szStartInfo = %s \n", pType->param.szStartInfo);
+                               MSG_DEBUG("szStartInfo = %s", pType->param.szStartInfo);
 
                                break;
 
@@ -4840,12 +4782,12 @@ static bool __MsgParseParameter(MsgType *pType, char *pSrc)
                                        pType->param.reportType = MSG_PARAM_REPORT_TYPE_UNKNOWN;
                                }
 
-                               MSG_DEBUG("_MsgParseParameter: reportType = %s \n", pDec);
+                               MSG_DEBUG("reportType = %s", pDec);
                                break;
 
                        default:
 
-                               MSG_DEBUG("_MsgParseParameter: Unknown paremeter (%s)\n", pDec);
+                               MSG_DEBUG("Unknown paremeter (%s)", pDec);
                                break;
                        }
 
@@ -4937,12 +4879,12 @@ static char *__MsgConvertLatin2UTF8FileName(char *pSrc)
                pUTF8Buff = (char *)malloc(utf8BufSize + 1);
 
                if (pUTF8Buff == NULL) {
-                       MSG_DEBUG("MsgConvertLatin2UTF8FileName: pUTF8Buff alloc fail \n");
+                       MSG_DEBUG("pUTF8Buff alloc fail");
                        goto __CATCH;
                }
 
                if (__MsgLatin2UTF ((unsigned char*)pUTF8Buff, utf8BufSize + 1, (unsigned char*)pSrc, length) < 0) {
-                       MSG_DEBUG("MsgConvertLatin2UTF8FileName: MsgLatin2UTF fail \n");
+                       MSG_DEBUG("MsgLatin2UTF fail");
                        goto __CATCH;
                }
        } else {
@@ -4950,7 +4892,7 @@ static char *__MsgConvertLatin2UTF8FileName(char *pSrc)
                pUTF8Buff = (char *)calloc(1, length+1);
 
                if (pUTF8Buff == NULL) {
-                       MSG_DEBUG("MsgConvertLatin2UTF8FileName: pUTF8Buff alloc fail \n");
+                       MSG_DEBUG("pUTF8Buff alloc fail");
                        goto __CATCH;
                }
 
@@ -5030,7 +4972,7 @@ static void __MsgRemoveFilePath(char *pSrc)
        }
 
        if (pPath) {
-               MSG_DEBUG("_MsgRemoveFilePath: filename(%s)\n", pSrc);
+               MSG_DEBUG("filename(%s)", pSrc);
 
                // case : images/vf7.gif -> vf7.gif
                if (pPath != NULL && *(pPath+1) != '\0') {
@@ -5050,10 +4992,10 @@ static void __MsgRemoveFilePath(char *pSrc)
 
 static bool __MsgIsUTF8String(unsigned char *szSrc, int nChar)
 {
-       MSG_DEBUG("MsgIsUTF8String: --------------- \n");
+       MSG_DEBUG("MsgIsUTF8String: ---------------");
 
        if (szSrc == NULL) {
-               MSG_DEBUG("MsgIsUTF8String: szSrc is NULL !!!! --------------- \n");
+               MSG_DEBUG("szSrc is NULL !!!! ---------------");
                return true;
        }
 
@@ -5066,7 +5008,7 @@ static bool __MsgIsUTF8String(unsigned char *szSrc, int nChar)
                                szSrc += 2;
                                nChar -= 2;
                        } else {
-                               MSG_DEBUG("MsgIsUTF8String: 1. NOT utf8 range!\n");
+                               MSG_DEBUG("1. NOT utf8 range!");
                                goto __CATCH;
                        }
                } else if (*szSrc >= 0xE0) {
@@ -5075,15 +5017,15 @@ static bool __MsgIsUTF8String(unsigned char *szSrc, int nChar)
                                        szSrc += 3;
                                        nChar -= 3;
                                } else {
-                                       MSG_DEBUG("MsgIsUTF8String: 2. NOT utf8 range!\n");
+                                       MSG_DEBUG("2. NOT utf8 range!");
                                        goto __CATCH;
                                }
                        } else {
-                               MSG_DEBUG("MsgIsUTF8String: 3. NOT utf8 range!\n");
+                               MSG_DEBUG("3. NOT utf8 range!");
                                goto __CATCH;
                        }
                } else {
-                       MSG_DEBUG("MsgIsUTF8String: 4. NOT utf8 range!\n");
+                       MSG_DEBUG("4. NOT utf8 range!");
                        goto __CATCH;
                }
        }
@@ -5114,17 +5056,17 @@ static MsgMultipart *__MsgAllocMultipart(void)
 {
        MsgMultipart *pMultipart = NULL;
 
-       MSG_DEBUG("MsgAllocMultipart: --------- \n");
+       MSG_BEGIN();
 
        pMultipart = (MsgMultipart*)malloc(sizeof(MsgMultipart));
        if (pMultipart == NULL) {
-               MSG_DEBUG("MsgAllocMultipart: pMultipart malloc Fail \n");
+               MSG_DEBUG("pMultipart malloc Fail");
                goto __CATCH;
        }
 
        pMultipart->pBody = (MsgBody*)malloc(sizeof(MsgBody));
        if (pMultipart->pBody == NULL) {
-               MSG_DEBUG("MsgAllocMultipart: pMultipart->pBody malloc Fail \n");
+               MSG_DEBUG("pMultipart->pBody malloc Fail");
                goto __CATCH;
        }
 
@@ -5133,6 +5075,7 @@ static MsgMultipart *__MsgAllocMultipart(void)
 
        pMultipart->pNext = NULL;
 
+       MSG_END();
        return pMultipart;
 
 __CATCH:
@@ -5357,7 +5300,7 @@ bool MsgCopyDrmInfo(MsgType *pPartType)
                        strcpy (pPartType->param.szName + fileNameLen, pExt);
                } else {
                        strncpy(pPartType->param.szName, pTmpBuf, MSG_LOCALE_FILENAME_LEN_MAX);
-                       __MsgMakeFileName(pPartType->type, pPartType->param.szName, MSG_DRM_TYPE_NONE, 0);
+                       __MsgMakeFileName(pPartType->type, pPartType->param.szName, MSG_DRM_TYPE_NONE, 0, pPartType->param.szName, sizeof(pPartType->param.szName));
                }
        }
 
@@ -5400,13 +5343,13 @@ static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
                 * to the selected media part.
                 */
 
-               MSG_DEBUG("MsgResolveNestedMultipart : MIME_APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE\n");
+               MSG_DEBUG("MIME_APPLICATION_VND_WAP_MULTIPART_ALTERNATIVE");
 
                pSelectedPart = pPartBody->body.pMultipart;
 
                // NULL Pointer check!!
                if (pSelectedPart == NULL) {
-                       MSG_DEBUG("MsgResolveNestedMultipart : multipart(ALTERNATIVE) does not exist\n");
+                       MSG_DEBUG("multipart(ALTERNATIVE) does not exist");
                        break;
                }
 
@@ -5452,7 +5395,7 @@ static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
                }
 
                if (__MsgCopyNestedMsgType(pPartType, &(pSelectedPart->type)) == false) {
-                       MSG_DEBUG("MsgResolveNestedMultipart : MsgPriorityCopyMsgType failed \n");
+                       MSG_DEBUG("MsgPriorityCopyMsgType failed");
                        goto __CATCH;
                }
 
@@ -5477,7 +5420,7 @@ static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
        case MIME_APPLICATION_VND_WAP_MULTIPART_RELATED:
        case MIME_MULTIPART_RELATED:
 
-               MSG_DEBUG("MsgResolveNestedMultipart : MIME_APPLICATION_VND_WAP_MULTIPART_RELATED\n");
+               MSG_DEBUG("MIME_APPLICATION_VND_WAP_MULTIPART_RELATED");
 
                pSelectedPart = pPartBody->body.pMultipart;
 
@@ -5485,14 +5428,14 @@ static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
                        if (__MsgIsMultipartMixed(pSelectedPart->type.type)) {
 
                                if (pSelectedPart->pBody == NULL) {
-                                       MSG_DEBUG("MsgResolveNestedMultipart :pSelectedPart->pBody(1) is NULL\n");
+                                       MSG_DEBUG("pSelectedPart->pBody(1) is NULL");
                                        break;
                                }
 
                                pFirstPart = pSelectedPart->pBody->body.pMultipart;
 
                                if (pFirstPart == NULL) {
-                                       MSG_DEBUG("MsgResolveNestedMultipart : multipart(RELATED) does not exist\n");
+                                       MSG_DEBUG("multipart(RELATED) does not exist");
                                        break;
                                }
 
@@ -5542,7 +5485,7 @@ static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
        case MIME_APPLICATION_VND_WAP_MULTIPART_MIXED:
        case MIME_MULTIPART_MIXED:
 
-               MSG_DEBUG("MsgResolveNestedMultipart : MIME_APPLICATION_VND_WAP_MULTIPART_MIXED\n");
+               MSG_DEBUG("MIME_APPLICATION_VND_WAP_MULTIPART_MIXED");
 
                pPrevPart = NULL;
                pSelectedPart = pPartBody->body.pMultipart;
@@ -5550,7 +5493,7 @@ static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
                while (pSelectedPart) {
                        if (MsgIsMultipart(pSelectedPart->type.type)) {
                                if (pSelectedPart->pBody == NULL) {
-                                       MSG_DEBUG("MsgResolveNestedMultipart :pSelectedPart->pBody(2) is NULL\n");
+                                       MSG_DEBUG("pSelectedPart->pBody(2) is NULL");
                                        break;
                                }
 
@@ -5558,7 +5501,7 @@ static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
 
                                // NULL Pointer check!!
                                if (pFirstPart == NULL) {
-                                       MSG_DEBUG("MsgResolveNestedMultipart : multipart does not exist\n");
+                                       MSG_DEBUG("multipart does not exist");
                                        break;
                                }
 
@@ -5606,13 +5549,13 @@ static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
 
        case MIME_MULTIPART_REPORT:
 
-               MSG_DEBUG("MsgResolveNestedMultipart : MIME_MULTIPART_REPORT \n");
+               MSG_DEBUG("MIME_MULTIPART_REPORT");
 
                pTmpMultipart = pPartBody->body.pMultipart;
                pPrevPart = NULL;
 
                if (pTmpMultipart == NULL) {
-                       MSG_DEBUG("MsgResolveNestedMultipart : pTmpMultipart == NULL \n");
+                       MSG_DEBUG("pTmpMultipart == NULL");
                        return false;
                }
 
@@ -5627,7 +5570,7 @@ static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
                }
 
                if (pSelectedPart == NULL) {
-                       MSG_DEBUG("MsgResolveNestedMultipart : MIME_MULTIPART_REPORT [no selected part]\n");
+                       MSG_DEBUG("MIME_MULTIPART_REPORT [no selected part]");
 
                        pRemoveList = pPartBody->body.pMultipart->pNext;
                        if (pPartBody->body.pMultipart != NULL) {
@@ -5662,7 +5605,7 @@ static bool __MsgResolveNestedMultipart(MsgType *pPartType, MsgBody *pPartBody)
                }
 
                if (__MsgCopyNestedMsgType(pPartType, &(pSelectedPart->type)) == false) {
-                       MSG_DEBUG("MsgResolveNestedMultipart : MsgPriorityCopyMsgType failed \n");
+                       MSG_DEBUG("MsgPriorityCopyMsgType failed");
                        goto __CATCH;
                }
 
@@ -5719,7 +5662,7 @@ char *MsgResolveContentURI(char *szSrc)
 
        szTemp = (char *)malloc(length);
        if (szTemp == NULL) {
-               MSG_DEBUG("MsgResolveContentURI: memory full\n");
+               MSG_DEBUG("memory full");
                goto __CATCH;
        }
 
@@ -5746,7 +5689,7 @@ char *MsgRemoveQuoteFromFilename(char *pSrc)
        char *pBuff = NULL;
 
        if (pSrc == NULL) {
-               MSG_DEBUG("MsgRemoveQuoteFromFilename: pSrc is Null\n");
+               MSG_DEBUG("pSrc is Null");
                return NULL;
        }
 
@@ -5755,7 +5698,7 @@ char *MsgRemoveQuoteFromFilename(char *pSrc)
        pBuff = (char *)malloc(cLen + 1);
 
        if (pBuff == NULL) {
-               MSG_DEBUG("MsgRemoveQuoteFromFilename: pBuff mem alloc fail!\n");
+               MSG_DEBUG("pBuff mem alloc fail!");
                return NULL;
        }
        memset(pBuff, 0 , sizeof(char)*(cLen + 1));
@@ -5962,7 +5905,7 @@ bool MmsGetMsgAttrib(MmsMsgID msgID, MmsAttrib* pAttrib)
        MmsPluginStorage::instance()->getMmsMessage(&pMsg);
        memcpy(pAttrib, &(pMsg->mmsAttrib), sizeof(MmsAttrib));
 
-       MSG_DEBUG("MmsGetMsgAttrib: msgID = %lu ---------------------\n", msgID);
+       MSG_DEBUG("msgID = %lu ---------------------\n", msgID);
 
        if ('\0' != pMsg->szTrID[0])
                MSG_DEBUG("szTrID = %s \n", pMsg->szTrID);
@@ -6036,10 +5979,10 @@ static int __MsgGetLatin2UTFCodeSize(unsigned char *szSrc, int nChar)
 {
        int nCount = 0;
 
-       MSG_DEBUG("MsgGetLatin2UTFCodeSize: --------------- \n");
+       MSG_DEBUG("---------------");
 
        if ((szSrc == NULL) || (nChar <= 0)) {
-               MSG_DEBUG("MsgGetLatin2UTFCodeSize: szSrc is NULL !!!! --------------- \n");
+               MSG_DEBUG("szSrc is NULL !!!! ---------------");
                return 0;
        }
 
@@ -6212,7 +6155,7 @@ static int __MsgGetLatin52UTFCodeSize(unsigned char *szSrc, int nChar)
 {
        int nCount = 0;
 
-       MSG_DEBUG("MsgGetLatin52UTFCodeSize: --------------- \n");
+       MSG_DEBUG("---------------");
 
        if ((szSrc == NULL) || (nChar <= 0))
                return 0;
@@ -6223,7 +6166,7 @@ static int __MsgGetLatin52UTFCodeSize(unsigned char *szSrc, int nChar)
                        szSrc++;
                        nChar--;
                } else if (*szSrc == 0x00 || (*szSrc >= 0x80 && *szSrc <= 0x9F) ||
-                                       (*szSrc >= 0xA0 && *szSrc <= 0xCF) || (*szSrc >= 0xD1 && *szSrc <= 0xDC) |
+                                       (*szSrc >= 0xA0 && *szSrc <= 0xCF) || (*szSrc >= 0xD1 && *szSrc <= 0xDC) ||
                                        (*szSrc >= 0xDF && *szSrc <= 0xEF) || (*szSrc >= 0xF1 && *szSrc <= 0xFC) ||
                                        *szSrc == 0xD0 || *szSrc == 0xDD || *szSrc == 0xDE || *szSrc == 0xF0 ||
                                        *szSrc == 0xFD || *szSrc == 0xFE        || *szSrc == 0xFF) { //uni 0x00A0 ~ 0x00CF
@@ -6242,7 +6185,7 @@ static int __MsgLatin2UTF(unsigned char *des, int outBufSize, unsigned char *szS
        unsigned char*  org;
        unsigned char   t1, t2;
 
-       MSG_DEBUG("MsgLatin2UTF: --------------- \n");
+       MSG_DEBUG("---------------");
 
        org = des;
        outBufSize--;                   // NULL character
@@ -6294,7 +6237,7 @@ static int __MsgLatin7code2UTF(unsigned char *des, int outBufSize, unsigned char
        unsigned char t3;
        unsigned short temp = 0;
 
-       MSG_DEBUG("MsgUnicode2UTF: --------------- \n");
+       MSG_DEBUG("---------------");
 
        org = des;
        outBufSize--;   //Null Character
@@ -6453,7 +6396,7 @@ static int __MsgGetLatin72UTFCodeSize(unsigned char *szSrc, int nChar)
 {
        int nCount = 0;
 
-       MSG_DEBUG("MsgGetLatin72UTFCodeSize: --------------- \n");
+       MSG_DEBUG(" ---------------");
 
        if ((szSrc == NULL) || (nChar <= 0))
                return 0;
@@ -6488,7 +6431,7 @@ static int __MsgUnicode2UTF(unsigned char *des, int outBufSize, unsigned short *
        unsigned char t2;
        unsigned char t3;
 
-       MSG_DEBUG("MsgUnicode2UTF: --------------- \n");
+       MSG_DEBUG(" ---------------");
 
        org = des;
        outBufSize--;                   // NULL character
@@ -6553,10 +6496,10 @@ static int __MsgGetUnicode2UTFCodeSize(unsigned short *szSrc, int nChar)
 {
        int nCount = 0;
 
-       MSG_DEBUG("MsgGetUnicode2UTFCodeSize: --------------- \n");
+       MSG_DEBUG(" ---------------");
 
        if ((szSrc == NULL) || (nChar <= 0)) {
-               MSG_DEBUG("MsgGetUnicode2UTFCodeSize: szSrc is NULL !!!! --------------- \n");
+               MSG_DEBUG("szSrc is NULL !!!! ---------------");
                return 0;
        }
 
@@ -6598,7 +6541,7 @@ bool MmsAddrUtilRemovePlmnString(char *pszAddr)
        int strLen = 0;
 
        if ((!pszAddr) || (pszAddr[0] == 0)) {
-               MSG_DEBUG("MmsAddrUtilRemovePlmnString: pszAddr is null or zero\n");
+               MSG_DEBUG("pszAddr is null or zero");
                return false;
        }
 
@@ -6606,7 +6549,7 @@ bool MmsAddrUtilRemovePlmnString(char *pszAddr)
 
        pszAddrCopy = (char*)calloc(1,strLen + 1);
        if (!pszAddrCopy) {
-               MSG_DEBUG("MmsAddrUtilRemovePlmnString: pszAddrCopy is NULL, mem alloc failed\n");
+               MSG_DEBUG("pszAddrCopy is NULL, mem alloc failed");
                return false;
        }
 
@@ -6675,7 +6618,7 @@ static int __MsgCutUTFString(unsigned char *des, int outBufSize, unsigned char *
 {
        unsigned char *org;
 
-       MSG_DEBUG("MsgCutUTFString: --------------- \n");
+       MSG_DEBUG("---------------");
 
        org = des;
        outBufSize--;                   // NULL character
@@ -6718,7 +6661,7 @@ static int __MsgCutUTFString(unsigned char *des, int outBufSize, unsigned char *
                        *des = *szSrc;
                        des++;
                        szSrc++;
-                       MSG_DEBUG("MsgCutUTFString: utf8 incorrect range!\n");
+                       MSG_DEBUG("utf8 incorrect range!");
                }
 
                nChar--;
@@ -6750,8 +6693,6 @@ static bool __MsgLoadDataToDecodeBuffer(FILE *pFile, char **ppBuf, int *pPtr, in
        int nRead = 0;
        int length= 0;
 
-       MSG_DEBUG("MsgLoadDataToDecodeBuffer: \n");
-
        if (pFile == NULL) {
                MSG_DEBUG("Error");
 
@@ -6838,7 +6779,7 @@ bool MsgGetTypeByFileName(int *type, char *szFileName)
                        goto __CATCH;
 
                AvType = AvGetFileCodecType(szFileName);
-               MSG_DEBUG("MsgGetTypeByFileName:AvType(0x%x)\n", AvType);
+               MSG_DEBUG("AvType(0x%x)\n", AvType);
 
                switch (AvType) {
                case AV_DEC_AUDIO_MPEG4:
@@ -6868,15 +6809,13 @@ bool MsgGetTypeByFileName(int *type, char *szFileName)
        }
 
        *type = MimeGetMimeFromExtInt((const char*)pExt);
-       MSG_DEBUG("MsgGetTypeByFileName: szFileName = %s     type = %d \n", szFileName, type);
+       MSG_DEBUG("filename [%s], type [%d]", szFileName, *type);
        return true;
 
-
 __CATCH:
 
        *type = MIME_UNKNOWN;
-       MSG_DEBUG("MsgGetTypeByFileName: szFileName = %s     type = %d \n", szFileName, type);
-
+       MSG_DEBUG("filename [%s], type [%d]", szFileName, *type);
        return false;
 
 }
@@ -6896,11 +6835,11 @@ static bool __MmsMultipartSaveAsTempFile(MsgType *pPartType, MsgBody *pPartBody,
        FILE *pFile = NULL;
        char szFileName[MSG_FILENAME_LEN_MAX+1] = {0, };        // file name of temp file
        char szFullPath[MSG_FILEPATH_LEN_MAX] = {0, }; // full absolute path of temp file.
-
-       MSG_DEBUG("****   _MmsSaveMediaData:  [Multi part]  START  ***\n");
+       bool bFileExist = false;
+       MSG_BEGIN();
 
        if (!pPartType) {
-               MSG_DEBUG("pPartType is NULL\n");
+               MSG_DEBUG("pPartType is NULL");
                return false;
        }
 
@@ -6920,7 +6859,7 @@ static bool __MmsMultipartSaveAsTempFile(MsgType *pPartType, MsgBody *pPartBody,
 #ifndef __SUPPORT_DRM__
        __MsgMakeFileName(pPartType->type, szFileName, 0);      //FL & CD -> extension(.dm) SD -> extension(.dcf)
 #else
-       __MsgMakeFileName(pPartType->type, szFileName, pPartType->drmInfo.drmType, 0);  //FL & CD -> extension(.dm) SD -> extension(.dcf)
+       __MsgMakeFileName(pPartType->type, szFileName, pPartType->drmInfo.drmType, 0, szFileName, sizeof(szFileName));  //FL & CD -> extension(.dm) SD -> extension(.dcf)
        if (MsgDRMIsForwardLockType(pPartType->drmInfo.drmType))
                MsgChangeDrm2FileName(szFileName);
 #endif
@@ -6938,7 +6877,12 @@ static bool __MmsMultipartSaveAsTempFile(MsgType *pPartType, MsgBody *pPartBody,
                MsgGetTypeByFileName(&pPartType->type, szFullPath);
 
        // save file
-       if (bSave) {
+       bFileExist = MsgAccessFile(szFullPath, F_OK);
+
+       MSG_DEBUG("save flag  [%d],  filepath [%s], file exist [%d]", bSave, szFullPath, bFileExist);
+
+       if (bSave == true && bFileExist == false) {
+
                if ((pFile = MsgOpenFile(szFullPath, "wb+")) == NULL) {
                        MSG_DEBUG("MsgOpenFile failed");
                        goto __CATCH;
@@ -6956,7 +6900,6 @@ static bool __MmsMultipartSaveAsTempFile(MsgType *pPartType, MsgBody *pPartBody,
                pPartBody->offset = 0;
                pPartBody->size = MsgGetFileSize(pPartBody->szOrgFilePath);
 
-               MSG_DEBUG("Save Temp File to [%s]", pPartBody->szOrgFilePath);
 
                if (pPartType->drmInfo.drmType != MSG_DRM_TYPE_NONE) {
                        MsgDrmRegisterFile(MSG_MODE_FILE, szFullPath, strlen(szFullPath));
@@ -6967,10 +6910,15 @@ static bool __MmsMultipartSaveAsTempFile(MsgType *pPartType, MsgBody *pPartBody,
                                pPartType->drmInfo.szDrm2FullPath = MsgStrCopy(szFullPath);
                        }
                }
-
+               MSG_DEBUG("Save Part File to [%s]", pPartBody->szOrgFilePath);
+       } else {
+               snprintf(pPartBody->szOrgFilePath, sizeof(pPartBody->szOrgFilePath), "%s", szFullPath);
+               pPartBody->offset = 0;
+               pPartBody->size = MsgGetFileSize(pPartBody->szOrgFilePath);
+               MSG_DEBUG("Set Part File to [%s]", pPartBody->szOrgFilePath);
        }
-       MSG_DEBUG("****   MmsGetMediaPartData:  [Multi part]  E  N  D  (Successfully)  ***\n");
 
+       MSG_END();
        return true;
 
 __CATCH:
@@ -6979,11 +6927,11 @@ __CATCH:
                MsgCloseFile(pFile);
                pFile = NULL;
        }
-
+       MSG_END();
        return false;
 }
 
-static bool __MmsGetMediaPartData(MsgType *pPartType, MsgBody *pPartBody, FILE* pFile)
+bool __MmsGetMediaPartData(MsgType *pPartType, MsgBody *pPartBody, FILE* pFile)
 {
        int nRead = 0;
        int nRead2 = 0;
@@ -7011,7 +6959,7 @@ static bool __MmsGetMediaPartData(MsgType *pPartType, MsgBody *pPartBody, FILE*
                pTempData = MsgOpenAndReadMmsFile(pPartBody->szOrgFilePath, offset, size, &nRead);
 
                if (pTempData == NULL) {
-                       MSG_DEBUG("MmsGetMediaPartData : pTempData read fail\n");
+                       MSG_DEBUG("pTempData read fail");
                        goto __CATCH;
                }
 
@@ -7022,7 +6970,7 @@ static bool __MmsGetMediaPartData(MsgType *pPartType, MsgBody *pPartBody, FILE*
        }
 
        if (pData == NULL) {
-               MSG_DEBUG("MmsGetMediaPartData : there is no data \n");
+               MSG_DEBUG("there is no data");
                goto __RETURN;
        }
 
@@ -7033,7 +6981,7 @@ static bool __MmsGetMediaPartData(MsgType *pPartType, MsgBody *pPartBody, FILE*
                pPartType->param.charset = MSG_CHARSET_UTF8;
 
        if (MsgWriteFile(pNewData, sizeof(char), nRead2,  pFile) != (size_t)nRead2) {
-               MSG_DEBUG("MmsGetMediaPartData: file writing fail \n");
+               MSG_DEBUG("file writing fail");
 
                goto __CATCH;
        }
@@ -7084,7 +7032,7 @@ static char *__MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue
        case MSG_ENCODING_BASE64:
 
                pConvertedData = (char*)MsgDecodeBase64((UCHAR*)pData, (ULONG)nRead, (ULONG*)&nByte);
-               MSG_DEBUG("MmsGetBinaryUTF8Data : MSG_ENCODING_BASE64     bodyLength = %d \n", nByte);
+               MSG_DEBUG("MSG_ENCODING_BASE64 bodyLength [%d]", nByte);
 
                pTemp = pConvertedData;
                nTemp = nByte;
@@ -7094,7 +7042,7 @@ static char *__MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue
        case MSG_ENCODING_QUOTE_PRINTABLE:
 
                pConvertedData = (char*)MsgDecodeQuotePrintable((UCHAR*)pData, (ULONG)nRead, (ULONG*)&nByte);
-               MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_ENCODING_QUOTE_PRINTABLE     bodyLength = %d \n", nByte);
+               MSG_DEBUG("MSG_ENCODING_QUOTE_PRINTABLE bodyLength [%d]", nByte);
 
                pTemp = pConvertedData;
                nTemp = nByte;
@@ -7103,8 +7051,7 @@ static char *__MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue
 
        default:
 
-               MSG_DEBUG("MmsGetBinaryUTF8Data: 8bit    OR    Binary   bodyLength = %d \n", nRead);
-
+               MSG_DEBUG("encoding val [%d] bodyLength [%d]", msgEncodingValue, nRead);
                pTemp = pData;
                nTemp = nRead;
 
@@ -7118,14 +7065,14 @@ static char *__MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue
                case MSG_CHARSET_UTF16:
                case MSG_CHARSET_USC2:
 
-                       MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_CHARSET_USC2 \n");
+                       MSG_DEBUG("MSG_CHARSET_USC2");
 
                        if (((UINT8)pTemp[0]) == 0xFF && ((UINT8)pTemp[1]) == 0xFE) {
                                nChar = (nTemp / 2 - 1);
 
                                mszTempStr = (unsigned short*) malloc(nChar * sizeof(unsigned short));
                                if (mszTempStr == NULL) {
-                                       MSG_DEBUG("MmsGetBinaryUTF8Data : 1. Memory Full !!! \n");
+                                       MSG_DEBUG("Memory Full !!!");
                                        goto __CATCH;
                                }
 
@@ -7143,7 +7090,7 @@ static char *__MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue
 
                                mszTempStr = (unsigned short*) malloc(nChar * sizeof(unsigned short));
                                if (mszTempStr == NULL) {
-                                       MSG_DEBUG("MmsGetBinaryUTF8Data: 2. Memory Full !!! \n");
+                                       MSG_DEBUG("Memory Full !!!");
                                        goto __CATCH;
                                }
 
@@ -7165,13 +7112,12 @@ static char *__MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue
 
                case MSG_CHARSET_US_ASCII:
 
-                       MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_CHARSET_US_ASCII \n");
+                       MSG_DEBUG("MSG_CHARSET_US_ASCII");
 
                        /* fall through */
-
                case MSG_CHARSET_UTF8:
 
-                       MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_CHARSET_UTF8 or Others \n");
+                       MSG_DEBUG("MSG_CHARSET_UTF8 or Others");
 
                        // skip BOM (Byte Order Mark) bytes .. (Please refer to the http://www.unicode.org/faq/utf_bom.html#BOM)
                        if (nTemp >= 3) {
@@ -7189,7 +7135,7 @@ static char *__MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue
 
                        /* Greek */
 
-                       MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_CHARSET_ISO_8859_7 \n");
+                       MSG_DEBUG("MSG_CHARSET_ISO_8859_7");
 
                        nByte = __MsgGetLatin72UTFCodeSize((unsigned char*)pTemp, nTemp);
                        pConvertedStr = (char *)malloc(nByte + 1);
@@ -7204,7 +7150,7 @@ static char *__MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue
                case MSG_CHARSET_ISO_8859_9:
 
                        /* Turkish */
-                       MSG_DEBUG("MmsGetBinaryUTF8Data: MSG_CHARSET_ISO_8859_9 \n");
+                       MSG_DEBUG("MSG_CHARSET_ISO_8859_9");
 
                        nByte = __MsgGetLatin52UTFCodeSize((unsigned char*)pTemp, nTemp);
                        pConvertedStr = (char *)malloc(nByte + 1);
@@ -7218,7 +7164,7 @@ static char *__MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue
 
                default:
 
-                       MSG_DEBUG("MmsGetBinaryUTF8Data: Other charsets \n");
+                       MSG_DEBUG("Other charsets");
 
                        nByte = __MsgGetLatin2UTFCodeSize((unsigned char*)pTemp, nTemp);
                        pConvertedStr = (char *)malloc(nByte + 1);
@@ -7237,7 +7183,7 @@ static char *__MmsGetBinaryUTF8Data(char *pData, int nRead, int msgEncodingValue
 
        pReturnData = (char *)malloc(*npRead);
        if (pReturnData == NULL) {
-               MSG_DEBUG("MmsGetBinaryUTF8Data : pReturnData alloc fail. \n");
+               MSG_DEBUG("pReturnData alloc fail.");
 
                goto __CATCH;
        }
@@ -7293,7 +7239,7 @@ static bool __MsgMakeFileName(int iMsgType, char *szFileName, int nUntitleIndex)
        char *pExt = NULL;
 
 
-       MSG_DEBUG("MsgMakeFileName: iMsgType = %d     szFileName = %s \n", iMsgType, szFileName);
+       MSG_DEBUG("iMsgType = %d, szFileName = %s", iMsgType, szFileName);
 
        if (szFileName == NULL)
                return false;
@@ -7319,13 +7265,13 @@ static bool __MsgMakeFileName(int iMsgType, char *szFileName, int nUntitleIndex)
        }
 
        if (iMsgType == MIME_APPLICATION_OCTET_STREAM) {
-               MSG_DEBUG("MsgMakeFileName: unsupported MsgType\n");
+               MSG_DEBUG("unsupported MsgType");
                goto __CATCH;
        } else {
                int             nLen = 0;
                strncpy(szTemp, szText, MSG_FILENAME_LEN_MAX - 5);
                if (iMsgType == MIME_UNKNOWN || (pExt = MimeGetExtFromMimeInt((MimeType)iMsgType)) == NULL) {
-                       MSG_DEBUG("MsgMakeFileName: Failed to get extension of that mime data file. \n");
+                       MSG_DEBUG("Failed to get extension of that mime data file.");
                        goto __CATCH;
                }
                nLen = MSG_FILENAME_LEN_MAX - strlen(szTemp);
@@ -7335,7 +7281,7 @@ static bool __MsgMakeFileName(int iMsgType, char *szFileName, int nUntitleIndex)
 
        strcpy(szFileName, szTemp);
 
-       MSG_DEBUG("MsgMakeFileName: made szFileName = %s \n", szFileName);
+       MSG_DEBUG("made szFileName = %s", szFileName);
 
        return true;
 
@@ -7351,92 +7297,59 @@ __CATCH:
        }
 }
 #else
-static bool __MsgMakeFileName(int iMsgType, char *szFileName, MsgDrmType drmType, int nUntitleIndex)
+static bool __MsgMakeFileName(int iMsgType, char *szFileName, MsgDrmType drmType, int nUntitleIndex, char *outBuf, int outBufLen)
 {
-       char szText[MSG_FILENAME_LEN_MAX+1]={0,};
        char szTemp[MSG_FILENAME_LEN_MAX+1]={0,};
        char szTempFileName[MSG_FILENAME_LEN_MAX+1]={0,};
        char *pExt = NULL;
 
-       MSG_DEBUG("MsgMakeFileName: iMsgType = 0x%x, drmType = %d, szFileName = %s \n", iMsgType, drmType, szFileName);
+       MSG_DEBUG("Input : type  [0x%x], drmType [%d], filename [%s]", iMsgType, drmType, szFileName);
 
        if (szFileName == NULL)
                return false;
 
-       if (szFileName && (szFileName[0] != '\0')) {
+       int inp_len = strlen(szFileName);
+       if (inp_len >0) {
                MsgGetFileNameWithoutExtension (szTempFileName, szFileName);
-
-               if (drmType != MSG_DRM_TYPE_NONE) {
-                       pExt = strrchr(szTempFileName, '.');
-                       if (pExt == NULL) {
-                               memset(szText, 0, MSG_FILENAME_LEN_MAX+1);
-                               strncpy(szText, szTempFileName, MSG_FILENAME_LEN_MAX - 1);
-                               strcat(szText, ".");                    // add '.'
-                       } else {
-                               memset(szText, 0, MSG_FILENAME_LEN_MAX+1);
-                               strncpy(szText, szTempFileName, pExt+1 - szFileName);
-                       }
-               } else {
-                       pExt = strrchr(szTempFileName, '.');
-                       if (pExt == NULL) {
-                               memset(szText, 0, MSG_FILENAME_LEN_MAX+1);
-                               strncpy(szText, szTempFileName, MSG_FILENAME_LEN_MAX - 1);
-                               strcat(szText, ".");
-                       } else  {
-                               return true;
-                       }
-               }
        } else {
                if (nUntitleIndex >= 1) {
-                       snprintf(szText, MSG_FILENAME_LEN_MAX+1, "%s_%d.", "untitled", nUntitleIndex);
+                       snprintf(szTempFileName, sizeof(szTempFileName), "%s_%d", "untitled", nUntitleIndex);
                } else {
-                       snprintf(szText, MSG_FILENAME_LEN_MAX+1, "%s.", "untitled");
+                       snprintf(szTempFileName, sizeof(szTempFileName), "%s", "untitled");
                }
        }
 
        if (drmType == MSG_DRM_TYPE_SD) {
-               strncpy(szTemp, szText, MSG_FILENAME_LEN_MAX - 5);
-               strcat(szTemp, "dcf");
+               snprintf(szTemp, sizeof(szTemp), "%s.dcf", szTempFileName);
        } else if (MsgDRMIsForwardLockType(drmType)) {
-               strncpy(szTemp, szText, MSG_FILENAME_LEN_MAX - 4);
-               strcat(szTemp, "dm");
+               snprintf(szTemp, sizeof(szTemp), "%s.dm", szTempFileName);
        } else {
                if (iMsgType == MIME_APPLICATION_OCTET_STREAM) {
-                       MSG_DEBUG("MsgMakeFileName: unsupported MsgType\n");
+                       MSG_DEBUG("unsupported MsgType");
                        goto __CATCH;
                } else {
-                       int             nLen = 0;
-                       strncpy(szTemp, szText, MSG_FILENAME_LEN_MAX - 5);
-                       //temporary commented to save file as original name.
-                       if (pExt == NULL) {
 
-                               if (iMsgType == MIME_UNKNOWN || (pExt = MimeGetExtFromMimeInt((MimeType)iMsgType)) == NULL) {
-                                       MSG_DEBUG("MsgMakeFileName: Failed to get extension of that mime data file. \n");
-                                       goto __CATCH;
-                               }
+                       if (iMsgType == MIME_UNKNOWN) {
+                               MSG_DEBUG("Failed to get extension of that mime data file.");
+                               goto __CATCH;
                        }
 
-                       nLen = MSG_FILENAME_LEN_MAX - strlen(szTemp);
-                       strncat(szTemp, pExt, nLen);
+                       pExt = MimeGetExtFromMimeInt((MimeType)iMsgType);
+                       if (pExt) {
+                               snprintf(szTemp, sizeof(szTemp), "%s.%s", szTempFileName, pExt);
+                       } else {
+                               MSG_DEBUG("Failed to get extension of that mime data file.");
+                               goto __CATCH;
+                       }
                }
        }
 
-       strcpy(szFileName, szTemp);
-
-       MSG_DEBUG("MsgMakeFileName: made szFileName = %s \n", szFileName);
-
+       snprintf(outBuf, outBufLen, "%s", szTemp);
+       MSG_DEBUG("Result : filename [%s]", outBuf);
        return true;
 
 __CATCH:
-       {
-               char *p = NULL;
-               p = strrchr(szText, '.');
-               if (p != NULL)
-                       *p = 0;
-               snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%s", szText);
-
-               return false;
-       }
+       return false;
 }
 #endif
 
@@ -7479,7 +7392,7 @@ bool MmsGetMediaPartHeader(int index, MsgType *pHeader)
        MsgMultipart *pPart = NULL;
 
        if (pHeader == NULL) {
-               MSG_DEBUG("MmsGetMediaPartHeader: Invalid pHeader input. It's null \n");
+               MSG_DEBUG("Invalid pHeader input. It's null");
                return false;
        }
 
@@ -7490,7 +7403,7 @@ bool MmsGetMediaPartHeader(int index, MsgType *pHeader)
 
        /* Requires header of non-presentation */
        if (MsgIsMultipart(pMsg->msgType.type)) {
-               MSG_DEBUG("MmsGetMediaPartHeader: Multipart header [index = %d] \n", index);
+               MSG_DEBUG("Multipart header [index = %d] \n", index);
 
                pPart = pMsg->msgBody.body.pMultipart;
 
@@ -7498,13 +7411,13 @@ bool MmsGetMediaPartHeader(int index, MsgType *pHeader)
                        pPart = pPart->pNext;
 
                if (pPart == NULL) {
-                       MSG_DEBUG("MmsGetMediaPartHeader: There is no such msg part.\n");
+                       MSG_DEBUG("There is no such msg part.");
                        return false;
                }
 
                memcpy(pHeader, &pPart->type, sizeof(MsgType));
        } else {
-               MSG_DEBUG("MmsGetMediaPartHeader: Requires singlepart header \n");
+               MSG_DEBUG("Requires singlepart header");
                memcpy(pHeader, &pMsg->msgType, sizeof(MsgType));
        }
 
@@ -7513,28 +7426,27 @@ bool MmsGetMediaPartHeader(int index, MsgType *pHeader)
 
 static bool __MmsDebugPrintMulitpartEntry(MsgMultipart *pMultipart, int index)
 {
-       MSG_DEBUG("------------------------------\n");
-       MSG_DEBUG("%dth multipart info\n", index);
-       MSG_DEBUG("header size=%d\n", pMultipart->type.size);
-       MSG_DEBUG("body size=%d\n", pMultipart->type.contentSize);
-       MSG_DEBUG("content type=%s\n", MmsDebugGetMimeType((MimeType)pMultipart->type.type));
-       MSG_DEBUG("content ID=%s\n", pMultipart->type.szContentID);
-       MSG_DEBUG("content location=%s\n", pMultipart->type.szContentLocation);
+       MSG_DEBUG("------------------------------");
+       MSG_DEBUG("[%dth] multipart info", index);
+       MSG_DEBUG("header size [%d], body size [%d]", pMultipart->type.size, pMultipart->type.contentSize);
+       MSG_DEBUG("content type [%s]", MmsDebugGetMimeType((MimeType)pMultipart->type.type));
+       MSG_DEBUG("content ID [%s]", pMultipart->type.szContentID);
+       MSG_DEBUG("content location [%s]", pMultipart->type.szContentLocation);
+       MSG_DEBUG("parameter Name [%s]", pMultipart->type.param.szName);
+       MSG_DEBUG("parameter Filename[%s]", pMultipart->type.param.szFileName);
 
        if (pMultipart->type.type == MIME_TEXT_PLAIN) {
-               MSG_DEBUG("text info\n");
-               MSG_DEBUG("charset=%d\n", pMultipart->type.param.charset);
-               MSG_DEBUG("text file name=%s\n", pMultipart->type.param.szName);
+               MSG_DEBUG("text info : charset [%d], name [%s]", pMultipart->type.param.charset, pMultipart->type.param.szName);
        }
 #ifdef __SUPPORT_DRM__
        if (pMultipart->type.drmInfo.drmType != MSG_DRM_TYPE_NONE) {
-               MSG_DEBUG("drm info\n");
-               MSG_DEBUG("drm type=%d      (0: NONE 1: Fowward Lock, 2:Combined Delivery, 3: Separated Delivery)\n", pMultipart->type.drmInfo.drmType);
-               MSG_DEBUG("drm content type=%s\n", MmsDebugGetMimeType((MimeType)pMultipart->type.drmInfo.contentType));
-               MSG_DEBUG("drm content URI=%s\n", pMultipart->type.drmInfo.szContentURI);
-               MSG_DEBUG("drm2FullPath=%s\n", pMultipart->type.drmInfo.szDrm2FullPath);
+               MSG_DEBUG("drm info");
+               MSG_DEBUG("drm type [%d] (0: NONE 1: Fowward Lock, 2:Combined Delivery, 3: Separated Delivery)", pMultipart->type.drmInfo.drmType);
+               MSG_DEBUG("drm content type [%s]", MmsDebugGetMimeType((MimeType)pMultipart->type.drmInfo.contentType));
+               MSG_DEBUG("drm content URI [%s]", pMultipart->type.drmInfo.szContentURI);
+               MSG_DEBUG("drm2FullPath [%s]", pMultipart->type.drmInfo.szDrm2FullPath);
        }
 #endif
-       MSG_DEBUG("------------------------------\n");
+       MSG_DEBUG("------------------------------");
        return true;
 }
index cbdcd22..5d5a4f9 100755 (executable)
 #include "MmsPluginUserAgent.h"
 #include "MmsPluginConnManWrapper.h"
 
-static bool __httpGetHeaderField(MMS_HTTP_HEADER_FIELD_T httpHeaderItem, char *szHeaderBuffer);
-static void __httpGetHost(char *szUrl, char *szHost, int nBufferLen);
-static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int ulContentLen);
-
-static MMS_NET_ERROR_T __httpReceiveData(void *ptr, size_t size, size_t nmemb, void *userdata);
-static size_t  __httpGetTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata);
-static size_t  __httpPostTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata);
+#define MMS_FREE(obj)\
+       if (obj){\
+               free(obj);\
+               obj = NULL;\
+       }
 
-static int __httpCmdInitSession(MMS_PLUGIN_HTTP_DATA_S *httpConfig);
-static int __httpCmdPostTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig);
-static int __httpCmdGetTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig);
 
 static void __http_print_profile(CURL *curl);
+static int __http_debug_cb (CURL *input_curl, curl_infotype input_info_type, char *input_data , size_t input_size, void *input_void);
+
+static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int ulContentLen);
+static bool __httpGetHeaderField(MMS_HTTP_HEADER_FIELD_T httpHeaderItem, char *szHeaderBuffer);
+static void __httpGetHost(char *szUrl, char *szHost, int nBufferLen);
 
 /*==================================================================================================
                                      FUNCTION IMPLEMENTATION
 ==================================================================================================*/
+static int __http_progress_cb(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
+{
+       MSG_DEBUG("download(%.0f/%.0f) : upload(%.0f/%.0f)", dlnow, dltotal, ulnow, ultotal);
+       return 0;
+}
+
+static int __http_debug_cb (CURL *input_curl, curl_infotype input_info_type, char *input_data , size_t input_size, void *input_void)
+{
+       MSG_DEBUG("curl_infotype [%d] : %s", input_info_type, input_data);
+       return 0;
+}
+
+static size_t __http_write_response_cb(void *ptr, size_t size, size_t nmemb, void *data)
+{
+       MSG_BEGIN();
+       FILE *writehere = (FILE *)data;
+       return fwrite(ptr, size, nmemb, writehere);
+}
+
 static void __http_print_profile(CURL *curl)
 {
        double speed_upload, speed_download, total_time;
@@ -167,7 +186,7 @@ static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int
                MSG_DEBUG("%s", pcheader);
                *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
        }
-
+/* NOW not support gzip, deflate encoding in MMS Plugin
        memset(szBuffer, 0, 1025);
        memset(pcheader, 0, HTTP_REQUEST_LEN);
        nResult = __httpGetHeaderField(MMS_HH_ACCEPT_ENCODING, szBuffer);
@@ -176,7 +195,7 @@ static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int
                MSG_DEBUG("%s", pcheader);
                *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
        }
-
+*/
        memset(szBuffer, 0, 1025);
        memset(pcheader, 0, HTTP_REQUEST_LEN);
        nResult = __httpGetHeaderField(MMS_HH_USER_AGENT, szBuffer);
@@ -309,369 +328,373 @@ static void __httpGetHost(char *szUrl, char *szHost, int nBufferLen)
        }
 }
 
-static MMS_NET_ERROR_T __httpReceiveData(void *ptr, size_t size, size_t nmemb, void *userdata)
+static int __http_multi_perform(void *session)
 {
-       MMS_NET_ERROR_T httpRet = eMMS_UNKNOWN;
+       MSG_BEGIN();
 
-       MmsPluginHttpAgent *pHttpAgent = MmsPluginHttpAgent::instance();
-       MMS_PLUGIN_HTTP_CONTEXT_S *pMmsPlgCd = pHttpAgent->getMmsPldCd();
-       long length_received = size * nmemb;
+       CURLM *multi_handle;
+       CURLMcode rcm;
 
-       if (length_received) {
-               //Save the received buffer in a safe place.
-               if (pMmsPlgCd->final_content_buf == NULL) {
-                       MSG_DEBUG("Body Lenghth Read = %d", length_received);
-                       pMmsPlgCd->final_content_buf = (unsigned char *)malloc((length_received + 1) * sizeof(unsigned char));
+       int still_running;
+       int ret = 0;
+       bool abort_flag = false;
 
-                       if (pMmsPlgCd->final_content_buf == NULL) {
-                               MSG_DEBUG("malloc fail");
-                               return eMMS_HTTP_EVENT_RECV_DATA_ERROR;
-                       }
+       CURLMsg *msg;
+       int msgs_left;
 
-                       memset(pMmsPlgCd->final_content_buf,0x0,((length_received + 1) * sizeof(unsigned char)));
-                       MSG_DEBUG(" Global g_final_content_buf=%0x", pMmsPlgCd->final_content_buf);
-               } else {
-                       //realloc pHttpEvent->bodyLen extra and memset
+       multi_handle = curl_multi_init();
 
-                       unsigned char * buf = (unsigned char *)realloc(pMmsPlgCd->final_content_buf,
-                                       (pMmsPlgCd->bufOffset + length_received + 1) * sizeof(unsigned char));
+       if (curl_multi_add_handle(multi_handle, session) != 0) {
+               MSG_DEBUG("curl_multi_add_handle is failed");
+               curl_multi_cleanup(multi_handle);
+               return -1;
+       }
 
-                       if (buf == NULL) {
-                               MSG_DEBUG("realloc fail");
-                               return eMMS_HTTP_EVENT_RECV_DATA_ERROR;
-                       }
+       /* we start some action by calling perform right away */
+       rcm = curl_multi_perform(multi_handle, &still_running);
+       MSG_DEBUG("curl_multi_perform first end : rcm = %d, still_running = %d", rcm, still_running);
+
+       do {
+               struct timeval timeout;
+               int rc; /* select() return code */
+
+               fd_set fdread;
+               fd_set fdwrite;
+               fd_set fdexcep;
+               int maxfd = -1;
+
+               long curl_timeo = -1;
+
+               FD_ZERO(&fdread);
+               FD_ZERO(&fdwrite);
+               FD_ZERO(&fdexcep);
+
+               /* set a suitable timeout to play around with */
+               timeout.tv_sec = 10;
+               timeout.tv_usec = 0;
+
+               curl_multi_timeout(multi_handle, &curl_timeo);
+               if(curl_timeo >= 0) {
+                       MSG_DEBUG("curl_timeo = %ld", curl_timeo);
+                       timeout.tv_sec = curl_timeo / 1000;
+                       if(timeout.tv_sec > 1)
+                               timeout.tv_sec = 1;
+                       else
+                               timeout.tv_usec = (curl_timeo % 1000) * 1000;
+               }
+
+               curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
 
-                       pMmsPlgCd->final_content_buf = buf;
-                       MSG_DEBUG("Body Lenghth Read = %d Content Length = %d", length_received, pMmsPlgCd->bufOffset);
-                       memset((pMmsPlgCd->final_content_buf +pMmsPlgCd->bufOffset), 0x0,
-                                       ((length_received + 1) * sizeof(unsigned char)));
-                       MSG_DEBUG(" Global g_final_content_buf=%0x", pMmsPlgCd->final_content_buf);
+               /* In a real-world program you OF COURSE check the return code of the
+               function calls.  On success, the value of maxfd is guaranteed to be
+               greater or equal than -1.  We call select(maxfd + 1, ...), specially in
+               case of (maxfd == -1), we call select(0, ...), which is basically equal
+               to sleep. */
 
+               rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
 
+               switch(rc) {
+                       case -1:
+                               /* select error */
+                               MSG_DEBUG("select error");
+                       break;
+                       case 0: /* timeout */
+                       default: /* action */
+                               rcm = curl_multi_perform(multi_handle, &still_running);
+                       break;
                }
 
-               //copy body
-               if (pMmsPlgCd->final_content_buf != NULL) {
-                       memcpy( pMmsPlgCd->final_content_buf + pMmsPlgCd->bufOffset, ptr, length_received);
-                       MSG_DEBUG("Current g_bufOffset =%d", pMmsPlgCd->bufOffset);
-                       /*  Content  Received */
-                       MSG_DEBUG("Total Content received PTR =%0X, Content Size =%d", pMmsPlgCd->final_content_buf,
-                                               pMmsPlgCd->bufOffset);
-                       pMmsPlgCd->bufOffset = pMmsPlgCd->bufOffset + length_received;
-                       httpRet = eMMS_UNKNOWN;
+               abort_flag = MmsPluginHttpAgent::instance()->getAbortFlag();
+               if (abort_flag == true) {
+                       MSG_DEBUG("abort flag is Set");
+                       ret = -1;
                }
-       } else {
-               MSG_DEBUG("End of Data transfer");
-               MSG_DEBUG("MmsHttpReadData Buffer Size = %d", pMmsPlgCd->bufOffset);
-               MSG_DEBUG("MmsHttpReadData Buffer = %s", pMmsPlgCd->final_content_buf);
 
-               if (pMmsPlgCd->bufOffset == 0) {
-                       /*  This is applicable when - M-ReadRec.inf,M-Ack.ind, M-NotifyResp.ind posted  */
-                       MSG_DEBUG(" Content Size is Zero");
+               MSG_DEBUG("curl_multi_perform end : rcm = %d, still_running = %d, abort_flag = %d", rcm, still_running, abort_flag);
 
-                       if (pMmsPlgCd->final_content_buf != NULL) {
-                               free(pMmsPlgCd->final_content_buf );
-                               pMmsPlgCd->final_content_buf = NULL;
-                       }
+       } while(still_running && (abort_flag == false));
 
-                       httpRet = eMMS_HTTP_EVENT_SENT_ACK_COMPLETED;
-               } else if (pMmsPlgCd->final_content_buf != NULL && pMmsPlgCd->bufOffset != 0) {
-                       // Process Http Data
-                       MSG_DEBUG(" Send Received Data to UA");
-                       httpRet = eMMS_HTTP_RECV_DATA; // eMMS_HTTP_RECV_DATA;
-               } else {
-                       httpRet = eMMS_UNKNOWN; // check later
-               }
+       while ((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
+               if (msg->msg == CURLMSG_DONE) {
 
-               return httpRet;
+                       if (msg->easy_handle == session) {
+                               MSG_DEBUG("HTTP transfer completed with status %d", msg->data.result);
+                               curl_multi_remove_handle(multi_handle, session);
+                       } else {
+                               MSG_DEBUG("Unknown handle HTTP transfer completed with status %d", msg->data.result);
+                       }
+               }
        }
 
-       return httpRet;
-}
+       curl_multi_cleanup(multi_handle);
 
+       MSG_END();
+       return ret;
+}
 
-static size_t  __httpPostTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata)
+MmsPluginHttpAgent *MmsPluginHttpAgent::pInstance = NULL;
+MmsPluginHttpAgent *MmsPluginHttpAgent::instance()
 {
-       MSG_DEBUG(" ======  HTTP_EVENT_SENT ========");
-       long length_received = size * nmemb;
-       __httpReceiveData(ptr, size, nmemb, userdata);
+       if (!pInstance)
+       {
+               pInstance = new MmsPluginHttpAgent();
+       }
 
-       return length_received;
+       return pInstance;
 }
 
-static size_t  __httpGetTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata)
+
+MmsPluginHttpAgent::MmsPluginHttpAgent()
 {
-       MSG_DEBUG(" ======  HTTP_EVENT_RECEIVED ========");
-       long length_received = size * nmemb;
-       __httpReceiveData(ptr, size, nmemb, userdata);
+       MSG_BEGIN();
 
-       return length_received;
+       abort = false;
+       respfile = NULL;
+       session_header = NULL;
+       session_option = NULL;
+
+       transaction_type = MMS_HTTP_TRANSACTION_TYPE_UNKNOWN;
+       MSG_END();
 }
 
-static int __httpCmdInitSession(MMS_PLUGIN_HTTP_DATA_S *httpConfig)
+MmsPluginHttpAgent::~MmsPluginHttpAgent()
 {
-       MSG_DEBUG("HttpCmd Init Session");
-
-       char proxyAddr[MAX_IPV4_LENGTH + 1] = {0};
-
-       snprintf(proxyAddr, MAX_IPV4_LENGTH + 1, "%s:%d", httpConfig->mmscConfig.httpProxyIpAddr, httpConfig->mmscConfig.proxyPortNo);
-       MSG_DEBUG("profileId [%d], proxyAddr [%s]", httpConfig->currentProfileId, proxyAddr);
+       MSG_BEGIN();
 
-       CURL *curl_session = curl_easy_init();
-       if (NULL == curl_session) {
-               MSG_DEBUG("curl_easy_init() failed");
-               return eMMS_HTTP_SESSION_OPEN_FAILED;
+       if (session_header) {
+               MSG_DEBUG("session header is exist : free session header");
+               curl_slist_free_all((curl_slist *)session_header);
+               session_header = NULL;
        }
 
-       int curl_status = curl_easy_setopt(curl_session, CURLOPT_PROXY, proxyAddr);
-       if (curl_status != CURLM_OK) {
-               MSG_DEBUG("curl_easy_setopt(): CURLOPT_PROXY failed");
-               curl_easy_cleanup(curl_session);
-               return eMMS_HTTP_SESSION_OPEN_FAILED;
+       if (session_option) {
+               MSG_DEBUG("session is exist : cleanup session");
+               curl_easy_cleanup(session_option);
+               session_option = NULL;
        }
 
-       httpConfig->session = curl_session;
-
-       return eMMS_HTTP_SESSION_INIT;
+       MSG_END();
 }
 
-
-static int __httpCmdPostTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig)
+void MmsPluginHttpAgent::initSession()
 {
-       int trId;
-
-       MSG_DEBUG("HttpCmd Post Transaction");
-       MSG_DEBUG(" === HTTP Agent Thread : Signal ==> eMMS_HTTP_SIGNAL_POST_TRANSACTION");
-
-       char deviceName[1024] = {0,};
-
-       MmsPluginCmAgent::instance()->getDeviceName(deviceName);
-
-       MSG_DEBUG("deviceName: [%s]", deviceName);
-       int curl_status = curl_easy_setopt(httpConfig->session, CURLOPT_INTERFACE, deviceName);
+       MSG_BEGIN();
 
-       if (curl_status != CURLM_OK) {
-               MSG_DEBUG("curl_easy_setopt(): CURLOPT_INTERFACE failed");
+       this->transaction_type = MMS_HTTP_TRANSACTION_TYPE_UNKNOWN;
 
-               return eMMS_EXCEPTIONAL_ERROR;
+       if (session_header) {
+               MSG_DEBUG("session header is exist : free session header");
+               curl_slist_free_all((curl_slist *)session_header);
+               session_header = NULL;
        }
 
-       CURLcode rc = curl_easy_perform(httpConfig->session);
-
-       __http_print_profile(httpConfig->session);
-
-       MmsPluginHttpAgent*     httpAgent = MmsPluginHttpAgent::instance();
-       MMS_PLUGIN_HTTP_DATA_S *httpConfigData = httpAgent->getHttpConfigData();
-       if (httpConfigData->sessionHeader) {
-               curl_slist_free_all((curl_slist *)httpConfigData->sessionHeader);
-               httpConfigData->sessionHeader = NULL;
+       if (session_option) {
+               MSG_DEBUG("session is exist : cleanup session");
+               curl_easy_cleanup(session_option);
+               session_option = NULL;
        }
 
-       if (CURLE_OK != rc) {
-               MSG_DEBUG("curl_easy_perform return error rc[%d]", rc);
-
-               return eMMS_HTTP_ERROR_NETWORK;
+       if (respfile) {
+               fclose(respfile);
+               respfile = NULL;
        }
 
-       MSG_DEBUG("## End Transaction ##");
-
-       srandom((unsigned int) time(NULL));
-       trId = random() % 1000000000 + 1;
-       MSG_DEBUG("############ trID = %d ###########", trId);
-
-       httpConfig->transactionId = trId;
+       initAbortFlag();
 
-       return eMMS_HTTP_SENT_SUCCESS;
+       MSG_END();
 }
 
-static int __httpCmdGetTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig)
+void MmsPluginHttpAgent::clearSession()
 {
-       int trId;
-
-       MSG_DEBUG("HttpCmd Get Transaction");
-       MSG_DEBUG(" === HTTP Agent Thread : Signal ==> eMMS_HTTP_SIGNAL_GET_TRANSACTION");
-
-       char deviceName[1024] = {0,};
-       MmsPluginCmAgent::instance()->getDeviceName(deviceName);
-       MSG_DEBUG("deviceName: [%s]", deviceName);
+       MSG_BEGIN();
 
-       int curl_status = curl_easy_setopt(httpConfig->session, CURLOPT_INTERFACE, deviceName);
-       if (curl_status != CURLM_OK) {
-               MSG_DEBUG("curl_easy_setopt(): CURLOPT_INTERFACE failed");
+       this->transaction_type = MMS_HTTP_TRANSACTION_TYPE_UNKNOWN;
 
-               return eMMS_EXCEPTIONAL_ERROR;
+       if (session_header) {
+               MSG_DEBUG("session header is exist : free session header");
+               curl_slist_free_all((curl_slist *)session_header);
+               session_header = NULL;
        }
 
-       CURLcode rc = curl_easy_perform(httpConfig->session);
-
-       __http_print_profile(httpConfig->session);
-
-       MmsPluginHttpAgent*     httpAgent = MmsPluginHttpAgent::instance();
-       MMS_PLUGIN_HTTP_DATA_S *httpConfigData = httpAgent->getHttpConfigData();
-       if (httpConfigData->sessionHeader) {
-               curl_slist_free_all((curl_slist *)httpConfigData->sessionHeader);
-               httpConfigData->sessionHeader = NULL;
+       if (session_option) {
+               MSG_DEBUG("session is exist : cleanup session");
+               curl_easy_cleanup(session_option);
+               session_option = NULL;
        }
 
-       if (CURLE_OK != rc) {
-               MSG_DEBUG("curl_easy_perform return error = %d", rc);
-
-               return eMMS_HTTP_ERROR_NETWORK;
+       if (respfile) {
+               fclose(respfile);
+               respfile = NULL;
        }
 
-       MSG_DEBUG("## End Transaction ##");
-
-       srandom((unsigned int) time(NULL));
-       trId = random() % 1000000000 + 1;
-       MSG_DEBUG("############ trID = %d ###########", trId);
-
-       httpConfig->transactionId = trId;
-
-       return eMMS_HTTP_SENT_SUCCESS;
+       initAbortFlag();
+       MSG_END();
 }
 
-MmsPluginHttpAgent *MmsPluginHttpAgent::pInstance = NULL;
-MmsPluginHttpAgent *MmsPluginHttpAgent::instance()
+MMS_HTTP_ERROR_E MmsPluginHttpAgent::setSession(http_request_info_s &request_info)
 {
-       if (!pInstance)
-               pInstance = new MmsPluginHttpAgent();
-
-       return pInstance;
-}
-
+       MSG_BEGIN();
+       MMS_HTTP_ERROR_E http_error = MMS_HTTP_ERROR_NONE;
+       int content_len = 0;
+       char *url = NULL;
 
-MmsPluginHttpAgent::MmsPluginHttpAgent()
-{
-       MSG_DEBUG("MmsPluginHttpAgent()");
+       // Verify request info
+       if (request_info.transaction_type != MMS_HTTP_TRANSACTION_TYPE_GET
+                       && request_info.transaction_type != MMS_HTTP_TRANSACTION_TYPE_POST)
+       {
+               MSG_ERR("transaction_type of request_info is Invaild [%d]", request_info.transaction_type);
+               goto __CATCH;
+       }
 
-       bzero(&httpConfigData, sizeof(httpConfigData));
-       bzero(&mmsPlgCd, sizeof(mmsPlgCd));
+       if (request_info.transaction_type == MMS_HTTP_TRANSACTION_TYPE_POST) {
 
-       httpCmdHandler.clear();
+               if (request_info.post_data == NULL || request_info.post_data_len == 0) {
+                       MSG_ERR("post data info is Invaild");
+                       goto __CATCH;
+               }
+       }
 
-       httpCmdHandler[eHTTP_CMD_INIT_SESSION] = &__httpCmdInitSession;
-       httpCmdHandler[eHTTP_CMD_POST_TRANSACTION] = &__httpCmdPostTransaction;
-       httpCmdHandler[eHTTP_CMD_GET_TRANSACTION] = &__httpCmdGetTransaction;
-}
+       if (request_info.url == NULL || request_info.proxy == NULL || request_info.interface == NULL) {
+               MSG_ERR("request_info parameter invalid url [%s], proxy [%s] interface [%s]", request_info.url, request_info.proxy, request_info.interface);
+               goto __CATCH;
+       }
 
-MmsPluginHttpAgent::~MmsPluginHttpAgent()
-{
+       //Set type
+       this->transaction_type = request_info.transaction_type;
+       MSG_DEBUG("set transaction type [%d]", this->transaction_type);
 
-}
+       //Set http Headers
+       if (this->transaction_type == MMS_HTTP_TRANSACTION_TYPE_POST) {
+               content_len = request_info.post_data_len;
+       } else { //MMS_HTTP_TRANSACTION_TYPE_GET
+               content_len = 0;
+       }
 
-void MmsPluginHttpAgent::SetMMSProfile()
-{
-       MSG_BEGIN();
+       url = strdup(request_info.url);
 
-       MMSC_CONFIG_DATA_S *mmscConfig = &(httpConfigData.mmscConfig);
+       if (url) {
+               __httpAllocHeaderInfo((curl_slist**)&session_header, url, content_len);
+               if (session_header == NULL) {
+                       MSG_ERR("Failed to __httpAllocHeaderInfo");
+                       goto __CATCH;
+               }
 
-       MmsPluginCmAgent::instance()->getHomeURL(mmscConfig->mmscUrl);
-       if (strlen(mmscConfig->mmscUrl) < 1) {
-               MSG_DEBUG("##### get Home URL Error");
+               free(url);
+               url = NULL;
+       } else {
+               MSG_ERR("Failed to strdup");
+               goto __CATCH;
        }
 
-       MmsPluginCmAgent::instance()->getProxyAddr(mmscConfig->httpProxyIpAddr);
-       mmscConfig->proxyPortNo = MmsPluginCmAgent::instance()->getProxyPort();
 
-       MSG_END();
-}
+       //Set curl option
+       session_option = curl_easy_init();
+       if (session_option == NULL) {
+               MSG_DEBUG("curl_easy_init() failed");
+               goto __CATCH;
+       }
 
-int MmsPluginHttpAgent::cmdRequest(MMS_HTTP_CMD_TYPE_T cmdType)
-{
-       MSG_DEBUG("cmdRequest:%x", cmdType);
+       curl_easy_setopt(session_option, CURLOPT_PROXY, request_info.proxy);
+       curl_easy_setopt(session_option, CURLOPT_VERBOSE, true);
+       curl_easy_setopt(session_option, CURLOPT_URL, request_info.url);
+       curl_easy_setopt(session_option, CURLOPT_NOPROGRESS, true);
+       curl_easy_setopt(session_option, CURLOPT_HTTPHEADER, session_header);
+       curl_easy_setopt(session_option, CURLOPT_DEBUGFUNCTION , __http_debug_cb);
+       curl_easy_setopt(session_option, CURLOPT_INTERFACE, request_info.interface);
+       //curl_easy_setopt(httpConfigData.session, CURLOPT_PROGRESSFUNCTION, __http_progress_cb); //for debug
+
+       if (respfile) {
+               curl_easy_setopt(session_option, CURLOPT_WRITEFUNCTION, __http_write_response_cb);
+               curl_easy_setopt(session_option, CURLOPT_WRITEDATA, respfile);
+       }
 
-       int ret = 0;
+       if (transaction_type == MMS_HTTP_TRANSACTION_TYPE_POST) {
+               curl_easy_setopt(session_option, CURLOPT_POST, true);
+               curl_easy_setopt(session_option, CURLOPT_POSTFIELDS, request_info.post_data);
+               curl_easy_setopt(session_option, CURLOPT_POSTFIELDSIZE, request_info.post_data_len);
+       //      curl_easy_setopt(session_option, CURLOPT_TCP_NODELAY, 1);
+       }
 
-       ret = httpCmdHandler[cmdType](&httpConfigData);
+       MSG_END();
+       return http_error;
 
-       return ret;
-}
+__CATCH:
 
-MMS_PLUGIN_HTTP_CONTEXT_S* MmsPluginHttpAgent::getMmsPldCd()
-{
-       return &mmsPlgCd;
-}
+       clearSession();
 
-MMS_PLUGIN_HTTP_DATA_S *MmsPluginHttpAgent::getHttpConfigData()
-{
-       return &httpConfigData;
+       MSG_END();
+       return http_error;
 }
 
-int MmsPluginHttpAgent::setSession(mmsTranQEntity *qEntity)
+MMS_HTTP_ERROR_E MmsPluginHttpAgent::startTransaction()
 {
-       MSG_DEBUG("%s %d", qEntity->pPostData, qEntity->postDataLen);
+       MSG_BEGIN();
+       MMS_HTTP_ERROR_E http_error = MMS_HTTP_ERROR_NONE;
 
-       if (qEntity->eHttpCmdType == eHTTP_CMD_POST_TRANSACTION) {
-               MSG_DEBUG("HttpCmd Post Transaction");
-               MSG_DEBUG(" === HTTP Agent Thread : Signal ==> eMMS_HTTP_SIGNAL_POST_TRANSACTION");
+       int rc = __http_multi_perform(session_option);
 
-               curl_slist *responseHeaders = NULL;
+       __http_print_profile(session_option);
 
-               __httpAllocHeaderInfo(&responseHeaders, httpConfigData.mmscConfig.mmscUrl, qEntity->postDataLen);
+       if (rc != 0) {
+               MSG_DEBUG("curl_easy_perform return error rc [%d]", rc);
+               http_error = MMS_HTTP_ERROR_TRANSACTION;
+       }
 
-               MSG_DEBUG(" === MMSCURI = %s === ", httpConfigData.mmscConfig.mmscUrl);
+       MSG_END();
+       return http_error;
+}
 
-               httpConfigData.sessionHeader = (void *)responseHeaders;
+MMS_HTTP_ERROR_E MmsPluginHttpAgent::httpRequest(http_request_info_s &request_info)
+{
+       MSG_BEGIN();
 
-               MSG_DEBUG("## Start Transaction : Post ##");
-               curl_easy_setopt(httpConfigData.session, CURLOPT_VERBOSE, true);
-               curl_easy_setopt(httpConfigData.session, CURLOPT_POST, true);
-               curl_easy_setopt(httpConfigData.session, CURLOPT_URL, httpConfigData.mmscConfig.mmscUrl);
-               curl_easy_setopt(httpConfigData.session, CURLOPT_NOPROGRESS, true);
-               curl_easy_setopt(httpConfigData.session, CURLOPT_HTTPHEADER, responseHeaders);
-               curl_easy_setopt(httpConfigData.session, CURLOPT_POSTFIELDS, qEntity->pPostData);
-               curl_easy_setopt(httpConfigData.session, CURLOPT_POSTFIELDSIZE, qEntity->postDataLen);
-               curl_easy_setopt(httpConfigData.session, CURLOPT_WRITEFUNCTION, __httpPostTransactionCB);
-               curl_easy_setopt(httpConfigData.session, CURLOPT_TCP_NODELAY, 1);
+       const char *conf_filename = MSG_DATA_PATH"mms.conf";
 
-       } else if (qEntity->eHttpCmdType == eHTTP_CMD_GET_TRANSACTION) {
-               MSG_DEBUG("MmsHttpInitTransactionGet  %d pGetData (%s)", qEntity->getDataLen, qEntity->pGetData);
-               MSG_DEBUG("MmsHttpInitTransactionGet  mmscURL (%s) ", httpConfigData.mmscConfig.mmscUrl);
+       MMS_HTTP_ERROR_E http_error = MMS_HTTP_ERROR_NONE;
 
-               char szUrl[MAX_MMSC_URL_LEN] = {0, };
+       this->initSession();
 
-               memcpy(szUrl, qEntity->pGetData, qEntity->getDataLen);
+       respfile = fopen(conf_filename, "wb");
 
-               MSG_DEBUG("MmsHttpInitTransactionGet  szURL (%s)", szUrl);
+       //set session
+       http_error = this->setSession(request_info);
+       if (http_error != MMS_HTTP_ERROR_NONE) {
+               MSG_DEBUG("Fail to setSession");
+               goto __CATCH;
+       }
 
-               curl_slist *responseHeaders = NULL;
+       //transaction
+       http_error = this->startTransaction();
+       if (http_error != MMS_HTTP_ERROR_NONE) {
+               MSG_DEBUG("Fail to startTransaction");
+               goto __CATCH;
+       }
 
-               __httpAllocHeaderInfo(&responseHeaders, szUrl, 0);
+       //close conf file & load response data
+       if (respfile) {
 
-               httpConfigData.sessionHeader = (void *)responseHeaders;
+               fclose(respfile);
+               respfile = NULL;
 
-               MSG_DEBUG("## Start Transaction : Get ##");
-               curl_easy_setopt(httpConfigData.session, CURLOPT_VERBOSE, true);
-               curl_easy_setopt(httpConfigData.session, CURLOPT_URL, szUrl);
-               curl_easy_setopt(httpConfigData.session, CURLOPT_NOPROGRESS, true);
-               curl_easy_setopt(httpConfigData.session, CURLOPT_HTTPHEADER, responseHeaders);
-               curl_easy_setopt(httpConfigData.session, CURLOPT_WRITEFUNCTION, __httpGetTransactionCB);
-       } else {
-               MSG_DEBUG("Unknown eHttpCmdType [%d]", qEntity->eHttpCmdType);
-               return -1;
+               if (g_file_get_contents(conf_filename, &request_info.response_data, &request_info.response_data_len, NULL) == false) {
+                       MSG_DEBUG("Fail to g_file_get_contents");
+               }
        }
 
-       return 0;
-}
-
+       this->clearSession();
 
-void MmsPluginHttpAgent::clearSession()
-{
-       MSG_BEGIN();
+       MSG_END();
+       return http_error;
 
-       if (httpConfigData.sessionHeader) {
-               curl_slist_free_all((curl_slist *)httpConfigData.sessionHeader);
-               httpConfigData.sessionHeader = NULL;
-       }
+__CATCH:
 
-       if (httpConfigData.session == NULL) {
-               MSG_DEBUG("[Error]httpConfigData.session is NULL");
-               return;
+       if (respfile) {
+               fclose(respfile);
+               respfile = NULL;
        }
 
-       curl_easy_cleanup(httpConfigData.session);
-
-       httpConfigData.session = NULL;
+       this->clearSession();
 
        MSG_END();
+       return http_error;
 }
index 40d0afe..ead9151 100755 (executable)
@@ -140,7 +140,7 @@ msg_error_t MmsAddMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *p
                return MSG_ERR_PLUGIN_TRANSPORT;
        }
 
-       MSG_END();
+       //MSG_END();
 
        return MSG_SUCCESS;
 }
index e6f2c76..17b223d 100755 (executable)
@@ -647,7 +647,7 @@ bool MmsComposeMessage(MmsMsg *pMmsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDIN
 
        //setting adddress
        MmsSetMsgAddressList(&pMmsMsg->mmsAttrib, pMsgInfo);
-       MmsGetMsgBodyfromMsgInfo(pMsgInfo, pMsgData, pFileData);
+       //MmsGetMsgBodyfromMsgInfo(pMsgInfo, pMsgData, pFileData);
 
        int pageCnt = _MsgMmsGetPageCount(pMsgData);
 
@@ -1539,16 +1539,23 @@ bool MmsComposeSendReq(MmsMsg *pMmsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDIN
                        for (int j = 0; j < mediaCnt; ++j) {
                                MMS_MEDIA_S *pMedia = _MsgMmsGetMedia(pPage, j);
                                if (pMedia->szFilePath[0] != 0) {
-                                       MMS_MULTIPART_DATA_S pMultipart;
-                                       bzero(&pMultipart, sizeof(MMS_MULTIPART_DATA_S));
-                                       snprintf(pMultipart.szContentID, sizeof(pMultipart.szContentID), "%s", pMedia->szContentID);
-                                       snprintf(pMultipart.szContentLocation, sizeof(pMultipart.szContentLocation), "%s", pMedia->szContentLocation);
-                                       snprintf(pMultipart.szFileName, sizeof(pMultipart.szFileName), "%s", pMedia->szFileName);
-                                       snprintf(pMultipart.szFilePath, sizeof(pMultipart.szFilePath), "%s", pMedia->szFilePath);
-                                       snprintf(pMultipart.szContentType, sizeof(pMultipart.szContentType), "%s", pMedia->szContentType);
-
-                                       if (!MmsInsertPartFromMultipart(pMmsMsg, &pMultipart))
-                                               return false;
+                                       MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)calloc(1, sizeof(MMS_MULTIPART_DATA_S));
+                                       if (pMultipart) {
+                                               snprintf(pMultipart->szContentID, sizeof(pMultipart->szContentID), "%s", pMedia->szContentID);
+                                               snprintf(pMultipart->szContentLocation, sizeof(pMultipart->szContentLocation), "%s", pMedia->szContentLocation);
+                                               snprintf(pMultipart->szFileName, sizeof(pMultipart->szFileName), "%s", pMedia->szFileName);
+                                               snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), "%s", pMedia->szFilePath);
+                                               snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s", pMedia->szContentType);
+
+                                               if (!MmsInsertPartFromMultipart(pMmsMsg, pMultipart)) {
+                                                       free(pMultipart);
+                                                       pMultipart = NULL;
+                                                       return false;
+                                               }
+
+                                               free(pMultipart);
+                                               pMultipart = NULL;
+                                       }
                                }
                        }
                }
@@ -1558,16 +1565,23 @@ bool MmsComposeSendReq(MmsMsg *pMmsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDIN
        for (int i = 0; i < _MsgMmsGetAttachCount(pMsgData); ++i) {
                MMS_ATTACH_S *pMedia = _MsgMmsGetAttachment(pMsgData, i);
                if (pMedia->szFilePath[0] != 0) {
-                       MMS_MULTIPART_DATA_S pMultipart;
-                       bzero(&pMultipart, sizeof(MMS_MULTIPART_DATA_S));
-                       snprintf(pMultipart.szContentID, sizeof(pMultipart.szContentID), "%s", pMedia->szFileName);
-                       snprintf(pMultipart.szContentLocation, sizeof(pMultipart.szContentLocation), "%s", pMedia->szFileName);
-                       snprintf(pMultipart.szFileName, sizeof(pMultipart.szFileName), "%s", pMedia->szFileName);
-                       snprintf(pMultipart.szFilePath, sizeof(pMultipart.szFilePath), "%s", pMedia->szFilePath);
-                       snprintf(pMultipart.szContentType, sizeof(pMultipart.szContentType), "%s", pMedia->szContentType);
-
-                       if (!MmsInsertPartFromMultipart(pMmsMsg, &pMultipart))
-                               return false;
+                       MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)calloc(1, sizeof(MMS_MULTIPART_DATA_S));
+                       if (pMultipart) {
+                               snprintf(pMultipart->szContentID, sizeof(pMultipart->szContentID), "%s", pMedia->szFileName);
+                               snprintf(pMultipart->szContentLocation, sizeof(pMultipart->szContentLocation), "%s", pMedia->szFileName);
+                               snprintf(pMultipart->szFileName, sizeof(pMultipart->szFileName), "%s", pMedia->szFileName);
+                               snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), "%s", pMedia->szFilePath);
+                               snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s", pMedia->szContentType);
+
+                               if (!MmsInsertPartFromMultipart(pMmsMsg, pMultipart)) {
+                                       free(pMultipart);
+                                       pMultipart = NULL;
+                                       return false;
+                               }
+
+                               free(pMultipart);
+                               pMultipart = NULL;
+                       }
                }
        }
 
index 91950ca..a439b85 100755 (executable)
 #include "MmsPluginDrm.h"
 #include "MmsPluginMIME.h"
 
+#define MMS_FREE(obj)\
+       if (obj){\
+               free(obj);\
+               obj = NULL;\
+       }
+
 /*==================================================================================================
                                      IMPLEMENTATION OF SmsPluginStorage - Member Functions
 ==================================================================================================*/
@@ -63,314 +69,6 @@ void MmsPluginStorage::getMmsMessage(MmsMsg **pMmsMsg)
        *pMmsMsg = &mmsMsg;
 }
 
-#if 0 //Unused code
-void MmsPluginStorage::addMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData)
-{
-       MSG_BEGIN();
-
-       msg_error_t     err;
-
-       MmsMsg mmsMsg;
-
-       bzero(&mmsMsg, sizeof(mmsMsg));
-
-       mode_t file_mode = (S_IRUSR | S_IWUSR);
-
-       if (pMsgInfo->msgType.subType == MSG_SENDREQ_MMS) {
-
-               char szTemp[MAX_MSG_DATA_LEN + 1];
-
-               MMS_MESSAGE_DATA_S mmsMsgData;
-               bzero(&mmsMsgData,sizeof(MMS_MESSAGE_DATA_S));
-               if (MmsComposeMessage(&mmsMsg, pMsgInfo, pSendOptInfo, &mmsMsgData, pFileData) != true) {
-                       MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-
-                       MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-                       __MmsReleaseMmsLists(&mmsMsgData);
-
-                       THROW(MsgException::MMS_PLG_ERROR, "MMS Message Compose Error");
-               }
-
-               MmsPrintFileInfoForVLD(&mmsMsgData);
-
-               char fileName[MSG_FILENAME_LEN_MAX+1] = {0,};
-
-               FILE *pFile = NULL;
-
-               strcpy(szTemp,pMsgInfo->msgData);
-
-               snprintf((char *)pMsgInfo->msgData, MAX_MSG_DATA_LEN+1, MSG_DATA_PATH"%d.mms", pMsgInfo->msgId);
-
-               if (addMmsMsgToDB(&mmsMsg, pMsgInfo, _MsgMmsGetAttachCount(&mmsMsgData)) != MSG_SUCCESS) {
-                       MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-                       MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-                       __MmsReleaseMmsLists(&mmsMsgData);
-
-                       THROW(MsgException::MMS_PLG_ERROR, "MMS Stroage Error");
-               }
-
-               strcpy((char *)pMsgInfo->msgData,szTemp);
-
-               snprintf(fileName, MSG_FILENAME_LEN_MAX+1, MSG_DATA_PATH"%d", mmsMsg.msgID);
-
-               pFile = MsgOpenMMSFile(fileName);
-               if (!pFile) {
-                       MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-                       MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-                       __MmsReleaseMmsLists(&mmsMsgData);
-                       THROW(MsgException::MMS_PLG_ERROR, "MMS File open Error");
-               }
-
-               if (fchmod(fileno(pFile), file_mode) < 0) {
-                       MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-                       MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-                       __MmsReleaseMmsLists(&mmsMsgData);
-                       MsgCloseFile(pFile);
-
-                       THROW(MsgException::MMS_PLG_ERROR, "chmod() error: %s", strerror(errno));
-               }
-
-               if (MmsEncodeSendReq(pFile, &mmsMsg) != true) {
-                       MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-                       MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-                       __MmsReleaseMmsLists(&mmsMsgData);
-                       MsgCloseFile(pFile);
-
-                       THROW(MsgException::MMS_PLG_ERROR, "MMS Message Encode Send Req Error");
-               }
-
-               MsgFsync(pFile);        //file is written to device immediately, it prevents missing file data from unexpected power off
-               MsgCloseFile(pFile);
-
-               char filepath[MSG_FILEPATH_LEN_MAX+1] = {0,};
-               int size = 0;
-
-               snprintf((char *)filepath, MSG_FILEPATH_LEN_MAX+1, MSG_DATA_PATH"%d.mms", pMsgInfo->msgId);
-               if (MsgGetFileSize(filepath, &size) == false) {
-                       THROW(MsgException::MMS_PLG_ERROR, "MMS Message MsgGetFileSize Error");
-               }
-
-               pMsgInfo->dataSize = size;
-
-               MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-               MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-               __MmsReleaseMmsLists(&mmsMsgData);
-
-       } else if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
-               MSG_DEBUG("######## MmsPlgAddMessage -> MSG_NOTIFICATIONIND_MMS ###########");
-
-               MmsComposeNotiMessage(&mmsMsg, pMsgInfo->msgId);
-
-               //Need to store mms specific data (contents location, TrID, ExpiryTime, Delivery Report, message ID)
-               if (addMmsMsgToDB(&mmsMsg, pMsgInfo) != MSG_SUCCESS) {
-                       MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-                       THROW(MsgException::MMS_PLG_ERROR, "MMS Stroage Error");
-               }
-       } else if (pMsgInfo->msgType.subType == MSG_SENDCONF_MMS || pMsgInfo->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS) {
-               MmsMsg *pMsg = NULL;
-               char szTemp[MAX_MSG_DATA_LEN + 1]= {0, };
-
-               if (!MmsReadMsgBody(pMsgInfo->msgId, true, true, pFileData))
-                       THROW(MsgException::MMS_PLG_ERROR, "_MmsReadMsgBody Error");
-
-               MmsPluginStorage::instance()->getMmsMessage(&pMsg);
-
-               if (pMsgInfo->msgType.subType == MSG_SENDCONF_MMS)
-                       pMsgInfo->networkStatus = MSG_NETWORK_SEND_SUCCESS;
-               else
-                       pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_SUCCESS;
-               strcpy(szTemp,pMsgInfo->msgData);
-               memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
-               strncpy(pMsgInfo->msgData, pFileData, MAX_MSG_DATA_LEN);
-
-               MmsPluginStorage *pStorage = MmsPluginStorage::instance();
-
-               MMS_MESSAGE_DATA_S mmsMsgData;
-               bzero(&mmsMsgData,sizeof(MMS_MESSAGE_DATA_S));
-               if (mmsHeader.msgType.type == MIME_MULTIPART_RELATED || mmsHeader.msgType.type == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
-                       char *pSmilDoc;
-                       char szFileName[MSG_FILENAME_LEN_MAX] = {0, };
-
-                       mmsMsgData.regionCnt = 0;
-                       mmsMsgData.pageCnt = 0;
-                       mmsMsgData.attachCnt = 0;
-                       mmsMsgData.transitionCnt = 0;
-                       mmsMsgData.metaCnt = 0;
-                       memset(mmsMsgData.szSmilFilePath, 0, MSG_FILEPATH_LEN_MAX);
-
-                       pSmilDoc = MmsSmilGetPresentationData(pMsgInfo->msgId);
-                       if (pSmilDoc) {
-                               MmsSmilParseSmilDoc(&mmsMsgData, pSmilDoc);
-
-                               MmsPluginStorage::instance()->getMmsMessage(&pMsg);
-                               strcpy(szFileName, pMsg->szFileName);
-
-                               err = pStorage->getMsgText(&mmsMsgData, pMsgInfo->msgText);
-                               MmsMakePreviewInfo(pMsgInfo->msgId, &mmsMsgData);
-                       }
-
-                       MsgMmsReleaseMmsLists(&mmsMsgData);
-               }
-
-               if (addMmsMsgToDB(pMsg, pMsgInfo) != MSG_SUCCESS) {
-                       MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-
-                       THROW(MsgException::MMS_PLG_ERROR, "MMS Stroage Error");
-               }
-               memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
-               strcpy((char *)pMsgInfo->msgData,szTemp);
-
-               MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-
-       } else if (pMsgInfo->msgType.subType == MSG_READREPLY_MMS || pMsgInfo->msgType.subType == MSG_READRECIND_MMS) {
-               MSG_DEBUG("######## MmsPlgAddMessage -> MSG_READREPLY_MMS || MSG_READRECIND_MMS ###########");
-
-               char filePath[MAX_FULL_PATH_SIZE+1] = {0, };
-               FILE *pFile = NULL;
-
-               msg_read_report_status_t readStatus;
-               msg_message_id_t selectedMsgId;
-               int     version;
-
-               memcpy(&readStatus, pMsgInfo->msgData, sizeof(msg_read_report_status_t));
-               memcpy(&selectedMsgId, pMsgInfo->msgData + sizeof(msg_read_report_status_t), sizeof(msg_message_id_t));
-
-               version = MmsPluginStorage::instance()->getMmsVersion(selectedMsgId);
-
-               snprintf((char *)pMsgInfo->msgData, MAX_MSG_DATA_LEN+1, MSG_DATA_PATH"%d.mms", pMsgInfo->msgId);
-
-               MmsComposeReadReportMessage(&mmsMsg, pMsgInfo, selectedMsgId);
-
-               if (addMmsMsgToDB(&mmsMsg, pMsgInfo) != MSG_SUCCESS) {
-                       MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-                       MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-
-                       THROW(MsgException::MMS_PLG_ERROR, "MMS Stroage Error");
-               }
-
-               snprintf(filePath, MAX_FULL_PATH_SIZE+1, MSG_DATA_PATH"%d", mmsMsg.msgID);
-               pFile = MsgOpenMMSFile(filePath);
-               if (!pFile) {
-                       MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-                       MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-                       MsgCloseFile(pFile);
-                       pFile = NULL;
-
-                       THROW(MsgException::MMS_PLG_ERROR, "MsgOpenMMSFile error");
-               }
-
-               if (fchmod(fileno(pFile), file_mode) < 0) {
-                       MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-                       MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-                       MsgCloseFile(pFile);
-                       pFile = NULL;
-
-                       THROW(MsgException::MMS_PLG_ERROR, "chmod() error: %s", strerror(errno));
-               }
-
-               if (version == 0x90) {
-                       MSG_DEBUG("### version 1.0 ###");
-                       if (MmsEncodeReadReport10(pFile, &mmsMsg, readStatus) != true) {
-                               MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-                               MsgCloseFile(pFile);
-                               pFile = NULL;
-
-                               THROW(MsgException::MMS_PLG_ERROR, "MMS Encode Read Report 1.0 Error");
-                       }
-               } else {
-                       MSG_DEBUG("### version 1.1 ###");
-                       if (MmsEncodeReadReport11(pFile, &mmsMsg, readStatus) != true) {
-                               MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-                               MsgCloseFile(pFile);
-                               pFile = NULL;
-
-                               THROW(MsgException::MMS_PLG_ERROR, "MMS Encode Read Report 1.1 Error");
-                       }
-               }
-
-               MsgFsync(pFile);
-               MsgCloseFile(pFile);
-               pFile = NULL;
-
-               MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-
-               MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-
-       } else if (pMsgInfo->msgType.subType == MSG_FORWARD_MMS) {
-               MSG_DEBUG("######## MmsPlgAddMessage -> MSG_FORWARD_MMS ###########");
-
-               char filePath[MAX_FULL_PATH_SIZE + 1] = {0, };
-               char szTemp[MAX_MSG_DATA_LEN + 1] = {0, };
-               FILE *pFile = NULL;
-               MMS_MESSAGE_DATA_S mmsMsgData;
-
-               if (MmsComposeMessage(&mmsMsg, pMsgInfo, pSendOptInfo, &mmsMsgData, pFileData) != true) {
-                       MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-                       MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-                       __MmsReleaseMmsLists(&mmsMsgData);
-
-                       THROW(MsgException::MMS_PLG_ERROR, "MMS Message Compose Error");
-               }
-
-               strcpy(szTemp,pMsgInfo->msgData);
-
-               snprintf((char *)pMsgInfo->msgData, MAX_MSG_DATA_LEN + 1, MSG_DATA_PATH"%d.mms", pMsgInfo->msgId);
-
-               if (addMmsMsgToDB(&mmsMsg, pMsgInfo, _MsgMmsGetAttachCount(&mmsMsgData)) != MSG_SUCCESS) {
-                       MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-                       MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-                       __MmsReleaseMmsLists(&mmsMsgData);
-
-                       THROW(MsgException::MMS_PLG_ERROR, "MMS Stroage Error");
-               }
-
-               strcpy((char *)pMsgInfo->msgData,szTemp);
-
-               snprintf(filePath, MAX_FULL_PATH_SIZE + 1 , MSG_DATA_PATH"%d", mmsMsg.msgID);
-
-               pFile = MsgOpenMMSFile(filePath);
-               if (!pFile) {
-                       MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-                       MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-                       __MmsReleaseMmsLists(&mmsMsgData);
-                       MsgCloseFile(pFile);
-                       pFile = NULL;
-
-                       THROW(MsgException::MMS_PLG_ERROR, "MsgOpenMMSFile error");
-               }
-
-               if (fchmod(fileno(pFile), file_mode) < 0) {
-                       MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-                       MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-                       __MmsReleaseMmsLists(&mmsMsgData);
-                       MsgCloseFile(pFile);
-                       pFile = NULL;
-
-                       THROW(MsgException::MMS_PLG_ERROR, "chmod() error: %s", strerror(errno));
-               }
-
-               if (MmsEncodeSendReq(pFile, &mmsMsg) != true) {
-                       MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-                       MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-                       __MmsReleaseMmsLists(&mmsMsgData);
-                       MsgCloseFile(pFile);
-                       pFile = NULL;
-
-                       THROW(MsgException::MMS_PLG_ERROR, "MMS Message Encode Send Req Error");
-               }
-               MsgFsync(pFile);
-               MsgCloseFile(pFile);
-               pFile = NULL;
-
-               MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
-               MmsReleaseMmsAttrib(&mmsMsg.mmsAttrib);
-               __MmsReleaseMmsLists(&mmsMsgData);
-       }
-
-       MSG_END();
-}
-#endif
-
 void MmsPluginStorage::composeReadReport(MSG_MESSAGE_INFO_S *pMsgInfo)
 {
        FILE *pFile = NULL;
@@ -469,205 +167,6 @@ msg_error_t MmsPluginStorage::addMmsMsgToDB(MmsMsg *pMmsMsg, const char *raw_fil
 
        return MSG_SUCCESS;
 }
-#if 0
-msg_error_t    MmsPluginStorage::plgGetMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char **pDestMsg)
-{
-       MSG_BEGIN();
-
-       msg_error_t     err = MSG_SUCCESS;
-       MMS_MESSAGE_DATA_S tempMmsMsg = {0,};
-       MMS_MESSAGE_DATA_S *pMmsMsg = &tempMmsMsg;
-       int partCnt = 0;
-       size_t nSize = 0;
-
-       MsgType partHeader;
-       MmsAttrib pMmsAttrib;
-
-       char szBuf[MSG_FILEPATH_LEN_MAX + 1] = {0, };
-       bool bMultipartRelated = false;
-
-       if (pSendOptInfo != NULL) {
-               char sqlQuery[MAX_QUERY_LEN + 1];
-
-               memset(sqlQuery, 0x00, sizeof(sqlQuery));
-               snprintf(sqlQuery, sizeof(sqlQuery), "SELECT ASK_DELIVERY_REPORT, KEEP_COPY, ASK_READ_REPLY, PRIORITY, EXPIRY_TIME, CUSTOM_DELIVERY_TIME, DELIVERY_TIME \
-                               FROM %s WHERE MSG_ID = %d;", MMS_PLUGIN_MESSAGE_TABLE_NAME, pMsg->msgId);
-
-               MSG_DEBUG("### SQLQuery = %s ###", sqlQuery);
-
-               if (dbHandle.prepareQuery(sqlQuery) != MSG_SUCCESS)
-                       MSG_DEBUG("MSG_ERR_DB_PREPARE");
-
-               if (dbHandle.stepQuery() == MSG_ERR_DB_ROW) {
-                       pSendOptInfo->bDeliverReq = dbHandle.columnInt(0);
-                       MSG_DEBUG("## delivery = %d ##", pSendOptInfo->bDeliverReq);
-
-                       pSendOptInfo->bKeepCopy = dbHandle.columnInt(1);
-                       MSG_DEBUG("## bKeepCopy = %d ##", pSendOptInfo->bKeepCopy);
-
-                       pSendOptInfo->option.mmsSendOptInfo.bReadReq = dbHandle.columnInt(2);
-                       MSG_DEBUG("## bReadReq = %d ##", pSendOptInfo->option.mmsSendOptInfo.bReadReq);
-
-                       pSendOptInfo->option.mmsSendOptInfo.priority = dbHandle.columnInt(3);
-                       MSG_DEBUG("## priority = %d ##", pSendOptInfo->option.mmsSendOptInfo.priority);
-
-                       pSendOptInfo->option.mmsSendOptInfo.expiryTime.time = (unsigned int)dbHandle.columnInt(4);
-                       MSG_DEBUG("## expiryTime = %d ##", pSendOptInfo->option.mmsSendOptInfo.expiryTime.time);
-
-                       pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime = (unsigned int)dbHandle.columnInt(5);
-                       MSG_DEBUG("## bUseDeliveryCustomTime = %d ##", pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime);
-
-                       pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time = (unsigned int)dbHandle.columnInt(6);
-                       MSG_DEBUG("## deliveryTime = %d ##", pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time);
-               } else {
-                       dbHandle.finalizeQuery();
-                       return MSG_ERR_DB_STEP;
-               }
-
-               dbHandle.finalizeQuery();
-       }
-
-       if (MmsReadMsgBody(pMsg->msgId, true, false, NULL) == false) {
-               MSG_DEBUG("The MMS Message might include drm contents!!!");
-
-#ifdef __SUPPORT_DRM__
-               if (MmsDrm2GetConvertState() == MMS_DRM2_CONVERT_REQUIRED) {
-                       bool bRetToConvert = true;
-
-                       bRetToConvert = MmsDrm2ConvertMsgBody(mmsHeader.msgType.szOrgFilePath);
-
-                       MmsDrm2SetConvertState(MMS_DRM2_CONVERT_FINISH);
-
-                       if (bRetToConvert) {
-                               int ret;
-                               ret = remove(mmsHeader.msgType.szOrgFilePath);
-                               if (ret != 0) {
-                                       MSG_DEBUG("remove fail\n");
-                               }
-
-                               ret = rename(MMS_DECODE_DRM_CONVERTED_TEMP_FILE, mmsHeader.msgType.szOrgFilePath);
-                               if (ret != 0) {
-                                       MSG_DEBUG("rename fail\n");
-                               }
-
-                               if (MmsDrm2ReadMsgConvertedBody(pMsg, true, false, NULL) == false) {
-                                       MSG_DEBUG("MmsLoadMsg:MmsDrm2ReadMsgConvertedBody() returns false\n");
-                                       goto L_CATCH;
-                               }
-                       } else {
-                               goto L_CATCH;
-                       }
-               }
-#endif
-       }
-
-       MmsGetMsgAttrib(pMsg->msgId, &pMmsAttrib);
-
-       pMmsMsg->regionCnt = 0;
-       pMmsMsg->pageCnt = 0;
-       pMmsMsg->attachCnt = 0;
-       pMmsMsg->transitionCnt = 0;
-       pMmsMsg->metaCnt = 0;
-       memset(pMmsMsg->szSmilFilePath, 0, MSG_FILEPATH_LEN_MAX);
-
-       if (pMmsAttrib.contentType == MIME_MULTIPART_RELATED || pMmsAttrib.contentType == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
-               char *pSmilDoc = NULL;
-
-               pSmilDoc = MmsSmilGetPresentationData(pMsg->msgId);
-               if (!pSmilDoc) {
-                       goto L_CATCH;
-               }
-
-               MmsSmilParseSmilDoc(pMmsMsg, pSmilDoc);
-               MmsRemovePims(pMmsMsg);
-               bMultipartRelated = true;
-       }
-
-       partCnt = MmsGetMediaPartCount(pMsg->msgId);
-       MSG_DEBUG("MmsUiGetMediaAttachInfo: partCnt=%d\n", partCnt);
-
-       if (partCnt < 0) {
-               MSG_DEBUG("MmsUiGetMediaAttachInfo: partCnt=%d\n", partCnt);
-               goto FREE_CATCH;
-       }
-
-       for (int i = 0; i < partCnt; ++i) {
-               if (!MmsGetMediaPartHeader(i, &partHeader)) {
-                       MSG_DEBUG("MmsUiGetMediaAttachInfo: MmsGetMediaPartHeader failed\n");
-                       goto FREE_CATCH;
-               }
-
-               if (partHeader.contentSize > 0) {
-                       if (!strcasecmp(partHeader.param.szFileName, "cid:")) {
-                               strncpy((char *)szBuf, &partHeader.param.szFileName[4], MSG_FILEPATH_LEN_MAX);
-                       } else {
-                               strncpy((char *)szBuf, partHeader.param.szFileName, MSG_FILEPATH_LEN_MAX);
-                       }
-                       sprintf(partHeader.param.szFileName, MSG_DATA_PATH"%s", szBuf);
-
-                       if (!bMultipartRelated || MmsCheckAdditionalMedia(pMmsMsg, &partHeader)) {
-
-                               MMS_ATTACH_S *attachment = NULL;
-                               int tempType;
-
-                               attachment = (MMS_ATTACH_S *)calloc(sizeof(MMS_ATTACH_S), 1);
-
-                               MsgGetTypeByFileName(&tempType, partHeader.param.szFileName);
-                               attachment->mediatype = (MimeType)tempType;
-
-                               strcpy(attachment->szFilePath, partHeader.param.szFileName);
-
-                               strncpy(attachment->szFileName, partHeader.param.szName, MSG_FILENAME_LEN_MAX -1);
-
-                               attachment->fileSize = partHeader.contentSize;
-
-                               _MsgMmsAddAttachment(pMmsMsg, attachment);
-                       }
-               }
-       }
-
-       *pDestMsg = _MsgMmsSerializeMessageData(pMmsMsg, &nSize);
-
-       MsgMmsReleaseMmsLists(pMmsMsg);
-
-
-       MmsMsg *pStoMmsMsg;
-       MmsPluginStorage::instance()->getMmsMessage(&pStoMmsMsg);
-       MmsInitHeader();
-       MmsUnregisterDecodeBuffer();
-#ifdef __SUPPORT_DRM__
-       MmsReleaseMsgDRMInfo(&pStoMmsMsg->msgType.drmInfo);
-#endif
-       MmsReleaseMsgBody(&pStoMmsMsg->msgBody, pStoMmsMsg->msgType.type);
-
-       pMsg->dataSize = nSize;
-       MSG_END();
-
-       return err;
-
-FREE_CATCH:
-       if (bMultipartRelated) {
-               MsgMmsReleaseMmsLists(pMmsMsg);
-       }
-
-L_CATCH:
-       MSG_DEBUG("MmsPlgUpdateMessage : Update MMS Message Failed");
-       MSG_END();
-       {
-               MmsMsg *pMsg;
-               MmsPluginStorage::instance()->getMmsMessage(&pMsg);
-               MmsInitHeader();
-
-               MmsUnregisterDecodeBuffer();
-#ifdef __SUPPORT_DRM__
-               MmsReleaseMsgDRMInfo(&pMsg->msgType.drmInfo);
-#endif
-               MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
-
-               return MSG_ERR_STORAGE_ERROR;
-       }
-}
-#endif
 
 msg_error_t MmsPluginStorage::updateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, char *pFileData)
 {
@@ -678,7 +177,7 @@ msg_error_t MmsPluginStorage::updateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SE
        MmsMsg mmsMsg;
        MMS_MESSAGE_DATA_S mmsMsgData = {0,};
        char raw_filepath[MSG_FILENAME_LEN_MAX+1] = {0,};
-
+       char raw_filedir[MSG_FILENAME_LEN_MAX+1] = {0,};
        bzero(&mmsMsg, sizeof(mmsMsg));
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
@@ -690,6 +189,8 @@ msg_error_t MmsPluginStorage::updateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SE
        if (dbHandle.execQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_EXEC;
 
+       MSG_DEBUG("msg sub type = [%d]", pMsgInfo->msgType.subType);
+
        if (pMsgInfo->msgType.subType == MSG_SENDREQ_MMS) {
 
                if (_MsgMmsDeserializeMessageData(&mmsMsgData, pFileData) == false) {
@@ -715,6 +216,8 @@ msg_error_t MmsPluginStorage::updateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SE
                }
 
                //preview data
+               MmsPluginStorage::instance()->removePreviewInfo(pMsgInfo->msgId); //remove exist previnfo
+
                err = MmsMakePreviewInfo(pMsgInfo->msgId, &mmsMsgData);
 
                err = getMsgText(&mmsMsgData, pMsgInfo->msgText);
@@ -725,6 +228,10 @@ msg_error_t MmsPluginStorage::updateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SE
                        }
                }
 
+               snprintf(raw_filedir, sizeof(raw_filedir), MSG_DATA_PATH"%d.mms.dir", pMsgInfo->msgId);
+               MsgRmRf(raw_filedir);
+               rmdir(raw_filedir);
+
                int size = 0;
 
                if (MsgGetFileSize(raw_filepath, &size) == false) {
@@ -734,6 +241,8 @@ msg_error_t MmsPluginStorage::updateMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SE
                }
 
                pMsgInfo->dataSize = size;
+
+               MmsReadMsgBody(pMsgInfo->msgId, true, false, NULL);
        }
 
        MmsReleaseMmsMsg(&mmsMsg);
@@ -1040,8 +549,6 @@ int MmsPluginStorage::getMmsVersion(msg_message_id_t selectedMsgId)
        snprintf(sqlQuery, sizeof(sqlQuery), "SELECT VERSION FROM %s WHERE MSG_ID = %d;",
                        MMS_PLUGIN_MESSAGE_TABLE_NAME, selectedMsgId);
 
-       MSG_DEBUG("SqlQuery = %s", sqlQuery);
-
        err = dbHandle.getTable(sqlQuery, &rowCnt);
 
        if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
@@ -1425,9 +932,8 @@ msg_error_t MmsPluginStorage::plgGetMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SEN
        msg_error_t     err = MSG_SUCCESS;
        MMS_MESSAGE_DATA_S tempMmsMsgData = {0,};
        MMS_MESSAGE_DATA_S *pMmsMsg = &tempMmsMsgData;
-       size_t nSize = 0;
-       bool bMultipartRelated = false;
+
+       unsigned int nSize = 0;
 
        bzero(pMmsMsg, sizeof(MMS_MESSAGE_DATA_S));
        pMmsMsg->regionCnt = 0;
@@ -1526,13 +1032,7 @@ msg_error_t MmsPluginStorage::plgGetMmsMessage(MSG_MESSAGE_INFO_S *pMsg, MSG_SEN
        return err;
 
 FREE_CATCH:
-       /*
-       if (bMultipartRelated) {
-               MsgMmsReleaseMmsLists(pMmsMsg);
-       }
-       */
 
-L_CATCH:
        MSG_DEBUG("MmsPlgUpdateMessage : Update MMS Message Failed");
        MSG_END();
        {
@@ -1555,21 +1055,31 @@ void MmsPluginStorage::addMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_I
        MSG_BEGIN();
 
        msg_error_t     err;
+       MmsMsg *pMmsMsg = NULL;
+       MMS_MESSAGE_DATA_S *pMmsMsgData = NULL;
+
        char raw_filepath[MSG_FILENAME_LEN_MAX+1] = {0,};
-       MmsMsg mmsMsg;
-       MMS_MESSAGE_DATA_S mmsMsgData;
 
-       bzero(&mmsMsgData, sizeof(MMS_MESSAGE_DATA_S));
-       bzero(&mmsMsg, sizeof(mmsMsg));
+       pMmsMsg = (MmsMsg *)calloc(1, sizeof(MmsMsg));
+       if (pMmsMsg == NULL) {
+               MSG_DEBUG("memory allocation error");
+               goto __CATCH;
+       }
+
+       pMmsMsgData = (MMS_MESSAGE_DATA_S *)calloc(1, sizeof(MMS_MESSAGE_DATA_S));
+       if (pMmsMsgData == NULL) {
+               MSG_DEBUG("memory allocation error");
+               goto __CATCH;
+       }
 
        if (pMsgInfo->msgType.subType == MSG_SENDREQ_MMS) {
 
-               if (_MsgMmsDeserializeMessageData(&mmsMsgData, pFileData) == false) {
+               if (_MsgMmsDeserializeMessageData(pMmsMsgData, pFileData) == false) {
                        MSG_DEBUG("Fail to Deserialize Message Data");
                        goto __CATCH;
                }
 
-               if (MmsComposeMessage(&mmsMsg, pMsgInfo, pSendOptInfo, &mmsMsgData, pFileData) != true) {
+               if (MmsComposeSendReq(pMmsMsg, pMsgInfo, pSendOptInfo, pMmsMsgData) != true) {
                        MSG_DEBUG("Fail to Compose Message");
                        goto __CATCH;
                }
@@ -1578,23 +1088,23 @@ void MmsPluginStorage::addMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_I
                snprintf(raw_filepath, sizeof(raw_filepath), MSG_DATA_PATH"%d.mms", pMsgInfo->msgId);
 
                //encode mms
-               if (MmsEncodeMmsMessage(&mmsMsg, raw_filepath) == false) {
+               if (MmsEncodeMmsMessage(pMmsMsg, raw_filepath) == false) {
                        MSG_DEBUG("Fail to Encode Message");
                        goto __CATCH;
                }
 
                //add to db
-               if (addMmsMsgToDB(&mmsMsg, raw_filepath) != MSG_SUCCESS) {
+               if (addMmsMsgToDB(pMmsMsg, raw_filepath) != MSG_SUCCESS) {
                        MSG_DEBUG("Fail to add db message");
                        goto __CATCH;
                }
 
                //preview data
-               err = MmsMakePreviewInfo(pMsgInfo->msgId, &mmsMsgData);
-               err = getMsgText(&mmsMsgData, pMsgInfo->msgText);
+               err = MmsMakePreviewInfo(pMsgInfo->msgId, pMmsMsgData);
+               err = getMsgText(pMmsMsgData, pMsgInfo->msgText);
 
-               if (mmsMsgData.attachCnt > 0) {
-                       if (updateMmsAttachCount(mmsMsg.msgID, mmsMsgData.attachCnt) != MSG_SUCCESS) {
+               if (pMmsMsgData->attachCnt > 0) {
+                       if (updateMmsAttachCount(pMmsMsg->msgID, pMmsMsgData->attachCnt) != MSG_SUCCESS) {
                                MSG_DEBUG("Fail to updateMmsAttachCount");
                                goto __CATCH;
                        }
@@ -1605,22 +1115,27 @@ void MmsPluginStorage::addMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_I
                        goto __CATCH;
                }
 
-               MmsReleaseMmsMsg(&mmsMsg);
-               MsgMmsReleaseMmsLists(&mmsMsgData);
+               MmsReleaseMmsMsg(pMmsMsg);
+               MMS_FREE(pMmsMsg);
+
+               MsgMmsReleaseMmsLists(pMmsMsgData);
+               MMS_FREE(pMmsMsgData);
+
        } else if (pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
 
-               MmsComposeNotiMessage(&mmsMsg, pMsgInfo->msgId);
+               MmsComposeNotiMessage(pMmsMsg, pMsgInfo->msgId);
 
                //add to db
-               if (addMmsMsgToDB(&mmsMsg, "") != MSG_SUCCESS) {
+               if (addMmsMsgToDB(pMmsMsg, "") != MSG_SUCCESS) {
                        MSG_DEBUG("Fail to add db message");
                        goto __CATCH;
                }
 
-               MmsReleaseMmsMsg(&mmsMsg);
+               MmsReleaseMmsMsg(pMmsMsg);
+               MMS_FREE(pMmsMsg);
        } else if (pMsgInfo->msgType.subType == MSG_SENDCONF_MMS || pMsgInfo->msgType.subType == MSG_RETRIEVE_AUTOCONF_MMS) {
+
                MmsMsg *pMsg = NULL;
-               char szTemp[MAX_MSG_DATA_LEN + 1]= {0, };
 
                if (!MmsReadMsgBody(pMsgInfo->msgId, true, true, pFileData))
                        THROW(MsgException::MMS_PLG_ERROR, "_MmsReadMsgBody Error");
@@ -1631,62 +1146,55 @@ void MmsPluginStorage::addMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_I
                        pMsgInfo->networkStatus = MSG_NETWORK_SEND_SUCCESS;
                else
                        pMsgInfo->networkStatus = MSG_NETWORK_RETRIEVE_SUCCESS;
-               strcpy(szTemp,pMsgInfo->msgData);
-               memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
-               strncpy(pMsgInfo->msgData, pFileData, MAX_MSG_DATA_LEN);
-
-               MmsPluginStorage *pStorage = MmsPluginStorage::instance();
-
-               MMS_MESSAGE_DATA_S mmsMsgData;
-               bzero(&mmsMsgData,sizeof(MMS_MESSAGE_DATA_S));
-               if (mmsHeader.msgType.type == MIME_MULTIPART_RELATED || mmsHeader.msgType.type == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
-                       char *pSmilDoc;
-                       char szFileName[MSG_FILENAME_LEN_MAX] = {0, };
-
-                       mmsMsgData.regionCnt = 0;
-                       mmsMsgData.pageCnt = 0;
-                       mmsMsgData.attachCnt = 0;
-                       mmsMsgData.transitionCnt = 0;
-                       mmsMsgData.metaCnt = 0;
-                       memset(mmsMsgData.szSmilFilePath, 0, MSG_FILEPATH_LEN_MAX);
-
-                       pSmilDoc = MmsSmilGetPresentationData(pMsgInfo->msgId);
-                       if (pSmilDoc) {
-                               MmsSmilParseSmilDoc(&mmsMsgData, pSmilDoc);
-
-                               MmsPluginStorage::instance()->getMmsMessage(&pMsg);
-                               strcpy(szFileName, pMsg->szFileName);
-
-                               err = pStorage->getMsgText(&mmsMsgData, pMsgInfo->msgText);
-                               MmsMakePreviewInfo(pMsgInfo->msgId, &mmsMsgData);
+
+
+               {//preview data
+                       MMS_MESSAGE_DATA_S tempMmsMsgData = {0,};
+                       if (MmsMakeMmsData(pMsg, &tempMmsMsgData) == false) {
+                               MSG_DEBUG("Fail to makeMmsMessageData");
+                       } else {
+                               err = MmsMakePreviewInfo(pMsgInfo->msgId, &tempMmsMsgData);
+                               err = getMsgText(&tempMmsMsgData, pMsgInfo->msgText);
                        }
 
-                       MsgMmsReleaseMmsLists(&mmsMsgData);
-               }
+                       if (tempMmsMsgData.attachCnt > 0) {
+                               if (updateMmsAttachCount(pMsg->msgID, tempMmsMsgData.attachCnt) != MSG_SUCCESS) {
+                                       MSG_DEBUG("Fail to updateMmsAttachCount");
+                                       goto __CATCH;
+                               }
+                       }
+
+                       MsgMmsReleaseMmsLists(&tempMmsMsgData);
+               }//end preview data
 
-               if (addMmsMsgToDB(pMsg, pMsgInfo) != MSG_SUCCESS) {
-                       MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
+               if (addMmsMsgToDB(pMsg, pFileData) != MSG_SUCCESS) {
+                       MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
 
                        THROW(MsgException::MMS_PLG_ERROR, "MMS Stroage Error");
                }
-               memset(pMsgInfo->msgData, 0, MAX_MSG_DATA_LEN + 1);
-               strcpy((char *)pMsgInfo->msgData,szTemp);
-
-               MmsReleaseMsgBody(&mmsMsg.msgBody, mmsMsg.msgType.type);
 
+               MmsReleaseMsgBody(&pMsg->msgBody, pMsg->msgType.type);
        } else {
                MSG_DEBUG("Not support msg sub type [%d]", pMsgInfo->msgType.subType);
                goto __CATCH;
        }
 
+       MmsReleaseMmsMsg(pMmsMsg);
+       MsgMmsReleaseMmsLists(pMmsMsgData);
+       MMS_FREE(pMmsMsg);
+       MMS_FREE(pMmsMsgData);
+
        MSG_END();
        return;
 
 __CATCH:
 
        removePreviewInfo(pMsgInfo->msgId);
-       MmsReleaseMmsMsg(&mmsMsg);
-       MsgMmsReleaseMmsLists(&mmsMsgData);
+
+       MmsReleaseMmsMsg(pMmsMsg);
+       MsgMmsReleaseMmsLists(pMmsMsgData);
+       MMS_FREE(pMmsMsg);
+       MMS_FREE(pMmsMsgData);
 
        THROW(MsgException::MMS_PLG_ERROR, "MMS add Error");
 }
index 851c843..5ef83ef 100755 (executable)
@@ -30,8 +30,7 @@
 #include "MmsPluginCodec.h"
 #include "MmsPluginDrm.h"
 #include "MmsPluginStorage.h"
-
-extern MmsHeader mmsHeader;
+#include "MmsPluginUtil.h"
 
 void PRINT_PDU_TYPE(MMS_PDU_TYPE_T pduType)
 {
@@ -183,6 +182,18 @@ void updatePduType(mmsTranQEntity *qEntity)
        PRINT_PDU_TYPE(qEntity->eMmsPduType);
 }
 
+bool compare_func(mmsTranQEntity const &a, mmsTranQEntity const &b)
+{
+       if (a.msgId == b.msgId) {
+               if ((a.eMmsPduType == eMMS_RETRIEVE_MANUAL || a.eMmsPduType == eMMS_RETRIEVE_AUTO)
+                               &&(b.eMmsPduType == eMMS_RETRIEVE_MANUAL || b.eMmsPduType == eMMS_RETRIEVE_AUTO)) {
+                       return true;
+               }
+       }
+
+       return false;
+}
+
 MmsPluginUaManager *MmsPluginUaManager::pInstance = NULL;
 
 MmsPluginUaManager::MmsPluginUaManager()
@@ -231,12 +242,65 @@ MMS_NET_ERROR_T MmsPluginUaManager::submitHandler(mmsTranQEntity *qEntity)
 
        MmsPluginHttpAgent*     httpAgent = MmsPluginHttpAgent::instance();
 
+       http_request_info_s request_info = {};
+
+       char *http_url = NULL;
+
+       memset(&request_info, 0x00, sizeof(request_info));
+
+       const char *home_url = NULL;
+       const char *proxy_addr = NULL;
+       const char *interfaceName = NULL;
+
+       MmsPluginCmAgent::instance()->getProxyAddr(&proxy_addr);
+       MmsPluginCmAgent::instance()->getInterfaceName(&interfaceName);
+       MmsPluginCmAgent::instance()->getHomeUrl(&home_url);
+
+       if (qEntity->eHttpCmdType == eHTTP_CMD_POST_TRANSACTION) {
+
+               request_info.transaction_type = MMS_HTTP_TRANSACTION_TYPE_POST;
+
+               request_info.url = home_url;
+
+               request_info.proxy = proxy_addr;
+
+               request_info.interface = interfaceName;
+
+               request_info.post_data = qEntity->pPostData;
+
+               request_info.post_data_len = qEntity->postDataLen;
+
+       } else {
+               request_info.transaction_type = MMS_HTTP_TRANSACTION_TYPE_GET;
+
+               http_url = (char *)calloc(1, qEntity->getDataLen + 1);
+
+               memcpy(http_url, qEntity->pGetData, qEntity->getDataLen);
+
+               request_info.url = http_url;
+
+               request_info.proxy = proxy_addr;
+
+               request_info.interface = interfaceName;
+       }
+
+
        while (retryCount < RETRY_MAX) {
-               ret = httpAgent->cmdRequest(qEntity->eHttpCmdType);
+
+               ret = httpAgent->httpRequest(request_info);
 
                // Process result
-               if (ret == eMMS_HTTP_SENT_SUCCESS) {
+               if (ret == MMS_HTTP_ERROR_NONE) {
                        MSG_DEBUG("Submit request sent");
+
+                       if (qEntity->pGetData) {
+                               free(qEntity->pGetData);
+                               qEntity->pGetData = NULL;
+                       }
+
+                       qEntity->pGetData = request_info.response_data;
+                       qEntity->getDataLen = request_info.response_data_len;
+
                        break;
                } else if (ret == eMMS_HTTP_ERROR_NETWORK) {
                        retryCount++;
@@ -248,34 +312,15 @@ MMS_NET_ERROR_T MmsPluginUaManager::submitHandler(mmsTranQEntity *qEntity)
                }
        }
 
+       if (http_url)
+               free(http_url);
+
        return ret;
 }
 
 MMS_NET_ERROR_T MmsPluginUaManager::waitingConf(mmsTranQEntity *qEntity)
 {
-       MMS_NET_ERROR_T ret = eMMS_HTTP_ERROR_UNKNOWN;
-       MmsPluginHttpAgent *pHttpAgent = MmsPluginHttpAgent::instance();
-       MMS_PLUGIN_HTTP_CONTEXT_S *pMmsPldCd = NULL;
-
-       pMmsPldCd = pHttpAgent->getMmsPldCd();
-
-       if (qEntity->pGetData) {
-               free(qEntity->pGetData);
-               qEntity->pGetData = NULL;
-       }
-       qEntity->getDataLen = pMmsPldCd->bufOffset;
-       qEntity->pGetData = (char *)calloc(1, pMmsPldCd->bufOffset + 1);
-
-       memcpy(qEntity->pGetData, pMmsPldCd->final_content_buf, pMmsPldCd->bufOffset);
-       free(pMmsPldCd->final_content_buf);
-       pMmsPldCd->final_content_buf = NULL;
-       pMmsPldCd->bufOffset = 0;
-
-       MSG_DEBUG("dataLen:%d  pData:(%s)", qEntity->getDataLen, qEntity->pGetData);
-
-       ret = eMMS_HTTP_CONF_SUCCESS;
-
-       return ret;
+       return eMMS_HTTP_CONF_SUCCESS;
 }
 
 void MmsPluginUaManager::run()
@@ -283,10 +328,6 @@ void MmsPluginUaManager::run()
        MSG_BEGIN();
 
        MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance();
-       MmsPluginHttpAgent *httpAgent = MmsPluginHttpAgent::instance();
-
-       int trId;
-//     CURL *session = NULL;
 
        int msgId;
 
@@ -362,8 +403,6 @@ void MmsPluginUaManager::run()
                        goto CLEANUP;
                }
 
-               httpAgent->SetMMSProfile();
-
                while (!mmsTranQ.empty()) {
 
                        MSG_DEBUG("###### mmsTranQ.size [%d]", mmsTranQ.size());
@@ -382,21 +421,12 @@ void MmsPluginUaManager::run()
                                MmsPluginStorage::instance()->updateNetStatus(msgId, MSG_NETWORK_RETRIEVING);
                        }
 
-                       if (httpAgent->cmdRequest(eHTTP_CMD_INIT_SESSION) == eMMS_HTTP_SESSION_OPEN_FAILED) {
-                               MSG_DEBUG("HTTP session open failed");
-                               // cm close
-                               cmAgent->close();
-                               // delete all request from reqQEntities
-                               goto CLEANUP;
-                       }
-
                        // MMS Transaction
                        MSG_DEBUG("\n\n ===================  MMS Transaction Start ========================");
 
                        do {
-                               httpAgent->setSession(&reqEntity);
 
-                               if (submitHandler(&reqEntity) != eMMS_HTTP_SENT_SUCCESS) {
+                               if (submitHandler(&reqEntity) != MMS_HTTP_ERROR_NONE) {
                                        MSG_DEBUG("Transaction Error: submit failed");
 
                                        MmsPluginEventHandler::instance()->handleMmsError(&reqEntity);
@@ -406,7 +436,6 @@ void MmsPluginUaManager::run()
                                }
 
                                MSG_DEBUG("submitHandler(&reqEntity) success.");
-                               trId = httpAgent->getHttpConfigData()->transactionId;
 
                                MSG_DEBUG("#### MMS PDU TYPE = %d ####", reqEntity.eMmsPduType);
 
@@ -474,7 +503,7 @@ void MmsPluginUaManager::run()
                                                break;
                                        }
 
-                                       MsgSettingGetBool(MMS_RECV_DELIVERY_RECEIPT, &bReportAllowed);
+                                       MsgSettingGetBool(MMS_SEND_REPORT_ALLOWED, &bReportAllowed);
 
                                        MSG_DEBUG("conf received successfully -2");
                                        MSG_DEBUG("reqEntity.eMmsPduType [%d]", reqEntity.eMmsPduType);
@@ -515,7 +544,9 @@ void MmsPluginUaManager::run()
 
                                                mmsTranQ.push_front(reqEntity);
 
-                                               remove(filepath);
+                                               if (remove(filepath) != 0) {
+                                                       MSG_DEBUG("Error removing file");
+                                               }
 
                                                MSG_DEBUG("Submit Ind");
                                        } else if (reqEntity.eMmsPduType == eMMS_RETRIEVE_MANUAL_CONF) {
@@ -566,6 +597,7 @@ void MmsPluginUaManager::run()
                                        MmsPluginEventHandler::instance()->handleMmsError(&reqEntity);
                                        break;
                                }
+
                        } while (reqEntity.isCompleted == false);
 
                        MSG_DEBUG("==== MMS Transaction Completed ====\n\n");
@@ -580,8 +612,6 @@ void MmsPluginUaManager::run()
                                reqEntity.pGetData = NULL;
                        }
 
-                       // Http Session Close
-                       httpAgent->clearSession();
                }
 
                // Request CM Close
@@ -634,6 +664,11 @@ void MmsPluginUaManager::getMmsPduData(mmsTranQEntity *qEntity)
 
 void MmsPluginUaManager::addMmsReqEntity(mmsTranQEntity req)
 {
+       if (mmsTranQ.checkExist(req, compare_func) == true) {
+               MSG_DEBUG("request Already Exist, req_id = %d", req.msgId);
+               THROW(MsgException::REQ_EXIST_ERROR, "MMS request already exist");
+       }
+
        MSG_DEBUG("New MMS Tran Added");
        mmsTranQ.push_back(req);
        lock();
@@ -667,39 +702,7 @@ bool MmsPluginUaManager::processReceivedData(int msgId, char *pRcvdBody, int rcv
 
        if (MmsReadMsgBody(msgId, true, true, retrievedFilePath) == false) {
                MSG_DEBUG("The MMS Message might include drm contents!!!");
-
-#ifdef __SUPPORT_DRM__
-               if (MmsDrm2GetConvertState() == MMS_DRM2_CONVERT_REQUIRED) {
-                       bool bRetToConvert = true;
-                       MSG_MESSAGE_INFO_S pMsg = {0, };
-
-                       pMsg.msgId = msgId;
-
-                       bRetToConvert = MmsDrm2ConvertMsgBody(mmsHeader.msgType.szOrgFilePath);
-
-                       MmsDrm2SetConvertState(MMS_DRM2_CONVERT_FINISH);
-
-                       if (bRetToConvert) {
-                               int ret;
-                               ret = remove(mmsHeader.msgType.szOrgFilePath);
-                               if (ret != 0) {
-                                       MSG_DEBUG("remove fail\n");
-                                       goto ERR_MMS_UA_PROCESS_CONF;
-                               }
-
-                               ret = rename(MMS_DECODE_DRM_CONVERTED_TEMP_FILE, mmsHeader.msgType.szOrgFilePath);
-                               if (ret != 0) {
-                                       MSG_DEBUG("rename fail\n");
-                                       goto ERR_MMS_UA_PROCESS_CONF;
-                               }
-
-                               if (MmsDrm2ReadMsgConvertedBody(&pMsg, true, true, retrievedFilePath) == false) {
-                                       MSG_DEBUG("MmsLoadMsg:MmsDrm2ReadMsgConvertedBody() returns false\n");
-                                       goto ERR_MMS_UA_PROCESS_CONF;
-                               }
-                       }
-               }
-#endif
+               goto ERR_MMS_UA_PROCESS_CONF;
        }
 
        MSG_END();
@@ -724,3 +727,4 @@ ERR_MMS_UA_PROCESS_CONF:
        }
 }
 
+
index fb6a31a..eddbd69 100755 (executable)
@@ -20,6 +20,8 @@
 #include <network-cm-intf.h>
 #include <network-pm-intf.h>
 #include "MsgMutex.h"
+#include <glib.h>
+#include "net_connection.h"
 
 class MmsPluginCmAgent
 {
@@ -32,36 +34,33 @@ public:
 
        bool getCmStatus() { return isCmOpened; }
 
-       void processCBdatas(net_event_info_t *event_cb, void *user_data);
-
-       bool getDeviceName(char *deviceName);
-       bool getHomeURL(char *homeURL);
-       bool getProxyAddr(char *proxyAddr);
-       int getProxyPort();
+       void open_callback(connection_error_e result, void* user_data);
+       void close_callback(connection_error_e result, void* user_data);
 
+       bool getInterfaceName(const char **deviceName);
+       bool getProxyAddr(const char **proxyAddr);
+       bool getHomeUrl(const char **homeURL);
 private:
        MmsPluginCmAgent();
        ~MmsPluginCmAgent();
 
        static MmsPluginCmAgent *pInstance;
 
-       /* register/deregister is called once at initialization/finalization of MMS plugin */
-       bool registration();
-       void deregistration();
-
-
        void lock() { mx.lock(); }
        void unlock() { mx.unlock(); }
        void signal() { cv.signal(); }
        void setCmStatus() { isCmOpened = true; }
        void resetCmStatus() { isCmOpened = false; }
 
-       // shared variable between CmAgent and Dnet callback
        bool isCmOpened;
+       bool isCmRegistered;
+
+       char *home_url;
+       char *interface_name;
+       char *proxy_address;
        Mutex mx;
        CndVar cv;
 
-       net_profile_info_t mmsProfile;
 };
 
 #endif //MMS_PLUGIN_CONNMAN_H
index b150be6..36eda58 100755 (executable)
@@ -97,7 +97,7 @@ typedef struct {
        MsgBody msgBody;
 } MmsHeader;
 
-extern MmsHeader mmsHeader;
+extern __thread MmsHeader mmsHeader;
 
 /* Decoding */
 void MmsInitHeader();
index ea3c9dd..d090de6 100755 (executable)
@@ -19,6 +19,7 @@
 
 #include <map>
 #include "MmsPluginTypes.h"
+#include "MsgMutex.h"
 
 #define MSG_MMS_HH_CONTENT_TYPE     "application/vnd.wap.mms-message"
 #define MSG_MMS_HH_ACCEPT           "application/vnd.wap.mms-message, */*"
@@ -43,23 +44,46 @@ enum _MMS_HTTP_HEADER_FIELD_E {
        MMS_HH_WAP_PROFILE
 };
 
+typedef enum _MMS_HTTP_TRANSACTION_TYPE_E {
+       MMS_HTTP_TRANSACTION_TYPE_UNKNOWN = 0,
+       MMS_HTTP_TRANSACTION_TYPE_GET,
+       MMS_HTTP_TRANSACTION_TYPE_POST,
+} MMS_HTTP_TRANSACTION_TYPE_E;
+
+typedef enum _MMS_HTTP_ERROR_E {
+       MMS_HTTP_ERROR_NONE = 0,
+       MMS_HTTP_ERROR_ABORT,
+       MMS_HTTP_ERROR_TRANSACTION_TYPE,
+       MMS_HTTP_ERROR_TRANSACTION,
+} MMS_HTTP_ERROR_E;
+
+typedef struct _http_session_info_s {
+       MMS_HTTP_TRANSACTION_TYPE_E transaction_type;
+       const char *url;
+       const char *proxy;
+       const char *interface;
+       const char *post_data;
+       unsigned int post_data_len;
+       char *response_data;
+       unsigned int response_data_len;
+} http_request_info_s;
+
 class MmsPluginHttpAgent
 {
        public:
                static MmsPluginHttpAgent *instance();
 
-               int cmdRequest(MMS_HTTP_CMD_TYPE_T cmdType);
-
-               int setSession(mmsTranQEntity *qEntity);
-
-               void clearSession();
-
-               void SetMMSProfile();
+               MMS_HTTP_ERROR_E httpRequest(http_request_info_s &request_info);
 
-               MMS_PLUGIN_HTTP_DATA_S *getHttpConfigData();
-               MMS_PLUGIN_HTTP_CONTEXT_S *getMmsPldCd();
+               void setAbortFlag(){
+                       MutexLocker locker(mx);
+                       abort = true;
+               };
 
-               MMS_PLUGIN_HTTP_DATA_S httpConfigData;
+               bool getAbortFlag(){
+                       MutexLocker locker(mx);
+                       return abort;
+               };
 
        private:
                static MmsPluginHttpAgent *pInstance;
@@ -67,9 +91,24 @@ class MmsPluginHttpAgent
                MmsPluginHttpAgent();
                ~MmsPluginHttpAgent();
 
-               MMS_PLUGIN_HTTP_CONTEXT_S mmsPlgCd;
+               void initSession();
+               MMS_HTTP_ERROR_E setSession(http_request_info_s &request_info);
+               MMS_HTTP_ERROR_E startTransaction();
+               void clearSession();
+
+               void initAbortFlag(){
+                       MutexLocker locker(mx);
+                       abort = false;
+               };
+
+               MMS_HTTP_TRANSACTION_TYPE_E transaction_type;
+
+               void *session_header;
+               void *session_option;
 
-               std::map<MMS_HTTP_CMD_TYPE_T,int(*)(MMS_PLUGIN_HTTP_DATA_S *)> httpCmdHandler;
+               FILE *respfile;
+               bool abort;
+               Mutex mx;
 };
 
 #endif //MMS_PLUGIN_HTTP_H
index 048885f..cad9cc8 100755 (executable)
@@ -286,7 +286,7 @@ MSG_DEBUG("address [%s]", tpdu.data.submit.destAddress.address);
                        }
                        else
                        {
-                               MsgInsertTicker("Sending SMS is failed", NULL);
+                               //MsgInsertTicker("Sending SMS is failed", NULL);
                                MsgInsertTicker("Sending SMS is failed", SMS_MESSAGE_SENDING_FAIL);
 
                                SmsPluginEventHandler::instance()->handleSentStatus(MSG_NETWORK_SEND_FAIL);
index 5bffa64..3596afa 100755 (executable)
@@ -3179,7 +3179,7 @@ void SmsPluginWapPushHandler::wspHeaderDecodeDateValue( unsigned long length, un
 
        /* check date value validity */
        {
-               if (( pTMData->tm_wday > 6 ) || (pTMData->tm_mon > 12 ) || (pTMData->tm_mday >  31 ))
+               if (( pTMData->tm_wday > 6 ) || (pTMData->tm_mon > 11 ) || (pTMData->tm_mday >  31 ))
                {
                        MSG_DEBUG( "WspLHeaderDecodeDateValue: Date decode fail %d, %d, %d \n", pTMData->tm_wday, pTMData->tm_mon, pTMData->tm_mday );
                        strncpy( (char*)*pDecodedString, "Decoding Failed", WSP_STANDARD_STR_LEN_MAX-1);
index 3d59896..cf2905f 100755 (executable)
@@ -44,7 +44,7 @@ INCLUDE_DIRECTORIES(
 )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(utils_pkgs REQUIRED glib-2.0 vconf db-util contacts-service2 dlog pmapi mm-session alarm-service notification drm-client)
+pkg_check_modules(utils_pkgs REQUIRED glib-2.0 vconf db-util contacts-service2 dlog pmapi mm-session alarm-service notification drm-client appsvc)
 
 FOREACH(flag ${utils_pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index 5b75e67..56518f5 100755 (executable)
@@ -20,6 +20,7 @@ extern "C"
 }
 
 #include "MsgDebug.h"
+#include "MsgIpcSocket.h"
 #include "MsgUtilStorage.h"
 #include "MsgGconfWrapper.h"
 #include "MsgContact.h"
@@ -40,10 +41,34 @@ static void MsgContactSvcCallback(const char *view_uri, void *user_data)
 {
        MSG_DEBUG("Contact Data is Changed!!!");
 
-       MsgSyncContact();
+       // establish connection to msgfw daemon
+       MsgIpcClientSocket client;
+       client.connect(MSG_SOCKET_PATH);
 
-       if (ContactDbHandle.disconnect() != MSG_SUCCESS)
-               MSG_DEBUG("DB Disconnect Fail");
+       // composing command
+       int cmdSize = sizeof(MSG_CMD_S); // cmd type
+
+       char cmdBuf[cmdSize];
+       bzero(cmdBuf, cmdSize);
+
+       MSG_CMD_S* pCmd = (MSG_CMD_S*) cmdBuf;
+
+       // Set Command Parameters
+       pCmd->cmdType = MSG_CMD_CONTACT_SYNC;
+
+       memset(pCmd->cmdCookie, 0x00, MAX_COOKIE_LEN);
+
+       // Send Command to Transaction Manager
+       client.write(cmdBuf, cmdSize);
+
+       // Receive result from Transaction Manager
+       char *temp = NULL;
+       AutoPtr<char> wrap(&temp);
+       unsigned int len;
+       client.read(&temp, &len);
+
+       // close connection to msgfw daemon
+       client.close();
 }
 
 
@@ -93,18 +118,23 @@ msg_error_t MsgInitContactSvc(MsgContactChangeCB cb)
 {
        msg_error_t err = MSG_SUCCESS;
 
-       if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
-               MSG_DEBUG("MsgOpenContactSvc fail.");
-               return err;
-       }
+       unsigned int retryCnt = 100;
 
-       int errCode = CONTACTS_ERROR_NONE;
+       do {
+               if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
+                       retryCnt--;
+                       MSG_DEBUG("MsgOpenContactSvc fail. Retry count left [%d]", retryCnt);
+                       usleep(500 * 1000);
+               }
+       } while (err != MSG_SUCCESS && retryCnt > 0);
 
        if (!isContactSvcConnected) {
                MSG_DEBUG("Contact Service Not Opened.");
                return MSG_ERR_UNKNOWN;
        }
 
+       int errCode = CONTACTS_ERROR_NONE;
+
        if (cb != NULL)
                cbFunction = cb;
 
@@ -189,6 +219,9 @@ msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_I
                return MSG_SUCCESS;
        }
 
+       contacts_query_destroy(query);
+       contacts_filter_destroy(filter);
+
        contacts_record_h contact = NULL;
 
        if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN || pAddrInfo->addressType == MSG_ADDRESS_TYPE_UNKNOWN) {
@@ -205,7 +238,6 @@ msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_I
                if (ret != CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
                        contacts_list_destroy(contacts, true);
-                       contacts_record_destroy(number, true);
                        return MSG_SUCCESS;
                }
 
@@ -214,7 +246,6 @@ msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_I
                        MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
                        contacts_list_destroy(contacts, true);
                        contacts_record_destroy(contact, true);
-                       contacts_record_destroy(number, true);
                        return MSG_SUCCESS;
                }
        } else if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_EMAIL) {
@@ -231,7 +262,6 @@ msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_I
                if (ret != CONTACTS_ERROR_NONE) {
                        MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
                        contacts_list_destroy(contacts, true);
-                       contacts_record_destroy(email, true);
                        return MSG_SUCCESS;
                }
 
@@ -240,7 +270,6 @@ msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_I
                        MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
                        contacts_list_destroy(contacts, true);
                        contacts_record_destroy(contact, true);
-                       contacts_record_destroy(email, true);
                        return MSG_SUCCESS;
                }
        }
@@ -253,33 +282,37 @@ msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_I
        ret = contacts_record_get_child_record_at_p(contact, _contacts_contact.name, 0, &name);
        if (ret != CONTACTS_ERROR_NONE) {
                MSG_DEBUG("contacts_record_get_child_record_at_p() Error [%d]", ret);
-               contacts_record_destroy(contact, true);
-               return MSG_SUCCESS;
-       }
+       } else {
+               char* strFirstName = NULL;
+               ret = contacts_record_get_str_p(name, _contacts_name.first, &strFirstName);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+               }
 
-       char* strFirstName = NULL;
-       ret = contacts_record_get_str_p(name, _contacts_name.first, &strFirstName);
-       if (ret != CONTACTS_ERROR_NONE) {
-               MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
-               contacts_record_destroy(contact, true);
-               return MSG_SUCCESS;
-       }
+               char* strLastName = NULL;
+               ret = contacts_record_get_str_p(name, _contacts_name.last, &strLastName);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+               }
 
-       char* strLastName = NULL;
-       ret = contacts_record_get_str_p(name, _contacts_name.last, &strLastName);
-       if (ret != CONTACTS_ERROR_NONE) {
-               MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
-               contacts_record_destroy(contact, true);
-               return MSG_SUCCESS;
-       }
+               char* strDisplayName = NULL;
+               ret = contacts_record_get_str_p(contact, _contacts_contact.display_name, &strDisplayName);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+               }
+
+               if (strFirstName != NULL)
+                       strncpy(pContactInfo->firstName, strFirstName, MAX_DISPLAY_NAME_LEN);
 
-       MSG_DEBUG("First Name : [%s], Last Name : [%s]", strFirstName, strLastName);
+               if (strLastName != NULL)
+                       strncpy(pContactInfo->lastName, strLastName, MAX_DISPLAY_NAME_LEN);
 
-       if (strFirstName != NULL)
-               strncpy(pContactInfo->firstName, strFirstName, MAX_DISPLAY_NAME_LEN);
+               if (strDisplayName != NULL)
+                       strncpy(pContactInfo->displayName, strDisplayName, MAX_DISPLAY_NAME_LEN);
+       }
 
-       if (strLastName != NULL)
-               strncpy(pContactInfo->lastName, strLastName, MAX_DISPLAY_NAME_LEN);
+       MSG_DEBUG("pContactInfo->firstName : [%s], pContactInfo->lastName : [%s]", pContactInfo->firstName, pContactInfo->lastName);
+       MSG_DEBUG("pContactInfo->displayName : [%s]", pContactInfo->displayName);
 
        ret = contacts_record_get_int(contact, _contacts_contact.id, (int*)&pContactInfo->contactId);
        if (ret != CONTACTS_ERROR_NONE) {
@@ -332,6 +365,7 @@ void MsgSyncContact()
 
        if (ret != CONTACTS_ERROR_NONE) {
                MSG_DEBUG("contacts_db_get_changes_by_version() Error [%d]", ret);
+               contacts_list_destroy(contactsList, true);
                return;
        }
 
@@ -454,35 +488,39 @@ bool MsgUpdateContact(int index, int type)
        ret = contacts_record_get_child_record_at_p(contact, _contacts_contact.name, 0, &name);
        if (ret != CONTACTS_ERROR_NONE) {
                MSG_DEBUG("contacts_record_get_child_record_at_p() Error [%d]", ret);
-               contacts_record_destroy(contact, true);
-               return false;
-       }
+       } else {
+               char* strFirstName = NULL;
+               ret = contacts_record_get_str_p(name, _contacts_name.first, &strFirstName);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+               }
 
-       char* strFirstName = NULL;
-       ret = contacts_record_get_str_p(name, _contacts_name.first, &strFirstName);
-       if (ret != CONTACTS_ERROR_NONE) {
-               MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
-               contacts_record_destroy(contact, true);
-               return false;
-       }
+               char* strLastName = NULL;
+               ret = contacts_record_get_str_p(name, _contacts_name.last, &strLastName);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+               }
 
-       char* strLastName = NULL;
-       ret = contacts_record_get_str_p(name, _contacts_name.last, &strLastName);
-       if (ret != CONTACTS_ERROR_NONE) {
-               MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
-               contacts_record_destroy(contact, true);
-               return false;
-       }
+               char* strDisplayName = NULL;
+               ret = contacts_record_get_str_p(contact, _contacts_contact.display_name, &strDisplayName);
+               if (ret != CONTACTS_ERROR_NONE) {
+                       MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
+               }
 
-       MSG_DEBUG("First Name : [%s], Last Name : [%s]", strFirstName, strLastName);
+               if (strFirstName != NULL)
+                       strncpy(contactInfo.firstName, strFirstName, MAX_DISPLAY_NAME_LEN);
 
-       if (strFirstName != NULL)
-               strncpy(contactInfo.firstName, strFirstName, MAX_DISPLAY_NAME_LEN);
+               if (strLastName != NULL)
+                       strncpy(contactInfo.lastName, strLastName, MAX_DISPLAY_NAME_LEN);
 
-       if (strLastName != NULL)
-               strncpy(contactInfo.lastName, strLastName, MAX_DISPLAY_NAME_LEN);
+               if (strDisplayName != NULL)
+                       strncpy(contactInfo.displayName, strDisplayName, MAX_DISPLAY_NAME_LEN);
 
-       MsgStoClearContactInfo(&ContactDbHandle, index);
+               MSG_DEBUG("First Name : [%s], Last Name : [%s]", contactInfo.firstName, contactInfo.lastName);
+               MSG_DEBUG("displayName : [%s]", contactInfo.displayName);
+       }
+
+       MsgStoResetContactInfo(&ContactDbHandle, index);
 
        unsigned int count = 0;
        ret = contacts_record_get_child_record_count(contact, _contacts_contact.number, &count);
@@ -570,13 +608,16 @@ bool MsgUpdateContact(int index, int type)
 
        contacts_record_destroy(contact, true);
 
+       if (type == -1 && cbFunction != NULL)
+               cbFunction();
+
        return true;
 }
 
 
 bool MsgDeleteContact(int index)
 {
-       if (MsgStoClearContactInfo(&ContactDbHandle, index) != MSG_SUCCESS)
+       if (MsgStoResetContactInfo(&ContactDbHandle, index) != MSG_SUCCESS)
                return false;
 
        return true;
index 7c3c572..48114ac 100755 (executable)
@@ -189,7 +189,7 @@ bool MsgDrmGetContentID(const char *szFileName, char *szContentID, int nContentI
 
        char strTemp[MSG_MAX_DRM_FILE_PATH + 1] = {0,};
 
-       strncpy(strTemp, szFileName, sizeof(strTemp));
+       strncpy(strTemp, szFileName, MSG_MAX_DRM_FILE_PATH);
 
        drm_content_info_s  content_info;
        memset(&content_info, 0x00, sizeof(drm_content_info_s));
index 7fcc0d0..4dcf2a6 100755 (executable)
@@ -58,6 +58,10 @@ static void MsgVconfCB(keynode_t *key, void* data)
        } else if (!strcmp(keyStr, VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL)) {
                bUnknownAutoReject = vconf_keynode_get_bool(key);
                MSG_DEBUG("[%s] key CB called. set to [%d].", VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, bUnknownAutoReject);
+       } else if (!strcmp(keyStr, VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER)) {
+               int contactDisplayOrder = vconf_keynode_get_int(key);
+               MSG_DEBUG("[%s] key CB called. Apply [%d]", VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, contactDisplayOrder);
+               MsgStoRefreshConversationDisplayName();
        } else {
                MSG_DEBUG("key did not match.");
        }
@@ -284,11 +288,12 @@ void MsgSettingRegVconfCB()
 
        MsgSettingRegVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, MsgVconfCB);
        MsgSettingRegVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, MsgVconfCB);
+       MsgSettingRegVconfCBCommon(VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, MsgVconfCB);
 }
 
 void MsgSettingRemoveVconfCB()
 {
        MsgSettingRemoveVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, MsgVconfCB);
        MsgSettingRemoveVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, MsgVconfCB);
-
+       MsgSettingRemoveVconfCBCommon(VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, MsgVconfCB);
 }
index bb14376..933ee37 100755 (executable)
@@ -24,6 +24,7 @@
 extern "C"
 {
        #include <notification.h>
+       #include <appsvc.h>
 }
 
 /*==================================================================================================
@@ -37,10 +38,7 @@ void MsgSmsClass0Noti(MSG_MESSAGE_INFO_S* pMsg, notification_h noti, bundle* arg
 
        memset(tempId, 0x00, sizeof(tempId));
 
-       noti_err = notification_set_application(noti, "org.tizen.msg-ui-class0");
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
-       }
+       appsvc_set_appid(args, "org.tizen.msg-ui-class0");
 
        noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
        if (noti_err != NOTIFICATION_ERROR_NONE) {
@@ -66,7 +64,10 @@ void MsgSmsClass0Noti(MSG_MESSAGE_INFO_S* pMsg, notification_h noti, bundle* arg
        // set time.
        notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, pMsg->displayTime);
 
-       bundle_add(args, "type", "msg_id");
+       // set led.
+       notification_set_led(noti, NOTIFICATION_LED_OP_ON, 0x00);
+
+       bundle_add(args, "type", "new_msg");
 
        snprintf(tempId, 5, "%d", pMsg->msgId);
        bundle_add(args, "msgId", tempId);
@@ -74,34 +75,29 @@ void MsgSmsClass0Noti(MSG_MESSAGE_INFO_S* pMsg, notification_h noti, bundle* arg
        MSG_END();
 }
 
-void MsgSmsCBNoti(MSG_MESSAGE_INFO_S* pMsg, notification_h noti, bundle* args)
+
+void MsgSmsMWINoti(MSG_MESSAGE_INFO_S* pMsg, notification_h noti, bundle* args)
 {
        MSG_BEGIN();
 
        notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
-       char tempId[6];
-
-       memset(tempId, 0x00, sizeof(tempId));
 
-       noti_err = notification_set_application(noti, "8r4r5ddzzn.Messages");
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
-       }
+       appsvc_set_appid(args, "org.tizen.call");
 
        noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
        if (noti_err != NOTIFICATION_ERROR_NONE) {
                MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
        }
 
-       noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, CB_MSG_ICON_PATH);
+       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "MWI Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New MWI Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+       noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
        if (noti_err != NOTIFICATION_ERROR_NONE) {
                MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
        }
 
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "CB Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New CB Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
        if (pMsg->addressList[0].displayName[0] == '\0')
                notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
        else
@@ -112,37 +108,58 @@ void MsgSmsCBNoti(MSG_MESSAGE_INFO_S* pMsg, notification_h noti, bundle* args)
        // set time.
        notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, pMsg->displayTime);
 
-       memset(&tempId, 0x00, sizeof(tempId));
-
-       bundle_add(args, "type", "msg_id");
+       // set led.
+       notification_set_led(noti, NOTIFICATION_LED_OP_ON, 0x00);
 
-       snprintf(tempId, 5, "%d", pMsg->msgId);
-       bundle_add(args, "msgId", tempId);
+       bundle_add(args, "launch-type", "MO");
+       bundle_add(args, "number", pMsg->addressList[0].addressVal);
 
        MSG_END();
 }
 
-void MsgSmsVoiceNoti(MSG_MESSAGE_INFO_S* pMsg, notification_h noti, bundle* args)
+
+void MsgSmsVoiceNoti(MSG_MESSAGE_INFO_S* pMsg)
 {
        MSG_BEGIN();
 
+       int notiId = 0;
+       notification_h noti = NULL;
        notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+       bundle* args;
 
-       noti_err = notification_set_application(noti, "org.tizen.call");
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
+       args = bundle_create();
+
+       notiId = MsgSettingGetInt(VOICE_NOTI_ID_1);
+
+       if (notiId > 0) {
+               noti = notification_load(NULL, notiId);
+               if (noti == NULL)
+                       MSG_DEBUG("notification_load is failed.");
+       }
+
+       if (noti == NULL) {
+               noti = notification_create(NOTIFICATION_TYPE_NOTI);
+               if (noti == NULL) {
+                       MSG_DEBUG("notification_new is failed.");
+                       if (args != NULL) bundle_free(args);
+                       return;
+               }
+
+               notiId = 0;
        }
 
+       appsvc_set_appid(args, "org.tizen.call");
+
        noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
        if (noti_err != NOTIFICATION_ERROR_NONE) {
                MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
        }
 
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Voice Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Voicemail", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
 
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Voice Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Voicemail", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
 
-       noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, VOICE_MSG_ICON_PATH);
+       noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
        if (noti_err != NOTIFICATION_ERROR_NONE) {
                MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
        }
@@ -157,10 +174,47 @@ void MsgSmsVoiceNoti(MSG_MESSAGE_INFO_S* pMsg, notification_h noti, bundle* args
        // set time.
        notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, pMsg->displayTime);
 
-       //FIXME :: Temp code for voice number, 2012.08.16 sangkoo.kim
+       // set led.
+       notification_set_led(noti, NOTIFICATION_LED_OP_ON, 0x00);
+
        bundle_add(args, "launch-type", "MO");
        bundle_add(args, "number", pMsg->addressList[0].addressVal);
 
+       if (args != NULL) {
+               noti_err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, args);
+               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                       MSG_DEBUG("Fail to notification_set_execute_option : %d", noti_err);
+               }
+       }
+
+       if (notiId > 0) {
+               noti_err = notification_update(noti);
+               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                       MSG_DEBUG("Fail to notification_update");
+               }
+       } else {
+               noti_err = notification_insert(noti, &notiId);
+               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                       MSG_DEBUG("Fail to notification_insert");
+               }
+
+               if (MsgSettingSetInt(VOICE_NOTI_ID_1, notiId) == MSG_SUCCESS)
+                       MSG_DEBUG("Insert VOICE_NOTI_ID_1 [%d]", notiId);
+               else
+                       MSG_DEBUG("MsgSettingSetInt fail: VOICE_NOTI_ID_1");
+       }
+
+       noti_err = notification_free(noti);
+       if (noti_err != NOTIFICATION_ERROR_NONE) {
+               MSG_DEBUG("Fail to notification_free");
+       }
+
+       if (args != NULL) {
+               bundle_free(args);
+       }
+
+       MsgChangePmState();
+
        MSG_END();
 }
 
@@ -170,66 +224,67 @@ void MsgSmsReportNoti(MSG_MESSAGE_INFO_S* pMsg, notification_h noti, bundle* arg
        MSG_BEGIN();
 
        notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
-       char tempId[6];
-
-       memset(tempId, 0x00, sizeof(tempId));
 
-       noti_err = notification_set_application(noti, "8r4r5ddzzn.Messages");
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
-       }
        noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
        if (noti_err != NOTIFICATION_ERROR_NONE) {
                MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
        }
 
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Delivery Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Delivery Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Delivery Report", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+       if(pMsg->networkStatus == MSG_NETWORK_DELIVER_SUCCESS)
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Message Delivered", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+       else
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Message delivery failed", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
 
-       noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NOTI_MSG_ICON_PATH);
+       noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
        if (noti_err != NOTIFICATION_ERROR_NONE) {
                MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
        }
 
+       // get contact info.
+       MSG_CONTACT_INFO_S contactInfo;
+       memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
+       MsgGetContactInfo(&(pMsg->addressList[0]), &contactInfo);
+
+       int order = MsgGetContactNameOrder();
+
+       if (order == 0) {
+               if (contactInfo.firstName[0] != '\0') {
+                       strncpy(pMsg->addressList[0].displayName, contactInfo.firstName, MAX_DISPLAY_NAME_LEN);
+               }
+
+               if (contactInfo.lastName[0] != '\0') {
+                       strncat(pMsg->addressList[0].displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(pMsg->addressList[0].displayName));
+                       strncat(pMsg->addressList[0].displayName, contactInfo.lastName, MAX_DISPLAY_NAME_LEN-strlen(pMsg->addressList[0].displayName));
+               }
+       } else if (order == 1) {
+               if (contactInfo.lastName[0] != '\0') {
+                       strncpy(pMsg->addressList[0].displayName, contactInfo.lastName, MAX_DISPLAY_NAME_LEN);
+                       strncat(pMsg->addressList[0].displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(pMsg->addressList[0].displayName));
+               }
+
+               if (contactInfo.firstName[0] != '\0') {
+                       strncat(pMsg->addressList[0].displayName, contactInfo.firstName, MAX_DISPLAY_NAME_LEN-strlen(pMsg->addressList[0].displayName));
+               }
+       }
+
        if (pMsg->addressList[0].displayName[0] == '\0')
                notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
        else
                notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, pMsg->addressList[0].displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
 
-       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, pMsg->msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message delivered.", pMsg->msgText, NOTIFICATION_VARIABLE_TYPE_NONE);
 
        // set time.
        notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, pMsg->displayTime);
 
-       // get msg id
-       MsgDbHandler dbhandler;
-       char sqlQuery[MAX_QUERY_LEN+1];
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery),
-                       "SELECT MSG_ID "
-                       "FROM %s "
-                       "WHERE CONV_ID IN (SELECT CONV_ID FROM %s WHERE ADDRESS_VAL LIKE '%%%s') AND FOLDER_ID=%d "
-                       "ORDER BY DISPLAY_TIME DESC;"
-                       , MSGFW_MESSAGE_TABLE_NAME, MSGFW_ADDRESS_TABLE_NAME, pMsg->addressList[0].addressVal, MSG_SENTBOX_ID);
-
-       MSG_DEBUG("sqlQuery - %s", sqlQuery);
-
-       if (dbhandler.prepareQuery(sqlQuery) == MSG_SUCCESS) {
+       // set led.
+       notification_set_led(noti, NOTIFICATION_LED_OP_ON, 0x00);
 
-               if (dbhandler.stepQuery() == MSG_ERR_DB_ROW) {
-                       memset(&tempId, 0x00, sizeof(tempId));
-
-                       bundle_add(args, "type", "report");
-
-                       snprintf(tempId, 5, "%d", dbhandler.columnInt(0));
-                       bundle_add(args, "msgId", tempId);
-
-                       MSG_DEBUG("msgId [%s] add.", tempId);
-               }
-
-               dbhandler.finalizeQuery();
-       }
+       // set launch type
+       noti_err = notification_set_property(noti, NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
+       if (noti_err != NOTIFICATION_ERROR_NONE)
+               MSG_DEBUG("Fail to notification_set_display_applist");
 
        MSG_END();
 }
@@ -248,60 +303,55 @@ msg_error_t MsgInsertNoti(MSG_MESSAGE_INFO_S* pMsg)
                return MSG_ERR_UNKNOWN;
        }
 
-       if (pMsg->msgType.mainType == MSG_SMS_TYPE) {
-               switch(pMsg->msgType.subType)
-               {
-               case MSG_CB_SMS :
-                       args = bundle_create();
-                       MsgSmsCBNoti(pMsg, noti, args);
-                       break;
-               case MSG_MWI_VOICE_SMS :
-               case MSG_MWI_FAX_SMS :
-               case MSG_MWI_EMAIL_SMS :
-               case MSG_MWI_OTHER_SMS :
-                       args = bundle_create();
-                       MsgSmsVoiceNoti(pMsg, noti, args);
-                       break;
-               case MSG_STATUS_REPORT_SMS :
-                       args = bundle_create();
-                       MsgSmsReportNoti(pMsg, noti, args);
-                       break;
-               default :
-                       MsgRefreshNoti(true);
-                       noti_err = notification_free(noti);
-                       if (noti_err != NOTIFICATION_ERROR_NONE) {
-                               MSG_DEBUG("Fail to notification_free");
-                       }
-                       return MSG_SUCCESS;
-                       break;
+       switch(pMsg->msgType.subType)
+       {
+       case MSG_CB_SMS :
+               noti_err = notification_free(noti);
+               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                       MSG_DEBUG("Fail to notification_free");
                }
-       } else if (pMsg->msgType.mainType == MSG_MMS_TYPE) {
-               switch(pMsg->msgType.subType)
-               {
-               default :
-                       MsgRefreshNoti(true);
-                       noti_err = notification_free(noti);
-                       if (noti_err != NOTIFICATION_ERROR_NONE) {
-                               MSG_DEBUG("Fail to notification_free");
-                       }
-                       return MSG_SUCCESS;
-                       break;
+               MsgRefreshCBNoti(true);
+               return MSG_SUCCESS;
+               break;
+       case MSG_MWI_FAX_SMS :
+       case MSG_MWI_EMAIL_SMS :
+       case MSG_MWI_OTHER_SMS :
+               args = bundle_create();
+               MsgSmsMWINoti(pMsg, noti, args);
+               break;
+       case MSG_MWI_VOICE_SMS :
+               noti_err = notification_free(noti);
+               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                       MSG_DEBUG("Fail to notification_free");
                }
-       } else {
-               MSG_DEBUG("Message type does not match.");
-
+               MsgSmsVoiceNoti(pMsg);
+               return MSG_SUCCESS;
+               break;
+       case MSG_STATUS_REPORT_SMS :
+               //args = bundle_create();
+               MsgSmsReportNoti(pMsg, noti, NULL);
+               break;
+       case MSG_NORMAL_SMS :
+               if (pMsg->msgType.classType == MSG_CLASS_0) {
+                       args = bundle_create();
+                       MsgSmsClass0Noti(pMsg, noti, args);
+                       break;
+               } // Do not break here.
+       default :
                noti_err = notification_free(noti);
                if (noti_err != NOTIFICATION_ERROR_NONE) {
                        MSG_DEBUG("Fail to notification_free");
                }
-
-               return MSG_ERR_INVALID_PARAMETER;
+               MsgRefreshNoti(true);
+               return MSG_SUCCESS;
+               break;
        }
 
        if (args != NULL) {
-               noti_err = notification_set_args(noti, args, NULL);
+               // set execute option
+               noti_err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, args);
                if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_args : %d", noti_err);
+                       MSG_DEBUG("Fail to notification_set_execute_option : %d", noti_err);
                }
        }
 
@@ -334,14 +384,12 @@ msg_error_t MsgInsertMmsReportToNoti(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S
        char addressVal[MAX_ADDRESS_VAL_LEN+1];
        char firstName[MAX_DISPLAY_NAME_LEN+1], lastName[MAX_DISPLAY_NAME_LEN+1];
        char displayName[MAX_DISPLAY_NAME_LEN+1];
-       char contents[MAX_DISPLAY_NAME_LEN+1];
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(addressVal, 0x00, sizeof(addressVal));
        memset(firstName, 0x00, sizeof(firstName));
        memset(lastName, 0x00, sizeof(lastName));
        memset(displayName, 0x00, sizeof(displayName));
-       memset(contents, 0x00, sizeof(contents));
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
        int report_status_type;
@@ -460,18 +508,32 @@ msg_error_t MsgInsertMmsReportToNoti(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S
                return MSG_ERR_UNKNOWN;
        }
 
-       noti_err = notification_set_application(noti, "8r4r5ddzzn.Messages");
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
-       }
        noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
        if (noti_err != NOTIFICATION_ERROR_NONE) {
                MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
        }
 
-       noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NOTI_MSG_ICON_PATH);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
+       if (pMsg->msgType.subType == MSG_DELIVERYIND_MMS) { // MMS delivery report
+
+               noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
+               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                       MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
+               }
+
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "New message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Delivery Report", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+       } else if (pMsg->msgType.subType == MSG_READORGIND_MMS) {  // MMS read report
+
+               noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
+               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                       MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
+               }
+
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "New message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "Read Report", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
        }
 
        if (displayName[0] == '\0')
@@ -479,9 +541,10 @@ msg_error_t MsgInsertMmsReportToNoti(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S
        else
                notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
 
-       // set time.
-//     notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, msgTime);
-
+       // set launch type
+       noti_err = notification_set_property(noti, NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
+       if (noti_err != NOTIFICATION_ERROR_NONE)
+               MSG_DEBUG("Fail to notification_set_display_applist");
 
        if (pMsg->msgType.subType == MSG_DELIVERYIND_MMS) {
 
@@ -495,47 +558,60 @@ msg_error_t MsgInsertMmsReportToNoti(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S
                        return MSG_ERR_UNKNOWN;
 
                case MSG_DELIVERY_REPORT_EXPIRED:
-                       snprintf(contents, MAX_DISPLAY_NAME_LEN, "Expired.");
+                       MSG_DEBUG("Message expired.");
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message expired", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message expired", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
                        break;
 
                case MSG_DELIVERY_REPORT_REJECTED:
-                       snprintf(contents, MAX_DISPLAY_NAME_LEN, "Rejected.");
+                       MSG_DEBUG("Message rejected.");
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message rejected", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message rejected", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
                        break;
 
                case MSG_DELIVERY_REPORT_DEFERRED:
-                       snprintf(contents, MAX_DISPLAY_NAME_LEN, "Deferred.");
+                       MSG_DEBUG("Message deferred.");
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message deferred", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message deferred", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
                        break;
 
                case MSG_DELIVERY_REPORT_UNRECOGNISED:
-                       snprintf(contents, MAX_DISPLAY_NAME_LEN, "Unrecognised.");
+                       MSG_DEBUG("Message unrecognised.");
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message unrecognised", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message unrecognised", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
                        break;
 
                case MSG_DELIVERY_REPORT_INDETERMINATE:
-                       snprintf(contents, MAX_DISPLAY_NAME_LEN, "Indeterminate.");
+                       MSG_DEBUG("Message indeterminate.");
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message indeterminate", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message indeterminate", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
                        break;
 
                case MSG_DELIVERY_REPORT_FORWARDED:
-                       snprintf(contents, MAX_DISPLAY_NAME_LEN, "Forwarded.");
+                       MSG_DEBUG("Message forwarded.");
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message forwarded", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message forwarded", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
                        break;
 
                case MSG_DELIVERY_REPORT_UNREACHABLE:
-                       snprintf(contents, MAX_DISPLAY_NAME_LEN, "Unreachable.");
+                       MSG_DEBUG("Message unreachable.");
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message unreachable", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message unreachable", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
                        break;
 
                case MSG_DELIVERY_REPORT_ERROR:
-                       snprintf(contents, MAX_DISPLAY_NAME_LEN, "Error.");
+                       MSG_DEBUG("Message error.");
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message error", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message error", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
                        break;
 
                default :
-                       snprintf(contents, MAX_DISPLAY_NAME_LEN, "Delivered.");
+                       MSG_DEBUG("Message delivered.");
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message delivered", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, "Message delivered", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
                        break;
                }
 
-               MSG_DEBUG("content text : %s", contents);
-
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, contents, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, contents, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
                noti_err = notification_insert(noti, NULL);
                if (noti_err != NOTIFICATION_ERROR_NONE)
                        MSG_DEBUG("Fail to notification_insert");
@@ -551,17 +627,21 @@ msg_error_t MsgInsertMmsReportToNoti(MsgDbHandler *pDbHandle, MSG_MESSAGE_INFO_S
                        return MSG_ERR_UNKNOWN;
 
                case MSG_READ_REPORT_IS_DELETED:
-                       snprintf(contents, MAX_DISPLAY_NAME_LEN, "Deleted.");
+                       MSG_DEBUG("Message deleted.");
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message deleted", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
                        break;
 
                default :
-                       snprintf(contents, MAX_DISPLAY_NAME_LEN, "Read.");
+                       MSG_DEBUG("Message read.");
+                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, "Message read", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
                        break;
                }
 
-               MSG_DEBUG("content text : %s", contents);
+               // set time.
+               notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, pMsg->displayTime);
 
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, contents, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+               // set led.
+               notification_set_led(noti, NOTIFICATION_LED_OP_ON, 0x00);
 
                noti_err = notification_insert(noti, NULL);
                if (noti_err != NOTIFICATION_ERROR_NONE) {
@@ -596,7 +676,8 @@ msg_error_t MsgRefreshNoti(bool bWithTicker)
 
        notification_h noti = NULL;
        notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
-       bundle* args;
+       bundle* args = NULL;
+       bundle* reply = NULL;
 
        int contactId = 0;
        msg_thread_id_t threadId = 0;
@@ -616,10 +697,12 @@ msg_error_t MsgRefreshNoti(bool bWithTicker)
        memset(thumbPath, 0x00, sizeof(thumbPath));
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, \
-                       B.DISPLAY_TIME, A.CONTACT_ID, A.IMAGE_PATH, B.MSG_ID, B.MSG_TEXT, B.SUBJECT, B.MAIN_TYPE \
-                       FROM %s A, %s B WHERE A.CONV_ID=B.CONV_ID AND B.READ_STATUS=0 AND B.FOLDER_ID=%d ORDER BY B.DISPLAY_TIME DESC;",
-                       MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID);
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, "
+                       "B.DISPLAY_TIME, A.CONTACT_ID, A.IMAGE_PATH, B.MSG_ID, B.MSG_TEXT, B.SUBJECT, B.MAIN_TYPE "
+                       "FROM %s A, %s B WHERE A.CONV_ID=B.CONV_ID AND B.READ_STATUS=0 AND B.FOLDER_ID=%d AND "
+                       "(B.STORAGE_ID = %d OR B.STORAGE_ID = %d) "
+                       "ORDER BY B.DISPLAY_TIME DESC;",
+                       MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, MSG_INBOX_ID, MSG_STORAGE_PHONE, MSG_STORAGE_SIM);
 
        if (dbhandler.prepareQuery(sqlQuery) != MSG_SUCCESS)
                return MSG_ERR_DB_PREPARE;
@@ -688,7 +771,7 @@ msg_error_t MsgRefreshNoti(bool bWithTicker)
 
                // No unread message.
                if (notiPrivId > 0) {
-                       noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, notiPrivId);
+                       noti_err = notification_delete_by_priv_id("8r4r5ddzzn.Messages", NOTIFICATION_TYPE_NOTI, notiPrivId);
                        if (noti_err != NOTIFICATION_ERROR_NONE) {
                                MSG_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
                        }
@@ -704,11 +787,19 @@ msg_error_t MsgRefreshNoti(bool bWithTicker)
 
        dbhandler.finalizeQuery();
 
-
-       args = bundle_create();
-
-       int unreadMsgCnt = MsgStoGetUnreadCnt(&dbhandler, MSG_SMS_TYPE);
+       int unreadMsgCnt = 0;
+#if 0
+       unreadMsgCnt = MsgStoGetUnreadCnt(&dbhandler, MSG_SMS_TYPE);
        unreadMsgCnt += MsgStoGetUnreadCnt(&dbhandler, MSG_MMS_TYPE);
+#else
+       if (dbhandler.getTable(sqlQuery , &unreadMsgCnt) != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to getTable");
+               dbhandler.freeTable();
+               return MSG_ERR_DB_GETTABLE;
+       }
+
+       dbhandler.freeTable();
+#endif
 
        MSG_DEBUG("notiPrivId [%d], unreadMsgCnt [%d]", notiPrivId, unreadMsgCnt);
 
@@ -722,21 +813,28 @@ msg_error_t MsgRefreshNoti(bool bWithTicker)
                noti = notification_create(NOTIFICATION_TYPE_NOTI);
                if (noti == NULL) {
                        MSG_DEBUG("notification_new is failed.");
-                       bundle_free(args);
                        return MSG_ERR_UNKNOWN;
                }
 
                notiPrivId = 0;
        }
-       noti_err = notification_set_application(noti, "8r4r5ddzzn.Messages");
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
-       }
-       noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
+
+       // set pkg name.
+       noti_err = notification_set_pkgname(noti, "8r4r5ddzzn.Messages");
        if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
+               MSG_DEBUG("Fail to notification_set_pkgname : %d", noti_err);
        }
 
+       // create bundle
+       args = bundle_create();
+
+       appsvc_set_appid(args, "8r4r5ddzzn.Messages");
+
+       // Set bundle values
+       memset(&tempId, 0x00, sizeof(tempId));
+       bundle_add(args, "type", "new_msg");
+       snprintf(tempId, 5, "%d", msg.msgId);
+       bundle_add(args, "msgId", tempId);
 
        if (unreadMsgCnt > 1) {
 
@@ -745,31 +843,23 @@ msg_error_t MsgRefreshNoti(bool bWithTicker)
                        MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
                }
 
-               noti_err = notification_set_text_domain(noti, MSG_SYS_PACKAGE_NAME, MSG_SYS_LOCALEDIR);
+               noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
                if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_text_domain.");
+                       MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
                }
 
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Message", MESSAGE, NOTIFICATION_VARIABLE_TYPE_NONE);
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
 
                char unreadMsgCntStr[5] = {0,};
                snprintf(unreadMsgCntStr, 5, "%d", unreadMsgCnt);
                notification_set_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadMsgCntStr, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
 
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Messages", NEW_MESSAGES, NOTIFICATION_VARIABLE_TYPE_NONE);
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Messages", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
 
-               if (displayName[0] == '\0')
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-               else
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+               // set execute option
+               notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH, NULL, NULL, args);
 
-               if (msg.msgType.mainType == MSG_SMS_TYPE)
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2,msg.msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-               else
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, msg.subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-
-               // set time.
-               notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, msgTime);
+               notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_RESPONDING, NULL, NULL, NULL);
 
        } else {
 
@@ -778,68 +868,322 @@ msg_error_t MsgRefreshNoti(bool bWithTicker)
                        MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
                }
 
-               noti_err = notification_set_text_domain(noti, MSG_SYS_PACKAGE_NAME, MSG_SYS_LOCALEDIR);
+               noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
                if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_text_domain.");
+                       MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
                }
 
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Message", MESSAGE, NOTIFICATION_VARIABLE_TYPE_NONE);
+               noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, NORMAL_MSG_ICON_PATH);
+               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                       MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
+               }
 
-               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Message", NEW_MESSAGE, NOTIFICATION_VARIABLE_TYPE_NONE);
+               noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, NORMAL_MSG_ICON_PATH);
+               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                       MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
+               }
 
-               if (displayName[0] == '\0')
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-               else
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
 
-               if (msg.msgType.mainType == MSG_SMS_TYPE)
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2,msg.msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
-               else
-                       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, msg.subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
 
-               // set time.
-               notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, msgTime);
+               // set execute option
+               notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, args);
+
+               // Set responding option
+               reply = bundle_create();
+               appsvc_set_appid(reply, "8r4r5ddzzn.Messages");
+
+               bundle_add(reply, "type", "reply");
+               bundle_add(reply, "show_list", "list_show");
 
+               memset(&tempId, 0x00, sizeof(tempId));
+               snprintf(tempId, 5, "%d", msg.msgId);
+               bundle_add(reply, "msgId", tempId);
+
+               notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_RESPONDING, NULL, NULL, reply);
        }
-       {
-               if (bWithTicker)
-                       noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_ALL);
-               else
-                       noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_TICKER);
 
+
+       if (displayName[0] == '\0')
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+       else
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+       if (msg.msgType.mainType == MSG_SMS_TYPE)
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2,msg.msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+       else
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, msg.subject, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+       // set time.
+       notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, msgTime);
+
+       // set led.
+       notification_set_led(noti, NOTIFICATION_LED_OP_ON, 0x00);
+
+       notification_set_property(noti, NOTIFICATION_PROP_DISABLE_AUTO_DELETE);
+
+       if (bWithTicker)
+               noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_ALL);
+       else
+               noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_TICKER);
+
+       if (noti_err != NOTIFICATION_ERROR_NONE) {
+               MSG_DEBUG("Fail to notification_set_display_applist : %d", noti_err);
+       }
+
+       if (notiPrivId > 0) {
+               noti_err = notification_update(noti);
                if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_display_applist : %d", noti_err);
+                       MSG_DEBUG("Fail to notification_update");
                }
+       } else {
+               noti_err = notification_insert(noti, &notiPrivId);
+               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                       MSG_DEBUG("Fail to notification_insert");
+               }
+
+               if (MsgSettingSetInt(NOTIFICATION_PRIV_ID, notiPrivId) != MSG_SUCCESS)
+                       MSG_DEBUG("MsgSettingSetInt fail: NOTIFICATION_PRIV_ID");
+               MSG_DEBUG("Insert notiPrivId [%d]", notiPrivId);
        }
 
-       memset(&tempId, 0x00, sizeof(tempId));
+       noti_err = notification_free(noti);
+       if (noti_err != NOTIFICATION_ERROR_NONE) {
+               MSG_DEBUG("Fail to notification_free");
+       }
+
+       if (args != NULL) {
+               bundle_free(args);
+       }
 
-       bundle_add(args, "type", "msg_id");
+       if (reply != NULL) {
+               bundle_free(reply);
+       }
 
-       snprintf(tempId, 5, "%d", msg.msgId);
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgRefreshCBNoti(bool bWithTicker)
+{
+       MsgDbHandler dbhandler;
+
+       int notiCbId = MsgSettingGetInt(CB_NOTI_PRIV_ID);
+
+       notification_h noti = NULL;
+       notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+       bundle* args = NULL;
+
+       int contactId = 0;
+       msg_thread_id_t threadId = 0;
+       msg_message_id_t msgId = 0;
+       time_t msgTime = 0;
+       char tempId[6];
+       char addressVal[MAX_ADDRESS_VAL_LEN+1];
+       char firstName[MAX_DISPLAY_NAME_LEN+1], lastName[MAX_DISPLAY_NAME_LEN+1];
+       char displayName[MAX_DISPLAY_NAME_LEN+1];
+       char thumbPath[MAX_IMAGE_PATH_LEN+1];
+       char msgText[MAX_MSG_TEXT_LEN+1];
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       memset(tempId, 0x00, sizeof(tempId));
+       memset(addressVal, 0x00, sizeof(addressVal));
+       memset(firstName, 0x00, sizeof(firstName));
+       memset(lastName, 0x00, sizeof(lastName));
+       memset(displayName, 0x00, sizeof(displayName));
+       memset(thumbPath, 0x00, sizeof(thumbPath));
+       memset(msgText, 0x00, sizeof(msgText));
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT A.CONV_ID, A.ADDRESS_VAL, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, "
+                       "B.DISPLAY_TIME, A.CONTACT_ID, A.IMAGE_PATH, B.MSG_ID, B.MSG_TEXT "
+                       "FROM %s A, %s B WHERE A.CONV_ID=B.CONV_ID AND B.READ_STATUS=0 AND B.FOLDER_ID=%d AND B.STORAGE_ID = %d "
+                       "ORDER BY B.DISPLAY_TIME DESC;",
+                       MSGFW_ADDRESS_TABLE_NAME, MSGFW_MESSAGE_TABLE_NAME, MSG_CBMSGBOX_ID, MSG_STORAGE_PHONE);
+
+       if (dbhandler.prepareQuery(sqlQuery) != MSG_SUCCESS)
+               return MSG_ERR_DB_PREPARE;
+
+       if (dbhandler.stepQuery() == MSG_ERR_DB_ROW) {
+               threadId = dbhandler.columnInt(0);
+
+               if (dbhandler.columnText(1) != NULL)
+                       strncpy(addressVal, (char*)dbhandler.columnText(1), MAX_ADDRESS_VAL_LEN);
+
+
+               char *pTempDisplayName = (char *)dbhandler.columnText(2);
+               if (pTempDisplayName != NULL && pTempDisplayName[0] != '\0') {
+                       strncpy(displayName, pTempDisplayName, MAX_DISPLAY_NAME_LEN);
+               } else {
+                       if (dbhandler.columnText(3) != NULL)
+                               strncpy(firstName, (char*)dbhandler.columnText(3), MAX_DISPLAY_NAME_LEN);
+
+                       if (dbhandler.columnText(4) != NULL)
+                               strncpy(lastName, (char*)dbhandler.columnText(4), MAX_DISPLAY_NAME_LEN);
+
+                       int order = MsgGetContactNameOrder();
+
+                       if (order == 0) {
+                               if (firstName[0] != '\0') {
+                                       strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
+                               }
+
+                               if (lastName[0] != '\0') {
+                                       strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
+                                       strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
+                               }
+                       } else if (order == 1) {
+                               if (lastName[0] != '\0') {
+                                       strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
+                                       strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
+                               }
+
+                               if (firstName[0] != '\0') {
+                                       strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
+                               }
+                       }
+               }
+
+               msgTime = (time_t)dbhandler.columnInt(5);
+
+               contactId = dbhandler.columnInt(6);
+
+               strncpy(thumbPath, (char*)dbhandler.columnText(7), MAX_IMAGE_PATH_LEN);
+
+               msgId = dbhandler.columnInt(8);
+
+               strncpy(msgText, (char*)dbhandler.columnText(9), MAX_MSG_TEXT_LEN);
+
+               MSG_DEBUG("unread CB message [%d].", msgId);
+       } else {
+
+               MSG_DEBUG("No unread CB message.");
+               MSG_DEBUG("notiCbId [%d]", notiCbId);
+
+               dbhandler.finalizeQuery();
+
+               // No unread message.
+               if (notiCbId > 0) {
+                       noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, notiCbId);
+                       if (noti_err != NOTIFICATION_ERROR_NONE) {
+                               MSG_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
+                       }
+               }
+
+               notiCbId = 0;
+
+               if(MsgSettingSetInt(CB_NOTI_PRIV_ID, notiCbId) != MSG_SUCCESS)
+                       MSG_DEBUG("MsgSettingSetInt fail : CB_NOTI_PRIV_ID");
+
+               return MSG_ERR_DB_STEP;
+       }
+
+       dbhandler.finalizeQuery();
+
+       int unreadCbMsgCnt = 0;
+
+       if (dbhandler.getTable(sqlQuery, &unreadCbMsgCnt) != MSG_SUCCESS) {
+               MSG_DEBUG("getTable is failed");
+               dbhandler.freeTable();
+               return MSG_ERR_DB_GETTABLE;
+       }
+
+       MSG_DEBUG("notiCbId [%d], unreadCbMsgCnt [%d]", notiCbId, unreadCbMsgCnt);
+
+       if (notiCbId > 0) {
+               noti = notification_load(NULL, notiCbId);
+               if (noti == NULL)
+                       MSG_DEBUG("notification_load is failed.");
+       }
+
+       if (noti == NULL) {
+               noti = notification_create(NOTIFICATION_TYPE_NOTI);
+               if (noti == NULL) {
+                       MSG_DEBUG("notification_new is failed.");
+                       return MSG_ERR_UNKNOWN;
+               }
+               notiCbId = 0;
+       }
+
+       args = bundle_create();
+
+       appsvc_set_appid(args, "8r4r5ddzzn.Messages");
+
+       // Set bundle values
+       memset(&tempId, 0x00, sizeof(tempId));
+       bundle_add(args, "type", "new_msg");
+       snprintf(tempId, 5, "%d", msgId);
        bundle_add(args, "msgId", tempId);
 
-       if (args != NULL) {
-               noti_err = notification_set_args(noti, args, NULL);
+       if (unreadCbMsgCnt > 1) {
+               noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE);
                if (noti_err != NOTIFICATION_ERROR_NONE) {
-                       MSG_DEBUG("Fail to notification_set_args : %d", noti_err);
+                       MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
+               }
+
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Broadcast message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Messages", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+               char unreadCbMsgCntStr[5] = {0,};
+               snprintf(unreadCbMsgCntStr, 5, "%d", unreadCbMsgCnt);
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_EVENT_COUNT, unreadCbMsgCntStr, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+               notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_MULTI_LAUNCH, NULL, NULL, args);
+       } else {
+               noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
+               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                       MSG_DEBUG("Fail to notification_set_layout : %d", noti_err);
                }
+
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, "Broadcast message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT, "New Message", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+               notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, args);
        }
 
-       if (notiPrivId > 0) {
+
+       if (displayName[0] == '\0')
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, addressVal, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+       else
+               notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_1, displayName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+       notification_set_text(noti, NOTIFICATION_TEXT_TYPE_INFO_2, msgText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+
+       // set time.
+       notification_set_time_to_text(noti, NOTIFICATION_TEXT_TYPE_INFO_SUB_1, msgTime);
+
+       // set icon image
+       notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
+
+       // set led.
+       notification_set_led(noti, NOTIFICATION_LED_OP_ON, 0x00);
+
+       if (bWithTicker)
+               noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_ALL^NOTIFICATION_DISPLAY_APP_LOCK);
+       else
+               noti_err = notification_set_display_applist(noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY|NOTIFICATION_DISPLAY_APP_INDICATOR);
+
+       if (noti_err != NOTIFICATION_ERROR_NONE) {
+               MSG_DEBUG("Fail to notification_set_display_applist : %d", noti_err);
+       }
+
+       if (notiCbId > 0) {
                noti_err = notification_update(noti);
                if (noti_err != NOTIFICATION_ERROR_NONE) {
                        MSG_DEBUG("Fail to notification_update");
                }
        } else {
-               noti_err = notification_insert(noti, &notiPrivId);
+               noti_err = notification_insert(noti, &notiCbId);
                if (noti_err != NOTIFICATION_ERROR_NONE) {
                        MSG_DEBUG("Fail to notification_insert");
                }
 
-               if (MsgSettingSetInt(NOTIFICATION_PRIV_ID, notiPrivId) != MSG_SUCCESS)
-                       MSG_DEBUG("MsgSettingSetInt fail: NOTIFICATION_PRIV_ID");
-               MSG_DEBUG("Insert notiPrivId [%d]", notiPrivId);
+               if (MsgSettingSetInt(CB_NOTI_PRIV_ID, notiCbId) != MSG_SUCCESS)
+                       MSG_DEBUG("MsgSettingSetInt fail: CB_NOTI_PRIV_ID");
+               MSG_DEBUG("Insert notiCbId [%d]", notiCbId);
        }
 
        noti_err = notification_free(noti);
@@ -847,25 +1191,32 @@ msg_error_t MsgRefreshNoti(bool bWithTicker)
                MSG_DEBUG("Fail to notification_free");
        }
 
-       bundle_free(args);
+       if (args != NULL) {
+               bundle_free(args);
+       }
 
        return MSG_SUCCESS;
 }
 
+
 msg_error_t MsgCleanAndResetNoti()
 {
        msg_error_t err = MSG_SUCCESS;
        notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
 
-       noti_err = notification_delete_all_by_type("/usr/bin/msg-server", NOTIFICATION_TYPE_NOTI);
+       noti_err = notification_delete_all_by_type("8r4r5ddzzn.Messages", NOTIFICATION_TYPE_NOTI);
        if (noti_err != NOTIFICATION_ERROR_NONE) {
                MSG_DEBUG("Fail to notification_delete_all_by_type noti_err [%d]", noti_err);
-               return MSG_ERR_UNKNOWN;
        }
 
        err = MsgRefreshNoti(false);
        if (err != MSG_SUCCESS) {
-                       MSG_DEBUG("Fail to MsgRefreshNoti");
+               MSG_DEBUG("Fail to MsgRefreshNoti : [err=%d]", err);
+       }
+
+       err = MsgRefreshCBNoti(false);
+       if (err != MSG_SUCCESS) {
+               MSG_DEBUG("Fail to MsgRefreshCBNoti : [err=%d]", err);
        }
 
        return err;
@@ -874,10 +1225,6 @@ msg_error_t MsgCleanAndResetNoti()
 
 msg_error_t MsgInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg)
 {
-
-       MSG_DEBUG("pTickerMsg [%s]", pTickerMsg);
-       MSG_DEBUG("pLocaleTickerMsg [%s]", pLocaleTickerMsg);
-
        notification_h noti = NULL;
        notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
 
@@ -887,21 +1234,11 @@ msg_error_t MsgInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg
                return MSG_ERR_UNKNOWN;
        }
 
-       noti_err = notification_set_application(noti, "8r4r5ddzzn.Messages");
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_application : %d", noti_err);
-       }
-
        noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, NORMAL_MSG_ICON_PATH);
        if (noti_err != NOTIFICATION_ERROR_NONE) {
                MSG_DEBUG("Fail to notification_set_image : %d", noti_err);
        }
 
-       noti_err = notification_set_text_domain(noti, MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR);
-       if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_text_domain.");
-       }
-
        noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE, pTickerMsg, pLocaleTickerMsg, NOTIFICATION_VARIABLE_TYPE_NONE);
        if (noti_err != NOTIFICATION_ERROR_NONE) {
                MSG_DEBUG("Fail to notification_set_text : %d", noti_err);
@@ -917,19 +1254,62 @@ msg_error_t MsgInsertTicker(const char* pTickerMsg, const char* pLocaleTickerMsg
                MSG_DEBUG("Fail to notification_set_display_applist : %d", noti_err);
        }
 
+       noti_err = notification_set_property(noti, NOTIFICATION_PROP_DISABLE_APP_LAUNCH);
+       if (noti_err != NOTIFICATION_ERROR_NONE)
+               MSG_DEBUG("Fail to notification_set_display_applist");
+
        noti_err = notification_insert(noti, NULL);
        if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_text_domain");
+               MSG_DEBUG("Fail to notification_insert");
        }
 
        noti_err = notification_free(noti);
        if (noti_err != NOTIFICATION_ERROR_NONE) {
-               MSG_DEBUG("Fail to notification_set_text_domain");
+               MSG_DEBUG("Fail to notification_free");
        }
 
        return MSG_SUCCESS;
 }
+
+
 msg_error_t MsgInsertBadge(unsigned int unreadMsgCnt)
 {
        return MSG_SUCCESS;
 }
+
+
+msg_error_t MsgClearVoiceNoti(MSG_SUB_TYPE_T subType)
+{
+       MSG_BEGIN();
+
+       msg_error_t err = MSG_SUCCESS;
+       int notiId = 0;
+       notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
+
+       if (subType == MSG_MWI_VOICE_SMS) {
+               notiId = MsgSettingGetInt(VOICE_NOTI_ID_1);
+       } else {
+               return MSG_ERR_UNKNOWN;
+       }
+
+       if (notiId>0) {
+               noti_err = notification_delete_by_priv_id(NULL, NOTIFICATION_TYPE_NOTI, notiId);
+               if (noti_err != NOTIFICATION_ERROR_NONE) {
+                       MSG_DEBUG("Fail to notification_delete_by_priv_id : %d", noti_err);
+                       err = MSG_ERR_UNKNOWN;
+               }
+       }
+
+       notiId = 0;
+
+       if (subType == MSG_MWI_VOICE_SMS) {
+               if (MsgSettingSetInt(VOICE_NOTI_ID_1, notiId) == MSG_SUCCESS)
+                       MSG_DEBUG("Insert VOICE_NOTI_ID_1 [%d]", notiId);
+               else
+                       MSG_DEBUG("MsgSettingSetInt fail: VOICE_NOTI_ID_1");
+       }
+
+       MSG_END();
+
+       return err;
+}
index 889deeb..96bea63 100755 (executable)
@@ -199,10 +199,14 @@ bool MsgSoundCreateRepeatAlarm(int RepeatTime)
 
        target_time.sec = current_tm.tm_sec;
 
-       alarmmgr_set_time(alarm_info, target_time);
-       alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, 0);
-       alarmmgr_set_type(alarm_info, ALARM_TYPE_VOLATILE);
-       alarmmgr_add_alarm_with_localtime(alarm_info, NULL, &g_alarmId);
+       retval = alarmmgr_set_time(alarm_info, target_time);
+       MSG_DEBUG("alarmmgr_set_time return = [%d]", retval);
+       retval = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, 0);
+       MSG_DEBUG("alarmmgr_set_repeat_mode return = [%d]", retval);
+       retval = alarmmgr_set_type(alarm_info, ALARM_TYPE_VOLATILE);
+       MSG_DEBUG("alarmmgr_set_type return = [%d]", retval);
+       retval = alarmmgr_add_alarm_with_localtime(alarm_info, NULL, &g_alarmId);
+       MSG_DEBUG("alarmmgr_add_alarm_with_localtime return = [%d]", retval);
 
        retval = alarmmgr_set_cb(MsgSoundRepeatAlarmCB, (void *)alarm_info);
 
index 9a58a10..68734f9 100755 (executable)
@@ -42,22 +42,12 @@ __thread sqlite3_stmt *stmt = NULL;
 ==================================================================================================*/
 MsgDbHandler::MsgDbHandler()
 {
-       handle = NULL;
-       stmt = NULL;
        result = NULL;
 }
 
 
 MsgDbHandler::~MsgDbHandler()
 {
-       if(handle != NULL) {
-               if (disconnect() != MSG_SUCCESS)
-                       MSG_DEBUG("disconnect is failed!!");
-       }
-
-       if(stmt != NULL)
-               finalizeQuery();
-
        if(result != NULL)
                freeTable();
 }
@@ -472,3 +462,36 @@ void MsgReleaseMemoryDB()
        MSG_DEBUG("freed memory size (bytes) : [%d]", freeSize);
 }
 
+
+msg_error_t MsgConvertStrWithEscape(const char *input, char **output)
+{
+       if (input == NULL || output == NULL || strlen(input) == 0) {
+               MSG_DEBUG("MSG_ERR_INVALID_PARAMETER");
+               return MSG_ERR_INVALID_PARAMETER;
+       }
+
+       int inputSize = 0;
+       int i = 0;
+       int j = 0;
+
+       inputSize = strlen(input);
+       MSG_DEBUG("Size of input string [%d]", inputSize);
+
+       char tmpStr[(inputSize*2)+3];
+       memset(tmpStr, 0x00, sizeof(tmpStr));
+
+       tmpStr[j++] = '%';
+
+       for(i=0;i<inputSize;i++) {
+               if (input[i] == '\'' || input[i] == '_' || input[i] == '%' || input[i] == '\\') {
+                       tmpStr[j++] = MSGFW_DB_ESCAPE_CHAR;
+               }
+               tmpStr[j++] = input[i];
+       }
+       tmpStr[j++] = '%';
+       tmpStr[j] = '\0';
+
+       *output = strdup(tmpStr);
+
+       return MSG_SUCCESS;
+}
index 2de1578..b4034aa 100755 (executable)
@@ -374,7 +374,7 @@ msg_error_t MsgStoAddAddress(MsgDbHandler *pDbHandle, const MSG_MESSAGE_INFO_S *
 
                // Add Address
                memset(sqlQuery, 0x00, sizeof(sqlQuery));
-               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, '%s', %d, '', ?, ?, '%s', 0);",
+               snprintf(sqlQuery, sizeof(sqlQuery), "INSERT INTO %s VALUES (%d, %d, %d, %d, '%s', %d, ?, ?, ?, '%s', 0);",
                                        MSGFW_ADDRESS_TABLE_NAME, addrId, *pConvId, pMsg->addressList[i].addressType, pMsg->addressList[i].recipientType, pMsg->addressList[i].addressVal,
                                        contactInfo.contactId, contactInfo.imagePath);
 
@@ -383,8 +383,9 @@ msg_error_t MsgStoAddAddress(MsgDbHandler *pDbHandle, const MSG_MESSAGE_INFO_S *
                if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS)
                        return MSG_ERR_DB_PREPARE;
 
-               pDbHandle->bindText(contactInfo.firstName, 1);
-               pDbHandle->bindText(contactInfo.lastName, 2);
+               pDbHandle->bindText(contactInfo.displayName, 1);
+               pDbHandle->bindText(contactInfo.firstName, 2);
+               pDbHandle->bindText(contactInfo.lastName, 3);
 
                if (pDbHandle->stepQuery() != MSG_ERR_DB_DONE) {
                        pDbHandle->finalizeQuery();
@@ -611,8 +612,7 @@ msg_error_t MsgStoGetAddressByConvId(MsgDbHandler *pDbHandle, msg_thread_id_t co
                pAddr->contactId = pDbHandle->getColumnToInt(index++);
                pDbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, pAddr->addressVal);
                pDbHandle->getColumnToString(index++, MAX_DISPLAY_NAME_LEN, pAddr->displayName);
-               if(!strlen(pAddr->displayName))
-               {
+               if(!strlen(pAddr->displayName)) {
                        pDbHandle->getColumnToString(index++,MAX_DISPLAY_NAME_LEN, firstName);
                        pDbHandle->getColumnToString(index++,MAX_DISPLAY_NAME_LEN, lastName);
 
@@ -635,6 +635,9 @@ msg_error_t MsgStoGetAddressByConvId(MsgDbHandler *pDbHandle, msg_thread_id_t co
                                        strncat(pAddr->displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(pAddr->displayName));
                                }
                        }
+               } else {
+                       index++; // firstname
+                       index++; // lastname
                }
 
        }
@@ -981,9 +984,13 @@ msg_error_t MsgStoAddContactInfo(MsgDbHandler *pDbHandle, MSG_CONTACT_INFO_S *pC
        char sqlQuery[MAX_QUERY_LEN+1];
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET \
-                       CONTACT_ID = %d, FIRST_NAME = ?, LAST_NAME = ?, IMAGE_PATH = '%s' \
-                       WHERE ADDRESS_VAL = '%s';",
+       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET "
+                       "CONTACT_ID = %d, "
+                       "DISPLAY_NAME = ?, "
+                       "FIRST_NAME = ?, "
+                       "LAST_NAME = ?, "
+                       "IMAGE_PATH = '%s' "
+                       "WHERE ADDRESS_VAL = '%s';",
                        MSGFW_ADDRESS_TABLE_NAME, pContactInfo->contactId, pContactInfo->imagePath, pNumber);
 
        if (pDbHandle->prepareQuery(sqlQuery) != MSG_SUCCESS) {
@@ -991,9 +998,9 @@ msg_error_t MsgStoAddContactInfo(MsgDbHandler *pDbHandle, MSG_CONTACT_INFO_S *pC
                return MSG_ERR_DB_PREPARE;
        }
 
-       pDbHandle->bindText(pContactInfo->firstName, 1);
-
-       pDbHandle->bindText(pContactInfo->lastName, 2);
+       pDbHandle->bindText(pContactInfo->displayName, 1);
+       pDbHandle->bindText(pContactInfo->firstName, 2);
+       pDbHandle->bindText(pContactInfo->lastName, 3);
 
        if (pDbHandle->stepQuery() != MSG_ERR_DB_DONE) {
                pDbHandle->finalizeQuery();
@@ -1007,16 +1014,17 @@ msg_error_t MsgStoAddContactInfo(MsgDbHandler *pDbHandle, MSG_CONTACT_INFO_S *pC
 }
 
 
-msg_error_t MsgStoClearContactInfo(MsgDbHandler *pDbHandle, int contactId)
+msg_error_t MsgStoResetContactInfo(MsgDbHandler *pDbHandle, int contactId)
 {
        msg_error_t err = MSG_SUCCESS;
 
        char sqlQuery[MAX_QUERY_LEN+1];
        int rowCnt = 0;
+       int index = 2;
 
        memset(sqlQuery, 0x00, sizeof(sqlQuery));
 
-       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT DISTINCT(CONV_ID) FROM %s WHERE CONTACT_ID = %d;",
+       snprintf(sqlQuery, sizeof(sqlQuery), "SELECT ADDRESS_VAL, CONV_ID FROM %s WHERE CONTACT_ID = %d;",
                        MSGFW_ADDRESS_TABLE_NAME, contactId);
 
        err = pDbHandle->getTable(sqlQuery, &rowCnt);
@@ -1027,20 +1035,21 @@ msg_error_t MsgStoClearContactInfo(MsgDbHandler *pDbHandle, int contactId)
                return err;
        }
 
-       memset(sqlQuery, 0x00, sizeof(sqlQuery));
-       snprintf(sqlQuery, sizeof(sqlQuery), "UPDATE %s SET \
-                       CONTACT_ID = 0, DISPLAY_NAME = '', FIRST_NAME = '', LAST_NAME = '', IMAGE_PATH = '' \
-                       WHERE CONTACT_ID = %d;",
-                       MSGFW_ADDRESS_TABLE_NAME, contactId);
+       MsgDbHandler tmpDbHandle;
+       for (int i=0; i<rowCnt; i++) {
 
-       if (pDbHandle->execQuery(sqlQuery) != MSG_SUCCESS) {
-               MSG_DEBUG("Fail to execute query");
-               return MSG_ERR_DB_EXEC;
-       }
+               MSG_CONTACT_INFO_S contactInfo;
+               memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
+               MSG_ADDRESS_INFO_S addrInfo;
+               memset(&addrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
 
-       MsgDbHandler tmpDbHandle;
-       for (int i=1; i<=rowCnt; i++)
-               MsgStoSetConversationDisplayName(&tmpDbHandle, (msg_thread_id_t)pDbHandle->getColumnToInt(i));
+               pDbHandle->getColumnToString(index++, MAX_ADDRESS_VAL_LEN, addrInfo.addressVal);
+
+               MsgGetContactInfo(&addrInfo, &contactInfo);
+               MsgStoAddContactInfo(&tmpDbHandle, &contactInfo, addrInfo.addressVal);
+
+               MsgStoSetConversationDisplayName(&tmpDbHandle, (msg_thread_id_t)pDbHandle->getColumnToInt(index++));
+       }
 
        pDbHandle->freeTable();
 
@@ -1404,3 +1413,35 @@ char *MsgStoReplaceString(const char *origStr, const char *oldStr, const char *n
 
        return replaceStr;
 }
+
+
+msg_error_t MsgStoRefreshConversationDisplayName()
+{
+       msg_error_t err = MSG_SUCCESS;
+       MsgDbHandler dbHandle;
+       int rowCnt = 0;
+       char displayName[MAX_DISPLAY_NAME_LEN+1];
+       char sqlQuery[MAX_QUERY_LEN+1];
+
+       memset(sqlQuery, 0x00, sizeof(sqlQuery));
+       snprintf(sqlQuery, sizeof(sqlQuery),
+                       "SELECT DISTINCT(CONTACT_ID) FROM %s;",
+                       MSGFW_ADDRESS_TABLE_NAME);
+
+       err = dbHandle.getTable(sqlQuery, &rowCnt);
+
+       if (err != MSG_SUCCESS && err != MSG_ERR_DB_NORECORD) {
+               dbHandle.freeTable();
+               MSG_DEBUG("Query Failed [%s]", sqlQuery);
+               return err;
+       }
+
+       for (int i = 1; i <= rowCnt; i++)
+       {
+               MsgUpdateContact(dbHandle.getColumnToInt(i), -1);
+       }
+
+       dbHandle.freeTable();
+
+       return err;
+}
index d6cab9d..a6f1892 100755 (executable)
@@ -600,10 +600,10 @@ __VCardGetParamVal( char* pVCardRaw, int* pStatus, int* pDLen )
 
        pBuf = (char *)malloc(len);
        if(len < 1 || (pBuf  == NULL)) {
-               if (pBuf) {
-                       free(pBuf);
-                       pBuf = NULL;
-               }
+//             if (pBuf) {
+//                     free(pBuf);
+//                     pBuf = NULL;
+//             }
 
                return NULL;
        }
@@ -904,6 +904,7 @@ vcard_decode( char *pCardRaw )
                                                if(start_status == 1) {
                                                        goto CATCH;
                                                }
+
                                                if ( ( pVCard = ( VTree* )malloc( sizeof( VTree ) ) ) == NULL ) {
                                                        start_status = 1;
                                                        goto CATCH;