4 * Copyright (c) 2010 - 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.
21 #include "ctsvc_internal.h"
22 #include "ctsvc_record.h"
23 #include "ctsvc_view.h"
25 static int __ctsvc_person_create(contacts_record_h *out_record);
26 static int __ctsvc_person_destroy(contacts_record_h record, bool delete_child);
27 static int __ctsvc_person_clone(contacts_record_h record, contacts_record_h *out_record);
28 static int __ctsvc_person_get_int(contacts_record_h record, unsigned int property_id, int *out);
29 static int __ctsvc_person_get_str_p(contacts_record_h record, unsigned int property_id, char **out_str);
30 static int __ctsvc_person_get_str(contacts_record_h record, unsigned int property_id, char **out_str);
31 static int __ctsvc_person_get_bool(contacts_record_h record, unsigned int property_id, bool *value);
32 static int __ctsvc_person_get_double(contacts_record_h record, unsigned int property_id, double *out);
33 static int __ctsvc_person_set_int(contacts_record_h record, unsigned int property_id, int value, bool *is_dirty);
34 static int __ctsvc_person_set_str(contacts_record_h record, unsigned int property_id, const char *str, bool *is_dirty);
35 static int __ctsvc_person_set_bool(contacts_record_h record, unsigned int property_id, bool value, bool *is_dirty);
37 ctsvc_record_plugin_cb_s person_plugin_cbs = {
38 .create = __ctsvc_person_create,
39 .destroy = __ctsvc_person_destroy,
40 .clone = __ctsvc_person_clone,
41 .get_str = __ctsvc_person_get_str,
42 .get_str_p = __ctsvc_person_get_str_p,
43 .get_int = __ctsvc_person_get_int,
44 .get_bool = __ctsvc_person_get_bool,
46 .get_double = __ctsvc_person_get_double,
47 .set_str = __ctsvc_person_set_str,
48 .set_int = __ctsvc_person_set_int,
49 .set_bool = __ctsvc_person_set_bool,
52 .add_child_record = NULL,
53 .remove_child_record = NULL,
54 .get_child_record_count = NULL,
55 .get_child_record_at_p = NULL,
56 .clone_child_record_list = NULL,
59 static int __ctsvc_person_create(contacts_record_h *out_record)
61 ctsvc_person_s *person;
62 person = calloc(1, sizeof(ctsvc_person_s));
63 RETVM_IF(NULL == person, CONTACTS_ERROR_OUT_OF_MEMORY, "calloc() Fail");
65 *out_record = (contacts_record_h)person;
66 return CONTACTS_ERROR_NONE;
69 static int __ctsvc_person_destroy(contacts_record_h record, bool delete_child)
71 ctsvc_person_s *person = (ctsvc_person_s*)record;
73 /* help to find double-destroy bug (refer to the contacts_record_destroy) */
74 person->base.plugin_cbs = NULL;
76 free(person->base.properties_flags);
77 free(person->display_name);
78 free(person->display_name_index);
79 free(person->ringtone_path);
80 free(person->vibration);
81 free(person->message_alert);
82 free(person->image_thumbnail_path);
84 free(person->addressbook_ids);
85 free(person->snippet_string);
88 return CONTACTS_ERROR_NONE;
91 static int __ctsvc_person_clone(contacts_record_h record, contacts_record_h *out_record)
93 ctsvc_person_s *out_data = NULL;
94 ctsvc_person_s *src_data = NULL;
96 src_data = (ctsvc_person_s*)record;
97 out_data = calloc(1, sizeof(ctsvc_person_s));
98 RETVM_IF(NULL == out_data, CONTACTS_ERROR_OUT_OF_MEMORY, "calloc() Fail");
100 out_data->is_favorite = src_data->is_favorite;
101 out_data->has_phonenumber = src_data->has_phonenumber;
102 out_data->has_email = src_data->has_email;
103 out_data->person_id = src_data->person_id;
104 out_data->name_contact_id = src_data->name_contact_id;
105 out_data->link_count = src_data->link_count;
106 out_data->addressbook_ids = SAFE_STRDUP(src_data->addressbook_ids);
107 out_data->display_name = SAFE_STRDUP(src_data->display_name);
108 out_data->display_name_index = SAFE_STRDUP(src_data->display_name_index);
109 out_data->image_thumbnail_path = SAFE_STRDUP(src_data->image_thumbnail_path);
110 out_data->ringtone_path = SAFE_STRDUP(src_data->ringtone_path);
111 out_data->vibration = SAFE_STRDUP(src_data->vibration);
112 out_data->message_alert = SAFE_STRDUP(src_data->message_alert);
113 out_data->status = SAFE_STRDUP(src_data->status);
114 out_data->snippet_type = src_data->snippet_type;
115 out_data->snippet_string = SAFE_STRDUP(src_data->snippet_string);
117 int ret = ctsvc_record_copy_base(&(out_data->base), &(src_data->base));
118 if (CONTACTS_ERROR_NONE != ret) {
119 ERR("ctsvc_record_copy_base() Fail");
120 __ctsvc_person_destroy((contacts_record_h)out_data, true);
124 *out_record = (contacts_record_h)out_data;
125 return CONTACTS_ERROR_NONE;
128 static int __ctsvc_person_get_int(contacts_record_h record, unsigned int property_id,
131 ctsvc_person_s *person = (ctsvc_person_s*)record;
132 switch (property_id) {
133 case CTSVC_PROPERTY_PERSON_ID:
134 *out = person->person_id;
136 case CTSVC_PROPERTY_PERSON_DISPLAY_CONTACT_ID:
137 *out = person->name_contact_id;
139 case CTSVC_PROPERTY_PERSON_LINK_COUNT:
140 *out = person->link_count;
142 case CTSVC_PROPERTY_PERSON_SNIPPET_TYPE:
143 *out = person->snippet_type;
146 ERR("This field(%d) is not supported in value(person)", property_id);
147 return CONTACTS_ERROR_INVALID_PARAMETER;
149 return CONTACTS_ERROR_NONE;
152 static int __ctsvc_person_get_double(contacts_record_h record, unsigned int property_id,
155 ctsvc_person_s *person = (ctsvc_person_s*)record;
156 switch (property_id) {
157 case CTSVC_PROPERTY_PERSON_FAVORITE_PRIORITY:
158 *out = person->favorite_prio;
162 ERR("This field(%d) is not supported in value(person)", property_id);
163 return CONTACTS_ERROR_INVALID_PARAMETER;
165 return CONTACTS_ERROR_NONE;
168 static int __ctsvc_person_get_str_real(contacts_record_h record, unsigned int property_id,
169 char **out_str, bool copy)
171 ctsvc_person_s *person = (ctsvc_person_s*)record;
172 switch (property_id) {
173 case CTSVC_PROPERTY_PERSON_DISPLAY_NAME:
174 *out_str = GET_STR(copy, person->display_name);
176 case CTSVC_PROPERTY_PERSON_RINGTONE:
177 *out_str = GET_STR(copy, person->ringtone_path);
179 case CTSVC_PROPERTY_PERSON_IMAGE_THUMBNAIL:
180 *out_str = GET_STR(copy, person->image_thumbnail_path);
182 case CTSVC_PROPERTY_PERSON_VIBRATION:
183 *out_str = GET_STR(copy, person->vibration);
185 case CTSVC_PROPERTY_PERSON_MESSAGE_ALERT:
186 *out_str = GET_STR(copy, person->message_alert);
188 case CTSVC_PROPERTY_PERSON_STATUS:
189 *out_str = GET_STR(copy, person->status);
191 case CTSVC_PROPERTY_PERSON_DISPLAY_NAME_INDEX:
192 *out_str = GET_STR(copy, person->display_name_index);
194 case CTSVC_PROPERTY_PERSON_ADDRESSBOOK_IDS:
195 *out_str = GET_STR(copy, person->addressbook_ids);
197 case CTSVC_PROPERTY_PERSON_SNIPPET_STRING:
198 *out_str = GET_STR(copy, person->snippet_string);
201 ERR("This field(%d) is not supported in value(person)", property_id);
202 return CONTACTS_ERROR_INVALID_PARAMETER;
204 return CONTACTS_ERROR_NONE;
207 static int __ctsvc_person_get_str_p(contacts_record_h record, unsigned int property_id,
210 return __ctsvc_person_get_str_real(record, property_id, out_str, false);
213 static int __ctsvc_person_get_str(contacts_record_h record, unsigned int property_id,
216 return __ctsvc_person_get_str_real(record, property_id, out_str, true);
219 static int __ctsvc_person_get_bool(contacts_record_h record, unsigned int property_id,
222 ctsvc_person_s *person = (ctsvc_person_s*)record;
223 switch (property_id) {
224 case CTSVC_PROPERTY_PERSON_IS_FAVORITE:
225 *value = person->is_favorite;
227 case CTSVC_PROPERTY_PERSON_HAS_PHONENUMBER:
228 *value = person->has_phonenumber;
230 case CTSVC_PROPERTY_PERSON_HAS_EMAIL:
231 *value = person->has_email;
234 ERR("This field(%d) is not supported in value(company)", property_id);
235 return CONTACTS_ERROR_INVALID_PARAMETER;
237 return CONTACTS_ERROR_NONE;
240 static int __ctsvc_person_set_int(contacts_record_h record, unsigned int property_id,
241 int value, bool *is_dirty)
243 ctsvc_person_s *person = (ctsvc_person_s*)record;
245 switch (property_id) {
246 case CTSVC_PROPERTY_PERSON_DISPLAY_CONTACT_ID:
247 CHECK_DIRTY_VAL(person->name_contact_id, value, is_dirty);
248 person->name_contact_id = value;
250 case CTSVC_PROPERTY_PERSON_ID:
251 CHECK_DIRTY_VAL(person->person_id, value, is_dirty);
252 person->person_id = value;
254 case CTSVC_PROPERTY_PERSON_LINK_COUNT:
255 CHECK_DIRTY_VAL(person->link_count, value, is_dirty);
256 person->link_count = value;
258 case CTSVC_PROPERTY_PERSON_SNIPPET_TYPE:
259 CHECK_DIRTY_VAL(person->snippet_type, value, is_dirty);
260 person->snippet_type = value;
263 ERR("This field(0x%0x) is not supported in value(person)", property_id);
264 return CONTACTS_ERROR_INVALID_PARAMETER;
266 return CONTACTS_ERROR_NONE;
269 static int __ctsvc_person_set_str(contacts_record_h record, unsigned int property_id,
270 const char *str, bool *is_dirty)
272 ctsvc_person_s *person = (ctsvc_person_s*)record;
274 switch (property_id) {
275 case CTSVC_PROPERTY_PERSON_DISPLAY_NAME:
276 CHECK_DIRTY_STR(person->display_name, str, is_dirty);
277 FREEandSTRDUP(person->display_name, str);
279 case CTSVC_PROPERTY_PERSON_DISPLAY_NAME_INDEX:
280 CHECK_DIRTY_STR(person->display_name_index, str, is_dirty);
281 FREEandSTRDUP(person->display_name_index, str);
283 case CTSVC_PROPERTY_PERSON_IMAGE_THUMBNAIL:
284 CHECK_DIRTY_STR(person->image_thumbnail_path, str, is_dirty);
285 FREEandSTRDUP(person->image_thumbnail_path, str);
287 case CTSVC_PROPERTY_PERSON_RINGTONE:
288 CHECK_DIRTY_STR(person->ringtone_path, str, is_dirty);
289 FREEandSTRDUP(person->ringtone_path, str);
291 case CTSVC_PROPERTY_PERSON_VIBRATION:
292 CHECK_DIRTY_STR(person->vibration, str, is_dirty);
293 FREEandSTRDUP(person->vibration, str);
295 case CTSVC_PROPERTY_PERSON_MESSAGE_ALERT:
296 CHECK_DIRTY_STR(person->message_alert, str, is_dirty);
297 FREEandSTRDUP(person->message_alert, str);
299 case CTSVC_PROPERTY_PERSON_SNIPPET_STRING:
300 CHECK_DIRTY_STR(person->snippet_string, str, is_dirty);
301 FREEandSTRDUP(person->snippet_string, str);
304 ERR("This field(%d) is not supported in value(person)", property_id);
305 return CONTACTS_ERROR_INVALID_PARAMETER;
307 return CONTACTS_ERROR_NONE;
310 static int __ctsvc_person_set_bool(contacts_record_h record, unsigned int property_id,
311 bool value, bool *is_dirty)
313 ctsvc_person_s *person = (ctsvc_person_s*)record;
315 switch (property_id) {
316 case CTSVC_PROPERTY_PERSON_IS_FAVORITE:
317 CHECK_DIRTY_VAL(person->is_favorite, value, is_dirty);
318 if (person->is_favorite != value)
319 person->is_favorite = value;
322 ERR("This field(%d) is not supported in value(person)", property_id);
323 return CONTACTS_ERROR_INVALID_PARAMETER;
325 return CONTACTS_ERROR_NONE;