4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * Girishashok Joshi <girish.joshi@samsung.com>
8 * Chanyeol Park <chanyeol.park@samsung.com>
9 * Jaekyun Lee <jkyun.lee@samsung.com>
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
36 #include <image_util.h>
37 #include <image_util_internal.h>
38 #include <libexif/exif-data.h>
41 #include "bluetooth_pb_vcard.h"
42 #include "bluetooth_pb_agent.h"
44 #define VCARD_FORMAT_2_1 0x0
45 #define VCARD_FORMAT_3_0 0x1
47 #define VCARD_VERSION (0x1)
48 #define VCARD_FN (0x1 << 1)
49 #define VCARD_N (0x1 << 2)
50 #define VCARD_PHOTO (0x1 << 3)
51 #define VCARD_BDAY (0x1 << 4)
52 #define VCARD_ADR (0x1 << 5)
53 #define VCARD_LABEL (0x1 << 6) /* not supported */
54 #define VCARD_TEL (0x1 << 7)
55 #define VCARD_EMAIL (0x1 << 8)
56 #define VCARD_MAILER (0x1 << 9) /* not supported */
57 #define VCARD_TZ (0x1 << 10) /* not supported */
58 #define VCARD_GEO (0x1 << 11) /* not supported */
59 #define VCARD_TITLE (0x1 << 12)
60 #define VCARD_ROLE (0x1 << 13)
61 #define VCARD_LOGO (0x1 << 14) /* not supported */
62 #define VCARD_AGENT (0x1 << 15) /* not supported */
63 #define VCARD_ORG (0x1 << 16)
64 #define VCARD_NOTE (0x1 << 17)
65 #define VCARD_REV (0x1 << 18)
66 #define VCARD_SOUND (0x1 << 19) /* not supported */
67 #define VCARD_URL (0x1 << 20)
68 #define VCARD_UID (0x1 << 21)
69 #define VCARD_KEY (0x1 << 22) /* not supported */
70 #define VCARD_NICKNAME (0x1 << 23)
71 #define VCARD_CATEGORIES (0x1 << 24) /* not supported */
72 #define VCARD_PROID (0x1 << 25) /* not supported */
73 #define VCARD_CLASS (0x1 << 26) /* not supported */
74 #define VCARD_SORT_STRING (0x1 << 27) /* not supported */
75 #define VCARD_X_IRMC_CALL_DATETIME (0x1 << 28)
78 #define LINEBREAK_LEN 75
84 contacts_record_h person;
88 gchar dest_thumb_path[255];
89 #define PBAP_IMAGE_THUMB_SIZE 48
90 #define PBAP_THMB_PATH "_thumb"
91 #define PBAP_THUMB_FILE_SIZE 4096
92 #define PBAP_IMAGE_ENCODE_QUALITY 90
93 #define PBAP_SECURITY_FILE_GROUP 6005
94 #define PBAP_SECURITY_DEFAULT_PERMISSION 0660
95 #define PBAP_SECURITY_DIR_DEFAULT_PERMISSION 0770
96 #define PBAP_SECURITY_IMAGE_PERMISSION 0440
98 static gchar *__bluetooth_pb_vcard_escape(const gchar *str);
100 static gchar *__bluetooth_pb_vcard_strv_concat(gchar **strv,
101 const gchar *delimeter);
103 static gboolean __bluetooth_pb_vcard_qp_encode_check(const gchar *str);
105 static gint __bluetooth_pb_vcard_qp_encode_strlen(const gchar *str,
108 static void __bluetooth_pb_vcard_qp_encode_append_to_hex(GString *string,
113 static void __bluetooth_pb_vcard_qp_encode_append_printable_c(GString *string,
117 static void __bluetooth_pb_vcard_qp_encode_append(GString *string,
122 static gchar *__bluetooth_pb_vcard_qp_encode(const gchar *str);
124 static void __bluetooth_pb_vcard_append_param_v21(GString *string,
127 static void __bluetooth_pb_vcard_append_qp_encode_v21(GString *string,
132 static void __bluetooth_pb_vcard_append_base64_encode_v21(GString *string,
139 static void __bluetooth_pb_vcard_append_n_v21(GString *string,
140 contacts_record_h contact);
142 static void __bluetooth_pb_vcard_append_phonetic_first_v21(GString *string,
143 contacts_record_h contact);
145 static void __bluetooth_pb_vcard_append_tel_v21(GString *string,
146 contacts_record_h conatct);
148 static void __bluetooth_pb_vcard_append_fn_v21(GString *string,
149 contacts_record_h person);
151 static void __bluetooth_pb_vcard_append_photo_v21(GString *string,
152 contacts_record_h person);
154 static void __bluetooth_pb_vcard_append_bday_v21(GString *string,
155 contacts_record_h contact);
157 static void __bluetooth_pb_vcard_append_adr_v21(GString *string,
158 contacts_record_h contact);
160 static void __bluetooth_pb_vcard_append_email_v21(GString *string,
161 contacts_record_h contact);
163 static void __bluetooth_pb_vcard_append_title_v21(GString *string,
164 contacts_record_h contact);
166 static void __bluetooth_pb_vcard_append_role_v21(GString *string,
167 contacts_record_h contact);
169 static void __bluetooth_pb_vcard_append_org_v21(GString *string,
170 contacts_record_h contact);
172 static void __bluetooth_pb_vcard_append_note_v21(GString *string,
173 contacts_record_h contact);
175 static void __bluetooth_pb_vcard_append_rev_v21(GString *string,
176 contacts_record_h contact);
178 static void __bluetooth_pb_vcard_append_url_v21(GString *string,
179 contacts_record_h contact);
181 static void __bluetooth_pb_vcard_append_uid_v21(GString *string,
182 contacts_record_h contact);
184 static void __bluetooth_pb_vcard_append_v30(GString *string,
189 static void __bluetooth_pb_vcard_remove_v30(GString *string,
190 const gchar *property_name);
192 static gchar *__bluetooth_pb_vcard_filter_v30(const gchar *vcard,
195 static gchar *__bluetooth_pb_vcard_real_contact_valist_v21(gint person_id,
198 const gchar *first_name,
201 static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
204 const gchar *first_name,
207 static gchar *__bluetooth_pb_vcard_real_contact_with_properties(gint person_id,
211 const gchar *first_name,
214 static gchar *__bluetooth_pb_vcard_real_call_v21(gint phonelog_id,
218 static gchar *__bluetooth_pb_vcard_real_call_v30(gint phonelog_id,
222 static gchar *__bluetooth_pb_vcard_real_call(gint phonelog_id,
227 static gchar **__bluetooth_pb_contact_add_field_str(contacts_record_h record,
231 static gchar **__bluetooth_pb_contact_tel_param(contacts_record_h number);
233 static gchar *__bluetooth_pb_contact_photo_type(const gchar *filename);
235 static gchar **__bluetooth_pb_contact_addr(contacts_record_h address);
237 static gchar **__bluetooth_pb_contact_addr_param(contacts_record_h address);
239 static gchar *__bluetooth_pb_phonelog_datetime(gint phonelog_id);
241 static gchar *__bluetooth_pb_name_from_contact(contacts_record_h contact);
243 static gchar *__bluetooth_pb_phonetic_name_from_contact(contacts_record_h contact);
245 static gchar *__bluetooth_pb_number_from_contact(contacts_record_h contact);
247 static gint __bluetooth_pb_person_id_from_phonelog_id(gint phonelog_id);
250 static gchar *__bluetooth_pb_vcard_escape(const gchar *str)
261 escaped = g_string_new(NULL);
266 while (*pos != '\0') {
268 g_string_append_len(escaped, st, (pos - st));
269 g_string_append(escaped, "\\;");
278 g_string_append_len(escaped, st, (pos - st));
280 return g_string_free(escaped, FALSE);
283 static gchar *__bluetooth_pb_vcard_strv_concat(gchar **strv,
284 const gchar *separator)
287 GString *string = g_string_new(NULL);
290 for (i = 0; strv[i] != NULL; i++) {
292 g_string_append(string, ";");
294 g_string_append(string, strv[i]);
298 return g_string_free(string, FALSE);
301 static gboolean __bluetooth_pb_vcard_qp_encode_check(const gchar *str)
310 while (*pos != '\0') {
311 /* ascii code ' ' : 32, '~' : 126 */
312 if ((guchar)*pos < ' ' || (guchar)*pos > '~')
321 /* get string length, which convert to quoted-printable encoding */
322 static gint __bluetooth_pb_vcard_qp_encode_strlen(const gchar *str,
334 if (strlen(str) < len)
339 while (*pos != '\0' && (((pos - str) < length) || length < 0)) {
340 if ((guchar)*pos == '\t') {
346 if ((guchar)*pos < ' ' || (guchar)*pos == '=') {
352 /* check no-ascii utf-8 character */
353 if ((guchar)*pos > '~') {
357 next = g_utf8_next_char(pos);
359 count += QP_ENC_LEN * (next - pos);
372 /* convert to quoted printable code */
373 static void __bluetooth_pb_vcard_qp_encode_append_to_hex(GString *string,
381 if (str == NULL || len == 0)
384 /* add soft linebreak when it exceed */
385 if ((*line_pos + (QP_ENC_LEN * len) > LINEBREAK_LEN)) {
386 g_string_append(string, "=\r\n");
390 for (i = 0; i < len; i++) {
391 g_string_append_printf(string, "=%02X", (guchar)*(str+i));
392 *line_pos += QP_ENC_LEN;
397 /* append plain visiable ascii character */
398 static void __bluetooth_pb_vcard_qp_encode_append_printable_c(GString *string,
403 /* add soft linebreak when it exceed */
404 if (*line_pos + 1 > LINEBREAK_LEN) {
405 g_string_append(string, "=\r\n");
408 g_string_append_c(string, ch);
413 static void __bluetooth_pb_vcard_qp_encode_append(GString *string,
426 encode_len = __bluetooth_pb_vcard_qp_encode_strlen(str, len);
428 /* add soft linebreak when it exceed */
429 if (((*line_pos + encode_len) > LINEBREAK_LEN) && (*line_pos > 1)) {
430 g_string_append(string, "=\r\n");
437 pos = ((gchar *)str) + i;
439 /* converts invisiable character and escape character '='
440 to quoted-printable */
441 if ((guchar)*pos != '\t' &&
442 ((guchar)*pos < ' ' || (guchar)*pos == '=')) {
443 __bluetooth_pb_vcard_qp_encode_append_to_hex(string,
450 /* converts non-ascii utf-8 character to quoted-printable */
451 if ((guchar)*pos > '~') {
455 next = g_utf8_next_char(pos);
458 __bluetooth_pb_vcard_qp_encode_append_to_hex(string,
459 pos, ch_len, line_pos);
465 __bluetooth_pb_vcard_qp_encode_append_printable_c(string, *pos,
472 static gchar *__bluetooth_pb_vcard_qp_encode(const gchar *str)
485 enc = g_string_new(NULL);
487 st_pos = (gchar *)str;
490 while (*pos != '\0') {
491 /* split string with given delimeter ' ' or '\t' */
492 if (*pos == ' ' || *pos == '\t') {
493 __bluetooth_pb_vcard_qp_encode_append(enc, st_pos,
494 (pos - st_pos), &line_pos);
502 /* split string with given delimeter '\r', '\n' or
504 if (*pos == '\r' || *pos == '\n') {
505 __bluetooth_pb_vcard_qp_encode_append(enc, st_pos,
506 (pos - st_pos), &line_pos);
508 /* converts newline to qp_encode with soft linebreak
509 for example, converts \r\n to =0D=0A=\r\n */
510 __bluetooth_pb_vcard_qp_encode_append_to_hex(enc,
511 "\r\n", 2, &line_pos);
512 g_string_append(enc, "=\r\n ");
516 if (*pos == '\r' && *(pos + 1) == '\n')
529 __bluetooth_pb_vcard_qp_encode_append(enc, st_pos,
530 (pos - st_pos), &line_pos);
533 return g_string_free(enc, FALSE);
536 static void __bluetooth_pb_vcard_append_param_v21(GString *string,
545 pos = (gchar *)param;
547 /* trim ';' on first */
548 while (*pos != '\0') {
556 g_string_append_printf(string, ";%s", pos);
560 static void __bluetooth_pb_vcard_append_qp_encode_v21(GString *string,
566 GString *property = NULL;
571 property = g_string_new(name);
572 __bluetooth_pb_vcard_append_param_v21(property, param);
574 if (__bluetooth_pb_vcard_qp_encode_check(value)) {
577 __bluetooth_pb_vcard_append_param_v21(property,
579 __bluetooth_pb_vcard_append_param_v21(property,
580 "ENCODING=QUOTED-PRINTABLE");
581 g_string_append(property, ":");
583 enc = __bluetooth_pb_vcard_qp_encode(value);
586 g_string_append(property, enc);
590 g_string_append(property, ":");
592 g_string_append(property , value);
595 g_string_append_printf(string, "%s\r\n", property->str);
597 g_string_free(property, TRUE);
602 static void __bluetooth_pb_vcard_append_base64_encode_v21(GString *string,
614 DBG("base 64 encoding\n");
616 g_string_append(string, name);
618 __bluetooth_pb_vcard_append_param_v21(string, param);
619 __bluetooth_pb_vcard_append_param_v21(string, "ENCODING=BASE64");
621 g_string_append(string, ":");
626 enc = g_base64_encode((const guchar *)value, len);
628 if (folding == FALSE) {
629 g_string_append(string, enc);
631 gint enc_len = strlen(enc);
634 /* count ' ' size for folding */
635 gint fline_len = LINEBREAK_LEN - 1;
637 for (i = 0; (i * fline_len) < enc_len; i++) {
638 g_string_append(string, "\r\n ");
639 if ((i * fline_len) + fline_len > enc_len)
640 g_string_append(string, enc + (i * fline_len));
642 g_string_append_len(string, enc +
643 (i * fline_len), fline_len);
646 /* some application requires more \r\n */
647 g_string_append(string, "\r\n");
649 g_string_append(string, "\r\n");
650 DBG("base 64 encoding\n");
656 static void __bluetooth_pb_vcard_append_n_v21(GString *string,
657 contacts_record_h contact)
662 str = __bluetooth_pb_name_from_contact(contact);
663 __bluetooth_pb_vcard_append_qp_encode_v21(string, "N", NULL, str);
669 static void __bluetooth_pb_vcard_append_phonetic_first_v21(GString *string,
670 contacts_record_h contact)
675 str = __bluetooth_pb_phonetic_name_from_contact(contact);
678 __bluetooth_pb_vcard_append_qp_encode_v21(string, "SOUND", "X-IRMC-N", str);
684 static void __bluetooth_pb_vcard_append_tel_v21(GString *string,
685 contacts_record_h contact)
693 status = contacts_record_get_child_record_count(contact,
694 _contacts_contact.number,
697 if (status != CONTACTS_ERROR_NONE)
700 for (i = 0; i < count; i++) {
701 contacts_record_h number = NULL;
703 gchar **paramv = NULL;
707 gchar *escaped = NULL;
709 status = contacts_record_get_child_record_at_p(contact,
710 _contacts_contact.number, i, &number);
712 if (status != CONTACTS_ERROR_NONE)
715 status = contacts_record_get_str_p(number,
716 _contacts_number.number,
719 if (status != CONTACTS_ERROR_NONE)
722 escaped = __bluetooth_pb_vcard_escape(tel);
724 paramv = __bluetooth_pb_contact_tel_param(number);
726 param = __bluetooth_pb_vcard_strv_concat(paramv, ";");
728 __bluetooth_pb_vcard_append_qp_encode_v21(string, "TEL", param,
738 static void __bluetooth_pb_vcard_append_fn_v21(GString *string,
739 contacts_record_h person)
747 status = contacts_record_get_str_p(person,
748 _contacts_person.display_name,
751 if (status != CONTACTS_ERROR_NONE)
754 fn = __bluetooth_pb_vcard_escape(tmp);
756 __bluetooth_pb_vcard_append_qp_encode_v21(string, "FN", NULL, fn);
761 /* image util APIs will be deprecated in Tizen 5.0. So we should replace it to new API
762 https://developer.tizen.org/development/guides/native-application/media-and-camera/image-editing#decode
763 https://developer.tizen.org/development/guides/native-application/media-and-camera/image-editing#encode
766 static image_util_rotation_e __bt_pbap_get_rotation_info(const char *path)
771 image_util_rotation_e rotation = IMAGE_UTIL_ROTATION_NONE;
774 ed = exif_data_new_from_file(path);
776 ERR("exif_data_new_from_file : ExifData is NULL");
777 return IMAGE_UTIL_ROTATION_NONE;
780 entry = exif_data_get_entry(ed, EXIF_TAG_ORIENTATION);
782 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
783 orientation = (int)exif_get_short(entry->data, mByteOrder);
784 if (orientation < 0 || orientation > 8)
790 switch (orientation) {
791 case 1: /* Top-left */
792 rotation = IMAGE_UTIL_ROTATION_NONE;
794 case 2: /* Top-right */
795 rotation = IMAGE_UTIL_ROTATION_FLIP_HORZ;
797 case 3: /* Bottom-right */
798 rotation = IMAGE_UTIL_ROTATION_180;
800 case 4: /* Bottom-left */
801 rotation = IMAGE_UTIL_ROTATION_FLIP_VERT;
803 case 6: /* Right-top */
804 rotation = IMAGE_UTIL_ROTATION_90;
806 case 8: /* Left-bottom */
807 rotation = IMAGE_UTIL_ROTATION_270;
809 case 5: /* Left-top */
810 case 7: /* Right-bottom */
821 static bool __bt_pbap_image_util_supported_jpeg_colorspace_cb(
822 image_util_colorspace_e colorspace, void *user_data)
825 unsigned char *img_target = 0;
826 unsigned char *img_source = 0;
829 gchar *contents = NULL;
832 int resized_width = 0;
833 int resized_height = 0;
835 unsigned int size_decode = 0;
836 image_util_rotation_e rotation;
837 image_util_error_e ret = 0;
840 bt_image_info_t *info = (bt_image_info_t *)user_data;
841 rotation = __bt_pbap_get_rotation_info(info->src);
842 ret = image_util_decode_jpeg(info->src, colorspace, &img_source, &width,
843 &height, &size_decode);
844 if (ret != IMAGE_UTIL_ERROR_NONE) {
845 ERR("Can not decode");
846 memset(info, 0x00, sizeof(bt_image_info_t));
850 DBG("decoding completed width = %d, height = %d, size = %d\n", width,
851 height, size_decode);
852 if (width > PBAP_IMAGE_THUMB_SIZE || height > PBAP_IMAGE_THUMB_SIZE) {
853 if (width <= 0 || height <= 0) {
855 ERR("image size error(%d)", PBAP_IMAGE_THUMB_SIZE);
856 memset(info, 0x00, sizeof(bt_image_info_t));
860 if (width > height) {
861 resized_width = PBAP_IMAGE_THUMB_SIZE ;
862 resized_height = height * PBAP_IMAGE_THUMB_SIZE / width;
864 resized_height = PBAP_IMAGE_THUMB_SIZE;
865 resized_width = width * PBAP_IMAGE_THUMB_SIZE / height;
868 if (resized_height % 8)
869 resized_height += 8 - (resized_height % 8);
870 if (resized_width % 8)
871 resized_width += 8 - (resized_width % 8);
873 DBG("original size[%d, %d] changed to resize[%d,%d]", width,
874 height, resized_width, resized_height);
876 ret = image_util_calculate_buffer_size(resized_width,
881 img_target = g_malloc0(size_decode);
884 ret = image_util_resize(img_target, &resized_width,
885 &resized_height, img_source, width,
887 if (ret != IMAGE_UTIL_ERROR_NONE) {
888 ERR("image_util_resize failed(%d)", ret);
891 memset(info, 0x00, sizeof(bt_image_info_t));
896 resized_width = width;
897 resized_height = height;
898 img_target = img_source;
900 DBG("Resized w = %d, ht = %d, size = %d\n", width, height, size_decode);
902 if (IMAGE_UTIL_ROTATION_NONE != rotation) {
903 int rotated_width, rotated_height;
904 unsigned char *img_rotate = 0;
905 img_rotate = g_malloc0(size_decode);
906 ret = image_util_rotate(img_rotate, &rotated_width, &rotated_height,
907 rotation, img_target, resized_width,
908 resized_height, colorspace);
910 ERR("image_util_rotate failed");
911 resized_width = rotated_width;
912 resized_height = rotated_height;
914 img_target = img_rotate;
918 ret = image_util_encode_jpeg(img_target, resized_width, resized_height,
919 colorspace, PBAP_IMAGE_ENCODE_QUALITY,
922 if (ret != IMAGE_UTIL_ERROR_NONE) {
923 ERR("image_util_encode_jpeg failed(%d)", ret);
924 info->ret = CONTACTS_ERROR_INTERNAL;
927 DBG("Encoding done\n");
929 dest_fd = open(info->dest, O_RDONLY);
931 ERR("System : Open Failed(%d)", errno);
932 ERR_SECURE("Open : dest path(%s)", info->dest);
936 ret = fchown(dest_fd, getuid(), PBAP_SECURITY_FILE_GROUP);
938 ERR("fchown Failed(%d)", errno);
939 DBG_SECURE("fchown : dest path(%s)", info->dest);
944 ret = fchmod(dest_fd, PBAP_SECURITY_IMAGE_PERMISSION);
946 ERR("fchmod Failed(%d)", errno);
947 ERR_SECURE("fchmod : dest path(%s)", info->dest);
953 info->ret = CONTACTS_ERROR_NONE;
954 type = __bluetooth_pb_contact_photo_type(info->dest);
955 DBG("Cintact image thumb type is = %s\n", type);
958 param = g_strdup_printf("TYPE=%s", type);
962 if (g_file_get_contents(info->dest, &contents, &len, NULL) == FALSE) {
963 ERR("can not read file contents:%s\n", info->dest);
967 __bluetooth_pb_vcard_append_base64_encode_v21(info->string,
968 "PHOTO", param, contents, len, TRUE);
974 memset(info, 0x00, sizeof(bt_image_info_t));
975 DBG("Cintact image thumb created successfuly\n");
981 static void __bluetooth_pb_vcard_append_photo_v21(GString *string,
982 contacts_record_h person)
986 gchar *filename = NULL;
987 struct stat stat_info;
990 gchar *contents = NULL;
994 status = contacts_record_get_str_p(person,
995 _contacts_person.image_thumbnail_path,
998 if (status != CONTACTS_ERROR_NONE || NULL == filename)
1001 stat_info.st_size = 0;
1003 if (0 > stat(filename, &stat_info))
1004 ERR("fstat failed, file does not exist %s", filename);
1006 if (PBAP_THUMB_FILE_SIZE > stat_info.st_size) {
1007 DBG_SECURE("File size small, so use thubnail %s\n", filename);
1009 type = __bluetooth_pb_contact_photo_type(filename);
1011 param = g_strdup_printf("TYPE=%s", type);
1015 if (g_file_get_contents(filename, &contents, &len, NULL) ==
1017 ERR("can not read file contents:%s\n", filename);
1021 DBG("Retrieved the contents of the file \n");
1022 __bluetooth_pb_vcard_append_base64_encode_v21(string,
1023 "PHOTO", param, contents, len, TRUE);
1030 ptr = strrchr(filename, '.');
1032 memset(dest_thumb_path, 0x00, sizeof(dest_thumb_path));
1033 g_strlcpy(dest_thumb_path, filename, ptr - filename);
1034 g_strlcat(dest_thumb_path, PBAP_THMB_PATH,
1035 sizeof(dest_thumb_path));
1036 g_strlcat(dest_thumb_path, ptr, sizeof(dest_thumb_path));
1037 DBG("Thumbnail path is = %s", dest_thumb_path);
1039 DBG_SECURE("filename = %s Thumbnail path is = %s", filename, dest_thumb_path);
1041 /* image_util_foreach_supported_jpeg_colorspace API will be deprecated in Tizen 5.0. So we should replace it to new API
1042 https://developer.tizen.org/development/guides/native-application/media-and-camera/image-editing#decode
1043 https://developer.tizen.org/development/guides/native-application/media-and-camera/image-editing#encode
1046 bt_image_info_t img_info;
1049 img_info.src = filename;
1050 img_info.dest = dest_thumb_path;
1051 img_info.ret = CONTACTS_ERROR_INTERNAL;
1052 img_info.person = person;
1053 img_info.string = string;
1055 res = image_util_foreach_supported_jpeg_colorspace(
1056 __bt_pbap_image_util_supported_jpeg_colorspace_cb, &img_info);
1058 if (res != IMAGE_UTIL_ERROR_NONE)
1059 ERR("Image resizing is failed");
1065 static void __bluetooth_pb_vcard_append_bday_v21(GString *string,
1066 contacts_record_h contact)
1074 status = contacts_record_get_child_record_count(contact,
1075 _contacts_contact.event, &count);
1077 if (status != CONTACTS_ERROR_NONE)
1080 for (i = 0; i < count; i++) {
1081 contacts_record_h event = NULL;
1087 contacts_event_type_e type;
1089 status = contacts_record_get_child_record_at_p(contact,
1090 _contacts_contact.event, i, &event);
1092 if (status != CONTACTS_ERROR_NONE)
1095 status = contacts_record_get_int(event,
1096 _contacts_event.type,
1099 if (status != CONTACTS_ERROR_NONE)
1102 if (type != CONTACTS_EVENT_TYPE_BIRTH)
1105 status = contacts_record_get_int(event,
1106 _contacts_event.date,
1109 if (status != CONTACTS_ERROR_NONE)
1115 bday = g_strdup_printf("%04d-%02d-%02d",
1116 (date/10000), (date/100)%100, date%100);
1117 __bluetooth_pb_vcard_append_qp_encode_v21(string, "BDAY",
1124 static void __bluetooth_pb_vcard_append_adr_v21(GString *string,
1125 contacts_record_h contact)
1133 status = contacts_record_get_child_record_count(contact,
1134 _contacts_contact.address,
1137 if (status != CONTACTS_ERROR_NONE)
1140 for (i = 0; i < count; i++) {
1141 contacts_record_h address = NULL;
1149 status = contacts_record_get_child_record_at_p(contact,
1150 _contacts_contact.address, i, &address);
1152 if (status != CONTACTS_ERROR_NONE)
1155 addrv = __bluetooth_pb_contact_addr(address);
1160 addr = __bluetooth_pb_vcard_strv_concat(addrv, ";");
1163 paramv = __bluetooth_pb_contact_addr_param(address);
1165 param = __bluetooth_pb_vcard_strv_concat(paramv, ";");
1168 __bluetooth_pb_vcard_append_qp_encode_v21(string, "ADR",
1178 static void __bluetooth_pb_vcard_append_email_v21(GString *string,
1179 contacts_record_h contact)
1187 status = contacts_record_get_child_record_count(contact,
1188 _contacts_contact.email,
1191 if (status != CONTACTS_ERROR_NONE)
1194 for (i = 0; i < count; i++) {
1195 contacts_record_h email = NULL;
1200 status = contacts_record_get_child_record_at_p(contact,
1201 _contacts_contact.email, i, &email);
1203 if (status != CONTACTS_ERROR_NONE)
1206 status = contacts_record_get_str_p(email,
1207 _contacts_email.email,
1210 if (status != CONTACTS_ERROR_NONE)
1213 escaped = __bluetooth_pb_vcard_escape(tmp);
1214 __bluetooth_pb_vcard_append_qp_encode_v21(string, "EMAIL", NULL,
1222 static void __bluetooth_pb_vcard_append_title_v21(GString *string,
1223 contacts_record_h contact)
1231 status = contacts_record_get_child_record_count(contact,
1232 _contacts_contact.company,
1235 if (status != CONTACTS_ERROR_NONE)
1238 for (i = 0; i < count; i++) {
1239 contacts_record_h company = NULL;
1244 status = contacts_record_get_child_record_at_p(contact,
1245 _contacts_contact.company, i, &company);
1247 if (status != CONTACTS_ERROR_NONE)
1250 status = contacts_record_get_str_p(company,
1251 _contacts_company.job_title,
1254 if (status != CONTACTS_ERROR_NONE)
1257 escaped = __bluetooth_pb_vcard_escape(title);
1258 __bluetooth_pb_vcard_append_qp_encode_v21(string, "TITLE", NULL,
1266 static void __bluetooth_pb_vcard_append_role_v21(GString *string,
1267 contacts_record_h contact)
1275 status = contacts_record_get_child_record_count(contact,
1276 _contacts_contact.company,
1279 if (status != CONTACTS_ERROR_NONE)
1282 for (i = 0; i < count; i++) {
1283 contacts_record_h company = NULL;
1288 status = contacts_record_get_child_record_at_p(contact,
1289 _contacts_contact.company, i, &company);
1291 if (status != CONTACTS_ERROR_NONE)
1294 status = contacts_record_get_str_p(company,
1295 _contacts_company.role,
1298 if (status != CONTACTS_ERROR_NONE)
1301 escaped = __bluetooth_pb_vcard_escape(role);
1302 __bluetooth_pb_vcard_append_qp_encode_v21(string, "ROLE", NULL,
1310 static void __bluetooth_pb_vcard_append_org_v21(GString *string,
1311 contacts_record_h contact)
1319 status = contacts_record_get_child_record_count(contact,
1320 _contacts_contact.company,
1323 if (status != CONTACTS_ERROR_NONE)
1326 for (i = 0; i < count; i++) {
1327 contacts_record_h company = NULL;
1332 gchar *department = NULL;
1335 gint department_status;
1337 status = contacts_record_get_child_record_at_p(contact,
1338 _contacts_contact.company, i, &company);
1340 if (status != CONTACTS_ERROR_NONE)
1344 name_status = contacts_record_get_str_p(company,
1345 _contacts_company.name,
1348 department_status = contacts_record_get_str_p(company,
1349 _contacts_company.department,
1352 if ((name_status != CONTACTS_ERROR_NONE) &&
1353 (department_status != CONTACTS_ERROR_NONE))
1356 str = g_string_new(NULL);
1361 escaped = __bluetooth_pb_vcard_escape(name);
1362 g_string_append(str, escaped);
1366 g_string_append(str, ";");
1371 escaped = __bluetooth_pb_vcard_escape(department);
1372 g_string_append(str, escaped);
1376 __bluetooth_pb_vcard_append_qp_encode_v21(string, "ORG", NULL,
1379 g_string_free(str, TRUE);
1385 static void __bluetooth_pb_vcard_append_note_v21(GString *string,
1386 contacts_record_h contact)
1394 status = contacts_record_get_child_record_count(contact,
1395 _contacts_contact.note,
1398 if (status != CONTACTS_ERROR_NONE)
1401 for (i = 0; i < count; i++) {
1402 contacts_record_h note = NULL;
1407 status = contacts_record_get_child_record_at_p(contact,
1408 _contacts_contact.note, i, ¬e);
1410 if (status != CONTACTS_ERROR_NONE)
1413 status = contacts_record_get_str_p(note,
1414 _contacts_note.note,
1417 if (status != CONTACTS_ERROR_NONE)
1420 escaped = __bluetooth_pb_vcard_escape(tmp);
1421 __bluetooth_pb_vcard_append_qp_encode_v21(string, "NOTE", NULL,
1429 static void __bluetooth_pb_vcard_append_rev_v21(GString *string,
1430 contacts_record_h contact)
1439 status = contacts_record_get_int(contact,
1440 _contacts_contact.changed_time,
1443 if (status != CONTACTS_ERROR_NONE)
1449 gmtime_r((const time_t *)(&time), &result);
1451 rev = g_strdup_printf("%04d-%02d-%02dT%02d:%02d:%02dZ",
1452 (1900 + result.tm_year), (1 + result.tm_mon),
1453 result.tm_mday, result.tm_hour, result.tm_min,
1456 __bluetooth_pb_vcard_append_qp_encode_v21(string, "REV", NULL, rev);
1462 static void __bluetooth_pb_vcard_append_url_v21(GString *string,
1463 contacts_record_h contact)
1471 status = contacts_record_get_child_record_count(contact,
1472 _contacts_contact.url,
1475 if (status != CONTACTS_ERROR_NONE)
1478 for (i = 0; i < count; i++) {
1479 contacts_record_h url = NULL;
1484 status = contacts_record_get_child_record_at_p(contact,
1485 _contacts_contact.url, i, &url);
1487 if (status != CONTACTS_ERROR_NONE)
1493 status = contacts_record_get_str_p(url,
1497 if (status != CONTACTS_ERROR_NONE)
1500 escaped = __bluetooth_pb_vcard_escape(tmp);
1501 __bluetooth_pb_vcard_append_qp_encode_v21(string, "URL", NULL,
1509 static void __bluetooth_pb_vcard_append_uid_v21(GString *string,
1510 contacts_record_h contact)
1518 status = contacts_record_get_str_p(contact,
1519 _contacts_contact.uid,
1522 if (status != CONTACTS_ERROR_NONE)
1525 escaped = __bluetooth_pb_vcard_escape(uid);
1526 __bluetooth_pb_vcard_append_qp_encode_v21(string, "UID", NULL, escaped);
1532 static void __bluetooth_pb_vcard_append_v30(GString *string,
1543 g_string_append(string, name);
1546 g_string_append_printf(string, ";%s", param);
1548 g_string_append(string, ":");
1551 g_string_append(string, value);
1553 g_string_append(string, "\r\n");
1557 static void __bluetooth_pb_vcard_remove_v30(GString *string,
1558 const gchar *property_name)
1562 gchar *st_pos = NULL;
1564 gboolean matched = FALSE;
1566 if (string == NULL || property_name == NULL)
1571 while (*pos != '\0') {
1572 if (matched == FALSE) {
1573 if (g_ascii_strncasecmp(pos, "\r\n", 2) == 0) {
1579 attrlen = strlen(property_name);
1580 if (g_ascii_strncasecmp(pos, property_name,
1584 if (*pos == ':' || *pos == ';') {
1592 if (g_ascii_strncasecmp(pos, "\r\n", 2) == 0) {
1595 if (*pos != ' ' && *pos != '\t') {
1596 /* +2 means move over \r\n */
1597 g_string_erase(string,
1598 (st_pos+2)-(string->str),
1613 static gchar *__bluetooth_pb_vcard_filter_v30(const gchar *vcard,
1617 GString *string = NULL;
1622 string = g_string_new(vcard);
1624 if ((filter & VCARD_BDAY) == 0)
1625 __bluetooth_pb_vcard_remove_v30(string, "BDAY");
1627 if ((filter & VCARD_ADR) == 0)
1628 __bluetooth_pb_vcard_remove_v30(string, "ADR");
1630 if ((filter & VCARD_EMAIL) == 0)
1631 __bluetooth_pb_vcard_remove_v30(string, "EMAIL");
1633 if ((filter & VCARD_TITLE) == 0)
1634 __bluetooth_pb_vcard_remove_v30(string, "TITLE");
1636 if ((filter & VCARD_ROLE) == 0)
1637 __bluetooth_pb_vcard_remove_v30(string, "ROLE");
1639 if ((filter & VCARD_ORG) == 0)
1640 __bluetooth_pb_vcard_remove_v30(string, "ORG");
1642 if ((filter & VCARD_NOTE) == 0)
1643 __bluetooth_pb_vcard_remove_v30(string, "NOTE");
1645 if ((filter & VCARD_REV) == 0)
1646 __bluetooth_pb_vcard_remove_v30(string, "REV");
1648 if ((filter & VCARD_URL) == 0)
1649 __bluetooth_pb_vcard_remove_v30(string, "URL");
1651 if ((filter & VCARD_UID) == 0)
1652 __bluetooth_pb_vcard_remove_v30(string, "UID");
1654 if ((filter & VCARD_NICKNAME) == 0)
1655 __bluetooth_pb_vcard_remove_v30(string, "NICKNAME");
1658 return g_string_free(string, FALSE);
1661 static gchar *__bluetooth_pb_vcard_real_contact_valist_v21(gint person_id,
1664 const gchar *first_name,
1668 contacts_record_h person = NULL;
1669 contacts_record_h contact = NULL;
1671 GString *str = NULL;
1673 gint contact_id = 0;
1678 const gchar *name = first_name;
1680 status = contacts_db_get_record(_contacts_person._uri,
1684 if (status != CONTACTS_ERROR_NONE)
1687 status = contacts_record_get_int(person,
1688 _contacts_person.display_contact_id,
1691 if (status != CONTACTS_ERROR_NONE)
1694 status = contacts_db_get_record(_contacts_contact._uri,
1698 if (status != CONTACTS_ERROR_NONE) {
1699 contacts_record_destroy(person, TRUE);
1706 DBG("filter[%x]\n", filter);
1708 str = g_string_new("BEGIN:VCARD\r\nVERSION:2.1\r\n");
1710 /* N, TEL is default */
1711 __bluetooth_pb_vcard_append_n_v21(str, contact);
1713 if (phonelog_id > 0) {
1716 number = _bluetooth_pb_number_from_phonelog_id(phonelog_id);
1717 __bluetooth_pb_vcard_append_qp_encode_v21(str, "TEL", "X-0",
1723 __bluetooth_pb_vcard_append_tel_v21(str, contact);
1727 __bluetooth_pb_vcard_append_fn_v21(str, person);
1728 /* Need to check filter
1729 if (f & VCARD_SOUND)*/
1730 __bluetooth_pb_vcard_append_phonetic_first_v21(str, contact);
1731 if (f & VCARD_PHOTO)
1732 __bluetooth_pb_vcard_append_photo_v21(str, person);
1734 __bluetooth_pb_vcard_append_bday_v21(str, contact);
1736 __bluetooth_pb_vcard_append_adr_v21(str, contact);
1737 if (f & VCARD_EMAIL)
1738 __bluetooth_pb_vcard_append_email_v21(str, contact);
1739 if (f & VCARD_TITLE)
1740 __bluetooth_pb_vcard_append_title_v21(str, contact);
1742 __bluetooth_pb_vcard_append_role_v21(str, contact);
1744 __bluetooth_pb_vcard_append_org_v21(str, contact);
1746 __bluetooth_pb_vcard_append_note_v21(str, contact);
1748 __bluetooth_pb_vcard_append_rev_v21(str, contact);
1750 __bluetooth_pb_vcard_append_url_v21(str, contact);
1752 __bluetooth_pb_vcard_append_uid_v21(str, contact);
1755 const gchar *param = va_arg(args, const gchar *);
1756 const gchar *value = va_arg(args, const gchar *);
1759 gchar *escaped = NULL;
1761 escaped = __bluetooth_pb_vcard_escape(value);
1762 __bluetooth_pb_vcard_append_qp_encode_v21(str, name,
1768 name = va_arg(args, const gchar *);
1771 g_string_append(str, "END:VCARD\r\n");
1773 contacts_record_destroy(contact, TRUE);
1774 contacts_record_destroy(person, TRUE);
1777 return g_string_free(str, FALSE);
1781 static gchar *__bluetooth_pb_vcard_real_contact_valist_v30(gint person_id,
1784 const gchar *first_name,
1788 contacts_record_h person = NULL;
1790 GString *str = NULL;
1794 const gchar *name = first_name;
1795 gchar *vcard = NULL;
1797 status = contacts_db_get_record(_contacts_person._uri,
1801 if (status != CONTACTS_ERROR_NONE)
1804 status = contacts_vcard_make_from_person(person, &vcard);
1806 if (status != CONTACTS_ERROR_NONE)
1809 /* removing the END:VCARD\r\n" to append extra data */
1810 str = g_string_new_len(vcard, (strlen(vcard)-11));
1813 /* append contents on vcard */
1815 const gchar *param = va_arg(args, const gchar *);
1816 const gchar *value = va_arg(args, const gchar *);
1818 __bluetooth_pb_vcard_append_v30(str, name, param, value);
1820 name = va_arg(args, const gchar *);
1823 /* if phonelog_id exist, we shall show only the phone number, which was
1824 used for that phone log */
1825 if (phonelog_id > 0) {
1828 __bluetooth_pb_vcard_remove_v30(str, "TEL");
1830 number = _bluetooth_pb_number_from_phonelog_id(phonelog_id);
1831 __bluetooth_pb_vcard_append_v30(str, "TEL", NULL, number);
1835 /* Remove Full contact image and add thumbnail image */
1836 __bluetooth_pb_vcard_remove_v30(str, "PHOTO");
1837 if (filter & VCARD_PHOTO)
1838 __bluetooth_pb_vcard_append_photo_v21(str, person); /* Photo is same as vCard 2.1 */
1840 /* Destroy contact record */
1841 status = contacts_record_destroy(person, TRUE);
1842 if (status != CONTACTS_ERROR_NONE)
1843 ERR("Failed to destroy person");
1845 g_string_append(str, "END:VCARD\r\n");
1847 vcard = g_string_free(str, FALSE);
1849 /* temporary fixed for some application crash */
1851 filter = ~VCARD_NOTE;
1854 gchar *new_vcard = NULL;
1856 new_vcard = __bluetooth_pb_vcard_filter_v30(vcard, filter);
1869 static gchar *__bluetooth_pb_vcard_real_contact_with_properties(gint person_id,
1873 const gchar *first_name,
1877 DBG(" format [%d]\n", format);
1878 gchar *vcard = NULL;
1881 va_start(args, first_name);
1884 case VCARD_FORMAT_3_0:
1885 vcard = __bluetooth_pb_vcard_real_contact_valist_v30(person_id,
1886 phonelog_id, filter,
1889 case VCARD_FORMAT_2_1:
1891 vcard = __bluetooth_pb_vcard_real_contact_valist_v21(person_id,
1892 phonelog_id, filter,
1903 static gchar *__bluetooth_pb_vcard_real_call_v21(gint phonelog_id,
1911 str = g_string_new("BEGIN:VCARD\r\nVERSION:2.1\r\n");
1913 __bluetooth_pb_vcard_append_qp_encode_v21(str, "N", NULL, NULL);
1915 number = _bluetooth_pb_number_from_phonelog_id(phonelog_id);
1916 __bluetooth_pb_vcard_append_qp_encode_v21(str, "TEL", "X-0", number);
1919 if (((filter == 0) || (filter & VCARD_X_IRMC_CALL_DATETIME))
1921 gchar *datetime = NULL;
1923 datetime = __bluetooth_pb_phonelog_datetime(phonelog_id);
1924 __bluetooth_pb_vcard_append_qp_encode_v21(str,
1925 "X-IRMC-CALL-DATETIME",
1930 g_string_append(str, "END:VCARD\r\n");
1933 return g_string_free(str, FALSE);
1936 static gchar *__bluetooth_pb_vcard_real_call_v30(gint phonelog_id,
1944 str = g_string_new("BEGIN:VCARD\r\nVERSION:3.0\r\n");
1946 __bluetooth_pb_vcard_append_v30(str, "N", NULL, NULL);
1947 __bluetooth_pb_vcard_append_v30(str, "FN", NULL, NULL);
1949 number = _bluetooth_pb_number_from_phonelog_id(phonelog_id);
1950 __bluetooth_pb_vcard_append_v30(str, "TEL", NULL, number);
1953 if (((filter == 0) || (filter & VCARD_X_IRMC_CALL_DATETIME))
1955 gchar *datetime = NULL;
1957 datetime = __bluetooth_pb_phonelog_datetime(phonelog_id);
1958 __bluetooth_pb_vcard_append_v30(str,
1959 "X-IRMC-CALL-DATETIME", attr, datetime);
1963 g_string_append(str, "END:VCARD\r\n");
1966 return g_string_free(str, FALSE);
1969 static gchar *__bluetooth_pb_vcard_real_call(gint phonelog_id,
1975 gchar *vcard = NULL;
1978 case VCARD_FORMAT_3_0:
1979 vcard = __bluetooth_pb_vcard_real_call_v30(phonelog_id,
1982 case VCARD_FORMAT_2_1:
1984 vcard = __bluetooth_pb_vcard_real_call_v21(phonelog_id,
1993 static gchar **__bluetooth_pb_contact_add_field_str(contacts_record_h record,
2003 gboolean valid = FALSE;
2005 /* check empty field */
2006 for (i = 0; i < field_size; i++) {
2009 status = contacts_record_get_str_p(record, field[i], &tmp);
2011 if (status != CONTACTS_ERROR_NONE)
2023 strv = g_new0(gchar *, field_size + 1);
2025 for (i = 0; i < field_size; i++) {
2028 status = contacts_record_get_str_p(record, field[i], &tmp);
2030 if (status != CONTACTS_ERROR_NONE)
2034 strv[i] = g_strdup("");
2036 strv[i] = __bluetooth_pb_vcard_escape(tmp);
2043 static gchar **__bluetooth_pb_contact_tel_param(contacts_record_h number)
2046 gchar **strv = NULL;
2048 const gint TEL_PARAM_LEN = 13;
2053 contacts_number_type_e type;
2055 bool is_default = false;
2057 status = contacts_record_get_bool(number, _contacts_number.is_default,
2060 if (status != CONTACTS_ERROR_NONE)
2063 status = contacts_record_get_int(number,
2064 _contacts_number.type,
2067 if (status != CONTACTS_ERROR_NONE)
2070 strv = g_new0(char *, TEL_PARAM_LEN + 1);/* tel param max size is 13 */
2073 strv[i] = g_strdup("PREF");
2077 if (type & CONTACTS_NUMBER_TYPE_HOME) {
2078 strv[i] = g_strdup("HOME");
2082 if (type & CONTACTS_NUMBER_TYPE_WORK) {
2083 strv[i] = g_strdup("WORK");
2087 if (type & CONTACTS_NUMBER_TYPE_VOICE) {
2088 strv[i] = g_strdup("VOICE");
2092 if (type & CONTACTS_NUMBER_TYPE_FAX) {
2093 strv[i] = g_strdup("FAX");
2097 if (type & CONTACTS_NUMBER_TYPE_MSG) {
2098 strv[i] = g_strdup("MSG");
2102 if (type & CONTACTS_NUMBER_TYPE_CELL) {
2103 strv[i] = g_strdup("CELL");
2107 if (type & CONTACTS_NUMBER_TYPE_PAGER) {
2108 strv[i] = g_strdup("PAGER");
2112 if (type & CONTACTS_NUMBER_TYPE_BBS) {
2113 strv[i] = g_strdup("BBS");
2117 if (type & CONTACTS_NUMBER_TYPE_MODEM) {
2118 strv[i] = g_strdup("MODEM");
2122 if (type & CONTACTS_NUMBER_TYPE_CAR) {
2123 strv[i] = g_strdup("CAR");
2127 if (type & CONTACTS_NUMBER_TYPE_ISDN) {
2128 strv[i] = g_strdup("ISDN");
2132 if (type & CONTACTS_NUMBER_TYPE_VIDEO) {
2133 strv[i] = g_strdup("VIDEO");
2137 /* CTS_NUM_TYPE_PCS is not part of vcard2.1 */
2143 static gchar *__bluetooth_pb_contact_photo_type(const gchar *filename)
2146 gchar *filetype = NULL;
2149 if (g_file_test(filename, G_FILE_TEST_IS_REGULAR) == FALSE) {
2150 ERR_SECURE("file does not regular:%s\n", filename);
2154 ext = strrchr(filename, '.');
2156 ERR("file doesn't have extension\n");
2162 if (g_ascii_strcasecmp(ext, "gif") == 0)
2164 else if (g_ascii_strcasecmp(ext, "cgm") == 0)
2166 else if (g_ascii_strcasecmp(ext, "wmf") == 0)
2168 else if (g_ascii_strcasecmp(ext, "bmp") == 0)
2170 else if (g_ascii_strcasecmp(ext, "met") == 0)
2172 else if (g_ascii_strcasecmp(ext, "dib") == 0)
2174 else if (g_ascii_strcasecmp(ext, "pict") == 0 ||
2175 g_ascii_strcasecmp(ext, "pct") == 0 ||
2176 g_ascii_strcasecmp(ext, "pic") == 0)
2178 else if (g_ascii_strcasecmp(ext, "tiff") == 0 ||
2179 g_ascii_strcasecmp(ext, "tif") == 0)
2181 else if (g_ascii_strcasecmp(ext, "ps") == 0)
2183 else if (g_ascii_strcasecmp(ext, "pdf") == 0)
2185 else if (g_ascii_strcasecmp(ext, "jpeg") == 0 ||
2186 g_ascii_strcasecmp(ext, "jpg") == 0 ||
2187 g_ascii_strcasecmp(ext, "jpe") == 0)
2189 else if (g_ascii_strcasecmp(ext, "mpeg") == 0 ||
2190 g_ascii_strcasecmp(ext, "mpg") == 0)
2192 else if (g_ascii_strcasecmp(ext, "m2v") == 0)
2194 else if (g_ascii_strcasecmp(ext, "avi") == 0)
2196 else if (g_ascii_strcasecmp(ext, "mov") == 0)
2198 else if (g_ascii_strcasecmp(ext, "png") == 0)
2202 return g_strdup(filetype);
2205 static gchar **__bluetooth_pb_contact_addr(contacts_record_h address)
2208 const gint ADDR_LEN = 7;
2210 gchar **strv = NULL;
2212 gint addr[] = { _contacts_address.postbox,
2213 _contacts_address.extended,
2214 _contacts_address.street,
2215 _contacts_address.locality,
2216 _contacts_address.region,
2217 _contacts_address.postal_code,
2218 _contacts_address.country };
2220 strv = __bluetooth_pb_contact_add_field_str(address,
2226 static gchar **__bluetooth_pb_contact_addr_param(contacts_record_h address)
2229 contacts_address_type_e type;
2234 gchar **strv = NULL;
2236 status = contacts_record_get_int(address,
2237 _contacts_address.type,
2240 if (status != CONTACTS_ERROR_NONE)
2243 strv = g_new0(gchar *, 7); /* ADDR param max size is 6 */
2245 if (type & CONTACTS_ADDRESS_TYPE_HOME) {
2246 strv[i] = g_strdup("HOME");
2249 if (type & CONTACTS_ADDRESS_TYPE_WORK) {
2250 strv[i] = g_strdup("WORK");
2253 if (type & CONTACTS_ADDRESS_TYPE_DOM) {
2254 strv[i] = g_strdup("DOM");
2257 if (type & CONTACTS_ADDRESS_TYPE_INTL) {
2258 strv[i] = g_strdup("INTL");
2261 if (type & CONTACTS_ADDRESS_TYPE_POSTAL) {
2262 strv[i] = g_strdup("POSTAL");
2265 if (type & CONTACTS_ADDRESS_TYPE_PARCEL) {
2266 strv[i] = g_strdup("PARCEL");
2273 static gchar *__bluetooth_pb_phonelog_datetime(gint phonelog_id)
2276 contacts_record_h phone_log;
2278 char time_str[32] = {0,};
2283 struct tm time_info;
2285 status = contacts_db_get_record(_contacts_phone_log._uri,
2289 if (status != CONTACTS_ERROR_NONE)
2292 status = contacts_record_get_int(phone_log,
2293 _contacts_phone_log.log_time,
2296 if (status != CONTACTS_ERROR_NONE)
2302 localtime_r((time_t *)&time, &time_info);
2304 strftime(time_str, sizeof(time_str),
2305 "%Y%m%dT%H%M%S", &time_info);
2307 contacts_record_destroy(phone_log, TRUE);
2310 return g_strdup(time_str);
2313 static gchar *__bluetooth_pb_name_from_contact(contacts_record_h contact)
2316 contacts_record_h name = NULL;
2323 gint name_val[] = { _contacts_name.last,
2324 _contacts_name.first,
2325 _contacts_name.addition,
2326 _contacts_name.prefix,
2327 _contacts_name.suffix };
2330 status = contacts_record_get_child_record_at_p(contact,
2331 _contacts_contact.name, 0, &name);
2333 if (status != CONTACTS_ERROR_NONE)
2336 str = g_string_new(NULL);
2338 for (i = 0; i < name_size; i++) {
2340 gchar *escape = NULL;
2343 g_string_append_c(str, ';');
2345 status = contacts_record_get_str_p(name, name_val[i], &tmp);
2347 if (status != CONTACTS_ERROR_NONE)
2350 escape = __bluetooth_pb_vcard_escape(tmp);
2351 g_string_append(str, escape);
2357 return g_string_free(str, FALSE);
2360 static gchar *__bluetooth_pb_phonetic_name_from_contact(contacts_record_h contact)
2363 contacts_record_h name = NULL;
2369 gchar *phonetic_first = NULL;
2370 gchar *phonetic_last = NULL;
2371 gchar *escape = NULL;
2373 status = contacts_record_get_child_record_at_p(contact,
2374 _contacts_contact.name, 0, &name);
2376 if (status != CONTACTS_ERROR_NONE)
2379 status = contacts_record_get_str_p(name, _contacts_name.phonetic_first, &phonetic_first);
2381 if (status != CONTACTS_ERROR_NONE)
2384 if (phonetic_first == NULL)
2387 str = g_string_new(NULL);
2389 status = contacts_record_get_str_p(name, _contacts_name.phonetic_last, &phonetic_last);
2391 if ((status == CONTACTS_ERROR_NONE) && (phonetic_last != NULL)) {
2392 escape = __bluetooth_pb_vcard_escape(phonetic_last);
2393 g_string_append(str, escape);
2395 g_string_append_c(str, ' ');
2398 escape = __bluetooth_pb_vcard_escape(phonetic_first);
2399 g_string_append(str, escape);
2402 g_string_append_c(str, ';');
2403 g_string_append_c(str, ';');
2404 g_string_append_c(str, ';');
2405 g_string_append_c(str, ';');
2408 return g_string_free(str, FALSE);
2412 static gchar *__bluetooth_pb_number_from_contact(contacts_record_h contact)
2422 status = contacts_record_get_child_record_count(contact,
2423 _contacts_contact.number,
2426 if (status != CONTACTS_ERROR_NONE)
2429 for (i = 0; i < count; i++) {
2430 contacts_record_h number = NULL;
2434 bool is_default = false;
2436 status = contacts_record_get_child_record_at_p(contact,
2437 _contacts_contact.number, i, &number);
2439 if (status != CONTACTS_ERROR_NONE)
2442 status = contacts_record_get_bool(number,
2443 _contacts_number.is_default,
2446 if (status != CONTACTS_ERROR_NONE)
2449 if (is_default == FALSE)
2452 status = contacts_record_get_str_p(number,
2453 _contacts_number.number,
2456 if (status != CONTACTS_ERROR_NONE)
2460 str = g_strdup(tmp);
2465 /* get first number */
2469 contacts_record_h number = NULL;
2471 status = contacts_record_get_child_record_at_p(contact,
2472 _contacts_contact.number, 0, &number);
2474 if (status != CONTACTS_ERROR_NONE)
2477 status = contacts_record_get_str_p(number,
2478 _contacts_number.number,
2481 if (status != CONTACTS_ERROR_NONE)
2484 str = g_strdup(tmp);
2491 static gint __bluetooth_pb_person_id_from_phonelog_id(gint phonelog_id)
2494 contacts_query_h query = NULL;
2495 contacts_filter_h filter = NULL;
2496 contacts_list_h record_list = NULL;
2498 contacts_record_h phone_log = NULL;
2499 contacts_record_h record = NULL;
2504 status = contacts_db_get_record(_contacts_phone_log._uri,
2508 if (status != CONTACTS_ERROR_NONE)
2511 status = contacts_record_get_int(phone_log,
2512 _contacts_phone_log.person_id,
2515 if (status != CONTACTS_ERROR_NONE) {
2516 contacts_record_destroy(phone_log, TRUE);
2520 contacts_record_destroy(phone_log, TRUE);
2525 status = contacts_filter_create(_contacts_person_phone_log._uri,
2528 if (status != CONTACTS_ERROR_NONE)
2532 status = contacts_filter_add_int(filter,
2533 _contacts_person_phone_log.log_id,
2534 CONTACTS_MATCH_EQUAL,
2537 if (status != CONTACTS_ERROR_NONE)
2540 status = contacts_query_create(_contacts_person_phone_log._uri, &query);
2542 if (status != CONTACTS_ERROR_NONE)
2545 status = contacts_query_set_filter(query, filter);
2547 if (status != CONTACTS_ERROR_NONE)
2550 status = contacts_db_get_records_with_query(query, -1, -1,
2553 if (status != CONTACTS_ERROR_NONE)
2556 status = contacts_list_first(record_list);
2558 if (status != CONTACTS_ERROR_NONE)
2561 status = contacts_list_get_current_record_p(record_list, &record);
2563 if (status != CONTACTS_ERROR_NONE)
2566 status = contacts_record_get_int(record,
2567 _contacts_person_phone_log.person_id,
2570 if (status != CONTACTS_ERROR_NONE)
2574 if (record_list != NULL)
2575 contacts_list_destroy(record_list, TRUE);
2577 contacts_filter_destroy(filter);
2580 contacts_query_destroy(query);
2586 int _bluetooth_get_contact_addressbook(gint person_id)
2588 contacts_record_h person = NULL;
2589 contacts_record_h contact = NULL;
2590 contacts_record_h addressbook = NULL;
2592 char* addressbook_name = NULL;
2593 gint contact_id = 0;
2594 gint address_book_id = 0;
2597 status = contacts_db_get_record(_contacts_person._uri,
2600 if (status != CONTACTS_ERROR_NONE)
2601 return PBAP_ADDRESSBOOK_PHONE; /* Default*/
2603 status = contacts_record_get_int(person,
2604 _contacts_person.display_contact_id,
2606 contacts_record_destroy(person, TRUE);
2608 if (status != CONTACTS_ERROR_NONE)
2609 return PBAP_ADDRESSBOOK_PHONE; /* Default*/
2611 status = contacts_db_get_record(_contacts_contact._uri,
2614 if (status != CONTACTS_ERROR_NONE)
2615 return PBAP_ADDRESSBOOK_PHONE; /* Default*/
2617 status = contacts_record_get_int(contact,
2618 _contacts_contact.address_book_id,
2620 contacts_record_destroy(contact, TRUE);
2622 if (status != CONTACTS_ERROR_NONE)
2623 return PBAP_ADDRESSBOOK_PHONE; /* Default*/
2625 status = contacts_db_get_record(_contacts_address_book._uri,
2628 if (status != CONTACTS_ERROR_NONE)
2629 return PBAP_ADDRESSBOOK_PHONE; /* Default*/
2631 status = contacts_record_get_str_p(addressbook, _contacts_address_book.name,
2633 contacts_record_destroy(addressbook, TRUE);
2635 if (status != CONTACTS_ERROR_NONE)
2636 return PBAP_ADDRESSBOOK_PHONE; /* Default*/
2638 if (address_book_id == 0 || _bt_is_sim_addressbook(addressbook_name) == false)
2639 return PBAP_ADDRESSBOOK_PHONE;
2641 return PBAP_ADDRESSBOOK_SIM;
2644 gchar *_bluetooth_pb_vcard_contact(gint person_id,
2654 str = __bluetooth_pb_vcard_real_contact_with_properties(person_id, 0,
2661 gchar *_bluetooth_pb_vcard_contact_owner(const gchar *number,
2666 GString *str = g_string_new("BEGIN:VCARD\r\n");
2670 fn = _bluetooth_pb_owner_name();
2671 name = g_strdup_printf("%s;;;;", fn);
2674 case VCARD_FORMAT_3_0:
2675 g_string_append(str, "VERSION:3.0\r\n");
2677 __bluetooth_pb_vcard_append_v30(str, "N", NULL, name);
2678 __bluetooth_pb_vcard_append_v30(str, "FN", NULL, fn);
2679 __bluetooth_pb_vcard_append_v30(str, "TEL", "TYPE=CELL",
2682 case VCARD_FORMAT_2_1:
2684 g_string_append(str, "VERSION:2.1\r\n");
2686 __bluetooth_pb_vcard_append_qp_encode_v21(str, "N", NULL, name);
2688 if (filter == 0 || (filter & VCARD_FN))
2689 __bluetooth_pb_vcard_append_qp_encode_v21(str, "FN",
2692 __bluetooth_pb_vcard_append_qp_encode_v21(str, "TEL", "CELL",
2698 g_string_append(str, "END:VCARD\r\n");
2704 return g_string_free(str, FALSE);
2707 gchar *_bluetooth_pb_vcard_call(gint phonelog_id,
2718 ERR("Unknown attribute type ignored\n");
2722 person_id = __bluetooth_pb_person_id_from_phonelog_id(phonelog_id);
2724 DBG("person_id %d\n", person_id);
2727 if (filter == 0 || (filter & VCARD_X_IRMC_CALL_DATETIME)) {
2728 gchar *datetime = NULL;
2730 datetime = __bluetooth_pb_phonelog_datetime(
2733 str = __bluetooth_pb_vcard_real_contact_with_properties(
2737 "X-IRMC-CALL-DATETIME", attr, datetime,
2743 str = __bluetooth_pb_vcard_real_contact_with_properties(
2750 str = __bluetooth_pb_vcard_real_call(phonelog_id, filter,
2757 gchar *_bluetooth_pb_fn_from_person_id(gint person_id)
2760 contacts_record_h person = NULL;
2766 status = contacts_db_get_record(_contacts_person._uri,
2770 if (status != CONTACTS_ERROR_NONE)
2773 status = contacts_record_get_str(person,
2774 _contacts_person.display_name,
2777 if (status != CONTACTS_ERROR_NONE)
2780 contacts_record_destroy(person, TRUE);
2786 gchar *_bluetooth_pb_name_from_person_id(gint person_id)
2789 contacts_record_h person = NULL;
2790 contacts_record_h contact = NULL;
2793 gint contact_id = 0;
2797 status = contacts_db_get_record(_contacts_person._uri,
2801 if (status != CONTACTS_ERROR_NONE)
2804 status = contacts_record_get_int(person,
2805 _contacts_person.display_contact_id,
2808 if (status != CONTACTS_ERROR_NONE) {
2809 contacts_record_destroy(person, TRUE);
2813 status = contacts_db_get_record(_contacts_contact._uri,
2817 if (status != CONTACTS_ERROR_NONE) {
2818 contacts_record_destroy(person, TRUE);
2822 str = __bluetooth_pb_name_from_contact(contact);
2824 contacts_record_destroy(contact, TRUE);
2825 contacts_record_destroy(person, TRUE);
2831 gchar *_bluetooth_pb_number_from_person_id(gint person_id)
2834 contacts_record_h person = NULL;
2835 contacts_record_h contact = NULL;
2838 gint contact_id = 0;
2842 status = contacts_db_get_record(_contacts_person._uri,
2846 if (status != CONTACTS_ERROR_NONE)
2850 status = contacts_record_get_int(person,
2851 _contacts_person.display_contact_id,
2854 if (status != CONTACTS_ERROR_NONE) {
2855 contacts_record_destroy(person, TRUE);
2859 status = contacts_db_get_record(_contacts_contact._uri,
2863 if (status != CONTACTS_ERROR_NONE) {
2864 contacts_record_destroy(person, TRUE);
2868 str = __bluetooth_pb_number_from_contact(contact);
2870 contacts_record_destroy(contact, TRUE);
2871 contacts_record_destroy(person, TRUE);
2877 gchar *_bluetooth_pb_fn_from_phonelog_id(gint phonelog_id)
2883 person_id = __bluetooth_pb_person_id_from_phonelog_id(phonelog_id);
2886 str = _bluetooth_pb_fn_from_person_id(person_id);
2894 gchar *_bluetooth_pb_name_from_phonelog_id(gint phonelog_id)
2900 person_id = __bluetooth_pb_person_id_from_phonelog_id(phonelog_id);
2903 str = _bluetooth_pb_name_from_person_id(person_id);
2907 tmp = _bluetooth_pb_number_from_phonelog_id(phonelog_id);
2908 str = g_strdup_printf("%s;;;;", tmp);
2917 gchar *_bluetooth_pb_number_from_phonelog_id(gint phonelog_id)
2920 contacts_record_h phone_log;
2927 status = contacts_db_get_record(_contacts_phone_log._uri,
2928 phonelog_id, &phone_log);
2930 if (status != CONTACTS_ERROR_NONE)
2933 status = contacts_record_get_str_p(phone_log,
2934 _contacts_phone_log.address,
2937 if (status != CONTACTS_ERROR_NONE) {
2938 contacts_record_destroy(phone_log, TRUE);
2942 str = g_strdup(tmp);
2944 contacts_record_destroy(phone_log, TRUE);
2950 gchar *_bluetooth_pb_owner_name(void)
2955 name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
2958 name = g_strdup("My Name");
2964 bool _bt_is_sim_addressbook(const char *addressbook)
2966 return g_str_has_prefix(addressbook, SIM_ADDRESSBOOK_PREFIX);