4 * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
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.
24 #include "ctsvc_internal.h"
25 #include "ctsvc_db_sqlite.h"
26 #include "ctsvc_db_schema.h"
27 #include "ctsvc_db_init.h"
28 #include "ctsvc_db_utils.h"
29 #include "ctsvc_record.h"
30 #include "ctsvc_normalize.h"
31 #include "ctsvc_server_setting.h"
32 #include "ctsvc_localize.h"
33 #include "ctsvc_localize_utils.h"
34 #include "ctsvc_localize_ch.h"
35 #include "ctsvc_notification.h"
36 #include "ctsvc_notify.h"
37 #include "ctsvc_db_access_control.h"
39 #include "ctsvc_db_plugin_contact_helper.h"
40 #include "ctsvc_db_plugin_company_helper.h"
41 #include "ctsvc_db_plugin_name_helper.h"
42 #include "ctsvc_db_plugin_number_helper.h"
43 #include "ctsvc_db_plugin_email_helper.h"
44 #include "ctsvc_db_plugin_event_helper.h"
45 #include "ctsvc_db_plugin_url_helper.h"
46 #include "ctsvc_db_plugin_note_helper.h"
47 #include "ctsvc_db_plugin_profile_helper.h"
48 #include "ctsvc_db_plugin_address_helper.h"
49 #include "ctsvc_db_plugin_nickname_helper.h"
50 #include "ctsvc_db_plugin_messenger_helper.h"
51 #include "ctsvc_db_plugin_relationship_helper.h"
52 #include "ctsvc_db_plugin_image_helper.h"
53 #include "ctsvc_db_plugin_extension_helper.h"
54 #include "ctsvc_db_plugin_sip_helper.h"
56 #include "ctsvc_server_person.h"
57 #include "ctsvc_server_group.h"
59 #ifdef ENABLE_LOG_FEATURE
60 #include "ctsvc_server_phonelog.h"
61 #endif /* ENABLE_LOG_FEATURE */
63 #define CTSVC_CONTACT_INITIAL_DATA_MAX_LEN 128
65 int ctsvc_contact_add_image_file(int parent_id, int img_id,
66 char *src_img, char *dest, int dest_size)
74 RETV_IF(NULL == src_img, CONTACTS_ERROR_INVALID_PARAMETER);
76 ext = strrchr(src_img, '.');
77 if (NULL == ext || strchr(ext, '/'))
80 lower_ext = strdup(ext);
85 return CONTACTS_ERROR_OUT_OF_MEMORY;
89 *temp = tolower(*temp);
93 version = ctsvc_get_next_ver();
94 snprintf(dest, dest_size, "%d_%d-%d%s", parent_id, img_id, version, lower_ext);
97 ret = ctsvc_utils_copy_image(CTSVC_CONTACT_IMG_FULL_LOCATION, src_img, dest);
98 if (CONTACTS_ERROR_NONE != ret) {
100 ERR("ctsvc_utils_copy_image() Fail(%d)", ret);
106 return CONTACTS_ERROR_NONE;
109 static int __ctsvc_contact_get_current_image_file(int image_id, char *dest, int dest_size)
114 char query[CTS_SQL_MIN_LEN] = {0};
116 snprintf(query, sizeof(query), "SELECT data3 FROM %s WHERE id = %d", CTS_TABLE_DATA, image_id);
117 ret = ctsvc_query_prepare(query, &stmt);
118 RETVM_IF(NULL == stmt, ret, "ctsvc_query_prepare() Fail(%d)", ret);
120 ret = ctsvc_stmt_step(stmt);
121 if (1 /*CTS_TRUE*/ != ret) {
122 /* LCOV_EXCL_START */
123 ERR("DB error: ctsvc_stmt_step() Fail(%d)", ret);
124 ctsvc_stmt_finalize(stmt);
125 if (CONTACTS_ERROR_NONE == ret)
126 return CONTACTS_ERROR_NO_DATA;
132 tmp_path = ctsvc_stmt_get_text(stmt, 0);
134 snprintf(dest, dest_size, "%s/%s", CTSVC_CONTACT_IMG_FULL_LOCATION, tmp_path);
136 ctsvc_stmt_finalize(stmt);
137 return CONTACTS_ERROR_NONE;
141 * check that the image file under location or not
142 * we should check CTSVC_CONTACT_IMG_FULL_LOCATION, CTSVC_VCARD_IMAGE_LOCATION,
143 * CTS_GROUP_IMAGE_LOCATION, CTS_LOGO_IMAGE_LOCATION
145 bool ctsvc_contact_check_image_location(const char *path)
150 if (path == NULL || *path == '\0')
153 slash = strrchr(path, '/');
154 if (slash == NULL || slash == path)
157 len = (int)(slash-path);
158 if (len != strlen(CTSVC_CONTACT_IMG_FULL_LOCATION))
161 if (STRING_EQUAL == strncmp(path, CTSVC_CONTACT_IMG_FULL_LOCATION, len))
167 int ctsvc_contact_update_image_file(int parent_id, int img_id,
168 char *src_img, char *dest_name, int dest_size)
171 char dest[CTSVC_IMG_FULL_PATH_SIZE_MAX] = {0};
172 char *thumbnail_path = NULL;
174 ret = __ctsvc_contact_get_current_image_file(img_id, dest, sizeof(dest));
176 WARN_IF(CONTACTS_ERROR_NONE != ret && CONTACTS_ERROR_NO_DATA != ret,
177 "__ctsvc_contact_get_current_image_file() Fail(%d)", ret);
179 if (src_img && STRING_EQUAL == strcmp(dest, src_img)) {
180 snprintf(dest_name, dest_size, "%s", src_img + strlen(CTSVC_CONTACT_IMG_FULL_LOCATION) + 1);
181 return CONTACTS_ERROR_NONE;
186 WARN("unlink() Fail(%d)", errno);
188 /* remove thumbnail */
189 thumbnail_path = ctsvc_utils_get_thumbnail_path(dest);
190 if (thumbnail_path && 0 == access(thumbnail_path, F_OK)) {
191 ret = unlink(thumbnail_path);
193 WARN("unlink() Fail(%d)", errno);
195 free(thumbnail_path);
199 ret = ctsvc_contact_add_image_file(parent_id, img_id, src_img, dest_name, dest_size);
200 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_contact_add_image_file() Fail(%d)", ret);
206 int ctsvc_db_contact_update_changed_time(int contact_id)
209 char query[CTS_SQL_MIN_LEN] = {0};
211 snprintf(query, sizeof(query),
212 "UPDATE %s SET changed_ver=%d, changed_time=%d WHERE contact_id=%d AND deleted = 0",
213 CTS_TABLE_CONTACTS, ctsvc_get_next_ver(), (int)time(NULL), contact_id);
215 ret = ctsvc_query_exec(query);
216 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_query_exec() Fail(%d)", ret);
218 ctsvc_set_contact_noti();
220 return CONTACTS_ERROR_NONE;
223 int ctsvc_contact_delete_image_file_with_path(const unsigned char *image_path)
228 char full_path[CTSVC_IMG_FULL_PATH_SIZE_MAX] = {0};
229 char *thumbnail_path = NULL;
230 snprintf(full_path, sizeof(full_path), "%s/%s", CTSVC_CONTACT_IMG_FULL_LOCATION, image_path);
231 ret = unlink(full_path);
233 WARN("unlink() Fail(%d)", errno);
235 /* remove thumbnail */
236 thumbnail_path = ctsvc_utils_get_thumbnail_path(full_path);
237 if (thumbnail_path && 0 == access(thumbnail_path, F_OK)) {
238 ret = unlink(thumbnail_path);
240 WARN("unlink() Fail(%d)", errno);
242 free(thumbnail_path);
245 return CONTACTS_ERROR_NONE;
248 int ctsvc_db_contact_delete(int contact_id)
251 int ret, rel_changed;
255 char query[CTS_SQL_MAX_LEN] = {0};
256 cts_stmt stmt = NULL;
259 ret = ctsvc_begin_trans();
260 RETVM_IF(ret, ret, "ctsvc_begin_trans() Fail(%d)", ret);
262 snprintf(query, sizeof(query),
263 "SELECT addressbook_id, person_id "
264 "FROM "CTS_TABLE_CONTACTS" WHERE contact_id = %d AND deleted = 0", contact_id);
266 ret = ctsvc_query_prepare(query, &stmt);
268 /* LCOV_EXCL_START */
269 ERR("ctsvc_query_prepare() Fail(%d)", ret);
270 ctsvc_end_trans(false);
275 ret = ctsvc_stmt_step(stmt);
277 /* LCOV_EXCL_START */
278 ERR("ctsvc_stmt_step() Fail(%d)", ret);
279 ctsvc_stmt_finalize(stmt);
280 ctsvc_end_trans(false);
281 if (CONTACTS_ERROR_NONE == ret)
282 return CONTACTS_ERROR_NO_DATA;
288 addressbook_id = ctsvc_stmt_get_int(stmt, 0);
289 person_id = ctsvc_stmt_get_int(stmt, 1);
290 DBG("addressbook_id : %d, person_id : %d", addressbook_id, person_id);
291 ctsvc_stmt_finalize(stmt);
294 if (false == ctsvc_have_ab_write_permission(addressbook_id, false)) {
295 /* LCOV_EXCL_START */
296 ERR("No permission in this addresbook_id(%d)", addressbook_id);
297 ctsvc_end_trans(false);
298 return CONTACTS_ERROR_PERMISSION_DENIED;
302 version = ctsvc_get_next_ver();
303 snprintf(query, sizeof(query),
304 "UPDATE %s SET member_changed_ver=%d "
305 "WHERE group_id IN (SELECT group_id FROM %s WHERE contact_id = %d AND deleted = 0) ",
306 CTS_TABLE_GROUPS, version, CTS_TABLE_GROUP_RELATIONS, contact_id);
307 ret = ctsvc_query_exec(query);
308 if (CONTACTS_ERROR_NONE != ret) {
309 /* LCOV_EXCL_START */
310 ERR("ctsvc_query_exec() Fail(%d)", ret);
311 ctsvc_end_trans(false);
315 rel_changed = ctsvc_db_change();
317 snprintf(query, sizeof(query),
318 "UPDATE %s SET deleted = 1, person_id = 0, changed_ver=%d WHERE contact_id = %d",
319 CTS_TABLE_CONTACTS, version, contact_id);
320 ret = ctsvc_query_exec(query);
321 if (CONTACTS_ERROR_NONE != ret) {
322 /* LCOV_EXCL_START */
323 ERR("ctsvc_query_exec() Fail(%d)", ret);
324 ctsvc_end_trans(false);
329 snprintf(query, sizeof(query), "SELECT link_count FROM "CTS_TABLE_PERSONS" WHERE person_id = %d", person_id);
330 ret = ctsvc_query_get_first_int_result(query, &link_count);
331 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_query_get_first_int_result() Fail(%d)", ret);
333 * set dirty bit to person by trigger
334 * : person will be aggregated in ctsvc_person_aggregate
337 if (1 < link_count) {
338 ctsvc_person_aggregate(person_id);
340 #ifdef ENABLE_LOG_FEATURE
341 /* update phonelog */
342 ctsvc_db_phone_log_update_person_id(NULL, person_id, -1, false, NULL);
343 #endif /* ENABLE_LOG_FEATURE */
345 ctsvc_set_person_noti();
348 ctsvc_set_contact_noti();
350 ctsvc_set_group_rel_noti();
352 ret = ctsvc_end_trans(true);
353 if (ret < CONTACTS_ERROR_NONE) {
354 /* LCOV_EXCL_START */
355 ERR("ctsvc_end_trans() Fail(%d)", ret);
359 return CONTACTS_ERROR_NONE;
363 static inline void __ctsvc_contact_get_initial(char *src, char *dest, int dest_size, bool pinyin)
367 int len = strlen(src);
368 for (i = 0; i < len && j < (dest_size-1);) {
373 int char_len = ctsvc_check_utf8(src[i]);
375 for (k = 0; k < char_len && j < (dest_size-1); k++)
376 dest[j++] = src[i++];
377 if (false == pinyin && j < (dest_size-1))
386 static inline void __ctsvc_remove_space(char *src, char *dest, int dest_size)
388 int len = strlen(src);
391 for (i = 0; i < len && i < dest_size; i++) {
392 if (src[i] && src[i] != ' ') {
400 /* make search name to insert search_index table name column
401 * korean : display_name, chosung, phonetic
402 * japanese : dislay_name(hiragana), phonetic
403 * if display_name is chinese and sort_name(phonetic) is japanese,
404 * then search_name is normalized_name and sort_name (phonetic)
405 * chinese : display_name, pinyin name, pinyin initial, phonetic
406 * others : display_name, phonetic
408 int ctsvc_contact_make_search_name(ctsvc_contact_s *contact, char **search_name)
411 char *temp_name = NULL;
414 RETV_IF(NULL == contact, CONTACTS_ERROR_NO_DATA);
416 if (contact->display_name) {
417 if (ctsvc_has_chinese(contact->display_name)) {
418 if (CTSVC_LANG_JAPANESE == ctsvc_check_language_type(contact->sort_name)) {
419 char *normalized_display_name = NULL;
421 ctsvc_normalize_str(contact->display_name, &normalized_display_name);
422 if (normalized_display_name) {
423 buf_size = SAFE_STRLEN(normalized_display_name) + strlen(contact->sort_name) + 2;
424 name = calloc(1, buf_size);
426 /* LCOV_EXCL_START */
427 ERR("calloc() Fail");
428 free(normalized_display_name);
429 return CONTACTS_ERROR_OUT_OF_MEMORY;
432 snprintf(name, buf_size, "%s %s", normalized_display_name, contact->sort_name);
433 free(normalized_display_name);
436 char *langset = ctsvc_get_langset();
437 if (STRING_EQUAL == strncmp(langset, "zh_CN", strlen("zh_CN"))) {
438 pinyin_name_s *pinyinname;
441 ret = ctsvc_convert_chinese_to_pinyin(contact->display_name, &pinyinname, &size);
442 if (CONTACTS_ERROR_NONE == ret) {
443 int name_len = (CHINESE_PINYIN_SPELL_MAX_LEN*strlen(contact->display_name)+1) *sizeof(char);
444 char *name_nospace = calloc(1, name_len);
445 if (NULL == name_nospace) {
446 /* LCOV_EXCL_START */
447 ERR("calloc() Fail");
448 ctsvc_pinyin_free(pinyinname, size);
449 return CONTACTS_ERROR_OUT_OF_MEMORY;
452 char *temp_name = NULL;
454 ctsvc_normalize_str(contact->display_name, &name);
456 for (i = 0; i < size; i++) {
457 __ctsvc_remove_space(pinyinname[i].pinyin_name, name_nospace, name_len);
459 buf_size = SAFE_STRLEN(name)
460 + SAFE_STRLEN(pinyinname[i].pinyin_name)
461 + SAFE_STRLEN(name_nospace)
462 + SAFE_STRLEN(pinyinname[i].pinyin_initial)
464 temp_name = calloc(1, buf_size);
465 if (NULL == temp_name) {
466 /* LCOV_EXCL_START */
467 ERR("calloc() Fail");
469 ctsvc_pinyin_free(pinyinname, size);
471 return CONTACTS_ERROR_OUT_OF_MEMORY;
474 snprintf(temp_name, buf_size, "%s %s %s %s",
475 name, pinyinname[i].pinyin_name, name_nospace, pinyinname[i].pinyin_initial);
481 len = ctsvc_check_utf8(contact->display_name[0]);
482 for (i = len; i < strlen(contact->display_name); i += len) {
483 len = ctsvc_check_utf8(contact->display_name[i]);
485 buf_size = SAFE_STRLEN(name) + SAFE_STRLEN(&contact->display_name[i]) + 2;
486 temp_name = calloc(1, buf_size);
487 if (NULL == temp_name) {
488 /* LCOV_EXCL_START */
489 ERR("calloc() Fail");
491 ctsvc_pinyin_free(pinyinname, size);
493 return CONTACTS_ERROR_OUT_OF_MEMORY;
496 snprintf(temp_name, buf_size, "%s %s", name, &contact->display_name[i]);
503 ctsvc_pinyin_free(pinyinname, size);
505 char initial[CTSVC_CONTACT_INITIAL_DATA_MAX_LEN] = {0,};
506 char *normalized_display_name = NULL;
508 ctsvc_normalize_str(contact->display_name, &normalized_display_name);
509 if (normalized_display_name) {
510 __ctsvc_contact_get_initial(contact->display_name, initial, sizeof(initial), false);
511 buf_size = SAFE_STRLEN(normalized_display_name) + strlen(initial) + 2;
512 name = calloc(1, buf_size);
514 /* LCOV_EXCL_START */
515 ERR("calloc() Fail");
516 free(normalized_display_name);
517 return CONTACTS_ERROR_OUT_OF_MEMORY;
520 snprintf(name, buf_size, "%s %s", normalized_display_name, initial);
522 free(normalized_display_name);
526 char initial[CTSVC_CONTACT_INITIAL_DATA_MAX_LEN] = {0,};
527 char *normalized_display_name = NULL;
529 ctsvc_normalize_str(contact->display_name, &normalized_display_name);
530 if (normalized_display_name) {
531 __ctsvc_contact_get_initial(contact->display_name, initial, sizeof(initial), false);
532 buf_size = SAFE_STRLEN(normalized_display_name) + strlen(initial) + 2;
533 name = calloc(1, buf_size);
535 /* LCOV_EXCL_START */
536 ERR("calloc() Fail");
537 free(normalized_display_name);
538 return CONTACTS_ERROR_OUT_OF_MEMORY;
541 snprintf(name, buf_size, "%s %s", normalized_display_name, initial);
543 free(normalized_display_name);
547 } else if (ctsvc_has_korean(contact->display_name)) {
548 /* 'a가' should be searched by 'ㄱ' */
550 int full_len, chosung_len;
551 char *chosung = calloc(1, strlen(contact->display_name) * 5);
552 if (NULL == chosung) {
553 /* LCOV_EXCL_START */
554 ERR("calloc() Fail");
555 return CONTACTS_ERROR_OUT_OF_MEMORY;
558 int total_len = strlen(contact->display_name);
560 count = ctsvc_get_chosung(contact->display_name, chosung, strlen(contact->display_name) * 5);
562 ctsvc_normalize_str(contact->display_name, &name);
565 for (i = 0, j = 0; i < total_len; i += full_len, j += chosung_len) {
566 full_len = ctsvc_check_utf8(contact->display_name[i]);
567 chosung_len = ctsvc_check_utf8(chosung[j]);
569 buf_size = SAFE_STRLEN(name) + SAFE_STRLEN(&contact->display_name[i]) + SAFE_STRLEN(&chosung[j]) + 3;
570 temp_name = calloc(1, buf_size);
571 if (NULL == temp_name) {
572 /* LCOV_EXCL_START */
573 ERR("calloc() Fail");
576 return CONTACTS_ERROR_OUT_OF_MEMORY;
580 snprintf(temp_name, buf_size, "%s %s %s", name, &contact->display_name[i], &chosung[j]);
587 } else if (CTSVC_LANG_JAPANESE == ctsvc_check_language_type(contact->display_name)) {
588 ctsvc_convert_japanese_to_hiragana(contact->display_name, &name);
590 /* Insert 'ABO Â' for 'ÂBC' */
591 char initial[CTSVC_CONTACT_INITIAL_DATA_MAX_LEN] = {0};
592 char *normalized_display_name = NULL;
594 ctsvc_normalize_str(contact->display_name, &normalized_display_name);
595 if (normalized_display_name) {
596 __ctsvc_contact_get_initial(contact->display_name, initial, sizeof(initial), false);
597 buf_size = SAFE_STRLEN(normalized_display_name) + strlen(initial) + 2;
598 name = calloc(1, buf_size);
600 /* LCOV_EXCL_START */
601 ERR("calloc() Fail");
602 free(normalized_display_name);
603 return CONTACTS_ERROR_OUT_OF_MEMORY;
606 snprintf(name, buf_size, "%s %s", normalized_display_name, initial);
608 free(normalized_display_name);
613 /* append phonetic name */
615 contacts_list_h name_list = (contacts_list_h)contact->name;
616 ctsvc_name_s *name_record;
617 contacts_list_first(name_list);
618 char *phonetic = NULL;
621 contacts_list_get_current_record_p(name_list, (contacts_record_h*)&name_record);
623 buf_size = SAFE_STRLEN(name_record->phonetic_first) + SAFE_STRLEN(name_record->phonetic_last) + SAFE_STRLEN(name_record->phonetic_middle);
625 buf_size += 3; /* for space and null string */
626 phonetic = calloc(1, buf_size);
627 if (NULL == phonetic) {
628 /* LCOV_EXCL_START */
629 ERR("calloc() Fail");
631 return CONTACTS_ERROR_OUT_OF_MEMORY;
635 if (name_record->phonetic_first)
636 temp_len += snprintf(phonetic, buf_size, "%s", name_record->phonetic_first);
637 if (name_record->phonetic_middle) {
639 temp_len += snprintf(phonetic + temp_len, buf_size - temp_len, " ");
640 temp_len += snprintf(phonetic + temp_len, buf_size - temp_len, "%s", name_record->phonetic_middle);
642 if (name_record->phonetic_last) {
644 temp_len += snprintf(phonetic + temp_len, buf_size - temp_len, " ");
645 temp_len += snprintf(phonetic + temp_len, buf_size - temp_len, "%s", name_record->phonetic_last);
649 buf_size = SAFE_STRLEN(name) + SAFE_STRLEN(phonetic) + 2;
650 temp_name = calloc(1, buf_size);
651 if (NULL == temp_name) {
652 /* LCOV_EXCL_START */
653 ERR("calloc() Fail");
656 return CONTACTS_ERROR_OUT_OF_MEMORY;
659 snprintf(temp_name, buf_size, "%s %s", name, phonetic);
671 return CONTACTS_ERROR_NONE;
674 static int __ctsvc_make_phonetic_name(ctsvc_name_s *name, char **phonetic, contacts_name_display_order_e order)
676 int len = SAFE_STRLEN(name->phonetic_first) + SAFE_STRLEN(name->phonetic_last) + SAFE_STRLEN(name->phonetic_middle);
678 len += 3; /* for space and null string */
679 *phonetic = calloc(1, len);
680 if (NULL == *phonetic) {
681 /* LCOV_EXCL_START */
682 ERR("calloc() Fail");
683 return CONTACTS_ERROR_OUT_OF_MEMORY;
688 if (order == CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST) {
689 if (name->phonetic_first)
690 temp_len += snprintf(*phonetic, len, "%s", name->phonetic_first);
691 if (name->phonetic_middle) {
693 temp_len += snprintf(*phonetic + temp_len, len - temp_len, " ");
694 temp_len += snprintf(*phonetic + temp_len, len - temp_len, "%s", name->phonetic_middle);
696 if (name->phonetic_last) {
698 temp_len += snprintf(*phonetic + temp_len, len - temp_len, " ");
699 temp_len += snprintf(*phonetic + temp_len, len - temp_len, "%s", name->phonetic_last);
702 if (name->phonetic_last)
703 temp_len += snprintf(*phonetic, len, "%s", name->phonetic_last);
704 if (name->phonetic_middle) {
706 temp_len += snprintf(*phonetic + temp_len, len - temp_len, " ");
707 temp_len += snprintf(*phonetic + temp_len, len - temp_len, "%s", name->phonetic_middle);
709 if (name->phonetic_first) {
711 temp_len += snprintf(*phonetic + temp_len, len - temp_len, " ");
712 temp_len += snprintf(*phonetic + temp_len, len - temp_len, "%s", name->phonetic_first);
717 return CONTACTS_ERROR_NONE;
720 static inline int __ctsvc_get_sort_name_to_pinyin(const char *display_name, char **sort_name)
724 pinyin_name_s *pinyinname = NULL;
727 if (false == ctsvc_has_chinese(display_name))
728 return CONTACTS_ERROR_INVALID_PARAMETER;
730 ret = ctsvc_convert_chinese_to_pinyin(display_name, &pinyinname, &size);
732 if (ret == CONTACTS_ERROR_NONE) {
733 char temp[strlen(display_name) * 2 + strlen(pinyinname[0].pinyin_name)];
734 int pinyin_index = 0;
742 if (pinyinname[0].pinyin_name[pinyin_index] == '\0') {
743 if (display_name[name_index] != '\0') {
744 temp[temp_index] = ' ';
746 name_len = ctsvc_check_utf8(display_name[name_index]);
748 memcpy(&(temp[temp_index]), &(display_name[name_index]), name_len);
749 temp_index += name_len;
750 name_index += name_len;
755 pinyin_len = ctsvc_check_utf8(pinyinname[0].pinyin_name[pinyin_index]);
758 memcpy(&(temp[temp_index]), &(pinyinname[0].pinyin_name[pinyin_index]), pinyin_len);
759 temp_index += pinyin_len;
761 if (pinyinname[0].pinyin_name[pinyin_index] == ' ') {
762 name_len = ctsvc_check_utf8(display_name[name_index]);
766 if (name_len == 1 && display_name[name_index] == ' ') {
767 temp[temp_index] = ' ';
771 memcpy(&(temp[temp_index]), &(display_name[name_index]), name_len);
772 temp_index += name_len;
773 name_index += name_len;
774 temp[temp_index] = ' ';
778 pinyin_index += pinyin_len;
780 temp[temp_index] = '\0';
781 *sort_name = strdup(temp);
782 ctsvc_pinyin_free(pinyinname, size);
787 void ctsvc_contact_make_sortkey(ctsvc_contact_s *contact)
789 char *sortkey = NULL;
790 char *phonetic = NULL;
793 if (contact->display_source_type == CONTACTS_DISPLAY_NAME_SOURCE_TYPE_NAME) {
794 if (0 < contact->name->count && contact->name->records
795 && contact->name->records->data) {
796 ctsvc_name_s *name = (ctsvc_name_s*)contact->name->records->data;
797 __ctsvc_make_phonetic_name(name, &phonetic, CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST);
802 sort_type = ctsvc_get_name_sort_type(phonetic);
803 else if (contact->sort_name)
804 sort_type = ctsvc_get_name_sort_type(contact->sort_name);
806 sort_type = CTSVC_SORT_OTHERS;
808 WARN_IF(sort_type < 0, "ctsvc_get_name_sort_type Fail(%d)", sort_type);
809 char *langset = ctsvc_get_langset();
814 if (STRING_EQUAL == strncmp(langset, "zh_CN", strlen("zh_CN"))) {
815 /* chinese to pinyin */
818 __ctsvc_get_sort_name_to_pinyin(phonetic, &pinyin);
820 __ctsvc_get_sort_name_to_pinyin(contact->sort_name, &pinyin);
823 free(contact->sort_name);
824 contact->sort_name = pinyin;
825 sort_type = CTSVC_SORT_WESTERN;
827 } else if (STRING_EQUAL == strncmp(langset, "ko_KR", strlen("ko_KR"))) {
828 sort_type = CTSVC_SORT_KOREAN;
832 case CTSVC_SORT_JAPANESE:
834 char *hiragana = NULL;
835 ctsvc_convert_japanese_to_hiragana(contact->sort_name, &hiragana);
838 free(contact->sort_name);
839 contact->sort_name = hiragana;
846 FREEandSTRDUP(contact->sort_name, phonetic);
854 if (ctsvc_get_primary_sort() == sort_type)
855 contact->display_name_language = CTSVC_SORT_PRIMARY;
856 else if (ctsvc_get_secondary_sort() == sort_type)
857 contact->display_name_language = CTSVC_SORT_SECONDARY;
858 else if (sort_type < 0)
859 contact->display_name_language = CTSVC_SORT_OTHERS;
861 contact->display_name_language = sort_type;
864 * check reverse sort_name, reverser_display_name_language
865 * make reverse phonetic name
867 if (contact->display_source_type == CONTACTS_DISPLAY_NAME_SOURCE_TYPE_NAME) {
868 if (0 < contact->name->count && contact->name->records
869 && contact->name->records->data) {
870 ctsvc_name_s *name = (ctsvc_name_s*)contact->name->records->data;
871 __ctsvc_make_phonetic_name(name, &phonetic, CONTACTS_NAME_DISPLAY_ORDER_LASTFIRST);
876 sort_type = ctsvc_get_name_sort_type(phonetic);
877 else if (contact->reverse_sort_name)
878 sort_type = ctsvc_get_name_sort_type(contact->reverse_sort_name);
880 sort_type = CTSVC_SORT_OTHERS;
882 WARN_IF(sort_type < 0, "ctsvc_get_name_sort_type Fail(%d)", sort_type);
887 if (STRING_EQUAL == strncmp(langset, "zh_CN", strlen("zh_CN"))) {
890 __ctsvc_get_sort_name_to_pinyin(phonetic, &pinyin);
892 __ctsvc_get_sort_name_to_pinyin(contact->reverse_sort_name, &pinyin);
895 free(contact->reverse_sort_name);
896 contact->reverse_sort_name = pinyin;
897 sort_type = CTSVC_SORT_WESTERN;
899 } else if (STRING_EQUAL == strncmp(langset, "ko_KR", strlen("ko_KR"))) {
900 sort_type = CTSVC_SORT_KOREAN;
904 case CTSVC_SORT_JAPANESE:
906 char *hiragana = NULL;
907 ctsvc_convert_japanese_to_hiragana(contact->reverse_sort_name, &hiragana);
910 free(contact->reverse_sort_name);
911 contact->reverse_sort_name = hiragana;
918 FREEandSTRDUP(contact->reverse_sort_name, phonetic);
926 if (ctsvc_get_primary_sort() == sort_type)
927 contact->reverse_display_name_language = CTSVC_SORT_PRIMARY;
928 else if (ctsvc_get_secondary_sort() == sort_type)
929 contact->reverse_display_name_language = CTSVC_SORT_SECONDARY;
930 else if (sort_type < 0)
931 contact->reverse_display_name_language = CTSVC_SORT_OTHERS;
933 contact->reverse_display_name_language = sort_type;
935 if (contact->sort_name) {
936 sort_type = ctsvc_collation_str(contact->sort_name, &sortkey);
937 if (CONTACTS_ERROR_NONE == sort_type)
938 contact->sortkey = sortkey;
945 if (contact->reverse_sort_name) {
946 sort_type = ctsvc_collation_str(contact->reverse_sort_name, &sortkey);
947 if (CONTACTS_ERROR_NONE == sort_type)
948 contact->reverse_sortkey = sortkey;
954 static bool __ctsvc_contact_check_name_has_korean(const ctsvc_name_s *name)
956 if (name->first && ctsvc_has_korean(name->first))
958 else if (name->last && ctsvc_has_korean(name->last))
960 else if (name->addition && ctsvc_has_korean(name->addition))
962 else if (name->prefix && ctsvc_has_korean(name->prefix))
964 else if (name->suffix && ctsvc_has_korean(name->suffix))
970 static bool __ctsvc_contact_check_name_has_japanese(const ctsvc_name_s *name)
972 if (name->first && ctsvc_check_language_type(name->first) == CTSVC_LANG_JAPANESE)
974 else if (name->addition && ctsvc_check_language_type(name->addition) == CTSVC_LANG_JAPANESE)
976 else if (name->last && ctsvc_check_language_type(name->last) == CTSVC_LANG_JAPANESE)
982 static bool __ctsvc_contact_check_name_has_chinese(const ctsvc_name_s *name)
984 if (name->first && ctsvc_check_language_type(name->first) == CTSVC_LANG_CHINESE)
986 else if (name->addition && ctsvc_check_language_type(name->addition) == CTSVC_LANG_CHINESE)
988 else if (name->last && ctsvc_check_language_type(name->last) == CTSVC_LANG_CHINESE)
994 int ctsvc_contact_get_name_language(const ctsvc_name_s *name)
997 if (__ctsvc_contact_check_name_has_korean(name))
998 lang = CTSVC_LANG_KOREAN;
999 else if (__ctsvc_contact_check_name_has_japanese(name))
1000 lang = CTSVC_LANG_JAPANESE;
1001 else if (__ctsvc_contact_check_name_has_chinese(name))
1002 lang = CTSVC_LANG_CHINESE;
1005 lang = ctsvc_check_language_type(name->last);
1006 else if (name->first)
1007 lang = ctsvc_check_language_type(name->first);
1008 else if (name->addition)
1009 lang = ctsvc_check_language_type(name->addition);
1015 char* __ctsvc_remove_first_space(char *src)
1017 if (src == NULL || SAFE_STRLEN(src) == 0)
1020 int name_len = (SAFE_STRLEN(src)+1)*sizeof(char);
1021 char *name_nospace = NULL;
1022 name_nospace = calloc(1, name_len);
1023 if (NULL == name_nospace) {
1024 /* LCOV_EXCL_START */
1025 ERR("calloc() Fail");
1027 /* LCOV_EXCL_STOP */
1030 int len = strlen(src);
1033 for (i = 0; i < len && i < name_len; i++) {
1034 if (src[i] && src[i] != ' ') {
1035 strncpy(name_nospace, src+i, name_len);
1039 return name_nospace;
1042 * Make display_name, sort_name, sortkey of the contact by name record
1043 * If the contact record does not have name record,
1044 * we use company, nickname, number, email record in order
1046 void ctsvc_contact_make_display_name(ctsvc_contact_s *contact)
1049 ctsvc_name_s *name = NULL;
1051 free(contact->display_name);
1052 contact->display_name = NULL;
1054 free(contact->reverse_display_name);
1055 contact->reverse_display_name = NULL;
1057 free(contact->sort_name);
1058 contact->sort_name = NULL;
1060 free(contact->reverse_sort_name);
1061 contact->reverse_sort_name = NULL;
1063 free(contact->sortkey);
1064 contact->sortkey = NULL;
1066 free(contact->reverse_sortkey);
1067 contact->reverse_sortkey = NULL;
1069 contact->display_name_language = CTSVC_SORT_OTHERS;
1070 contact->reverse_display_name_language = CTSVC_SORT_OTHERS;
1072 contact->display_source_type = CONTACTS_DISPLAY_NAME_SOURCE_TYPE_INVALID;
1074 if (0 < contact->name->count && contact->name->records
1075 && contact->name->records->data) {
1076 name = (ctsvc_name_s*)contact->name->records->data;
1079 if (name && (name->first || name->last || name->prefix || name->addition
1081 int reverse_lang_type = -1;
1083 int temp_display_len;
1084 char *display = NULL;
1085 char *temp_display = NULL;
1088 * Make reverse display name (Last name first)
1089 * Default : Prefix Last, First Middle(addition), Suffix
1090 * Korean, Chinese : Prefix LastMiddleFirstSuffix
1091 * Japanese : Prefix Last Middle First Suffix
1092 * reverse sort name does not include prefix
1093 * But, if there is only prefix, reverse sort_name is prefix
1095 temp_display_len = SAFE_STRLEN(name->first)
1096 + SAFE_STRLEN(name->addition)
1097 + SAFE_STRLEN(name->last)
1098 + SAFE_STRLEN(name->suffix);
1099 if (0 < temp_display_len) {
1100 temp_display_len += 7;
1101 temp_display = calloc(1, temp_display_len);
1102 if (NULL == temp_display) {
1103 /* LCOV_EXCL_START */
1104 ERR("calloc() Fail");
1106 /* LCOV_EXCL_STOP */
1110 /* get language type */
1111 reverse_lang_type = ctsvc_contact_get_name_language(name);
1113 char *temp = __ctsvc_remove_first_space(name->last);
1114 len += snprintf(temp_display + len, temp_display_len - len, "%s", temp);
1116 if (reverse_lang_type != CTSVC_LANG_KOREAN &&
1117 reverse_lang_type != CTSVC_LANG_CHINESE &&
1118 reverse_lang_type != CTSVC_LANG_JAPANESE) {
1119 if (name->first || name->addition)
1120 len += snprintf(temp_display + len, temp_display_len - len, ",");
1124 if (reverse_lang_type == CTSVC_LANG_JAPANESE) {
1125 /* make temp_display name Prefix - Last - Middle - First - Suffix */
1126 if (name->addition) {
1127 char *temp = __ctsvc_remove_first_space(name->addition);
1129 len += snprintf(temp_display + len, temp_display_len - len, " ");
1130 len += snprintf(temp_display + len, temp_display_len - len, "%s", temp);
1135 char *temp = __ctsvc_remove_first_space(name->first);
1137 len += snprintf(temp_display + len, temp_display_len - len, " ");
1138 len += snprintf(temp_display + len, temp_display_len - len, "%s", temp);
1141 } else if (reverse_lang_type == CTSVC_LANG_CHINESE || reverse_lang_type == CTSVC_LANG_KOREAN) {
1142 if (name->addition) {
1143 char *temp = __ctsvc_remove_first_space(name->addition);
1144 len += snprintf(temp_display + len, temp_display_len - len, "%s", temp);
1149 char *temp = __ctsvc_remove_first_space(name->first);
1150 len += snprintf(temp_display + len, temp_display_len - len, "%s", temp);
1154 /* make temp_display name Prefix - Last - First - Middle - Suffix */
1156 if (*temp_display) {
1157 if (reverse_lang_type < 0)
1158 reverse_lang_type = ctsvc_check_language_type(temp_display);
1160 if (reverse_lang_type != CTSVC_LANG_KOREAN &&
1161 reverse_lang_type != CTSVC_LANG_CHINESE)
1162 len += snprintf(temp_display + len, temp_display_len - len, " ");
1164 char *temp = __ctsvc_remove_first_space(name->first);
1165 len += snprintf(temp_display + len, temp_display_len - len, "%s", temp);
1169 if (name->addition) {
1170 if (*temp_display) {
1171 if (reverse_lang_type < 0)
1172 reverse_lang_type = ctsvc_check_language_type(temp_display);
1174 if (reverse_lang_type != CTSVC_LANG_KOREAN &&
1175 reverse_lang_type != CTSVC_LANG_CHINESE)
1176 len += snprintf(temp_display + len, temp_display_len - len, " ");
1178 char *temp = __ctsvc_remove_first_space(name->addition);
1179 len += snprintf(temp_display + len, temp_display_len - len, "%s", temp);
1185 if (*temp_display) {
1186 if (reverse_lang_type < 0)
1187 reverse_lang_type = ctsvc_check_language_type(temp_display);
1189 if (reverse_lang_type == CTSVC_LANG_JAPANESE)
1190 len += snprintf(temp_display + len, temp_display_len - len, " ");
1191 else if (reverse_lang_type != CTSVC_LANG_KOREAN &&
1192 reverse_lang_type != CTSVC_LANG_CHINESE)
1193 len += snprintf(temp_display + len, temp_display_len - len, ", ");
1195 char *temp = __ctsvc_remove_first_space(name->suffix);
1196 len += snprintf(temp_display + len, temp_display_len - len, "%s", temp);
1201 if (name->prefix && temp_display) {
1202 display_len = SAFE_STRLEN(name->prefix) + temp_display_len + 2;
1203 display = calloc(1, display_len);
1204 if (NULL == display) {
1205 /* LCOV_EXCL_START */
1206 ERR("calloc() Fail");
1209 /* LCOV_EXCL_STOP */
1211 char *temp = __ctsvc_remove_first_space(name->prefix);
1212 snprintf(display, display_len, "%s %s", temp, temp_display);
1214 contact->reverse_display_name = display;
1215 contact->reverse_sort_name = temp_display;
1216 } else if (temp_display) {
1217 contact->reverse_display_name = temp_display;
1218 contact->reverse_sort_name = strdup(temp_display);
1219 } else if (name->prefix) {
1220 contact->reverse_display_name = strdup(name->prefix);
1221 contact->reverse_sort_name = strdup(name->prefix);
1225 * Make display name (First name first)
1226 * Default : Prefix First Middle Last, Suffix
1227 * Korean, Chinese : Prefix LastFirstMiddleSuffix (Same as reverse display name)
1228 * Japanese : Prefix First Middle Last Suffix
1229 * sort name does not include prefix
1230 * But, if there is only prefix, sort_name is prefix
1232 if (reverse_lang_type == CTSVC_LANG_KOREAN ||
1233 reverse_lang_type == CTSVC_LANG_CHINESE ||
1234 reverse_lang_type == CTSVC_LANG_JAPANESE) {
1235 contact->display_name = strdup(contact->reverse_display_name);
1236 contact->sort_name = SAFE_STRDUP(contact->reverse_sort_name);
1239 temp_display = NULL;
1240 temp_display_len = SAFE_STRLEN(name->first)
1241 + SAFE_STRLEN(name->addition)
1242 + SAFE_STRLEN(name->last)
1243 + SAFE_STRLEN(name->suffix);
1244 if (0 < temp_display_len) {
1245 temp_display_len += 6;
1246 /* make reverse_temp_display_name */
1247 temp_display = calloc(1, temp_display_len);
1248 if (NULL == temp_display) {
1249 /* LCOV_EXCL_START */
1250 ERR("calloc() Fail");
1252 /* LCOV_EXCL_STOP */
1257 char *temp = __ctsvc_remove_first_space(name->first);
1258 len += snprintf(temp_display + len, temp_display_len - len, "%s", temp);
1262 if (name->addition) {
1263 char *temp = __ctsvc_remove_first_space(name->addition);
1265 len += snprintf(temp_display + len, temp_display_len - len, " ");
1266 len += snprintf(temp_display + len, temp_display_len - len, "%s", temp);
1271 char *temp = __ctsvc_remove_first_space(name->last);
1273 len += snprintf(temp_display + len, temp_display_len - len, " ");
1274 len += snprintf(temp_display + len, temp_display_len - len, "%s", temp);
1279 if (*temp_display) {
1280 lang_type = ctsvc_check_language_type(temp_display);
1281 if (lang_type == CTSVC_LANG_JAPANESE)
1282 len += snprintf(temp_display + len, temp_display_len - len, " ");
1284 len += snprintf(temp_display + len, temp_display_len - len, ", ");
1286 char *temp = __ctsvc_remove_first_space(name->suffix);
1287 len += snprintf(temp_display + len, temp_display_len - len, "%s", temp);
1292 if (name->prefix && temp_display) {
1293 display_len = SAFE_STRLEN(name->prefix) + temp_display_len + 2;
1294 display = calloc(1, display_len);
1295 if (NULL == display) {
1296 /* LCOV_EXCL_START */
1297 ERR("calloc() Fail");
1300 /* LCOV_EXCL_STOP */
1302 snprintf(display, display_len, "%s %s", name->prefix, temp_display);
1303 contact->display_name = display;
1304 contact->sort_name = temp_display;
1305 } else if (temp_display) {
1306 contact->display_name = temp_display;
1307 contact->sort_name = strdup(temp_display);
1308 } else if (name->prefix) {
1309 contact->display_name = strdup(name->prefix);
1310 contact->sort_name = strdup(name->prefix);
1314 ctsvc_record_set_property_flag((ctsvc_record_s*)contact, _contacts_contact.display_name, CTSVC_PROPERTY_FLAG_DIRTY);
1315 contact->display_source_type = CONTACTS_DISPLAY_NAME_SOURCE_TYPE_NAME;
1318 if (contact->company && contact->company->records) {
1319 for (cur = contact->company->records; cur; cur = cur->next) {
1320 ctsvc_company_s *company = cur->data;
1321 if (company && company->name) {
1322 ctsvc_record_set_property_flag((ctsvc_record_s*)contact, _contacts_contact.display_name, CTSVC_PROPERTY_FLAG_DIRTY);
1323 contact->display_name = SAFE_STRDUP(company->name);
1324 contact->display_source_type = CONTACTS_DISPLAY_NAME_SOURCE_TYPE_COMPANY;
1330 if (false == ctsvc_record_check_property_flag((ctsvc_record_s*)contact, _contacts_contact.display_name, CTSVC_PROPERTY_FLAG_DIRTY) &&
1331 contact->nicknames && contact->nicknames->records) {
1332 for (cur = contact->nicknames->records; cur; cur = cur->next) {
1333 ctsvc_nickname_s *nickname = cur->data;
1334 if (nickname && nickname->nickname) {
1335 ctsvc_record_set_property_flag((ctsvc_record_s*)contact, _contacts_contact.display_name, CTSVC_PROPERTY_FLAG_DIRTY);
1336 free(contact->display_name);
1337 contact->display_name = SAFE_STRDUP(nickname->nickname);
1338 contact->display_source_type = CONTACTS_DISPLAY_NAME_SOURCE_TYPE_NICKNAME;
1344 if (false == ctsvc_record_check_property_flag((ctsvc_record_s*)contact, _contacts_contact.display_name, CTSVC_PROPERTY_FLAG_DIRTY) &&
1345 contact->numbers && contact->numbers->records) {
1346 for (cur = contact->numbers->records; cur; cur = cur->next) {
1347 ctsvc_number_s *number = cur->data;
1348 if (number && number->number) {
1349 ctsvc_record_set_property_flag((ctsvc_record_s*)contact, _contacts_contact.display_name, CTSVC_PROPERTY_FLAG_DIRTY);
1350 free(contact->display_name);
1351 contact->display_name = SAFE_STRDUP(number->number);
1352 contact->display_source_type = CONTACTS_DISPLAY_NAME_SOURCE_TYPE_NUMBER;
1358 if (false == ctsvc_record_check_property_flag((ctsvc_record_s*)contact, _contacts_contact.display_name, CTSVC_PROPERTY_FLAG_DIRTY) &&
1359 contact->emails && contact->emails->records) {
1360 for (cur = contact->emails->records; cur; cur = cur->next) {
1361 ctsvc_email_s *email = cur->data;
1362 if (email && email->email_addr) {
1363 ctsvc_record_set_property_flag((ctsvc_record_s*)contact, _contacts_contact.display_name, CTSVC_PROPERTY_FLAG_DIRTY);
1364 free(contact->display_name);
1365 contact->display_name = SAFE_STRDUP(email->email_addr);
1366 contact->display_source_type = CONTACTS_DISPLAY_NAME_SOURCE_TYPE_EMAIL;
1372 if (ctsvc_record_check_property_flag((ctsvc_record_s*)contact, _contacts_contact.display_name, CTSVC_PROPERTY_FLAG_DIRTY)) {
1373 contact->reverse_display_name = SAFE_STRDUP(contact->display_name);
1374 contact->sort_name = SAFE_STRDUP(contact->display_name);
1375 contact->reverse_sort_name = SAFE_STRDUP(contact->display_name);
1377 /* Update as NULL */
1378 ctsvc_record_set_property_flag((ctsvc_record_s*)contact, _contacts_contact.display_name, CTSVC_PROPERTY_FLAG_DIRTY);
1383 if (ctsvc_record_check_property_flag((ctsvc_record_s*)contact, _contacts_contact.display_name, CTSVC_PROPERTY_FLAG_DIRTY))
1384 ctsvc_contact_make_sortkey(contact);
1389 int ctsvc_get_data_info_name(cts_stmt stmt, contacts_list_h name_list)
1393 contacts_record_h record;
1395 ret = contacts_list_get_count(name_list, &count);
1396 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "contacts_list_get_count Fail(%d)", ret);
1397 RETVM_IF(1 < count, CONTACTS_ERROR_INVALID_PARAMETER, "already had name");
1399 ctsvc_db_name_get_value_from_stmt(stmt, &record, 1);
1400 contacts_list_add(name_list, record);
1402 return CONTACTS_ERROR_NONE;
1405 int ctsvc_get_data_info_event(cts_stmt stmt, contacts_list_h list)
1407 contacts_record_h record;
1409 ctsvc_db_event_get_value_from_stmt(stmt, &record, 1);
1410 contacts_list_add(list, record);
1412 return CONTACTS_ERROR_NONE;
1415 int ctsvc_get_data_info_number(cts_stmt stmt, contacts_list_h number_list)
1417 contacts_record_h record;
1419 ctsvc_db_number_get_value_from_stmt(stmt, &record, 1);
1420 contacts_list_add(number_list, record);
1422 return CONTACTS_ERROR_NONE;
1425 int ctsvc_get_data_info_email(cts_stmt stmt, contacts_list_h list)
1427 contacts_record_h record;
1429 ctsvc_db_email_get_value_from_stmt(stmt, &record, 1);
1430 contacts_list_add(list, record);
1432 return CONTACTS_ERROR_NONE;
1435 int ctsvc_get_data_info_address(cts_stmt stmt, contacts_list_h list)
1437 contacts_record_h record;
1439 ctsvc_db_address_get_value_from_stmt(stmt, &record, 1);
1440 contacts_list_add(list, record);
1442 return CONTACTS_ERROR_NONE;
1445 int ctsvc_get_data_info_messenger(cts_stmt stmt, contacts_list_h list)
1447 contacts_record_h record;
1449 ctsvc_db_messenger_get_value_from_stmt(stmt, &record, 1);
1450 contacts_list_add(list, record);
1452 return CONTACTS_ERROR_NONE;
1455 int ctsvc_get_data_info_note(cts_stmt stmt, contacts_list_h list)
1457 contacts_record_h record;
1459 ctsvc_db_note_get_value_from_stmt(stmt, &record, 1);
1460 contacts_list_add(list, record);
1462 return CONTACTS_ERROR_NONE;
1465 int ctsvc_get_data_info_company(cts_stmt stmt, contacts_list_h list)
1467 contacts_record_h record;
1469 ctsvc_db_company_get_value_from_stmt(stmt, &record, 1);
1470 contacts_list_add(list, record);
1472 return CONTACTS_ERROR_NONE;
1475 int ctsvc_get_data_info_profile(cts_stmt stmt, contacts_list_h list)
1477 contacts_record_h record;
1479 ctsvc_db_profile_get_value_from_stmt(stmt, &record, 1);
1480 contacts_list_add(list, record);
1482 return CONTACTS_ERROR_NONE;
1485 int ctsvc_get_data_info_relationship(cts_stmt stmt, contacts_list_h list)
1487 contacts_record_h record;
1489 ctsvc_db_relationship_get_value_from_stmt(stmt, &record, 1);
1490 contacts_list_add(list, record);
1492 return CONTACTS_ERROR_NONE;
1495 int ctsvc_get_data_info_image(cts_stmt stmt, contacts_list_h list)
1497 contacts_record_h record;
1499 ctsvc_db_image_get_value_from_stmt(stmt, &record, 1);
1500 contacts_list_add(list, record);
1502 return CONTACTS_ERROR_NONE;
1505 int ctsvc_get_data_info_url(cts_stmt stmt, contacts_list_h list)
1507 contacts_record_h record;
1509 ctsvc_db_url_get_value_from_stmt(stmt, &record, 1);
1510 contacts_list_add(list, record);
1512 return CONTACTS_ERROR_NONE;
1515 int ctsvc_get_data_info_nickname(cts_stmt stmt, contacts_list_h list)
1517 contacts_record_h record;
1519 ctsvc_db_nickname_get_value_from_stmt(stmt, &record, 1);
1520 contacts_list_add(list, record);
1522 return CONTACTS_ERROR_NONE;
1525 int ctsvc_get_data_info_extension(cts_stmt stmt, contacts_list_h list)
1527 contacts_record_h record;
1529 ctsvc_db_extension_get_value_from_stmt(stmt, &record, 1);
1530 contacts_list_add(list, record);
1532 return CONTACTS_ERROR_NONE;
1535 int ctsvc_get_data_info_sip(cts_stmt stmt, contacts_list_h list)
1537 contacts_record_h record;
1539 ctsvc_db_sip_get_value_from_stmt(stmt, &record, 1);
1540 contacts_list_add(list, record);
1542 return CONTACTS_ERROR_NONE;
1545 bool ctsvc_contact_check_default_number(contacts_list_h number_list)
1547 bool has_default = false;
1548 ctsvc_number_s *number;
1552 RETV_IF(NULL == number_list, false);
1554 ret = contacts_list_get_count(number_list, &count);
1555 if (CONTACTS_ERROR_NONE != ret || 0 == count)
1558 contacts_list_first(number_list);
1560 contacts_list_get_current_record_p(number_list, (contacts_record_h*)&number);
1561 if (number && number->number && *number->number) {
1562 if (number->is_default && false == has_default)
1564 else if (has_default)
1565 number->is_default = false;
1567 } while (CONTACTS_ERROR_NONE == contacts_list_next(number_list));
1569 if (false == has_default) {
1570 contacts_list_first(number_list);
1572 contacts_list_get_current_record_p(number_list, (contacts_record_h*)&number);
1573 if (number && number->number && *number->number) {
1574 number->is_default = true;
1575 ctsvc_record_set_property_flag((ctsvc_record_s*)number, _contacts_number.is_default, CTSVC_PROPERTY_FLAG_DIRTY);
1579 } while (CONTACTS_ERROR_NONE == contacts_list_next(number_list));
1584 bool ctsvc_contact_check_default_email(contacts_list_h email_list)
1586 bool has_default = false;
1587 ctsvc_email_s *email;
1591 RETV_IF(NULL == email_list, false);
1593 ret = contacts_list_get_count(email_list, &count);
1594 if (CONTACTS_ERROR_NONE != ret || 0 == count)
1597 contacts_list_first(email_list);
1599 contacts_list_get_current_record_p(email_list, (contacts_record_h*)&email);
1600 if (email && email->email_addr && *email->email_addr) {
1601 if (email->is_default && false == has_default)
1603 else if (has_default)
1604 email->is_default = false;
1606 } while (CONTACTS_ERROR_NONE == contacts_list_next(email_list));
1608 if (false == has_default) {
1609 contacts_list_first(email_list);
1611 contacts_list_get_current_record_p(email_list, (contacts_record_h*)&email);
1612 if (email && email->email_addr && *email->email_addr) {
1613 email->is_default = true;
1614 ctsvc_record_set_property_flag((ctsvc_record_s*)email, _contacts_email.is_default, CTSVC_PROPERTY_FLAG_DIRTY);
1618 } while (CONTACTS_ERROR_NONE == contacts_list_next(email_list));
1623 bool ctsvc_contact_check_default_image(contacts_list_h image_list)
1625 bool has_default = false;
1626 ctsvc_image_s *image;
1630 RETV_IF(NULL == image_list, false);
1632 ret = contacts_list_get_count(image_list, &count);
1633 if (CONTACTS_ERROR_NONE != ret || 0 == count) {
1634 DBG("list get count Fail(%d)", count);
1638 contacts_list_first(image_list);
1640 contacts_list_get_current_record_p(image_list, (contacts_record_h*)&image);
1641 if (image && image->path && *image->path) {
1642 if (image->is_default && false == has_default)
1644 else if (has_default)
1645 image->is_default = false;
1647 } while (CONTACTS_ERROR_NONE == contacts_list_next(image_list));
1649 if (false == has_default) {
1650 contacts_list_first(image_list);
1652 contacts_list_get_current_record_p(image_list, (contacts_record_h*)&image);
1653 if (image && image->path && *image->path) {
1654 image->is_default = true;
1655 ctsvc_record_set_property_flag((ctsvc_record_s*)image, _contacts_image.is_default, CTSVC_PROPERTY_FLAG_DIRTY);
1659 } while (CONTACTS_ERROR_NONE == contacts_list_next(image_list));
1661 return CONTACTS_ERROR_NONE;
1664 bool ctsvc_contact_check_default_address(contacts_list_h address_list)
1666 bool has_default = false;
1667 ctsvc_address_s *address;
1671 RETV_IF(NULL == address_list, false);
1673 ret = contacts_list_get_count(address_list, &count);
1674 if (CONTACTS_ERROR_NONE != ret || 0 == count) {
1675 DBG("list get count Fail(%d)", count);
1679 contacts_list_first(address_list);
1681 contacts_list_get_current_record_p(address_list, (contacts_record_h*)&address);
1683 (address->pobox || address->postalcode || address->region || address->locality
1684 || address->street || address->extended || address->country)) {
1685 if (address->is_default && false == has_default)
1687 else if (has_default)
1688 address->is_default = false;
1690 } while (CONTACTS_ERROR_NONE == contacts_list_next(address_list));
1692 if (false == has_default) {
1693 contacts_list_first(address_list);
1695 contacts_list_get_current_record_p(address_list, (contacts_record_h*)&address);
1697 (address->pobox || address->postalcode || address->region || address->locality
1698 || address->street || address->extended || address->country)) {
1699 address->is_default = true;
1700 ctsvc_record_set_property_flag((ctsvc_record_s*)address, _contacts_address.is_default, CTSVC_PROPERTY_FLAG_DIRTY);
1704 } while (CONTACTS_ERROR_NONE == contacts_list_next(address_list));
1706 return CONTACTS_ERROR_NONE;
1709 int ctsvc_contact_update_data_name(contacts_list_h name_list, int contact_id, bool is_my_profile)
1712 int ret = CONTACTS_ERROR_NONE;
1713 contacts_record_h record;
1715 ctsvc_list_s *list = (ctsvc_list_s*)name_list;
1717 RETV_IF(NULL == name_list, CONTACTS_ERROR_INVALID_PARAMETER);
1719 for (cursor = list->deleted_records; cursor; cursor = cursor->next) {
1720 name = cursor->data;
1721 ctsvc_db_name_delete(name->id, is_my_profile);
1724 contacts_list_first(name_list);
1725 contacts_list_get_current_record_p(name_list, &record);
1727 name = (ctsvc_name_s*)record;
1729 if (name->first || name->last || name->addition || name->prefix || name->suffix
1730 || name->phonetic_first || name->phonetic_middle || name->phonetic_last) {
1731 ret = ctsvc_db_name_update(record, is_my_profile);
1733 ret = ctsvc_db_name_delete(name->id, is_my_profile);
1736 ret = ctsvc_db_name_insert(record, contact_id, is_my_profile, NULL);
1738 if (CONTACTS_ERROR_DB == ret)
1739 /* LCOV_EXCL_START */
1740 ERR("return(%d)", ret);
1741 /* LCOV_EXCL_STOP */
1747 int ctsvc_contact_update_data_company(contacts_list_h company_list, int contact_id, bool is_my_profile)
1750 int ret = CONTACTS_ERROR_NONE;
1751 contacts_record_h record = NULL;
1753 ctsvc_list_s *list = (ctsvc_list_s*)company_list;
1754 ctsvc_company_s *company;
1757 RETV_IF(NULL == company_list, CONTACTS_ERROR_INVALID_PARAMETER);
1759 for (cursor = list->deleted_records; cursor; cursor = cursor->next) {
1760 company = cursor->data;
1761 ctsvc_db_company_delete(company->id, is_my_profile);
1764 ret = contacts_list_get_count(company_list, &count);
1766 return CONTACTS_ERROR_NONE;
1768 contacts_list_first(company_list);
1770 contacts_list_get_current_record_p(company_list, &record);
1771 company = (ctsvc_company_s*)record;
1772 if (0 < company->id) {
1773 if (company->name || company->department || company->job_title || company->role
1774 || company->assistant_name || company->logo || company->location || company->description
1775 || company->phonetic_name) {
1776 ret = ctsvc_db_company_update(record, contact_id, is_my_profile);
1778 ret = ctsvc_db_company_delete(company->id, is_my_profile);
1781 ret = ctsvc_db_company_insert(record, contact_id, is_my_profile, NULL);
1783 if (CONTACTS_ERROR_DB == ret) {
1784 /* LCOV_EXCL_START */
1785 ERR("return (%d)", ret);
1787 /* LCOV_EXCL_STOP */
1789 } while (CONTACTS_ERROR_NONE == contacts_list_next(company_list));
1794 int ctsvc_contact_update_data_note(contacts_list_h note_list, int contact_id, bool is_my_profile)
1797 int ret = CONTACTS_ERROR_NONE;
1798 contacts_record_h record = NULL;
1800 ctsvc_list_s *list = (ctsvc_list_s*)note_list;
1804 RETV_IF(NULL == note_list, CONTACTS_ERROR_INVALID_PARAMETER);
1806 for (cursor = list->deleted_records; cursor; cursor = cursor->next) {
1807 note = cursor->data;
1808 ctsvc_db_note_delete(note->id, is_my_profile);
1811 ret = contacts_list_get_count(note_list, &count);
1813 return CONTACTS_ERROR_NONE;
1815 contacts_list_first(note_list);
1817 contacts_list_get_current_record_p(note_list, &record);
1818 note = (ctsvc_note_s*)record;
1821 ret = ctsvc_db_note_update(record, is_my_profile);
1823 ret = ctsvc_db_note_delete(note->id, is_my_profile);
1825 ret = ctsvc_db_note_insert(record, contact_id, is_my_profile, NULL);
1827 if (CONTACTS_ERROR_DB == ret) {
1828 /* LCOV_EXCL_START */
1829 ERR("return (%d)", ret);
1831 /* LCOV_EXCL_STOP */
1833 } while (CONTACTS_ERROR_NONE == contacts_list_next(note_list));
1838 int ctsvc_contact_update_data_event(contacts_list_h event_list, int contact_id, bool is_my_profile)
1841 int ret = CONTACTS_ERROR_NONE;
1842 contacts_record_h record = NULL;
1844 ctsvc_list_s *list = (ctsvc_list_s*)event_list;
1845 ctsvc_event_s *event;
1848 RETV_IF(NULL == event_list, CONTACTS_ERROR_INVALID_PARAMETER);
1850 for (cursor = list->deleted_records; cursor; cursor = cursor->next) {
1851 event = cursor->data;
1852 ctsvc_db_event_delete(event->id, is_my_profile);
1855 ret = contacts_list_get_count(event_list, &count);
1857 return CONTACTS_ERROR_NONE;
1859 contacts_list_first(event_list);
1861 contacts_list_get_current_record_p(event_list, &record);
1862 event = (ctsvc_event_s*)record;
1863 if (0 < event->id) {
1864 if (0 < event->date)
1865 ret = ctsvc_db_event_update(record, is_my_profile);
1867 ret = ctsvc_db_event_delete(event->id, is_my_profile);
1869 ret = ctsvc_db_event_insert(record, contact_id, is_my_profile, NULL);
1871 if (CONTACTS_ERROR_DB == ret) {
1872 /* LCOV_EXCL_START */
1873 ERR("return (%d)", ret);
1875 /* LCOV_EXCL_STOP */
1877 } while (CONTACTS_ERROR_NONE == contacts_list_next(event_list));
1882 int ctsvc_contact_update_data_messenger(contacts_list_h messenger_list, int contact_id, bool is_my_profile)
1885 int ret = CONTACTS_ERROR_NONE;
1886 contacts_record_h record = NULL;
1888 ctsvc_list_s *list = (ctsvc_list_s*)messenger_list;
1889 ctsvc_messenger_s *messenger;
1892 RETV_IF(NULL == messenger_list, CONTACTS_ERROR_INVALID_PARAMETER);
1894 for (cursor = list->deleted_records; cursor; cursor = cursor->next) {
1895 messenger = cursor->data;
1896 ctsvc_db_messenger_delete(messenger->id, is_my_profile);
1899 ret = contacts_list_get_count(messenger_list, &count);
1901 return CONTACTS_ERROR_NONE;
1903 contacts_list_first(messenger_list);
1905 contacts_list_get_current_record_p(messenger_list, &record);
1906 messenger = (ctsvc_messenger_s*)record;
1907 if (0 < messenger->id) {
1908 if (messenger->im_id)
1909 ret = ctsvc_db_messenger_update(record, is_my_profile);
1911 ret = ctsvc_db_messenger_delete(messenger->id, is_my_profile);
1913 ret = ctsvc_db_messenger_insert(record, contact_id, is_my_profile, NULL);
1915 if (CONTACTS_ERROR_DB == ret) {
1916 /* LCOV_EXCL_START */
1917 ERR("return (%d)", ret);
1919 /* LCOV_EXCL_STOP */
1921 } while (CONTACTS_ERROR_NONE == contacts_list_next(messenger_list));
1926 int ctsvc_contact_update_data_address(contacts_list_h address_list, int contact_id, bool is_my_profile)
1929 int ret = CONTACTS_ERROR_NONE;
1930 contacts_record_h record = NULL;
1932 ctsvc_list_s *list = (ctsvc_list_s*)address_list;
1933 ctsvc_address_s *address;
1936 RETV_IF(NULL == address_list, CONTACTS_ERROR_INVALID_PARAMETER);
1938 for (cursor = list->deleted_records; cursor; cursor = cursor->next) {
1939 address = cursor->data;
1940 ctsvc_db_address_delete(address->id, is_my_profile);
1943 ret = contacts_list_get_count(address_list, &count);
1945 return CONTACTS_ERROR_NONE;
1947 contacts_list_first(address_list);
1949 contacts_list_get_current_record_p(address_list, &record);
1950 address = (ctsvc_address_s*)record;
1951 if (0 < address->id) {
1952 if (address->pobox || address->postalcode || address->region || address->locality
1953 || address->street || address->extended || address->country) {
1954 ret = ctsvc_db_address_update(record, is_my_profile);
1956 ret = ctsvc_db_address_delete(address->id, is_my_profile);
1959 ret = ctsvc_db_address_insert(record, contact_id, is_my_profile, NULL);
1961 if (CONTACTS_ERROR_DB == ret) {
1962 /* LCOV_EXCL_START */
1963 ERR("return (%d)", ret);
1965 /* LCOV_EXCL_STOP */
1967 } while (CONTACTS_ERROR_NONE == contacts_list_next(address_list));
1972 int ctsvc_contact_update_data_url(contacts_list_h url_list, int contact_id, bool is_my_profile)
1975 int ret = CONTACTS_ERROR_NONE;
1976 contacts_record_h record = NULL;
1978 ctsvc_list_s *list = (ctsvc_list_s*)url_list;
1982 RETV_IF(NULL == url_list, CONTACTS_ERROR_INVALID_PARAMETER);
1984 for (cursor = list->deleted_records; cursor; cursor = cursor->next) {
1986 ctsvc_db_url_delete(url->id, is_my_profile);
1989 ret = contacts_list_get_count(url_list, &count);
1991 return CONTACTS_ERROR_NONE;
1993 contacts_list_first(url_list);
1995 contacts_list_get_current_record_p(url_list, &record);
1996 url = (ctsvc_url_s*)record;
1999 ret = ctsvc_db_url_update(record, is_my_profile);
2001 ret = ctsvc_db_url_delete(url->id, is_my_profile);
2003 ret = ctsvc_db_url_insert(record, contact_id, is_my_profile, NULL);
2005 if (CONTACTS_ERROR_DB == ret) {
2006 /* LCOV_EXCL_START */
2007 ERR("return (%d)", ret);
2009 /* LCOV_EXCL_STOP */
2011 } while (CONTACTS_ERROR_NONE == contacts_list_next(url_list));
2016 int ctsvc_contact_update_data_profile(contacts_list_h profile_list, int contact_id, bool is_my_profile)
2019 int ret = CONTACTS_ERROR_NONE;
2020 contacts_record_h record = NULL;
2022 ctsvc_list_s *list = (ctsvc_list_s*)profile_list;
2023 ctsvc_profile_s *profile;
2026 RETV_IF(NULL == profile_list, CONTACTS_ERROR_INVALID_PARAMETER);
2028 for (cursor = list->deleted_records; cursor; cursor = cursor->next) {
2029 profile = cursor->data;
2030 ctsvc_db_profile_delete(profile->id, is_my_profile);
2032 ret = contacts_list_get_count(profile_list, &count);
2034 return CONTACTS_ERROR_NONE;
2036 contacts_list_first(profile_list);
2038 contacts_list_get_current_record_p(profile_list, &record);
2039 profile = (ctsvc_profile_s*)record;
2040 if (0 < profile->id) {
2042 ret = ctsvc_db_profile_update(record, is_my_profile);
2044 ret = ctsvc_db_profile_delete(profile->id, is_my_profile);
2046 ret = ctsvc_db_profile_insert(record, contact_id, is_my_profile, NULL);
2048 if (CONTACTS_ERROR_DB == ret) {
2049 /* LCOV_EXCL_START */
2050 ERR("return (%d)", ret);
2052 /* LCOV_EXCL_STOP */
2054 } while (CONTACTS_ERROR_NONE == contacts_list_next(profile_list));
2059 int ctsvc_contact_update_data_relationship(contacts_list_h relationship_list, int contact_id, bool is_my_profile)
2062 int ret = CONTACTS_ERROR_NONE;
2063 contacts_record_h record = NULL;
2065 ctsvc_list_s *list = (ctsvc_list_s*)relationship_list;
2066 ctsvc_relationship_s *relationship;
2069 RETV_IF(NULL == relationship_list, CONTACTS_ERROR_INVALID_PARAMETER);
2071 for (cursor = list->deleted_records; cursor; cursor = cursor->next) {
2072 relationship = cursor->data;
2073 ctsvc_db_relationship_delete(relationship->id, is_my_profile);
2076 ret = contacts_list_get_count(relationship_list, &count);
2078 return CONTACTS_ERROR_NONE;
2080 contacts_list_first(relationship_list);
2082 contacts_list_get_current_record_p(relationship_list, &record);
2083 relationship = (ctsvc_relationship_s*)record;
2084 if (0 < relationship->id) {
2085 if (relationship->name)
2086 ret = ctsvc_db_relationship_update(record, is_my_profile);
2088 ret = ctsvc_db_relationship_delete(relationship->id, is_my_profile);
2090 ret = ctsvc_db_relationship_insert(record, contact_id, is_my_profile, NULL);
2092 if (CONTACTS_ERROR_DB == ret) {
2093 /* LCOV_EXCL_START */
2094 ERR("return (%d)", ret);
2096 /* LCOV_EXCL_STOP */
2098 } while (CONTACTS_ERROR_NONE == contacts_list_next(relationship_list));
2103 int ctsvc_contact_update_data_image(contacts_list_h image_list, int contact_id, bool is_my_profile)
2106 int ret = CONTACTS_ERROR_NONE;
2107 contacts_record_h record = NULL;
2109 ctsvc_list_s *list = (ctsvc_list_s*)image_list;
2110 ctsvc_image_s *image;
2113 RETV_IF(NULL == image_list, CONTACTS_ERROR_INVALID_PARAMETER);
2115 for (cursor = list->deleted_records; cursor; cursor = cursor->next) {
2116 image = cursor->data;
2117 ctsvc_db_image_delete(image->id, is_my_profile);
2120 ret = contacts_list_get_count(image_list, &count);
2122 return CONTACTS_ERROR_NONE;
2124 contacts_list_first(image_list);
2126 contacts_list_get_current_record_p(image_list, &record);
2127 image = (ctsvc_image_s*)record;
2128 if (CTSVC_PROPERTY_FLAG_DIRTY & image->base.property_flag) {
2129 if (0 < image->id) {
2131 ret = ctsvc_db_image_update(record, contact_id, is_my_profile);
2133 ret = ctsvc_db_image_delete(image->id, is_my_profile);
2135 ret = ctsvc_db_image_insert(record, contact_id, is_my_profile, NULL);
2138 if (CONTACTS_ERROR_DB == ret) {
2139 /* LCOV_EXCL_START */
2140 ERR("return (%d)", ret);
2142 /* LCOV_EXCL_STOP */
2144 } while (CONTACTS_ERROR_NONE == contacts_list_next(image_list));
2149 int ctsvc_contact_update_data_nickname(contacts_list_h nickname_list, int contact_id, bool is_my_profile)
2152 int ret = CONTACTS_ERROR_NONE;
2153 contacts_record_h record = NULL;
2155 ctsvc_list_s *list = (ctsvc_list_s*)nickname_list;
2156 ctsvc_nickname_s *nickname;
2159 RETV_IF(NULL == nickname_list, CONTACTS_ERROR_INVALID_PARAMETER);
2161 for (cursor = list->deleted_records; cursor; cursor = cursor->next) {
2162 nickname = cursor->data;
2163 ctsvc_db_nickname_delete(nickname->id, is_my_profile);
2166 ret = contacts_list_get_count(nickname_list, &count);
2168 return CONTACTS_ERROR_NONE;
2170 contacts_list_first(nickname_list);
2172 contacts_list_get_current_record_p(nickname_list, &record);
2173 nickname = (ctsvc_nickname_s*)record;
2174 if (0 < nickname->id) {
2175 if (nickname->nickname)
2176 ret = ctsvc_db_nickname_update(record, is_my_profile);
2178 ret = ctsvc_db_nickname_delete(nickname->id, is_my_profile);
2180 ret = ctsvc_db_nickname_insert(record, contact_id, is_my_profile, NULL);
2182 if (CONTACTS_ERROR_DB == ret) {
2183 /* LCOV_EXCL_START */
2184 ERR("return (%d)", ret);
2186 /* LCOV_EXCL_STOP */
2188 } while (CONTACTS_ERROR_NONE == contacts_list_next(nickname_list));
2193 int ctsvc_contact_update_data_extension(contacts_list_h extension_list, int contact_id, bool is_my_profile)
2196 int ret = CONTACTS_ERROR_NONE;
2197 contacts_record_h record = NULL;
2199 ctsvc_list_s *list = (ctsvc_list_s*)extension_list;
2200 ctsvc_extension_s *extension;
2203 RETV_IF(NULL == extension_list, CONTACTS_ERROR_INVALID_PARAMETER);
2205 for (cursor = list->deleted_records; cursor; cursor = cursor->next) {
2206 extension = cursor->data;
2207 ctsvc_db_extension_delete(extension->id, is_my_profile);
2210 ret = contacts_list_get_count(extension_list, &count);
2212 return CONTACTS_ERROR_NONE;
2214 contacts_list_first(extension_list);
2216 contacts_list_get_current_record_p(extension_list, &record);
2217 extension = (ctsvc_extension_s*)record;
2218 if (0 < extension->id) {
2219 if (extension->data2 || extension->data3 || extension->data4 || extension->data5
2220 || extension->data6 || extension->data7 || extension->data8 || extension->data9
2221 || extension->data10 || extension->data11 || extension->data12) {
2222 ret = ctsvc_db_extension_update(record);
2224 ret = ctsvc_db_extension_delete(extension->id, is_my_profile);
2227 ret = ctsvc_db_extension_insert(record, contact_id, is_my_profile, NULL);
2229 if (CONTACTS_ERROR_DB == ret) {
2230 /* LCOV_EXCL_START */
2231 ERR("return (%d)", ret);
2233 /* LCOV_EXCL_STOP */
2235 } while (CONTACTS_ERROR_NONE == contacts_list_next(extension_list));
2240 int ctsvc_contact_update_data_sip(contacts_list_h sip_list, int contact_id, bool is_my_profile)
2243 int ret = CONTACTS_ERROR_NONE;
2244 contacts_record_h record = NULL;
2246 ctsvc_list_s *list = (ctsvc_list_s*)sip_list;
2250 RETV_IF(NULL == sip_list, CONTACTS_ERROR_INVALID_PARAMETER);
2252 for (cursor = list->deleted_records; cursor; cursor = cursor->next) {
2253 sip = (ctsvc_sip_s *)cursor->data;
2254 ctsvc_db_sip_delete(sip->id, is_my_profile);
2257 ret = contacts_list_get_count(sip_list, &count);
2259 return CONTACTS_ERROR_NONE;
2261 contacts_list_first(sip_list);
2263 contacts_list_get_current_record_p(sip_list, &record);
2264 sip = (ctsvc_sip_s*)record;
2267 ret = ctsvc_db_sip_update(record, is_my_profile);
2269 ret = ctsvc_db_sip_delete(sip->id, is_my_profile);
2271 ret = ctsvc_db_sip_insert(record, contact_id, is_my_profile, NULL);
2273 if (CONTACTS_ERROR_DB == ret) {
2274 /* LCOV_EXCL_START */
2275 ERR("DB error : return (%d)", ret);
2277 /* LCOV_EXCL_STOP */
2279 } while (CONTACTS_ERROR_NONE == contacts_list_next(sip_list));
2284 int ctsvc_contact_update_data_number(contacts_list_h number_list,
2285 int contact_id, bool is_my_profile, bool *had_phonenumber)
2288 int ret = CONTACTS_ERROR_NONE;
2289 contacts_record_h record = NULL;
2291 ctsvc_list_s *list = (ctsvc_list_s*)number_list;
2292 ctsvc_number_s *number;
2295 *had_phonenumber = false;
2297 RETV_IF(NULL == number_list, CONTACTS_ERROR_INVALID_PARAMETER);
2299 for (cursor = list->deleted_records; cursor; cursor = cursor->next) {
2300 number = cursor->data;
2301 ctsvc_db_number_delete(number->id, is_my_profile);
2304 ret = contacts_list_get_count(number_list, &count);
2306 return CONTACTS_ERROR_NONE;
2308 contacts_list_first(number_list);
2310 contacts_list_get_current_record_p(number_list, &record);
2311 number = (ctsvc_number_s*)record;
2312 if (0 < number->id) {
2313 if (number->number) {
2314 ret = ctsvc_db_number_update(record, is_my_profile);
2317 ret = ctsvc_db_number_delete(number->id, is_my_profile);
2319 } else if (number->number) {
2320 ret = ctsvc_db_number_insert(record, contact_id, is_my_profile, NULL);
2323 if (CONTACTS_ERROR_DB == ret) {
2324 /* LCOV_EXCL_START */
2325 ERR("return (%d)", ret);
2327 /* LCOV_EXCL_STOP */
2329 } while (CONTACTS_ERROR_NONE == contacts_list_next(number_list));
2331 *had_phonenumber = had;
2335 int ctsvc_contact_update_data_email(contacts_list_h email_list,
2336 int contact_id, bool is_my_profile, bool *had_email)
2339 int ret = CONTACTS_ERROR_NONE;
2340 contacts_record_h record = NULL;
2342 ctsvc_list_s *list = (ctsvc_list_s*)email_list;
2343 ctsvc_email_s *email;
2348 RETV_IF(NULL == email_list, CONTACTS_ERROR_INVALID_PARAMETER);
2350 for (cursor = list->deleted_records; cursor; cursor = cursor->next) {
2351 email = cursor->data;
2352 ctsvc_db_email_delete(email->id, is_my_profile);
2355 ret = contacts_list_get_count(email_list, &count);
2357 return CONTACTS_ERROR_NONE;
2359 contacts_list_first(email_list);
2361 contacts_list_get_current_record_p(email_list, &record);
2362 email = (ctsvc_email_s*)record;
2364 if (0 < email->id) {
2365 if (email->email_addr) {
2366 ret = ctsvc_db_email_update(record, is_my_profile);
2369 ret = ctsvc_db_email_delete(email->id, is_my_profile);
2371 } else if (email->email_addr) {
2372 ret = ctsvc_db_email_insert(record, contact_id, is_my_profile, NULL);
2375 if (CONTACTS_ERROR_DB == ret) {
2376 /* LCOV_EXCL_START */
2377 ERR("return (%d)", ret);
2379 /* LCOV_EXCL_STOP */
2381 } while (CONTACTS_ERROR_NONE == contacts_list_next(email_list));
2387 int ctsvc_contact_insert_data_name(contacts_list_h name_list, int contact_id, bool is_my_profile)
2390 int ret = CONTACTS_ERROR_NONE;
2391 contacts_record_h record;
2392 RETV_IF(NULL == name_list, CONTACTS_ERROR_INVALID_PARAMETER);
2394 contacts_list_first(name_list);
2395 contacts_list_get_current_record_p(name_list, &record);
2397 ret = ctsvc_db_name_insert(record, contact_id, is_my_profile, NULL);
2398 if (CONTACTS_ERROR_DB == ret)
2399 /* LCOV_EXCL_START */
2400 ERR("ctsvc_db_name_insert() Fail");
2401 /* LCOV_EXCL_STOP */
2406 int ctsvc_contact_insert_data_number(contacts_list_h number_list, int contact_id, bool is_my_profile)
2409 int ret = CONTACTS_ERROR_NONE;
2410 contacts_record_h record;
2413 RETV_IF(NULL == number_list, CONTACTS_ERROR_INVALID_PARAMETER);
2414 ret = contacts_list_get_count(number_list, &count);
2416 return CONTACTS_ERROR_NONE;
2418 contacts_list_first(number_list);
2420 contacts_list_get_current_record_p(number_list, &record);
2421 ret = ctsvc_db_number_insert(record, contact_id, is_my_profile, NULL);
2422 if (CONTACTS_ERROR_DB == ret) {
2423 /* LCOV_EXCL_START */
2424 ERR("ctsvc_db_number_insert");
2426 /* LCOV_EXCL_STOP */
2428 } while (CONTACTS_ERROR_NONE == contacts_list_next(number_list));
2433 int ctsvc_contact_insert_data_email(contacts_list_h email_list, int contact_id, bool is_my_profile)
2436 int ret = CONTACTS_ERROR_NONE;
2437 contacts_record_h record;
2440 RETV_IF(NULL == email_list, CONTACTS_ERROR_INVALID_PARAMETER);
2441 ret = contacts_list_get_count(email_list, &count);
2443 return CONTACTS_ERROR_NONE;
2445 contacts_list_first(email_list);
2447 contacts_list_get_current_record_p(email_list, &record);
2448 ret = ctsvc_db_email_insert(record, contact_id, is_my_profile, NULL);
2449 if (CONTACTS_ERROR_DB == ret) {
2450 /* LCOV_EXCL_START */
2451 ERR("ctsvc_db_email_insert");
2453 /* LCOV_EXCL_STOP */
2455 } while (CONTACTS_ERROR_NONE == contacts_list_next(email_list));
2460 int ctsvc_contact_insert_data_profile(contacts_list_h profile_list, int contact_id, bool is_my_profile)
2463 int ret = CONTACTS_ERROR_NONE;
2464 contacts_record_h record;
2467 RETV_IF(NULL == profile_list, CONTACTS_ERROR_INVALID_PARAMETER);
2468 ret = contacts_list_get_count(profile_list, &count);
2470 return CONTACTS_ERROR_NONE;
2472 contacts_list_first(profile_list);
2474 contacts_list_get_current_record_p(profile_list, &record);
2475 ret = ctsvc_db_profile_insert(record, contact_id, is_my_profile, NULL);
2476 if (CONTACTS_ERROR_DB == ret) {
2477 /* LCOV_EXCL_START */
2478 ERR("ctsvc_db_profile_insert");
2480 /* LCOV_EXCL_STOP */
2482 } while (CONTACTS_ERROR_NONE == contacts_list_next(profile_list));
2487 int ctsvc_contact_insert_data_company(contacts_list_h company_list, int contact_id, bool is_my_profile)
2490 int ret = CONTACTS_ERROR_NONE;
2491 contacts_record_h record = NULL;
2494 RETV_IF(NULL == company_list, CONTACTS_ERROR_INVALID_PARAMETER);
2495 ret = contacts_list_get_count(company_list, &count);
2497 return CONTACTS_ERROR_NONE;
2499 contacts_list_first(company_list);
2501 contacts_list_get_current_record_p(company_list, &record);
2502 ret = ctsvc_db_company_insert(record, contact_id, is_my_profile, NULL);
2503 if (CONTACTS_ERROR_DB == ret) {
2504 /* LCOV_EXCL_START */
2505 ERR("ctsvc_db_company_insert");
2507 /* LCOV_EXCL_STOP */
2509 } while (CONTACTS_ERROR_NONE == contacts_list_next(company_list));
2514 int ctsvc_contact_insert_data_note(contacts_list_h note_list, int contact_id, bool is_my_profile)
2517 int ret = CONTACTS_ERROR_NONE;
2518 contacts_record_h record = NULL;
2521 RETV_IF(NULL == note_list, CONTACTS_ERROR_INVALID_PARAMETER);
2522 ret = contacts_list_get_count(note_list, &count);
2524 return CONTACTS_ERROR_NONE;
2526 contacts_list_first(note_list);
2528 contacts_list_get_current_record_p(note_list, &record);
2530 ret = ctsvc_db_note_insert(record, contact_id, is_my_profile, NULL);
2531 if (CONTACTS_ERROR_DB == ret) {
2532 /* LCOV_EXCL_START */
2533 ERR("ctsvc_db_note_insert");
2535 /* LCOV_EXCL_STOP */
2538 } while (CONTACTS_ERROR_NONE == contacts_list_next(note_list));
2542 int ctsvc_contact_insert_data_event(contacts_list_h event_list, int contact_id, bool is_my_profile)
2545 int ret = CONTACTS_ERROR_NONE;
2546 contacts_record_h record;
2549 RETV_IF(NULL == event_list, CONTACTS_ERROR_INVALID_PARAMETER);
2550 ret = contacts_list_get_count(event_list, &count);
2552 return CONTACTS_ERROR_NONE;
2554 contacts_list_first(event_list);
2556 contacts_list_get_current_record_p(event_list, &record);
2557 ret = ctsvc_db_event_insert(record, contact_id, is_my_profile, NULL);
2558 if (CONTACTS_ERROR_DB == ret) {
2559 /* LCOV_EXCL_START */
2560 ERR("ctsvc_db_event_insert");
2562 /* LCOV_EXCL_STOP */
2564 } while (CONTACTS_ERROR_NONE == contacts_list_next(event_list));
2569 int ctsvc_contact_insert_data_messenger(contacts_list_h messenger_list, int contact_id, bool is_my_profile)
2572 int ret = CONTACTS_ERROR_NONE;
2573 contacts_record_h record;
2576 RETV_IF(NULL == messenger_list, CONTACTS_ERROR_INVALID_PARAMETER);
2577 ret = contacts_list_get_count(messenger_list, &count);
2579 return CONTACTS_ERROR_NONE;
2581 contacts_list_first(messenger_list);
2583 contacts_list_get_current_record_p(messenger_list, &record);
2584 ret = ctsvc_db_messenger_insert(record, contact_id, is_my_profile, NULL);
2585 if (CONTACTS_ERROR_DB == ret) {
2586 /* LCOV_EXCL_START */
2587 ERR("ctsvc_db_messenger_insert");
2589 /* LCOV_EXCL_STOP */
2591 } while (CONTACTS_ERROR_NONE == contacts_list_next(messenger_list));
2596 int ctsvc_contact_insert_data_address(contacts_list_h address_list, int contact_id, bool is_my_profile)
2599 int ret = CONTACTS_ERROR_NONE;
2600 contacts_record_h record;
2603 RETV_IF(NULL == address_list, CONTACTS_ERROR_INVALID_PARAMETER);
2604 ret = contacts_list_get_count(address_list, &count);
2606 return CONTACTS_ERROR_NONE;
2608 contacts_list_first(address_list);
2610 contacts_list_get_current_record_p(address_list, &record);
2611 ret = ctsvc_db_address_insert(record, contact_id, is_my_profile, NULL);
2612 if (CONTACTS_ERROR_DB == ret) {
2613 /* LCOV_EXCL_START */
2614 ERR("ctsvc_db_address_insert");
2616 /* LCOV_EXCL_STOP */
2618 } while (CONTACTS_ERROR_NONE == contacts_list_next(address_list));
2623 int ctsvc_contact_insert_data_url(contacts_list_h url_list, int contact_id, bool is_my_profile)
2626 int ret = CONTACTS_ERROR_NONE;
2627 contacts_record_h record;
2630 RETV_IF(NULL == url_list, CONTACTS_ERROR_INVALID_PARAMETER);
2631 ret = contacts_list_get_count(url_list, &count);
2633 return CONTACTS_ERROR_NONE;
2635 contacts_list_first(url_list);
2637 contacts_list_get_current_record_p(url_list, &record);
2638 ret = ctsvc_db_url_insert(record, contact_id, is_my_profile, NULL);
2639 if (CONTACTS_ERROR_DB == ret) {
2640 /* LCOV_EXCL_START */
2641 ERR("ctsvc_db_url_insert");
2643 /* LCOV_EXCL_STOP */
2645 } while (CONTACTS_ERROR_NONE == contacts_list_next(url_list));
2650 int ctsvc_contact_insert_data_nickname(contacts_list_h nickname_list, int contact_id, bool is_my_profile)
2653 int ret = CONTACTS_ERROR_NONE;
2654 contacts_record_h record;
2657 RETV_IF(NULL == nickname_list, CONTACTS_ERROR_INVALID_PARAMETER);
2658 ret = contacts_list_get_count(nickname_list, &count);
2660 return CONTACTS_ERROR_NONE;
2662 contacts_list_first(nickname_list);
2664 contacts_list_get_current_record_p(nickname_list, &record);
2665 ret = ctsvc_db_nickname_insert(record, contact_id, is_my_profile, NULL);
2666 if (CONTACTS_ERROR_DB == ret) {
2667 /* LCOV_EXCL_START */
2668 ERR("ctsvc_db_nickname_insert");
2670 /* LCOV_EXCL_STOP */
2672 } while (CONTACTS_ERROR_NONE == contacts_list_next(nickname_list));
2677 int ctsvc_contact_insert_data_relationship(contacts_list_h relationship_list, int contact_id, bool is_my_profile)
2680 int ret = CONTACTS_ERROR_NONE;
2681 contacts_record_h record;
2684 RETV_IF(NULL == relationship_list, CONTACTS_ERROR_INVALID_PARAMETER);
2685 ret = contacts_list_get_count(relationship_list, &count);
2687 return CONTACTS_ERROR_NONE;
2689 contacts_list_first(relationship_list);
2691 contacts_list_get_current_record_p(relationship_list, &record);
2692 ret = ctsvc_db_relationship_insert(record, contact_id, is_my_profile, NULL);
2693 if (CONTACTS_ERROR_DB == ret) {
2694 /* LCOV_EXCL_START */
2695 ERR("ctsvc_db_relationship_insert");
2697 /* LCOV_EXCL_STOP */
2699 } while (CONTACTS_ERROR_NONE == contacts_list_next(relationship_list));
2704 int ctsvc_contact_insert_data_image(contacts_list_h image_list, int contact_id, bool is_my_profile)
2707 int ret = CONTACTS_ERROR_NONE;
2708 contacts_record_h record;
2711 RETV_IF(NULL == image_list, CONTACTS_ERROR_INVALID_PARAMETER);
2712 ret = contacts_list_get_count(image_list, &count);
2714 return CONTACTS_ERROR_NONE;
2716 contacts_list_first(image_list);
2718 contacts_list_get_current_record_p(image_list, &record);
2719 ret = ctsvc_db_image_insert(record, contact_id, is_my_profile, NULL);
2720 if (CONTACTS_ERROR_DB == ret) {
2721 /* LCOV_EXCL_START */
2722 ERR("ctsvc_db_image_insert");
2724 /* LCOV_EXCL_STOP */
2726 } while (CONTACTS_ERROR_NONE == contacts_list_next(image_list));
2731 int ctsvc_contact_insert_data_extension(contacts_list_h extension_list, int contact_id, bool is_my_profile)
2734 int ret = CONTACTS_ERROR_NONE;
2735 contacts_record_h record;
2738 RETV_IF(NULL == extension_list, CONTACTS_ERROR_INVALID_PARAMETER);
2739 ret = contacts_list_get_count(extension_list, &count);
2741 return CONTACTS_ERROR_NONE;
2743 contacts_list_first(extension_list);
2745 contacts_list_get_current_record_p(extension_list, &record);
2746 ret = ctsvc_db_extension_insert(record, contact_id, is_my_profile, NULL);
2747 if (CONTACTS_ERROR_DB == ret) {
2748 /* LCOV_EXCL_START */
2749 ERR("ctsvc_db_extension_insert");
2751 /* LCOV_EXCL_STOP */
2753 } while (CONTACTS_ERROR_NONE == contacts_list_next(extension_list));
2758 int ctsvc_contact_insert_data_sip(contacts_list_h sip_list, int contact_id, bool is_my_profile)
2761 int ret = CONTACTS_ERROR_NONE;
2762 contacts_record_h record;
2765 RETV_IF(NULL == sip_list, CONTACTS_ERROR_INVALID_PARAMETER);
2766 ret = contacts_list_get_count(sip_list, &count);
2768 return CONTACTS_ERROR_NONE;
2770 contacts_list_first(sip_list);
2772 contacts_list_get_current_record_p(sip_list, &record);
2773 ret = ctsvc_db_sip_insert(record, contact_id, is_my_profile, NULL);
2774 if (CONTACTS_ERROR_DB == ret) {
2775 /* LCOV_EXCL_START */
2776 ERR("DB error : ctsvc_db_sip_insert");
2778 /* LCOV_EXCL_STOP */
2780 } while (CONTACTS_ERROR_NONE == contacts_list_next(sip_list));
2785 int ctsvc_contact_update_display_name(int contact_id, contacts_display_name_source_type_e changed_record_type)
2787 int ret = CONTACTS_ERROR_NONE;
2788 int display_name_type;
2789 contacts_record_h record;
2790 ret = ctsvc_db_contact_get(contact_id, (contacts_record_h*)&record);
2791 RETVM_IF(ret != CONTACTS_ERROR_NONE, ret, "ctsvc_db_contact_get Fail(%d)", ret);
2792 contacts_record_get_int(record, _contacts_contact.display_source_type, &display_name_type);
2794 if (display_name_type <= changed_record_type) {
2796 cts_stmt stmt = NULL;
2797 char query[CTS_SQL_MAX_LEN] = {0};
2798 ctsvc_contact_s *contact = (ctsvc_contact_s*)record;
2799 ctsvc_contact_make_display_name(contact);
2801 snprintf(query, sizeof(query), "UPDATE "CTS_TABLE_CONTACTS" SET "
2802 "display_name=?, reverse_display_name=?, display_name_source=%d, "
2803 "display_name_language=%d, reverse_display_name_language=%d, "
2804 "sort_name=?, reverse_sort_name=?, sortkey=?, reverse_sortkey=?, "
2805 "changed_ver=%d, changed_time=%d WHERE contact_id=%d",
2806 contact->display_source_type,
2807 contact->display_name_language, contact->reverse_display_name_language,
2808 ctsvc_get_next_ver(), (int)time(NULL), contact_id);
2810 ret = ctsvc_query_prepare(query, &stmt);
2812 /* LCOV_EXCL_START */
2813 ERR("ctsvc_query_prepare() Fail(%d)", ret);
2814 contacts_record_destroy(record, true);
2816 /* LCOV_EXCL_STOP */
2819 if (contact->display_name)
2820 ctsvc_stmt_bind_text(stmt, 1, contact->display_name);
2821 if (contact->reverse_display_name)
2822 ctsvc_stmt_bind_text(stmt, 2, contact->reverse_display_name);
2823 if (contact->sort_name)
2824 ctsvc_stmt_bind_text(stmt, 3, contact->sort_name);
2825 if (contact->reverse_sort_name)
2826 ctsvc_stmt_bind_text(stmt, 4, contact->reverse_sort_name);
2827 if (contact->sortkey)
2828 ctsvc_stmt_bind_text(stmt, 5, contact->sortkey);
2829 if (contact->reverse_sortkey)
2830 ctsvc_stmt_bind_text(stmt, 6, contact->reverse_sortkey);
2832 ret = ctsvc_stmt_step(stmt);
2833 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_stmt_step() Fail(%d)", ret);
2835 ctsvc_stmt_finalize(stmt);
2838 contacts_record_destroy(record, true);
2842 extern ctsvc_db_plugin_info_s ctsvc_db_plugin_contact;
2843 int ctsvc_db_contact_get(int id, contacts_record_h *out_record)
2845 return ctsvc_db_plugin_contact.get_record(id, out_record);