int cal_db_link_record(int base_id, int linked_id)
{
+ RETV_IF(base_id == linked_id, CALENDAR_ERROR_INVALID_PARAMETER);
+
int ret = 0;
char query[CAL_DB_SQL_MAX_LEN] = {0};
RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "cal_db_util_begin_trans() Fail");
calendar_record_h record = NULL;
+ cal_record_s *record_s = NULL;
+ /* check linked_id validation */
ret = cal_db_get_record(_calendar_event._uri, linked_id, &record);
if (CALENDAR_ERROR_NONE != ret) {
/* LCOV_EXCL_START */
return ret;
/* LCOV_EXCL_STOP */
}
- cal_record_s *record_s = (cal_record_s *)record;
+ record_s = (cal_record_s *)record;
+ if (CAL_STRING_EQUAL != strcmp(record_s->view_uri, CALENDAR_VIEW_EVENT)) {
+ /* LCOV_EXCL_START */
+ DBG("This link is invalid in event");
+ calendar_record_destroy(record, true);
+ cal_db_util_end_trans(false);
+ return CALENDAR_ERROR_INVALID_PARAMETER;
+ /* LCOV_EXCL_STOP */
+ }
+ calendar_record_destroy(record, true);
+ record = NULL;
+
+ /* check base_id validation */
+ ret = cal_db_get_record(_calendar_event._uri, base_id, &record);
+ if (CALENDAR_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ ERR("cal_db_get_record() Fail(%d)", ret);
+ cal_db_util_end_trans(false);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+ record_s = (cal_record_s *)record;
if (CAL_STRING_EQUAL != strcmp(record_s->view_uri, CALENDAR_VIEW_EVENT)) {
/* LCOV_EXCL_START */
DBG("This link is invalid in event");
return CALENDAR_ERROR_INVALID_PARAMETER;
/* LCOV_EXCL_STOP */
}
+ cal_event_s *event_s = (cal_event_s *)record;
+ if (event_s->link_base_id == linked_id) {
+ /* LCOV_EXCL_START */
+ DBG("Invalid argument: Tried to link cross link");
+ calendar_record_destroy(record, true);
+ cal_db_util_end_trans(false);
+ return CALENDAR_ERROR_INVALID_PARAMETER;
+ /* LCOV_EXCL_STOP */
+ }
+ calendar_record_destroy(record, true);
/* if linked record already has base, reduce base linked count. */
snprintf(query, sizeof(query), "UPDATE "CAL_TABLE_SCHEDULE" SET link_count = link_count -1 "
"WHERE id = (SELECT link_base_id FROM "CAL_TABLE_SCHEDULE" WHERE id = %d) AND type = %d "
"AND (SELECT link_base_id FROM "CAL_TABLE_SCHEDULE" WHERE id = %d) > 0 ",
- linked_id, CALENDAR_BOOK_TYPE_EVENT, linked_id);
+ linked_id, CALENDAR_BOOK_TYPE_EVENT, linked_id, base_id);
ret = cal_db_util_query_exec(query);
if (CALENDAR_ERROR_NONE != ret) {
/* LCOV_EXCL_START */
ERR("cal_db_util_query_exec() Fail(%d)", ret);
SECURE("[%s]", query);
- calendar_record_destroy(record, true);
cal_db_util_end_trans(false);
return ret;
/* LCOV_EXCL_STOP */
/* LCOV_EXCL_START */
ERR("cal_db_util_query_exec() Fail(%d)", ret);
SECURE("[%s]", query);
- calendar_record_destroy(record, true);
cal_db_util_end_trans(false);
return ret;
/* LCOV_EXCL_STOP */
* we choose case 1. so modify alarm logic not to pick liked record alarm.
*/
- calendar_record_destroy(record, true);
cal_db_util_end_trans(true);
return ret;