#include "ctsvc_number_utils.h"
#include "ctsvc_localize_utils.h"
#include "ctsvc_server_setting.h"
+#include "ctsvc_server_utils.h"
#ifdef _CONTACTS_IPC_SERVER
#include "ctsvc_server_change_subject.h"
return ctsvc_query_exec(query);
}
+int ctsvc_phone_log_reset_statistics_by_sim(int sim_slot_no)
+{
+ char query[CTS_SQL_MIN_LEN] = {0};
+ int sim_info_id;
+
+ RETVM_IF(false == ctsvc_server_have_telephony_feature(), CONTACTS_ERROR_NOT_SUPPORTED, "Telephony feature disabled");
+
+ sim_info_id = ctsvc_server_sim_get_info_id_by_sim_slot_no(sim_slot_no);
+ if (sim_info_id <= 0) {
+ /* LCOV_EXCL_START */
+ ERR("ctsvc_server_sim_get_info_id_by_sim_slot_no() Fail(%d)", sim_info_id);
+ return CONTACTS_ERROR_NO_DATA;
+ /* LCOV_EXCL_STOP */
+ }
+
+ snprintf(query, sizeof(query), "DELETE FROM "CTS_TABLE_PHONELOG_STAT
+ " WHERE sim_id = %d", sim_info_id);
+ return ctsvc_query_exec(query);
+}
+
int ctsvc_phone_log_delete(contacts_phone_log_delete_e op, ...)
{
int ret;
snprintf(query, sizeof(query),
"DELETE FROM "CTS_TABLE_PHONELOGS" "
"WHERE data1 = %d AND %d <= log_type AND log_type <= %d",
- extra_data1, CONTACTS_PLOG_TYPE_MMS_INCOMMING, CONTACTS_PLOG_TYPE_MMS_BLOCKED);
+ extra_data1, CONTACTS_PLOG_TYPE_MMS_INCOMING, CONTACTS_PLOG_TYPE_MMS_BLOCKED);
break;
case CONTACTS_PHONE_LOG_DELETE_BY_EMAIL_EXTRA_DATA1:
va_start(args, op);
extra_data1, CONTACTS_PLOG_TYPE_EMAIL_RECEIVED, CONTACTS_PLOG_TYPE_EMAIL_SENT);
break;
default:
+ /* LCOV_EXCL_START */
ERR("the operation is not proper (op : %d)", op);
return CONTACTS_ERROR_INVALID_PARAMETER;
+ /* LCOV_EXCL_STOP */
}
ret = ctsvc_begin_trans();
RETVM_IF(ret, ret, "ctsvc_begin_trans() Fail(%d)", ret);
ret = ctsvc_query_exec(query);
if (CONTACTS_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
ERR("ctsvc_query_exec() Fail(%d)", ret);
ctsvc_end_trans(false);
return ret;
+ /* LCOV_EXCL_STOP */
}
ctsvc_set_phonelog_noti();
ret = ctsvc_end_trans(true);
#endif
}
-static int __ctsvc_db_phone_log_find_person_id(char *number, char *normal_num, char *minmatch, int person_id, int *find_number_type)
+static int __ctsvc_db_phone_log_find_person_id(char *number, char *normal_num,
+ char *minmatch, int person_id, int *find_number_type)
{
int ret;
int find_person_id = -1;
"ON "CTS_TABLE_CONTACTS".contact_id = "CTS_TABLE_DATA".contact_id "
"AND datatype = %d AND is_my_profile = 0 AND deleted = 0 "
"WHERE data4 = ? AND _NUMBER_COMPARE_(data5, ?, NULL, NULL)",
- CTSVC_DATA_NUMBER);
+ CONTACTS_DATA_TYPE_NUMBER);
bind_text = g_slist_append(bind_text, strdup(minmatch));
bind_text = g_slist_append(bind_text, strdup(normal_num));
}
ret = ctsvc_query_prepare(query, &stmt);
if (stmt == NULL) {
+ /* LCOV_EXCL_START */
ERR("ctsvc_query_prepare fail(%d)", ret);
if (bind_text) {
for (cursor = bind_text; cursor; cursor = cursor->next)
g_slist_free(bind_text);
}
return CONTACTS_ERROR_DB;
+ /* LCOV_EXCL_STOP */
}
if (bind_text) {
return find_person_id;
}
-int ctsvc_db_phone_log_update_person_id(const char *number, int old_person_id, int candidate_person_id, bool person_link)
+int ctsvc_db_phone_log_update_person_id(const char *number, int old_person_id,
+ int candidate_person_id, bool person_link, int *found_person_id)
{
CTS_FN_CALL;
int ret;
GSList *bind_text = NULL;
GSList *cursor = NULL;
int i = 0;
+ bool need_noti = false;
RETVM_IF(old_person_id <= 0 && NULL == number, CONTACTS_ERROR_INVALID_PARAMETER,
"old person_id (%d), number is NULL", old_person_id);
ret = ctsvc_normalize_number(clean_num, normal_num, sizeof(normal_num), true);
if (0 < ret) {
char minmatch[sizeof(normal_num)+1];
- ret = ctsvc_get_minmatch_number(normal_num, minmatch, sizeof(minmatch), ctsvc_get_phonenumber_min_match_digit());
+ ret = ctsvc_get_minmatch_number(normal_num, minmatch, sizeof(minmatch),
+ ctsvc_get_phonenumber_min_match_digit());
if (CONTACTS_ERROR_NONE == ret) {
len += snprintf(query+len, sizeof(query)-len,
"OR (minmatch = ? AND _NUMBER_COMPARE_(normal_num, ?, NULL, NULL))) ");
ret = ctsvc_query_prepare(query, &get_log);
if (get_log == NULL) {
+ /* LCOV_EXCL_START */
ERR("ctsvc_query_prepare() Fail(%d)", ret);
if (bind_text) {
for (cursor = bind_text; cursor; cursor = cursor->next)
g_slist_free(bind_text);
}
return CONTACTS_ERROR_DB;
+ /* LCOV_EXCL_STOP */
}
if (bind_text) {
"UPDATE "CTS_TABLE_PHONELOGS" SET person_id=?, number_type = ? WHERE id = ?");
ret = ctsvc_query_prepare(query, &update_log);
if (update_log == NULL) {
+ /* LCOV_EXCL_START */
ERR("ctsvc_query_prepare() Fail(%d)", ret);
ctsvc_stmt_finalize(get_log);
g_slist_free(bind_text);
}
return CONTACTS_ERROR_DB;
+ /* LCOV_EXCL_STOP */
}
while ((ret = ctsvc_stmt_step(get_log))) {
/* CASE : number is inserted (contact insert/update) => update person_id of phone logs from NULL */
if (number && old_person_id <= 0 && 0 < candidate_person_id) {
- __ctsvc_db_phone_log_find_person_id(address, normal_address, minmatch_address, candidate_person_id, &number_type);
+ __ctsvc_db_phone_log_find_person_id(address, normal_address,
+ minmatch_address, candidate_person_id, &number_type);
new_person_id = candidate_person_id;
} else if (number && old_person_id <= 0) {
/* CASE : phonelog insert without person_id */
/* address == number */
- new_person_id = __ctsvc_db_phone_log_find_person_id(address, normal_address, minmatch_address, -1, &number_type);
- if (new_person_id <= 0) continue;
+ new_person_id = __ctsvc_db_phone_log_find_person_id(address, normal_address,
+ minmatch_address, -1, &number_type);
+ if (new_person_id <= 0)
+ continue;
+
+ if (found_person_id)
+ *found_person_id = new_person_id;
} else if (number && 0 < old_person_id) {
/* CASE : number update/delete (contact update/delete) => find new_person_id by address */
/* CASE : phonelog insert with person_id */
/* address == number */
/* although new_person_id and old_person_id are same, update phonelog for setting number_type */
- new_person_id = __ctsvc_db_phone_log_find_person_id(address, normal_address, minmatch_address, old_person_id, &number_type);
+ new_person_id = __ctsvc_db_phone_log_find_person_id(address, normal_address,
+ minmatch_address, old_person_id, &number_type);
} else if (NULL == number && 0 < old_person_id && 0 < candidate_person_id && person_link) {
/* CASE : person link => deleted person_id -> new person_id (base_person_id) */
new_person_id = candidate_person_id;
} else if (NULL == number && 0 < old_person_id && 0 < candidate_person_id) {
/* CASE : person unlink => check person_id of the address, */
/* if person_id is not old_person_id then change person_id to new_person_id */
- temp_id = __ctsvc_db_phone_log_find_person_id(address, normal_address, minmatch_address, candidate_person_id, &number_type);
+ temp_id = __ctsvc_db_phone_log_find_person_id(address, normal_address,
+ minmatch_address, candidate_person_id, &number_type);
if (0 < temp_id && temp_id == old_person_id)
continue;
else if (0 < temp_id && temp_id != old_person_id)
* continue;
*/
+ if (!need_noti)
+ need_noti = true;
+
if (0 < new_person_id)
ctsvc_stmt_bind_int(update_log, 1, new_person_id);
if (0 <= number_type)
ctsvc_stmt_finalize(get_log);
ctsvc_stmt_finalize(update_log);
+ if (need_noti)
+ ctsvc_set_phonelog_noti();
+
if (bind_text) {
for (cursor = bind_text; cursor; cursor = cursor->next)
free(cursor->data);