revise packaging
[platform/core/pim/contacts-service.git] / common / ctsvc_record_my_profile.c
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 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
20 #include "contacts.h"
21 #include "ctsvc_internal.h"
22 #include "ctsvc_list.h"
23 #include "ctsvc_record.h"
24 #include "ctsvc_view.h"
25
26 static int __ctsvc_my_profile_create(contacts_record_h *out_record);
27 static int __ctsvc_my_profile_destroy(contacts_record_h record, bool delete_child);
28 static int __ctsvc_my_profile_clone(contacts_record_h record, contacts_record_h *out_record);
29 static int __ctsvc_my_profile_get_int(contacts_record_h record, unsigned int property_id, int *out);
30 static int __ctsvc_my_profile_get_str(contacts_record_h record, unsigned int property_id, char **out_str);
31 static int __ctsvc_my_profile_get_str_p(contacts_record_h record, unsigned int property_id, char **out_str);
32 static int __ctsvc_my_profile_set_int(contacts_record_h record, unsigned int property_id, int value, bool *is_dirty);
33 static int __ctsvc_my_profile_set_str(contacts_record_h record, unsigned int property_id, const char *str, bool *is_dirty);
34 static int __ctsvc_my_profile_clone_child_record_list(contacts_record_h record, unsigned int property_id, contacts_list_h *out_list);
35 static int __ctsvc_my_profile_get_child_record_at_p(contacts_record_h record, unsigned int property_id, int index, contacts_record_h *out_record);
36 static int __ctsvc_my_profile_get_child_record_count(contacts_record_h record, unsigned int property_id, int *count);
37 static int __ctsvc_my_profile_add_child_record(contacts_record_h record, unsigned int property_id, contacts_record_h child_record);
38 static int __ctsvc_my_profile_remove_child_record(contacts_record_h record, unsigned int property_id, contacts_record_h child_record);
39
40 ctsvc_record_plugin_cb_s my_profile_plugin_cbs = {
41         .create = __ctsvc_my_profile_create,
42         .destroy = __ctsvc_my_profile_destroy,
43         .clone = __ctsvc_my_profile_clone,
44         .get_str = __ctsvc_my_profile_get_str,
45         .get_str_p = __ctsvc_my_profile_get_str_p,
46         .get_int = __ctsvc_my_profile_get_int,
47         .get_bool = NULL,
48         .get_lli = NULL,
49         .get_double = NULL,
50         .set_str = __ctsvc_my_profile_set_str,
51         .set_int = __ctsvc_my_profile_set_int,
52         .set_bool = NULL,
53         .set_lli = NULL,
54         .set_double = NULL,
55         .add_child_record = __ctsvc_my_profile_add_child_record,
56         .remove_child_record = __ctsvc_my_profile_remove_child_record,
57         .get_child_record_count = __ctsvc_my_profile_get_child_record_count,
58         .get_child_record_at_p = __ctsvc_my_profile_get_child_record_at_p,
59         .clone_child_record_list = __ctsvc_my_profile_clone_child_record_list,
60 };
61
62 static int __ctsvc_my_profile_create(contacts_record_h *out_record)
63 {
64         ctsvc_my_profile_s *my_profile;
65
66         my_profile = calloc(1, sizeof(ctsvc_my_profile_s));
67         RETVM_IF(NULL == my_profile, CONTACTS_ERROR_OUT_OF_MEMORY,
68                         "calloc() Fail");
69
70         do {
71                 my_profile->name = calloc(1, sizeof(ctsvc_list_s));
72                 if (NULL == my_profile->name)
73                         break;
74                 my_profile->name->l_type = CTSVC_RECORD_NAME;
75
76                 my_profile->company = calloc(1, sizeof(ctsvc_list_s));
77                 if (NULL == my_profile->company)
78                         break;
79                 my_profile->company->l_type = CTSVC_RECORD_COMPANY;
80
81                 my_profile->note = calloc(1, sizeof(ctsvc_list_s));
82                 if (NULL == my_profile->note)
83                         break;
84                 my_profile->note->l_type = CTSVC_RECORD_NOTE;
85
86                 my_profile->numbers = calloc(1, sizeof(ctsvc_list_s));
87                 if (NULL == my_profile->numbers)
88                         break;
89                 my_profile->numbers->l_type = CTSVC_RECORD_NUMBER;
90
91                 my_profile->emails = calloc(1, sizeof(ctsvc_list_s));
92                 if (NULL == my_profile->emails)
93                         break;
94                 my_profile->emails->l_type = CTSVC_RECORD_EMAIL;
95
96                 my_profile->events = calloc(1, sizeof(ctsvc_list_s));
97                 if (NULL == my_profile->events)
98                         break;
99                 my_profile->events->l_type = CTSVC_RECORD_EVENT;
100
101                 my_profile->messengers = calloc(1, sizeof(ctsvc_list_s));
102                 if (NULL == my_profile->messengers)
103                         break;
104                 my_profile->messengers->l_type = CTSVC_RECORD_MESSENGER;
105
106                 my_profile->postal_addrs = calloc(1, sizeof(ctsvc_list_s));
107                 if (NULL == my_profile->postal_addrs)
108                         break;
109                 my_profile->postal_addrs->l_type = CTSVC_RECORD_ADDRESS;
110
111                 my_profile->urls = calloc(1, sizeof(ctsvc_list_s));
112                 if (NULL == my_profile->urls)
113                         break;
114                 my_profile->urls->l_type = CTSVC_RECORD_URL;
115
116                 my_profile->nicknames = calloc(1, sizeof(ctsvc_list_s));
117                 if (NULL == my_profile->nicknames)
118                         break;
119                 my_profile->nicknames->l_type = CTSVC_RECORD_NICKNAME;
120
121                 my_profile->profiles = calloc(1, sizeof(ctsvc_list_s));
122                 if (NULL == my_profile->profiles)
123                         break;
124                 my_profile->profiles->l_type = CTSVC_RECORD_PROFILE;
125
126                 my_profile->relationships = calloc(1, sizeof(ctsvc_list_s));
127                 if (NULL == my_profile->relationships)
128                         break;
129                 my_profile->relationships->l_type = CTSVC_RECORD_RELATIONSHIP;
130
131                 my_profile->images = calloc(1, sizeof(ctsvc_list_s));
132                 if (NULL == my_profile->images)
133                         break;
134                 my_profile->images->l_type = CTSVC_RECORD_IMAGE;
135
136                 my_profile->extensions = calloc(1, sizeof(ctsvc_list_s));
137                 if (NULL == my_profile->extensions)
138                         break;
139                 my_profile->extensions->l_type = CTSVC_RECORD_EXTENSION;
140
141                 my_profile->sips = calloc(1, sizeof(ctsvc_list_s));
142                 if (NULL == my_profile->sips)
143                         break;
144                 my_profile->sips->l_type = CTSVC_RECORD_SIP;
145
146                 *out_record = (contacts_record_h)my_profile;
147                 return CONTACTS_ERROR_NONE;
148         } while (0);
149
150         ERR("calloc() Fail");
151         free(my_profile->extensions);
152         free(my_profile->images);
153         free(my_profile->relationships);
154         free(my_profile->profiles);
155         free(my_profile->nicknames);
156         free(my_profile->urls);
157         free(my_profile->postal_addrs);
158         free(my_profile->messengers);
159         free(my_profile->events);
160         free(my_profile->emails);
161         free(my_profile->numbers);
162         free(my_profile->note);
163         free(my_profile->company);
164         free(my_profile->name);
165         free(my_profile->sips);
166         free(my_profile);
167         return CONTACTS_ERROR_OUT_OF_MEMORY;
168 }
169
170 static int __ctsvc_my_profile_destroy(contacts_record_h record, bool delete_child)
171 {
172         ctsvc_my_profile_s *my_profile = (ctsvc_my_profile_s*)record;
173
174         /* help to find double destroy bug (refer to the contacts_record_destroy) */
175         my_profile->base.plugin_cbs = NULL;
176         free(my_profile->base.properties_flags);
177
178         free(my_profile->display_name);
179         free(my_profile->reverse_display_name);
180         free(my_profile->uid);
181         free(my_profile->image_thumbnail_path);
182
183         contacts_list_destroy((contacts_list_h)my_profile->name, delete_child);
184
185         contacts_list_destroy((contacts_list_h)my_profile->company, delete_child);
186
187         contacts_list_destroy((contacts_list_h)my_profile->note, delete_child);
188
189         contacts_list_destroy((contacts_list_h)my_profile->numbers, delete_child);
190
191         contacts_list_destroy((contacts_list_h)my_profile->emails, delete_child);
192
193         contacts_list_destroy((contacts_list_h)my_profile->events, delete_child);
194
195         contacts_list_destroy((contacts_list_h)my_profile->messengers, delete_child);
196
197         contacts_list_destroy((contacts_list_h)my_profile->postal_addrs, delete_child);
198
199         contacts_list_destroy((contacts_list_h)my_profile->urls, delete_child);
200
201         contacts_list_destroy((contacts_list_h)my_profile->nicknames, delete_child);
202
203         contacts_list_destroy((contacts_list_h)my_profile->profiles, delete_child);
204
205         contacts_list_destroy((contacts_list_h)my_profile->relationships, delete_child);
206
207         contacts_list_destroy((contacts_list_h)my_profile->images, delete_child);
208
209         contacts_list_destroy((contacts_list_h)my_profile->extensions, delete_child);
210
211         contacts_list_destroy((contacts_list_h)my_profile->sips, delete_child);
212
213         free(my_profile);
214
215         return CONTACTS_ERROR_NONE;
216 }
217
218 static int __ctsvc_my_profile_get_int(contacts_record_h record, unsigned int property_id, int *out)
219 {
220         ctsvc_my_profile_s *my_profile = (ctsvc_my_profile_s*)record;
221
222         switch (property_id) {
223         case CTSVC_PROPERTY_MY_PROFILE_ID:
224                 *out = my_profile->id;
225                 break;
226         case CTSVC_PROPERTY_MY_PROFILE_ADDRESSBOOK_ID:
227                 *out = my_profile->addressbook_id;
228                 break;
229         case CTSVC_PROPERTY_MY_PROFILE_CHANGED_TIME:
230                 *out = my_profile->changed_time;
231                 break;
232         default:
233                 ERR("property_id(%d) is not supported in value(my_profile)", property_id);
234                 return CONTACTS_ERROR_INVALID_PARAMETER;
235         }
236         return CONTACTS_ERROR_NONE;
237 }
238
239 static int __ctsvc_my_profile_set_int(contacts_record_h record, unsigned int property_id, int value, bool *is_dirty)
240 {
241         ctsvc_my_profile_s *my_profile = (ctsvc_my_profile_s*)record;
242
243         switch (property_id) {
244         case CTSVC_PROPERTY_MY_PROFILE_ID:
245                 CHECK_DIRTY_VAL(my_profile->id, value, is_dirty);
246                 my_profile->id = value;
247                 break;
248         case CTSVC_PROPERTY_MY_PROFILE_CHANGED_TIME:
249                 CHECK_DIRTY_VAL(my_profile->changed_time, value, is_dirty);
250                 my_profile->changed_time = value;
251                 break;
252         case CTSVC_PROPERTY_MY_PROFILE_ADDRESSBOOK_ID:
253                 RETVM_IF(0 < my_profile->id, CONTACTS_ERROR_INVALID_PARAMETER,
254                                 "property_id(%d) is a read-only value (my_profile)", property_id);
255                 CHECK_DIRTY_VAL(my_profile->addressbook_id, value, is_dirty);
256                 my_profile->addressbook_id = value;
257                 break;
258         default:
259                 ERR("property_id(%d) is not supported in valuecontact)", property_id);
260                 return CONTACTS_ERROR_INVALID_PARAMETER;
261         }
262         return CONTACTS_ERROR_NONE;
263 }
264
265 static int __ctsvc_my_profile_get_str_real(contacts_record_h record,
266                 unsigned int property_id, char **out_str, bool copy)
267 {
268         ctsvc_my_profile_s *my_profile = (ctsvc_my_profile_s*)record;
269         switch (property_id) {
270         case CTSVC_PROPERTY_MY_PROFILE_DISPLAY_NAME:
271                 *out_str = GET_STR(copy, my_profile->display_name);
272                 break;
273         case CTSVC_PROPERTY_MY_PROFILE_IMAGE_THUMBNAIL:
274                 *out_str = GET_STR(copy, my_profile->image_thumbnail_path);
275                 break;
276         case CTSVC_PROPERTY_MY_PROFILE_UID:
277                 *out_str = GET_STR(copy, my_profile->uid);
278                 break;
279         default:
280                 ERR("property_id(%d) is not supported in value(my_profile)", property_id);
281                 return CONTACTS_ERROR_INVALID_PARAMETER;
282         }
283         return CONTACTS_ERROR_NONE;
284 }
285
286 static int __ctsvc_my_profile_get_str_p(contacts_record_h record,
287                 unsigned int property_id, char **out_str)
288 {
289         return __ctsvc_my_profile_get_str_real(record, property_id, out_str, false);
290 }
291
292 static int __ctsvc_my_profile_get_str(contacts_record_h record, unsigned int property_id,
293                 char **out_str)
294 {
295         return __ctsvc_my_profile_get_str_real(record, property_id, out_str, true);
296 }
297
298 static int __ctsvc_my_profile_get_record_list_p(contacts_record_h record,
299                 unsigned int property_id, contacts_list_h *list)
300 {
301         ctsvc_my_profile_s *contact = (ctsvc_my_profile_s*)record;
302
303         switch (property_id) {
304         case CTSVC_PROPERTY_MY_PROFILE_NAME:
305                 *list = (contacts_list_h)contact->name;
306                 break;
307         case CTSVC_PROPERTY_MY_PROFILE_COMPANY:
308                 *list = (contacts_list_h)contact->company;
309                 break;
310         case CTSVC_PROPERTY_MY_PROFILE_NOTE:
311                 *list = (contacts_list_h)contact->note;
312                 break;
313         case CTSVC_PROPERTY_MY_PROFILE_NUMBER:
314                 *list = (contacts_list_h)contact->numbers;
315                 break;
316         case CTSVC_PROPERTY_MY_PROFILE_EMAIL:
317                 *list = (contacts_list_h)contact->emails;
318                 break;
319         case CTSVC_PROPERTY_MY_PROFILE_EVENT:
320                 *list = (contacts_list_h)contact->events;
321                 break;
322         case CTSVC_PROPERTY_MY_PROFILE_MESSENGER:
323                 *list = (contacts_list_h)contact->messengers;
324                 break;
325         case CTSVC_PROPERTY_MY_PROFILE_ADDRESS:
326                 *list = (contacts_list_h)contact->postal_addrs;
327                 break;
328         case CTSVC_PROPERTY_MY_PROFILE_URL:
329                 *list = (contacts_list_h)contact->urls;
330                 break;
331         case CTSVC_PROPERTY_MY_PROFILE_NICKNAME:
332                 *list = (contacts_list_h)contact->nicknames;
333                 break;
334         case CTSVC_PROPERTY_MY_PROFILE_PROFILE:
335                 *list = (contacts_list_h)contact->profiles;
336                 break;
337         case CTSVC_PROPERTY_MY_PROFILE_RELATIONSHIP:
338                 *list = (contacts_list_h)contact->relationships;
339                 break;
340         case CTSVC_PROPERTY_MY_PROFILE_IMAGE:
341                 *list = (contacts_list_h)contact->images;
342                 break;
343         case CTSVC_PROPERTY_MY_PROFILE_EXTENSION:
344                 *list = (contacts_list_h)contact->extensions;
345                 break;
346         case CTSVC_PROPERTY_MY_PROFILE_SIP:
347                 *list = (contacts_list_h)contact->sips;
348                 break;
349         default:
350                 ERR("property_id(%d) is not supported in value(contact)", property_id);
351                 return CONTACTS_ERROR_INVALID_PARAMETER;
352         }
353         return CONTACTS_ERROR_NONE;
354 }
355
356 static int __ctsvc_my_profile_get_child_record_count(contacts_record_h record,
357                 unsigned int property_id, int *count)
358 {
359         int ret;
360         contacts_list_h list = NULL;
361
362         *count = 0;
363         ret = __ctsvc_my_profile_get_record_list_p(record, property_id, &list);
364         if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
365                 return ret;
366
367         if (list)
368                 contacts_list_get_count(list, count);
369
370         return CONTACTS_ERROR_NONE;
371 }
372
373 static int __ctsvc_my_profile_get_child_record_at_p(contacts_record_h record,
374                 unsigned int property_id, int index, contacts_record_h *out_record)
375 {
376         int ret;
377         int count;
378         contacts_list_h list = NULL;
379
380         ret = __ctsvc_my_profile_get_record_list_p(record, property_id, &list);
381         if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
382                 return ret;
383
384         contacts_list_get_count(list, &count);
385         if (count < index) {
386                 ERR("The index(%d) is greather than total length(%d)", index, count);
387                 *out_record = NULL;
388                 return CONTACTS_ERROR_NO_DATA;
389         } else {
390                 return ctsvc_list_get_nth_record_p(list, index, out_record);
391         }
392 }
393
394 static int __ctsvc_my_profile_clone_child_record_list(contacts_record_h record,
395                 unsigned int property_id, contacts_list_h *out_list)
396 {
397         int ret;
398         int count;
399         contacts_list_h list = NULL;
400
401         ret = __ctsvc_my_profile_get_record_list_p(record, property_id, &list);
402         if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
403                 return ret;
404
405         contacts_list_get_count(list, &count);
406         if (count <= 0) {
407                 *out_list = NULL;
408                 return CONTACTS_ERROR_NO_DATA;
409         }
410         ctsvc_list_clone(list, out_list);
411
412         return CONTACTS_ERROR_NONE;
413 }
414
415 static int __ctsvc_my_profile_reset_child_record_id(contacts_record_h child_record)
416 {
417         ctsvc_record_s *record = (ctsvc_record_s*)child_record;
418
419         switch (record->r_type) {
420         case CTSVC_RECORD_NAME:
421                 ((ctsvc_name_s*)record)->id = 0;
422                 break;
423         case CTSVC_RECORD_COMPANY:
424                 ((ctsvc_company_s*)record)->id = 0;
425                 break;
426         case CTSVC_RECORD_NOTE:
427                 ((ctsvc_note_s*)record)->id = 0;
428                 break;
429         case CTSVC_RECORD_NUMBER:
430                 ((ctsvc_number_s*)record)->id = 0;
431                 break;
432         case CTSVC_RECORD_EMAIL:
433                 ((ctsvc_email_s*)record)->id = 0;
434                 break;
435         case CTSVC_RECORD_URL:
436                 ((ctsvc_url_s*)record)->id = 0;
437                 break;
438         case CTSVC_RECORD_EVENT:
439                 ((ctsvc_event_s*)record)->id = 0;
440                 break;
441         case CTSVC_RECORD_NICKNAME:
442                 ((ctsvc_nickname_s*)record)->id = 0;
443                 break;
444         case CTSVC_RECORD_ADDRESS:
445                 ((ctsvc_address_s*)record)->id = 0;
446                 break;
447         case CTSVC_RECORD_MESSENGER:
448                 ((ctsvc_messenger_s*)record)->id = 0;
449                 break;
450         case CTSVC_RECORD_GROUP_RELATION:
451                 ((ctsvc_group_relation_s*)record)->id = 0;
452                 break;
453         case CTSVC_RECORD_ACTIVITY:
454                 ((ctsvc_activity_s*)record)->id = 0;
455                 break;
456         case CTSVC_RECORD_PROFILE:
457                 ((ctsvc_profile_s*)record)->id = 0;
458                 break;
459         case CTSVC_RECORD_RELATIONSHIP:
460                 ((ctsvc_relationship_s*)record)->id = 0;
461                 break;
462         case CTSVC_RECORD_IMAGE:
463                 ((ctsvc_image_s*)record)->id = 0;
464                 break;
465         case CTSVC_RECORD_EXTENSION:
466                 ((ctsvc_extension_s*)record)->id = 0;
467                 break;
468         case CTSVC_RECORD_SIP:
469                 ((ctsvc_sip_s *)record)->id = 0;
470                 break;
471         default:
472                 ERR("record(%d) is not child of contact", record->r_type);
473                 return CONTACTS_ERROR_INVALID_PARAMETER;
474         }
475         return CONTACTS_ERROR_NONE;
476 }
477
478
479 static int __ctsvc_my_profile_add_child_record(contacts_record_h record,
480                 unsigned int property_id, contacts_record_h child_record)
481 {
482         int ret;
483         contacts_list_h list = NULL;
484         ctsvc_record_s *s_record = (ctsvc_record_s*)child_record;
485
486         ret = __ctsvc_my_profile_get_record_list_p(record, property_id, &list);
487         if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
488                 return ret;
489
490         if (CTSVC_RECORD_NAME == s_record->r_type && 1 == ((ctsvc_list_s*)list)->count) {
491                 ERR("This type(%d) of child_record can not be added anymore", s_record->r_type);
492                 return CONTACTS_ERROR_INVALID_PARAMETER;
493         }
494
495         if (CTSVC_RECORD_IMAGE == s_record->r_type && 1 == ((ctsvc_list_s*)list)->count) {
496                 ERR("This type(%d) of child_record can not be added anymore", s_record->r_type);
497                 return CONTACTS_ERROR_INVALID_PARAMETER;
498         }
499
500         ret = __ctsvc_my_profile_reset_child_record_id(child_record);
501         if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
502                 return ret;
503
504         ctsvc_list_add_child(list, child_record);
505
506         return CONTACTS_ERROR_NONE;
507 }
508
509 static int __ctsvc_my_profile_get_child_record_id(contacts_record_h child_record)
510 {
511         ctsvc_record_s *record = (ctsvc_record_s*)child_record;
512
513         switch (record->r_type) {
514         case CTSVC_RECORD_NAME:
515                 return ((ctsvc_name_s*)record)->id;
516         case CTSVC_RECORD_COMPANY:
517                 return ((ctsvc_company_s*)record)->id;
518         case CTSVC_RECORD_NOTE:
519                 return ((ctsvc_note_s*)record)->id;
520         case CTSVC_RECORD_NUMBER:
521                 return ((ctsvc_number_s*)record)->id;
522         case CTSVC_RECORD_EMAIL:
523                 return ((ctsvc_email_s*)record)->id;
524         case CTSVC_RECORD_URL:
525                 return ((ctsvc_url_s*)record)->id;
526         case CTSVC_RECORD_EVENT:
527                 return ((ctsvc_event_s*)record)->id;
528         case CTSVC_RECORD_NICKNAME:
529                 return ((ctsvc_nickname_s*)record)->id;
530         case CTSVC_RECORD_ADDRESS:
531                 return ((ctsvc_address_s*)record)->id;
532         case CTSVC_RECORD_MESSENGER:
533                 return ((ctsvc_messenger_s*)record)->id;
534         case CTSVC_RECORD_GROUP_RELATION:
535                 return ((ctsvc_group_relation_s*)record)->id;
536         case CTSVC_RECORD_ACTIVITY:
537                 return ((ctsvc_activity_s*)record)->id;
538         case CTSVC_RECORD_PROFILE:
539                 return ((ctsvc_profile_s*)record)->id;
540         case CTSVC_RECORD_RELATIONSHIP:
541                 return ((ctsvc_relationship_s*)record)->id;
542         case CTSVC_RECORD_IMAGE:
543                 return ((ctsvc_image_s*)record)->id;
544         case CTSVC_RECORD_EXTENSION:
545                 return ((ctsvc_extension_s*)record)->id;
546         case CTSVC_RECORD_SIP:
547                 return ((ctsvc_sip_s *)record)->id;
548         default:
549                 ERR("record(%d) is not child of contact", record->r_type);
550                 return 0;
551         }
552         return 0;
553 }
554
555
556 static int __ctsvc_my_profile_remove_child_record(contacts_record_h record,
557                 unsigned int property_id, contacts_record_h child_record)
558 {
559         int id;
560         int ret;
561         contacts_list_h list = NULL;
562
563         ret = __ctsvc_my_profile_get_record_list_p(record, property_id, &list);
564         if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
565                 return ret;
566
567         id = __ctsvc_my_profile_get_child_record_id(child_record);
568         ctsvc_list_remove_child(list, child_record, id ? true : false);
569
570         return CONTACTS_ERROR_NONE;
571 }
572
573 static int __ctsvc_my_profile_set_str(contacts_record_h record, unsigned int property_id,
574                 const char *str, bool *is_dirty)
575 {
576         ctsvc_my_profile_s *my_profile = (ctsvc_my_profile_s*)record;
577
578         switch (property_id) {
579         case CTSVC_PROPERTY_MY_PROFILE_DISPLAY_NAME:
580                 CHECK_DIRTY_STR(my_profile->display_name, str, is_dirty);
581                 FREEandSTRDUP(my_profile->display_name, str);
582                 break;
583         case CTSVC_PROPERTY_MY_PROFILE_IMAGE_THUMBNAIL:
584                 CHECK_DIRTY_STR(my_profile->image_thumbnail_path, str, is_dirty);
585                 FREEandSTRDUP(my_profile->image_thumbnail_path, str);
586                 break;
587         case CTSVC_PROPERTY_MY_PROFILE_UID:
588                 CHECK_DIRTY_STR(my_profile->uid, str, is_dirty);
589                 FREEandSTRDUP(my_profile->uid, str);
590                 break;
591         default:
592                 ERR("property_id(%d) is not supported in value(my_profile)", property_id);
593                 return CONTACTS_ERROR_INVALID_PARAMETER;
594         }
595         return CONTACTS_ERROR_NONE;
596 }
597
598 static int __ctsvc_my_profile_clone(contacts_record_h record,
599                 contacts_record_h *out_record)
600 {
601         ctsvc_my_profile_s *out_data = NULL;
602         ctsvc_my_profile_s *src_data = NULL;
603
604         src_data = (ctsvc_my_profile_s*)record;
605         out_data = calloc(1, sizeof(ctsvc_my_profile_s));
606         RETVM_IF(NULL == out_data, CONTACTS_ERROR_OUT_OF_MEMORY, "calloc() Fail");
607
608         out_data->id = src_data->id;
609         out_data->addressbook_id = src_data->addressbook_id;
610         out_data->changed_time = src_data->changed_time;
611
612         out_data->display_name = SAFE_STRDUP(src_data->display_name);
613         out_data->reverse_display_name = SAFE_STRDUP(src_data->reverse_display_name);
614         out_data->uid = SAFE_STRDUP(src_data->uid);
615         out_data->image_thumbnail_path = SAFE_STRDUP(src_data->image_thumbnail_path);
616
617         ctsvc_list_clone((contacts_list_h)src_data->name, (contacts_list_h*)&out_data->name);
618         out_data->name->l_type = CTSVC_RECORD_NAME;
619
620         ctsvc_list_clone((contacts_list_h)src_data->company, (contacts_list_h*)&out_data->company);
621         out_data->company->l_type = CTSVC_RECORD_COMPANY;
622
623         ctsvc_list_clone((contacts_list_h)src_data->note, (contacts_list_h*)&out_data->note);
624         out_data->note->l_type = CTSVC_RECORD_NOTE;
625
626         ctsvc_list_clone((contacts_list_h)src_data->numbers, (contacts_list_h*)&out_data->numbers);
627         out_data->numbers->l_type = CTSVC_RECORD_NUMBER;
628
629         ctsvc_list_clone((contacts_list_h)src_data->emails, (contacts_list_h*)&out_data->emails);
630         out_data->emails->l_type = CTSVC_RECORD_EMAIL;
631
632         ctsvc_list_clone((contacts_list_h)src_data->events, (contacts_list_h*)&out_data->events);
633         out_data->events->l_type = CTSVC_RECORD_EVENT;
634
635         ctsvc_list_clone((contacts_list_h)src_data->messengers, (contacts_list_h*)&out_data->messengers);
636         out_data->messengers->l_type = CTSVC_RECORD_MESSENGER;
637
638         ctsvc_list_clone((contacts_list_h)src_data->postal_addrs, (contacts_list_h*)&out_data->postal_addrs);
639         out_data->postal_addrs->l_type = CTSVC_RECORD_ADDRESS;
640
641         ctsvc_list_clone((contacts_list_h)src_data->urls, (contacts_list_h*)&out_data->urls);
642         out_data->urls->l_type = CTSVC_RECORD_URL;
643
644         ctsvc_list_clone((contacts_list_h)src_data->nicknames, (contacts_list_h*)&out_data->nicknames);
645         out_data->nicknames->l_type = CTSVC_RECORD_NICKNAME;
646
647         ctsvc_list_clone((contacts_list_h)src_data->profiles, (contacts_list_h*)&out_data->profiles);
648         out_data->profiles->l_type = CTSVC_RECORD_PROFILE;
649
650         ctsvc_list_clone((contacts_list_h)src_data->relationships, (contacts_list_h*)&out_data->relationships);
651         out_data->relationships->l_type = CTSVC_RECORD_RELATIONSHIP;
652
653         ctsvc_list_clone((contacts_list_h)src_data->images, (contacts_list_h*)&out_data->images);
654         out_data->images->l_type = CTSVC_RECORD_IMAGE;
655
656         ctsvc_list_clone((contacts_list_h)src_data->extensions, (contacts_list_h*)&out_data->extensions);
657         out_data->extensions->l_type = CTSVC_RECORD_EXTENSION;
658
659         ctsvc_list_clone((contacts_list_h)src_data->sips, (contacts_list_h*)&out_data->sips);
660         out_data->sips->l_type = CTSVC_RECORD_SIP;
661
662         int ret = ctsvc_record_copy_base(&(out_data->base), &(src_data->base));
663         if (CONTACTS_ERROR_NONE != ret) {
664                 ERR("ctsvc_record_copy_base() Fail");
665                 __ctsvc_my_profile_destroy((contacts_record_h)out_data, true);
666                 return ret;
667         }
668
669         *out_record = (contacts_record_h)out_data;
670
671         return CONTACTS_ERROR_NONE;
672 }
673