SVACE issue fix
[platform/core/messaging/msg-service.git] / utils / MsgVMessage.cpp
index c03c8d7..39ba518 100755 (executable)
@@ -261,8 +261,7 @@ static int __msgsvc_vmsg_append_str(char **buf, int *buf_size, int len, const ch
                                        *r = '\\';
                                        r++;
                                        *r = 'n';
-                               }
-                               else {
+                               } else {
                                        *r = *s;
                                }
                                break;
@@ -272,9 +271,9 @@ static int __msgsvc_vmsg_append_str(char **buf, int *buf_size, int len, const ch
                                str_len++;
                                if (*buf_size < str_len+len+1) {
                                        *buf_size = *buf_size * 2;
-                                       if (NULL == (tmp = (char *)realloc(*buf, *buf_size)))
+                                       if (NULL == (tmp = (char *)realloc(*buf, *buf_size))) {
                                                return -1;
-                                       else {
+                                       else {
                                                int pos_temp = r-(*buf+len);
                                                *buf = tmp;
                                                r = (char *)(*buf+len+pos_temp);
@@ -293,9 +292,9 @@ static int __msgsvc_vmsg_append_str(char **buf, int *buf_size, int len, const ch
                                str_len++;
                                if (*buf_size < str_len+len+1) {
                                        *buf_size = *buf_size * 2;
-                                       if (NULL == (tmp = (char *)realloc(*buf, *buf_size)))
+                                       if (NULL == (tmp = (char *)realloc(*buf, *buf_size))) {
                                                return -1;
-                                       else {
+                                       else {
                                                int pos_temp = r-(*buf+len);
                                                *buf = tmp;
                                                r = (char *)(*buf+len+pos_temp);
@@ -310,9 +309,9 @@ static int __msgsvc_vmsg_append_str(char **buf, int *buf_size, int len, const ch
                                        str_len++;
                                        if (*buf_size < str_len+len+1) {
                                                *buf_size = *buf_size * 2;
-                                               if (NULL == (tmp = (char *)realloc(*buf, *buf_size)))
+                                               if (NULL == (tmp = (char *)realloc(*buf, *buf_size))) {
                                                        return -1;
-                                               else {
+                                               else {
                                                        int pos_temp = r-(*buf+len);
                                                        *buf = tmp;
                                                        r = (char *)(*buf+len+pos_temp);
@@ -324,17 +323,16 @@ static int __msgsvc_vmsg_append_str(char **buf, int *buf_size, int len, const ch
                                        s++;
                                        if (*buf_size < str_len+len+1) {
                                                *buf_size = *buf_size * 2;
-                                               if (NULL == (tmp = (char *)realloc(*buf, *buf_size)))
+                                               if (NULL == (tmp = (char *)realloc(*buf, *buf_size))) {
                                                        return -1;
-                                               else {
+                                               else {
                                                        int pos_temp = r-(*buf+len);
                                                        *buf = tmp;
                                                        r = (char *)(*buf+len+pos_temp);
                                                }
                                        }
                                        *r = *s;
-                               }
-                               else {
+                               } else {
                                        *r = *s;
                                }
                                break;
@@ -345,9 +343,9 @@ static int __msgsvc_vmsg_append_str(char **buf, int *buf_size, int len, const ch
                                        str_len++;
                                        if (*buf_size < str_len+len+1) {
                                                *buf_size = *buf_size * 2;
-                                               if (NULL == (tmp = (char *)realloc(*buf, *buf_size)))
+                                               if (NULL == (tmp = (char *)realloc(*buf, *buf_size))) {
                                                        return -1;
-                                               else {
+                                               else {
                                                        int pos_temp = r-(*buf+len);
                                                        *buf = tmp;
                                                        r = (char *)(*buf+len+pos_temp);
@@ -359,17 +357,16 @@ static int __msgsvc_vmsg_append_str(char **buf, int *buf_size, int len, const ch
                                        s++;
                                        if (*buf_size < str_len+len+1) {
                                                *buf_size = *buf_size * 2;
-                                               if (NULL == (tmp = (char *)realloc(*buf, *buf_size)))
+                                               if (NULL == (tmp = (char *)realloc(*buf, *buf_size))) {
                                                        return -1;
-                                               else {
+                                               else {
                                                        int pos_temp = r-(*buf+len);
                                                        *buf = tmp;
                                                        r = (char *)(*buf+len+pos_temp);
                                                }
                                        }
                                        *r = *s;
-                               }
-                               else {
+                               } else {
                                        *r = *s;
                                }
                                break;
@@ -381,8 +378,7 @@ static int __msgsvc_vmsg_append_str(char **buf, int *buf_size, int len, const ch
                        s++;
                }
                len_temp = str_len;
-       }
-       else {
+       } else {
                len_temp = snprintf(*buf+len, *buf_size-len+1, "%s", safe_str);
        }
        len += len_temp;
@@ -397,7 +393,7 @@ static int __msgsvc_vmsg_append_str(char **buf, int *buf_size, int len, const ch
                                       if ( !pObject )\
 {\
    vmsg_free_vtree_memory(pMessage);\
-   return false;\
+   return NULL;\
 }\
 if (pMessage->pTop == NULL)\
 {\
@@ -414,7 +410,7 @@ pMessage->pCur = pObject;
                                       if ( !pObject )\
 {\
    vmsg_free_vtree_memory(pMessage);\
-   return false;\
+   return NULL;\
 }\
 if (pBody->pTop == NULL)\
 {\
@@ -431,7 +427,7 @@ pBody->pCur = pObject;
                                       if ( !pObject )\
 {\
    vmsg_free_vtree_memory(pMessage);\
-   return false;\
+   return NULL;\
 }\
 if (pCard->pTop == NULL)\
 {\
@@ -453,7 +449,7 @@ pCard->pCur = pObject;
       free(pObject);\
       pObject = NULL;\
    }\
-   return false;\
+   return NULL;\
 }
 
 
@@ -465,13 +461,15 @@ char* _convert_tm_to_vdata_str(const struct tm * tm)
 {
        char str[17] = {0, };
 
-       snprintf(str, 17, "%04d%02d%02dT%02d%02d%02dZ",
+       int wrn = snprintf(str, 17, "%04d%02d%02dT%02d%02d%02dZ",
                tm->tm_year + 1900,
                tm->tm_mon +1,
                tm->tm_mday,
                tm->tm_hour,
                tm->tm_min,
                tm->tm_sec);
+       if(wrn < 0)
+               MSG_DEBUG("snprintf was failed  ");
 
        return strdup(str);
 }
@@ -552,11 +550,12 @@ char* __msgsvc_vmsg_convert_tm_to_vdata_str(struct tm * tm)
        int mon = 0;
        int hour = 0;
        mon = tm->tm_mon + 1;
+       int wrn=0;
 
        if (tm->tm_hour >= 12)
-               strncpy(APM, "PM", 2);
+               strncpy(APM, "PM", 3);
        else
-               strncpy(APM, "AM", 2);
+               strncpy(APM, "AM", 3);
 
        if (tm->tm_hour > 12)
                hour = tm->tm_hour - 12;
@@ -565,53 +564,55 @@ char* __msgsvc_vmsg_convert_tm_to_vdata_str(struct tm * tm)
 
        switch(mon) {
                case 1:
-                       strncpy(month, "Jan", 3);
+                       strncpy(month, "Jan", 4);
                        break;
                case 2:
-                       strncpy(month, "Feb", 3);
+                       strncpy(month, "Feb", 4);
                        break;
                case 3:
-                       strncpy(month, "Mar", 3);
+                       strncpy(month, "Mar", 4);
                        break;
                case 4:
-                       strncpy(month, "Apr", 3);
+                       strncpy(month, "Apr", 4);
                        break;
                case 5:
-                       strncpy(month, "May", 3);
+                       strncpy(month, "May", 4);
                        break;
                case 6:
-                       strncpy(month, "Jun", 3);
+                       strncpy(month, "Jun", 4);
                        break;
                case 7:
-                       strncpy(month, "Jul", 3);
+                       strncpy(month, "Jul", 4);
                        break;
                case 8:
-                       strncpy(month, "Aug", 3);
+                       strncpy(month, "Aug", 4);
                        break;
                case 9:
-                       strncpy(month, "Sep", 3);
+                       strncpy(month, "Sep", 4);
                        break;
                case 10:
-                       strncpy(month, "Oct", 3);
+                       strncpy(month, "Oct", 4);
                        break;
                case 11:
-                       strncpy(month, "Nov", 3);
+                       strncpy(month, "Nov", 4);
                        break;
                case 12:
-                       strncpy(month, "Dec", 3);
+                       strncpy(month, "Dec", 4);
                        break;
                default:
                        MSG_DEBUG("invalid month number");
                break;
        }
 
-       snprintf(str, 22, "%d:%02d%s, %04d %s %d",
+       wrn = snprintf(str, 22, "%d:%02d%s, %04d %s %d",
                hour,
                tm->tm_min,
                APM,
                tm->tm_year + 1900,
                month,
                tm->tm_mday);
+       if(wrn < 0)
+               MSG_DEBUG("snprintf was failed  ");
 
        return strdup(str);
 }
@@ -627,6 +628,9 @@ static inline int __msgsvc_vmsg_add_folding(char **buf, int *buf_size, int buf_l
 
        buf_copy = (char *)calloc(1, *buf_size);
 
+       if (buf_copy == NULL)
+               return -1;
+
        s = *buf;
        r = buf_copy;
        len = result_len = 0;
@@ -638,8 +642,7 @@ static inline int __msgsvc_vmsg_add_folding(char **buf, int *buf_size, int buf_l
                        if (NULL == (tmp = (char *)realloc(buf_copy, *buf_size))) {
                                free(buf_copy);
                                return -1;
-                       }
-                       else {
+                       } else {
                                buf_copy = tmp;
                                r = (buf_copy + result_len);
                        }
@@ -652,9 +655,9 @@ static inline int __msgsvc_vmsg_add_folding(char **buf, int *buf_size, int buf_l
                                encode_64 = true;
                }
 
-               if ('\r' == *s)
+               if ('\r' == *s) {
                        len--;
-               else if ('\n' == *s) {
+               else if ('\n' == *s) {
                        len = -1;
                        char_len = 0;
                        content_start = false;
@@ -1110,9 +1113,9 @@ char *MsgVMessageEncode(MSG_MESSAGE_INFO_S *pMsg)
                char* msgText = NULL;
 #if 0
                char filePath[MSG_FILEPATH_LEN_MAX] = {0, };
-               if(pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS)
+               if(pMsg->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
                        pFileData = MsgOpenAndReadMmsFile(pMsg->msgData, 0, -1, &fileSize);
-               else {
+               else {
                        err = MsgStoGetMmsRawFilePath(pDbHandle, pMsg->msgId, filePath);
 
                        if (err != MSG_SUCCESS)
@@ -1128,9 +1131,10 @@ char *MsgVMessageEncode(MSG_MESSAGE_INFO_S *pMsg)
                        }
                } else {
                        fileSize = strlen(pMsg->msgData);
-                       pFileData = (char *)calloc(1, fileSize+1);
+                       pFileData = new char[fileSize+1];
                        if (!pFileData)
                                goto __CATCH_FAIL__;
+                       memset(pFileData, 0x00, fileSize+1);
                        snprintf(pFileData, fileSize, "%s", pMsg->msgData);
                }
 
@@ -1165,7 +1169,7 @@ char *MsgVMessageEncode(MSG_MESSAGE_INFO_S *pMsg)
                pObject->valueCount = 1;
 
                if (pFileData) {
-                       free(pFileData);
+                       delete [] pFileData;
                        pFileData = NULL;
                }
        }
@@ -1431,8 +1435,7 @@ static inline char* __msgsvc_vmsg_translate_charset(char *src, int len)
                                val += sizeof("CHARSET");
                                break;
                        }
-               }
-               else if (':' == *val) {
+               } else if (':' == *val) {
                        return NULL;
                }
                val++;
@@ -1487,9 +1490,12 @@ static void __msgsvc_vmsg_get_prefix(char **prefix, char *src)
        if (temp) {
                long len = (long)temp - (long)src;
                *prefix = (char *)calloc(len+1, sizeof(char));
-               snprintf(*prefix, len+1, "%s", src);
-       }
-       else {
+               if (*prefix) {
+                       snprintf(*prefix, len+1, "%s", src);
+               } else {
+                       *prefix = NULL;
+               }
+       } else {
                *prefix = NULL;
        }
 }
@@ -1548,8 +1554,7 @@ static char* __msgsvc_vmsg_get_val(int ver, char *src, char **prefix, char **des
 
                        cursor++;
                }
-       }
-       else {
+       } else {
                while (*cursor) {
                        if ('\r' == *cursor && '\n' == *(cursor+1) && ' ' != *(cursor+2))
                                break;
@@ -1564,8 +1569,7 @@ static char* __msgsvc_vmsg_get_val(int ver, char *src, char **prefix, char **des
        if (src == cursor) {
                *dest = NULL;
                return NULL;
-       }
-       else {
+       } else {
                int len = 0;
                char temp = *cursor;
                char *new_dest;
@@ -1604,9 +1608,9 @@ static int  __msgsvc_vmsg_check_content_type(char **vcard)
                        break;
        }
 
-       if (VMSG_MAXIMUM_VALUE == i)
+       if (VMSG_MAXIMUM_VALUE == i) {
                return VMSG_VALUE_NONE;
-       else {
+       else {
                *vcard = new_start;
                return i;
        }
@@ -1646,6 +1650,10 @@ static char* __msgsvc_vmsg_decode_base64_val(char *val)
        decoded_str = g_base64_decode(src, &size);
 
        dest = (char *)calloc((src-val)+size+1, sizeof(char));
+       if (NULL == dest) {
+               g_free(decoded_str);
+               return NULL;
+       }
        snprintf(dest, (src-val)+1, "%s", val);
        snprintf(dest+(src-val), size+1, "%s", decoded_str);
        g_free(decoded_str);
@@ -1767,8 +1775,7 @@ static inline msg_error_t __msgsvc_vmsg_get_msg_box(MSG_MESSAGE_INFO_S *pMsg, ch
                pMsg->folderId = MSG_DRAFT_ID;
                pMsg->direction = MSG_DIRECTION_TYPE_MO;
                pMsg->networkStatus = MSG_NETWORK_NOT_SEND;
-       }
-       else if (strcmp(temp, content_name[VMSG_INDICATION_MSG_BOX_INBOX]) == 0) {
+       } else if (strcmp(temp, content_name[VMSG_INDICATION_MSG_BOX_INBOX]) == 0) {
                pMsg->folderId = MSG_INBOX_ID;
                pMsg->direction = MSG_DIRECTION_TYPE_MT;
                pMsg->networkStatus = MSG_NETWORK_RECEIVED;
@@ -1776,8 +1783,9 @@ static inline msg_error_t __msgsvc_vmsg_get_msg_box(MSG_MESSAGE_INFO_S *pMsg, ch
                pMsg->folderId = MSG_SENTBOX_ID;
                pMsg->direction = MSG_DIRECTION_TYPE_MO;
                pMsg->networkStatus = MSG_NETWORK_SEND_SUCCESS;
-       } else
+       } else {
                return MSG_ERR_INVALID_PARAMETER;
+       }
 
        MSG_DEBUG("pMsg->folderId = %d", pMsg->folderId);
        return MSG_SUCCESS;
@@ -1796,12 +1804,11 @@ static inline msg_error_t __msgsvc_vmsg_get_msg_type(MSG_MESSAGE_INFO_S *pMsg, c
                pMsg->msgType.mainType = MSG_SMS_TYPE;
                pMsg->msgType.subType = MSG_NORMAL_SMS;
                pMsg->msgType.classType = MSG_CLASS_NONE;
-       }
-       else if (strcmp(temp, content_name[VMSG_INDICATION_MESSAGE_TYPE_INET]) == 0) {
+       } else if (strcmp(temp, content_name[VMSG_INDICATION_MESSAGE_TYPE_INET]) == 0) {
                /* To do */
-       }
-       else
+       } else {
                return MSG_ERR_INVALID_PARAMETER;
+       }
 
        MSG_DEBUG("pMsg->msgType.subType = %d", pMsg->msgType.subType);
        return MSG_SUCCESS;
@@ -1984,9 +1991,9 @@ static inline msg_error_t __msgsvc_vmsg_get_msg(int ver, char *vmsg, MSG_MESSAGE
                                if (new_start) {
                                        cursor = new_start;
                                        continue;
-                               }
-                               else
+                               } else {
                                        break;
+                               }
                        }
                }
 
@@ -2041,8 +2048,9 @@ static inline msg_error_t __msgsvc_vmsg_get_msg(int ver, char *vmsg, MSG_MESSAGE
                                g_free(val);
                                g_free(prefix);
                                return MSG_SUCCESS;
-                       } else
+                       } else {
                                break;
+                       }
                default:
                        MSG_ERR("Invalid parameter : __msgsvc_vmsg_check_content_type() Failed(%d)", type);
                        g_free(val);