Fix 64bit dlog format error
[platform/core/connectivity/bluetooth-agent.git] / pb-agent / bluetooth_pb_vcard.c
old mode 100755 (executable)
new mode 100644 (file)
index 7c10f35..1b0cc34
@@ -27,7 +27,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <glib.h>
-#include <dbus/dbus-glib.h>
 #include <vconf.h>
 #include <dlog.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <contacts.h>
 #include <image_util.h>
-//#include <image_util_product.h>
 #include <libexif/exif-data.h>
 #include <unistd.h>
 
 #include "bluetooth_pb_vcard.h"
 #include "bluetooth_pb_agent.h"
 
-#define VCARD_FORMAT_2_1 0x0
-#define VCARD_FORMAT_3_0 0x1
-
-#define VCARD_VERSION  (0x1)
-#define VCARD_FN       (0x1 << 1)
-#define VCARD_N                (0x1 << 2)
-#define VCARD_PHOTO    (0x1 << 3)
-#define VCARD_BDAY     (0x1 << 4)
-#define VCARD_ADR      (0x1 << 5)
-#define VCARD_LABEL    (0x1 << 6)      /* not supported */
-#define VCARD_TEL      (0x1 << 7)
-#define VCARD_EMAIL    (0x1 << 8)
-#define VCARD_MAILER   (0x1 << 9)      /* not supported */
-#define VCARD_TZ       (0x1 << 10)     /* not supported */
-#define VCARD_GEO      (0x1 << 11)     /* not supported */
-#define VCARD_TITLE    (0x1 << 12)
-#define VCARD_ROLE     (0x1 << 13)
-#define VCARD_LOGO     (0x1 << 14)     /* not supported */
-#define VCARD_AGENT    (0x1 << 15)     /* not supported */
-#define VCARD_ORG      (0x1 << 16)
-#define VCARD_NOTE     (0x1 << 17)
-#define VCARD_REV      (0x1 << 18)
-#define VCARD_SOUND    (0x1 << 19)     /* not supported */
-#define VCARD_URL      (0x1 << 20)
-#define VCARD_UID      (0x1 << 21)
-#define VCARD_KEY      (0x1 << 22)     /* not supported */
-#define VCARD_NICKNAME (0x1 << 23)
-#define VCARD_CATEGORIES       (0x1 << 24)     /* not supported */
-#define VCARD_PROID    (0x1 << 25)     /* not supported */
-#define VCARD_CLASS    (0x1 << 26)     /* not supported */
-#define VCARD_SORT_STRING      (0x1 << 27)     /* not supported */
-#define VCARD_X_IRMC_CALL_DATETIME     (0x1 << 28)
-
 #define QP_ENC_LEN     3
 #define LINEBREAK_LEN  75
 
@@ -247,7 +212,7 @@ static gchar *__bluetooth_pb_number_from_contact(contacts_record_h contact);
 
 static gint __bluetooth_pb_person_id_from_phonelog_id(gint phonelog_id);
 
-
+/* LCOV_EXCL_START */
 static gchar *__bluetooth_pb_vcard_escape(const gchar *str)
 {
        FN_START;
@@ -298,6 +263,7 @@ static gchar *__bluetooth_pb_vcard_strv_concat(gchar **strv,
        FN_END;
        return g_string_free(string, FALSE);
 }
+/* LCOV_EXCL_STOP */
 
 static gboolean __bluetooth_pb_vcard_qp_encode_check(const gchar *str)
 {
@@ -319,6 +285,7 @@ static gboolean __bluetooth_pb_vcard_qp_encode_check(const gchar *str)
        return FALSE;
 }
 
+/* LCOV_EXCL_START */
 /* get string length, which convert to quoted-printable encoding */
 static gint __bluetooth_pb_vcard_qp_encode_strlen(const gchar *str,
                                                gint len)
@@ -533,6 +500,7 @@ static gchar *__bluetooth_pb_vcard_qp_encode(const gchar *str)
        FN_END;
        return g_string_free(enc, FALSE);
 }
+/* LCOV_EXCL_STOP */
 
 static void __bluetooth_pb_vcard_append_param_v21(GString *string,
                                                 const gchar *param)
@@ -573,6 +541,7 @@ static void __bluetooth_pb_vcard_append_qp_encode_v21(GString *string,
        __bluetooth_pb_vcard_append_param_v21(property, param);
 
        if (__bluetooth_pb_vcard_qp_encode_check(value)) {
+               /* LCOV_EXCL_START */
                gchar *enc = NULL;
 
                __bluetooth_pb_vcard_append_param_v21(property,
@@ -587,6 +556,7 @@ static void __bluetooth_pb_vcard_append_qp_encode_v21(GString *string,
                        g_string_append(property, enc);
                        g_free(enc);
                }
+               /* LCOV_EXCL_STOP */
        } else {
                g_string_append(property, ":");
                if (value)
@@ -599,7 +569,7 @@ static void __bluetooth_pb_vcard_append_qp_encode_v21(GString *string,
        FN_END;
 }
 
-
+/* LCOV_EXCL_START */
 static void __bluetooth_pb_vcard_append_base64_encode_v21(GString *string,
                                                        const gchar *name,
                                                        const gchar *param,
@@ -758,7 +728,13 @@ static void __bluetooth_pb_vcard_append_fn_v21(GString *string,
 
        g_free(fn);
 }
+/* LCOV_EXCL_STOP */
 
+/* image util APIs will be deprecated in Tizen 5.0. So we should replace it to new API
+     https://developer.tizen.org/development/guides/native-application/media-and-camera/image-editing#decode
+     https://developer.tizen.org/development/guides/native-application/media-and-camera/image-editing#encode
+*/
+#if 0
 static image_util_rotation_e __bt_pbap_get_rotation_info(const char *path)
 {
        FN_START;
@@ -899,9 +875,11 @@ static bool __bt_pbap_image_util_supported_jpeg_colorspace_cb(
                int rotated_width, rotated_height;
                unsigned char *img_rotate = 0;
                img_rotate = g_malloc0(size_decode);
-               image_util_rotate(img_rotate, &rotated_width, &rotated_height,
+               ret = image_util_rotate(img_rotate, &rotated_width, &rotated_height,
                                        rotation, img_target, resized_width,
                                        resized_height, colorspace);
+               if (ret != 0)
+                       ERR("image_util_rotate failed");
                resized_width = rotated_width;
                resized_height = rotated_height;
                g_free(img_target);
@@ -970,15 +948,15 @@ done:
        FN_END;
        return false;
 }
+#endif
 
+/* LCOV_EXCL_START */
 static void __bluetooth_pb_vcard_append_photo_v21(GString *string,
                                                contacts_record_h person)
 {
        FN_START;
        gint status;
        gchar *filename = NULL;
-       int res = 0;
-       bt_image_info_t img_info;
        struct stat stat_info;
        gchar *type = NULL;
        gchar *param = NULL;
@@ -995,9 +973,8 @@ static void __bluetooth_pb_vcard_append_photo_v21(GString *string,
 
        stat_info.st_size = 0;
 
-       if (0 > stat(filename, &stat_info)) {
+       if (0 > stat(filename, &stat_info))
                ERR("fstat failed, file does not exist %s", filename);
-       }
 
        if (PBAP_THUMB_FILE_SIZE > stat_info.st_size) {
                DBG_SECURE("File size small, so use thubnail %s\n", filename);
@@ -1033,6 +1010,15 @@ static void __bluetooth_pb_vcard_append_photo_v21(GString *string,
                DBG("Thumbnail path is = %s", dest_thumb_path);
        }
        DBG_SECURE("filename = %s Thumbnail path is = %s", filename, dest_thumb_path);
+
+/* image_util_foreach_supported_jpeg_colorspace API will be deprecated in Tizen 5.0. So we should replace it to new API
+     https://developer.tizen.org/development/guides/native-application/media-and-camera/image-editing#decode
+     https://developer.tizen.org/development/guides/native-application/media-and-camera/image-editing#encode
+*/
+#if 0
+       bt_image_info_t img_info;
+       int res = 0;
+
        img_info.src = filename;
        img_info.dest = dest_thumb_path;
        img_info.ret = CONTACTS_ERROR_INTERNAL;
@@ -1041,9 +1027,11 @@ static void __bluetooth_pb_vcard_append_photo_v21(GString *string,
 
        res = image_util_foreach_supported_jpeg_colorspace(
                __bt_pbap_image_util_supported_jpeg_colorspace_cb, &img_info);
-       if (res != IMAGE_UTIL_ERROR_NONE) {
+
+       if (res != IMAGE_UTIL_ERROR_NONE)
                ERR("Image resizing is failed");
-       }
+#endif
+
        FN_END;
 }
 
@@ -1513,6 +1501,7 @@ static void __bluetooth_pb_vcard_append_uid_v21(GString *string,
        g_free(escaped);
        FN_END;
 }
+/* LCOV_EXCL_STOP */
 
 static void __bluetooth_pb_vcard_append_v30(GString *string,
                                        const gchar *name,
@@ -1539,6 +1528,7 @@ static void __bluetooth_pb_vcard_append_v30(GString *string,
        FN_END;
 }
 
+/* LCOV_EXCL_START */
 static void __bluetooth_pb_vcard_remove_v30(GString *string,
                                        const gchar *property_name)
 {
@@ -1606,9 +1596,6 @@ static gchar *__bluetooth_pb_vcard_filter_v30(const gchar *vcard,
 
        string = g_string_new(vcard);
 
-       if ((filter & VCARD_PHOTO) == 0)
-               __bluetooth_pb_vcard_remove_v30(string, "PHOTO");
-
        if ((filter & VCARD_BDAY) == 0)
                __bluetooth_pb_vcard_remove_v30(string, "BDAY");
 
@@ -1691,7 +1678,7 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v21(gint person_id,
        if (f == 0)
                f = ~f;
 
-       DBG("filter[%x]\n", filter);
+       DBG("filter[%llu]\n", (unsigned long long int)filter);
 
        str = g_string_new("BEGIN:VCARD\r\nVERSION:2.1\r\n");
 
@@ -1764,7 +1751,7 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v21(gint person_id,
        FN_END;
        return g_string_free(str, FALSE);
 }
-
+/* LCOV_EXCL_STOP */
 
 static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
                                                        gint phonelog_id,
@@ -1789,16 +1776,12 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
+       /* LCOV_EXCL_START */
        status = contacts_vcard_make_from_person(person, &vcard);
 
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
-       status = contacts_record_destroy(person, TRUE);
-
-       if (status != CONTACTS_ERROR_NONE)
-               return NULL;
-
        /* removing the END:VCARD\r\n" to append extra data */
        str = g_string_new_len(vcard, (strlen(vcard)-11));
        g_free(vcard);
@@ -1825,6 +1808,16 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
                g_free(number);
        }
 
+       /* Remove Full contact image and add thumbnail image */
+       __bluetooth_pb_vcard_remove_v30(str, "PHOTO");
+       if (filter & VCARD_PHOTO)
+               __bluetooth_pb_vcard_append_photo_v21(str, person); /* Photo is same as vCard 2.1 */
+
+       /* Destroy contact record */
+       status = contacts_record_destroy(person, TRUE);
+       if (status != CONTACTS_ERROR_NONE)
+               ERR("Failed to destroy person");
+
        g_string_append(str, "END:VCARD\r\n");
 
        vcard = g_string_free(str, FALSE);
@@ -1846,6 +1839,7 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
 
        FN_END;
        return vcard;
+       /* LCOV_EXCL_STOP */
 }
 
 
@@ -1899,6 +1893,7 @@ static gchar *__bluetooth_pb_vcard_real_call_v21(gint phonelog_id,
        __bluetooth_pb_vcard_append_qp_encode_v21(str, "TEL", "X-0", number);
        g_free(number);
 
+       /* LCOV_EXCL_START */
        if (((filter == 0) || (filter & VCARD_X_IRMC_CALL_DATETIME))
                        && attr) {
                gchar *datetime = NULL;
@@ -1909,6 +1904,7 @@ static gchar *__bluetooth_pb_vcard_real_call_v21(gint phonelog_id,
                                                        attr, datetime);
                g_free(datetime);
        }
+       /* LCOV_EXCL_STOP */
 
        g_string_append(str, "END:VCARD\r\n");
 
@@ -1916,6 +1912,7 @@ static gchar *__bluetooth_pb_vcard_real_call_v21(gint phonelog_id,
        return g_string_free(str, FALSE);
 }
 
+/* LCOV_EXCL_START */
 static gchar *__bluetooth_pb_vcard_real_call_v30(gint phonelog_id,
                                                guint filter,
                                                const gchar *attr)
@@ -1948,6 +1945,7 @@ static gchar *__bluetooth_pb_vcard_real_call_v30(gint phonelog_id,
        FN_END;
        return g_string_free(str, FALSE);
 }
+/* LCOV_EXCL_STOP */
 
 static gchar *__bluetooth_pb_vcard_real_call(gint phonelog_id,
                                        guint filter,
@@ -1973,6 +1971,7 @@ static gchar *__bluetooth_pb_vcard_real_call(gint phonelog_id,
        return vcard;
 }
 
+/* LCOV_EXCL_START */
 static gchar **__bluetooth_pb_contact_add_field_str(contacts_record_h record,
                                                int *field,
                                                gint field_size)
@@ -2043,13 +2042,6 @@ static gchar **__bluetooth_pb_contact_tel_param(contacts_record_h number)
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
-       strv = g_new0(char *, TEL_PARAM_LEN + 1);/* tel param max size is 13 */
-
-       if (is_default) {
-               strv[i] = g_strdup("PREF");
-               i++;
-       }
-
        status = contacts_record_get_int(number,
                        _contacts_number.type,
                        (gint *)&type);
@@ -2057,6 +2049,13 @@ static gchar **__bluetooth_pb_contact_tel_param(contacts_record_h number)
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
+       strv = g_new0(char *, TEL_PARAM_LEN + 1);/* tel param max size is 13 */
+
+       if (is_default) {
+               strv[i] = g_strdup("PREF");
+               i++;
+       }
+
        if (type & CONTACTS_NUMBER_TYPE_HOME) {
                strv[i] = g_strdup("HOME");
                i++;
@@ -2298,8 +2297,7 @@ static gchar *__bluetooth_pb_name_from_contact(contacts_record_h contact)
        FN_START;
        contacts_record_h name = NULL;
 
-       GString *str = g_string_new(NULL);
-
+       GString *str;
        gint status;
        gint i;
 
@@ -2317,6 +2315,8 @@ static gchar *__bluetooth_pb_name_from_contact(contacts_record_h contact)
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
+       str = g_string_new(NULL);
+
        for (i = 0; i < name_size; i++) {
                gchar *tmp = NULL;
                gchar *escape = NULL;
@@ -2344,7 +2344,7 @@ static gchar *__bluetooth_pb_phonetic_name_from_contact(contacts_record_h contac
        FN_START;
        contacts_record_h name = NULL;
 
-       GString *str = g_string_new(NULL);
+       GString *str;
 
        gint status;
 
@@ -2366,6 +2366,8 @@ static gchar *__bluetooth_pb_phonetic_name_from_contact(contacts_record_h contac
        if (phonetic_first == NULL)
                return NULL;
 
+       str = g_string_new(NULL);
+
        status = contacts_record_get_str_p(name, _contacts_name.phonetic_last, &phonetic_last);
 
        if ((status == CONTACTS_ERROR_NONE) && (phonetic_last != NULL)) {
@@ -2467,6 +2469,7 @@ static gchar *__bluetooth_pb_number_from_contact(contacts_record_h contact)
        FN_END;
        return str;
 }
+/* LCOV_EXCL_STOP */
 
 static gint __bluetooth_pb_person_id_from_phonelog_id(gint phonelog_id)
 {
@@ -2488,6 +2491,7 @@ static gint __bluetooth_pb_person_id_from_phonelog_id(gint phonelog_id)
        if (status != CONTACTS_ERROR_NONE)
                return 0;
 
+       /* LCOV_EXCL_START */
        status = contacts_record_get_int(phone_log,
                        _contacts_phone_log.person_id,
                        &person_id);
@@ -2561,6 +2565,7 @@ done:
 
        FN_END;
        return person_id;
+       /* LCOV_EXCL_STOP */
 }
 
 int _bluetooth_get_contact_addressbook(gint person_id)
@@ -2580,6 +2585,7 @@ int _bluetooth_get_contact_addressbook(gint person_id)
        if (status != CONTACTS_ERROR_NONE)
                return PBAP_ADDRESSBOOK_PHONE; /* Default*/
 
+       /* LCOV_EXCL_START */
        status = contacts_record_get_int(person,
                        _contacts_person.display_contact_id,
                        &contact_id);
@@ -2619,6 +2625,7 @@ int _bluetooth_get_contact_addressbook(gint person_id)
                return PBAP_ADDRESSBOOK_PHONE;
 
        return PBAP_ADDRESSBOOK_SIM;
+       /* LCOV_EXCL_STOP */
 }
 /* API for vcard */
 gchar *_bluetooth_pb_vcard_contact(gint person_id,
@@ -2704,6 +2711,7 @@ gchar *_bluetooth_pb_vcard_call(gint phonelog_id,
        DBG("person_id %d\n", person_id);
 
        if (person_id) {
+               /* LCOV_EXCL_START */
                if (filter == 0 || (filter & VCARD_X_IRMC_CALL_DATETIME)) {
                        gchar *datetime = NULL;
 
@@ -2726,6 +2734,7 @@ gchar *_bluetooth_pb_vcard_call(gint phonelog_id,
                                        filter, format,
                                        NULL);
                }
+               /* LCOV_EXCL_STOP */
        } else
                str = __bluetooth_pb_vcard_real_call(phonelog_id, filter,
                                                                format, attr);
@@ -2750,6 +2759,7 @@ gchar *_bluetooth_pb_fn_from_person_id(gint person_id)
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
+       /* LCOV_EXCL_START */
        status = contacts_record_get_str(person,
                        _contacts_person.display_name,
                        &str);
@@ -2761,6 +2771,7 @@ gchar *_bluetooth_pb_fn_from_person_id(gint person_id)
 
        FN_END;
        return str;
+       /* LCOV_EXCL_STOP */
 }
 
 gchar *_bluetooth_pb_name_from_person_id(gint person_id)
@@ -2781,6 +2792,7 @@ gchar *_bluetooth_pb_name_from_person_id(gint person_id)
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
+       /* LCOV_EXCL_START */
        status = contacts_record_get_int(person,
                        _contacts_person.display_contact_id,
                        &contact_id);
@@ -2803,6 +2815,7 @@ gchar *_bluetooth_pb_name_from_person_id(gint person_id)
 
        contacts_record_destroy(contact, TRUE);
        contacts_record_destroy(person, TRUE);
+       /* LCOV_EXCL_STOP */
 
        FN_END;
        return str;
@@ -2826,7 +2839,7 @@ gchar *_bluetooth_pb_number_from_person_id(gint person_id)
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
-
+       /* LCOV_EXCL_START */
        status = contacts_record_get_int(person,
                        _contacts_person.display_contact_id,
                        &contact_id);
@@ -2849,6 +2862,7 @@ gchar *_bluetooth_pb_number_from_person_id(gint person_id)
 
        contacts_record_destroy(contact, TRUE);
        contacts_record_destroy(person, TRUE);
+       /* LCOV_EXCL_STOP */
 
        FN_END;
        return str;
@@ -2910,6 +2924,7 @@ gchar *_bluetooth_pb_number_from_phonelog_id(gint phonelog_id)
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
+       /* LCOV_EXCL_START */
        status = contacts_record_get_str_p(phone_log,
                        _contacts_phone_log.address,
                        &tmp);
@@ -2922,6 +2937,7 @@ gchar *_bluetooth_pb_number_from_phonelog_id(gint phonelog_id)
        str = g_strdup(tmp);
 
        contacts_record_destroy(phone_log, TRUE);
+       /* LCOV_EXCL_STOP */
 
        FN_END;
        return str;
@@ -2935,7 +2951,7 @@ gchar *_bluetooth_pb_owner_name(void)
        name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
 
        if (name == NULL)
-               name = g_strdup("My Name");
+               name = g_strdup("My Name"); /* LCOV_EXCL_LINE */
 
        FN_END;
        return name;