2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include "MsgUtilStorage.h"
24 #include "MsgGconfWrapper.h"
25 #include "MsgContact.h"
28 /*==================================================================================================
30 ==================================================================================================*/
31 __thread bool isContactSvcConnected = false;
33 MsgDbHandler ContactDbHandle;
35 MsgContactChangeCB cbFunction = NULL;
36 /*==================================================================================================
37 FUNCTION IMPLEMENTATION
38 ==================================================================================================*/
39 static void MsgContactSvcCallback(const char *view_uri, void *user_data)
41 MSG_DEBUG("Contact Data is Changed!!!");
45 if (ContactDbHandle.disconnect() != MSG_SUCCESS)
46 MSG_DEBUG("DB Disconnect Fail");
50 msg_error_t MsgOpenContactSvc()
52 int errCode = CONTACTS_ERROR_NONE;
54 if (!isContactSvcConnected) {
55 errCode = contacts_connect2();
57 if (errCode == CONTACTS_ERROR_NONE) {
58 MSG_DEBUG("Connect to Contact Service Success");
59 isContactSvcConnected = true;
61 MSG_DEBUG("Connect to Contact Service Fail [%d]", errCode);
62 isContactSvcConnected = false;
63 return MSG_ERR_DB_CONNECT;
66 MSG_DEBUG("Already connected to Contact Service.");
73 msg_error_t MsgCloseContactSvc()
75 int errCode = CONTACTS_ERROR_NONE;
77 if (isContactSvcConnected) {
78 errCode = contacts_disconnect2();
80 if (errCode == CONTACTS_ERROR_NONE) {
81 MSG_DEBUG("Disconnect to Contact Service Success");
83 MSG_DEBUG("Disconnect to Contact Service Fail [%d]", errCode);
84 return MSG_ERR_DB_DISCONNECT;
92 msg_error_t MsgInitContactSvc(MsgContactChangeCB cb)
94 msg_error_t err = MSG_SUCCESS;
96 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
97 MSG_DEBUG("MsgOpenContactSvc fail.");
101 int errCode = CONTACTS_ERROR_NONE;
103 if (!isContactSvcConnected) {
104 MSG_DEBUG("Contact Service Not Opened.");
105 return MSG_ERR_UNKNOWN;
111 // Register callback function
112 errCode = contacts_db_add_changed_cb(_contacts_contact._uri, MsgContactSvcCallback, NULL);
114 if (errCode == CONTACTS_ERROR_NONE)
115 MSG_DEBUG("Register Contact Service Callback");
117 MSG_DEBUG("Fail to Register Contact Service Callback [%d]", errCode);
123 msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_INFO_S *pContactInfo)
127 msg_error_t err = MSG_SUCCESS;
129 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
130 MSG_DEBUG("MsgOpenContactSvc fail.");
134 if (!isContactSvcConnected) {
135 MSG_DEBUG("Contact Service Not Opened.");
136 return MSG_ERR_UNKNOWN;
139 MSG_DEBUG("Address Type [%d], Address Value [%s]", pAddrInfo->addressType, pAddrInfo->addressVal);
141 memset(pContactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
143 if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN && strlen(pAddrInfo->addressVal) > (MAX_PHONE_NUMBER_LEN+1)) {
144 MSG_DEBUG("Phone Number is too long [%s]", pAddrInfo->addressVal);
150 unsigned int count = 0;
151 contacts_query_h query = NULL;
152 contacts_filter_h filter = NULL;
153 contacts_list_h contacts = NULL;
155 if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN || pAddrInfo->addressType == MSG_ADDRESS_TYPE_UNKNOWN) {
156 ret = contacts_query_create(_contacts_contact_number._uri, &query);
157 ret = contacts_filter_create(_contacts_contact_number._uri, &filter);
159 ret = contacts_filter_add_str(filter, _contacts_contact_number.number, CONTACTS_MATCH_EXACTLY, pAddrInfo->addressVal);
161 } else if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_EMAIL) {
162 ret = contacts_query_create(_contacts_contact_email._uri, &query);
163 ret = contacts_filter_create(_contacts_contact_email._uri, &filter);
165 ret = contacts_filter_add_str(filter, _contacts_contact_email.email, CONTACTS_MATCH_EXACTLY, pAddrInfo->addressVal);
168 MSG_DEBUG("Invalid pAddrInfo->addressType.");
172 ret = contacts_query_set_filter(query, filter);
173 ret = contacts_db_get_records_with_query(query, 0, 1, &contacts);
174 if (ret != CONTACTS_ERROR_NONE) {
175 MSG_DEBUG("contacts_db_get_records_with_query() Error [%d]", ret);
176 contacts_query_destroy(query);
177 contacts_filter_destroy(filter);
178 contacts_list_destroy(contacts, true);
182 ret = contacts_list_get_count(contacts, &count);
184 if (count == 0 || ret != CONTACTS_ERROR_NONE) {
185 MSG_DEBUG("No Serach Data from Contact Service.");
186 contacts_query_destroy(query);
187 contacts_filter_destroy(filter);
188 contacts_list_destroy(contacts, true);
192 contacts_record_h contact = NULL;
194 if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN || pAddrInfo->addressType == MSG_ADDRESS_TYPE_UNKNOWN) {
195 contacts_record_h number = NULL;
197 ret = contacts_list_get_current_record_p(contacts, &number);
198 if (ret != CONTACTS_ERROR_NONE) {
199 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
200 contacts_list_destroy(contacts, true);
204 ret = contacts_record_get_int(number, _contacts_contact_number.contact_id, &index);
205 if (ret != CONTACTS_ERROR_NONE) {
206 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
207 contacts_list_destroy(contacts, true);
208 contacts_record_destroy(number, true);
212 ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
213 if (ret != CONTACTS_ERROR_NONE) {
214 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
215 contacts_list_destroy(contacts, true);
216 contacts_record_destroy(contact, true);
217 contacts_record_destroy(number, true);
220 } else if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_EMAIL) {
221 contacts_record_h email = NULL;
223 ret = contacts_list_get_current_record_p(contacts, &email);
224 if (ret != CONTACTS_ERROR_NONE) {
225 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
226 contacts_list_destroy(contacts, true);
230 ret = contacts_record_get_int(email, _contacts_contact_email.contact_id, &index);
231 if (ret != CONTACTS_ERROR_NONE) {
232 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
233 contacts_list_destroy(contacts, true);
234 contacts_record_destroy(email, true);
238 ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
239 if (ret != CONTACTS_ERROR_NONE) {
240 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
241 contacts_list_destroy(contacts, true);
242 contacts_record_destroy(contact, true);
243 contacts_record_destroy(email, true);
248 contacts_list_destroy(contacts, true);
251 contacts_record_h name = NULL;
253 ret = contacts_record_get_child_record_at_p(contact, _contacts_contact.name, 0, &name);
254 if (ret != CONTACTS_ERROR_NONE) {
255 MSG_DEBUG("contacts_record_get_child_record_at_p() Error [%d]", ret);
256 contacts_record_destroy(contact, true);
260 char* strFirstName = NULL;
261 ret = contacts_record_get_str_p(name, _contacts_name.first, &strFirstName);
262 if (ret != CONTACTS_ERROR_NONE) {
263 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
264 contacts_record_destroy(contact, true);
268 char* strLastName = NULL;
269 ret = contacts_record_get_str_p(name, _contacts_name.last, &strLastName);
270 if (ret != CONTACTS_ERROR_NONE) {
271 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
272 contacts_record_destroy(contact, true);
276 MSG_DEBUG("First Name : [%s], Last Name : [%s]", strFirstName, strLastName);
278 if (strFirstName != NULL)
279 strncpy(pContactInfo->firstName, strFirstName, MAX_DISPLAY_NAME_LEN);
281 if (strLastName != NULL)
282 strncpy(pContactInfo->lastName, strLastName, MAX_DISPLAY_NAME_LEN);
284 ret = contacts_record_get_int(contact, _contacts_contact.id, (int*)&pContactInfo->contactId);
285 if (ret != CONTACTS_ERROR_NONE) {
286 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
287 contacts_record_destroy(contact, true);
291 MSG_DEBUG("Contact ID [%d]", pContactInfo->contactId);
293 char* strImagePath = NULL;
294 ret = contacts_record_get_str_p(contact, _contacts_contact.image_thumbnail_path, &strImagePath);
295 if (ret != CONTACTS_ERROR_NONE) {
296 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
297 contacts_record_destroy(contact, true);
301 if (strImagePath != NULL)
302 strncpy(pContactInfo->imagePath , strImagePath, MAX_IMAGE_PATH_LEN);
304 MSG_DEBUG("Image Path [%s]", pContactInfo->imagePath);
306 contacts_record_destroy(contact, true);
314 void MsgSyncContact()
317 unsigned int changed_count = 0;
318 int lastSyncTime = 0;
319 int finalSyncTime = 0;
321 /* get contact sync time */
322 lastSyncTime = MsgSettingGetInt(CONTACT_SYNC_TIME);
324 if (lastSyncTime < 0) {
325 MSG_DEBUG("Fail to get CONTACT_SYNC_TIME.");
329 contacts_list_h contactsList = NULL;
331 ret = contacts_db_get_changes_by_version(_contacts_contact_updated_info._uri, -1, lastSyncTime, &contactsList, &finalSyncTime);
333 if (ret != CONTACTS_ERROR_NONE) {
334 MSG_DEBUG("contacts_db_get_changes_by_version() Error [%d]", ret);
338 ret = contacts_list_get_count(contactsList, &changed_count);
340 if (ret != CONTACTS_ERROR_NONE) {
341 MSG_DEBUG("contacts_list_get_count() Error [%d]", ret);
342 contacts_list_destroy(contactsList, true);
346 for (unsigned int i = 0; i < changed_count; i++)
350 contacts_record_h event = NULL;
352 ret = contacts_list_get_current_record_p(contactsList, &event);
353 if (ret != CONTACTS_ERROR_NONE) {
354 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
355 contacts_list_destroy(contactsList, true);
359 ret = contacts_record_get_int(event, _contacts_contact_updated_info.contact_id, &index_num);
360 if (ret != CONTACTS_ERROR_NONE) {
361 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
362 contacts_list_destroy(contactsList, true);
366 MSG_DEBUG("index (%d)", index_num);
368 ret = contacts_record_get_int(event, _contacts_contact_updated_info.type, &type);
369 if (ret != CONTACTS_ERROR_NONE) {
370 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
371 contacts_list_destroy(contactsList, true);
375 if (type == CONTACTS_CHANGE_UPDATED || type == CONTACTS_CHANGE_INSERTED) {
376 MsgUpdateContact(index_num, type);
378 MSG_DEBUG("Delete Contact");
379 MsgDeleteContact(index_num);
382 ret = contacts_list_next(contactsList);
383 if (ret != CONTACTS_ERROR_NONE) {
384 MSG_DEBUG("contacts_list_next() Error [%d]", ret);
388 if(MsgSettingSetInt(CONTACT_SYNC_TIME, finalSyncTime) != MSG_SUCCESS)
389 MSG_DEBUG("MsgSettingSetInt fail : CONTACT_SYNC_TIME");
390 MSG_DEBUG("lastSyncTime : %d", finalSyncTime);
392 contacts_list_destroy(contactsList, true);
394 if(changed_count > 0)
399 bool MsgInsertContact(MSG_CONTACT_INFO_S *pContactInfo, const char *pNumber)
401 if (!pNumber || strlen(pNumber) <= 0)
404 if (MsgStoAddContactInfo(&ContactDbHandle, pContactInfo, pNumber) != MSG_SUCCESS) {
405 MSG_DEBUG("Fail to add contact info.");
413 bool MsgUpdateContact(int index, int type)
415 int ret = CONTACTS_ERROR_NONE;
417 contacts_record_h contact = NULL;
419 ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
420 if (ret != CONTACTS_ERROR_NONE) {
421 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
422 contacts_record_destroy(contact, true);
426 MSG_CONTACT_INFO_S contactInfo;
427 memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
429 ret = contacts_record_get_int(contact, _contacts_contact.id, (int*)&contactInfo.contactId);
430 if (ret != CONTACTS_ERROR_NONE) {
431 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
432 contacts_record_destroy(contact, true);
436 MSG_DEBUG("Contact ID [%d]", contactInfo.contactId);
438 char* strImagePath = NULL;
439 ret = contacts_record_get_str_p(contact, _contacts_contact.image_thumbnail_path, &strImagePath);
440 if (ret != CONTACTS_ERROR_NONE) {
441 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
442 contacts_record_destroy(contact, true);
446 if (strImagePath != NULL)
447 strncpy(contactInfo.imagePath , strImagePath, MAX_IMAGE_PATH_LEN);
449 MSG_DEBUG("Image Path [%s]", contactInfo.imagePath);
452 contacts_record_h name = NULL;
454 ret = contacts_record_get_child_record_at_p(contact, _contacts_contact.name, 0, &name);
455 if (ret != CONTACTS_ERROR_NONE) {
456 MSG_DEBUG("contacts_record_get_child_record_at_p() Error [%d]", ret);
457 contacts_record_destroy(contact, true);
461 char* strFirstName = NULL;
462 ret = contacts_record_get_str_p(name, _contacts_name.first, &strFirstName);
463 if (ret != CONTACTS_ERROR_NONE) {
464 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
465 contacts_record_destroy(contact, true);
469 char* strLastName = NULL;
470 ret = contacts_record_get_str_p(name, _contacts_name.last, &strLastName);
471 if (ret != CONTACTS_ERROR_NONE) {
472 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
473 contacts_record_destroy(contact, true);
477 MSG_DEBUG("First Name : [%s], Last Name : [%s]", strFirstName, strLastName);
479 if (strFirstName != NULL)
480 strncpy(contactInfo.firstName, strFirstName, MAX_DISPLAY_NAME_LEN);
482 if (strLastName != NULL)
483 strncpy(contactInfo.lastName, strLastName, MAX_DISPLAY_NAME_LEN);
485 MsgStoClearContactInfo(&ContactDbHandle, index);
487 unsigned int count = 0;
488 ret = contacts_record_get_child_record_count(contact, _contacts_contact.number, &count);
489 if (ret != CONTACTS_ERROR_NONE) {
490 MSG_DEBUG("contacts_record_get_child_record_count() Error [%d]", ret);
491 contacts_record_destroy(contact, true);
495 MSG_DEBUG("_contacts_contact.number count [%d]", count);
498 for(unsigned int i=0; i < count; i++)
500 MSG_DEBUG("Add Number Contact Data");
502 contacts_record_h number = NULL;
504 ret = contacts_record_get_child_record_at_p(contact, _contacts_contact.number, i, &number);
505 if (ret != CONTACTS_ERROR_NONE) {
506 MSG_DEBUG("contacts_record_get_child_record_at_p() Error [%d]", ret);
507 contacts_record_destroy(contact, true);
511 char* strNumber = NULL;
512 ret = contacts_record_get_str_p(number, _contacts_number.number, &strNumber);
513 if (ret != CONTACTS_ERROR_NONE) {
514 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
515 contacts_record_destroy(contact, true);
519 if (strNumber != NULL) {
520 MSG_DEBUG("Number = %s", strNumber);
521 if (!MsgInsertContact(&contactInfo, strNumber)) {
522 MSG_DEBUG("MsgInsertContact fail.");
529 ret = contacts_record_get_child_record_count(contact, _contacts_contact.email, &count);
530 if (ret != CONTACTS_ERROR_NONE) {
531 MSG_DEBUG("contacts_record_get_child_record_count() Error [%d]", ret);
532 contacts_record_destroy(contact, true);
536 MSG_DEBUG("_contacts_contact.email count [%d]", count);
539 for(unsigned int i=0; i < count; i++)
541 MSG_DEBUG("Add Email Contact Data");
543 contacts_record_h email = NULL;
545 ret = contacts_record_get_child_record_at_p(contact, _contacts_contact.email, i, &email);
546 if (ret != CONTACTS_ERROR_NONE) {
547 MSG_DEBUG("contacts_record_get_child_record_at_p() Error [%d]", ret);
548 contacts_record_destroy(contact, true);
552 char* strNumber = NULL;
553 ret = contacts_record_get_str_p(email, _contacts_email.email, &strNumber);
554 if (ret != CONTACTS_ERROR_NONE) {
555 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
556 contacts_record_destroy(contact, true);
560 if (strNumber != NULL) {
561 MSG_DEBUG("email = %s", strNumber);
562 if (!MsgInsertContact(&contactInfo, strNumber)) {
563 MSG_DEBUG("MsgInsertContact fail.");
569 MsgStoSetConversationDisplayName(&ContactDbHandle, index);
571 contacts_record_destroy(contact, true);
577 bool MsgDeleteContact(int index)
579 if (MsgStoClearContactInfo(&ContactDbHandle, index) != MSG_SUCCESS)
586 int MsgGetContactNameOrder()
588 msg_error_t err = MSG_SUCCESS;
590 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
591 MSG_DEBUG("MsgOpenContactSvc fail.");
595 if (!isContactSvcConnected) {
596 MSG_DEBUG("Contact Service Not Opened.");
597 return 0; // return default value : FIRSTLAST
600 int ret = CONTACTS_ERROR_NONE;
602 contacts_name_display_order_e order = CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST;
604 ret = contacts_setting_get_name_display_order(&order);
605 if (ret != CONTACTS_ERROR_NONE) {
606 MSG_DEBUG("contacts_setting_get_name_display_order() Error [%d]", ret);
610 if (order == CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST)
617 void MsgAddPhoneLog(const MSG_MESSAGE_INFO_S *pMsgInfo)
619 msg_error_t err = MSG_SUCCESS;
621 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
622 MSG_DEBUG("MsgOpenContactSvc fail.");
626 if (!isContactSvcConnected) {
627 MSG_DEBUG("Contact Service Not Opened.");
631 if(pMsgInfo->nAddressCnt < 1) {
632 MSG_DEBUG("address count is [%d]", pMsgInfo->nAddressCnt);
636 for (int i = 0; pMsgInfo->nAddressCnt > i; i++) {
638 contacts_record_h plog = NULL;
640 ret = contacts_record_create(_contacts_phone_log._uri, &plog);
641 if (ret != CONTACTS_ERROR_NONE) {
642 MSG_DEBUG("contacts_record_create() Error [%d]", ret);
643 contacts_record_destroy(plog, true);
647 contacts_record_set_str(plog, _contacts_phone_log.address, (char*)pMsgInfo->addressList[i].addressVal);
648 contacts_record_set_int(plog, _contacts_phone_log.log_time, (int)time(NULL));
651 memset(strText, 0x00, sizeof(strText));
653 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE) {
654 strncpy(strText, pMsgInfo->msgText, 100);
655 MSG_DEBUG("msgText : %s", strText);
656 } else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE) {
657 if (strlen(pMsgInfo->subject) > 0 || pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
658 strncpy(strText, pMsgInfo->subject, 100);
659 MSG_DEBUG("subject : %s", strText);
661 strncpy(strText, pMsgInfo->msgText, 100);
662 MSG_DEBUG("msgText : %s", strText);
666 contacts_record_set_str(plog, _contacts_phone_log.extra_data2, strText);
667 contacts_record_set_int(plog, _contacts_phone_log.extra_data1, (int)pMsgInfo->msgId);
669 if (pMsgInfo->folderId == MSG_INBOX_ID) {
670 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
671 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_INCOMMING);
672 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
673 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_INCOMMING);
674 } else if (pMsgInfo->folderId == MSG_OUTBOX_ID) {
675 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
676 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_OUTGOING);
677 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
678 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_OUTGOING);
679 } else if (pMsgInfo->folderId == MSG_SPAMBOX_ID) {
680 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
681 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_BLOCKED);
682 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
683 contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_BLOCKED);
686 ret = contacts_db_insert_record(plog, NULL);
687 if (ret != CONTACTS_ERROR_NONE) {
688 MSG_DEBUG("contacts_db_insert_record() Error [%d]", ret);
691 contacts_record_destroy(plog, true);
696 void MsgDeletePhoneLog(msg_message_id_t msgId)
698 msg_error_t err = MSG_SUCCESS;
700 if ((err = MsgOpenContactSvc()) != MSG_SUCCESS) {
701 MSG_DEBUG("MsgOpenContactSvc fail.");
705 MSG_DEBUG("MsgDeletePhoneLog [%d]", msgId);
707 if (!isContactSvcConnected) {
708 MSG_DEBUG("Contact Service Not Opened.");
712 int ret = CONTACTS_ERROR_NONE;
714 unsigned int count = 0;
715 contacts_query_h query;
716 contacts_filter_h filter;
717 contacts_list_h plogs = NULL;
719 ret = contacts_query_create(_contacts_phone_log._uri, &query);
720 ret = contacts_filter_create(_contacts_phone_log._uri, &filter);
722 ret = contacts_filter_add_int(filter, _contacts_phone_log.extra_data1, CONTACTS_MATCH_EQUAL, (int)msgId);
725 ret = contacts_query_set_filter(query, filter);
726 ret = contacts_db_get_records_with_query(query, 0, 1, &plogs);
728 ret = contacts_list_get_count(plogs, &count);
731 MSG_DEBUG("No Serach Data from Contact Service.");
733 contacts_record_h plog = NULL;
735 ret = contacts_list_get_current_record_p(plogs, &plog);
736 if (ret != CONTACTS_ERROR_NONE) {
737 MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
740 ret = contacts_record_get_int(plog, _contacts_phone_log.id, &index);
741 if (ret != CONTACTS_ERROR_NONE) {
742 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
745 ret = contacts_db_delete_record(_contacts_phone_log._uri, index);
746 if (ret != CONTACTS_ERROR_NONE) {
747 MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
749 MSG_DEBUG("contacts_db_delete_record() Success.");
753 contacts_query_destroy(query);
754 contacts_filter_destroy(filter);
755 contacts_list_destroy(plogs, true);
760 int MsgContactSVCBeginTrans()
762 //return contacts_svc_begin_trans();
767 int MsgContactSVCEndTrans(bool bSuccess)
769 //return contacts_svc_end_trans(bSuccess);