Update HID, PBAP and MAP agent codes 38/166238/2
authorSangki Park <sangki79.park@samsung.com>
Mon, 8 Jan 2018 10:18:57 +0000 (19:18 +0900)
committerSangki Park <sangki79.park@samsung.com>
Tue, 9 Jan 2018 04:49:05 +0000 (04:49 +0000)
Change-Id: I84ed5e999dd327ffbbae13e43e417537e9a26b27

hid-agent/CMakeLists.txt
hid-agent/bluetooth-hid-agent.c
hid-agent/bluetooth-hid-agent.h
map-agent/bluetooth_map_agent.c
map-agent/bluetooth_map_email.c
pb-agent/bluetooth_pb_agent.c
pb-agent/bluetooth_pb_agent.h
pb-agent/bluetooth_pb_vcard.c
pb-agent/bluetooth_pb_vcard.h

index 186db21..b54c7e7 100644 (file)
@@ -8,8 +8,9 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
 INCLUDE(FindPkgConfig)
 pkg_check_modules(pkgs_hid_agent
                REQUIRED
-               dlog aul bluetooth-api capi-appfw-app-manager
-               glib-2.0 gio-2.0 gio-unix-2.0 capi-system-device vconf)
+               dlog aul
+               glib-2.0 gio-2.0 gio-unix-2.0 capi-system-device vconf
+               capi-system-info bluetooth-api)
 
 FOREACH(flag ${pkgs_hid_agent_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index b778388..34f8049 100644 (file)
@@ -800,9 +800,6 @@ static void __bt_hid_agent_dbus_deinit(void)
        }
 }
 
-
-
-
 bt_hid_agent_error_t _bt_hid_disconnect_profile(void)
 {
        FN_START;
index 8552031..6c96861 100644 (file)
@@ -158,6 +158,10 @@ struct sockaddr_remote {
        uint8_t         channel;
 };
 
+void _bt_hid_set_profile_state(bt_hid_state_t new_state);
+bt_hid_agent_error_t _bt_hid_register_application(gboolean register_flag,
+               const char *sender_name);
+
 bt_hid_agent_error_t _bt_hid_disconnect_profile(void);
 
 #endif /* __DEF_BT_HID_AGENT_H_ */
index 5f59b9f..1d1087d 100644 (file)
@@ -595,24 +595,9 @@ time_t _get_time_t_from_timestamp(char *timestamp)
        int month;
        time_t int_time;
 
-       int ymd; /* year, month, day */
-       int hms; /* hour, min, sec */
-       char *ptr, *ptr2;
-
-       ymd = strtol(timestamp, &ptr, 10);
-       hms = strtol(ptr + 1, &ptr2, 10);
-
-       /* parse year, month, day */
-       local_time.tm_mday = ymd % 100;
-       ymd = (ymd - local_time.tm_mday) / 100;
-       month = ymd % 100;
-       year = (ymd - month) / 100;
-
-       /* parse hour, minute, sec */
-       local_time.tm_sec = hms % 100;
-       hms = (hms - local_time.tm_sec) / 100;
-       local_time.tm_min = hms % 100;
-       local_time.tm_hour = (hms - local_time.tm_min) / 100;
+       sscanf(timestamp, "%04d%02d%02dT%02d%02d%02d", &year, &month,
+                       &local_time.tm_mday, &local_time.tm_hour,
+                       &local_time.tm_min, &local_time.tm_sec);
 
        local_time.tm_year = year - 1900;
        local_time.tm_mon = month - 1;
@@ -1545,7 +1530,9 @@ int main(void)
        int ret;
        DBG("Starting Bluetooth MAP agent");
 
-       //g_type_init();
+#if GLIB_VERSION_MIN_REQUIRED < GLIB_VERSION_2_36
+       g_type_init();
+#endif
 
        g_mainloop = g_main_loop_new(NULL, FALSE);
 
index 03c0ea2..80d2124 100644 (file)
@@ -293,7 +293,7 @@ gboolean _bt_map_start_email_service(void)
        int err;
        GDBusConnection *dbus_conn = NULL;
        GError *error = NULL;
-       int signal_handler_storage = -1;
+       guint signal_handler_storage = 0;
        err = email_service_begin();
        if (err != EMAIL_ERROR_NONE) {
                ERR("email_service_begin fail  error = %d\n", err);
@@ -313,7 +313,7 @@ gboolean _bt_map_start_email_service(void)
                        BT_EMAIL_STORAGE_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
                        __bt_email_subscription_callback, NULL, NULL);
 
-       if (signal_handler_storage == -1) {
+       if (signal_handler_storage == 0) {
                ERR("Failed to g_dbus_connection_signal_subscribe()");
                g_object_unref(dbus_conn);
                email_service_end();
@@ -849,11 +849,16 @@ static int __bt_map_save_email_to_outbox(char *subject, char *body,
                                                EMAIL_MAIL_REQUEST_MDN;
        mail_data->remaining_resend_times = 3;
        mail_data->file_path_plain = g_strdup(BT_MAIL_TEMP_BODY);
-       mail_data->subject = g_strdup(subject);
-       mail_data->full_address_to = g_strdup(recepients);
+
+       if (subject)
+               mail_data->subject = g_strdup(subject);
+
+       if (recepients)
+               mail_data->full_address_to = g_strdup(recepients);
 
        /* Get Sender Address  from Account data*/
-       mail_data->full_address_from = g_strdup(account_data->user_email_address);
+       if (account_data->user_email_address)
+               mail_data->full_address_from = g_strdup(account_data->user_email_address);
 
        /* Get MailboxID and Type from mailbox data */
        mail_data->mailbox_id = mailbox_data->mailbox_id;
@@ -940,11 +945,17 @@ static int __bt_map_save_email_to_draft(char *subject,
        mail_data->flags_draft_field = 1;
        mail_data->report_status = EMAIL_MAIL_REPORT_NONE;
        mail_data->remaining_resend_times = -1;
-       mail_data->subject = g_strdup(subject);
-       mail_data->full_address_to = g_strdup(recepients);
+
+       if (subject)
+               mail_data->subject = g_strdup(subject);
+
+       if (recepients)
+               mail_data->full_address_to = g_strdup(recepients);
 
        /* Get Sender Address  from Account data*/
-       mail_data->full_address_from = g_strdup(account_data->user_email_address);
+       if (account_data->user_email_address)
+               mail_data->full_address_from = g_strdup(account_data->user_email_address);
+
        email_free_account(&account_data, 1);
 
        /* Get MailboxID and Type from mailbox data */
index e132ee7..b6a85d9 100644 (file)
@@ -65,6 +65,15 @@ static gchar *bluetooth_pb_agent_folder_list[] = {
 static guint total_missed_call_count = 0;
 static guint unnotified_missed_call_count = 0;
 
+static int *mapping_cch; /* CCH: handle and call log ID mapping */
+static int count_cch; /* CCH: count of handles */
+static int *mapping_och; /* OCH: handle and call log ID mapping */
+static int count_och; /* OCH: count of handles */
+static int *mapping_ich; /* ICH: handle and call log ID mapping */
+static int count_ich; /* ICH: count of handles */
+static int *mapping_mch; /* MCH: handle and call log ID mapping */
+static int count_mch; /* MCH: count of handles */
+
 GMainLoop *g_mainloop;
 static GDBusConnection *pb_dbus_conn = NULL;
 
@@ -139,6 +148,65 @@ static const gchar pb_agent_introspection_xml[] =
        "</interface>"
 "</node>";
 
+static void add_log_id(int call_log_id, int handle, PhoneBookType pb_type)
+{
+       DBG("HANDLE[%d] CALL_ID[%d]", handle, call_log_id);
+
+       switch (pb_type) {
+       case TELECOM_ICH:
+               mapping_ich[handle - 1] = call_log_id;
+               break;
+       case TELECOM_OCH:
+               mapping_och[handle - 1] = call_log_id;
+               break;
+       case TELECOM_MCH:
+               mapping_mch[handle - 1] = call_log_id;
+               break;
+       case TELECOM_CCH:
+               mapping_cch[handle - 1] = call_log_id;
+               break;
+       case TELECOM_PB:
+       case TELECOM_NONE:
+#ifdef TIZEN_FEATURE_BT_PBAP_SIM
+       case SIM_PB:
+#endif
+               break;
+       }
+}
+
+static int get_log_id(int handle, PhoneBookType pb_type)
+{
+       int call_log_id = -1;
+
+       switch (pb_type) {
+       case TELECOM_ICH:
+               if (handle <= count_ich && handle > 0)
+                       call_log_id = mapping_ich[handle - 1];
+               break;
+       case TELECOM_OCH:
+               if (handle <= count_och && handle > 0)
+                       call_log_id = mapping_och[handle - 1];
+               break;
+       case TELECOM_MCH:
+               if (handle <= count_mch && handle > 0)
+                       call_log_id = mapping_mch[handle - 1];
+               break;
+       case TELECOM_CCH:
+               if (handle <= count_cch && handle > 0)
+                       call_log_id = mapping_cch[handle - 1];
+               break;
+       case TELECOM_PB:
+       case TELECOM_NONE:
+#ifdef TIZEN_FEATURE_BT_PBAP_SIM
+       case SIM_PB:
+#endif
+               break;
+       }
+
+       DBG("PB-TYPE[%d] HANDLE[%d] CALL_ID[%d]", pb_type, handle, call_log_id);
+       return call_log_id;
+}
+
 static void __bt_pb_agent_method(GDBusConnection *connection,
                        const gchar *sender, const gchar *object_path,
                        const gchar *interface_name, const gchar *method_name,
@@ -178,7 +246,7 @@ static GVariant *__bt_pb_get_total_object_count(PbAgentData *agent,
 static gboolean __bt_pb_add_contact(PbAgentData *agent, const char *filename,
                                        GError **error);
 
-static gboolean __bt_pb_destroy_agent();
+static gboolean __bt_pb_destroy_agent(void);
 
 static GError *__bt_pb_error(gint error_code, const gchar *error_message);
 
@@ -217,7 +285,7 @@ static void __bluetooth_pb_get_contact_list(PbAgentData *agent,
                        contacts_query_h query, GVariantBuilder *builder);
 
 static void __bluetooth_pb_get_phone_log_list(PbAgentData *agent,
-                       contacts_query_h query, GVariantBuilder *builder);
+                       contacts_query_h query, GVariantBuilder *builder, PhoneBookType pb_type);
 
 static void __bluetooth_pb_get_list(PbAgentData *agent, PhoneBookType pb_type,
                                GVariantBuilder *builder);
@@ -480,7 +548,7 @@ static GVariant *__bt_pb_get_phonebook(PbAgentData *agent, const char *name,
        PhoneBookType pb_type = TELECOM_NONE;
        GVariantBuilder *vcards;
 
-       INFO("name: %s filter: %lld format: %d max_list_count: %d list_start_offset: %d\n",
+       INFO_SECURE("name: %s filter: %lld format: %d max_list_count: %d list_start_offset: %d\n",
                        name, filter, format, max_list_count, list_start_offset);
 
        __bluetooth_pb_agent_timeout_add_seconds(agent);
@@ -558,7 +626,6 @@ static GVariant *__bt_pb_get_phonebook_size(PbAgentData *agent,
        return phonebook_size;
 }
 
-
 static GVariant *__bt_pb_get_phonebook_list(PbAgentData *agent,
                                                const char *name, GError **err)
 {
@@ -613,6 +680,7 @@ static GVariant *__bt_pb_get_phonebook_entry(PbAgentData *agent,
        gint handle = 0;
        gchar *str = NULL;
        const gchar *attr = NULL;
+       int call_log_id = -1;
 
        DBG_SECURE("folder: %s id: %s filter: %ld format: %d\n",
                        folder, id, filter, format);
@@ -637,27 +705,31 @@ static GVariant *__bt_pb_get_phonebook_entry(PbAgentData *agent,
        /* create index cache */
        __bluetooth_pb_get_list(agent, pb_type, NULL);
 
+       if (pb_type >= TELECOM_ICH && pb_type <= TELECOM_CCH) {
+               call_log_id = get_log_id(handle, pb_type);
+               if (call_log_id == -1)
+                       goto end;
+       }
+
        switch (pb_type) {
        case TELECOM_PB:
-               if (handle == 0) {
+               if (handle == 0)
                        str = _bluetooth_pb_vcard_contact_owner(agent->tel_number,
                                                                filter, format);
-               } else {
+               else
                        if (_bluetooth_get_contact_addressbook(handle) == PBAP_ADDRESSBOOK_PHONE)
                                str = _bluetooth_pb_vcard_contact(handle,
                                                                filter, format);
-               }
                break;
-
        case TELECOM_ICH:
-               str = _bluetooth_pb_vcard_call(handle, filter, format,
+               str = _bluetooth_pb_vcard_call(call_log_id, filter, format,
                                                                "RECEIVED");
                break;
        case TELECOM_OCH:
-               str = _bluetooth_pb_vcard_call(handle, filter, format, "DIALED");
+               str = _bluetooth_pb_vcard_call(call_log_id, filter, format, "DIALED");
                break;
        case TELECOM_MCH:
-               str = _bluetooth_pb_vcard_call(handle, filter, format, "MISSED");
+               str = _bluetooth_pb_vcard_call(call_log_id, filter, format, "MISSED");
                break;
        case TELECOM_CCH: {
                contacts_record_h record = NULL;
@@ -665,13 +737,13 @@ static GVariant *__bt_pb_get_phonebook_entry(PbAgentData *agent,
                gint status;
 
                status = contacts_db_get_record(_contacts_phone_log._uri,
-                               handle, &record);
+                               call_log_id, &record);
 
                if (status != CONTACTS_ERROR_NONE)
                        break;
 
                attr = __bluetooth_pb_phone_log_get_log_type(record);
-               str = _bluetooth_pb_vcard_call(handle, filter, format, attr);
+               str = _bluetooth_pb_vcard_call(call_log_id, filter, format, attr);
 
                contacts_record_destroy(record, TRUE);
                break;
@@ -694,6 +766,7 @@ static GVariant *__bt_pb_get_phonebook_entry(PbAgentData *agent,
                return NULL;
        }
 
+end:
        phonebook_entry = g_variant_new("(s)", str);
 
        g_free(str);
@@ -771,7 +844,7 @@ static GVariant *__bt_pb_get_phonebook_entries_find_at(PbAgentData *agent,
        PhoneBookType pb_type = TELECOM_NONE;
        GVariantBuilder *builder;
 
-       DBG("command: %s, find text: %s\n", command, find_text);
+       DBG_SECURE("command: %s, find text: %s\n", command, find_text);
 
        __bluetooth_pb_agent_timeout_add_seconds(agent);
 
@@ -1427,11 +1500,17 @@ static void __bluetooth_pb_get_vcards(PbAgentData *agent, PhoneBookType pb_type,
                /* for owner */
                if (list_start_offset == 0) {
                        char *vcard;
-
-                       vcard = _bluetooth_pb_vcard_contact_owner(agent->tel_number,
+                       if (agent->tel_number && g_strcmp0(agent->tel_number, "") != 0) {
+                               vcard = _bluetooth_pb_vcard_contact_owner(agent->tel_number,
                                                                filter, format);
-                       if (vcard)
+                       } else {
+                               vcard = _bluetooth_pb_add_owner_details(filter, format);
+                       }
+
+                       if (vcard) {
                                g_variant_builder_add(vcards, "s", vcard);
+                               g_free(vcard);
+                       }
 
                        offset = 0;
 
@@ -1531,8 +1610,10 @@ static void __bluetooth_pb_get_vcards(PbAgentData *agent, PhoneBookType pb_type,
                                                                format, attr);
                        }
 
-                       if (vcard)
+                       if (vcard) {
                                g_variant_builder_add(vcards, "s", vcard);
+                               g_free(vcard);
+                       }
 
                } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
                contacts_list_destroy(record_list, TRUE);
@@ -1623,11 +1704,13 @@ static void __bluetooth_pb_get_contact_list(PbAgentData *agent,
 }
 
 static void __bluetooth_pb_get_phone_log_list(PbAgentData *agent,
-                       contacts_query_h query, GVariantBuilder *builder)
+                       contacts_query_h query, GVariantBuilder *builder,  PhoneBookType pb_type)
 {
        FN_START;
        contacts_list_h record_list = NULL;
        gint status;
+       int handle = 0;
+       int count = 0;
 
        status = contacts_db_get_records_with_query(query, -1, -1,
                                                                &record_list);
@@ -1635,6 +1718,43 @@ static void __bluetooth_pb_get_phone_log_list(PbAgentData *agent,
        if (status != CONTACTS_ERROR_NONE)
                return;
 
+       status = contacts_list_get_count(record_list, &count);
+       if (status != CONTACTS_ERROR_NONE)
+               goto done;
+
+       if (count == 0)
+               goto done;
+
+       /* Initialize Mapping Array */
+       switch (pb_type) {
+       case TELECOM_ICH:
+               g_free(mapping_ich);
+               count_ich = count;
+               mapping_ich = g_new(int, count_ich);
+               break;
+       case TELECOM_OCH:
+               g_free(mapping_och);
+               count_och = count;
+               mapping_och = g_new(int, count_och);
+               break;
+       case TELECOM_MCH:
+               g_free(mapping_mch);
+               count_mch = count;
+               mapping_mch = g_new(int, count_mch);
+               break;
+       case TELECOM_CCH:
+               g_free(mapping_cch);
+               count_cch = count;
+               mapping_cch = g_new(int, count_cch);
+               break;
+       case TELECOM_PB:
+       case TELECOM_NONE:
+#ifdef TIZEN_FEATURE_BT_PBAP_SIM
+       case SIM_PB:
+#endif
+               break;
+       }
+
        status = contacts_list_first(record_list);
 
        if (status != CONTACTS_ERROR_NONE) {
@@ -1668,14 +1788,17 @@ static void __bluetooth_pb_get_phone_log_list(PbAgentData *agent,
                        contacts_record_get_str_p(record,
                                        _contacts_phone_log.address, &number);
 
+                       handle++;
+                       add_log_id(id, handle, pb_type);
                        __bluetooth_pb_list_ptr_array_add(builder, name,
-                                                               number, id);
+                                                               number, handle);
 
                        g_free(name);
                }
 
        } while (contacts_list_next(record_list) == CONTACTS_ERROR_NONE);
 
+done:
        contacts_list_destroy(record_list, TRUE);
        FN_END;
 }
@@ -1698,19 +1821,19 @@ static void __bluetooth_pb_get_list(PbAgentData *agent, PhoneBookType pb_type,
                break;
        case TELECOM_ICH:
                query = __bluetooth_pb_query_phone_log_incoming();
-               __bluetooth_pb_get_phone_log_list(agent, query, builder);
+               __bluetooth_pb_get_phone_log_list(agent, query, builder, pb_type);
                break;
        case TELECOM_OCH:
                query = __bluetooth_pb_query_phone_log_outgoing();
-               __bluetooth_pb_get_phone_log_list(agent, query, builder);
+               __bluetooth_pb_get_phone_log_list(agent, query, builder, pb_type);
                break;
        case TELECOM_MCH:
                query = __bluetooth_pb_query_phone_log_missed();
-               __bluetooth_pb_get_phone_log_list(agent, query, builder);
+               __bluetooth_pb_get_phone_log_list(agent, query, builder, pb_type);
                break;
        case TELECOM_CCH:
                query = __bluetooth_pb_query_phone_log_combined();
-               __bluetooth_pb_get_phone_log_list(agent, query, builder);
+               __bluetooth_pb_get_phone_log_list(agent, query, builder, pb_type);
                break;
 #ifdef TIZEN_FEATURE_BT_PBAP_SIM
        case SIM_PB:
@@ -1886,7 +2009,7 @@ static void __bluetooth_pb_get_list_number(PbAgentData *agent,
        DBG("type = %d", pb_type);
        switch (pb_type) {
        case TELECOM_PB:
-               query = __bluetooth_pb_query_person(PBAP_ADDRESSBOOK_PHONE);
+               query = __bluetooth_pb_query_person_number();
                __bluetooth_pb_get_contact_list_number(agent, query,
                                start_index, end_index, builder);
                break;
@@ -2186,7 +2309,7 @@ static void __bluetooth_pb_tel_callback(TapiHandle *handle, int result,
        FN_END;
 }
 
-static gboolean __bt_pb_destroy_agent()
+static gboolean __bt_pb_destroy_agent(void)
 {
        FN_START;
        g_main_loop_quit(g_mainloop);
@@ -2395,8 +2518,15 @@ int main(void)
 
        __bt_pb_dbus_deinit(agent);
 
+       g_free(mapping_cch);
+       g_free(mapping_ich);
+       g_free(mapping_och);
+       g_free(mapping_mch);
        g_free(agent);
 
+       if (g_mainloop)
+               g_main_loop_unref(g_mainloop);
+
        DBG("Terminate Bluetooth PBAP agent");
        FN_END;
        return ret;
index e7127a2..1090814 100644 (file)
@@ -40,6 +40,7 @@
 #define ERR(fmt, args...) SLOGE(fmt, ##args)
 
 #define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
+#define INFO_SECURE(fmt, args...) SECURE_SLOGI(fmt, ##args)
 #define ERR_SECURE(fmt, args...) SECURE_SLOGE(fmt, ##args)
 
 #ifdef FUCNTION_CALLS
index dd19d63..f369ae7 100644 (file)
@@ -44,6 +44,8 @@
 #define VCARD_FORMAT_2_1 0x0
 #define VCARD_FORMAT_3_0 0x1
 
+#define VCARD_ALL_FIELDS 0xFFFFFFFFFFFFFFFFull
+
 #define VCARD_VERSION  (0x1)
 #define VCARD_FN       (0x1 << 1)
 #define VCARD_N                (0x1 << 2)
@@ -955,7 +957,7 @@ static bool __bt_pbap_image_util_supported_jpeg_colorspace_cb(
        }
 
        if (g_file_get_contents(info->dest, &contents, &len, NULL) == FALSE) {
-               ERR("can not read file contents:%s\n", info->dest);
+               ERR_SECURE("can not read file contents:%s\n", info->dest);
                goto done;
        }
 
@@ -1010,7 +1012,7 @@ static void __bluetooth_pb_vcard_append_photo_v21(GString *string,
 
                if (g_file_get_contents(filename, &contents, &len, NULL) ==
                                                                        FALSE) {
-                       ERR("can not read file contents:%s\n", filename);
+                       ERR_SECURE("can not read file contents:%s\n", filename);
                        g_free(param);
                        return;
                }
@@ -1030,7 +1032,7 @@ static void __bluetooth_pb_vcard_append_photo_v21(GString *string,
                g_strlcat(dest_thumb_path, PBAP_THMB_PATH,
                                                sizeof(dest_thumb_path));
                g_strlcat(dest_thumb_path, ptr, sizeof(dest_thumb_path));
-               DBG("Thumbnail path is = %s", dest_thumb_path);
+               DBG_SECURE("Thumbnail path is = %s", dest_thumb_path);
        }
        DBG_SECURE("filename = %s Thumbnail path is = %s", filename, dest_thumb_path);
        img_info.src = filename;
@@ -1686,10 +1688,10 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v21(gint person_id,
                return NULL;;
        }
 
+       /* All fields are sent if no filter is used */
+       DBG("FILTER: [0x%llx]", f);
        if (f == 0)
-               f = ~f;
-
-       DBG("filter[%x]\n", filter);
+               f = VCARD_ALL_FIELDS;
 
        str = g_string_new("BEGIN:VCARD\r\nVERSION:2.1\r\n");
 
@@ -1776,7 +1778,7 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
        GString *str = NULL;
 
        gint status;
-
+       guint64 f = filter;
        const gchar *name = first_name;
        gchar *vcard = NULL;
 
@@ -1792,6 +1794,11 @@ static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
        if (status != CONTACTS_ERROR_NONE)
                return NULL;
 
+       /* All fields are sent if no filter is used */
+       DBG("FILTER: [0x%llx]", f);
+       if (f == 0)
+               f = VCARD_ALL_FIELDS;
+
        /* removing the END:VCARD\r\n" to append extra data */
        str = g_string_new_len(vcard, (strlen(vcard)-11));
        g_free(vcard);
@@ -2690,6 +2697,145 @@ gchar *_bluetooth_pb_vcard_contact_owner(const gchar *number,
        return g_string_free(str, FALSE);
 }
 
+static gboolean __bluetooth_pb_contact_tel_type(contacts_number_type_e type)
+{
+       FN_START;
+       int match_flag = CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_WORK |
+                       CONTACTS_NUMBER_TYPE_VOICE | CONTACTS_NUMBER_TYPE_FAX |
+                       CONTACTS_NUMBER_TYPE_MSG | CONTACTS_NUMBER_TYPE_CELL |
+                       CONTACTS_NUMBER_TYPE_PAGER | CONTACTS_NUMBER_TYPE_BBS |
+                       CONTACTS_NUMBER_TYPE_MODEM | CONTACTS_NUMBER_TYPE_CAR |
+                       CONTACTS_NUMBER_TYPE_ISDN | CONTACTS_NUMBER_TYPE_VIDEO;
+
+       if (type & match_flag)
+               return true;
+
+       FN_END;
+       return false;
+}
+
+char *_bluetooth_pb_add_owner_details(guint64 filter, guint8 format)
+{
+       FN_START;
+       int err = CONTACTS_ERROR_NONE;
+       contacts_list_h owner_profile = NULL;
+       int count = 0;
+       contacts_record_h record = NULL;
+       contacts_record_h numberRecord = NULL;
+       int numberRecordIndex = 0;
+       int value = 0;
+       gchar *phone_number = NULL;
+       gchar *name = NULL;
+       GString *str = NULL;
+       GString *number_str = NULL;
+       gchar *fn;
+       gchar *tmp_str = NULL;
+
+       fn = _bluetooth_pb_owner_name();
+
+       err = contacts_db_get_all_records(_contacts_my_profile._uri, 0, 0, &owner_profile);
+       if (CONTACTS_ERROR_NONE != err) {
+               ERR("contacts_db_get_all_records() Failed(%d)", err);
+               goto card;
+       }
+
+       if (owner_profile == NULL) {
+               ERR("owner_profile does not exist!");
+               goto card;
+       }
+
+       contacts_list_get_count(owner_profile, &count);
+       if (count > 0) {
+               err = contacts_list_get_current_record_p(owner_profile, &record);
+               if (CONTACTS_ERROR_NONE != err) {
+                       ERR("contacts_list_get_current_record_p() Failed(%d)", err);
+                       contacts_list_destroy(owner_profile, true);
+                       goto card;
+               }
+
+               while (CONTACTS_ERROR_NONE == contacts_record_get_child_record_at_p(
+                                       record, _contacts_my_profile.number, numberRecordIndex,
+                                       &numberRecord)) {
+                       gchar *escaped = NULL;
+                       err = contacts_record_get_int(numberRecord, _contacts_number.type, &value);
+                       numberRecordIndex++;
+
+                       err = contacts_record_get_str_p(numberRecord, _contacts_number.number, &phone_number);
+                       if (CONTACTS_ERROR_NONE != err) {
+                               ERR("contacts_record_get_str_p() Failed(%d)", err);
+                               continue;
+                       }
+
+                       escaped = __bluetooth_pb_vcard_escape(phone_number);
+                       if (__bluetooth_pb_contact_tel_type(value)) {
+                               if (number_str == NULL)
+                                       number_str = g_string_new("");
+
+                               switch (format) {
+                               case VCARD_FORMAT_3_0:
+                                       __bluetooth_pb_vcard_append_v30(number_str, "TEL",
+                                                       "TYPE=CELL", escaped);
+                                       break;
+                               case VCARD_FORMAT_2_1:
+                               default:
+                                       __bluetooth_pb_vcard_append_qp_encode_v21(number_str,
+                                                       "TEL", "CELL", escaped);
+                                       break;
+                               }
+                       }
+                       g_free(escaped);
+               }
+
+               err =  contacts_record_get_str(record, _contacts_my_profile.display_name, &fn);
+               if (CONTACTS_ERROR_NONE != err)
+                       ERR("contacts_record_get_str_p() Failed(%d)", err);
+       }
+
+       err = contacts_list_destroy(owner_profile, TRUE);
+       if (CONTACTS_ERROR_NONE != err)
+               ERR("contacts_list_destroy() Failed(%d)", err);
+
+card:
+       name = g_strdup_printf("%s;;;;", fn);
+       str = g_string_new("BEGIN:VCARD\r\n");
+       switch (format) {
+       case VCARD_FORMAT_3_0:
+               g_string_append(str, "VERSION:3.0\r\n");
+               __bluetooth_pb_vcard_append_v30(str, "N", NULL, name);
+               __bluetooth_pb_vcard_append_v30(str, "FN", NULL, fn);
+
+               if (number_str) {
+                       tmp_str = g_string_free(number_str, FALSE);
+                       g_string_append_printf(str, "%s", tmp_str);
+                       g_free(tmp_str);
+               }
+
+               break;
+       case VCARD_FORMAT_2_1:
+       default:
+               g_string_append(str, "VERSION:2.1\r\n");
+               __bluetooth_pb_vcard_append_qp_encode_v21(str, "N", NULL, name);
+
+               if (filter == 0 || (filter & VCARD_FN))
+                       __bluetooth_pb_vcard_append_qp_encode_v21(str, "FN", NULL, fn);
+
+               if (number_str) {
+                       tmp_str = g_string_free(number_str, FALSE);
+                       g_string_append_printf(str, "%s", tmp_str);
+                       g_free(tmp_str);
+               }
+
+               break;
+       }
+       g_string_append(str, "END:VCARD\r\n");
+
+       g_free(fn);
+       g_free(name);
+       DBG_SECURE("OWNER's CARD: [%s]", str->str);
+       FN_END;
+       return g_string_free(str, FALSE);
+}
+
 gchar *_bluetooth_pb_vcard_call(gint phonelog_id,
                                guint64 filter,
                                guint8 format,
index 97fb014..e9ab7c1 100644 (file)
@@ -25,6 +25,7 @@
 #define __DEF_BT_PB_VCARD_H_
 
 #include <glib.h>
+#include <contacts_record.h>
 
 #define SIM_ADDRESSBOOK_PREFIX "http://tizen.org/addressbook/sim"
 
@@ -44,6 +45,8 @@ gchar *_bluetooth_pb_vcard_contact_owner(const gchar *number,
                                        guint64 filter,
                                        guint8 format);
 
+char *_bluetooth_pb_add_owner_details(guint64 filter, guint8 format);
+
 gchar *_bluetooth_pb_vcard_call(gint phonelog_id,
                                guint64 filter,
                                guint8 format,