revise packaging
[platform/core/pim/contacts-service.git] / common / ctsvc_record_sdn.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_record.h"
23 #include "ctsvc_view.h"
24
25 static int __ctsvc_sdn_create(contacts_record_h *out_record);
26 static int __ctsvc_sdn_destroy(contacts_record_h record, bool delete_child);
27 static int __ctsvc_sdn_clone(contacts_record_h record, contacts_record_h *out_record);
28 static int __ctsvc_sdn_get_int(contacts_record_h record, unsigned int property_id, int *out);
29 static int __ctsvc_sdn_get_str(contacts_record_h record, unsigned int property_id, char **out_str);
30 static int __ctsvc_sdn_get_str_p(contacts_record_h record, unsigned int property_id, char **out_str);
31 static int __ctsvc_sdn_set_int(contacts_record_h record, unsigned int property_id, int value, bool *is_dirty);
32 static int __ctsvc_sdn_set_str(contacts_record_h record, unsigned int property_id, const char *str, bool *is_dirty);
33
34 ctsvc_record_plugin_cb_s sdn_plugin_cbs = {
35         .create = __ctsvc_sdn_create,
36         .destroy = __ctsvc_sdn_destroy,
37         .clone = __ctsvc_sdn_clone,
38         .get_str = __ctsvc_sdn_get_str,
39         .get_str_p = __ctsvc_sdn_get_str_p,
40         .get_int = __ctsvc_sdn_get_int,
41         .get_bool = NULL,
42         .get_lli = NULL,
43         .get_double = NULL,
44         .set_str = __ctsvc_sdn_set_str,
45         .set_int = __ctsvc_sdn_set_int,
46         .set_bool = NULL,
47         .set_lli = NULL,
48         .set_double = NULL,
49         .add_child_record = NULL,
50         .remove_child_record = NULL,
51         .get_child_record_count = NULL,
52         .get_child_record_at_p = NULL,
53         .clone_child_record_list = NULL,
54 };
55
56 static int __ctsvc_sdn_create(contacts_record_h *out_record)
57 {
58         ctsvc_sdn_s *sdn;
59         sdn = calloc(1, sizeof(ctsvc_sdn_s));
60         RETVM_IF(NULL == sdn, CONTACTS_ERROR_OUT_OF_MEMORY, "calloc() Fail");
61
62         *out_record = (contacts_record_h)sdn;
63         return CONTACTS_ERROR_NONE;
64 }
65
66 static int __ctsvc_sdn_destroy(contacts_record_h record, bool delete_child)
67 {
68         ctsvc_sdn_s *sdn = (ctsvc_sdn_s*)record;
69         sdn->base.plugin_cbs = NULL; /* help to find double destroy bug (refer to the contacts_record_destroy) */
70         free(sdn->base.properties_flags);
71
72         free(sdn->name);
73         free(sdn->number);
74         free(sdn);
75
76         return CONTACTS_ERROR_NONE;
77 }
78
79 static int __ctsvc_sdn_clone(contacts_record_h record, contacts_record_h *out_record)
80 {
81         ctsvc_sdn_s *out_data = NULL;
82         ctsvc_sdn_s *src_data = NULL;
83
84         src_data = (ctsvc_sdn_s*)record;
85         out_data = calloc(1, sizeof(ctsvc_sdn_s));
86         RETVM_IF(NULL == out_data, CONTACTS_ERROR_OUT_OF_MEMORY,
87                         "Out of memeory : calloc(ctsvc_sdn_s) Fail(%d)", CONTACTS_ERROR_OUT_OF_MEMORY);
88
89         out_data->id = src_data->id;
90         out_data->name = SAFE_STRDUP(src_data->name);
91         out_data->number = SAFE_STRDUP(src_data->number);
92         out_data->sim_slot_no = src_data->sim_slot_no;
93
94         int ret = ctsvc_record_copy_base(&(out_data->base), &(src_data->base));
95         if (CONTACTS_ERROR_NONE != ret) {
96                 ERR("ctsvc_record_copy_base() Fail");
97                 __ctsvc_sdn_destroy((contacts_record_h)out_data, true);
98                 return ret;
99         }
100
101         *out_record = (contacts_record_h)out_data;
102         return CONTACTS_ERROR_NONE;
103 }
104
105 static int __ctsvc_sdn_get_int(contacts_record_h record, unsigned int property_id, int *out)
106 {
107         ctsvc_sdn_s *sdn = (ctsvc_sdn_s*)record;
108
109         switch (property_id) {
110         case CTSVC_PROPERTY_SDN_ID:
111                 *out = sdn->id;
112                 break;
113         case CTSVC_PROPERTY_SDN_SIM_SLOT_NO:
114                 *out = sdn->sim_slot_no;
115                 break;
116         default:
117                 ERR("This field(%d) is not supported in value(sdn)", property_id);
118                 return CONTACTS_ERROR_INVALID_PARAMETER;
119         }
120         return CONTACTS_ERROR_NONE;
121 }
122
123 static int __ctsvc_sdn_get_str_real(contacts_record_h record, unsigned int property_id, char **out_str, bool copy)
124 {
125         ctsvc_sdn_s *sdn = (ctsvc_sdn_s*)record;
126
127         switch (property_id) {
128         case CTSVC_PROPERTY_SDN_NAME:
129                 *out_str = GET_STR(copy, sdn->name);
130                 break;
131         case CTSVC_PROPERTY_SDN_NUMBER:
132                 *out_str = GET_STR(copy, sdn->number);
133                 break;
134         default:
135                 ERR("This field(%d) is not supported in value(sdn)", property_id);
136                 return CONTACTS_ERROR_INVALID_PARAMETER;
137         }
138         return CONTACTS_ERROR_NONE;
139 }
140
141 static int __ctsvc_sdn_get_str_p(contacts_record_h record, unsigned int property_id, char **out_str)
142 {
143         return __ctsvc_sdn_get_str_real(record, property_id, out_str, false);
144 }
145
146 static int __ctsvc_sdn_get_str(contacts_record_h record, unsigned int property_id, char **out_str)
147 {
148         return __ctsvc_sdn_get_str_real(record, property_id, out_str, true);
149 }
150
151 static int __ctsvc_sdn_set_int(contacts_record_h record, unsigned int property_id, int value, bool *is_dirty)
152 {
153         ctsvc_sdn_s *sdn = (ctsvc_sdn_s*)record;
154
155         switch (property_id) {
156         case CTSVC_PROPERTY_SDN_ID:
157                 CHECK_DIRTY_VAL(sdn->id, value, is_dirty);
158                 sdn->id = value;
159                 break;
160         case CTSVC_PROPERTY_SDN_SIM_SLOT_NO:
161                 CHECK_DIRTY_VAL(sdn->sim_slot_no, value, is_dirty);
162                 sdn->sim_slot_no = value;
163                 break;
164         default:
165                 ERR("This field(%d) is not supported in value(sdn)", property_id);
166                 return CONTACTS_ERROR_INVALID_PARAMETER;
167         }
168         return CONTACTS_ERROR_NONE;
169 }
170
171 static int __ctsvc_sdn_set_str(contacts_record_h record, unsigned int property_id, const char *str, bool *is_dirty)
172 {
173         ctsvc_sdn_s *sdn = (ctsvc_sdn_s*)record;
174
175         switch (property_id) {
176         case CTSVC_PROPERTY_SDN_NAME:
177                 CHECK_DIRTY_STR(sdn->name, str, is_dirty);
178                 FREEandSTRDUP(sdn->name, str);
179                 break;
180         case CTSVC_PROPERTY_SDN_NUMBER:
181                 CHECK_DIRTY_STR(sdn->number, str, is_dirty);
182                 FREEandSTRDUP(sdn->number, str);
183                 break;
184         default:
185                 ERR("This field(%d) is not supported in value(sdn)", property_id);
186                 return CONTACTS_ERROR_INVALID_PARAMETER;
187         }
188         return CONTACTS_ERROR_NONE;
189 }
190