4 * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include "cal_internal.h"
25 #include "cal_typedef.h"
27 #include "cal_record.h"
28 #include "cal_utils.h"
30 static int _cal_record_book_create(calendar_record_h* out_record);
31 static int _cal_record_book_destroy(calendar_record_h record, bool delete_child);
32 static int _cal_record_book_clone(calendar_record_h record, calendar_record_h* out_record);
33 static int _cal_record_book_get_str(calendar_record_h record, unsigned int property_id, char** out_str);
34 static int _cal_record_book_get_str_p(calendar_record_h record, unsigned int property_id, char** out_str);
35 static int _cal_record_book_get_int(calendar_record_h record, unsigned int property_id, int* out_value);
36 static int _cal_record_book_set_str(calendar_record_h record, unsigned int property_id, const char* value);
37 static int _cal_record_book_set_int(calendar_record_h record, unsigned int property_id, int value);
39 cal_record_plugin_cb_s cal_record_book_plugin_cb = {
40 .create = _cal_record_book_create,
41 .destroy = _cal_record_book_destroy,
42 .clone = _cal_record_book_clone,
43 .get_str = _cal_record_book_get_str,
44 .get_str_p = _cal_record_book_get_str_p,
45 .get_int = _cal_record_book_get_int,
49 .set_str = _cal_record_book_set_str,
50 .set_int = _cal_record_book_set_int,
54 .add_child_record = NULL,
55 .remove_child_record = NULL,
56 .get_child_record_count = NULL,
57 .get_child_record_at_p = NULL,
58 .clone_child_record_list = NULL
61 static void _cal_record_book_struct_init(cal_book_s *record)
63 memset(record, 0, sizeof(cal_book_s));
65 record->visibility = true;
66 record->account_id = LOCAL_ACCOUNT_ID;
67 record->sync_event = 1;
70 static int _cal_record_book_create(calendar_record_h* out_record)
72 cal_book_s *temp = NULL;
73 int ret = CALENDAR_ERROR_NONE;
75 temp = calloc(1, sizeof(cal_book_s));
76 RETVM_IF(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
78 _cal_record_book_struct_init(temp);
80 *out_record = (calendar_record_h)temp;
85 static void _cal_record_book_struct_free(cal_book_s *record)
87 CAL_FREE(record->uid);
88 CAL_FREE(record->name);
89 CAL_FREE(record->description);
90 CAL_FREE(record->color);
91 CAL_FREE(record->location);
92 CAL_FREE(record->sync_data1);
93 CAL_FREE(record->sync_data2);
94 CAL_FREE(record->sync_data3);
95 CAL_FREE(record->sync_data4);
99 static int _cal_record_book_destroy(calendar_record_h record, bool delete_child)
101 int ret = CALENDAR_ERROR_NONE;
103 cal_book_s *temp = (cal_book_s*)(record);
105 _cal_record_book_struct_free(temp);
110 static int _cal_record_book_clone(calendar_record_h record, calendar_record_h* out_record)
112 cal_book_s *out_data = NULL;
113 cal_book_s *src_data = NULL;
115 src_data = (cal_book_s*)(record);
117 out_data = calloc(1, sizeof(cal_book_s));
118 RETVM_IF(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
121 CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
123 out_data->index = src_data->index;
124 out_data->store_type = src_data->store_type;
125 out_data->uid = cal_strdup(src_data->uid);
126 out_data->updated = src_data->updated;
127 out_data->name = cal_strdup(src_data->name);
128 out_data->description = cal_strdup(src_data->description);
129 out_data->color = cal_strdup(src_data->color);
130 out_data->location = cal_strdup(src_data->location);
131 out_data->visibility = src_data->visibility;
132 out_data->sync_event = src_data->sync_event;
133 out_data->is_deleted = src_data->is_deleted;
134 out_data->account_id = src_data->account_id;
135 out_data->sync_data1 = cal_strdup(src_data->sync_data1);
136 out_data->sync_data2 = cal_strdup(src_data->sync_data2);
137 out_data->sync_data3 = cal_strdup(src_data->sync_data3);
138 out_data->sync_data4 = cal_strdup(src_data->sync_data4);
139 out_data->mode = src_data->mode;
141 *out_record = (calendar_record_h)out_data;
143 return CALENDAR_ERROR_NONE;
146 static int _cal_record_book_get_str(calendar_record_h record, unsigned int property_id, char** out_str)
148 cal_book_s *cal_rec = (cal_book_s*)(record);
149 switch (property_id) {
150 case CAL_PROPERTY_BOOK_UID:
151 *out_str = cal_strdup(cal_rec->uid);
153 case CAL_PROPERTY_BOOK_NAME:
154 *out_str = cal_strdup(cal_rec->name);
156 case CAL_PROPERTY_BOOK_DESCRIPTION:
157 *out_str = cal_strdup(cal_rec->description);
159 case CAL_PROPERTY_BOOK_COLOR:
160 *out_str = cal_strdup(cal_rec->color);
162 case CAL_PROPERTY_BOOK_LOCATION:
163 *out_str = cal_strdup(cal_rec->location);
165 case CAL_PROPERTY_BOOK_SYNC_DATA1:
166 *out_str = cal_strdup(cal_rec->sync_data1);
168 case CAL_PROPERTY_BOOK_SYNC_DATA2:
169 *out_str = cal_strdup(cal_rec->sync_data2);
171 case CAL_PROPERTY_BOOK_SYNC_DATA3:
172 *out_str = cal_strdup(cal_rec->sync_data3);
174 case CAL_PROPERTY_BOOK_SYNC_DATA4:
175 *out_str = cal_strdup(cal_rec->sync_data4);
178 /* LCOV_EXCL_START */
179 ERR("invalid parameter (property:0x%x)", property_id);
180 return CALENDAR_ERROR_INVALID_PARAMETER;
184 return CALENDAR_ERROR_NONE;
187 static int _cal_record_book_get_str_p(calendar_record_h record, unsigned int property_id, char** out_str)
189 cal_book_s *cal_rec = (cal_book_s*)(record);
190 switch (property_id) {
191 case CAL_PROPERTY_BOOK_UID:
192 *out_str = (cal_rec->uid);
194 case CAL_PROPERTY_BOOK_NAME:
195 *out_str = (cal_rec->name);
197 case CAL_PROPERTY_BOOK_DESCRIPTION:
198 *out_str = (cal_rec->description);
200 case CAL_PROPERTY_BOOK_COLOR:
201 *out_str = (cal_rec->color);
203 case CAL_PROPERTY_BOOK_LOCATION:
204 *out_str = (cal_rec->location);
206 case CAL_PROPERTY_BOOK_SYNC_DATA1:
207 *out_str = (cal_rec->sync_data1);
209 case CAL_PROPERTY_BOOK_SYNC_DATA2:
210 *out_str = (cal_rec->sync_data2);
212 case CAL_PROPERTY_BOOK_SYNC_DATA3:
213 *out_str = (cal_rec->sync_data3);
215 case CAL_PROPERTY_BOOK_SYNC_DATA4:
216 *out_str = (cal_rec->sync_data4);
219 /* LCOV_EXCL_START */
220 ERR("invalid parameter (property:0x%x)", property_id);
221 return CALENDAR_ERROR_INVALID_PARAMETER;
225 return CALENDAR_ERROR_NONE;
228 static int _cal_record_book_get_int(calendar_record_h record, unsigned int property_id, int* out_value)
230 cal_book_s *cal_rec = (cal_book_s*)(record);
231 switch (property_id) {
232 case CAL_PROPERTY_BOOK_ID:
233 *out_value = (cal_rec->index);
235 case CAL_PROPERTY_BOOK_VISIBILITY:
236 *out_value = (cal_rec->visibility);
238 case CAL_PROPERTY_BOOK_ACCOUNT_ID:
239 *out_value = (cal_rec->account_id);
241 case CAL_PROPERTY_BOOK_STORE_TYPE:
242 *out_value = (cal_rec->store_type);
244 case CAL_PROPERTY_BOOK_SYNC_EVENT:
245 *out_value = (cal_rec->sync_event);
247 case CAL_PROPERTY_BOOK_MODE:
248 *out_value = (cal_rec->mode);
251 /* LCOV_EXCL_START */
252 ERR("invalid parameter (property:0x%x)", property_id);
253 return CALENDAR_ERROR_INVALID_PARAMETER;
257 return CALENDAR_ERROR_NONE;
260 static int _cal_record_book_set_str(calendar_record_h record, unsigned int property_id, const char* value)
262 cal_book_s *cal_rec = (cal_book_s*)(record);
263 switch (property_id) {
264 case CAL_PROPERTY_BOOK_UID:
265 CAL_FREE(cal_rec->uid);
266 cal_rec->uid = cal_strdup(value);
268 case CAL_PROPERTY_BOOK_NAME:
269 CAL_FREE(cal_rec->name);
270 cal_rec->name = cal_strdup(value);
272 case CAL_PROPERTY_BOOK_DESCRIPTION:
273 CAL_FREE(cal_rec->description);
274 cal_rec->description = cal_strdup(value);
276 case CAL_PROPERTY_BOOK_COLOR:
277 CAL_FREE(cal_rec->color);
278 cal_rec->color = cal_strdup(value);
280 case CAL_PROPERTY_BOOK_LOCATION:
281 CAL_FREE(cal_rec->location);
282 cal_rec->location = cal_strdup(value);
284 case CAL_PROPERTY_BOOK_SYNC_DATA1:
285 CAL_FREE(cal_rec->sync_data1);
286 cal_rec->sync_data1 = cal_strdup(value);
288 case CAL_PROPERTY_BOOK_SYNC_DATA2:
289 CAL_FREE(cal_rec->sync_data2);
290 cal_rec->sync_data2 = cal_strdup(value);
292 case CAL_PROPERTY_BOOK_SYNC_DATA3:
293 CAL_FREE(cal_rec->sync_data3);
294 cal_rec->sync_data3 = cal_strdup(value);
296 case CAL_PROPERTY_BOOK_SYNC_DATA4:
297 CAL_FREE(cal_rec->sync_data4);
298 cal_rec->sync_data4 = cal_strdup(value);
301 /* LCOV_EXCL_START */
302 ERR("invalid parameter (property:0x%x)", property_id);
303 return CALENDAR_ERROR_INVALID_PARAMETER;
307 return CALENDAR_ERROR_NONE;
310 static int _cal_record_book_set_int(calendar_record_h record, unsigned int property_id, int value)
312 cal_book_s *cal_rec = (cal_book_s*)(record);
313 switch (property_id) {
314 case CAL_PROPERTY_BOOK_ID:
315 (cal_rec->index) = value;
317 case CAL_PROPERTY_BOOK_VISIBILITY:
318 (cal_rec->visibility) = value;
320 case CAL_PROPERTY_BOOK_ACCOUNT_ID:
321 RETVM_IF(0 < cal_rec->index, CALENDAR_ERROR_INVALID_PARAMETER, "property_id(%d) is a write-once value (calendar)", property_id);
322 (cal_rec->account_id) = value;
324 case CAL_PROPERTY_BOOK_STORE_TYPE:
326 case CALENDAR_BOOK_TYPE_NONE:
327 case CALENDAR_BOOK_TYPE_EVENT:
328 case CALENDAR_BOOK_TYPE_TODO:
329 (cal_rec->store_type) = value;
332 /* LCOV_EXCL_START */
333 ERR("Invalid parameter : store type is invalid value (%d)", value);
334 return CALENDAR_ERROR_INVALID_PARAMETER;
338 case CAL_PROPERTY_BOOK_SYNC_EVENT:
340 case CALENDAR_BOOK_SYNC_EVENT_FOR_ME:
341 case CALENDAR_BOOK_SYNC_EVENT_FOR_EVERY_AND_REMAIN:
342 case CALENDAR_BOOK_SYNC_EVENT_FOR_EVERY_AND_DELETE:
343 (cal_rec->sync_event) = value;
346 /* LCOV_EXCL_START */
347 ERR("Invalid parameter : sync event is invalid value (%d)", value);
348 return CALENDAR_ERROR_INVALID_PARAMETER;
352 case CAL_PROPERTY_BOOK_MODE:
353 RETVM_IF(value != CALENDAR_BOOK_MODE_NONE && value != CALENDAR_BOOK_MODE_RECORD_READONLY,
354 CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter : mode type is invalid value (%d)", value);
355 (cal_rec->mode) = value;
358 /* LCOV_EXCL_START */
359 ERR("invalid parameter (property:0x%x)", property_id);
360 return CALENDAR_ERROR_INVALID_PARAMETER;
364 return CALENDAR_ERROR_NONE;