modify terminology:calendar->book,allday->localtime,normal->utime,svc->service
[platform/core/pim/calendar-service.git] / server / db / cal_db.h
1 /*
2  * Calendar Service
3  *
4  * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19 #include <tzplatform_config.h>
20
21 #ifndef __CAL_DB_H__
22 #define __CAL_DB_H__
23
24 #include "calendar_view.h"
25 #include "calendar_list.h"
26
27 #define CALS_DB_NAME ".calendar-svc.db"
28 #define DB_PATH tzplatform_getenv(TZ_USER_DB)
29 #define DATA_PATH tzplatform_getenv(TZ_USER_DATA)
30 #define CAL_DB_FILE tzplatform_mkpath(TZ_USER_DB, ".calendar-svc.db")
31 #define CAL_DATA_PATH tzplatform_mkpath(TZ_USER_DATA, "calendar-svc")
32
33 /* For Security */
34 #define CAL_SECURITY_FILE_GROUP 5000
35 #define CAL_SECURITY_DEFAULT_PERMISSION 0660
36 #define CAL_SECURITY_DIR_DEFAULT_PERMISSION 0770
37
38 #define CAL_DB_SQL_MAX_LEN 2048
39 #define CAL_DB_SQL_MIN_LEN 1024
40 #define _BUFFER_ORDER 128
41
42 /* DB table */
43 #define CAL_TABLE_SCHEDULE "schedule_table"
44 #define CAL_TABLE_ALARM "alarm_table"
45 #define CAL_TABLE_CALENDAR "calendar_table"
46 #define CAL_TABLE_ATTENDEE "attendee_table"
47 #define CAL_TABLE_TIMEZONE "timezone_table"
48 #define CAL_TABLE_VERSION "version_table"
49 #define CAL_TABLE_DELETED "deleted_table"
50 #define CAL_TABLE_RRULE "rrule_table"
51 #define CAL_TABLE_UTIME_INSTANCE "normal_instance_table"
52 #define CAL_TABLE_LOCALTIME_INSTANCE "allday_instance_table"
53 #define CAL_TABLE_EXTENDED "extended_table"
54
55 /* for event or todo.. */
56 #define CAL_VIEW_TABLE_EVENT "event_view"
57 #define CAL_VIEW_TABLE_TODO "todo_view"
58 #define CAL_VIEW_TABLE_EVENT_BOOK "event_book_view"
59 #define CAL_VIEW_TABLE_TODO_BOOK "todo_book_view"
60 #define CAL_VIEW_TABLE_EVENT_BOOK_ATTENDEE "event_calendar_attendee_view"
61 #define CAL_VIEW_TABLE_UTIME_INSTANCE "utime_instance_view"
62 #define CAL_VIEW_TABLE_LOCALTIME_INSTANCE "localtime_instance_view"
63 #define CAL_VIEW_TABLE_UTIME_INSTANCE_EXTENDED "utime_instance_view_extended"
64 #define CAL_VIEW_TABLE_LOCALTIME_INSTANCE_EXTENDED "localtime_instance_view_extended"
65
66 #define CAL_QUERY_SCHEDULE_A_ALL "A.id, A.type, A.summary, A.description, A.location, A.categories, A.exdate, A.task_status, "\
67                                 "A.priority, A.timezone, A.contact_id, A.busy_status, A.sensitivity, A.uid, A.organizer_name, "\
68                                 "A.organizer_email, A.meeting_status, A.calendar_id, A.original_event_id, A.latitude, A.longitude, "\
69                                 "A.email_id, A.created_time, A.completed_time, A.progress, A.changed_ver, A.created_ver, A.is_deleted, "\
70                                 "A.dtstart_type, A.dtstart_utime, A.dtstart_datetime, A.dtstart_tzid, "\
71                                 "A.dtend_type, A.dtend_utime, A.dtend_datetime, A.dtend_tzid, "\
72                                 "A.last_mod, A.rrule_id, A.recurrence_id, A.rdate, A.has_attendee, A.has_alarm, A.system_type, A.updated, "\
73                                 "A.sync_data1, A.sync_data2, A.sync_data3, A.sync_data4, A.has_exception, A.has_extended, A.freq, A.is_allday "
74
75 typedef int (*cal_db_get_record_cb)(int id, calendar_record_h* out_record);
76 typedef int (*cal_db_insert_record_cb)(calendar_record_h record, int* id);
77 typedef int (*cal_db_update_record_cb)(calendar_record_h record);
78 typedef int (*cal_db_delete_record_cb)(int id);
79 typedef int (*cal_db_replace_record_cb)(calendar_record_h record, int record_id);
80 typedef int (*cal_db_insert_records_cb)(const calendar_list_h in_list, int** ids);
81 typedef int (*cal_db_update_records_cb)(const calendar_list_h in_list);
82 typedef int (*cal_db_delete_records_cb)(int ids[], int count);
83 typedef int (*cal_db_replace_records_cb)(calendar_list_h record_list, int *record_id_array, int count);
84 typedef int (*cal_db_get_all_records_cb)(int offset, int limit, calendar_list_h* out_list);
85 typedef int (*cal_db_get_records_with_query_cb)(calendar_query_h query, int offset, int limit, calendar_list_h* out_list);
86 typedef int (*cal_db_get_count_cb)(int *out_count);
87 typedef int (*cal_db_get_count_with_query_cb)(calendar_query_h query, int *out_count);
88
89 typedef struct {
90         bool is_query_only;
91         cal_db_get_record_cb get_record;
92         cal_db_insert_record_cb insert_record;
93         cal_db_update_record_cb update_record;
94         cal_db_delete_record_cb delete_record;
95         cal_db_replace_record_cb replace_record;
96         cal_db_insert_records_cb insert_records;
97         cal_db_update_records_cb update_records;
98         cal_db_delete_records_cb delete_records;
99         cal_db_replace_records_cb replace_records;
100         cal_db_get_all_records_cb get_all_records;
101         cal_db_get_records_with_query_cb get_records_with_query;
102         cal_db_get_count_cb get_count;
103         cal_db_get_count_with_query_cb get_count_with_query;
104 } cal_db_plugin_cb_s;
105
106 void cal_db_initialize_view_table(void);
107 int cal_db_insert_record(calendar_record_h record, int* id);
108 int cal_db_update_record(calendar_record_h record);
109 int cal_db_delete_record(const char* view_uri, int id);
110 int cal_db_replace_record(calendar_record_h record, int record_id);
111 int cal_db_get_all_records(const char* view_uri, int offset, int limit, calendar_list_h* out_list);
112 int cal_db_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list);
113 int cal_db_clean_after_sync(int calendar_book_id,  int calendar_db_version);
114 int cal_db_get_record(const char* view_uri, int id, calendar_record_h* out_record);
115 int cal_db_get_count(const char* view_uri, int *out_count);
116 int cal_db_get_count_with_query(calendar_query_h query, int *out_count);
117 int cal_db_insert_records(calendar_list_h list, int** ids, int* count);
118 int cal_db_update_records(calendar_list_h list);
119 int cal_db_delete_records(const char* view_uri, int record_id_array[], int count);
120 int cal_db_replace_records(calendar_list_h list, int *ids, int count);
121 int cal_db_insert_vcalendars(const char* vcalendar_stream, int **record_id_array, int *count);
122 int cal_db_replace_vcalendars(const char* vcalendar_stream, int *record_id_array, int count);
123 int cal_db_get_current_version(int* current_version);
124 int cal_db_get_changes_by_version(const char* view_uri, int calendar_book_id, int calendar_db_version, calendar_list_h* record_list, int *current_calendar_db_version);
125 int cal_db_get_changes_exception_by_version(const char* view_uri, int original_event_id, int calendar_db_version, calendar_list_h* record_list);
126
127 int cal_db_append_string(char **dst, const char *src);
128 cal_db_plugin_cb_s* _cal_db_get_plugin(cal_record_type_e type);
129
130 #endif /* __CAL_DB_H__ */