4 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
26 #include <dbus/dbus-glib.h>
32 #include "bluetooth_pb_vcard.h"
34 #define BT_PB_AGENT "BT_PB_AGENT"
35 #define DBG(fmt, args...) SLOG(LOG_DEBUG, BT_PB_AGENT, "%s():%d "fmt, __func__, __LINE__, ##args)
36 #define ERR(fmt, args...) SLOG(LOG_ERROR, BT_PB_AGENT, "%s():%d "fmt, __func__, __LINE__, ##args)
38 #define VCARD_FORMAT_2_1 0x0
39 #define VCARD_FORMAT_3_0 0x1
41 #define VCARD_VERSION (0x1)
42 #define VCARD_FN (0x1 << 1)
43 #define VCARD_N (0x1 << 2)
44 #define VCARD_PHOTO (0x1 << 3)
45 #define VCARD_BDAY (0x1 << 4)
46 #define VCARD_ADR (0x1 << 5)
47 #define VCARD_LABEL (0x1 << 6) /* not supported */
48 #define VCARD_TEL (0x1 << 7)
49 #define VCARD_EMAIL (0x1 << 8)
50 #define VCARD_MAILER (0x1 << 9) /* not supported */
51 #define VCARD_TZ (0x1 << 10) /* not supported */
52 #define VCARD_GEO (0x1 << 11) /* not supported */
53 #define VCARD_TITLE (0x1 << 12)
54 #define VCARD_ROLE (0x1 << 13)
55 #define VCARD_LOGO (0x1 << 14) /* not supported */
56 #define VCARD_AGENT (0x1 << 15) /* not supported */
57 #define VCARD_ORG (0x1 << 16)
58 #define VCARD_NOTE (0x1 << 17)
59 #define VCARD_REV (0x1 << 18)
60 #define VCARD_SOUND (0x1 << 19) /* not supported */
61 #define VCARD_URL (0x1 << 20)
62 #define VCARD_UID (0x1 << 21)
63 #define VCARD_KEY (0x1 << 22) /* not supported */
64 #define VCARD_NICKNAME (0x1 << 23)
65 #define VCARD_CATEGORIES (0x1 << 24) /* not supported */
66 #define VCARD_PROID (0x1 << 25) /* not supported */
67 #define VCARD_CLASS (0x1 << 26) /* not supported */
68 #define VCARD_SORT_STRING (0x1 << 27) /* not supported */
70 #define VCARD_X_IRMC_CALL_DATETIME (0x1 << 28)
73 #define LINEBREAK_LEN 75
75 static gchar *__bluetooth_pb_vcard_escape(const gchar *str);
77 static gchar *__bluetooth_pb_vcard_strv_concat(gchar **strv,
78 const gchar *delimeter);
80 static gboolean __bluetooth_pb_vcard_qp_encode_check(const gchar *str);
82 static gint __bluetooth_pb_vcard_qp_encode_strlen(const gchar *str,
85 static void __bluetooth_pb_vcard_qp_encode_append_to_hex(GString *string,
90 static void __bluetooth_pb_vcard_qp_encode_append_printable_c(GString *string,
94 static void __bluetooth_pb_vcard_qp_encode_append(GString *string,
99 static gchar *__bluetooth_pb_vcard_qp_encode(const gchar *str);
101 static void __bluetooth_pb_vcard_append_param_v21(GString *string,
104 static void __bluetooth_pb_vcard_append_qp_encode_v21(GString *string,
109 static void __bluetooth_pb_vcard_append_base64_encode_v21(GString *string,
116 static void __bluetooth_pb_vcard_append_n_v21(GString *string,
117 contacts_record_h contact);
119 static void __bluetooth_pb_vcard_append_tel_v21(GString *string,
120 contacts_record_h conatct);
122 static void __bluetooth_pb_vcard_append_fn_v21(GString *string,
123 contacts_record_h person);
125 static void __bluetooth_pb_vcard_append_photo_v21(GString *string,
126 contacts_record_h person);
128 static void __bluetooth_pb_vcard_append_bday_v21(GString *string,
129 contacts_record_h contact);
131 static void __bluetooth_pb_vcard_append_adr_v21(GString *string,
132 contacts_record_h contact);
134 static void __bluetooth_pb_vcard_append_email_v21(GString *string,
135 contacts_record_h contact);
137 static void __bluetooth_pb_vcard_append_title_v21(GString *string,
138 contacts_record_h contact);
140 static void __bluetooth_pb_vcard_append_role_v21(GString *string,
141 contacts_record_h contact);
143 static void __bluetooth_pb_vcard_append_org_v21(GString *string,
144 contacts_record_h contact);
146 static void __bluetooth_pb_vcard_append_note_v21(GString *string,
147 contacts_record_h contact);
149 static void __bluetooth_pb_vcard_append_rev_v21(GString *string,
150 contacts_record_h contact);
152 static void __bluetooth_pb_vcard_append_url_v21(GString *string,
153 contacts_record_h contact);
155 static void __bluetooth_pb_vcard_append_uid_v21(GString *string,
156 contacts_record_h contact);
158 static void __bluetooth_pb_vcard_append_v30(GString *string,
163 static void __bluetooth_pb_vcard_remove_v30(GString *string,
164 const gchar *property_name);
166 static gchar *__bluetooth_pb_vcard_filter_v30(const gchar *vcard,
169 static gchar *__bluetooth_pb_vcard_real_contact_valist_v21(gint person_id,
172 const gchar *first_name,
175 static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
178 const gchar *first_name,
181 static gchar *__bluetooth_pb_vcard_real_contact_with_properties(gint person_id,
185 const gchar *first_name,
188 static gchar *__bluetooth_pb_vcard_real_call_v21(gint phonelog_id,
192 static gchar *__bluetooth_pb_vcard_real_call_v30(gint phonelog_id,
196 static gchar *__bluetooth_pb_vcard_real_call(gint phonelog_id,
201 static gchar **__bluetooth_pb_contact_add_field_str(contacts_record_h record,
205 static gchar **__bluetooth_pb_contact_tel_param(contacts_record_h number);
207 static gchar *__bluetooth_pb_contact_photo_type(const gchar *filename);
209 static gchar **__bluetooth_pb_contact_addr(contacts_record_h address);
211 static gchar **__bluetooth_pb_contact_addr_param(contacts_record_h address);
213 static gchar *__bluetooth_pb_phonelog_datetime(gint phonelog_id);
215 static gchar *__bluetooth_pb_name_from_contact(contacts_record_h contact);
217 static gchar *__bluetooth_pb_number_from_contact(contacts_record_h contact);
219 static gint __bluetooth_pb_person_id_from_phonelog_id(gint phonelog_id);
222 static gchar *__bluetooth_pb_vcard_escape(const gchar *str)
232 escaped = g_string_new(NULL);
237 while (*pos != '\0') {
239 g_string_append_len(escaped, st, (pos - st));
240 g_string_append(escaped, "\\;");
250 g_string_append_len(escaped, st, (pos - st));
251 return g_string_free(escaped, FALSE);
254 static gchar *__bluetooth_pb_vcard_strv_concat(gchar **strv,
255 const gchar *separator)
257 GString *string = g_string_new(NULL);
260 for (i = 0; strv[i] != NULL; i++) {
262 g_string_append(string, ";");
264 g_string_append(string, strv[i]);
267 return g_string_free(string, FALSE);
270 static gboolean __bluetooth_pb_vcard_qp_encode_check(const gchar *str)
278 while (*pos != '\0') {
279 /* ascii code ' ' : 32, '~' : 126 */
280 if ((guchar)*pos < ' ' || (guchar)*pos > '~')
288 /* get string length, which convert to quoted-printable encoding */
289 static gint __bluetooth_pb_vcard_qp_encode_strlen(const gchar *str,
300 if (strlen(str) < len )
305 while (*pos != '\0' && (((pos - str) < length) || length < 0)) {
306 if ((guchar)*pos == '\t') {
312 if ((guchar)*pos < ' ' || (guchar)*pos == '=') {
318 /* check no-ascii utf-8 character */
319 if ((guchar)*pos > '~') {
323 next = g_utf8_next_char(pos);
325 count += QP_ENC_LEN * (next - pos);
337 /* convert to quoted printable code */
338 static void __bluetooth_pb_vcard_qp_encode_append_to_hex(GString *string,
345 if (str == NULL || len == 0)
348 /* add soft linebreak when it exceed */
349 if ((*line_pos + (QP_ENC_LEN * len) > LINEBREAK_LEN)) {
350 g_string_append(string, "=\r\n");
354 for (i = 0; i < len; i++) {
355 g_string_append_printf(string, "=%02X", (guchar)*(str+i));
356 *line_pos += QP_ENC_LEN;
360 /* append plain visiable ascii character */
361 static void __bluetooth_pb_vcard_qp_encode_append_printable_c(GString *string,
365 /* add soft linebreak when it exceed */
366 if (*line_pos + 1 > LINEBREAK_LEN) {
367 g_string_append(string, "=\r\n");
370 g_string_append_c(string, ch);
374 static void __bluetooth_pb_vcard_qp_encode_append(GString *string,
387 encode_len = __bluetooth_pb_vcard_qp_encode_strlen(str, len);
389 /* add soft linebreak when it exceed */
390 if (((*line_pos + encode_len) > LINEBREAK_LEN) && (*line_pos > 1)) {
391 g_string_append(string, "=\r\n");
395 length = strlen(str);
402 pos = ((gchar *)str) + i;
404 /* converts invisiable character and escape character '=' to quoted-printable */
405 if ((guchar)*pos != '\t' &&
406 ((guchar)*pos < ' ' || (guchar)*pos == '=')) {
407 __bluetooth_pb_vcard_qp_encode_append_to_hex(string, pos,
414 /* converts non-ascii utf-8 character to quoted-printable */
415 if ((guchar)*pos > '~') {
419 next = g_utf8_next_char(pos);
422 __bluetooth_pb_vcard_qp_encode_append_to_hex(string, pos,
429 __bluetooth_pb_vcard_qp_encode_append_printable_c(string, *pos, line_pos);
434 static gchar* __bluetooth_pb_vcard_qp_encode(const gchar *str)
446 enc = g_string_new(NULL);
448 st_pos = (gchar *)str;
451 while (*pos != '\0') {
452 /* split string with given delimeter ' ' or '\t' */
453 if (*pos == ' ' || *pos == '\t') {
454 __bluetooth_pb_vcard_qp_encode_append(enc, st_pos,
455 (pos - st_pos), &line_pos);
463 /* split string with given delimeter '\r', '\n' or '\r\n' - newline */
464 if (*pos == '\r' || *pos == '\n' ) {
465 __bluetooth_pb_vcard_qp_encode_append(enc, st_pos,
466 (pos - st_pos), &line_pos);
468 /* converts newline to qp_encode with soft linebreak
469 for example, converts \r\n to =0D=0A=\r\n */
470 __bluetooth_pb_vcard_qp_encode_append_to_hex(enc, "\r\n",
472 g_string_append(enc, "=\r\n ");
476 if (*pos == '\r' && *(pos + 1) == '\n')
489 __bluetooth_pb_vcard_qp_encode_append(enc, st_pos,
490 (pos - st_pos), &line_pos);
492 return g_string_free(enc, FALSE);
495 static void __bluetooth_pb_vcard_append_param_v21(GString *string,
503 pos = (gchar *)param;
505 /* trim ';' on first */
506 while (*pos != '\0') {
514 g_string_append_printf(string, ";%s", pos);
517 static void __bluetooth_pb_vcard_append_qp_encode_v21(GString *string,
522 GString *property = NULL;
527 property = g_string_new(name);
528 __bluetooth_pb_vcard_append_param_v21(property, param);
530 if (__bluetooth_pb_vcard_qp_encode_check(value)) {
533 __bluetooth_pb_vcard_append_param_v21(property,
535 __bluetooth_pb_vcard_append_param_v21(property,
536 "ENCODING=QUOTED-PRINTABLE");
537 g_string_append(property, ":");
539 enc = __bluetooth_pb_vcard_qp_encode(value);
542 g_string_append(property, enc);
546 g_string_append(property, ":");
548 g_string_append(property , value);
551 g_string_append_printf(string, "%s\r\n", property->str);
553 g_string_free(property, TRUE);
557 static void __bluetooth_pb_vcard_append_base64_encode_v21(GString *string,
569 g_string_append(string, name);
571 __bluetooth_pb_vcard_append_param_v21(string, param);
572 __bluetooth_pb_vcard_append_param_v21(string, "ENCODING=BASE64");
574 g_string_append(string, ":");
579 enc = g_base64_encode((const guchar *)value, len);
582 if (folding == FALSE) {
583 g_string_append(string, enc);
585 gint enc_len = strlen(enc);
588 /* count ' ' size for folding */
589 gint fline_len = LINEBREAK_LEN -1;
591 for (i = 0; (i * fline_len) < enc_len; i++) {
592 g_string_append(string, "\r\n ");
593 if ((i * fline_len) + fline_len > enc_len)
594 g_string_append(string, enc + (i * fline_len));
596 g_string_append_len(string, enc + (i * fline_len), fline_len);
599 /* some application requires more \r\n */
600 g_string_append(string, "\r\n");
602 g_string_append(string, "\r\n");
607 static void __bluetooth_pb_vcard_append_n_v21(GString *string,
608 contacts_record_h contact)
612 str = __bluetooth_pb_name_from_contact(contact);
613 __bluetooth_pb_vcard_append_qp_encode_v21(string, "N", NULL, str);
618 static void __bluetooth_pb_vcard_append_tel_v21(GString *string,
619 contacts_record_h contact)
626 status = contacts_record_get_child_record_count(contact,
627 _contacts_contact.number,
630 if (status != CONTACTS_ERROR_NONE)
633 for (i = 0; i < count; i++) {
634 contacts_record_h number = NULL;
636 gchar **paramv = NULL;
640 gchar *escaped = NULL;
642 status = contacts_record_get_child_record_at_p(contact,
643 _contacts_contact.number, i, &number);
645 if (status != CONTACTS_ERROR_NONE)
648 status = contacts_record_get_str_p(number,
649 _contacts_number.number,
652 if (status != CONTACTS_ERROR_NONE)
655 escaped = __bluetooth_pb_vcard_escape(tel);
657 paramv = __bluetooth_pb_contact_tel_param(number);
658 param = __bluetooth_pb_vcard_strv_concat(paramv, ";");
662 __bluetooth_pb_vcard_append_qp_encode_v21(string, "TEL", param, escaped);
669 static void __bluetooth_pb_vcard_append_fn_v21(GString *string,
670 contacts_record_h person)
677 status = contacts_record_get_str_p(person,
678 _contacts_person.display_name,
681 if (status != CONTACTS_ERROR_NONE)
684 fn = __bluetooth_pb_vcard_escape(tmp);
686 __bluetooth_pb_vcard_append_qp_encode_v21(string, "FN", NULL, fn);
691 static void __bluetooth_pb_vcard_append_photo_v21(GString *string,
692 contacts_record_h person)
698 gchar *filename = NULL;
702 gchar *contents = NULL;
705 status = contacts_record_get_str_p(person,
706 _contacts_person.image_thumbnail_path,
709 if (status != CONTACTS_ERROR_NONE)
712 type = __bluetooth_pb_contact_photo_type(filename);
715 param = g_strdup_printf("TYPE=%s", type);
719 if (g_file_get_contents(filename, &contents, &len, NULL) == FALSE) {
720 ERR("can not read file contents:%s\n", filename);
724 __bluetooth_pb_vcard_append_base64_encode_v21(string,
725 "PHOTO", param, contents, len, TRUE);
731 static void __bluetooth_pb_vcard_append_bday_v21(GString *string,
732 contacts_record_h contact)
739 status = contacts_record_get_child_record_count(contact,
740 _contacts_contact.event, &count);
742 if (status != CONTACTS_ERROR_NONE)
745 for (i = 0; i < count; i++) {
746 contacts_record_h event = NULL;
752 contacts_event_type_e type;
754 status = contacts_record_get_child_record_at_p(contact,
755 _contacts_contact.event, i, &event);
757 if (status != CONTACTS_ERROR_NONE)
760 status = contacts_record_get_int(event,
761 _contacts_event.type,
764 if (status != CONTACTS_ERROR_NONE)
767 if (type != CONTACTS_EVENT_TYPE_BIRTH)
770 status = contacts_record_get_int(event,
771 _contacts_event.date,
774 if (status != CONTACTS_ERROR_NONE)
780 bday = g_strdup_printf("%04d-%02d-%02d",
781 (date/10000), (date/100)%100, date%100);
782 __bluetooth_pb_vcard_append_qp_encode_v21(string, "BDAY",
788 static void __bluetooth_pb_vcard_append_adr_v21(GString *string,
789 contacts_record_h contact)
796 status = contacts_record_get_child_record_count(contact,
797 _contacts_contact.address,
800 if (status != CONTACTS_ERROR_NONE)
803 for (i = 0; i < count; i++) {
804 contacts_record_h address = NULL;
812 status = contacts_record_get_child_record_at_p(contact,
813 _contacts_contact.address, i, &address);
815 if (status != CONTACTS_ERROR_NONE)
818 addrv = __bluetooth_pb_contact_addr(address);
823 addr = __bluetooth_pb_vcard_strv_concat(addrv, ";");
826 paramv = __bluetooth_pb_contact_addr_param(address);
827 param = __bluetooth_pb_vcard_strv_concat(paramv, ";");
830 __bluetooth_pb_vcard_append_qp_encode_v21(string, "ADR",
838 static void __bluetooth_pb_vcard_append_email_v21(GString *string,
839 contacts_record_h contact)
846 status = contacts_record_get_child_record_count(contact,
847 _contacts_contact.email,
850 if (status != CONTACTS_ERROR_NONE)
853 for (i = 0; i < count; i++) {
854 contacts_record_h email = NULL;
859 status = contacts_record_get_child_record_at_p(contact,
860 _contacts_contact.email, i, &email);
862 if (status != CONTACTS_ERROR_NONE)
865 status = contacts_record_get_str_p(email,
866 _contacts_email.email,
869 if (status != CONTACTS_ERROR_NONE)
872 escaped = __bluetooth_pb_vcard_escape(tmp);
873 __bluetooth_pb_vcard_append_qp_encode_v21(string, "EMAIL", NULL, escaped);
879 static void __bluetooth_pb_vcard_append_title_v21(GString *string,
880 contacts_record_h contact)
887 status = contacts_record_get_child_record_count(contact,
888 _contacts_contact.company,
891 if (status != CONTACTS_ERROR_NONE)
894 for (i = 0; i < count; i++) {
895 contacts_record_h company = NULL;
900 status = contacts_record_get_child_record_at_p(contact,
901 _contacts_contact.company,i, &company);
903 if (status != CONTACTS_ERROR_NONE)
906 status = contacts_record_get_str_p(company,
907 _contacts_company.job_title,
910 if (status != CONTACTS_ERROR_NONE)
913 escaped = __bluetooth_pb_vcard_escape(title);
914 __bluetooth_pb_vcard_append_qp_encode_v21(string, "TITLE", NULL, escaped);
920 static void __bluetooth_pb_vcard_append_role_v21(GString *string,
921 contacts_record_h contact)
928 status = contacts_record_get_child_record_count(contact,
929 _contacts_contact.company,
932 if (status != CONTACTS_ERROR_NONE)
935 for (i = 0; i < count; i++) {
936 contacts_record_h company = NULL;
941 status = contacts_record_get_child_record_at_p(contact,
942 _contacts_contact.company, i, &company);
944 if (status != CONTACTS_ERROR_NONE)
947 status = contacts_record_get_str_p(company,
948 _contacts_company.role,
951 if (status != CONTACTS_ERROR_NONE)
954 escaped = __bluetooth_pb_vcard_escape(role);
955 __bluetooth_pb_vcard_append_qp_encode_v21(string, "ROLE", NULL, escaped);
961 static void __bluetooth_pb_vcard_append_org_v21(GString *string,
962 contacts_record_h contact)
969 status = contacts_record_get_child_record_count(contact,
970 _contacts_contact.company,
973 if (status != CONTACTS_ERROR_NONE)
976 for (i = 0; i < count; i++) {
977 contacts_record_h company = NULL;
982 gchar *department = NULL;
985 gint department_status;
987 status = contacts_record_get_child_record_at_p(contact,
988 _contacts_contact.company, i, &company);
990 if (status != CONTACTS_ERROR_NONE)
994 name_status = contacts_record_get_str_p(company,
995 _contacts_company.name,
998 department_status = contacts_record_get_str_p(company,
999 _contacts_company.department,
1002 if ((name_status != CONTACTS_ERROR_NONE) &&
1003 (department_status != CONTACTS_ERROR_NONE))
1006 str = g_string_new(NULL);
1011 escaped = __bluetooth_pb_vcard_escape(name);
1012 g_string_append(str, escaped);
1016 g_string_append(str, ";");
1021 escaped = __bluetooth_pb_vcard_escape(department);
1022 g_string_append(str, escaped);
1026 __bluetooth_pb_vcard_append_qp_encode_v21(string, "ORG", NULL, str->str);
1028 g_string_free(str, TRUE);
1033 static void __bluetooth_pb_vcard_append_note_v21(GString *string,
1034 contacts_record_h contact)
1041 status = contacts_record_get_child_record_count(contact,
1042 _contacts_contact.note,
1045 if (status != CONTACTS_ERROR_NONE)
1048 for (i = 0; i < count; i++) {
1049 contacts_record_h note = NULL;
1054 status = contacts_record_get_child_record_at_p(contact,
1055 _contacts_contact.note, i, ¬e);
1057 if (status != CONTACTS_ERROR_NONE)
1060 status = contacts_record_get_str_p(note,
1061 _contacts_note.note,
1064 if (status != CONTACTS_ERROR_NONE)
1067 escaped = __bluetooth_pb_vcard_escape(tmp);
1068 __bluetooth_pb_vcard_append_qp_encode_v21(string, "NOTE", NULL, escaped);
1074 static void __bluetooth_pb_vcard_append_rev_v21(GString *string,
1075 contacts_record_h contact)
1083 status = contacts_record_get_int(contact,
1084 _contacts_contact.changed_time,
1087 if (status != CONTACTS_ERROR_NONE)
1093 gmtime_r((const time_t*)(&time), &result);
1095 rev = g_strdup_printf("%04d-%02d-%02dT%02d:%02d:%02dZ",
1096 (1900 + result.tm_year), (1 + result.tm_mon), result.tm_mday,
1097 result.tm_hour, result.tm_min, result.tm_sec);
1099 __bluetooth_pb_vcard_append_qp_encode_v21(string, "REV", NULL, rev);
1104 static void __bluetooth_pb_vcard_append_url_v21(GString *string,
1105 contacts_record_h contact)
1112 status = contacts_record_get_child_record_count(contact,
1113 _contacts_contact.url,
1116 if (status != CONTACTS_ERROR_NONE)
1119 for (i = 0; i < count; i++) {
1120 contacts_record_h url = NULL;
1125 status = contacts_record_get_child_record_at_p(contact,
1126 _contacts_contact.url, i, &url);
1128 if (status != CONTACTS_ERROR_NONE)
1134 status = contacts_record_get_str_p(url,
1138 if (status != CONTACTS_ERROR_NONE)
1141 escaped = __bluetooth_pb_vcard_escape(tmp);
1142 __bluetooth_pb_vcard_append_qp_encode_v21(string, "URL", NULL, escaped);
1148 static void __bluetooth_pb_vcard_append_uid_v21(GString *string,
1149 contacts_record_h contact)
1156 status = contacts_record_get_str_p(contact,
1157 _contacts_contact.uid,
1160 if (status != CONTACTS_ERROR_NONE)
1163 escaped = __bluetooth_pb_vcard_escape(uid);
1164 __bluetooth_pb_vcard_append_qp_encode_v21(string, "UID", NULL, escaped);
1169 static void __bluetooth_pb_vcard_append_v30(GString *string,
1179 g_string_append(string, name);
1182 g_string_append_printf(string, ";%s", param);
1184 g_string_append(string, ":");
1187 g_string_append(string, value);
1189 g_string_append(string, "\r\n");
1192 static void __bluetooth_pb_vcard_remove_v30(GString *string,
1193 const gchar *property_name)
1196 gchar *st_pos = NULL;
1198 gboolean matched = FALSE;
1200 if(string == NULL || property_name == NULL)
1205 while(*pos != '\0') {
1206 if (matched == FALSE) {
1207 if (g_ascii_strncasecmp(pos, "\r\n", 2) == 0) {
1213 attrlen = strlen(property_name);
1214 if (g_ascii_strncasecmp(pos, property_name, attrlen) == 0) {
1217 if (*pos == ':' || *pos == ';') {
1226 if (g_ascii_strncasecmp(pos, "\r\n", 2) == 0) {
1229 if (*pos != ' ' && *pos != '\t') {
1230 /* +2 means move over \r\n */
1231 g_string_erase(string, (st_pos+2)-(string->str), pos-(st_pos +2));
1243 static gchar *__bluetooth_pb_vcard_filter_v30(const gchar *vcard,
1246 GString *string = NULL;
1251 string = g_string_new(vcard);
1253 if ((filter & VCARD_PHOTO) == 0)
1254 __bluetooth_pb_vcard_remove_v30(string, "PHOTO");
1256 if ((filter & VCARD_BDAY) == 0)
1257 __bluetooth_pb_vcard_remove_v30(string, "BDAY");
1259 if ((filter & VCARD_ADR) == 0 )
1260 __bluetooth_pb_vcard_remove_v30(string, "ADR");
1262 if ((filter & VCARD_EMAIL) == 0 )
1263 __bluetooth_pb_vcard_remove_v30(string, "EMAIL");
1265 if ((filter & VCARD_TITLE) == 0 )
1266 __bluetooth_pb_vcard_remove_v30(string, "TITLE");
1268 if ((filter & VCARD_ROLE) == 0 )
1269 __bluetooth_pb_vcard_remove_v30(string, "ROLE");
1271 if ((filter & VCARD_ORG) == 0 )
1272 __bluetooth_pb_vcard_remove_v30(string, "ORG");
1274 if ((filter & VCARD_NOTE) == 0 )
1275 __bluetooth_pb_vcard_remove_v30(string, "NOTE");
1277 if ((filter & VCARD_REV) == 0 )
1278 __bluetooth_pb_vcard_remove_v30(string, "REV");
1280 if ((filter & VCARD_URL) == 0 )
1281 __bluetooth_pb_vcard_remove_v30(string, "URL");
1283 if ((filter & VCARD_UID) == 0 )
1284 __bluetooth_pb_vcard_remove_v30(string, "UID");
1286 if ((filter & VCARD_NICKNAME) == 0 )
1287 __bluetooth_pb_vcard_remove_v30(string, "NICKNAME");
1289 return g_string_free(string, FALSE);
1292 static gchar *__bluetooth_pb_vcard_real_contact_valist_v21(gint person_id,
1295 const gchar *first_name,
1298 contacts_record_h person = NULL;
1299 contacts_record_h contact = NULL;
1301 GString *str = NULL;
1303 gint contact_id = 0;
1308 const gchar *name = first_name;
1310 status = contacts_db_get_record(_contacts_person._uri,
1314 if (status != CONTACTS_ERROR_NONE)
1317 status = contacts_record_get_int(person,
1318 _contacts_person.display_contact_id,
1321 if (status != CONTACTS_ERROR_NONE)
1324 status = contacts_db_get_record(_contacts_contact._uri,
1328 if (status != CONTACTS_ERROR_NONE) {
1329 contacts_record_destroy(person, TRUE);
1336 str = g_string_new("BEGIN:VCARD\r\nVERSION:2.1\r\n");
1338 /* N, TEL is default */
1339 __bluetooth_pb_vcard_append_n_v21(str, contact);
1341 if (phonelog_id > 0) {
1344 number = _bluetooth_pb_number_from_phonelog_id(phonelog_id);
1345 __bluetooth_pb_vcard_append_qp_encode_v21(str, "TEL", "X-0", number);
1350 __bluetooth_pb_vcard_append_tel_v21(str, contact);
1354 __bluetooth_pb_vcard_append_fn_v21(str, person);
1355 if (f & VCARD_PHOTO)
1356 __bluetooth_pb_vcard_append_photo_v21(str, person);
1358 __bluetooth_pb_vcard_append_bday_v21(str, contact);
1360 __bluetooth_pb_vcard_append_adr_v21(str, contact);
1361 if (f & VCARD_EMAIL)
1362 __bluetooth_pb_vcard_append_email_v21(str, contact);
1363 if (f & VCARD_TITLE)
1364 __bluetooth_pb_vcard_append_title_v21(str, contact);
1366 __bluetooth_pb_vcard_append_role_v21(str, contact);
1368 __bluetooth_pb_vcard_append_org_v21(str, contact);
1370 __bluetooth_pb_vcard_append_note_v21(str, contact);
1372 __bluetooth_pb_vcard_append_rev_v21(str, contact);
1374 __bluetooth_pb_vcard_append_url_v21(str, contact);
1376 __bluetooth_pb_vcard_append_uid_v21(str, contact);
1379 const gchar *param = va_arg(args, const gchar *);
1380 const gchar *value = va_arg(args, const gchar *);
1383 gchar *escaped = NULL;
1385 escaped = __bluetooth_pb_vcard_escape(value);
1386 __bluetooth_pb_vcard_append_qp_encode_v21(str, name, param, escaped);
1391 name = va_arg(args, const gchar *);
1394 g_string_append(str, "END:VCARD\r\n");
1396 contacts_record_destroy(contact, TRUE);
1397 contacts_record_destroy(person, TRUE);
1399 return g_string_free(str, FALSE);
1403 static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
1406 const gchar *first_name,
1409 contacts_record_h person = NULL;
1411 GString *str = NULL;
1415 const gchar *name = first_name;
1416 gchar *vcard = NULL;
1418 status = contacts_db_get_record(_contacts_person._uri,
1422 if (status != CONTACTS_ERROR_NONE)
1425 status = contacts_vcard_make_from_person(person, &vcard);
1427 if (status != CONTACTS_ERROR_NONE)
1430 status = contacts_record_destroy(person, TRUE);
1432 if (status != CONTACTS_ERROR_NONE)
1435 str = g_string_new(vcard);
1438 /* append contents on vcard */
1440 const gchar *param = va_arg(args, const gchar *);
1441 const gchar *value = va_arg(args, const gchar *);
1443 __bluetooth_pb_vcard_append_v30(str, name, param, value);
1445 name = va_arg(args, const gchar *);
1448 /* if phonelog_id exist,
1449 we shall show only the phone number, which was used for that phone log */
1450 if (phonelog_id > 0) {
1453 __bluetooth_pb_vcard_remove_v30(str, "TEL");
1455 number = _bluetooth_pb_number_from_phonelog_id(phonelog_id);
1456 __bluetooth_pb_vcard_append_v30(str, "TEL", NULL, number);
1460 vcard = g_string_free(str, FALSE);
1462 /* temporary fixed for some application crash */
1464 filter = ~VCARD_NOTE;
1467 gchar *new_vcard = NULL;
1469 new_vcard = __bluetooth_pb_vcard_filter_v30(vcard, filter);
1481 static gchar *__bluetooth_pb_vcard_real_contact_with_properties(gint person_id,
1485 const gchar *first_name,
1489 gchar *vcard = NULL;
1492 va_start(args, first_name);
1495 case VCARD_FORMAT_3_0:
1496 vcard = __bluetooth_pb_vcard_real_contact_valist_v30(person_id,
1497 phonelog_id, filter,
1500 case VCARD_FORMAT_2_1:
1502 vcard = __bluetooth_pb_vcard_real_contact_valist_v21(person_id,
1503 phonelog_id, filter,
1513 static gchar *__bluetooth_pb_vcard_real_call_v21(gint phonelog_id,
1520 str = g_string_new("BEGIN:VCARD\r\nVERSION:2.1\r\n");
1522 __bluetooth_pb_vcard_append_qp_encode_v21(str, "N", NULL, NULL);
1524 number = _bluetooth_pb_number_from_phonelog_id(phonelog_id);
1525 __bluetooth_pb_vcard_append_qp_encode_v21(str, "TEL", "X-0", number);
1528 if (((filter == 0) || (filter & VCARD_X_IRMC_CALL_DATETIME))
1530 gchar *datetime = NULL;
1532 datetime = __bluetooth_pb_phonelog_datetime(phonelog_id);
1533 __bluetooth_pb_vcard_append_qp_encode_v21(str, "X-IRMC-CALL-DATETIME",
1538 g_string_append(str, "END:VCARD\r\n");
1540 return g_string_free(str, FALSE);
1543 static gchar *__bluetooth_pb_vcard_real_call_v30(gint phonelog_id,
1550 str = g_string_new("BEGIN:VCARD\r\nVERSION:3.0\r\n");
1552 __bluetooth_pb_vcard_append_v30(str, "N", NULL, NULL);
1553 __bluetooth_pb_vcard_append_v30(str, "FN", NULL, NULL);
1555 number = _bluetooth_pb_number_from_phonelog_id(phonelog_id);
1556 __bluetooth_pb_vcard_append_v30(str, "TEL", NULL, number);
1559 if (((filter == 0) || (filter & VCARD_X_IRMC_CALL_DATETIME))
1561 gchar *datetime = NULL;
1563 datetime = __bluetooth_pb_phonelog_datetime(phonelog_id);
1564 __bluetooth_pb_vcard_append_v30(str,
1565 "X-IRMC-CALL-DATETIME", attr, datetime);
1569 g_string_append(str, "END:VCARD\r\n");
1571 return g_string_free(str, FALSE);
1574 static gchar *__bluetooth_pb_vcard_real_call(gint phonelog_id,
1580 gchar *vcard = NULL;
1583 case VCARD_FORMAT_3_0:
1584 vcard = __bluetooth_pb_vcard_real_call_v30(phonelog_id,
1587 case VCARD_FORMAT_2_1:
1589 vcard = __bluetooth_pb_vcard_real_call_v21(phonelog_id,
1597 static gchar **__bluetooth_pb_contact_add_field_str(contacts_record_h record,
1606 gboolean valid = FALSE;
1608 /* check empty field */
1609 for (i = 0; i < field_size; i++) {
1612 status = contacts_record_get_str_p(record, field[i], &tmp);
1614 if (status != CONTACTS_ERROR_NONE)
1626 strv = g_new0(gchar *, field_size + 1);
1628 for (i = 0; i < field_size; i++) {
1631 status = contacts_record_get_str_p(record, field[i], &tmp);
1633 if (status != CONTACTS_ERROR_NONE)
1637 strv[i] = g_strdup("");
1639 strv[i] = __bluetooth_pb_vcard_escape(tmp);
1645 static gchar **__bluetooth_pb_contact_tel_param(contacts_record_h number)
1647 gchar **strv = NULL;
1649 const gint TEL_PARAM_LEN = 13;
1654 contacts_number_type_e type;
1656 bool is_default = false;
1658 strv = g_new0(char *, TEL_PARAM_LEN + 1); /* tel param max size is 13 */
1660 status = contacts_record_get_bool(number, _contacts_number.is_default,
1663 if (status != CONTACTS_ERROR_NONE)
1667 strv[i] = g_strdup("PREF");
1671 status = contacts_record_get_int(number,
1672 _contacts_number.type,
1675 if (status != CONTACTS_ERROR_NONE)
1678 if (type & CONTACTS_NUMBER_TYPE_HOME) {
1679 strv[i] = g_strdup("HOME");
1683 if (type & CONTACTS_NUMBER_TYPE_WORK) {
1684 strv[i] = g_strdup("WORK");
1688 if (type & CONTACTS_NUMBER_TYPE_VOICE) {
1689 strv[i] = g_strdup("VOICE");
1693 if (type & CONTACTS_NUMBER_TYPE_FAX) {
1694 strv[i] = g_strdup("FAX");
1698 if (type & CONTACTS_NUMBER_TYPE_MSG) {
1699 strv[i] = g_strdup("MSG");
1703 if (type & CONTACTS_NUMBER_TYPE_CELL) {
1704 strv[i] = g_strdup("CELL");
1708 if (type & CONTACTS_NUMBER_TYPE_PAGER) {
1709 strv[i] = g_strdup("PAGER");
1713 if (type & CONTACTS_NUMBER_TYPE_BBS) {
1714 strv[i] = g_strdup("BBS");
1718 if (type & CONTACTS_NUMBER_TYPE_MODEM) {
1719 strv[i] = g_strdup("MODEM");
1723 if (type & CONTACTS_NUMBER_TYPE_CAR) {
1724 strv[i] = g_strdup("CAR");
1728 if (type & CONTACTS_NUMBER_TYPE_ISDN) {
1729 strv[i] = g_strdup("ISDN");
1733 if (type & CONTACTS_NUMBER_TYPE_VIDEO) {
1734 strv[i] = g_strdup("VIDEO");
1738 /* CTS_NUM_TYPE_PCS is not part of vcard2.1 */
1743 static gchar *__bluetooth_pb_contact_photo_type(const gchar *filename)
1745 gchar *filetype = NULL;
1748 if (g_file_test(filename, G_FILE_TEST_IS_REGULAR) == FALSE) {
1749 ERR("file does not regular:%s\n", filename);
1753 ext = strrchr(filename, '.');
1755 ERR("file doesn't have extension\n");
1761 if (g_ascii_strcasecmp(ext, "gif") == 0)
1763 else if (g_ascii_strcasecmp(ext, "cgm") == 0)
1765 else if (g_ascii_strcasecmp(ext, "wmf") == 0)
1767 else if (g_ascii_strcasecmp(ext, "bmp") == 0)
1769 else if (g_ascii_strcasecmp(ext, "met") == 0)
1771 else if (g_ascii_strcasecmp(ext, "dib") == 0)
1773 else if (g_ascii_strcasecmp(ext, "pict") == 0 || g_ascii_strcasecmp(ext, "pct") == 0 ||
1774 g_ascii_strcasecmp(ext, "pic") == 0)
1776 else if (g_ascii_strcasecmp(ext, "tiff") == 0 || g_ascii_strcasecmp(ext, "tif") == 0)
1778 else if (g_ascii_strcasecmp(ext, "ps") == 0)
1780 else if (g_ascii_strcasecmp(ext, "pdf") == 0)
1782 else if (g_ascii_strcasecmp(ext, "jpeg") == 0 || g_ascii_strcasecmp(ext, "jpg") == 0 ||
1783 g_ascii_strcasecmp(ext, "jpe") == 0)
1785 else if (g_ascii_strcasecmp(ext, "mpeg") == 0 || g_ascii_strcasecmp(ext, "mpg") == 0)
1787 else if (g_ascii_strcasecmp(ext, "m2v") == 0)
1789 else if (g_ascii_strcasecmp(ext, "avi") == 0)
1791 else if (g_ascii_strcasecmp(ext, "mov") == 0)
1793 else if (g_ascii_strcasecmp(ext, "png") == 0)
1796 return g_strdup(filetype);
1799 static gchar **__bluetooth_pb_contact_addr(contacts_record_h address)
1801 const gint ADDR_LEN = 7;
1803 gchar **strv = NULL;
1805 gint addr[] = { _contacts_address.postbox,
1806 _contacts_address.extended,
1807 _contacts_address.street,
1808 _contacts_address.locality,
1809 _contacts_address.region,
1810 _contacts_address.postal_code,
1811 _contacts_address.country };
1813 strv = __bluetooth_pb_contact_add_field_str(address,
1818 static gchar **__bluetooth_pb_contact_addr_param(contacts_record_h address)
1821 contacts_address_type_e type;
1826 gchar **strv = NULL;
1828 strv = g_new0(gchar *, 7); /* ADDR param max size is 6 */
1830 status = contacts_record_get_int(address,
1831 _contacts_address.type,
1834 if (status != CONTACTS_ERROR_NONE)
1837 if (type & CONTACTS_ADDRESS_TYPE_HOME) {
1838 strv[i] = g_strdup("HOME");
1841 if (type & CONTACTS_ADDRESS_TYPE_WORK) {
1842 strv[i] = g_strdup("WORK");
1845 if (type & CONTACTS_ADDRESS_TYPE_DOM) {
1846 strv[i] = g_strdup("DOM");
1849 if (type & CONTACTS_ADDRESS_TYPE_INTL) {
1850 strv[i] = g_strdup("INTL");
1853 if (type & CONTACTS_ADDRESS_TYPE_POSTAL) {
1854 strv[i] = g_strdup("POSTAL");
1857 if (type & CONTACTS_ADDRESS_TYPE_PARCEL) {
1858 strv[i] = g_strdup("PARCEL");
1864 static gchar *__bluetooth_pb_phonelog_datetime(gint phonelog_id)
1866 contacts_record_h phone_log;
1868 char time_str[32] = {0,};
1873 struct tm time_info;
1875 status = contacts_db_get_record(_contacts_phone_log._uri,
1879 if (status != CONTACTS_ERROR_NONE)
1882 status = contacts_record_get_int(phone_log,
1883 _contacts_phone_log.log_time,
1886 if (status != CONTACTS_ERROR_NONE)
1892 localtime_r((time_t *)&time, &time_info);
1894 strftime(time_str, sizeof(time_str),
1895 "%Y%m%dT%H%M%S", &time_info);
1897 contacts_record_destroy(phone_log, TRUE);
1899 return g_strdup(time_str);
1902 static gchar *__bluetooth_pb_name_from_contact(contacts_record_h contact)
1904 contacts_record_h name = NULL;
1906 GString *str = g_string_new(NULL);
1912 gint name_val[] = { _contacts_name.last,
1913 _contacts_name.first,
1914 _contacts_name.addition,
1915 _contacts_name.prefix,
1916 _contacts_name.suffix };
1919 status = contacts_record_get_child_record_at_p(contact,
1920 _contacts_contact.name, 0, &name);
1922 if (status != CONTACTS_ERROR_NONE)
1925 for (i = 0; i < name_size; i++) {
1927 gchar *escape = NULL;
1930 g_string_append_c(str, ';');
1932 status = contacts_record_get_str_p(name, name_val[i], &tmp);
1934 if (status != CONTACTS_ERROR_NONE)
1937 escape = __bluetooth_pb_vcard_escape(tmp);
1938 g_string_append(str, escape);
1943 return g_string_free(str, FALSE);
1946 static gchar *__bluetooth_pb_number_from_contact(contacts_record_h contact)
1955 status = contacts_record_get_child_record_count(contact,
1956 _contacts_contact.number,
1959 if (status != CONTACTS_ERROR_NONE)
1962 for (i = 0; i < count; i++) {
1963 contacts_record_h number = NULL;
1967 bool is_default = false;
1969 status = contacts_record_get_child_record_at_p(contact,
1970 _contacts_contact.number, i, &number);
1972 if (status != CONTACTS_ERROR_NONE)
1975 status = contacts_record_get_bool(number,
1976 _contacts_number.is_default,
1979 if (status != CONTACTS_ERROR_NONE)
1982 if (is_default == FALSE)
1985 status = contacts_record_get_str_p(number,
1986 _contacts_number.number,
1989 if (status != CONTACTS_ERROR_NONE)
1993 str = g_strdup(tmp);
1998 /* get first number */
2002 contacts_record_h number = NULL;
2004 status = contacts_record_get_child_record_at_p(contact,
2005 _contacts_contact.number, 0, &number);
2007 if (status != CONTACTS_ERROR_NONE)
2010 status = contacts_record_get_str_p(number,
2011 _contacts_number.number,
2014 if (status != CONTACTS_ERROR_NONE)
2017 str = g_strdup(tmp);
2023 static gint __bluetooth_pb_person_id_from_phonelog_id(gint phonelog_id)
2025 contacts_query_h query = NULL;
2026 contacts_filter_h filter = NULL;
2027 contacts_list_h record_list = NULL;
2029 contacts_record_h phone_log = NULL;
2030 contacts_record_h record = NULL;
2035 status = contacts_db_get_record(_contacts_phone_log._uri,
2039 if (status != CONTACTS_ERROR_NONE)
2042 status = contacts_record_get_int(phone_log,
2043 _contacts_phone_log.person_id,
2046 if (status != CONTACTS_ERROR_NONE) {
2047 contacts_record_destroy(phone_log, TRUE);
2051 contacts_record_destroy(phone_log, TRUE);
2056 status = contacts_filter_create(_contacts_person_phone_log._uri,
2059 if (status != CONTACTS_ERROR_NONE)
2063 status = contacts_filter_add_int(filter,
2064 _contacts_person_phone_log.log_id,
2065 CONTACTS_MATCH_EQUAL,
2068 if (status != CONTACTS_ERROR_NONE) {
2069 contacts_filter_destroy(filter);
2073 status = contacts_query_create(_contacts_person_phone_log._uri, &query);
2075 if (status != CONTACTS_ERROR_NONE) {
2076 contacts_filter_destroy(filter);
2080 status = contacts_query_set_filter(query, filter);
2082 if (status != CONTACTS_ERROR_NONE) {
2083 contacts_filter_destroy(filter);
2084 contacts_query_destroy(query);
2088 status = contacts_db_get_records_with_query(query, -1, -1, &record_list);
2090 if (status != CONTACTS_ERROR_NONE) {
2091 contacts_filter_destroy(filter);
2092 contacts_query_destroy(query);
2097 status = contacts_list_first(record_list);
2099 if (status != CONTACTS_ERROR_NONE) {
2100 contacts_list_destroy(record_list, TRUE);
2101 contacts_filter_destroy(filter);
2102 contacts_query_destroy(query);
2107 status = contacts_list_get_current_record_p(record_list, &record);
2109 if (status != CONTACTS_ERROR_NONE) {
2110 contacts_list_destroy(record_list, TRUE);
2111 contacts_filter_destroy(filter);
2112 contacts_query_destroy(query);
2117 status = contacts_record_get_int(record,
2118 _contacts_person_phone_log.person_id,
2121 if (status != CONTACTS_ERROR_NONE) {
2122 contacts_list_destroy(record_list, TRUE);
2123 contacts_filter_destroy(filter);
2124 contacts_query_destroy(query);
2129 contacts_list_destroy(record_list, TRUE);
2130 contacts_filter_destroy(filter);
2131 contacts_query_destroy(query);
2137 gchar *_bluetooth_pb_vcard_contact(gint person_id,
2146 str = __bluetooth_pb_vcard_real_contact_with_properties(person_id, 0,
2152 gchar *_bluetooth_pb_vcard_contact_owner(const gchar *number,
2156 GString *str = g_string_new("BEGIN:VCARD\r\n");
2160 fn = _bluetooth_pb_owner_name();
2161 name = g_strdup_printf("%s;;;;", fn);
2164 case VCARD_FORMAT_3_0:
2165 g_string_append(str, "VERSION:3.0\r\n");
2167 __bluetooth_pb_vcard_append_v30(str, "N", NULL, name);
2168 __bluetooth_pb_vcard_append_v30(str, "FN", NULL, fn);
2169 __bluetooth_pb_vcard_append_v30(str, "TEL", "TYPE=CELL", number);
2171 case VCARD_FORMAT_2_1:
2173 g_string_append(str, "VERSION:2.1\r\n");
2175 __bluetooth_pb_vcard_append_qp_encode_v21(str, "N", NULL, name);
2177 if (filter == 0 || (filter & VCARD_FN))
2178 __bluetooth_pb_vcard_append_qp_encode_v21(str, "FN", NULL, fn);
2180 __bluetooth_pb_vcard_append_qp_encode_v21(str, "TEL", "CELL", number);
2185 g_string_append(str, "END:VCARD\r\n");
2190 return g_string_free(str, FALSE);
2193 gchar *_bluetooth_pb_vcard_call(gint phonelog_id,
2203 DBG("Unknown attribute type ignored\n");
2207 person_id = __bluetooth_pb_person_id_from_phonelog_id(phonelog_id);
2209 DBG("person_id %d\n", person_id);
2212 if (filter == 0 || (filter & VCARD_X_IRMC_CALL_DATETIME)) {
2213 gchar *datetime = NULL;
2215 datetime = __bluetooth_pb_phonelog_datetime(phonelog_id);
2217 str = __bluetooth_pb_vcard_real_contact_with_properties(person_id,
2220 "X-IRMC-CALL-DATETIME", attr, datetime,
2227 str = __bluetooth_pb_vcard_real_contact_with_properties(person_id,
2234 str = __bluetooth_pb_vcard_real_call(phonelog_id, filter, format, attr);
2239 gchar *_bluetooth_pb_fn_from_person_id(gint person_id)
2241 contacts_record_h person = NULL;
2247 status = contacts_db_get_record(_contacts_person._uri,
2251 if (status != CONTACTS_ERROR_NONE)
2254 status = contacts_record_get_str(person,
2255 _contacts_person.display_name,
2258 if (status != CONTACTS_ERROR_NONE)
2261 contacts_record_destroy(person, TRUE);
2266 gchar *_bluetooth_pb_name_from_person_id(gint person_id)
2268 contacts_record_h person = NULL;
2269 contacts_record_h contact = NULL;
2272 gint contact_id = 0;
2276 status = contacts_db_get_record(_contacts_person._uri,
2280 if (status != CONTACTS_ERROR_NONE)
2283 status = contacts_record_get_int(person,
2284 _contacts_person.display_contact_id,
2287 if (status != CONTACTS_ERROR_NONE) {
2288 contacts_record_destroy(person, TRUE);
2292 contacts_db_get_record(_contacts_contact._uri,
2296 if (status != CONTACTS_ERROR_NONE) {
2297 contacts_record_destroy(person, TRUE);
2301 str = __bluetooth_pb_name_from_contact(contact);
2303 contacts_record_destroy(contact, TRUE);
2304 contacts_record_destroy(person, TRUE);
2309 gchar *_bluetooth_pb_number_from_person_id(gint person_id)
2311 contacts_record_h person = NULL;
2312 contacts_record_h contact = NULL;
2315 gint contact_id = 0;
2319 status = contacts_db_get_record(_contacts_person._uri,
2323 if (status != CONTACTS_ERROR_NONE)
2327 status = contacts_record_get_int(person,
2328 _contacts_person.display_contact_id,
2331 if (status != CONTACTS_ERROR_NONE) {
2332 contacts_record_destroy(person, TRUE);
2336 status = contacts_db_get_record(_contacts_contact._uri,
2340 if (status != CONTACTS_ERROR_NONE) {
2341 contacts_record_destroy(person, TRUE);
2345 str = __bluetooth_pb_number_from_contact(contact);
2347 contacts_record_destroy(contact, TRUE);
2348 contacts_record_destroy(person, TRUE);
2353 gchar *_bluetooth_pb_fn_from_phonelog_id(gint phonelog_id)
2358 person_id = __bluetooth_pb_person_id_from_phonelog_id(phonelog_id);
2361 str = _bluetooth_pb_fn_from_person_id(person_id);
2363 str = _bluetooth_pb_number_from_phonelog_id(phonelog_id);
2368 gchar *_bluetooth_pb_name_from_phonelog_id(gint phonelog_id)
2373 person_id = __bluetooth_pb_person_id_from_phonelog_id(phonelog_id);
2376 str = _bluetooth_pb_name_from_person_id(person_id);
2380 tmp = _bluetooth_pb_number_from_phonelog_id(phonelog_id);
2381 str = g_strdup_printf("%s;;;;", tmp);
2389 gchar *_bluetooth_pb_number_from_phonelog_id(gint phonelog_id)
2391 contacts_record_h phone_log;
2398 status = contacts_db_get_record(_contacts_phone_log._uri,
2399 phonelog_id, &phone_log);
2401 if (status != CONTACTS_ERROR_NONE)
2404 contacts_record_get_str_p(phone_log,
2405 _contacts_phone_log.address,
2408 if (status != CONTACTS_ERROR_NONE) {
2409 contacts_record_destroy(phone_log, TRUE);
2413 str = g_strdup(tmp);
2415 contacts_record_destroy(phone_log, TRUE);
2420 gchar *_bluetooth_pb_owner_name(void)
2424 name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
2427 name = g_strdup("My Name");