improve line coverage
[platform/core/pim/contacts-service.git] / common / ipc / ctsvc_ipc_contact.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 #include "ctsvc_internal.h"
20 #include "ctsvc_ipc_marshal.h"
21
22
23 static int __ctsvc_ipc_unmarshal_contact(pims_ipc_data_h ipc_data,
24                 const char *view_uri, contacts_record_h record)
25 {
26         ctsvc_contact_s *pcontact = (ctsvc_contact_s*)record;
27
28         RETV_IF(NULL == ipc_data, CONTACTS_ERROR_NO_DATA);
29         RETV_IF(NULL == record, CONTACTS_ERROR_NO_DATA);
30
31         do {
32                 if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->is_favorite) != CONTACTS_ERROR_NONE)
33                         break;
34                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->id) != CONTACTS_ERROR_NONE)
35                         break;
36                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->person_id) != CONTACTS_ERROR_NONE)
37                         break;
38                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->changed_time) != CONTACTS_ERROR_NONE)
39                         break;
40                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->link_mode) != CONTACTS_ERROR_NONE)
41                         break;
42                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->addressbook_id) != CONTACTS_ERROR_NONE)
43                         break;
44                 if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->has_phonenumber) != CONTACTS_ERROR_NONE)
45                         break;
46                 if (ctsvc_ipc_unmarshal_bool(ipc_data, &pcontact->has_email) != CONTACTS_ERROR_NONE)
47                         break;
48                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->display_name) != CONTACTS_ERROR_NONE)
49                         break;
50                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->reverse_display_name) != CONTACTS_ERROR_NONE)
51                         break;
52                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->display_source_type) != CONTACTS_ERROR_NONE)
53                         break;
54                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->display_name_language) != CONTACTS_ERROR_NONE)
55                         break;
56                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->reverse_display_name_language) != CONTACTS_ERROR_NONE)
57                         break;
58                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->sort_name) != CONTACTS_ERROR_NONE)
59                         break;
60                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->reverse_sort_name) != CONTACTS_ERROR_NONE)
61                         break;
62                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->sortkey) != CONTACTS_ERROR_NONE)
63                         break;
64                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->reverse_sortkey) != CONTACTS_ERROR_NONE)
65                         break;
66                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->uid) != CONTACTS_ERROR_NONE)
67                         break;
68                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->image_thumbnail_path) != CONTACTS_ERROR_NONE)
69                         break;
70                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->ringtone_path) != CONTACTS_ERROR_NONE)
71                         break;
72                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->vibration) != CONTACTS_ERROR_NONE)
73                         break;
74                 if (ctsvc_ipc_unmarshal_string(ipc_data, &pcontact->message_alert) != CONTACTS_ERROR_NONE)
75                         break;
76                 if (ctsvc_ipc_unmarshal_int(ipc_data, &pcontact->changed_ver) != CONTACTS_ERROR_NONE)
77                         break;
78
79                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->name) != CONTACTS_ERROR_NONE)
80                         break;
81                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->note) != CONTACTS_ERROR_NONE)
82                         break;
83                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->company) != CONTACTS_ERROR_NONE)
84                         break;
85                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->numbers) != CONTACTS_ERROR_NONE)
86                         break;
87                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->emails) != CONTACTS_ERROR_NONE)
88                         break;
89                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->grouprelations) != CONTACTS_ERROR_NONE)
90                         break;
91                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->events) != CONTACTS_ERROR_NONE)
92                         break;
93                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->messengers) != CONTACTS_ERROR_NONE)
94                         break;
95                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->postal_addrs) != CONTACTS_ERROR_NONE)
96                         break;
97                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->urls) != CONTACTS_ERROR_NONE)
98                         break;
99                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->nicknames) != CONTACTS_ERROR_NONE)
100                         break;
101                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->profiles) != CONTACTS_ERROR_NONE)
102                         break;
103                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->relationships) != CONTACTS_ERROR_NONE)
104                         break;
105                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->images) != CONTACTS_ERROR_NONE)
106                         break;
107                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->extensions) != CONTACTS_ERROR_NONE)
108                         break;
109                 if (ctsvc_ipc_unmarshal_child_list(ipc_data, (contacts_list_h*)&pcontact->sips) != CONTACTS_ERROR_NONE)
110                         break;
111
112                 return CONTACTS_ERROR_NONE;
113         } while (0);
114
115         /* LCOV_EXCL_START */
116         ERR("__ctsvc_ipc_unmarshal_contact() Fail");
117         return CONTACTS_ERROR_INVALID_PARAMETER;
118         /* LCOV_EXCL_STOP */
119 }
120
121 static int __ctsvc_ipc_marshal_contact(const contacts_record_h record,
122                 pims_ipc_data_h ipc_data)
123 {
124         ctsvc_contact_s *pcontact = (ctsvc_contact_s*)record;
125
126         RETV_IF(NULL == ipc_data, CONTACTS_ERROR_NO_DATA);
127         RETV_IF(NULL == pcontact, CONTACTS_ERROR_NO_DATA);
128
129         do {
130                 if (ctsvc_ipc_marshal_bool((pcontact->is_favorite), ipc_data) != CONTACTS_ERROR_NONE)
131                         break;
132                 if (ctsvc_ipc_marshal_int((pcontact->id), ipc_data) != CONTACTS_ERROR_NONE)
133                         break;
134                 if (ctsvc_ipc_marshal_int((pcontact->person_id), ipc_data) != CONTACTS_ERROR_NONE)
135                         break;
136                 if (ctsvc_ipc_marshal_int((pcontact->changed_time), ipc_data) != CONTACTS_ERROR_NONE)
137                         break;
138                 if (ctsvc_ipc_marshal_int((pcontact->link_mode), ipc_data) != CONTACTS_ERROR_NONE)
139                         break;
140                 if (ctsvc_ipc_marshal_int((pcontact->addressbook_id), ipc_data) != CONTACTS_ERROR_NONE)
141                         break;
142                 if (ctsvc_ipc_marshal_bool((pcontact->has_phonenumber), ipc_data) != CONTACTS_ERROR_NONE)
143                         break;
144                 if (ctsvc_ipc_marshal_bool((pcontact->has_email), ipc_data) != CONTACTS_ERROR_NONE)
145                         break;
146                 if (ctsvc_ipc_marshal_string((pcontact->display_name), ipc_data) != CONTACTS_ERROR_NONE)
147                         break;
148                 if (ctsvc_ipc_marshal_string((pcontact->reverse_display_name), ipc_data) != CONTACTS_ERROR_NONE)
149                         break;
150                 if (ctsvc_ipc_marshal_int((pcontact->display_source_type), ipc_data) != CONTACTS_ERROR_NONE)
151                         break;
152                 if (ctsvc_ipc_marshal_int((pcontact->display_name_language), ipc_data) != CONTACTS_ERROR_NONE)
153                         break;
154                 if (ctsvc_ipc_marshal_int((pcontact->reverse_display_name_language), ipc_data) != CONTACTS_ERROR_NONE)
155                         break;
156                 if (ctsvc_ipc_marshal_string((pcontact->sort_name), ipc_data) != CONTACTS_ERROR_NONE)
157                         break;
158                 if (ctsvc_ipc_marshal_string((pcontact->reverse_sort_name), ipc_data) != CONTACTS_ERROR_NONE)
159                         break;
160                 if (ctsvc_ipc_marshal_string((pcontact->sortkey), ipc_data) != CONTACTS_ERROR_NONE)
161                         break;
162                 if (ctsvc_ipc_marshal_string((pcontact->reverse_sortkey), ipc_data) != CONTACTS_ERROR_NONE)
163                         break;
164                 if (ctsvc_ipc_marshal_string((pcontact->uid), ipc_data) != CONTACTS_ERROR_NONE)
165                         break;
166                 if (ctsvc_ipc_marshal_string((pcontact->image_thumbnail_path), ipc_data) != CONTACTS_ERROR_NONE)
167                         break;
168                 if (ctsvc_ipc_marshal_string((pcontact->ringtone_path), ipc_data) != CONTACTS_ERROR_NONE)
169                         break;
170                 if (ctsvc_ipc_marshal_string((pcontact->vibration), ipc_data) != CONTACTS_ERROR_NONE)
171                         break;
172                 if (ctsvc_ipc_marshal_string((pcontact->message_alert), ipc_data) != CONTACTS_ERROR_NONE)
173                         break;
174                 if (ctsvc_ipc_marshal_int((pcontact->changed_ver), ipc_data) != CONTACTS_ERROR_NONE)
175                         break;
176
177                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->name, ipc_data) != CONTACTS_ERROR_NONE)
178                         break;
179                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->note, ipc_data) != CONTACTS_ERROR_NONE)
180                         break;
181                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->company, ipc_data) != CONTACTS_ERROR_NONE)
182                         break;
183                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->numbers, ipc_data) != CONTACTS_ERROR_NONE)
184                         break;
185                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->emails, ipc_data) != CONTACTS_ERROR_NONE)
186                         break;
187                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->grouprelations, ipc_data) != CONTACTS_ERROR_NONE)
188                         break;
189                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->events, ipc_data) != CONTACTS_ERROR_NONE)
190                         break;
191                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->messengers, ipc_data) != CONTACTS_ERROR_NONE)
192                         break;
193                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->postal_addrs, ipc_data) != CONTACTS_ERROR_NONE)
194                         break;
195                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->urls, ipc_data) != CONTACTS_ERROR_NONE)
196                         break;
197                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->nicknames, ipc_data) != CONTACTS_ERROR_NONE)
198                         break;
199                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->profiles, ipc_data) != CONTACTS_ERROR_NONE)
200                         break;
201                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->relationships, ipc_data) != CONTACTS_ERROR_NONE)
202                         break;
203                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->images, ipc_data) != CONTACTS_ERROR_NONE)
204                         break;
205                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->extensions, ipc_data) != CONTACTS_ERROR_NONE)
206                         break;
207                 if (ctsvc_ipc_marshal_list((contacts_list_h)pcontact->sips, ipc_data) != CONTACTS_ERROR_NONE)
208                         break;
209
210                 return CONTACTS_ERROR_NONE;
211         } while (0);
212
213         /* LCOV_EXCL_START */
214         ERR("_ctsvc_ipc_marshal() Fail");
215         return CONTACTS_ERROR_INVALID_PARAMETER;
216         /* LCOV_EXCL_STOP */
217 }
218
219 ctsvc_ipc_marshal_record_plugin_cb_s _ctsvc_ipc_record_contact_plugin_cb = {
220         .unmarshal_record = __ctsvc_ipc_unmarshal_contact,
221         .marshal_record = __ctsvc_ipc_marshal_contact
222 };
223