RSA sync with private
[platform/core/messaging/msg-service.git] / utils / MsgContact.cpp
1 /*
2 * Copyright 2012  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.0 (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
7 *
8 *    http://www.tizenopensource.org/license
9 *
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.
15 */
16
17 extern "C"
18 {
19         #include <contacts.h>
20 }
21
22 #include "MsgDebug.h"
23 #include "MsgUtilStorage.h"
24 #include "MsgGconfWrapper.h"
25 #include "MsgContact.h"
26
27
28 /*==================================================================================================
29                                      VARIABLES
30 ==================================================================================================*/
31 //static bool isContactSvcOpened = false;
32
33 MsgDbHandler ContactDbHandle;
34
35 MsgContactChangeCB cbFunction = NULL;
36 /*==================================================================================================
37                                      FUNCTION IMPLEMENTATION
38 ==================================================================================================*/
39 static void MsgContactSvcCallback(const char *view_uri, void *user_data)
40 {
41         MSG_DEBUG("Contact Data is Changed!!!");
42
43         MsgSyncContact();
44
45         if (ContactDbHandle.disconnect() != MSG_SUCCESS)
46                 MSG_DEBUG("DB Disconnect Fail");
47 }
48
49
50 msg_error_t MsgOpenContactSvc()
51 {
52         int errCode = CONTACTS_ERROR_NONE;
53
54 //      if (!isContactSvcOpened) {
55                 errCode = contacts_connect2();
56
57                 if (errCode == CONTACTS_ERROR_NONE) {
58                         MSG_DEBUG("Connect to Contact Service Success");
59 //                      isContactSvcOpened = true;
60                 } else {
61                         MSG_DEBUG("Connect to Contact Service Fail [%d]", errCode);
62 //                      isContactSvcOpened = false;
63                         return MSG_ERR_DB_CONNECT;
64                 }
65 //      } else {
66 //              MSG_DEBUG("Already connected to Contact Service.");
67 //      }
68
69         return MSG_SUCCESS;
70 }
71
72
73 msg_error_t MsgCloseContactSvc()
74 {
75         int errCode = CONTACTS_ERROR_NONE;
76
77 //      if (isContactSvcOpened) {
78                 errCode = contacts_disconnect2();
79
80                 if (errCode == CONTACTS_ERROR_NONE) {
81                         MSG_DEBUG("Disconnect to Contact Service Success");
82                 } else {
83                         MSG_DEBUG("Disconnect to Contact Service Fail [%d]", errCode);
84                         return MSG_ERR_DB_DISCONNECT;
85                 }
86 //      }
87
88         return MSG_SUCCESS;
89 }
90
91
92 msg_error_t MsgInitContactSvc(MsgContactChangeCB cb)
93 {
94         int errCode = CONTACTS_ERROR_NONE;
95
96         if (cb != NULL)
97                 cbFunction = cb;
98
99         // Register callback function
100         errCode = contacts_db_add_changed_cb(_contacts_contact._uri, MsgContactSvcCallback, NULL);
101
102         if (errCode == CONTACTS_ERROR_NONE)
103                 MSG_DEBUG("Register Contact Service Callback");
104         else
105                 MSG_DEBUG("Fail to Register Contact Service Callback [%d]", errCode);
106
107         return MSG_SUCCESS;
108 }
109
110
111 msg_error_t MsgGetContactInfo(const MSG_ADDRESS_INFO_S *pAddrInfo, MSG_CONTACT_INFO_S *pContactInfo)
112 {
113         MSG_BEGIN();
114
115         MSG_DEBUG("Address Type [%d], Address Value [%s]", pAddrInfo->addressType, pAddrInfo->addressVal);
116
117         memset(pContactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
118
119         if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN && strlen(pAddrInfo->addressVal) > (MAX_PHONE_NUMBER_LEN+1)) {
120                 MSG_DEBUG("Phone Number is too long [%s]", pAddrInfo->addressVal);
121                 return MSG_SUCCESS;
122         }
123
124         int ret = 0;
125         int index = 0;
126         unsigned int count = 0;
127         contacts_query_h query = NULL;
128         contacts_filter_h filter = NULL;
129         contacts_list_h contacts = NULL;
130
131         if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN) {
132                 ret = contacts_query_create(_contacts_contact_number._uri, &query);
133                 ret = contacts_filter_create(_contacts_contact_number._uri, &filter);
134
135                 ret = contacts_filter_add_str(filter, _contacts_contact_number.number_filter, CONTACTS_MATCH_EXACTLY, pAddrInfo->addressVal);
136
137         } else if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_EMAIL) {
138                 ret = contacts_query_create(_contacts_contact_email._uri, &query);
139                 ret = contacts_filter_create(_contacts_contact_email._uri, &filter);
140
141                 ret = contacts_filter_add_str(filter, _contacts_contact_email.email, CONTACTS_MATCH_EXACTLY, pAddrInfo->addressVal);
142
143         } else {
144                 MSG_DEBUG("Invalid pAddrInfo->addressType.");
145                 return MSG_SUCCESS;
146         }
147
148         ret = contacts_query_set_filter(query, filter);
149         ret = contacts_db_get_records_with_query(query, 0, 1, &contacts);
150         if (ret != CONTACTS_ERROR_NONE) {
151                 MSG_DEBUG("contacts_db_get_records_with_query() Error [%d]", ret);
152                 contacts_query_destroy(query);
153                 contacts_filter_destroy(filter);
154                 contacts_list_destroy(contacts, true);
155                 return MSG_SUCCESS;
156         }
157
158         ret = contacts_list_get_count(contacts, &count);
159
160         if (count == 0 || ret != CONTACTS_ERROR_NONE) {
161                 MSG_DEBUG("No Serach Data from Contact Service.");
162                 contacts_query_destroy(query);
163                 contacts_filter_destroy(filter);
164                 contacts_list_destroy(contacts, true);
165                 return MSG_SUCCESS;
166         }
167
168         contacts_record_h contact = NULL;
169
170         if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_PLMN) {
171                 contacts_record_h number = NULL;
172
173                 ret = contacts_list_get_current_record_p(contacts, &number);
174                 if (ret != CONTACTS_ERROR_NONE) {
175                         MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
176                         contacts_list_destroy(contacts, true);
177                         return MSG_SUCCESS;
178                 }
179
180                 ret = contacts_record_get_int(number, _contacts_contact_number.contact_id, &index);
181                 if (ret != CONTACTS_ERROR_NONE) {
182                         MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
183                         contacts_list_destroy(contacts, true);
184                         contacts_record_destroy(number, true);
185                         return MSG_SUCCESS;
186                 }
187
188                 ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
189                 if (ret != CONTACTS_ERROR_NONE) {
190                         MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
191                         contacts_list_destroy(contacts, true);
192                         contacts_record_destroy(contact, true);
193                         contacts_record_destroy(number, true);
194                         return MSG_SUCCESS;
195                 }
196         } else if (pAddrInfo->addressType == MSG_ADDRESS_TYPE_EMAIL) {
197                 contacts_record_h email = NULL;
198
199                 ret = contacts_list_get_current_record_p(contacts, &email);
200                 if (ret != CONTACTS_ERROR_NONE) {
201                         MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
202                         contacts_list_destroy(contacts, true);
203                         return MSG_SUCCESS;
204                 }
205
206                 ret = contacts_record_get_int(email, _contacts_contact_email.contact_id, &index);
207                 if (ret != CONTACTS_ERROR_NONE) {
208                         MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
209                         contacts_list_destroy(contacts, true);
210                         contacts_record_destroy(email, true);
211                         return MSG_SUCCESS;
212                 }
213
214                 ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
215                 if (ret != CONTACTS_ERROR_NONE) {
216                         MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
217                         contacts_list_destroy(contacts, true);
218                         contacts_record_destroy(contact, true);
219                         contacts_record_destroy(email, true);
220                         return MSG_SUCCESS;
221                 }
222         }
223
224         contacts_list_destroy(contacts, true);
225
226         // Name Info
227         contacts_record_h name = NULL;
228
229         ret = contacts_record_get_child_record_at_p(contact, _contacts_contact.name, 0, &name);
230         if (ret != CONTACTS_ERROR_NONE) {
231                 MSG_DEBUG("contacts_record_get_child_record_at_p() Error [%d]", ret);
232                 contacts_record_destroy(contact, true);
233                 return MSG_SUCCESS;
234         }
235
236         char* strFirstName = NULL;
237         ret = contacts_record_get_str_p(name, _contacts_name.first, &strFirstName);
238         if (ret != CONTACTS_ERROR_NONE) {
239                 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
240                 contacts_record_destroy(contact, true);
241                 return MSG_SUCCESS;
242         }
243
244         char* strLastName = NULL;
245         ret = contacts_record_get_str_p(name, _contacts_name.last, &strLastName);
246         if (ret != CONTACTS_ERROR_NONE) {
247                 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
248                 contacts_record_destroy(contact, true);
249                 return MSG_SUCCESS;
250         }
251
252         MSG_DEBUG("First Name : [%s], Last Name : [%s]", strFirstName, strLastName);
253
254         if (strFirstName != NULL)
255                 strncpy(pContactInfo->firstName, strFirstName, MAX_DISPLAY_NAME_LEN);
256
257         if (strLastName != NULL)
258                 strncpy(pContactInfo->lastName, strLastName, MAX_DISPLAY_NAME_LEN);
259
260         ret = contacts_record_get_int(contact, _contacts_contact.id, (int*)&pContactInfo->contactId);
261         if (ret != CONTACTS_ERROR_NONE) {
262                 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
263                 contacts_record_destroy(contact, true);
264                 return MSG_SUCCESS;
265         }
266
267         MSG_DEBUG("Contact ID [%d]", pContactInfo->contactId);
268
269         char* strImagePath = NULL;
270         ret = contacts_record_get_str_p(contact, _contacts_contact.image_thumbnail_path, &strImagePath);
271         if (ret != CONTACTS_ERROR_NONE) {
272                 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
273                 contacts_record_destroy(contact, true);
274                 return MSG_SUCCESS;
275         }
276
277         if (strImagePath != NULL)
278                 strncpy(pContactInfo->imagePath , strImagePath, MAX_IMAGE_PATH_LEN);
279
280         MSG_DEBUG("Image Path [%s]", pContactInfo->imagePath);
281
282         contacts_record_destroy(contact, true);
283
284         MSG_END();
285
286         return MSG_SUCCESS;
287 }
288
289
290 void MsgSyncContact()
291 {
292         int ret = -1;
293         unsigned int changed_count = 0;
294         int lastSyncTime = 0;
295         int finalSyncTime = 0;
296
297         /* get contact sync time */
298         lastSyncTime = MsgSettingGetInt(CONTACT_SYNC_TIME);
299
300         if (lastSyncTime < 0) {
301                 MSG_DEBUG("Fail to get CONTACT_SYNC_TIME.");
302                 lastSyncTime = 0;
303         }
304
305         contacts_list_h contactsList = NULL;
306
307         ret = contacts_db_get_changes_by_version(_contacts_contact_updated_info._uri, -1, lastSyncTime, &contactsList, &finalSyncTime);
308
309         if (ret != CONTACTS_ERROR_NONE) {
310                 MSG_DEBUG("contacts_db_get_changes_by_version() Error [%d]", ret);
311                 return;
312         }
313
314         ret = contacts_list_get_count(contactsList, &changed_count);
315
316         if (ret != CONTACTS_ERROR_NONE) {
317                 MSG_DEBUG("contacts_list_get_count() Error [%d]", ret);
318                 contacts_list_destroy(contactsList, true);
319                 return;
320         }
321
322         for (unsigned int i = 0; i < changed_count; i++);
323         {
324                 int index_num = 0;
325                 int type = 0;
326                 contacts_record_h event = NULL;
327
328                 ret = contacts_list_get_current_record_p(contactsList, &event);
329                 if (ret != CONTACTS_ERROR_NONE) {
330                         MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
331                         contacts_list_destroy(contactsList, true);
332                         return;
333                 }
334
335                 ret = contacts_record_get_int(event, _contacts_contact_updated_info.contact_id, &index_num);
336                 if (ret != CONTACTS_ERROR_NONE) {
337                         MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
338                         contacts_list_destroy(contactsList, true);
339                         return;
340                 }
341
342                 MSG_DEBUG("index (%d)", index_num);
343
344                 ret = contacts_record_get_int(event, _contacts_contact_updated_info.type, &type);
345                 if (ret != CONTACTS_ERROR_NONE) {
346                         MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
347                         contacts_list_destroy(contactsList, true);
348                         return;
349                 }
350
351                 if (type == CONTACTS_CHANGE_UPDATED || type == CONTACTS_CHANGE_INSERTED) {
352                         MsgUpdateContact(index_num, type);
353                 } else {// Delete
354                         MSG_DEBUG("Delete Contact");
355                         MsgDeleteContact(index_num);
356                 }
357
358                 ret = contacts_list_next(contactsList);
359                 if (ret != CONTACTS_ERROR_NONE) {
360                         MSG_DEBUG("contacts_list_next() Error [%d]", ret);
361                 }
362         }
363
364         MsgSettingSetInt(CONTACT_SYNC_TIME, finalSyncTime);
365         MSG_DEBUG("lastSyncTime : %d", finalSyncTime);
366
367         contacts_list_destroy(contactsList, true);
368
369         if(changed_count > 0)
370                 cbFunction();
371 }
372
373
374 bool MsgInsertContact(MSG_CONTACT_INFO_S *pContactInfo, const char *pNumber)
375 {
376         if (!pNumber || strlen(pNumber) <= 0)
377                 return false;
378
379         if (MsgStoAddContactInfo(&ContactDbHandle, pContactInfo, pNumber) != MSG_SUCCESS) {
380                 MSG_DEBUG("Fail to add contact info.");
381                 return false;
382         }
383
384         return true;
385 }
386
387
388 bool MsgUpdateContact(int index, int type)
389 {
390         int ret = CONTACTS_ERROR_NONE;
391
392         contacts_record_h contact = NULL;
393
394         ret = contacts_db_get_record(_contacts_contact._uri, index, &contact);
395         if (ret != CONTACTS_ERROR_NONE) {
396                 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
397                 contacts_record_destroy(contact, true);
398                 return false;
399         }
400
401         MSG_CONTACT_INFO_S contactInfo;
402         memset(&contactInfo, 0x00, sizeof(MSG_CONTACT_INFO_S));
403
404         ret = contacts_record_get_int(contact, _contacts_contact.id, (int*)&contactInfo.contactId);
405         if (ret != CONTACTS_ERROR_NONE) {
406                 MSG_DEBUG("contacts_db_get_record() Error [%d]", ret);
407                 contacts_record_destroy(contact, true);
408                 return false;
409         }
410
411         MSG_DEBUG("Contact ID [%d]", contactInfo.contactId);
412
413         char* strImagePath = NULL;
414         ret = contacts_record_get_str_p(contact, _contacts_contact.image_thumbnail_path, &strImagePath);
415         if (ret != CONTACTS_ERROR_NONE) {
416                 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
417                 contacts_record_destroy(contact, true);
418                 return false;
419         }
420
421         if (strImagePath != NULL)
422                 strncpy(contactInfo.imagePath , strImagePath, MAX_IMAGE_PATH_LEN);
423
424         MSG_DEBUG("Image Path [%s]", contactInfo.imagePath);
425
426         // Name Info
427         contacts_record_h name = NULL;
428
429         ret = contacts_record_get_child_record_at_p(contact, _contacts_contact.name, 0, &name);
430         if (ret != CONTACTS_ERROR_NONE) {
431                 MSG_DEBUG("contacts_record_get_child_record_at_p() Error [%d]", ret);
432                 contacts_record_destroy(contact, true);
433                 return false;
434         }
435
436         char* strFirstName = NULL;
437         ret = contacts_record_get_str_p(name, _contacts_name.first, &strFirstName);
438         if (ret != CONTACTS_ERROR_NONE) {
439                 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
440                 contacts_record_destroy(contact, true);
441                 return false;
442         }
443
444         char* strLastName = NULL;
445         ret = contacts_record_get_str_p(name, _contacts_name.last, &strLastName);
446         if (ret != CONTACTS_ERROR_NONE) {
447                 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
448                 contacts_record_destroy(contact, true);
449                 return false;
450         }
451
452         MSG_DEBUG("First Name : [%s], Last Name : [%s]", strFirstName, strLastName);
453
454         if (strFirstName != NULL)
455                 strncpy(contactInfo.firstName, strFirstName, MAX_DISPLAY_NAME_LEN);
456
457         if (strLastName != NULL)
458                 strncpy(contactInfo.lastName, strLastName, MAX_DISPLAY_NAME_LEN);
459
460         MsgStoClearContactInfo(&ContactDbHandle, index);
461
462         unsigned int count = 0;
463         ret = contacts_record_get_child_record_count(contact, _contacts_contact.number, &count);
464         if (ret != CONTACTS_ERROR_NONE) {
465                 MSG_DEBUG("contacts_record_get_child_record_count() Error [%d]", ret);
466                 contacts_record_destroy(contact, true);
467                 return false;
468         }
469
470         if (count > 0) {
471                 for(unsigned int i=0; i < count; i++)
472                 {
473                         MSG_DEBUG("Add Contact Data");
474
475                         contacts_record_h number = NULL;
476
477                         ret = contacts_record_get_child_record_at_p(contact, _contacts_contact.number, i, &number);
478                         if (ret != CONTACTS_ERROR_NONE) {
479                                 MSG_DEBUG("contacts_record_get_child_record_at_p() Error [%d]", ret);
480                                 contacts_record_destroy(contact, true);
481                                 return false;
482                         }
483
484                         char* strNumber = NULL;
485                         ret = contacts_record_get_str_p(number, _contacts_number.number, &strNumber);
486                         if (ret != CONTACTS_ERROR_NONE) {
487                                 MSG_DEBUG("contacts_record_get_str_p() Error [%d]", ret);
488                                 contacts_record_destroy(contact, true);
489                                 return false;
490                         }
491
492                         if (strNumber != NULL) {
493                                 MSG_DEBUG("Number = %s", strNumber);
494                                 if (!MsgInsertContact(&contactInfo, strNumber)) {
495                                         MSG_DEBUG("MsgInsertContact fail.");
496                                 }
497                         }
498                 }
499         } else {// No phone number in contact
500                 contacts_record_destroy(contact, true);
501                 return true;
502         }
503
504         MsgStoSetConversationDisplayName(&ContactDbHandle, index);
505
506         contacts_record_destroy(contact, true);
507
508         return true;
509 }
510
511
512 bool MsgDeleteContact(int index)
513 {
514         if (MsgStoClearContactInfo(&ContactDbHandle, index) != MSG_SUCCESS)
515                 return false;
516
517         return true;
518 }
519
520
521 int MsgGetContactNameOrder()
522 {
523         int ret = CONTACTS_ERROR_NONE;
524
525         contacts_name_display_order_e order = CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST;
526
527         ret = contacts_setting_get_name_display_order(&order);
528         if (ret != CONTACTS_ERROR_NONE) {
529                 MSG_DEBUG("contacts_setting_get_name_display_order() Error [%d]", ret);
530                 return 0;
531         }
532
533         if (order == CONTACTS_NAME_DISPLAY_ORDER_FIRSTLAST)
534                 return 0;
535         else
536                 return 1;
537 }
538
539
540 void MsgAddPhoneLog(const MSG_MESSAGE_INFO_S *pMsgInfo)
541 {
542         int ret = 0;
543
544         MSG_DEBUG("folderId [%d], number [%s]", pMsgInfo->folderId, pMsgInfo->addressList[0].addressVal);
545
546         contacts_record_h plog = NULL;
547
548         ret = contacts_record_create(_contacts_phone_log._uri, &plog);
549         if (ret != CONTACTS_ERROR_NONE) {
550                 MSG_DEBUG("contacts_record_create() Error [%d]", ret);
551                 contacts_record_destroy(plog, true);
552         }
553
554         contacts_record_set_str(plog, _contacts_phone_log.address, (char*)pMsgInfo->addressList[0].addressVal);
555         contacts_record_set_int(plog, _contacts_phone_log.log_time, (int)time(NULL));
556
557         char strText[101];
558         memset(strText, 0x00, sizeof(strText));
559
560         if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE) {
561                 strncpy(strText, pMsgInfo->msgText, 100);
562                 MSG_DEBUG("msgText : %s", strText);
563         } else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE) {
564                 if (strlen(pMsgInfo->subject) > 0 || pMsgInfo->msgType.subType == MSG_NOTIFICATIONIND_MMS) {
565                         strncpy(strText, pMsgInfo->subject, 100);
566                         MSG_DEBUG("subject : %s", strText);
567                 } else {
568                         strncpy(strText, pMsgInfo->msgText, 100);
569                         MSG_DEBUG("msgText : %s", strText);
570                 }
571         }
572
573         contacts_record_set_str(plog, _contacts_phone_log.extra_data2, strText);
574         contacts_record_set_int(plog, _contacts_phone_log.extra_data1, (int)pMsgInfo->msgId);
575
576         if (pMsgInfo->folderId == MSG_INBOX_ID) {
577                 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
578                         contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_INCOMMING);
579                 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
580                         contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_INCOMMING);
581         } else if (pMsgInfo->folderId == MSG_OUTBOX_ID) {
582                 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
583                         contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_OUTGOING);
584                 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
585                         contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_OUTGOING);
586         } else if (pMsgInfo->folderId == MSG_SPAMBOX_ID) {
587                 if (pMsgInfo->msgType.mainType == MSG_SMS_TYPE)
588                         contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_SMS_BLOCKED);
589                 else if (pMsgInfo->msgType.mainType == MSG_MMS_TYPE)
590                         contacts_record_set_int(plog, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_MMS_BLOCKED);
591         }
592
593         ret = contacts_db_insert_record(plog, NULL);
594         if (ret != CONTACTS_ERROR_NONE) {
595                 MSG_DEBUG("contacts_db_insert_record() Error [%d]", ret);
596         }
597
598         contacts_record_destroy(plog, true);
599 }
600
601
602 void MsgDeletePhoneLog(msg_message_id_t msgId)
603 {
604         MSG_DEBUG("MsgDeletePhoneLog [%d]", msgId);
605
606         int ret = CONTACTS_ERROR_NONE;
607         int index = 0;
608         unsigned int count = 0;
609         contacts_query_h query;
610         contacts_filter_h filter;
611         contacts_list_h plogs = NULL;
612
613         ret = contacts_query_create(_contacts_phone_log._uri, &query);
614         ret = contacts_filter_create(_contacts_phone_log._uri, &filter);
615
616         ret = contacts_filter_add_int(filter, _contacts_phone_log.extra_data1, CONTACTS_MATCH_EQUAL, (int)msgId);
617
618
619         ret = contacts_query_set_filter(query, filter);
620         ret = contacts_db_get_records_with_query(query, 0, 1, &plogs);
621
622         ret = contacts_list_get_count(plogs, &count);
623
624         if (count == 0) {
625                 MSG_DEBUG("No Serach Data from Contact Service.");
626         } else {
627                 contacts_record_h plog = NULL;
628
629                 ret = contacts_list_get_current_record_p(plogs, &plog);
630                 if (ret != CONTACTS_ERROR_NONE) {
631                         MSG_DEBUG("contacts_list_get_current_record_p() Error [%d]", ret);
632                 }
633
634                 ret = contacts_record_get_int(plog, _contacts_phone_log.id, &index);
635                 if (ret != CONTACTS_ERROR_NONE) {
636                         MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
637                 }
638
639                 ret = contacts_db_delete_record(_contacts_phone_log._uri, index);
640                 if (ret != CONTACTS_ERROR_NONE) {
641                         MSG_DEBUG("contacts_record_get_int() Error [%d]", ret);
642                 } else {
643                         MSG_DEBUG("contacts_db_delete_record() Success.");
644                 }
645         }
646
647         contacts_query_destroy(query);
648         contacts_filter_destroy(filter);
649         contacts_list_destroy(plogs, true);
650
651 }
652
653
654 int MsgContactSVCBeginTrans()
655 {
656         //return contacts_svc_begin_trans();
657         return 0;
658 }
659
660
661 int MsgContactSVCEndTrans(bool bSuccess)
662 {
663         //return contacts_svc_end_trans(bSuccess);
664         return 0;
665 }