Code to convert image extention path to lower case 69/218469/1 submit/tizen/20191122.144351
authorkamaljeet chauhan <kamal.jc@samsung.com>
Fri, 22 Nov 2019 14:38:09 +0000 (20:08 +0530)
committerkamaljeet chauhan <kamal.jc@samsung.com>
Fri, 22 Nov 2019 14:38:09 +0000 (20:08 +0530)
Change-Id: I18e7514e99d516c99830659531d5bb29cc3b9a4a
Signed-off-by: kamaljeet chauhan <kamal.jc@samsung.com>
common/ctsvc_vcard.c

index 9385ff6..70e20ec 100644 (file)
@@ -538,71 +538,127 @@ static inline const char* __ctsvc_get_img_suffix(int type)
        }
 }
 
-static inline int __ctsvc_vcard_get_image_type(char *val)
+static inline int __ctsvc_vcard_get_image_type(const char *val)
 {
-       char *temp, *result;
+       char *temp, *image_path, *result;
        RETV_IF(NULL == val, CTSVC_VCARD_IMG_NONE);
 
-       temp = val;
+       image_path = strdup(val);
+       temp = image_path;
        while (*temp) {
                *temp = tolower(*temp);
                temp++;
        }
 
-       result = strstr(val, "jpeg");
-       if (result) return CTSVC_VCARD_IMG_JPEG;
+       result = strstr(image_path, "jpeg");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_JPEG;
+       }
 
-       result = strstr(val, "jpg");
-       if (result) return CTSVC_VCARD_IMG_JPEG;
+       result = strstr(image_path, "jpg");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_JPEG;
+       }
 
-       result = strstr(val, "png");
-       if (result) return CTSVC_VCARD_IMG_PNG;
+       result = strstr(image_path, "png");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_PNG;
+       }
 
-       result = strstr(val, "gif");
-       if (result) return CTSVC_VCARD_IMG_GIF;
+       result = strstr(image_path, "gif");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_GIF;
+       }
 
-       result = strstr(val, "tiff");
-       if (result) return CTSVC_VCARD_IMG_TIFF;
+       result = strstr(image_path, "tiff");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_TIFF;
+       }
 
-       result = strstr(val, "cgm");
-       if (result) return CTSVC_VCARD_IMG_CGM;
+       result = strstr(image_path, "cgm");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_CGM;
+       }
 
-       result = strstr(val, "wmf");
-       if (result) return CTSVC_VCARD_IMG_WMF;
+       result = strstr(image_path, "wmf");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_WMF;
+       }
 
-       result = strstr(val, "bmp");
-       if (result) return CTSVC_VCARD_IMG_BMP;
+       result = strstr(image_path, "bmp");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_BMP;
+       }
 
-       result = strstr(val, "met");
-       if (result) return CTSVC_VCARD_IMG_MET;
+       result = strstr(image_path, "met");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_MET;
+       }
 
-       result = strstr(val, "pmb");
-       if (result) return CTSVC_VCARD_IMG_PMB;
+       result = strstr(image_path, "pmb");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_PMB;
+       }
 
-       result = strstr(val, "dib");
-       if (result) return CTSVC_VCARD_IMG_DIB;
+       result = strstr(image_path, "dib");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_DIB;
+       }
 
-       result = strstr(val, "pict");
-       if (result) return CTSVC_VCARD_IMG_PICT;
+       result = strstr(image_path, "pict");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_PICT;
+       }
 
-       result = strstr(val, "pdf");
-       if (result) return CTSVC_VCARD_IMG_PDF;
+       result = strstr(image_path, "pdf");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_PDF;
+       }
 
-       result = strstr(val, "ps");
-       if (result) return CTSVC_VCARD_IMG_PS;
+       result = strstr(image_path, "ps");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_PS;
+       }
 
-       result = strstr(val, "qtime");
-       if (result) return CTSVC_VCARD_IMG_QTIME;
+       result = strstr(image_path, "qtime");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_QTIME;
+       }
 
-       result = strstr(val, "mpeg");
-       if (result) return CTSVC_VCARD_IMG_MPEG;
+       result = strstr(image_path, "mpeg");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_MPEG;
+       }
 
-       result = strstr(val, "mpeg2");
-       if (result) return CTSVC_VCARD_IMG_MPEG2;
+       result = strstr(image_path, "mpeg2");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_MPEG2;
+       }
 
-       result = strstr(val, "avi");
-       if (result) return CTSVC_VCARD_IMG_AVI;
+       result = strstr(image_path, "avi");
+       if (result) {
+               free(image_path);
+               return CTSVC_VCARD_IMG_AVI;
+       }
 
+       free(image_path);
        return CTSVC_VCARD_IMG_NONE;
 }
 
@@ -656,7 +712,7 @@ static inline int __ctsvc_vcard_put_company_logo(const char *path, char **buf, i
        guchar image[CTSVC_VCARD_PHOTO_MAX_SIZE] = {0};
 
        suffix = strrchr(path, '.');
-       type = __ctsvc_vcard_get_image_type(suffix);
+       type = __ctsvc_vcard_get_image_type((const char *)suffix);
 
        fd = open(path, O_RDONLY);
        RETVM_IF(fd < 0, CONTACTS_ERROR_SYSTEM, "System : Open Fail(%d)", errno);
@@ -1705,7 +1761,7 @@ static inline int __ctsvc_vcard_put_photo(ctsvc_list_s *image_list, char **buf,
                }
 
                suffix = strrchr(data->path, '.');
-               type = __ctsvc_vcard_get_image_type(suffix);
+               type = __ctsvc_vcard_get_image_type((const char *)suffix);
 
                buf_image = g_base64_encode(image, read_len);
                free(image);
@@ -2882,7 +2938,7 @@ static inline int __ctsvc_vcard_get_photo(contacts_record_h contact, ctsvc_list_
 
        *temp = '\0';
 
-       type = __ctsvc_vcard_get_image_type(prefix);
+       type = __ctsvc_vcard_get_image_type((const char *)prefix);
 
        buf = g_base64_decode(temp+1, &size);
        if ((0 == size) || (NULL == buf)) {
@@ -3144,7 +3200,7 @@ static inline int __ctsvc_vcard_get_company_logo(ctsvc_list_s *company_list, cha
        RETVM_IF(NULL == temp, CONTACTS_ERROR_INVALID_PARAMETER, "val is invalid");
 
        *temp = '\0';
-       type = __ctsvc_vcard_get_image_type(prefix);
+       type = __ctsvc_vcard_get_image_type((const char *)prefix);
 
        buf = g_base64_decode(temp+1, &size);
        if ((0 == size) || (NULL == buf)) {
@@ -3918,6 +3974,8 @@ static inline int __ctsvc_vcard_get_contact(int ver, char *vcard, contacts_recor
                        cursor = new_start;
                        if (prefix)
                                free(prefix);
+                       if (val)
+                               free(val);
                        continue;
                }
 
@@ -4666,7 +4724,7 @@ EXPORT_API int contacts_vcard_parse_to_contact_foreach(const char *vcard_file_na
                if (CONTACTS_ERROR_NONE != ret) {
                        free(stream);
                        fclose(file);
-                       ERR("_ctsvc_safe_add() Fail(%u + %d)", len, written_len);
+                       ERR("_ctsvc_safe_add() Fail(len:%d, written_len:%d)", len, written_len);
                        return ret;
                }